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 /*__declspec(dllimport) struct GXKeyList GXGetDefaultKeys(int iOptions);
66 __declspec(dllimport) int GXOpenInput();
69 extern void wince_GetDefaultKeys(void* nData, int iOptions);
70 extern void wince_OpenInput();
72 /*void wince_GetDefaultKeys(void* nData, int iOptions)
74 *(struct GXKeyList*)nData = GXGetDefaultKeys(iOptions);
76 void wince_OpenInput()
84 #define MAX(a,b) (((a)>(b)) ? (a) : (b))
88 #define MIN(a,b) (((a)<(b)) ? (a) : (b))
93 * TODO BEFORE THE STABLE RELEASE:
95 * There are some issues concerning window redrawing under X11, and maybe
96 * some events are not handled. The Win32 version lacks some more features,
97 * but seems acceptable for not demanding purposes.
99 * Need to investigate why the X11 version breaks out with an error when
100 * closing a window (using the window manager, not glutDestroyWindow)...
103 /* -- PRIVATE FUNCTIONS ---------------------------------------------------- */
106 * Handle a window configuration change. When no reshape
107 * callback is hooked, the viewport size is updated to
108 * match the new window size.
110 static void fghReshapeWindowByHandle ( SFG_WindowHandleType handle,
111 int width, int height )
113 SFG_Window *current_window = fgStructure.Window;
115 SFG_Window* window = fgWindowByHandle( handle );
116 freeglut_return_if_fail( window != NULL );
119 #if TARGET_HOST_UNIX_X11
121 XResizeWindow( fgDisplay.Display, window->Window.Handle,
123 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
125 #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE
127 #if !TARGET_HOST_WINCE
132 * For windowed mode, get the current position of the
133 * window and resize taking the size of the frame
134 * decorations into account.
137 GetWindowRect( window->Window.Handle, &rect );
138 rect.right = rect.left + width;
139 rect.bottom = rect.top + height;
141 if ( window->Parent == NULL )
143 if ( ! window->IsMenu && !window->State.IsGameMode )
145 rect.right += GetSystemMetrics( SM_CXSIZEFRAME ) * 2;
146 rect.bottom += GetSystemMetrics( SM_CYSIZEFRAME ) * 2 +
147 GetSystemMetrics( SM_CYCAPTION );
152 GetWindowRect( window->Parent->Window.Handle, &rect );
153 AdjustWindowRect ( &rect, WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS |
154 WS_CLIPCHILDREN, FALSE );
158 * SWP_NOACTIVATE Do not activate the window
159 * SWP_NOOWNERZORDER Do not change position in z-order
160 * SWP_NOSENDCHANGING Supress WM_WINDOWPOSCHANGING message
161 * SWP_NOZORDER Retains the current Z order (ignore 2nd param)
164 SetWindowPos( window->Window.Handle,
168 rect.right - rect.left,
169 rect.bottom - rect.top,
170 SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOSENDCHANGING |
174 #endif /* TARGET_HOST_WINCE */
177 * XXX Should update {window->State.OldWidth, window->State.OldHeight}
178 * XXX to keep in lockstep with UNIX_X11 code.
180 if( FETCH_WCB( *window, Reshape ) )
181 INVOKE_WCB( *window, Reshape, ( width, height ) );
184 fgSetWindow( window );
185 glViewport( 0, 0, width, height );
191 * Force a window redraw. In Windows at least this is only a partial
192 * solution: if the window is increasing in size in either dimension,
193 * the already-drawn part does not get drawn again and things look funny.
194 * But without this we get this bad behaviour whenever we resize the
197 window->State.Redisplay = GL_TRUE;
200 fgSetWindow( current_window );
204 * Calls a window's redraw method. This is used when
205 * a redraw is forced by the incoming window messages.
207 static void fghRedrawWindowByHandle ( SFG_WindowHandleType handle )
209 SFG_Window* window = fgWindowByHandle( handle );
210 freeglut_return_if_fail( window );
211 freeglut_return_if_fail( FETCH_WCB ( *window, Display ) );
213 window->State.Redisplay = GL_FALSE;
215 freeglut_return_if_fail( window->State.Visible );
217 if( window->State.NeedToResize )
219 SFG_Window *current_window = fgStructure.Window;
221 fgSetWindow( window );
223 fghReshapeWindowByHandle(
224 window->Window.Handle,
229 window->State.NeedToResize = GL_FALSE;
230 fgSetWindow( current_window );
233 INVOKE_WCB( *window, Display, ( ) );
237 * A static helper function to execute display callback for a window
239 static void fghcbDisplayWindow( SFG_Window *window,
240 SFG_Enumerator *enumerator )
242 if( window->State.NeedToResize )
244 SFG_Window *current_window = fgStructure.Window;
246 fgSetWindow( window );
248 fghReshapeWindowByHandle(
249 window->Window.Handle,
254 window->State.NeedToResize = GL_FALSE;
255 fgSetWindow ( current_window );
258 if( window->State.Redisplay &&
259 window->State.Visible )
261 window->State.Redisplay = GL_FALSE;
263 #if TARGET_HOST_UNIX_X11
265 SFG_Window *current_window = fgStructure.Window;
267 INVOKE_WCB( *window, Display, ( ) );
268 fgSetWindow( current_window );
270 #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE
272 window->Window.Handle, NULL, NULL,
273 RDW_NOERASE | RDW_INTERNALPAINT | RDW_INVALIDATE | RDW_UPDATENOW
278 fgEnumSubWindows( window, fghcbDisplayWindow, enumerator );
282 * Make all windows perform a display call
284 static void fghDisplayAll( void )
286 SFG_Enumerator enumerator;
288 enumerator.found = GL_FALSE;
289 enumerator.data = NULL;
291 fgEnumWindows( fghcbDisplayWindow, &enumerator );
295 * Window enumerator callback to check for the joystick polling code
297 static void fghcbCheckJoystickPolls( SFG_Window *window,
298 SFG_Enumerator *enumerator )
300 long int checkTime = fgElapsedTime( );
302 if( window->State.JoystickLastPoll + window->State.JoystickPollRate <=
305 #if !TARGET_HOST_WINCE
306 fgJoystickPollWindow( window );
307 #endif /* !TARGET_HOST_WINCE */
308 window->State.JoystickLastPoll = checkTime;
311 fgEnumSubWindows( window, fghcbCheckJoystickPolls, enumerator );
315 * Check all windows for joystick polling
317 static void fghCheckJoystickPolls( void )
319 SFG_Enumerator enumerator;
321 enumerator.found = GL_FALSE;
322 enumerator.data = NULL;
324 fgEnumWindows( fghcbCheckJoystickPolls, &enumerator );
328 * Check the global timers
330 static void fghCheckTimers( void )
332 long checkTime = fgElapsedTime( );
334 while( fgState.Timers.First )
336 SFG_Timer *timer = fgState.Timers.First;
338 if( timer->TriggerTime > checkTime )
341 fgListRemove( &fgState.Timers, &timer->Node );
342 fgListAppend( &fgState.FreeTimers, &timer->Node );
344 timer->Callback( timer->ID );
351 long fgElapsedTime( void )
353 if ( fgState.Time.Set )
355 #if TARGET_HOST_UNIX_X11
359 gettimeofday( &now, NULL );
361 elapsed = (now.tv_usec - fgState.Time.Value.tv_usec) / 1000;
362 elapsed += (now.tv_sec - fgState.Time.Value.tv_sec) * 1000;
365 #elif TARGET_HOST_WIN32
366 return timeGetTime() - fgState.Time.Value;
367 #elif TARGET_HOST_WINCE
368 return GetTickCount() - fgState.Time.Value;
373 #if TARGET_HOST_UNIX_X11
374 gettimeofday( &fgState.Time.Value, NULL );
375 #elif TARGET_HOST_WIN32
376 fgState.Time.Value = timeGetTime ();
377 #elif TARGET_HOST_WINCE
378 fgState.Time.Value = GetTickCount();
380 fgState.Time.Set = GL_TRUE ;
389 void fgError( const char *fmt, ... )
395 fprintf( stderr, "freeglut ");
396 if( fgState.ProgramName )
397 fprintf (stderr, "(%s): ", fgState.ProgramName);
398 vfprintf( stderr, fmt, ap );
399 fprintf( stderr, "\n" );
403 if ( fgState.Initialised )
409 void fgWarning( const char *fmt, ... )
415 fprintf( stderr, "freeglut ");
416 if( fgState.ProgramName )
417 fprintf( stderr, "(%s): ", fgState.ProgramName );
418 vfprintf( stderr, fmt, ap );
419 fprintf( stderr, "\n" );
425 * Indicates whether Joystick events are being used by ANY window.
427 * The current mechanism is to walk all of the windows and ask if
428 * there is a joystick callback. We have a short-circuit early
429 * return if we find any joystick handler registered.
431 * The real way to do this is to make use of the glutTimer() API
432 * to more cleanly re-implement the joystick API. Then, this code
433 * and all other "joystick timer" code can be yanked.
436 static void fgCheckJoystickCallback( SFG_Window* w, SFG_Enumerator* e)
438 if( FETCH_WCB( *w, Joystick ) )
443 fgEnumSubWindows( w, fgCheckJoystickCallback, e );
445 static int fgHaveJoystick( void )
447 SFG_Enumerator enumerator;
448 enumerator.found = GL_FALSE;
449 enumerator.data = NULL;
450 fgEnumWindows( fgCheckJoystickCallback, &enumerator );
451 return !!enumerator.data;
453 static void fgHavePendingRedisplaysCallback( SFG_Window* w, SFG_Enumerator* e)
455 if( w->State.Redisplay )
460 fgEnumSubWindows( w, fgHavePendingRedisplaysCallback, e );
462 static int fgHavePendingRedisplays (void)
464 SFG_Enumerator enumerator;
465 enumerator.found = GL_FALSE;
466 enumerator.data = NULL;
467 fgEnumWindows( fgHavePendingRedisplaysCallback, &enumerator );
468 return !!enumerator.data;
471 * Returns the number of GLUT ticks (milliseconds) till the next timer event.
473 static long fgNextTimer( void )
476 SFG_Timer *timer = fgState.Timers.First;
479 ret = timer->TriggerTime - fgElapsedTime();
486 * Does the magic required to relinquish the CPU until something interesting
489 static void fgSleepForEvents( void )
493 if( fgState.IdleCallback || fgHavePendingRedisplays( ) )
496 msec = fgNextTimer( );
497 if( fgHaveJoystick( ) ) /* XXX Use GLUT timers for joysticks... */
498 msec = MIN( msec, 10 ); /* XXX Dumb; forces granularity to .01sec */
500 #if TARGET_HOST_UNIX_X11
502 * Possibly due to aggressive use of XFlush() and friends,
503 * it is possible to have our socket drained but still have
504 * unprocessed events. (Or, this may just be normal with
505 * X, anyway?) We do non-trivial processing of X events
506 * after tham in event-reading loop, in any case, so we
507 * need to allow that we may have an empty socket but non-
510 if( ! XPending( fgDisplay.Display ) )
517 socket = ConnectionNumber( fgDisplay.Display );
519 FD_SET( socket, &fdset );
520 wait.tv_sec = msec / 1000;
521 wait.tv_usec = (msec % 1000) * 1000;
522 err = select( socket+1, &fdset, NULL, NULL, &wait );
525 fgWarning ( "freeglut select() error: %d\n", errno );
527 #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE
528 MsgWaitForMultipleObjects( 0, NULL, FALSE, msec, QS_ALLEVENTS );
532 #if TARGET_HOST_UNIX_X11
534 * Returns GLUT modifier mask for an XEvent.
536 int fgGetXModifiers( XEvent *event )
540 if( event->xkey.state & ( ShiftMask | LockMask ) )
541 ret |= GLUT_ACTIVE_SHIFT;
542 if( event->xkey.state & ControlMask )
543 ret |= GLUT_ACTIVE_CTRL;
544 if( event->xkey.state & Mod1Mask )
545 ret |= GLUT_ACTIVE_ALT;
552 /* -- INTERFACE FUNCTIONS -------------------------------------------------- */
555 * Executes a single iteration in the freeglut processing loop.
557 void FGAPIENTRY glutMainLoopEvent( void )
559 #if TARGET_HOST_UNIX_X11
564 * This code was repeated constantly, so here it goes into a definition:
566 #define GETWINDOW(a) \
567 window = fgWindowByHandle( event.a.window ); \
568 if( window == NULL ) \
571 #define GETMOUSE(a) \
572 window->State.MouseX = event.a.x; \
573 window->State.MouseY = event.a.y;
575 freeglut_assert_ready;
577 while( XPending( fgDisplay.Display ) )
579 XNextEvent( fgDisplay.Display, &event );
585 * Destroy the window when the WM_DELETE_WINDOW message arrives
587 if( (Atom) event.xclient.data.l[ 0 ] == fgDisplay.DeleteWindow )
589 GETWINDOW( xclient );
591 fgDestroyWindow ( window );
593 if( fgState.ActionOnWindowClose == GLUT_ACTION_EXIT )
599 fgState.ExecState = GLUT_EXEC_STATE_STOP;
605 * CreateNotify causes a configure-event so that sub-windows are
606 * handled compatibly with GLUT. Otherwise, your sub-windows
607 * (in freeglut only) will not get an initial reshape event,
608 * which can break things.
610 * GLUT presumably does this because it generally tries to treat
611 * sub-windows the same as windows.
613 * XXX Technically, GETWINDOW( xconfigure ) and
614 * XXX {event.xconfigure} may not be legit ways to get at
615 * XXX data for CreateNotify events. In practice, the data
616 * XXX is in a union which is laid out much the same either
617 * XXX way. But if you want to split hairs, this isn't legit,
618 * XXX and we should instead duplicate some code.
621 case ConfigureNotify:
622 GETWINDOW( xconfigure );
624 int width = event.xconfigure.width;
625 int height = event.xconfigure.height;
627 if( ( width != window->State.OldWidth ) ||
628 ( height != window->State.OldHeight ) )
630 window->State.OldWidth = width;
631 window->State.OldHeight = height;
632 if( FETCH_WCB( *window, Reshape ) )
633 INVOKE_WCB( *window, Reshape, ( width, height ) );
636 fgSetWindow( window );
637 glViewport( 0, 0, width, height );
639 glutPostRedisplay( );
646 * This is sent to confirm the XDestroyWindow call.
648 * XXX WHY is this commented out? Should we re-enable it?
650 /* fgAddToWindowDestroyList ( window ); */
655 * We are too dumb to process partial exposes...
657 * XXX Well, we could do it. However, it seems to only
658 * XXX be potentially useful for single-buffered (since
659 * XXX double-buffered does not respect viewport when we
660 * XXX do a buffer-swap).
663 if( event.xexpose.count == 0 )
665 GETWINDOW( xexpose );
666 fgSetWindow( window );
667 glutPostRedisplay( );
674 * If we never do anything with this, can we just not ask to
675 * get these messages?
681 * Have the client's keyboard knowledge updated (xlib.ps,
682 * page 206, says that's a good thing to do)
684 XRefreshKeyboardMapping( (XMappingEvent *) &event );
687 case VisibilityNotify:
689 GETWINDOW( xvisibility );
691 * XXX INVOKE_WCB() does this check for us.
693 if( ! FETCH_WCB( *window, WindowStatus ) )
695 fgSetWindow( window );
698 * Sending this event, the X server can notify us that the window
699 * has just acquired one of the three possible visibility states:
700 * VisibilityUnobscured, VisibilityPartiallyObscured or
701 * VisibilityFullyObscured
703 switch( event.xvisibility.state )
705 case VisibilityUnobscured:
706 INVOKE_WCB( *window, WindowStatus, ( GLUT_FULLY_RETAINED ) );
707 window->State.Visible = GL_TRUE;
710 case VisibilityPartiallyObscured:
711 INVOKE_WCB( *window, WindowStatus,
712 ( GLUT_PARTIALLY_RETAINED ) );
713 window->State.Visible = GL_TRUE;
716 case VisibilityFullyObscured:
717 INVOKE_WCB( *window, WindowStatus, ( GLUT_FULLY_COVERED ) );
718 window->State.Visible = GL_FALSE;
722 fgWarning( "Uknown X visibility state: %d",
723 event.xvisibility.state );
731 GETWINDOW( xcrossing );
732 GETMOUSE( xcrossing );
733 INVOKE_WCB( *window, Entry, ( ( EnterNotify == event.type ) ?
740 GETWINDOW( xmotion );
743 if( window->ActiveMenu )
745 if( window == window->ActiveMenu->ParentWindow )
747 window->ActiveMenu->Window->State.MouseX =
748 event.xmotion.x_root - window->ActiveMenu->X;
749 window->ActiveMenu->Window->State.MouseY =
750 event.xmotion.y_root - window->ActiveMenu->Y;
752 window->ActiveMenu->Window->State.Redisplay = GL_TRUE ;
753 fgSetWindow( window->ActiveMenu->ParentWindow );
759 * XXX For more than 5 buttons, just check {event.xmotion.state},
760 * XXX rather than a host of bit-masks? Or maybe we need to
761 * XXX track ButtonPress/ButtonRelease events in our own
764 #define BUTTON_MASK \
765 ( Button1Mask | Button2Mask | Button3Mask | Button4Mask | Button5Mask )
766 if ( event.xmotion.state & BUTTON_MASK )
767 INVOKE_WCB( *window, Motion, ( event.xmotion.x,
770 INVOKE_WCB( *window, Passive, ( event.xmotion.x,
778 GLboolean pressed = GL_TRUE;
781 if( event.type == ButtonRelease )
785 * A mouse button has been pressed or released. Traditionally,
786 * break if the window was found within the freeglut structures.
788 GETWINDOW( xbutton );
792 * An X button (at least in XFree86) is numbered from 1.
793 * A GLUT button is numbered from 0.
794 * Old GLUT passed through buttons other than just the first
795 * three, though it only gave symbolic names and official
796 * support to the first three.
798 button = event.xbutton.button - 1;
801 * XXX This comment is replicated in the WIN32 section and
802 * XXX maybe also in the menu code. Can we move the info
803 * XXX to one central place and *reference* it from here?
805 * Do not execute the application's mouse callback if a menu
806 * is hooked to this button. In that case an appropriate
807 * private call should be generated.
808 * Near as I can tell, this is the menu behaviour:
809 * - Down-click the menu button, menu not active: activate
810 * the menu with its upper left-hand corner at the mouse
812 * - Down-click any button outside the menu, menu active:
813 * deactivate the menu
814 * - Down-click any button inside the menu, menu active:
815 * select the menu entry and deactivate the menu
816 * - Up-click the menu button, menu not active: nothing happens
817 * - Up-click the menu button outside the menu, menu active:
819 * - Up-click the menu button inside the menu, menu active:
820 * select the menu entry and deactivate the menu
822 /* Window has an active menu, it absorbs any mouse click */
823 if( window->ActiveMenu )
825 if( window == window->ActiveMenu->ParentWindow )
827 window->ActiveMenu->Window->State.MouseX =
828 event.xbutton.x_root - window->ActiveMenu->X;
829 window->ActiveMenu->Window->State.MouseY =
830 event.xbutton.y_root - window->ActiveMenu->Y;
833 /* In the menu, invoke the callback and deactivate the menu*/
834 if( fgCheckActiveMenu( window->ActiveMenu->Window,
835 window->ActiveMenu ) )
838 * Save the current window and menu and set the current
839 * window to the window whose menu this is
841 SFG_Window *save_window = fgStructure.Window;
842 SFG_Menu *save_menu = fgStructure.Menu;
843 SFG_Window *parent_window =
844 window->ActiveMenu->ParentWindow;
845 fgSetWindow( parent_window );
846 fgStructure.Menu = window->ActiveMenu;
848 /* Execute the menu callback */
849 fgExecuteMenuCallback( window->ActiveMenu );
850 fgDeactivateMenu( parent_window );
852 /* Restore the current window and menu */
853 fgSetWindow( save_window );
854 fgStructure.Menu = save_menu;
858 * Outside the menu, deactivate if it's a downclick
860 * XXX This isn't enough. A downclick outside of
861 * XXX the interior of our freeglut windows should also
862 * XXX deactivate the menu. This is more complicated.
864 fgDeactivateMenu( window->ActiveMenu->ParentWindow );
867 * XXX Why does an active menu require a redisplay at
868 * XXX this point? If this can come out cleanly, then
869 * XXX it probably should do so; if not, a comment should
872 window->State.Redisplay = GL_TRUE;
877 * No active menu, let's check whether we need to activate one.
879 if( ( 0 <= button ) &&
880 ( FREEGLUT_MAX_MENUS > button ) &&
881 ( window->Menu[ button ] ) &&
885 * XXX Posting a requisite Redisplay seems bogus.
887 window->State.Redisplay = GL_TRUE;
888 fgSetWindow( window );
889 fgActivateMenu( window, button );
894 * Check if there is a mouse or mouse wheel callback hooked to the
897 if( ! FETCH_WCB( *window, Mouse ) &&
898 ! FETCH_WCB( *window, MouseWheel ) )
901 fgState.Modifiers = fgGetXModifiers( &event );
904 * Finally execute the mouse or mouse wheel callback
906 * XXX Use a symbolic constant, *not* "4"! ("3, sire!")
908 if( ( button < 3 ) || ( ! FETCH_WCB( *window, MouseWheel ) ) )
909 INVOKE_WCB( *window, Mouse, ( button,
910 pressed ? GLUT_DOWN : GLUT_UP,
917 * Map 4 and 5 to wheel zero; EVEN to +1, ODD to -1
918 * " 6 and 7 " " one; ...
920 * XXX This *should* be behind some variables/macros,
921 * XXX since the order and numbering isn't certain
922 * XXX See XFree86 configuration docs (even back in the
923 * XXX 3.x days, and especially with 4.x).
925 * XXX Note that {button} has already been decremeted
926 * XXX in mapping from X button numbering to GLUT.
928 int wheel_number = (button - 3) / 2;
934 INVOKE_WCB( *window, MouseWheel, ( wheel_number,
942 * Trash the modifiers state
944 fgState.Modifiers = 0xffffffff;
951 FGCBKeyboard keyboard_cb;
952 FGCBSpecial special_cb;
957 /* Detect auto repeated keys, if configured globally or per-window */
959 if ( fgState.KeyRepeat==GLUT_KEY_REPEAT_OFF || window->State.IgnoreKeyRepeat==GL_TRUE )
961 if (event.type==KeyRelease)
964 * Look at X11 keystate to detect repeat mode.
965 * While X11 says the key is actually held down, we'll ignore KeyRelease/KeyPress pairs.
969 XQueryKeymap( fgDisplay.Display, keys ); /* Look at X11 keystate to detect repeat mode */
971 if ( event.xkey.keycode<256 ) /* XQueryKeymap is limited to 256 keycodes */
973 if ( keys[event.xkey.keycode>>3] & (1<<(event.xkey.keycode%8)) )
974 window->State.KeyRepeating = GL_TRUE;
976 window->State.KeyRepeating = GL_FALSE;
981 window->State.KeyRepeating = GL_FALSE;
983 /* Cease processing this event if it is auto repeated */
985 if (window->State.KeyRepeating)
988 if( event.type == KeyPress )
990 keyboard_cb = FETCH_WCB( *window, Keyboard );
991 special_cb = FETCH_WCB( *window, Special );
995 keyboard_cb = FETCH_WCB( *window, KeyboardUp );
996 special_cb = FETCH_WCB( *window, SpecialUp );
1000 * Is there a keyboard/special callback hooked for this window?
1002 if( keyboard_cb || special_cb )
1004 XComposeStatus composeStatus;
1005 char asciiCode[ 32 ];
1010 * Check for the ASCII/KeySym codes associated with the event:
1012 len = XLookupString( &event.xkey, asciiCode, sizeof(asciiCode),
1013 &keySym, &composeStatus
1017 * GLUT API tells us to have two separate callbacks...
1022 * ...one for the ASCII translateable keypresses...
1026 fgSetWindow( window );
1027 fgState.Modifiers = fgGetXModifiers( &event );
1028 keyboard_cb( asciiCode[ 0 ],
1029 event.xkey.x, event.xkey.y
1031 fgState.Modifiers = 0xffffffff;
1039 * ...and one for all the others, which need to be
1040 * translated to GLUT_KEY_Xs...
1044 case XK_F1: special = GLUT_KEY_F1; break;
1045 case XK_F2: special = GLUT_KEY_F2; break;
1046 case XK_F3: special = GLUT_KEY_F3; break;
1047 case XK_F4: special = GLUT_KEY_F4; break;
1048 case XK_F5: special = GLUT_KEY_F5; break;
1049 case XK_F6: special = GLUT_KEY_F6; break;
1050 case XK_F7: special = GLUT_KEY_F7; break;
1051 case XK_F8: special = GLUT_KEY_F8; break;
1052 case XK_F9: special = GLUT_KEY_F9; break;
1053 case XK_F10: special = GLUT_KEY_F10; break;
1054 case XK_F11: special = GLUT_KEY_F11; break;
1055 case XK_F12: special = GLUT_KEY_F12; break;
1057 case XK_Left: special = GLUT_KEY_LEFT; break;
1058 case XK_Right: special = GLUT_KEY_RIGHT; break;
1059 case XK_Up: special = GLUT_KEY_UP; break;
1060 case XK_Down: special = GLUT_KEY_DOWN; break;
1063 case XK_Prior: special = GLUT_KEY_PAGE_UP; break;
1065 case XK_Next: special = GLUT_KEY_PAGE_DOWN; break;
1067 case XK_Home: special = GLUT_KEY_HOME; break;
1069 case XK_End: special = GLUT_KEY_END; break;
1071 case XK_Insert: special = GLUT_KEY_INSERT; break;
1075 * Execute the callback (if one has been specified),
1076 * given that the special code seems to be valid...
1078 if( special_cb && (special != -1) )
1080 fgSetWindow( window );
1081 fgState.Modifiers = fgGetXModifiers( &event );
1082 special_cb( special, event.xkey.x, event.xkey.y );
1083 fgState.Modifiers = 0xffffffff;
1090 case ReparentNotify:
1091 break; /* XXX Should disable this event */
1094 fgWarning ("Unknown X event type: %d", event.type);
1099 #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE
1103 while( PeekMessage( &stMsg, NULL, 0, 0, PM_NOREMOVE ) )
1105 if( GetMessage( &stMsg, NULL, 0, 0 ) == 0 )
1107 if( fgState.ActionOnWindowClose == GLUT_ACTION_EXIT )
1112 fgState.ExecState = GLUT_EXEC_STATE_STOP;
1116 TranslateMessage( &stMsg );
1117 DispatchMessage( &stMsg );
1121 if( fgState.Timers.First )
1123 fghCheckJoystickPolls( );
1130 * Enters the freeglut processing loop.
1131 * Stays until the "ExecState" changes to "GLUT_EXEC_STATE_STOP".
1133 void FGAPIENTRY glutMainLoop( void )
1137 #if TARGET_HOST_WIN32 || TARGET_HOST_WINCE
1138 SFG_Window *window = (SFG_Window *)fgStructure.Windows.First ;
1141 freeglut_assert_ready;
1143 #if TARGET_HOST_WIN32 || TARGET_HOST_WINCE
1145 * Processing before the main loop: If there is a window which is open and
1146 * which has a visibility callback, call it. I know this is an ugly hack,
1147 * but I'm not sure what else to do about it. Ideally we should leave
1148 * something uninitialized in the create window code and initialize it in
1149 * the main loop, and have that initialization create a "WM_ACTIVATE"
1150 * message. Then we would put the visibility callback code in the
1151 * "case WM_ACTIVATE" block below. - John Fay -- 10/24/02
1155 if ( FETCH_WCB( *window, Visibility ) )
1157 SFG_Window *current_window = fgStructure.Window ;
1159 INVOKE_WCB( *window, Visibility, ( window->State.Visible ) );
1160 fgSetWindow( current_window );
1163 window = (SFG_Window *)window->Node.Next ;
1167 fgState.ExecState = GLUT_EXEC_STATE_RUNNING ;
1168 while( fgState.ExecState == GLUT_EXEC_STATE_RUNNING )
1172 glutMainLoopEvent( );
1174 * Step through the list of windows, seeing if there are any
1175 * that are not menus
1177 for( window = ( SFG_Window * )fgStructure.Windows.First;
1179 window = ( SFG_Window * )window->Node.Next )
1180 if ( ! ( window->IsMenu ) )
1184 fgState.ExecState = GLUT_EXEC_STATE_STOP;
1187 if( fgState.IdleCallback )
1188 fgState.IdleCallback( );
1190 fgSleepForEvents( );
1195 * When this loop terminates, destroy the display, state and structure
1196 * of a freeglut session, so that another glutInit() call can happen
1198 * Save the "ActionOnWindowClose" because "fgDeinitialize" resets it.
1200 action = fgState.ActionOnWindowClose;
1202 if( action == GLUT_ACTION_EXIT )
1207 * Leaves the freeglut processing loop.
1209 void FGAPIENTRY glutLeaveMainLoop( void )
1211 fgState.ExecState = GLUT_EXEC_STATE_STOP ;
1215 #if TARGET_HOST_WIN32 || TARGET_HOST_WINCE
1217 * Determine a GLUT modifer mask based on MS-WINDOWS system info.
1219 int fgGetWin32Modifiers (void)
1222 ( ( ( GetKeyState( VK_LSHIFT ) < 0 ) ||
1223 ( GetKeyState( VK_RSHIFT ) < 0 )) ? GLUT_ACTIVE_SHIFT : 0 ) |
1224 ( ( ( GetKeyState( VK_LCONTROL ) < 0 ) ||
1225 ( GetKeyState( VK_RCONTROL ) < 0 )) ? GLUT_ACTIVE_CTRL : 0 ) |
1226 ( ( ( GetKeyState( VK_LMENU ) < 0 ) ||
1227 ( GetKeyState( VK_RMENU ) < 0 )) ? GLUT_ACTIVE_ALT : 0 );
1231 * The window procedure for handling Win32 events
1233 LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam,
1236 SFG_Window* window = fgWindowByHandle( hWnd );
1240 if ( ( window == NULL ) && ( uMsg != WM_CREATE ) )
1241 return DefWindowProc( hWnd, uMsg, wParam, lParam );
1243 /* printf ( "Window %3d message <%04x> %12d %12d\n", window?window->ID:0,
1244 uMsg, wParam, lParam ); */
1249 * The window structure is passed as the creation structure paramter...
1251 window = (SFG_Window *) (((LPCREATESTRUCT) lParam)->lpCreateParams);
1252 assert( window != NULL );
1254 window->Window.Handle = hWnd;
1255 window->Window.Device = GetDC( hWnd );
1256 if( window->IsMenu )
1258 unsigned int current_DisplayMode = fgState.DisplayMode;
1259 fgState.DisplayMode = GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH;
1260 #if !TARGET_HOST_WINCE
1261 fgSetupPixelFormat( window, GL_FALSE, PFD_MAIN_PLANE );
1263 fgState.DisplayMode = current_DisplayMode;
1265 if( fgStructure.MenuContext )
1266 wglMakeCurrent( window->Window.Device,
1267 fgStructure.MenuContext->Context
1271 fgStructure.MenuContext =
1272 (SFG_MenuContext *)malloc( sizeof(SFG_MenuContext) );
1273 fgStructure.MenuContext->Context =
1274 wglCreateContext( window->Window.Device );
1277 /* window->Window.Context = wglGetCurrentContext (); */
1278 window->Window.Context = wglCreateContext( window->Window.Device );
1282 #if !TARGET_HOST_WINCE
1283 fgSetupPixelFormat( window, GL_FALSE, PFD_MAIN_PLANE );
1286 if( ! fgState.UseCurrentContext )
1287 window->Window.Context =
1288 wglCreateContext( window->Window.Device );
1291 window->Window.Context = wglGetCurrentContext( );
1292 if( ! window->Window.Context )
1293 window->Window.Context =
1294 wglCreateContext( window->Window.Device );
1298 window->State.NeedToResize = GL_TRUE;
1299 window->State.Width = fgState.Size.X;
1300 window->State.Height = fgState.Size.Y;
1302 ReleaseDC( window->Window.Handle, window->Window.Device );
1304 #if TARGET_HOST_WINCE
1305 // Take over button handling
1307 #endif /* TARGET_HOST_WINCE */
1312 * If the window is visible, then it is the user manually resizing it.
1313 * If it is not, then it is the system sending us a dummy resize with
1314 * zero dimensions on a "glutIconifyWindow" call.
1316 if( window->State.Visible )
1318 window->State.NeedToResize = GL_TRUE;
1319 #if TARGET_HOST_WINCE
1320 window->State.Width = HIWORD(lParam);
1321 window->State.Height = LOWORD(lParam);
1323 window->State.Width = LOWORD(lParam);
1324 window->State.Height = HIWORD(lParam);
1325 #endif /* TARGET_HOST_WINCE */
1331 printf("WM_SETFOCUS: %p\n", window );
1332 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1336 if (LOWORD(wParam) != WA_INACTIVE)
1338 /* glutSetCursor( fgStructure.Window->State.Cursor ); */
1339 printf("WM_ACTIVATE: glutSetCursor( %p, %d)\n", window,
1340 window->State.Cursor );
1341 glutSetCursor( window->State.Cursor );
1344 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1349 * XXX Why not re-use some common code with the glutSetCursor()
1350 * XXX function (or perhaps invoke glutSetCursor())?
1351 * XXX That is, why are we duplicating code, here, from
1352 * XXX glutSetCursor()? The WIN32 code should be able to just
1353 * XXX call glutSetCurdsor() instead of defining two macros
1354 * XXX and implementing a nested case in-line.
1357 /* Set the cursor AND change it for this window class. */
1358 #define MAP_CURSOR(a,b) \
1360 SetCursor( LoadCursor( NULL, b ) ); \
1363 /* Nuke the cursor AND change it for this window class. */
1364 #define ZAP_CURSOR(a,b) \
1366 SetCursor( NULL ); \
1369 if( LOWORD( lParam ) == HTCLIENT )
1370 switch( window->State.Cursor )
1372 MAP_CURSOR( GLUT_CURSOR_RIGHT_ARROW, IDC_ARROW );
1373 MAP_CURSOR( GLUT_CURSOR_LEFT_ARROW, IDC_ARROW );
1374 MAP_CURSOR( GLUT_CURSOR_INFO, IDC_HELP );
1375 MAP_CURSOR( GLUT_CURSOR_DESTROY, IDC_CROSS );
1376 MAP_CURSOR( GLUT_CURSOR_HELP, IDC_HELP );
1377 MAP_CURSOR( GLUT_CURSOR_CYCLE, IDC_SIZEALL );
1378 MAP_CURSOR( GLUT_CURSOR_SPRAY, IDC_CROSS );
1379 MAP_CURSOR( GLUT_CURSOR_WAIT, IDC_WAIT );
1380 MAP_CURSOR( GLUT_CURSOR_TEXT, IDC_UPARROW );
1381 MAP_CURSOR( GLUT_CURSOR_CROSSHAIR, IDC_CROSS );
1382 /* MAP_CURSOR( GLUT_CURSOR_NONE, IDC_NO ); */
1383 ZAP_CURSOR( GLUT_CURSOR_NONE, NULL );
1386 MAP_CURSOR( GLUT_CURSOR_UP_DOWN, IDC_ARROW );
1389 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1393 window->State.Visible = GL_TRUE;
1394 window->State.Redisplay = GL_TRUE;
1398 /* Turn on the visibility in case it was turned off somehow */
1399 window->State.Visible = GL_TRUE;
1400 BeginPaint( hWnd, &ps );
1401 fghRedrawWindowByHandle( hWnd );
1402 EndPaint( hWnd, &ps );
1406 fgDestroyWindow ( window );
1407 if ( fgState.ActionOnWindowClose != GLUT_ACTION_CONTINUE_EXECUTION )
1413 * The window already got destroyed, so don't bother with it.
1419 #if TARGET_HOST_WINCE
1420 window->State.MouseX = 320-HIWORD( lParam );
1421 window->State.MouseY = LOWORD( lParam );
1423 window->State.MouseX = LOWORD( lParam );
1424 window->State.MouseY = HIWORD( lParam );
1425 #endif /* TARGET_HOST_WINCE */
1427 if ( window->ActiveMenu )
1429 window->State.Redisplay = GL_TRUE;
1430 fgSetWindow ( window->ActiveMenu->ParentWindow );
1434 fgState.Modifiers = fgGetWin32Modifiers( );
1436 if( ( wParam & MK_LBUTTON ) ||
1437 ( wParam & MK_MBUTTON ) ||
1438 ( wParam & MK_RBUTTON ) )
1439 INVOKE_WCB( *window, Motion, ( window->State.MouseX,
1440 window->State.MouseY ) );
1442 INVOKE_WCB( *window, Passive, ( window->State.MouseX,
1443 window->State.MouseY ) );
1445 fgState.Modifiers = 0xffffffff;
1449 case WM_LBUTTONDOWN:
1450 case WM_MBUTTONDOWN:
1451 case WM_RBUTTONDOWN:
1456 GLboolean pressed = GL_TRUE;
1459 #if TARGET_HOST_WINCE
1460 window->State.MouseX = 320-HIWORD( lParam );
1461 window->State.MouseY = LOWORD( lParam );
1463 window->State.MouseX = LOWORD( lParam );
1464 window->State.MouseY = HIWORD( lParam );
1465 #endif /* TARGET_HOST_WINCE */
1469 case WM_LBUTTONDOWN:
1471 button = GLUT_LEFT_BUTTON;
1473 case WM_MBUTTONDOWN:
1475 button = GLUT_MIDDLE_BUTTON;
1477 case WM_RBUTTONDOWN:
1479 button = GLUT_RIGHT_BUTTON;
1483 button = GLUT_LEFT_BUTTON;
1487 button = GLUT_MIDDLE_BUTTON;
1491 button = GLUT_RIGHT_BUTTON;
1499 #if !TARGET_HOST_WINCE
1500 if( GetSystemMetrics( SM_SWAPBUTTON ) )
1502 if( button == GLUT_LEFT_BUTTON )
1503 button = GLUT_RIGHT_BUTTON;
1505 if( button == GLUT_RIGHT_BUTTON )
1506 button = GLUT_LEFT_BUTTON;
1508 #endif /* !TARGET_HOST_WINCE */
1511 return DefWindowProc( hWnd, uMsg, lParam, wParam );
1514 * XXX This comment is duplicated in two other spots.
1515 * XXX Can we centralize it?
1517 * Do not execute the application's mouse callback if a
1518 * menu is hooked to this button.
1519 * In that case an appropriate private call should be generated.
1520 * Near as I can tell, this is the menu behaviour:
1521 * - Down-click the menu button, menu not active: activate
1522 * the menu with its upper left-hand corner at the mouse location.
1523 * - Down-click any button outside the menu, menu active:
1524 * deactivate the menu
1525 * - Down-click any button inside the menu, menu active:
1526 * select the menu entry and deactivate the menu
1527 * - Up-click the menu button, menu not active: nothing happens
1528 * - Up-click the menu button outside the menu, menu active:
1530 * - Up-click the menu button inside the menu, menu active:
1531 * select the menu entry and deactivate the menu
1533 /* Window has an active menu, it absorbs any mouse click */
1534 if( window->ActiveMenu )
1536 /* Outside the menu, deactivate the menu if it's a downclick */
1537 if( ! fgCheckActiveMenu( window, window->ActiveMenu ) )
1540 fgDeactivateMenu( window->ActiveMenu->ParentWindow );
1542 else /* In menu, invoke the callback and deactivate the menu*/
1545 * Save the current window and menu and set the current
1546 * window to the window whose menu this is
1548 SFG_Window *save_window = fgStructure.Window;
1549 SFG_Menu *save_menu = fgStructure.Menu;
1550 SFG_Window *parent_window = window->ActiveMenu->ParentWindow;
1551 fgSetWindow( parent_window );
1552 fgStructure.Menu = window->ActiveMenu;
1554 /* Execute the menu callback */
1555 fgExecuteMenuCallback( window->ActiveMenu );
1556 fgDeactivateMenu( parent_window );
1558 /* Restore the current window and menu */
1559 fgSetWindow( save_window );
1560 fgStructure.Menu = save_menu;
1564 * Let's make the window redraw as a result of the mouse
1565 * click and menu activity.
1567 if( ! window->IsMenu )
1568 window->State.Redisplay = GL_TRUE;
1573 if( window->Menu[ button ] && pressed )
1575 window->State.Redisplay = GL_TRUE;
1576 fgSetWindow( window );
1577 fgActivateMenu( window, button );
1582 if( ! FETCH_WCB( *window, Mouse ) )
1585 fgSetWindow( window );
1586 fgState.Modifiers = fgGetWin32Modifiers( );
1591 pressed ? GLUT_DOWN : GLUT_UP,
1592 window->State.MouseX,
1593 window->State.MouseY
1597 fgState.Modifiers = 0xffffffff;
1602 /* Should be WM_MOUSEWHEEL but my compiler doesn't recognize it */
1605 * XXX THIS IS SPECULATIVE -- John Fay, 10/2/03
1606 * XXX Should use WHEEL_DELTA instead of 120
1608 int wheel_number = LOWORD( wParam );
1609 short ticks = ( short )HIWORD( wParam ) / 120;
1619 * The mouse cursor has moved. Remember the new mouse cursor's position
1621 /* window->State.MouseX = LOWORD( lParam ); */
1622 /* Need to adjust by window position, */
1623 /* window->State.MouseY = HIWORD( lParam ); */
1624 /* change "lParam" to other parameter */
1626 if( ! FETCH_WCB( *window, MouseWheel ) &&
1627 ! FETCH_WCB( *window, Mouse ) )
1630 fgSetWindow( window );
1631 fgState.Modifiers = fgGetWin32Modifiers( );
1634 if( FETCH_WCB( *window, MouseWheel ) )
1635 INVOKE_WCB( *window, MouseWheel,
1638 window->State.MouseX,
1639 window->State.MouseY
1642 else /* No mouse wheel, call the mouse button callback twice */
1645 * XXX The below assumes that you have no more than 3 mouse
1646 * XXX buttons. Sorry.
1648 int button = wheel_number*2 + 4;
1651 INVOKE_WCB( *window, Mouse,
1652 ( button, GLUT_DOWN,
1653 window->State.MouseX, window->State.MouseY )
1655 INVOKE_WCB( *window, Mouse,
1657 window->State.MouseX, window->State.MouseX )
1661 fgState.Modifiers = 0xffffffff;
1668 #if TARGET_HOST_WINCE
1669 struct GXKeyList gxKeyList;
1670 #endif /* TARGET_HOST_WINCE */
1674 if( ( fgState.KeyRepeat==GLUT_KEY_REPEAT_OFF || window->State.IgnoreKeyRepeat==GL_TRUE ) && (HIWORD(lParam) & KF_REPEAT) )
1678 * Remember the current modifiers state. This is done here in order
1679 * to make sure the VK_DELETE keyboard callback is executed properly.
1681 fgState.Modifiers = fgGetWin32Modifiers( );
1683 GetCursorPos( &mouse_pos );
1684 ScreenToClient( window->Window.Handle, &mouse_pos );
1686 window->State.MouseX = mouse_pos.x;
1687 window->State.MouseY = mouse_pos.y;
1690 * Convert the Win32 keystroke codes to GLUTtish way
1692 # define KEY(a,b) case a: keypress = b; break;
1696 KEY( VK_F1, GLUT_KEY_F1 );
1697 KEY( VK_F2, GLUT_KEY_F2 );
1698 KEY( VK_F3, GLUT_KEY_F3 );
1699 KEY( VK_F4, GLUT_KEY_F4 );
1700 KEY( VK_F5, GLUT_KEY_F5 );
1701 KEY( VK_F6, GLUT_KEY_F6 );
1702 KEY( VK_F7, GLUT_KEY_F7 );
1703 KEY( VK_F8, GLUT_KEY_F8 );
1704 KEY( VK_F9, GLUT_KEY_F9 );
1705 KEY( VK_F10, GLUT_KEY_F10 );
1706 KEY( VK_F11, GLUT_KEY_F11 );
1707 KEY( VK_F12, GLUT_KEY_F12 );
1708 KEY( VK_PRIOR, GLUT_KEY_PAGE_UP );
1709 KEY( VK_NEXT, GLUT_KEY_PAGE_DOWN );
1710 KEY( VK_HOME, GLUT_KEY_HOME );
1711 KEY( VK_END, GLUT_KEY_END );
1712 KEY( VK_LEFT, GLUT_KEY_LEFT );
1713 KEY( VK_UP, GLUT_KEY_UP );
1714 KEY( VK_RIGHT, GLUT_KEY_RIGHT );
1715 KEY( VK_DOWN, GLUT_KEY_DOWN );
1716 KEY( VK_INSERT, GLUT_KEY_INSERT );
1720 * The delete key should be treated as an ASCII keypress:
1722 INVOKE_WCB( *window, Keyboard,
1723 ( 127, window->State.MouseX, window->State.MouseY )
1727 #if TARGET_HOST_WINCE
1728 if(!(lParam & 0x40000000)) // Prevent auto-repeat
1730 wince_GetDefaultKeys(&gxKeyList, 0x03);
1732 if(wParam==(unsigned)gxKeyList.vkRight)
1733 keypress = GLUT_KEY_RIGHT;
1734 else if(wParam==(unsigned)gxKeyList.vkLeft)
1735 keypress = GLUT_KEY_LEFT;
1736 else if(wParam==(unsigned)gxKeyList.vkUp)
1737 keypress = GLUT_KEY_UP;
1738 else if(wParam==(unsigned)gxKeyList.vkDown)
1739 keypress = GLUT_KEY_DOWN;
1740 else if(wParam==(unsigned)gxKeyList.vkA)
1741 keypress = GLUT_KEY_F1;
1742 else if(wParam==(unsigned)gxKeyList.vkB)
1743 keypress = GLUT_KEY_F2;
1744 else if(wParam==(unsigned)gxKeyList.vkC)
1745 keypress = GLUT_KEY_F3;
1746 else if(wParam==(unsigned)gxKeyList.vkStart)
1747 keypress = GLUT_KEY_F4;
1751 if( keypress != -1 )
1752 INVOKE_WCB( *window, Special,
1754 window->State.MouseX, window->State.MouseY )
1757 fgState.Modifiers = 0xffffffff;
1768 * Remember the current modifiers state. This is done here in order
1769 * to make sure the VK_DELETE keyboard callback is executed properly.
1771 fgState.Modifiers = fgGetWin32Modifiers( );
1773 GetCursorPos( &mouse_pos );
1774 ScreenToClient( window->Window.Handle, &mouse_pos );
1776 window->State.MouseX = mouse_pos.x;
1777 window->State.MouseY = mouse_pos.y;
1780 * Convert the Win32 keystroke codes to GLUTtish way.
1781 * "KEY(a,b)" was defined under "WM_KEYDOWN"
1786 KEY( VK_F1, GLUT_KEY_F1 );
1787 KEY( VK_F2, GLUT_KEY_F2 );
1788 KEY( VK_F3, GLUT_KEY_F3 );
1789 KEY( VK_F4, GLUT_KEY_F4 );
1790 KEY( VK_F5, GLUT_KEY_F5 );
1791 KEY( VK_F6, GLUT_KEY_F6 );
1792 KEY( VK_F7, GLUT_KEY_F7 );
1793 KEY( VK_F8, GLUT_KEY_F8 );
1794 KEY( VK_F9, GLUT_KEY_F9 );
1795 KEY( VK_F10, GLUT_KEY_F10 );
1796 KEY( VK_F11, GLUT_KEY_F11 );
1797 KEY( VK_F12, GLUT_KEY_F12 );
1798 KEY( VK_PRIOR, GLUT_KEY_PAGE_UP );
1799 KEY( VK_NEXT, GLUT_KEY_PAGE_DOWN );
1800 KEY( VK_HOME, GLUT_KEY_HOME );
1801 KEY( VK_END, GLUT_KEY_END );
1802 KEY( VK_LEFT, GLUT_KEY_LEFT );
1803 KEY( VK_UP, GLUT_KEY_UP );
1804 KEY( VK_RIGHT, GLUT_KEY_RIGHT );
1805 KEY( VK_DOWN, GLUT_KEY_DOWN );
1806 KEY( VK_INSERT, GLUT_KEY_INSERT );
1810 * The delete key should be treated as an ASCII keypress:
1812 INVOKE_WCB( *window, KeyboardUp,
1813 ( 127, window->State.MouseX, window->State.MouseY )
1819 #if !TARGET_HOST_WINCE
1823 GetKeyboardState( state );
1825 if( ToAscii( wParam, 0, state, code, 0 ) == 1 )
1828 INVOKE_WCB( *window, KeyboardUp,
1830 window->State.MouseX, window->State.MouseY )
1832 #endif /* !TARGET_HOST_WINCE */
1836 if( keypress != -1 )
1837 INVOKE_WCB( *window, SpecialUp,
1839 window->State.MouseX, window->State.MouseY )
1842 fgState.Modifiers = 0xffffffff;
1849 if( (fgState.KeyRepeat==GLUT_KEY_REPEAT_OFF || window->State.IgnoreKeyRepeat==GL_TRUE) && (HIWORD(lParam) & KF_REPEAT) )
1852 fgState.Modifiers = fgGetWin32Modifiers( );
1853 INVOKE_WCB( *window, Keyboard,
1855 window->State.MouseX, window->State.MouseY )
1857 fgState.Modifiers = 0xffffffff;
1861 case WM_CAPTURECHANGED:
1862 /* User has finished resizing the window, force a redraw */
1863 INVOKE_WCB( *window, Display, ( ) );
1865 /*lRet = DefWindowProc( hWnd, uMsg, wParam, lParam ); */
1869 * Other messages that I have seen and which are not handled already
1871 case WM_SETTEXT: /* 0x000c */
1872 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1873 /* Pass it on to "DefWindowProc" to set the window text */
1876 case WM_GETTEXT: /* 0x000d */
1877 /* Ideally we would copy the title of the window into "lParam" */
1878 /* strncpy ( (char *)lParam, "Window Title", wParam );
1879 lRet = ( wParam > 12 ) ? 12 : wParam; */
1880 /* the number of characters copied */
1881 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1884 case WM_GETTEXTLENGTH: /* 0x000e */
1885 /* Ideally we would get the length of the title of the window */
1887 /* the number of characters in "Window Title\0" (see above) */
1890 case WM_ERASEBKGND: /* 0x0014 */
1891 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1894 #if !TARGET_HOST_WINCE
1895 case WM_SYNCPAINT: /* 0x0088 */
1896 /* Another window has moved, need to update this one */
1897 window->State.Redisplay = GL_TRUE;
1898 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1899 /* Help screen says this message must be passed to "DefWindowProc" */
1902 case WM_NCPAINT: /* 0x0085 */
1903 /* Need to update the border of this window */
1904 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1905 /* Pass it on to "DefWindowProc" to repaint a standard border */
1908 case WM_SYSCOMMAND : /* 0x0112 */
1911 * We have received a system command message. Try to act on it.
1912 * The commands are passed in through the "lParam" parameter:
1913 * Clicking on a corner to resize the window gives a "F004" message
1914 * but this is not defined in my header file.
1925 /* User has clicked on the "-" to minimize the window */
1926 /* Turn off the visibility */
1927 window->State.Visible = GL_FALSE ;
1934 case SC_NEXTWINDOW :
1937 case SC_PREVWINDOW :
1941 /* Followed very closely by a WM_CLOSE message */
1965 case SC_SCREENSAVE :
1972 #endif /* !TARGET_HOST_WINCE */
1974 /* We need to pass the message on to the operating system as well */
1975 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1980 * Handle unhandled messages
1982 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1990 /*** END OF FILE ***/