4 * The windows message processing methods.
\r
6 * Copyright (c) 1999-2000 Pawel W. Olszta. All Rights Reserved.
\r
7 * Written by Pawel W. Olszta, <olszta@sourceforge.net>
\r
8 * Creation date: Fri Dec 3 1999
\r
10 * Permission is hereby granted, free of charge, to any person obtaining a
\r
11 * copy of this software and associated documentation files (the "Software"),
\r
12 * to deal in the Software without restriction, including without limitation
\r
13 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
\r
14 * and/or sell copies of the Software, and to permit persons to whom the
\r
15 * Software is furnished to do so, subject to the following conditions:
\r
17 * The above copyright notice and this permission notice shall be included
\r
18 * in all copies or substantial portions of the Software.
\r
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
\r
21 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
\r
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
\r
23 * PAWEL W. OLSZTA BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
\r
24 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
\r
25 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
28 #include <GL/freeglut.h>
\r
29 #include "freeglut_internal.h"
\r
34 #ifdef HAVE_VFPRINTF
\r
35 # define VFPRINTF(s,f,a) vfprintf((s),(f),(a))
\r
36 #elif defined(HAVE__DOPRNT)
\r
37 # define VFPRINTF(s,f,a) _doprnt((f),(a),(s))
\r
39 # define VFPRINTF(s,f,a)
\r
44 typedef struct GXDisplayProperties GXDisplayProperties;
\r
45 typedef struct GXKeyList GXKeyList;
\r
48 typedef struct GXKeyList (*GXGETDEFAULTKEYS)(int);
\r
49 typedef int (*GXOPENINPUT)();
\r
51 GXGETDEFAULTKEYS GXGetDefaultKeys_ = NULL;
\r
52 GXOPENINPUT GXOpenInput_ = NULL;
\r
54 struct GXKeyList gxKeyList;
\r
56 #endif /* _WIN32_WCE */
\r
59 * Try to get the maximum value allowed for ints, falling back to the minimum
\r
60 * guaranteed by ISO C99 if there is no suitable header.
\r
62 #ifdef HAVE_LIMITS_H
\r
63 # include <limits.h>
\r
66 # define INT_MAX 32767
\r
70 # define MIN(a,b) (((a)<(b)) ? (a) : (b))
\r
74 typedef BOOL (WINAPI *pGetTouchInputInfo)(HTOUCHINPUT,UINT,PTOUCHINPUT,int);
\r
75 typedef BOOL (WINAPI *pCloseTouchInputHandle)(HTOUCHINPUT);
\r
76 static pGetTouchInputInfo fghGetTouchInputInfo = (pGetTouchInputInfo)0xDEADBEEF;
\r
77 static pCloseTouchInputHandle fghCloseTouchInputHandle = (pCloseTouchInputHandle)0xDEADBEEF;
\r
81 * TODO BEFORE THE STABLE RELEASE:
\r
83 * There are some issues concerning window redrawing under X11, and maybe
\r
84 * some events are not handled. The Win32 version lacks some more features,
\r
85 * but seems acceptable for not demanding purposes.
\r
87 * Need to investigate why the X11 version breaks out with an error when
\r
88 * closing a window (using the window manager, not glutDestroyWindow)...
\r
91 /* -- PRIVATE FUNCTIONS ---------------------------------------------------- */
\r
94 * Handle a window configuration change. When no reshape
\r
95 * callback is hooked, the viewport size is updated to
\r
96 * match the new window size.
\r
98 static void fghReshapeWindow ( SFG_Window *window, int width, int height )
\r
100 SFG_Window *current_window = fgStructure.CurrentWindow;
\r
102 freeglut_return_if_fail( window != NULL );
\r
104 #if TARGET_HOST_POSIX_X11
\r
106 XResizeWindow( fgDisplay.Display, window->Window.Handle,
\r
108 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
\r
110 #elif TARGET_HOST_MS_WINDOWS && !defined(_WIN32_WCE)
\r
115 * For windowed mode, get the current position of the
\r
116 * window and resize taking the size of the frame
\r
117 * decorations into account.
\r
120 /* "GetWindowRect" returns the pixel coordinates of the outside of the window */
\r
121 GetWindowRect( window->Window.Handle, &windowRect );
\r
123 /* Create rect in FreeGLUT format, (X,Y) topleft outside window, WxH of client area */
\r
124 windowRect.right = windowRect.left+width;
\r
125 windowRect.bottom = windowRect.top+height;
\r
127 if (window->Parent == NULL)
\r
128 /* get the window rect from this to feed to SetWindowPos, correct for window decorations */
\r
129 fghComputeWindowRectFromClientArea_QueryWindow(window,&windowRect,TRUE);
\r
132 /* correct rect for position client area of parent window
\r
133 * (SetWindowPos input for child windows is in coordinates
\r
134 * relative to the parent's client area).
\r
135 * Child windows don't have decoration, so no need to correct
\r
139 parentRect = fghGetClientArea( window->Parent, FALSE );
\r
140 windowRect.left -= parentRect.left;
\r
141 windowRect.right -= parentRect.left;
\r
142 windowRect.top -= parentRect.top;
\r
143 windowRect.bottom -= parentRect.top;
\r
146 /* Do the actual resizing */
\r
147 SetWindowPos( window->Window.Handle,
\r
149 windowRect.left, windowRect.top,
\r
150 windowRect.right - windowRect.left,
\r
151 windowRect.bottom- windowRect.top,
\r
152 SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOSENDCHANGING |
\r
158 if( FETCH_WCB( *window, Reshape ) )
\r
159 INVOKE_WCB( *window, Reshape, ( width, height ) );
\r
162 fgSetWindow( window );
\r
163 glViewport( 0, 0, width, height );
\r
167 * Force a window redraw. In Windows at least this is only a partial
\r
168 * solution: if the window is increasing in size in either dimension,
\r
169 * the already-drawn part does not get drawn again and things look funny.
\r
170 * But without this we get this bad behaviour whenever we resize the
\r
173 window->State.Redisplay = GL_TRUE;
\r
175 if( window->IsMenu )
\r
176 fgSetWindow( current_window );
\r
180 * Calls a window's redraw method. This is used when
\r
181 * a redraw is forced by the incoming window messages.
\r
183 static void fghRedrawWindow ( SFG_Window *window )
\r
185 SFG_Window *current_window = fgStructure.CurrentWindow;
\r
187 freeglut_return_if_fail( window );
\r
188 freeglut_return_if_fail( FETCH_WCB ( *window, Display ) );
\r
190 window->State.Redisplay = GL_FALSE;
\r
192 freeglut_return_if_fail( window->State.Visible );
\r
194 fgSetWindow( window );
\r
196 if( window->State.NeedToResize )
\r
200 window->State.Width,
\r
201 window->State.Height
\r
204 window->State.NeedToResize = GL_FALSE;
\r
207 INVOKE_WCB( *window, Display, ( ) );
\r
209 fgSetWindow( current_window );
\r
213 * A static helper function to execute display callback for a window
\r
215 static void fghcbDisplayWindow( SFG_Window *window,
\r
216 SFG_Enumerator *enumerator )
\r
218 if( window->State.Redisplay &&
\r
219 window->State.Visible )
\r
221 window->State.Redisplay = GL_FALSE;
\r
223 #if TARGET_HOST_POSIX_X11
\r
224 fghRedrawWindow ( window ) ;
\r
225 #elif TARGET_HOST_MS_WINDOWS
\r
228 window->Window.Handle, NULL, NULL,
\r
229 RDW_NOERASE | RDW_INTERNALPAINT | RDW_INVALIDATE | RDW_UPDATENOW
\r
234 fgEnumSubWindows( window, fghcbDisplayWindow, enumerator );
\r
238 * Make all windows perform a display call
\r
240 static void fghDisplayAll( void )
\r
242 SFG_Enumerator enumerator;
\r
244 enumerator.found = GL_FALSE;
\r
245 enumerator.data = NULL;
\r
247 fgEnumWindows( fghcbDisplayWindow, &enumerator );
\r
251 * Window enumerator callback to check for the joystick polling code
\r
253 static void fghcbCheckJoystickPolls( SFG_Window *window,
\r
254 SFG_Enumerator *enumerator )
\r
256 long int checkTime = fgElapsedTime( );
\r
258 if( window->State.JoystickLastPoll + window->State.JoystickPollRate <=
\r
261 #if !defined(_WIN32_WCE)
\r
262 fgJoystickPollWindow( window );
\r
263 #endif /* !defined(_WIN32_WCE) */
\r
264 window->State.JoystickLastPoll = checkTime;
\r
267 fgEnumSubWindows( window, fghcbCheckJoystickPolls, enumerator );
\r
271 * Check all windows for joystick polling
\r
273 static void fghCheckJoystickPolls( void )
\r
275 SFG_Enumerator enumerator;
\r
277 enumerator.found = GL_FALSE;
\r
278 enumerator.data = NULL;
\r
280 fgEnumWindows( fghcbCheckJoystickPolls, &enumerator );
\r
284 * Check the global timers
\r
286 static void fghCheckTimers( void )
\r
288 long checkTime = fgElapsedTime( );
\r
290 while( fgState.Timers.First )
\r
292 SFG_Timer *timer = fgState.Timers.First;
\r
294 if( timer->TriggerTime > checkTime )
\r
297 fgListRemove( &fgState.Timers, &timer->Node );
\r
298 fgListAppend( &fgState.FreeTimers, &timer->Node );
\r
300 timer->Callback( timer->ID );
\r
305 /* Platform-dependent time in milliseconds, as an unsigned 32-bit integer.
\r
306 * This value wraps every 49.7 days, but integer overflows cancel
\r
307 * when subtracting an initial start time, unless the total time exceeds
\r
308 * 32-bit, where the GLUT API return value is also overflowed.
\r
310 unsigned long fgSystemTime(void) {
\r
311 #if TARGET_HOST_SOLARIS || HAVE_GETTIMEOFDAY
\r
312 struct timeval now;
\r
313 gettimeofday( &now, NULL );
\r
314 return now.tv_usec/1000 + now.tv_sec*1000;
\r
315 #elif TARGET_HOST_MS_WINDOWS
\r
316 # if defined(_WIN32_WCE)
\r
317 return GetTickCount();
\r
319 return timeGetTime();
\r
327 long fgElapsedTime( void )
\r
329 return (long) (fgSystemTime() - fgState.Time);
\r
335 void fgError( const char *fmt, ... )
\r
339 if (fgState.ErrorFunc) {
\r
341 va_start( ap, fmt );
\r
343 /* call user set error handler here */
\r
344 fgState.ErrorFunc(fmt, ap);
\r
350 va_start( ap, fmt );
\r
352 fprintf( stderr, "freeglut ");
\r
353 if( fgState.ProgramName )
\r
354 fprintf( stderr, "(%s): ", fgState.ProgramName );
\r
355 VFPRINTF( stderr, fmt, ap );
\r
356 fprintf( stderr, "\n" );
\r
360 if ( fgState.Initialised )
\r
367 void fgWarning( const char *fmt, ... )
\r
371 if (fgState.WarningFunc) {
\r
373 va_start( ap, fmt );
\r
375 /* call user set warning handler here */
\r
376 fgState.WarningFunc(fmt, ap);
\r
382 va_start( ap, fmt );
\r
384 fprintf( stderr, "freeglut ");
\r
385 if( fgState.ProgramName )
\r
386 fprintf( stderr, "(%s): ", fgState.ProgramName );
\r
387 VFPRINTF( stderr, fmt, ap );
\r
388 fprintf( stderr, "\n" );
\r
396 * Indicates whether Joystick events are being used by ANY window.
\r
398 * The current mechanism is to walk all of the windows and ask if
\r
399 * there is a joystick callback. We have a short-circuit early
\r
400 * return if we find any joystick handler registered.
\r
402 * The real way to do this is to make use of the glutTimer() API
\r
403 * to more cleanly re-implement the joystick API. Then, this code
\r
404 * and all other "joystick timer" code can be yanked.
\r
407 static void fghCheckJoystickCallback( SFG_Window* w, SFG_Enumerator* e)
\r
409 if( FETCH_WCB( *w, Joystick ) )
\r
411 e->found = GL_TRUE;
\r
414 fgEnumSubWindows( w, fghCheckJoystickCallback, e );
\r
416 static int fghHaveJoystick( void )
\r
418 SFG_Enumerator enumerator;
\r
420 enumerator.found = GL_FALSE;
\r
421 enumerator.data = NULL;
\r
422 fgEnumWindows( fghCheckJoystickCallback, &enumerator );
\r
423 return !!enumerator.data;
\r
425 static void fghHavePendingRedisplaysCallback( SFG_Window* w, SFG_Enumerator* e)
\r
427 if( w->State.Redisplay && w->State.Visible )
\r
429 e->found = GL_TRUE;
\r
432 fgEnumSubWindows( w, fghHavePendingRedisplaysCallback, e );
\r
434 static int fghHavePendingRedisplays (void)
\r
436 SFG_Enumerator enumerator;
\r
438 enumerator.found = GL_FALSE;
\r
439 enumerator.data = NULL;
\r
440 fgEnumWindows( fghHavePendingRedisplaysCallback, &enumerator );
\r
441 return !!enumerator.data;
\r
444 * Returns the number of GLUT ticks (milliseconds) till the next timer event.
\r
446 static long fghNextTimer( void )
\r
448 long ret = INT_MAX;
\r
449 SFG_Timer *timer = fgState.Timers.First;
\r
452 ret = timer->TriggerTime - fgElapsedTime();
\r
459 * Does the magic required to relinquish the CPU until something interesting
\r
462 static void fghSleepForEvents( void )
\r
466 if( fgState.IdleCallback || fghHavePendingRedisplays( ) )
\r
469 msec = fghNextTimer( );
\r
470 /* XXX Use GLUT timers for joysticks... */
\r
471 /* XXX Dumb; forces granularity to .01sec */
\r
472 if( fghHaveJoystick( ) && ( msec > 10 ) )
\r
475 #if TARGET_HOST_POSIX_X11
\r
477 * Possibly due to aggressive use of XFlush() and friends,
\r
478 * it is possible to have our socket drained but still have
\r
479 * unprocessed events. (Or, this may just be normal with
\r
480 * X, anyway?) We do non-trivial processing of X events
\r
481 * after the event-reading loop, in any case, so we
\r
482 * need to allow that we may have an empty socket but non-
\r
483 * empty event queue.
\r
485 if( ! XPending( fgDisplay.Display ) )
\r
490 struct timeval wait;
\r
492 socket = ConnectionNumber( fgDisplay.Display );
\r
494 FD_SET( socket, &fdset );
\r
495 wait.tv_sec = msec / 1000;
\r
496 wait.tv_usec = (msec % 1000) * 1000;
\r
497 err = select( socket+1, &fdset, NULL, NULL, &wait );
\r
499 #ifdef HAVE_ERRNO_H
\r
500 if( ( -1 == err ) && ( errno != EINTR ) )
\r
501 fgWarning ( "freeglut select() error: %d", errno );
\r
504 #elif TARGET_HOST_MS_WINDOWS
\r
505 MsgWaitForMultipleObjects( 0, NULL, FALSE, msec, QS_ALLINPUT );
\r
509 #if TARGET_HOST_POSIX_X11
\r
511 * Returns GLUT modifier mask for the state field of an X11 event.
\r
513 int fghGetXModifiers( int state )
\r
517 if( state & ( ShiftMask | LockMask ) )
\r
518 ret |= GLUT_ACTIVE_SHIFT;
\r
519 if( state & ControlMask )
\r
520 ret |= GLUT_ACTIVE_CTRL;
\r
521 if( state & Mod1Mask )
\r
522 ret |= GLUT_ACTIVE_ALT;
\r
529 #if TARGET_HOST_POSIX_X11 && _DEBUG
\r
531 static const char* fghTypeToString( int type )
\r
534 case KeyPress: return "KeyPress";
\r
535 case KeyRelease: return "KeyRelease";
\r
536 case ButtonPress: return "ButtonPress";
\r
537 case ButtonRelease: return "ButtonRelease";
\r
538 case MotionNotify: return "MotionNotify";
\r
539 case EnterNotify: return "EnterNotify";
\r
540 case LeaveNotify: return "LeaveNotify";
\r
541 case FocusIn: return "FocusIn";
\r
542 case FocusOut: return "FocusOut";
\r
543 case KeymapNotify: return "KeymapNotify";
\r
544 case Expose: return "Expose";
\r
545 case GraphicsExpose: return "GraphicsExpose";
\r
546 case NoExpose: return "NoExpose";
\r
547 case VisibilityNotify: return "VisibilityNotify";
\r
548 case CreateNotify: return "CreateNotify";
\r
549 case DestroyNotify: return "DestroyNotify";
\r
550 case UnmapNotify: return "UnmapNotify";
\r
551 case MapNotify: return "MapNotify";
\r
552 case MapRequest: return "MapRequest";
\r
553 case ReparentNotify: return "ReparentNotify";
\r
554 case ConfigureNotify: return "ConfigureNotify";
\r
555 case ConfigureRequest: return "ConfigureRequest";
\r
556 case GravityNotify: return "GravityNotify";
\r
557 case ResizeRequest: return "ResizeRequest";
\r
558 case CirculateNotify: return "CirculateNotify";
\r
559 case CirculateRequest: return "CirculateRequest";
\r
560 case PropertyNotify: return "PropertyNotify";
\r
561 case SelectionClear: return "SelectionClear";
\r
562 case SelectionRequest: return "SelectionRequest";
\r
563 case SelectionNotify: return "SelectionNotify";
\r
564 case ColormapNotify: return "ColormapNotify";
\r
565 case ClientMessage: return "ClientMessage";
\r
566 case MappingNotify: return "MappingNotify";
\r
567 default: return "UNKNOWN";
\r
571 static const char* fghBoolToString( Bool b )
\r
573 return b == False ? "False" : "True";
\r
576 static const char* fghNotifyHintToString( char is_hint )
\r
578 switch( is_hint ) {
\r
579 case NotifyNormal: return "NotifyNormal";
\r
580 case NotifyHint: return "NotifyHint";
\r
581 default: return "UNKNOWN";
\r
585 static const char* fghNotifyModeToString( int mode )
\r
588 case NotifyNormal: return "NotifyNormal";
\r
589 case NotifyGrab: return "NotifyGrab";
\r
590 case NotifyUngrab: return "NotifyUngrab";
\r
591 case NotifyWhileGrabbed: return "NotifyWhileGrabbed";
\r
592 default: return "UNKNOWN";
\r
596 static const char* fghNotifyDetailToString( int detail )
\r
599 case NotifyAncestor: return "NotifyAncestor";
\r
600 case NotifyVirtual: return "NotifyVirtual";
\r
601 case NotifyInferior: return "NotifyInferior";
\r
602 case NotifyNonlinear: return "NotifyNonlinear";
\r
603 case NotifyNonlinearVirtual: return "NotifyNonlinearVirtual";
\r
604 case NotifyPointer: return "NotifyPointer";
\r
605 case NotifyPointerRoot: return "NotifyPointerRoot";
\r
606 case NotifyDetailNone: return "NotifyDetailNone";
\r
607 default: return "UNKNOWN";
\r
611 static const char* fghVisibilityToString( int state ) {
\r
613 case VisibilityUnobscured: return "VisibilityUnobscured";
\r
614 case VisibilityPartiallyObscured: return "VisibilityPartiallyObscured";
\r
615 case VisibilityFullyObscured: return "VisibilityFullyObscured";
\r
616 default: return "UNKNOWN";
\r
620 static const char* fghConfigureDetailToString( int detail )
\r
623 case Above: return "Above";
\r
624 case Below: return "Below";
\r
625 case TopIf: return "TopIf";
\r
626 case BottomIf: return "BottomIf";
\r
627 case Opposite: return "Opposite";
\r
628 default: return "UNKNOWN";
\r
632 static const char* fghPlaceToString( int place )
\r
635 case PlaceOnTop: return "PlaceOnTop";
\r
636 case PlaceOnBottom: return "PlaceOnBottom";
\r
637 default: return "UNKNOWN";
\r
641 static const char* fghMappingRequestToString( int request )
\r
643 switch( request ) {
\r
644 case MappingModifier: return "MappingModifier";
\r
645 case MappingKeyboard: return "MappingKeyboard";
\r
646 case MappingPointer: return "MappingPointer";
\r
647 default: return "UNKNOWN";
\r
651 static const char* fghPropertyStateToString( int state )
\r
654 case PropertyNewValue: return "PropertyNewValue";
\r
655 case PropertyDelete: return "PropertyDelete";
\r
656 default: return "UNKNOWN";
\r
660 static const char* fghColormapStateToString( int state )
\r
663 case ColormapUninstalled: return "ColormapUninstalled";
\r
664 case ColormapInstalled: return "ColormapInstalled";
\r
665 default: return "UNKNOWN";
\r
669 static void fghPrintEvent( XEvent *event )
\r
671 switch( event->type ) {
\r
675 XKeyEvent *e = &event->xkey;
\r
676 fgWarning( "%s: window=0x%x, root=0x%x, subwindow=0x%x, time=%lu, "
\r
677 "(x,y)=(%d,%d), (x_root,y_root)=(%d,%d), state=0x%x, "
\r
678 "keycode=%u, same_screen=%s", fghTypeToString( e->type ),
\r
679 e->window, e->root, e->subwindow, (unsigned long)e->time,
\r
680 e->x, e->y, e->x_root, e->y_root, e->state, e->keycode,
\r
681 fghBoolToString( e->same_screen ) );
\r
686 case ButtonRelease: {
\r
687 XButtonEvent *e = &event->xbutton;
\r
688 fgWarning( "%s: window=0x%x, root=0x%x, subwindow=0x%x, time=%lu, "
\r
689 "(x,y)=(%d,%d), (x_root,y_root)=(%d,%d), state=0x%x, "
\r
690 "button=%u, same_screen=%d", fghTypeToString( e->type ),
\r
691 e->window, e->root, e->subwindow, (unsigned long)e->time,
\r
692 e->x, e->y, e->x_root, e->y_root, e->state, e->button,
\r
693 fghBoolToString( e->same_screen ) );
\r
697 case MotionNotify: {
\r
698 XMotionEvent *e = &event->xmotion;
\r
699 fgWarning( "%s: window=0x%x, root=0x%x, subwindow=0x%x, time=%lu, "
\r
700 "(x,y)=(%d,%d), (x_root,y_root)=(%d,%d), state=0x%x, "
\r
701 "is_hint=%s, same_screen=%d", fghTypeToString( e->type ),
\r
702 e->window, e->root, e->subwindow, (unsigned long)e->time,
\r
703 e->x, e->y, e->x_root, e->y_root, e->state,
\r
704 fghNotifyHintToString( e->is_hint ),
\r
705 fghBoolToString( e->same_screen ) );
\r
710 case LeaveNotify: {
\r
711 XCrossingEvent *e = &event->xcrossing;
\r
712 fgWarning( "%s: window=0x%x, root=0x%x, subwindow=0x%x, time=%lu, "
\r
713 "(x,y)=(%d,%d), mode=%s, detail=%s, same_screen=%d, "
\r
714 "focus=%d, state=0x%x", fghTypeToString( e->type ),
\r
715 e->window, e->root, e->subwindow, (unsigned long)e->time,
\r
716 e->x, e->y, fghNotifyModeToString( e->mode ),
\r
717 fghNotifyDetailToString( e->detail ), (int)e->same_screen,
\r
718 (int)e->focus, e->state );
\r
724 XFocusChangeEvent *e = &event->xfocus;
\r
725 fgWarning( "%s: window=0x%x, mode=%s, detail=%s",
\r
726 fghTypeToString( e->type ), e->window,
\r
727 fghNotifyModeToString( e->mode ),
\r
728 fghNotifyDetailToString( e->detail ) );
\r
732 case KeymapNotify: {
\r
733 XKeymapEvent *e = &event->xkeymap;
\r
734 char buf[32 * 2 + 1];
\r
736 for ( i = 0; i < 32; i++ ) {
\r
737 snprintf( &buf[ i * 2 ], sizeof( buf ) - i * 2,
\r
738 "%02x", e->key_vector[ i ] );
\r
741 fgWarning( "%s: window=0x%x, %s", fghTypeToString( e->type ), e->window,
\r
747 XExposeEvent *e = &event->xexpose;
\r
748 fgWarning( "%s: window=0x%x, (x,y)=(%d,%d), (width,height)=(%d,%d), "
\r
749 "count=%d", fghTypeToString( e->type ), e->window, e->x,
\r
750 e->y, e->width, e->height, e->count );
\r
754 case GraphicsExpose: {
\r
755 XGraphicsExposeEvent *e = &event->xgraphicsexpose;
\r
756 fgWarning( "%s: drawable=0x%x, (x,y)=(%d,%d), (width,height)=(%d,%d), "
\r
757 "count=%d, (major_code,minor_code)=(%d,%d)",
\r
758 fghTypeToString( e->type ), e->drawable, e->x, e->y,
\r
759 e->width, e->height, e->count, e->major_code,
\r
765 XNoExposeEvent *e = &event->xnoexpose;
\r
766 fgWarning( "%s: drawable=0x%x, (major_code,minor_code)=(%d,%d)",
\r
767 fghTypeToString( e->type ), e->drawable, e->major_code,
\r
772 case VisibilityNotify: {
\r
773 XVisibilityEvent *e = &event->xvisibility;
\r
774 fgWarning( "%s: window=0x%x, state=%s", fghTypeToString( e->type ),
\r
775 e->window, fghVisibilityToString( e->state) );
\r
779 case CreateNotify: {
\r
780 XCreateWindowEvent *e = &event->xcreatewindow;
\r
781 fgWarning( "%s: (x,y)=(%d,%d), (width,height)=(%d,%d), border_width=%d, "
\r
782 "window=0x%x, override_redirect=%s",
\r
783 fghTypeToString( e->type ), e->x, e->y, e->width, e->height,
\r
784 e->border_width, e->window,
\r
785 fghBoolToString( e->override_redirect ) );
\r
789 case DestroyNotify: {
\r
790 XDestroyWindowEvent *e = &event->xdestroywindow;
\r
791 fgWarning( "%s: event=0x%x, window=0x%x",
\r
792 fghTypeToString( e->type ), e->event, e->window );
\r
796 case UnmapNotify: {
\r
797 XUnmapEvent *e = &event->xunmap;
\r
798 fgWarning( "%s: event=0x%x, window=0x%x, from_configure=%s",
\r
799 fghTypeToString( e->type ), e->event, e->window,
\r
800 fghBoolToString( e->from_configure ) );
\r
805 XMapEvent *e = &event->xmap;
\r
806 fgWarning( "%s: event=0x%x, window=0x%x, override_redirect=%s",
\r
807 fghTypeToString( e->type ), e->event, e->window,
\r
808 fghBoolToString( e->override_redirect ) );
\r
813 XMapRequestEvent *e = &event->xmaprequest;
\r
814 fgWarning( "%s: parent=0x%x, window=0x%x",
\r
815 fghTypeToString( event->type ), e->parent, e->window );
\r
819 case ReparentNotify: {
\r
820 XReparentEvent *e = &event->xreparent;
\r
821 fgWarning( "%s: event=0x%x, window=0x%x, parent=0x%x, (x,y)=(%d,%d), "
\r
822 "override_redirect=%s", fghTypeToString( e->type ),
\r
823 e->event, e->window, e->parent, e->x, e->y,
\r
824 fghBoolToString( e->override_redirect ) );
\r
828 case ConfigureNotify: {
\r
829 XConfigureEvent *e = &event->xconfigure;
\r
830 fgWarning( "%s: event=0x%x, window=0x%x, (x,y)=(%d,%d), "
\r
831 "(width,height)=(%d,%d), border_width=%d, above=0x%x, "
\r
832 "override_redirect=%s", fghTypeToString( e->type ), e->event,
\r
833 e->window, e->x, e->y, e->width, e->height, e->border_width,
\r
834 e->above, fghBoolToString( e->override_redirect ) );
\r
838 case ConfigureRequest: {
\r
839 XConfigureRequestEvent *e = &event->xconfigurerequest;
\r
840 fgWarning( "%s: parent=0x%x, window=0x%x, (x,y)=(%d,%d), "
\r
841 "(width,height)=(%d,%d), border_width=%d, above=0x%x, "
\r
842 "detail=%s, value_mask=%lx", fghTypeToString( e->type ),
\r
843 e->parent, e->window, e->x, e->y, e->width, e->height,
\r
844 e->border_width, e->above,
\r
845 fghConfigureDetailToString( e->detail ), e->value_mask );
\r
849 case GravityNotify: {
\r
850 XGravityEvent *e = &event->xgravity;
\r
851 fgWarning( "%s: event=0x%x, window=0x%x, (x,y)=(%d,%d)",
\r
852 fghTypeToString( e->type ), e->event, e->window, e->x, e->y );
\r
856 case ResizeRequest: {
\r
857 XResizeRequestEvent *e = &event->xresizerequest;
\r
858 fgWarning( "%s: window=0x%x, (width,height)=(%d,%d)",
\r
859 fghTypeToString( e->type ), e->window, e->width, e->height );
\r
863 case CirculateNotify: {
\r
864 XCirculateEvent *e = &event->xcirculate;
\r
865 fgWarning( "%s: event=0x%x, window=0x%x, place=%s",
\r
866 fghTypeToString( e->type ), e->event, e->window,
\r
867 fghPlaceToString( e->place ) );
\r
871 case CirculateRequest: {
\r
872 XCirculateRequestEvent *e = &event->xcirculaterequest;
\r
873 fgWarning( "%s: parent=0x%x, window=0x%x, place=%s",
\r
874 fghTypeToString( e->type ), e->parent, e->window,
\r
875 fghPlaceToString( e->place ) );
\r
879 case PropertyNotify: {
\r
880 XPropertyEvent *e = &event->xproperty;
\r
881 fgWarning( "%s: window=0x%x, atom=%lu, time=%lu, state=%s",
\r
882 fghTypeToString( e->type ), e->window,
\r
883 (unsigned long)e->atom, (unsigned long)e->time,
\r
884 fghPropertyStateToString( e->state ) );
\r
888 case SelectionClear: {
\r
889 XSelectionClearEvent *e = &event->xselectionclear;
\r
890 fgWarning( "%s: window=0x%x, selection=%lu, time=%lu",
\r
891 fghTypeToString( e->type ), e->window,
\r
892 (unsigned long)e->selection, (unsigned long)e->time );
\r
896 case SelectionRequest: {
\r
897 XSelectionRequestEvent *e = &event->xselectionrequest;
\r
898 fgWarning( "%s: owner=0x%x, requestor=0x%x, selection=0x%x, "
\r
899 "target=0x%x, property=%lu, time=%lu",
\r
900 fghTypeToString( e->type ), e->owner, e->requestor,
\r
901 (unsigned long)e->selection, (unsigned long)e->target,
\r
902 (unsigned long)e->property, (unsigned long)e->time );
\r
906 case SelectionNotify: {
\r
907 XSelectionEvent *e = &event->xselection;
\r
908 fgWarning( "%s: requestor=0x%x, selection=0x%x, target=0x%x, "
\r
909 "property=%lu, time=%lu", fghTypeToString( e->type ),
\r
910 e->requestor, (unsigned long)e->selection,
\r
911 (unsigned long)e->target, (unsigned long)e->property,
\r
912 (unsigned long)e->time );
\r
916 case ColormapNotify: {
\r
917 XColormapEvent *e = &event->xcolormap;
\r
918 fgWarning( "%s: window=0x%x, colormap=%lu, new=%s, state=%s",
\r
919 fghTypeToString( e->type ), e->window,
\r
920 (unsigned long)e->colormap, fghBoolToString( e->new ),
\r
921 fghColormapStateToString( e->state ) );
\r
925 case ClientMessage: {
\r
926 XClientMessageEvent *e = &event->xclient;
\r
929 char* end = buf + sizeof( buf );
\r
931 switch( e->format ) {
\r
933 for ( i = 0; i < 20; i++, p += 3 ) {
\r
934 snprintf( p, end - p, " %02x", e->data.b[ i ] );
\r
938 for ( i = 0; i < 10; i++, p += 5 ) {
\r
939 snprintf( p, end - p, " %04x", e->data.s[ i ] );
\r
943 for ( i = 0; i < 5; i++, p += 9 ) {
\r
944 snprintf( p, end - p, " %08lx", e->data.l[ i ] );
\r
949 fgWarning( "%s: window=0x%x, message_type=%lu, format=%d, data=(%s )",
\r
950 fghTypeToString( e->type ), e->window,
\r
951 (unsigned long)e->message_type, e->format, buf );
\r
955 case MappingNotify: {
\r
956 XMappingEvent *e = &event->xmapping;
\r
957 fgWarning( "%s: window=0x%x, request=%s, first_keycode=%d, count=%d",
\r
958 fghTypeToString( e->type ), e->window,
\r
959 fghMappingRequestToString( e->request ), e->first_keycode,
\r
965 fgWarning( "%s", fghTypeToString( event->type ) );
\r
973 /* -- INTERFACE FUNCTIONS -------------------------------------------------- */
\r
976 * Executes a single iteration in the freeglut processing loop.
\r
978 void FGAPIENTRY glutMainLoopEvent( void )
\r
980 #if TARGET_HOST_POSIX_X11
\r
981 SFG_Window* window;
\r
984 /* This code was repeated constantly, so here it goes into a definition: */
\r
985 #define GETWINDOW(a) \
\r
986 window = fgWindowByHandle( event.a.window ); \
\r
987 if( window == NULL ) \
\r
990 #define GETMOUSE(a) \
\r
991 window->State.MouseX = event.a.x; \
\r
992 window->State.MouseY = event.a.y;
\r
994 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutMainLoopEvent" );
\r
996 while( XPending( fgDisplay.Display ) )
\r
998 XNextEvent( fgDisplay.Display, &event );
\r
1000 fghPrintEvent( &event );
\r
1003 switch( event.type )
\r
1005 case ClientMessage:
\r
1006 if(fgIsSpaceballXEvent(&event)) {
\r
1007 fgSpaceballHandleXEvent(&event);
\r
1010 /* Destroy the window when the WM_DELETE_WINDOW message arrives */
\r
1011 if( (Atom) event.xclient.data.l[ 0 ] == fgDisplay.DeleteWindow )
\r
1013 GETWINDOW( xclient );
\r
1015 fgDestroyWindow ( window );
\r
1017 if( fgState.ActionOnWindowClose == GLUT_ACTION_EXIT )
\r
1019 fgDeinitialize( );
\r
1022 else if( fgState.ActionOnWindowClose == GLUT_ACTION_GLUTMAINLOOP_RETURNS )
\r
1023 fgState.ExecState = GLUT_EXEC_STATE_STOP;
\r
1030 * CreateNotify causes a configure-event so that sub-windows are
\r
1031 * handled compatibly with GLUT. Otherwise, your sub-windows
\r
1032 * (in freeglut only) will not get an initial reshape event,
\r
1033 * which can break things.
\r
1035 * GLUT presumably does this because it generally tries to treat
\r
1036 * sub-windows the same as windows.
\r
1038 case CreateNotify:
\r
1039 case ConfigureNotify:
\r
1041 int width, height;
\r
1042 if( event.type == CreateNotify ) {
\r
1043 GETWINDOW( xcreatewindow );
\r
1044 width = event.xcreatewindow.width;
\r
1045 height = event.xcreatewindow.height;
\r
1047 GETWINDOW( xconfigure );
\r
1048 width = event.xconfigure.width;
\r
1049 height = event.xconfigure.height;
\r
1052 if( ( width != window->State.OldWidth ) ||
\r
1053 ( height != window->State.OldHeight ) )
\r
1055 SFG_Window *current_window = fgStructure.CurrentWindow;
\r
1057 window->State.OldWidth = width;
\r
1058 window->State.OldHeight = height;
\r
1059 if( FETCH_WCB( *window, Reshape ) )
\r
1060 INVOKE_WCB( *window, Reshape, ( width, height ) );
\r
1063 fgSetWindow( window );
\r
1064 glViewport( 0, 0, width, height );
\r
1066 glutPostRedisplay( );
\r
1067 if( window->IsMenu )
\r
1068 fgSetWindow( current_window );
\r
1073 case DestroyNotify:
\r
1075 * This is sent to confirm the XDestroyWindow call.
\r
1077 * XXX WHY is this commented out? Should we re-enable it?
\r
1079 /* fgAddToWindowDestroyList ( window ); */
\r
1084 * We are too dumb to process partial exposes...
\r
1086 * XXX Well, we could do it. However, it seems to only
\r
1087 * XXX be potentially useful for single-buffered (since
\r
1088 * XXX double-buffered does not respect viewport when we
\r
1089 * XXX do a buffer-swap).
\r
1092 if( event.xexpose.count == 0 )
\r
1094 GETWINDOW( xexpose );
\r
1095 window->State.Redisplay = GL_TRUE;
\r
1103 /* We get this when iconifying a window. */
\r
1104 GETWINDOW( xunmap );
\r
1105 INVOKE_WCB( *window, WindowStatus, ( GLUT_HIDDEN ) );
\r
1106 window->State.Visible = GL_FALSE;
\r
1109 case MappingNotify:
\r
1111 * Have the client's keyboard knowledge updated (xlib.ps,
\r
1112 * page 206, says that's a good thing to do)
\r
1114 XRefreshKeyboardMapping( (XMappingEvent *) &event );
\r
1117 case VisibilityNotify:
\r
1120 * Sending this event, the X server can notify us that the window
\r
1121 * has just acquired one of the three possible visibility states:
\r
1122 * VisibilityUnobscured, VisibilityPartiallyObscured or
\r
1123 * VisibilityFullyObscured. Note that we DO NOT receive a
\r
1124 * VisibilityNotify event when iconifying a window, we only get an
\r
1125 * UnmapNotify then.
\r
1127 GETWINDOW( xvisibility );
\r
1128 switch( event.xvisibility.state )
\r
1130 case VisibilityUnobscured:
\r
1131 INVOKE_WCB( *window, WindowStatus, ( GLUT_FULLY_RETAINED ) );
\r
1132 window->State.Visible = GL_TRUE;
\r
1135 case VisibilityPartiallyObscured:
\r
1136 INVOKE_WCB( *window, WindowStatus,
\r
1137 ( GLUT_PARTIALLY_RETAINED ) );
\r
1138 window->State.Visible = GL_TRUE;
\r
1141 case VisibilityFullyObscured:
\r
1142 INVOKE_WCB( *window, WindowStatus, ( GLUT_FULLY_COVERED ) );
\r
1143 window->State.Visible = GL_FALSE;
\r
1147 fgWarning( "Unknown X visibility state: %d",
\r
1148 event.xvisibility.state );
\r
1156 GETWINDOW( xcrossing );
\r
1157 GETMOUSE( xcrossing );
\r
1158 if( ( event.type == LeaveNotify ) && window->IsMenu &&
\r
1159 window->ActiveMenu && window->ActiveMenu->IsActive )
\r
1160 fgUpdateMenuHighlight( window->ActiveMenu );
\r
1162 INVOKE_WCB( *window, Entry, ( ( EnterNotify == event.type ) ?
\r
1167 case MotionNotify:
\r
1169 GETWINDOW( xmotion );
\r
1170 GETMOUSE( xmotion );
\r
1172 if( window->ActiveMenu )
\r
1174 if( window == window->ActiveMenu->ParentWindow )
\r
1176 window->ActiveMenu->Window->State.MouseX =
\r
1177 event.xmotion.x_root - window->ActiveMenu->X;
\r
1178 window->ActiveMenu->Window->State.MouseY =
\r
1179 event.xmotion.y_root - window->ActiveMenu->Y;
\r
1182 fgUpdateMenuHighlight( window->ActiveMenu );
\r
1188 * XXX For more than 5 buttons, just check {event.xmotion.state},
\r
1189 * XXX rather than a host of bit-masks? Or maybe we need to
\r
1190 * XXX track ButtonPress/ButtonRelease events in our own
\r
1193 fgState.Modifiers = fghGetXModifiers( event.xmotion.state );
\r
1194 if ( event.xmotion.state & ( Button1Mask | Button2Mask | Button3Mask | Button4Mask | Button5Mask ) ) {
\r
1195 INVOKE_WCB( *window, Motion, ( event.xmotion.x,
\r
1196 event.xmotion.y ) );
\r
1198 INVOKE_WCB( *window, Passive, ( event.xmotion.x,
\r
1199 event.xmotion.y ) );
\r
1201 fgState.Modifiers = INVALID_MODIFIERS;
\r
1205 case ButtonRelease:
\r
1208 GLboolean pressed = GL_TRUE;
\r
1211 if( event.type == ButtonRelease )
\r
1212 pressed = GL_FALSE ;
\r
1215 * A mouse button has been pressed or released. Traditionally,
\r
1216 * break if the window was found within the freeglut structures.
\r
1218 GETWINDOW( xbutton );
\r
1219 GETMOUSE( xbutton );
\r
1222 * An X button (at least in XFree86) is numbered from 1.
\r
1223 * A GLUT button is numbered from 0.
\r
1224 * Old GLUT passed through buttons other than just the first
\r
1225 * three, though it only gave symbolic names and official
\r
1226 * support to the first three.
\r
1228 button = event.xbutton.button - 1;
\r
1231 * Do not execute the application's mouse callback if a menu
\r
1232 * is hooked to this button. In that case an appropriate
\r
1233 * private call should be generated.
\r
1235 if( fgCheckActiveMenu( window, button, pressed,
\r
1236 event.xbutton.x_root, event.xbutton.y_root ) )
\r
1240 * Check if there is a mouse or mouse wheel callback hooked to the
\r
1243 if( ! FETCH_WCB( *window, Mouse ) &&
\r
1244 ! FETCH_WCB( *window, MouseWheel ) )
\r
1247 fgState.Modifiers = fghGetXModifiers( event.xbutton.state );
\r
1249 /* Finally execute the mouse or mouse wheel callback */
\r
1250 if( ( button < glutDeviceGet ( GLUT_NUM_MOUSE_BUTTONS ) ) || ( ! FETCH_WCB( *window, MouseWheel ) ) )
\r
1251 INVOKE_WCB( *window, Mouse, ( button,
\r
1252 pressed ? GLUT_DOWN : GLUT_UP,
\r
1259 * Map 4 and 5 to wheel zero; EVEN to +1, ODD to -1
\r
1260 * " 6 and 7 " " one; ...
\r
1262 * XXX This *should* be behind some variables/macros,
\r
1263 * XXX since the order and numbering isn't certain
\r
1264 * XXX See XFree86 configuration docs (even back in the
\r
1265 * XXX 3.x days, and especially with 4.x).
\r
1267 * XXX Note that {button} has already been decremented
\r
1268 * XXX in mapping from X button numbering to GLUT.
\r
1270 * XXX Should add support for partial wheel turns as Windows does -- 5/27/11
\r
1272 int wheel_number = (button - glutDeviceGet ( GLUT_NUM_MOUSE_BUTTONS )) / 2;
\r
1273 int direction = -1;
\r
1278 INVOKE_WCB( *window, MouseWheel, ( wheel_number,
\r
1284 fgState.Modifiers = INVALID_MODIFIERS;
\r
1291 FGCBKeyboard keyboard_cb;
\r
1292 FGCBSpecial special_cb;
\r
1294 GETWINDOW( xkey );
\r
1297 /* Detect auto repeated keys, if configured globally or per-window */
\r
1299 if ( fgState.KeyRepeat==GLUT_KEY_REPEAT_OFF || window->State.IgnoreKeyRepeat==GL_TRUE )
\r
1301 if (event.type==KeyRelease)
\r
1304 * Look at X11 keystate to detect repeat mode.
\r
1305 * While X11 says the key is actually held down, we'll ignore KeyRelease/KeyPress pairs.
\r
1309 XQueryKeymap( fgDisplay.Display, keys ); /* Look at X11 keystate to detect repeat mode */
\r
1311 if ( event.xkey.keycode<256 ) /* XQueryKeymap is limited to 256 keycodes */
\r
1313 if ( keys[event.xkey.keycode>>3] & (1<<(event.xkey.keycode%8)) )
\r
1314 window->State.KeyRepeating = GL_TRUE;
\r
1316 window->State.KeyRepeating = GL_FALSE;
\r
1321 window->State.KeyRepeating = GL_FALSE;
\r
1323 /* Cease processing this event if it is auto repeated */
\r
1325 if (window->State.KeyRepeating)
\r
1327 if (event.type == KeyPress) window->State.KeyRepeating = GL_FALSE;
\r
1331 if( event.type == KeyPress )
\r
1333 keyboard_cb = (FGCBKeyboard)( FETCH_WCB( *window, Keyboard ));
\r
1334 special_cb = (FGCBSpecial) ( FETCH_WCB( *window, Special ));
\r
1338 keyboard_cb = (FGCBKeyboard)( FETCH_WCB( *window, KeyboardUp ));
\r
1339 special_cb = (FGCBSpecial) ( FETCH_WCB( *window, SpecialUp ));
\r
1342 /* Is there a keyboard/special callback hooked for this window? */
\r
1343 if( keyboard_cb || special_cb )
\r
1345 XComposeStatus composeStatus;
\r
1346 char asciiCode[ 32 ];
\r
1350 /* Check for the ASCII/KeySym codes associated with the event: */
\r
1351 len = XLookupString( &event.xkey, asciiCode, sizeof(asciiCode),
\r
1352 &keySym, &composeStatus
\r
1355 /* GLUT API tells us to have two separate callbacks... */
\r
1358 /* ...one for the ASCII translateable keypresses... */
\r
1361 fgSetWindow( window );
\r
1362 fgState.Modifiers = fghGetXModifiers( event.xkey.state );
\r
1363 keyboard_cb( asciiCode[ 0 ],
\r
1364 event.xkey.x, event.xkey.y
\r
1366 fgState.Modifiers = INVALID_MODIFIERS;
\r
1374 * ...and one for all the others, which need to be
\r
1375 * translated to GLUT_KEY_Xs...
\r
1379 case XK_F1: special = GLUT_KEY_F1; break;
\r
1380 case XK_F2: special = GLUT_KEY_F2; break;
\r
1381 case XK_F3: special = GLUT_KEY_F3; break;
\r
1382 case XK_F4: special = GLUT_KEY_F4; break;
\r
1383 case XK_F5: special = GLUT_KEY_F5; break;
\r
1384 case XK_F6: special = GLUT_KEY_F6; break;
\r
1385 case XK_F7: special = GLUT_KEY_F7; break;
\r
1386 case XK_F8: special = GLUT_KEY_F8; break;
\r
1387 case XK_F9: special = GLUT_KEY_F9; break;
\r
1388 case XK_F10: special = GLUT_KEY_F10; break;
\r
1389 case XK_F11: special = GLUT_KEY_F11; break;
\r
1390 case XK_F12: special = GLUT_KEY_F12; break;
\r
1393 case XK_Left: special = GLUT_KEY_LEFT; break;
\r
1395 case XK_Right: special = GLUT_KEY_RIGHT; break;
\r
1397 case XK_Up: special = GLUT_KEY_UP; break;
\r
1399 case XK_Down: special = GLUT_KEY_DOWN; break;
\r
1402 case XK_Prior: special = GLUT_KEY_PAGE_UP; break;
\r
1404 case XK_Next: special = GLUT_KEY_PAGE_DOWN; break;
\r
1406 case XK_Home: special = GLUT_KEY_HOME; break;
\r
1408 case XK_End: special = GLUT_KEY_END; break;
\r
1409 case XK_KP_Insert:
\r
1410 case XK_Insert: special = GLUT_KEY_INSERT; break;
\r
1412 case XK_Num_Lock : special = GLUT_KEY_NUM_LOCK; break;
\r
1413 case XK_KP_Begin : special = GLUT_KEY_BEGIN; break;
\r
1414 case XK_KP_Delete: special = GLUT_KEY_DELETE; break;
\r
1416 case XK_Shift_L: special = GLUT_KEY_SHIFT_L; break;
\r
1417 case XK_Shift_R: special = GLUT_KEY_SHIFT_R; break;
\r
1418 case XK_Control_L: special = GLUT_KEY_CTRL_L; break;
\r
1419 case XK_Control_R: special = GLUT_KEY_CTRL_R; break;
\r
1420 case XK_Alt_L: special = GLUT_KEY_ALT_L; break;
\r
1421 case XK_Alt_R: special = GLUT_KEY_ALT_R; break;
\r
1425 * Execute the callback (if one has been specified),
\r
1426 * given that the special code seems to be valid...
\r
1428 if( special_cb && (special != -1) )
\r
1430 fgSetWindow( window );
\r
1431 fgState.Modifiers = fghGetXModifiers( event.xkey.state );
\r
1432 special_cb( special, event.xkey.x, event.xkey.y );
\r
1433 fgState.Modifiers = INVALID_MODIFIERS;
\r
1440 case ReparentNotify:
\r
1441 break; /* XXX Should disable this event */
\r
1444 case GravityNotify:
\r
1448 /* enter handling of Extension Events here */
\r
1449 #ifdef HAVE_X11_EXTENSIONS_XINPUT2_H
\r
1450 fgHandleExtensionEvents( &event );
\r
1456 #elif TARGET_HOST_MS_WINDOWS
\r
1460 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutMainLoopEvent" );
\r
1462 while( PeekMessage( &stMsg, NULL, 0, 0, PM_NOREMOVE ) )
\r
1464 if( GetMessage( &stMsg, NULL, 0, 0 ) == 0 )
\r
1466 if( fgState.ActionOnWindowClose == GLUT_ACTION_EXIT )
\r
1468 fgDeinitialize( );
\r
1471 else if( fgState.ActionOnWindowClose == GLUT_ACTION_GLUTMAINLOOP_RETURNS )
\r
1472 fgState.ExecState = GLUT_EXEC_STATE_STOP;
\r
1477 TranslateMessage( &stMsg );
\r
1478 DispatchMessage( &stMsg );
\r
1482 if( fgState.Timers.First )
\r
1483 fghCheckTimers( );
\r
1484 fghCheckJoystickPolls( );
\r
1487 fgCloseWindows( );
\r
1491 * Enters the freeglut processing loop.
\r
1492 * Stays until the "ExecState" changes to "GLUT_EXEC_STATE_STOP".
\r
1494 void FGAPIENTRY glutMainLoop( void )
\r
1498 #if TARGET_HOST_MS_WINDOWS
\r
1499 SFG_Window *window = (SFG_Window *)fgStructure.Windows.First ;
\r
1502 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutMainLoop" );
\r
1504 #if TARGET_HOST_MS_WINDOWS
\r
1506 * Processing before the main loop: If there is a window which is open and
\r
1507 * which has a visibility callback, call it. I know this is an ugly hack,
\r
1508 * but I'm not sure what else to do about it. Ideally we should leave
\r
1509 * something uninitialized in the create window code and initialize it in
\r
1510 * the main loop, and have that initialization create a "WM_ACTIVATE"
\r
1511 * message. Then we would put the visibility callback code in the
\r
1512 * "case WM_ACTIVATE" block below. - John Fay -- 10/24/02
\r
1516 if ( FETCH_WCB( *window, Visibility ) )
\r
1518 SFG_Window *current_window = fgStructure.CurrentWindow ;
\r
1520 INVOKE_WCB( *window, Visibility, ( window->State.Visible ) );
\r
1521 fgSetWindow( current_window );
\r
1524 window = (SFG_Window *)window->Node.Next ;
\r
1528 fgState.ExecState = GLUT_EXEC_STATE_RUNNING ;
\r
1529 while( fgState.ExecState == GLUT_EXEC_STATE_RUNNING )
\r
1531 SFG_Window *window;
\r
1533 glutMainLoopEvent( );
\r
1535 * Step through the list of windows, seeing if there are any
\r
1536 * that are not menus
\r
1538 for( window = ( SFG_Window * )fgStructure.Windows.First;
\r
1540 window = ( SFG_Window * )window->Node.Next )
\r
1541 if ( ! ( window->IsMenu ) )
\r
1545 fgState.ExecState = GLUT_EXEC_STATE_STOP;
\r
1548 if( fgState.IdleCallback )
\r
1550 if( fgStructure.CurrentWindow &&
\r
1551 fgStructure.CurrentWindow->IsMenu )
\r
1553 fgSetWindow( window );
\r
1554 fgState.IdleCallback( );
\r
1557 fghSleepForEvents( );
\r
1562 * When this loop terminates, destroy the display, state and structure
\r
1563 * of a freeglut session, so that another glutInit() call can happen
\r
1565 * Save the "ActionOnWindowClose" because "fgDeinitialize" resets it.
\r
1567 action = fgState.ActionOnWindowClose;
\r
1568 fgDeinitialize( );
\r
1569 if( action == GLUT_ACTION_EXIT )
\r
1574 * Leaves the freeglut processing loop.
\r
1576 void FGAPIENTRY glutLeaveMainLoop( void )
\r
1578 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutLeaveMainLoop" );
\r
1579 fgState.ExecState = GLUT_EXEC_STATE_STOP ;
\r
1583 #if TARGET_HOST_MS_WINDOWS
\r
1585 * Determine a GLUT modifer mask based on MS-WINDOWS system info.
\r
1587 static int fghGetWin32Modifiers (void)
\r
1590 ( ( ( GetKeyState( VK_LSHIFT ) < 0 ) ||
\r
1591 ( GetKeyState( VK_RSHIFT ) < 0 )) ? GLUT_ACTIVE_SHIFT : 0 ) |
\r
1592 ( ( ( GetKeyState( VK_LCONTROL ) < 0 ) ||
\r
1593 ( GetKeyState( VK_RCONTROL ) < 0 )) ? GLUT_ACTIVE_CTRL : 0 ) |
\r
1594 ( ( ( GetKeyState( VK_LMENU ) < 0 ) ||
\r
1595 ( GetKeyState( VK_RMENU ) < 0 )) ? GLUT_ACTIVE_ALT : 0 );
\r
1599 * The window procedure for handling Win32 events
\r
1601 LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam,
\r
1604 static unsigned char lControl = 0, rControl = 0, lShift = 0,
\r
1605 rShift = 0, lAlt = 0, rAlt = 0;
\r
1607 SFG_Window* window;
\r
1611 FREEGLUT_INTERNAL_ERROR_EXIT_IF_NOT_INITIALISED ( "Event Handler" ) ;
\r
1613 window = fgWindowByHandle( hWnd );
\r
1615 if ( ( window == NULL ) && ( uMsg != WM_CREATE ) )
\r
1616 return DefWindowProc( hWnd, uMsg, wParam, lParam );
\r
1618 /* printf ( "Window %3d message <%04x> %12d %12d\n", window?window->ID:0,
\r
1619 uMsg, wParam, lParam ); */
\r
1623 /* Checking for CTRL, ALT, and SHIFT key positions: Key Down! */
\r
1624 if ( !lControl && GetAsyncKeyState ( VK_LCONTROL ) )
\r
1626 INVOKE_WCB ( *window, Special,
\r
1627 ( GLUT_KEY_CTRL_L, window->State.MouseX, window->State.MouseY )
\r
1633 if ( !rControl && GetAsyncKeyState ( VK_RCONTROL ) )
\r
1635 INVOKE_WCB ( *window, Special,
\r
1636 ( GLUT_KEY_CTRL_R, window->State.MouseX, window->State.MouseY )
\r
1642 if ( !lShift && GetAsyncKeyState ( VK_LSHIFT ) )
\r
1644 INVOKE_WCB ( *window, Special,
\r
1645 ( GLUT_KEY_SHIFT_L, window->State.MouseX, window->State.MouseY )
\r
1651 if ( !rShift && GetAsyncKeyState ( VK_RSHIFT ) )
\r
1653 INVOKE_WCB ( *window, Special,
\r
1654 ( GLUT_KEY_SHIFT_R, window->State.MouseX, window->State.MouseY )
\r
1660 if ( !lAlt && GetAsyncKeyState ( VK_LMENU ) )
\r
1662 INVOKE_WCB ( *window, Special,
\r
1663 ( GLUT_KEY_ALT_L, window->State.MouseX, window->State.MouseY )
\r
1669 if ( !rAlt && GetAsyncKeyState ( VK_RMENU ) )
\r
1671 INVOKE_WCB ( *window, Special,
\r
1672 ( GLUT_KEY_ALT_R, window->State.MouseX, window->State.MouseY )
\r
1678 /* Checking for CTRL, ALT, and SHIFT key positions: Key Up! */
\r
1679 if ( lControl && !GetAsyncKeyState ( VK_LCONTROL ) )
\r
1681 INVOKE_WCB ( *window, SpecialUp,
\r
1682 ( GLUT_KEY_CTRL_L, window->State.MouseX, window->State.MouseY )
\r
1688 if ( rControl && !GetAsyncKeyState ( VK_RCONTROL ) )
\r
1690 INVOKE_WCB ( *window, SpecialUp,
\r
1691 ( GLUT_KEY_CTRL_R, window->State.MouseX, window->State.MouseY )
\r
1697 if ( lShift && !GetAsyncKeyState ( VK_LSHIFT ) )
\r
1699 INVOKE_WCB ( *window, SpecialUp,
\r
1700 ( GLUT_KEY_SHIFT_L, window->State.MouseX, window->State.MouseY )
\r
1706 if ( rShift && !GetAsyncKeyState ( VK_RSHIFT ) )
\r
1708 INVOKE_WCB ( *window, SpecialUp,
\r
1709 ( GLUT_KEY_SHIFT_R, window->State.MouseX, window->State.MouseY )
\r
1715 if ( lAlt && !GetAsyncKeyState ( VK_LMENU ) )
\r
1717 INVOKE_WCB ( *window, SpecialUp,
\r
1718 ( GLUT_KEY_ALT_L, window->State.MouseX, window->State.MouseY )
\r
1724 if ( rAlt && !GetAsyncKeyState ( VK_RMENU ) )
\r
1726 INVOKE_WCB ( *window, SpecialUp,
\r
1727 ( GLUT_KEY_ALT_R, window->State.MouseX, window->State.MouseY )
\r
1737 /* The window structure is passed as the creation structure parameter... */
\r
1738 window = (SFG_Window *) (((LPCREATESTRUCT) lParam)->lpCreateParams);
\r
1739 FREEGLUT_INTERNAL_ERROR_EXIT ( ( window != NULL ), "Cannot create window",
\r
1742 window->Window.Handle = hWnd;
\r
1743 window->Window.Device = GetDC( hWnd );
\r
1744 if( window->IsMenu )
\r
1746 unsigned int current_DisplayMode = fgState.DisplayMode;
\r
1747 fgState.DisplayMode = GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH;
\r
1748 #if !defined(_WIN32_WCE)
\r
1749 fgSetupPixelFormat( window, GL_FALSE, PFD_MAIN_PLANE );
\r
1751 fgState.DisplayMode = current_DisplayMode;
\r
1753 if( fgStructure.MenuContext )
\r
1754 wglMakeCurrent( window->Window.Device,
\r
1755 fgStructure.MenuContext->MContext
\r
1759 fgStructure.MenuContext =
\r
1760 (SFG_MenuContext *)malloc( sizeof(SFG_MenuContext) );
\r
1761 fgStructure.MenuContext->MContext =
\r
1762 wglCreateContext( window->Window.Device );
\r
1765 /* window->Window.Context = wglGetCurrentContext (); */
\r
1766 window->Window.Context = wglCreateContext( window->Window.Device );
\r
1770 #if !defined(_WIN32_WCE)
\r
1771 fgSetupPixelFormat( window, GL_FALSE, PFD_MAIN_PLANE );
\r
1774 if( ! fgState.UseCurrentContext )
\r
1775 window->Window.Context =
\r
1776 wglCreateContext( window->Window.Device );
\r
1779 window->Window.Context = wglGetCurrentContext( );
\r
1780 if( ! window->Window.Context )
\r
1781 window->Window.Context =
\r
1782 wglCreateContext( window->Window.Device );
\r
1785 #if !defined(_WIN32_WCE)
\r
1786 fgNewWGLCreateContext( window );
\r
1790 window->State.NeedToResize = GL_TRUE;
\r
1791 /* if we used CW_USEDEFAULT (thats a negative value) for the size
\r
1792 * of the window, query the window now for the size at which it
\r
1795 if( ( window->State.Width < 0 ) || ( window->State.Height < 0 ) )
\r
1797 SFG_Window *current_window = fgStructure.CurrentWindow;
\r
1799 fgSetWindow( window );
\r
1800 window->State.Width = glutGet( GLUT_WINDOW_WIDTH );
\r
1801 window->State.Height = glutGet( GLUT_WINDOW_HEIGHT );
\r
1802 fgSetWindow( current_window );
\r
1805 ReleaseDC( window->Window.Handle, window->Window.Device );
\r
1807 #if defined(_WIN32_WCE)
\r
1808 /* Take over button handling */
\r
1810 HINSTANCE dxDllLib=LoadLibrary(_T("gx.dll"));
\r
1813 GXGetDefaultKeys_=(GXGETDEFAULTKEYS)GetProcAddress(dxDllLib, _T("?GXGetDefaultKeys@@YA?AUGXKeyList@@H@Z"));
\r
1814 GXOpenInput_=(GXOPENINPUT)GetProcAddress(dxDllLib, _T("?GXOpenInput@@YAHXZ"));
\r
1818 (*GXOpenInput_)();
\r
1819 if(GXGetDefaultKeys_)
\r
1820 gxKeyList = (*GXGetDefaultKeys_)(GX_LANDSCAPEKEYS);
\r
1823 #endif /* defined(_WIN32_WCE) */
\r
1828 * If the window is visible, then it is the user manually resizing it.
\r
1829 * If it is not, then it is the system sending us a dummy resize with
\r
1830 * zero dimensions on a "glutIconifyWindow" call.
\r
1832 if( window->State.Visible )
\r
1834 window->State.NeedToResize = GL_TRUE;
\r
1835 #if defined(_WIN32_WCE)
\r
1836 window->State.Width = HIWORD(lParam);
\r
1837 window->State.Height = LOWORD(lParam);
\r
1839 window->State.Width = LOWORD(lParam);
\r
1840 window->State.Height = HIWORD(lParam);
\r
1841 #endif /* defined(_WIN32_WCE) */
\r
1847 /* printf("WM_SETFOCUS: %p\n", window ); */
\r
1848 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
\r
1849 INVOKE_WCB( *window, Entry, ( GLUT_ENTERED ) );
\r
1852 case WM_KILLFOCUS:
\r
1853 /* printf("WM_KILLFOCUS: %p\n", window ); */
\r
1854 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
\r
1855 INVOKE_WCB( *window, Entry, ( GLUT_LEFT ) );
\r
1857 if( window->IsMenu &&
\r
1858 window->ActiveMenu && window->ActiveMenu->IsActive )
\r
1859 fgUpdateMenuHighlight( window->ActiveMenu );
\r
1865 if (LOWORD(wParam) != WA_INACTIVE)
\r
1867 /* printf("WM_ACTIVATE: fgSetCursor( %p, %d)\n", window,
\r
1868 window->State.Cursor ); */
\r
1869 fgSetCursor( window, window->State.Cursor );
\r
1872 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
\r
1876 case WM_SETCURSOR:
\r
1877 /* printf ( "Cursor event %x %x %x %x\n", window, window->State.Cursor, lParam, wParam ) ; */
\r
1878 if( LOWORD( lParam ) == HTCLIENT )
\r
1879 fgSetCursor ( window, window->State.Cursor ) ;
\r
1881 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
\r
1884 case WM_SHOWWINDOW:
\r
1885 window->State.Visible = GL_TRUE;
\r
1886 window->State.Redisplay = GL_TRUE;
\r
1890 /* Turn on the visibility in case it was turned off somehow */
\r
1891 window->State.Visible = GL_TRUE;
\r
1892 BeginPaint( hWnd, &ps );
\r
1893 fghRedrawWindow( window );
\r
1894 EndPaint( hWnd, &ps );
\r
1898 fgDestroyWindow ( window );
\r
1899 if ( fgState.ActionOnWindowClose != GLUT_ACTION_CONTINUE_EXECUTION )
\r
1900 PostQuitMessage(0);
\r
1905 * The window already got destroyed, so don't bother with it.
\r
1909 case WM_MOUSEMOVE:
\r
1911 #if defined(_WIN32_WCE)
\r
1912 window->State.MouseX = 320-HIWORD( lParam );
\r
1913 window->State.MouseY = LOWORD( lParam );
\r
1915 window->State.MouseX = LOWORD( lParam );
\r
1916 window->State.MouseY = HIWORD( lParam );
\r
1917 #endif /* defined(_WIN32_WCE) */
\r
1918 /* Restrict to [-32768, 32767] to match X11 behaviour */
\r
1919 /* See comment in "freeglut_developer" mailing list 10/4/04 */
\r
1920 if ( window->State.MouseX > 32767 ) window->State.MouseX -= 65536;
\r
1921 if ( window->State.MouseY > 32767 ) window->State.MouseY -= 65536;
\r
1923 if ( window->ActiveMenu )
\r
1925 fgUpdateMenuHighlight( window->ActiveMenu );
\r
1928 SetFocus(window->Window.Handle);
\r
1930 fgState.Modifiers = fghGetWin32Modifiers( );
\r
1932 if( ( wParam & MK_LBUTTON ) ||
\r
1933 ( wParam & MK_MBUTTON ) ||
\r
1934 ( wParam & MK_RBUTTON ) )
\r
1935 INVOKE_WCB( *window, Motion, ( window->State.MouseX,
\r
1936 window->State.MouseY ) );
\r
1938 INVOKE_WCB( *window, Passive, ( window->State.MouseX,
\r
1939 window->State.MouseY ) );
\r
1941 fgState.Modifiers = INVALID_MODIFIERS;
\r
1945 case WM_LBUTTONDOWN:
\r
1946 case WM_MBUTTONDOWN:
\r
1947 case WM_RBUTTONDOWN:
\r
1948 case WM_LBUTTONUP:
\r
1949 case WM_MBUTTONUP:
\r
1950 case WM_RBUTTONUP:
\r
1952 GLboolean pressed = GL_TRUE;
\r
1955 #if defined(_WIN32_WCE)
\r
1956 window->State.MouseX = 320-HIWORD( lParam );
\r
1957 window->State.MouseY = LOWORD( lParam );
\r
1959 window->State.MouseX = LOWORD( lParam );
\r
1960 window->State.MouseY = HIWORD( lParam );
\r
1961 #endif /* defined(_WIN32_WCE) */
\r
1963 /* Restrict to [-32768, 32767] to match X11 behaviour */
\r
1964 /* See comment in "freeglut_developer" mailing list 10/4/04 */
\r
1965 if ( window->State.MouseX > 32767 ) window->State.MouseX -= 65536;
\r
1966 if ( window->State.MouseY > 32767 ) window->State.MouseY -= 65536;
\r
1970 case WM_LBUTTONDOWN:
\r
1971 pressed = GL_TRUE;
\r
1972 button = GLUT_LEFT_BUTTON;
\r
1974 case WM_MBUTTONDOWN:
\r
1975 pressed = GL_TRUE;
\r
1976 button = GLUT_MIDDLE_BUTTON;
\r
1978 case WM_RBUTTONDOWN:
\r
1979 pressed = GL_TRUE;
\r
1980 button = GLUT_RIGHT_BUTTON;
\r
1982 case WM_LBUTTONUP:
\r
1983 pressed = GL_FALSE;
\r
1984 button = GLUT_LEFT_BUTTON;
\r
1986 case WM_MBUTTONUP:
\r
1987 pressed = GL_FALSE;
\r
1988 button = GLUT_MIDDLE_BUTTON;
\r
1990 case WM_RBUTTONUP:
\r
1991 pressed = GL_FALSE;
\r
1992 button = GLUT_RIGHT_BUTTON;
\r
1995 pressed = GL_FALSE;
\r
2000 #if !defined(_WIN32_WCE)
\r
2001 if( GetSystemMetrics( SM_SWAPBUTTON ) )
\r
2003 if( button == GLUT_LEFT_BUTTON )
\r
2004 button = GLUT_RIGHT_BUTTON;
\r
2006 if( button == GLUT_RIGHT_BUTTON )
\r
2007 button = GLUT_LEFT_BUTTON;
\r
2009 #endif /* !defined(_WIN32_WCE) */
\r
2011 if( button == -1 )
\r
2012 return DefWindowProc( hWnd, uMsg, lParam, wParam );
\r
2015 * Do not execute the application's mouse callback if a menu
\r
2016 * is hooked to this button. In that case an appropriate
\r
2017 * private call should be generated.
\r
2019 if( fgCheckActiveMenu( window, button, pressed,
\r
2020 window->State.MouseX, window->State.MouseY ) )
\r
2023 /* Set capture so that the window captures all the mouse messages */
\r
2025 * XXX - Multiple button support: Under X11, the mouse is not released
\r
2026 * XXX - from the window until all buttons have been released, even if the
\r
2027 * XXX - user presses a button in another window. This will take more
\r
2028 * XXX - code changes than I am up to at the moment (10/5/04). The present
\r
2029 * XXX - is a 90 percent solution.
\r
2031 if ( pressed == GL_TRUE )
\r
2032 SetCapture ( window->Window.Handle ) ;
\r
2034 ReleaseCapture () ;
\r
2036 if( ! FETCH_WCB( *window, Mouse ) )
\r
2039 fgSetWindow( window );
\r
2040 fgState.Modifiers = fghGetWin32Modifiers( );
\r
2045 pressed ? GLUT_DOWN : GLUT_UP,
\r
2046 window->State.MouseX,
\r
2047 window->State.MouseY
\r
2051 fgState.Modifiers = INVALID_MODIFIERS;
\r
2056 /* Should be WM_MOUSEWHEEL but my compiler doesn't recognize it */
\r
2058 int wheel_number = LOWORD( wParam );
\r
2059 short ticks = ( short )HIWORD( wParam );
\r
2060 fgState.MouseWheelTicks += ticks;
\r
2063 * XXX Should use WHEEL_DELTA instead of 120
\r
2065 if ( abs ( fgState.MouseWheelTicks ) > 120 )
\r
2067 int direction = ( fgState.MouseWheelTicks > 0 ) ? 1 : -1;
\r
2069 if( ! FETCH_WCB( *window, MouseWheel ) &&
\r
2070 ! FETCH_WCB( *window, Mouse ) )
\r
2073 fgSetWindow( window );
\r
2074 fgState.Modifiers = fghGetWin32Modifiers( );
\r
2077 * XXX Should use WHEEL_DELTA instead of 120
\r
2079 while( abs ( fgState.MouseWheelTicks ) > 120 )
\r
2081 if( FETCH_WCB( *window, MouseWheel ) )
\r
2082 INVOKE_WCB( *window, MouseWheel,
\r
2085 window->State.MouseX,
\r
2086 window->State.MouseY
\r
2089 else /* No mouse wheel, call the mouse button callback twice */
\r
2092 * Map wheel zero to button 3 and 4; +1 to 3, -1 to 4
\r
2093 * " " one +1 to 5, -1 to 6, ...
\r
2095 * XXX The below assumes that you have no more than 3 mouse
\r
2096 * XXX buttons. Sorry.
\r
2098 int button = wheel_number * 2 + 3;
\r
2099 if( direction < 0 )
\r
2101 INVOKE_WCB( *window, Mouse,
\r
2102 ( button, GLUT_DOWN,
\r
2103 window->State.MouseX, window->State.MouseY )
\r
2105 INVOKE_WCB( *window, Mouse,
\r
2106 ( button, GLUT_UP,
\r
2107 window->State.MouseX, window->State.MouseY )
\r
2112 * XXX Should use WHEEL_DELTA instead of 120
\r
2114 fgState.MouseWheelTicks -= 120 * direction;
\r
2117 fgState.Modifiers = INVALID_MODIFIERS;
\r
2122 case WM_SYSKEYDOWN:
\r
2125 int keypress = -1;
\r
2128 if( ( fgState.KeyRepeat==GLUT_KEY_REPEAT_OFF || window->State.IgnoreKeyRepeat==GL_TRUE ) && (HIWORD(lParam) & KF_REPEAT) )
\r
2132 * Remember the current modifiers state. This is done here in order
\r
2133 * to make sure the VK_DELETE keyboard callback is executed properly.
\r
2135 fgState.Modifiers = fghGetWin32Modifiers( );
\r
2137 GetCursorPos( &mouse_pos );
\r
2138 ScreenToClient( window->Window.Handle, &mouse_pos );
\r
2140 window->State.MouseX = mouse_pos.x;
\r
2141 window->State.MouseY = mouse_pos.y;
\r
2143 /* Convert the Win32 keystroke codes to GLUTtish way */
\r
2144 # define KEY(a,b) case a: keypress = b; break;
\r
2148 KEY( VK_F1, GLUT_KEY_F1 );
\r
2149 KEY( VK_F2, GLUT_KEY_F2 );
\r
2150 KEY( VK_F3, GLUT_KEY_F3 );
\r
2151 KEY( VK_F4, GLUT_KEY_F4 );
\r
2152 KEY( VK_F5, GLUT_KEY_F5 );
\r
2153 KEY( VK_F6, GLUT_KEY_F6 );
\r
2154 KEY( VK_F7, GLUT_KEY_F7 );
\r
2155 KEY( VK_F8, GLUT_KEY_F8 );
\r
2156 KEY( VK_F9, GLUT_KEY_F9 );
\r
2157 KEY( VK_F10, GLUT_KEY_F10 );
\r
2158 KEY( VK_F11, GLUT_KEY_F11 );
\r
2159 KEY( VK_F12, GLUT_KEY_F12 );
\r
2160 KEY( VK_PRIOR, GLUT_KEY_PAGE_UP );
\r
2161 KEY( VK_NEXT, GLUT_KEY_PAGE_DOWN );
\r
2162 KEY( VK_HOME, GLUT_KEY_HOME );
\r
2163 KEY( VK_END, GLUT_KEY_END );
\r
2164 KEY( VK_LEFT, GLUT_KEY_LEFT );
\r
2165 KEY( VK_UP, GLUT_KEY_UP );
\r
2166 KEY( VK_RIGHT, GLUT_KEY_RIGHT );
\r
2167 KEY( VK_DOWN, GLUT_KEY_DOWN );
\r
2168 KEY( VK_INSERT, GLUT_KEY_INSERT );
\r
2169 KEY( VK_LCONTROL, GLUT_KEY_CTRL_L );
\r
2170 KEY( VK_RCONTROL, GLUT_KEY_CTRL_R );
\r
2171 KEY( VK_LSHIFT, GLUT_KEY_SHIFT_L );
\r
2172 KEY( VK_RSHIFT, GLUT_KEY_SHIFT_R );
\r
2173 KEY( VK_LMENU, GLUT_KEY_ALT_L );
\r
2174 KEY( VK_RMENU, GLUT_KEY_ALT_R );
\r
2177 /* The delete key should be treated as an ASCII keypress: */
\r
2178 INVOKE_WCB( *window, Keyboard,
\r
2179 ( 127, window->State.MouseX, window->State.MouseY )
\r
2183 #if defined(_WIN32_WCE)
\r
2184 if(!(lParam & 0x40000000)) /* Prevent auto-repeat */
\r
2186 if(wParam==(unsigned)gxKeyList.vkRight)
\r
2187 keypress = GLUT_KEY_RIGHT;
\r
2188 else if(wParam==(unsigned)gxKeyList.vkLeft)
\r
2189 keypress = GLUT_KEY_LEFT;
\r
2190 else if(wParam==(unsigned)gxKeyList.vkUp)
\r
2191 keypress = GLUT_KEY_UP;
\r
2192 else if(wParam==(unsigned)gxKeyList.vkDown)
\r
2193 keypress = GLUT_KEY_DOWN;
\r
2194 else if(wParam==(unsigned)gxKeyList.vkA)
\r
2195 keypress = GLUT_KEY_F1;
\r
2196 else if(wParam==(unsigned)gxKeyList.vkB)
\r
2197 keypress = GLUT_KEY_F2;
\r
2198 else if(wParam==(unsigned)gxKeyList.vkC)
\r
2199 keypress = GLUT_KEY_F3;
\r
2200 else if(wParam==(unsigned)gxKeyList.vkStart)
\r
2201 keypress = GLUT_KEY_F4;
\r
2205 if( keypress != -1 )
\r
2206 INVOKE_WCB( *window, Special,
\r
2208 window->State.MouseX, window->State.MouseY )
\r
2211 fgState.Modifiers = INVALID_MODIFIERS;
\r
2218 int keypress = -1;
\r
2222 * Remember the current modifiers state. This is done here in order
\r
2223 * to make sure the VK_DELETE keyboard callback is executed properly.
\r
2225 fgState.Modifiers = fghGetWin32Modifiers( );
\r
2227 GetCursorPos( &mouse_pos );
\r
2228 ScreenToClient( window->Window.Handle, &mouse_pos );
\r
2230 window->State.MouseX = mouse_pos.x;
\r
2231 window->State.MouseY = mouse_pos.y;
\r
2234 * Convert the Win32 keystroke codes to GLUTtish way.
\r
2235 * "KEY(a,b)" was defined under "WM_KEYDOWN"
\r
2240 KEY( VK_F1, GLUT_KEY_F1 );
\r
2241 KEY( VK_F2, GLUT_KEY_F2 );
\r
2242 KEY( VK_F3, GLUT_KEY_F3 );
\r
2243 KEY( VK_F4, GLUT_KEY_F4 );
\r
2244 KEY( VK_F5, GLUT_KEY_F5 );
\r
2245 KEY( VK_F6, GLUT_KEY_F6 );
\r
2246 KEY( VK_F7, GLUT_KEY_F7 );
\r
2247 KEY( VK_F8, GLUT_KEY_F8 );
\r
2248 KEY( VK_F9, GLUT_KEY_F9 );
\r
2249 KEY( VK_F10, GLUT_KEY_F10 );
\r
2250 KEY( VK_F11, GLUT_KEY_F11 );
\r
2251 KEY( VK_F12, GLUT_KEY_F12 );
\r
2252 KEY( VK_PRIOR, GLUT_KEY_PAGE_UP );
\r
2253 KEY( VK_NEXT, GLUT_KEY_PAGE_DOWN );
\r
2254 KEY( VK_HOME, GLUT_KEY_HOME );
\r
2255 KEY( VK_END, GLUT_KEY_END );
\r
2256 KEY( VK_LEFT, GLUT_KEY_LEFT );
\r
2257 KEY( VK_UP, GLUT_KEY_UP );
\r
2258 KEY( VK_RIGHT, GLUT_KEY_RIGHT );
\r
2259 KEY( VK_DOWN, GLUT_KEY_DOWN );
\r
2260 KEY( VK_INSERT, GLUT_KEY_INSERT );
\r
2261 KEY( VK_LCONTROL, GLUT_KEY_CTRL_L );
\r
2262 KEY( VK_RCONTROL, GLUT_KEY_CTRL_R );
\r
2263 KEY( VK_LSHIFT, GLUT_KEY_SHIFT_L );
\r
2264 KEY( VK_RSHIFT, GLUT_KEY_SHIFT_R );
\r
2265 KEY( VK_LMENU, GLUT_KEY_ALT_L );
\r
2266 KEY( VK_RMENU, GLUT_KEY_ALT_R );
\r
2269 /* The delete key should be treated as an ASCII keypress: */
\r
2270 INVOKE_WCB( *window, KeyboardUp,
\r
2271 ( 127, window->State.MouseX, window->State.MouseY )
\r
2277 #if !defined(_WIN32_WCE)
\r
2278 BYTE state[ 256 ];
\r
2281 GetKeyboardState( state );
\r
2283 if( ToAscii( (UINT)wParam, 0, state, code, 0 ) == 1 )
\r
2286 INVOKE_WCB( *window, KeyboardUp,
\r
2288 window->State.MouseX, window->State.MouseY )
\r
2290 #endif /* !defined(_WIN32_WCE) */
\r
2294 if( keypress != -1 )
\r
2295 INVOKE_WCB( *window, SpecialUp,
\r
2297 window->State.MouseX, window->State.MouseY )
\r
2300 fgState.Modifiers = INVALID_MODIFIERS;
\r
2307 if( (fgState.KeyRepeat==GLUT_KEY_REPEAT_OFF || window->State.IgnoreKeyRepeat==GL_TRUE) && (HIWORD(lParam) & KF_REPEAT) )
\r
2310 fgState.Modifiers = fghGetWin32Modifiers( );
\r
2311 INVOKE_WCB( *window, Keyboard,
\r
2313 window->State.MouseX, window->State.MouseY )
\r
2315 fgState.Modifiers = INVALID_MODIFIERS;
\r
2319 case WM_CAPTURECHANGED:
\r
2320 /* User has finished resizing the window, force a redraw */
\r
2321 INVOKE_WCB( *window, Display, ( ) );
\r
2323 /*lRet = DefWindowProc( hWnd, uMsg, wParam, lParam ); */
\r
2326 /* Other messages that I have seen and which are not handled already */
\r
2327 case WM_SETTEXT: /* 0x000c */
\r
2328 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
\r
2329 /* Pass it on to "DefWindowProc" to set the window text */
\r
2332 case WM_GETTEXT: /* 0x000d */
\r
2333 /* Ideally we would copy the title of the window into "lParam" */
\r
2334 /* strncpy ( (char *)lParam, "Window Title", wParam );
\r
2335 lRet = ( wParam > 12 ) ? 12 : wParam; */
\r
2336 /* the number of characters copied */
\r
2337 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
\r
2340 case WM_GETTEXTLENGTH: /* 0x000e */
\r
2341 /* Ideally we would get the length of the title of the window */
\r
2343 /* the number of characters in "Window Title\0" (see above) */
\r
2346 case WM_ERASEBKGND: /* 0x0014 */
\r
2347 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
\r
2350 #if !defined(_WIN32_WCE)
\r
2351 case WM_SYNCPAINT: /* 0x0088 */
\r
2352 /* Another window has moved, need to update this one */
\r
2353 window->State.Redisplay = GL_TRUE;
\r
2354 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
\r
2355 /* Help screen says this message must be passed to "DefWindowProc" */
\r
2358 case WM_NCPAINT: /* 0x0085 */
\r
2359 /* Need to update the border of this window */
\r
2360 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
\r
2361 /* Pass it on to "DefWindowProc" to repaint a standard border */
\r
2364 case WM_SYSCOMMAND : /* 0x0112 */
\r
2367 * We have received a system command message. Try to act on it.
\r
2368 * The commands are passed in through the "wParam" parameter:
\r
2369 * The least significant digit seems to be which edge of the window
\r
2370 * is being used for a resize event:
\r
2374 * Congratulations and thanks to Richard Rauch for figuring this out..
\r
2376 switch ( wParam & 0xfff0 )
\r
2384 case SC_MINIMIZE :
\r
2385 /* User has clicked on the "-" to minimize the window */
\r
2386 /* Turn off the visibility */
\r
2387 window->State.Visible = GL_FALSE ;
\r
2391 case SC_MAXIMIZE :
\r
2394 case SC_NEXTWINDOW :
\r
2397 case SC_PREVWINDOW :
\r
2401 /* Followed very closely by a WM_CLOSE message */
\r
2410 case SC_MOUSEMENU :
\r
2422 case SC_TASKLIST :
\r
2425 case SC_SCREENSAVE :
\r
2431 #if(WINVER >= 0x0400)
\r
2435 case SC_MONITORPOWER :
\r
2438 case SC_CONTEXTHELP :
\r
2440 #endif /* WINVER >= 0x0400 */
\r
2444 fgWarning( "Unknown wParam type 0x%x", wParam );
\r
2449 #endif /* !defined(_WIN32_WCE) */
\r
2451 /* We need to pass the message on to the operating system as well */
\r
2452 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
\r
2456 /* handle multi-touch messages */
\r
2459 unsigned int numInputs = (unsigned int)wParam;
\r
2460 unsigned int i = 0;
\r
2461 TOUCHINPUT* ti = (TOUCHINPUT*)malloc( sizeof(TOUCHINPUT)*numInputs);
\r
2463 if (fghGetTouchInputInfo == (pGetTouchInputInfo)0xDEADBEEF) {
\r
2464 fghGetTouchInputInfo = (pGetTouchInputInfo)GetProcAddress(GetModuleHandle("user32"),"GetTouchInputInfo");
\r
2465 fghCloseTouchInputHandle = (pCloseTouchInputHandle)GetProcAddress(GetModuleHandle("user32"),"CloseTouchInputHandle");
\r
2468 if (!fghGetTouchInputInfo) {
\r
2469 free( (void*)ti );
\r
2473 if (fghGetTouchInputInfo( (HTOUCHINPUT)lParam, numInputs, ti, sizeof(TOUCHINPUT) )) {
\r
2474 /* Handle each contact point */
\r
2475 for (i = 0; i < numInputs; ++i ) {
\r
2478 tp.x = TOUCH_COORD_TO_PIXEL(ti[i].x);
\r
2479 tp.y = TOUCH_COORD_TO_PIXEL(ti[i].y);
\r
2480 ScreenToClient( hWnd, &tp );
\r
2482 ti[i].dwID = ti[i].dwID * 2;
\r
2484 if (ti[i].dwFlags & TOUCHEVENTF_DOWN) {
\r
2485 INVOKE_WCB( *window, MultiEntry, ( ti[i].dwID, GLUT_ENTERED ) );
\r
2486 INVOKE_WCB( *window, MultiButton, ( ti[i].dwID, tp.x, tp.y, 0, GLUT_DOWN ) );
\r
2487 } else if (ti[i].dwFlags & TOUCHEVENTF_MOVE) {
\r
2488 INVOKE_WCB( *window, MultiMotion, ( ti[i].dwID, tp.x, tp.y ) );
\r
2489 } else if (ti[i].dwFlags & TOUCHEVENTF_UP) {
\r
2490 INVOKE_WCB( *window, MultiButton, ( ti[i].dwID, tp.x, tp.y, 0, GLUT_UP ) );
\r
2491 INVOKE_WCB( *window, MultiEntry, ( ti[i].dwID, GLUT_LEFT ) );
\r
2495 fghCloseTouchInputHandle((HTOUCHINPUT)lParam);
\r
2496 free( (void*)ti );
\r
2497 lRet = 0; /*DefWindowProc( hWnd, uMsg, wParam, lParam );*/
\r
2502 /* Handle unhandled messages */
\r
2503 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
\r
2511 /*** END OF FILE ***/
\r