4 * The windows message processing methods.
6 * Copyright (c) 1999-2000 Pawel W. Olszta. All Rights Reserved.
7 * Written by Pawel W. Olszta, <olszta@sourceforge.net>
8 * Creation date: Fri Dec 3 1999
10 * Permission is hereby granted, free of charge, to any person obtaining a
11 * copy of this software and associated documentation files (the "Software"),
12 * to deal in the Software without restriction, including without limitation
13 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 * and/or sell copies of the Software, and to permit persons to whom the
15 * Software is furnished to do so, subject to the following conditions:
17 * The above copyright notice and this permission notice shall be included
18 * in all copies or substantial portions of the Software.
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23 * PAWEL W. OLSZTA BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
24 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
25 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 #include "../include/GL/freeglut.h"
33 #include "freeglut_internal.h"
36 #if TARGET_HOST_UNIX_X11
37 #include <sys/types.h>
42 #elif TARGET_HOST_WIN32
46 #define MAX(a,b) (((a)>(b)) ? (a) : (b))
50 #define MIN(a,b) (((a)<(b)) ? (a) : (b))
55 * TODO BEFORE THE STABLE RELEASE:
57 * There are some issues concerning window redrawing under X11, and maybe
58 * some events are not handled. The Win32 version lacks some more features,
59 * but seems acceptable for not demanding purposes.
61 * Need to investigate why the X11 version breaks out with an error when
62 * closing a window (using the window manager, not glutDestroyWindow)...
65 /* -- PRIVATE FUNCTIONS ---------------------------------------------------- */
68 * Handle a window configuration change. When no reshape
69 * callback is hooked, the viewport size is updated to
70 * match the new window size.
72 * XXX We can/should make a "unified" window handle type so that
73 * XXX the function headers don't need this silly #ifdef junk.
74 * XXX Make the type, say, {fgWindow}. On UNIX_X11, this is
75 * XXX {Window}. On WIN32, it is {HWND}. Then do the #ifdef
76 * XXX junk *once* in "freeglut_internal.h".
78 static void fghReshapeWindowByHandle
79 #if TARGET_HOST_UNIX_X11
80 ( Window handle, int width, int height )
81 #elif TARGET_HOST_WIN32
82 ( HWND handle, int width, int height )
85 SFG_Window *current_window = fgStructure.Window;
87 SFG_Window* window = fgWindowByHandle( handle );
88 freeglut_return_if_fail( window != NULL );
91 #if TARGET_HOST_UNIX_X11
93 XResizeWindow( fgDisplay.Display, window->Window.Handle,
95 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
97 * XXX REALLY shouldn't be done. GLUT docs state that this
98 * XXX isn't even processed immediately, but rather waits
99 * XXX for return to the mainloop. "This allows multiple
100 * XXX glutReshapeWindow, glutPositionWindow, and glutFullScreen
101 * XXX requests to the same window to be coalesced." (This is
102 * XXX having some deleterious effect on a sample program of mine.)
103 * XXX Not only does GLUT not flush at this point, GLUT doesn't even
104 * XXX *do* the reshape at this point! We should probably rip this
105 * XXX out and do what GLUT promises. It would be more efficient, and
106 * XXX might be more compatible.
109 #elif TARGET_HOST_WIN32
115 GetWindowRect( window->Window.Handle, &winRect );
119 if ( window->Parent == NULL )
122 * Adjust the size of the window to allow for the size of the
123 * frame, if we are not a menu
125 if ( ! window->IsMenu )
127 width += GetSystemMetrics( SM_CXSIZEFRAME ) * 2;
128 height += GetSystemMetrics( SM_CYSIZEFRAME ) * 2 +
129 GetSystemMetrics( SM_CYCAPTION );
134 GetWindowRect( window->Parent->Window.Handle,
136 x -= winRect.left + GetSystemMetrics( SM_CXSIZEFRAME );
137 y -= winRect.top + GetSystemMetrics( SM_CYSIZEFRAME ) +
138 GetSystemMetrics( SM_CYCAPTION );
142 window->Window.Handle,
153 if( !( FETCH_WCB( *window, Reshape ) ) )
155 fgSetWindow( window );
156 glViewport( 0, 0, width, height );
159 INVOKE_WCB( *window, Reshape, ( width, height ) );
162 * Force a window redraw. In Windows at least this is only a partial
163 * solution: if the window is increasing in size in either dimension,
164 * the already-drawn part does not get drawn again and things look funny.
165 * But without this we get this bad behaviour whenever we resize the
168 window->State.Redisplay = GL_TRUE;
171 fgSetWindow( current_window );
175 * Calls a window's redraw method. This is used when
176 * a redraw is forced by the incoming window messages.
178 static void fghRedrawWindowByHandle
179 #if TARGET_HOST_UNIX_X11
181 #elif TARGET_HOST_WIN32
185 SFG_Window* window = fgWindowByHandle( handle );
186 freeglut_return_if_fail( window != NULL );
189 * XXX Other than clearing the Redisplay flag or not,
190 * XXX we may as well rely on the INVOK_WCB() doing this
193 * XXX If we do not invoke the display because the pointer
194 * XXX is not defined (should never happen, really), then
195 * XXX we may enter an infinite busy-loop trying to update
196 * XXX the window. Similarly, if we skip because the window
197 * XXX is not visible. However, if the window becomes visible
198 * XXX at a later time, the window should get its callback
199 * XXX invoked. I would recommend removing the first check,
200 * XXX and making the second check only affect whether the
201 * XXX callback is invoked---but always clear the flag, if
202 * XXX the {window} pointer is defined.
204 freeglut_return_if_fail( FETCH_WCB( *window, Display ) );
205 freeglut_return_if_fail( window->State.Visible );
207 if( window->State.NeedToResize )
209 SFG_Window *current_window = fgStructure.Window;
211 fgSetWindow( window );
213 fghReshapeWindowByHandle(
214 window->Window.Handle,
219 window->State.NeedToResize = GL_FALSE;
220 fgSetWindow ( current_window );
223 window->State.Redisplay = GL_FALSE;
224 INVOKE_WCB( *window, Display, ( ) );
228 * A static helper function to execute display callback for a window
230 static void fghcbDisplayWindow( SFG_Window *window,
231 SFG_Enumerator *enumerator )
234 * XXX Do we need/want to check the callback pointer here?
235 * XXX INVOKE_WCB() will check for us. Arguably, the
236 * XXX Redisplay status flag should be cleared regardless
237 * XXX of any concern but that {window} is a valid pointer
238 * XXX (which this function is assuming anyway).
239 * XXX Especially since old GLUT wouldn't even enter its main
240 * XXX loop if you didn't have a display callback defined...
242 if( ( FETCH_WCB( *window, Display ) ) &&
243 window->State.Redisplay &&
244 window->State.Visible )
246 if( window->State.NeedToResize )
248 SFG_Window *current_window = fgStructure.Window;
250 fgSetWindow( window );
252 fghReshapeWindowByHandle(
253 window->Window.Handle,
258 window->State.NeedToResize = GL_FALSE;
259 fgSetWindow ( current_window );
262 window->State.Redisplay = GL_FALSE;
264 #if TARGET_HOST_UNIX_X11
266 SFG_Window *current_window = fgStructure.Window;
268 INVOKE_WCB( *window, Display, ( ) );
269 fgSetWindow( current_window );
271 #elif TARGET_HOST_WIN32
273 window->Window.Handle, NULL, NULL,
274 RDW_NOERASE | RDW_INTERNALPAINT | RDW_INVALIDATE | RDW_UPDATENOW
279 fgEnumSubWindows( window, fghcbDisplayWindow, enumerator );
283 * Make all windows perform a display call
285 static void fghDisplayAll( void )
287 SFG_Enumerator enumerator;
289 enumerator.found = GL_FALSE;
290 enumerator.data = NULL;
292 fgEnumWindows( fghcbDisplayWindow, &enumerator );
296 * Window enumerator callback to check for the joystick polling code
298 static void fghcbCheckJoystickPolls( SFG_Window *window,
299 SFG_Enumerator *enumerator )
301 long int checkTime = fgElapsedTime( );
303 if( window->State.JoystickLastPoll + window->State.JoystickPollRate <=
306 fgJoystickPollWindow( window );
307 window->State.JoystickLastPoll = checkTime;
310 fgEnumSubWindows( window, fghcbCheckJoystickPolls, enumerator );
314 * Check all windows for joystick polling
316 static void fghCheckJoystickPolls( void )
318 SFG_Enumerator enumerator;
320 enumerator.found = GL_FALSE;
321 enumerator.data = NULL;
323 fgEnumWindows( fghcbCheckJoystickPolls, &enumerator );
327 * Check the global timers
329 static void fghCheckTimers( void )
331 long checkTime = fgElapsedTime( );
332 SFG_Timer *timer, *next;
335 fgListInit(&timedOut);
337 for( timer = (SFG_Timer *)fgState.Timers.First;
339 timer = (SFG_Timer *)next )
341 next = (SFG_Timer *)timer->Node.Next;
343 if( timer->TriggerTime <= checkTime )
345 fgListRemove( &fgState.Timers, &timer->Node );
346 fgListAppend( &timedOut, &timer->Node );
351 * Now feel free to execute all the hooked and timed out timer callbacks
352 * And delete the timed out timers...
354 while ( (timer = (SFG_Timer *)timedOut.First) )
356 if( timer->Callback != NULL )
357 timer->Callback( timer->ID );
358 fgListRemove( &timedOut, &timer->Node );
367 long fgElapsedTime( void )
369 if ( fgState.Time.Set )
371 #if TARGET_HOST_UNIX_X11
375 gettimeofday( &now, NULL );
377 elapsed = (now.tv_usec - fgState.Time.Value.tv_usec) / 1000;
378 elapsed += (now.tv_sec - fgState.Time.Value.tv_sec) * 1000;
381 #elif TARGET_HOST_WIN32
382 return timeGetTime() - fgState.Time.Value;
387 #if TARGET_HOST_UNIX_X11
388 gettimeofday( &fgState.Time.Value, NULL );
389 #elif TARGET_HOST_WIN32
390 fgState.Time.Value = timeGetTime () ;
392 fgState.Time.Set = GL_TRUE ;
401 void fgError( const char *fmt, ... )
407 fprintf( stderr, "freeglut ");
408 if( fgState.ProgramName )
409 fprintf (stderr, "(%s): ", fgState.ProgramName);
410 vfprintf( stderr, fmt, ap );
411 fprintf( stderr, "\n" );
415 if ( fgState.Initialised )
421 void fgWarning( const char *fmt, ... )
427 fprintf( stderr, "freeglut ");
428 if( fgState.ProgramName )
429 fprintf( stderr, "(%s): ", fgState.ProgramName );
430 vfprintf( stderr, fmt, ap );
431 fprintf( stderr, "\n" );
437 * Indicates whether Joystick events are being used by ANY window.
439 * The current mechanism is to walk all of the windows and ask if
440 * there is a joystick callback. Certainly in some cases, maybe
441 * in all cases, the joystick is attached to the system and accessed
442 * from ONE point by GLUT/freeglut, so this is not the right way,
443 * in general, to do this. However, the Joystick code is segregated
444 * in its own little world, so we can't access the information that
445 * we need in order to do that nicely.
448 * * Store Joystick data into freeglut global state.
449 * * Provide NON-static functions or data from Joystick *.c file.
451 * Basically, the RIGHT way to do this requires knowing something
452 * about the Joystick. Right now, the Joystick code is behind
456 static void fgCheckJoystickCallback( SFG_Window* w, SFG_Enumerator* e)
458 if( FETCH_WCB( *w, Joystick ) )
463 fgEnumSubWindows( w, fgCheckJoystickCallback, e );
465 static int fgHaveJoystick( void )
467 SFG_Enumerator enumerator;
468 enumerator.found = GL_FALSE;
469 enumerator.data = NULL;
470 fgEnumWindows( fgCheckJoystickCallback, &enumerator );
471 return !!enumerator.data;
473 static void fgHavePendingRedisplaysCallback( SFG_Window* w, SFG_Enumerator* e)
475 if( w->State.Redisplay )
480 fgEnumSubWindows( w, fgHavePendingRedisplaysCallback, e );
482 static int fgHavePendingRedisplays (void)
484 SFG_Enumerator enumerator;
485 enumerator.found = GL_FALSE;
486 enumerator.data = NULL;
487 fgEnumWindows( fgHavePendingRedisplaysCallback, &enumerator );
488 return !!enumerator.data;
491 * Indicates whether there are any outstanding timers.
494 static int fgHaveTimers( void )
496 return !!fgState.Timers.First;
500 * Returns the number of GLUT ticks (milliseconds) till the next timer event.
502 static long fgNextTimer( void )
504 long now = fgElapsedTime();
508 for( timer = (SFG_Timer *)fgState.Timers.First;
510 timer = (SFG_Timer *)timer->Node.Next )
511 ret = MIN( ret, MAX( 0, timer->TriggerTime - now ) );
516 * Does the magic required to relinquish the CPU until something interesting
519 static void fgSleepForEvents( void )
521 #if TARGET_HOST_UNIX_X11
528 if( fgState.IdleCallback || fgHavePendingRedisplays( ) )
530 socket = ConnectionNumber( fgDisplay.Display );
532 FD_SET( socket, &fdset );
534 msec = fgNextTimer( );
535 if( fgHaveJoystick( ) )
536 msec = MIN( msec, 10 );
538 wait.tv_sec = msec / 1000;
539 wait.tv_usec = (msec % 1000) * 1000;
540 err = select( socket+1, &fdset, NULL, NULL, &wait );
543 fgWarning ( "freeglut select() error: %d\n", errno );
545 #elif TARGET_HOST_WIN32
549 #if TARGET_HOST_UNIX_X11
551 * Returns GLUT modifier mask for an XEvent.
553 int fgGetXModifiers( XEvent *event )
557 if( event->xkey.state & ( ShiftMask | LockMask ) )
558 ret |= GLUT_ACTIVE_SHIFT;
559 if( event->xkey.state & ControlMask )
560 ret |= GLUT_ACTIVE_CTRL;
561 if( event->xkey.state & Mod1Mask )
562 ret |= GLUT_ACTIVE_ALT;
569 /* -- INTERFACE FUNCTIONS -------------------------------------------------- */
572 * Executes a single iteration in the freeglut processing loop.
574 void FGAPIENTRY glutMainLoopEvent( void )
576 #if TARGET_HOST_UNIX_X11
581 * This code was repeated constantly, so here it goes into a definition:
583 #define GETWINDOW(a) \
584 window = fgWindowByHandle( event.a.window ); \
585 if( window == NULL ) \
588 #define GETMOUSE(a) \
589 window->State.MouseX = event.a.x; \
590 window->State.MouseY = event.a.y;
592 freeglut_assert_ready;
594 while( XPending( fgDisplay.Display ) )
596 XNextEvent( fgDisplay.Display, &event );
602 * Destroy the window when the WM_DELETE_WINDOW message arrives
604 if( (Atom) event.xclient.data.l[ 0 ] == fgDisplay.DeleteWindow )
606 GETWINDOW( xclient );
608 fgCloseWindow ( window ) ;
609 fgAddToWindowDestroyList ( window, GL_FALSE );
614 * CreateNotify causes a configure-event so that sub-windows are
615 * handled compatibly with GLUT. Otherwise, your sub-windows
616 * (in freeglut only) will not get an initial reshape event,
617 * which can break things.
619 * XXX NOTE that it is possible that you will more than one Reshape
620 * XXX event for your top-level window, but something like this
621 * XXX appears to be required for compatbility.
623 * GLUT presumably does this because it generally tries to treat
624 * sub-windows the same as windows.
627 case ConfigureNotify:
628 GETWINDOW( xconfigure );
629 window->State.NeedToResize = GL_TRUE ;
630 window->State.Width = event.xconfigure.width ;
631 window->State.Height = event.xconfigure.height;
636 * This is sent to confirm the XDestroyWindow call.
637 * XXX WHY is this commented out? Should we re-enable it?
639 /* fgAddToWindowDestroyList ( window, GL_FALSE ); */
644 * We are too dumb to process partial exposes...
645 * XXX Well, we could do it. However, it seems to only
646 * XXX be potentially useful for single-buffered (since
647 * XXX double-buffered does not respect viewport when we
648 * XXX do a buffer-swap).
650 if( event.xexpose.count == 0 )
651 fghRedrawWindowByHandle( event.xexpose.window );
657 * If we never do anything with this, can we just not ask to
658 * get these messages?
664 * Have the client's keyboard knowledge updated (xlib.ps,
665 * page 206, says that's a good thing to do)
667 XRefreshKeyboardMapping( (XMappingEvent *) &event );
670 case VisibilityNotify:
672 GETWINDOW( xvisibility );
673 if( ! FETCH_WCB( *window, WindowStatus ) )
675 fgSetWindow( window );
678 * Sending this event, the X server can notify us that the window
679 * has just acquired one of the three possible visibility states:
680 * VisibilityUnobscured, VisibilityPartiallyObscured or
681 * VisibilityFullyObscured
683 switch( event.xvisibility.state )
685 case VisibilityUnobscured:
686 INVOKE_WCB( *window, WindowStatus, ( GLUT_FULLY_RETAINED ) );
687 window->State.Visible = GL_TRUE;
690 case VisibilityPartiallyObscured:
691 INVOKE_WCB( *window, WindowStatus,
692 ( GLUT_PARTIALLY_RETAINED ) );
693 window->State.Visible = GL_TRUE;
696 case VisibilityFullyObscured:
697 INVOKE_WCB( *window, WindowStatus, ( GLUT_FULLY_COVERED ) );
698 window->State.Visible = GL_FALSE;
702 fgWarning( "Uknown X visibility state: %d",
703 event.xvisibility.state );
711 GETWINDOW( xcrossing );
712 GETMOUSE( xcrossing );
713 INVOKE_WCB( *window, Entry, ( ( EnterNotify == event.type ) ?
720 GETWINDOW( xmotion );
723 if( window->ActiveMenu )
725 if( window == window->ActiveMenu->ParentWindow )
727 window->ActiveMenu->Window->State.MouseX =
728 event.xmotion.x_root - window->ActiveMenu->X;
729 window->ActiveMenu->Window->State.MouseY =
730 event.xmotion.y_root - window->ActiveMenu->Y;
732 window->ActiveMenu->Window->State.Redisplay = GL_TRUE ;
733 fgSetWindow( window->ActiveMenu->ParentWindow ) ;
739 * XXX For more than 5 buttons, just check {event.xmotion.state},
740 * XXX rather than a host of bit-masks?
742 #define BUTTON_MASK \
743 ( Button1Mask | Button2Mask | Button3Mask | Button4Mask | Button5Mask )
744 if ( event.xmotion.state & BUTTON_MASK )
745 INVOKE_WCB( *window, Motion, ( event.xmotion.x,
748 INVOKE_WCB( *window, Passive, ( event.xmotion.x,
756 GLboolean pressed = GL_TRUE;
759 if( event.type == ButtonRelease )
763 * A mouse button has been pressed or released. Traditionally,
764 * break if the window was found within the freeglut structures.
766 GETWINDOW( xbutton );
770 * An X button (at least in XFree86) is numbered from 1.
771 * A GLUT button is numbered from 0.
772 * Old GLUT passed through buttons other than just the first
773 * three, though it only gave symbolic names and official
774 * support to the first three.
776 button = event.xbutton.button - 1;
779 * XXX This comment is replicated in the WIN32 section and
780 * XXX maybe also in the menu code. Can we move the info
781 * XXX to one central place and *reference* it from here?
783 * Do not execute the application's mouse callback if a menu
784 * is hooked to this button. In that case an appropriate
785 * private call should be generated.
786 * Near as I can tell, this is the menu behaviour:
787 * - Down-click the menu button, menu not active: activate
788 * the menu with its upper left-hand corner at the mouse
790 * - Down-click any button outside the menu, menu active:
791 * deactivate the menu
792 * - Down-click any button inside the menu, menu active:
793 * select the menu entry and deactivate the menu
794 * - Up-click the menu button, menu not active: nothing happens
795 * - Up-click the menu button outside the menu, menu active:
797 * - Up-click the menu button inside the menu, menu active:
798 * select the menu entry and deactivate the menu
800 /* Window has an active menu, it absorbs any mouse click */
801 if( window->ActiveMenu )
803 if( window == window->ActiveMenu->ParentWindow )
805 window->ActiveMenu->Window->State.MouseX =
806 event.xbutton.x_root - window->ActiveMenu->X;
807 window->ActiveMenu->Window->State.MouseY =
808 event.xbutton.y_root - window->ActiveMenu->Y;
811 /* In the menu, invoke the callback and deactivate the menu*/
812 if( fgCheckActiveMenu( window->ActiveMenu->Window,
813 window->ActiveMenu ) )
816 * Save the current window and menu and set the current
817 * window to the window whose menu this is
819 SFG_Window *save_window = fgStructure.Window;
820 SFG_Menu *save_menu = fgStructure.Menu;
821 SFG_Window *parent_window =
822 window->ActiveMenu->ParentWindow;
823 fgSetWindow( parent_window );
824 fgStructure.Menu = window->ActiveMenu;
826 /* Execute the menu callback */
827 fgExecuteMenuCallback( window->ActiveMenu );
828 fgDeactivateMenu( parent_window );
830 /* Restore the current window and menu */
831 fgSetWindow( save_window );
832 fgStructure.Menu = save_menu;
836 * Outside the menu, deactivate if it's a downclick
837 * XXX This isn't enough. A downclick outside of
838 * XXX the interior of our freeglut windows should also
839 * XXX deactivate the menu. This is more complicated.
841 fgDeactivateMenu( window->ActiveMenu->ParentWindow );
843 window->State.Redisplay = GL_TRUE;
848 * No active menu, let's check whether we need to activate one.
850 if( ( 0 <= button ) &&
851 ( FREEGLUT_MAX_MENUS > button ) &&
852 ( window->Menu[ button ] ) &&
855 window->State.Redisplay = GL_TRUE;
856 fgSetWindow( window );
857 fgActivateMenu( window, button );
862 * Check if there is a mouse or mouse wheel callback hooked to the
865 if( ! FETCH_WCB( *window, Mouse ) &&
866 ! FETCH_WCB( *window, MouseWheel ) )
870 * XXX Why don't we use {window}? Other code here does...
872 fgState.Modifiers = fgGetXModifiers( &event );
875 * Finally execute the mouse or mouse wheel callback
877 * XXX Use a symbolic constant, *not* "4"!
879 if( ( button < 3 ) || ( ! FETCH_WCB( *window, MouseWheel ) ) )
880 INVOKE_WCB( *window, Mouse, ( button,
881 pressed ? GLUT_DOWN : GLUT_UP,
888 * Map 4 and 5 to wheel zero; EVEN to +1, ODD to -1
889 * " 6 and 7 " " one; ...
891 * XXX This *should* be behind some variables/macros,
892 * XXX since the order and numbering isn't certain
893 * XXX See XFree86 configuration docs (even back in the
894 * XXX 3.x days, and especially with 4.x).
896 * XXX Note that {button} has already been decremeted
897 * XXX in mapping from X button numbering to GLUT.
899 int wheel_number = (button - 3) / 2;
905 INVOKE_WCB( *window, MouseWheel, ( wheel_number,
913 * Trash the modifiers state
915 fgState.Modifiers = 0xffffffff;
922 FGCBKeyboard keyboard_cb;
923 FGCBSpecial special_cb;
928 if( event.type == KeyPress )
930 keyboard_cb = FETCH_WCB( *window, Keyboard );
931 special_cb = FETCH_WCB( *window, Special );
935 keyboard_cb = FETCH_WCB( *window, KeyboardUp );
936 special_cb = FETCH_WCB( *window, SpecialUp );
940 * Is there a keyboard/special callback hooked for this window?
942 if( keyboard_cb || special_cb )
944 XComposeStatus composeStatus;
945 char asciiCode[ 32 ];
950 * Check for the ASCII/KeySym codes associated with the event:
952 len = XLookupString( &event.xkey, asciiCode, sizeof(asciiCode),
953 &keySym, &composeStatus
957 * GLUT API tells us to have two separate callbacks...
962 * ...one for the ASCII translateable keypresses...
966 fgSetWindow( window );
967 fgState.Modifiers = fgGetXModifiers( &event );
968 keyboard_cb( asciiCode[ 0 ],
969 event.xkey.x, event.xkey.y
971 fgState.Modifiers = 0xffffffff;
979 * ...and one for all the others, which need to be
980 * translated to GLUT_KEY_Xs...
984 case XK_F1: special = GLUT_KEY_F1; break;
985 case XK_F2: special = GLUT_KEY_F2; break;
986 case XK_F3: special = GLUT_KEY_F3; break;
987 case XK_F4: special = GLUT_KEY_F4; break;
988 case XK_F5: special = GLUT_KEY_F5; break;
989 case XK_F6: special = GLUT_KEY_F6; break;
990 case XK_F7: special = GLUT_KEY_F7; break;
991 case XK_F8: special = GLUT_KEY_F8; break;
992 case XK_F9: special = GLUT_KEY_F9; break;
993 case XK_F10: special = GLUT_KEY_F10; break;
994 case XK_F11: special = GLUT_KEY_F11; break;
995 case XK_F12: special = GLUT_KEY_F12; break;
997 case XK_Left: special = GLUT_KEY_LEFT; break;
998 case XK_Right: special = GLUT_KEY_RIGHT; break;
999 case XK_Up: special = GLUT_KEY_UP; break;
1000 case XK_Down: special = GLUT_KEY_DOWN; break;
1003 case XK_Prior: special = GLUT_KEY_PAGE_UP; break;
1005 case XK_Next: special = GLUT_KEY_PAGE_DOWN; break;
1007 case XK_Home: special = GLUT_KEY_HOME; break;
1009 case XK_End: special = GLUT_KEY_END; break;
1011 case XK_Insert: special = GLUT_KEY_INSERT; break;
1015 * Execute the callback (if one has been specified),
1016 * given that the special code seems to be valid...
1018 if( special_cb && (special != -1) )
1020 fgSetWindow( window );
1021 fgState.Modifiers = fgGetXModifiers( &event );
1022 special_cb( special, event.xkey.x, event.xkey.y );
1023 fgState.Modifiers = 0xffffffff;
1030 case ReparentNotify:
1031 break; /* XXX Should disable this event */
1034 fgWarning ("Unknown X event type: %d", event.type);
1039 #elif TARGET_HOST_WIN32
1043 while( PeekMessage( &stMsg, NULL, 0, 0, PM_NOREMOVE ) )
1045 if( GetMessage( &stMsg, NULL, 0, 0 ) == 0 )
1046 fgState.ExecState = GLUT_EXEC_STATE_STOP ;
1048 TranslateMessage( &stMsg );
1049 DispatchMessage( &stMsg );
1054 fghCheckJoystickPolls( );
1061 * Enters the freeglut processing loop.
1062 * Stays until the "ExecState" changes to "GLUT_EXEC_STATE_STOP".
1064 void FGAPIENTRY glutMainLoop( void )
1066 #if TARGET_HOST_WIN32
1067 SFG_Window *window = (SFG_Window *)fgStructure.Windows.First ;
1070 freeglut_assert_ready;
1072 #if TARGET_HOST_WIN32
1074 * Processing before the main loop: If there is a window which is open and
1075 * which has a visibility callback, call it. I know this is an ugly hack,
1076 * but I'm not sure what else to do about it. Ideally we should leave
1077 * something uninitialized in the create window code and initialize it in
1078 * the main loop, and have that initialization create a "WM_ACTIVATE"
1079 * message. Then we would put the visibility callback code in the
1080 * "case WM_ACTIVATE" block below. - John Fay -- 10/24/02
1084 if ( FETCH_WCB( *window, Visibility ) )
1086 SFG_Window *current_window = fgStructure.Window ;
1088 INVOKE_WCB( *window, Visibility, ( window->State.Visible ) );
1089 fgSetWindow( current_window );
1092 window = (SFG_Window *)window->Node.Next ;
1096 fgState.ExecState = GLUT_EXEC_STATE_RUNNING ;
1097 while( fgState.ExecState == GLUT_EXEC_STATE_RUNNING )
1099 glutMainLoopEvent( );
1101 if( fgStructure.Windows.First == NULL )
1102 fgState.ExecState = GLUT_EXEC_STATE_STOP;
1105 if( fgState.IdleCallback )
1106 fgState.IdleCallback( );
1113 fgExecutionState execState = fgState.ExecState;
1116 * When this loop terminates, destroy the display, state and structure
1117 * of a freeglut session, so that another glutInit() call can happen
1121 if( execState == GLUT_ACTION_EXIT )
1127 * Leaves the freeglut processing loop.
1129 void FGAPIENTRY glutLeaveMainLoop( void )
1131 fgState.ExecState = GLUT_EXEC_STATE_STOP ;
1135 #if TARGET_HOST_WIN32
1137 * Determine a GLUT modifer mask based on MS-WINDOWS system info.
1139 int fgGetWin32Modifiers (void)
1142 ( ( ( GetKeyState( VK_LSHIFT ) < 0 ) ||
1143 ( GetKeyState( VK_RSHIFT ) < 0 )) ? GLUT_ACTIVE_SHIFT : 0 ) |
1144 ( ( ( GetKeyState( VK_LCONTROL ) < 0 ) ||
1145 ( GetKeyState( VK_RCONTROL ) < 0 )) ? GLUT_ACTIVE_CTRL : 0 ) |
1146 ( ( ( GetKeyState( VK_LMENU ) < 0 ) ||
1147 ( GetKeyState( VK_RMENU ) < 0 )) ? GLUT_ACTIVE_ALT : 0 );
1151 * The window procedure for handling Win32 events
1153 LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam,
1156 SFG_Window* window = fgWindowByHandle( hWnd );
1160 if ( ( window == NULL ) && ( uMsg != WM_CREATE ) )
1161 return DefWindowProc( hWnd, uMsg, wParam, lParam ) ;
1163 /* printf ( "Window %3d message <%04x> %12d %12d\n", window?window->ID:0,
1164 uMsg, wParam, lParam ); */
1169 * The window structure is passed as the creation structure paramter...
1171 window = (SFG_Window *) (((LPCREATESTRUCT) lParam)->lpCreateParams);
1172 assert( window != NULL );
1174 window->Window.Handle = hWnd;
1175 window->Window.Device = GetDC( hWnd );
1176 if( window->IsMenu )
1178 unsigned int current_DisplayMode = fgState.DisplayMode;
1179 fgState.DisplayMode = GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH;
1180 fgSetupPixelFormat( window, GL_FALSE, PFD_MAIN_PLANE );
1181 fgState.DisplayMode = current_DisplayMode;
1183 if( fgStructure.MenuContext )
1184 wglMakeCurrent( window->Window.Device,
1185 fgStructure.MenuContext->Context
1189 fgStructure.MenuContext =
1190 (SFG_MenuContext *)malloc( sizeof(SFG_MenuContext) );
1191 fgStructure.MenuContext->Context =
1192 wglCreateContext( window->Window.Device );
1195 /* window->Window.Context = wglGetCurrentContext () ; */
1196 window->Window.Context = wglCreateContext( window->Window.Device );
1200 fgSetupPixelFormat( window, GL_FALSE, PFD_MAIN_PLANE );
1202 if( ! fgState.UseCurrentContext )
1203 window->Window.Context =
1204 wglCreateContext( window->Window.Device );
1207 window->Window.Context = wglGetCurrentContext( );
1208 if( ! window->Window.Context )
1209 window->Window.Context =
1210 wglCreateContext( window->Window.Device );
1214 window->State.NeedToResize = GL_TRUE;
1215 window->State.Width = fgState.Size.X;
1216 window->State.Height = fgState.Size.Y;
1218 ReleaseDC( window->Window.Handle, window->Window.Device );
1223 * We got resized... But check if the window has been already added...
1225 window->State.NeedToResize = GL_TRUE;
1226 window->State.Width = LOWORD(lParam);
1227 window->State.Height = HIWORD(lParam);
1231 printf("WM_SETFOCUS: %p\n", window );
1232 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1236 if (LOWORD(wParam) != WA_INACTIVE)
1238 /* glutSetCursor( fgStructure.Window->State.Cursor ); */
1239 printf("WM_ACTIVATE: glutSetCursor( %p, %d)\n", window,
1240 window->State.Cursor );
1241 glutSetCursor( window->State.Cursor );
1244 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1249 * XXX Why not re-use some common code with the glutSetCursor()
1250 * XXX function (or perhaps invoke glutSetCursor())?
1251 * XXX That is, why are we duplicating code, here, from
1252 * XXX glutSetCursor()? The WIN32 code should be able to just
1253 * XXX call glutSetCurdsor() instead of defining two macros
1254 * XXX and implementing a nested case in-line.
1257 /* Set the cursor AND change it for this window class. */
1258 #define MAP_CURSOR(a,b) \
1260 SetCursor( LoadCursor( NULL, b ) ); \
1263 /* Nuke the cursor AND change it for this window class. */
1264 #define ZAP_CURSOR(a,b) \
1266 SetCursor( NULL ); \
1269 if( LOWORD( lParam ) == HTCLIENT )
1270 switch( window->State.Cursor )
1272 MAP_CURSOR( GLUT_CURSOR_RIGHT_ARROW, IDC_ARROW );
1273 MAP_CURSOR( GLUT_CURSOR_LEFT_ARROW, IDC_ARROW );
1274 MAP_CURSOR( GLUT_CURSOR_INFO, IDC_HELP );
1275 MAP_CURSOR( GLUT_CURSOR_DESTROY, IDC_CROSS );
1276 MAP_CURSOR( GLUT_CURSOR_HELP, IDC_HELP );
1277 MAP_CURSOR( GLUT_CURSOR_CYCLE, IDC_SIZEALL );
1278 MAP_CURSOR( GLUT_CURSOR_SPRAY, IDC_CROSS );
1279 MAP_CURSOR( GLUT_CURSOR_WAIT, IDC_WAIT );
1280 MAP_CURSOR( GLUT_CURSOR_TEXT, IDC_UPARROW );
1281 MAP_CURSOR( GLUT_CURSOR_CROSSHAIR, IDC_CROSS );
1282 /* MAP_CURSOR( GLUT_CURSOR_NONE, IDC_NO ); */
1283 ZAP_CURSOR( GLUT_CURSOR_NONE, NULL );
1286 MAP_CURSOR( GLUT_CURSOR_UP_DOWN, IDC_ARROW );
1289 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1293 window->State.Visible = GL_TRUE;
1294 window->State.Redisplay = GL_TRUE;
1298 /* Turn on the visibility in case it was turned off somehow */
1299 window->State.Visible = GL_TRUE;
1300 BeginPaint( hWnd, &ps );
1301 fghRedrawWindowByHandle( hWnd );
1302 EndPaint( hWnd, &ps );
1307 * Make sure we don't close a window with current context active
1309 if( fgStructure.Window == window )
1314 wglMakeCurrent( NULL, NULL );
1316 * Step through the list of windows. If the rendering context
1317 * is not being used by another window, then we delete it.
1319 for( iter = (SFG_Window *)fgStructure.Windows.First;
1321 iter = (SFG_Window *)iter->Node.Next )
1323 if( ( iter->Window.Context == window->Window.Context ) &&
1324 ( iter != window ) )
1329 wglDeleteContext( window->Window.Context );
1333 * Put on a linked list of windows to be removed after all the
1334 * callbacks have returned
1336 fgAddToWindowDestroyList( window, GL_FALSE );
1337 DestroyWindow( hWnd );
1342 * The window already got destroyed, so don't bother with it.
1348 window->State.MouseX = LOWORD( lParam );
1349 window->State.MouseY = HIWORD( lParam );
1351 if ( window->ActiveMenu )
1353 window->State.Redisplay = GL_TRUE;
1354 fgSetWindow ( window->ActiveMenu->ParentWindow );
1358 fgState.Modifiers = fgGetWin32Modifiers( );
1360 if( ( wParam & MK_LBUTTON ) ||
1361 ( wParam & MK_MBUTTON ) ||
1362 ( wParam & MK_RBUTTON ) )
1363 INVOKE_WCB( *window, Motion, ( window->State.MouseX,
1364 window->State.MouseY ) );
1366 INVOKE_WCB( *window, Passive, ( window->State.MouseX,
1367 window->State.MouseY ) );
1369 fgState.Modifiers = 0xffffffff;
1373 case WM_LBUTTONDOWN:
1374 case WM_MBUTTONDOWN:
1375 case WM_RBUTTONDOWN:
1380 GLboolean pressed = GL_TRUE;
1383 window->State.MouseX = LOWORD( lParam );
1384 window->State.MouseY = HIWORD( lParam );
1388 case WM_LBUTTONDOWN:
1390 button = GLUT_LEFT_BUTTON;
1392 case WM_MBUTTONDOWN:
1394 button = GLUT_MIDDLE_BUTTON;
1396 case WM_RBUTTONDOWN:
1398 button = GLUT_RIGHT_BUTTON;
1402 button = GLUT_LEFT_BUTTON;
1406 button = GLUT_MIDDLE_BUTTON;
1410 button = GLUT_RIGHT_BUTTON;
1418 if( GetSystemMetrics( SM_SWAPBUTTON ) )
1419 if( button == GLUT_LEFT_BUTTON )
1420 button = GLUT_RIGHT_BUTTON;
1421 else if( button == GLUT_RIGHT_BUTTON )
1422 button = GLUT_LEFT_BUTTON;
1425 return DefWindowProc( hWnd, uMsg, lParam, wParam );
1428 * XXX This comment is duplicated in two other spots.
1429 * XXX Can we centralize it?
1431 * Do not execute the application's mouse callback if a
1432 * menu is hooked to this button.
1433 * In that case an appropriate private call should be generated.
1434 * Near as I can tell, this is the menu behaviour:
1435 * - Down-click the menu button, menu not active: activate
1436 * the menu with its upper left-hand corner at the mouse location.
1437 * - Down-click any button outside the menu, menu active:
1438 * deactivate the menu
1439 * - Down-click any button inside the menu, menu active:
1440 * select the menu entry and deactivate the menu
1441 * - Up-click the menu button, menu not active: nothing happens
1442 * - Up-click the menu button outside the menu, menu active:
1444 * - Up-click the menu button inside the menu, menu active:
1445 * select the menu entry and deactivate the menu
1447 /* Window has an active menu, it absorbs any mouse click */
1448 if( window->ActiveMenu )
1450 /* Outside the menu, deactivate the menu if it's a downclick */
1451 if( ! fgCheckActiveMenu( window, window->ActiveMenu ) )
1454 fgDeactivateMenu( window->ActiveMenu->ParentWindow );
1456 else /* In menu, invoke the callback and deactivate the menu*/
1459 * Save the current window and menu and set the current
1460 * window to the window whose menu this is
1462 SFG_Window *save_window = fgStructure.Window;
1463 SFG_Menu *save_menu = fgStructure.Menu;
1464 SFG_Window *parent_window = window->ActiveMenu->ParentWindow;
1465 fgSetWindow( parent_window );
1466 fgStructure.Menu = window->ActiveMenu;
1468 /* Execute the menu callback */
1469 fgExecuteMenuCallback( window->ActiveMenu );
1470 fgDeactivateMenu( parent_window );
1472 /* Restore the current window and menu */
1473 fgSetWindow( save_window );
1474 fgStructure.Menu = save_menu;
1478 * Let's make the window redraw as a result of the mouse
1479 * click and menu activity.
1481 if( ! window->IsMenu )
1482 window->State.Redisplay = GL_TRUE;
1487 if ( window->Menu[ button ] && pressed )
1489 window->State.Redisplay = GL_TRUE;
1490 fgSetWindow( window );
1491 fgActivateMenu( window, button );
1496 if( ! FETCH_WCB( *window, Mouse ) )
1499 fgSetWindow( window );
1500 fgState.Modifiers = fgGetWin32Modifiers( );
1505 pressed ? GLUT_DOWN : GLUT_UP,
1506 window->State.MouseX,
1507 window->State.MouseY
1511 fgState.Modifiers = 0xffffffff;
1516 /* Should be WM_MOUSEWHEEL but my compiler doesn't recognize it */
1519 * XXX THIS IS SPECULATIVE -- John Fay, 10/2/03
1520 * XXX Should use WHEEL_DELTA instead of 120
1522 int wheel_number = LOWORD( wParam );
1523 short ticks = ( short )HIWORD( wParam ) / 120;
1533 * The mouse cursor has moved. Remember the new mouse cursor's position
1535 /* window->State.MouseX = LOWORD( lParam ); */
1536 /* Need to adjust by window position, */
1537 /* window->State.MouseY = HIWORD( lParam ); */
1538 /* change "lParam" to other parameter */
1540 if( ! FETCH_WCB( *window, MouseWheel ) &&
1541 ! FETCH_WCB( *window, Mouse ) )
1544 fgSetWindow( window );
1545 fgState.Modifiers = fgGetWin32Modifiers( );
1548 if( FETCH_WCB( *window, MouseWheel ) )
1549 INVOKE_WCB( *window, MouseWheel,
1552 window->State.MouseX,
1553 window->State.MouseY
1556 else /* No mouse wheel, call the mouse button callback twice */
1559 * XXX The below assumes that you have no more than 3 mouse
1560 * XXX buttons. Sorry.
1562 int button = wheel_number*2 + 4;
1565 INVOKE_WCB( *window, Mouse,
1566 ( button, GLUT_DOWN,
1567 window->State.MouseX, window->State.MouseY )
1569 INVOKE_WCB( *window, Mouse,
1571 window->State.MouseX, window->State.MouseX )
1575 fgState.Modifiers = 0xffffffff;
1585 if( fgState.IgnoreKeyRepeat && (lParam & KF_REPEAT) )
1589 * Remember the current modifiers state. This is done here in order
1590 * to make sure the VK_DELETE keyboard callback is executed properly.
1592 fgState.Modifiers = fgGetWin32Modifiers( );
1594 GetCursorPos( &mouse_pos );
1595 ScreenToClient( window->Window.Handle, &mouse_pos );
1597 window->State.MouseX = mouse_pos.x;
1598 window->State.MouseY = mouse_pos.y;
1601 * Convert the Win32 keystroke codes to GLUTtish way
1603 # define KEY(a,b) case a: keypress = b; break;
1607 KEY( VK_F1, GLUT_KEY_F1 );
1608 KEY( VK_F2, GLUT_KEY_F2 );
1609 KEY( VK_F3, GLUT_KEY_F3 );
1610 KEY( VK_F4, GLUT_KEY_F4 );
1611 KEY( VK_F5, GLUT_KEY_F5 );
1612 KEY( VK_F6, GLUT_KEY_F6 );
1613 KEY( VK_F7, GLUT_KEY_F7 );
1614 KEY( VK_F8, GLUT_KEY_F8 );
1615 KEY( VK_F9, GLUT_KEY_F9 );
1616 KEY( VK_F10, GLUT_KEY_F10 );
1617 KEY( VK_F11, GLUT_KEY_F11 );
1618 KEY( VK_F12, GLUT_KEY_F12 );
1619 KEY( VK_PRIOR, GLUT_KEY_PAGE_UP );
1620 KEY( VK_NEXT, GLUT_KEY_PAGE_DOWN );
1621 KEY( VK_HOME, GLUT_KEY_HOME );
1622 KEY( VK_END, GLUT_KEY_END );
1623 KEY( VK_LEFT, GLUT_KEY_LEFT );
1624 KEY( VK_UP, GLUT_KEY_UP );
1625 KEY( VK_RIGHT, GLUT_KEY_RIGHT );
1626 KEY( VK_DOWN, GLUT_KEY_DOWN );
1627 KEY( VK_INSERT, GLUT_KEY_INSERT );
1631 * The delete key should be treated as an ASCII keypress:
1633 INVOKE_WCB( *window, Keyboard,
1634 ( 127, window->State.MouseX, window->State.MouseY )
1638 if( keypress != -1 )
1639 INVOKE_WCB( *window, Special,
1641 window->State.MouseX, window->State.MouseY )
1644 fgState.Modifiers = 0xffffffff;
1655 * Remember the current modifiers state. This is done here in order
1656 * to make sure the VK_DELETE keyboard callback is executed properly.
1658 fgState.Modifiers = fgGetWin32Modifiers( );
1660 GetCursorPos( &mouse_pos );
1661 ScreenToClient( window->Window.Handle, &mouse_pos );
1663 window->State.MouseX = mouse_pos.x;
1664 window->State.MouseY = mouse_pos.y;
1667 * Convert the Win32 keystroke codes to GLUTtish way.
1668 * "KEY(a,b)" was defined under "WM_KEYDOWN"
1673 KEY( VK_F1, GLUT_KEY_F1 );
1674 KEY( VK_F2, GLUT_KEY_F2 );
1675 KEY( VK_F3, GLUT_KEY_F3 );
1676 KEY( VK_F4, GLUT_KEY_F4 );
1677 KEY( VK_F5, GLUT_KEY_F5 );
1678 KEY( VK_F6, GLUT_KEY_F6 );
1679 KEY( VK_F7, GLUT_KEY_F7 );
1680 KEY( VK_F8, GLUT_KEY_F8 );
1681 KEY( VK_F9, GLUT_KEY_F9 );
1682 KEY( VK_F10, GLUT_KEY_F10 );
1683 KEY( VK_F11, GLUT_KEY_F11 );
1684 KEY( VK_F12, GLUT_KEY_F12 );
1685 KEY( VK_PRIOR, GLUT_KEY_PAGE_UP );
1686 KEY( VK_NEXT, GLUT_KEY_PAGE_DOWN );
1687 KEY( VK_HOME, GLUT_KEY_HOME );
1688 KEY( VK_END, GLUT_KEY_END );
1689 KEY( VK_LEFT, GLUT_KEY_LEFT );
1690 KEY( VK_UP, GLUT_KEY_UP );
1691 KEY( VK_RIGHT, GLUT_KEY_RIGHT );
1692 KEY( VK_DOWN, GLUT_KEY_DOWN );
1693 KEY( VK_INSERT, GLUT_KEY_INSERT );
1697 * The delete key should be treated as an ASCII keypress:
1699 INVOKE_WCB( *window, KeyboardUp,
1700 ( 127, window->State.MouseX, window->State.MouseY )
1709 GetKeyboardState( state );
1711 if( ToAscii( wParam, 0, state, code, 0 ) == 1 )
1714 INVOKE_WCB( *window, KeyboardUp,
1716 window->State.MouseX, window->State.MouseY )
1721 if( keypress != -1 )
1722 INVOKE_WCB( *window, SpecialUp,
1724 window->State.MouseX, window->State.MouseY )
1727 fgState.Modifiers = 0xffffffff;
1734 if( fgState.IgnoreKeyRepeat && (lParam & KF_REPEAT) )
1738 * XXX INVOKE_WCB() takes care of the callback-pointer check.
1739 * XXX We could just uncoditionally find/trash the Modifiers
1740 * XXX and get rid of the "if( ... ) {" and "}". Unconditinal
1741 * XXX code is simpler code. (^&
1743 if( FETCH_WCB( *window, Keyboard ) )
1745 fgState.Modifiers = fgGetWin32Modifiers( );
1746 INVOKE_WCB( *window, Keyboard,
1748 window->State.MouseX, window->State.MouseY )
1750 fgState.Modifiers = 0xffffffff;
1755 case WM_CAPTURECHANGED:
1756 /* User has finished resizing the window, force a redraw */
1757 INVOKE_WCB( *window, Display, ( ) );
1759 /*lRet = DefWindowProc( hWnd, uMsg, wParam, lParam ) ; */
1763 * Other messages that I have seen and which are not handled already
1765 case WM_SETTEXT: /* 0x000c */
1766 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1767 /* Pass it on to "DefWindowProc" to set the window text */
1770 case WM_GETTEXT: /* 0x000d */
1771 /* Ideally we would copy the title of the window into "lParam" */
1772 /* strncpy ( (char *)lParam, "Window Title", wParam );
1773 lRet = ( wParam > 12 ) ? 12 : wParam; */
1774 /* the number of characters copied */
1775 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1778 case WM_GETTEXTLENGTH: /* 0x000e */
1779 /* Ideally we would get the length of the title of the window */
1781 /* the number of characters in "Window Title\0" (see above) */
1784 case WM_ERASEBKGND: /* 0x0014 */
1785 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1788 case WM_SYNCPAINT: /* 0x0088 */
1789 /* Another window has moved, need to update this one */
1790 window->State.Redisplay = GL_TRUE;
1791 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1792 /* Help screen says this message must be passed to "DefWindowProc" */
1795 case WM_NCPAINT: /* 0x0085 */
1796 /* Need to update the border of this window */
1797 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1798 /* Pass it on to "DefWindowProc" to repaint a standard border */
1801 case WM_SYSCOMMAND : /* 0x0112 */
1804 * We have received a system command message. Try to act on it.
1805 * The commands are passed in through the "lParam" parameter:
1806 * Clicking on a corner to resize the window gives a "F004" message
1807 * but this is not defined in my header file.
1818 /* User has clicked on the "-" to minimize the window */
1819 /* Turn off the visibility */
1820 window->State.Visible = GL_FALSE ;
1827 case SC_NEXTWINDOW :
1830 case SC_PREVWINDOW :
1834 /* Followed very closely by a WM_CLOSE message */
1858 case SC_SCREENSAVE :
1866 /* We need to pass the message on to the operating system as well */
1867 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1872 * Handle unhandled messages
1874 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1882 /*** END OF FILE ***/