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"
36 typedef struct GXDisplayProperties GXDisplayProperties;
37 typedef struct GXKeyList GXKeyList;
40 typedef struct GXKeyList (*GXGETDEFAULTKEYS)(int);
41 typedef int (*GXOPENINPUT)();
43 GXGETDEFAULTKEYS GXGetDefaultKeys_ = NULL;
44 GXOPENINPUT GXOpenInput_ = NULL;
46 struct GXKeyList gxKeyList;
51 * Try to get the maximum value allowed for ints, falling back to the minimum
52 * guaranteed by ISO C99 if there is no suitable header.
58 # define INT_MAX 32767
62 #define MIN(a,b) (((a)<(b)) ? (a) : (b))
67 * TODO BEFORE THE STABLE RELEASE:
69 * There are some issues concerning window redrawing under X11, and maybe
70 * some events are not handled. The Win32 version lacks some more features,
71 * but seems acceptable for not demanding purposes.
73 * Need to investigate why the X11 version breaks out with an error when
74 * closing a window (using the window manager, not glutDestroyWindow)...
77 /* -- PRIVATE FUNCTIONS ---------------------------------------------------- */
80 * Handle a window configuration change. When no reshape
81 * callback is hooked, the viewport size is updated to
82 * match the new window size.
84 static void fghReshapeWindow ( SFG_Window *window, int width, int height )
86 SFG_Window *current_window = fgStructure.Window;
88 freeglut_return_if_fail( window != NULL );
91 #if TARGET_HOST_UNIX_X11
93 XResizeWindow( fgDisplay.Display, window->Window.Handle,
95 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
97 #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE
99 #if !TARGET_HOST_WINCE
105 * For windowed mode, get the current position of the
106 * window and resize taking the size of the frame
107 * decorations into account.
110 /* "GetWindowRect" returns the pixel coordinates of the outside of the window */
111 GetWindowRect( window->Window.Handle, &winRect );
117 if ( window->Parent == NULL )
119 if ( ! window->IsMenu && !window->State.IsGameMode )
121 w += GetSystemMetrics( SM_CXSIZEFRAME ) * 2;
122 h += GetSystemMetrics( SM_CYSIZEFRAME ) * 2 +
123 GetSystemMetrics( SM_CYCAPTION );
129 GetWindowRect( window->Parent->Window.Handle, &parentRect );
130 x -= parentRect.left + GetSystemMetrics( SM_CXSIZEFRAME ) * 2;
131 y -= parentRect.top + GetSystemMetrics( SM_CYSIZEFRAME ) * 2 +
132 GetSystemMetrics( SM_CYCAPTION );
136 * SWP_NOACTIVATE Do not activate the window
137 * SWP_NOOWNERZORDER Do not change position in z-order
138 * SWP_NOSENDCHANGING Supress WM_WINDOWPOSCHANGING message
139 * SWP_NOZORDER Retains the current Z order (ignore 2nd param)
142 SetWindowPos( window->Window.Handle,
145 SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOSENDCHANGING |
149 #endif /* TARGET_HOST_WINCE */
152 * XXX Should update {window->State.OldWidth, window->State.OldHeight}
153 * XXX to keep in lockstep with UNIX_X11 code.
155 if( FETCH_WCB( *window, Reshape ) )
156 INVOKE_WCB( *window, Reshape, ( width, height ) );
159 fgSetWindow( window );
160 glViewport( 0, 0, width, height );
166 * Force a window redraw. In Windows at least this is only a partial
167 * solution: if the window is increasing in size in either dimension,
168 * the already-drawn part does not get drawn again and things look funny.
169 * But without this we get this bad behaviour whenever we resize the
172 window->State.Redisplay = GL_TRUE;
175 fgSetWindow( current_window );
179 * Calls a window's redraw method. This is used when
180 * a redraw is forced by the incoming window messages.
182 static void fghRedrawWindow ( SFG_Window *window )
184 SFG_Window *current_window = fgStructure.Window;
186 freeglut_return_if_fail( window );
187 freeglut_return_if_fail( FETCH_WCB ( *window, Display ) );
189 window->State.Redisplay = GL_FALSE;
191 freeglut_return_if_fail( window->State.Visible );
193 fgSetWindow( window );
195 if( window->State.NeedToResize )
203 window->State.NeedToResize = GL_FALSE;
206 INVOKE_WCB( *window, Display, ( ) );
208 fgSetWindow( current_window );
212 * A static helper function to execute display callback for a window
214 static void fghcbDisplayWindow( SFG_Window *window,
215 SFG_Enumerator *enumerator )
217 if( window->State.Redisplay &&
218 window->State.Visible )
220 window->State.Redisplay = GL_FALSE;
222 #if TARGET_HOST_UNIX_X11
223 fghRedrawWindow ( window ) ;
224 #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE
226 window->Window.Handle, NULL, NULL,
227 RDW_NOERASE | RDW_INTERNALPAINT | RDW_INVALIDATE | RDW_UPDATENOW
232 fgEnumSubWindows( window, fghcbDisplayWindow, enumerator );
236 * Make all windows perform a display call
238 static void fghDisplayAll( void )
240 SFG_Enumerator enumerator;
242 enumerator.found = GL_FALSE;
243 enumerator.data = NULL;
245 fgEnumWindows( fghcbDisplayWindow, &enumerator );
249 * Window enumerator callback to check for the joystick polling code
251 static void fghcbCheckJoystickPolls( SFG_Window *window,
252 SFG_Enumerator *enumerator )
254 long int checkTime = fgElapsedTime( );
256 if( window->State.JoystickLastPoll + window->State.JoystickPollRate <=
259 #if !TARGET_HOST_WINCE
260 fgJoystickPollWindow( window );
261 #endif /* !TARGET_HOST_WINCE */
262 window->State.JoystickLastPoll = checkTime;
265 fgEnumSubWindows( window, fghcbCheckJoystickPolls, enumerator );
269 * Check all windows for joystick polling
271 static void fghCheckJoystickPolls( void )
273 SFG_Enumerator enumerator;
275 enumerator.found = GL_FALSE;
276 enumerator.data = NULL;
278 fgEnumWindows( fghcbCheckJoystickPolls, &enumerator );
282 * Check the global timers
284 static void fghCheckTimers( void )
286 long checkTime = fgElapsedTime( );
288 while( fgState.Timers.First )
290 SFG_Timer *timer = fgState.Timers.First;
292 if( timer->TriggerTime > checkTime )
295 fgListRemove( &fgState.Timers, &timer->Node );
296 fgListAppend( &fgState.FreeTimers, &timer->Node );
298 timer->Callback( timer->ID );
305 long fgElapsedTime( void )
307 if ( fgState.Time.Set )
309 #if TARGET_HOST_UNIX_X11
313 gettimeofday( &now, NULL );
315 elapsed = (now.tv_usec - fgState.Time.Value.tv_usec) / 1000;
316 elapsed += (now.tv_sec - fgState.Time.Value.tv_sec) * 1000;
319 #elif TARGET_HOST_WIN32
320 return timeGetTime() - fgState.Time.Value;
321 #elif TARGET_HOST_WINCE
322 return GetTickCount() - fgState.Time.Value;
327 #if TARGET_HOST_UNIX_X11
328 gettimeofday( &fgState.Time.Value, NULL );
329 #elif TARGET_HOST_WIN32
330 fgState.Time.Value = timeGetTime ();
331 #elif TARGET_HOST_WINCE
332 fgState.Time.Value = GetTickCount();
334 fgState.Time.Set = GL_TRUE ;
343 void fgError( const char *fmt, ... )
349 fprintf( stderr, "freeglut ");
350 if( fgState.ProgramName )
351 fprintf (stderr, "(%s): ", fgState.ProgramName);
352 vfprintf( stderr, fmt, ap );
353 fprintf( stderr, "\n" );
357 if ( fgState.Initialised )
363 void fgWarning( const char *fmt, ... )
369 fprintf( stderr, "freeglut ");
370 if( fgState.ProgramName )
371 fprintf( stderr, "(%s): ", fgState.ProgramName );
372 vfprintf( stderr, fmt, ap );
373 fprintf( stderr, "\n" );
379 * Indicates whether Joystick events are being used by ANY window.
381 * The current mechanism is to walk all of the windows and ask if
382 * there is a joystick callback. We have a short-circuit early
383 * return if we find any joystick handler registered.
385 * The real way to do this is to make use of the glutTimer() API
386 * to more cleanly re-implement the joystick API. Then, this code
387 * and all other "joystick timer" code can be yanked.
390 static void fghCheckJoystickCallback( SFG_Window* w, SFG_Enumerator* e)
392 if( FETCH_WCB( *w, Joystick ) )
397 fgEnumSubWindows( w, fghCheckJoystickCallback, e );
399 static int fghHaveJoystick( void )
401 SFG_Enumerator enumerator;
403 enumerator.found = GL_FALSE;
404 enumerator.data = NULL;
405 fgEnumWindows( fghCheckJoystickCallback, &enumerator );
406 return !!enumerator.data;
408 static void fghHavePendingRedisplaysCallback( SFG_Window* w, SFG_Enumerator* e)
410 if( w->State.Redisplay )
415 fgEnumSubWindows( w, fghHavePendingRedisplaysCallback, e );
417 static int fghHavePendingRedisplays (void)
419 SFG_Enumerator enumerator;
421 enumerator.found = GL_FALSE;
422 enumerator.data = NULL;
423 fgEnumWindows( fghHavePendingRedisplaysCallback, &enumerator );
424 return !!enumerator.data;
427 * Returns the number of GLUT ticks (milliseconds) till the next timer event.
429 static long fghNextTimer( void )
432 SFG_Timer *timer = fgState.Timers.First;
435 ret = timer->TriggerTime - fgElapsedTime();
442 * Does the magic required to relinquish the CPU until something interesting
445 static void fghSleepForEvents( void )
449 if( fgState.IdleCallback || fghHavePendingRedisplays( ) )
452 msec = fghNextTimer( );
453 /* XXX Use GLUT timers for joysticks... */
454 /* XXX Dumb; forces granularity to .01sec */
455 if( fghHaveJoystick( ) && ( msec < 10 ) )
458 #if TARGET_HOST_UNIX_X11
460 * Possibly due to aggressive use of XFlush() and friends,
461 * it is possible to have our socket drained but still have
462 * unprocessed events. (Or, this may just be normal with
463 * X, anyway?) We do non-trivial processing of X events
464 * after the event-reading loop, in any case, so we
465 * need to allow that we may have an empty socket but non-
468 if( ! XPending( fgDisplay.Display ) )
475 socket = ConnectionNumber( fgDisplay.Display );
477 FD_SET( socket, &fdset );
478 wait.tv_sec = msec / 1000;
479 wait.tv_usec = (msec % 1000) * 1000;
480 err = select( socket+1, &fdset, NULL, NULL, &wait );
483 fgWarning ( "freeglut select() error: %d", errno );
485 #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE
486 MsgWaitForMultipleObjects( 0, NULL, FALSE, msec, QS_ALLEVENTS );
490 #if TARGET_HOST_UNIX_X11
492 * Returns GLUT modifier mask for an XEvent.
494 static int fghGetXModifiers( XEvent *event )
498 if( event->xkey.state & ( ShiftMask | LockMask ) )
499 ret |= GLUT_ACTIVE_SHIFT;
500 if( event->xkey.state & ControlMask )
501 ret |= GLUT_ACTIVE_CTRL;
502 if( event->xkey.state & Mod1Mask )
503 ret |= GLUT_ACTIVE_ALT;
510 /* -- INTERFACE FUNCTIONS -------------------------------------------------- */
513 * Executes a single iteration in the freeglut processing loop.
515 void FGAPIENTRY glutMainLoopEvent( void )
517 #if TARGET_HOST_UNIX_X11
521 /* This code was repeated constantly, so here it goes into a definition: */
522 #define GETWINDOW(a) \
523 window = fgWindowByHandle( event.a.window ); \
524 if( window == NULL ) \
527 #define GETMOUSE(a) \
528 window->State.MouseX = event.a.x; \
529 window->State.MouseY = event.a.y;
531 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutMainLoopEvent" );
533 while( XPending( fgDisplay.Display ) )
535 XNextEvent( fgDisplay.Display, &event );
540 /* Destroy the window when the WM_DELETE_WINDOW message arrives */
541 if( (Atom) event.xclient.data.l[ 0 ] == fgDisplay.DeleteWindow )
543 GETWINDOW( xclient );
545 fgDestroyWindow ( window );
547 if( fgState.ActionOnWindowClose == GLUT_ACTION_EXIT )
552 else if( fgState.ActionOnWindowClose == GLUT_ACTION_GLUTMAINLOOP_RETURNS )
553 fgState.ExecState = GLUT_EXEC_STATE_STOP;
560 * CreateNotify causes a configure-event so that sub-windows are
561 * handled compatibly with GLUT. Otherwise, your sub-windows
562 * (in freeglut only) will not get an initial reshape event,
563 * which can break things.
565 * GLUT presumably does this because it generally tries to treat
566 * sub-windows the same as windows.
568 * XXX Technically, GETWINDOW( xconfigure ) and
569 * XXX {event.xconfigure} may not be legit ways to get at
570 * XXX data for CreateNotify events. In practice, the data
571 * XXX is in a union which is laid out much the same either
572 * XXX way. But if you want to split hairs, this isn't legit,
573 * XXX and we should instead duplicate some code.
576 case ConfigureNotify:
577 GETWINDOW( xconfigure );
579 int width = event.xconfigure.width;
580 int height = event.xconfigure.height;
582 if( ( width != window->State.OldWidth ) ||
583 ( height != window->State.OldHeight ) )
585 window->State.OldWidth = width;
586 window->State.OldHeight = height;
587 if( FETCH_WCB( *window, Reshape ) )
588 INVOKE_WCB( *window, Reshape, ( width, height ) );
591 fgSetWindow( window );
592 glViewport( 0, 0, width, height );
594 glutPostRedisplay( );
601 * This is sent to confirm the XDestroyWindow call.
603 * XXX WHY is this commented out? Should we re-enable it?
605 /* fgAddToWindowDestroyList ( window ); */
610 * We are too dumb to process partial exposes...
612 * XXX Well, we could do it. However, it seems to only
613 * XXX be potentially useful for single-buffered (since
614 * XXX double-buffered does not respect viewport when we
615 * XXX do a buffer-swap).
618 if( event.xexpose.count == 0 )
620 GETWINDOW( xexpose );
621 fgSetWindow( window );
622 glutPostRedisplay( );
629 * If we never do anything with this, can we just not ask to
630 * get these messages?
636 * Have the client's keyboard knowledge updated (xlib.ps,
637 * page 206, says that's a good thing to do)
639 XRefreshKeyboardMapping( (XMappingEvent *) &event );
642 case VisibilityNotify:
644 GETWINDOW( xvisibility );
646 * XXX INVOKE_WCB() does this check for us.
648 if( ! FETCH_WCB( *window, WindowStatus ) )
650 fgSetWindow( window );
653 * Sending this event, the X server can notify us that the window
654 * has just acquired one of the three possible visibility states:
655 * VisibilityUnobscured, VisibilityPartiallyObscured or
656 * VisibilityFullyObscured
658 switch( event.xvisibility.state )
660 case VisibilityUnobscured:
661 INVOKE_WCB( *window, WindowStatus, ( GLUT_FULLY_RETAINED ) );
662 window->State.Visible = GL_TRUE;
665 case VisibilityPartiallyObscured:
666 INVOKE_WCB( *window, WindowStatus,
667 ( GLUT_PARTIALLY_RETAINED ) );
668 window->State.Visible = GL_TRUE;
671 case VisibilityFullyObscured:
672 INVOKE_WCB( *window, WindowStatus, ( GLUT_FULLY_COVERED ) );
673 window->State.Visible = GL_FALSE;
677 fgWarning( "Unknown X visibility state: %d",
678 event.xvisibility.state );
686 GETWINDOW( xcrossing );
687 GETMOUSE( xcrossing );
688 INVOKE_WCB( *window, Entry, ( ( EnterNotify == event.type ) ?
695 GETWINDOW( xmotion );
698 if( window->ActiveMenu )
700 if( window == window->ActiveMenu->ParentWindow )
702 window->ActiveMenu->Window->State.MouseX =
703 event.xmotion.x_root - window->ActiveMenu->X;
704 window->ActiveMenu->Window->State.MouseY =
705 event.xmotion.y_root - window->ActiveMenu->Y;
707 window->ActiveMenu->Window->State.Redisplay = GL_TRUE ;
708 fgSetWindow( window->ActiveMenu->ParentWindow );
714 * XXX For more than 5 buttons, just check {event.xmotion.state},
715 * XXX rather than a host of bit-masks? Or maybe we need to
716 * XXX track ButtonPress/ButtonRelease events in our own
719 #define BUTTON_MASK \
720 ( Button1Mask | Button2Mask | Button3Mask | Button4Mask | Button5Mask )
721 if ( event.xmotion.state & BUTTON_MASK )
722 INVOKE_WCB( *window, Motion, ( event.xmotion.x,
725 INVOKE_WCB( *window, Passive, ( event.xmotion.x,
733 GLboolean pressed = GL_TRUE;
736 if( event.type == ButtonRelease )
740 * A mouse button has been pressed or released. Traditionally,
741 * break if the window was found within the freeglut structures.
743 GETWINDOW( xbutton );
747 * An X button (at least in XFree86) is numbered from 1.
748 * A GLUT button is numbered from 0.
749 * Old GLUT passed through buttons other than just the first
750 * three, though it only gave symbolic names and official
751 * support to the first three.
753 button = event.xbutton.button - 1;
756 * Do not execute the application's mouse callback if a menu
757 * is hooked to this button. In that case an appropriate
758 * private call should be generated.
760 if( fgCheckActiveMenu( window, button, pressed,
761 event.xbutton.x_root, event.xbutton.y_root ) )
765 * Check if there is a mouse or mouse wheel callback hooked to the
768 if( ! FETCH_WCB( *window, Mouse ) &&
769 ! FETCH_WCB( *window, MouseWheel ) )
772 fgState.Modifiers = fghGetXModifiers( &event );
775 * Finally execute the mouse or mouse wheel callback
777 * XXX Use a symbolic constant, *not* "4"! ("3, sire!")
779 if( ( button < 3 ) || ( ! FETCH_WCB( *window, MouseWheel ) ) )
780 INVOKE_WCB( *window, Mouse, ( button,
781 pressed ? GLUT_DOWN : GLUT_UP,
788 * Map 4 and 5 to wheel zero; EVEN to +1, ODD to -1
789 * " 6 and 7 " " one; ...
791 * XXX This *should* be behind some variables/macros,
792 * XXX since the order and numbering isn't certain
793 * XXX See XFree86 configuration docs (even back in the
794 * XXX 3.x days, and especially with 4.x).
796 * XXX Note that {button} has already been decremeted
797 * XXX in mapping from X button numbering to GLUT.
799 int wheel_number = (button - 3) / 2;
805 INVOKE_WCB( *window, MouseWheel, ( wheel_number,
812 /* Trash the modifiers state */
813 fgState.Modifiers = 0xffffffff;
820 FGCBKeyboard keyboard_cb;
821 FGCBSpecial special_cb;
826 /* Detect auto repeated keys, if configured globally or per-window */
828 if ( fgState.KeyRepeat==GLUT_KEY_REPEAT_OFF || window->State.IgnoreKeyRepeat==GL_TRUE )
830 if (event.type==KeyRelease)
833 * Look at X11 keystate to detect repeat mode.
834 * While X11 says the key is actually held down, we'll ignore KeyRelease/KeyPress pairs.
838 XQueryKeymap( fgDisplay.Display, keys ); /* Look at X11 keystate to detect repeat mode */
840 if ( event.xkey.keycode<256 ) /* XQueryKeymap is limited to 256 keycodes */
842 if ( keys[event.xkey.keycode>>3] & (1<<(event.xkey.keycode%8)) )
843 window->State.KeyRepeating = GL_TRUE;
845 window->State.KeyRepeating = GL_FALSE;
850 window->State.KeyRepeating = GL_FALSE;
852 /* Cease processing this event if it is auto repeated */
854 if (window->State.KeyRepeating)
857 if( event.type == KeyPress )
859 keyboard_cb = FETCH_WCB( *window, Keyboard );
860 special_cb = FETCH_WCB( *window, Special );
864 keyboard_cb = FETCH_WCB( *window, KeyboardUp );
865 special_cb = FETCH_WCB( *window, SpecialUp );
868 /* Is there a keyboard/special callback hooked for this window? */
869 if( keyboard_cb || special_cb )
871 XComposeStatus composeStatus;
872 char asciiCode[ 32 ];
876 /* Check for the ASCII/KeySym codes associated with the event: */
877 len = XLookupString( &event.xkey, asciiCode, sizeof(asciiCode),
878 &keySym, &composeStatus
881 /* GLUT API tells us to have two separate callbacks... */
884 /* ...one for the ASCII translateable keypresses... */
887 fgSetWindow( window );
888 fgState.Modifiers = fghGetXModifiers( &event );
889 keyboard_cb( asciiCode[ 0 ],
890 event.xkey.x, event.xkey.y
892 fgState.Modifiers = 0xffffffff;
900 * ...and one for all the others, which need to be
901 * translated to GLUT_KEY_Xs...
905 case XK_F1: special = GLUT_KEY_F1; break;
906 case XK_F2: special = GLUT_KEY_F2; break;
907 case XK_F3: special = GLUT_KEY_F3; break;
908 case XK_F4: special = GLUT_KEY_F4; break;
909 case XK_F5: special = GLUT_KEY_F5; break;
910 case XK_F6: special = GLUT_KEY_F6; break;
911 case XK_F7: special = GLUT_KEY_F7; break;
912 case XK_F8: special = GLUT_KEY_F8; break;
913 case XK_F9: special = GLUT_KEY_F9; break;
914 case XK_F10: special = GLUT_KEY_F10; break;
915 case XK_F11: special = GLUT_KEY_F11; break;
916 case XK_F12: special = GLUT_KEY_F12; break;
918 case XK_Left: special = GLUT_KEY_LEFT; break;
919 case XK_Right: special = GLUT_KEY_RIGHT; break;
920 case XK_Up: special = GLUT_KEY_UP; break;
921 case XK_Down: special = GLUT_KEY_DOWN; break;
924 case XK_Prior: special = GLUT_KEY_PAGE_UP; break;
926 case XK_Next: special = GLUT_KEY_PAGE_DOWN; break;
928 case XK_Home: special = GLUT_KEY_HOME; break;
930 case XK_End: special = GLUT_KEY_END; break;
932 case XK_Insert: special = GLUT_KEY_INSERT; break;
936 * Execute the callback (if one has been specified),
937 * given that the special code seems to be valid...
939 if( special_cb && (special != -1) )
941 fgSetWindow( window );
942 fgState.Modifiers = fghGetXModifiers( &event );
943 special_cb( special, event.xkey.x, event.xkey.y );
944 fgState.Modifiers = 0xffffffff;
952 break; /* XXX Should disable this event */
955 fgWarning ("Unknown X event type: %d", event.type);
960 #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE
964 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutMainLoopEvent" );
966 while( PeekMessage( &stMsg, NULL, 0, 0, PM_NOREMOVE ) )
968 if( GetMessage( &stMsg, NULL, 0, 0 ) == 0 )
970 if( fgState.ActionOnWindowClose == GLUT_ACTION_EXIT )
975 else if( fgState.ActionOnWindowClose == GLUT_ACTION_GLUTMAINLOOP_RETURNS )
976 fgState.ExecState = GLUT_EXEC_STATE_STOP;
981 TranslateMessage( &stMsg );
982 DispatchMessage( &stMsg );
986 if( fgState.Timers.First )
988 fghCheckJoystickPolls( );
995 * Enters the freeglut processing loop.
996 * Stays until the "ExecState" changes to "GLUT_EXEC_STATE_STOP".
998 void FGAPIENTRY glutMainLoop( void )
1002 #if TARGET_HOST_WIN32 || TARGET_HOST_WINCE
1003 SFG_Window *window = (SFG_Window *)fgStructure.Windows.First ;
1006 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutMainLoop" );
1008 #if TARGET_HOST_WIN32 || TARGET_HOST_WINCE
1010 * Processing before the main loop: If there is a window which is open and
1011 * which has a visibility callback, call it. I know this is an ugly hack,
1012 * but I'm not sure what else to do about it. Ideally we should leave
1013 * something uninitialized in the create window code and initialize it in
1014 * the main loop, and have that initialization create a "WM_ACTIVATE"
1015 * message. Then we would put the visibility callback code in the
1016 * "case WM_ACTIVATE" block below. - John Fay -- 10/24/02
1020 if ( FETCH_WCB( *window, Visibility ) )
1022 SFG_Window *current_window = fgStructure.Window ;
1024 INVOKE_WCB( *window, Visibility, ( window->State.Visible ) );
1025 fgSetWindow( current_window );
1028 window = (SFG_Window *)window->Node.Next ;
1032 fgState.ExecState = GLUT_EXEC_STATE_RUNNING ;
1033 while( fgState.ExecState == GLUT_EXEC_STATE_RUNNING )
1037 glutMainLoopEvent( );
1039 * Step through the list of windows, seeing if there are any
1040 * that are not menus
1042 for( window = ( SFG_Window * )fgStructure.Windows.First;
1044 window = ( SFG_Window * )window->Node.Next )
1045 if ( ! ( window->IsMenu ) )
1049 fgState.ExecState = GLUT_EXEC_STATE_STOP;
1052 if( fgState.IdleCallback )
1053 fgState.IdleCallback( );
1055 fghSleepForEvents( );
1060 * When this loop terminates, destroy the display, state and structure
1061 * of a freeglut session, so that another glutInit() call can happen
1063 * Save the "ActionOnWindowClose" because "fgDeinitialize" resets it.
1065 action = fgState.ActionOnWindowClose;
1067 if( action == GLUT_ACTION_EXIT )
1072 * Leaves the freeglut processing loop.
1074 void FGAPIENTRY glutLeaveMainLoop( void )
1076 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutLeaveMainLoop" );
1077 fgState.ExecState = GLUT_EXEC_STATE_STOP ;
1081 #if TARGET_HOST_WIN32 || TARGET_HOST_WINCE
1083 * Determine a GLUT modifer mask based on MS-WINDOWS system info.
1085 static int fghGetWin32Modifiers (void)
1088 ( ( ( GetKeyState( VK_LSHIFT ) < 0 ) ||
1089 ( GetKeyState( VK_RSHIFT ) < 0 )) ? GLUT_ACTIVE_SHIFT : 0 ) |
1090 ( ( ( GetKeyState( VK_LCONTROL ) < 0 ) ||
1091 ( GetKeyState( VK_RCONTROL ) < 0 )) ? GLUT_ACTIVE_CTRL : 0 ) |
1092 ( ( ( GetKeyState( VK_LMENU ) < 0 ) ||
1093 ( GetKeyState( VK_RMENU ) < 0 )) ? GLUT_ACTIVE_ALT : 0 );
1097 * The window procedure for handling Win32 events
1099 LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam,
1106 FREEGLUT_INTERNAL_ERROR_EXIT_IF_NOT_INITIALISED ( "Event Handler" ) ;
1108 window = fgWindowByHandle( hWnd );
1110 if ( ( window == NULL ) && ( uMsg != WM_CREATE ) )
1111 return DefWindowProc( hWnd, uMsg, wParam, lParam );
1113 /* printf ( "Window %3d message <%04x> %12d %12d\n", window?window->ID:0,
1114 uMsg, wParam, lParam ); */
1118 /* The window structure is passed as the creation structure paramter... */
1119 window = (SFG_Window *) (((LPCREATESTRUCT) lParam)->lpCreateParams);
1120 FREEGLUT_INTERNAL_ERROR_EXIT ( ( window != NULL ), "Cannot create window",
1123 window->Window.Handle = hWnd;
1124 window->Window.Device = GetDC( hWnd );
1125 if( window->IsMenu )
1127 unsigned int current_DisplayMode = fgState.DisplayMode;
1128 fgState.DisplayMode = GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH;
1129 #if !TARGET_HOST_WINCE
1130 fgSetupPixelFormat( window, GL_FALSE, PFD_MAIN_PLANE );
1132 fgState.DisplayMode = current_DisplayMode;
1134 if( fgStructure.MenuContext )
1135 wglMakeCurrent( window->Window.Device,
1136 fgStructure.MenuContext->Context
1140 fgStructure.MenuContext =
1141 (SFG_MenuContext *)malloc( sizeof(SFG_MenuContext) );
1142 fgStructure.MenuContext->Context =
1143 wglCreateContext( window->Window.Device );
1146 /* window->Window.Context = wglGetCurrentContext (); */
1147 window->Window.Context = wglCreateContext( window->Window.Device );
1151 #if !TARGET_HOST_WINCE
1152 fgSetupPixelFormat( window, GL_FALSE, PFD_MAIN_PLANE );
1155 if( ! fgState.UseCurrentContext )
1156 window->Window.Context =
1157 wglCreateContext( window->Window.Device );
1160 window->Window.Context = wglGetCurrentContext( );
1161 if( ! window->Window.Context )
1162 window->Window.Context =
1163 wglCreateContext( window->Window.Device );
1167 window->State.NeedToResize = GL_TRUE;
1168 window->State.Width = fgState.Size.X;
1169 window->State.Height = fgState.Size.Y;
1171 ReleaseDC( window->Window.Handle, window->Window.Device );
1173 #if TARGET_HOST_WINCE
1174 /* Take over button handling */
1176 HINSTANCE dxDllLib=LoadLibrary(_T("gx.dll"));
1179 GXGetDefaultKeys_=(GXGETDEFAULTKEYS)GetProcAddress(dxDllLib, _T("?GXGetDefaultKeys@@YA?AUGXKeyList@@H@Z"));
1180 GXOpenInput_=(GXOPENINPUT)GetProcAddress(dxDllLib, _T("?GXOpenInput@@YAHXZ"));
1185 if(GXGetDefaultKeys_)
1186 gxKeyList = (*GXGetDefaultKeys_)(GX_LANDSCAPEKEYS);
1189 #endif /* TARGET_HOST_WINCE */
1194 * If the window is visible, then it is the user manually resizing it.
1195 * If it is not, then it is the system sending us a dummy resize with
1196 * zero dimensions on a "glutIconifyWindow" call.
1198 if( window->State.Visible )
1200 window->State.NeedToResize = GL_TRUE;
1201 #if TARGET_HOST_WINCE
1202 window->State.Width = HIWORD(lParam);
1203 window->State.Height = LOWORD(lParam);
1205 window->State.Width = LOWORD(lParam);
1206 window->State.Height = HIWORD(lParam);
1207 #endif /* TARGET_HOST_WINCE */
1213 /* printf("WM_SETFOCUS: %p\n", window ); */
1214 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1218 if (LOWORD(wParam) != WA_INACTIVE)
1220 /* glutSetCursor( fgStructure.Window->State.Cursor ); */
1221 /* printf("WM_ACTIVATE: glutSetCursor( %p, %d)\n", window,
1222 window->State.Cursor ); */
1223 glutSetCursor( window->State.Cursor );
1226 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1231 * XXX Why not re-use some common code with the glutSetCursor()
1232 * XXX function (or perhaps invoke glutSetCursor())?
1233 * XXX That is, why are we duplicating code, here, from
1234 * XXX glutSetCursor()? The WIN32 code should be able to just
1235 * XXX call glutSetCursor() instead of defining two macros
1236 * XXX and implementing a nested case in-line.
1239 /* Set the cursor AND change it for this window class. */
1240 #define MAP_CURSOR(a,b) \
1242 SetCursor( LoadCursor( NULL, b ) ); \
1245 /* Nuke the cursor AND change it for this window class. */
1246 #define ZAP_CURSOR(a,b) \
1248 SetCursor( NULL ); \
1251 /* printf ( "Cursor event %x %x %x %x\n", window, window->State.Cursor, lParam, wParam ) ; */
1252 if( LOWORD( lParam ) == HTCLIENT )
1253 switch( window->State.Cursor )
1255 MAP_CURSOR( GLUT_CURSOR_RIGHT_ARROW, IDC_ARROW );
1256 MAP_CURSOR( GLUT_CURSOR_LEFT_ARROW, IDC_ARROW );
1257 MAP_CURSOR( GLUT_CURSOR_INFO, IDC_HELP );
1258 MAP_CURSOR( GLUT_CURSOR_DESTROY, IDC_CROSS );
1259 MAP_CURSOR( GLUT_CURSOR_HELP, IDC_HELP );
1260 MAP_CURSOR( GLUT_CURSOR_CYCLE, IDC_SIZEALL );
1261 MAP_CURSOR( GLUT_CURSOR_SPRAY, IDC_CROSS );
1262 MAP_CURSOR( GLUT_CURSOR_WAIT, IDC_WAIT );
1263 MAP_CURSOR( GLUT_CURSOR_TEXT, IDC_UPARROW );
1264 MAP_CURSOR( GLUT_CURSOR_CROSSHAIR, IDC_CROSS );
1265 /* MAP_CURSOR( GLUT_CURSOR_NONE, IDC_NO ); */
1266 ZAP_CURSOR( GLUT_CURSOR_NONE, NULL );
1269 MAP_CURSOR( GLUT_CURSOR_UP_DOWN, IDC_ARROW );
1272 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1276 window->State.Visible = GL_TRUE;
1277 window->State.Redisplay = GL_TRUE;
1281 /* Turn on the visibility in case it was turned off somehow */
1282 window->State.Visible = GL_TRUE;
1283 BeginPaint( hWnd, &ps );
1284 fghRedrawWindow( window );
1285 EndPaint( hWnd, &ps );
1289 fgDestroyWindow ( window );
1290 if ( fgState.ActionOnWindowClose != GLUT_ACTION_CONTINUE_EXECUTION )
1296 * The window already got destroyed, so don't bother with it.
1302 #if TARGET_HOST_WINCE
1303 window->State.MouseX = 320-HIWORD( lParam );
1304 window->State.MouseY = LOWORD( lParam );
1306 window->State.MouseX = LOWORD( lParam );
1307 window->State.MouseY = HIWORD( lParam );
1308 #endif /* TARGET_HOST_WINCE */
1309 /* Restrict to [-32768, 32767] to match X11 behaviour */
1310 /* See comment in "freeglut_developer" mailing list 10/4/04 */
1311 if ( window->State.MouseX > 32767 ) window->State.MouseX -= 65536;
1312 if ( window->State.MouseY > 32767 ) window->State.MouseY -= 65536;
1314 if ( window->ActiveMenu )
1316 window->State.Redisplay = GL_TRUE;
1317 fgSetWindow ( window->ActiveMenu->ParentWindow );
1321 fgState.Modifiers = fghGetWin32Modifiers( );
1323 if( ( wParam & MK_LBUTTON ) ||
1324 ( wParam & MK_MBUTTON ) ||
1325 ( wParam & MK_RBUTTON ) )
1326 INVOKE_WCB( *window, Motion, ( window->State.MouseX,
1327 window->State.MouseY ) );
1329 INVOKE_WCB( *window, Passive, ( window->State.MouseX,
1330 window->State.MouseY ) );
1332 fgState.Modifiers = 0xffffffff;
1336 case WM_LBUTTONDOWN:
1337 case WM_MBUTTONDOWN:
1338 case WM_RBUTTONDOWN:
1343 GLboolean pressed = GL_TRUE;
1346 #if TARGET_HOST_WINCE
1347 window->State.MouseX = 320-HIWORD( lParam );
1348 window->State.MouseY = LOWORD( lParam );
1350 window->State.MouseX = LOWORD( lParam );
1351 window->State.MouseY = HIWORD( lParam );
1352 #endif /* TARGET_HOST_WINCE */
1354 /* Restrict to [-32768, 32767] to match X11 behaviour */
1355 /* See comment in "freeglut_developer" mailing list 10/4/04 */
1356 if ( window->State.MouseX > 32767 ) window->State.MouseX -= 65536;
1357 if ( window->State.MouseY > 32767 ) window->State.MouseY -= 65536;
1361 case WM_LBUTTONDOWN:
1363 button = GLUT_LEFT_BUTTON;
1365 case WM_MBUTTONDOWN:
1367 button = GLUT_MIDDLE_BUTTON;
1369 case WM_RBUTTONDOWN:
1371 button = GLUT_RIGHT_BUTTON;
1375 button = GLUT_LEFT_BUTTON;
1379 button = GLUT_MIDDLE_BUTTON;
1383 button = GLUT_RIGHT_BUTTON;
1391 #if !TARGET_HOST_WINCE
1392 if( GetSystemMetrics( SM_SWAPBUTTON ) )
1394 if( button == GLUT_LEFT_BUTTON )
1395 button = GLUT_RIGHT_BUTTON;
1397 if( button == GLUT_RIGHT_BUTTON )
1398 button = GLUT_LEFT_BUTTON;
1400 #endif /* !TARGET_HOST_WINCE */
1403 return DefWindowProc( hWnd, uMsg, lParam, wParam );
1406 * Do not execute the application's mouse callback if a menu
1407 * is hooked to this button. In that case an appropriate
1408 * private call should be generated.
1410 if( fgCheckActiveMenu( window, button, pressed,
1411 window->State.MouseX, window->State.MouseY ) )
1414 if( window->Menu[ button ] && pressed )
1416 window->State.Redisplay = GL_TRUE;
1417 fgSetWindow( window );
1418 fgActivateMenu( window, button );
1423 /* Set capture so that the window captures all the mouse messages */
1425 * XXX - Multiple button support: Under X11, the mouse is not released
1426 * XXX - from the window until all buttons have been released, even if the
1427 * XXX - user presses a button in another window. This will take more
1428 * XXX - code changes than I am up to at the moment (10/5/04). The present
1429 * XXX - is a 90 percent solution.
1431 if ( pressed == GL_TRUE )
1432 SetCapture ( window->Window.Handle ) ;
1436 if( ! FETCH_WCB( *window, Mouse ) )
1439 fgSetWindow( window );
1440 fgState.Modifiers = fghGetWin32Modifiers( );
1445 pressed ? GLUT_DOWN : GLUT_UP,
1446 window->State.MouseX,
1447 window->State.MouseY
1451 fgState.Modifiers = 0xffffffff;
1456 /* Should be WM_MOUSEWHEEL but my compiler doesn't recognize it */
1459 * XXX THIS IS SPECULATIVE -- John Fay, 10/2/03
1460 * XXX Should use WHEEL_DELTA instead of 120
1462 int wheel_number = LOWORD( wParam );
1463 short ticks = ( short )HIWORD( wParam ) / 120;
1473 * The mouse cursor has moved. Remember the new mouse cursor's position
1475 /* window->State.MouseX = LOWORD( lParam ); */
1476 /* Need to adjust by window position, */
1477 /* window->State.MouseY = HIWORD( lParam ); */
1478 /* change "lParam" to other parameter */
1480 if( ! FETCH_WCB( *window, MouseWheel ) &&
1481 ! FETCH_WCB( *window, Mouse ) )
1484 fgSetWindow( window );
1485 fgState.Modifiers = fghGetWin32Modifiers( );
1488 if( FETCH_WCB( *window, MouseWheel ) )
1489 INVOKE_WCB( *window, MouseWheel,
1492 window->State.MouseX,
1493 window->State.MouseY
1496 else /* No mouse wheel, call the mouse button callback twice */
1499 * XXX The below assumes that you have no more than 3 mouse
1500 * XXX buttons. Sorry.
1502 int button = wheel_number*2 + 4;
1505 INVOKE_WCB( *window, Mouse,
1506 ( button, GLUT_DOWN,
1507 window->State.MouseX, window->State.MouseY )
1509 INVOKE_WCB( *window, Mouse,
1511 window->State.MouseX, window->State.MouseX )
1515 fgState.Modifiers = 0xffffffff;
1525 if( ( fgState.KeyRepeat==GLUT_KEY_REPEAT_OFF || window->State.IgnoreKeyRepeat==GL_TRUE ) && (HIWORD(lParam) & KF_REPEAT) )
1529 * Remember the current modifiers state. This is done here in order
1530 * to make sure the VK_DELETE keyboard callback is executed properly.
1532 fgState.Modifiers = fghGetWin32Modifiers( );
1534 GetCursorPos( &mouse_pos );
1535 ScreenToClient( window->Window.Handle, &mouse_pos );
1537 window->State.MouseX = mouse_pos.x;
1538 window->State.MouseY = mouse_pos.y;
1540 /* Convert the Win32 keystroke codes to GLUTtish way */
1541 # define KEY(a,b) case a: keypress = b; break;
1545 KEY( VK_F1, GLUT_KEY_F1 );
1546 KEY( VK_F2, GLUT_KEY_F2 );
1547 KEY( VK_F3, GLUT_KEY_F3 );
1548 KEY( VK_F4, GLUT_KEY_F4 );
1549 KEY( VK_F5, GLUT_KEY_F5 );
1550 KEY( VK_F6, GLUT_KEY_F6 );
1551 KEY( VK_F7, GLUT_KEY_F7 );
1552 KEY( VK_F8, GLUT_KEY_F8 );
1553 KEY( VK_F9, GLUT_KEY_F9 );
1554 KEY( VK_F10, GLUT_KEY_F10 );
1555 KEY( VK_F11, GLUT_KEY_F11 );
1556 KEY( VK_F12, GLUT_KEY_F12 );
1557 KEY( VK_PRIOR, GLUT_KEY_PAGE_UP );
1558 KEY( VK_NEXT, GLUT_KEY_PAGE_DOWN );
1559 KEY( VK_HOME, GLUT_KEY_HOME );
1560 KEY( VK_END, GLUT_KEY_END );
1561 KEY( VK_LEFT, GLUT_KEY_LEFT );
1562 KEY( VK_UP, GLUT_KEY_UP );
1563 KEY( VK_RIGHT, GLUT_KEY_RIGHT );
1564 KEY( VK_DOWN, GLUT_KEY_DOWN );
1565 KEY( VK_INSERT, GLUT_KEY_INSERT );
1568 /* The delete key should be treated as an ASCII keypress: */
1569 INVOKE_WCB( *window, Keyboard,
1570 ( 127, window->State.MouseX, window->State.MouseY )
1574 #if TARGET_HOST_WINCE
1575 if(!(lParam & 0x40000000)) /* Prevent auto-repeat */
1577 if(wParam==(unsigned)gxKeyList.vkRight)
1578 keypress = GLUT_KEY_RIGHT;
1579 else if(wParam==(unsigned)gxKeyList.vkLeft)
1580 keypress = GLUT_KEY_LEFT;
1581 else if(wParam==(unsigned)gxKeyList.vkUp)
1582 keypress = GLUT_KEY_UP;
1583 else if(wParam==(unsigned)gxKeyList.vkDown)
1584 keypress = GLUT_KEY_DOWN;
1585 else if(wParam==(unsigned)gxKeyList.vkA)
1586 keypress = GLUT_KEY_F1;
1587 else if(wParam==(unsigned)gxKeyList.vkB)
1588 keypress = GLUT_KEY_F2;
1589 else if(wParam==(unsigned)gxKeyList.vkC)
1590 keypress = GLUT_KEY_F3;
1591 else if(wParam==(unsigned)gxKeyList.vkStart)
1592 keypress = GLUT_KEY_F4;
1596 if( keypress != -1 )
1597 INVOKE_WCB( *window, Special,
1599 window->State.MouseX, window->State.MouseY )
1602 fgState.Modifiers = 0xffffffff;
1613 * Remember the current modifiers state. This is done here in order
1614 * to make sure the VK_DELETE keyboard callback is executed properly.
1616 fgState.Modifiers = fghGetWin32Modifiers( );
1618 GetCursorPos( &mouse_pos );
1619 ScreenToClient( window->Window.Handle, &mouse_pos );
1621 window->State.MouseX = mouse_pos.x;
1622 window->State.MouseY = mouse_pos.y;
1625 * Convert the Win32 keystroke codes to GLUTtish way.
1626 * "KEY(a,b)" was defined under "WM_KEYDOWN"
1631 KEY( VK_F1, GLUT_KEY_F1 );
1632 KEY( VK_F2, GLUT_KEY_F2 );
1633 KEY( VK_F3, GLUT_KEY_F3 );
1634 KEY( VK_F4, GLUT_KEY_F4 );
1635 KEY( VK_F5, GLUT_KEY_F5 );
1636 KEY( VK_F6, GLUT_KEY_F6 );
1637 KEY( VK_F7, GLUT_KEY_F7 );
1638 KEY( VK_F8, GLUT_KEY_F8 );
1639 KEY( VK_F9, GLUT_KEY_F9 );
1640 KEY( VK_F10, GLUT_KEY_F10 );
1641 KEY( VK_F11, GLUT_KEY_F11 );
1642 KEY( VK_F12, GLUT_KEY_F12 );
1643 KEY( VK_PRIOR, GLUT_KEY_PAGE_UP );
1644 KEY( VK_NEXT, GLUT_KEY_PAGE_DOWN );
1645 KEY( VK_HOME, GLUT_KEY_HOME );
1646 KEY( VK_END, GLUT_KEY_END );
1647 KEY( VK_LEFT, GLUT_KEY_LEFT );
1648 KEY( VK_UP, GLUT_KEY_UP );
1649 KEY( VK_RIGHT, GLUT_KEY_RIGHT );
1650 KEY( VK_DOWN, GLUT_KEY_DOWN );
1651 KEY( VK_INSERT, GLUT_KEY_INSERT );
1654 /* The delete key should be treated as an ASCII keypress: */
1655 INVOKE_WCB( *window, KeyboardUp,
1656 ( 127, window->State.MouseX, window->State.MouseY )
1662 #if !TARGET_HOST_WINCE
1666 GetKeyboardState( state );
1668 if( ToAscii( wParam, 0, state, code, 0 ) == 1 )
1671 INVOKE_WCB( *window, KeyboardUp,
1673 window->State.MouseX, window->State.MouseY )
1675 #endif /* !TARGET_HOST_WINCE */
1679 if( keypress != -1 )
1680 INVOKE_WCB( *window, SpecialUp,
1682 window->State.MouseX, window->State.MouseY )
1685 fgState.Modifiers = 0xffffffff;
1692 if( (fgState.KeyRepeat==GLUT_KEY_REPEAT_OFF || window->State.IgnoreKeyRepeat==GL_TRUE) && (HIWORD(lParam) & KF_REPEAT) )
1695 fgState.Modifiers = fghGetWin32Modifiers( );
1696 INVOKE_WCB( *window, Keyboard,
1698 window->State.MouseX, window->State.MouseY )
1700 fgState.Modifiers = 0xffffffff;
1704 case WM_CAPTURECHANGED:
1705 /* User has finished resizing the window, force a redraw */
1706 INVOKE_WCB( *window, Display, ( ) );
1708 /*lRet = DefWindowProc( hWnd, uMsg, wParam, lParam ); */
1711 /* Other messages that I have seen and which are not handled already */
1712 case WM_SETTEXT: /* 0x000c */
1713 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1714 /* Pass it on to "DefWindowProc" to set the window text */
1717 case WM_GETTEXT: /* 0x000d */
1718 /* Ideally we would copy the title of the window into "lParam" */
1719 /* strncpy ( (char *)lParam, "Window Title", wParam );
1720 lRet = ( wParam > 12 ) ? 12 : wParam; */
1721 /* the number of characters copied */
1722 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1725 case WM_GETTEXTLENGTH: /* 0x000e */
1726 /* Ideally we would get the length of the title of the window */
1728 /* the number of characters in "Window Title\0" (see above) */
1731 case WM_ERASEBKGND: /* 0x0014 */
1732 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1735 #if !TARGET_HOST_WINCE
1736 case WM_SYNCPAINT: /* 0x0088 */
1737 /* Another window has moved, need to update this one */
1738 window->State.Redisplay = GL_TRUE;
1739 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1740 /* Help screen says this message must be passed to "DefWindowProc" */
1743 case WM_NCPAINT: /* 0x0085 */
1744 /* Need to update the border of this window */
1745 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1746 /* Pass it on to "DefWindowProc" to repaint a standard border */
1749 case WM_SYSCOMMAND : /* 0x0112 */
1752 * We have received a system command message. Try to act on it.
1753 * The commands are passed in through the "wParam" parameter:
1754 * The least significant digit seems to be which edge of the window
1755 * is being used for a resize event:
1759 * Congratulations and thanks to Richard Rauch for figuring this out..
1761 switch ( wParam & 0xfff0 )
1770 /* User has clicked on the "-" to minimize the window */
1771 /* Turn off the visibility */
1772 window->State.Visible = GL_FALSE ;
1779 case SC_NEXTWINDOW :
1782 case SC_PREVWINDOW :
1786 /* Followed very closely by a WM_CLOSE message */
1810 case SC_SCREENSAVE :
1818 fgWarning( "Unknown wParam type 0x%x", wParam );
1823 #endif /* !TARGET_HOST_WINCE */
1825 /* We need to pass the message on to the operating system as well */
1826 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1830 /* Handle unhandled messages */
1831 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1839 /*** END OF FILE ***/