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 #define G_LOG_DOMAIN "freeglut-main"
34 #include "../include/GL/freeglut.h"
35 #include "freeglut_internal.h"
38 #if TARGET_HOST_UNIX_X11
39 #include <sys/types.h>
44 #elif TARGET_HOST_WIN32
48 #define MAX(a,b) (((a)>(b)) ? (a) : (b))
52 #define MIN(a,b) (((a)<(b)) ? (a) : (b))
57 * TODO BEFORE THE STABLE RELEASE:
59 * There are some issues concerning window redrawing under X11, and maybe
60 * some events are not handled. The Win32 version lacks some more features,
61 * but seems acceptable for not demanding purposes.
63 * Need to investigate why the X11 version breaks out with an error when
64 * closing a window (using the window manager, not glutDestroyWindow)...
67 /* -- PRIVATE FUNCTIONS ---------------------------------------------------- */
70 * Calls a window's redraw method. This is used when
71 * a redraw is forced by the incoming window messages.
73 static void fghRedrawWindowByHandle
74 #if TARGET_HOST_UNIX_X11
76 #elif TARGET_HOST_WIN32
80 SFG_Window* window = fgWindowByHandle( handle );
82 freeglut_return_if_fail( window != NULL );
83 freeglut_return_if_fail( window->Callbacks.Display != NULL );
84 freeglut_return_if_fail( window->State.Visible == TRUE );
85 fgSetWindow( window );
86 window->State.Redisplay = FALSE;
88 window->Callbacks.Display();
92 * Handle a window configuration change. When no reshape
93 * callback is hooked, the viewport size is updated to
94 * match the new window size.
96 static void fghReshapeWindowByHandle
97 #if TARGET_HOST_UNIX_X11
98 ( Window handle, int width, int height )
99 #elif TARGET_HOST_WIN32
100 ( HWND handle, int width, int height )
103 SFG_Window *current_window = fgStructure.Window ;
105 SFG_Window* window = fgWindowByHandle( handle );
106 freeglut_return_if_fail( window != NULL );
107 fgSetWindow( window );
108 if( window->Callbacks.Reshape != NULL )
109 window->Callbacks.Reshape( width, height );
111 glViewport( 0, 0, width, height );
114 * Force a window redraw. In Windows at least this is only a partial
115 * solution: if the window is increasing in size in either dimension,
116 * the already-drawn part does not get drawn again and things look funny.
117 * But without this we get this bad behaviour whenever we resize the
120 window->State.Redisplay = TRUE ;
122 if ( window->IsMenu )
123 fgSetWindow ( current_window ) ;
127 * A static helper function to execute display callback for a window
129 static void fghcbDisplayWindow( SFG_Window *window, SFG_Enumerator *enumerator )
131 #if TARGET_HOST_UNIX_X11
132 if( (window->Callbacks.Display != NULL) &&
133 (window->State.Redisplay == TRUE) &&
134 (window->State.Visible == TRUE) )
136 SFG_Window *current_window = fgStructure.Window ;
138 fgSetWindow( window );
139 window->State.Redisplay = FALSE;
140 window->Callbacks.Display();
141 fgSetWindow ( current_window ) ;
144 #elif TARGET_HOST_WIN32
146 if( window->State.NeedToResize )
148 SFG_Window *current_window = fgStructure.Window ;
150 fgSetWindow( window );
152 fghReshapeWindowByHandle(
153 window->Window.Handle,
154 glutGet( GLUT_WINDOW_WIDTH ),
155 glutGet( GLUT_WINDOW_HEIGHT )
158 window->State.NeedToResize = FALSE;
159 fgSetWindow ( current_window ) ;
162 if( (window->Callbacks.Display != NULL) &&
163 (window->State.Redisplay == TRUE) &&
164 (window->State.Visible == TRUE) )
166 window->State.Redisplay = FALSE;
168 window->Window.Handle, NULL, NULL,
169 RDW_NOERASE | RDW_INTERNALPAINT | RDW_INVALIDATE | RDW_UPDATENOW
175 fgEnumSubWindows( window, fghcbDisplayWindow, enumerator );
179 * Make all windows perform a display call
181 static void fghDisplayAll( void )
183 SFG_Enumerator enumerator;
185 enumerator.found = FALSE;
186 enumerator.data = NULL;
187 fgEnumWindows( fghcbDisplayWindow, &enumerator );
191 * Window enumerator callback to check for the joystick polling code
193 static void fghcbCheckJoystickPolls( SFG_Window *window, SFG_Enumerator *enumerator )
195 long int checkTime = fgElapsedTime();
197 if( window->State.JoystickLastPoll + window->State.JoystickPollRate <= checkTime )
199 fgJoystickPollWindow( window );
200 window->State.JoystickLastPoll = checkTime;
202 fgEnumSubWindows( window, fghcbCheckJoystickPolls, enumerator );
206 * Check all windows for joystick polling
208 static void fghCheckJoystickPolls( void )
210 SFG_Enumerator enumerator;
212 enumerator.found = FALSE;
213 enumerator.data = NULL;
214 fgEnumWindows( fghcbCheckJoystickPolls, &enumerator );
218 * Check the global timers
220 static void fghCheckTimers( void )
222 long checkTime = fgElapsedTime();
223 SFG_Timer *timer, *next;
226 fgListInit(&timedOut);
229 * For every timer that is waiting for triggering
231 for( timer = (SFG_Timer *)fgState.Timers.First;
233 timer = (SFG_Timer *)next )
235 next = (SFG_Timer *)timer->Node.Next;
236 if( timer->TriggerTime <= checkTime )
238 fgListRemove( &fgState.Timers, &timer->Node );
239 fgListAppend( &timedOut, &timer->Node );
244 * Now feel free to execute all the hooked and timed out timer callbacks
245 * And delete the timed out timers...
247 while ( (timer = (SFG_Timer *)timedOut.First) )
249 if( timer->Callback != NULL )
250 timer->Callback( timer->ID );
251 fgListRemove( &timedOut, &timer->Node );
260 long fgElapsedTime( void )
262 #if TARGET_HOST_UNIX_X11
266 gettimeofday( &now, NULL );
268 elapsed = (now.tv_usec - fgState.Time.Value.tv_usec) / 1000;
269 elapsed += (now.tv_sec - fgState.Time.Value.tv_sec) * 1000;
272 #elif TARGET_HOST_WIN32
273 return (timeGetTime() - fgState.Time.Value);
280 void fgError( const char *fmt, ... )
286 fprintf( stderr, "freeglut (%s): ", fgState.ProgramName || "");
287 vfprintf( stderr, fmt, ap );
288 fprintf( stderr, "\n" );
295 void fgWarning( const char *fmt, ... )
301 fprintf( stderr, "freeglut (%s): ", fgState.ProgramName || "");
302 vfprintf( stderr, fmt, ap );
303 fprintf( stderr, "\n" );
309 * Indicates whether Joystick events are being used by ANY window.
311 * The current mechanism is to walk all of the windows and ask if
312 * there is a joystick callback. Certainly in some cases, maybe
313 * in all cases, the joystick is attached to the system and accessed
314 * from ONE point by GLUT/freeglut, so this is not the right way,
315 * in general, to do this. However, the Joystick code is segregated
316 * in its own little world, so we can't access the information that
317 * we need in order to do that nicely.
320 * * Store Joystick data into freeglut global state.
321 * * Provide NON-static functions or data from Joystick *.c file.
323 * Basically, the RIGHT way to do this requires knowing something
324 * about the Joystick. Right now, the Joystick code is behind
328 static void fgCheckJoystickCallback( SFG_Window* w, SFG_Enumerator* e)
330 if( w->Callbacks.Joystick )
335 fgEnumSubWindows( w, fgCheckJoystickCallback, e );
337 static int fgHaveJoystick( void )
339 SFG_Enumerator enumerator;
340 enumerator.found = FALSE;
341 enumerator.data = NULL;
342 fgEnumWindows( fgCheckJoystickCallback, &enumerator );
343 return !!enumerator.data;
345 static void fgHavePendingRedisplaysCallback( SFG_Window* w, SFG_Enumerator* e)
347 if( w->State.Redisplay )
352 fgEnumSubWindows( w, fgHavePendingRedisplaysCallback, e );
354 static int fgHavePendingRedisplays (void)
356 SFG_Enumerator enumerator;
357 enumerator.found = FALSE;
358 enumerator.data = NULL;
359 fgEnumWindows( fgHavePendingRedisplaysCallback, &enumerator );
360 return !!enumerator.data;
363 * Indicates whether there are any outstanding timers.
365 static int fgHaveTimers( void )
367 return !!fgState.Timers.First;
370 * Returns the number of GLUT ticks (milliseconds) till the next timer event.
372 static long fgNextTimer( void )
374 long now = fgElapsedTime();
378 for( timer = (SFG_Timer *)fgState.Timers.First;
380 timer = (SFG_Timer *)timer->Node.Next )
381 ret = MIN( ret, MAX( 0, (timer->TriggerTime) - now ) );
386 * Does the magic required to relinquish the CPU until something interesting
389 static void fgSleepForEvents( void )
391 #if TARGET_HOST_UNIX_X11
398 if( fgState.IdleCallback ||
399 fgHavePendingRedisplays() )
401 socket = ConnectionNumber( fgDisplay.Display );
403 FD_SET( socket, &fdset );
405 msec = fgNextTimer();
406 if( fgHaveJoystick() )
407 msec = MIN( msec, 10 );
409 wait.tv_sec = msec / 1000;
410 wait.tv_usec = (msec % 1000) * 1000;
411 err = select( socket+1, &fdset, NULL, NULL, &wait );
414 printf( "freeglut select() error: %d\n", errno );
416 #elif TARGET_HOST_WIN32
420 /* -- INTERFACE FUNCTIONS -------------------------------------------------- */
423 * Executes a single iteration in the freeglut processing loop.
425 void FGAPIENTRY glutMainLoopEvent( void )
427 #if TARGET_HOST_UNIX_X11
433 * This code was repeated constantly, so here it goes into a definition:
435 # define GETWINDOW(a) \
436 window = fgWindowByHandle( event.a.window ); \
437 if( window == NULL ) \
439 # define GETMOUSE(a) \
440 window->State.MouseX = event.a.x; \
441 window->State.MouseY = event.a.y;
443 freeglut_assert_ready;
444 while( XPending( fgDisplay.Display ) )
446 XNextEvent( fgDisplay.Display, &event );
451 * This is sent to confirm the XDestroyWindow call.
454 * Call the window closure callback, remove from the structure, etc.
456 /* fgAddToWindowDestroyList ( window, FALSE ); */
462 * Destroy the window when the WM_DELETE_WINDOW message arrives
464 if( (Atom) event.xclient.data.l[ 0 ] == fgDisplay.DeleteWindow )
466 GETWINDOW( xclient );
469 * Call the XWindows functions to close the window
471 fgCloseWindow ( window ) ;
474 * Call the window closure callback, remove from the structure, etc.
476 fgAddToWindowDestroyList ( window, FALSE );
482 * A window of ours has been unmapped...
488 * We are too dumb to process partial exposes...
490 if( event.xexpose.count == 0 )
491 fghRedrawWindowByHandle( event.xexpose.window );
495 * CreateNotify causes a configure-event so that sub-windows are
496 * handled compatibly with GLUT.
498 * NOTE that it is possible that you will more than one Reshape
499 * event for your top-level window, but something like this appears
500 * to be required for compatbility.
502 * GLUT presumably does this because it generally tries to treat
503 * sub-windows the same as windows.
507 case ConfigureNotify:
509 * The window gets resized
511 fghReshapeWindowByHandle(
512 event.xconfigure.window,
513 event.xconfigure.width,
514 event.xconfigure.height
520 * Have the client's keyboard knowledge updated (xlib.ps,
521 * page 206, says that's a good thing to do)
523 XRefreshKeyboardMapping( (XMappingEvent *) &event );
526 case VisibilityNotify:
529 * The window's visiblity might have changed
531 GETWINDOW( xvisibility );
534 * Break now if no window status callback has been hooked to that window
536 if( window->Callbacks.WindowStatus == NULL )
540 * We're going to send a callback to a window. Make it current.
542 fgSetWindow( window );
545 * Sending this event, the X server can notify us that the window has just
546 * acquired one of the three possible visibility states: VisibilityUnobscured,
547 * VisibilityPartiallyObscured or VisibilityFullyObscured
549 switch( event.xvisibility.state )
551 case VisibilityUnobscured:
553 * We are fully visible...
555 window->Callbacks.WindowStatus( GLUT_FULLY_RETAINED );
556 window->State.Visible = TRUE;
559 case VisibilityPartiallyObscured:
561 * The window is partially visible
563 window->Callbacks.WindowStatus( GLUT_PARTIALLY_RETAINED );
564 window->State.Visible = TRUE;
567 case VisibilityFullyObscured:
569 * The window is totally obscured
571 window->Callbacks.WindowStatus( GLUT_FULLY_COVERED );
572 window->State.Visible = FALSE;
581 * Mouse is over one of our windows
583 GETWINDOW( xcrossing ); GETMOUSE( xcrossing );
586 * Is there an entry callback hooked to the window?
588 if( window->Callbacks.Entry != NULL )
591 * Set the current window
593 fgSetWindow ( window ) ;
596 * Yeah. Notify the window about having the mouse cursor over
598 window->Callbacks.Entry( GLUT_ENTERED );
606 * Mouse is no longer over one of our windows
608 GETWINDOW( xcrossing ); GETMOUSE( xcrossing );
611 * Is there an entry callback hooked to the window?
613 if( window->Callbacks.Entry != NULL )
616 * Set the current window
618 fgSetWindow ( window ) ;
621 * Yeah. Notify the window about having the mouse cursor over
623 window->Callbacks.Entry( GLUT_LEFT );
631 * The mouse cursor was moved...
633 GETWINDOW( xmotion ); GETMOUSE( xmotion );
636 * Fallback if there's an active menu hooked to this window
638 if( window->ActiveMenu != NULL )
640 if ( window == window->ActiveMenu->ParentWindow )
642 window->ActiveMenu->Window->State.MouseX = event.xmotion.x_root - window->ActiveMenu->X ;
643 window->ActiveMenu->Window->State.MouseY = event.xmotion.y_root - window->ActiveMenu->Y ;
647 * Let's make the window redraw as a result of the mouse motion.
649 window->ActiveMenu->Window->State.Redisplay = TRUE ;
652 * Since the window is a menu, make the parent window current
654 fgSetWindow ( window->ActiveMenu->ParentWindow ) ;
656 break; /* I think this should stay in -- an active menu should absorb the mouse motion */
660 * What kind of a movement was it?
662 if( (event.xmotion.state & Button1Mask) || (event.xmotion.state & Button2Mask) ||
663 (event.xmotion.state & Button3Mask) || (event.xmotion.state & Button4Mask) ||
664 (event.xmotion.state & Button5Mask) )
667 * A mouse button was pressed during the movement...
668 * Is there a motion callback hooked to the window?
670 if( window->Callbacks.Motion != NULL )
673 * Set the current window
675 fgSetWindow ( window ) ;
678 * Yup. Have it executed immediately
680 window->Callbacks.Motion( event.xmotion.x, event.xmotion.y );
686 * Otherwise it was a passive movement...
688 if( window->Callbacks.Passive != NULL )
691 * Set the current window
693 fgSetWindow ( window ) ;
696 * That's right, and there is a passive callback, too.
698 window->Callbacks.Passive( event.xmotion.x, event.xmotion.y );
707 GLboolean pressed = TRUE ;
710 if ( event.type == ButtonRelease ) pressed = FALSE ;
713 * A mouse button has been pressed or released. Traditionally,
714 * break if the window was found within the freeglut structures.
716 GETWINDOW( xbutton ); GETMOUSE( xbutton );
719 * An X button (at least in XFree86) is numbered from 1.
720 * A GLUT button is numbered from 0.
721 * Old GLUT passed through buttons other than just the first
722 * three, though it only gave symbolic names and official
723 * support to the first three.
726 button = event.xbutton.button - 1;
729 * Do not execute the application's mouse callback if a menu is hooked to this button.
730 * In that case an appropriate private call should be generated.
731 * Near as I can tell, this is the menu behaviour:
732 * - Down-click the menu button, menu not active: activate the menu with its upper left-hand corner at the mouse location.
733 * - Down-click any button outside the menu, menu active: deactivate the menu
734 * - Down-click any button inside the menu, menu active: select the menu entry and deactivate the menu
735 * - Up-click the menu button, menu not active: nothing happens
736 * - Up-click the menu button outside the menu, menu active: nothing happens
737 * - Up-click the menu button inside the menu, menu active: select the menu entry and deactivate the menu
739 if ( window->ActiveMenu != NULL ) /* Window has an active menu, it absorbs any mouse click */
741 if ( window == window->ActiveMenu->ParentWindow )
743 window->ActiveMenu->Window->State.MouseX = event.xbutton.x_root - window->ActiveMenu->X ;
744 window->ActiveMenu->Window->State.MouseY = event.xbutton.y_root - window->ActiveMenu->Y ;
747 if ( fgCheckActiveMenu ( window->ActiveMenu->Window, window->ActiveMenu ) == TRUE ) /* Inside the menu, invoke the callback and deactivate the menu*/
749 /* Save the current window and menu and set the current window to the window whose menu this is */
750 SFG_Window *save_window = fgStructure.Window ;
751 SFG_Menu *save_menu = fgStructure.Menu ;
752 SFG_Window *parent_window = window->ActiveMenu->ParentWindow ;
753 fgSetWindow ( parent_window ) ;
754 fgStructure.Menu = window->ActiveMenu ;
756 /* Execute the menu callback */
757 fgExecuteMenuCallback ( window->ActiveMenu ) ;
758 fgDeactivateMenu ( parent_window ) ;
760 /* Restore the current window and menu */
761 fgSetWindow ( save_window ) ;
762 fgStructure.Menu = save_menu ;
764 else /* Outside the menu, deactivate the menu if it's a downclick */
766 if ( pressed == TRUE ) fgDeactivateMenu ( window->ActiveMenu->ParentWindow ) ;
770 * Let's make the window redraw as a result of the mouse click and menu activity.
772 window->State.Redisplay = TRUE ;
778 * No active menu, let's check whether we need to activate one.
780 if (( 0 <= button ) && ( 2 >= button ) &&
781 ( window->Menu[ button ] != NULL ) && ( pressed == TRUE ) )
784 * Let's make the window redraw as a result of the mouse click.
786 window->State.Redisplay = TRUE ;
789 * Set the current window
791 fgSetWindow( window );
794 * Activate the appropriate menu structure...
796 fgActivateMenu( window, button );
802 * Check if there is a mouse callback hooked to the window
804 if( window->Callbacks.Mouse == NULL )
808 * Set the current window
810 fgSetWindow ( window );
813 * Remember the current modifiers state
816 if (event.xbutton.state & (ShiftMask|LockMask))
817 modifiers |= GLUT_ACTIVE_SHIFT;
818 if (event.xbutton.state & ControlMask)
819 modifiers |= GLUT_ACTIVE_CTRL;
820 if (event.xbutton.state & Mod1Mask)
821 modifiers |= GLUT_ACTIVE_ALT;
822 fgStructure.Window->State.Modifiers = modifiers;
825 * Finally execute the mouse callback
827 fgStructure.Window->Callbacks.Mouse(
829 event.type == ButtonPress ? GLUT_DOWN : GLUT_UP,
835 * Trash the modifiers state
837 fgStructure.Window->State.Modifiers = 0xffffffff;
844 FGCBkeyboard keyboard_cb;
845 FGCBspecial special_cb;
848 * A key has been pressed, find the window that had the focus:
850 GETWINDOW( xkey ); GETMOUSE( xkey );
852 if( event.type == KeyPress )
854 keyboard_cb = window->Callbacks.Keyboard;
855 special_cb = window->Callbacks.Special;
859 keyboard_cb = window->Callbacks.KeyboardUp;
860 special_cb = window->Callbacks.SpecialUp;
864 * Is there a keyboard/special callback hooked for this window?
866 if( (keyboard_cb != NULL) || (special_cb != NULL) )
868 XComposeStatus composeStatus;
869 char asciiCode[ 32 ];
874 * Check for the ASCII/KeySym codes associated with the event:
876 len = XLookupString( &event.xkey, asciiCode, sizeof(asciiCode), &keySym, &composeStatus );
879 * GLUT API tells us to have two separate callbacks...
884 * ...one for the ASCII translateable keypresses...
886 if( keyboard_cb != NULL )
889 * Set the current window
891 fgSetWindow( window );
894 * Remember the current modifiers state
897 if (event.xkey.state & (ShiftMask|LockMask))
898 modifiers |= GLUT_ACTIVE_SHIFT;
899 if (event.xkey.state & ControlMask)
900 modifiers |= GLUT_ACTIVE_CTRL;
901 if (event.xkey.state & Mod1Mask)
902 modifiers |= GLUT_ACTIVE_ALT;
903 window->State.Modifiers = modifiers;
906 * Execute the callback
908 keyboard_cb( asciiCode[ 0 ], event.xkey.x, event.xkey.y );
911 * Trash the modifiers state
913 window->State.Modifiers = 0xffffffff;
921 * ...and one for all the others, which need to be translated to GLUT_KEY_Xs...
926 * First the function keys come:
928 case XK_F1: special = GLUT_KEY_F1; break;
929 case XK_F2: special = GLUT_KEY_F2; break;
930 case XK_F3: special = GLUT_KEY_F3; break;
931 case XK_F4: special = GLUT_KEY_F4; break;
932 case XK_F5: special = GLUT_KEY_F5; break;
933 case XK_F6: special = GLUT_KEY_F6; break;
934 case XK_F7: special = GLUT_KEY_F7; break;
935 case XK_F8: special = GLUT_KEY_F8; break;
936 case XK_F9: special = GLUT_KEY_F9; break;
937 case XK_F10: special = GLUT_KEY_F10; break;
938 case XK_F11: special = GLUT_KEY_F11; break;
939 case XK_F12: special = GLUT_KEY_F12; break;
942 * Then the arrows and stuff:
944 case XK_Left: special = GLUT_KEY_LEFT; break;
945 case XK_Right: special = GLUT_KEY_RIGHT; break;
946 case XK_Up: special = GLUT_KEY_UP; break;
947 case XK_Down: special = GLUT_KEY_DOWN; break;
950 case XK_Prior: special = GLUT_KEY_PAGE_UP; break;
952 case XK_Next: special = GLUT_KEY_PAGE_DOWN; break;
954 case XK_Home: special = GLUT_KEY_HOME; break;
956 case XK_End: special = GLUT_KEY_END; break;
958 case XK_Insert: special = GLUT_KEY_INSERT; break;
962 * Execute the callback (if one has been specified),
963 * given that the special code seems to be valid...
965 if( (special_cb != NULL) && (special != -1) )
968 * Set the current window
970 fgSetWindow( window );
973 * Remember the current modifiers state
976 if (event.xkey.state & (ShiftMask|LockMask))
977 modifiers |= GLUT_ACTIVE_SHIFT;
978 if (event.xkey.state & ControlMask)
979 modifiers |= GLUT_ACTIVE_CTRL;
980 if (event.xkey.state & Mod1Mask)
981 modifiers |= GLUT_ACTIVE_ALT;
982 window->State.Modifiers = modifiers;
984 special_cb( special, event.xkey.x, event.xkey.y );
987 * Trash the modifiers state
989 window->State.Modifiers = 0xffffffff;
1000 * Have all the timers checked.
1005 * Poll the joystick and notify all windows that want to be notified...
1007 fghCheckJoystickPolls();
1010 * No messages in the queue, which means we are idling...
1012 if( fgState.IdleCallback != NULL )
1013 fgState.IdleCallback();
1016 * Remember about displaying all the windows that have
1017 * been marked for a redisplay (possibly in the idle call):
1022 #elif TARGET_HOST_WIN32
1027 * The windows processing is considerably smaller
1029 while( PeekMessage( &stMsg, NULL, 0, 0, PM_NOREMOVE ) )
1032 * Grab the message now, checking for WM_QUIT
1034 if( GetMessage( &stMsg, NULL, 0, 0 ) == 0 )
1035 fgState.ExecState = GLUT_EXEC_STATE_STOP ;
1038 * Translate virtual-key messages and send them to the window...
1040 TranslateMessage( &stMsg );
1041 DispatchMessage( &stMsg );
1046 * Have all the timers checked.
1051 * Poll the joystick and notify all windows that want to be notified...
1053 fghCheckJoystickPolls();
1056 * No messages in the queue, which means we are idling...
1058 if( fgState.IdleCallback != NULL )
1059 fgState.IdleCallback();
1062 * Remember about displaying all the windows that have
1063 * been marked for a redisplay (possibly in the idle call):
1070 * If an event caused a window to be closed, do the actual closing here
1076 * Enters the freeglut processing loop. Stays until the "ExecState" changes to "GLUT_EXEC_STATE_STOP".
1078 void FGAPIENTRY glutMainLoop( void )
1080 #if TARGET_HOST_WIN32
1081 SFG_Window *window = (SFG_Window *)fgStructure.Windows.First ;
1085 * Make sure the display has been created etc.
1087 freeglut_assert_ready;
1089 #if TARGET_HOST_WIN32
1091 * Processing before the main loop: If there is a window which is open and which
1092 * has a visibility callback, call it. I know this is an ugly hack, but I'm not sure
1093 * what else to do about it. Ideally we should leave something uninitialized in the
1094 * create window code and initialize it in the main loop, and have that initialization
1095 * create a "WM_ACTIVATE" message. Then we would put the visibility callback code in
1096 * the "case WM_ACTIVATE" block below. - John Fay -- 10/24/02
1098 while ( window != NULL )
1100 if ( window->Callbacks.Visibility != NULL )
1102 SFG_Window *current_window = fgStructure.Window ;
1105 * Set the current window
1107 fgSetWindow( window );
1109 window->Callbacks.Visibility ( window->State.Visible ) ;
1112 * Restore the current window
1114 fgSetWindow( current_window );
1117 window = (SFG_Window *)window->Node.Next ;
1122 * Set freeglut to be running
1124 fgState.ExecState = GLUT_EXEC_STATE_RUNNING ;
1127 * Enter the main loop itself. Inside the loop, process events and check for loop exit.
1129 while ( fgState.ExecState == GLUT_EXEC_STATE_RUNNING )
1131 glutMainLoopEvent () ;
1134 * If there are no more windows open, stop execution
1136 if ( fgStructure.Windows.First == NULL )
1137 fgState.ExecState = GLUT_EXEC_STATE_STOP ;
1143 fgExecutionState execState = fgState.ActionOnWindowClose;
1146 * When this loop terminates, destroy the display, state and structure
1147 * of a freeglut session, so that another glutInit() call can happen
1152 * Check whether we return to the calling program or simply exit
1154 if ( execState == GLUT_ACTION_EXIT )
1160 * Leaves the freeglut processing loop.
1162 void FGAPIENTRY glutLeaveMainLoop( void )
1164 fgState.ExecState = GLUT_EXEC_STATE_STOP ;
1168 * The window procedure for handling Win32 events
1170 #if TARGET_HOST_WIN32
1171 LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
1173 SFG_Window* window = fgWindowByHandle( hWnd );
1177 if ( ( window == NULL ) && ( uMsg != WM_CREATE ) )
1178 return( DefWindowProc( hWnd, uMsg, wParam, lParam ) );
1180 /* printf ( "Window %3d message <%04x> %12d %12d\n", window?window->ID:0, uMsg, wParam, lParam ) ; */
1182 * Check what type of message are we receiving
1188 * The window structure is passed as the creation structure paramter...
1190 window = (SFG_Window *) (((LPCREATESTRUCT) lParam)->lpCreateParams);
1191 assert( window != NULL );
1194 * We can safely store the window's handle now:
1196 window->Window.Handle = hWnd;
1199 * Get the window's device context
1201 window->Window.Device = GetDC( hWnd );
1204 * Create or get the OpenGL rendering context now
1206 if ( fgState.BuildingAMenu )
1209 * Setup the pixel format of our window
1211 unsigned int current_DisplayMode = fgState.DisplayMode ;
1212 fgState.DisplayMode = GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH ;
1213 fgSetupPixelFormat( window, FALSE, PFD_MAIN_PLANE );
1214 fgState.DisplayMode = current_DisplayMode ;
1217 * If there isn't already an OpenGL rendering context for menu windows, make one
1219 if ( !fgStructure.MenuContext )
1221 fgStructure.MenuContext = (SFG_MenuContext *)malloc ( sizeof(SFG_MenuContext) ) ;
1222 fgStructure.MenuContext->Context = wglCreateContext( window->Window.Device );
1225 wglMakeCurrent ( window->Window.Device, fgStructure.MenuContext->Context ) ;
1227 /* window->Window.Context = wglGetCurrentContext () ; */
1228 window->Window.Context = wglCreateContext( window->Window.Device );
1233 * Setup the pixel format of our window
1235 fgSetupPixelFormat( window, FALSE, PFD_MAIN_PLANE );
1237 if ( fgState.UseCurrentContext == TRUE )
1239 window->Window.Context = wglGetCurrentContext();
1240 if ( ! window->Window.Context )
1241 window->Window.Context = wglCreateContext( window->Window.Device );
1244 window->Window.Context = wglCreateContext( window->Window.Device );
1248 * Still, we'll be needing to explicitly resize the window
1250 window->State.NeedToResize = TRUE;
1253 * Finally, have the window's device context released
1255 ReleaseDC( window->Window.Handle, window->Window.Device );
1260 * We got resized... But check if the window has been already added...
1262 fghReshapeWindowByHandle( hWnd, LOWORD(lParam), HIWORD(lParam) );
1266 printf("WM_SETFOCUS: %p\n", window );
1267 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1271 if (LOWORD(wParam) != WA_INACTIVE)
1273 /* glutSetCursor( fgStructure.Window->State.Cursor ); */
1274 printf("WM_ACTIVATE: glutSetCursor( %p, %d)\n", window, window->State.Cursor );
1276 glutSetCursor( window->State.Cursor );
1279 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1285 * Windows seems to need reminding to erase the cursor for NONE.
1288 if ((LOWORD(lParam) == HTCLIENT) &&
1289 (fgStructure.Window->State.Cursor == GLUT_CURSOR_NONE))
1292 /* Set the cursor AND change it for this window class. */
1293 # define MAP_CURSOR(a,b) case a: SetCursor( LoadCursor( NULL, b ) ); \
1295 /* Nuke the cursor AND change it for this window class. */
1296 # define ZAP_CURSOR(a,b) case a: SetCursor( NULL ); \
1299 if (LOWORD(lParam) == HTCLIENT)
1300 switch( window->State.Cursor )
1302 MAP_CURSOR( GLUT_CURSOR_RIGHT_ARROW, IDC_ARROW );
1303 MAP_CURSOR( GLUT_CURSOR_LEFT_ARROW, IDC_ARROW );
1304 MAP_CURSOR( GLUT_CURSOR_INFO, IDC_HELP );
1305 MAP_CURSOR( GLUT_CURSOR_DESTROY, IDC_CROSS );
1306 MAP_CURSOR( GLUT_CURSOR_HELP, IDC_HELP );
1307 MAP_CURSOR( GLUT_CURSOR_CYCLE, IDC_SIZEALL );
1308 MAP_CURSOR( GLUT_CURSOR_SPRAY, IDC_CROSS );
1309 MAP_CURSOR( GLUT_CURSOR_WAIT, IDC_WAIT );
1310 MAP_CURSOR( GLUT_CURSOR_TEXT, IDC_UPARROW );
1311 MAP_CURSOR( GLUT_CURSOR_CROSSHAIR, IDC_CROSS );
1312 /* MAP_CURSOR( GLUT_CURSOR_NONE, IDC_NO ); */
1313 ZAP_CURSOR( GLUT_CURSOR_NONE, NULL );
1316 MAP_CURSOR( GLUT_CURSOR_UP_DOWN, IDC_ARROW );
1320 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1325 * We are now Visible!
1327 window->State.Visible = TRUE;
1328 window->State.Redisplay = TRUE;
1333 * Start the painting job
1336 BeginPaint( hWnd, &ps );
1339 * Call the engine's main frame drawing method
1341 fghRedrawWindowByHandle( hWnd );
1344 * End the painting job, release the device context
1346 EndPaint( hWnd, &ps );
1351 * Make sure we don't close a window with current context active
1353 if( fgStructure.Window == window )
1358 wglMakeCurrent( NULL, NULL );
1359 /* Step through the list of windows. If the rendering context is notbeing used
1360 * by another window, then we delete it.
1362 for ( iter = (SFG_Window *)fgStructure.Windows.First; iter; iter = (SFG_Window *)iter->Node.Next )
1364 if ( ( iter->Window.Context == window->Window.Context ) && ( iter != window ) )
1368 if ( used == FALSE ) wglDeleteContext( window->Window.Context );
1372 * Put on a linked list of windows to be removed after all the callbacks have returned
1374 fgAddToWindowDestroyList ( window, FALSE ) ;
1377 * Proceed with the window destruction
1379 DestroyWindow( hWnd );
1384 * The window already got destroyed, so don't bother with it.
1391 * The mouse cursor has moved. Remember the new mouse cursor's position
1393 window->State.MouseX = LOWORD( lParam );
1394 window->State.MouseY = HIWORD( lParam );
1397 * Fallback if there's an active menu hooked to this window
1399 if ( window->ActiveMenu != NULL )
1402 * Let's make the window redraw as a result of the mouse motion.
1404 window->State.Redisplay = TRUE ;
1407 * Since the window is a menu, make the parent window current
1409 fgSetWindow ( window->ActiveMenu->ParentWindow ) ;
1415 * Remember the current modifiers state.
1417 window->State.Modifiers =
1418 ( ( (GetKeyState( VK_LSHIFT ) < 0 ) || ( GetKeyState( VK_RSHIFT ) < 0 )) ? GLUT_ACTIVE_SHIFT : 0 ) |
1419 ( ( (GetKeyState( VK_LCONTROL ) < 0 ) || ( GetKeyState( VK_RCONTROL ) < 0 )) ? GLUT_ACTIVE_CTRL : 0 ) |
1420 ( ( (GetKeyState( VK_LMENU ) < 0 ) || ( GetKeyState( VK_RMENU ) < 0 )) ? GLUT_ACTIVE_ALT : 0 );
1423 * Check if any of the mouse buttons is pressed...
1425 if( (wParam & MK_LBUTTON) || (wParam & MK_MBUTTON) || (wParam & MK_RBUTTON) )
1428 * Yeah, indeed. We need to use the motion callback then:
1430 if( window->Callbacks.Motion != NULL )
1433 * Make sure the current window is set...
1435 fgSetWindow( window );
1438 * Execute the active mouse motion callback now
1440 window->Callbacks.Motion( window->State.MouseX, window->State.MouseY );
1446 * All mouse buttons are up, execute the passive mouse motion callback
1448 if( window->Callbacks.Passive != NULL )
1451 * Make sure the current window is set
1453 fgSetWindow( window );
1456 * Execute the passive mouse motion callback
1458 window->Callbacks.Passive( window->State.MouseX, window->State.MouseY );
1463 * Thrash the current modifiers state now
1465 window->State.Modifiers = 0xffffffff;
1469 case WM_LBUTTONDOWN:
1470 case WM_MBUTTONDOWN:
1471 case WM_RBUTTONDOWN:
1476 GLboolean pressed = TRUE;
1480 * The mouse cursor has moved. Remember the new mouse cursor's position
1482 window->State.MouseX = LOWORD( lParam );
1483 window->State.MouseY = HIWORD( lParam );
1486 * We're curious about the GLUT API button name...
1490 case WM_LBUTTONDOWN: pressed = TRUE; button = GLUT_LEFT_BUTTON; break;
1491 case WM_MBUTTONDOWN: pressed = TRUE; button = GLUT_MIDDLE_BUTTON; break;
1492 case WM_RBUTTONDOWN: pressed = TRUE; button = GLUT_RIGHT_BUTTON; break;
1493 case WM_LBUTTONUP: pressed = FALSE; button = GLUT_LEFT_BUTTON; break;
1494 case WM_MBUTTONUP: pressed = FALSE; button = GLUT_MIDDLE_BUTTON; break;
1495 case WM_RBUTTONUP: pressed = FALSE; button = GLUT_RIGHT_BUTTON; break;
1496 default: pressed = FALSE; button = -1; break;
1500 * The left and right mouse buttons might have been swapped...
1502 if( GetSystemMetrics( SM_SWAPBUTTON ) )
1503 if( button == GLUT_LEFT_BUTTON ) button = GLUT_RIGHT_BUTTON;
1504 else if( button == GLUT_RIGHT_BUTTON ) button = GLUT_LEFT_BUTTON;
1507 * Hey, what's up with you?
1510 return( DefWindowProc( hWnd, uMsg, lParam, wParam ) );
1513 * Do not execute the application's mouse callback if a menu is hooked to this button.
1514 * In that case an appropriate private call should be generated.
1515 * Near as I can tell, this is the menu behaviour:
1516 * - Down-click the menu button, menu not active: activate the menu with its upper left-hand corner at the mouse location.
1517 * - Down-click any button outside the menu, menu active: deactivate the menu
1518 * - Down-click any button inside the menu, menu active: select the menu entry and deactivate the menu
1519 * - Up-click the menu button, menu not active: nothing happens
1520 * - Up-click the menu button outside the menu, menu active: nothing happens
1521 * - Up-click the menu button inside the menu, menu active: select the menu entry and deactivate the menu
1523 if ( window->ActiveMenu != NULL ) /* Window has an active menu, it absorbs any mouse click */
1525 if ( fgCheckActiveMenu ( window, window->ActiveMenu ) == TRUE ) /* Inside the menu, invoke the callback and deactivate the menu*/
1527 /* Save the current window and menu and set the current window to the window whose menu this is */
1528 SFG_Window *save_window = fgStructure.Window ;
1529 SFG_Menu *save_menu = fgStructure.Menu ;
1530 SFG_Window *parent_window = window->ActiveMenu->ParentWindow ;
1531 fgSetWindow ( parent_window ) ;
1532 fgStructure.Menu = window->ActiveMenu ;
1534 /* Execute the menu callback */
1535 fgExecuteMenuCallback ( window->ActiveMenu ) ;
1536 fgDeactivateMenu ( parent_window ) ;
1538 /* Restore the current window and menu */
1539 fgSetWindow ( save_window ) ;
1540 fgStructure.Menu = save_menu ;
1542 else /* Outside the menu, deactivate the menu if it's a downclick */
1544 if ( pressed == TRUE ) fgDeactivateMenu ( window->ActiveMenu->ParentWindow ) ;
1548 * Let's make the window redraw as a result of the mouse click and menu activity.
1550 if ( ! window->IsMenu ) window->State.Redisplay = TRUE ;
1556 * No active menu, let's check whether we need to activate one.
1558 if ( ( window->Menu[ button ] != NULL ) && ( pressed == TRUE ) )
1561 * Let's make the window redraw as a result of the mouse click.
1563 window->State.Redisplay = TRUE ;
1566 * Set the current window
1568 fgSetWindow( window );
1571 * Activate the appropriate menu structure...
1573 fgActivateMenu( window, button );
1579 * Check if there is a mouse callback hooked to the window
1581 if( window->Callbacks.Mouse == NULL )
1585 * Set the current window
1587 fgSetWindow ( window );
1590 * Remember the current modifiers state.
1592 fgStructure.Window->State.Modifiers =
1593 ( ( (GetKeyState( VK_LSHIFT ) < 0 ) || ( GetKeyState( VK_RSHIFT ) < 0 )) ? GLUT_ACTIVE_SHIFT : 0 ) |
1594 ( ( (GetKeyState( VK_LCONTROL ) < 0 ) || ( GetKeyState( VK_RCONTROL ) < 0 )) ? GLUT_ACTIVE_CTRL : 0 ) |
1595 ( ( (GetKeyState( VK_LMENU ) < 0 ) || ( GetKeyState( VK_RMENU ) < 0 )) ? GLUT_ACTIVE_ALT : 0 );
1598 * Finally execute the mouse callback
1600 window->Callbacks.Mouse(
1602 pressed == TRUE ? GLUT_DOWN : GLUT_UP,
1603 window->State.MouseX,
1604 window->State.MouseY
1608 * Trash the modifiers state
1610 fgStructure.Window->State.Modifiers = 0xffffffff;
1621 * Ignore the automatic key repetition if needed:
1623 if( fgState.IgnoreKeyRepeat && (lParam & KF_REPEAT) )
1627 * Remember the current modifiers state. This is done here in order
1628 * to make sure the VK_DELETE keyboard callback is executed properly.
1630 window->State.Modifiers =
1631 ( ( (GetKeyState( VK_LSHIFT ) < 0 ) || ( GetKeyState( VK_RSHIFT ) < 0 )) ? GLUT_ACTIVE_SHIFT : 0 ) |
1632 ( ( (GetKeyState( VK_LCONTROL ) < 0 ) || ( GetKeyState( VK_RCONTROL ) < 0 )) ? GLUT_ACTIVE_CTRL : 0 ) |
1633 ( ( (GetKeyState( VK_LMENU ) < 0 ) || ( GetKeyState( VK_RMENU ) < 0 )) ? GLUT_ACTIVE_ALT : 0 );
1636 * Set the mouse position
1638 GetCursorPos ( &mouse_pos ) ;
1639 ScreenToClient ( window->Window.Handle, &mouse_pos ) ;
1641 window->State.MouseX = mouse_pos.x ;
1642 window->State.MouseY = mouse_pos.y ;
1645 * Convert the Win32 keystroke codes to GLUTtish way
1647 # define KEY(a,b) case a: keypress = b; break;
1652 * Most of the special characters can be handled automagically...
1654 KEY( VK_F1, GLUT_KEY_F1 ); KEY( VK_F2, GLUT_KEY_F2 );
1655 KEY( VK_F3, GLUT_KEY_F3 ); KEY( VK_F4, GLUT_KEY_F4 );
1656 KEY( VK_F5, GLUT_KEY_F5 ); KEY( VK_F6, GLUT_KEY_F6 );
1657 KEY( VK_F7, GLUT_KEY_F7 ); KEY( VK_F8, GLUT_KEY_F8 );
1658 KEY( VK_F9, GLUT_KEY_F9 ); KEY( VK_F10, GLUT_KEY_F10 );
1659 KEY( VK_F11, GLUT_KEY_F11 ); KEY( VK_F12, GLUT_KEY_F12 );
1660 KEY( VK_PRIOR, GLUT_KEY_PAGE_UP ); KEY( VK_NEXT, GLUT_KEY_PAGE_DOWN );
1661 KEY( VK_HOME, GLUT_KEY_HOME ); KEY( VK_END, GLUT_KEY_END );
1662 KEY( VK_LEFT, GLUT_KEY_LEFT ); KEY( VK_UP, GLUT_KEY_UP );
1663 KEY( VK_RIGHT, GLUT_KEY_RIGHT ); KEY( VK_DOWN, GLUT_KEY_DOWN );
1664 KEY( VK_INSERT, GLUT_KEY_INSERT );
1667 * ...yet there is a small exception we need to have handled...
1671 * The delete key should be treated as an ASCII keypress:
1673 if( window->Callbacks.Keyboard != NULL )
1675 fgSetWindow( window );
1676 window->Callbacks.Keyboard( 127, window->State.MouseX, window->State.MouseY );
1681 * Execute the special callback, if present, given the conversion was a success:
1683 if( (keypress != -1) && (window->Callbacks.Special != NULL) )
1686 * Set the current window
1688 fgSetWindow( window );
1691 * Have the special callback executed:
1693 window->Callbacks.Special( keypress, window->State.MouseX, window->State.MouseY );
1697 * Thrash the modifiers register now
1699 window->State.Modifiers = 0xffffffff;
1710 * Remember the current modifiers state. This is done here in order
1711 * to make sure the VK_DELETE keyboard callback is executed properly.
1713 window->State.Modifiers =
1714 ( ( (GetKeyState( VK_LSHIFT ) < 0 ) || ( GetKeyState( VK_RSHIFT ) < 0 )) ? GLUT_ACTIVE_SHIFT : 0 ) |
1715 ( ( (GetKeyState( VK_LCONTROL ) < 0 ) || ( GetKeyState( VK_RCONTROL ) < 0 )) ? GLUT_ACTIVE_CTRL : 0 ) |
1716 ( ( (GetKeyState( VK_LMENU ) < 0 ) || ( GetKeyState( VK_RMENU ) < 0 )) ? GLUT_ACTIVE_ALT : 0 );
1719 * Set the mouse position
1721 GetCursorPos ( &mouse_pos ) ;
1722 ScreenToClient ( window->Window.Handle, &mouse_pos ) ;
1724 window->State.MouseX = mouse_pos.x ;
1725 window->State.MouseY = mouse_pos.y ;
1728 * Convert the Win32 keystroke codes to GLUTtish way. "KEY(a,b)" was defined under "WM_KEYDOWN"
1734 * Most of the special characters can be handled automagically...
1736 KEY( VK_F1, GLUT_KEY_F1 ); KEY( VK_F2, GLUT_KEY_F2 );
1737 KEY( VK_F3, GLUT_KEY_F3 ); KEY( VK_F4, GLUT_KEY_F4 );
1738 KEY( VK_F5, GLUT_KEY_F5 ); KEY( VK_F6, GLUT_KEY_F6 );
1739 KEY( VK_F7, GLUT_KEY_F7 ); KEY( VK_F8, GLUT_KEY_F8 );
1740 KEY( VK_F9, GLUT_KEY_F9 ); KEY( VK_F10, GLUT_KEY_F10 );
1741 KEY( VK_F11, GLUT_KEY_F11 ); KEY( VK_F12, GLUT_KEY_F12 );
1742 KEY( VK_PRIOR, GLUT_KEY_PAGE_UP ); KEY( VK_NEXT, GLUT_KEY_PAGE_DOWN );
1743 KEY( VK_HOME, GLUT_KEY_HOME ); KEY( VK_END, GLUT_KEY_END );
1744 KEY( VK_LEFT, GLUT_KEY_LEFT ); KEY( VK_UP, GLUT_KEY_UP );
1745 KEY( VK_RIGHT, GLUT_KEY_RIGHT ); KEY( VK_DOWN, GLUT_KEY_DOWN );
1746 KEY( VK_INSERT, GLUT_KEY_INSERT );
1749 * ...yet there is a small exception we need to have handled...
1753 * The delete key should be treated as an ASCII keypress:
1755 if( window->Callbacks.KeyboardUp != NULL )
1757 fgSetWindow ( window ) ;
1758 window->Callbacks.KeyboardUp( 127, window->State.MouseX, window->State.MouseY );
1765 * Call the KeyboardUp callback for a regular character if there is one.
1770 GetKeyboardState(state);
1772 if ( ToAscii( wParam, 0, state, code, 0 ) == 1 )
1775 if( window->Callbacks.KeyboardUp != NULL )
1778 * Set the current window
1780 fgSetWindow( window );
1782 window->Callbacks.KeyboardUp( (char)wParam, window->State.MouseX, window->State.MouseY );
1788 * Execute the special callback, if present, given the conversion was a success:
1790 if( (keypress != -1) && (window->Callbacks.SpecialUp != NULL) )
1793 * Set the current window
1795 fgSetWindow( window );
1798 * Have the special callback executed:
1800 window->Callbacks.SpecialUp( keypress, window->State.MouseX, window->State.MouseY );
1804 * Thrash the modifiers register now
1806 window->State.Modifiers = 0xffffffff;
1814 * Ignore the automatic key repetition if needed:
1816 if( fgState.IgnoreKeyRepeat && (lParam & KF_REPEAT) )
1820 * Clear to go with the keyboard callback, if registered:
1822 if( window->Callbacks.Keyboard != NULL )
1825 * Set the current window
1827 fgSetWindow( window );
1830 * Remember the current modifiers state
1832 window->State.Modifiers =
1833 ( ( (GetKeyState( VK_LSHIFT ) < 0 ) || ( GetKeyState( VK_RSHIFT ) < 0 )) ? GLUT_ACTIVE_SHIFT : 0 ) |
1834 ( ( (GetKeyState( VK_LCONTROL ) < 0 ) || ( GetKeyState( VK_RCONTROL ) < 0 )) ? GLUT_ACTIVE_CTRL : 0 ) |
1835 ( ( (GetKeyState( VK_LMENU ) < 0 ) || ( GetKeyState( VK_RMENU ) < 0 )) ? GLUT_ACTIVE_ALT : 0 );
1838 * Have the special callback executed:
1840 window->Callbacks.Keyboard( (char)wParam, window->State.MouseX, window->State.MouseY );
1843 * Thrash the modifiers register now
1845 window->State.Modifiers = 0xffffffff;
1850 case WM_CAPTURECHANGED : /* User has finished resizing the window, force a redraw */
1851 if ( window->Callbacks.Display )
1854 * Set the current window
1856 fgSetWindow( window );
1858 window->Callbacks.Display () ;
1861 /* lRet = DefWindowProc( hWnd, uMsg, wParam, lParam ) ; */
1865 * Other messages that I have seen and which are not handled already
1867 case WM_SETTEXT : /* 0x000c */
1868 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam ); /* Pass it on to "DefWindowProc" to set the window text */
1871 case WM_GETTEXT : /* 0x000d */
1872 /* Ideally we would copy the title of the window into "lParam" */
1873 /* strncpy ( (char *)lParam, "Window Title", wParam ) ;
1874 lRet = ( wParam > 12 ) ? 12 : wParam ; */ /* the number of characters copied */
1875 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1878 case WM_GETTEXTLENGTH : /* 0x000e */
1879 /* Ideally we would get the length of the title of the window */
1880 lRet = 12 ; /* the number of characters in "Window Title\0" (see above) */
1883 case WM_ERASEBKGND : /* 0x0014 */
1884 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1887 case WM_SYNCPAINT : /* 0x0088 */
1888 /* Another window has moved, need to update this one */
1889 window->State.Redisplay = TRUE ;
1890 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam ); /* Help screen says this message must be passed to "DefWindowProc" */
1893 case WM_NCPAINT : /* 0x0085 */
1894 /* Need to update the border of this window */
1895 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam ); /* Pass it on to "DefWindowProc" to repaint a standard border */
1900 * Handle unhandled messages
1902 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1910 /*** END OF FILE ***/