4 * The windows message processing methods.
6 * Copyright (c) 1999-2000 Pawel W. Olszta. All Rights Reserved.
7 * Written by Pawel W. Olszta, <olszta@sourceforge.net>
8 * Creation date: Fri Dec 3 1999
10 * Permission is hereby granted, free of charge, to any person obtaining a
11 * copy of this software and associated documentation files (the "Software"),
12 * to deal in the Software without restriction, including without limitation
13 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 * and/or sell copies of the Software, and to permit persons to whom the
15 * Software is furnished to do so, subject to the following conditions:
17 * The above copyright notice and this permission notice shall be included
18 * in all copies or substantial portions of the Software.
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23 * PAWEL W. OLSZTA BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
24 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
25 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 #include <GL/freeglut.h>
33 #include "freeglut_internal.h"
36 #if TARGET_HOST_UNIX_X11
37 #include <sys/types.h>
42 #elif TARGET_HOST_WIN32
46 #define MAX(a,b) (((a)>(b)) ? (a) : (b))
50 #define MIN(a,b) (((a)<(b)) ? (a) : (b))
55 * TODO BEFORE THE STABLE RELEASE:
57 * There are some issues concerning window redrawing under X11, and maybe
58 * some events are not handled. The Win32 version lacks some more features,
59 * but seems acceptable for not demanding purposes.
61 * Need to investigate why the X11 version breaks out with an error when
62 * closing a window (using the window manager, not glutDestroyWindow)...
65 /* -- PRIVATE FUNCTIONS ---------------------------------------------------- */
68 * Handle a window configuration change. When no reshape
69 * callback is hooked, the viewport size is updated to
70 * match the new window size.
72 static void fghReshapeWindowByHandle ( SFG_WindowHandleType handle,
73 int width, int height )
75 SFG_Window *current_window = fgStructure.Window;
77 SFG_Window* window = fgWindowByHandle( handle );
78 freeglut_return_if_fail( window != NULL );
81 #if TARGET_HOST_UNIX_X11
83 XResizeWindow( fgDisplay.Display, window->Window.Handle,
85 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
87 #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE
89 #if !TARGET_HOST_WINCE
94 * For windowed mode, get the current position of the
95 * window and resize taking the size of the frame
96 * decorations into account.
99 GetWindowRect( window->Window.Handle, &rect );
100 rect.right = rect.left + width;
101 rect.bottom = rect.top + height;
103 if ( window->Parent == NULL )
105 if ( ! window->IsMenu && !window->State.IsGameMode )
107 rect.right += GetSystemMetrics( SM_CXSIZEFRAME ) * 2;
108 rect.bottom += GetSystemMetrics( SM_CYSIZEFRAME ) * 2 +
109 GetSystemMetrics( SM_CYCAPTION );
114 GetWindowRect( window->Parent->Window.Handle, &rect );
115 AdjustWindowRect ( &rect, WS_OVERLAPPEDWINDOW | WS_CLIPSIBLINGS |
116 WS_CLIPCHILDREN, FALSE );
120 * SWP_NOACTIVATE Do not activate the window
121 * SWP_NOOWNERZORDER Do not change position in z-order
122 * SWP_NOSENDCHANGING Supress WM_WINDOWPOSCHANGING message
123 * SWP_NOZORDER Retains the current Z order (ignore 2nd param)
126 SetWindowPos( window->Window.Handle,
130 rect.right - rect.left,
131 rect.bottom - rect.top,
132 SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOSENDCHANGING |
136 #endif //TARGET_HOST_WINCE
139 * XXX Should update {window->State.OldWidth, window->State.OldHeight}
140 * XXX to keep in lockstep with UNIX_X11 code.
142 if( FETCH_WCB( *window, Reshape ) )
143 INVOKE_WCB( *window, Reshape, ( width, height ) );
146 fgSetWindow( window );
147 glViewport( 0, 0, width, height );
153 * Force a window redraw. In Windows at least this is only a partial
154 * solution: if the window is increasing in size in either dimension,
155 * the already-drawn part does not get drawn again and things look funny.
156 * But without this we get this bad behaviour whenever we resize the
159 window->State.Redisplay = GL_TRUE;
162 fgSetWindow( current_window );
166 * Calls a window's redraw method. This is used when
167 * a redraw is forced by the incoming window messages.
169 static void fghRedrawWindowByHandle ( SFG_WindowHandleType handle )
171 SFG_Window* window = fgWindowByHandle( handle );
172 freeglut_return_if_fail( window );
173 freeglut_return_if_fail( FETCH_WCB ( *window, Display ) );
175 window->State.Redisplay = GL_FALSE;
177 freeglut_return_if_fail( window->State.Visible );
179 if( window->State.NeedToResize )
181 SFG_Window *current_window = fgStructure.Window;
183 fgSetWindow( window );
185 fghReshapeWindowByHandle(
186 window->Window.Handle,
191 window->State.NeedToResize = GL_FALSE;
192 fgSetWindow( current_window );
195 INVOKE_WCB( *window, Display, ( ) );
199 * A static helper function to execute display callback for a window
201 static void fghcbDisplayWindow( SFG_Window *window,
202 SFG_Enumerator *enumerator )
204 if( window->State.NeedToResize )
206 SFG_Window *current_window = fgStructure.Window;
208 fgSetWindow( window );
210 fghReshapeWindowByHandle(
211 window->Window.Handle,
216 window->State.NeedToResize = GL_FALSE;
217 fgSetWindow ( current_window );
220 if( window->State.Redisplay &&
221 window->State.Visible )
223 window->State.Redisplay = GL_FALSE;
225 #if TARGET_HOST_UNIX_X11
227 SFG_Window *current_window = fgStructure.Window;
229 INVOKE_WCB( *window, Display, ( ) );
230 fgSetWindow( current_window );
232 #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE
234 window->Window.Handle, NULL, NULL,
235 RDW_NOERASE | RDW_INTERNALPAINT | RDW_INVALIDATE | RDW_UPDATENOW
240 fgEnumSubWindows( window, fghcbDisplayWindow, enumerator );
244 * Make all windows perform a display call
246 static void fghDisplayAll( void )
248 SFG_Enumerator enumerator;
250 enumerator.found = GL_FALSE;
251 enumerator.data = NULL;
253 fgEnumWindows( fghcbDisplayWindow, &enumerator );
257 * Window enumerator callback to check for the joystick polling code
259 static void fghcbCheckJoystickPolls( SFG_Window *window,
260 SFG_Enumerator *enumerator )
262 long int checkTime = fgElapsedTime( );
264 if( window->State.JoystickLastPoll + window->State.JoystickPollRate <=
267 #if !TARGET_HOST_WINCE
268 fgJoystickPollWindow( window );
269 #endif //!TARGET_HOST_WINCE
270 window->State.JoystickLastPoll = checkTime;
273 fgEnumSubWindows( window, fghcbCheckJoystickPolls, enumerator );
277 * Check all windows for joystick polling
279 static void fghCheckJoystickPolls( void )
281 SFG_Enumerator enumerator;
283 enumerator.found = GL_FALSE;
284 enumerator.data = NULL;
286 fgEnumWindows( fghcbCheckJoystickPolls, &enumerator );
290 * Check the global timers
292 static void fghCheckTimers( void )
294 long checkTime = fgElapsedTime( );
296 while( fgState.Timers.First )
298 SFG_Timer *timer = fgState.Timers.First;
300 if( timer->TriggerTime > checkTime )
303 fgListRemove( &fgState.Timers, &timer->Node );
304 fgListAppend( &fgState.FreeTimers, &timer->Node );
306 timer->Callback( timer->ID );
313 long fgElapsedTime( void )
315 if ( fgState.Time.Set )
317 #if TARGET_HOST_UNIX_X11
321 gettimeofday( &now, NULL );
323 elapsed = (now.tv_usec - fgState.Time.Value.tv_usec) / 1000;
324 elapsed += (now.tv_sec - fgState.Time.Value.tv_sec) * 1000;
327 #elif TARGET_HOST_WIN32
328 return timeGetTime() - fgState.Time.Value;
329 #elif TARGET_HOST_WINCE
330 return GetTickCount() - fgState.Time.Value;
335 #if TARGET_HOST_UNIX_X11
336 gettimeofday( &fgState.Time.Value, NULL );
337 #elif TARGET_HOST_WIN32
338 fgState.Time.Value = timeGetTime ();
339 #elif TARGET_HOST_WINCE
340 fgState.Time.Value = GetTickCount();
342 fgState.Time.Set = GL_TRUE ;
351 void fgError( const char *fmt, ... )
357 fprintf( stderr, "freeglut ");
358 if( fgState.ProgramName )
359 fprintf (stderr, "(%s): ", fgState.ProgramName);
360 vfprintf( stderr, fmt, ap );
361 fprintf( stderr, "\n" );
365 if ( fgState.Initialised )
371 void fgWarning( const char *fmt, ... )
377 fprintf( stderr, "freeglut ");
378 if( fgState.ProgramName )
379 fprintf( stderr, "(%s): ", fgState.ProgramName );
380 vfprintf( stderr, fmt, ap );
381 fprintf( stderr, "\n" );
387 * Indicates whether Joystick events are being used by ANY window.
389 * The current mechanism is to walk all of the windows and ask if
390 * there is a joystick callback. We have a short-circuit early
391 * return if we find any joystick handler registered.
393 * The real way to do this is to make use of the glutTimer() API
394 * to more cleanly re-implement the joystick API. Then, this code
395 * and all other "joystick timer" code can be yanked.
398 static void fgCheckJoystickCallback( SFG_Window* w, SFG_Enumerator* e)
400 if( FETCH_WCB( *w, Joystick ) )
405 fgEnumSubWindows( w, fgCheckJoystickCallback, e );
407 static int fgHaveJoystick( void )
409 SFG_Enumerator enumerator;
410 enumerator.found = GL_FALSE;
411 enumerator.data = NULL;
412 fgEnumWindows( fgCheckJoystickCallback, &enumerator );
413 return !!enumerator.data;
415 static void fgHavePendingRedisplaysCallback( SFG_Window* w, SFG_Enumerator* e)
417 if( w->State.Redisplay )
422 fgEnumSubWindows( w, fgHavePendingRedisplaysCallback, e );
424 static int fgHavePendingRedisplays (void)
426 SFG_Enumerator enumerator;
427 enumerator.found = GL_FALSE;
428 enumerator.data = NULL;
429 fgEnumWindows( fgHavePendingRedisplaysCallback, &enumerator );
430 return !!enumerator.data;
433 * Returns the number of GLUT ticks (milliseconds) till the next timer event.
435 static long fgNextTimer( void )
438 SFG_Timer *timer = fgState.Timers.First;
441 ret = timer->TriggerTime - fgElapsedTime();
448 * Does the magic required to relinquish the CPU until something interesting
451 static void fgSleepForEvents( void )
455 if( fgState.IdleCallback || fgHavePendingRedisplays( ) )
458 msec = fgNextTimer( );
459 if( fgHaveJoystick( ) ) /* XXX Use GLUT timers for joysticks... */
460 msec = MIN( msec, 10 ); /* XXX Dumb; forces granularity to .01sec */
462 #if TARGET_HOST_UNIX_X11
464 * Possibly due to aggressive use of XFlush() and friends,
465 * it is possible to have our socket drained but still have
466 * unprocessed events. (Or, this may just be normal with
467 * X, anyway?) We do non-trivial processing of X events
468 * after tham in event-reading loop, in any case, so we
469 * need to allow that we may have an empty socket but non-
472 if( ! XPending( fgDisplay.Display ) )
479 socket = ConnectionNumber( fgDisplay.Display );
481 FD_SET( socket, &fdset );
482 wait.tv_sec = msec / 1000;
483 wait.tv_usec = (msec % 1000) * 1000;
484 err = select( socket+1, &fdset, NULL, NULL, &wait );
487 fgWarning ( "freeglut select() error: %d\n", errno );
489 #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE
490 MsgWaitForMultipleObjects( 0, NULL, FALSE, msec, QS_ALLEVENTS );
494 #if TARGET_HOST_UNIX_X11
496 * Returns GLUT modifier mask for an XEvent.
498 int fgGetXModifiers( XEvent *event )
502 if( event->xkey.state & ( ShiftMask | LockMask ) )
503 ret |= GLUT_ACTIVE_SHIFT;
504 if( event->xkey.state & ControlMask )
505 ret |= GLUT_ACTIVE_CTRL;
506 if( event->xkey.state & Mod1Mask )
507 ret |= GLUT_ACTIVE_ALT;
514 /* -- INTERFACE FUNCTIONS -------------------------------------------------- */
517 * Executes a single iteration in the freeglut processing loop.
519 void FGAPIENTRY glutMainLoopEvent( void )
521 #if TARGET_HOST_UNIX_X11
526 * This code was repeated constantly, so here it goes into a definition:
528 #define GETWINDOW(a) \
529 window = fgWindowByHandle( event.a.window ); \
530 if( window == NULL ) \
533 #define GETMOUSE(a) \
534 window->State.MouseX = event.a.x; \
535 window->State.MouseY = event.a.y;
537 freeglut_assert_ready;
539 while( XPending( fgDisplay.Display ) )
541 XNextEvent( fgDisplay.Display, &event );
547 * Destroy the window when the WM_DELETE_WINDOW message arrives
549 if( (Atom) event.xclient.data.l[ 0 ] == fgDisplay.DeleteWindow )
551 GETWINDOW( xclient );
553 fgDestroyWindow ( window );
555 if( fgState.ActionOnWindowClose == GLUT_ACTION_EXIT )
561 fgState.ExecState = GLUT_EXEC_STATE_STOP;
567 * CreateNotify causes a configure-event so that sub-windows are
568 * handled compatibly with GLUT. Otherwise, your sub-windows
569 * (in freeglut only) will not get an initial reshape event,
570 * which can break things.
572 * GLUT presumably does this because it generally tries to treat
573 * sub-windows the same as windows.
575 * XXX Technically, GETWINDOW( xconfigure ) and
576 * XXX {event.xconfigure} may not be legit ways to get at
577 * XXX data for CreateNotify events. In practice, the data
578 * XXX is in a union which is laid out much the same either
579 * XXX way. But if you want to split hairs, this isn't legit,
580 * XXX and we should instead duplicate some code.
583 case ConfigureNotify:
584 GETWINDOW( xconfigure );
586 int width = event.xconfigure.width;
587 int height = event.xconfigure.height;
589 if( ( width != window->State.OldWidth ) ||
590 ( height != window->State.OldHeight ) )
592 window->State.OldWidth = width;
593 window->State.OldHeight = height;
594 if( FETCH_WCB( *window, Reshape ) )
595 INVOKE_WCB( *window, Reshape, ( width, height ) );
598 fgSetWindow( window );
599 glViewport( 0, 0, width, height );
601 glutPostRedisplay( );
608 * This is sent to confirm the XDestroyWindow call.
610 * XXX WHY is this commented out? Should we re-enable it?
612 /* fgAddToWindowDestroyList ( window ); */
617 * We are too dumb to process partial exposes...
619 * XXX Well, we could do it. However, it seems to only
620 * XXX be potentially useful for single-buffered (since
621 * XXX double-buffered does not respect viewport when we
622 * XXX do a buffer-swap).
625 if( event.xexpose.count == 0 )
627 GETWINDOW( xexpose );
628 fgSetWindow( window );
629 glutPostRedisplay( );
636 * If we never do anything with this, can we just not ask to
637 * get these messages?
643 * Have the client's keyboard knowledge updated (xlib.ps,
644 * page 206, says that's a good thing to do)
646 XRefreshKeyboardMapping( (XMappingEvent *) &event );
649 case VisibilityNotify:
651 GETWINDOW( xvisibility );
653 * XXX INVOKE_WCB() does this check for us.
655 if( ! FETCH_WCB( *window, WindowStatus ) )
657 fgSetWindow( window );
660 * Sending this event, the X server can notify us that the window
661 * has just acquired one of the three possible visibility states:
662 * VisibilityUnobscured, VisibilityPartiallyObscured or
663 * VisibilityFullyObscured
665 switch( event.xvisibility.state )
667 case VisibilityUnobscured:
668 INVOKE_WCB( *window, WindowStatus, ( GLUT_FULLY_RETAINED ) );
669 window->State.Visible = GL_TRUE;
672 case VisibilityPartiallyObscured:
673 INVOKE_WCB( *window, WindowStatus,
674 ( GLUT_PARTIALLY_RETAINED ) );
675 window->State.Visible = GL_TRUE;
678 case VisibilityFullyObscured:
679 INVOKE_WCB( *window, WindowStatus, ( GLUT_FULLY_COVERED ) );
680 window->State.Visible = GL_FALSE;
684 fgWarning( "Uknown X visibility state: %d",
685 event.xvisibility.state );
693 GETWINDOW( xcrossing );
694 GETMOUSE( xcrossing );
695 INVOKE_WCB( *window, Entry, ( ( EnterNotify == event.type ) ?
702 GETWINDOW( xmotion );
705 if( window->ActiveMenu )
707 if( window == window->ActiveMenu->ParentWindow )
709 window->ActiveMenu->Window->State.MouseX =
710 event.xmotion.x_root - window->ActiveMenu->X;
711 window->ActiveMenu->Window->State.MouseY =
712 event.xmotion.y_root - window->ActiveMenu->Y;
714 window->ActiveMenu->Window->State.Redisplay = GL_TRUE ;
715 fgSetWindow( window->ActiveMenu->ParentWindow );
721 * XXX For more than 5 buttons, just check {event.xmotion.state},
722 * XXX rather than a host of bit-masks? Or maybe we need to
723 * XXX track ButtonPress/ButtonRelease events in our own
726 #define BUTTON_MASK \
727 ( Button1Mask | Button2Mask | Button3Mask | Button4Mask | Button5Mask )
728 if ( event.xmotion.state & BUTTON_MASK )
729 INVOKE_WCB( *window, Motion, ( event.xmotion.x,
732 INVOKE_WCB( *window, Passive, ( event.xmotion.x,
740 GLboolean pressed = GL_TRUE;
743 if( event.type == ButtonRelease )
747 * A mouse button has been pressed or released. Traditionally,
748 * break if the window was found within the freeglut structures.
750 GETWINDOW( xbutton );
754 * An X button (at least in XFree86) is numbered from 1.
755 * A GLUT button is numbered from 0.
756 * Old GLUT passed through buttons other than just the first
757 * three, though it only gave symbolic names and official
758 * support to the first three.
760 button = event.xbutton.button - 1;
763 * XXX This comment is replicated in the WIN32 section and
764 * XXX maybe also in the menu code. Can we move the info
765 * XXX to one central place and *reference* it from here?
767 * Do not execute the application's mouse callback if a menu
768 * is hooked to this button. In that case an appropriate
769 * private call should be generated.
770 * Near as I can tell, this is the menu behaviour:
771 * - Down-click the menu button, menu not active: activate
772 * the menu with its upper left-hand corner at the mouse
774 * - Down-click any button outside the menu, menu active:
775 * deactivate the menu
776 * - Down-click any button inside the menu, menu active:
777 * select the menu entry and deactivate the menu
778 * - Up-click the menu button, menu not active: nothing happens
779 * - Up-click the menu button outside the menu, menu active:
781 * - Up-click the menu button inside the menu, menu active:
782 * select the menu entry and deactivate the menu
784 /* Window has an active menu, it absorbs any mouse click */
785 if( window->ActiveMenu )
787 if( window == window->ActiveMenu->ParentWindow )
789 window->ActiveMenu->Window->State.MouseX =
790 event.xbutton.x_root - window->ActiveMenu->X;
791 window->ActiveMenu->Window->State.MouseY =
792 event.xbutton.y_root - window->ActiveMenu->Y;
795 /* In the menu, invoke the callback and deactivate the menu*/
796 if( fgCheckActiveMenu( window->ActiveMenu->Window,
797 window->ActiveMenu ) )
800 * Save the current window and menu and set the current
801 * window to the window whose menu this is
803 SFG_Window *save_window = fgStructure.Window;
804 SFG_Menu *save_menu = fgStructure.Menu;
805 SFG_Window *parent_window =
806 window->ActiveMenu->ParentWindow;
807 fgSetWindow( parent_window );
808 fgStructure.Menu = window->ActiveMenu;
810 /* Execute the menu callback */
811 fgExecuteMenuCallback( window->ActiveMenu );
812 fgDeactivateMenu( parent_window );
814 /* Restore the current window and menu */
815 fgSetWindow( save_window );
816 fgStructure.Menu = save_menu;
820 * Outside the menu, deactivate if it's a downclick
822 * XXX This isn't enough. A downclick outside of
823 * XXX the interior of our freeglut windows should also
824 * XXX deactivate the menu. This is more complicated.
826 fgDeactivateMenu( window->ActiveMenu->ParentWindow );
829 * XXX Why does an active menu require a redisplay at
830 * XXX this point? If this can come out cleanly, then
831 * XXX it probably should do so; if not, a comment should
834 window->State.Redisplay = GL_TRUE;
839 * No active menu, let's check whether we need to activate one.
841 if( ( 0 <= button ) &&
842 ( FREEGLUT_MAX_MENUS > button ) &&
843 ( window->Menu[ button ] ) &&
847 * XXX Posting a requisite Redisplay seems bogus.
849 window->State.Redisplay = GL_TRUE;
850 fgSetWindow( window );
851 fgActivateMenu( window, button );
856 * Check if there is a mouse or mouse wheel callback hooked to the
859 if( ! FETCH_WCB( *window, Mouse ) &&
860 ! FETCH_WCB( *window, MouseWheel ) )
863 fgState.Modifiers = fgGetXModifiers( &event );
866 * Finally execute the mouse or mouse wheel callback
868 * XXX Use a symbolic constant, *not* "4"! ("3, sire!")
870 if( ( button < 3 ) || ( ! FETCH_WCB( *window, MouseWheel ) ) )
871 INVOKE_WCB( *window, Mouse, ( button,
872 pressed ? GLUT_DOWN : GLUT_UP,
879 * Map 4 and 5 to wheel zero; EVEN to +1, ODD to -1
880 * " 6 and 7 " " one; ...
882 * XXX This *should* be behind some variables/macros,
883 * XXX since the order and numbering isn't certain
884 * XXX See XFree86 configuration docs (even back in the
885 * XXX 3.x days, and especially with 4.x).
887 * XXX Note that {button} has already been decremeted
888 * XXX in mapping from X button numbering to GLUT.
890 int wheel_number = (button - 3) / 2;
896 INVOKE_WCB( *window, MouseWheel, ( wheel_number,
904 * Trash the modifiers state
906 fgState.Modifiers = 0xffffffff;
913 FGCBKeyboard keyboard_cb;
914 FGCBSpecial special_cb;
919 /* Detect auto repeated keys, if configured globally or per-window */
921 if ( fgState.KeyRepeat==GLUT_KEY_REPEAT_OFF || window->State.IgnoreKeyRepeat==GL_TRUE )
923 if (event.type==KeyRelease)
926 * Look at X11 keystate to detect repeat mode.
927 * While X11 says the key is actually held down, we'll ignore KeyRelease/KeyPress pairs.
931 XQueryKeymap( fgDisplay.Display, keys ); /* Look at X11 keystate to detect repeat mode */
933 if ( keys[event.xkey.keycode>>3] & (1<<(event.xkey.keycode%8)) )
934 window->State.KeyRepeating = GL_TRUE;
936 window->State.KeyRepeating = GL_FALSE;
940 window->State.KeyRepeating = GL_FALSE;
942 /* Cease processing this event if it is auto repeated */
944 if (window->State.KeyRepeating)
947 if( event.type == KeyPress )
949 keyboard_cb = FETCH_WCB( *window, Keyboard );
950 special_cb = FETCH_WCB( *window, Special );
954 keyboard_cb = FETCH_WCB( *window, KeyboardUp );
955 special_cb = FETCH_WCB( *window, SpecialUp );
959 * Is there a keyboard/special callback hooked for this window?
961 if( keyboard_cb || special_cb )
963 XComposeStatus composeStatus;
964 char asciiCode[ 32 ];
969 * Check for the ASCII/KeySym codes associated with the event:
971 len = XLookupString( &event.xkey, asciiCode, sizeof(asciiCode),
972 &keySym, &composeStatus
976 * GLUT API tells us to have two separate callbacks...
981 * ...one for the ASCII translateable keypresses...
985 fgSetWindow( window );
986 fgState.Modifiers = fgGetXModifiers( &event );
987 keyboard_cb( asciiCode[ 0 ],
988 event.xkey.x, event.xkey.y
990 fgState.Modifiers = 0xffffffff;
998 * ...and one for all the others, which need to be
999 * translated to GLUT_KEY_Xs...
1003 case XK_F1: special = GLUT_KEY_F1; break;
1004 case XK_F2: special = GLUT_KEY_F2; break;
1005 case XK_F3: special = GLUT_KEY_F3; break;
1006 case XK_F4: special = GLUT_KEY_F4; break;
1007 case XK_F5: special = GLUT_KEY_F5; break;
1008 case XK_F6: special = GLUT_KEY_F6; break;
1009 case XK_F7: special = GLUT_KEY_F7; break;
1010 case XK_F8: special = GLUT_KEY_F8; break;
1011 case XK_F9: special = GLUT_KEY_F9; break;
1012 case XK_F10: special = GLUT_KEY_F10; break;
1013 case XK_F11: special = GLUT_KEY_F11; break;
1014 case XK_F12: special = GLUT_KEY_F12; break;
1016 case XK_Left: special = GLUT_KEY_LEFT; break;
1017 case XK_Right: special = GLUT_KEY_RIGHT; break;
1018 case XK_Up: special = GLUT_KEY_UP; break;
1019 case XK_Down: special = GLUT_KEY_DOWN; break;
1022 case XK_Prior: special = GLUT_KEY_PAGE_UP; break;
1024 case XK_Next: special = GLUT_KEY_PAGE_DOWN; break;
1026 case XK_Home: special = GLUT_KEY_HOME; break;
1028 case XK_End: special = GLUT_KEY_END; break;
1030 case XK_Insert: special = GLUT_KEY_INSERT; break;
1034 * Execute the callback (if one has been specified),
1035 * given that the special code seems to be valid...
1037 if( special_cb && (special != -1) )
1039 fgSetWindow( window );
1040 fgState.Modifiers = fgGetXModifiers( &event );
1041 special_cb( special, event.xkey.x, event.xkey.y );
1042 fgState.Modifiers = 0xffffffff;
1049 case ReparentNotify:
1050 break; /* XXX Should disable this event */
1053 fgWarning ("Unknown X event type: %d", event.type);
1058 #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE
1062 while( PeekMessage( &stMsg, NULL, 0, 0, PM_NOREMOVE ) )
1064 if( GetMessage( &stMsg, NULL, 0, 0 ) == 0 )
1066 if( fgState.ActionOnWindowClose == GLUT_ACTION_EXIT )
1071 fgState.ExecState = GLUT_EXEC_STATE_STOP;
1075 TranslateMessage( &stMsg );
1076 DispatchMessage( &stMsg );
1080 if( fgState.Timers.First )
1082 fghCheckJoystickPolls( );
1089 * Enters the freeglut processing loop.
1090 * Stays until the "ExecState" changes to "GLUT_EXEC_STATE_STOP".
1092 void FGAPIENTRY glutMainLoop( void )
1096 #if TARGET_HOST_WIN32 || TARGET_HOST_WINCE
1097 SFG_Window *window = (SFG_Window *)fgStructure.Windows.First ;
1100 freeglut_assert_ready;
1102 #if TARGET_HOST_WIN32 || TARGET_HOST_WINCE
1104 * Processing before the main loop: If there is a window which is open and
1105 * which has a visibility callback, call it. I know this is an ugly hack,
1106 * but I'm not sure what else to do about it. Ideally we should leave
1107 * something uninitialized in the create window code and initialize it in
1108 * the main loop, and have that initialization create a "WM_ACTIVATE"
1109 * message. Then we would put the visibility callback code in the
1110 * "case WM_ACTIVATE" block below. - John Fay -- 10/24/02
1114 if ( FETCH_WCB( *window, Visibility ) )
1116 SFG_Window *current_window = fgStructure.Window ;
1118 INVOKE_WCB( *window, Visibility, ( window->State.Visible ) );
1119 fgSetWindow( current_window );
1122 window = (SFG_Window *)window->Node.Next ;
1126 fgState.ExecState = GLUT_EXEC_STATE_RUNNING ;
1127 while( fgState.ExecState == GLUT_EXEC_STATE_RUNNING )
1131 glutMainLoopEvent( );
1133 * Step through the list of windows, seeing if there are any
1134 * that are not menus
1136 for( window = ( SFG_Window * )fgStructure.Windows.First;
1138 window = ( SFG_Window * )window->Node.Next )
1139 if ( ! ( window->IsMenu ) )
1143 fgState.ExecState = GLUT_EXEC_STATE_STOP;
1146 if( fgState.IdleCallback )
1147 fgState.IdleCallback( );
1149 fgSleepForEvents( );
1154 * When this loop terminates, destroy the display, state and structure
1155 * of a freeglut session, so that another glutInit() call can happen
1157 * Save the "ActionOnWindowClose" because "fgDeinitialize" resets it.
1159 action = fgState.ActionOnWindowClose;
1161 if( action == GLUT_ACTION_EXIT )
1166 * Leaves the freeglut processing loop.
1168 void FGAPIENTRY glutLeaveMainLoop( void )
1170 fgState.ExecState = GLUT_EXEC_STATE_STOP ;
1174 #if TARGET_HOST_WIN32 || TARGET_HOST_WINCE
1176 * Determine a GLUT modifer mask based on MS-WINDOWS system info.
1178 int fgGetWin32Modifiers (void)
1181 ( ( ( GetKeyState( VK_LSHIFT ) < 0 ) ||
1182 ( GetKeyState( VK_RSHIFT ) < 0 )) ? GLUT_ACTIVE_SHIFT : 0 ) |
1183 ( ( ( GetKeyState( VK_LCONTROL ) < 0 ) ||
1184 ( GetKeyState( VK_RCONTROL ) < 0 )) ? GLUT_ACTIVE_CTRL : 0 ) |
1185 ( ( ( GetKeyState( VK_LMENU ) < 0 ) ||
1186 ( GetKeyState( VK_RMENU ) < 0 )) ? GLUT_ACTIVE_ALT : 0 );
1190 * The window procedure for handling Win32 events
1192 LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam,
1195 SFG_Window* window = fgWindowByHandle( hWnd );
1199 if ( ( window == NULL ) && ( uMsg != WM_CREATE ) )
1200 return DefWindowProc( hWnd, uMsg, wParam, lParam );
1202 /* printf ( "Window %3d message <%04x> %12d %12d\n", window?window->ID:0,
1203 uMsg, wParam, lParam ); */
1208 * The window structure is passed as the creation structure paramter...
1210 window = (SFG_Window *) (((LPCREATESTRUCT) lParam)->lpCreateParams);
1211 assert( window != NULL );
1213 window->Window.Handle = hWnd;
1214 window->Window.Device = GetDC( hWnd );
1215 if( window->IsMenu )
1217 unsigned int current_DisplayMode = fgState.DisplayMode;
1218 fgState.DisplayMode = GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH;
1219 #if !TARGET_HOST_WINCE
1220 fgSetupPixelFormat( window, GL_FALSE, PFD_MAIN_PLANE );
1222 fgState.DisplayMode = current_DisplayMode;
1224 if( fgStructure.MenuContext )
1225 wglMakeCurrent( window->Window.Device,
1226 fgStructure.MenuContext->Context
1230 fgStructure.MenuContext =
1231 (SFG_MenuContext *)malloc( sizeof(SFG_MenuContext) );
1232 fgStructure.MenuContext->Context =
1233 wglCreateContext( window->Window.Device );
1236 /* window->Window.Context = wglGetCurrentContext (); */
1237 window->Window.Context = wglCreateContext( window->Window.Device );
1241 #if !TARGET_HOST_WINCE
1242 fgSetupPixelFormat( window, GL_FALSE, PFD_MAIN_PLANE );
1245 if( ! fgState.UseCurrentContext )
1246 window->Window.Context =
1247 wglCreateContext( window->Window.Device );
1250 window->Window.Context = wglGetCurrentContext( );
1251 if( ! window->Window.Context )
1252 window->Window.Context =
1253 wglCreateContext( window->Window.Device );
1257 window->State.NeedToResize = GL_TRUE;
1258 window->State.Width = fgState.Size.X;
1259 window->State.Height = fgState.Size.Y;
1261 ReleaseDC( window->Window.Handle, window->Window.Device );
1266 * If the window is visible, then it is the user manually resizing it.
1267 * If it is not, then it is the system sending us a dummy resize with
1268 * zero dimensions on a "glutIconifyWindow" call.
1270 if( window->State.Visible )
1272 window->State.NeedToResize = GL_TRUE;
1273 #if TARGET_HOST_WINCE
1274 window->State.Width = HIWORD(lParam);
1275 window->State.Height = LOWORD(lParam);
1277 window->State.Width = LOWORD(lParam);
1278 window->State.Height = HIWORD(lParam);
1279 #endif //TARGET_HOST_WINCE
1285 printf("WM_SETFOCUS: %p\n", window );
1286 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1290 if (LOWORD(wParam) != WA_INACTIVE)
1292 /* glutSetCursor( fgStructure.Window->State.Cursor ); */
1293 printf("WM_ACTIVATE: glutSetCursor( %p, %d)\n", window,
1294 window->State.Cursor );
1295 glutSetCursor( window->State.Cursor );
1298 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1303 * XXX Why not re-use some common code with the glutSetCursor()
1304 * XXX function (or perhaps invoke glutSetCursor())?
1305 * XXX That is, why are we duplicating code, here, from
1306 * XXX glutSetCursor()? The WIN32 code should be able to just
1307 * XXX call glutSetCurdsor() instead of defining two macros
1308 * XXX and implementing a nested case in-line.
1311 /* Set the cursor AND change it for this window class. */
1312 #define MAP_CURSOR(a,b) \
1314 SetCursor( LoadCursor( NULL, b ) ); \
1317 /* Nuke the cursor AND change it for this window class. */
1318 #define ZAP_CURSOR(a,b) \
1320 SetCursor( NULL ); \
1323 if( LOWORD( lParam ) == HTCLIENT )
1324 switch( window->State.Cursor )
1326 MAP_CURSOR( GLUT_CURSOR_RIGHT_ARROW, IDC_ARROW );
1327 MAP_CURSOR( GLUT_CURSOR_LEFT_ARROW, IDC_ARROW );
1328 MAP_CURSOR( GLUT_CURSOR_INFO, IDC_HELP );
1329 MAP_CURSOR( GLUT_CURSOR_DESTROY, IDC_CROSS );
1330 MAP_CURSOR( GLUT_CURSOR_HELP, IDC_HELP );
1331 MAP_CURSOR( GLUT_CURSOR_CYCLE, IDC_SIZEALL );
1332 MAP_CURSOR( GLUT_CURSOR_SPRAY, IDC_CROSS );
1333 MAP_CURSOR( GLUT_CURSOR_WAIT, IDC_WAIT );
1334 MAP_CURSOR( GLUT_CURSOR_TEXT, IDC_UPARROW );
1335 MAP_CURSOR( GLUT_CURSOR_CROSSHAIR, IDC_CROSS );
1336 /* MAP_CURSOR( GLUT_CURSOR_NONE, IDC_NO ); */
1337 ZAP_CURSOR( GLUT_CURSOR_NONE, NULL );
1340 MAP_CURSOR( GLUT_CURSOR_UP_DOWN, IDC_ARROW );
1343 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1347 window->State.Visible = GL_TRUE;
1348 window->State.Redisplay = GL_TRUE;
1352 /* Turn on the visibility in case it was turned off somehow */
1353 window->State.Visible = GL_TRUE;
1354 BeginPaint( hWnd, &ps );
1355 fghRedrawWindowByHandle( hWnd );
1356 EndPaint( hWnd, &ps );
1360 fgDestroyWindow ( window );
1361 if ( fgState.ActionOnWindowClose != GLUT_ACTION_CONTINUE_EXECUTION )
1367 * The window already got destroyed, so don't bother with it.
1373 window->State.MouseX = LOWORD( lParam );
1374 window->State.MouseY = HIWORD( lParam );
1376 if ( window->ActiveMenu )
1378 window->State.Redisplay = GL_TRUE;
1379 fgSetWindow ( window->ActiveMenu->ParentWindow );
1383 fgState.Modifiers = fgGetWin32Modifiers( );
1385 if( ( wParam & MK_LBUTTON ) ||
1386 ( wParam & MK_MBUTTON ) ||
1387 ( wParam & MK_RBUTTON ) )
1388 INVOKE_WCB( *window, Motion, ( window->State.MouseX,
1389 window->State.MouseY ) );
1391 INVOKE_WCB( *window, Passive, ( window->State.MouseX,
1392 window->State.MouseY ) );
1394 fgState.Modifiers = 0xffffffff;
1398 case WM_LBUTTONDOWN:
1399 case WM_MBUTTONDOWN:
1400 case WM_RBUTTONDOWN:
1405 GLboolean pressed = GL_TRUE;
1408 window->State.MouseX = LOWORD( lParam );
1409 window->State.MouseY = HIWORD( lParam );
1413 case WM_LBUTTONDOWN:
1415 button = GLUT_LEFT_BUTTON;
1417 case WM_MBUTTONDOWN:
1419 button = GLUT_MIDDLE_BUTTON;
1421 case WM_RBUTTONDOWN:
1423 button = GLUT_RIGHT_BUTTON;
1427 button = GLUT_LEFT_BUTTON;
1431 button = GLUT_MIDDLE_BUTTON;
1435 button = GLUT_RIGHT_BUTTON;
1443 #if !TARGET_HOST_WINCE
1444 if( GetSystemMetrics( SM_SWAPBUTTON ) )
1446 if( button == GLUT_LEFT_BUTTON )
1447 button = GLUT_RIGHT_BUTTON;
1449 if( button == GLUT_RIGHT_BUTTON )
1450 button = GLUT_LEFT_BUTTON;
1452 #endif //!TARGET_HOST_WINCE
1455 return DefWindowProc( hWnd, uMsg, lParam, wParam );
1458 * XXX This comment is duplicated in two other spots.
1459 * XXX Can we centralize it?
1461 * Do not execute the application's mouse callback if a
1462 * menu is hooked to this button.
1463 * In that case an appropriate private call should be generated.
1464 * Near as I can tell, this is the menu behaviour:
1465 * - Down-click the menu button, menu not active: activate
1466 * the menu with its upper left-hand corner at the mouse location.
1467 * - Down-click any button outside the menu, menu active:
1468 * deactivate the menu
1469 * - Down-click any button inside the menu, menu active:
1470 * select the menu entry and deactivate the menu
1471 * - Up-click the menu button, menu not active: nothing happens
1472 * - Up-click the menu button outside the menu, menu active:
1474 * - Up-click the menu button inside the menu, menu active:
1475 * select the menu entry and deactivate the menu
1477 /* Window has an active menu, it absorbs any mouse click */
1478 if( window->ActiveMenu )
1480 /* Outside the menu, deactivate the menu if it's a downclick */
1481 if( ! fgCheckActiveMenu( window, window->ActiveMenu ) )
1484 fgDeactivateMenu( window->ActiveMenu->ParentWindow );
1486 else /* In menu, invoke the callback and deactivate the menu*/
1489 * Save the current window and menu and set the current
1490 * window to the window whose menu this is
1492 SFG_Window *save_window = fgStructure.Window;
1493 SFG_Menu *save_menu = fgStructure.Menu;
1494 SFG_Window *parent_window = window->ActiveMenu->ParentWindow;
1495 fgSetWindow( parent_window );
1496 fgStructure.Menu = window->ActiveMenu;
1498 /* Execute the menu callback */
1499 fgExecuteMenuCallback( window->ActiveMenu );
1500 fgDeactivateMenu( parent_window );
1502 /* Restore the current window and menu */
1503 fgSetWindow( save_window );
1504 fgStructure.Menu = save_menu;
1508 * Let's make the window redraw as a result of the mouse
1509 * click and menu activity.
1511 if( ! window->IsMenu )
1512 window->State.Redisplay = GL_TRUE;
1517 if( window->Menu[ button ] && pressed )
1519 window->State.Redisplay = GL_TRUE;
1520 fgSetWindow( window );
1521 fgActivateMenu( window, button );
1526 if( ! FETCH_WCB( *window, Mouse ) )
1529 fgSetWindow( window );
1530 fgState.Modifiers = fgGetWin32Modifiers( );
1535 pressed ? GLUT_DOWN : GLUT_UP,
1536 window->State.MouseX,
1537 window->State.MouseY
1541 fgState.Modifiers = 0xffffffff;
1546 /* Should be WM_MOUSEWHEEL but my compiler doesn't recognize it */
1549 * XXX THIS IS SPECULATIVE -- John Fay, 10/2/03
1550 * XXX Should use WHEEL_DELTA instead of 120
1552 int wheel_number = LOWORD( wParam );
1553 short ticks = ( short )HIWORD( wParam ) / 120;
1563 * The mouse cursor has moved. Remember the new mouse cursor's position
1565 /* window->State.MouseX = LOWORD( lParam ); */
1566 /* Need to adjust by window position, */
1567 /* window->State.MouseY = HIWORD( lParam ); */
1568 /* change "lParam" to other parameter */
1570 if( ! FETCH_WCB( *window, MouseWheel ) &&
1571 ! FETCH_WCB( *window, Mouse ) )
1574 fgSetWindow( window );
1575 fgState.Modifiers = fgGetWin32Modifiers( );
1578 if( FETCH_WCB( *window, MouseWheel ) )
1579 INVOKE_WCB( *window, MouseWheel,
1582 window->State.MouseX,
1583 window->State.MouseY
1586 else /* No mouse wheel, call the mouse button callback twice */
1589 * XXX The below assumes that you have no more than 3 mouse
1590 * XXX buttons. Sorry.
1592 int button = wheel_number*2 + 4;
1595 INVOKE_WCB( *window, Mouse,
1596 ( button, GLUT_DOWN,
1597 window->State.MouseX, window->State.MouseY )
1599 INVOKE_WCB( *window, Mouse,
1601 window->State.MouseX, window->State.MouseX )
1605 fgState.Modifiers = 0xffffffff;
1615 if( ( fgState.KeyRepeat==GLUT_KEY_REPEAT_OFF || window->State.IgnoreKeyRepeat==GL_TRUE ) && (HIWORD(lParam) & KF_REPEAT) )
1619 * Remember the current modifiers state. This is done here in order
1620 * to make sure the VK_DELETE keyboard callback is executed properly.
1622 fgState.Modifiers = fgGetWin32Modifiers( );
1624 GetCursorPos( &mouse_pos );
1625 ScreenToClient( window->Window.Handle, &mouse_pos );
1627 window->State.MouseX = mouse_pos.x;
1628 window->State.MouseY = mouse_pos.y;
1631 * Convert the Win32 keystroke codes to GLUTtish way
1633 # define KEY(a,b) case a: keypress = b; break;
1637 KEY( VK_F1, GLUT_KEY_F1 );
1638 KEY( VK_F2, GLUT_KEY_F2 );
1639 KEY( VK_F3, GLUT_KEY_F3 );
1640 KEY( VK_F4, GLUT_KEY_F4 );
1641 KEY( VK_F5, GLUT_KEY_F5 );
1642 KEY( VK_F6, GLUT_KEY_F6 );
1643 KEY( VK_F7, GLUT_KEY_F7 );
1644 KEY( VK_F8, GLUT_KEY_F8 );
1645 KEY( VK_F9, GLUT_KEY_F9 );
1646 KEY( VK_F10, GLUT_KEY_F10 );
1647 KEY( VK_F11, GLUT_KEY_F11 );
1648 KEY( VK_F12, GLUT_KEY_F12 );
1649 KEY( VK_PRIOR, GLUT_KEY_PAGE_UP );
1650 KEY( VK_NEXT, GLUT_KEY_PAGE_DOWN );
1651 KEY( VK_HOME, GLUT_KEY_HOME );
1652 KEY( VK_END, GLUT_KEY_END );
1653 KEY( VK_LEFT, GLUT_KEY_LEFT );
1654 KEY( VK_UP, GLUT_KEY_UP );
1655 KEY( VK_RIGHT, GLUT_KEY_RIGHT );
1656 KEY( VK_DOWN, GLUT_KEY_DOWN );
1657 KEY( VK_INSERT, GLUT_KEY_INSERT );
1661 * The delete key should be treated as an ASCII keypress:
1663 INVOKE_WCB( *window, Keyboard,
1664 ( 127, window->State.MouseX, window->State.MouseY )
1668 if( keypress != -1 )
1669 INVOKE_WCB( *window, Special,
1671 window->State.MouseX, window->State.MouseY )
1674 fgState.Modifiers = 0xffffffff;
1685 * Remember the current modifiers state. This is done here in order
1686 * to make sure the VK_DELETE keyboard callback is executed properly.
1688 fgState.Modifiers = fgGetWin32Modifiers( );
1690 GetCursorPos( &mouse_pos );
1691 ScreenToClient( window->Window.Handle, &mouse_pos );
1693 window->State.MouseX = mouse_pos.x;
1694 window->State.MouseY = mouse_pos.y;
1697 * Convert the Win32 keystroke codes to GLUTtish way.
1698 * "KEY(a,b)" was defined under "WM_KEYDOWN"
1703 KEY( VK_F1, GLUT_KEY_F1 );
1704 KEY( VK_F2, GLUT_KEY_F2 );
1705 KEY( VK_F3, GLUT_KEY_F3 );
1706 KEY( VK_F4, GLUT_KEY_F4 );
1707 KEY( VK_F5, GLUT_KEY_F5 );
1708 KEY( VK_F6, GLUT_KEY_F6 );
1709 KEY( VK_F7, GLUT_KEY_F7 );
1710 KEY( VK_F8, GLUT_KEY_F8 );
1711 KEY( VK_F9, GLUT_KEY_F9 );
1712 KEY( VK_F10, GLUT_KEY_F10 );
1713 KEY( VK_F11, GLUT_KEY_F11 );
1714 KEY( VK_F12, GLUT_KEY_F12 );
1715 KEY( VK_PRIOR, GLUT_KEY_PAGE_UP );
1716 KEY( VK_NEXT, GLUT_KEY_PAGE_DOWN );
1717 KEY( VK_HOME, GLUT_KEY_HOME );
1718 KEY( VK_END, GLUT_KEY_END );
1719 KEY( VK_LEFT, GLUT_KEY_LEFT );
1720 KEY( VK_UP, GLUT_KEY_UP );
1721 KEY( VK_RIGHT, GLUT_KEY_RIGHT );
1722 KEY( VK_DOWN, GLUT_KEY_DOWN );
1723 KEY( VK_INSERT, GLUT_KEY_INSERT );
1727 * The delete key should be treated as an ASCII keypress:
1729 INVOKE_WCB( *window, KeyboardUp,
1730 ( 127, window->State.MouseX, window->State.MouseY )
1736 #if !TARGET_HOST_WINCE
1740 GetKeyboardState( state );
1742 if( ToAscii( wParam, 0, state, code, 0 ) == 1 )
1745 INVOKE_WCB( *window, KeyboardUp,
1747 window->State.MouseX, window->State.MouseY )
1749 #endif //!TARGET_HOST_WINCE
1753 if( keypress != -1 )
1754 INVOKE_WCB( *window, SpecialUp,
1756 window->State.MouseX, window->State.MouseY )
1759 fgState.Modifiers = 0xffffffff;
1766 if( (fgState.KeyRepeat==GLUT_KEY_REPEAT_OFF || window->State.IgnoreKeyRepeat==GL_TRUE) && (HIWORD(lParam) & KF_REPEAT) )
1769 fgState.Modifiers = fgGetWin32Modifiers( );
1770 INVOKE_WCB( *window, Keyboard,
1772 window->State.MouseX, window->State.MouseY )
1774 fgState.Modifiers = 0xffffffff;
1778 case WM_CAPTURECHANGED:
1779 /* User has finished resizing the window, force a redraw */
1780 INVOKE_WCB( *window, Display, ( ) );
1782 /*lRet = DefWindowProc( hWnd, uMsg, wParam, lParam ); */
1786 * Other messages that I have seen and which are not handled already
1788 case WM_SETTEXT: /* 0x000c */
1789 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1790 /* Pass it on to "DefWindowProc" to set the window text */
1793 case WM_GETTEXT: /* 0x000d */
1794 /* Ideally we would copy the title of the window into "lParam" */
1795 /* strncpy ( (char *)lParam, "Window Title", wParam );
1796 lRet = ( wParam > 12 ) ? 12 : wParam; */
1797 /* the number of characters copied */
1798 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1801 case WM_GETTEXTLENGTH: /* 0x000e */
1802 /* Ideally we would get the length of the title of the window */
1804 /* the number of characters in "Window Title\0" (see above) */
1807 case WM_ERASEBKGND: /* 0x0014 */
1808 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1811 #if !TARGET_HOST_WINCE
1812 case WM_SYNCPAINT: /* 0x0088 */
1813 /* Another window has moved, need to update this one */
1814 window->State.Redisplay = GL_TRUE;
1815 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1816 /* Help screen says this message must be passed to "DefWindowProc" */
1819 case WM_NCPAINT: /* 0x0085 */
1820 /* Need to update the border of this window */
1821 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1822 /* Pass it on to "DefWindowProc" to repaint a standard border */
1825 case WM_SYSCOMMAND : /* 0x0112 */
1828 * We have received a system command message. Try to act on it.
1829 * The commands are passed in through the "lParam" parameter:
1830 * Clicking on a corner to resize the window gives a "F004" message
1831 * but this is not defined in my header file.
1842 /* User has clicked on the "-" to minimize the window */
1843 /* Turn off the visibility */
1844 window->State.Visible = GL_FALSE ;
1851 case SC_NEXTWINDOW :
1854 case SC_PREVWINDOW :
1858 /* Followed very closely by a WM_CLOSE message */
1882 case SC_SCREENSAVE :
1889 #endif //!TARGET_HOST_WINCE
1891 /* We need to pass the message on to the operating system as well */
1892 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1897 * Handle unhandled messages
1899 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1907 /*** END OF FILE ***/