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 ( keys[event.xkey.keycode>>3] & (1<<(event.xkey.keycode%8)) )
972 window->State.KeyRepeating = GL_TRUE;
974 window->State.KeyRepeating = GL_FALSE;
978 window->State.KeyRepeating = GL_FALSE;
980 /* Cease processing this event if it is auto repeated */
982 if (window->State.KeyRepeating)
985 if( event.type == KeyPress )
987 keyboard_cb = FETCH_WCB( *window, Keyboard );
988 special_cb = FETCH_WCB( *window, Special );
992 keyboard_cb = FETCH_WCB( *window, KeyboardUp );
993 special_cb = FETCH_WCB( *window, SpecialUp );
997 * Is there a keyboard/special callback hooked for this window?
999 if( keyboard_cb || special_cb )
1001 XComposeStatus composeStatus;
1002 char asciiCode[ 32 ];
1007 * Check for the ASCII/KeySym codes associated with the event:
1009 len = XLookupString( &event.xkey, asciiCode, sizeof(asciiCode),
1010 &keySym, &composeStatus
1014 * GLUT API tells us to have two separate callbacks...
1019 * ...one for the ASCII translateable keypresses...
1023 fgSetWindow( window );
1024 fgState.Modifiers = fgGetXModifiers( &event );
1025 keyboard_cb( asciiCode[ 0 ],
1026 event.xkey.x, event.xkey.y
1028 fgState.Modifiers = 0xffffffff;
1036 * ...and one for all the others, which need to be
1037 * translated to GLUT_KEY_Xs...
1041 case XK_F1: special = GLUT_KEY_F1; break;
1042 case XK_F2: special = GLUT_KEY_F2; break;
1043 case XK_F3: special = GLUT_KEY_F3; break;
1044 case XK_F4: special = GLUT_KEY_F4; break;
1045 case XK_F5: special = GLUT_KEY_F5; break;
1046 case XK_F6: special = GLUT_KEY_F6; break;
1047 case XK_F7: special = GLUT_KEY_F7; break;
1048 case XK_F8: special = GLUT_KEY_F8; break;
1049 case XK_F9: special = GLUT_KEY_F9; break;
1050 case XK_F10: special = GLUT_KEY_F10; break;
1051 case XK_F11: special = GLUT_KEY_F11; break;
1052 case XK_F12: special = GLUT_KEY_F12; break;
1054 case XK_Left: special = GLUT_KEY_LEFT; break;
1055 case XK_Right: special = GLUT_KEY_RIGHT; break;
1056 case XK_Up: special = GLUT_KEY_UP; break;
1057 case XK_Down: special = GLUT_KEY_DOWN; break;
1060 case XK_Prior: special = GLUT_KEY_PAGE_UP; break;
1062 case XK_Next: special = GLUT_KEY_PAGE_DOWN; break;
1064 case XK_Home: special = GLUT_KEY_HOME; break;
1066 case XK_End: special = GLUT_KEY_END; break;
1068 case XK_Insert: special = GLUT_KEY_INSERT; break;
1072 * Execute the callback (if one has been specified),
1073 * given that the special code seems to be valid...
1075 if( special_cb && (special != -1) )
1077 fgSetWindow( window );
1078 fgState.Modifiers = fgGetXModifiers( &event );
1079 special_cb( special, event.xkey.x, event.xkey.y );
1080 fgState.Modifiers = 0xffffffff;
1087 case ReparentNotify:
1088 break; /* XXX Should disable this event */
1091 fgWarning ("Unknown X event type: %d", event.type);
1096 #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE
1100 while( PeekMessage( &stMsg, NULL, 0, 0, PM_NOREMOVE ) )
1102 if( GetMessage( &stMsg, NULL, 0, 0 ) == 0 )
1104 if( fgState.ActionOnWindowClose == GLUT_ACTION_EXIT )
1109 fgState.ExecState = GLUT_EXEC_STATE_STOP;
1113 TranslateMessage( &stMsg );
1114 DispatchMessage( &stMsg );
1118 if( fgState.Timers.First )
1120 fghCheckJoystickPolls( );
1127 * Enters the freeglut processing loop.
1128 * Stays until the "ExecState" changes to "GLUT_EXEC_STATE_STOP".
1130 void FGAPIENTRY glutMainLoop( void )
1134 #if TARGET_HOST_WIN32 || TARGET_HOST_WINCE
1135 SFG_Window *window = (SFG_Window *)fgStructure.Windows.First ;
1138 freeglut_assert_ready;
1140 #if TARGET_HOST_WIN32 || TARGET_HOST_WINCE
1142 * Processing before the main loop: If there is a window which is open and
1143 * which has a visibility callback, call it. I know this is an ugly hack,
1144 * but I'm not sure what else to do about it. Ideally we should leave
1145 * something uninitialized in the create window code and initialize it in
1146 * the main loop, and have that initialization create a "WM_ACTIVATE"
1147 * message. Then we would put the visibility callback code in the
1148 * "case WM_ACTIVATE" block below. - John Fay -- 10/24/02
1152 if ( FETCH_WCB( *window, Visibility ) )
1154 SFG_Window *current_window = fgStructure.Window ;
1156 INVOKE_WCB( *window, Visibility, ( window->State.Visible ) );
1157 fgSetWindow( current_window );
1160 window = (SFG_Window *)window->Node.Next ;
1164 fgState.ExecState = GLUT_EXEC_STATE_RUNNING ;
1165 while( fgState.ExecState == GLUT_EXEC_STATE_RUNNING )
1169 glutMainLoopEvent( );
1171 * Step through the list of windows, seeing if there are any
1172 * that are not menus
1174 for( window = ( SFG_Window * )fgStructure.Windows.First;
1176 window = ( SFG_Window * )window->Node.Next )
1177 if ( ! ( window->IsMenu ) )
1181 fgState.ExecState = GLUT_EXEC_STATE_STOP;
1184 if( fgState.IdleCallback )
1185 fgState.IdleCallback( );
1187 fgSleepForEvents( );
1192 * When this loop terminates, destroy the display, state and structure
1193 * of a freeglut session, so that another glutInit() call can happen
1195 * Save the "ActionOnWindowClose" because "fgDeinitialize" resets it.
1197 action = fgState.ActionOnWindowClose;
1199 if( action == GLUT_ACTION_EXIT )
1204 * Leaves the freeglut processing loop.
1206 void FGAPIENTRY glutLeaveMainLoop( void )
1208 fgState.ExecState = GLUT_EXEC_STATE_STOP ;
1212 #if TARGET_HOST_WIN32 || TARGET_HOST_WINCE
1214 * Determine a GLUT modifer mask based on MS-WINDOWS system info.
1216 int fgGetWin32Modifiers (void)
1219 ( ( ( GetKeyState( VK_LSHIFT ) < 0 ) ||
1220 ( GetKeyState( VK_RSHIFT ) < 0 )) ? GLUT_ACTIVE_SHIFT : 0 ) |
1221 ( ( ( GetKeyState( VK_LCONTROL ) < 0 ) ||
1222 ( GetKeyState( VK_RCONTROL ) < 0 )) ? GLUT_ACTIVE_CTRL : 0 ) |
1223 ( ( ( GetKeyState( VK_LMENU ) < 0 ) ||
1224 ( GetKeyState( VK_RMENU ) < 0 )) ? GLUT_ACTIVE_ALT : 0 );
1228 * The window procedure for handling Win32 events
1230 LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam,
1233 SFG_Window* window = fgWindowByHandle( hWnd );
1237 if ( ( window == NULL ) && ( uMsg != WM_CREATE ) )
1238 return DefWindowProc( hWnd, uMsg, wParam, lParam );
1240 /* printf ( "Window %3d message <%04x> %12d %12d\n", window?window->ID:0,
1241 uMsg, wParam, lParam ); */
1246 * The window structure is passed as the creation structure paramter...
1248 window = (SFG_Window *) (((LPCREATESTRUCT) lParam)->lpCreateParams);
1249 assert( window != NULL );
1251 window->Window.Handle = hWnd;
1252 window->Window.Device = GetDC( hWnd );
1253 if( window->IsMenu )
1255 unsigned int current_DisplayMode = fgState.DisplayMode;
1256 fgState.DisplayMode = GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH;
1257 #if !TARGET_HOST_WINCE
1258 fgSetupPixelFormat( window, GL_FALSE, PFD_MAIN_PLANE );
1260 fgState.DisplayMode = current_DisplayMode;
1262 if( fgStructure.MenuContext )
1263 wglMakeCurrent( window->Window.Device,
1264 fgStructure.MenuContext->Context
1268 fgStructure.MenuContext =
1269 (SFG_MenuContext *)malloc( sizeof(SFG_MenuContext) );
1270 fgStructure.MenuContext->Context =
1271 wglCreateContext( window->Window.Device );
1274 /* window->Window.Context = wglGetCurrentContext (); */
1275 window->Window.Context = wglCreateContext( window->Window.Device );
1279 #if !TARGET_HOST_WINCE
1280 fgSetupPixelFormat( window, GL_FALSE, PFD_MAIN_PLANE );
1283 if( ! fgState.UseCurrentContext )
1284 window->Window.Context =
1285 wglCreateContext( window->Window.Device );
1288 window->Window.Context = wglGetCurrentContext( );
1289 if( ! window->Window.Context )
1290 window->Window.Context =
1291 wglCreateContext( window->Window.Device );
1295 window->State.NeedToResize = GL_TRUE;
1296 window->State.Width = fgState.Size.X;
1297 window->State.Height = fgState.Size.Y;
1299 ReleaseDC( window->Window.Handle, window->Window.Device );
1301 #if TARGET_HOST_WINCE
1302 // Take over button handling
1304 #endif /* TARGET_HOST_WINCE */
1309 * If the window is visible, then it is the user manually resizing it.
1310 * If it is not, then it is the system sending us a dummy resize with
1311 * zero dimensions on a "glutIconifyWindow" call.
1313 if( window->State.Visible )
1315 window->State.NeedToResize = GL_TRUE;
1316 #if TARGET_HOST_WINCE
1317 window->State.Width = HIWORD(lParam);
1318 window->State.Height = LOWORD(lParam);
1320 window->State.Width = LOWORD(lParam);
1321 window->State.Height = HIWORD(lParam);
1322 #endif /* TARGET_HOST_WINCE */
1328 printf("WM_SETFOCUS: %p\n", window );
1329 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1333 if (LOWORD(wParam) != WA_INACTIVE)
1335 /* glutSetCursor( fgStructure.Window->State.Cursor ); */
1336 printf("WM_ACTIVATE: glutSetCursor( %p, %d)\n", window,
1337 window->State.Cursor );
1338 glutSetCursor( window->State.Cursor );
1341 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1346 * XXX Why not re-use some common code with the glutSetCursor()
1347 * XXX function (or perhaps invoke glutSetCursor())?
1348 * XXX That is, why are we duplicating code, here, from
1349 * XXX glutSetCursor()? The WIN32 code should be able to just
1350 * XXX call glutSetCurdsor() instead of defining two macros
1351 * XXX and implementing a nested case in-line.
1354 /* Set the cursor AND change it for this window class. */
1355 #define MAP_CURSOR(a,b) \
1357 SetCursor( LoadCursor( NULL, b ) ); \
1360 /* Nuke the cursor AND change it for this window class. */
1361 #define ZAP_CURSOR(a,b) \
1363 SetCursor( NULL ); \
1366 if( LOWORD( lParam ) == HTCLIENT )
1367 switch( window->State.Cursor )
1369 MAP_CURSOR( GLUT_CURSOR_RIGHT_ARROW, IDC_ARROW );
1370 MAP_CURSOR( GLUT_CURSOR_LEFT_ARROW, IDC_ARROW );
1371 MAP_CURSOR( GLUT_CURSOR_INFO, IDC_HELP );
1372 MAP_CURSOR( GLUT_CURSOR_DESTROY, IDC_CROSS );
1373 MAP_CURSOR( GLUT_CURSOR_HELP, IDC_HELP );
1374 MAP_CURSOR( GLUT_CURSOR_CYCLE, IDC_SIZEALL );
1375 MAP_CURSOR( GLUT_CURSOR_SPRAY, IDC_CROSS );
1376 MAP_CURSOR( GLUT_CURSOR_WAIT, IDC_WAIT );
1377 MAP_CURSOR( GLUT_CURSOR_TEXT, IDC_UPARROW );
1378 MAP_CURSOR( GLUT_CURSOR_CROSSHAIR, IDC_CROSS );
1379 /* MAP_CURSOR( GLUT_CURSOR_NONE, IDC_NO ); */
1380 ZAP_CURSOR( GLUT_CURSOR_NONE, NULL );
1383 MAP_CURSOR( GLUT_CURSOR_UP_DOWN, IDC_ARROW );
1386 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1390 window->State.Visible = GL_TRUE;
1391 window->State.Redisplay = GL_TRUE;
1395 /* Turn on the visibility in case it was turned off somehow */
1396 window->State.Visible = GL_TRUE;
1397 BeginPaint( hWnd, &ps );
1398 fghRedrawWindowByHandle( hWnd );
1399 EndPaint( hWnd, &ps );
1403 fgDestroyWindow ( window );
1404 if ( fgState.ActionOnWindowClose != GLUT_ACTION_CONTINUE_EXECUTION )
1410 * The window already got destroyed, so don't bother with it.
1416 #if TARGET_HOST_WINCE
1417 window->State.MouseX = 320-HIWORD( lParam );
1418 window->State.MouseY = LOWORD( lParam );
1420 window->State.MouseX = LOWORD( lParam );
1421 window->State.MouseY = HIWORD( lParam );
1422 #endif /* TARGET_HOST_WINCE */
1424 if ( window->ActiveMenu )
1426 window->State.Redisplay = GL_TRUE;
1427 fgSetWindow ( window->ActiveMenu->ParentWindow );
1431 fgState.Modifiers = fgGetWin32Modifiers( );
1433 if( ( wParam & MK_LBUTTON ) ||
1434 ( wParam & MK_MBUTTON ) ||
1435 ( wParam & MK_RBUTTON ) )
1436 INVOKE_WCB( *window, Motion, ( window->State.MouseX,
1437 window->State.MouseY ) );
1439 INVOKE_WCB( *window, Passive, ( window->State.MouseX,
1440 window->State.MouseY ) );
1442 fgState.Modifiers = 0xffffffff;
1446 case WM_LBUTTONDOWN:
1447 case WM_MBUTTONDOWN:
1448 case WM_RBUTTONDOWN:
1453 GLboolean pressed = GL_TRUE;
1456 #if TARGET_HOST_WINCE
1457 window->State.MouseX = 320-HIWORD( lParam );
1458 window->State.MouseY = LOWORD( lParam );
1460 window->State.MouseX = LOWORD( lParam );
1461 window->State.MouseY = HIWORD( lParam );
1462 #endif /* TARGET_HOST_WINCE */
1466 case WM_LBUTTONDOWN:
1468 button = GLUT_LEFT_BUTTON;
1470 case WM_MBUTTONDOWN:
1472 button = GLUT_MIDDLE_BUTTON;
1474 case WM_RBUTTONDOWN:
1476 button = GLUT_RIGHT_BUTTON;
1480 button = GLUT_LEFT_BUTTON;
1484 button = GLUT_MIDDLE_BUTTON;
1488 button = GLUT_RIGHT_BUTTON;
1496 #if !TARGET_HOST_WINCE
1497 if( GetSystemMetrics( SM_SWAPBUTTON ) )
1499 if( button == GLUT_LEFT_BUTTON )
1500 button = GLUT_RIGHT_BUTTON;
1502 if( button == GLUT_RIGHT_BUTTON )
1503 button = GLUT_LEFT_BUTTON;
1505 #endif /* !TARGET_HOST_WINCE */
1508 return DefWindowProc( hWnd, uMsg, lParam, wParam );
1511 * XXX This comment is duplicated in two other spots.
1512 * XXX Can we centralize it?
1514 * Do not execute the application's mouse callback if a
1515 * menu is hooked to this button.
1516 * In that case an appropriate private call should be generated.
1517 * Near as I can tell, this is the menu behaviour:
1518 * - Down-click the menu button, menu not active: activate
1519 * the menu with its upper left-hand corner at the mouse location.
1520 * - Down-click any button outside the menu, menu active:
1521 * deactivate the menu
1522 * - Down-click any button inside the menu, menu active:
1523 * select the menu entry and deactivate the menu
1524 * - Up-click the menu button, menu not active: nothing happens
1525 * - Up-click the menu button outside the menu, menu active:
1527 * - Up-click the menu button inside the menu, menu active:
1528 * select the menu entry and deactivate the menu
1530 /* Window has an active menu, it absorbs any mouse click */
1531 if( window->ActiveMenu )
1533 /* Outside the menu, deactivate the menu if it's a downclick */
1534 if( ! fgCheckActiveMenu( window, window->ActiveMenu ) )
1537 fgDeactivateMenu( window->ActiveMenu->ParentWindow );
1539 else /* In menu, invoke the callback and deactivate the menu*/
1542 * Save the current window and menu and set the current
1543 * window to the window whose menu this is
1545 SFG_Window *save_window = fgStructure.Window;
1546 SFG_Menu *save_menu = fgStructure.Menu;
1547 SFG_Window *parent_window = window->ActiveMenu->ParentWindow;
1548 fgSetWindow( parent_window );
1549 fgStructure.Menu = window->ActiveMenu;
1551 /* Execute the menu callback */
1552 fgExecuteMenuCallback( window->ActiveMenu );
1553 fgDeactivateMenu( parent_window );
1555 /* Restore the current window and menu */
1556 fgSetWindow( save_window );
1557 fgStructure.Menu = save_menu;
1561 * Let's make the window redraw as a result of the mouse
1562 * click and menu activity.
1564 if( ! window->IsMenu )
1565 window->State.Redisplay = GL_TRUE;
1570 if( window->Menu[ button ] && pressed )
1572 window->State.Redisplay = GL_TRUE;
1573 fgSetWindow( window );
1574 fgActivateMenu( window, button );
1579 if( ! FETCH_WCB( *window, Mouse ) )
1582 fgSetWindow( window );
1583 fgState.Modifiers = fgGetWin32Modifiers( );
1588 pressed ? GLUT_DOWN : GLUT_UP,
1589 window->State.MouseX,
1590 window->State.MouseY
1594 fgState.Modifiers = 0xffffffff;
1599 /* Should be WM_MOUSEWHEEL but my compiler doesn't recognize it */
1602 * XXX THIS IS SPECULATIVE -- John Fay, 10/2/03
1603 * XXX Should use WHEEL_DELTA instead of 120
1605 int wheel_number = LOWORD( wParam );
1606 short ticks = ( short )HIWORD( wParam ) / 120;
1616 * The mouse cursor has moved. Remember the new mouse cursor's position
1618 /* window->State.MouseX = LOWORD( lParam ); */
1619 /* Need to adjust by window position, */
1620 /* window->State.MouseY = HIWORD( lParam ); */
1621 /* change "lParam" to other parameter */
1623 if( ! FETCH_WCB( *window, MouseWheel ) &&
1624 ! FETCH_WCB( *window, Mouse ) )
1627 fgSetWindow( window );
1628 fgState.Modifiers = fgGetWin32Modifiers( );
1631 if( FETCH_WCB( *window, MouseWheel ) )
1632 INVOKE_WCB( *window, MouseWheel,
1635 window->State.MouseX,
1636 window->State.MouseY
1639 else /* No mouse wheel, call the mouse button callback twice */
1642 * XXX The below assumes that you have no more than 3 mouse
1643 * XXX buttons. Sorry.
1645 int button = wheel_number*2 + 4;
1648 INVOKE_WCB( *window, Mouse,
1649 ( button, GLUT_DOWN,
1650 window->State.MouseX, window->State.MouseY )
1652 INVOKE_WCB( *window, Mouse,
1654 window->State.MouseX, window->State.MouseX )
1658 fgState.Modifiers = 0xffffffff;
1665 #if TARGET_HOST_WINCE
1666 struct GXKeyList gxKeyList;
1667 #endif /* TARGET_HOST_WINCE */
1671 if( ( fgState.KeyRepeat==GLUT_KEY_REPEAT_OFF || window->State.IgnoreKeyRepeat==GL_TRUE ) && (HIWORD(lParam) & KF_REPEAT) )
1675 * Remember the current modifiers state. This is done here in order
1676 * to make sure the VK_DELETE keyboard callback is executed properly.
1678 fgState.Modifiers = fgGetWin32Modifiers( );
1680 GetCursorPos( &mouse_pos );
1681 ScreenToClient( window->Window.Handle, &mouse_pos );
1683 window->State.MouseX = mouse_pos.x;
1684 window->State.MouseY = mouse_pos.y;
1687 * Convert the Win32 keystroke codes to GLUTtish way
1689 # define KEY(a,b) case a: keypress = b; break;
1693 KEY( VK_F1, GLUT_KEY_F1 );
1694 KEY( VK_F2, GLUT_KEY_F2 );
1695 KEY( VK_F3, GLUT_KEY_F3 );
1696 KEY( VK_F4, GLUT_KEY_F4 );
1697 KEY( VK_F5, GLUT_KEY_F5 );
1698 KEY( VK_F6, GLUT_KEY_F6 );
1699 KEY( VK_F7, GLUT_KEY_F7 );
1700 KEY( VK_F8, GLUT_KEY_F8 );
1701 KEY( VK_F9, GLUT_KEY_F9 );
1702 KEY( VK_F10, GLUT_KEY_F10 );
1703 KEY( VK_F11, GLUT_KEY_F11 );
1704 KEY( VK_F12, GLUT_KEY_F12 );
1705 KEY( VK_PRIOR, GLUT_KEY_PAGE_UP );
1706 KEY( VK_NEXT, GLUT_KEY_PAGE_DOWN );
1707 KEY( VK_HOME, GLUT_KEY_HOME );
1708 KEY( VK_END, GLUT_KEY_END );
1709 KEY( VK_LEFT, GLUT_KEY_LEFT );
1710 KEY( VK_UP, GLUT_KEY_UP );
1711 KEY( VK_RIGHT, GLUT_KEY_RIGHT );
1712 KEY( VK_DOWN, GLUT_KEY_DOWN );
1713 KEY( VK_INSERT, GLUT_KEY_INSERT );
1717 * The delete key should be treated as an ASCII keypress:
1719 INVOKE_WCB( *window, Keyboard,
1720 ( 127, window->State.MouseX, window->State.MouseY )
1724 #if TARGET_HOST_WINCE
1725 if(!(lParam & 0x40000000)) // Prevent auto-repeat
1727 wince_GetDefaultKeys(&gxKeyList, 0x03);
1729 if(wParam==(unsigned)gxKeyList.vkRight)
1730 keypress = GLUT_KEY_RIGHT;
1731 else if(wParam==(unsigned)gxKeyList.vkLeft)
1732 keypress = GLUT_KEY_LEFT;
1733 else if(wParam==(unsigned)gxKeyList.vkUp)
1734 keypress = GLUT_KEY_UP;
1735 else if(wParam==(unsigned)gxKeyList.vkDown)
1736 keypress = GLUT_KEY_DOWN;
1737 else if(wParam==(unsigned)gxKeyList.vkA)
1738 keypress = GLUT_KEY_F1;
1739 else if(wParam==(unsigned)gxKeyList.vkB)
1740 keypress = GLUT_KEY_F2;
1741 else if(wParam==(unsigned)gxKeyList.vkC)
1742 keypress = GLUT_KEY_F3;
1743 else if(wParam==(unsigned)gxKeyList.vkStart)
1744 keypress = GLUT_KEY_F4;
1748 if( keypress != -1 )
1749 INVOKE_WCB( *window, Special,
1751 window->State.MouseX, window->State.MouseY )
1754 fgState.Modifiers = 0xffffffff;
1765 * Remember the current modifiers state. This is done here in order
1766 * to make sure the VK_DELETE keyboard callback is executed properly.
1768 fgState.Modifiers = fgGetWin32Modifiers( );
1770 GetCursorPos( &mouse_pos );
1771 ScreenToClient( window->Window.Handle, &mouse_pos );
1773 window->State.MouseX = mouse_pos.x;
1774 window->State.MouseY = mouse_pos.y;
1777 * Convert the Win32 keystroke codes to GLUTtish way.
1778 * "KEY(a,b)" was defined under "WM_KEYDOWN"
1783 KEY( VK_F1, GLUT_KEY_F1 );
1784 KEY( VK_F2, GLUT_KEY_F2 );
1785 KEY( VK_F3, GLUT_KEY_F3 );
1786 KEY( VK_F4, GLUT_KEY_F4 );
1787 KEY( VK_F5, GLUT_KEY_F5 );
1788 KEY( VK_F6, GLUT_KEY_F6 );
1789 KEY( VK_F7, GLUT_KEY_F7 );
1790 KEY( VK_F8, GLUT_KEY_F8 );
1791 KEY( VK_F9, GLUT_KEY_F9 );
1792 KEY( VK_F10, GLUT_KEY_F10 );
1793 KEY( VK_F11, GLUT_KEY_F11 );
1794 KEY( VK_F12, GLUT_KEY_F12 );
1795 KEY( VK_PRIOR, GLUT_KEY_PAGE_UP );
1796 KEY( VK_NEXT, GLUT_KEY_PAGE_DOWN );
1797 KEY( VK_HOME, GLUT_KEY_HOME );
1798 KEY( VK_END, GLUT_KEY_END );
1799 KEY( VK_LEFT, GLUT_KEY_LEFT );
1800 KEY( VK_UP, GLUT_KEY_UP );
1801 KEY( VK_RIGHT, GLUT_KEY_RIGHT );
1802 KEY( VK_DOWN, GLUT_KEY_DOWN );
1803 KEY( VK_INSERT, GLUT_KEY_INSERT );
1807 * The delete key should be treated as an ASCII keypress:
1809 INVOKE_WCB( *window, KeyboardUp,
1810 ( 127, window->State.MouseX, window->State.MouseY )
1816 #if !TARGET_HOST_WINCE
1820 GetKeyboardState( state );
1822 if( ToAscii( wParam, 0, state, code, 0 ) == 1 )
1825 INVOKE_WCB( *window, KeyboardUp,
1827 window->State.MouseX, window->State.MouseY )
1829 #endif /* !TARGET_HOST_WINCE */
1833 if( keypress != -1 )
1834 INVOKE_WCB( *window, SpecialUp,
1836 window->State.MouseX, window->State.MouseY )
1839 fgState.Modifiers = 0xffffffff;
1846 if( (fgState.KeyRepeat==GLUT_KEY_REPEAT_OFF || window->State.IgnoreKeyRepeat==GL_TRUE) && (HIWORD(lParam) & KF_REPEAT) )
1849 fgState.Modifiers = fgGetWin32Modifiers( );
1850 INVOKE_WCB( *window, Keyboard,
1852 window->State.MouseX, window->State.MouseY )
1854 fgState.Modifiers = 0xffffffff;
1858 case WM_CAPTURECHANGED:
1859 /* User has finished resizing the window, force a redraw */
1860 INVOKE_WCB( *window, Display, ( ) );
1862 /*lRet = DefWindowProc( hWnd, uMsg, wParam, lParam ); */
1866 * Other messages that I have seen and which are not handled already
1868 case WM_SETTEXT: /* 0x000c */
1869 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1870 /* Pass it on to "DefWindowProc" to set the window text */
1873 case WM_GETTEXT: /* 0x000d */
1874 /* Ideally we would copy the title of the window into "lParam" */
1875 /* strncpy ( (char *)lParam, "Window Title", wParam );
1876 lRet = ( wParam > 12 ) ? 12 : wParam; */
1877 /* the number of characters copied */
1878 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1881 case WM_GETTEXTLENGTH: /* 0x000e */
1882 /* Ideally we would get the length of the title of the window */
1884 /* the number of characters in "Window Title\0" (see above) */
1887 case WM_ERASEBKGND: /* 0x0014 */
1888 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1891 #if !TARGET_HOST_WINCE
1892 case WM_SYNCPAINT: /* 0x0088 */
1893 /* Another window has moved, need to update this one */
1894 window->State.Redisplay = GL_TRUE;
1895 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1896 /* Help screen says this message must be passed to "DefWindowProc" */
1899 case WM_NCPAINT: /* 0x0085 */
1900 /* Need to update the border of this window */
1901 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1902 /* Pass it on to "DefWindowProc" to repaint a standard border */
1905 case WM_SYSCOMMAND : /* 0x0112 */
1908 * We have received a system command message. Try to act on it.
1909 * The commands are passed in through the "lParam" parameter:
1910 * Clicking on a corner to resize the window gives a "F004" message
1911 * but this is not defined in my header file.
1922 /* User has clicked on the "-" to minimize the window */
1923 /* Turn off the visibility */
1924 window->State.Visible = GL_FALSE ;
1931 case SC_NEXTWINDOW :
1934 case SC_PREVWINDOW :
1938 /* Followed very closely by a WM_CLOSE message */
1962 case SC_SCREENSAVE :
1969 #endif /* !TARGET_HOST_WINCE */
1971 /* We need to pass the message on to the operating system as well */
1972 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1977 * Handle unhandled messages
1979 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1987 /*** END OF FILE ***/