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.
33 #include <GL/freeglut.h>
34 #include "freeglut_internal.h"
37 #if TARGET_HOST_UNIX_X11
38 #include <sys/types.h>
43 #elif TARGET_HOST_WIN32
44 #elif TARGET_HOST_WINCE
46 typedef struct GXDisplayProperties GXDisplayProperties;
47 typedef struct GXKeyList GXKeyList;
50 typedef struct GXKeyList (*GXGETDEFAULTKEYS)(int);
51 typedef int (*GXOPENINPUT)();
53 GXGETDEFAULTKEYS GXGetDefaultKeys_ = NULL;
54 GXOPENINPUT GXOpenInput_ = NULL;
56 struct GXKeyList gxKeyList;
61 #define MAX(a,b) (((a)>(b)) ? (a) : (b))
65 #define MIN(a,b) (((a)<(b)) ? (a) : (b))
70 * TODO BEFORE THE STABLE RELEASE:
72 * There are some issues concerning window redrawing under X11, and maybe
73 * some events are not handled. The Win32 version lacks some more features,
74 * but seems acceptable for not demanding purposes.
76 * Need to investigate why the X11 version breaks out with an error when
77 * closing a window (using the window manager, not glutDestroyWindow)...
80 /* -- PRIVATE FUNCTIONS ---------------------------------------------------- */
83 * Handle a window configuration change. When no reshape
84 * callback is hooked, the viewport size is updated to
85 * match the new window size.
87 static void fghReshapeWindow ( SFG_Window *window, int width, int height )
89 SFG_Window *current_window = fgStructure.Window;
91 freeglut_return_if_fail( window != NULL );
94 #if TARGET_HOST_UNIX_X11
96 XResizeWindow( fgDisplay.Display, window->Window.Handle,
98 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
100 #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE
102 #if !TARGET_HOST_WINCE
108 * For windowed mode, get the current position of the
109 * window and resize taking the size of the frame
110 * decorations into account.
113 /* "GetWindowRect" returns the pixel coordinates of the outside of the window */
114 GetWindowRect( window->Window.Handle, &winRect );
120 if ( window->Parent == NULL )
122 if ( ! window->IsMenu && !window->State.IsGameMode )
124 w += GetSystemMetrics( SM_CXSIZEFRAME ) * 2;
125 h += GetSystemMetrics( SM_CYSIZEFRAME ) * 2 +
126 GetSystemMetrics( SM_CYCAPTION );
132 GetWindowRect( window->Parent->Window.Handle, &parentRect );
133 x -= parentRect.left + GetSystemMetrics( SM_CXSIZEFRAME ) * 2;
134 y -= parentRect.top + GetSystemMetrics( SM_CYSIZEFRAME ) * 2 +
135 GetSystemMetrics( SM_CYCAPTION );
139 * SWP_NOACTIVATE Do not activate the window
140 * SWP_NOOWNERZORDER Do not change position in z-order
141 * SWP_NOSENDCHANGING Supress WM_WINDOWPOSCHANGING message
142 * SWP_NOZORDER Retains the current Z order (ignore 2nd param)
145 SetWindowPos( window->Window.Handle,
148 SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOSENDCHANGING |
152 #endif /* TARGET_HOST_WINCE */
155 * XXX Should update {window->State.OldWidth, window->State.OldHeight}
156 * XXX to keep in lockstep with UNIX_X11 code.
158 if( FETCH_WCB( *window, Reshape ) )
159 INVOKE_WCB( *window, Reshape, ( width, height ) );
162 fgSetWindow( window );
163 glViewport( 0, 0, width, height );
169 * Force a window redraw. In Windows at least this is only a partial
170 * solution: if the window is increasing in size in either dimension,
171 * the already-drawn part does not get drawn again and things look funny.
172 * But without this we get this bad behaviour whenever we resize the
175 window->State.Redisplay = GL_TRUE;
178 fgSetWindow( current_window );
182 * Calls a window's redraw method. This is used when
183 * a redraw is forced by the incoming window messages.
185 static void fghRedrawWindow ( SFG_Window *window )
187 SFG_Window *current_window = fgStructure.Window;
189 freeglut_return_if_fail( window );
190 freeglut_return_if_fail( FETCH_WCB ( *window, Display ) );
192 window->State.Redisplay = GL_FALSE;
194 freeglut_return_if_fail( window->State.Visible );
196 fgSetWindow( window );
198 if( window->State.NeedToResize )
206 window->State.NeedToResize = GL_FALSE;
209 INVOKE_WCB( *window, Display, ( ) );
211 fgSetWindow( current_window );
215 * A static helper function to execute display callback for a window
217 static void fghcbDisplayWindow( SFG_Window *window,
218 SFG_Enumerator *enumerator )
220 if( window->State.Redisplay &&
221 window->State.Visible )
223 window->State.Redisplay = GL_FALSE;
225 #if TARGET_HOST_UNIX_X11
226 fghRedrawWindow ( window ) ;
227 #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE
229 window->Window.Handle, NULL, NULL,
230 RDW_NOERASE | RDW_INTERNALPAINT | RDW_INVALIDATE | RDW_UPDATENOW
235 fgEnumSubWindows( window, fghcbDisplayWindow, enumerator );
239 * Make all windows perform a display call
241 static void fghDisplayAll( void )
243 SFG_Enumerator enumerator;
245 enumerator.found = GL_FALSE;
246 enumerator.data = NULL;
248 fgEnumWindows( fghcbDisplayWindow, &enumerator );
252 * Window enumerator callback to check for the joystick polling code
254 static void fghcbCheckJoystickPolls( SFG_Window *window,
255 SFG_Enumerator *enumerator )
257 long int checkTime = fgElapsedTime( );
259 if( window->State.JoystickLastPoll + window->State.JoystickPollRate <=
262 #if !TARGET_HOST_WINCE
263 fgJoystickPollWindow( window );
264 #endif /* !TARGET_HOST_WINCE */
265 window->State.JoystickLastPoll = checkTime;
268 fgEnumSubWindows( window, fghcbCheckJoystickPolls, enumerator );
272 * Check all windows for joystick polling
274 static void fghCheckJoystickPolls( void )
276 SFG_Enumerator enumerator;
278 enumerator.found = GL_FALSE;
279 enumerator.data = NULL;
281 fgEnumWindows( fghcbCheckJoystickPolls, &enumerator );
285 * Check the global timers
287 static void fghCheckTimers( void )
289 long checkTime = fgElapsedTime( );
291 while( fgState.Timers.First )
293 SFG_Timer *timer = fgState.Timers.First;
295 if( timer->TriggerTime > checkTime )
298 fgListRemove( &fgState.Timers, &timer->Node );
299 fgListAppend( &fgState.FreeTimers, &timer->Node );
301 timer->Callback( timer->ID );
308 long fgElapsedTime( void )
310 if ( fgState.Time.Set )
312 #if TARGET_HOST_UNIX_X11
316 gettimeofday( &now, NULL );
318 elapsed = (now.tv_usec - fgState.Time.Value.tv_usec) / 1000;
319 elapsed += (now.tv_sec - fgState.Time.Value.tv_sec) * 1000;
322 #elif TARGET_HOST_WIN32
323 return timeGetTime() - fgState.Time.Value;
324 #elif TARGET_HOST_WINCE
325 return GetTickCount() - fgState.Time.Value;
330 #if TARGET_HOST_UNIX_X11
331 gettimeofday( &fgState.Time.Value, NULL );
332 #elif TARGET_HOST_WIN32
333 fgState.Time.Value = timeGetTime ();
334 #elif TARGET_HOST_WINCE
335 fgState.Time.Value = GetTickCount();
337 fgState.Time.Set = GL_TRUE ;
346 void fgError( const char *fmt, ... )
352 fprintf( stderr, "freeglut ");
353 if( fgState.ProgramName )
354 fprintf (stderr, "(%s): ", fgState.ProgramName);
355 vfprintf( stderr, fmt, ap );
356 fprintf( stderr, "\n" );
360 if ( fgState.Initialised )
366 void fgWarning( const char *fmt, ... )
372 fprintf( stderr, "freeglut ");
373 if( fgState.ProgramName )
374 fprintf( stderr, "(%s): ", fgState.ProgramName );
375 vfprintf( stderr, fmt, ap );
376 fprintf( stderr, "\n" );
382 * Indicates whether Joystick events are being used by ANY window.
384 * The current mechanism is to walk all of the windows and ask if
385 * there is a joystick callback. We have a short-circuit early
386 * return if we find any joystick handler registered.
388 * The real way to do this is to make use of the glutTimer() API
389 * to more cleanly re-implement the joystick API. Then, this code
390 * and all other "joystick timer" code can be yanked.
393 static void fghCheckJoystickCallback( SFG_Window* w, SFG_Enumerator* e)
395 if( FETCH_WCB( *w, Joystick ) )
400 fgEnumSubWindows( w, fghCheckJoystickCallback, e );
402 static int fghHaveJoystick( void )
404 SFG_Enumerator enumerator;
405 enumerator.found = GL_FALSE;
406 enumerator.data = NULL;
407 fgEnumWindows( fghCheckJoystickCallback, &enumerator );
408 return !!enumerator.data;
410 static void fghHavePendingRedisplaysCallback( SFG_Window* w, SFG_Enumerator* e)
412 if( w->State.Redisplay )
417 fgEnumSubWindows( w, fghHavePendingRedisplaysCallback, e );
419 static int fghHavePendingRedisplays (void)
421 SFG_Enumerator enumerator;
422 enumerator.found = GL_FALSE;
423 enumerator.data = NULL;
424 fgEnumWindows( fghHavePendingRedisplaysCallback, &enumerator );
425 return !!enumerator.data;
428 * Returns the number of GLUT ticks (milliseconds) till the next timer event.
430 static long fghNextTimer( void )
433 SFG_Timer *timer = fgState.Timers.First;
436 ret = timer->TriggerTime - fgElapsedTime();
443 * Does the magic required to relinquish the CPU until something interesting
446 static void fghSleepForEvents( void )
450 if( fgState.IdleCallback || fghHavePendingRedisplays( ) )
453 msec = fghNextTimer( );
454 if( fghHaveJoystick( ) ) /* XXX Use GLUT timers for joysticks... */
455 msec = MIN( msec, 10 ); /* XXX Dumb; forces granularity to .01sec */
457 #if TARGET_HOST_UNIX_X11
459 * Possibly due to aggressive use of XFlush() and friends,
460 * it is possible to have our socket drained but still have
461 * unprocessed events. (Or, this may just be normal with
462 * X, anyway?) We do non-trivial processing of X events
463 * after the event-reading loop, in any case, so we
464 * need to allow that we may have an empty socket but non-
467 if( ! XPending( fgDisplay.Display ) )
474 socket = ConnectionNumber( fgDisplay.Display );
476 FD_SET( socket, &fdset );
477 wait.tv_sec = msec / 1000;
478 wait.tv_usec = (msec % 1000) * 1000;
479 err = select( socket+1, &fdset, NULL, NULL, &wait );
482 fgWarning ( "freeglut select() error: %d", errno );
484 #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE
485 MsgWaitForMultipleObjects( 0, NULL, FALSE, msec, QS_ALLEVENTS );
489 #if TARGET_HOST_UNIX_X11
491 * Returns GLUT modifier mask for an XEvent.
493 static int fghGetXModifiers( XEvent *event )
497 if( event->xkey.state & ( ShiftMask | LockMask ) )
498 ret |= GLUT_ACTIVE_SHIFT;
499 if( event->xkey.state & ControlMask )
500 ret |= GLUT_ACTIVE_CTRL;
501 if( event->xkey.state & Mod1Mask )
502 ret |= GLUT_ACTIVE_ALT;
509 /* -- INTERFACE FUNCTIONS -------------------------------------------------- */
512 * Executes a single iteration in the freeglut processing loop.
514 void FGAPIENTRY glutMainLoopEvent( void )
516 #if TARGET_HOST_UNIX_X11
520 /* This code was repeated constantly, so here it goes into a definition: */
521 #define GETWINDOW(a) \
522 window = fgWindowByHandle( event.a.window ); \
523 if( window == NULL ) \
526 #define GETMOUSE(a) \
527 window->State.MouseX = event.a.x; \
528 window->State.MouseY = event.a.y;
530 freeglut_assert_ready;
532 while( XPending( fgDisplay.Display ) )
534 XNextEvent( fgDisplay.Display, &event );
539 /* Destroy the window when the WM_DELETE_WINDOW message arrives */
540 if( (Atom) event.xclient.data.l[ 0 ] == fgDisplay.DeleteWindow )
542 GETWINDOW( xclient );
544 fgDestroyWindow ( window );
546 if( fgState.ActionOnWindowClose == GLUT_ACTION_EXIT )
551 else if( fgState.ActionOnWindowClose == GLUT_ACTION_GLUTMAINLOOP_RETURNS )
552 fgState.ExecState = GLUT_EXEC_STATE_STOP;
559 * CreateNotify causes a configure-event so that sub-windows are
560 * handled compatibly with GLUT. Otherwise, your sub-windows
561 * (in freeglut only) will not get an initial reshape event,
562 * which can break things.
564 * GLUT presumably does this because it generally tries to treat
565 * sub-windows the same as windows.
567 * XXX Technically, GETWINDOW( xconfigure ) and
568 * XXX {event.xconfigure} may not be legit ways to get at
569 * XXX data for CreateNotify events. In practice, the data
570 * XXX is in a union which is laid out much the same either
571 * XXX way. But if you want to split hairs, this isn't legit,
572 * XXX and we should instead duplicate some code.
575 case ConfigureNotify:
576 GETWINDOW( xconfigure );
578 int width = event.xconfigure.width;
579 int height = event.xconfigure.height;
581 if( ( width != window->State.OldWidth ) ||
582 ( height != window->State.OldHeight ) )
584 window->State.OldWidth = width;
585 window->State.OldHeight = height;
586 if( FETCH_WCB( *window, Reshape ) )
587 INVOKE_WCB( *window, Reshape, ( width, height ) );
590 fgSetWindow( window );
591 glViewport( 0, 0, width, height );
593 glutPostRedisplay( );
600 * This is sent to confirm the XDestroyWindow call.
602 * XXX WHY is this commented out? Should we re-enable it?
604 /* fgAddToWindowDestroyList ( window ); */
609 * We are too dumb to process partial exposes...
611 * XXX Well, we could do it. However, it seems to only
612 * XXX be potentially useful for single-buffered (since
613 * XXX double-buffered does not respect viewport when we
614 * XXX do a buffer-swap).
617 if( event.xexpose.count == 0 )
619 GETWINDOW( xexpose );
620 fgSetWindow( window );
621 glutPostRedisplay( );
628 * If we never do anything with this, can we just not ask to
629 * get these messages?
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:
643 GETWINDOW( xvisibility );
645 * XXX INVOKE_WCB() does this check for us.
647 if( ! FETCH_WCB( *window, WindowStatus ) )
649 fgSetWindow( window );
652 * Sending this event, the X server can notify us that the window
653 * has just acquired one of the three possible visibility states:
654 * VisibilityUnobscured, VisibilityPartiallyObscured or
655 * VisibilityFullyObscured
657 switch( event.xvisibility.state )
659 case VisibilityUnobscured:
660 INVOKE_WCB( *window, WindowStatus, ( GLUT_FULLY_RETAINED ) );
661 window->State.Visible = GL_TRUE;
664 case VisibilityPartiallyObscured:
665 INVOKE_WCB( *window, WindowStatus,
666 ( GLUT_PARTIALLY_RETAINED ) );
667 window->State.Visible = GL_TRUE;
670 case VisibilityFullyObscured:
671 INVOKE_WCB( *window, WindowStatus, ( GLUT_FULLY_COVERED ) );
672 window->State.Visible = GL_FALSE;
676 fgWarning( "Unknown X visibility state: %d",
677 event.xvisibility.state );
685 GETWINDOW( xcrossing );
686 GETMOUSE( xcrossing );
687 INVOKE_WCB( *window, Entry, ( ( EnterNotify == event.type ) ?
694 GETWINDOW( xmotion );
697 if( window->ActiveMenu )
699 if( window == window->ActiveMenu->ParentWindow )
701 window->ActiveMenu->Window->State.MouseX =
702 event.xmotion.x_root - window->ActiveMenu->X;
703 window->ActiveMenu->Window->State.MouseY =
704 event.xmotion.y_root - window->ActiveMenu->Y;
706 window->ActiveMenu->Window->State.Redisplay = GL_TRUE ;
707 fgSetWindow( window->ActiveMenu->ParentWindow );
713 * XXX For more than 5 buttons, just check {event.xmotion.state},
714 * XXX rather than a host of bit-masks? Or maybe we need to
715 * XXX track ButtonPress/ButtonRelease events in our own
718 #define BUTTON_MASK \
719 ( Button1Mask | Button2Mask | Button3Mask | Button4Mask | Button5Mask )
720 if ( event.xmotion.state & BUTTON_MASK )
721 INVOKE_WCB( *window, Motion, ( event.xmotion.x,
724 INVOKE_WCB( *window, Passive, ( event.xmotion.x,
732 GLboolean pressed = GL_TRUE;
735 if( event.type == ButtonRelease )
739 * A mouse button has been pressed or released. Traditionally,
740 * break if the window was found within the freeglut structures.
742 GETWINDOW( xbutton );
746 * An X button (at least in XFree86) is numbered from 1.
747 * A GLUT button is numbered from 0.
748 * Old GLUT passed through buttons other than just the first
749 * three, though it only gave symbolic names and official
750 * support to the first three.
752 button = event.xbutton.button - 1;
755 * XXX This comment is replicated in the WIN32 section and
756 * XXX maybe also in the menu code. Can we move the info
757 * XXX to one central place and *reference* it from here?
759 * Do not execute the application's mouse callback if a menu
760 * is hooked to this button. In that case an appropriate
761 * private call should be generated.
762 * Near as I can tell, this is the menu behaviour:
763 * - Down-click the menu button, menu not active: activate
764 * the menu with its upper left-hand corner at the mouse
766 * - Down-click any button outside the menu, menu active:
767 * deactivate the menu
768 * - Down-click any button inside the menu, menu active:
769 * select the menu entry and deactivate the menu
770 * - Up-click the menu button, menu not active: nothing happens
771 * - Up-click the menu button outside the menu, menu active:
773 * - Up-click the menu button inside the menu, menu active:
774 * select the menu entry and deactivate the menu
776 /* Window has an active menu, it absorbs any mouse click */
777 if( window->ActiveMenu )
779 if( window == window->ActiveMenu->ParentWindow )
781 window->ActiveMenu->Window->State.MouseX =
782 event.xbutton.x_root - window->ActiveMenu->X;
783 window->ActiveMenu->Window->State.MouseY =
784 event.xbutton.y_root - window->ActiveMenu->Y;
787 /* In the menu, invoke the callback and deactivate the menu*/
788 if( fgCheckActiveMenu( window->ActiveMenu->Window,
789 window->ActiveMenu ) )
792 * Save the current window and menu and set the current
793 * window to the window whose menu this is
795 SFG_Window *save_window = fgStructure.Window;
796 SFG_Menu *save_menu = fgStructure.Menu;
797 SFG_Window *parent_window =
798 window->ActiveMenu->ParentWindow;
799 fgSetWindow( parent_window );
800 fgStructure.Menu = window->ActiveMenu;
802 /* Execute the menu callback */
803 fgExecuteMenuCallback( window->ActiveMenu );
804 fgDeactivateMenu( parent_window );
806 /* Restore the current window and menu */
807 fgSetWindow( save_window );
808 fgStructure.Menu = save_menu;
812 * Outside the menu, deactivate if it's a downclick
814 * XXX This isn't enough. A downclick outside of
815 * XXX the interior of our freeglut windows should also
816 * XXX deactivate the menu. This is more complicated.
818 fgDeactivateMenu( window->ActiveMenu->ParentWindow );
821 * XXX Why does an active menu require a redisplay at
822 * XXX this point? If this can come out cleanly, then
823 * XXX it probably should do so; if not, a comment should
826 window->State.Redisplay = GL_TRUE;
830 /* No active menu, let's check whether we need to activate one. */
831 if( ( 0 <= button ) &&
832 ( FREEGLUT_MAX_MENUS > button ) &&
833 ( window->Menu[ button ] ) &&
836 /* XXX Posting a requisite Redisplay seems bogus. */
837 window->State.Redisplay = GL_TRUE;
838 fgSetWindow( window );
839 fgActivateMenu( window, button );
844 * Check if there is a mouse or mouse wheel callback hooked to the
847 if( ! FETCH_WCB( *window, Mouse ) &&
848 ! FETCH_WCB( *window, MouseWheel ) )
851 fgState.Modifiers = fghGetXModifiers( &event );
854 * Finally execute the mouse or mouse wheel callback
856 * XXX Use a symbolic constant, *not* "4"! ("3, sire!")
858 if( ( button < 3 ) || ( ! FETCH_WCB( *window, MouseWheel ) ) )
859 INVOKE_WCB( *window, Mouse, ( button,
860 pressed ? GLUT_DOWN : GLUT_UP,
867 * Map 4 and 5 to wheel zero; EVEN to +1, ODD to -1
868 * " 6 and 7 " " one; ...
870 * XXX This *should* be behind some variables/macros,
871 * XXX since the order and numbering isn't certain
872 * XXX See XFree86 configuration docs (even back in the
873 * XXX 3.x days, and especially with 4.x).
875 * XXX Note that {button} has already been decremeted
876 * XXX in mapping from X button numbering to GLUT.
878 int wheel_number = (button - 3) / 2;
884 INVOKE_WCB( *window, MouseWheel, ( wheel_number,
891 /* Trash the modifiers state */
892 fgState.Modifiers = 0xffffffff;
899 FGCBKeyboard keyboard_cb;
900 FGCBSpecial special_cb;
905 /* Detect auto repeated keys, if configured globally or per-window */
907 if ( fgState.KeyRepeat==GLUT_KEY_REPEAT_OFF || window->State.IgnoreKeyRepeat==GL_TRUE )
909 if (event.type==KeyRelease)
912 * Look at X11 keystate to detect repeat mode.
913 * While X11 says the key is actually held down, we'll ignore KeyRelease/KeyPress pairs.
917 XQueryKeymap( fgDisplay.Display, keys ); /* Look at X11 keystate to detect repeat mode */
919 if ( event.xkey.keycode<256 ) /* XQueryKeymap is limited to 256 keycodes */
921 if ( keys[event.xkey.keycode>>3] & (1<<(event.xkey.keycode%8)) )
922 window->State.KeyRepeating = GL_TRUE;
924 window->State.KeyRepeating = GL_FALSE;
929 window->State.KeyRepeating = GL_FALSE;
931 /* Cease processing this event if it is auto repeated */
933 if (window->State.KeyRepeating)
936 if( event.type == KeyPress )
938 keyboard_cb = FETCH_WCB( *window, Keyboard );
939 special_cb = FETCH_WCB( *window, Special );
943 keyboard_cb = FETCH_WCB( *window, KeyboardUp );
944 special_cb = FETCH_WCB( *window, SpecialUp );
948 * Is there a keyboard/special callback hooked for this window?
950 if( keyboard_cb || special_cb )
952 XComposeStatus composeStatus;
953 char asciiCode[ 32 ];
958 * Check for the ASCII/KeySym codes associated with the event:
960 len = XLookupString( &event.xkey, asciiCode, sizeof(asciiCode),
961 &keySym, &composeStatus
965 * GLUT API tells us to have two separate callbacks...
970 * ...one for the ASCII translateable keypresses...
974 fgSetWindow( window );
975 fgState.Modifiers = fghGetXModifiers( &event );
976 keyboard_cb( asciiCode[ 0 ],
977 event.xkey.x, event.xkey.y
979 fgState.Modifiers = 0xffffffff;
987 * ...and one for all the others, which need to be
988 * translated to GLUT_KEY_Xs...
992 case XK_F1: special = GLUT_KEY_F1; break;
993 case XK_F2: special = GLUT_KEY_F2; break;
994 case XK_F3: special = GLUT_KEY_F3; break;
995 case XK_F4: special = GLUT_KEY_F4; break;
996 case XK_F5: special = GLUT_KEY_F5; break;
997 case XK_F6: special = GLUT_KEY_F6; break;
998 case XK_F7: special = GLUT_KEY_F7; break;
999 case XK_F8: special = GLUT_KEY_F8; break;
1000 case XK_F9: special = GLUT_KEY_F9; break;
1001 case XK_F10: special = GLUT_KEY_F10; break;
1002 case XK_F11: special = GLUT_KEY_F11; break;
1003 case XK_F12: special = GLUT_KEY_F12; break;
1005 case XK_Left: special = GLUT_KEY_LEFT; break;
1006 case XK_Right: special = GLUT_KEY_RIGHT; break;
1007 case XK_Up: special = GLUT_KEY_UP; break;
1008 case XK_Down: special = GLUT_KEY_DOWN; break;
1011 case XK_Prior: special = GLUT_KEY_PAGE_UP; break;
1013 case XK_Next: special = GLUT_KEY_PAGE_DOWN; break;
1015 case XK_Home: special = GLUT_KEY_HOME; break;
1017 case XK_End: special = GLUT_KEY_END; break;
1019 case XK_Insert: special = GLUT_KEY_INSERT; break;
1023 * Execute the callback (if one has been specified),
1024 * given that the special code seems to be valid...
1026 if( special_cb && (special != -1) )
1028 fgSetWindow( window );
1029 fgState.Modifiers = fghGetXModifiers( &event );
1030 special_cb( special, event.xkey.x, event.xkey.y );
1031 fgState.Modifiers = 0xffffffff;
1038 case ReparentNotify:
1039 break; /* XXX Should disable this event */
1042 fgWarning ("Unknown X event type: %d", event.type);
1047 #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE
1051 while( PeekMessage( &stMsg, NULL, 0, 0, PM_NOREMOVE ) )
1053 if( GetMessage( &stMsg, NULL, 0, 0 ) == 0 )
1055 if( fgState.ActionOnWindowClose == GLUT_ACTION_EXIT )
1060 else if( fgState.ActionOnWindowClose == GLUT_ACTION_GLUTMAINLOOP_RETURNS )
1061 fgState.ExecState = GLUT_EXEC_STATE_STOP;
1066 TranslateMessage( &stMsg );
1067 DispatchMessage( &stMsg );
1071 if( fgState.Timers.First )
1073 fghCheckJoystickPolls( );
1080 * Enters the freeglut processing loop.
1081 * Stays until the "ExecState" changes to "GLUT_EXEC_STATE_STOP".
1083 void FGAPIENTRY glutMainLoop( void )
1087 #if TARGET_HOST_WIN32 || TARGET_HOST_WINCE
1088 SFG_Window *window = (SFG_Window *)fgStructure.Windows.First ;
1091 freeglut_assert_ready;
1093 #if TARGET_HOST_WIN32 || TARGET_HOST_WINCE
1095 * Processing before the main loop: If there is a window which is open and
1096 * which has a visibility callback, call it. I know this is an ugly hack,
1097 * but I'm not sure what else to do about it. Ideally we should leave
1098 * something uninitialized in the create window code and initialize it in
1099 * the main loop, and have that initialization create a "WM_ACTIVATE"
1100 * message. Then we would put the visibility callback code in the
1101 * "case WM_ACTIVATE" block below. - John Fay -- 10/24/02
1105 if ( FETCH_WCB( *window, Visibility ) )
1107 SFG_Window *current_window = fgStructure.Window ;
1109 INVOKE_WCB( *window, Visibility, ( window->State.Visible ) );
1110 fgSetWindow( current_window );
1113 window = (SFG_Window *)window->Node.Next ;
1117 fgState.ExecState = GLUT_EXEC_STATE_RUNNING ;
1118 while( fgState.ExecState == GLUT_EXEC_STATE_RUNNING )
1122 glutMainLoopEvent( );
1124 * Step through the list of windows, seeing if there are any
1125 * that are not menus
1127 for( window = ( SFG_Window * )fgStructure.Windows.First;
1129 window = ( SFG_Window * )window->Node.Next )
1130 if ( ! ( window->IsMenu ) )
1134 fgState.ExecState = GLUT_EXEC_STATE_STOP;
1137 if( fgState.IdleCallback )
1138 fgState.IdleCallback( );
1140 fghSleepForEvents( );
1145 * When this loop terminates, destroy the display, state and structure
1146 * of a freeglut session, so that another glutInit() call can happen
1148 * Save the "ActionOnWindowClose" because "fgDeinitialize" resets it.
1150 action = fgState.ActionOnWindowClose;
1152 if( action == GLUT_ACTION_EXIT )
1157 * Leaves the freeglut processing loop.
1159 void FGAPIENTRY glutLeaveMainLoop( void )
1161 fgState.ExecState = GLUT_EXEC_STATE_STOP ;
1165 #if TARGET_HOST_WIN32 || TARGET_HOST_WINCE
1167 * Determine a GLUT modifer mask based on MS-WINDOWS system info.
1169 static int fghGetWin32Modifiers (void)
1172 ( ( ( GetKeyState( VK_LSHIFT ) < 0 ) ||
1173 ( GetKeyState( VK_RSHIFT ) < 0 )) ? GLUT_ACTIVE_SHIFT : 0 ) |
1174 ( ( ( GetKeyState( VK_LCONTROL ) < 0 ) ||
1175 ( GetKeyState( VK_RCONTROL ) < 0 )) ? GLUT_ACTIVE_CTRL : 0 ) |
1176 ( ( ( GetKeyState( VK_LMENU ) < 0 ) ||
1177 ( GetKeyState( VK_RMENU ) < 0 )) ? GLUT_ACTIVE_ALT : 0 );
1181 * The window procedure for handling Win32 events
1183 LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam,
1186 SFG_Window* window = fgWindowByHandle( hWnd );
1190 if ( ( window == NULL ) && ( uMsg != WM_CREATE ) )
1191 return DefWindowProc( hWnd, uMsg, wParam, lParam );
1193 /* printf ( "Window %3d message <%04x> %12d %12d\n", window?window->ID:0,
1194 uMsg, wParam, lParam ); */
1198 /* The window structure is passed as the creation structure paramter... */
1199 window = (SFG_Window *) (((LPCREATESTRUCT) lParam)->lpCreateParams);
1200 assert( window != NULL );
1202 window->Window.Handle = hWnd;
1203 window->Window.Device = GetDC( hWnd );
1204 if( window->IsMenu )
1206 unsigned int current_DisplayMode = fgState.DisplayMode;
1207 fgState.DisplayMode = GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH;
1208 #if !TARGET_HOST_WINCE
1209 fgSetupPixelFormat( window, GL_FALSE, PFD_MAIN_PLANE );
1211 fgState.DisplayMode = current_DisplayMode;
1213 if( fgStructure.MenuContext )
1214 wglMakeCurrent( window->Window.Device,
1215 fgStructure.MenuContext->Context
1219 fgStructure.MenuContext =
1220 (SFG_MenuContext *)malloc( sizeof(SFG_MenuContext) );
1221 fgStructure.MenuContext->Context =
1222 wglCreateContext( window->Window.Device );
1225 /* window->Window.Context = wglGetCurrentContext (); */
1226 window->Window.Context = wglCreateContext( window->Window.Device );
1230 #if !TARGET_HOST_WINCE
1231 fgSetupPixelFormat( window, GL_FALSE, PFD_MAIN_PLANE );
1234 if( ! fgState.UseCurrentContext )
1235 window->Window.Context =
1236 wglCreateContext( window->Window.Device );
1239 window->Window.Context = wglGetCurrentContext( );
1240 if( ! window->Window.Context )
1241 window->Window.Context =
1242 wglCreateContext( window->Window.Device );
1246 window->State.NeedToResize = GL_TRUE;
1247 window->State.Width = fgState.Size.X;
1248 window->State.Height = fgState.Size.Y;
1250 ReleaseDC( window->Window.Handle, window->Window.Device );
1252 #if TARGET_HOST_WINCE
1253 /* Take over button handling */
1255 HINSTANCE dxDllLib=LoadLibrary(_T("gx.dll"));
1258 GXGetDefaultKeys_=(GXGETDEFAULTKEYS)GetProcAddress(dxDllLib, _T("?GXGetDefaultKeys@@YA?AUGXKeyList@@H@Z"));
1259 GXOpenInput_=(GXOPENINPUT)GetProcAddress(dxDllLib, _T("?GXOpenInput@@YAHXZ"));
1264 if(GXGetDefaultKeys_)
1265 gxKeyList = (*GXGetDefaultKeys_)(GX_LANDSCAPEKEYS);
1268 #endif /* TARGET_HOST_WINCE */
1273 * If the window is visible, then it is the user manually resizing it.
1274 * If it is not, then it is the system sending us a dummy resize with
1275 * zero dimensions on a "glutIconifyWindow" call.
1277 if( window->State.Visible )
1279 window->State.NeedToResize = GL_TRUE;
1280 #if TARGET_HOST_WINCE
1281 window->State.Width = HIWORD(lParam);
1282 window->State.Height = LOWORD(lParam);
1284 window->State.Width = LOWORD(lParam);
1285 window->State.Height = HIWORD(lParam);
1286 #endif /* TARGET_HOST_WINCE */
1292 /* printf("WM_SETFOCUS: %p\n", window ); */
1293 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1297 if (LOWORD(wParam) != WA_INACTIVE)
1299 /* glutSetCursor( fgStructure.Window->State.Cursor ); */
1300 /* printf("WM_ACTIVATE: glutSetCursor( %p, %d)\n", window,
1301 window->State.Cursor ); */
1302 glutSetCursor( window->State.Cursor );
1305 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1310 * XXX Why not re-use some common code with the glutSetCursor()
1311 * XXX function (or perhaps invoke glutSetCursor())?
1312 * XXX That is, why are we duplicating code, here, from
1313 * XXX glutSetCursor()? The WIN32 code should be able to just
1314 * XXX call glutSetCurdsor() instead of defining two macros
1315 * XXX and implementing a nested case in-line.
1318 /* Set the cursor AND change it for this window class. */
1319 #define MAP_CURSOR(a,b) \
1321 SetCursor( LoadCursor( NULL, b ) ); \
1324 /* Nuke the cursor AND change it for this window class. */
1325 #define ZAP_CURSOR(a,b) \
1327 SetCursor( NULL ); \
1330 if( LOWORD( lParam ) == HTCLIENT )
1331 switch( window->State.Cursor )
1333 MAP_CURSOR( GLUT_CURSOR_RIGHT_ARROW, IDC_ARROW );
1334 MAP_CURSOR( GLUT_CURSOR_LEFT_ARROW, IDC_ARROW );
1335 MAP_CURSOR( GLUT_CURSOR_INFO, IDC_HELP );
1336 MAP_CURSOR( GLUT_CURSOR_DESTROY, IDC_CROSS );
1337 MAP_CURSOR( GLUT_CURSOR_HELP, IDC_HELP );
1338 MAP_CURSOR( GLUT_CURSOR_CYCLE, IDC_SIZEALL );
1339 MAP_CURSOR( GLUT_CURSOR_SPRAY, IDC_CROSS );
1340 MAP_CURSOR( GLUT_CURSOR_WAIT, IDC_WAIT );
1341 MAP_CURSOR( GLUT_CURSOR_TEXT, IDC_UPARROW );
1342 MAP_CURSOR( GLUT_CURSOR_CROSSHAIR, IDC_CROSS );
1343 /* MAP_CURSOR( GLUT_CURSOR_NONE, IDC_NO ); */
1344 ZAP_CURSOR( GLUT_CURSOR_NONE, NULL );
1347 MAP_CURSOR( GLUT_CURSOR_UP_DOWN, IDC_ARROW );
1350 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1354 window->State.Visible = GL_TRUE;
1355 window->State.Redisplay = GL_TRUE;
1359 /* Turn on the visibility in case it was turned off somehow */
1360 window->State.Visible = GL_TRUE;
1361 BeginPaint( hWnd, &ps );
1362 fghRedrawWindow( window );
1363 EndPaint( hWnd, &ps );
1367 fgDestroyWindow ( window );
1368 if ( fgState.ActionOnWindowClose != GLUT_ACTION_CONTINUE_EXECUTION )
1374 * The window already got destroyed, so don't bother with it.
1380 #if TARGET_HOST_WINCE
1381 window->State.MouseX = 320-HIWORD( lParam );
1382 window->State.MouseY = LOWORD( lParam );
1384 window->State.MouseX = LOWORD( lParam );
1385 window->State.MouseY = HIWORD( lParam );
1386 #endif /* TARGET_HOST_WINCE */
1388 if ( window->ActiveMenu )
1390 window->State.Redisplay = GL_TRUE;
1391 fgSetWindow ( window->ActiveMenu->ParentWindow );
1395 fgState.Modifiers = fghGetWin32Modifiers( );
1397 if( ( wParam & MK_LBUTTON ) ||
1398 ( wParam & MK_MBUTTON ) ||
1399 ( wParam & MK_RBUTTON ) )
1400 INVOKE_WCB( *window, Motion, ( window->State.MouseX,
1401 window->State.MouseY ) );
1403 INVOKE_WCB( *window, Passive, ( window->State.MouseX,
1404 window->State.MouseY ) );
1406 fgState.Modifiers = 0xffffffff;
1410 case WM_LBUTTONDOWN:
1411 case WM_MBUTTONDOWN:
1412 case WM_RBUTTONDOWN:
1417 GLboolean pressed = GL_TRUE;
1420 #if TARGET_HOST_WINCE
1421 window->State.MouseX = 320-HIWORD( lParam );
1422 window->State.MouseY = LOWORD( lParam );
1424 window->State.MouseX = LOWORD( lParam );
1425 window->State.MouseY = HIWORD( lParam );
1426 #endif /* TARGET_HOST_WINCE */
1430 case WM_LBUTTONDOWN:
1432 button = GLUT_LEFT_BUTTON;
1434 case WM_MBUTTONDOWN:
1436 button = GLUT_MIDDLE_BUTTON;
1438 case WM_RBUTTONDOWN:
1440 button = GLUT_RIGHT_BUTTON;
1444 button = GLUT_LEFT_BUTTON;
1448 button = GLUT_MIDDLE_BUTTON;
1452 button = GLUT_RIGHT_BUTTON;
1460 #if !TARGET_HOST_WINCE
1461 if( GetSystemMetrics( SM_SWAPBUTTON ) )
1463 if( button == GLUT_LEFT_BUTTON )
1464 button = GLUT_RIGHT_BUTTON;
1466 if( button == GLUT_RIGHT_BUTTON )
1467 button = GLUT_LEFT_BUTTON;
1469 #endif /* !TARGET_HOST_WINCE */
1472 return DefWindowProc( hWnd, uMsg, lParam, wParam );
1475 * XXX This comment is duplicated in two other spots.
1476 * XXX Can we centralize it?
1478 * Do not execute the application's mouse callback if a
1479 * menu is hooked to this button.
1480 * In that case an appropriate private call should be generated.
1481 * Near as I can tell, this is the menu behaviour:
1482 * - Down-click the menu button, menu not active: activate
1483 * the menu with its upper left-hand corner at the mouse location.
1484 * - Down-click any button outside the menu, menu active:
1485 * deactivate the menu
1486 * - Down-click any button inside the menu, menu active:
1487 * select the menu entry and deactivate the menu
1488 * - Up-click the menu button, menu not active: nothing happens
1489 * - Up-click the menu button outside the menu, menu active:
1491 * - Up-click the menu button inside the menu, menu active:
1492 * select the menu entry and deactivate the menu
1494 /* Window has an active menu, it absorbs any mouse click */
1495 if( window->ActiveMenu )
1497 /* Outside the menu, deactivate the menu if it's a downclick */
1498 if( ! fgCheckActiveMenu( window, window->ActiveMenu ) )
1501 fgDeactivateMenu( window->ActiveMenu->ParentWindow );
1503 else /* In menu, invoke the callback and deactivate the menu*/
1506 * Save the current window and menu and set the current
1507 * window to the window whose menu this is
1509 SFG_Window *save_window = fgStructure.Window;
1510 SFG_Menu *save_menu = fgStructure.Menu;
1511 SFG_Window *parent_window = window->ActiveMenu->ParentWindow;
1512 fgSetWindow( parent_window );
1513 fgStructure.Menu = window->ActiveMenu;
1515 /* Execute the menu callback */
1516 fgExecuteMenuCallback( window->ActiveMenu );
1517 fgDeactivateMenu( parent_window );
1519 /* Restore the current window and menu */
1520 fgSetWindow( save_window );
1521 fgStructure.Menu = save_menu;
1525 * Let's make the window redraw as a result of the mouse
1526 * click and menu activity.
1528 if( ! window->IsMenu )
1529 window->State.Redisplay = GL_TRUE;
1534 if( window->Menu[ button ] && pressed )
1536 window->State.Redisplay = GL_TRUE;
1537 fgSetWindow( window );
1538 fgActivateMenu( window, button );
1543 if( ! FETCH_WCB( *window, Mouse ) )
1546 fgSetWindow( window );
1547 fgState.Modifiers = fghGetWin32Modifiers( );
1552 pressed ? GLUT_DOWN : GLUT_UP,
1553 window->State.MouseX,
1554 window->State.MouseY
1558 fgState.Modifiers = 0xffffffff;
1563 /* Should be WM_MOUSEWHEEL but my compiler doesn't recognize it */
1566 * XXX THIS IS SPECULATIVE -- John Fay, 10/2/03
1567 * XXX Should use WHEEL_DELTA instead of 120
1569 int wheel_number = LOWORD( wParam );
1570 short ticks = ( short )HIWORD( wParam ) / 120;
1580 * The mouse cursor has moved. Remember the new mouse cursor's position
1582 /* window->State.MouseX = LOWORD( lParam ); */
1583 /* Need to adjust by window position, */
1584 /* window->State.MouseY = HIWORD( lParam ); */
1585 /* change "lParam" to other parameter */
1587 if( ! FETCH_WCB( *window, MouseWheel ) &&
1588 ! FETCH_WCB( *window, Mouse ) )
1591 fgSetWindow( window );
1592 fgState.Modifiers = fghGetWin32Modifiers( );
1595 if( FETCH_WCB( *window, MouseWheel ) )
1596 INVOKE_WCB( *window, MouseWheel,
1599 window->State.MouseX,
1600 window->State.MouseY
1603 else /* No mouse wheel, call the mouse button callback twice */
1606 * XXX The below assumes that you have no more than 3 mouse
1607 * XXX buttons. Sorry.
1609 int button = wheel_number*2 + 4;
1612 INVOKE_WCB( *window, Mouse,
1613 ( button, GLUT_DOWN,
1614 window->State.MouseX, window->State.MouseY )
1616 INVOKE_WCB( *window, Mouse,
1618 window->State.MouseX, window->State.MouseX )
1622 fgState.Modifiers = 0xffffffff;
1632 if( ( fgState.KeyRepeat==GLUT_KEY_REPEAT_OFF || window->State.IgnoreKeyRepeat==GL_TRUE ) && (HIWORD(lParam) & KF_REPEAT) )
1636 * Remember the current modifiers state. This is done here in order
1637 * to make sure the VK_DELETE keyboard callback is executed properly.
1639 fgState.Modifiers = fghGetWin32Modifiers( );
1641 GetCursorPos( &mouse_pos );
1642 ScreenToClient( window->Window.Handle, &mouse_pos );
1644 window->State.MouseX = mouse_pos.x;
1645 window->State.MouseY = mouse_pos.y;
1648 * Convert the Win32 keystroke codes to GLUTtish way
1650 # define KEY(a,b) case a: keypress = b; break;
1654 KEY( VK_F1, GLUT_KEY_F1 );
1655 KEY( VK_F2, GLUT_KEY_F2 );
1656 KEY( VK_F3, GLUT_KEY_F3 );
1657 KEY( VK_F4, GLUT_KEY_F4 );
1658 KEY( VK_F5, GLUT_KEY_F5 );
1659 KEY( VK_F6, GLUT_KEY_F6 );
1660 KEY( VK_F7, GLUT_KEY_F7 );
1661 KEY( VK_F8, GLUT_KEY_F8 );
1662 KEY( VK_F9, GLUT_KEY_F9 );
1663 KEY( VK_F10, GLUT_KEY_F10 );
1664 KEY( VK_F11, GLUT_KEY_F11 );
1665 KEY( VK_F12, GLUT_KEY_F12 );
1666 KEY( VK_PRIOR, GLUT_KEY_PAGE_UP );
1667 KEY( VK_NEXT, GLUT_KEY_PAGE_DOWN );
1668 KEY( VK_HOME, GLUT_KEY_HOME );
1669 KEY( VK_END, GLUT_KEY_END );
1670 KEY( VK_LEFT, GLUT_KEY_LEFT );
1671 KEY( VK_UP, GLUT_KEY_UP );
1672 KEY( VK_RIGHT, GLUT_KEY_RIGHT );
1673 KEY( VK_DOWN, GLUT_KEY_DOWN );
1674 KEY( VK_INSERT, GLUT_KEY_INSERT );
1678 * The delete key should be treated as an ASCII keypress:
1680 INVOKE_WCB( *window, Keyboard,
1681 ( 127, window->State.MouseX, window->State.MouseY )
1685 #if TARGET_HOST_WINCE
1686 if(!(lParam & 0x40000000)) /* Prevent auto-repeat */
1688 if(wParam==(unsigned)gxKeyList.vkRight)
1689 keypress = GLUT_KEY_RIGHT;
1690 else if(wParam==(unsigned)gxKeyList.vkLeft)
1691 keypress = GLUT_KEY_LEFT;
1692 else if(wParam==(unsigned)gxKeyList.vkUp)
1693 keypress = GLUT_KEY_UP;
1694 else if(wParam==(unsigned)gxKeyList.vkDown)
1695 keypress = GLUT_KEY_DOWN;
1696 else if(wParam==(unsigned)gxKeyList.vkA)
1697 keypress = GLUT_KEY_F1;
1698 else if(wParam==(unsigned)gxKeyList.vkB)
1699 keypress = GLUT_KEY_F2;
1700 else if(wParam==(unsigned)gxKeyList.vkC)
1701 keypress = GLUT_KEY_F3;
1702 else if(wParam==(unsigned)gxKeyList.vkStart)
1703 keypress = GLUT_KEY_F4;
1707 if( keypress != -1 )
1708 INVOKE_WCB( *window, Special,
1710 window->State.MouseX, window->State.MouseY )
1713 fgState.Modifiers = 0xffffffff;
1724 * Remember the current modifiers state. This is done here in order
1725 * to make sure the VK_DELETE keyboard callback is executed properly.
1727 fgState.Modifiers = fghGetWin32Modifiers( );
1729 GetCursorPos( &mouse_pos );
1730 ScreenToClient( window->Window.Handle, &mouse_pos );
1732 window->State.MouseX = mouse_pos.x;
1733 window->State.MouseY = mouse_pos.y;
1736 * Convert the Win32 keystroke codes to GLUTtish way.
1737 * "KEY(a,b)" was defined under "WM_KEYDOWN"
1742 KEY( VK_F1, GLUT_KEY_F1 );
1743 KEY( VK_F2, GLUT_KEY_F2 );
1744 KEY( VK_F3, GLUT_KEY_F3 );
1745 KEY( VK_F4, GLUT_KEY_F4 );
1746 KEY( VK_F5, GLUT_KEY_F5 );
1747 KEY( VK_F6, GLUT_KEY_F6 );
1748 KEY( VK_F7, GLUT_KEY_F7 );
1749 KEY( VK_F8, GLUT_KEY_F8 );
1750 KEY( VK_F9, GLUT_KEY_F9 );
1751 KEY( VK_F10, GLUT_KEY_F10 );
1752 KEY( VK_F11, GLUT_KEY_F11 );
1753 KEY( VK_F12, GLUT_KEY_F12 );
1754 KEY( VK_PRIOR, GLUT_KEY_PAGE_UP );
1755 KEY( VK_NEXT, GLUT_KEY_PAGE_DOWN );
1756 KEY( VK_HOME, GLUT_KEY_HOME );
1757 KEY( VK_END, GLUT_KEY_END );
1758 KEY( VK_LEFT, GLUT_KEY_LEFT );
1759 KEY( VK_UP, GLUT_KEY_UP );
1760 KEY( VK_RIGHT, GLUT_KEY_RIGHT );
1761 KEY( VK_DOWN, GLUT_KEY_DOWN );
1762 KEY( VK_INSERT, GLUT_KEY_INSERT );
1766 * The delete key should be treated as an ASCII keypress:
1768 INVOKE_WCB( *window, KeyboardUp,
1769 ( 127, window->State.MouseX, window->State.MouseY )
1775 #if !TARGET_HOST_WINCE
1779 GetKeyboardState( state );
1781 if( ToAscii( wParam, 0, state, code, 0 ) == 1 )
1784 INVOKE_WCB( *window, KeyboardUp,
1786 window->State.MouseX, window->State.MouseY )
1788 #endif /* !TARGET_HOST_WINCE */
1792 if( keypress != -1 )
1793 INVOKE_WCB( *window, SpecialUp,
1795 window->State.MouseX, window->State.MouseY )
1798 fgState.Modifiers = 0xffffffff;
1805 if( (fgState.KeyRepeat==GLUT_KEY_REPEAT_OFF || window->State.IgnoreKeyRepeat==GL_TRUE) && (HIWORD(lParam) & KF_REPEAT) )
1808 fgState.Modifiers = fghGetWin32Modifiers( );
1809 INVOKE_WCB( *window, Keyboard,
1811 window->State.MouseX, window->State.MouseY )
1813 fgState.Modifiers = 0xffffffff;
1817 case WM_CAPTURECHANGED:
1818 /* User has finished resizing the window, force a redraw */
1819 INVOKE_WCB( *window, Display, ( ) );
1821 /*lRet = DefWindowProc( hWnd, uMsg, wParam, lParam ); */
1825 * Other messages that I have seen and which are not handled already
1827 case WM_SETTEXT: /* 0x000c */
1828 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1829 /* Pass it on to "DefWindowProc" to set the window text */
1832 case WM_GETTEXT: /* 0x000d */
1833 /* Ideally we would copy the title of the window into "lParam" */
1834 /* strncpy ( (char *)lParam, "Window Title", wParam );
1835 lRet = ( wParam > 12 ) ? 12 : wParam; */
1836 /* the number of characters copied */
1837 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1840 case WM_GETTEXTLENGTH: /* 0x000e */
1841 /* Ideally we would get the length of the title of the window */
1843 /* the number of characters in "Window Title\0" (see above) */
1846 case WM_ERASEBKGND: /* 0x0014 */
1847 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1850 #if !TARGET_HOST_WINCE
1851 case WM_SYNCPAINT: /* 0x0088 */
1852 /* Another window has moved, need to update this one */
1853 window->State.Redisplay = GL_TRUE;
1854 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1855 /* Help screen says this message must be passed to "DefWindowProc" */
1858 case WM_NCPAINT: /* 0x0085 */
1859 /* Need to update the border of this window */
1860 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1861 /* Pass it on to "DefWindowProc" to repaint a standard border */
1864 case WM_SYSCOMMAND : /* 0x0112 */
1867 * We have received a system command message. Try to act on it.
1868 * The commands are passed in through the "wParam" parameter:
1869 * The least significant digit seems to be which edge of the window
1870 * is being used for a resize event:
1874 * Congratulations and thanks to Richard Rauch for figuring this out..
1876 switch ( wParam & 0xfff0 )
1885 /* User has clicked on the "-" to minimize the window */
1886 /* Turn off the visibility */
1887 window->State.Visible = GL_FALSE ;
1894 case SC_NEXTWINDOW :
1897 case SC_PREVWINDOW :
1901 /* Followed very closely by a WM_CLOSE message */
1925 case SC_SCREENSAVE :
1933 fgWarning( "Unknown wParam type 0x%x", wParam );
1938 #endif /* !TARGET_HOST_WINCE */
1940 /* We need to pass the message on to the operating system as well */
1941 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1946 * Handle unhandled messages
1948 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1956 /*** END OF FILE ***/