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.
74 static void fghRedrawWindowByHandle
75 #if TARGET_HOST_UNIX_X11
77 #elif TARGET_HOST_WIN32
82 * Find the window we have to redraw...
84 SFG_Window* window = fgWindowByHandle( handle );
85 freeglut_return_if_fail( window != NULL );
88 * Check if there is a display callback hooked to it
90 freeglut_return_if_fail( window->Callbacks.Display != NULL );
93 * Return if the window is not visible
95 freeglut_return_if_fail( window->State.Visible == TRUE );
98 * Set the window as the current one.
100 fgSetWindow( window );
103 * Do not exagerate with the redisplaying
105 window->State.Redisplay = FALSE;
108 * Have the callback executed now. The buffers should
109 * be swapped by the glutSwapBuffers() execution inside
110 * the callback itself.
113 window->Callbacks.Display();
117 * Handle a window configuration change. When no reshape
118 * callback is hooked, the viewport size is updated to
119 * match the new window size.
121 static void fghReshapeWindowByHandle
122 #if TARGET_HOST_UNIX_X11
123 ( Window handle, int width, int height )
124 #elif TARGET_HOST_WIN32
125 ( HWND handle, int width, int height )
128 SFG_Window *current_window = fgStructure.Window ;
131 * Find the window that received the reshape event
133 SFG_Window* window = fgWindowByHandle( handle );
134 freeglut_return_if_fail( window != NULL );
137 * Remember about setting the current window...
139 fgSetWindow( window );
142 * Check if there is a reshape callback hooked
144 if( window->Callbacks.Reshape != NULL )
147 * OKi, have it called immediately
149 window->Callbacks.Reshape( width, height );
154 * Otherwise just resize the viewport
156 glViewport( 0, 0, width, height );
160 * Force a window redraw. In Windows at least this is only a partial solution: if the
161 * window is increasing in size in either dimension, the already-drawn part does not get
162 * drawn again and things look funny. But without this we get this bad behaviour whenever
163 * we resize the window.
165 window->State.Redisplay = TRUE ;
168 * If this is a menu, restore the active window
170 if ( window->IsMenu )
171 fgSetWindow ( current_window ) ;
175 * A static helper function to execute display callback for a window
177 static void fghcbDisplayWindow( SFG_Window *window, SFG_Enumerator *enumerator )
179 #if TARGET_HOST_UNIX_X11
181 * Check if there is an idle callback hooked
183 if( (window->Callbacks.Display != NULL) &&
184 (window->State.Redisplay == TRUE) &&
185 (window->State.Visible == TRUE) )
187 SFG_Window *current_window = fgStructure.Window ;
190 * OKi, this is the case: have the window set as the current one
192 fgSetWindow( window );
195 * Do not exagerate with the redisplaying
197 window->State.Redisplay = FALSE;
200 * And execute the display callback immediately after
202 window->Callbacks.Display();
204 fgSetWindow ( current_window ) ;
207 #elif TARGET_HOST_WIN32
210 * Do we need to explicitly resize the window?
212 if( window->State.NeedToResize )
214 SFG_Window *current_window = fgStructure.Window ;
216 fgSetWindow( window );
218 fghReshapeWindowByHandle(
219 window->Window.Handle,
220 glutGet( GLUT_WINDOW_WIDTH ),
221 glutGet( GLUT_WINDOW_HEIGHT )
225 * Never ever do that again:
227 window->State.NeedToResize = FALSE;
229 fgSetWindow ( current_window ) ;
233 * This is done in a bit different way under Windows
235 if( (window->Callbacks.Display != NULL) &&
236 (window->State.Redisplay == TRUE) &&
237 (window->State.Visible == TRUE) )
240 * Do not exagerate with the redisplaying
242 window->State.Redisplay = FALSE;
245 window->Window.Handle, NULL, NULL,
246 RDW_NOERASE | RDW_INTERNALPAINT | RDW_INVALIDATE | RDW_UPDATENOW
253 * Process this window's children (if any)
255 fgEnumSubWindows( window, fghcbDisplayWindow, enumerator );
259 * Make all windows perform a display call
261 static void fghDisplayAll( void )
263 SFG_Enumerator enumerator;
266 * Uses a method very similiar for fgWindowByHandle...
268 enumerator.found = FALSE;
269 enumerator.data = NULL;
272 * Start the enumeration now:
274 fgEnumWindows( fghcbDisplayWindow, &enumerator );
278 * Window enumerator callback to check for the joystick polling code
280 static void fghcbCheckJoystickPolls( SFG_Window *window, SFG_Enumerator *enumerator )
282 long int checkTime = fgElapsedTime();
285 * Check if actually need to do the poll for the currently enumerated window:
287 if( window->State.JoystickLastPoll + window->State.JoystickPollRate <= checkTime )
290 * Yeah, that's it. Poll the joystick...
292 fgJoystickPollWindow( window );
295 * ...and reset the polling counters:
297 window->State.JoystickLastPoll = checkTime;
301 * Process this window's children (if any)
303 fgEnumSubWindows( window, fghcbCheckJoystickPolls, enumerator );
307 * Check all windows for joystick polling
309 static void fghCheckJoystickPolls( void )
311 SFG_Enumerator enumerator;
314 * Uses a method very similiar for fgWindowByHandle...
316 enumerator.found = FALSE;
317 enumerator.data = NULL;
320 * Start the enumeration now:
322 fgEnumWindows( fghcbCheckJoystickPolls, &enumerator );
326 * Check the global timers
328 static void fghCheckTimers( void )
330 long checkTime = fgElapsedTime();
331 SFG_Timer *timer, *next;
334 fgListInit(&timedOut);
337 * For every timer that is waiting for triggering
339 for( timer = (SFG_Timer *)fgState.Timers.First; timer; timer = (SFG_Timer *)next )
341 next = (SFG_Timer *)timer->Node.Next;
344 * Check for the timeout:
346 if( timer->TriggerTime <= checkTime )
349 * Add the timer to the timed out timers list
351 fgListRemove( &fgState.Timers, &timer->Node );
352 fgListAppend( &timedOut, &timer->Node );
357 * Now feel free to execute all the hooked and timed out timer callbacks
358 * And delete the timed out timers...
360 while ( (timer = (SFG_Timer *)timedOut.First) )
362 if( timer->Callback != NULL )
363 timer->Callback( timer->ID );
364 fgListRemove( &timedOut, &timer->Node );
373 long fgElapsedTime( void )
375 #if TARGET_HOST_UNIX_X11
379 gettimeofday( &now, NULL );
381 elapsed = (now.tv_usec - fgState.Time.Value.tv_usec) / 1000;
382 elapsed += (now.tv_sec - fgState.Time.Value.tv_sec) * 1000;
385 #elif TARGET_HOST_WIN32
386 return (timeGetTime() - fgState.Time.Value);
393 void fgError( const char *fmt, ... )
399 fprintf( stderr, "freeglut: ");
400 vfprintf( stderr, fmt, ap );
401 fprintf( stderr, "\n" );
408 void fgWarning( const char *fmt, ... )
414 fprintf( stderr, "freeglut: ");
415 vfprintf( stderr, fmt, ap );
416 fprintf( stderr, "\n" );
422 * Indicates whether Joystick events are being used by ANY window.
424 * The current mechanism is to walk all of the windows and ask if
425 * there is a joystick callback. Certainly in some cases, maybe
426 * in all cases, the joystick is attached to the system and accessed
427 * from ONE point by GLUT/freeglut, so this is not the right way,
428 * in general, to do this. However, the Joystick code is segregated
429 * in its own little world, so we can't access the information that
430 * we need in order to do that nicely.
433 * * Store Joystick data into freeglut global state.
434 * * Provide NON-static functions or data from Joystick *.c file.
436 * Basically, the RIGHT way to do this requires knowing something
437 * about the Joystick. Right now, the Joystick code is behind
441 static void fgCheckJoystickCallback( SFG_Window* w, SFG_Enumerator* e)
443 if( w->Callbacks.Joystick )
448 fgEnumSubWindows( w, fgCheckJoystickCallback, e );
450 static int fgHaveJoystick( void )
452 SFG_Enumerator enumerator;
453 enumerator.found = FALSE;
454 enumerator.data = NULL;
455 fgEnumWindows( fgCheckJoystickCallback, &enumerator );
456 return !!enumerator.data;
458 static void fgHavePendingRedisplaysCallback( SFG_Window* w, SFG_Enumerator* e)
460 if( w->State.Redisplay )
465 fgEnumSubWindows( w, fgHavePendingRedisplaysCallback, e );
467 static int fgHavePendingRedisplays (void)
469 SFG_Enumerator enumerator;
470 enumerator.found = FALSE;
471 enumerator.data = NULL;
472 fgEnumWindows( fgHavePendingRedisplaysCallback, &enumerator );
473 return !!enumerator.data;
476 * Indicates whether there are any outstanding timers.
478 static int fgHaveTimers( void )
480 return !!fgState.Timers.First;
483 * Returns the number of GLUT ticks (milliseconds) till the next timer event.
485 static long fgNextTimer( void )
487 long now = fgElapsedTime();
491 for( timer = (SFG_Timer *)fgState.Timers.First;
493 timer = (SFG_Timer *)timer->Node.Next )
494 ret = MIN( ret, MAX( 0, (timer->TriggerTime) - now ) );
499 * Does the magic required to relinquish the CPU until something interesting
502 static void fgSleepForEvents( void )
504 #if TARGET_HOST_UNIX_X11
511 if( fgState.IdleCallback ||
512 fgHavePendingRedisplays() )
514 socket = ConnectionNumber( fgDisplay.Display );
516 FD_SET( socket, &fdset );
518 msec = fgNextTimer();
519 if( fgHaveJoystick() )
520 msec = MIN( msec, 10 );
522 wait.tv_sec = msec / 1000;
523 wait.tv_usec = (msec % 1000) * 1000;
524 err = select( socket+1, &fdset, NULL, NULL, &wait );
527 printf( "freeglut select() error: %d\n", errno );
529 #elif TARGET_HOST_WIN32
533 /* -- INTERFACE FUNCTIONS -------------------------------------------------- */
536 * Executes a single iteration in the freeglut processing loop.
538 void FGAPIENTRY glutMainLoopEvent( void )
540 #if TARGET_HOST_UNIX_X11
546 * This code was repeated constantly, so here it goes into a definition:
548 # define GETWINDOW(a) window = fgWindowByHandle( event.a.window );if( window == NULL ) break;
549 # define GETMOUSE(a) window->State.MouseX = event.a.x; window->State.MouseY = event.a.y;
552 * Make sure the display has been created etc.
554 freeglut_assert_ready;
557 * Do we have any event messages pending?
559 while( XPending( fgDisplay.Display ) )
562 * Grab the next event to be processed...
564 XNextEvent( fgDisplay.Display, &event );
567 * Check the event's type
573 * The window creation confirmation
579 * This is sent to confirm the XDestroyWindow call.
582 * Call the window closure callback, remove from the structure, etc.
584 /* fgAddToWindowDestroyList ( window, FALSE ); */
590 * Destroy the window when the WM_DELETE_WINDOW message arrives
592 if( (Atom) event.xclient.data.l[ 0 ] == fgDisplay.DeleteWindow )
594 GETWINDOW( xclient );
597 * Call the XWindows functions to close the window
599 fgCloseWindow ( window ) ;
602 * Call the window closure callback, remove from the structure, etc.
604 fgAddToWindowDestroyList ( window, FALSE );
610 * A window of ours has been unmapped...
616 * We are too dumb to process partial exposes...
618 if( event.xexpose.count == 0 )
619 fghRedrawWindowByHandle( event.xexpose.window );
622 case ConfigureNotify:
624 * The window gets resized
626 fghReshapeWindowByHandle(
627 event.xconfigure.window,
628 event.xconfigure.width,
629 event.xconfigure.height
635 * Have the client's keyboard knowledge updated (xlib.ps,
636 * page 206, says that's a good thing to do)
638 XRefreshKeyboardMapping( (XMappingEvent *) &event );
641 case VisibilityNotify:
644 * The window's visiblity might have changed
646 GETWINDOW( xvisibility );
649 * Break now if no window status callback has been hooked to that window
651 if( window->Callbacks.WindowStatus == NULL )
655 * We're going to send a callback to a window. Make it current.
657 fgSetWindow( window );
660 * Sending this event, the X server can notify us that the window has just
661 * acquired one of the three possible visibility states: VisibilityUnobscured,
662 * VisibilityPartiallyObscured or VisibilityFullyObscured
664 switch( event.xvisibility.state )
666 case VisibilityUnobscured:
668 * We are fully visible...
670 window->Callbacks.WindowStatus( GLUT_FULLY_RETAINED );
671 window->State.Visible = TRUE;
674 case VisibilityPartiallyObscured:
676 * The window is partially visible
678 window->Callbacks.WindowStatus( GLUT_PARTIALLY_RETAINED );
679 window->State.Visible = TRUE;
682 case VisibilityFullyObscured:
684 * The window is totally obscured
686 window->Callbacks.WindowStatus( GLUT_FULLY_COVERED );
687 window->State.Visible = FALSE;
696 * Mouse is over one of our windows
698 GETWINDOW( xcrossing ); GETMOUSE( xcrossing );
701 * Is there an entry callback hooked to the window?
703 if( window->Callbacks.Entry != NULL )
706 * Set the current window
708 fgSetWindow ( window ) ;
711 * Yeah. Notify the window about having the mouse cursor over
713 window->Callbacks.Entry( GLUT_ENTERED );
721 * Mouse is no longer over one of our windows
723 GETWINDOW( xcrossing ); GETMOUSE( xcrossing );
726 * Is there an entry callback hooked to the window?
728 if( window->Callbacks.Entry != NULL )
731 * Set the current window
733 fgSetWindow ( window ) ;
736 * Yeah. Notify the window about having the mouse cursor over
738 window->Callbacks.Entry( GLUT_LEFT );
746 * The mouse cursor was moved...
748 GETWINDOW( xmotion ); GETMOUSE( xmotion );
751 * Fallback if there's an active menu hooked to this window
753 if( window->ActiveMenu != NULL )
755 if ( window == window->ActiveMenu->ParentWindow )
757 window->ActiveMenu->Window->State.MouseX = event.xmotion.x_root - window->ActiveMenu->X ;
758 window->ActiveMenu->Window->State.MouseY = event.xmotion.y_root - window->ActiveMenu->Y ;
762 * Let's make the window redraw as a result of the mouse motion.
764 window->ActiveMenu->Window->State.Redisplay = TRUE ;
767 * Since the window is a menu, make the parent window current
769 fgSetWindow ( window->ActiveMenu->ParentWindow ) ;
771 break; /* I think this should stay in -- an active menu should absorb the mouse motion */
775 * What kind of a movement was it?
777 if( (event.xmotion.state & Button1Mask) || (event.xmotion.state & Button2Mask) ||
778 (event.xmotion.state & Button3Mask) || (event.xmotion.state & Button4Mask) ||
779 (event.xmotion.state & Button5Mask) )
782 * A mouse button was pressed during the movement...
783 * Is there a motion callback hooked to the window?
785 if( window->Callbacks.Motion != NULL )
788 * Set the current window
790 fgSetWindow ( window ) ;
793 * Yup. Have it executed immediately
795 window->Callbacks.Motion( event.xmotion.x, event.xmotion.y );
801 * Otherwise it was a passive movement...
803 if( window->Callbacks.Passive != NULL )
806 * Set the current window
808 fgSetWindow ( window ) ;
811 * That's right, and there is a passive callback, too.
813 window->Callbacks.Passive( event.xmotion.x, event.xmotion.y );
822 GLboolean pressed = TRUE ;
825 if ( event.type == ButtonRelease ) pressed = FALSE ;
828 * A mouse button has been pressed or released. Traditionally,
829 * break if the window was found within the freeglut structures.
831 GETWINDOW( xbutton ); GETMOUSE( xbutton );
834 * An X button (at least in XFree86) is numbered from 1.
835 * A GLUT button is numbered from 0.
836 * Old GLUT passed through buttons other than just the first
837 * three, though it only gave symbolic names and official
838 * support to the first three.
841 button = event.xbutton.button - 1;
844 * Do not execute the application's mouse callback if a menu is hooked to this button.
845 * In that case an appropriate private call should be generated.
846 * Near as I can tell, this is the menu behaviour:
847 * - Down-click the menu button, menu not active: activate the menu with its upper left-hand corner at the mouse location.
848 * - Down-click any button outside the menu, menu active: deactivate the menu
849 * - Down-click any button inside the menu, menu active: select the menu entry and deactivate the menu
850 * - Up-click the menu button, menu not active: nothing happens
851 * - Up-click the menu button outside the menu, menu active: nothing happens
852 * - Up-click the menu button inside the menu, menu active: select the menu entry and deactivate the menu
854 if ( window->ActiveMenu != NULL ) /* Window has an active menu, it absorbs any mouse click */
856 if ( window == window->ActiveMenu->ParentWindow )
858 window->ActiveMenu->Window->State.MouseX = event.xbutton.x_root - window->ActiveMenu->X ;
859 window->ActiveMenu->Window->State.MouseY = event.xbutton.y_root - window->ActiveMenu->Y ;
862 if ( fgCheckActiveMenu ( window->ActiveMenu->Window, window->ActiveMenu ) == TRUE ) /* Inside the menu, invoke the callback and deactivate the menu*/
864 /* Save the current window and menu and set the current window to the window whose menu this is */
865 SFG_Window *save_window = fgStructure.Window ;
866 SFG_Menu *save_menu = fgStructure.Menu ;
867 SFG_Window *parent_window = window->ActiveMenu->ParentWindow ;
868 fgSetWindow ( parent_window ) ;
869 fgStructure.Menu = window->ActiveMenu ;
871 /* Execute the menu callback */
872 fgExecuteMenuCallback ( window->ActiveMenu ) ;
873 fgDeactivateMenu ( parent_window ) ;
875 /* Restore the current window and menu */
876 fgSetWindow ( save_window ) ;
877 fgStructure.Menu = save_menu ;
879 else /* Outside the menu, deactivate the menu if it's a downclick */
881 if ( pressed == TRUE ) fgDeactivateMenu ( window->ActiveMenu->ParentWindow ) ;
885 * Let's make the window redraw as a result of the mouse click and menu activity.
887 window->State.Redisplay = TRUE ;
893 * No active menu, let's check whether we need to activate one.
895 if (( 0 <= button ) && ( 2 >= button ) &&
896 ( window->Menu[ button ] != NULL ) && ( pressed == TRUE ) )
899 * Let's make the window redraw as a result of the mouse click.
901 window->State.Redisplay = TRUE ;
904 * Set the current window
906 fgSetWindow( window );
909 * Activate the appropriate menu structure...
911 fgActivateMenu( window, button );
917 * Check if there is a mouse callback hooked to the window
919 if( window->Callbacks.Mouse == NULL )
923 * Set the current window
925 fgSetWindow ( window );
928 * Remember the current modifiers state
931 if (event.xbutton.state & (ShiftMask|LockMask))
932 modifiers |= GLUT_ACTIVE_SHIFT;
933 if (event.xbutton.state & ControlMask)
934 modifiers |= GLUT_ACTIVE_CTRL;
935 if (event.xbutton.state & Mod1Mask)
936 modifiers |= GLUT_ACTIVE_ALT;
937 fgStructure.Window->State.Modifiers = modifiers;
940 * Finally execute the mouse callback
942 fgStructure.Window->Callbacks.Mouse(
944 event.type == ButtonPress ? GLUT_DOWN : GLUT_UP,
950 * Trash the modifiers state
952 fgStructure.Window->State.Modifiers = 0xffffffff;
959 FGCBkeyboard keyboard_cb;
960 FGCBspecial special_cb;
963 * A key has been pressed, find the window that had the focus:
965 GETWINDOW( xkey ); GETMOUSE( xkey );
967 if( event.type == KeyPress )
969 keyboard_cb = window->Callbacks.Keyboard;
970 special_cb = window->Callbacks.Special;
974 keyboard_cb = window->Callbacks.KeyboardUp;
975 special_cb = window->Callbacks.SpecialUp;
979 * Is there a keyboard/special callback hooked for this window?
981 if( (keyboard_cb != NULL) || (special_cb != NULL) )
983 XComposeStatus composeStatus;
984 char asciiCode[ 32 ];
989 * Check for the ASCII/KeySym codes associated with the event:
991 len = XLookupString( &event.xkey, asciiCode, sizeof(asciiCode), &keySym, &composeStatus );
994 * GLUT API tells us to have two separate callbacks...
999 * ...one for the ASCII translateable keypresses...
1001 if( keyboard_cb != NULL )
1004 * Set the current window
1006 fgSetWindow( window );
1009 * Remember the current modifiers state
1012 if (event.xkey.state & (ShiftMask|LockMask))
1013 modifiers |= GLUT_ACTIVE_SHIFT;
1014 if (event.xkey.state & ControlMask)
1015 modifiers |= GLUT_ACTIVE_CTRL;
1016 if (event.xkey.state & Mod1Mask)
1017 modifiers |= GLUT_ACTIVE_ALT;
1018 window->State.Modifiers = modifiers;
1021 * Execute the callback
1023 keyboard_cb( asciiCode[ 0 ], event.xkey.x, event.xkey.y );
1026 * Trash the modifiers state
1028 window->State.Modifiers = 0xffffffff;
1036 * ...and one for all the others, which need to be translated to GLUT_KEY_Xs...
1041 * First the function keys come:
1043 case XK_F1: special = GLUT_KEY_F1; break;
1044 case XK_F2: special = GLUT_KEY_F2; break;
1045 case XK_F3: special = GLUT_KEY_F3; break;
1046 case XK_F4: special = GLUT_KEY_F4; break;
1047 case XK_F5: special = GLUT_KEY_F5; break;
1048 case XK_F6: special = GLUT_KEY_F6; break;
1049 case XK_F7: special = GLUT_KEY_F7; break;
1050 case XK_F8: special = GLUT_KEY_F8; break;
1051 case XK_F9: special = GLUT_KEY_F9; break;
1052 case XK_F10: special = GLUT_KEY_F10; break;
1053 case XK_F11: special = GLUT_KEY_F11; break;
1054 case XK_F12: special = GLUT_KEY_F12; break;
1057 * Then the arrows and stuff:
1059 case XK_Left: special = GLUT_KEY_LEFT; break;
1060 case XK_Right: special = GLUT_KEY_RIGHT; break;
1061 case XK_Up: special = GLUT_KEY_UP; break;
1062 case XK_Down: special = GLUT_KEY_DOWN; break;
1065 case XK_Prior: special = GLUT_KEY_PAGE_UP; break;
1067 case XK_Next: special = GLUT_KEY_PAGE_DOWN; break;
1069 case XK_Home: special = GLUT_KEY_HOME; break;
1071 case XK_End: special = GLUT_KEY_END; break;
1073 case XK_Insert: special = GLUT_KEY_INSERT; break;
1077 * Execute the callback (if one has been specified),
1078 * given that the special code seems to be valid...
1080 if( (special_cb != NULL) && (special != -1) )
1083 * Set the current window
1085 fgSetWindow( window );
1088 * Remember the current modifiers state
1091 if (event.xkey.state & (ShiftMask|LockMask))
1092 modifiers |= GLUT_ACTIVE_SHIFT;
1093 if (event.xkey.state & ControlMask)
1094 modifiers |= GLUT_ACTIVE_CTRL;
1095 if (event.xkey.state & Mod1Mask)
1096 modifiers |= GLUT_ACTIVE_ALT;
1097 window->State.Modifiers = modifiers;
1099 special_cb( special, event.xkey.x, event.xkey.y );
1102 * Trash the modifiers state
1104 window->State.Modifiers = 0xffffffff;
1115 * Have all the timers checked.
1120 * Poll the joystick and notify all windows that want to be notified...
1122 fghCheckJoystickPolls();
1125 * No messages in the queue, which means we are idling...
1127 if( fgState.IdleCallback != NULL )
1128 fgState.IdleCallback();
1131 * Remember about displaying all the windows that have
1132 * been marked for a redisplay (possibly in the idle call):
1137 #elif TARGET_HOST_WIN32
1142 * The windows processing is considerably smaller
1144 while( PeekMessage( &stMsg, NULL, 0, 0, PM_NOREMOVE ) )
1147 * Grab the message now, checking for WM_QUIT
1149 if( GetMessage( &stMsg, NULL, 0, 0 ) == 0 )
1150 fgState.ExecState = GLUT_EXEC_STATE_STOP ;
1153 * Translate virtual-key messages and send them to the window...
1155 TranslateMessage( &stMsg );
1156 DispatchMessage( &stMsg );
1161 * Have all the timers checked.
1166 * Poll the joystick and notify all windows that want to be notified...
1168 fghCheckJoystickPolls();
1171 * No messages in the queue, which means we are idling...
1173 if( fgState.IdleCallback != NULL )
1174 fgState.IdleCallback();
1177 * Remember about displaying all the windows that have
1178 * been marked for a redisplay (possibly in the idle call):
1185 * If an event caused a window to be closed, do the actual closing here
1191 * Enters the freeglut processing loop. Stays until the "ExecState" changes to "GLUT_EXEC_STATE_STOP".
1193 void FGAPIENTRY glutMainLoop( void )
1195 #if TARGET_HOST_WIN32
1196 SFG_Window *window = (SFG_Window *)fgStructure.Windows.First ;
1200 * Make sure the display has been created etc.
1202 freeglut_assert_ready;
1204 #if TARGET_HOST_WIN32
1206 * Processing before the main loop: If there is a window which is open and which
1207 * has a visibility callback, call it. I know this is an ugly hack, but I'm not sure
1208 * what else to do about it. Ideally we should leave something uninitialized in the
1209 * create window code and initialize it in the main loop, and have that initialization
1210 * create a "WM_ACTIVATE" message. Then we would put the visibility callback code in
1211 * the "case WM_ACTIVATE" block below. - John Fay -- 10/24/02
1213 while ( window != NULL )
1215 if ( window->Callbacks.Visibility != NULL )
1217 SFG_Window *current_window = fgStructure.Window ;
1220 * Set the current window
1222 fgSetWindow( window );
1224 window->Callbacks.Visibility ( window->State.Visible ) ;
1227 * Restore the current window
1229 fgSetWindow( current_window );
1232 window = (SFG_Window *)window->Node.Next ;
1237 * Set freeglut to be running
1239 fgState.ExecState = GLUT_EXEC_STATE_RUNNING ;
1242 * Enter the main loop itself. Inside the loop, process events and check for loop exit.
1244 while ( fgState.ExecState == GLUT_EXEC_STATE_RUNNING )
1246 glutMainLoopEvent () ;
1249 * If there are no more windows open, stop execution
1251 if ( fgStructure.Windows.First == NULL )
1252 fgState.ExecState = GLUT_EXEC_STATE_STOP ;
1258 fgExecutionState execState = fgState.ActionOnWindowClose;
1261 * When this loop terminates, destroy the display, state and structure
1262 * of a freeglut session, so that another glutInit() call can happen
1267 * Check whether we return to the calling program or simply exit
1269 if ( execState == GLUT_ACTION_EXIT )
1275 * Leaves the freeglut processing loop.
1277 void FGAPIENTRY glutLeaveMainLoop( void )
1279 fgState.ExecState = GLUT_EXEC_STATE_STOP ;
1283 * The window procedure for handling Win32 events
1285 #if TARGET_HOST_WIN32
1286 LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
1288 SFG_Window* window = fgWindowByHandle( hWnd );
1292 if ( ( window == NULL ) && ( uMsg != WM_CREATE ) )
1293 return( DefWindowProc( hWnd, uMsg, wParam, lParam ) );
1295 /* printf ( "Window %3d message <%04x> %12d %12d\n", window?window->ID:0, uMsg, wParam, lParam ) ; */
1297 * Check what type of message are we receiving
1303 * The window structure is passed as the creation structure paramter...
1305 window = (SFG_Window *) (((LPCREATESTRUCT) lParam)->lpCreateParams);
1306 assert( window != NULL );
1309 * We can safely store the window's handle now:
1311 window->Window.Handle = hWnd;
1314 * Get the window's device context
1316 window->Window.Device = GetDC( hWnd );
1319 * Create or get the OpenGL rendering context now
1321 if ( fgState.BuildingAMenu )
1324 * Setup the pixel format of our window
1326 unsigned int current_DisplayMode = fgState.DisplayMode ;
1327 fgState.DisplayMode = GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH ;
1328 fgSetupPixelFormat( window, FALSE, PFD_MAIN_PLANE );
1329 fgState.DisplayMode = current_DisplayMode ;
1332 * If there isn't already an OpenGL rendering context for menu windows, make one
1334 if ( !fgStructure.MenuContext )
1336 fgStructure.MenuContext = (SFG_MenuContext *)malloc ( sizeof(SFG_MenuContext) ) ;
1337 fgStructure.MenuContext->Context = wglCreateContext( window->Window.Device );
1340 wglMakeCurrent ( window->Window.Device, fgStructure.MenuContext->Context ) ;
1342 /* window->Window.Context = wglGetCurrentContext () ; */
1343 window->Window.Context = wglCreateContext( window->Window.Device );
1348 * Setup the pixel format of our window
1350 fgSetupPixelFormat( window, FALSE, PFD_MAIN_PLANE );
1352 if ( fgState.UseCurrentContext == TRUE )
1354 window->Window.Context = wglGetCurrentContext();
1355 if ( ! window->Window.Context )
1356 window->Window.Context = wglCreateContext( window->Window.Device );
1359 window->Window.Context = wglCreateContext( window->Window.Device );
1363 * Still, we'll be needing to explicitly resize the window
1365 window->State.NeedToResize = TRUE;
1368 * Finally, have the window's device context released
1370 ReleaseDC( window->Window.Handle, window->Window.Device );
1375 * We got resized... But check if the window has been already added...
1377 fghReshapeWindowByHandle( hWnd, LOWORD(lParam), HIWORD(lParam) );
1381 printf("WM_SETFOCUS: %p\n", window );
1382 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1386 if (LOWORD(wParam) != WA_INACTIVE)
1388 /* glutSetCursor( fgStructure.Window->State.Cursor ); */
1389 printf("WM_ACTIVATE: glutSetCursor( %p, %d)\n", window, window->State.Cursor );
1391 glutSetCursor( window->State.Cursor );
1394 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1400 * Windows seems to need reminding to erase the cursor for NONE.
1403 if ((LOWORD(lParam) == HTCLIENT) &&
1404 (fgStructure.Window->State.Cursor == GLUT_CURSOR_NONE))
1407 /* Set the cursor AND change it for this window class. */
1408 # define MAP_CURSOR(a,b) case a: SetCursor( LoadCursor( NULL, b ) ); \
1410 /* Nuke the cursor AND change it for this window class. */
1411 # define ZAP_CURSOR(a,b) case a: SetCursor( NULL ); \
1414 if (LOWORD(lParam) == HTCLIENT)
1415 switch( window->State.Cursor )
1417 MAP_CURSOR( GLUT_CURSOR_RIGHT_ARROW, IDC_ARROW );
1418 MAP_CURSOR( GLUT_CURSOR_LEFT_ARROW, IDC_ARROW );
1419 MAP_CURSOR( GLUT_CURSOR_INFO, IDC_HELP );
1420 MAP_CURSOR( GLUT_CURSOR_DESTROY, IDC_CROSS );
1421 MAP_CURSOR( GLUT_CURSOR_HELP, IDC_HELP );
1422 MAP_CURSOR( GLUT_CURSOR_CYCLE, IDC_SIZEALL );
1423 MAP_CURSOR( GLUT_CURSOR_SPRAY, IDC_CROSS );
1424 MAP_CURSOR( GLUT_CURSOR_WAIT, IDC_WAIT );
1425 MAP_CURSOR( GLUT_CURSOR_TEXT, IDC_UPARROW );
1426 MAP_CURSOR( GLUT_CURSOR_CROSSHAIR, IDC_CROSS );
1427 /* MAP_CURSOR( GLUT_CURSOR_NONE, IDC_NO ); */
1428 ZAP_CURSOR( GLUT_CURSOR_NONE, NULL );
1431 MAP_CURSOR( GLUT_CURSOR_UP_DOWN, IDC_ARROW );
1435 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1440 * We are now Visible!
1442 window->State.Visible = TRUE;
1443 window->State.Redisplay = TRUE;
1448 * Start the painting job
1451 BeginPaint( hWnd, &ps );
1454 * Call the engine's main frame drawing method
1456 fghRedrawWindowByHandle( hWnd );
1459 * End the painting job, release the device context
1461 EndPaint( hWnd, &ps );
1466 * Make sure we don't close a window with current context active
1468 if( fgStructure.Window == window )
1473 wglMakeCurrent( NULL, NULL );
1474 /* Step through the list of windows. If the rendering context is notbeing used
1475 * by another window, then we delete it.
1477 for ( iter = (SFG_Window *)fgStructure.Windows.First; iter; iter = (SFG_Window *)iter->Node.Next )
1479 if ( ( iter->Window.Context == window->Window.Context ) && ( iter != window ) )
1483 if ( used == FALSE ) wglDeleteContext( window->Window.Context );
1487 * Put on a linked list of windows to be removed after all the callbacks have returned
1489 fgAddToWindowDestroyList ( window, FALSE ) ;
1492 * Proceed with the window destruction
1494 DestroyWindow( hWnd );
1499 * The window already got destroyed, so don't bother with it.
1506 * The mouse cursor has moved. Remember the new mouse cursor's position
1508 window->State.MouseX = LOWORD( lParam );
1509 window->State.MouseY = HIWORD( lParam );
1512 * Fallback if there's an active menu hooked to this window
1514 if ( window->ActiveMenu != NULL )
1517 * Let's make the window redraw as a result of the mouse motion.
1519 window->State.Redisplay = TRUE ;
1522 * Since the window is a menu, make the parent window current
1524 fgSetWindow ( window->ActiveMenu->ParentWindow ) ;
1530 * Remember the current modifiers state.
1532 window->State.Modifiers =
1533 ( ( (GetKeyState( VK_LSHIFT ) < 0 ) || ( GetKeyState( VK_RSHIFT ) < 0 )) ? GLUT_ACTIVE_SHIFT : 0 ) |
1534 ( ( (GetKeyState( VK_LCONTROL ) < 0 ) || ( GetKeyState( VK_RCONTROL ) < 0 )) ? GLUT_ACTIVE_CTRL : 0 ) |
1535 ( ( (GetKeyState( VK_LMENU ) < 0 ) || ( GetKeyState( VK_RMENU ) < 0 )) ? GLUT_ACTIVE_ALT : 0 );
1538 * Check if any of the mouse buttons is pressed...
1540 if( (wParam & MK_LBUTTON) || (wParam & MK_MBUTTON) || (wParam & MK_RBUTTON) )
1543 * Yeah, indeed. We need to use the motion callback then:
1545 if( window->Callbacks.Motion != NULL )
1548 * Make sure the current window is set...
1550 fgSetWindow( window );
1553 * Execute the active mouse motion callback now
1555 window->Callbacks.Motion( window->State.MouseX, window->State.MouseY );
1561 * All mouse buttons are up, execute the passive mouse motion callback
1563 if( window->Callbacks.Passive != NULL )
1566 * Make sure the current window is set
1568 fgSetWindow( window );
1571 * Execute the passive mouse motion callback
1573 window->Callbacks.Passive( window->State.MouseX, window->State.MouseY );
1578 * Thrash the current modifiers state now
1580 window->State.Modifiers = 0xffffffff;
1584 case WM_LBUTTONDOWN:
1585 case WM_MBUTTONDOWN:
1586 case WM_RBUTTONDOWN:
1591 GLboolean pressed = TRUE;
1595 * The mouse cursor has moved. Remember the new mouse cursor's position
1597 window->State.MouseX = LOWORD( lParam );
1598 window->State.MouseY = HIWORD( lParam );
1601 * We're curious about the GLUT API button name...
1605 case WM_LBUTTONDOWN: pressed = TRUE; button = GLUT_LEFT_BUTTON; break;
1606 case WM_MBUTTONDOWN: pressed = TRUE; button = GLUT_MIDDLE_BUTTON; break;
1607 case WM_RBUTTONDOWN: pressed = TRUE; button = GLUT_RIGHT_BUTTON; break;
1608 case WM_LBUTTONUP: pressed = FALSE; button = GLUT_LEFT_BUTTON; break;
1609 case WM_MBUTTONUP: pressed = FALSE; button = GLUT_MIDDLE_BUTTON; break;
1610 case WM_RBUTTONUP: pressed = FALSE; button = GLUT_RIGHT_BUTTON; break;
1611 default: pressed = FALSE; button = -1; break;
1615 * The left and right mouse buttons might have been swapped...
1617 if( GetSystemMetrics( SM_SWAPBUTTON ) )
1618 if( button == GLUT_LEFT_BUTTON ) button = GLUT_RIGHT_BUTTON;
1619 else if( button == GLUT_RIGHT_BUTTON ) button = GLUT_LEFT_BUTTON;
1622 * Hey, what's up with you?
1625 return( DefWindowProc( hWnd, uMsg, lParam, wParam ) );
1628 * Do not execute the application's mouse callback if a menu is hooked to this button.
1629 * In that case an appropriate private call should be generated.
1630 * Near as I can tell, this is the menu behaviour:
1631 * - Down-click the menu button, menu not active: activate the menu with its upper left-hand corner at the mouse location.
1632 * - Down-click any button outside the menu, menu active: deactivate the menu
1633 * - Down-click any button inside the menu, menu active: select the menu entry and deactivate the menu
1634 * - Up-click the menu button, menu not active: nothing happens
1635 * - Up-click the menu button outside the menu, menu active: nothing happens
1636 * - Up-click the menu button inside the menu, menu active: select the menu entry and deactivate the menu
1638 if ( window->ActiveMenu != NULL ) /* Window has an active menu, it absorbs any mouse click */
1640 if ( fgCheckActiveMenu ( window, window->ActiveMenu ) == TRUE ) /* Inside the menu, invoke the callback and deactivate the menu*/
1642 /* Save the current window and menu and set the current window to the window whose menu this is */
1643 SFG_Window *save_window = fgStructure.Window ;
1644 SFG_Menu *save_menu = fgStructure.Menu ;
1645 SFG_Window *parent_window = window->ActiveMenu->ParentWindow ;
1646 fgSetWindow ( parent_window ) ;
1647 fgStructure.Menu = window->ActiveMenu ;
1649 /* Execute the menu callback */
1650 fgExecuteMenuCallback ( window->ActiveMenu ) ;
1651 fgDeactivateMenu ( parent_window ) ;
1653 /* Restore the current window and menu */
1654 fgSetWindow ( save_window ) ;
1655 fgStructure.Menu = save_menu ;
1657 else /* Outside the menu, deactivate the menu if it's a downclick */
1659 if ( pressed == TRUE ) fgDeactivateMenu ( window->ActiveMenu->ParentWindow ) ;
1663 * Let's make the window redraw as a result of the mouse click and menu activity.
1665 if ( ! window->IsMenu ) window->State.Redisplay = TRUE ;
1671 * No active menu, let's check whether we need to activate one.
1673 if ( ( window->Menu[ button ] != NULL ) && ( pressed == TRUE ) )
1676 * Let's make the window redraw as a result of the mouse click.
1678 window->State.Redisplay = TRUE ;
1681 * Set the current window
1683 fgSetWindow( window );
1686 * Activate the appropriate menu structure...
1688 fgActivateMenu( window, button );
1694 * Check if there is a mouse callback hooked to the window
1696 if( window->Callbacks.Mouse == NULL )
1700 * Set the current window
1702 fgSetWindow ( window );
1705 * Remember the current modifiers state.
1707 fgStructure.Window->State.Modifiers =
1708 ( ( (GetKeyState( VK_LSHIFT ) < 0 ) || ( GetKeyState( VK_RSHIFT ) < 0 )) ? GLUT_ACTIVE_SHIFT : 0 ) |
1709 ( ( (GetKeyState( VK_LCONTROL ) < 0 ) || ( GetKeyState( VK_RCONTROL ) < 0 )) ? GLUT_ACTIVE_CTRL : 0 ) |
1710 ( ( (GetKeyState( VK_LMENU ) < 0 ) || ( GetKeyState( VK_RMENU ) < 0 )) ? GLUT_ACTIVE_ALT : 0 );
1713 * Finally execute the mouse callback
1715 window->Callbacks.Mouse(
1717 pressed == TRUE ? GLUT_DOWN : GLUT_UP,
1718 window->State.MouseX,
1719 window->State.MouseY
1723 * Trash the modifiers state
1725 fgStructure.Window->State.Modifiers = 0xffffffff;
1736 * Ignore the automatic key repetition if needed:
1738 if( fgState.IgnoreKeyRepeat && (lParam & KF_REPEAT) )
1742 * Remember the current modifiers state. This is done here in order
1743 * to make sure the VK_DELETE keyboard callback is executed properly.
1745 window->State.Modifiers =
1746 ( ( (GetKeyState( VK_LSHIFT ) < 0 ) || ( GetKeyState( VK_RSHIFT ) < 0 )) ? GLUT_ACTIVE_SHIFT : 0 ) |
1747 ( ( (GetKeyState( VK_LCONTROL ) < 0 ) || ( GetKeyState( VK_RCONTROL ) < 0 )) ? GLUT_ACTIVE_CTRL : 0 ) |
1748 ( ( (GetKeyState( VK_LMENU ) < 0 ) || ( GetKeyState( VK_RMENU ) < 0 )) ? GLUT_ACTIVE_ALT : 0 );
1751 * Set the mouse position
1753 GetCursorPos ( &mouse_pos ) ;
1754 ScreenToClient ( window->Window.Handle, &mouse_pos ) ;
1756 window->State.MouseX = mouse_pos.x ;
1757 window->State.MouseY = mouse_pos.y ;
1760 * Convert the Win32 keystroke codes to GLUTtish way
1762 # define KEY(a,b) case a: keypress = b; break;
1767 * Most of the special characters can be handled automagically...
1769 KEY( VK_F1, GLUT_KEY_F1 ); KEY( VK_F2, GLUT_KEY_F2 );
1770 KEY( VK_F3, GLUT_KEY_F3 ); KEY( VK_F4, GLUT_KEY_F4 );
1771 KEY( VK_F5, GLUT_KEY_F5 ); KEY( VK_F6, GLUT_KEY_F6 );
1772 KEY( VK_F7, GLUT_KEY_F7 ); KEY( VK_F8, GLUT_KEY_F8 );
1773 KEY( VK_F9, GLUT_KEY_F9 ); KEY( VK_F10, GLUT_KEY_F10 );
1774 KEY( VK_F11, GLUT_KEY_F11 ); KEY( VK_F12, GLUT_KEY_F12 );
1775 KEY( VK_PRIOR, GLUT_KEY_PAGE_UP ); KEY( VK_NEXT, GLUT_KEY_PAGE_DOWN );
1776 KEY( VK_HOME, GLUT_KEY_HOME ); KEY( VK_END, GLUT_KEY_END );
1777 KEY( VK_LEFT, GLUT_KEY_LEFT ); KEY( VK_UP, GLUT_KEY_UP );
1778 KEY( VK_RIGHT, GLUT_KEY_RIGHT ); KEY( VK_DOWN, GLUT_KEY_DOWN );
1779 KEY( VK_INSERT, GLUT_KEY_INSERT );
1782 * ...yet there is a small exception we need to have handled...
1786 * The delete key should be treated as an ASCII keypress:
1788 if( window->Callbacks.Keyboard != NULL )
1790 fgSetWindow( window );
1791 window->Callbacks.Keyboard( 127, window->State.MouseX, window->State.MouseY );
1796 * Execute the special callback, if present, given the conversion was a success:
1798 if( (keypress != -1) && (window->Callbacks.Special != NULL) )
1801 * Set the current window
1803 fgSetWindow( window );
1806 * Have the special callback executed:
1808 window->Callbacks.Special( keypress, window->State.MouseX, window->State.MouseY );
1812 * Thrash the modifiers register now
1814 window->State.Modifiers = 0xffffffff;
1825 * Remember the current modifiers state. This is done here in order
1826 * to make sure the VK_DELETE keyboard callback is executed properly.
1828 window->State.Modifiers =
1829 ( ( (GetKeyState( VK_LSHIFT ) < 0 ) || ( GetKeyState( VK_RSHIFT ) < 0 )) ? GLUT_ACTIVE_SHIFT : 0 ) |
1830 ( ( (GetKeyState( VK_LCONTROL ) < 0 ) || ( GetKeyState( VK_RCONTROL ) < 0 )) ? GLUT_ACTIVE_CTRL : 0 ) |
1831 ( ( (GetKeyState( VK_LMENU ) < 0 ) || ( GetKeyState( VK_RMENU ) < 0 )) ? GLUT_ACTIVE_ALT : 0 );
1834 * Set the mouse position
1836 GetCursorPos ( &mouse_pos ) ;
1837 ScreenToClient ( window->Window.Handle, &mouse_pos ) ;
1839 window->State.MouseX = mouse_pos.x ;
1840 window->State.MouseY = mouse_pos.y ;
1843 * Convert the Win32 keystroke codes to GLUTtish way. "KEY(a,b)" was defined under "WM_KEYDOWN"
1849 * Most of the special characters can be handled automagically...
1851 KEY( VK_F1, GLUT_KEY_F1 ); KEY( VK_F2, GLUT_KEY_F2 );
1852 KEY( VK_F3, GLUT_KEY_F3 ); KEY( VK_F4, GLUT_KEY_F4 );
1853 KEY( VK_F5, GLUT_KEY_F5 ); KEY( VK_F6, GLUT_KEY_F6 );
1854 KEY( VK_F7, GLUT_KEY_F7 ); KEY( VK_F8, GLUT_KEY_F8 );
1855 KEY( VK_F9, GLUT_KEY_F9 ); KEY( VK_F10, GLUT_KEY_F10 );
1856 KEY( VK_F11, GLUT_KEY_F11 ); KEY( VK_F12, GLUT_KEY_F12 );
1857 KEY( VK_PRIOR, GLUT_KEY_PAGE_UP ); KEY( VK_NEXT, GLUT_KEY_PAGE_DOWN );
1858 KEY( VK_HOME, GLUT_KEY_HOME ); KEY( VK_END, GLUT_KEY_END );
1859 KEY( VK_LEFT, GLUT_KEY_LEFT ); KEY( VK_UP, GLUT_KEY_UP );
1860 KEY( VK_RIGHT, GLUT_KEY_RIGHT ); KEY( VK_DOWN, GLUT_KEY_DOWN );
1861 KEY( VK_INSERT, GLUT_KEY_INSERT );
1864 * ...yet there is a small exception we need to have handled...
1868 * The delete key should be treated as an ASCII keypress:
1870 if( window->Callbacks.KeyboardUp != NULL )
1872 fgSetWindow ( window ) ;
1873 window->Callbacks.KeyboardUp( 127, window->State.MouseX, window->State.MouseY );
1880 * Call the KeyboardUp callback for a regular character if there is one.
1885 GetKeyboardState(state);
1887 if ( ToAscii( wParam, 0, state, code, 0 ) == 1 )
1890 if( window->Callbacks.KeyboardUp != NULL )
1893 * Set the current window
1895 fgSetWindow( window );
1897 window->Callbacks.KeyboardUp( (char)wParam, window->State.MouseX, window->State.MouseY );
1903 * Execute the special callback, if present, given the conversion was a success:
1905 if( (keypress != -1) && (window->Callbacks.SpecialUp != NULL) )
1908 * Set the current window
1910 fgSetWindow( window );
1913 * Have the special callback executed:
1915 window->Callbacks.SpecialUp( keypress, window->State.MouseX, window->State.MouseY );
1919 * Thrash the modifiers register now
1921 window->State.Modifiers = 0xffffffff;
1929 * Ignore the automatic key repetition if needed:
1931 if( fgState.IgnoreKeyRepeat && (lParam & KF_REPEAT) )
1935 * Clear to go with the keyboard callback, if registered:
1937 if( window->Callbacks.Keyboard != NULL )
1940 * Set the current window
1942 fgSetWindow( window );
1945 * Remember the current modifiers state
1947 window->State.Modifiers =
1948 ( ( (GetKeyState( VK_LSHIFT ) < 0 ) || ( GetKeyState( VK_RSHIFT ) < 0 )) ? GLUT_ACTIVE_SHIFT : 0 ) |
1949 ( ( (GetKeyState( VK_LCONTROL ) < 0 ) || ( GetKeyState( VK_RCONTROL ) < 0 )) ? GLUT_ACTIVE_CTRL : 0 ) |
1950 ( ( (GetKeyState( VK_LMENU ) < 0 ) || ( GetKeyState( VK_RMENU ) < 0 )) ? GLUT_ACTIVE_ALT : 0 );
1953 * Have the special callback executed:
1955 window->Callbacks.Keyboard( (char)wParam, window->State.MouseX, window->State.MouseY );
1958 * Thrash the modifiers register now
1960 window->State.Modifiers = 0xffffffff;
1965 case WM_CAPTURECHANGED : /* User has finished resizing the window, force a redraw */
1966 if ( window->Callbacks.Display )
1969 * Set the current window
1971 fgSetWindow( window );
1973 window->Callbacks.Display () ;
1976 /* lRet = DefWindowProc( hWnd, uMsg, wParam, lParam ) ; */
1980 * Other messages that I have seen and which are not handled already
1982 case WM_SETTEXT : /* 0x000c */
1983 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam ); /* Pass it on to "DefWindowProc" to set the window text */
1986 case WM_GETTEXT : /* 0x000d */
1987 /* Ideally we would copy the title of the window into "lParam" */
1988 /* strncpy ( (char *)lParam, "Window Title", wParam ) ;
1989 lRet = ( wParam > 12 ) ? 12 : wParam ; */ /* the number of characters copied */
1990 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1993 case WM_GETTEXTLENGTH : /* 0x000e */
1994 /* Ideally we would get the length of the title of the window */
1995 lRet = 12 ; /* the number of characters in "Window Title\0" (see above) */
1998 case WM_ERASEBKGND : /* 0x0014 */
1999 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
2002 case WM_SYNCPAINT : /* 0x0088 */
2003 /* Another window has moved, need to update this one */
2004 window->State.Redisplay = TRUE ;
2005 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam ); /* Help screen says this message must be passed to "DefWindowProc" */
2008 case WM_NCPAINT : /* 0x0085 */
2009 /* Need to update the border of this window */
2010 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam ); /* Pass it on to "DefWindowProc" to repaint a standard border */
2015 * Handle unhandled messages
2017 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
2025 /*** END OF FILE ***/