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"
35 # define VFPRINTF(s,f,a) vfprintf((s),(f),(a))
37 # define VFPRINTF(s,f,a) _doprnt((f),(a),(s))
39 # define VFPRINTF(s,f,a)
44 typedef struct GXDisplayProperties GXDisplayProperties;
45 typedef struct GXKeyList GXKeyList;
48 typedef struct GXKeyList (*GXGETDEFAULTKEYS)(int);
49 typedef int (*GXOPENINPUT)();
51 GXGETDEFAULTKEYS GXGetDefaultKeys_ = NULL;
52 GXOPENINPUT GXOpenInput_ = NULL;
54 struct GXKeyList gxKeyList;
59 * Try to get the maximum value allowed for ints, falling back to the minimum
60 * guaranteed by ISO C99 if there is no suitable header.
66 # define INT_MAX 32767
70 #define MIN(a,b) (((a)<(b)) ? (a) : (b))
75 * TODO BEFORE THE STABLE RELEASE:
77 * There are some issues concerning window redrawing under X11, and maybe
78 * some events are not handled. The Win32 version lacks some more features,
79 * but seems acceptable for not demanding purposes.
81 * Need to investigate why the X11 version breaks out with an error when
82 * closing a window (using the window manager, not glutDestroyWindow)...
85 /* -- PRIVATE FUNCTIONS ---------------------------------------------------- */
88 * Handle a window configuration change. When no reshape
89 * callback is hooked, the viewport size is updated to
90 * match the new window size.
92 static void fghReshapeWindow ( SFG_Window *window, int width, int height )
94 SFG_Window *current_window = fgStructure.Window;
96 freeglut_return_if_fail( window != NULL );
99 #if TARGET_HOST_UNIX_X11
101 XResizeWindow( fgDisplay.Display, window->Window.Handle,
103 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
105 #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE
107 #if !TARGET_HOST_WINCE
113 * For windowed mode, get the current position of the
114 * window and resize taking the size of the frame
115 * decorations into account.
118 /* "GetWindowRect" returns the pixel coordinates of the outside of the window */
119 GetWindowRect( window->Window.Handle, &winRect );
125 if ( window->Parent == NULL )
127 if ( ! window->IsMenu && !window->State.IsGameMode )
129 w += GetSystemMetrics( SM_CXSIZEFRAME ) * 2;
130 h += GetSystemMetrics( SM_CYSIZEFRAME ) * 2 +
131 GetSystemMetrics( SM_CYCAPTION );
137 GetWindowRect( window->Parent->Window.Handle, &parentRect );
138 x -= parentRect.left + GetSystemMetrics( SM_CXSIZEFRAME ) * 2;
139 y -= parentRect.top + GetSystemMetrics( SM_CYSIZEFRAME ) * 2 +
140 GetSystemMetrics( SM_CYCAPTION );
144 * SWP_NOACTIVATE Do not activate the window
145 * SWP_NOOWNERZORDER Do not change position in z-order
146 * SWP_NOSENDCHANGING Supress WM_WINDOWPOSCHANGING message
147 * SWP_NOZORDER Retains the current Z order (ignore 2nd param)
150 SetWindowPos( window->Window.Handle,
153 SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOSENDCHANGING |
157 #endif /* TARGET_HOST_WINCE */
160 * XXX Should update {window->State.OldWidth, window->State.OldHeight}
161 * XXX to keep in lockstep with UNIX_X11 code.
163 if( FETCH_WCB( *window, Reshape ) )
164 INVOKE_WCB( *window, Reshape, ( width, height ) );
167 fgSetWindow( window );
168 glViewport( 0, 0, width, height );
174 * Force a window redraw. In Windows at least this is only a partial
175 * solution: if the window is increasing in size in either dimension,
176 * the already-drawn part does not get drawn again and things look funny.
177 * But without this we get this bad behaviour whenever we resize the
180 window->State.Redisplay = GL_TRUE;
183 fgSetWindow( current_window );
187 * Calls a window's redraw method. This is used when
188 * a redraw is forced by the incoming window messages.
190 static void fghRedrawWindow ( SFG_Window *window )
192 SFG_Window *current_window = fgStructure.Window;
194 freeglut_return_if_fail( window );
195 freeglut_return_if_fail( FETCH_WCB ( *window, Display ) );
197 window->State.Redisplay = GL_FALSE;
199 freeglut_return_if_fail( window->State.Visible );
201 fgSetWindow( window );
203 if( window->State.NeedToResize )
211 window->State.NeedToResize = GL_FALSE;
214 INVOKE_WCB( *window, Display, ( ) );
216 fgSetWindow( current_window );
220 * A static helper function to execute display callback for a window
222 static void fghcbDisplayWindow( SFG_Window *window,
223 SFG_Enumerator *enumerator )
225 if( window->State.Redisplay &&
226 window->State.Visible )
228 window->State.Redisplay = GL_FALSE;
230 #if TARGET_HOST_UNIX_X11
231 fghRedrawWindow ( 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 fghCheckJoystickCallback( SFG_Window* w, SFG_Enumerator* e)
400 if( FETCH_WCB( *w, Joystick ) )
405 fgEnumSubWindows( w, fghCheckJoystickCallback, e );
407 static int fghHaveJoystick( void )
409 SFG_Enumerator enumerator;
411 enumerator.found = GL_FALSE;
412 enumerator.data = NULL;
413 fgEnumWindows( fghCheckJoystickCallback, &enumerator );
414 return !!enumerator.data;
416 static void fghHavePendingRedisplaysCallback( SFG_Window* w, SFG_Enumerator* e)
418 if( w->State.Redisplay )
423 fgEnumSubWindows( w, fghHavePendingRedisplaysCallback, e );
425 static int fghHavePendingRedisplays (void)
427 SFG_Enumerator enumerator;
429 enumerator.found = GL_FALSE;
430 enumerator.data = NULL;
431 fgEnumWindows( fghHavePendingRedisplaysCallback, &enumerator );
432 return !!enumerator.data;
435 * Returns the number of GLUT ticks (milliseconds) till the next timer event.
437 static long fghNextTimer( void )
440 SFG_Timer *timer = fgState.Timers.First;
443 ret = timer->TriggerTime - fgElapsedTime();
450 * Does the magic required to relinquish the CPU until something interesting
453 static void fghSleepForEvents( void )
457 if( fgState.IdleCallback || fghHavePendingRedisplays( ) )
460 msec = fghNextTimer( );
461 /* XXX Use GLUT timers for joysticks... */
462 /* XXX Dumb; forces granularity to .01sec */
463 if( fghHaveJoystick( ) && ( msec < 10 ) )
466 #if TARGET_HOST_UNIX_X11
468 * Possibly due to aggressive use of XFlush() and friends,
469 * it is possible to have our socket drained but still have
470 * unprocessed events. (Or, this may just be normal with
471 * X, anyway?) We do non-trivial processing of X events
472 * after the event-reading loop, in any case, so we
473 * need to allow that we may have an empty socket but non-
476 if( ! XPending( fgDisplay.Display ) )
483 socket = ConnectionNumber( fgDisplay.Display );
485 FD_SET( socket, &fdset );
486 wait.tv_sec = msec / 1000;
487 wait.tv_usec = (msec % 1000) * 1000;
488 err = select( socket+1, &fdset, NULL, NULL, &wait );
491 fgWarning ( "freeglut select() error: %d", errno );
493 #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE
494 MsgWaitForMultipleObjects( 0, NULL, FALSE, msec, QS_ALLEVENTS );
498 #if TARGET_HOST_UNIX_X11
500 * Returns GLUT modifier mask for an XEvent.
502 static int fghGetXModifiers( XEvent *event )
506 if( event->xkey.state & ( ShiftMask | LockMask ) )
507 ret |= GLUT_ACTIVE_SHIFT;
508 if( event->xkey.state & ControlMask )
509 ret |= GLUT_ACTIVE_CTRL;
510 if( event->xkey.state & Mod1Mask )
511 ret |= GLUT_ACTIVE_ALT;
518 /* -- INTERFACE FUNCTIONS -------------------------------------------------- */
521 * Executes a single iteration in the freeglut processing loop.
523 void FGAPIENTRY glutMainLoopEvent( void )
525 #if TARGET_HOST_UNIX_X11
529 /* This code was repeated constantly, so here it goes into a definition: */
530 #define GETWINDOW(a) \
531 window = fgWindowByHandle( event.a.window ); \
532 if( window == NULL ) \
535 #define GETMOUSE(a) \
536 window->State.MouseX = event.a.x; \
537 window->State.MouseY = event.a.y;
539 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutMainLoopEvent" );
541 while( XPending( fgDisplay.Display ) )
543 XNextEvent( fgDisplay.Display, &event );
548 /* 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 )
560 else if( fgState.ActionOnWindowClose == GLUT_ACTION_GLUTMAINLOOP_RETURNS )
561 fgState.ExecState = GLUT_EXEC_STATE_STOP;
568 * CreateNotify causes a configure-event so that sub-windows are
569 * handled compatibly with GLUT. Otherwise, your sub-windows
570 * (in freeglut only) will not get an initial reshape event,
571 * which can break things.
573 * GLUT presumably does this because it generally tries to treat
574 * sub-windows the same as windows.
576 * XXX Technically, GETWINDOW( xconfigure ) and
577 * XXX {event.xconfigure} may not be legit ways to get at
578 * XXX data for CreateNotify events. In practice, the data
579 * XXX is in a union which is laid out much the same either
580 * XXX way. But if you want to split hairs, this isn't legit,
581 * XXX and we should instead duplicate some code.
584 case ConfigureNotify:
585 GETWINDOW( xconfigure );
587 int width = event.xconfigure.width;
588 int height = event.xconfigure.height;
590 if( ( width != window->State.OldWidth ) ||
591 ( height != window->State.OldHeight ) )
593 window->State.OldWidth = width;
594 window->State.OldHeight = height;
595 if( FETCH_WCB( *window, Reshape ) )
596 INVOKE_WCB( *window, Reshape, ( width, height ) );
599 fgSetWindow( window );
600 glViewport( 0, 0, width, height );
602 glutPostRedisplay( );
609 * This is sent to confirm the XDestroyWindow call.
611 * XXX WHY is this commented out? Should we re-enable it?
613 /* fgAddToWindowDestroyList ( window ); */
618 * We are too dumb to process partial exposes...
620 * XXX Well, we could do it. However, it seems to only
621 * XXX be potentially useful for single-buffered (since
622 * XXX double-buffered does not respect viewport when we
623 * XXX do a buffer-swap).
626 if( event.xexpose.count == 0 )
628 GETWINDOW( xexpose );
629 fgSetWindow( window );
630 glutPostRedisplay( );
637 * If we never do anything with this, can we just not ask to
638 * get these messages?
644 * Have the client's keyboard knowledge updated (xlib.ps,
645 * page 206, says that's a good thing to do)
647 XRefreshKeyboardMapping( (XMappingEvent *) &event );
650 case VisibilityNotify:
652 GETWINDOW( xvisibility );
654 * XXX INVOKE_WCB() does this check for us.
656 if( ! FETCH_WCB( *window, WindowStatus ) )
658 fgSetWindow( window );
661 * Sending this event, the X server can notify us that the window
662 * has just acquired one of the three possible visibility states:
663 * VisibilityUnobscured, VisibilityPartiallyObscured or
664 * VisibilityFullyObscured
666 switch( event.xvisibility.state )
668 case VisibilityUnobscured:
669 INVOKE_WCB( *window, WindowStatus, ( GLUT_FULLY_RETAINED ) );
670 window->State.Visible = GL_TRUE;
673 case VisibilityPartiallyObscured:
674 INVOKE_WCB( *window, WindowStatus,
675 ( GLUT_PARTIALLY_RETAINED ) );
676 window->State.Visible = GL_TRUE;
679 case VisibilityFullyObscured:
680 INVOKE_WCB( *window, WindowStatus, ( GLUT_FULLY_COVERED ) );
681 window->State.Visible = GL_FALSE;
685 fgWarning( "Unknown X visibility state: %d",
686 event.xvisibility.state );
694 GETWINDOW( xcrossing );
695 GETMOUSE( xcrossing );
696 INVOKE_WCB( *window, Entry, ( ( EnterNotify == event.type ) ?
703 GETWINDOW( xmotion );
706 if( window->ActiveMenu )
708 if( window == window->ActiveMenu->ParentWindow )
710 window->ActiveMenu->Window->State.MouseX =
711 event.xmotion.x_root - window->ActiveMenu->X;
712 window->ActiveMenu->Window->State.MouseY =
713 event.xmotion.y_root - window->ActiveMenu->Y;
715 window->ActiveMenu->Window->State.Redisplay = GL_TRUE ;
716 fgSetWindow( window->ActiveMenu->ParentWindow );
722 * XXX For more than 5 buttons, just check {event.xmotion.state},
723 * XXX rather than a host of bit-masks? Or maybe we need to
724 * XXX track ButtonPress/ButtonRelease events in our own
727 #define BUTTON_MASK \
728 ( Button1Mask | Button2Mask | Button3Mask | Button4Mask | Button5Mask )
729 if ( event.xmotion.state & BUTTON_MASK )
730 INVOKE_WCB( *window, Motion, ( event.xmotion.x,
733 INVOKE_WCB( *window, Passive, ( event.xmotion.x,
741 GLboolean pressed = GL_TRUE;
744 if( event.type == ButtonRelease )
748 * A mouse button has been pressed or released. Traditionally,
749 * break if the window was found within the freeglut structures.
751 GETWINDOW( xbutton );
755 * An X button (at least in XFree86) is numbered from 1.
756 * A GLUT button is numbered from 0.
757 * Old GLUT passed through buttons other than just the first
758 * three, though it only gave symbolic names and official
759 * support to the first three.
761 button = event.xbutton.button - 1;
764 * Do not execute the application's mouse callback if a menu
765 * is hooked to this button. In that case an appropriate
766 * private call should be generated.
768 if( fgCheckActiveMenu( window, button, pressed,
769 event.xbutton.x_root, event.xbutton.y_root ) )
773 * Check if there is a mouse or mouse wheel callback hooked to the
776 if( ! FETCH_WCB( *window, Mouse ) &&
777 ! FETCH_WCB( *window, MouseWheel ) )
780 fgState.Modifiers = fghGetXModifiers( &event );
783 * Finally execute the mouse or mouse wheel callback
785 * XXX Use a symbolic constant, *not* "4"! ("3, sire!")
787 if( ( button < 3 ) || ( ! FETCH_WCB( *window, MouseWheel ) ) )
788 INVOKE_WCB( *window, Mouse, ( button,
789 pressed ? GLUT_DOWN : GLUT_UP,
796 * Map 4 and 5 to wheel zero; EVEN to +1, ODD to -1
797 * " 6 and 7 " " one; ...
799 * XXX This *should* be behind some variables/macros,
800 * XXX since the order and numbering isn't certain
801 * XXX See XFree86 configuration docs (even back in the
802 * XXX 3.x days, and especially with 4.x).
804 * XXX Note that {button} has already been decremeted
805 * XXX in mapping from X button numbering to GLUT.
807 int wheel_number = (button - 3) / 2;
813 INVOKE_WCB( *window, MouseWheel, ( wheel_number,
820 /* Trash the modifiers state */
821 fgState.Modifiers = 0xffffffff;
828 FGCBKeyboard keyboard_cb;
829 FGCBSpecial special_cb;
834 /* Detect auto repeated keys, if configured globally or per-window */
836 if ( fgState.KeyRepeat==GLUT_KEY_REPEAT_OFF || window->State.IgnoreKeyRepeat==GL_TRUE )
838 if (event.type==KeyRelease)
841 * Look at X11 keystate to detect repeat mode.
842 * While X11 says the key is actually held down, we'll ignore KeyRelease/KeyPress pairs.
846 XQueryKeymap( fgDisplay.Display, keys ); /* Look at X11 keystate to detect repeat mode */
848 if ( event.xkey.keycode<256 ) /* XQueryKeymap is limited to 256 keycodes */
850 if ( keys[event.xkey.keycode>>3] & (1<<(event.xkey.keycode%8)) )
851 window->State.KeyRepeating = GL_TRUE;
853 window->State.KeyRepeating = GL_FALSE;
858 window->State.KeyRepeating = GL_FALSE;
860 /* Cease processing this event if it is auto repeated */
862 if (window->State.KeyRepeating)
865 if( event.type == KeyPress )
867 keyboard_cb = FETCH_WCB( *window, Keyboard );
868 special_cb = FETCH_WCB( *window, Special );
872 keyboard_cb = FETCH_WCB( *window, KeyboardUp );
873 special_cb = FETCH_WCB( *window, SpecialUp );
876 /* Is there a keyboard/special callback hooked for this window? */
877 if( keyboard_cb || special_cb )
879 XComposeStatus composeStatus;
880 char asciiCode[ 32 ];
884 /* Check for the ASCII/KeySym codes associated with the event: */
885 len = XLookupString( &event.xkey, asciiCode, sizeof(asciiCode),
886 &keySym, &composeStatus
889 /* GLUT API tells us to have two separate callbacks... */
892 /* ...one for the ASCII translateable keypresses... */
895 fgSetWindow( window );
896 fgState.Modifiers = fghGetXModifiers( &event );
897 keyboard_cb( asciiCode[ 0 ],
898 event.xkey.x, event.xkey.y
900 fgState.Modifiers = 0xffffffff;
908 * ...and one for all the others, which need to be
909 * translated to GLUT_KEY_Xs...
913 case XK_F1: special = GLUT_KEY_F1; break;
914 case XK_F2: special = GLUT_KEY_F2; break;
915 case XK_F3: special = GLUT_KEY_F3; break;
916 case XK_F4: special = GLUT_KEY_F4; break;
917 case XK_F5: special = GLUT_KEY_F5; break;
918 case XK_F6: special = GLUT_KEY_F6; break;
919 case XK_F7: special = GLUT_KEY_F7; break;
920 case XK_F8: special = GLUT_KEY_F8; break;
921 case XK_F9: special = GLUT_KEY_F9; break;
922 case XK_F10: special = GLUT_KEY_F10; break;
923 case XK_F11: special = GLUT_KEY_F11; break;
924 case XK_F12: special = GLUT_KEY_F12; break;
926 case XK_Left: special = GLUT_KEY_LEFT; break;
927 case XK_Right: special = GLUT_KEY_RIGHT; break;
928 case XK_Up: special = GLUT_KEY_UP; break;
929 case XK_Down: special = GLUT_KEY_DOWN; break;
932 case XK_Prior: special = GLUT_KEY_PAGE_UP; break;
934 case XK_Next: special = GLUT_KEY_PAGE_DOWN; break;
936 case XK_Home: special = GLUT_KEY_HOME; break;
938 case XK_End: special = GLUT_KEY_END; break;
940 case XK_Insert: special = GLUT_KEY_INSERT; break;
944 * Execute the callback (if one has been specified),
945 * given that the special code seems to be valid...
947 if( special_cb && (special != -1) )
949 fgSetWindow( window );
950 fgState.Modifiers = fghGetXModifiers( &event );
951 special_cb( special, event.xkey.x, event.xkey.y );
952 fgState.Modifiers = 0xffffffff;
960 break; /* XXX Should disable this event */
963 fgWarning ("Unknown X event type: %d", event.type);
968 #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE
972 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutMainLoopEvent" );
974 while( PeekMessage( &stMsg, NULL, 0, 0, PM_NOREMOVE ) )
976 if( GetMessage( &stMsg, NULL, 0, 0 ) == 0 )
978 if( fgState.ActionOnWindowClose == GLUT_ACTION_EXIT )
983 else if( fgState.ActionOnWindowClose == GLUT_ACTION_GLUTMAINLOOP_RETURNS )
984 fgState.ExecState = GLUT_EXEC_STATE_STOP;
989 TranslateMessage( &stMsg );
990 DispatchMessage( &stMsg );
994 if( fgState.Timers.First )
996 fghCheckJoystickPolls( );
1003 * Enters the freeglut processing loop.
1004 * Stays until the "ExecState" changes to "GLUT_EXEC_STATE_STOP".
1006 void FGAPIENTRY glutMainLoop( void )
1010 #if TARGET_HOST_WIN32 || TARGET_HOST_WINCE
1011 SFG_Window *window = (SFG_Window *)fgStructure.Windows.First ;
1014 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutMainLoop" );
1016 #if TARGET_HOST_WIN32 || TARGET_HOST_WINCE
1018 * Processing before the main loop: If there is a window which is open and
1019 * which has a visibility callback, call it. I know this is an ugly hack,
1020 * but I'm not sure what else to do about it. Ideally we should leave
1021 * something uninitialized in the create window code and initialize it in
1022 * the main loop, and have that initialization create a "WM_ACTIVATE"
1023 * message. Then we would put the visibility callback code in the
1024 * "case WM_ACTIVATE" block below. - John Fay -- 10/24/02
1028 if ( FETCH_WCB( *window, Visibility ) )
1030 SFG_Window *current_window = fgStructure.Window ;
1032 INVOKE_WCB( *window, Visibility, ( window->State.Visible ) );
1033 fgSetWindow( current_window );
1036 window = (SFG_Window *)window->Node.Next ;
1040 fgState.ExecState = GLUT_EXEC_STATE_RUNNING ;
1041 while( fgState.ExecState == GLUT_EXEC_STATE_RUNNING )
1045 glutMainLoopEvent( );
1047 * Step through the list of windows, seeing if there are any
1048 * that are not menus
1050 for( window = ( SFG_Window * )fgStructure.Windows.First;
1052 window = ( SFG_Window * )window->Node.Next )
1053 if ( ! ( window->IsMenu ) )
1057 fgState.ExecState = GLUT_EXEC_STATE_STOP;
1060 if( fgState.IdleCallback )
1061 fgState.IdleCallback( );
1063 fghSleepForEvents( );
1068 * When this loop terminates, destroy the display, state and structure
1069 * of a freeglut session, so that another glutInit() call can happen
1071 * Save the "ActionOnWindowClose" because "fgDeinitialize" resets it.
1073 action = fgState.ActionOnWindowClose;
1075 if( action == GLUT_ACTION_EXIT )
1080 * Leaves the freeglut processing loop.
1082 void FGAPIENTRY glutLeaveMainLoop( void )
1084 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutLeaveMainLoop" );
1085 fgState.ExecState = GLUT_EXEC_STATE_STOP ;
1089 #if TARGET_HOST_WIN32 || TARGET_HOST_WINCE
1091 * Determine a GLUT modifer mask based on MS-WINDOWS system info.
1093 static int fghGetWin32Modifiers (void)
1096 ( ( ( GetKeyState( VK_LSHIFT ) < 0 ) ||
1097 ( GetKeyState( VK_RSHIFT ) < 0 )) ? GLUT_ACTIVE_SHIFT : 0 ) |
1098 ( ( ( GetKeyState( VK_LCONTROL ) < 0 ) ||
1099 ( GetKeyState( VK_RCONTROL ) < 0 )) ? GLUT_ACTIVE_CTRL : 0 ) |
1100 ( ( ( GetKeyState( VK_LMENU ) < 0 ) ||
1101 ( GetKeyState( VK_RMENU ) < 0 )) ? GLUT_ACTIVE_ALT : 0 );
1105 * The window procedure for handling Win32 events
1107 LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam,
1114 FREEGLUT_INTERNAL_ERROR_EXIT_IF_NOT_INITIALISED ( "Event Handler" ) ;
1116 window = fgWindowByHandle( hWnd );
1118 if ( ( window == NULL ) && ( uMsg != WM_CREATE ) )
1119 return DefWindowProc( hWnd, uMsg, wParam, lParam );
1121 /* printf ( "Window %3d message <%04x> %12d %12d\n", window?window->ID:0,
1122 uMsg, wParam, lParam ); */
1126 /* The window structure is passed as the creation structure paramter... */
1127 window = (SFG_Window *) (((LPCREATESTRUCT) lParam)->lpCreateParams);
1128 FREEGLUT_INTERNAL_ERROR_EXIT ( ( window != NULL ), "Cannot create window",
1131 window->Window.Handle = hWnd;
1132 window->Window.Device = GetDC( hWnd );
1133 if( window->IsMenu )
1135 unsigned int current_DisplayMode = fgState.DisplayMode;
1136 fgState.DisplayMode = GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH;
1137 #if !TARGET_HOST_WINCE
1138 fgSetupPixelFormat( window, GL_FALSE, PFD_MAIN_PLANE );
1140 fgState.DisplayMode = current_DisplayMode;
1142 if( fgStructure.MenuContext )
1143 wglMakeCurrent( window->Window.Device,
1144 fgStructure.MenuContext->Context
1148 fgStructure.MenuContext =
1149 (SFG_MenuContext *)malloc( sizeof(SFG_MenuContext) );
1150 fgStructure.MenuContext->Context =
1151 wglCreateContext( window->Window.Device );
1154 /* window->Window.Context = wglGetCurrentContext (); */
1155 window->Window.Context = wglCreateContext( window->Window.Device );
1159 #if !TARGET_HOST_WINCE
1160 fgSetupPixelFormat( window, GL_FALSE, PFD_MAIN_PLANE );
1163 if( ! fgState.UseCurrentContext )
1164 window->Window.Context =
1165 wglCreateContext( window->Window.Device );
1168 window->Window.Context = wglGetCurrentContext( );
1169 if( ! window->Window.Context )
1170 window->Window.Context =
1171 wglCreateContext( window->Window.Device );
1175 window->State.NeedToResize = GL_TRUE;
1176 window->State.Width = fgState.Size.X;
1177 window->State.Height = fgState.Size.Y;
1179 ReleaseDC( window->Window.Handle, window->Window.Device );
1181 #if TARGET_HOST_WINCE
1182 /* Take over button handling */
1184 HINSTANCE dxDllLib=LoadLibrary(_T("gx.dll"));
1187 GXGetDefaultKeys_=(GXGETDEFAULTKEYS)GetProcAddress(dxDllLib, _T("?GXGetDefaultKeys@@YA?AUGXKeyList@@H@Z"));
1188 GXOpenInput_=(GXOPENINPUT)GetProcAddress(dxDllLib, _T("?GXOpenInput@@YAHXZ"));
1193 if(GXGetDefaultKeys_)
1194 gxKeyList = (*GXGetDefaultKeys_)(GX_LANDSCAPEKEYS);
1197 #endif /* TARGET_HOST_WINCE */
1202 * If the window is visible, then it is the user manually resizing it.
1203 * If it is not, then it is the system sending us a dummy resize with
1204 * zero dimensions on a "glutIconifyWindow" call.
1206 if( window->State.Visible )
1208 window->State.NeedToResize = GL_TRUE;
1209 #if TARGET_HOST_WINCE
1210 window->State.Width = HIWORD(lParam);
1211 window->State.Height = LOWORD(lParam);
1213 window->State.Width = LOWORD(lParam);
1214 window->State.Height = HIWORD(lParam);
1215 #endif /* TARGET_HOST_WINCE */
1221 /* printf("WM_SETFOCUS: %p\n", window ); */
1222 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1226 if (LOWORD(wParam) != WA_INACTIVE)
1228 /* glutSetCursor( fgStructure.Window->State.Cursor ); */
1229 /* printf("WM_ACTIVATE: glutSetCursor( %p, %d)\n", window,
1230 window->State.Cursor ); */
1231 glutSetCursor( window->State.Cursor );
1234 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1239 * XXX Why not re-use some common code with the glutSetCursor()
1240 * XXX function (or perhaps invoke glutSetCursor())?
1241 * XXX That is, why are we duplicating code, here, from
1242 * XXX glutSetCursor()? The WIN32 code should be able to just
1243 * XXX call glutSetCursor() instead of defining two macros
1244 * XXX and implementing a nested case in-line.
1247 /* Set the cursor AND change it for this window class. */
1248 #define MAP_CURSOR(a,b) \
1250 SetCursor( LoadCursor( NULL, b ) ); \
1253 /* Nuke the cursor AND change it for this window class. */
1254 #define ZAP_CURSOR(a,b) \
1256 SetCursor( NULL ); \
1259 /* printf ( "Cursor event %x %x %x %x\n", window, window->State.Cursor, lParam, wParam ) ; */
1260 if( LOWORD( lParam ) == HTCLIENT )
1261 switch( window->State.Cursor )
1263 MAP_CURSOR( GLUT_CURSOR_RIGHT_ARROW, IDC_ARROW );
1264 MAP_CURSOR( GLUT_CURSOR_LEFT_ARROW, IDC_ARROW );
1265 MAP_CURSOR( GLUT_CURSOR_INFO, IDC_HELP );
1266 MAP_CURSOR( GLUT_CURSOR_DESTROY, IDC_CROSS );
1267 MAP_CURSOR( GLUT_CURSOR_HELP, IDC_HELP );
1268 MAP_CURSOR( GLUT_CURSOR_CYCLE, IDC_SIZEALL );
1269 MAP_CURSOR( GLUT_CURSOR_SPRAY, IDC_CROSS );
1270 MAP_CURSOR( GLUT_CURSOR_WAIT, IDC_WAIT );
1271 MAP_CURSOR( GLUT_CURSOR_TEXT, IDC_UPARROW );
1272 MAP_CURSOR( GLUT_CURSOR_CROSSHAIR, IDC_CROSS );
1273 /* MAP_CURSOR( GLUT_CURSOR_NONE, IDC_NO ); */
1274 ZAP_CURSOR( GLUT_CURSOR_NONE, NULL );
1277 MAP_CURSOR( GLUT_CURSOR_UP_DOWN, IDC_ARROW );
1280 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1284 window->State.Visible = GL_TRUE;
1285 window->State.Redisplay = GL_TRUE;
1289 /* Turn on the visibility in case it was turned off somehow */
1290 window->State.Visible = GL_TRUE;
1291 BeginPaint( hWnd, &ps );
1292 fghRedrawWindow( window );
1293 EndPaint( hWnd, &ps );
1297 fgDestroyWindow ( window );
1298 if ( fgState.ActionOnWindowClose != GLUT_ACTION_CONTINUE_EXECUTION )
1304 * The window already got destroyed, so don't bother with it.
1310 #if TARGET_HOST_WINCE
1311 window->State.MouseX = 320-HIWORD( lParam );
1312 window->State.MouseY = LOWORD( lParam );
1314 window->State.MouseX = LOWORD( lParam );
1315 window->State.MouseY = HIWORD( lParam );
1316 #endif /* TARGET_HOST_WINCE */
1317 /* Restrict to [-32768, 32767] to match X11 behaviour */
1318 /* See comment in "freeglut_developer" mailing list 10/4/04 */
1319 if ( window->State.MouseX > 32767 ) window->State.MouseX -= 65536;
1320 if ( window->State.MouseY > 32767 ) window->State.MouseY -= 65536;
1322 if ( window->ActiveMenu )
1324 window->State.Redisplay = GL_TRUE;
1325 fgSetWindow ( window->ActiveMenu->ParentWindow );
1329 fgState.Modifiers = fghGetWin32Modifiers( );
1331 if( ( wParam & MK_LBUTTON ) ||
1332 ( wParam & MK_MBUTTON ) ||
1333 ( wParam & MK_RBUTTON ) )
1334 INVOKE_WCB( *window, Motion, ( window->State.MouseX,
1335 window->State.MouseY ) );
1337 INVOKE_WCB( *window, Passive, ( window->State.MouseX,
1338 window->State.MouseY ) );
1340 fgState.Modifiers = 0xffffffff;
1344 case WM_LBUTTONDOWN:
1345 case WM_MBUTTONDOWN:
1346 case WM_RBUTTONDOWN:
1351 GLboolean pressed = GL_TRUE;
1354 #if TARGET_HOST_WINCE
1355 window->State.MouseX = 320-HIWORD( lParam );
1356 window->State.MouseY = LOWORD( lParam );
1358 window->State.MouseX = LOWORD( lParam );
1359 window->State.MouseY = HIWORD( lParam );
1360 #endif /* TARGET_HOST_WINCE */
1362 /* Restrict to [-32768, 32767] to match X11 behaviour */
1363 /* See comment in "freeglut_developer" mailing list 10/4/04 */
1364 if ( window->State.MouseX > 32767 ) window->State.MouseX -= 65536;
1365 if ( window->State.MouseY > 32767 ) window->State.MouseY -= 65536;
1369 case WM_LBUTTONDOWN:
1371 button = GLUT_LEFT_BUTTON;
1373 case WM_MBUTTONDOWN:
1375 button = GLUT_MIDDLE_BUTTON;
1377 case WM_RBUTTONDOWN:
1379 button = GLUT_RIGHT_BUTTON;
1383 button = GLUT_LEFT_BUTTON;
1387 button = GLUT_MIDDLE_BUTTON;
1391 button = GLUT_RIGHT_BUTTON;
1399 #if !TARGET_HOST_WINCE
1400 if( GetSystemMetrics( SM_SWAPBUTTON ) )
1402 if( button == GLUT_LEFT_BUTTON )
1403 button = GLUT_RIGHT_BUTTON;
1405 if( button == GLUT_RIGHT_BUTTON )
1406 button = GLUT_LEFT_BUTTON;
1408 #endif /* !TARGET_HOST_WINCE */
1411 return DefWindowProc( hWnd, uMsg, lParam, wParam );
1414 * Do not execute the application's mouse callback if a menu
1415 * is hooked to this button. In that case an appropriate
1416 * private call should be generated.
1418 if( fgCheckActiveMenu( window, button, pressed,
1419 window->State.MouseX, window->State.MouseY ) )
1422 if( window->Menu[ button ] && pressed )
1424 window->State.Redisplay = GL_TRUE;
1425 fgSetWindow( window );
1426 fgActivateMenu( window, button );
1431 /* Set capture so that the window captures all the mouse messages */
1433 * XXX - Multiple button support: Under X11, the mouse is not released
1434 * XXX - from the window until all buttons have been released, even if the
1435 * XXX - user presses a button in another window. This will take more
1436 * XXX - code changes than I am up to at the moment (10/5/04). The present
1437 * XXX - is a 90 percent solution.
1439 if ( pressed == GL_TRUE )
1440 SetCapture ( window->Window.Handle ) ;
1444 if( ! FETCH_WCB( *window, Mouse ) )
1447 fgSetWindow( window );
1448 fgState.Modifiers = fghGetWin32Modifiers( );
1453 pressed ? GLUT_DOWN : GLUT_UP,
1454 window->State.MouseX,
1455 window->State.MouseY
1459 fgState.Modifiers = 0xffffffff;
1464 /* Should be WM_MOUSEWHEEL but my compiler doesn't recognize it */
1467 * XXX THIS IS SPECULATIVE -- John Fay, 10/2/03
1468 * XXX Should use WHEEL_DELTA instead of 120
1470 int wheel_number = LOWORD( wParam );
1471 short ticks = ( short )HIWORD( wParam ) / 120;
1481 * The mouse cursor has moved. Remember the new mouse cursor's position
1483 /* window->State.MouseX = LOWORD( lParam ); */
1484 /* Need to adjust by window position, */
1485 /* window->State.MouseY = HIWORD( lParam ); */
1486 /* change "lParam" to other parameter */
1488 if( ! FETCH_WCB( *window, MouseWheel ) &&
1489 ! FETCH_WCB( *window, Mouse ) )
1492 fgSetWindow( window );
1493 fgState.Modifiers = fghGetWin32Modifiers( );
1496 if( FETCH_WCB( *window, MouseWheel ) )
1497 INVOKE_WCB( *window, MouseWheel,
1500 window->State.MouseX,
1501 window->State.MouseY
1504 else /* No mouse wheel, call the mouse button callback twice */
1507 * XXX The below assumes that you have no more than 3 mouse
1508 * XXX buttons. Sorry.
1510 int button = wheel_number*2 + 4;
1513 INVOKE_WCB( *window, Mouse,
1514 ( button, GLUT_DOWN,
1515 window->State.MouseX, window->State.MouseY )
1517 INVOKE_WCB( *window, Mouse,
1519 window->State.MouseX, window->State.MouseX )
1523 fgState.Modifiers = 0xffffffff;
1533 if( ( fgState.KeyRepeat==GLUT_KEY_REPEAT_OFF || window->State.IgnoreKeyRepeat==GL_TRUE ) && (HIWORD(lParam) & KF_REPEAT) )
1537 * Remember the current modifiers state. This is done here in order
1538 * to make sure the VK_DELETE keyboard callback is executed properly.
1540 fgState.Modifiers = fghGetWin32Modifiers( );
1542 GetCursorPos( &mouse_pos );
1543 ScreenToClient( window->Window.Handle, &mouse_pos );
1545 window->State.MouseX = mouse_pos.x;
1546 window->State.MouseY = mouse_pos.y;
1548 /* Convert the Win32 keystroke codes to GLUTtish way */
1549 # define KEY(a,b) case a: keypress = b; break;
1553 KEY( VK_F1, GLUT_KEY_F1 );
1554 KEY( VK_F2, GLUT_KEY_F2 );
1555 KEY( VK_F3, GLUT_KEY_F3 );
1556 KEY( VK_F4, GLUT_KEY_F4 );
1557 KEY( VK_F5, GLUT_KEY_F5 );
1558 KEY( VK_F6, GLUT_KEY_F6 );
1559 KEY( VK_F7, GLUT_KEY_F7 );
1560 KEY( VK_F8, GLUT_KEY_F8 );
1561 KEY( VK_F9, GLUT_KEY_F9 );
1562 KEY( VK_F10, GLUT_KEY_F10 );
1563 KEY( VK_F11, GLUT_KEY_F11 );
1564 KEY( VK_F12, GLUT_KEY_F12 );
1565 KEY( VK_PRIOR, GLUT_KEY_PAGE_UP );
1566 KEY( VK_NEXT, GLUT_KEY_PAGE_DOWN );
1567 KEY( VK_HOME, GLUT_KEY_HOME );
1568 KEY( VK_END, GLUT_KEY_END );
1569 KEY( VK_LEFT, GLUT_KEY_LEFT );
1570 KEY( VK_UP, GLUT_KEY_UP );
1571 KEY( VK_RIGHT, GLUT_KEY_RIGHT );
1572 KEY( VK_DOWN, GLUT_KEY_DOWN );
1573 KEY( VK_INSERT, GLUT_KEY_INSERT );
1576 /* The delete key should be treated as an ASCII keypress: */
1577 INVOKE_WCB( *window, Keyboard,
1578 ( 127, window->State.MouseX, window->State.MouseY )
1582 #if TARGET_HOST_WINCE
1583 if(!(lParam & 0x40000000)) /* Prevent auto-repeat */
1585 if(wParam==(unsigned)gxKeyList.vkRight)
1586 keypress = GLUT_KEY_RIGHT;
1587 else if(wParam==(unsigned)gxKeyList.vkLeft)
1588 keypress = GLUT_KEY_LEFT;
1589 else if(wParam==(unsigned)gxKeyList.vkUp)
1590 keypress = GLUT_KEY_UP;
1591 else if(wParam==(unsigned)gxKeyList.vkDown)
1592 keypress = GLUT_KEY_DOWN;
1593 else if(wParam==(unsigned)gxKeyList.vkA)
1594 keypress = GLUT_KEY_F1;
1595 else if(wParam==(unsigned)gxKeyList.vkB)
1596 keypress = GLUT_KEY_F2;
1597 else if(wParam==(unsigned)gxKeyList.vkC)
1598 keypress = GLUT_KEY_F3;
1599 else if(wParam==(unsigned)gxKeyList.vkStart)
1600 keypress = GLUT_KEY_F4;
1604 if( keypress != -1 )
1605 INVOKE_WCB( *window, Special,
1607 window->State.MouseX, window->State.MouseY )
1610 fgState.Modifiers = 0xffffffff;
1621 * Remember the current modifiers state. This is done here in order
1622 * to make sure the VK_DELETE keyboard callback is executed properly.
1624 fgState.Modifiers = fghGetWin32Modifiers( );
1626 GetCursorPos( &mouse_pos );
1627 ScreenToClient( window->Window.Handle, &mouse_pos );
1629 window->State.MouseX = mouse_pos.x;
1630 window->State.MouseY = mouse_pos.y;
1633 * Convert the Win32 keystroke codes to GLUTtish way.
1634 * "KEY(a,b)" was defined under "WM_KEYDOWN"
1639 KEY( VK_F1, GLUT_KEY_F1 );
1640 KEY( VK_F2, GLUT_KEY_F2 );
1641 KEY( VK_F3, GLUT_KEY_F3 );
1642 KEY( VK_F4, GLUT_KEY_F4 );
1643 KEY( VK_F5, GLUT_KEY_F5 );
1644 KEY( VK_F6, GLUT_KEY_F6 );
1645 KEY( VK_F7, GLUT_KEY_F7 );
1646 KEY( VK_F8, GLUT_KEY_F8 );
1647 KEY( VK_F9, GLUT_KEY_F9 );
1648 KEY( VK_F10, GLUT_KEY_F10 );
1649 KEY( VK_F11, GLUT_KEY_F11 );
1650 KEY( VK_F12, GLUT_KEY_F12 );
1651 KEY( VK_PRIOR, GLUT_KEY_PAGE_UP );
1652 KEY( VK_NEXT, GLUT_KEY_PAGE_DOWN );
1653 KEY( VK_HOME, GLUT_KEY_HOME );
1654 KEY( VK_END, GLUT_KEY_END );
1655 KEY( VK_LEFT, GLUT_KEY_LEFT );
1656 KEY( VK_UP, GLUT_KEY_UP );
1657 KEY( VK_RIGHT, GLUT_KEY_RIGHT );
1658 KEY( VK_DOWN, GLUT_KEY_DOWN );
1659 KEY( VK_INSERT, GLUT_KEY_INSERT );
1662 /* The delete key should be treated as an ASCII keypress: */
1663 INVOKE_WCB( *window, KeyboardUp,
1664 ( 127, window->State.MouseX, window->State.MouseY )
1670 #if !TARGET_HOST_WINCE
1674 GetKeyboardState( state );
1676 if( ToAscii( wParam, 0, state, code, 0 ) == 1 )
1679 INVOKE_WCB( *window, KeyboardUp,
1681 window->State.MouseX, window->State.MouseY )
1683 #endif /* !TARGET_HOST_WINCE */
1687 if( keypress != -1 )
1688 INVOKE_WCB( *window, SpecialUp,
1690 window->State.MouseX, window->State.MouseY )
1693 fgState.Modifiers = 0xffffffff;
1700 if( (fgState.KeyRepeat==GLUT_KEY_REPEAT_OFF || window->State.IgnoreKeyRepeat==GL_TRUE) && (HIWORD(lParam) & KF_REPEAT) )
1703 fgState.Modifiers = fghGetWin32Modifiers( );
1704 INVOKE_WCB( *window, Keyboard,
1706 window->State.MouseX, window->State.MouseY )
1708 fgState.Modifiers = 0xffffffff;
1712 case WM_CAPTURECHANGED:
1713 /* User has finished resizing the window, force a redraw */
1714 INVOKE_WCB( *window, Display, ( ) );
1716 /*lRet = DefWindowProc( hWnd, uMsg, wParam, lParam ); */
1719 /* Other messages that I have seen and which are not handled already */
1720 case WM_SETTEXT: /* 0x000c */
1721 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1722 /* Pass it on to "DefWindowProc" to set the window text */
1725 case WM_GETTEXT: /* 0x000d */
1726 /* Ideally we would copy the title of the window into "lParam" */
1727 /* strncpy ( (char *)lParam, "Window Title", wParam );
1728 lRet = ( wParam > 12 ) ? 12 : wParam; */
1729 /* the number of characters copied */
1730 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1733 case WM_GETTEXTLENGTH: /* 0x000e */
1734 /* Ideally we would get the length of the title of the window */
1736 /* the number of characters in "Window Title\0" (see above) */
1739 case WM_ERASEBKGND: /* 0x0014 */
1740 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1743 #if !TARGET_HOST_WINCE
1744 case WM_SYNCPAINT: /* 0x0088 */
1745 /* Another window has moved, need to update this one */
1746 window->State.Redisplay = GL_TRUE;
1747 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1748 /* Help screen says this message must be passed to "DefWindowProc" */
1751 case WM_NCPAINT: /* 0x0085 */
1752 /* Need to update the border of this window */
1753 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1754 /* Pass it on to "DefWindowProc" to repaint a standard border */
1757 case WM_SYSCOMMAND : /* 0x0112 */
1760 * We have received a system command message. Try to act on it.
1761 * The commands are passed in through the "wParam" parameter:
1762 * The least significant digit seems to be which edge of the window
1763 * is being used for a resize event:
1767 * Congratulations and thanks to Richard Rauch for figuring this out..
1769 switch ( wParam & 0xfff0 )
1778 /* User has clicked on the "-" to minimize the window */
1779 /* Turn off the visibility */
1780 window->State.Visible = GL_FALSE ;
1787 case SC_NEXTWINDOW :
1790 case SC_PREVWINDOW :
1794 /* Followed very closely by a WM_CLOSE message */
1818 case SC_SCREENSAVE :
1826 fgWarning( "Unknown wParam type 0x%x", wParam );
1831 #endif /* !TARGET_HOST_WINCE */
1833 /* We need to pass the message on to the operating system as well */
1834 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1838 /* Handle unhandled messages */
1839 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1847 /*** END OF FILE ***/