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
45 // including gx.h does only work in c++ (thanks MS...),
46 // so we define this on our own...
48 short vkUp; // key for up
49 POINT ptUp; // x,y position of key/button. Not on screen but in screen coordinates.
65 extern void wince_GetDefaultKeys(void* nData, int iOptions);
66 extern void wince_OpenInput();
70 #define MAX(a,b) (((a)>(b)) ? (a) : (b))
74 #define MIN(a,b) (((a)<(b)) ? (a) : (b))
79 * TODO BEFORE THE STABLE RELEASE:
81 * There are some issues concerning window redrawing under X11, and maybe
82 * some events are not handled. The Win32 version lacks some more features,
83 * but seems acceptable for not demanding purposes.
85 * Need to investigate why the X11 version breaks out with an error when
86 * closing a window (using the window manager, not glutDestroyWindow)...
89 /* -- PRIVATE FUNCTIONS ---------------------------------------------------- */
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 ( SFG_WindowHandleType handle,
97 int width, int height )
99 SFG_Window *current_window = fgStructure.Window;
101 SFG_Window* window = fgWindowByHandle( handle );
102 freeglut_return_if_fail( window != NULL );
105 #if TARGET_HOST_UNIX_X11
107 XResizeWindow( fgDisplay.Display, window->Window.Handle,
109 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
111 #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE
113 #if !TARGET_HOST_WINCE
118 * For windowed mode, get the current position of the
119 * window and resize taking the size of the frame
120 * decorations into account.
123 GetWindowRect( window->Window.Handle, &rect );
124 rect.right = rect.left + width;
125 rect.bottom = rect.top + height;
127 if ( window->Parent == NULL )
129 if ( ! window->IsMenu && !window->State.IsGameMode )
131 rect.right += GetSystemMetrics( SM_CXSIZEFRAME ) * 2;
132 rect.bottom += GetSystemMetrics( SM_CYSIZEFRAME ) * 2 +
133 GetSystemMetrics( SM_CYCAPTION );
138 GetWindowRect( window->Parent->Window.Handle, &rect );
139 AdjustWindowRect ( &rect, WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS |
140 WS_CLIPCHILDREN, FALSE );
144 * SWP_NOACTIVATE Do not activate the window
145 * SWP_NOOWNERZORDER Do not change position in z-order
146 * SWP_NOSENDCHANGING Supress WM_WINDOWPOSCHANGING message
147 * SWP_NOZORDER Retains the current Z order (ignore 2nd param)
150 SetWindowPos( window->Window.Handle,
154 rect.right - rect.left,
155 rect.bottom - rect.top,
156 SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOSENDCHANGING |
160 #endif //TARGET_HOST_WINCE
163 * XXX Should update {window->State.OldWidth, window->State.OldHeight}
164 * XXX to keep in lockstep with UNIX_X11 code.
166 if( FETCH_WCB( *window, Reshape ) )
167 INVOKE_WCB( *window, Reshape, ( width, height ) );
170 fgSetWindow( window );
171 glViewport( 0, 0, width, height );
177 * Force a window redraw. In Windows at least this is only a partial
178 * solution: if the window is increasing in size in either dimension,
179 * the already-drawn part does not get drawn again and things look funny.
180 * But without this we get this bad behaviour whenever we resize the
183 window->State.Redisplay = GL_TRUE;
186 fgSetWindow( current_window );
190 * Calls a window's redraw method. This is used when
191 * a redraw is forced by the incoming window messages.
193 static void fghRedrawWindowByHandle ( SFG_WindowHandleType handle )
195 SFG_Window* window = fgWindowByHandle( handle );
196 freeglut_return_if_fail( window );
197 freeglut_return_if_fail( FETCH_WCB ( *window, Display ) );
199 window->State.Redisplay = GL_FALSE;
201 freeglut_return_if_fail( window->State.Visible );
203 if( window->State.NeedToResize )
205 SFG_Window *current_window = fgStructure.Window;
207 fgSetWindow( window );
209 fghReshapeWindowByHandle(
210 window->Window.Handle,
215 window->State.NeedToResize = GL_FALSE;
216 fgSetWindow( current_window );
219 INVOKE_WCB( *window, Display, ( ) );
223 * A static helper function to execute display callback for a window
225 static void fghcbDisplayWindow( SFG_Window *window,
226 SFG_Enumerator *enumerator )
228 if( window->State.NeedToResize )
230 SFG_Window *current_window = fgStructure.Window;
232 fgSetWindow( window );
234 fghReshapeWindowByHandle(
235 window->Window.Handle,
240 window->State.NeedToResize = GL_FALSE;
241 fgSetWindow ( current_window );
244 if( window->State.Redisplay &&
245 window->State.Visible )
247 window->State.Redisplay = GL_FALSE;
249 #if TARGET_HOST_UNIX_X11
251 SFG_Window *current_window = fgStructure.Window;
253 INVOKE_WCB( *window, Display, ( ) );
254 fgSetWindow( current_window );
256 #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE
258 window->Window.Handle, NULL, NULL,
259 RDW_NOERASE | RDW_INTERNALPAINT | RDW_INVALIDATE | RDW_UPDATENOW
264 fgEnumSubWindows( window, fghcbDisplayWindow, enumerator );
268 * Make all windows perform a display call
270 static void fghDisplayAll( void )
272 SFG_Enumerator enumerator;
274 enumerator.found = GL_FALSE;
275 enumerator.data = NULL;
277 fgEnumWindows( fghcbDisplayWindow, &enumerator );
281 * Window enumerator callback to check for the joystick polling code
283 static void fghcbCheckJoystickPolls( SFG_Window *window,
284 SFG_Enumerator *enumerator )
286 long int checkTime = fgElapsedTime( );
288 if( window->State.JoystickLastPoll + window->State.JoystickPollRate <=
291 #if !TARGET_HOST_WINCE
292 fgJoystickPollWindow( window );
293 #endif //!TARGET_HOST_WINCE
294 window->State.JoystickLastPoll = checkTime;
297 fgEnumSubWindows( window, fghcbCheckJoystickPolls, enumerator );
301 * Check all windows for joystick polling
303 static void fghCheckJoystickPolls( void )
305 SFG_Enumerator enumerator;
307 enumerator.found = GL_FALSE;
308 enumerator.data = NULL;
310 fgEnumWindows( fghcbCheckJoystickPolls, &enumerator );
314 * Check the global timers
316 static void fghCheckTimers( void )
318 long checkTime = fgElapsedTime( );
320 while( fgState.Timers.First )
322 SFG_Timer *timer = fgState.Timers.First;
324 if( timer->TriggerTime > checkTime )
327 fgListRemove( &fgState.Timers, &timer->Node );
328 fgListAppend( &fgState.FreeTimers, &timer->Node );
330 timer->Callback( timer->ID );
337 long fgElapsedTime( void )
339 if ( fgState.Time.Set )
341 #if TARGET_HOST_UNIX_X11
345 gettimeofday( &now, NULL );
347 elapsed = (now.tv_usec - fgState.Time.Value.tv_usec) / 1000;
348 elapsed += (now.tv_sec - fgState.Time.Value.tv_sec) * 1000;
351 #elif TARGET_HOST_WIN32
352 return timeGetTime() - fgState.Time.Value;
353 #elif TARGET_HOST_WINCE
354 return GetTickCount() - fgState.Time.Value;
359 #if TARGET_HOST_UNIX_X11
360 gettimeofday( &fgState.Time.Value, NULL );
361 #elif TARGET_HOST_WIN32
362 fgState.Time.Value = timeGetTime ();
363 #elif TARGET_HOST_WINCE
364 fgState.Time.Value = GetTickCount();
366 fgState.Time.Set = GL_TRUE ;
375 void fgError( const char *fmt, ... )
381 fprintf( stderr, "freeglut ");
382 if( fgState.ProgramName )
383 fprintf (stderr, "(%s): ", fgState.ProgramName);
384 vfprintf( stderr, fmt, ap );
385 fprintf( stderr, "\n" );
389 if ( fgState.Initialised )
395 void fgWarning( const char *fmt, ... )
401 fprintf( stderr, "freeglut ");
402 if( fgState.ProgramName )
403 fprintf( stderr, "(%s): ", fgState.ProgramName );
404 vfprintf( stderr, fmt, ap );
405 fprintf( stderr, "\n" );
411 * Indicates whether Joystick events are being used by ANY window.
413 * The current mechanism is to walk all of the windows and ask if
414 * there is a joystick callback. We have a short-circuit early
415 * return if we find any joystick handler registered.
417 * The real way to do this is to make use of the glutTimer() API
418 * to more cleanly re-implement the joystick API. Then, this code
419 * and all other "joystick timer" code can be yanked.
422 static void fgCheckJoystickCallback( SFG_Window* w, SFG_Enumerator* e)
424 if( FETCH_WCB( *w, Joystick ) )
429 fgEnumSubWindows( w, fgCheckJoystickCallback, e );
431 static int fgHaveJoystick( void )
433 SFG_Enumerator enumerator;
434 enumerator.found = GL_FALSE;
435 enumerator.data = NULL;
436 fgEnumWindows( fgCheckJoystickCallback, &enumerator );
437 return !!enumerator.data;
439 static void fgHavePendingRedisplaysCallback( SFG_Window* w, SFG_Enumerator* e)
441 if( w->State.Redisplay )
446 fgEnumSubWindows( w, fgHavePendingRedisplaysCallback, e );
448 static int fgHavePendingRedisplays (void)
450 SFG_Enumerator enumerator;
451 enumerator.found = GL_FALSE;
452 enumerator.data = NULL;
453 fgEnumWindows( fgHavePendingRedisplaysCallback, &enumerator );
454 return !!enumerator.data;
457 * Returns the number of GLUT ticks (milliseconds) till the next timer event.
459 static long fgNextTimer( void )
462 SFG_Timer *timer = fgState.Timers.First;
465 ret = timer->TriggerTime - fgElapsedTime();
472 * Does the magic required to relinquish the CPU until something interesting
475 static void fgSleepForEvents( void )
479 if( fgState.IdleCallback || fgHavePendingRedisplays( ) )
482 msec = fgNextTimer( );
483 if( fgHaveJoystick( ) ) /* XXX Use GLUT timers for joysticks... */
484 msec = MIN( msec, 10 ); /* XXX Dumb; forces granularity to .01sec */
486 #if TARGET_HOST_UNIX_X11
488 * Possibly due to aggressive use of XFlush() and friends,
489 * it is possible to have our socket drained but still have
490 * unprocessed events. (Or, this may just be normal with
491 * X, anyway?) We do non-trivial processing of X events
492 * after tham in event-reading loop, in any case, so we
493 * need to allow that we may have an empty socket but non-
496 if( ! XPending( fgDisplay.Display ) )
503 socket = ConnectionNumber( fgDisplay.Display );
505 FD_SET( socket, &fdset );
506 wait.tv_sec = msec / 1000;
507 wait.tv_usec = (msec % 1000) * 1000;
508 err = select( socket+1, &fdset, NULL, NULL, &wait );
511 fgWarning ( "freeglut select() error: %d\n", errno );
513 #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE
514 MsgWaitForMultipleObjects( 0, NULL, FALSE, msec, QS_ALLEVENTS );
518 #if TARGET_HOST_UNIX_X11
520 * Returns GLUT modifier mask for an XEvent.
522 int fgGetXModifiers( XEvent *event )
526 if( event->xkey.state & ( ShiftMask | LockMask ) )
527 ret |= GLUT_ACTIVE_SHIFT;
528 if( event->xkey.state & ControlMask )
529 ret |= GLUT_ACTIVE_CTRL;
530 if( event->xkey.state & Mod1Mask )
531 ret |= GLUT_ACTIVE_ALT;
538 /* -- INTERFACE FUNCTIONS -------------------------------------------------- */
541 * Executes a single iteration in the freeglut processing loop.
543 void FGAPIENTRY glutMainLoopEvent( void )
545 #if TARGET_HOST_UNIX_X11
550 * This code was repeated constantly, so here it goes into a definition:
552 #define GETWINDOW(a) \
553 window = fgWindowByHandle( event.a.window ); \
554 if( window == NULL ) \
557 #define GETMOUSE(a) \
558 window->State.MouseX = event.a.x; \
559 window->State.MouseY = event.a.y;
561 freeglut_assert_ready;
563 while( XPending( fgDisplay.Display ) )
565 XNextEvent( fgDisplay.Display, &event );
571 * Destroy the window when the WM_DELETE_WINDOW message arrives
573 if( (Atom) event.xclient.data.l[ 0 ] == fgDisplay.DeleteWindow )
575 GETWINDOW( xclient );
577 fgDestroyWindow ( window );
579 if( fgState.ActionOnWindowClose == GLUT_ACTION_EXIT )
585 fgState.ExecState = GLUT_EXEC_STATE_STOP;
591 * CreateNotify causes a configure-event so that sub-windows are
592 * handled compatibly with GLUT. Otherwise, your sub-windows
593 * (in freeglut only) will not get an initial reshape event,
594 * which can break things.
596 * GLUT presumably does this because it generally tries to treat
597 * sub-windows the same as windows.
599 * XXX Technically, GETWINDOW( xconfigure ) and
600 * XXX {event.xconfigure} may not be legit ways to get at
601 * XXX data for CreateNotify events. In practice, the data
602 * XXX is in a union which is laid out much the same either
603 * XXX way. But if you want to split hairs, this isn't legit,
604 * XXX and we should instead duplicate some code.
607 case ConfigureNotify:
608 GETWINDOW( xconfigure );
610 int width = event.xconfigure.width;
611 int height = event.xconfigure.height;
613 if( ( width != window->State.OldWidth ) ||
614 ( height != window->State.OldHeight ) )
616 window->State.OldWidth = width;
617 window->State.OldHeight = height;
618 if( FETCH_WCB( *window, Reshape ) )
619 INVOKE_WCB( *window, Reshape, ( width, height ) );
622 fgSetWindow( window );
623 glViewport( 0, 0, width, height );
625 glutPostRedisplay( );
632 * This is sent to confirm the XDestroyWindow call.
634 * XXX WHY is this commented out? Should we re-enable it?
636 /* fgAddToWindowDestroyList ( window ); */
641 * We are too dumb to process partial exposes...
643 * XXX Well, we could do it. However, it seems to only
644 * XXX be potentially useful for single-buffered (since
645 * XXX double-buffered does not respect viewport when we
646 * XXX do a buffer-swap).
649 if( event.xexpose.count == 0 )
651 GETWINDOW( xexpose );
652 fgSetWindow( window );
653 glutPostRedisplay( );
660 * If we never do anything with this, can we just not ask to
661 * get these messages?
667 * Have the client's keyboard knowledge updated (xlib.ps,
668 * page 206, says that's a good thing to do)
670 XRefreshKeyboardMapping( (XMappingEvent *) &event );
673 case VisibilityNotify:
675 GETWINDOW( xvisibility );
677 * XXX INVOKE_WCB() does this check for us.
679 if( ! FETCH_WCB( *window, WindowStatus ) )
681 fgSetWindow( window );
684 * Sending this event, the X server can notify us that the window
685 * has just acquired one of the three possible visibility states:
686 * VisibilityUnobscured, VisibilityPartiallyObscured or
687 * VisibilityFullyObscured
689 switch( event.xvisibility.state )
691 case VisibilityUnobscured:
692 INVOKE_WCB( *window, WindowStatus, ( GLUT_FULLY_RETAINED ) );
693 window->State.Visible = GL_TRUE;
696 case VisibilityPartiallyObscured:
697 INVOKE_WCB( *window, WindowStatus,
698 ( GLUT_PARTIALLY_RETAINED ) );
699 window->State.Visible = GL_TRUE;
702 case VisibilityFullyObscured:
703 INVOKE_WCB( *window, WindowStatus, ( GLUT_FULLY_COVERED ) );
704 window->State.Visible = GL_FALSE;
708 fgWarning( "Uknown X visibility state: %d",
709 event.xvisibility.state );
717 GETWINDOW( xcrossing );
718 GETMOUSE( xcrossing );
719 INVOKE_WCB( *window, Entry, ( ( EnterNotify == event.type ) ?
726 GETWINDOW( xmotion );
729 if( window->ActiveMenu )
731 if( window == window->ActiveMenu->ParentWindow )
733 window->ActiveMenu->Window->State.MouseX =
734 event.xmotion.x_root - window->ActiveMenu->X;
735 window->ActiveMenu->Window->State.MouseY =
736 event.xmotion.y_root - window->ActiveMenu->Y;
738 window->ActiveMenu->Window->State.Redisplay = GL_TRUE ;
739 fgSetWindow( window->ActiveMenu->ParentWindow );
745 * XXX For more than 5 buttons, just check {event.xmotion.state},
746 * XXX rather than a host of bit-masks? Or maybe we need to
747 * XXX track ButtonPress/ButtonRelease events in our own
750 #define BUTTON_MASK \
751 ( Button1Mask | Button2Mask | Button3Mask | Button4Mask | Button5Mask )
752 if ( event.xmotion.state & BUTTON_MASK )
753 INVOKE_WCB( *window, Motion, ( event.xmotion.x,
756 INVOKE_WCB( *window, Passive, ( event.xmotion.x,
764 GLboolean pressed = GL_TRUE;
767 if( event.type == ButtonRelease )
771 * A mouse button has been pressed or released. Traditionally,
772 * break if the window was found within the freeglut structures.
774 GETWINDOW( xbutton );
778 * An X button (at least in XFree86) is numbered from 1.
779 * A GLUT button is numbered from 0.
780 * Old GLUT passed through buttons other than just the first
781 * three, though it only gave symbolic names and official
782 * support to the first three.
784 button = event.xbutton.button - 1;
787 * XXX This comment is replicated in the WIN32 section and
788 * XXX maybe also in the menu code. Can we move the info
789 * XXX to one central place and *reference* it from here?
791 * Do not execute the application's mouse callback if a menu
792 * is hooked to this button. In that case an appropriate
793 * private call should be generated.
794 * Near as I can tell, this is the menu behaviour:
795 * - Down-click the menu button, menu not active: activate
796 * the menu with its upper left-hand corner at the mouse
798 * - Down-click any button outside the menu, menu active:
799 * deactivate the menu
800 * - Down-click any button inside the menu, menu active:
801 * select the menu entry and deactivate the menu
802 * - Up-click the menu button, menu not active: nothing happens
803 * - Up-click the menu button outside the menu, menu active:
805 * - Up-click the menu button inside the menu, menu active:
806 * select the menu entry and deactivate the menu
808 /* Window has an active menu, it absorbs any mouse click */
809 if( window->ActiveMenu )
811 if( window == window->ActiveMenu->ParentWindow )
813 window->ActiveMenu->Window->State.MouseX =
814 event.xbutton.x_root - window->ActiveMenu->X;
815 window->ActiveMenu->Window->State.MouseY =
816 event.xbutton.y_root - window->ActiveMenu->Y;
819 /* In the menu, invoke the callback and deactivate the menu*/
820 if( fgCheckActiveMenu( window->ActiveMenu->Window,
821 window->ActiveMenu ) )
824 * Save the current window and menu and set the current
825 * window to the window whose menu this is
827 SFG_Window *save_window = fgStructure.Window;
828 SFG_Menu *save_menu = fgStructure.Menu;
829 SFG_Window *parent_window =
830 window->ActiveMenu->ParentWindow;
831 fgSetWindow( parent_window );
832 fgStructure.Menu = window->ActiveMenu;
834 /* Execute the menu callback */
835 fgExecuteMenuCallback( window->ActiveMenu );
836 fgDeactivateMenu( parent_window );
838 /* Restore the current window and menu */
839 fgSetWindow( save_window );
840 fgStructure.Menu = save_menu;
844 * Outside the menu, deactivate if it's a downclick
846 * XXX This isn't enough. A downclick outside of
847 * XXX the interior of our freeglut windows should also
848 * XXX deactivate the menu. This is more complicated.
850 fgDeactivateMenu( window->ActiveMenu->ParentWindow );
853 * XXX Why does an active menu require a redisplay at
854 * XXX this point? If this can come out cleanly, then
855 * XXX it probably should do so; if not, a comment should
858 window->State.Redisplay = GL_TRUE;
863 * No active menu, let's check whether we need to activate one.
865 if( ( 0 <= button ) &&
866 ( FREEGLUT_MAX_MENUS > button ) &&
867 ( window->Menu[ button ] ) &&
871 * XXX Posting a requisite Redisplay seems bogus.
873 window->State.Redisplay = GL_TRUE;
874 fgSetWindow( window );
875 fgActivateMenu( window, button );
880 * Check if there is a mouse or mouse wheel callback hooked to the
883 if( ! FETCH_WCB( *window, Mouse ) &&
884 ! FETCH_WCB( *window, MouseWheel ) )
887 fgState.Modifiers = fgGetXModifiers( &event );
890 * Finally execute the mouse or mouse wheel callback
892 * XXX Use a symbolic constant, *not* "4"! ("3, sire!")
894 if( ( button < 3 ) || ( ! FETCH_WCB( *window, MouseWheel ) ) )
895 INVOKE_WCB( *window, Mouse, ( button,
896 pressed ? GLUT_DOWN : GLUT_UP,
903 * Map 4 and 5 to wheel zero; EVEN to +1, ODD to -1
904 * " 6 and 7 " " one; ...
906 * XXX This *should* be behind some variables/macros,
907 * XXX since the order and numbering isn't certain
908 * XXX See XFree86 configuration docs (even back in the
909 * XXX 3.x days, and especially with 4.x).
911 * XXX Note that {button} has already been decremeted
912 * XXX in mapping from X button numbering to GLUT.
914 int wheel_number = (button - 3) / 2;
920 INVOKE_WCB( *window, MouseWheel, ( wheel_number,
928 * Trash the modifiers state
930 fgState.Modifiers = 0xffffffff;
937 FGCBKeyboard keyboard_cb;
938 FGCBSpecial special_cb;
943 /* Detect auto repeated keys, if configured globally or per-window */
945 if ( fgState.KeyRepeat==GLUT_KEY_REPEAT_OFF || window->State.IgnoreKeyRepeat==GL_TRUE )
947 if (event.type==KeyRelease)
950 * Look at X11 keystate to detect repeat mode.
951 * While X11 says the key is actually held down, we'll ignore KeyRelease/KeyPress pairs.
955 XQueryKeymap( fgDisplay.Display, keys ); /* Look at X11 keystate to detect repeat mode */
957 if ( keys[event.xkey.keycode>>3] & (1<<(event.xkey.keycode%8)) )
958 window->State.KeyRepeating = GL_TRUE;
960 window->State.KeyRepeating = GL_FALSE;
964 window->State.KeyRepeating = GL_FALSE;
966 /* Cease processing this event if it is auto repeated */
968 if (window->State.KeyRepeating)
971 if( event.type == KeyPress )
973 keyboard_cb = FETCH_WCB( *window, Keyboard );
974 special_cb = FETCH_WCB( *window, Special );
978 keyboard_cb = FETCH_WCB( *window, KeyboardUp );
979 special_cb = FETCH_WCB( *window, SpecialUp );
983 * Is there a keyboard/special callback hooked for this window?
985 if( keyboard_cb || special_cb )
987 XComposeStatus composeStatus;
988 char asciiCode[ 32 ];
993 * Check for the ASCII/KeySym codes associated with the event:
995 len = XLookupString( &event.xkey, asciiCode, sizeof(asciiCode),
996 &keySym, &composeStatus
1000 * GLUT API tells us to have two separate callbacks...
1005 * ...one for the ASCII translateable keypresses...
1009 fgSetWindow( window );
1010 fgState.Modifiers = fgGetXModifiers( &event );
1011 keyboard_cb( asciiCode[ 0 ],
1012 event.xkey.x, event.xkey.y
1014 fgState.Modifiers = 0xffffffff;
1022 * ...and one for all the others, which need to be
1023 * translated to GLUT_KEY_Xs...
1027 case XK_F1: special = GLUT_KEY_F1; break;
1028 case XK_F2: special = GLUT_KEY_F2; break;
1029 case XK_F3: special = GLUT_KEY_F3; break;
1030 case XK_F4: special = GLUT_KEY_F4; break;
1031 case XK_F5: special = GLUT_KEY_F5; break;
1032 case XK_F6: special = GLUT_KEY_F6; break;
1033 case XK_F7: special = GLUT_KEY_F7; break;
1034 case XK_F8: special = GLUT_KEY_F8; break;
1035 case XK_F9: special = GLUT_KEY_F9; break;
1036 case XK_F10: special = GLUT_KEY_F10; break;
1037 case XK_F11: special = GLUT_KEY_F11; break;
1038 case XK_F12: special = GLUT_KEY_F12; break;
1040 case XK_Left: special = GLUT_KEY_LEFT; break;
1041 case XK_Right: special = GLUT_KEY_RIGHT; break;
1042 case XK_Up: special = GLUT_KEY_UP; break;
1043 case XK_Down: special = GLUT_KEY_DOWN; break;
1046 case XK_Prior: special = GLUT_KEY_PAGE_UP; break;
1048 case XK_Next: special = GLUT_KEY_PAGE_DOWN; break;
1050 case XK_Home: special = GLUT_KEY_HOME; break;
1052 case XK_End: special = GLUT_KEY_END; break;
1054 case XK_Insert: special = GLUT_KEY_INSERT; break;
1058 * Execute the callback (if one has been specified),
1059 * given that the special code seems to be valid...
1061 if( special_cb && (special != -1) )
1063 fgSetWindow( window );
1064 fgState.Modifiers = fgGetXModifiers( &event );
1065 special_cb( special, event.xkey.x, event.xkey.y );
1066 fgState.Modifiers = 0xffffffff;
1073 case ReparentNotify:
1074 break; /* XXX Should disable this event */
1077 fgWarning ("Unknown X event type: %d", event.type);
1082 #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE
1086 while( PeekMessage( &stMsg, NULL, 0, 0, PM_NOREMOVE ) )
1088 if( GetMessage( &stMsg, NULL, 0, 0 ) == 0 )
1090 if( fgState.ActionOnWindowClose == GLUT_ACTION_EXIT )
1095 fgState.ExecState = GLUT_EXEC_STATE_STOP;
1099 TranslateMessage( &stMsg );
1100 DispatchMessage( &stMsg );
1104 if( fgState.Timers.First )
1106 fghCheckJoystickPolls( );
1113 * Enters the freeglut processing loop.
1114 * Stays until the "ExecState" changes to "GLUT_EXEC_STATE_STOP".
1116 void FGAPIENTRY glutMainLoop( void )
1120 #if TARGET_HOST_WIN32 || TARGET_HOST_WINCE
1121 SFG_Window *window = (SFG_Window *)fgStructure.Windows.First ;
1124 freeglut_assert_ready;
1126 #if TARGET_HOST_WIN32 || TARGET_HOST_WINCE
1128 * Processing before the main loop: If there is a window which is open and
1129 * which has a visibility callback, call it. I know this is an ugly hack,
1130 * but I'm not sure what else to do about it. Ideally we should leave
1131 * something uninitialized in the create window code and initialize it in
1132 * the main loop, and have that initialization create a "WM_ACTIVATE"
1133 * message. Then we would put the visibility callback code in the
1134 * "case WM_ACTIVATE" block below. - John Fay -- 10/24/02
1138 if ( FETCH_WCB( *window, Visibility ) )
1140 SFG_Window *current_window = fgStructure.Window ;
1142 INVOKE_WCB( *window, Visibility, ( window->State.Visible ) );
1143 fgSetWindow( current_window );
1146 window = (SFG_Window *)window->Node.Next ;
1150 fgState.ExecState = GLUT_EXEC_STATE_RUNNING ;
1151 while( fgState.ExecState == GLUT_EXEC_STATE_RUNNING )
1155 glutMainLoopEvent( );
1157 * Step through the list of windows, seeing if there are any
1158 * that are not menus
1160 for( window = ( SFG_Window * )fgStructure.Windows.First;
1162 window = ( SFG_Window * )window->Node.Next )
1163 if ( ! ( window->IsMenu ) )
1167 fgState.ExecState = GLUT_EXEC_STATE_STOP;
1170 if( fgState.IdleCallback )
1171 fgState.IdleCallback( );
1173 fgSleepForEvents( );
1178 * When this loop terminates, destroy the display, state and structure
1179 * of a freeglut session, so that another glutInit() call can happen
1181 * Save the "ActionOnWindowClose" because "fgDeinitialize" resets it.
1183 action = fgState.ActionOnWindowClose;
1185 if( action == GLUT_ACTION_EXIT )
1190 * Leaves the freeglut processing loop.
1192 void FGAPIENTRY glutLeaveMainLoop( void )
1194 fgState.ExecState = GLUT_EXEC_STATE_STOP ;
1198 #if TARGET_HOST_WIN32 || TARGET_HOST_WINCE
1200 * Determine a GLUT modifer mask based on MS-WINDOWS system info.
1202 int fgGetWin32Modifiers (void)
1205 ( ( ( GetKeyState( VK_LSHIFT ) < 0 ) ||
1206 ( GetKeyState( VK_RSHIFT ) < 0 )) ? GLUT_ACTIVE_SHIFT : 0 ) |
1207 ( ( ( GetKeyState( VK_LCONTROL ) < 0 ) ||
1208 ( GetKeyState( VK_RCONTROL ) < 0 )) ? GLUT_ACTIVE_CTRL : 0 ) |
1209 ( ( ( GetKeyState( VK_LMENU ) < 0 ) ||
1210 ( GetKeyState( VK_RMENU ) < 0 )) ? GLUT_ACTIVE_ALT : 0 );
1214 * The window procedure for handling Win32 events
1216 LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam,
1219 SFG_Window* window = fgWindowByHandle( hWnd );
1223 if ( ( window == NULL ) && ( uMsg != WM_CREATE ) )
1224 return DefWindowProc( hWnd, uMsg, wParam, lParam );
1226 /* printf ( "Window %3d message <%04x> %12d %12d\n", window?window->ID:0,
1227 uMsg, wParam, lParam ); */
1232 * The window structure is passed as the creation structure paramter...
1234 window = (SFG_Window *) (((LPCREATESTRUCT) lParam)->lpCreateParams);
1235 assert( window != NULL );
1237 window->Window.Handle = hWnd;
1238 window->Window.Device = GetDC( hWnd );
1239 if( window->IsMenu )
1241 unsigned int current_DisplayMode = fgState.DisplayMode;
1242 fgState.DisplayMode = GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH;
1243 #if !TARGET_HOST_WINCE
1244 fgSetupPixelFormat( window, GL_FALSE, PFD_MAIN_PLANE );
1246 fgState.DisplayMode = current_DisplayMode;
1248 if( fgStructure.MenuContext )
1249 wglMakeCurrent( window->Window.Device,
1250 fgStructure.MenuContext->Context
1254 fgStructure.MenuContext =
1255 (SFG_MenuContext *)malloc( sizeof(SFG_MenuContext) );
1256 fgStructure.MenuContext->Context =
1257 wglCreateContext( window->Window.Device );
1260 /* window->Window.Context = wglGetCurrentContext (); */
1261 window->Window.Context = wglCreateContext( window->Window.Device );
1265 #if !TARGET_HOST_WINCE
1266 fgSetupPixelFormat( window, GL_FALSE, PFD_MAIN_PLANE );
1269 if( ! fgState.UseCurrentContext )
1270 window->Window.Context =
1271 wglCreateContext( window->Window.Device );
1274 window->Window.Context = wglGetCurrentContext( );
1275 if( ! window->Window.Context )
1276 window->Window.Context =
1277 wglCreateContext( window->Window.Device );
1281 window->State.NeedToResize = GL_TRUE;
1282 window->State.Width = fgState.Size.X;
1283 window->State.Height = fgState.Size.Y;
1285 ReleaseDC( window->Window.Handle, window->Window.Device );
1287 #if TARGET_HOST_WINCE
1288 // Take over button handling
1290 #endif //TARGET_HOST_WINCE
1295 * If the window is visible, then it is the user manually resizing it.
1296 * If it is not, then it is the system sending us a dummy resize with
1297 * zero dimensions on a "glutIconifyWindow" call.
1299 if( window->State.Visible )
1301 window->State.NeedToResize = GL_TRUE;
1302 #if TARGET_HOST_WINCE
1303 window->State.Width = HIWORD(lParam);
1304 window->State.Height = LOWORD(lParam);
1306 window->State.Width = LOWORD(lParam);
1307 window->State.Height = HIWORD(lParam);
1308 #endif //TARGET_HOST_WINCE
1314 printf("WM_SETFOCUS: %p\n", window );
1315 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1319 if (LOWORD(wParam) != WA_INACTIVE)
1321 /* glutSetCursor( fgStructure.Window->State.Cursor ); */
1322 printf("WM_ACTIVATE: glutSetCursor( %p, %d)\n", window,
1323 window->State.Cursor );
1324 glutSetCursor( window->State.Cursor );
1327 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1332 * XXX Why not re-use some common code with the glutSetCursor()
1333 * XXX function (or perhaps invoke glutSetCursor())?
1334 * XXX That is, why are we duplicating code, here, from
1335 * XXX glutSetCursor()? The WIN32 code should be able to just
1336 * XXX call glutSetCurdsor() instead of defining two macros
1337 * XXX and implementing a nested case in-line.
1340 /* Set the cursor AND change it for this window class. */
1341 #define MAP_CURSOR(a,b) \
1343 SetCursor( LoadCursor( NULL, b ) ); \
1346 /* Nuke the cursor AND change it for this window class. */
1347 #define ZAP_CURSOR(a,b) \
1349 SetCursor( NULL ); \
1352 if( LOWORD( lParam ) == HTCLIENT )
1353 switch( window->State.Cursor )
1355 MAP_CURSOR( GLUT_CURSOR_RIGHT_ARROW, IDC_ARROW );
1356 MAP_CURSOR( GLUT_CURSOR_LEFT_ARROW, IDC_ARROW );
1357 MAP_CURSOR( GLUT_CURSOR_INFO, IDC_HELP );
1358 MAP_CURSOR( GLUT_CURSOR_DESTROY, IDC_CROSS );
1359 MAP_CURSOR( GLUT_CURSOR_HELP, IDC_HELP );
1360 MAP_CURSOR( GLUT_CURSOR_CYCLE, IDC_SIZEALL );
1361 MAP_CURSOR( GLUT_CURSOR_SPRAY, IDC_CROSS );
1362 MAP_CURSOR( GLUT_CURSOR_WAIT, IDC_WAIT );
1363 MAP_CURSOR( GLUT_CURSOR_TEXT, IDC_UPARROW );
1364 MAP_CURSOR( GLUT_CURSOR_CROSSHAIR, IDC_CROSS );
1365 /* MAP_CURSOR( GLUT_CURSOR_NONE, IDC_NO ); */
1366 ZAP_CURSOR( GLUT_CURSOR_NONE, NULL );
1369 MAP_CURSOR( GLUT_CURSOR_UP_DOWN, IDC_ARROW );
1372 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1376 window->State.Visible = GL_TRUE;
1377 window->State.Redisplay = GL_TRUE;
1381 /* Turn on the visibility in case it was turned off somehow */
1382 window->State.Visible = GL_TRUE;
1383 BeginPaint( hWnd, &ps );
1384 fghRedrawWindowByHandle( hWnd );
1385 EndPaint( hWnd, &ps );
1389 fgDestroyWindow ( window );
1390 if ( fgState.ActionOnWindowClose != GLUT_ACTION_CONTINUE_EXECUTION )
1396 * The window already got destroyed, so don't bother with it.
1402 #if TARGET_HOST_WINCE
1403 window->State.MouseX = 320-HIWORD( lParam );
1404 window->State.MouseY = LOWORD( lParam );
1406 window->State.MouseX = LOWORD( lParam );
1407 window->State.MouseY = HIWORD( lParam );
1408 #endif //TARGET_HOST_WINCE
1410 if ( window->ActiveMenu )
1412 window->State.Redisplay = GL_TRUE;
1413 fgSetWindow ( window->ActiveMenu->ParentWindow );
1417 fgState.Modifiers = fgGetWin32Modifiers( );
1419 if( ( wParam & MK_LBUTTON ) ||
1420 ( wParam & MK_MBUTTON ) ||
1421 ( wParam & MK_RBUTTON ) )
1422 INVOKE_WCB( *window, Motion, ( window->State.MouseX,
1423 window->State.MouseY ) );
1425 INVOKE_WCB( *window, Passive, ( window->State.MouseX,
1426 window->State.MouseY ) );
1428 fgState.Modifiers = 0xffffffff;
1432 case WM_LBUTTONDOWN:
1433 case WM_MBUTTONDOWN:
1434 case WM_RBUTTONDOWN:
1439 GLboolean pressed = GL_TRUE;
1442 #if TARGET_HOST_WINCE
1443 window->State.MouseX = 320-HIWORD( lParam );
1444 window->State.MouseY = LOWORD( lParam );
1446 window->State.MouseX = LOWORD( lParam );
1447 window->State.MouseY = HIWORD( lParam );
1448 #endif //TARGET_HOST_WINCE
1452 case WM_LBUTTONDOWN:
1454 button = GLUT_LEFT_BUTTON;
1456 case WM_MBUTTONDOWN:
1458 button = GLUT_MIDDLE_BUTTON;
1460 case WM_RBUTTONDOWN:
1462 button = GLUT_RIGHT_BUTTON;
1466 button = GLUT_LEFT_BUTTON;
1470 button = GLUT_MIDDLE_BUTTON;
1474 button = GLUT_RIGHT_BUTTON;
1482 #if !TARGET_HOST_WINCE
1483 if( GetSystemMetrics( SM_SWAPBUTTON ) )
1485 if( button == GLUT_LEFT_BUTTON )
1486 button = GLUT_RIGHT_BUTTON;
1488 if( button == GLUT_RIGHT_BUTTON )
1489 button = GLUT_LEFT_BUTTON;
1491 #endif //!TARGET_HOST_WINCE
1494 return DefWindowProc( hWnd, uMsg, lParam, wParam );
1497 * XXX This comment is duplicated in two other spots.
1498 * XXX Can we centralize it?
1500 * Do not execute the application's mouse callback if a
1501 * menu is hooked to this button.
1502 * In that case an appropriate private call should be generated.
1503 * Near as I can tell, this is the menu behaviour:
1504 * - Down-click the menu button, menu not active: activate
1505 * the menu with its upper left-hand corner at the mouse location.
1506 * - Down-click any button outside the menu, menu active:
1507 * deactivate the menu
1508 * - Down-click any button inside the menu, menu active:
1509 * select the menu entry and deactivate the menu
1510 * - Up-click the menu button, menu not active: nothing happens
1511 * - Up-click the menu button outside the menu, menu active:
1513 * - Up-click the menu button inside the menu, menu active:
1514 * select the menu entry and deactivate the menu
1516 /* Window has an active menu, it absorbs any mouse click */
1517 if( window->ActiveMenu )
1519 /* Outside the menu, deactivate the menu if it's a downclick */
1520 if( ! fgCheckActiveMenu( window, window->ActiveMenu ) )
1523 fgDeactivateMenu( window->ActiveMenu->ParentWindow );
1525 else /* In menu, invoke the callback and deactivate the menu*/
1528 * Save the current window and menu and set the current
1529 * window to the window whose menu this is
1531 SFG_Window *save_window = fgStructure.Window;
1532 SFG_Menu *save_menu = fgStructure.Menu;
1533 SFG_Window *parent_window = window->ActiveMenu->ParentWindow;
1534 fgSetWindow( parent_window );
1535 fgStructure.Menu = window->ActiveMenu;
1537 /* Execute the menu callback */
1538 fgExecuteMenuCallback( window->ActiveMenu );
1539 fgDeactivateMenu( parent_window );
1541 /* Restore the current window and menu */
1542 fgSetWindow( save_window );
1543 fgStructure.Menu = save_menu;
1547 * Let's make the window redraw as a result of the mouse
1548 * click and menu activity.
1550 if( ! window->IsMenu )
1551 window->State.Redisplay = GL_TRUE;
1556 if( window->Menu[ button ] && pressed )
1558 window->State.Redisplay = GL_TRUE;
1559 fgSetWindow( window );
1560 fgActivateMenu( window, button );
1565 if( ! FETCH_WCB( *window, Mouse ) )
1568 fgSetWindow( window );
1569 fgState.Modifiers = fgGetWin32Modifiers( );
1574 pressed ? GLUT_DOWN : GLUT_UP,
1575 window->State.MouseX,
1576 window->State.MouseY
1580 fgState.Modifiers = 0xffffffff;
1585 /* Should be WM_MOUSEWHEEL but my compiler doesn't recognize it */
1588 * XXX THIS IS SPECULATIVE -- John Fay, 10/2/03
1589 * XXX Should use WHEEL_DELTA instead of 120
1591 int wheel_number = LOWORD( wParam );
1592 short ticks = ( short )HIWORD( wParam ) / 120;
1602 * The mouse cursor has moved. Remember the new mouse cursor's position
1604 /* window->State.MouseX = LOWORD( lParam ); */
1605 /* Need to adjust by window position, */
1606 /* window->State.MouseY = HIWORD( lParam ); */
1607 /* change "lParam" to other parameter */
1609 if( ! FETCH_WCB( *window, MouseWheel ) &&
1610 ! FETCH_WCB( *window, Mouse ) )
1613 fgSetWindow( window );
1614 fgState.Modifiers = fgGetWin32Modifiers( );
1617 if( FETCH_WCB( *window, MouseWheel ) )
1618 INVOKE_WCB( *window, MouseWheel,
1621 window->State.MouseX,
1622 window->State.MouseY
1625 else /* No mouse wheel, call the mouse button callback twice */
1628 * XXX The below assumes that you have no more than 3 mouse
1629 * XXX buttons. Sorry.
1631 int button = wheel_number*2 + 4;
1634 INVOKE_WCB( *window, Mouse,
1635 ( button, GLUT_DOWN,
1636 window->State.MouseX, window->State.MouseY )
1638 INVOKE_WCB( *window, Mouse,
1640 window->State.MouseX, window->State.MouseX )
1644 fgState.Modifiers = 0xffffffff;
1651 #if TARGET_HOST_WINCE
1652 struct GXKeyList gxKeyList;
1653 #endif //TARGET_HOST_WINCE
1657 if( ( fgState.KeyRepeat==GLUT_KEY_REPEAT_OFF || window->State.IgnoreKeyRepeat==GL_TRUE ) && (HIWORD(lParam) & KF_REPEAT) )
1661 * Remember the current modifiers state. This is done here in order
1662 * to make sure the VK_DELETE keyboard callback is executed properly.
1664 fgState.Modifiers = fgGetWin32Modifiers( );
1666 GetCursorPos( &mouse_pos );
1667 ScreenToClient( window->Window.Handle, &mouse_pos );
1669 window->State.MouseX = mouse_pos.x;
1670 window->State.MouseY = mouse_pos.y;
1673 * Convert the Win32 keystroke codes to GLUTtish way
1675 # define KEY(a,b) case a: keypress = b; break;
1679 KEY( VK_F1, GLUT_KEY_F1 );
1680 KEY( VK_F2, GLUT_KEY_F2 );
1681 KEY( VK_F3, GLUT_KEY_F3 );
1682 KEY( VK_F4, GLUT_KEY_F4 );
1683 KEY( VK_F5, GLUT_KEY_F5 );
1684 KEY( VK_F6, GLUT_KEY_F6 );
1685 KEY( VK_F7, GLUT_KEY_F7 );
1686 KEY( VK_F8, GLUT_KEY_F8 );
1687 KEY( VK_F9, GLUT_KEY_F9 );
1688 KEY( VK_F10, GLUT_KEY_F10 );
1689 KEY( VK_F11, GLUT_KEY_F11 );
1690 KEY( VK_F12, GLUT_KEY_F12 );
1691 KEY( VK_PRIOR, GLUT_KEY_PAGE_UP );
1692 KEY( VK_NEXT, GLUT_KEY_PAGE_DOWN );
1693 KEY( VK_HOME, GLUT_KEY_HOME );
1694 KEY( VK_END, GLUT_KEY_END );
1695 KEY( VK_LEFT, GLUT_KEY_LEFT );
1696 KEY( VK_UP, GLUT_KEY_UP );
1697 KEY( VK_RIGHT, GLUT_KEY_RIGHT );
1698 KEY( VK_DOWN, GLUT_KEY_DOWN );
1699 KEY( VK_INSERT, GLUT_KEY_INSERT );
1703 * The delete key should be treated as an ASCII keypress:
1705 INVOKE_WCB( *window, Keyboard,
1706 ( 127, window->State.MouseX, window->State.MouseY )
1710 #if TARGET_HOST_WINCE
1711 if(!(lParam & 0x40000000)) // Prevent auto-repeat
1713 wince_GetDefaultKeys(&gxKeyList, 0x03);
1715 if(wParam==(unsigned)gxKeyList.vkRight)
1716 keypress = GLUT_KEY_RIGHT;
1717 else if(wParam==(unsigned)gxKeyList.vkLeft)
1718 keypress = GLUT_KEY_LEFT;
1719 else if(wParam==(unsigned)gxKeyList.vkUp)
1720 keypress = GLUT_KEY_UP;
1721 else if(wParam==(unsigned)gxKeyList.vkDown)
1722 keypress = GLUT_KEY_DOWN;
1723 else if(wParam==(unsigned)gxKeyList.vkA)
1724 keypress = GLUT_KEY_F1;
1725 else if(wParam==(unsigned)gxKeyList.vkB)
1726 keypress = GLUT_KEY_F2;
1727 else if(wParam==(unsigned)gxKeyList.vkC)
1728 keypress = GLUT_KEY_F3;
1729 else if(wParam==(unsigned)gxKeyList.vkStart)
1730 keypress = GLUT_KEY_F4;
1734 if( keypress != -1 )
1735 INVOKE_WCB( *window, Special,
1737 window->State.MouseX, window->State.MouseY )
1740 fgState.Modifiers = 0xffffffff;
1751 * Remember the current modifiers state. This is done here in order
1752 * to make sure the VK_DELETE keyboard callback is executed properly.
1754 fgState.Modifiers = fgGetWin32Modifiers( );
1756 GetCursorPos( &mouse_pos );
1757 ScreenToClient( window->Window.Handle, &mouse_pos );
1759 window->State.MouseX = mouse_pos.x;
1760 window->State.MouseY = mouse_pos.y;
1763 * Convert the Win32 keystroke codes to GLUTtish way.
1764 * "KEY(a,b)" was defined under "WM_KEYDOWN"
1769 KEY( VK_F1, GLUT_KEY_F1 );
1770 KEY( VK_F2, GLUT_KEY_F2 );
1771 KEY( VK_F3, GLUT_KEY_F3 );
1772 KEY( VK_F4, GLUT_KEY_F4 );
1773 KEY( VK_F5, GLUT_KEY_F5 );
1774 KEY( VK_F6, GLUT_KEY_F6 );
1775 KEY( VK_F7, GLUT_KEY_F7 );
1776 KEY( VK_F8, GLUT_KEY_F8 );
1777 KEY( VK_F9, GLUT_KEY_F9 );
1778 KEY( VK_F10, GLUT_KEY_F10 );
1779 KEY( VK_F11, GLUT_KEY_F11 );
1780 KEY( VK_F12, GLUT_KEY_F12 );
1781 KEY( VK_PRIOR, GLUT_KEY_PAGE_UP );
1782 KEY( VK_NEXT, GLUT_KEY_PAGE_DOWN );
1783 KEY( VK_HOME, GLUT_KEY_HOME );
1784 KEY( VK_END, GLUT_KEY_END );
1785 KEY( VK_LEFT, GLUT_KEY_LEFT );
1786 KEY( VK_UP, GLUT_KEY_UP );
1787 KEY( VK_RIGHT, GLUT_KEY_RIGHT );
1788 KEY( VK_DOWN, GLUT_KEY_DOWN );
1789 KEY( VK_INSERT, GLUT_KEY_INSERT );
1793 * The delete key should be treated as an ASCII keypress:
1795 INVOKE_WCB( *window, KeyboardUp,
1796 ( 127, window->State.MouseX, window->State.MouseY )
1802 #if !TARGET_HOST_WINCE
1806 GetKeyboardState( state );
1808 if( ToAscii( wParam, 0, state, code, 0 ) == 1 )
1811 INVOKE_WCB( *window, KeyboardUp,
1813 window->State.MouseX, window->State.MouseY )
1815 #endif //!TARGET_HOST_WINCE
1819 if( keypress != -1 )
1820 INVOKE_WCB( *window, SpecialUp,
1822 window->State.MouseX, window->State.MouseY )
1825 fgState.Modifiers = 0xffffffff;
1832 if( (fgState.KeyRepeat==GLUT_KEY_REPEAT_OFF || window->State.IgnoreKeyRepeat==GL_TRUE) && (HIWORD(lParam) & KF_REPEAT) )
1835 fgState.Modifiers = fgGetWin32Modifiers( );
1836 INVOKE_WCB( *window, Keyboard,
1838 window->State.MouseX, window->State.MouseY )
1840 fgState.Modifiers = 0xffffffff;
1844 case WM_CAPTURECHANGED:
1845 /* User has finished resizing the window, force a redraw */
1846 INVOKE_WCB( *window, Display, ( ) );
1848 /*lRet = DefWindowProc( hWnd, uMsg, wParam, lParam ); */
1852 * Other messages that I have seen and which are not handled already
1854 case WM_SETTEXT: /* 0x000c */
1855 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1856 /* Pass it on to "DefWindowProc" to set the window text */
1859 case WM_GETTEXT: /* 0x000d */
1860 /* Ideally we would copy the title of the window into "lParam" */
1861 /* strncpy ( (char *)lParam, "Window Title", wParam );
1862 lRet = ( wParam > 12 ) ? 12 : wParam; */
1863 /* the number of characters copied */
1864 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1867 case WM_GETTEXTLENGTH: /* 0x000e */
1868 /* Ideally we would get the length of the title of the window */
1870 /* the number of characters in "Window Title\0" (see above) */
1873 case WM_ERASEBKGND: /* 0x0014 */
1874 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1877 #if !TARGET_HOST_WINCE
1878 case WM_SYNCPAINT: /* 0x0088 */
1879 /* Another window has moved, need to update this one */
1880 window->State.Redisplay = GL_TRUE;
1881 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1882 /* Help screen says this message must be passed to "DefWindowProc" */
1885 case WM_NCPAINT: /* 0x0085 */
1886 /* Need to update the border of this window */
1887 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1888 /* Pass it on to "DefWindowProc" to repaint a standard border */
1891 case WM_SYSCOMMAND : /* 0x0112 */
1894 * We have received a system command message. Try to act on it.
1895 * The commands are passed in through the "lParam" parameter:
1896 * Clicking on a corner to resize the window gives a "F004" message
1897 * but this is not defined in my header file.
1908 /* User has clicked on the "-" to minimize the window */
1909 /* Turn off the visibility */
1910 window->State.Visible = GL_FALSE ;
1917 case SC_NEXTWINDOW :
1920 case SC_PREVWINDOW :
1924 /* Followed very closely by a WM_CLOSE message */
1948 case SC_SCREENSAVE :
1955 #endif //!TARGET_HOST_WINCE
1957 /* We need to pass the message on to the operating system as well */
1958 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1963 * Handle unhandled messages
1965 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1973 /*** END OF FILE ***/