4 * The windows message processing methods.
6 * Copyright (c) 1999-2000 Pawel W. Olszta. All Rights Reserved.
7 * Written by Pawel W. Olszta, <olszta@sourceforge.net>
8 * Creation date: Fri Dec 3 1999
10 * Permission is hereby granted, free of charge, to any person obtaining a
11 * copy of this software and associated documentation files (the "Software"),
12 * to deal in the Software without restriction, including without limitation
13 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 * and/or sell copies of the Software, and to permit persons to whom the
15 * Software is furnished to do so, subject to the following conditions:
17 * The above copyright notice and this permission notice shall be included
18 * in all copies or substantial portions of the Software.
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23 * PAWEL W. OLSZTA BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
24 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
25 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
33 #include <GL/freeglut.h>
34 #include "freeglut_internal.h"
37 #if TARGET_HOST_UNIX_X11
38 #include <sys/types.h>
43 #elif TARGET_HOST_WIN32
44 #elif TARGET_HOST_WINCE
46 typedef struct GXDisplayProperties GXDisplayProperties;
47 typedef struct GXKeyList GXKeyList;
50 typedef struct GXKeyList (*GXGETDEFAULTKEYS)(int);
51 typedef int (*GXOPENINPUT)();
53 GXGETDEFAULTKEYS GXGetDefaultKeys_ = NULL;
54 GXOPENINPUT GXOpenInput_ = NULL;
56 struct GXKeyList gxKeyList;
61 #define MAX(a,b) (((a)>(b)) ? (a) : (b))
65 #define MIN(a,b) (((a)<(b)) ? (a) : (b))
70 * TODO BEFORE THE STABLE RELEASE:
72 * There are some issues concerning window redrawing under X11, and maybe
73 * some events are not handled. The Win32 version lacks some more features,
74 * but seems acceptable for not demanding purposes.
76 * Need to investigate why the X11 version breaks out with an error when
77 * closing a window (using the window manager, not glutDestroyWindow)...
80 /* -- PRIVATE FUNCTIONS ---------------------------------------------------- */
83 * Handle a window configuration change. When no reshape
84 * callback is hooked, the viewport size is updated to
85 * match the new window size.
87 static void fghReshapeWindow ( SFG_Window *window, int width, int height )
89 SFG_Window *current_window = fgStructure.Window;
91 freeglut_return_if_fail( window != NULL );
94 #if TARGET_HOST_UNIX_X11
96 XResizeWindow( fgDisplay.Display, window->Window.Handle,
98 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
100 #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE
102 #if !TARGET_HOST_WINCE
108 * For windowed mode, get the current position of the
109 * window and resize taking the size of the frame
110 * decorations into account.
113 /* "GetWindowRect" returns the pixel coordinates of the outside of the window */
114 GetWindowRect( window->Window.Handle, &winRect );
120 if ( window->Parent == NULL )
122 if ( ! window->IsMenu && !window->State.IsGameMode )
124 w += GetSystemMetrics( SM_CXSIZEFRAME ) * 2;
125 h += GetSystemMetrics( SM_CYSIZEFRAME ) * 2 +
126 GetSystemMetrics( SM_CYCAPTION );
132 GetWindowRect( window->Parent->Window.Handle, &parentRect );
133 x -= parentRect.left + GetSystemMetrics( SM_CXSIZEFRAME ) * 2;
134 y -= parentRect.top + GetSystemMetrics( SM_CYSIZEFRAME ) * 2 +
135 GetSystemMetrics( SM_CYCAPTION );
139 * SWP_NOACTIVATE Do not activate the window
140 * SWP_NOOWNERZORDER Do not change position in z-order
141 * SWP_NOSENDCHANGING Supress WM_WINDOWPOSCHANGING message
142 * SWP_NOZORDER Retains the current Z order (ignore 2nd param)
145 SetWindowPos( window->Window.Handle,
148 SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOSENDCHANGING |
152 #endif /* TARGET_HOST_WINCE */
155 * XXX Should update {window->State.OldWidth, window->State.OldHeight}
156 * XXX to keep in lockstep with UNIX_X11 code.
158 if( FETCH_WCB( *window, Reshape ) )
159 INVOKE_WCB( *window, Reshape, ( width, height ) );
162 fgSetWindow( window );
163 glViewport( 0, 0, width, height );
169 * Force a window redraw. In Windows at least this is only a partial
170 * solution: if the window is increasing in size in either dimension,
171 * the already-drawn part does not get drawn again and things look funny.
172 * But without this we get this bad behaviour whenever we resize the
175 window->State.Redisplay = GL_TRUE;
178 fgSetWindow( current_window );
182 * Calls a window's redraw method. This is used when
183 * a redraw is forced by the incoming window messages.
185 static void fghRedrawWindow ( SFG_Window *window )
187 SFG_Window *current_window = fgStructure.Window;
189 freeglut_return_if_fail( window );
190 freeglut_return_if_fail( FETCH_WCB ( *window, Display ) );
192 window->State.Redisplay = GL_FALSE;
194 freeglut_return_if_fail( window->State.Visible );
196 fgSetWindow( window );
198 if( window->State.NeedToResize )
206 window->State.NeedToResize = GL_FALSE;
209 INVOKE_WCB( *window, Display, ( ) );
211 fgSetWindow( current_window );
215 * A static helper function to execute display callback for a window
217 static void fghcbDisplayWindow( SFG_Window *window,
218 SFG_Enumerator *enumerator )
220 if( window->State.Redisplay &&
221 window->State.Visible )
223 window->State.Redisplay = GL_FALSE;
225 #if TARGET_HOST_UNIX_X11
226 fghRedrawWindow ( window ) ;
227 #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE
229 window->Window.Handle, NULL, NULL,
230 RDW_NOERASE | RDW_INTERNALPAINT | RDW_INVALIDATE | RDW_UPDATENOW
235 fgEnumSubWindows( window, fghcbDisplayWindow, enumerator );
239 * Make all windows perform a display call
241 static void fghDisplayAll( void )
243 SFG_Enumerator enumerator;
245 enumerator.found = GL_FALSE;
246 enumerator.data = NULL;
248 fgEnumWindows( fghcbDisplayWindow, &enumerator );
252 * Window enumerator callback to check for the joystick polling code
254 static void fghcbCheckJoystickPolls( SFG_Window *window,
255 SFG_Enumerator *enumerator )
257 long int checkTime = fgElapsedTime( );
259 if( window->State.JoystickLastPoll + window->State.JoystickPollRate <=
262 #if !TARGET_HOST_WINCE
263 fgJoystickPollWindow( window );
264 #endif /* !TARGET_HOST_WINCE */
265 window->State.JoystickLastPoll = checkTime;
268 fgEnumSubWindows( window, fghcbCheckJoystickPolls, enumerator );
272 * Check all windows for joystick polling
274 static void fghCheckJoystickPolls( void )
276 SFG_Enumerator enumerator;
278 enumerator.found = GL_FALSE;
279 enumerator.data = NULL;
281 fgEnumWindows( fghcbCheckJoystickPolls, &enumerator );
285 * Check the global timers
287 static void fghCheckTimers( void )
289 long checkTime = fgElapsedTime( );
291 while( fgState.Timers.First )
293 SFG_Timer *timer = fgState.Timers.First;
295 if( timer->TriggerTime > checkTime )
298 fgListRemove( &fgState.Timers, &timer->Node );
299 fgListAppend( &fgState.FreeTimers, &timer->Node );
301 timer->Callback( timer->ID );
308 long fgElapsedTime( void )
310 if ( fgState.Time.Set )
312 #if TARGET_HOST_UNIX_X11
316 gettimeofday( &now, NULL );
318 elapsed = (now.tv_usec - fgState.Time.Value.tv_usec) / 1000;
319 elapsed += (now.tv_sec - fgState.Time.Value.tv_sec) * 1000;
322 #elif TARGET_HOST_WIN32
323 return timeGetTime() - fgState.Time.Value;
324 #elif TARGET_HOST_WINCE
325 return GetTickCount() - fgState.Time.Value;
330 #if TARGET_HOST_UNIX_X11
331 gettimeofday( &fgState.Time.Value, NULL );
332 #elif TARGET_HOST_WIN32
333 fgState.Time.Value = timeGetTime ();
334 #elif TARGET_HOST_WINCE
335 fgState.Time.Value = GetTickCount();
337 fgState.Time.Set = GL_TRUE ;
346 void fgError( const char *fmt, ... )
352 fprintf( stderr, "freeglut ");
353 if( fgState.ProgramName )
354 fprintf (stderr, "(%s): ", fgState.ProgramName);
355 vfprintf( stderr, fmt, ap );
356 fprintf( stderr, "\n" );
360 if ( fgState.Initialised )
366 void fgWarning( const char *fmt, ... )
372 fprintf( stderr, "freeglut ");
373 if( fgState.ProgramName )
374 fprintf( stderr, "(%s): ", fgState.ProgramName );
375 vfprintf( stderr, fmt, ap );
376 fprintf( stderr, "\n" );
382 * Indicates whether Joystick events are being used by ANY window.
384 * The current mechanism is to walk all of the windows and ask if
385 * there is a joystick callback. We have a short-circuit early
386 * return if we find any joystick handler registered.
388 * The real way to do this is to make use of the glutTimer() API
389 * to more cleanly re-implement the joystick API. Then, this code
390 * and all other "joystick timer" code can be yanked.
393 static void fghCheckJoystickCallback( SFG_Window* w, SFG_Enumerator* e)
395 if( FETCH_WCB( *w, Joystick ) )
400 fgEnumSubWindows( w, fghCheckJoystickCallback, e );
402 static int fghHaveJoystick( void )
404 SFG_Enumerator enumerator;
406 enumerator.found = GL_FALSE;
407 enumerator.data = NULL;
408 fgEnumWindows( fghCheckJoystickCallback, &enumerator );
409 return !!enumerator.data;
411 static void fghHavePendingRedisplaysCallback( SFG_Window* w, SFG_Enumerator* e)
413 if( w->State.Redisplay )
418 fgEnumSubWindows( w, fghHavePendingRedisplaysCallback, e );
420 static int fghHavePendingRedisplays (void)
422 SFG_Enumerator enumerator;
424 enumerator.found = GL_FALSE;
425 enumerator.data = NULL;
426 fgEnumWindows( fghHavePendingRedisplaysCallback, &enumerator );
427 return !!enumerator.data;
430 * Returns the number of GLUT ticks (milliseconds) till the next timer event.
432 static long fghNextTimer( void )
435 SFG_Timer *timer = fgState.Timers.First;
438 ret = timer->TriggerTime - fgElapsedTime();
445 * Does the magic required to relinquish the CPU until something interesting
448 static void fghSleepForEvents( void )
452 if( fgState.IdleCallback || fghHavePendingRedisplays( ) )
455 msec = fghNextTimer( );
456 if( fghHaveJoystick( ) ) /* XXX Use GLUT timers for joysticks... */
457 msec = MIN( msec, 10 ); /* XXX Dumb; forces granularity to .01sec */
459 #if TARGET_HOST_UNIX_X11
461 * Possibly due to aggressive use of XFlush() and friends,
462 * it is possible to have our socket drained but still have
463 * unprocessed events. (Or, this may just be normal with
464 * X, anyway?) We do non-trivial processing of X events
465 * after the event-reading loop, in any case, so we
466 * need to allow that we may have an empty socket but non-
469 if( ! XPending( fgDisplay.Display ) )
476 socket = ConnectionNumber( fgDisplay.Display );
478 FD_SET( socket, &fdset );
479 wait.tv_sec = msec / 1000;
480 wait.tv_usec = (msec % 1000) * 1000;
481 err = select( socket+1, &fdset, NULL, NULL, &wait );
484 fgWarning ( "freeglut select() error: %d", errno );
486 #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE
487 MsgWaitForMultipleObjects( 0, NULL, FALSE, msec, QS_ALLEVENTS );
491 #if TARGET_HOST_UNIX_X11
493 * Returns GLUT modifier mask for an XEvent.
495 static int fghGetXModifiers( XEvent *event )
499 if( event->xkey.state & ( ShiftMask | LockMask ) )
500 ret |= GLUT_ACTIVE_SHIFT;
501 if( event->xkey.state & ControlMask )
502 ret |= GLUT_ACTIVE_CTRL;
503 if( event->xkey.state & Mod1Mask )
504 ret |= GLUT_ACTIVE_ALT;
511 /* -- INTERFACE FUNCTIONS -------------------------------------------------- */
514 * Executes a single iteration in the freeglut processing loop.
516 void FGAPIENTRY glutMainLoopEvent( void )
518 #if TARGET_HOST_UNIX_X11
522 /* This code was repeated constantly, so here it goes into a definition: */
523 #define GETWINDOW(a) \
524 window = fgWindowByHandle( event.a.window ); \
525 if( window == NULL ) \
528 #define GETMOUSE(a) \
529 window->State.MouseX = event.a.x; \
530 window->State.MouseY = event.a.y;
532 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutMainLoopEvent" );
534 while( XPending( fgDisplay.Display ) )
536 XNextEvent( fgDisplay.Display, &event );
541 /* Destroy the window when the WM_DELETE_WINDOW message arrives */
542 if( (Atom) event.xclient.data.l[ 0 ] == fgDisplay.DeleteWindow )
544 GETWINDOW( xclient );
546 fgDestroyWindow ( window );
548 if( fgState.ActionOnWindowClose == GLUT_ACTION_EXIT )
553 else if( fgState.ActionOnWindowClose == GLUT_ACTION_GLUTMAINLOOP_RETURNS )
554 fgState.ExecState = GLUT_EXEC_STATE_STOP;
561 * CreateNotify causes a configure-event so that sub-windows are
562 * handled compatibly with GLUT. Otherwise, your sub-windows
563 * (in freeglut only) will not get an initial reshape event,
564 * which can break things.
566 * GLUT presumably does this because it generally tries to treat
567 * sub-windows the same as windows.
569 * XXX Technically, GETWINDOW( xconfigure ) and
570 * XXX {event.xconfigure} may not be legit ways to get at
571 * XXX data for CreateNotify events. In practice, the data
572 * XXX is in a union which is laid out much the same either
573 * XXX way. But if you want to split hairs, this isn't legit,
574 * XXX and we should instead duplicate some code.
577 case ConfigureNotify:
578 GETWINDOW( xconfigure );
580 int width = event.xconfigure.width;
581 int height = event.xconfigure.height;
583 if( ( width != window->State.OldWidth ) ||
584 ( height != window->State.OldHeight ) )
586 window->State.OldWidth = width;
587 window->State.OldHeight = height;
588 if( FETCH_WCB( *window, Reshape ) )
589 INVOKE_WCB( *window, Reshape, ( width, height ) );
592 fgSetWindow( window );
593 glViewport( 0, 0, width, height );
595 glutPostRedisplay( );
602 * This is sent to confirm the XDestroyWindow call.
604 * XXX WHY is this commented out? Should we re-enable it?
606 /* fgAddToWindowDestroyList ( window ); */
611 * We are too dumb to process partial exposes...
613 * XXX Well, we could do it. However, it seems to only
614 * XXX be potentially useful for single-buffered (since
615 * XXX double-buffered does not respect viewport when we
616 * XXX do a buffer-swap).
619 if( event.xexpose.count == 0 )
621 GETWINDOW( xexpose );
622 fgSetWindow( window );
623 glutPostRedisplay( );
630 * If we never do anything with this, can we just not ask to
631 * get these messages?
637 * Have the client's keyboard knowledge updated (xlib.ps,
638 * page 206, says that's a good thing to do)
640 XRefreshKeyboardMapping( (XMappingEvent *) &event );
643 case VisibilityNotify:
645 GETWINDOW( xvisibility );
647 * XXX INVOKE_WCB() does this check for us.
649 if( ! FETCH_WCB( *window, WindowStatus ) )
651 fgSetWindow( window );
654 * Sending this event, the X server can notify us that the window
655 * has just acquired one of the three possible visibility states:
656 * VisibilityUnobscured, VisibilityPartiallyObscured or
657 * VisibilityFullyObscured
659 switch( event.xvisibility.state )
661 case VisibilityUnobscured:
662 INVOKE_WCB( *window, WindowStatus, ( GLUT_FULLY_RETAINED ) );
663 window->State.Visible = GL_TRUE;
666 case VisibilityPartiallyObscured:
667 INVOKE_WCB( *window, WindowStatus,
668 ( GLUT_PARTIALLY_RETAINED ) );
669 window->State.Visible = GL_TRUE;
672 case VisibilityFullyObscured:
673 INVOKE_WCB( *window, WindowStatus, ( GLUT_FULLY_COVERED ) );
674 window->State.Visible = GL_FALSE;
678 fgWarning( "Unknown X visibility state: %d",
679 event.xvisibility.state );
687 GETWINDOW( xcrossing );
688 GETMOUSE( xcrossing );
689 INVOKE_WCB( *window, Entry, ( ( EnterNotify == event.type ) ?
696 GETWINDOW( xmotion );
699 if( window->ActiveMenu )
701 if( window == window->ActiveMenu->ParentWindow )
703 window->ActiveMenu->Window->State.MouseX =
704 event.xmotion.x_root - window->ActiveMenu->X;
705 window->ActiveMenu->Window->State.MouseY =
706 event.xmotion.y_root - window->ActiveMenu->Y;
708 window->ActiveMenu->Window->State.Redisplay = GL_TRUE ;
709 fgSetWindow( window->ActiveMenu->ParentWindow );
715 * XXX For more than 5 buttons, just check {event.xmotion.state},
716 * XXX rather than a host of bit-masks? Or maybe we need to
717 * XXX track ButtonPress/ButtonRelease events in our own
720 #define BUTTON_MASK \
721 ( Button1Mask | Button2Mask | Button3Mask | Button4Mask | Button5Mask )
722 if ( event.xmotion.state & BUTTON_MASK )
723 INVOKE_WCB( *window, Motion, ( event.xmotion.x,
726 INVOKE_WCB( *window, Passive, ( event.xmotion.x,
734 GLboolean pressed = GL_TRUE;
737 if( event.type == ButtonRelease )
741 * A mouse button has been pressed or released. Traditionally,
742 * break if the window was found within the freeglut structures.
744 GETWINDOW( xbutton );
748 * An X button (at least in XFree86) is numbered from 1.
749 * A GLUT button is numbered from 0.
750 * Old GLUT passed through buttons other than just the first
751 * three, though it only gave symbolic names and official
752 * support to the first three.
754 button = event.xbutton.button - 1;
757 * Do not execute the application's mouse callback if a menu
758 * is hooked to this button. In that case an appropriate
759 * private call should be generated.
761 if( fgCheckActiveMenu( window, button, pressed,
762 event.xbutton.x_root, event.xbutton.y_root ) )
766 * Check if there is a mouse or mouse wheel callback hooked to the
769 if( ! FETCH_WCB( *window, Mouse ) &&
770 ! FETCH_WCB( *window, MouseWheel ) )
773 fgState.Modifiers = fghGetXModifiers( &event );
776 * Finally execute the mouse or mouse wheel callback
778 * XXX Use a symbolic constant, *not* "4"! ("3, sire!")
780 if( ( button < 3 ) || ( ! FETCH_WCB( *window, MouseWheel ) ) )
781 INVOKE_WCB( *window, Mouse, ( button,
782 pressed ? GLUT_DOWN : GLUT_UP,
789 * Map 4 and 5 to wheel zero; EVEN to +1, ODD to -1
790 * " 6 and 7 " " one; ...
792 * XXX This *should* be behind some variables/macros,
793 * XXX since the order and numbering isn't certain
794 * XXX See XFree86 configuration docs (even back in the
795 * XXX 3.x days, and especially with 4.x).
797 * XXX Note that {button} has already been decremeted
798 * XXX in mapping from X button numbering to GLUT.
800 int wheel_number = (button - 3) / 2;
806 INVOKE_WCB( *window, MouseWheel, ( wheel_number,
813 /* Trash the modifiers state */
814 fgState.Modifiers = 0xffffffff;
821 FGCBKeyboard keyboard_cb;
822 FGCBSpecial special_cb;
827 /* Detect auto repeated keys, if configured globally or per-window */
829 if ( fgState.KeyRepeat==GLUT_KEY_REPEAT_OFF || window->State.IgnoreKeyRepeat==GL_TRUE )
831 if (event.type==KeyRelease)
834 * Look at X11 keystate to detect repeat mode.
835 * While X11 says the key is actually held down, we'll ignore KeyRelease/KeyPress pairs.
839 XQueryKeymap( fgDisplay.Display, keys ); /* Look at X11 keystate to detect repeat mode */
841 if ( event.xkey.keycode<256 ) /* XQueryKeymap is limited to 256 keycodes */
843 if ( keys[event.xkey.keycode>>3] & (1<<(event.xkey.keycode%8)) )
844 window->State.KeyRepeating = GL_TRUE;
846 window->State.KeyRepeating = GL_FALSE;
851 window->State.KeyRepeating = GL_FALSE;
853 /* Cease processing this event if it is auto repeated */
855 if (window->State.KeyRepeating)
858 if( event.type == KeyPress )
860 keyboard_cb = FETCH_WCB( *window, Keyboard );
861 special_cb = FETCH_WCB( *window, Special );
865 keyboard_cb = FETCH_WCB( *window, KeyboardUp );
866 special_cb = FETCH_WCB( *window, SpecialUp );
869 /* Is there a keyboard/special callback hooked for this window? */
870 if( keyboard_cb || special_cb )
872 XComposeStatus composeStatus;
873 char asciiCode[ 32 ];
877 /* Check for the ASCII/KeySym codes associated with the event: */
878 len = XLookupString( &event.xkey, asciiCode, sizeof(asciiCode),
879 &keySym, &composeStatus
882 /* GLUT API tells us to have two separate callbacks... */
885 /* ...one for the ASCII translateable keypresses... */
888 fgSetWindow( window );
889 fgState.Modifiers = fghGetXModifiers( &event );
890 keyboard_cb( asciiCode[ 0 ],
891 event.xkey.x, event.xkey.y
893 fgState.Modifiers = 0xffffffff;
901 * ...and one for all the others, which need to be
902 * translated to GLUT_KEY_Xs...
906 case XK_F1: special = GLUT_KEY_F1; break;
907 case XK_F2: special = GLUT_KEY_F2; break;
908 case XK_F3: special = GLUT_KEY_F3; break;
909 case XK_F4: special = GLUT_KEY_F4; break;
910 case XK_F5: special = GLUT_KEY_F5; break;
911 case XK_F6: special = GLUT_KEY_F6; break;
912 case XK_F7: special = GLUT_KEY_F7; break;
913 case XK_F8: special = GLUT_KEY_F8; break;
914 case XK_F9: special = GLUT_KEY_F9; break;
915 case XK_F10: special = GLUT_KEY_F10; break;
916 case XK_F11: special = GLUT_KEY_F11; break;
917 case XK_F12: special = GLUT_KEY_F12; break;
919 case XK_Left: special = GLUT_KEY_LEFT; break;
920 case XK_Right: special = GLUT_KEY_RIGHT; break;
921 case XK_Up: special = GLUT_KEY_UP; break;
922 case XK_Down: special = GLUT_KEY_DOWN; break;
925 case XK_Prior: special = GLUT_KEY_PAGE_UP; break;
927 case XK_Next: special = GLUT_KEY_PAGE_DOWN; break;
929 case XK_Home: special = GLUT_KEY_HOME; break;
931 case XK_End: special = GLUT_KEY_END; break;
933 case XK_Insert: special = GLUT_KEY_INSERT; break;
937 * Execute the callback (if one has been specified),
938 * given that the special code seems to be valid...
940 if( special_cb && (special != -1) )
942 fgSetWindow( window );
943 fgState.Modifiers = fghGetXModifiers( &event );
944 special_cb( special, event.xkey.x, event.xkey.y );
945 fgState.Modifiers = 0xffffffff;
953 break; /* XXX Should disable this event */
956 fgWarning ("Unknown X event type: %d", event.type);
961 #elif TARGET_HOST_WIN32 || TARGET_HOST_WINCE
965 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutMainLoopEvent" );
967 while( PeekMessage( &stMsg, NULL, 0, 0, PM_NOREMOVE ) )
969 if( GetMessage( &stMsg, NULL, 0, 0 ) == 0 )
971 if( fgState.ActionOnWindowClose == GLUT_ACTION_EXIT )
976 else if( fgState.ActionOnWindowClose == GLUT_ACTION_GLUTMAINLOOP_RETURNS )
977 fgState.ExecState = GLUT_EXEC_STATE_STOP;
982 TranslateMessage( &stMsg );
983 DispatchMessage( &stMsg );
987 if( fgState.Timers.First )
989 fghCheckJoystickPolls( );
996 * Enters the freeglut processing loop.
997 * Stays until the "ExecState" changes to "GLUT_EXEC_STATE_STOP".
999 void FGAPIENTRY glutMainLoop( void )
1003 #if TARGET_HOST_WIN32 || TARGET_HOST_WINCE
1004 SFG_Window *window = (SFG_Window *)fgStructure.Windows.First ;
1007 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutMainLoop" );
1009 #if TARGET_HOST_WIN32 || TARGET_HOST_WINCE
1011 * Processing before the main loop: If there is a window which is open and
1012 * which has a visibility callback, call it. I know this is an ugly hack,
1013 * but I'm not sure what else to do about it. Ideally we should leave
1014 * something uninitialized in the create window code and initialize it in
1015 * the main loop, and have that initialization create a "WM_ACTIVATE"
1016 * message. Then we would put the visibility callback code in the
1017 * "case WM_ACTIVATE" block below. - John Fay -- 10/24/02
1021 if ( FETCH_WCB( *window, Visibility ) )
1023 SFG_Window *current_window = fgStructure.Window ;
1025 INVOKE_WCB( *window, Visibility, ( window->State.Visible ) );
1026 fgSetWindow( current_window );
1029 window = (SFG_Window *)window->Node.Next ;
1033 fgState.ExecState = GLUT_EXEC_STATE_RUNNING ;
1034 while( fgState.ExecState == GLUT_EXEC_STATE_RUNNING )
1038 glutMainLoopEvent( );
1040 * Step through the list of windows, seeing if there are any
1041 * that are not menus
1043 for( window = ( SFG_Window * )fgStructure.Windows.First;
1045 window = ( SFG_Window * )window->Node.Next )
1046 if ( ! ( window->IsMenu ) )
1050 fgState.ExecState = GLUT_EXEC_STATE_STOP;
1053 if( fgState.IdleCallback )
1054 fgState.IdleCallback( );
1056 fghSleepForEvents( );
1061 * When this loop terminates, destroy the display, state and structure
1062 * of a freeglut session, so that another glutInit() call can happen
1064 * Save the "ActionOnWindowClose" because "fgDeinitialize" resets it.
1066 action = fgState.ActionOnWindowClose;
1068 if( action == GLUT_ACTION_EXIT )
1073 * Leaves the freeglut processing loop.
1075 void FGAPIENTRY glutLeaveMainLoop( void )
1077 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutLeaveMainLoop" );
1078 fgState.ExecState = GLUT_EXEC_STATE_STOP ;
1082 #if TARGET_HOST_WIN32 || TARGET_HOST_WINCE
1084 * Determine a GLUT modifer mask based on MS-WINDOWS system info.
1086 static int fghGetWin32Modifiers (void)
1089 ( ( ( GetKeyState( VK_LSHIFT ) < 0 ) ||
1090 ( GetKeyState( VK_RSHIFT ) < 0 )) ? GLUT_ACTIVE_SHIFT : 0 ) |
1091 ( ( ( GetKeyState( VK_LCONTROL ) < 0 ) ||
1092 ( GetKeyState( VK_RCONTROL ) < 0 )) ? GLUT_ACTIVE_CTRL : 0 ) |
1093 ( ( ( GetKeyState( VK_LMENU ) < 0 ) ||
1094 ( GetKeyState( VK_RMENU ) < 0 )) ? GLUT_ACTIVE_ALT : 0 );
1098 * The window procedure for handling Win32 events
1100 LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam,
1107 FREEGLUT_INTERNAL_ERROR_EXIT_IF_NOT_INITIALISED ( "Event Handler" ) ;
1109 window = fgWindowByHandle( hWnd );
1111 if ( ( window == NULL ) && ( uMsg != WM_CREATE ) )
1112 return DefWindowProc( hWnd, uMsg, wParam, lParam );
1114 /* printf ( "Window %3d message <%04x> %12d %12d\n", window?window->ID:0,
1115 uMsg, wParam, lParam ); */
1119 /* The window structure is passed as the creation structure paramter... */
1120 window = (SFG_Window *) (((LPCREATESTRUCT) lParam)->lpCreateParams);
1121 FREEGLUT_INTERNAL_ERROR_EXIT ( ( window != NULL ), "Cannot create window",
1124 window->Window.Handle = hWnd;
1125 window->Window.Device = GetDC( hWnd );
1126 if( window->IsMenu )
1128 unsigned int current_DisplayMode = fgState.DisplayMode;
1129 fgState.DisplayMode = GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH;
1130 #if !TARGET_HOST_WINCE
1131 fgSetupPixelFormat( window, GL_FALSE, PFD_MAIN_PLANE );
1133 fgState.DisplayMode = current_DisplayMode;
1135 if( fgStructure.MenuContext )
1136 wglMakeCurrent( window->Window.Device,
1137 fgStructure.MenuContext->Context
1141 fgStructure.MenuContext =
1142 (SFG_MenuContext *)malloc( sizeof(SFG_MenuContext) );
1143 fgStructure.MenuContext->Context =
1144 wglCreateContext( window->Window.Device );
1147 /* window->Window.Context = wglGetCurrentContext (); */
1148 window->Window.Context = wglCreateContext( window->Window.Device );
1152 #if !TARGET_HOST_WINCE
1153 fgSetupPixelFormat( window, GL_FALSE, PFD_MAIN_PLANE );
1156 if( ! fgState.UseCurrentContext )
1157 window->Window.Context =
1158 wglCreateContext( window->Window.Device );
1161 window->Window.Context = wglGetCurrentContext( );
1162 if( ! window->Window.Context )
1163 window->Window.Context =
1164 wglCreateContext( window->Window.Device );
1168 window->State.NeedToResize = GL_TRUE;
1169 window->State.Width = fgState.Size.X;
1170 window->State.Height = fgState.Size.Y;
1172 ReleaseDC( window->Window.Handle, window->Window.Device );
1174 #if TARGET_HOST_WINCE
1175 /* Take over button handling */
1177 HINSTANCE dxDllLib=LoadLibrary(_T("gx.dll"));
1180 GXGetDefaultKeys_=(GXGETDEFAULTKEYS)GetProcAddress(dxDllLib, _T("?GXGetDefaultKeys@@YA?AUGXKeyList@@H@Z"));
1181 GXOpenInput_=(GXOPENINPUT)GetProcAddress(dxDllLib, _T("?GXOpenInput@@YAHXZ"));
1186 if(GXGetDefaultKeys_)
1187 gxKeyList = (*GXGetDefaultKeys_)(GX_LANDSCAPEKEYS);
1190 #endif /* TARGET_HOST_WINCE */
1195 * If the window is visible, then it is the user manually resizing it.
1196 * If it is not, then it is the system sending us a dummy resize with
1197 * zero dimensions on a "glutIconifyWindow" call.
1199 if( window->State.Visible )
1201 window->State.NeedToResize = GL_TRUE;
1202 #if TARGET_HOST_WINCE
1203 window->State.Width = HIWORD(lParam);
1204 window->State.Height = LOWORD(lParam);
1206 window->State.Width = LOWORD(lParam);
1207 window->State.Height = HIWORD(lParam);
1208 #endif /* TARGET_HOST_WINCE */
1214 /* printf("WM_SETFOCUS: %p\n", window ); */
1215 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1219 if (LOWORD(wParam) != WA_INACTIVE)
1221 /* glutSetCursor( fgStructure.Window->State.Cursor ); */
1222 /* printf("WM_ACTIVATE: glutSetCursor( %p, %d)\n", window,
1223 window->State.Cursor ); */
1224 glutSetCursor( window->State.Cursor );
1227 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1232 * XXX Why not re-use some common code with the glutSetCursor()
1233 * XXX function (or perhaps invoke glutSetCursor())?
1234 * XXX That is, why are we duplicating code, here, from
1235 * XXX glutSetCursor()? The WIN32 code should be able to just
1236 * XXX call glutSetCursor() instead of defining two macros
1237 * XXX and implementing a nested case in-line.
1240 /* Set the cursor AND change it for this window class. */
1241 #define MAP_CURSOR(a,b) \
1243 SetCursor( LoadCursor( NULL, b ) ); \
1246 /* Nuke the cursor AND change it for this window class. */
1247 #define ZAP_CURSOR(a,b) \
1249 SetCursor( NULL ); \
1252 /* printf ( "Cursor event %x %x %x %x\n", window, window->State.Cursor, lParam, wParam ) ; */
1253 if( LOWORD( lParam ) == HTCLIENT )
1254 switch( window->State.Cursor )
1256 MAP_CURSOR( GLUT_CURSOR_RIGHT_ARROW, IDC_ARROW );
1257 MAP_CURSOR( GLUT_CURSOR_LEFT_ARROW, IDC_ARROW );
1258 MAP_CURSOR( GLUT_CURSOR_INFO, IDC_HELP );
1259 MAP_CURSOR( GLUT_CURSOR_DESTROY, IDC_CROSS );
1260 MAP_CURSOR( GLUT_CURSOR_HELP, IDC_HELP );
1261 MAP_CURSOR( GLUT_CURSOR_CYCLE, IDC_SIZEALL );
1262 MAP_CURSOR( GLUT_CURSOR_SPRAY, IDC_CROSS );
1263 MAP_CURSOR( GLUT_CURSOR_WAIT, IDC_WAIT );
1264 MAP_CURSOR( GLUT_CURSOR_TEXT, IDC_UPARROW );
1265 MAP_CURSOR( GLUT_CURSOR_CROSSHAIR, IDC_CROSS );
1266 /* MAP_CURSOR( GLUT_CURSOR_NONE, IDC_NO ); */
1267 ZAP_CURSOR( GLUT_CURSOR_NONE, NULL );
1270 MAP_CURSOR( GLUT_CURSOR_UP_DOWN, IDC_ARROW );
1273 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1277 window->State.Visible = GL_TRUE;
1278 window->State.Redisplay = GL_TRUE;
1282 /* Turn on the visibility in case it was turned off somehow */
1283 window->State.Visible = GL_TRUE;
1284 BeginPaint( hWnd, &ps );
1285 fghRedrawWindow( window );
1286 EndPaint( hWnd, &ps );
1290 fgDestroyWindow ( window );
1291 if ( fgState.ActionOnWindowClose != GLUT_ACTION_CONTINUE_EXECUTION )
1297 * The window already got destroyed, so don't bother with it.
1303 #if TARGET_HOST_WINCE
1304 window->State.MouseX = 320-HIWORD( lParam );
1305 window->State.MouseY = LOWORD( lParam );
1307 window->State.MouseX = LOWORD( lParam );
1308 window->State.MouseY = HIWORD( lParam );
1309 #endif /* TARGET_HOST_WINCE */
1310 /* Restrict to [-32768, 32767] to match X11 behaviour */
1311 /* See comment in "freeglut_developer" mailing list 10/4/04 */
1312 if ( window->State.MouseX > 32767 ) window->State.MouseX -= 65536;
1313 if ( window->State.MouseY > 32767 ) window->State.MouseY -= 65536;
1315 if ( window->ActiveMenu )
1317 window->State.Redisplay = GL_TRUE;
1318 fgSetWindow ( window->ActiveMenu->ParentWindow );
1322 fgState.Modifiers = fghGetWin32Modifiers( );
1324 if( ( wParam & MK_LBUTTON ) ||
1325 ( wParam & MK_MBUTTON ) ||
1326 ( wParam & MK_RBUTTON ) )
1327 INVOKE_WCB( *window, Motion, ( window->State.MouseX,
1328 window->State.MouseY ) );
1330 INVOKE_WCB( *window, Passive, ( window->State.MouseX,
1331 window->State.MouseY ) );
1333 fgState.Modifiers = 0xffffffff;
1337 case WM_LBUTTONDOWN:
1338 case WM_MBUTTONDOWN:
1339 case WM_RBUTTONDOWN:
1344 GLboolean pressed = GL_TRUE;
1347 #if TARGET_HOST_WINCE
1348 window->State.MouseX = 320-HIWORD( lParam );
1349 window->State.MouseY = LOWORD( lParam );
1351 window->State.MouseX = LOWORD( lParam );
1352 window->State.MouseY = HIWORD( lParam );
1353 #endif /* TARGET_HOST_WINCE */
1355 /* Restrict to [-32768, 32767] to match X11 behaviour */
1356 /* See comment in "freeglut_developer" mailing list 10/4/04 */
1357 if ( window->State.MouseX > 32767 ) window->State.MouseX -= 65536;
1358 if ( window->State.MouseY > 32767 ) window->State.MouseY -= 65536;
1362 case WM_LBUTTONDOWN:
1364 button = GLUT_LEFT_BUTTON;
1366 case WM_MBUTTONDOWN:
1368 button = GLUT_MIDDLE_BUTTON;
1370 case WM_RBUTTONDOWN:
1372 button = GLUT_RIGHT_BUTTON;
1376 button = GLUT_LEFT_BUTTON;
1380 button = GLUT_MIDDLE_BUTTON;
1384 button = GLUT_RIGHT_BUTTON;
1392 #if !TARGET_HOST_WINCE
1393 if( GetSystemMetrics( SM_SWAPBUTTON ) )
1395 if( button == GLUT_LEFT_BUTTON )
1396 button = GLUT_RIGHT_BUTTON;
1398 if( button == GLUT_RIGHT_BUTTON )
1399 button = GLUT_LEFT_BUTTON;
1401 #endif /* !TARGET_HOST_WINCE */
1404 return DefWindowProc( hWnd, uMsg, lParam, wParam );
1407 * Do not execute the application's mouse callback if a menu
1408 * is hooked to this button. In that case an appropriate
1409 * private call should be generated.
1411 if( fgCheckActiveMenu( window, button, pressed,
1412 window->State.MouseX, window->State.MouseY ) )
1415 if( window->Menu[ button ] && pressed )
1417 window->State.Redisplay = GL_TRUE;
1418 fgSetWindow( window );
1419 fgActivateMenu( window, button );
1424 /* Set capture so that the window captures all the mouse messages */
1426 * XXX - Multiple button support: Under X11, the mouse is not released
1427 * XXX - from the window until all buttons have been released, even if the
1428 * XXX - user presses a button in another window. This will take more
1429 * XXX - code changes than I am up to at the moment (10/5/04). The present
1430 * XXX - is a 90 percent solution.
1432 if ( pressed == GL_TRUE )
1433 SetCapture ( window->Window.Handle ) ;
1437 if( ! FETCH_WCB( *window, Mouse ) )
1440 fgSetWindow( window );
1441 fgState.Modifiers = fghGetWin32Modifiers( );
1446 pressed ? GLUT_DOWN : GLUT_UP,
1447 window->State.MouseX,
1448 window->State.MouseY
1452 fgState.Modifiers = 0xffffffff;
1457 /* Should be WM_MOUSEWHEEL but my compiler doesn't recognize it */
1460 * XXX THIS IS SPECULATIVE -- John Fay, 10/2/03
1461 * XXX Should use WHEEL_DELTA instead of 120
1463 int wheel_number = LOWORD( wParam );
1464 short ticks = ( short )HIWORD( wParam ) / 120;
1474 * The mouse cursor has moved. Remember the new mouse cursor's position
1476 /* window->State.MouseX = LOWORD( lParam ); */
1477 /* Need to adjust by window position, */
1478 /* window->State.MouseY = HIWORD( lParam ); */
1479 /* change "lParam" to other parameter */
1481 if( ! FETCH_WCB( *window, MouseWheel ) &&
1482 ! FETCH_WCB( *window, Mouse ) )
1485 fgSetWindow( window );
1486 fgState.Modifiers = fghGetWin32Modifiers( );
1489 if( FETCH_WCB( *window, MouseWheel ) )
1490 INVOKE_WCB( *window, MouseWheel,
1493 window->State.MouseX,
1494 window->State.MouseY
1497 else /* No mouse wheel, call the mouse button callback twice */
1500 * XXX The below assumes that you have no more than 3 mouse
1501 * XXX buttons. Sorry.
1503 int button = wheel_number*2 + 4;
1506 INVOKE_WCB( *window, Mouse,
1507 ( button, GLUT_DOWN,
1508 window->State.MouseX, window->State.MouseY )
1510 INVOKE_WCB( *window, Mouse,
1512 window->State.MouseX, window->State.MouseX )
1516 fgState.Modifiers = 0xffffffff;
1526 if( ( fgState.KeyRepeat==GLUT_KEY_REPEAT_OFF || window->State.IgnoreKeyRepeat==GL_TRUE ) && (HIWORD(lParam) & KF_REPEAT) )
1530 * Remember the current modifiers state. This is done here in order
1531 * to make sure the VK_DELETE keyboard callback is executed properly.
1533 fgState.Modifiers = fghGetWin32Modifiers( );
1535 GetCursorPos( &mouse_pos );
1536 ScreenToClient( window->Window.Handle, &mouse_pos );
1538 window->State.MouseX = mouse_pos.x;
1539 window->State.MouseY = mouse_pos.y;
1541 /* Convert the Win32 keystroke codes to GLUTtish way */
1542 # define KEY(a,b) case a: keypress = b; break;
1546 KEY( VK_F1, GLUT_KEY_F1 );
1547 KEY( VK_F2, GLUT_KEY_F2 );
1548 KEY( VK_F3, GLUT_KEY_F3 );
1549 KEY( VK_F4, GLUT_KEY_F4 );
1550 KEY( VK_F5, GLUT_KEY_F5 );
1551 KEY( VK_F6, GLUT_KEY_F6 );
1552 KEY( VK_F7, GLUT_KEY_F7 );
1553 KEY( VK_F8, GLUT_KEY_F8 );
1554 KEY( VK_F9, GLUT_KEY_F9 );
1555 KEY( VK_F10, GLUT_KEY_F10 );
1556 KEY( VK_F11, GLUT_KEY_F11 );
1557 KEY( VK_F12, GLUT_KEY_F12 );
1558 KEY( VK_PRIOR, GLUT_KEY_PAGE_UP );
1559 KEY( VK_NEXT, GLUT_KEY_PAGE_DOWN );
1560 KEY( VK_HOME, GLUT_KEY_HOME );
1561 KEY( VK_END, GLUT_KEY_END );
1562 KEY( VK_LEFT, GLUT_KEY_LEFT );
1563 KEY( VK_UP, GLUT_KEY_UP );
1564 KEY( VK_RIGHT, GLUT_KEY_RIGHT );
1565 KEY( VK_DOWN, GLUT_KEY_DOWN );
1566 KEY( VK_INSERT, GLUT_KEY_INSERT );
1569 /* The delete key should be treated as an ASCII keypress: */
1570 INVOKE_WCB( *window, Keyboard,
1571 ( 127, window->State.MouseX, window->State.MouseY )
1575 #if TARGET_HOST_WINCE
1576 if(!(lParam & 0x40000000)) /* Prevent auto-repeat */
1578 if(wParam==(unsigned)gxKeyList.vkRight)
1579 keypress = GLUT_KEY_RIGHT;
1580 else if(wParam==(unsigned)gxKeyList.vkLeft)
1581 keypress = GLUT_KEY_LEFT;
1582 else if(wParam==(unsigned)gxKeyList.vkUp)
1583 keypress = GLUT_KEY_UP;
1584 else if(wParam==(unsigned)gxKeyList.vkDown)
1585 keypress = GLUT_KEY_DOWN;
1586 else if(wParam==(unsigned)gxKeyList.vkA)
1587 keypress = GLUT_KEY_F1;
1588 else if(wParam==(unsigned)gxKeyList.vkB)
1589 keypress = GLUT_KEY_F2;
1590 else if(wParam==(unsigned)gxKeyList.vkC)
1591 keypress = GLUT_KEY_F3;
1592 else if(wParam==(unsigned)gxKeyList.vkStart)
1593 keypress = GLUT_KEY_F4;
1597 if( keypress != -1 )
1598 INVOKE_WCB( *window, Special,
1600 window->State.MouseX, window->State.MouseY )
1603 fgState.Modifiers = 0xffffffff;
1614 * Remember the current modifiers state. This is done here in order
1615 * to make sure the VK_DELETE keyboard callback is executed properly.
1617 fgState.Modifiers = fghGetWin32Modifiers( );
1619 GetCursorPos( &mouse_pos );
1620 ScreenToClient( window->Window.Handle, &mouse_pos );
1622 window->State.MouseX = mouse_pos.x;
1623 window->State.MouseY = mouse_pos.y;
1626 * Convert the Win32 keystroke codes to GLUTtish way.
1627 * "KEY(a,b)" was defined under "WM_KEYDOWN"
1632 KEY( VK_F1, GLUT_KEY_F1 );
1633 KEY( VK_F2, GLUT_KEY_F2 );
1634 KEY( VK_F3, GLUT_KEY_F3 );
1635 KEY( VK_F4, GLUT_KEY_F4 );
1636 KEY( VK_F5, GLUT_KEY_F5 );
1637 KEY( VK_F6, GLUT_KEY_F6 );
1638 KEY( VK_F7, GLUT_KEY_F7 );
1639 KEY( VK_F8, GLUT_KEY_F8 );
1640 KEY( VK_F9, GLUT_KEY_F9 );
1641 KEY( VK_F10, GLUT_KEY_F10 );
1642 KEY( VK_F11, GLUT_KEY_F11 );
1643 KEY( VK_F12, GLUT_KEY_F12 );
1644 KEY( VK_PRIOR, GLUT_KEY_PAGE_UP );
1645 KEY( VK_NEXT, GLUT_KEY_PAGE_DOWN );
1646 KEY( VK_HOME, GLUT_KEY_HOME );
1647 KEY( VK_END, GLUT_KEY_END );
1648 KEY( VK_LEFT, GLUT_KEY_LEFT );
1649 KEY( VK_UP, GLUT_KEY_UP );
1650 KEY( VK_RIGHT, GLUT_KEY_RIGHT );
1651 KEY( VK_DOWN, GLUT_KEY_DOWN );
1652 KEY( VK_INSERT, GLUT_KEY_INSERT );
1655 /* The delete key should be treated as an ASCII keypress: */
1656 INVOKE_WCB( *window, KeyboardUp,
1657 ( 127, window->State.MouseX, window->State.MouseY )
1663 #if !TARGET_HOST_WINCE
1667 GetKeyboardState( state );
1669 if( ToAscii( wParam, 0, state, code, 0 ) == 1 )
1672 INVOKE_WCB( *window, KeyboardUp,
1674 window->State.MouseX, window->State.MouseY )
1676 #endif /* !TARGET_HOST_WINCE */
1680 if( keypress != -1 )
1681 INVOKE_WCB( *window, SpecialUp,
1683 window->State.MouseX, window->State.MouseY )
1686 fgState.Modifiers = 0xffffffff;
1693 if( (fgState.KeyRepeat==GLUT_KEY_REPEAT_OFF || window->State.IgnoreKeyRepeat==GL_TRUE) && (HIWORD(lParam) & KF_REPEAT) )
1696 fgState.Modifiers = fghGetWin32Modifiers( );
1697 INVOKE_WCB( *window, Keyboard,
1699 window->State.MouseX, window->State.MouseY )
1701 fgState.Modifiers = 0xffffffff;
1705 case WM_CAPTURECHANGED:
1706 /* User has finished resizing the window, force a redraw */
1707 INVOKE_WCB( *window, Display, ( ) );
1709 /*lRet = DefWindowProc( hWnd, uMsg, wParam, lParam ); */
1712 /* Other messages that I have seen and which are not handled already */
1713 case WM_SETTEXT: /* 0x000c */
1714 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1715 /* Pass it on to "DefWindowProc" to set the window text */
1718 case WM_GETTEXT: /* 0x000d */
1719 /* Ideally we would copy the title of the window into "lParam" */
1720 /* strncpy ( (char *)lParam, "Window Title", wParam );
1721 lRet = ( wParam > 12 ) ? 12 : wParam; */
1722 /* the number of characters copied */
1723 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1726 case WM_GETTEXTLENGTH: /* 0x000e */
1727 /* Ideally we would get the length of the title of the window */
1729 /* the number of characters in "Window Title\0" (see above) */
1732 case WM_ERASEBKGND: /* 0x0014 */
1733 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1736 #if !TARGET_HOST_WINCE
1737 case WM_SYNCPAINT: /* 0x0088 */
1738 /* Another window has moved, need to update this one */
1739 window->State.Redisplay = GL_TRUE;
1740 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1741 /* Help screen says this message must be passed to "DefWindowProc" */
1744 case WM_NCPAINT: /* 0x0085 */
1745 /* Need to update the border of this window */
1746 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1747 /* Pass it on to "DefWindowProc" to repaint a standard border */
1750 case WM_SYSCOMMAND : /* 0x0112 */
1753 * We have received a system command message. Try to act on it.
1754 * The commands are passed in through the "wParam" parameter:
1755 * The least significant digit seems to be which edge of the window
1756 * is being used for a resize event:
1760 * Congratulations and thanks to Richard Rauch for figuring this out..
1762 switch ( wParam & 0xfff0 )
1771 /* User has clicked on the "-" to minimize the window */
1772 /* Turn off the visibility */
1773 window->State.Visible = GL_FALSE ;
1780 case SC_NEXTWINDOW :
1783 case SC_PREVWINDOW :
1787 /* Followed very closely by a WM_CLOSE message */
1811 case SC_SCREENSAVE :
1819 fgWarning( "Unknown wParam type 0x%x", wParam );
1824 #endif /* !TARGET_HOST_WINCE */
1826 /* We need to pass the message on to the operating system as well */
1827 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1831 /* Handle unhandled messages */
1832 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1840 /*** END OF FILE ***/