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
80 extern void fghPlatformReshapeWindow ( SFG_Window *window, int width, int height );
\r
81 extern void fghcbPlatformDisplayWindow ( SFG_Window *window );
\r
82 extern void fghPlatformSleepForEvents( long msec );
\r
83 extern void fghProcessSingleEvent ( void );
\r
87 * TODO BEFORE THE STABLE RELEASE:
\r
89 * There are some issues concerning window redrawing under X11, and maybe
\r
90 * some events are not handled. The Win32 version lacks some more features,
\r
91 * but seems acceptable for not demanding purposes.
\r
93 * Need to investigate why the X11 version breaks out with an error when
\r
94 * closing a window (using the window manager, not glutDestroyWindow)...
\r
97 /* -- PRIVATE FUNCTIONS ---------------------------------------------------- */
\r
100 * Handle a window configuration change. When no reshape
\r
101 * callback is hooked, the viewport size is updated to
\r
102 * match the new window size.
\r
104 #if TARGET_HOST_POSIX_X11
\r
105 static void fghPlatformReshapeWindow ( SFG_Window *window, int width, int height )
\r
107 XResizeWindow( fgDisplay.Display, window->Window.Handle,
\r
109 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
\r
113 static void fghReshapeWindow ( SFG_Window *window, int width, int height )
\r
115 SFG_Window *current_window = fgStructure.CurrentWindow;
\r
117 freeglut_return_if_fail( window != NULL );
\r
119 fghPlatformReshapeWindow ( window, width, height );
\r
121 if( FETCH_WCB( *window, Reshape ) )
\r
122 INVOKE_WCB( *window, Reshape, ( width, height ) );
\r
125 fgSetWindow( window );
\r
126 glViewport( 0, 0, width, height );
\r
130 * Force a window redraw. In Windows at least this is only a partial
\r
131 * solution: if the window is increasing in size in either dimension,
\r
132 * the already-drawn part does not get drawn again and things look funny.
\r
133 * But without this we get this bad behaviour whenever we resize the
\r
136 window->State.Redisplay = GL_TRUE;
\r
138 if( window->IsMenu )
\r
139 fgSetWindow( current_window );
\r
143 * Calls a window's redraw method. This is used when
\r
144 * a redraw is forced by the incoming window messages.
\r
146 static void fghRedrawWindow ( SFG_Window *window )
\r
148 SFG_Window *current_window = fgStructure.CurrentWindow;
\r
150 freeglut_return_if_fail( window );
\r
151 freeglut_return_if_fail( FETCH_WCB ( *window, Display ) );
\r
153 window->State.Redisplay = GL_FALSE;
\r
155 freeglut_return_if_fail( window->State.Visible );
\r
157 fgSetWindow( window );
\r
159 if( window->State.NeedToResize )
\r
163 window->State.Width,
\r
164 window->State.Height
\r
167 window->State.NeedToResize = GL_FALSE;
\r
170 INVOKE_WCB( *window, Display, ( ) );
\r
172 fgSetWindow( current_window );
\r
176 * A static helper function to execute display callback for a window
\r
178 #if TARGET_HOST_POSIX_X11
\r
179 static void fghcbPlatformDisplayWindow ( SFG_Window *window )
\r
181 fghRedrawWindow ( window ) ;
\r
185 static void fghcbDisplayWindow( SFG_Window *window,
\r
186 SFG_Enumerator *enumerator )
\r
188 if( window->State.Redisplay &&
\r
189 window->State.Visible )
\r
191 window->State.Redisplay = GL_FALSE;
\r
192 fghcbPlatformDisplayWindow ( window );
\r
195 fgEnumSubWindows( window, fghcbDisplayWindow, enumerator );
\r
199 * Make all windows perform a display call
\r
201 static void fghDisplayAll( void )
\r
203 SFG_Enumerator enumerator;
\r
205 enumerator.found = GL_FALSE;
\r
206 enumerator.data = NULL;
\r
208 fgEnumWindows( fghcbDisplayWindow, &enumerator );
\r
212 * Window enumerator callback to check for the joystick polling code
\r
214 static void fghcbCheckJoystickPolls( SFG_Window *window,
\r
215 SFG_Enumerator *enumerator )
\r
217 long int checkTime = fgElapsedTime( );
\r
219 if( window->State.JoystickLastPoll + window->State.JoystickPollRate <=
\r
222 #if !defined(_WIN32_WCE)
\r
223 fgJoystickPollWindow( window );
\r
224 #endif /* !defined(_WIN32_WCE) */
\r
225 window->State.JoystickLastPoll = checkTime;
\r
228 fgEnumSubWindows( window, fghcbCheckJoystickPolls, enumerator );
\r
232 * Check all windows for joystick polling
\r
234 static void fghCheckJoystickPolls( void )
\r
236 SFG_Enumerator enumerator;
\r
238 enumerator.found = GL_FALSE;
\r
239 enumerator.data = NULL;
\r
241 fgEnumWindows( fghcbCheckJoystickPolls, &enumerator );
\r
245 * Check the global timers
\r
247 static void fghCheckTimers( void )
\r
249 long checkTime = fgElapsedTime( );
\r
251 while( fgState.Timers.First )
\r
253 SFG_Timer *timer = fgState.Timers.First;
\r
255 if( timer->TriggerTime > checkTime )
\r
258 fgListRemove( &fgState.Timers, &timer->Node );
\r
259 fgListAppend( &fgState.FreeTimers, &timer->Node );
\r
261 timer->Callback( timer->ID );
\r
266 /* Platform-dependent time in milliseconds, as an unsigned 32-bit integer.
\r
267 * This value wraps every 49.7 days, but integer overflows cancel
\r
268 * when subtracting an initial start time, unless the total time exceeds
\r
269 * 32-bit, where the GLUT API return value is also overflowed.
\r
271 unsigned long fgSystemTime(void) {
\r
272 #if TARGET_HOST_SOLARIS || HAVE_GETTIMEOFDAY
\r
273 struct timeval now;
\r
274 gettimeofday( &now, NULL );
\r
275 return now.tv_usec/1000 + now.tv_sec*1000;
\r
276 #elif TARGET_HOST_MS_WINDOWS
\r
277 # if defined(_WIN32_WCE)
\r
278 return GetTickCount();
\r
280 return timeGetTime();
\r
288 long fgElapsedTime( void )
\r
290 return (long) (fgSystemTime() - fgState.Time);
\r
296 void fgError( const char *fmt, ... )
\r
300 if (fgState.ErrorFunc) {
\r
302 va_start( ap, fmt );
\r
304 /* call user set error handler here */
\r
305 fgState.ErrorFunc(fmt, ap);
\r
311 va_start( ap, fmt );
\r
313 fprintf( stderr, "freeglut ");
\r
314 if( fgState.ProgramName )
\r
315 fprintf( stderr, "(%s): ", fgState.ProgramName );
\r
316 VFPRINTF( stderr, fmt, ap );
\r
317 fprintf( stderr, "\n" );
\r
321 if ( fgState.Initialised )
\r
328 void fgWarning( const char *fmt, ... )
\r
332 if (fgState.WarningFunc) {
\r
334 va_start( ap, fmt );
\r
336 /* call user set warning handler here */
\r
337 fgState.WarningFunc(fmt, ap);
\r
343 va_start( ap, fmt );
\r
345 fprintf( stderr, "freeglut ");
\r
346 if( fgState.ProgramName )
\r
347 fprintf( stderr, "(%s): ", fgState.ProgramName );
\r
348 VFPRINTF( stderr, fmt, ap );
\r
349 fprintf( stderr, "\n" );
\r
357 * Indicates whether Joystick events are being used by ANY window.
\r
359 * The current mechanism is to walk all of the windows and ask if
\r
360 * there is a joystick callback. We have a short-circuit early
\r
361 * return if we find any joystick handler registered.
\r
363 * The real way to do this is to make use of the glutTimer() API
\r
364 * to more cleanly re-implement the joystick API. Then, this code
\r
365 * and all other "joystick timer" code can be yanked.
\r
368 static void fghCheckJoystickCallback( SFG_Window* w, SFG_Enumerator* e)
\r
370 if( FETCH_WCB( *w, Joystick ) )
\r
372 e->found = GL_TRUE;
\r
375 fgEnumSubWindows( w, fghCheckJoystickCallback, e );
\r
377 static int fghHaveJoystick( void )
\r
379 SFG_Enumerator enumerator;
\r
381 enumerator.found = GL_FALSE;
\r
382 enumerator.data = NULL;
\r
383 fgEnumWindows( fghCheckJoystickCallback, &enumerator );
\r
384 return !!enumerator.data;
\r
386 static void fghHavePendingRedisplaysCallback( SFG_Window* w, SFG_Enumerator* e)
\r
388 if( w->State.Redisplay && w->State.Visible )
\r
390 e->found = GL_TRUE;
\r
393 fgEnumSubWindows( w, fghHavePendingRedisplaysCallback, e );
\r
395 static int fghHavePendingRedisplays (void)
\r
397 SFG_Enumerator enumerator;
\r
399 enumerator.found = GL_FALSE;
\r
400 enumerator.data = NULL;
\r
401 fgEnumWindows( fghHavePendingRedisplaysCallback, &enumerator );
\r
402 return !!enumerator.data;
\r
405 * Returns the number of GLUT ticks (milliseconds) till the next timer event.
\r
407 static long fghNextTimer( void )
\r
409 long ret = INT_MAX;
\r
410 SFG_Timer *timer = fgState.Timers.First;
\r
413 ret = timer->TriggerTime - fgElapsedTime();
\r
420 * Does the magic required to relinquish the CPU until something interesting
\r
424 #if TARGET_HOST_POSIX_X11
\r
425 static void fghPlatformSleepForEvents( long msec )
\r
428 * Possibly due to aggressive use of XFlush() and friends,
\r
429 * it is possible to have our socket drained but still have
\r
430 * unprocessed events. (Or, this may just be normal with
\r
431 * X, anyway?) We do non-trivial processing of X events
\r
432 * after the event-reading loop, in any case, so we
\r
433 * need to allow that we may have an empty socket but non-
\r
434 * empty event queue.
\r
436 if( ! XPending( fgDisplay.Display ) )
\r
441 struct timeval wait;
\r
443 socket = ConnectionNumber( fgDisplay.Display );
\r
445 FD_SET( socket, &fdset );
\r
446 wait.tv_sec = msec / 1000;
\r
447 wait.tv_usec = (msec % 1000) * 1000;
\r
448 err = select( socket+1, &fdset, NULL, NULL, &wait );
\r
450 #ifdef HAVE_ERRNO_H
\r
451 if( ( -1 == err ) && ( errno != EINTR ) )
\r
452 fgWarning ( "freeglut select() error: %d", errno );
\r
458 static void fghSleepForEvents( void )
\r
462 if( fgState.IdleCallback || fghHavePendingRedisplays( ) )
\r
465 msec = fghNextTimer( );
\r
466 /* XXX Use GLUT timers for joysticks... */
\r
467 /* XXX Dumb; forces granularity to .01sec */
\r
468 if( fghHaveJoystick( ) && ( msec > 10 ) )
\r
471 fghPlatformSleepForEvents ( msec );
\r
474 #if TARGET_HOST_POSIX_X11
\r
476 * Returns GLUT modifier mask for the state field of an X11 event.
\r
478 int fghGetXModifiers( int state )
\r
482 if( state & ( ShiftMask | LockMask ) )
\r
483 ret |= GLUT_ACTIVE_SHIFT;
\r
484 if( state & ControlMask )
\r
485 ret |= GLUT_ACTIVE_CTRL;
\r
486 if( state & Mod1Mask )
\r
487 ret |= GLUT_ACTIVE_ALT;
\r
494 static const char* fghTypeToString( int type )
\r
497 case KeyPress: return "KeyPress";
\r
498 case KeyRelease: return "KeyRelease";
\r
499 case ButtonPress: return "ButtonPress";
\r
500 case ButtonRelease: return "ButtonRelease";
\r
501 case MotionNotify: return "MotionNotify";
\r
502 case EnterNotify: return "EnterNotify";
\r
503 case LeaveNotify: return "LeaveNotify";
\r
504 case FocusIn: return "FocusIn";
\r
505 case FocusOut: return "FocusOut";
\r
506 case KeymapNotify: return "KeymapNotify";
\r
507 case Expose: return "Expose";
\r
508 case GraphicsExpose: return "GraphicsExpose";
\r
509 case NoExpose: return "NoExpose";
\r
510 case VisibilityNotify: return "VisibilityNotify";
\r
511 case CreateNotify: return "CreateNotify";
\r
512 case DestroyNotify: return "DestroyNotify";
\r
513 case UnmapNotify: return "UnmapNotify";
\r
514 case MapNotify: return "MapNotify";
\r
515 case MapRequest: return "MapRequest";
\r
516 case ReparentNotify: return "ReparentNotify";
\r
517 case ConfigureNotify: return "ConfigureNotify";
\r
518 case ConfigureRequest: return "ConfigureRequest";
\r
519 case GravityNotify: return "GravityNotify";
\r
520 case ResizeRequest: return "ResizeRequest";
\r
521 case CirculateNotify: return "CirculateNotify";
\r
522 case CirculateRequest: return "CirculateRequest";
\r
523 case PropertyNotify: return "PropertyNotify";
\r
524 case SelectionClear: return "SelectionClear";
\r
525 case SelectionRequest: return "SelectionRequest";
\r
526 case SelectionNotify: return "SelectionNotify";
\r
527 case ColormapNotify: return "ColormapNotify";
\r
528 case ClientMessage: return "ClientMessage";
\r
529 case MappingNotify: return "MappingNotify";
\r
530 default: return "UNKNOWN";
\r
534 static const char* fghBoolToString( Bool b )
\r
536 return b == False ? "False" : "True";
\r
539 static const char* fghNotifyHintToString( char is_hint )
\r
541 switch( is_hint ) {
\r
542 case NotifyNormal: return "NotifyNormal";
\r
543 case NotifyHint: return "NotifyHint";
\r
544 default: return "UNKNOWN";
\r
548 static const char* fghNotifyModeToString( int mode )
\r
551 case NotifyNormal: return "NotifyNormal";
\r
552 case NotifyGrab: return "NotifyGrab";
\r
553 case NotifyUngrab: return "NotifyUngrab";
\r
554 case NotifyWhileGrabbed: return "NotifyWhileGrabbed";
\r
555 default: return "UNKNOWN";
\r
559 static const char* fghNotifyDetailToString( int detail )
\r
562 case NotifyAncestor: return "NotifyAncestor";
\r
563 case NotifyVirtual: return "NotifyVirtual";
\r
564 case NotifyInferior: return "NotifyInferior";
\r
565 case NotifyNonlinear: return "NotifyNonlinear";
\r
566 case NotifyNonlinearVirtual: return "NotifyNonlinearVirtual";
\r
567 case NotifyPointer: return "NotifyPointer";
\r
568 case NotifyPointerRoot: return "NotifyPointerRoot";
\r
569 case NotifyDetailNone: return "NotifyDetailNone";
\r
570 default: return "UNKNOWN";
\r
574 static const char* fghVisibilityToString( int state ) {
\r
576 case VisibilityUnobscured: return "VisibilityUnobscured";
\r
577 case VisibilityPartiallyObscured: return "VisibilityPartiallyObscured";
\r
578 case VisibilityFullyObscured: return "VisibilityFullyObscured";
\r
579 default: return "UNKNOWN";
\r
583 static const char* fghConfigureDetailToString( int detail )
\r
586 case Above: return "Above";
\r
587 case Below: return "Below";
\r
588 case TopIf: return "TopIf";
\r
589 case BottomIf: return "BottomIf";
\r
590 case Opposite: return "Opposite";
\r
591 default: return "UNKNOWN";
\r
595 static const char* fghPlaceToString( int place )
\r
598 case PlaceOnTop: return "PlaceOnTop";
\r
599 case PlaceOnBottom: return "PlaceOnBottom";
\r
600 default: return "UNKNOWN";
\r
604 static const char* fghMappingRequestToString( int request )
\r
606 switch( request ) {
\r
607 case MappingModifier: return "MappingModifier";
\r
608 case MappingKeyboard: return "MappingKeyboard";
\r
609 case MappingPointer: return "MappingPointer";
\r
610 default: return "UNKNOWN";
\r
614 static const char* fghPropertyStateToString( int state )
\r
617 case PropertyNewValue: return "PropertyNewValue";
\r
618 case PropertyDelete: return "PropertyDelete";
\r
619 default: return "UNKNOWN";
\r
623 static const char* fghColormapStateToString( int state )
\r
626 case ColormapUninstalled: return "ColormapUninstalled";
\r
627 case ColormapInstalled: return "ColormapInstalled";
\r
628 default: return "UNKNOWN";
\r
632 static void fghPrintEvent( XEvent *event )
\r
634 switch( event->type ) {
\r
638 XKeyEvent *e = &event->xkey;
\r
639 fgWarning( "%s: window=0x%x, root=0x%x, subwindow=0x%x, time=%lu, "
\r
640 "(x,y)=(%d,%d), (x_root,y_root)=(%d,%d), state=0x%x, "
\r
641 "keycode=%u, same_screen=%s", fghTypeToString( e->type ),
\r
642 e->window, e->root, e->subwindow, (unsigned long)e->time,
\r
643 e->x, e->y, e->x_root, e->y_root, e->state, e->keycode,
\r
644 fghBoolToString( e->same_screen ) );
\r
649 case ButtonRelease: {
\r
650 XButtonEvent *e = &event->xbutton;
\r
651 fgWarning( "%s: window=0x%x, root=0x%x, subwindow=0x%x, time=%lu, "
\r
652 "(x,y)=(%d,%d), (x_root,y_root)=(%d,%d), state=0x%x, "
\r
653 "button=%u, same_screen=%d", fghTypeToString( e->type ),
\r
654 e->window, e->root, e->subwindow, (unsigned long)e->time,
\r
655 e->x, e->y, e->x_root, e->y_root, e->state, e->button,
\r
656 fghBoolToString( e->same_screen ) );
\r
660 case MotionNotify: {
\r
661 XMotionEvent *e = &event->xmotion;
\r
662 fgWarning( "%s: window=0x%x, root=0x%x, subwindow=0x%x, time=%lu, "
\r
663 "(x,y)=(%d,%d), (x_root,y_root)=(%d,%d), state=0x%x, "
\r
664 "is_hint=%s, same_screen=%d", fghTypeToString( e->type ),
\r
665 e->window, e->root, e->subwindow, (unsigned long)e->time,
\r
666 e->x, e->y, e->x_root, e->y_root, e->state,
\r
667 fghNotifyHintToString( e->is_hint ),
\r
668 fghBoolToString( e->same_screen ) );
\r
673 case LeaveNotify: {
\r
674 XCrossingEvent *e = &event->xcrossing;
\r
675 fgWarning( "%s: window=0x%x, root=0x%x, subwindow=0x%x, time=%lu, "
\r
676 "(x,y)=(%d,%d), mode=%s, detail=%s, same_screen=%d, "
\r
677 "focus=%d, state=0x%x", fghTypeToString( e->type ),
\r
678 e->window, e->root, e->subwindow, (unsigned long)e->time,
\r
679 e->x, e->y, fghNotifyModeToString( e->mode ),
\r
680 fghNotifyDetailToString( e->detail ), (int)e->same_screen,
\r
681 (int)e->focus, e->state );
\r
687 XFocusChangeEvent *e = &event->xfocus;
\r
688 fgWarning( "%s: window=0x%x, mode=%s, detail=%s",
\r
689 fghTypeToString( e->type ), e->window,
\r
690 fghNotifyModeToString( e->mode ),
\r
691 fghNotifyDetailToString( e->detail ) );
\r
695 case KeymapNotify: {
\r
696 XKeymapEvent *e = &event->xkeymap;
\r
697 char buf[32 * 2 + 1];
\r
699 for ( i = 0; i < 32; i++ ) {
\r
700 snprintf( &buf[ i * 2 ], sizeof( buf ) - i * 2,
\r
701 "%02x", e->key_vector[ i ] );
\r
704 fgWarning( "%s: window=0x%x, %s", fghTypeToString( e->type ), e->window,
\r
710 XExposeEvent *e = &event->xexpose;
\r
711 fgWarning( "%s: window=0x%x, (x,y)=(%d,%d), (width,height)=(%d,%d), "
\r
712 "count=%d", fghTypeToString( e->type ), e->window, e->x,
\r
713 e->y, e->width, e->height, e->count );
\r
717 case GraphicsExpose: {
\r
718 XGraphicsExposeEvent *e = &event->xgraphicsexpose;
\r
719 fgWarning( "%s: drawable=0x%x, (x,y)=(%d,%d), (width,height)=(%d,%d), "
\r
720 "count=%d, (major_code,minor_code)=(%d,%d)",
\r
721 fghTypeToString( e->type ), e->drawable, e->x, e->y,
\r
722 e->width, e->height, e->count, e->major_code,
\r
728 XNoExposeEvent *e = &event->xnoexpose;
\r
729 fgWarning( "%s: drawable=0x%x, (major_code,minor_code)=(%d,%d)",
\r
730 fghTypeToString( e->type ), e->drawable, e->major_code,
\r
735 case VisibilityNotify: {
\r
736 XVisibilityEvent *e = &event->xvisibility;
\r
737 fgWarning( "%s: window=0x%x, state=%s", fghTypeToString( e->type ),
\r
738 e->window, fghVisibilityToString( e->state) );
\r
742 case CreateNotify: {
\r
743 XCreateWindowEvent *e = &event->xcreatewindow;
\r
744 fgWarning( "%s: (x,y)=(%d,%d), (width,height)=(%d,%d), border_width=%d, "
\r
745 "window=0x%x, override_redirect=%s",
\r
746 fghTypeToString( e->type ), e->x, e->y, e->width, e->height,
\r
747 e->border_width, e->window,
\r
748 fghBoolToString( e->override_redirect ) );
\r
752 case DestroyNotify: {
\r
753 XDestroyWindowEvent *e = &event->xdestroywindow;
\r
754 fgWarning( "%s: event=0x%x, window=0x%x",
\r
755 fghTypeToString( e->type ), e->event, e->window );
\r
759 case UnmapNotify: {
\r
760 XUnmapEvent *e = &event->xunmap;
\r
761 fgWarning( "%s: event=0x%x, window=0x%x, from_configure=%s",
\r
762 fghTypeToString( e->type ), e->event, e->window,
\r
763 fghBoolToString( e->from_configure ) );
\r
768 XMapEvent *e = &event->xmap;
\r
769 fgWarning( "%s: event=0x%x, window=0x%x, override_redirect=%s",
\r
770 fghTypeToString( e->type ), e->event, e->window,
\r
771 fghBoolToString( e->override_redirect ) );
\r
776 XMapRequestEvent *e = &event->xmaprequest;
\r
777 fgWarning( "%s: parent=0x%x, window=0x%x",
\r
778 fghTypeToString( event->type ), e->parent, e->window );
\r
782 case ReparentNotify: {
\r
783 XReparentEvent *e = &event->xreparent;
\r
784 fgWarning( "%s: event=0x%x, window=0x%x, parent=0x%x, (x,y)=(%d,%d), "
\r
785 "override_redirect=%s", fghTypeToString( e->type ),
\r
786 e->event, e->window, e->parent, e->x, e->y,
\r
787 fghBoolToString( e->override_redirect ) );
\r
791 case ConfigureNotify: {
\r
792 XConfigureEvent *e = &event->xconfigure;
\r
793 fgWarning( "%s: event=0x%x, window=0x%x, (x,y)=(%d,%d), "
\r
794 "(width,height)=(%d,%d), border_width=%d, above=0x%x, "
\r
795 "override_redirect=%s", fghTypeToString( e->type ), e->event,
\r
796 e->window, e->x, e->y, e->width, e->height, e->border_width,
\r
797 e->above, fghBoolToString( e->override_redirect ) );
\r
801 case ConfigureRequest: {
\r
802 XConfigureRequestEvent *e = &event->xconfigurerequest;
\r
803 fgWarning( "%s: parent=0x%x, window=0x%x, (x,y)=(%d,%d), "
\r
804 "(width,height)=(%d,%d), border_width=%d, above=0x%x, "
\r
805 "detail=%s, value_mask=%lx", fghTypeToString( e->type ),
\r
806 e->parent, e->window, e->x, e->y, e->width, e->height,
\r
807 e->border_width, e->above,
\r
808 fghConfigureDetailToString( e->detail ), e->value_mask );
\r
812 case GravityNotify: {
\r
813 XGravityEvent *e = &event->xgravity;
\r
814 fgWarning( "%s: event=0x%x, window=0x%x, (x,y)=(%d,%d)",
\r
815 fghTypeToString( e->type ), e->event, e->window, e->x, e->y );
\r
819 case ResizeRequest: {
\r
820 XResizeRequestEvent *e = &event->xresizerequest;
\r
821 fgWarning( "%s: window=0x%x, (width,height)=(%d,%d)",
\r
822 fghTypeToString( e->type ), e->window, e->width, e->height );
\r
826 case CirculateNotify: {
\r
827 XCirculateEvent *e = &event->xcirculate;
\r
828 fgWarning( "%s: event=0x%x, window=0x%x, place=%s",
\r
829 fghTypeToString( e->type ), e->event, e->window,
\r
830 fghPlaceToString( e->place ) );
\r
834 case CirculateRequest: {
\r
835 XCirculateRequestEvent *e = &event->xcirculaterequest;
\r
836 fgWarning( "%s: parent=0x%x, window=0x%x, place=%s",
\r
837 fghTypeToString( e->type ), e->parent, e->window,
\r
838 fghPlaceToString( e->place ) );
\r
842 case PropertyNotify: {
\r
843 XPropertyEvent *e = &event->xproperty;
\r
844 fgWarning( "%s: window=0x%x, atom=%lu, time=%lu, state=%s",
\r
845 fghTypeToString( e->type ), e->window,
\r
846 (unsigned long)e->atom, (unsigned long)e->time,
\r
847 fghPropertyStateToString( e->state ) );
\r
851 case SelectionClear: {
\r
852 XSelectionClearEvent *e = &event->xselectionclear;
\r
853 fgWarning( "%s: window=0x%x, selection=%lu, time=%lu",
\r
854 fghTypeToString( e->type ), e->window,
\r
855 (unsigned long)e->selection, (unsigned long)e->time );
\r
859 case SelectionRequest: {
\r
860 XSelectionRequestEvent *e = &event->xselectionrequest;
\r
861 fgWarning( "%s: owner=0x%x, requestor=0x%x, selection=0x%x, "
\r
862 "target=0x%x, property=%lu, time=%lu",
\r
863 fghTypeToString( e->type ), e->owner, e->requestor,
\r
864 (unsigned long)e->selection, (unsigned long)e->target,
\r
865 (unsigned long)e->property, (unsigned long)e->time );
\r
869 case SelectionNotify: {
\r
870 XSelectionEvent *e = &event->xselection;
\r
871 fgWarning( "%s: requestor=0x%x, selection=0x%x, target=0x%x, "
\r
872 "property=%lu, time=%lu", fghTypeToString( e->type ),
\r
873 e->requestor, (unsigned long)e->selection,
\r
874 (unsigned long)e->target, (unsigned long)e->property,
\r
875 (unsigned long)e->time );
\r
879 case ColormapNotify: {
\r
880 XColormapEvent *e = &event->xcolormap;
\r
881 fgWarning( "%s: window=0x%x, colormap=%lu, new=%s, state=%s",
\r
882 fghTypeToString( e->type ), e->window,
\r
883 (unsigned long)e->colormap, fghBoolToString( e->new ),
\r
884 fghColormapStateToString( e->state ) );
\r
888 case ClientMessage: {
\r
889 XClientMessageEvent *e = &event->xclient;
\r
892 char* end = buf + sizeof( buf );
\r
894 switch( e->format ) {
\r
896 for ( i = 0; i < 20; i++, p += 3 ) {
\r
897 snprintf( p, end - p, " %02x", e->data.b[ i ] );
\r
901 for ( i = 0; i < 10; i++, p += 5 ) {
\r
902 snprintf( p, end - p, " %04x", e->data.s[ i ] );
\r
906 for ( i = 0; i < 5; i++, p += 9 ) {
\r
907 snprintf( p, end - p, " %08lx", e->data.l[ i ] );
\r
912 fgWarning( "%s: window=0x%x, message_type=%lu, format=%d, data=(%s )",
\r
913 fghTypeToString( e->type ), e->window,
\r
914 (unsigned long)e->message_type, e->format, buf );
\r
918 case MappingNotify: {
\r
919 XMappingEvent *e = &event->xmapping;
\r
920 fgWarning( "%s: window=0x%x, request=%s, first_keycode=%d, count=%d",
\r
921 fghTypeToString( e->type ), e->window,
\r
922 fghMappingRequestToString( e->request ), e->first_keycode,
\r
928 fgWarning( "%s", fghTypeToString( event->type ) );
\r
935 void fghProcessSingleEvent ( void )
\r
937 SFG_Window* window;
\r
940 /* This code was repeated constantly, so here it goes into a definition: */
\r
941 #define GETWINDOW(a) \
\r
942 window = fgWindowByHandle( event.a.window ); \
\r
943 if( window == NULL ) \
\r
946 #define GETMOUSE(a) \
\r
947 window->State.MouseX = event.a.x; \
\r
948 window->State.MouseY = event.a.y;
\r
950 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutMainLoopEvent" );
\r
952 while( XPending( fgDisplay.Display ) )
\r
954 XNextEvent( fgDisplay.Display, &event );
\r
956 fghPrintEvent( &event );
\r
959 switch( event.type )
\r
961 case ClientMessage:
\r
962 if(fgIsSpaceballXEvent(&event)) {
\r
963 fgSpaceballHandleXEvent(&event);
\r
966 /* Destroy the window when the WM_DELETE_WINDOW message arrives */
\r
967 if( (Atom) event.xclient.data.l[ 0 ] == fgDisplay.DeleteWindow )
\r
969 GETWINDOW( xclient );
\r
971 fgDestroyWindow ( window );
\r
973 if( fgState.ActionOnWindowClose == GLUT_ACTION_EXIT )
\r
978 else if( fgState.ActionOnWindowClose == GLUT_ACTION_GLUTMAINLOOP_RETURNS )
\r
979 fgState.ExecState = GLUT_EXEC_STATE_STOP;
\r
986 * CreateNotify causes a configure-event so that sub-windows are
\r
987 * handled compatibly with GLUT. Otherwise, your sub-windows
\r
988 * (in freeglut only) will not get an initial reshape event,
\r
989 * which can break things.
\r
991 * GLUT presumably does this because it generally tries to treat
\r
992 * sub-windows the same as windows.
\r
995 case ConfigureNotify:
\r
998 if( event.type == CreateNotify ) {
\r
999 GETWINDOW( xcreatewindow );
\r
1000 width = event.xcreatewindow.width;
\r
1001 height = event.xcreatewindow.height;
\r
1003 GETWINDOW( xconfigure );
\r
1004 width = event.xconfigure.width;
\r
1005 height = event.xconfigure.height;
\r
1008 if( ( width != window->State.OldWidth ) ||
\r
1009 ( height != window->State.OldHeight ) )
\r
1011 SFG_Window *current_window = fgStructure.CurrentWindow;
\r
1013 window->State.OldWidth = width;
\r
1014 window->State.OldHeight = height;
\r
1015 if( FETCH_WCB( *window, Reshape ) )
\r
1016 INVOKE_WCB( *window, Reshape, ( width, height ) );
\r
1019 fgSetWindow( window );
\r
1020 glViewport( 0, 0, width, height );
\r
1022 glutPostRedisplay( );
\r
1023 if( window->IsMenu )
\r
1024 fgSetWindow( current_window );
\r
1029 case DestroyNotify:
\r
1031 * This is sent to confirm the XDestroyWindow call.
\r
1033 * XXX WHY is this commented out? Should we re-enable it?
\r
1035 /* fgAddToWindowDestroyList ( window ); */
\r
1040 * We are too dumb to process partial exposes...
\r
1042 * XXX Well, we could do it. However, it seems to only
\r
1043 * XXX be potentially useful for single-buffered (since
\r
1044 * XXX double-buffered does not respect viewport when we
\r
1045 * XXX do a buffer-swap).
\r
1048 if( event.xexpose.count == 0 )
\r
1050 GETWINDOW( xexpose );
\r
1051 window->State.Redisplay = GL_TRUE;
\r
1059 /* We get this when iconifying a window. */
\r
1060 GETWINDOW( xunmap );
\r
1061 INVOKE_WCB( *window, WindowStatus, ( GLUT_HIDDEN ) );
\r
1062 window->State.Visible = GL_FALSE;
\r
1065 case MappingNotify:
\r
1067 * Have the client's keyboard knowledge updated (xlib.ps,
\r
1068 * page 206, says that's a good thing to do)
\r
1070 XRefreshKeyboardMapping( (XMappingEvent *) &event );
\r
1073 case VisibilityNotify:
\r
1076 * Sending this event, the X server can notify us that the window
\r
1077 * has just acquired one of the three possible visibility states:
\r
1078 * VisibilityUnobscured, VisibilityPartiallyObscured or
\r
1079 * VisibilityFullyObscured. Note that we DO NOT receive a
\r
1080 * VisibilityNotify event when iconifying a window, we only get an
\r
1081 * UnmapNotify then.
\r
1083 GETWINDOW( xvisibility );
\r
1084 switch( event.xvisibility.state )
\r
1086 case VisibilityUnobscured:
\r
1087 INVOKE_WCB( *window, WindowStatus, ( GLUT_FULLY_RETAINED ) );
\r
1088 window->State.Visible = GL_TRUE;
\r
1091 case VisibilityPartiallyObscured:
\r
1092 INVOKE_WCB( *window, WindowStatus,
\r
1093 ( GLUT_PARTIALLY_RETAINED ) );
\r
1094 window->State.Visible = GL_TRUE;
\r
1097 case VisibilityFullyObscured:
\r
1098 INVOKE_WCB( *window, WindowStatus, ( GLUT_FULLY_COVERED ) );
\r
1099 window->State.Visible = GL_FALSE;
\r
1103 fgWarning( "Unknown X visibility state: %d",
\r
1104 event.xvisibility.state );
\r
1112 GETWINDOW( xcrossing );
\r
1113 GETMOUSE( xcrossing );
\r
1114 if( ( event.type == LeaveNotify ) && window->IsMenu &&
\r
1115 window->ActiveMenu && window->ActiveMenu->IsActive )
\r
1116 fgUpdateMenuHighlight( window->ActiveMenu );
\r
1118 INVOKE_WCB( *window, Entry, ( ( EnterNotify == event.type ) ?
\r
1123 case MotionNotify:
\r
1125 GETWINDOW( xmotion );
\r
1126 GETMOUSE( xmotion );
\r
1128 if( window->ActiveMenu )
\r
1130 if( window == window->ActiveMenu->ParentWindow )
\r
1132 window->ActiveMenu->Window->State.MouseX =
\r
1133 event.xmotion.x_root - window->ActiveMenu->X;
\r
1134 window->ActiveMenu->Window->State.MouseY =
\r
1135 event.xmotion.y_root - window->ActiveMenu->Y;
\r
1138 fgUpdateMenuHighlight( window->ActiveMenu );
\r
1144 * XXX For more than 5 buttons, just check {event.xmotion.state},
\r
1145 * XXX rather than a host of bit-masks? Or maybe we need to
\r
1146 * XXX track ButtonPress/ButtonRelease events in our own
\r
1149 fgState.Modifiers = fghGetXModifiers( event.xmotion.state );
\r
1150 if ( event.xmotion.state & ( Button1Mask | Button2Mask | Button3Mask | Button4Mask | Button5Mask ) ) {
\r
1151 INVOKE_WCB( *window, Motion, ( event.xmotion.x,
\r
1152 event.xmotion.y ) );
\r
1154 INVOKE_WCB( *window, Passive, ( event.xmotion.x,
\r
1155 event.xmotion.y ) );
\r
1157 fgState.Modifiers = INVALID_MODIFIERS;
\r
1161 case ButtonRelease:
\r
1164 GLboolean pressed = GL_TRUE;
\r
1167 if( event.type == ButtonRelease )
\r
1168 pressed = GL_FALSE ;
\r
1171 * A mouse button has been pressed or released. Traditionally,
\r
1172 * break if the window was found within the freeglut structures.
\r
1174 GETWINDOW( xbutton );
\r
1175 GETMOUSE( xbutton );
\r
1178 * An X button (at least in XFree86) is numbered from 1.
\r
1179 * A GLUT button is numbered from 0.
\r
1180 * Old GLUT passed through buttons other than just the first
\r
1181 * three, though it only gave symbolic names and official
\r
1182 * support to the first three.
\r
1184 button = event.xbutton.button - 1;
\r
1187 * Do not execute the application's mouse callback if a menu
\r
1188 * is hooked to this button. In that case an appropriate
\r
1189 * private call should be generated.
\r
1191 if( fgCheckActiveMenu( window, button, pressed,
\r
1192 event.xbutton.x_root, event.xbutton.y_root ) )
\r
1196 * Check if there is a mouse or mouse wheel callback hooked to the
\r
1199 if( ! FETCH_WCB( *window, Mouse ) &&
\r
1200 ! FETCH_WCB( *window, MouseWheel ) )
\r
1203 fgState.Modifiers = fghGetXModifiers( event.xbutton.state );
\r
1205 /* Finally execute the mouse or mouse wheel callback */
\r
1206 if( ( button < glutDeviceGet ( GLUT_NUM_MOUSE_BUTTONS ) ) || ( ! FETCH_WCB( *window, MouseWheel ) ) )
\r
1207 INVOKE_WCB( *window, Mouse, ( button,
\r
1208 pressed ? GLUT_DOWN : GLUT_UP,
\r
1215 * Map 4 and 5 to wheel zero; EVEN to +1, ODD to -1
\r
1216 * " 6 and 7 " " one; ...
\r
1218 * XXX This *should* be behind some variables/macros,
\r
1219 * XXX since the order and numbering isn't certain
\r
1220 * XXX See XFree86 configuration docs (even back in the
\r
1221 * XXX 3.x days, and especially with 4.x).
\r
1223 * XXX Note that {button} has already been decremented
\r
1224 * XXX in mapping from X button numbering to GLUT.
\r
1226 * XXX Should add support for partial wheel turns as Windows does -- 5/27/11
\r
1228 int wheel_number = (button - glutDeviceGet ( GLUT_NUM_MOUSE_BUTTONS )) / 2;
\r
1229 int direction = -1;
\r
1234 INVOKE_WCB( *window, MouseWheel, ( wheel_number,
\r
1240 fgState.Modifiers = INVALID_MODIFIERS;
\r
1247 FGCBKeyboard keyboard_cb;
\r
1248 FGCBSpecial special_cb;
\r
1250 GETWINDOW( xkey );
\r
1253 /* Detect auto repeated keys, if configured globally or per-window */
\r
1255 if ( fgState.KeyRepeat==GLUT_KEY_REPEAT_OFF || window->State.IgnoreKeyRepeat==GL_TRUE )
\r
1257 if (event.type==KeyRelease)
\r
1260 * Look at X11 keystate to detect repeat mode.
\r
1261 * While X11 says the key is actually held down, we'll ignore KeyRelease/KeyPress pairs.
\r
1265 XQueryKeymap( fgDisplay.Display, keys ); /* Look at X11 keystate to detect repeat mode */
\r
1267 if ( event.xkey.keycode<256 ) /* XQueryKeymap is limited to 256 keycodes */
\r
1269 if ( keys[event.xkey.keycode>>3] & (1<<(event.xkey.keycode%8)) )
\r
1270 window->State.KeyRepeating = GL_TRUE;
\r
1272 window->State.KeyRepeating = GL_FALSE;
\r
1277 window->State.KeyRepeating = GL_FALSE;
\r
1279 /* Cease processing this event if it is auto repeated */
\r
1281 if (window->State.KeyRepeating)
\r
1283 if (event.type == KeyPress) window->State.KeyRepeating = GL_FALSE;
\r
1287 if( event.type == KeyPress )
\r
1289 keyboard_cb = (FGCBKeyboard)( FETCH_WCB( *window, Keyboard ));
\r
1290 special_cb = (FGCBSpecial) ( FETCH_WCB( *window, Special ));
\r
1294 keyboard_cb = (FGCBKeyboard)( FETCH_WCB( *window, KeyboardUp ));
\r
1295 special_cb = (FGCBSpecial) ( FETCH_WCB( *window, SpecialUp ));
\r
1298 /* Is there a keyboard/special callback hooked for this window? */
\r
1299 if( keyboard_cb || special_cb )
\r
1301 XComposeStatus composeStatus;
\r
1302 char asciiCode[ 32 ];
\r
1306 /* Check for the ASCII/KeySym codes associated with the event: */
\r
1307 len = XLookupString( &event.xkey, asciiCode, sizeof(asciiCode),
\r
1308 &keySym, &composeStatus
\r
1311 /* GLUT API tells us to have two separate callbacks... */
\r
1314 /* ...one for the ASCII translateable keypresses... */
\r
1317 fgSetWindow( window );
\r
1318 fgState.Modifiers = fghGetXModifiers( event.xkey.state );
\r
1319 keyboard_cb( asciiCode[ 0 ],
\r
1320 event.xkey.x, event.xkey.y
\r
1322 fgState.Modifiers = INVALID_MODIFIERS;
\r
1330 * ...and one for all the others, which need to be
\r
1331 * translated to GLUT_KEY_Xs...
\r
1335 case XK_F1: special = GLUT_KEY_F1; break;
\r
1336 case XK_F2: special = GLUT_KEY_F2; break;
\r
1337 case XK_F3: special = GLUT_KEY_F3; break;
\r
1338 case XK_F4: special = GLUT_KEY_F4; break;
\r
1339 case XK_F5: special = GLUT_KEY_F5; break;
\r
1340 case XK_F6: special = GLUT_KEY_F6; break;
\r
1341 case XK_F7: special = GLUT_KEY_F7; break;
\r
1342 case XK_F8: special = GLUT_KEY_F8; break;
\r
1343 case XK_F9: special = GLUT_KEY_F9; break;
\r
1344 case XK_F10: special = GLUT_KEY_F10; break;
\r
1345 case XK_F11: special = GLUT_KEY_F11; break;
\r
1346 case XK_F12: special = GLUT_KEY_F12; break;
\r
1349 case XK_Left: special = GLUT_KEY_LEFT; break;
\r
1351 case XK_Right: special = GLUT_KEY_RIGHT; break;
\r
1353 case XK_Up: special = GLUT_KEY_UP; break;
\r
1355 case XK_Down: special = GLUT_KEY_DOWN; break;
\r
1358 case XK_Prior: special = GLUT_KEY_PAGE_UP; break;
\r
1360 case XK_Next: special = GLUT_KEY_PAGE_DOWN; break;
\r
1362 case XK_Home: special = GLUT_KEY_HOME; break;
\r
1364 case XK_End: special = GLUT_KEY_END; break;
\r
1365 case XK_KP_Insert:
\r
1366 case XK_Insert: special = GLUT_KEY_INSERT; break;
\r
1368 case XK_Num_Lock : special = GLUT_KEY_NUM_LOCK; break;
\r
1369 case XK_KP_Begin : special = GLUT_KEY_BEGIN; break;
\r
1370 case XK_KP_Delete: special = GLUT_KEY_DELETE; break;
\r
1372 case XK_Shift_L: special = GLUT_KEY_SHIFT_L; break;
\r
1373 case XK_Shift_R: special = GLUT_KEY_SHIFT_R; break;
\r
1374 case XK_Control_L: special = GLUT_KEY_CTRL_L; break;
\r
1375 case XK_Control_R: special = GLUT_KEY_CTRL_R; break;
\r
1376 case XK_Alt_L: special = GLUT_KEY_ALT_L; break;
\r
1377 case XK_Alt_R: special = GLUT_KEY_ALT_R; break;
\r
1381 * Execute the callback (if one has been specified),
\r
1382 * given that the special code seems to be valid...
\r
1384 if( special_cb && (special != -1) )
\r
1386 fgSetWindow( window );
\r
1387 fgState.Modifiers = fghGetXModifiers( event.xkey.state );
\r
1388 special_cb( special, event.xkey.x, event.xkey.y );
\r
1389 fgState.Modifiers = INVALID_MODIFIERS;
\r
1396 case ReparentNotify:
\r
1397 break; /* XXX Should disable this event */
\r
1400 case GravityNotify:
\r
1404 /* enter handling of Extension Events here */
\r
1405 #ifdef HAVE_X11_EXTENSIONS_XINPUT2_H
\r
1406 fgHandleExtensionEvents( &event );
\r
1414 /* -- INTERFACE FUNCTIONS -------------------------------------------------- */
\r
1417 * Executes a single iteration in the freeglut processing loop.
\r
1419 void FGAPIENTRY glutMainLoopEvent( void )
\r
1421 fghProcessSingleEvent ();
\r
1423 if( fgState.Timers.First )
\r
1424 fghCheckTimers( );
\r
1425 fghCheckJoystickPolls( );
\r
1428 fgCloseWindows( );
\r
1432 * Enters the freeglut processing loop.
\r
1433 * Stays until the "ExecState" changes to "GLUT_EXEC_STATE_STOP".
\r
1435 void FGAPIENTRY glutMainLoop( void )
\r
1439 #if TARGET_HOST_MS_WINDOWS
\r
1440 SFG_Window *window = (SFG_Window *)fgStructure.Windows.First ;
\r
1443 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutMainLoop" );
\r
1445 #if TARGET_HOST_MS_WINDOWS
\r
1447 * Processing before the main loop: If there is a window which is open and
\r
1448 * which has a visibility callback, call it. I know this is an ugly hack,
\r
1449 * but I'm not sure what else to do about it. Ideally we should leave
\r
1450 * something uninitialized in the create window code and initialize it in
\r
1451 * the main loop, and have that initialization create a "WM_ACTIVATE"
\r
1452 * message. Then we would put the visibility callback code in the
\r
1453 * "case WM_ACTIVATE" block below. - John Fay -- 10/24/02
\r
1457 if ( FETCH_WCB( *window, Visibility ) )
\r
1459 SFG_Window *current_window = fgStructure.CurrentWindow ;
\r
1461 INVOKE_WCB( *window, Visibility, ( window->State.Visible ) );
\r
1462 fgSetWindow( current_window );
\r
1465 window = (SFG_Window *)window->Node.Next ;
\r
1469 fgState.ExecState = GLUT_EXEC_STATE_RUNNING ;
\r
1470 while( fgState.ExecState == GLUT_EXEC_STATE_RUNNING )
\r
1472 SFG_Window *window;
\r
1474 glutMainLoopEvent( );
\r
1476 * Step through the list of windows, seeing if there are any
\r
1477 * that are not menus
\r
1479 for( window = ( SFG_Window * )fgStructure.Windows.First;
\r
1481 window = ( SFG_Window * )window->Node.Next )
\r
1482 if ( ! ( window->IsMenu ) )
\r
1486 fgState.ExecState = GLUT_EXEC_STATE_STOP;
\r
1489 if( fgState.IdleCallback )
\r
1491 if( fgStructure.CurrentWindow &&
\r
1492 fgStructure.CurrentWindow->IsMenu )
\r
1494 fgSetWindow( window );
\r
1495 fgState.IdleCallback( );
\r
1498 fghSleepForEvents( );
\r
1503 * When this loop terminates, destroy the display, state and structure
\r
1504 * of a freeglut session, so that another glutInit() call can happen
\r
1506 * Save the "ActionOnWindowClose" because "fgDeinitialize" resets it.
\r
1508 action = fgState.ActionOnWindowClose;
\r
1509 fgDeinitialize( );
\r
1510 if( action == GLUT_ACTION_EXIT )
\r
1515 * Leaves the freeglut processing loop.
\r
1517 void FGAPIENTRY glutLeaveMainLoop( void )
\r
1519 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutLeaveMainLoop" );
\r
1520 fgState.ExecState = GLUT_EXEC_STATE_STOP ;
\r
1524 #if TARGET_HOST_MS_WINDOWS
\r
1526 * Determine a GLUT modifer mask based on MS-WINDOWS system info.
\r
1528 static int fghGetWin32Modifiers (void)
\r
1531 ( ( ( GetKeyState( VK_LSHIFT ) < 0 ) ||
\r
1532 ( GetKeyState( VK_RSHIFT ) < 0 )) ? GLUT_ACTIVE_SHIFT : 0 ) |
\r
1533 ( ( ( GetKeyState( VK_LCONTROL ) < 0 ) ||
\r
1534 ( GetKeyState( VK_RCONTROL ) < 0 )) ? GLUT_ACTIVE_CTRL : 0 ) |
\r
1535 ( ( ( GetKeyState( VK_LMENU ) < 0 ) ||
\r
1536 ( GetKeyState( VK_RMENU ) < 0 )) ? GLUT_ACTIVE_ALT : 0 );
\r
1540 * The window procedure for handling Win32 events
\r
1542 LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam,
\r
1545 static unsigned char lControl = 0, rControl = 0, lShift = 0,
\r
1546 rShift = 0, lAlt = 0, rAlt = 0;
\r
1548 SFG_Window* window;
\r
1552 FREEGLUT_INTERNAL_ERROR_EXIT_IF_NOT_INITIALISED ( "Event Handler" ) ;
\r
1554 window = fgWindowByHandle( hWnd );
\r
1556 if ( ( window == NULL ) && ( uMsg != WM_CREATE ) )
\r
1557 return DefWindowProc( hWnd, uMsg, wParam, lParam );
\r
1559 /* printf ( "Window %3d message <%04x> %12d %12d\n", window?window->ID:0,
\r
1560 uMsg, wParam, lParam ); */
\r
1564 /* Checking for CTRL, ALT, and SHIFT key positions: Key Down! */
\r
1565 if ( !lControl && GetAsyncKeyState ( VK_LCONTROL ) )
\r
1567 INVOKE_WCB ( *window, Special,
\r
1568 ( GLUT_KEY_CTRL_L, window->State.MouseX, window->State.MouseY )
\r
1574 if ( !rControl && GetAsyncKeyState ( VK_RCONTROL ) )
\r
1576 INVOKE_WCB ( *window, Special,
\r
1577 ( GLUT_KEY_CTRL_R, window->State.MouseX, window->State.MouseY )
\r
1583 if ( !lShift && GetAsyncKeyState ( VK_LSHIFT ) )
\r
1585 INVOKE_WCB ( *window, Special,
\r
1586 ( GLUT_KEY_SHIFT_L, window->State.MouseX, window->State.MouseY )
\r
1592 if ( !rShift && GetAsyncKeyState ( VK_RSHIFT ) )
\r
1594 INVOKE_WCB ( *window, Special,
\r
1595 ( GLUT_KEY_SHIFT_R, window->State.MouseX, window->State.MouseY )
\r
1601 if ( !lAlt && GetAsyncKeyState ( VK_LMENU ) )
\r
1603 INVOKE_WCB ( *window, Special,
\r
1604 ( GLUT_KEY_ALT_L, window->State.MouseX, window->State.MouseY )
\r
1610 if ( !rAlt && GetAsyncKeyState ( VK_RMENU ) )
\r
1612 INVOKE_WCB ( *window, Special,
\r
1613 ( GLUT_KEY_ALT_R, window->State.MouseX, window->State.MouseY )
\r
1619 /* Checking for CTRL, ALT, and SHIFT key positions: Key Up! */
\r
1620 if ( lControl && !GetAsyncKeyState ( VK_LCONTROL ) )
\r
1622 INVOKE_WCB ( *window, SpecialUp,
\r
1623 ( GLUT_KEY_CTRL_L, window->State.MouseX, window->State.MouseY )
\r
1629 if ( rControl && !GetAsyncKeyState ( VK_RCONTROL ) )
\r
1631 INVOKE_WCB ( *window, SpecialUp,
\r
1632 ( GLUT_KEY_CTRL_R, window->State.MouseX, window->State.MouseY )
\r
1638 if ( lShift && !GetAsyncKeyState ( VK_LSHIFT ) )
\r
1640 INVOKE_WCB ( *window, SpecialUp,
\r
1641 ( GLUT_KEY_SHIFT_L, window->State.MouseX, window->State.MouseY )
\r
1647 if ( rShift && !GetAsyncKeyState ( VK_RSHIFT ) )
\r
1649 INVOKE_WCB ( *window, SpecialUp,
\r
1650 ( GLUT_KEY_SHIFT_R, window->State.MouseX, window->State.MouseY )
\r
1656 if ( lAlt && !GetAsyncKeyState ( VK_LMENU ) )
\r
1658 INVOKE_WCB ( *window, SpecialUp,
\r
1659 ( GLUT_KEY_ALT_L, window->State.MouseX, window->State.MouseY )
\r
1665 if ( rAlt && !GetAsyncKeyState ( VK_RMENU ) )
\r
1667 INVOKE_WCB ( *window, SpecialUp,
\r
1668 ( GLUT_KEY_ALT_R, window->State.MouseX, window->State.MouseY )
\r
1678 /* The window structure is passed as the creation structure parameter... */
\r
1679 window = (SFG_Window *) (((LPCREATESTRUCT) lParam)->lpCreateParams);
\r
1680 FREEGLUT_INTERNAL_ERROR_EXIT ( ( window != NULL ), "Cannot create window",
\r
1683 window->Window.Handle = hWnd;
\r
1684 window->Window.Device = GetDC( hWnd );
\r
1685 if( window->IsMenu )
\r
1687 unsigned int current_DisplayMode = fgState.DisplayMode;
\r
1688 fgState.DisplayMode = GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH;
\r
1689 #if !defined(_WIN32_WCE)
\r
1690 fgSetupPixelFormat( window, GL_FALSE, PFD_MAIN_PLANE );
\r
1692 fgState.DisplayMode = current_DisplayMode;
\r
1694 if( fgStructure.MenuContext )
\r
1695 wglMakeCurrent( window->Window.Device,
\r
1696 fgStructure.MenuContext->MContext
\r
1700 fgStructure.MenuContext =
\r
1701 (SFG_MenuContext *)malloc( sizeof(SFG_MenuContext) );
\r
1702 fgStructure.MenuContext->MContext =
\r
1703 wglCreateContext( window->Window.Device );
\r
1706 /* window->Window.Context = wglGetCurrentContext (); */
\r
1707 window->Window.Context = wglCreateContext( window->Window.Device );
\r
1711 #if !defined(_WIN32_WCE)
\r
1712 fgSetupPixelFormat( window, GL_FALSE, PFD_MAIN_PLANE );
\r
1715 if( ! fgState.UseCurrentContext )
\r
1716 window->Window.Context =
\r
1717 wglCreateContext( window->Window.Device );
\r
1720 window->Window.Context = wglGetCurrentContext( );
\r
1721 if( ! window->Window.Context )
\r
1722 window->Window.Context =
\r
1723 wglCreateContext( window->Window.Device );
\r
1726 #if !defined(_WIN32_WCE)
\r
1727 fgNewWGLCreateContext( window );
\r
1731 window->State.NeedToResize = GL_TRUE;
\r
1732 /* if we used CW_USEDEFAULT (thats a negative value) for the size
\r
1733 * of the window, query the window now for the size at which it
\r
1736 if( ( window->State.Width < 0 ) || ( window->State.Height < 0 ) )
\r
1738 SFG_Window *current_window = fgStructure.CurrentWindow;
\r
1740 fgSetWindow( window );
\r
1741 window->State.Width = glutGet( GLUT_WINDOW_WIDTH );
\r
1742 window->State.Height = glutGet( GLUT_WINDOW_HEIGHT );
\r
1743 fgSetWindow( current_window );
\r
1746 ReleaseDC( window->Window.Handle, window->Window.Device );
\r
1748 #if defined(_WIN32_WCE)
\r
1749 /* Take over button handling */
\r
1751 HINSTANCE dxDllLib=LoadLibrary(_T("gx.dll"));
\r
1754 GXGetDefaultKeys_=(GXGETDEFAULTKEYS)GetProcAddress(dxDllLib, _T("?GXGetDefaultKeys@@YA?AUGXKeyList@@H@Z"));
\r
1755 GXOpenInput_=(GXOPENINPUT)GetProcAddress(dxDllLib, _T("?GXOpenInput@@YAHXZ"));
\r
1759 (*GXOpenInput_)();
\r
1760 if(GXGetDefaultKeys_)
\r
1761 gxKeyList = (*GXGetDefaultKeys_)(GX_LANDSCAPEKEYS);
\r
1764 #endif /* defined(_WIN32_WCE) */
\r
1769 * If the window is visible, then it is the user manually resizing it.
\r
1770 * If it is not, then it is the system sending us a dummy resize with
\r
1771 * zero dimensions on a "glutIconifyWindow" call.
\r
1773 if( window->State.Visible )
\r
1775 window->State.NeedToResize = GL_TRUE;
\r
1776 #if defined(_WIN32_WCE)
\r
1777 window->State.Width = HIWORD(lParam);
\r
1778 window->State.Height = LOWORD(lParam);
\r
1780 window->State.Width = LOWORD(lParam);
\r
1781 window->State.Height = HIWORD(lParam);
\r
1782 #endif /* defined(_WIN32_WCE) */
\r
1788 /* printf("WM_SETFOCUS: %p\n", window ); */
\r
1789 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
\r
1790 INVOKE_WCB( *window, Entry, ( GLUT_ENTERED ) );
\r
1793 case WM_KILLFOCUS:
\r
1794 /* printf("WM_KILLFOCUS: %p\n", window ); */
\r
1795 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
\r
1796 INVOKE_WCB( *window, Entry, ( GLUT_LEFT ) );
\r
1798 if( window->IsMenu &&
\r
1799 window->ActiveMenu && window->ActiveMenu->IsActive )
\r
1800 fgUpdateMenuHighlight( window->ActiveMenu );
\r
1806 if (LOWORD(wParam) != WA_INACTIVE)
\r
1808 /* printf("WM_ACTIVATE: fgSetCursor( %p, %d)\n", window,
\r
1809 window->State.Cursor ); */
\r
1810 fgSetCursor( window, window->State.Cursor );
\r
1813 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
\r
1817 case WM_SETCURSOR:
\r
1818 /* printf ( "Cursor event %x %x %x %x\n", window, window->State.Cursor, lParam, wParam ) ; */
\r
1819 if( LOWORD( lParam ) == HTCLIENT )
\r
1820 fgSetCursor ( window, window->State.Cursor ) ;
\r
1822 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
\r
1825 case WM_SHOWWINDOW:
\r
1826 window->State.Visible = GL_TRUE;
\r
1827 window->State.Redisplay = GL_TRUE;
\r
1831 /* Turn on the visibility in case it was turned off somehow */
\r
1832 window->State.Visible = GL_TRUE;
\r
1833 BeginPaint( hWnd, &ps );
\r
1834 fghRedrawWindow( window );
\r
1835 EndPaint( hWnd, &ps );
\r
1839 fgDestroyWindow ( window );
\r
1840 if ( fgState.ActionOnWindowClose != GLUT_ACTION_CONTINUE_EXECUTION )
\r
1841 PostQuitMessage(0);
\r
1846 * The window already got destroyed, so don't bother with it.
\r
1850 case WM_MOUSEMOVE:
\r
1852 #if defined(_WIN32_WCE)
\r
1853 window->State.MouseX = 320-HIWORD( lParam );
\r
1854 window->State.MouseY = LOWORD( lParam );
\r
1856 window->State.MouseX = LOWORD( lParam );
\r
1857 window->State.MouseY = HIWORD( lParam );
\r
1858 #endif /* defined(_WIN32_WCE) */
\r
1859 /* Restrict to [-32768, 32767] to match X11 behaviour */
\r
1860 /* See comment in "freeglut_developer" mailing list 10/4/04 */
\r
1861 if ( window->State.MouseX > 32767 ) window->State.MouseX -= 65536;
\r
1862 if ( window->State.MouseY > 32767 ) window->State.MouseY -= 65536;
\r
1864 if ( window->ActiveMenu )
\r
1866 fgUpdateMenuHighlight( window->ActiveMenu );
\r
1869 SetFocus(window->Window.Handle);
\r
1871 fgState.Modifiers = fghGetWin32Modifiers( );
\r
1873 if( ( wParam & MK_LBUTTON ) ||
\r
1874 ( wParam & MK_MBUTTON ) ||
\r
1875 ( wParam & MK_RBUTTON ) )
\r
1876 INVOKE_WCB( *window, Motion, ( window->State.MouseX,
\r
1877 window->State.MouseY ) );
\r
1879 INVOKE_WCB( *window, Passive, ( window->State.MouseX,
\r
1880 window->State.MouseY ) );
\r
1882 fgState.Modifiers = INVALID_MODIFIERS;
\r
1886 case WM_LBUTTONDOWN:
\r
1887 case WM_MBUTTONDOWN:
\r
1888 case WM_RBUTTONDOWN:
\r
1889 case WM_LBUTTONUP:
\r
1890 case WM_MBUTTONUP:
\r
1891 case WM_RBUTTONUP:
\r
1893 GLboolean pressed = GL_TRUE;
\r
1896 #if defined(_WIN32_WCE)
\r
1897 window->State.MouseX = 320-HIWORD( lParam );
\r
1898 window->State.MouseY = LOWORD( lParam );
\r
1900 window->State.MouseX = LOWORD( lParam );
\r
1901 window->State.MouseY = HIWORD( lParam );
\r
1902 #endif /* defined(_WIN32_WCE) */
\r
1904 /* Restrict to [-32768, 32767] to match X11 behaviour */
\r
1905 /* See comment in "freeglut_developer" mailing list 10/4/04 */
\r
1906 if ( window->State.MouseX > 32767 ) window->State.MouseX -= 65536;
\r
1907 if ( window->State.MouseY > 32767 ) window->State.MouseY -= 65536;
\r
1911 case WM_LBUTTONDOWN:
\r
1912 pressed = GL_TRUE;
\r
1913 button = GLUT_LEFT_BUTTON;
\r
1915 case WM_MBUTTONDOWN:
\r
1916 pressed = GL_TRUE;
\r
1917 button = GLUT_MIDDLE_BUTTON;
\r
1919 case WM_RBUTTONDOWN:
\r
1920 pressed = GL_TRUE;
\r
1921 button = GLUT_RIGHT_BUTTON;
\r
1923 case WM_LBUTTONUP:
\r
1924 pressed = GL_FALSE;
\r
1925 button = GLUT_LEFT_BUTTON;
\r
1927 case WM_MBUTTONUP:
\r
1928 pressed = GL_FALSE;
\r
1929 button = GLUT_MIDDLE_BUTTON;
\r
1931 case WM_RBUTTONUP:
\r
1932 pressed = GL_FALSE;
\r
1933 button = GLUT_RIGHT_BUTTON;
\r
1936 pressed = GL_FALSE;
\r
1941 #if !defined(_WIN32_WCE)
\r
1942 if( GetSystemMetrics( SM_SWAPBUTTON ) )
\r
1944 if( button == GLUT_LEFT_BUTTON )
\r
1945 button = GLUT_RIGHT_BUTTON;
\r
1947 if( button == GLUT_RIGHT_BUTTON )
\r
1948 button = GLUT_LEFT_BUTTON;
\r
1950 #endif /* !defined(_WIN32_WCE) */
\r
1952 if( button == -1 )
\r
1953 return DefWindowProc( hWnd, uMsg, lParam, wParam );
\r
1956 * Do not execute the application's mouse callback if a menu
\r
1957 * is hooked to this button. In that case an appropriate
\r
1958 * private call should be generated.
\r
1960 if( fgCheckActiveMenu( window, button, pressed,
\r
1961 window->State.MouseX, window->State.MouseY ) )
\r
1964 /* Set capture so that the window captures all the mouse messages */
\r
1966 * XXX - Multiple button support: Under X11, the mouse is not released
\r
1967 * XXX - from the window until all buttons have been released, even if the
\r
1968 * XXX - user presses a button in another window. This will take more
\r
1969 * XXX - code changes than I am up to at the moment (10/5/04). The present
\r
1970 * XXX - is a 90 percent solution.
\r
1972 if ( pressed == GL_TRUE )
\r
1973 SetCapture ( window->Window.Handle ) ;
\r
1975 ReleaseCapture () ;
\r
1977 if( ! FETCH_WCB( *window, Mouse ) )
\r
1980 fgSetWindow( window );
\r
1981 fgState.Modifiers = fghGetWin32Modifiers( );
\r
1986 pressed ? GLUT_DOWN : GLUT_UP,
\r
1987 window->State.MouseX,
\r
1988 window->State.MouseY
\r
1992 fgState.Modifiers = INVALID_MODIFIERS;
\r
1997 /* Should be WM_MOUSEWHEEL but my compiler doesn't recognize it */
\r
1999 int wheel_number = LOWORD( wParam );
\r
2000 short ticks = ( short )HIWORD( wParam );
\r
2001 fgState.MouseWheelTicks += ticks;
\r
2004 * XXX Should use WHEEL_DELTA instead of 120
\r
2006 if ( abs ( fgState.MouseWheelTicks ) > 120 )
\r
2008 int direction = ( fgState.MouseWheelTicks > 0 ) ? 1 : -1;
\r
2010 if( ! FETCH_WCB( *window, MouseWheel ) &&
\r
2011 ! FETCH_WCB( *window, Mouse ) )
\r
2014 fgSetWindow( window );
\r
2015 fgState.Modifiers = fghGetWin32Modifiers( );
\r
2018 * XXX Should use WHEEL_DELTA instead of 120
\r
2020 while( abs ( fgState.MouseWheelTicks ) > 120 )
\r
2022 if( FETCH_WCB( *window, MouseWheel ) )
\r
2023 INVOKE_WCB( *window, MouseWheel,
\r
2026 window->State.MouseX,
\r
2027 window->State.MouseY
\r
2030 else /* No mouse wheel, call the mouse button callback twice */
\r
2033 * Map wheel zero to button 3 and 4; +1 to 3, -1 to 4
\r
2034 * " " one +1 to 5, -1 to 6, ...
\r
2036 * XXX The below assumes that you have no more than 3 mouse
\r
2037 * XXX buttons. Sorry.
\r
2039 int button = wheel_number * 2 + 3;
\r
2040 if( direction < 0 )
\r
2042 INVOKE_WCB( *window, Mouse,
\r
2043 ( button, GLUT_DOWN,
\r
2044 window->State.MouseX, window->State.MouseY )
\r
2046 INVOKE_WCB( *window, Mouse,
\r
2047 ( button, GLUT_UP,
\r
2048 window->State.MouseX, window->State.MouseY )
\r
2053 * XXX Should use WHEEL_DELTA instead of 120
\r
2055 fgState.MouseWheelTicks -= 120 * direction;
\r
2058 fgState.Modifiers = INVALID_MODIFIERS;
\r
2063 case WM_SYSKEYDOWN:
\r
2066 int keypress = -1;
\r
2069 if( ( fgState.KeyRepeat==GLUT_KEY_REPEAT_OFF || window->State.IgnoreKeyRepeat==GL_TRUE ) && (HIWORD(lParam) & KF_REPEAT) )
\r
2073 * Remember the current modifiers state. This is done here in order
\r
2074 * to make sure the VK_DELETE keyboard callback is executed properly.
\r
2076 fgState.Modifiers = fghGetWin32Modifiers( );
\r
2078 GetCursorPos( &mouse_pos );
\r
2079 ScreenToClient( window->Window.Handle, &mouse_pos );
\r
2081 window->State.MouseX = mouse_pos.x;
\r
2082 window->State.MouseY = mouse_pos.y;
\r
2084 /* Convert the Win32 keystroke codes to GLUTtish way */
\r
2085 # define KEY(a,b) case a: keypress = b; break;
\r
2089 KEY( VK_F1, GLUT_KEY_F1 );
\r
2090 KEY( VK_F2, GLUT_KEY_F2 );
\r
2091 KEY( VK_F3, GLUT_KEY_F3 );
\r
2092 KEY( VK_F4, GLUT_KEY_F4 );
\r
2093 KEY( VK_F5, GLUT_KEY_F5 );
\r
2094 KEY( VK_F6, GLUT_KEY_F6 );
\r
2095 KEY( VK_F7, GLUT_KEY_F7 );
\r
2096 KEY( VK_F8, GLUT_KEY_F8 );
\r
2097 KEY( VK_F9, GLUT_KEY_F9 );
\r
2098 KEY( VK_F10, GLUT_KEY_F10 );
\r
2099 KEY( VK_F11, GLUT_KEY_F11 );
\r
2100 KEY( VK_F12, GLUT_KEY_F12 );
\r
2101 KEY( VK_PRIOR, GLUT_KEY_PAGE_UP );
\r
2102 KEY( VK_NEXT, GLUT_KEY_PAGE_DOWN );
\r
2103 KEY( VK_HOME, GLUT_KEY_HOME );
\r
2104 KEY( VK_END, GLUT_KEY_END );
\r
2105 KEY( VK_LEFT, GLUT_KEY_LEFT );
\r
2106 KEY( VK_UP, GLUT_KEY_UP );
\r
2107 KEY( VK_RIGHT, GLUT_KEY_RIGHT );
\r
2108 KEY( VK_DOWN, GLUT_KEY_DOWN );
\r
2109 KEY( VK_INSERT, GLUT_KEY_INSERT );
\r
2110 KEY( VK_LCONTROL, GLUT_KEY_CTRL_L );
\r
2111 KEY( VK_RCONTROL, GLUT_KEY_CTRL_R );
\r
2112 KEY( VK_LSHIFT, GLUT_KEY_SHIFT_L );
\r
2113 KEY( VK_RSHIFT, GLUT_KEY_SHIFT_R );
\r
2114 KEY( VK_LMENU, GLUT_KEY_ALT_L );
\r
2115 KEY( VK_RMENU, GLUT_KEY_ALT_R );
\r
2118 /* The delete key should be treated as an ASCII keypress: */
\r
2119 INVOKE_WCB( *window, Keyboard,
\r
2120 ( 127, window->State.MouseX, window->State.MouseY )
\r
2124 #if defined(_WIN32_WCE)
\r
2125 if(!(lParam & 0x40000000)) /* Prevent auto-repeat */
\r
2127 if(wParam==(unsigned)gxKeyList.vkRight)
\r
2128 keypress = GLUT_KEY_RIGHT;
\r
2129 else if(wParam==(unsigned)gxKeyList.vkLeft)
\r
2130 keypress = GLUT_KEY_LEFT;
\r
2131 else if(wParam==(unsigned)gxKeyList.vkUp)
\r
2132 keypress = GLUT_KEY_UP;
\r
2133 else if(wParam==(unsigned)gxKeyList.vkDown)
\r
2134 keypress = GLUT_KEY_DOWN;
\r
2135 else if(wParam==(unsigned)gxKeyList.vkA)
\r
2136 keypress = GLUT_KEY_F1;
\r
2137 else if(wParam==(unsigned)gxKeyList.vkB)
\r
2138 keypress = GLUT_KEY_F2;
\r
2139 else if(wParam==(unsigned)gxKeyList.vkC)
\r
2140 keypress = GLUT_KEY_F3;
\r
2141 else if(wParam==(unsigned)gxKeyList.vkStart)
\r
2142 keypress = GLUT_KEY_F4;
\r
2146 if( keypress != -1 )
\r
2147 INVOKE_WCB( *window, Special,
\r
2149 window->State.MouseX, window->State.MouseY )
\r
2152 fgState.Modifiers = INVALID_MODIFIERS;
\r
2159 int keypress = -1;
\r
2163 * Remember the current modifiers state. This is done here in order
\r
2164 * to make sure the VK_DELETE keyboard callback is executed properly.
\r
2166 fgState.Modifiers = fghGetWin32Modifiers( );
\r
2168 GetCursorPos( &mouse_pos );
\r
2169 ScreenToClient( window->Window.Handle, &mouse_pos );
\r
2171 window->State.MouseX = mouse_pos.x;
\r
2172 window->State.MouseY = mouse_pos.y;
\r
2175 * Convert the Win32 keystroke codes to GLUTtish way.
\r
2176 * "KEY(a,b)" was defined under "WM_KEYDOWN"
\r
2181 KEY( VK_F1, GLUT_KEY_F1 );
\r
2182 KEY( VK_F2, GLUT_KEY_F2 );
\r
2183 KEY( VK_F3, GLUT_KEY_F3 );
\r
2184 KEY( VK_F4, GLUT_KEY_F4 );
\r
2185 KEY( VK_F5, GLUT_KEY_F5 );
\r
2186 KEY( VK_F6, GLUT_KEY_F6 );
\r
2187 KEY( VK_F7, GLUT_KEY_F7 );
\r
2188 KEY( VK_F8, GLUT_KEY_F8 );
\r
2189 KEY( VK_F9, GLUT_KEY_F9 );
\r
2190 KEY( VK_F10, GLUT_KEY_F10 );
\r
2191 KEY( VK_F11, GLUT_KEY_F11 );
\r
2192 KEY( VK_F12, GLUT_KEY_F12 );
\r
2193 KEY( VK_PRIOR, GLUT_KEY_PAGE_UP );
\r
2194 KEY( VK_NEXT, GLUT_KEY_PAGE_DOWN );
\r
2195 KEY( VK_HOME, GLUT_KEY_HOME );
\r
2196 KEY( VK_END, GLUT_KEY_END );
\r
2197 KEY( VK_LEFT, GLUT_KEY_LEFT );
\r
2198 KEY( VK_UP, GLUT_KEY_UP );
\r
2199 KEY( VK_RIGHT, GLUT_KEY_RIGHT );
\r
2200 KEY( VK_DOWN, GLUT_KEY_DOWN );
\r
2201 KEY( VK_INSERT, GLUT_KEY_INSERT );
\r
2202 KEY( VK_LCONTROL, GLUT_KEY_CTRL_L );
\r
2203 KEY( VK_RCONTROL, GLUT_KEY_CTRL_R );
\r
2204 KEY( VK_LSHIFT, GLUT_KEY_SHIFT_L );
\r
2205 KEY( VK_RSHIFT, GLUT_KEY_SHIFT_R );
\r
2206 KEY( VK_LMENU, GLUT_KEY_ALT_L );
\r
2207 KEY( VK_RMENU, GLUT_KEY_ALT_R );
\r
2210 /* The delete key should be treated as an ASCII keypress: */
\r
2211 INVOKE_WCB( *window, KeyboardUp,
\r
2212 ( 127, window->State.MouseX, window->State.MouseY )
\r
2218 #if !defined(_WIN32_WCE)
\r
2219 BYTE state[ 256 ];
\r
2222 GetKeyboardState( state );
\r
2224 if( ToAscii( (UINT)wParam, 0, state, code, 0 ) == 1 )
\r
2227 INVOKE_WCB( *window, KeyboardUp,
\r
2229 window->State.MouseX, window->State.MouseY )
\r
2231 #endif /* !defined(_WIN32_WCE) */
\r
2235 if( keypress != -1 )
\r
2236 INVOKE_WCB( *window, SpecialUp,
\r
2238 window->State.MouseX, window->State.MouseY )
\r
2241 fgState.Modifiers = INVALID_MODIFIERS;
\r
2248 if( (fgState.KeyRepeat==GLUT_KEY_REPEAT_OFF || window->State.IgnoreKeyRepeat==GL_TRUE) && (HIWORD(lParam) & KF_REPEAT) )
\r
2251 fgState.Modifiers = fghGetWin32Modifiers( );
\r
2252 INVOKE_WCB( *window, Keyboard,
\r
2254 window->State.MouseX, window->State.MouseY )
\r
2256 fgState.Modifiers = INVALID_MODIFIERS;
\r
2260 case WM_CAPTURECHANGED:
\r
2261 /* User has finished resizing the window, force a redraw */
\r
2262 INVOKE_WCB( *window, Display, ( ) );
\r
2264 /*lRet = DefWindowProc( hWnd, uMsg, wParam, lParam ); */
\r
2267 /* Other messages that I have seen and which are not handled already */
\r
2268 case WM_SETTEXT: /* 0x000c */
\r
2269 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
\r
2270 /* Pass it on to "DefWindowProc" to set the window text */
\r
2273 case WM_GETTEXT: /* 0x000d */
\r
2274 /* Ideally we would copy the title of the window into "lParam" */
\r
2275 /* strncpy ( (char *)lParam, "Window Title", wParam );
\r
2276 lRet = ( wParam > 12 ) ? 12 : wParam; */
\r
2277 /* the number of characters copied */
\r
2278 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
\r
2281 case WM_GETTEXTLENGTH: /* 0x000e */
\r
2282 /* Ideally we would get the length of the title of the window */
\r
2284 /* the number of characters in "Window Title\0" (see above) */
\r
2287 case WM_ERASEBKGND: /* 0x0014 */
\r
2288 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
\r
2291 #if !defined(_WIN32_WCE)
\r
2292 case WM_SYNCPAINT: /* 0x0088 */
\r
2293 /* Another window has moved, need to update this one */
\r
2294 window->State.Redisplay = GL_TRUE;
\r
2295 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
\r
2296 /* Help screen says this message must be passed to "DefWindowProc" */
\r
2299 case WM_NCPAINT: /* 0x0085 */
\r
2300 /* Need to update the border of this window */
\r
2301 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
\r
2302 /* Pass it on to "DefWindowProc" to repaint a standard border */
\r
2305 case WM_SYSCOMMAND : /* 0x0112 */
\r
2308 * We have received a system command message. Try to act on it.
\r
2309 * The commands are passed in through the "wParam" parameter:
\r
2310 * The least significant digit seems to be which edge of the window
\r
2311 * is being used for a resize event:
\r
2315 * Congratulations and thanks to Richard Rauch for figuring this out..
\r
2317 switch ( wParam & 0xfff0 )
\r
2325 case SC_MINIMIZE :
\r
2326 /* User has clicked on the "-" to minimize the window */
\r
2327 /* Turn off the visibility */
\r
2328 window->State.Visible = GL_FALSE ;
\r
2332 case SC_MAXIMIZE :
\r
2335 case SC_NEXTWINDOW :
\r
2338 case SC_PREVWINDOW :
\r
2342 /* Followed very closely by a WM_CLOSE message */
\r
2351 case SC_MOUSEMENU :
\r
2363 case SC_TASKLIST :
\r
2366 case SC_SCREENSAVE :
\r
2372 #if(WINVER >= 0x0400)
\r
2376 case SC_MONITORPOWER :
\r
2379 case SC_CONTEXTHELP :
\r
2381 #endif /* WINVER >= 0x0400 */
\r
2385 fgWarning( "Unknown wParam type 0x%x", wParam );
\r
2390 #endif /* !defined(_WIN32_WCE) */
\r
2392 /* We need to pass the message on to the operating system as well */
\r
2393 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
\r
2397 /* handle multi-touch messages */
\r
2400 unsigned int numInputs = (unsigned int)wParam;
\r
2401 unsigned int i = 0;
\r
2402 TOUCHINPUT* ti = (TOUCHINPUT*)malloc( sizeof(TOUCHINPUT)*numInputs);
\r
2404 if (fghGetTouchInputInfo == (pGetTouchInputInfo)0xDEADBEEF) {
\r
2405 fghGetTouchInputInfo = (pGetTouchInputInfo)GetProcAddress(GetModuleHandle("user32"),"GetTouchInputInfo");
\r
2406 fghCloseTouchInputHandle = (pCloseTouchInputHandle)GetProcAddress(GetModuleHandle("user32"),"CloseTouchInputHandle");
\r
2409 if (!fghGetTouchInputInfo) {
\r
2410 free( (void*)ti );
\r
2414 if (fghGetTouchInputInfo( (HTOUCHINPUT)lParam, numInputs, ti, sizeof(TOUCHINPUT) )) {
\r
2415 /* Handle each contact point */
\r
2416 for (i = 0; i < numInputs; ++i ) {
\r
2419 tp.x = TOUCH_COORD_TO_PIXEL(ti[i].x);
\r
2420 tp.y = TOUCH_COORD_TO_PIXEL(ti[i].y);
\r
2421 ScreenToClient( hWnd, &tp );
\r
2423 ti[i].dwID = ti[i].dwID * 2;
\r
2425 if (ti[i].dwFlags & TOUCHEVENTF_DOWN) {
\r
2426 INVOKE_WCB( *window, MultiEntry, ( ti[i].dwID, GLUT_ENTERED ) );
\r
2427 INVOKE_WCB( *window, MultiButton, ( ti[i].dwID, tp.x, tp.y, 0, GLUT_DOWN ) );
\r
2428 } else if (ti[i].dwFlags & TOUCHEVENTF_MOVE) {
\r
2429 INVOKE_WCB( *window, MultiMotion, ( ti[i].dwID, tp.x, tp.y ) );
\r
2430 } else if (ti[i].dwFlags & TOUCHEVENTF_UP) {
\r
2431 INVOKE_WCB( *window, MultiButton, ( ti[i].dwID, tp.x, tp.y, 0, GLUT_UP ) );
\r
2432 INVOKE_WCB( *window, MultiEntry, ( ti[i].dwID, GLUT_LEFT ) );
\r
2436 fghCloseTouchInputHandle((HTOUCHINPUT)lParam);
\r
2437 free( (void*)ti );
\r
2438 lRet = 0; /*DefWindowProc( hWnd, uMsg, wParam, lParam );*/
\r
2443 /* Handle unhandled messages */
\r
2444 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
\r
2452 /*** END OF FILE ***/
\r