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.
28 #include <GL/freeglut.h>
29 #include "freeglut_internal.h"
32 #if TARGET_HOST_UNIX_X11
35 #elif TARGET_HOST_WIN32
36 #elif TARGET_HOST_WINCE
38 typedef struct GXDisplayProperties GXDisplayProperties;
39 typedef struct GXKeyList GXKeyList;
42 typedef struct GXKeyList (*GXGETDEFAULTKEYS)(int);
43 typedef int (*GXOPENINPUT)();
45 GXGETDEFAULTKEYS GXGetDefaultKeys_ = NULL;
46 GXOPENINPUT GXOpenInput_ = NULL;
48 struct GXKeyList gxKeyList;
53 #define MAX(a,b) (((a)>(b)) ? (a) : (b))
57 #define MIN(a,b) (((a)<(b)) ? (a) : (b))
62 * TODO BEFORE THE STABLE RELEASE:
64 * There are some issues concerning window redrawing under X11, and maybe
65 * some events are not handled. The Win32 version lacks some more features,
66 * but seems acceptable for not demanding purposes.
68 * Need to investigate why the X11 version breaks out with an error when
69 * closing a window (using the window manager, not glutDestroyWindow)...
72 /* -- PRIVATE FUNCTIONS ---------------------------------------------------- */
75 * Handle a window configuration change. When no reshape
76 * callback is hooked, the viewport size is updated to
77 * match the new window size.
79 static void fghReshapeWindow ( SFG_Window *window, int width, int height )
81 SFG_Window *current_window = fgStructure.Window;
83 freeglut_return_if_fail( window != NULL );
86 #if TARGET_HOST_UNIX_X11
88 XResizeWindow( fgDisplay.Display, window->Window.Handle,
90 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
92 #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE
94 #if !TARGET_HOST_WINCE
100 * For windowed mode, get the current position of the
101 * window and resize taking the size of the frame
102 * decorations into account.
105 /* "GetWindowRect" returns the pixel coordinates of the outside of the window */
106 GetWindowRect( window->Window.Handle, &winRect );
112 if ( window->Parent == NULL )
114 if ( ! window->IsMenu && !window->State.IsGameMode )
116 w += GetSystemMetrics( SM_CXSIZEFRAME ) * 2;
117 h += GetSystemMetrics( SM_CYSIZEFRAME ) * 2 +
118 GetSystemMetrics( SM_CYCAPTION );
124 GetWindowRect( window->Parent->Window.Handle, &parentRect );
125 x -= parentRect.left + GetSystemMetrics( SM_CXSIZEFRAME ) * 2;
126 y -= parentRect.top + GetSystemMetrics( SM_CYSIZEFRAME ) * 2 +
127 GetSystemMetrics( SM_CYCAPTION );
131 * SWP_NOACTIVATE Do not activate the window
132 * SWP_NOOWNERZORDER Do not change position in z-order
133 * SWP_NOSENDCHANGING Supress WM_WINDOWPOSCHANGING message
134 * SWP_NOZORDER Retains the current Z order (ignore 2nd param)
137 SetWindowPos( window->Window.Handle,
140 SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOSENDCHANGING |
144 #endif /* TARGET_HOST_WINCE */
147 * XXX Should update {window->State.OldWidth, window->State.OldHeight}
148 * XXX to keep in lockstep with UNIX_X11 code.
150 if( FETCH_WCB( *window, Reshape ) )
151 INVOKE_WCB( *window, Reshape, ( width, height ) );
154 fgSetWindow( window );
155 glViewport( 0, 0, width, height );
161 * Force a window redraw. In Windows at least this is only a partial
162 * solution: if the window is increasing in size in either dimension,
163 * the already-drawn part does not get drawn again and things look funny.
164 * But without this we get this bad behaviour whenever we resize the
167 window->State.Redisplay = GL_TRUE;
170 fgSetWindow( current_window );
174 * Calls a window's redraw method. This is used when
175 * a redraw is forced by the incoming window messages.
177 static void fghRedrawWindow ( SFG_Window *window )
179 SFG_Window *current_window = fgStructure.Window;
181 freeglut_return_if_fail( window );
182 freeglut_return_if_fail( FETCH_WCB ( *window, Display ) );
184 window->State.Redisplay = GL_FALSE;
186 freeglut_return_if_fail( window->State.Visible );
188 fgSetWindow( window );
190 if( window->State.NeedToResize )
198 window->State.NeedToResize = GL_FALSE;
201 INVOKE_WCB( *window, Display, ( ) );
203 fgSetWindow( current_window );
207 * A static helper function to execute display callback for a window
209 static void fghcbDisplayWindow( SFG_Window *window,
210 SFG_Enumerator *enumerator )
212 if( window->State.Redisplay &&
213 window->State.Visible )
215 window->State.Redisplay = GL_FALSE;
217 #if TARGET_HOST_UNIX_X11
218 fghRedrawWindow ( window ) ;
219 #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE
221 window->Window.Handle, NULL, NULL,
222 RDW_NOERASE | RDW_INTERNALPAINT | RDW_INVALIDATE | RDW_UPDATENOW
227 fgEnumSubWindows( window, fghcbDisplayWindow, enumerator );
231 * Make all windows perform a display call
233 static void fghDisplayAll( void )
235 SFG_Enumerator enumerator;
237 enumerator.found = GL_FALSE;
238 enumerator.data = NULL;
240 fgEnumWindows( fghcbDisplayWindow, &enumerator );
244 * Window enumerator callback to check for the joystick polling code
246 static void fghcbCheckJoystickPolls( SFG_Window *window,
247 SFG_Enumerator *enumerator )
249 long int checkTime = fgElapsedTime( );
251 if( window->State.JoystickLastPoll + window->State.JoystickPollRate <=
254 #if !TARGET_HOST_WINCE
255 fgJoystickPollWindow( window );
256 #endif /* !TARGET_HOST_WINCE */
257 window->State.JoystickLastPoll = checkTime;
260 fgEnumSubWindows( window, fghcbCheckJoystickPolls, enumerator );
264 * Check all windows for joystick polling
266 static void fghCheckJoystickPolls( void )
268 SFG_Enumerator enumerator;
270 enumerator.found = GL_FALSE;
271 enumerator.data = NULL;
273 fgEnumWindows( fghcbCheckJoystickPolls, &enumerator );
277 * Check the global timers
279 static void fghCheckTimers( void )
281 long checkTime = fgElapsedTime( );
283 while( fgState.Timers.First )
285 SFG_Timer *timer = fgState.Timers.First;
287 if( timer->TriggerTime > checkTime )
290 fgListRemove( &fgState.Timers, &timer->Node );
291 fgListAppend( &fgState.FreeTimers, &timer->Node );
293 timer->Callback( timer->ID );
300 long fgElapsedTime( void )
302 if ( fgState.Time.Set )
304 #if TARGET_HOST_UNIX_X11
308 gettimeofday( &now, NULL );
310 elapsed = (now.tv_usec - fgState.Time.Value.tv_usec) / 1000;
311 elapsed += (now.tv_sec - fgState.Time.Value.tv_sec) * 1000;
314 #elif TARGET_HOST_WIN32
315 return timeGetTime() - fgState.Time.Value;
316 #elif TARGET_HOST_WINCE
317 return GetTickCount() - fgState.Time.Value;
322 #if TARGET_HOST_UNIX_X11
323 gettimeofday( &fgState.Time.Value, NULL );
324 #elif TARGET_HOST_WIN32
325 fgState.Time.Value = timeGetTime ();
326 #elif TARGET_HOST_WINCE
327 fgState.Time.Value = GetTickCount();
329 fgState.Time.Set = GL_TRUE ;
338 void fgError( const char *fmt, ... )
344 fprintf( stderr, "freeglut ");
345 if( fgState.ProgramName )
346 fprintf (stderr, "(%s): ", fgState.ProgramName);
347 vfprintf( stderr, fmt, ap );
348 fprintf( stderr, "\n" );
352 if ( fgState.Initialised )
358 void fgWarning( const char *fmt, ... )
364 fprintf( stderr, "freeglut ");
365 if( fgState.ProgramName )
366 fprintf( stderr, "(%s): ", fgState.ProgramName );
367 vfprintf( stderr, fmt, ap );
368 fprintf( stderr, "\n" );
374 * Indicates whether Joystick events are being used by ANY window.
376 * The current mechanism is to walk all of the windows and ask if
377 * there is a joystick callback. We have a short-circuit early
378 * return if we find any joystick handler registered.
380 * The real way to do this is to make use of the glutTimer() API
381 * to more cleanly re-implement the joystick API. Then, this code
382 * and all other "joystick timer" code can be yanked.
385 static void fghCheckJoystickCallback( SFG_Window* w, SFG_Enumerator* e)
387 if( FETCH_WCB( *w, Joystick ) )
392 fgEnumSubWindows( w, fghCheckJoystickCallback, e );
394 static int fghHaveJoystick( void )
396 SFG_Enumerator enumerator;
398 enumerator.found = GL_FALSE;
399 enumerator.data = NULL;
400 fgEnumWindows( fghCheckJoystickCallback, &enumerator );
401 return !!enumerator.data;
403 static void fghHavePendingRedisplaysCallback( SFG_Window* w, SFG_Enumerator* e)
405 if( w->State.Redisplay )
410 fgEnumSubWindows( w, fghHavePendingRedisplaysCallback, e );
412 static int fghHavePendingRedisplays (void)
414 SFG_Enumerator enumerator;
416 enumerator.found = GL_FALSE;
417 enumerator.data = NULL;
418 fgEnumWindows( fghHavePendingRedisplaysCallback, &enumerator );
419 return !!enumerator.data;
422 * Returns the number of GLUT ticks (milliseconds) till the next timer event.
424 static long fghNextTimer( void )
427 SFG_Timer *timer = fgState.Timers.First;
430 ret = timer->TriggerTime - fgElapsedTime();
437 * Does the magic required to relinquish the CPU until something interesting
440 static void fghSleepForEvents( void )
444 if( fgState.IdleCallback || fghHavePendingRedisplays( ) )
447 msec = fghNextTimer( );
448 if( fghHaveJoystick( ) ) /* XXX Use GLUT timers for joysticks... */
449 msec = MIN( msec, 10 ); /* XXX Dumb; forces granularity to .01sec */
451 #if TARGET_HOST_UNIX_X11
453 * Possibly due to aggressive use of XFlush() and friends,
454 * it is possible to have our socket drained but still have
455 * unprocessed events. (Or, this may just be normal with
456 * X, anyway?) We do non-trivial processing of X events
457 * after the event-reading loop, in any case, so we
458 * need to allow that we may have an empty socket but non-
461 if( ! XPending( fgDisplay.Display ) )
468 socket = ConnectionNumber( fgDisplay.Display );
470 FD_SET( socket, &fdset );
471 wait.tv_sec = msec / 1000;
472 wait.tv_usec = (msec % 1000) * 1000;
473 err = select( socket+1, &fdset, NULL, NULL, &wait );
476 fgWarning ( "freeglut select() error: %d", errno );
478 #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE
479 MsgWaitForMultipleObjects( 0, NULL, FALSE, msec, QS_ALLEVENTS );
483 #if TARGET_HOST_UNIX_X11
485 * Returns GLUT modifier mask for an XEvent.
487 static int fghGetXModifiers( XEvent *event )
491 if( event->xkey.state & ( ShiftMask | LockMask ) )
492 ret |= GLUT_ACTIVE_SHIFT;
493 if( event->xkey.state & ControlMask )
494 ret |= GLUT_ACTIVE_CTRL;
495 if( event->xkey.state & Mod1Mask )
496 ret |= GLUT_ACTIVE_ALT;
503 /* -- INTERFACE FUNCTIONS -------------------------------------------------- */
506 * Executes a single iteration in the freeglut processing loop.
508 void FGAPIENTRY glutMainLoopEvent( void )
510 #if TARGET_HOST_UNIX_X11
514 /* This code was repeated constantly, so here it goes into a definition: */
515 #define GETWINDOW(a) \
516 window = fgWindowByHandle( event.a.window ); \
517 if( window == NULL ) \
520 #define GETMOUSE(a) \
521 window->State.MouseX = event.a.x; \
522 window->State.MouseY = event.a.y;
524 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutMainLoopEvent" );
526 while( XPending( fgDisplay.Display ) )
528 XNextEvent( fgDisplay.Display, &event );
533 /* Destroy the window when the WM_DELETE_WINDOW message arrives */
534 if( (Atom) event.xclient.data.l[ 0 ] == fgDisplay.DeleteWindow )
536 GETWINDOW( xclient );
538 fgDestroyWindow ( window );
540 if( fgState.ActionOnWindowClose == GLUT_ACTION_EXIT )
545 else if( fgState.ActionOnWindowClose == GLUT_ACTION_GLUTMAINLOOP_RETURNS )
546 fgState.ExecState = GLUT_EXEC_STATE_STOP;
553 * CreateNotify causes a configure-event so that sub-windows are
554 * handled compatibly with GLUT. Otherwise, your sub-windows
555 * (in freeglut only) will not get an initial reshape event,
556 * which can break things.
558 * GLUT presumably does this because it generally tries to treat
559 * sub-windows the same as windows.
561 * XXX Technically, GETWINDOW( xconfigure ) and
562 * XXX {event.xconfigure} may not be legit ways to get at
563 * XXX data for CreateNotify events. In practice, the data
564 * XXX is in a union which is laid out much the same either
565 * XXX way. But if you want to split hairs, this isn't legit,
566 * XXX and we should instead duplicate some code.
569 case ConfigureNotify:
570 GETWINDOW( xconfigure );
572 int width = event.xconfigure.width;
573 int height = event.xconfigure.height;
575 if( ( width != window->State.OldWidth ) ||
576 ( height != window->State.OldHeight ) )
578 window->State.OldWidth = width;
579 window->State.OldHeight = height;
580 if( FETCH_WCB( *window, Reshape ) )
581 INVOKE_WCB( *window, Reshape, ( width, height ) );
584 fgSetWindow( window );
585 glViewport( 0, 0, width, height );
587 glutPostRedisplay( );
594 * This is sent to confirm the XDestroyWindow call.
596 * XXX WHY is this commented out? Should we re-enable it?
598 /* fgAddToWindowDestroyList ( window ); */
603 * We are too dumb to process partial exposes...
605 * XXX Well, we could do it. However, it seems to only
606 * XXX be potentially useful for single-buffered (since
607 * XXX double-buffered does not respect viewport when we
608 * XXX do a buffer-swap).
611 if( event.xexpose.count == 0 )
613 GETWINDOW( xexpose );
614 fgSetWindow( window );
615 glutPostRedisplay( );
622 * If we never do anything with this, can we just not ask to
623 * get these messages?
629 * Have the client's keyboard knowledge updated (xlib.ps,
630 * page 206, says that's a good thing to do)
632 XRefreshKeyboardMapping( (XMappingEvent *) &event );
635 case VisibilityNotify:
637 GETWINDOW( xvisibility );
639 * XXX INVOKE_WCB() does this check for us.
641 if( ! FETCH_WCB( *window, WindowStatus ) )
643 fgSetWindow( window );
646 * Sending this event, the X server can notify us that the window
647 * has just acquired one of the three possible visibility states:
648 * VisibilityUnobscured, VisibilityPartiallyObscured or
649 * VisibilityFullyObscured
651 switch( event.xvisibility.state )
653 case VisibilityUnobscured:
654 INVOKE_WCB( *window, WindowStatus, ( GLUT_FULLY_RETAINED ) );
655 window->State.Visible = GL_TRUE;
658 case VisibilityPartiallyObscured:
659 INVOKE_WCB( *window, WindowStatus,
660 ( GLUT_PARTIALLY_RETAINED ) );
661 window->State.Visible = GL_TRUE;
664 case VisibilityFullyObscured:
665 INVOKE_WCB( *window, WindowStatus, ( GLUT_FULLY_COVERED ) );
666 window->State.Visible = GL_FALSE;
670 fgWarning( "Unknown X visibility state: %d",
671 event.xvisibility.state );
679 GETWINDOW( xcrossing );
680 GETMOUSE( xcrossing );
681 INVOKE_WCB( *window, Entry, ( ( EnterNotify == event.type ) ?
688 GETWINDOW( xmotion );
691 if( window->ActiveMenu )
693 if( window == window->ActiveMenu->ParentWindow )
695 window->ActiveMenu->Window->State.MouseX =
696 event.xmotion.x_root - window->ActiveMenu->X;
697 window->ActiveMenu->Window->State.MouseY =
698 event.xmotion.y_root - window->ActiveMenu->Y;
700 window->ActiveMenu->Window->State.Redisplay = GL_TRUE ;
701 fgSetWindow( window->ActiveMenu->ParentWindow );
707 * XXX For more than 5 buttons, just check {event.xmotion.state},
708 * XXX rather than a host of bit-masks? Or maybe we need to
709 * XXX track ButtonPress/ButtonRelease events in our own
712 #define BUTTON_MASK \
713 ( Button1Mask | Button2Mask | Button3Mask | Button4Mask | Button5Mask )
714 if ( event.xmotion.state & BUTTON_MASK )
715 INVOKE_WCB( *window, Motion, ( event.xmotion.x,
718 INVOKE_WCB( *window, Passive, ( event.xmotion.x,
726 GLboolean pressed = GL_TRUE;
729 if( event.type == ButtonRelease )
733 * A mouse button has been pressed or released. Traditionally,
734 * break if the window was found within the freeglut structures.
736 GETWINDOW( xbutton );
740 * An X button (at least in XFree86) is numbered from 1.
741 * A GLUT button is numbered from 0.
742 * Old GLUT passed through buttons other than just the first
743 * three, though it only gave symbolic names and official
744 * support to the first three.
746 button = event.xbutton.button - 1;
749 * Do not execute the application's mouse callback if a menu
750 * is hooked to this button. In that case an appropriate
751 * private call should be generated.
753 if( fgCheckActiveMenu( window, button, pressed,
754 event.xbutton.x_root, event.xbutton.y_root ) )
758 * Check if there is a mouse or mouse wheel callback hooked to the
761 if( ! FETCH_WCB( *window, Mouse ) &&
762 ! FETCH_WCB( *window, MouseWheel ) )
765 fgState.Modifiers = fghGetXModifiers( &event );
768 * Finally execute the mouse or mouse wheel callback
770 * XXX Use a symbolic constant, *not* "4"! ("3, sire!")
772 if( ( button < 3 ) || ( ! FETCH_WCB( *window, MouseWheel ) ) )
773 INVOKE_WCB( *window, Mouse, ( button,
774 pressed ? GLUT_DOWN : GLUT_UP,
781 * Map 4 and 5 to wheel zero; EVEN to +1, ODD to -1
782 * " 6 and 7 " " one; ...
784 * XXX This *should* be behind some variables/macros,
785 * XXX since the order and numbering isn't certain
786 * XXX See XFree86 configuration docs (even back in the
787 * XXX 3.x days, and especially with 4.x).
789 * XXX Note that {button} has already been decremeted
790 * XXX in mapping from X button numbering to GLUT.
792 int wheel_number = (button - 3) / 2;
798 INVOKE_WCB( *window, MouseWheel, ( wheel_number,
805 /* Trash the modifiers state */
806 fgState.Modifiers = 0xffffffff;
813 FGCBKeyboard keyboard_cb;
814 FGCBSpecial special_cb;
819 /* Detect auto repeated keys, if configured globally or per-window */
821 if ( fgState.KeyRepeat==GLUT_KEY_REPEAT_OFF || window->State.IgnoreKeyRepeat==GL_TRUE )
823 if (event.type==KeyRelease)
826 * Look at X11 keystate to detect repeat mode.
827 * While X11 says the key is actually held down, we'll ignore KeyRelease/KeyPress pairs.
831 XQueryKeymap( fgDisplay.Display, keys ); /* Look at X11 keystate to detect repeat mode */
833 if ( event.xkey.keycode<256 ) /* XQueryKeymap is limited to 256 keycodes */
835 if ( keys[event.xkey.keycode>>3] & (1<<(event.xkey.keycode%8)) )
836 window->State.KeyRepeating = GL_TRUE;
838 window->State.KeyRepeating = GL_FALSE;
843 window->State.KeyRepeating = GL_FALSE;
845 /* Cease processing this event if it is auto repeated */
847 if (window->State.KeyRepeating)
850 if( event.type == KeyPress )
852 keyboard_cb = FETCH_WCB( *window, Keyboard );
853 special_cb = FETCH_WCB( *window, Special );
857 keyboard_cb = FETCH_WCB( *window, KeyboardUp );
858 special_cb = FETCH_WCB( *window, SpecialUp );
861 /* Is there a keyboard/special callback hooked for this window? */
862 if( keyboard_cb || special_cb )
864 XComposeStatus composeStatus;
865 char asciiCode[ 32 ];
869 /* Check for the ASCII/KeySym codes associated with the event: */
870 len = XLookupString( &event.xkey, asciiCode, sizeof(asciiCode),
871 &keySym, &composeStatus
874 /* GLUT API tells us to have two separate callbacks... */
877 /* ...one for the ASCII translateable keypresses... */
880 fgSetWindow( window );
881 fgState.Modifiers = fghGetXModifiers( &event );
882 keyboard_cb( asciiCode[ 0 ],
883 event.xkey.x, event.xkey.y
885 fgState.Modifiers = 0xffffffff;
893 * ...and one for all the others, which need to be
894 * translated to GLUT_KEY_Xs...
898 case XK_F1: special = GLUT_KEY_F1; break;
899 case XK_F2: special = GLUT_KEY_F2; break;
900 case XK_F3: special = GLUT_KEY_F3; break;
901 case XK_F4: special = GLUT_KEY_F4; break;
902 case XK_F5: special = GLUT_KEY_F5; break;
903 case XK_F6: special = GLUT_KEY_F6; break;
904 case XK_F7: special = GLUT_KEY_F7; break;
905 case XK_F8: special = GLUT_KEY_F8; break;
906 case XK_F9: special = GLUT_KEY_F9; break;
907 case XK_F10: special = GLUT_KEY_F10; break;
908 case XK_F11: special = GLUT_KEY_F11; break;
909 case XK_F12: special = GLUT_KEY_F12; break;
911 case XK_Left: special = GLUT_KEY_LEFT; break;
912 case XK_Right: special = GLUT_KEY_RIGHT; break;
913 case XK_Up: special = GLUT_KEY_UP; break;
914 case XK_Down: special = GLUT_KEY_DOWN; break;
917 case XK_Prior: special = GLUT_KEY_PAGE_UP; break;
919 case XK_Next: special = GLUT_KEY_PAGE_DOWN; break;
921 case XK_Home: special = GLUT_KEY_HOME; break;
923 case XK_End: special = GLUT_KEY_END; break;
925 case XK_Insert: special = GLUT_KEY_INSERT; break;
929 * Execute the callback (if one has been specified),
930 * given that the special code seems to be valid...
932 if( special_cb && (special != -1) )
934 fgSetWindow( window );
935 fgState.Modifiers = fghGetXModifiers( &event );
936 special_cb( special, event.xkey.x, event.xkey.y );
937 fgState.Modifiers = 0xffffffff;
945 break; /* XXX Should disable this event */
948 fgWarning ("Unknown X event type: %d", event.type);
953 #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE
957 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutMainLoopEvent" );
959 while( PeekMessage( &stMsg, NULL, 0, 0, PM_NOREMOVE ) )
961 if( GetMessage( &stMsg, NULL, 0, 0 ) == 0 )
963 if( fgState.ActionOnWindowClose == GLUT_ACTION_EXIT )
968 else if( fgState.ActionOnWindowClose == GLUT_ACTION_GLUTMAINLOOP_RETURNS )
969 fgState.ExecState = GLUT_EXEC_STATE_STOP;
974 TranslateMessage( &stMsg );
975 DispatchMessage( &stMsg );
979 if( fgState.Timers.First )
981 fghCheckJoystickPolls( );
988 * Enters the freeglut processing loop.
989 * Stays until the "ExecState" changes to "GLUT_EXEC_STATE_STOP".
991 void FGAPIENTRY glutMainLoop( void )
995 #if TARGET_HOST_WIN32 || TARGET_HOST_WINCE
996 SFG_Window *window = (SFG_Window *)fgStructure.Windows.First ;
999 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutMainLoop" );
1001 #if TARGET_HOST_WIN32 || TARGET_HOST_WINCE
1003 * Processing before the main loop: If there is a window which is open and
1004 * which has a visibility callback, call it. I know this is an ugly hack,
1005 * but I'm not sure what else to do about it. Ideally we should leave
1006 * something uninitialized in the create window code and initialize it in
1007 * the main loop, and have that initialization create a "WM_ACTIVATE"
1008 * message. Then we would put the visibility callback code in the
1009 * "case WM_ACTIVATE" block below. - John Fay -- 10/24/02
1013 if ( FETCH_WCB( *window, Visibility ) )
1015 SFG_Window *current_window = fgStructure.Window ;
1017 INVOKE_WCB( *window, Visibility, ( window->State.Visible ) );
1018 fgSetWindow( current_window );
1021 window = (SFG_Window *)window->Node.Next ;
1025 fgState.ExecState = GLUT_EXEC_STATE_RUNNING ;
1026 while( fgState.ExecState == GLUT_EXEC_STATE_RUNNING )
1030 glutMainLoopEvent( );
1032 * Step through the list of windows, seeing if there are any
1033 * that are not menus
1035 for( window = ( SFG_Window * )fgStructure.Windows.First;
1037 window = ( SFG_Window * )window->Node.Next )
1038 if ( ! ( window->IsMenu ) )
1042 fgState.ExecState = GLUT_EXEC_STATE_STOP;
1045 if( fgState.IdleCallback )
1046 fgState.IdleCallback( );
1048 fghSleepForEvents( );
1053 * When this loop terminates, destroy the display, state and structure
1054 * of a freeglut session, so that another glutInit() call can happen
1056 * Save the "ActionOnWindowClose" because "fgDeinitialize" resets it.
1058 action = fgState.ActionOnWindowClose;
1060 if( action == GLUT_ACTION_EXIT )
1065 * Leaves the freeglut processing loop.
1067 void FGAPIENTRY glutLeaveMainLoop( void )
1069 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutLeaveMainLoop" );
1070 fgState.ExecState = GLUT_EXEC_STATE_STOP ;
1074 #if TARGET_HOST_WIN32 || TARGET_HOST_WINCE
1076 * Determine a GLUT modifer mask based on MS-WINDOWS system info.
1078 static int fghGetWin32Modifiers (void)
1081 ( ( ( GetKeyState( VK_LSHIFT ) < 0 ) ||
1082 ( GetKeyState( VK_RSHIFT ) < 0 )) ? GLUT_ACTIVE_SHIFT : 0 ) |
1083 ( ( ( GetKeyState( VK_LCONTROL ) < 0 ) ||
1084 ( GetKeyState( VK_RCONTROL ) < 0 )) ? GLUT_ACTIVE_CTRL : 0 ) |
1085 ( ( ( GetKeyState( VK_LMENU ) < 0 ) ||
1086 ( GetKeyState( VK_RMENU ) < 0 )) ? GLUT_ACTIVE_ALT : 0 );
1090 * The window procedure for handling Win32 events
1092 LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam,
1099 FREEGLUT_INTERNAL_ERROR_EXIT_IF_NOT_INITIALISED ( "Event Handler" ) ;
1101 window = fgWindowByHandle( hWnd );
1103 if ( ( window == NULL ) && ( uMsg != WM_CREATE ) )
1104 return DefWindowProc( hWnd, uMsg, wParam, lParam );
1106 /* printf ( "Window %3d message <%04x> %12d %12d\n", window?window->ID:0,
1107 uMsg, wParam, lParam ); */
1111 /* The window structure is passed as the creation structure paramter... */
1112 window = (SFG_Window *) (((LPCREATESTRUCT) lParam)->lpCreateParams);
1113 FREEGLUT_INTERNAL_ERROR_EXIT ( ( window != NULL ), "Cannot create window",
1116 window->Window.Handle = hWnd;
1117 window->Window.Device = GetDC( hWnd );
1118 if( window->IsMenu )
1120 unsigned int current_DisplayMode = fgState.DisplayMode;
1121 fgState.DisplayMode = GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH;
1122 #if !TARGET_HOST_WINCE
1123 fgSetupPixelFormat( window, GL_FALSE, PFD_MAIN_PLANE );
1125 fgState.DisplayMode = current_DisplayMode;
1127 if( fgStructure.MenuContext )
1128 wglMakeCurrent( window->Window.Device,
1129 fgStructure.MenuContext->Context
1133 fgStructure.MenuContext =
1134 (SFG_MenuContext *)malloc( sizeof(SFG_MenuContext) );
1135 fgStructure.MenuContext->Context =
1136 wglCreateContext( window->Window.Device );
1139 /* window->Window.Context = wglGetCurrentContext (); */
1140 window->Window.Context = wglCreateContext( window->Window.Device );
1144 #if !TARGET_HOST_WINCE
1145 fgSetupPixelFormat( window, GL_FALSE, PFD_MAIN_PLANE );
1148 if( ! fgState.UseCurrentContext )
1149 window->Window.Context =
1150 wglCreateContext( window->Window.Device );
1153 window->Window.Context = wglGetCurrentContext( );
1154 if( ! window->Window.Context )
1155 window->Window.Context =
1156 wglCreateContext( window->Window.Device );
1160 window->State.NeedToResize = GL_TRUE;
1161 window->State.Width = fgState.Size.X;
1162 window->State.Height = fgState.Size.Y;
1164 ReleaseDC( window->Window.Handle, window->Window.Device );
1166 #if TARGET_HOST_WINCE
1167 /* Take over button handling */
1169 HINSTANCE dxDllLib=LoadLibrary(_T("gx.dll"));
1172 GXGetDefaultKeys_=(GXGETDEFAULTKEYS)GetProcAddress(dxDllLib, _T("?GXGetDefaultKeys@@YA?AUGXKeyList@@H@Z"));
1173 GXOpenInput_=(GXOPENINPUT)GetProcAddress(dxDllLib, _T("?GXOpenInput@@YAHXZ"));
1178 if(GXGetDefaultKeys_)
1179 gxKeyList = (*GXGetDefaultKeys_)(GX_LANDSCAPEKEYS);
1182 #endif /* TARGET_HOST_WINCE */
1187 * If the window is visible, then it is the user manually resizing it.
1188 * If it is not, then it is the system sending us a dummy resize with
1189 * zero dimensions on a "glutIconifyWindow" call.
1191 if( window->State.Visible )
1193 window->State.NeedToResize = GL_TRUE;
1194 #if TARGET_HOST_WINCE
1195 window->State.Width = HIWORD(lParam);
1196 window->State.Height = LOWORD(lParam);
1198 window->State.Width = LOWORD(lParam);
1199 window->State.Height = HIWORD(lParam);
1200 #endif /* TARGET_HOST_WINCE */
1206 /* printf("WM_SETFOCUS: %p\n", window ); */
1207 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1211 if (LOWORD(wParam) != WA_INACTIVE)
1213 /* glutSetCursor( fgStructure.Window->State.Cursor ); */
1214 /* printf("WM_ACTIVATE: glutSetCursor( %p, %d)\n", window,
1215 window->State.Cursor ); */
1216 glutSetCursor( window->State.Cursor );
1219 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1224 * XXX Why not re-use some common code with the glutSetCursor()
1225 * XXX function (or perhaps invoke glutSetCursor())?
1226 * XXX That is, why are we duplicating code, here, from
1227 * XXX glutSetCursor()? The WIN32 code should be able to just
1228 * XXX call glutSetCursor() instead of defining two macros
1229 * XXX and implementing a nested case in-line.
1232 /* Set the cursor AND change it for this window class. */
1233 #define MAP_CURSOR(a,b) \
1235 SetCursor( LoadCursor( NULL, b ) ); \
1238 /* Nuke the cursor AND change it for this window class. */
1239 #define ZAP_CURSOR(a,b) \
1241 SetCursor( NULL ); \
1244 /* printf ( "Cursor event %x %x %x %x\n", window, window->State.Cursor, lParam, wParam ) ; */
1245 if( LOWORD( lParam ) == HTCLIENT )
1246 switch( window->State.Cursor )
1248 MAP_CURSOR( GLUT_CURSOR_RIGHT_ARROW, IDC_ARROW );
1249 MAP_CURSOR( GLUT_CURSOR_LEFT_ARROW, IDC_ARROW );
1250 MAP_CURSOR( GLUT_CURSOR_INFO, IDC_HELP );
1251 MAP_CURSOR( GLUT_CURSOR_DESTROY, IDC_CROSS );
1252 MAP_CURSOR( GLUT_CURSOR_HELP, IDC_HELP );
1253 MAP_CURSOR( GLUT_CURSOR_CYCLE, IDC_SIZEALL );
1254 MAP_CURSOR( GLUT_CURSOR_SPRAY, IDC_CROSS );
1255 MAP_CURSOR( GLUT_CURSOR_WAIT, IDC_WAIT );
1256 MAP_CURSOR( GLUT_CURSOR_TEXT, IDC_UPARROW );
1257 MAP_CURSOR( GLUT_CURSOR_CROSSHAIR, IDC_CROSS );
1258 /* MAP_CURSOR( GLUT_CURSOR_NONE, IDC_NO ); */
1259 ZAP_CURSOR( GLUT_CURSOR_NONE, NULL );
1262 MAP_CURSOR( GLUT_CURSOR_UP_DOWN, IDC_ARROW );
1265 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1269 window->State.Visible = GL_TRUE;
1270 window->State.Redisplay = GL_TRUE;
1274 /* Turn on the visibility in case it was turned off somehow */
1275 window->State.Visible = GL_TRUE;
1276 BeginPaint( hWnd, &ps );
1277 fghRedrawWindow( window );
1278 EndPaint( hWnd, &ps );
1282 fgDestroyWindow ( window );
1283 if ( fgState.ActionOnWindowClose != GLUT_ACTION_CONTINUE_EXECUTION )
1289 * The window already got destroyed, so don't bother with it.
1295 #if TARGET_HOST_WINCE
1296 window->State.MouseX = 320-HIWORD( lParam );
1297 window->State.MouseY = LOWORD( lParam );
1299 window->State.MouseX = LOWORD( lParam );
1300 window->State.MouseY = HIWORD( lParam );
1301 #endif /* TARGET_HOST_WINCE */
1302 /* Restrict to [-32768, 32767] to match X11 behaviour */
1303 /* See comment in "freeglut_developer" mailing list 10/4/04 */
1304 if ( window->State.MouseX > 32767 ) window->State.MouseX -= 65536;
1305 if ( window->State.MouseY > 32767 ) window->State.MouseY -= 65536;
1307 if ( window->ActiveMenu )
1309 window->State.Redisplay = GL_TRUE;
1310 fgSetWindow ( window->ActiveMenu->ParentWindow );
1314 fgState.Modifiers = fghGetWin32Modifiers( );
1316 if( ( wParam & MK_LBUTTON ) ||
1317 ( wParam & MK_MBUTTON ) ||
1318 ( wParam & MK_RBUTTON ) )
1319 INVOKE_WCB( *window, Motion, ( window->State.MouseX,
1320 window->State.MouseY ) );
1322 INVOKE_WCB( *window, Passive, ( window->State.MouseX,
1323 window->State.MouseY ) );
1325 fgState.Modifiers = 0xffffffff;
1329 case WM_LBUTTONDOWN:
1330 case WM_MBUTTONDOWN:
1331 case WM_RBUTTONDOWN:
1336 GLboolean pressed = GL_TRUE;
1339 #if TARGET_HOST_WINCE
1340 window->State.MouseX = 320-HIWORD( lParam );
1341 window->State.MouseY = LOWORD( lParam );
1343 window->State.MouseX = LOWORD( lParam );
1344 window->State.MouseY = HIWORD( lParam );
1345 #endif /* TARGET_HOST_WINCE */
1347 /* Restrict to [-32768, 32767] to match X11 behaviour */
1348 /* See comment in "freeglut_developer" mailing list 10/4/04 */
1349 if ( window->State.MouseX > 32767 ) window->State.MouseX -= 65536;
1350 if ( window->State.MouseY > 32767 ) window->State.MouseY -= 65536;
1354 case WM_LBUTTONDOWN:
1356 button = GLUT_LEFT_BUTTON;
1358 case WM_MBUTTONDOWN:
1360 button = GLUT_MIDDLE_BUTTON;
1362 case WM_RBUTTONDOWN:
1364 button = GLUT_RIGHT_BUTTON;
1368 button = GLUT_LEFT_BUTTON;
1372 button = GLUT_MIDDLE_BUTTON;
1376 button = GLUT_RIGHT_BUTTON;
1384 #if !TARGET_HOST_WINCE
1385 if( GetSystemMetrics( SM_SWAPBUTTON ) )
1387 if( button == GLUT_LEFT_BUTTON )
1388 button = GLUT_RIGHT_BUTTON;
1390 if( button == GLUT_RIGHT_BUTTON )
1391 button = GLUT_LEFT_BUTTON;
1393 #endif /* !TARGET_HOST_WINCE */
1396 return DefWindowProc( hWnd, uMsg, lParam, wParam );
1399 * Do not execute the application's mouse callback if a menu
1400 * is hooked to this button. In that case an appropriate
1401 * private call should be generated.
1403 if( fgCheckActiveMenu( window, button, pressed,
1404 window->State.MouseX, window->State.MouseY ) )
1407 if( window->Menu[ button ] && pressed )
1409 window->State.Redisplay = GL_TRUE;
1410 fgSetWindow( window );
1411 fgActivateMenu( window, button );
1416 /* Set capture so that the window captures all the mouse messages */
1418 * XXX - Multiple button support: Under X11, the mouse is not released
1419 * XXX - from the window until all buttons have been released, even if the
1420 * XXX - user presses a button in another window. This will take more
1421 * XXX - code changes than I am up to at the moment (10/5/04). The present
1422 * XXX - is a 90 percent solution.
1424 if ( pressed == GL_TRUE )
1425 SetCapture ( window->Window.Handle ) ;
1429 if( ! FETCH_WCB( *window, Mouse ) )
1432 fgSetWindow( window );
1433 fgState.Modifiers = fghGetWin32Modifiers( );
1438 pressed ? GLUT_DOWN : GLUT_UP,
1439 window->State.MouseX,
1440 window->State.MouseY
1444 fgState.Modifiers = 0xffffffff;
1449 /* Should be WM_MOUSEWHEEL but my compiler doesn't recognize it */
1452 * XXX THIS IS SPECULATIVE -- John Fay, 10/2/03
1453 * XXX Should use WHEEL_DELTA instead of 120
1455 int wheel_number = LOWORD( wParam );
1456 short ticks = ( short )HIWORD( wParam ) / 120;
1466 * The mouse cursor has moved. Remember the new mouse cursor's position
1468 /* window->State.MouseX = LOWORD( lParam ); */
1469 /* Need to adjust by window position, */
1470 /* window->State.MouseY = HIWORD( lParam ); */
1471 /* change "lParam" to other parameter */
1473 if( ! FETCH_WCB( *window, MouseWheel ) &&
1474 ! FETCH_WCB( *window, Mouse ) )
1477 fgSetWindow( window );
1478 fgState.Modifiers = fghGetWin32Modifiers( );
1481 if( FETCH_WCB( *window, MouseWheel ) )
1482 INVOKE_WCB( *window, MouseWheel,
1485 window->State.MouseX,
1486 window->State.MouseY
1489 else /* No mouse wheel, call the mouse button callback twice */
1492 * XXX The below assumes that you have no more than 3 mouse
1493 * XXX buttons. Sorry.
1495 int button = wheel_number*2 + 4;
1498 INVOKE_WCB( *window, Mouse,
1499 ( button, GLUT_DOWN,
1500 window->State.MouseX, window->State.MouseY )
1502 INVOKE_WCB( *window, Mouse,
1504 window->State.MouseX, window->State.MouseX )
1508 fgState.Modifiers = 0xffffffff;
1518 if( ( fgState.KeyRepeat==GLUT_KEY_REPEAT_OFF || window->State.IgnoreKeyRepeat==GL_TRUE ) && (HIWORD(lParam) & KF_REPEAT) )
1522 * Remember the current modifiers state. This is done here in order
1523 * to make sure the VK_DELETE keyboard callback is executed properly.
1525 fgState.Modifiers = fghGetWin32Modifiers( );
1527 GetCursorPos( &mouse_pos );
1528 ScreenToClient( window->Window.Handle, &mouse_pos );
1530 window->State.MouseX = mouse_pos.x;
1531 window->State.MouseY = mouse_pos.y;
1533 /* Convert the Win32 keystroke codes to GLUTtish way */
1534 # define KEY(a,b) case a: keypress = b; break;
1538 KEY( VK_F1, GLUT_KEY_F1 );
1539 KEY( VK_F2, GLUT_KEY_F2 );
1540 KEY( VK_F3, GLUT_KEY_F3 );
1541 KEY( VK_F4, GLUT_KEY_F4 );
1542 KEY( VK_F5, GLUT_KEY_F5 );
1543 KEY( VK_F6, GLUT_KEY_F6 );
1544 KEY( VK_F7, GLUT_KEY_F7 );
1545 KEY( VK_F8, GLUT_KEY_F8 );
1546 KEY( VK_F9, GLUT_KEY_F9 );
1547 KEY( VK_F10, GLUT_KEY_F10 );
1548 KEY( VK_F11, GLUT_KEY_F11 );
1549 KEY( VK_F12, GLUT_KEY_F12 );
1550 KEY( VK_PRIOR, GLUT_KEY_PAGE_UP );
1551 KEY( VK_NEXT, GLUT_KEY_PAGE_DOWN );
1552 KEY( VK_HOME, GLUT_KEY_HOME );
1553 KEY( VK_END, GLUT_KEY_END );
1554 KEY( VK_LEFT, GLUT_KEY_LEFT );
1555 KEY( VK_UP, GLUT_KEY_UP );
1556 KEY( VK_RIGHT, GLUT_KEY_RIGHT );
1557 KEY( VK_DOWN, GLUT_KEY_DOWN );
1558 KEY( VK_INSERT, GLUT_KEY_INSERT );
1561 /* The delete key should be treated as an ASCII keypress: */
1562 INVOKE_WCB( *window, Keyboard,
1563 ( 127, window->State.MouseX, window->State.MouseY )
1567 #if TARGET_HOST_WINCE
1568 if(!(lParam & 0x40000000)) /* Prevent auto-repeat */
1570 if(wParam==(unsigned)gxKeyList.vkRight)
1571 keypress = GLUT_KEY_RIGHT;
1572 else if(wParam==(unsigned)gxKeyList.vkLeft)
1573 keypress = GLUT_KEY_LEFT;
1574 else if(wParam==(unsigned)gxKeyList.vkUp)
1575 keypress = GLUT_KEY_UP;
1576 else if(wParam==(unsigned)gxKeyList.vkDown)
1577 keypress = GLUT_KEY_DOWN;
1578 else if(wParam==(unsigned)gxKeyList.vkA)
1579 keypress = GLUT_KEY_F1;
1580 else if(wParam==(unsigned)gxKeyList.vkB)
1581 keypress = GLUT_KEY_F2;
1582 else if(wParam==(unsigned)gxKeyList.vkC)
1583 keypress = GLUT_KEY_F3;
1584 else if(wParam==(unsigned)gxKeyList.vkStart)
1585 keypress = GLUT_KEY_F4;
1589 if( keypress != -1 )
1590 INVOKE_WCB( *window, Special,
1592 window->State.MouseX, window->State.MouseY )
1595 fgState.Modifiers = 0xffffffff;
1606 * Remember the current modifiers state. This is done here in order
1607 * to make sure the VK_DELETE keyboard callback is executed properly.
1609 fgState.Modifiers = fghGetWin32Modifiers( );
1611 GetCursorPos( &mouse_pos );
1612 ScreenToClient( window->Window.Handle, &mouse_pos );
1614 window->State.MouseX = mouse_pos.x;
1615 window->State.MouseY = mouse_pos.y;
1618 * Convert the Win32 keystroke codes to GLUTtish way.
1619 * "KEY(a,b)" was defined under "WM_KEYDOWN"
1624 KEY( VK_F1, GLUT_KEY_F1 );
1625 KEY( VK_F2, GLUT_KEY_F2 );
1626 KEY( VK_F3, GLUT_KEY_F3 );
1627 KEY( VK_F4, GLUT_KEY_F4 );
1628 KEY( VK_F5, GLUT_KEY_F5 );
1629 KEY( VK_F6, GLUT_KEY_F6 );
1630 KEY( VK_F7, GLUT_KEY_F7 );
1631 KEY( VK_F8, GLUT_KEY_F8 );
1632 KEY( VK_F9, GLUT_KEY_F9 );
1633 KEY( VK_F10, GLUT_KEY_F10 );
1634 KEY( VK_F11, GLUT_KEY_F11 );
1635 KEY( VK_F12, GLUT_KEY_F12 );
1636 KEY( VK_PRIOR, GLUT_KEY_PAGE_UP );
1637 KEY( VK_NEXT, GLUT_KEY_PAGE_DOWN );
1638 KEY( VK_HOME, GLUT_KEY_HOME );
1639 KEY( VK_END, GLUT_KEY_END );
1640 KEY( VK_LEFT, GLUT_KEY_LEFT );
1641 KEY( VK_UP, GLUT_KEY_UP );
1642 KEY( VK_RIGHT, GLUT_KEY_RIGHT );
1643 KEY( VK_DOWN, GLUT_KEY_DOWN );
1644 KEY( VK_INSERT, GLUT_KEY_INSERT );
1647 /* The delete key should be treated as an ASCII keypress: */
1648 INVOKE_WCB( *window, KeyboardUp,
1649 ( 127, window->State.MouseX, window->State.MouseY )
1655 #if !TARGET_HOST_WINCE
1659 GetKeyboardState( state );
1661 if( ToAscii( wParam, 0, state, code, 0 ) == 1 )
1664 INVOKE_WCB( *window, KeyboardUp,
1666 window->State.MouseX, window->State.MouseY )
1668 #endif /* !TARGET_HOST_WINCE */
1672 if( keypress != -1 )
1673 INVOKE_WCB( *window, SpecialUp,
1675 window->State.MouseX, window->State.MouseY )
1678 fgState.Modifiers = 0xffffffff;
1685 if( (fgState.KeyRepeat==GLUT_KEY_REPEAT_OFF || window->State.IgnoreKeyRepeat==GL_TRUE) && (HIWORD(lParam) & KF_REPEAT) )
1688 fgState.Modifiers = fghGetWin32Modifiers( );
1689 INVOKE_WCB( *window, Keyboard,
1691 window->State.MouseX, window->State.MouseY )
1693 fgState.Modifiers = 0xffffffff;
1697 case WM_CAPTURECHANGED:
1698 /* User has finished resizing the window, force a redraw */
1699 INVOKE_WCB( *window, Display, ( ) );
1701 /*lRet = DefWindowProc( hWnd, uMsg, wParam, lParam ); */
1704 /* Other messages that I have seen and which are not handled already */
1705 case WM_SETTEXT: /* 0x000c */
1706 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1707 /* Pass it on to "DefWindowProc" to set the window text */
1710 case WM_GETTEXT: /* 0x000d */
1711 /* Ideally we would copy the title of the window into "lParam" */
1712 /* strncpy ( (char *)lParam, "Window Title", wParam );
1713 lRet = ( wParam > 12 ) ? 12 : wParam; */
1714 /* the number of characters copied */
1715 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1718 case WM_GETTEXTLENGTH: /* 0x000e */
1719 /* Ideally we would get the length of the title of the window */
1721 /* the number of characters in "Window Title\0" (see above) */
1724 case WM_ERASEBKGND: /* 0x0014 */
1725 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1728 #if !TARGET_HOST_WINCE
1729 case WM_SYNCPAINT: /* 0x0088 */
1730 /* Another window has moved, need to update this one */
1731 window->State.Redisplay = GL_TRUE;
1732 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1733 /* Help screen says this message must be passed to "DefWindowProc" */
1736 case WM_NCPAINT: /* 0x0085 */
1737 /* Need to update the border of this window */
1738 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1739 /* Pass it on to "DefWindowProc" to repaint a standard border */
1742 case WM_SYSCOMMAND : /* 0x0112 */
1745 * We have received a system command message. Try to act on it.
1746 * The commands are passed in through the "wParam" parameter:
1747 * The least significant digit seems to be which edge of the window
1748 * is being used for a resize event:
1752 * Congratulations and thanks to Richard Rauch for figuring this out..
1754 switch ( wParam & 0xfff0 )
1763 /* User has clicked on the "-" to minimize the window */
1764 /* Turn off the visibility */
1765 window->State.Visible = GL_FALSE ;
1772 case SC_NEXTWINDOW :
1775 case SC_PREVWINDOW :
1779 /* Followed very closely by a WM_CLOSE message */
1803 case SC_SCREENSAVE :
1811 fgWarning( "Unknown wParam type 0x%x", wParam );
1816 #endif /* !TARGET_HOST_WINCE */
1818 /* We need to pass the message on to the operating system as well */
1819 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1823 /* Handle unhandled messages */
1824 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1832 /*** END OF FILE ***/