4 * The windows message processing methods.
6 * Copyright (c) 1999-2000 Pawel W. Olszta. All Rights Reserved.
7 * Written by Pawel W. Olszta, <olszta@sourceforge.net>
8 * Creation date: Fri Dec 3 1999
10 * Permission is hereby granted, free of charge, to any person obtaining a
11 * copy of this software and associated documentation files (the "Software"),
12 * to deal in the Software without restriction, including without limitation
13 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 * and/or sell copies of the Software, and to permit persons to whom the
15 * Software is furnished to do so, subject to the following conditions:
17 * The above copyright notice and this permission notice shall be included
18 * in all copies or substantial portions of the Software.
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23 * PAWEL W. OLSZTA BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
24 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
25 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 #include <GL/freeglut.h>
29 #include "freeglut_internal.h"
35 # define VFPRINTF(s,f,a) vfprintf((s),(f),(a))
36 #elif defined(HAVE__DOPRNT)
37 # define VFPRINTF(s,f,a) _doprnt((f),(a),(s))
39 # define VFPRINTF(s,f,a)
44 typedef struct GXDisplayProperties GXDisplayProperties;
45 typedef struct GXKeyList GXKeyList;
48 typedef struct GXKeyList (*GXGETDEFAULTKEYS)(int);
49 typedef int (*GXOPENINPUT)();
51 GXGETDEFAULTKEYS GXGetDefaultKeys_ = NULL;
52 GXOPENINPUT GXOpenInput_ = NULL;
54 struct GXKeyList gxKeyList;
56 #endif /* _WIN32_WCE */
59 * Try to get the maximum value allowed for ints, falling back to the minimum
60 * guaranteed by ISO C99 if there is no suitable header.
66 # define INT_MAX 32767
70 # define MIN(a,b) (((a)<(b)) ? (a) : (b))
74 typedef BOOL (WINAPI *pGetTouchInputInfo)(HTOUCHINPUT,UINT,PTOUCHINPUT,int);
75 typedef BOOL (WINAPI *pCloseTouchInputHandle)(HTOUCHINPUT);
76 static pGetTouchInputInfo fghGetTouchInputInfo = (pGetTouchInputInfo)0xDEADBEEF;
77 static pCloseTouchInputHandle fghCloseTouchInputHandle = (pCloseTouchInputHandle)0xDEADBEEF;
81 * TODO BEFORE THE STABLE RELEASE:
83 * There are some issues concerning window redrawing under X11, and maybe
84 * some events are not handled. The Win32 version lacks some more features,
85 * but seems acceptable for not demanding purposes.
87 * Need to investigate why the X11 version breaks out with an error when
88 * closing a window (using the window manager, not glutDestroyWindow)...
91 /* -- PRIVATE FUNCTIONS ---------------------------------------------------- */
94 * Handle a window configuration change. When no reshape
95 * callback is hooked, the viewport size is updated to
96 * match the new window size.
98 static void fghReshapeWindow ( SFG_Window *window, int width, int height )
100 SFG_Window *current_window = fgStructure.CurrentWindow;
102 freeglut_return_if_fail( window != NULL );
104 #if TARGET_HOST_POSIX_X11
106 XResizeWindow( fgDisplay.Display, window->Window.Handle,
108 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
110 #elif TARGET_HOST_MS_WINDOWS && !defined(_WIN32_WCE)
116 * For windowed mode, get the current position of the
117 * window and resize taking the size of the frame
118 * decorations into account.
121 /* "GetWindowRect" returns the pixel coordinates of the outside of the window */
122 GetWindowRect( window->Window.Handle, &winRect );
128 if ( window->Parent == NULL )
130 if ( ! window->IsMenu && (window != fgStructure.GameModeWindow) &&
131 !( fgState.DisplayMode & GLUT_BORDERLESS ))
133 w += GetSystemMetrics( SM_CXSIZEFRAME ) * 2;
134 h += GetSystemMetrics( SM_CYSIZEFRAME ) * 2 +
135 GetSystemMetrics( SM_CYCAPTION );
141 GetWindowRect( window->Parent->Window.Handle, &parentRect );
142 x -= parentRect.left + GetSystemMetrics( SM_CXSIZEFRAME ) * 2;
143 y -= parentRect.top + GetSystemMetrics( SM_CYSIZEFRAME ) * 2 +
144 GetSystemMetrics( SM_CYCAPTION );
148 * SWP_NOACTIVATE Do not activate the window
149 * SWP_NOOWNERZORDER Do not change position in z-order
150 * SWP_NOSENDCHANGING Supress WM_WINDOWPOSCHANGING message
151 * SWP_NOZORDER Retains the current Z order (ignore 2nd param)
154 SetWindowPos( window->Window.Handle,
157 SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOSENDCHANGING |
164 * XXX Should update {window->State.OldWidth, window->State.OldHeight}
165 * XXX to keep in lockstep with POSIX_X11 code.
167 if( FETCH_WCB( *window, Reshape ) )
168 INVOKE_WCB( *window, Reshape, ( width, height ) );
171 fgSetWindow( window );
172 glViewport( 0, 0, width, height );
176 * Force a window redraw. In Windows at least this is only a partial
177 * solution: if the window is increasing in size in either dimension,
178 * the already-drawn part does not get drawn again and things look funny.
179 * But without this we get this bad behaviour whenever we resize the
182 window->State.Redisplay = GL_TRUE;
185 fgSetWindow( current_window );
189 * Calls a window's redraw method. This is used when
190 * a redraw is forced by the incoming window messages.
192 static void fghRedrawWindow ( SFG_Window *window )
194 SFG_Window *current_window = fgStructure.CurrentWindow;
196 freeglut_return_if_fail( window );
197 freeglut_return_if_fail( FETCH_WCB ( *window, Display ) );
199 window->State.Redisplay = GL_FALSE;
201 freeglut_return_if_fail( window->State.Visible );
203 fgSetWindow( window );
205 if( window->State.NeedToResize )
213 window->State.NeedToResize = GL_FALSE;
216 INVOKE_WCB( *window, Display, ( ) );
218 fgSetWindow( current_window );
222 * A static helper function to execute display callback for a window
224 static void fghcbDisplayWindow( SFG_Window *window,
225 SFG_Enumerator *enumerator )
227 if( window->State.Redisplay &&
228 window->State.Visible )
230 window->State.Redisplay = GL_FALSE;
232 #if TARGET_HOST_POSIX_X11
233 fghRedrawWindow ( window ) ;
234 #elif TARGET_HOST_MS_WINDOWS
237 window->Window.Handle, NULL, NULL,
238 RDW_NOERASE | RDW_INTERNALPAINT | RDW_INVALIDATE | RDW_UPDATENOW
243 fgEnumSubWindows( window, fghcbDisplayWindow, enumerator );
247 * Make all windows perform a display call
249 static void fghDisplayAll( void )
251 SFG_Enumerator enumerator;
253 enumerator.found = GL_FALSE;
254 enumerator.data = NULL;
256 fgEnumWindows( fghcbDisplayWindow, &enumerator );
260 * Window enumerator callback to check for the joystick polling code
262 static void fghcbCheckJoystickPolls( SFG_Window *window,
263 SFG_Enumerator *enumerator )
265 long int checkTime = fgElapsedTime( );
267 if( window->State.JoystickLastPoll + window->State.JoystickPollRate <=
270 #if !defined(_WIN32_WCE)
271 fgJoystickPollWindow( window );
272 #endif /* !defined(_WIN32_WCE) */
273 window->State.JoystickLastPoll = checkTime;
276 fgEnumSubWindows( window, fghcbCheckJoystickPolls, enumerator );
280 * Check all windows for joystick polling
282 static void fghCheckJoystickPolls( void )
284 SFG_Enumerator enumerator;
286 enumerator.found = GL_FALSE;
287 enumerator.data = NULL;
289 fgEnumWindows( fghcbCheckJoystickPolls, &enumerator );
293 * Check the global timers
295 static void fghCheckTimers( void )
297 long checkTime = fgElapsedTime( );
299 while( fgState.Timers.First )
301 SFG_Timer *timer = fgState.Timers.First;
303 if( timer->TriggerTime > checkTime )
306 fgListRemove( &fgState.Timers, &timer->Node );
307 fgListAppend( &fgState.FreeTimers, &timer->Node );
309 timer->Callback( timer->ID );
314 /* Platform-dependent time in milliseconds, as an unsigned 32-bit integer.
315 * This value wraps every 49.7 days, but integer overflows cancel
316 * when subtracting an initial start time, unless the total time exceeds
317 * 32-bit, where the GLUT API return value is also overflowed.
319 unsigned long fgSystemTime(void) {
320 #if TARGET_HOST_SOLARIS || HAVE_GETTIMEOFDAY
322 gettimeofday( &now, NULL );
323 return now.tv_usec/1000 + now.tv_sec*1000;
324 #elif TARGET_HOST_MS_WINDOWS
325 # if defined(_WIN32_WCE)
326 return GetTickCount();
328 return timeGetTime();
336 long fgElapsedTime( void )
338 return (long) (fgSystemTime() - fgState.Time);
344 void fgError( const char *fmt, ... )
348 if (fgState.ErrorFunc) {
352 /* call user set error handler here */
353 fgState.ErrorFunc(fmt, ap);
361 fprintf( stderr, "freeglut ");
362 if( fgState.ProgramName )
363 fprintf( stderr, "(%s): ", fgState.ProgramName );
364 VFPRINTF( stderr, fmt, ap );
365 fprintf( stderr, "\n" );
369 if ( fgState.Initialised )
376 void fgWarning( const char *fmt, ... )
380 if (fgState.WarningFunc) {
384 /* call user set warning handler here */
385 fgState.WarningFunc(fmt, ap);
393 fprintf( stderr, "freeglut ");
394 if( fgState.ProgramName )
395 fprintf( stderr, "(%s): ", fgState.ProgramName );
396 VFPRINTF( stderr, fmt, ap );
397 fprintf( stderr, "\n" );
405 * Indicates whether Joystick events are being used by ANY window.
407 * The current mechanism is to walk all of the windows and ask if
408 * there is a joystick callback. We have a short-circuit early
409 * return if we find any joystick handler registered.
411 * The real way to do this is to make use of the glutTimer() API
412 * to more cleanly re-implement the joystick API. Then, this code
413 * and all other "joystick timer" code can be yanked.
416 static void fghCheckJoystickCallback( SFG_Window* w, SFG_Enumerator* e)
418 if( FETCH_WCB( *w, Joystick ) )
423 fgEnumSubWindows( w, fghCheckJoystickCallback, e );
425 static int fghHaveJoystick( void )
427 SFG_Enumerator enumerator;
429 enumerator.found = GL_FALSE;
430 enumerator.data = NULL;
431 fgEnumWindows( fghCheckJoystickCallback, &enumerator );
432 return !!enumerator.data;
434 static void fghHavePendingRedisplaysCallback( SFG_Window* w, SFG_Enumerator* e)
436 if( w->State.Redisplay && w->State.Visible )
441 fgEnumSubWindows( w, fghHavePendingRedisplaysCallback, e );
443 static int fghHavePendingRedisplays (void)
445 SFG_Enumerator enumerator;
447 enumerator.found = GL_FALSE;
448 enumerator.data = NULL;
449 fgEnumWindows( fghHavePendingRedisplaysCallback, &enumerator );
450 return !!enumerator.data;
453 * Returns the number of GLUT ticks (milliseconds) till the next timer event.
455 static long fghNextTimer( void )
458 SFG_Timer *timer = fgState.Timers.First;
461 ret = timer->TriggerTime - fgElapsedTime();
468 * Does the magic required to relinquish the CPU until something interesting
471 static void fghSleepForEvents( void )
475 if( fgState.IdleCallback || fghHavePendingRedisplays( ) )
478 msec = fghNextTimer( );
479 /* XXX Use GLUT timers for joysticks... */
480 /* XXX Dumb; forces granularity to .01sec */
481 if( fghHaveJoystick( ) && ( msec > 10 ) )
484 #if TARGET_HOST_POSIX_X11
486 * Possibly due to aggressive use of XFlush() and friends,
487 * it is possible to have our socket drained but still have
488 * unprocessed events. (Or, this may just be normal with
489 * X, anyway?) We do non-trivial processing of X events
490 * after the event-reading loop, in any case, so we
491 * need to allow that we may have an empty socket but non-
494 if( ! XPending( fgDisplay.Display ) )
501 socket = ConnectionNumber( fgDisplay.Display );
503 FD_SET( socket, &fdset );
504 wait.tv_sec = msec / 1000;
505 wait.tv_usec = (msec % 1000) * 1000;
506 err = select( socket+1, &fdset, NULL, NULL, &wait );
509 if( ( -1 == err ) && ( errno != EINTR ) )
510 fgWarning ( "freeglut select() error: %d", errno );
513 #elif TARGET_HOST_MS_WINDOWS
514 MsgWaitForMultipleObjects( 0, NULL, FALSE, msec, QS_ALLINPUT );
518 #if TARGET_HOST_POSIX_X11
520 * Returns GLUT modifier mask for the state field of an X11 event.
522 int fghGetXModifiers( int state )
526 if( state & ( ShiftMask | LockMask ) )
527 ret |= GLUT_ACTIVE_SHIFT;
528 if( state & ControlMask )
529 ret |= GLUT_ACTIVE_CTRL;
530 if( state & Mod1Mask )
531 ret |= GLUT_ACTIVE_ALT;
538 #if TARGET_HOST_POSIX_X11 && _DEBUG
540 static const char* fghTypeToString( int type )
543 case KeyPress: return "KeyPress";
544 case KeyRelease: return "KeyRelease";
545 case ButtonPress: return "ButtonPress";
546 case ButtonRelease: return "ButtonRelease";
547 case MotionNotify: return "MotionNotify";
548 case EnterNotify: return "EnterNotify";
549 case LeaveNotify: return "LeaveNotify";
550 case FocusIn: return "FocusIn";
551 case FocusOut: return "FocusOut";
552 case KeymapNotify: return "KeymapNotify";
553 case Expose: return "Expose";
554 case GraphicsExpose: return "GraphicsExpose";
555 case NoExpose: return "NoExpose";
556 case VisibilityNotify: return "VisibilityNotify";
557 case CreateNotify: return "CreateNotify";
558 case DestroyNotify: return "DestroyNotify";
559 case UnmapNotify: return "UnmapNotify";
560 case MapNotify: return "MapNotify";
561 case MapRequest: return "MapRequest";
562 case ReparentNotify: return "ReparentNotify";
563 case ConfigureNotify: return "ConfigureNotify";
564 case ConfigureRequest: return "ConfigureRequest";
565 case GravityNotify: return "GravityNotify";
566 case ResizeRequest: return "ResizeRequest";
567 case CirculateNotify: return "CirculateNotify";
568 case CirculateRequest: return "CirculateRequest";
569 case PropertyNotify: return "PropertyNotify";
570 case SelectionClear: return "SelectionClear";
571 case SelectionRequest: return "SelectionRequest";
572 case SelectionNotify: return "SelectionNotify";
573 case ColormapNotify: return "ColormapNotify";
574 case ClientMessage: return "ClientMessage";
575 case MappingNotify: return "MappingNotify";
576 default: return "UNKNOWN";
580 static const char* fghBoolToString( Bool b )
582 return b == False ? "False" : "True";
585 static const char* fghNotifyHintToString( char is_hint )
588 case NotifyNormal: return "NotifyNormal";
589 case NotifyHint: return "NotifyHint";
590 default: return "UNKNOWN";
594 static const char* fghNotifyModeToString( int mode )
597 case NotifyNormal: return "NotifyNormal";
598 case NotifyGrab: return "NotifyGrab";
599 case NotifyUngrab: return "NotifyUngrab";
600 case NotifyWhileGrabbed: return "NotifyWhileGrabbed";
601 default: return "UNKNOWN";
605 static const char* fghNotifyDetailToString( int detail )
608 case NotifyAncestor: return "NotifyAncestor";
609 case NotifyVirtual: return "NotifyVirtual";
610 case NotifyInferior: return "NotifyInferior";
611 case NotifyNonlinear: return "NotifyNonlinear";
612 case NotifyNonlinearVirtual: return "NotifyNonlinearVirtual";
613 case NotifyPointer: return "NotifyPointer";
614 case NotifyPointerRoot: return "NotifyPointerRoot";
615 case NotifyDetailNone: return "NotifyDetailNone";
616 default: return "UNKNOWN";
620 static const char* fghVisibilityToString( int state ) {
622 case VisibilityUnobscured: return "VisibilityUnobscured";
623 case VisibilityPartiallyObscured: return "VisibilityPartiallyObscured";
624 case VisibilityFullyObscured: return "VisibilityFullyObscured";
625 default: return "UNKNOWN";
629 static const char* fghConfigureDetailToString( int detail )
632 case Above: return "Above";
633 case Below: return "Below";
634 case TopIf: return "TopIf";
635 case BottomIf: return "BottomIf";
636 case Opposite: return "Opposite";
637 default: return "UNKNOWN";
641 static const char* fghPlaceToString( int place )
644 case PlaceOnTop: return "PlaceOnTop";
645 case PlaceOnBottom: return "PlaceOnBottom";
646 default: return "UNKNOWN";
650 static const char* fghMappingRequestToString( int request )
653 case MappingModifier: return "MappingModifier";
654 case MappingKeyboard: return "MappingKeyboard";
655 case MappingPointer: return "MappingPointer";
656 default: return "UNKNOWN";
660 static const char* fghPropertyStateToString( int state )
663 case PropertyNewValue: return "PropertyNewValue";
664 case PropertyDelete: return "PropertyDelete";
665 default: return "UNKNOWN";
669 static const char* fghColormapStateToString( int state )
672 case ColormapUninstalled: return "ColormapUninstalled";
673 case ColormapInstalled: return "ColormapInstalled";
674 default: return "UNKNOWN";
678 static void fghPrintEvent( XEvent *event )
680 switch( event->type ) {
684 XKeyEvent *e = &event->xkey;
685 fgWarning( "%s: window=0x%x, root=0x%x, subwindow=0x%x, time=%lu, "
686 "(x,y)=(%d,%d), (x_root,y_root)=(%d,%d), state=0x%x, "
687 "keycode=%u, same_screen=%s", fghTypeToString( e->type ),
688 e->window, e->root, e->subwindow, (unsigned long)e->time,
689 e->x, e->y, e->x_root, e->y_root, e->state, e->keycode,
690 fghBoolToString( e->same_screen ) );
695 case ButtonRelease: {
696 XButtonEvent *e = &event->xbutton;
697 fgWarning( "%s: window=0x%x, root=0x%x, subwindow=0x%x, time=%lu, "
698 "(x,y)=(%d,%d), (x_root,y_root)=(%d,%d), state=0x%x, "
699 "button=%u, same_screen=%d", fghTypeToString( e->type ),
700 e->window, e->root, e->subwindow, (unsigned long)e->time,
701 e->x, e->y, e->x_root, e->y_root, e->state, e->button,
702 fghBoolToString( e->same_screen ) );
707 XMotionEvent *e = &event->xmotion;
708 fgWarning( "%s: window=0x%x, root=0x%x, subwindow=0x%x, time=%lu, "
709 "(x,y)=(%d,%d), (x_root,y_root)=(%d,%d), state=0x%x, "
710 "is_hint=%s, same_screen=%d", fghTypeToString( e->type ),
711 e->window, e->root, e->subwindow, (unsigned long)e->time,
712 e->x, e->y, e->x_root, e->y_root, e->state,
713 fghNotifyHintToString( e->is_hint ),
714 fghBoolToString( e->same_screen ) );
720 XCrossingEvent *e = &event->xcrossing;
721 fgWarning( "%s: window=0x%x, root=0x%x, subwindow=0x%x, time=%lu, "
722 "(x,y)=(%d,%d), mode=%s, detail=%s, same_screen=%d, "
723 "focus=%d, state=0x%x", fghTypeToString( e->type ),
724 e->window, e->root, e->subwindow, (unsigned long)e->time,
725 e->x, e->y, fghNotifyModeToString( e->mode ),
726 fghNotifyDetailToString( e->detail ), (int)e->same_screen,
727 (int)e->focus, e->state );
733 XFocusChangeEvent *e = &event->xfocus;
734 fgWarning( "%s: window=0x%x, mode=%s, detail=%s",
735 fghTypeToString( e->type ), e->window,
736 fghNotifyModeToString( e->mode ),
737 fghNotifyDetailToString( e->detail ) );
742 XKeymapEvent *e = &event->xkeymap;
743 char buf[32 * 2 + 1];
745 for ( i = 0; i < 32; i++ ) {
746 snprintf( &buf[ i * 2 ], sizeof( buf ) - i * 2,
747 "%02x", e->key_vector[ i ] );
750 fgWarning( "%s: window=0x%x, %s", fghTypeToString( e->type ), e->window,
756 XExposeEvent *e = &event->xexpose;
757 fgWarning( "%s: window=0x%x, (x,y)=(%d,%d), (width,height)=(%d,%d), "
758 "count=%d", fghTypeToString( e->type ), e->window, e->x,
759 e->y, e->width, e->height, e->count );
763 case GraphicsExpose: {
764 XGraphicsExposeEvent *e = &event->xgraphicsexpose;
765 fgWarning( "%s: drawable=0x%x, (x,y)=(%d,%d), (width,height)=(%d,%d), "
766 "count=%d, (major_code,minor_code)=(%d,%d)",
767 fghTypeToString( e->type ), e->drawable, e->x, e->y,
768 e->width, e->height, e->count, e->major_code,
774 XNoExposeEvent *e = &event->xnoexpose;
775 fgWarning( "%s: drawable=0x%x, (major_code,minor_code)=(%d,%d)",
776 fghTypeToString( e->type ), e->drawable, e->major_code,
781 case VisibilityNotify: {
782 XVisibilityEvent *e = &event->xvisibility;
783 fgWarning( "%s: window=0x%x, state=%s", fghTypeToString( e->type ),
784 e->window, fghVisibilityToString( e->state) );
789 XCreateWindowEvent *e = &event->xcreatewindow;
790 fgWarning( "%s: (x,y)=(%d,%d), (width,height)=(%d,%d), border_width=%d, "
791 "window=0x%x, override_redirect=%s",
792 fghTypeToString( e->type ), e->x, e->y, e->width, e->height,
793 e->border_width, e->window,
794 fghBoolToString( e->override_redirect ) );
798 case DestroyNotify: {
799 XDestroyWindowEvent *e = &event->xdestroywindow;
800 fgWarning( "%s: event=0x%x, window=0x%x",
801 fghTypeToString( e->type ), e->event, e->window );
806 XUnmapEvent *e = &event->xunmap;
807 fgWarning( "%s: event=0x%x, window=0x%x, from_configure=%s",
808 fghTypeToString( e->type ), e->event, e->window,
809 fghBoolToString( e->from_configure ) );
814 XMapEvent *e = &event->xmap;
815 fgWarning( "%s: event=0x%x, window=0x%x, override_redirect=%s",
816 fghTypeToString( e->type ), e->event, e->window,
817 fghBoolToString( e->override_redirect ) );
822 XMapRequestEvent *e = &event->xmaprequest;
823 fgWarning( "%s: parent=0x%x, window=0x%x",
824 fghTypeToString( event->type ), e->parent, e->window );
828 case ReparentNotify: {
829 XReparentEvent *e = &event->xreparent;
830 fgWarning( "%s: event=0x%x, window=0x%x, parent=0x%x, (x,y)=(%d,%d), "
831 "override_redirect=%s", fghTypeToString( e->type ),
832 e->event, e->window, e->parent, e->x, e->y,
833 fghBoolToString( e->override_redirect ) );
837 case ConfigureNotify: {
838 XConfigureEvent *e = &event->xconfigure;
839 fgWarning( "%s: event=0x%x, window=0x%x, (x,y)=(%d,%d), "
840 "(width,height)=(%d,%d), border_width=%d, above=0x%x, "
841 "override_redirect=%s", fghTypeToString( e->type ), e->event,
842 e->window, e->x, e->y, e->width, e->height, e->border_width,
843 e->above, fghBoolToString( e->override_redirect ) );
847 case ConfigureRequest: {
848 XConfigureRequestEvent *e = &event->xconfigurerequest;
849 fgWarning( "%s: parent=0x%x, window=0x%x, (x,y)=(%d,%d), "
850 "(width,height)=(%d,%d), border_width=%d, above=0x%x, "
851 "detail=%s, value_mask=%lx", fghTypeToString( e->type ),
852 e->parent, e->window, e->x, e->y, e->width, e->height,
853 e->border_width, e->above,
854 fghConfigureDetailToString( e->detail ), e->value_mask );
858 case GravityNotify: {
859 XGravityEvent *e = &event->xgravity;
860 fgWarning( "%s: event=0x%x, window=0x%x, (x,y)=(%d,%d)",
861 fghTypeToString( e->type ), e->event, e->window, e->x, e->y );
865 case ResizeRequest: {
866 XResizeRequestEvent *e = &event->xresizerequest;
867 fgWarning( "%s: window=0x%x, (width,height)=(%d,%d)",
868 fghTypeToString( e->type ), e->window, e->width, e->height );
872 case CirculateNotify: {
873 XCirculateEvent *e = &event->xcirculate;
874 fgWarning( "%s: event=0x%x, window=0x%x, place=%s",
875 fghTypeToString( e->type ), e->event, e->window,
876 fghPlaceToString( e->place ) );
880 case CirculateRequest: {
881 XCirculateRequestEvent *e = &event->xcirculaterequest;
882 fgWarning( "%s: parent=0x%x, window=0x%x, place=%s",
883 fghTypeToString( e->type ), e->parent, e->window,
884 fghPlaceToString( e->place ) );
888 case PropertyNotify: {
889 XPropertyEvent *e = &event->xproperty;
890 fgWarning( "%s: window=0x%x, atom=%lu, time=%lu, state=%s",
891 fghTypeToString( e->type ), e->window,
892 (unsigned long)e->atom, (unsigned long)e->time,
893 fghPropertyStateToString( e->state ) );
897 case SelectionClear: {
898 XSelectionClearEvent *e = &event->xselectionclear;
899 fgWarning( "%s: window=0x%x, selection=%lu, time=%lu",
900 fghTypeToString( e->type ), e->window,
901 (unsigned long)e->selection, (unsigned long)e->time );
905 case SelectionRequest: {
906 XSelectionRequestEvent *e = &event->xselectionrequest;
907 fgWarning( "%s: owner=0x%x, requestor=0x%x, selection=0x%x, "
908 "target=0x%x, property=%lu, time=%lu",
909 fghTypeToString( e->type ), e->owner, e->requestor,
910 (unsigned long)e->selection, (unsigned long)e->target,
911 (unsigned long)e->property, (unsigned long)e->time );
915 case SelectionNotify: {
916 XSelectionEvent *e = &event->xselection;
917 fgWarning( "%s: requestor=0x%x, selection=0x%x, target=0x%x, "
918 "property=%lu, time=%lu", fghTypeToString( e->type ),
919 e->requestor, (unsigned long)e->selection,
920 (unsigned long)e->target, (unsigned long)e->property,
921 (unsigned long)e->time );
925 case ColormapNotify: {
926 XColormapEvent *e = &event->xcolormap;
927 fgWarning( "%s: window=0x%x, colormap=%lu, new=%s, state=%s",
928 fghTypeToString( e->type ), e->window,
929 (unsigned long)e->colormap, fghBoolToString( e->new ),
930 fghColormapStateToString( e->state ) );
934 case ClientMessage: {
935 XClientMessageEvent *e = &event->xclient;
938 char* end = buf + sizeof( buf );
940 switch( e->format ) {
942 for ( i = 0; i < 20; i++, p += 3 ) {
943 snprintf( p, end - p, " %02x", e->data.b[ i ] );
947 for ( i = 0; i < 10; i++, p += 5 ) {
948 snprintf( p, end - p, " %04x", e->data.s[ i ] );
952 for ( i = 0; i < 5; i++, p += 9 ) {
953 snprintf( p, end - p, " %08lx", e->data.l[ i ] );
958 fgWarning( "%s: window=0x%x, message_type=%lu, format=%d, data=(%s )",
959 fghTypeToString( e->type ), e->window,
960 (unsigned long)e->message_type, e->format, buf );
964 case MappingNotify: {
965 XMappingEvent *e = &event->xmapping;
966 fgWarning( "%s: window=0x%x, request=%s, first_keycode=%d, count=%d",
967 fghTypeToString( e->type ), e->window,
968 fghMappingRequestToString( e->request ), e->first_keycode,
974 fgWarning( "%s", fghTypeToString( event->type ) );
982 /* -- INTERFACE FUNCTIONS -------------------------------------------------- */
985 * Executes a single iteration in the freeglut processing loop.
987 void FGAPIENTRY glutMainLoopEvent( void )
989 #if TARGET_HOST_POSIX_X11
993 /* This code was repeated constantly, so here it goes into a definition: */
994 #define GETWINDOW(a) \
995 window = fgWindowByHandle( event.a.window ); \
996 if( window == NULL ) \
999 #define GETMOUSE(a) \
1000 window->State.MouseX = event.a.x; \
1001 window->State.MouseY = event.a.y;
1003 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutMainLoopEvent" );
1005 while( XPending( fgDisplay.Display ) )
1007 XNextEvent( fgDisplay.Display, &event );
1009 fghPrintEvent( &event );
1012 switch( event.type )
1015 if(fgIsSpaceballXEvent(&event)) {
1016 fgSpaceballHandleXEvent(&event);
1019 /* Destroy the window when the WM_DELETE_WINDOW message arrives */
1020 if( (Atom) event.xclient.data.l[ 0 ] == fgDisplay.DeleteWindow )
1022 GETWINDOW( xclient );
1024 fgDestroyWindow ( window );
1026 if( fgState.ActionOnWindowClose == GLUT_ACTION_EXIT )
1031 else if( fgState.ActionOnWindowClose == GLUT_ACTION_GLUTMAINLOOP_RETURNS )
1032 fgState.ExecState = GLUT_EXEC_STATE_STOP;
1039 * CreateNotify causes a configure-event so that sub-windows are
1040 * handled compatibly with GLUT. Otherwise, your sub-windows
1041 * (in freeglut only) will not get an initial reshape event,
1042 * which can break things.
1044 * GLUT presumably does this because it generally tries to treat
1045 * sub-windows the same as windows.
1048 case ConfigureNotify:
1051 if( event.type == CreateNotify ) {
1052 GETWINDOW( xcreatewindow );
1053 width = event.xcreatewindow.width;
1054 height = event.xcreatewindow.height;
1056 GETWINDOW( xconfigure );
1057 width = event.xconfigure.width;
1058 height = event.xconfigure.height;
1061 if( ( width != window->State.OldWidth ) ||
1062 ( height != window->State.OldHeight ) )
1064 SFG_Window *current_window = fgStructure.CurrentWindow;
1066 window->State.OldWidth = width;
1067 window->State.OldHeight = height;
1068 if( FETCH_WCB( *window, Reshape ) )
1069 INVOKE_WCB( *window, Reshape, ( width, height ) );
1072 fgSetWindow( window );
1073 glViewport( 0, 0, width, height );
1075 glutPostRedisplay( );
1076 if( window->IsMenu )
1077 fgSetWindow( current_window );
1084 * This is sent to confirm the XDestroyWindow call.
1086 * XXX WHY is this commented out? Should we re-enable it?
1088 /* fgAddToWindowDestroyList ( window ); */
1093 * We are too dumb to process partial exposes...
1095 * XXX Well, we could do it. However, it seems to only
1096 * XXX be potentially useful for single-buffered (since
1097 * XXX double-buffered does not respect viewport when we
1098 * XXX do a buffer-swap).
1101 if( event.xexpose.count == 0 )
1103 GETWINDOW( xexpose );
1104 window->State.Redisplay = GL_TRUE;
1112 /* We get this when iconifying a window. */
1113 GETWINDOW( xunmap );
1114 INVOKE_WCB( *window, WindowStatus, ( GLUT_HIDDEN ) );
1115 window->State.Visible = GL_FALSE;
1120 * Have the client's keyboard knowledge updated (xlib.ps,
1121 * page 206, says that's a good thing to do)
1123 XRefreshKeyboardMapping( (XMappingEvent *) &event );
1126 case VisibilityNotify:
1129 * Sending this event, the X server can notify us that the window
1130 * has just acquired one of the three possible visibility states:
1131 * VisibilityUnobscured, VisibilityPartiallyObscured or
1132 * VisibilityFullyObscured. Note that we DO NOT receive a
1133 * VisibilityNotify event when iconifying a window, we only get an
1136 GETWINDOW( xvisibility );
1137 switch( event.xvisibility.state )
1139 case VisibilityUnobscured:
1140 INVOKE_WCB( *window, WindowStatus, ( GLUT_FULLY_RETAINED ) );
1141 window->State.Visible = GL_TRUE;
1144 case VisibilityPartiallyObscured:
1145 INVOKE_WCB( *window, WindowStatus,
1146 ( GLUT_PARTIALLY_RETAINED ) );
1147 window->State.Visible = GL_TRUE;
1150 case VisibilityFullyObscured:
1151 INVOKE_WCB( *window, WindowStatus, ( GLUT_FULLY_COVERED ) );
1152 window->State.Visible = GL_FALSE;
1156 fgWarning( "Unknown X visibility state: %d",
1157 event.xvisibility.state );
1165 GETWINDOW( xcrossing );
1166 GETMOUSE( xcrossing );
1167 if( ( event.type == LeaveNotify ) && window->IsMenu &&
1168 window->ActiveMenu && window->ActiveMenu->IsActive )
1169 fgUpdateMenuHighlight( window->ActiveMenu );
1171 INVOKE_WCB( *window, Entry, ( ( EnterNotify == event.type ) ?
1178 GETWINDOW( xmotion );
1179 GETMOUSE( xmotion );
1181 if( window->ActiveMenu )
1183 if( window == window->ActiveMenu->ParentWindow )
1185 window->ActiveMenu->Window->State.MouseX =
1186 event.xmotion.x_root - window->ActiveMenu->X;
1187 window->ActiveMenu->Window->State.MouseY =
1188 event.xmotion.y_root - window->ActiveMenu->Y;
1191 fgUpdateMenuHighlight( window->ActiveMenu );
1197 * XXX For more than 5 buttons, just check {event.xmotion.state},
1198 * XXX rather than a host of bit-masks? Or maybe we need to
1199 * XXX track ButtonPress/ButtonRelease events in our own
1202 fgState.Modifiers = fghGetXModifiers( event.xmotion.state );
1203 if ( event.xmotion.state & ( Button1Mask | Button2Mask | Button3Mask | Button4Mask | Button5Mask ) ) {
1204 INVOKE_WCB( *window, Motion, ( event.xmotion.x,
1205 event.xmotion.y ) );
1207 INVOKE_WCB( *window, Passive, ( event.xmotion.x,
1208 event.xmotion.y ) );
1210 fgState.Modifiers = INVALID_MODIFIERS;
1217 GLboolean pressed = GL_TRUE;
1220 if( event.type == ButtonRelease )
1221 pressed = GL_FALSE ;
1224 * A mouse button has been pressed or released. Traditionally,
1225 * break if the window was found within the freeglut structures.
1227 GETWINDOW( xbutton );
1228 GETMOUSE( xbutton );
1231 * An X button (at least in XFree86) is numbered from 1.
1232 * A GLUT button is numbered from 0.
1233 * Old GLUT passed through buttons other than just the first
1234 * three, though it only gave symbolic names and official
1235 * support to the first three.
1237 button = event.xbutton.button - 1;
1240 * Do not execute the application's mouse callback if a menu
1241 * is hooked to this button. In that case an appropriate
1242 * private call should be generated.
1244 if( fgCheckActiveMenu( window, button, pressed,
1245 event.xbutton.x_root, event.xbutton.y_root ) )
1249 * Check if there is a mouse or mouse wheel callback hooked to the
1252 if( ! FETCH_WCB( *window, Mouse ) &&
1253 ! FETCH_WCB( *window, MouseWheel ) )
1256 fgState.Modifiers = fghGetXModifiers( event.xbutton.state );
1258 /* Finally execute the mouse or mouse wheel callback */
1259 if( ( button < glutDeviceGet ( GLUT_NUM_MOUSE_BUTTONS ) ) || ( ! FETCH_WCB( *window, MouseWheel ) ) )
1260 INVOKE_WCB( *window, Mouse, ( button,
1261 pressed ? GLUT_DOWN : GLUT_UP,
1268 * Map 4 and 5 to wheel zero; EVEN to +1, ODD to -1
1269 * " 6 and 7 " " one; ...
1271 * XXX This *should* be behind some variables/macros,
1272 * XXX since the order and numbering isn't certain
1273 * XXX See XFree86 configuration docs (even back in the
1274 * XXX 3.x days, and especially with 4.x).
1276 * XXX Note that {button} has already been decremented
1277 * XXX in mapping from X button numbering to GLUT.
1279 * XXX Should add support for partial wheel turns as Windows does -- 5/27/11
1281 int wheel_number = (button - glutDeviceGet ( GLUT_NUM_MOUSE_BUTTONS )) / 2;
1287 INVOKE_WCB( *window, MouseWheel, ( wheel_number,
1293 fgState.Modifiers = INVALID_MODIFIERS;
1300 FGCBKeyboard keyboard_cb;
1301 FGCBSpecial special_cb;
1306 /* Detect auto repeated keys, if configured globally or per-window */
1308 if ( fgState.KeyRepeat==GLUT_KEY_REPEAT_OFF || window->State.IgnoreKeyRepeat==GL_TRUE )
1310 if (event.type==KeyRelease)
1313 * Look at X11 keystate to detect repeat mode.
1314 * While X11 says the key is actually held down, we'll ignore KeyRelease/KeyPress pairs.
1318 XQueryKeymap( fgDisplay.Display, keys ); /* Look at X11 keystate to detect repeat mode */
1320 if ( event.xkey.keycode<256 ) /* XQueryKeymap is limited to 256 keycodes */
1322 if ( keys[event.xkey.keycode>>3] & (1<<(event.xkey.keycode%8)) )
1323 window->State.KeyRepeating = GL_TRUE;
1325 window->State.KeyRepeating = GL_FALSE;
1330 window->State.KeyRepeating = GL_FALSE;
1332 /* Cease processing this event if it is auto repeated */
1334 if (window->State.KeyRepeating)
1336 if (event.type == KeyPress) window->State.KeyRepeating = GL_FALSE;
1340 if( event.type == KeyPress )
1342 keyboard_cb = (FGCBKeyboard)( FETCH_WCB( *window, Keyboard ));
1343 special_cb = (FGCBSpecial) ( FETCH_WCB( *window, Special ));
1347 keyboard_cb = (FGCBKeyboard)( FETCH_WCB( *window, KeyboardUp ));
1348 special_cb = (FGCBSpecial) ( FETCH_WCB( *window, SpecialUp ));
1351 /* Is there a keyboard/special callback hooked for this window? */
1352 if( keyboard_cb || special_cb )
1354 XComposeStatus composeStatus;
1355 char asciiCode[ 32 ];
1359 /* Check for the ASCII/KeySym codes associated with the event: */
1360 len = XLookupString( &event.xkey, asciiCode, sizeof(asciiCode),
1361 &keySym, &composeStatus
1364 /* GLUT API tells us to have two separate callbacks... */
1367 /* ...one for the ASCII translateable keypresses... */
1370 fgSetWindow( window );
1371 fgState.Modifiers = fghGetXModifiers( event.xkey.state );
1372 keyboard_cb( asciiCode[ 0 ],
1373 event.xkey.x, event.xkey.y
1375 fgState.Modifiers = INVALID_MODIFIERS;
1383 * ...and one for all the others, which need to be
1384 * translated to GLUT_KEY_Xs...
1388 case XK_F1: special = GLUT_KEY_F1; break;
1389 case XK_F2: special = GLUT_KEY_F2; break;
1390 case XK_F3: special = GLUT_KEY_F3; break;
1391 case XK_F4: special = GLUT_KEY_F4; break;
1392 case XK_F5: special = GLUT_KEY_F5; break;
1393 case XK_F6: special = GLUT_KEY_F6; break;
1394 case XK_F7: special = GLUT_KEY_F7; break;
1395 case XK_F8: special = GLUT_KEY_F8; break;
1396 case XK_F9: special = GLUT_KEY_F9; break;
1397 case XK_F10: special = GLUT_KEY_F10; break;
1398 case XK_F11: special = GLUT_KEY_F11; break;
1399 case XK_F12: special = GLUT_KEY_F12; break;
1402 case XK_Left: special = GLUT_KEY_LEFT; break;
1404 case XK_Right: special = GLUT_KEY_RIGHT; break;
1406 case XK_Up: special = GLUT_KEY_UP; break;
1408 case XK_Down: special = GLUT_KEY_DOWN; break;
1411 case XK_Prior: special = GLUT_KEY_PAGE_UP; break;
1413 case XK_Next: special = GLUT_KEY_PAGE_DOWN; break;
1415 case XK_Home: special = GLUT_KEY_HOME; break;
1417 case XK_End: special = GLUT_KEY_END; break;
1419 case XK_Insert: special = GLUT_KEY_INSERT; break;
1421 case XK_Num_Lock : special = GLUT_KEY_NUM_LOCK; break;
1422 case XK_KP_Begin : special = GLUT_KEY_BEGIN; break;
1423 case XK_KP_Delete: special = GLUT_KEY_DELETE; break;
1425 case XK_Shift_L: special = GLUT_KEY_SHIFT_L; break;
1426 case XK_Shift_R: special = GLUT_KEY_SHIFT_R; break;
1427 case XK_Control_L: special = GLUT_KEY_CTRL_L; break;
1428 case XK_Control_R: special = GLUT_KEY_CTRL_R; break;
1429 case XK_Alt_L: special = GLUT_KEY_ALT_L; break;
1430 case XK_Alt_R: special = GLUT_KEY_ALT_R; break;
1434 * Execute the callback (if one has been specified),
1435 * given that the special code seems to be valid...
1437 if( special_cb && (special != -1) )
1439 fgSetWindow( window );
1440 fgState.Modifiers = fghGetXModifiers( event.xkey.state );
1441 special_cb( special, event.xkey.x, event.xkey.y );
1442 fgState.Modifiers = INVALID_MODIFIERS;
1449 case ReparentNotify:
1450 break; /* XXX Should disable this event */
1457 /* enter handling of Extension Events here */
1458 #ifdef HAVE_X11_EXTENSIONS_XINPUT2_H
1459 fgHandleExtensionEvents( &event );
1465 #elif TARGET_HOST_MS_WINDOWS
1469 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutMainLoopEvent" );
1471 while( PeekMessage( &stMsg, NULL, 0, 0, PM_NOREMOVE ) )
1473 if( GetMessage( &stMsg, NULL, 0, 0 ) == 0 )
1475 if( fgState.ActionOnWindowClose == GLUT_ACTION_EXIT )
1480 else if( fgState.ActionOnWindowClose == GLUT_ACTION_GLUTMAINLOOP_RETURNS )
1481 fgState.ExecState = GLUT_EXEC_STATE_STOP;
1486 TranslateMessage( &stMsg );
1487 DispatchMessage( &stMsg );
1491 if( fgState.Timers.First )
1493 fghCheckJoystickPolls( );
1500 * Enters the freeglut processing loop.
1501 * Stays until the "ExecState" changes to "GLUT_EXEC_STATE_STOP".
1503 void FGAPIENTRY glutMainLoop( void )
1507 #if TARGET_HOST_MS_WINDOWS
1508 SFG_Window *window = (SFG_Window *)fgStructure.Windows.First ;
1511 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutMainLoop" );
1513 #if TARGET_HOST_MS_WINDOWS
1515 * Processing before the main loop: If there is a window which is open and
1516 * which has a visibility callback, call it. I know this is an ugly hack,
1517 * but I'm not sure what else to do about it. Ideally we should leave
1518 * something uninitialized in the create window code and initialize it in
1519 * the main loop, and have that initialization create a "WM_ACTIVATE"
1520 * message. Then we would put the visibility callback code in the
1521 * "case WM_ACTIVATE" block below. - John Fay -- 10/24/02
1525 if ( FETCH_WCB( *window, Visibility ) )
1527 SFG_Window *current_window = fgStructure.CurrentWindow ;
1529 INVOKE_WCB( *window, Visibility, ( window->State.Visible ) );
1530 fgSetWindow( current_window );
1533 window = (SFG_Window *)window->Node.Next ;
1537 fgState.ExecState = GLUT_EXEC_STATE_RUNNING ;
1538 while( fgState.ExecState == GLUT_EXEC_STATE_RUNNING )
1542 glutMainLoopEvent( );
1544 * Step through the list of windows, seeing if there are any
1545 * that are not menus
1547 for( window = ( SFG_Window * )fgStructure.Windows.First;
1549 window = ( SFG_Window * )window->Node.Next )
1550 if ( ! ( window->IsMenu ) )
1554 fgState.ExecState = GLUT_EXEC_STATE_STOP;
1557 if( fgState.IdleCallback )
1559 if( fgStructure.CurrentWindow &&
1560 fgStructure.CurrentWindow->IsMenu )
1562 fgSetWindow( window );
1563 fgState.IdleCallback( );
1566 fghSleepForEvents( );
1571 * When this loop terminates, destroy the display, state and structure
1572 * of a freeglut session, so that another glutInit() call can happen
1574 * Save the "ActionOnWindowClose" because "fgDeinitialize" resets it.
1576 action = fgState.ActionOnWindowClose;
1578 if( action == GLUT_ACTION_EXIT )
1583 * Leaves the freeglut processing loop.
1585 void FGAPIENTRY glutLeaveMainLoop( void )
1587 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutLeaveMainLoop" );
1588 fgState.ExecState = GLUT_EXEC_STATE_STOP ;
1592 #if TARGET_HOST_MS_WINDOWS
1594 * Determine a GLUT modifer mask based on MS-WINDOWS system info.
1596 static int fghGetWin32Modifiers (void)
1599 ( ( ( GetKeyState( VK_LSHIFT ) < 0 ) ||
1600 ( GetKeyState( VK_RSHIFT ) < 0 )) ? GLUT_ACTIVE_SHIFT : 0 ) |
1601 ( ( ( GetKeyState( VK_LCONTROL ) < 0 ) ||
1602 ( GetKeyState( VK_RCONTROL ) < 0 )) ? GLUT_ACTIVE_CTRL : 0 ) |
1603 ( ( ( GetKeyState( VK_LMENU ) < 0 ) ||
1604 ( GetKeyState( VK_RMENU ) < 0 )) ? GLUT_ACTIVE_ALT : 0 );
1608 * The window procedure for handling Win32 events
1610 LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam,
1613 static unsigned char lControl = 0, rControl = 0, lShift = 0,
1614 rShift = 0, lAlt = 0, rAlt = 0;
1620 FREEGLUT_INTERNAL_ERROR_EXIT_IF_NOT_INITIALISED ( "Event Handler" ) ;
1622 window = fgWindowByHandle( hWnd );
1624 if ( ( window == NULL ) && ( uMsg != WM_CREATE ) )
1625 return DefWindowProc( hWnd, uMsg, wParam, lParam );
1627 /* printf ( "Window %3d message <%04x> %12d %12d\n", window?window->ID:0,
1628 uMsg, wParam, lParam ); */
1632 /* Checking for CTRL, ALT, and SHIFT key positions: Key Down! */
1633 if ( !lControl && GetAsyncKeyState ( VK_LCONTROL ) )
1635 INVOKE_WCB ( *window, Special,
1636 ( GLUT_KEY_CTRL_L, window->State.MouseX, window->State.MouseY )
1642 if ( !rControl && GetAsyncKeyState ( VK_RCONTROL ) )
1644 INVOKE_WCB ( *window, Special,
1645 ( GLUT_KEY_CTRL_R, window->State.MouseX, window->State.MouseY )
1651 if ( !lShift && GetAsyncKeyState ( VK_LSHIFT ) )
1653 INVOKE_WCB ( *window, Special,
1654 ( GLUT_KEY_SHIFT_L, window->State.MouseX, window->State.MouseY )
1660 if ( !rShift && GetAsyncKeyState ( VK_RSHIFT ) )
1662 INVOKE_WCB ( *window, Special,
1663 ( GLUT_KEY_SHIFT_R, window->State.MouseX, window->State.MouseY )
1669 if ( !lAlt && GetAsyncKeyState ( VK_LMENU ) )
1671 INVOKE_WCB ( *window, Special,
1672 ( GLUT_KEY_ALT_L, window->State.MouseX, window->State.MouseY )
1678 if ( !rAlt && GetAsyncKeyState ( VK_RMENU ) )
1680 INVOKE_WCB ( *window, Special,
1681 ( GLUT_KEY_ALT_R, window->State.MouseX, window->State.MouseY )
1687 /* Checking for CTRL, ALT, and SHIFT key positions: Key Up! */
1688 if ( lControl && !GetAsyncKeyState ( VK_LCONTROL ) )
1690 INVOKE_WCB ( *window, SpecialUp,
1691 ( GLUT_KEY_CTRL_L, window->State.MouseX, window->State.MouseY )
1697 if ( rControl && !GetAsyncKeyState ( VK_RCONTROL ) )
1699 INVOKE_WCB ( *window, SpecialUp,
1700 ( GLUT_KEY_CTRL_R, window->State.MouseX, window->State.MouseY )
1706 if ( lShift && !GetAsyncKeyState ( VK_LSHIFT ) )
1708 INVOKE_WCB ( *window, SpecialUp,
1709 ( GLUT_KEY_SHIFT_L, window->State.MouseX, window->State.MouseY )
1715 if ( rShift && !GetAsyncKeyState ( VK_RSHIFT ) )
1717 INVOKE_WCB ( *window, SpecialUp,
1718 ( GLUT_KEY_SHIFT_R, window->State.MouseX, window->State.MouseY )
1724 if ( lAlt && !GetAsyncKeyState ( VK_LMENU ) )
1726 INVOKE_WCB ( *window, SpecialUp,
1727 ( GLUT_KEY_ALT_L, window->State.MouseX, window->State.MouseY )
1733 if ( rAlt && !GetAsyncKeyState ( VK_RMENU ) )
1735 INVOKE_WCB ( *window, SpecialUp,
1736 ( GLUT_KEY_ALT_R, window->State.MouseX, window->State.MouseY )
1746 /* The window structure is passed as the creation structure parameter... */
1747 window = (SFG_Window *) (((LPCREATESTRUCT) lParam)->lpCreateParams);
1748 FREEGLUT_INTERNAL_ERROR_EXIT ( ( window != NULL ), "Cannot create window",
1751 window->Window.Handle = hWnd;
1752 window->Window.Device = GetDC( hWnd );
1753 if( window->IsMenu )
1755 unsigned int current_DisplayMode = fgState.DisplayMode;
1756 fgState.DisplayMode = GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH;
1757 #if !defined(_WIN32_WCE)
1758 fgSetupPixelFormat( window, GL_FALSE, PFD_MAIN_PLANE );
1760 fgState.DisplayMode = current_DisplayMode;
1762 if( fgStructure.MenuContext )
1763 wglMakeCurrent( window->Window.Device,
1764 fgStructure.MenuContext->MContext
1768 fgStructure.MenuContext =
1769 (SFG_MenuContext *)malloc( sizeof(SFG_MenuContext) );
1770 fgStructure.MenuContext->MContext =
1771 wglCreateContext( window->Window.Device );
1774 /* window->Window.Context = wglGetCurrentContext (); */
1775 window->Window.Context = wglCreateContext( window->Window.Device );
1779 #if !defined(_WIN32_WCE)
1780 fgSetupPixelFormat( window, GL_FALSE, PFD_MAIN_PLANE );
1783 if( ! fgState.UseCurrentContext )
1784 window->Window.Context =
1785 wglCreateContext( window->Window.Device );
1788 window->Window.Context = wglGetCurrentContext( );
1789 if( ! window->Window.Context )
1790 window->Window.Context =
1791 wglCreateContext( window->Window.Device );
1794 #if !defined(_WIN32_WCE)
1795 fgNewWGLCreateContext( window );
1799 window->State.NeedToResize = GL_TRUE;
1800 /* if we used CW_USEDEFAULT (thats a negative value) for the size
1801 * of the window, query the window now for the size at which it
1804 if( ( window->State.Width < 0 ) || ( window->State.Height < 0 ) )
1806 SFG_Window *current_window = fgStructure.CurrentWindow;
1808 fgSetWindow( window );
1809 window->State.Width = glutGet( GLUT_WINDOW_WIDTH );
1810 window->State.Height = glutGet( GLUT_WINDOW_HEIGHT );
1811 fgSetWindow( current_window );
1814 ReleaseDC( window->Window.Handle, window->Window.Device );
1816 #if defined(_WIN32_WCE)
1817 /* Take over button handling */
1819 HINSTANCE dxDllLib=LoadLibrary(_T("gx.dll"));
1822 GXGetDefaultKeys_=(GXGETDEFAULTKEYS)GetProcAddress(dxDllLib, _T("?GXGetDefaultKeys@@YA?AUGXKeyList@@H@Z"));
1823 GXOpenInput_=(GXOPENINPUT)GetProcAddress(dxDllLib, _T("?GXOpenInput@@YAHXZ"));
1828 if(GXGetDefaultKeys_)
1829 gxKeyList = (*GXGetDefaultKeys_)(GX_LANDSCAPEKEYS);
1832 #endif /* defined(_WIN32_WCE) */
1837 * If the window is visible, then it is the user manually resizing it.
1838 * If it is not, then it is the system sending us a dummy resize with
1839 * zero dimensions on a "glutIconifyWindow" call.
1841 if( window->State.Visible )
1843 window->State.NeedToResize = GL_TRUE;
1844 #if defined(_WIN32_WCE)
1845 window->State.Width = HIWORD(lParam);
1846 window->State.Height = LOWORD(lParam);
1848 window->State.Width = LOWORD(lParam);
1849 window->State.Height = HIWORD(lParam);
1850 #endif /* defined(_WIN32_WCE) */
1856 /* printf("WM_SETFOCUS: %p\n", window ); */
1857 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1858 INVOKE_WCB( *window, Entry, ( GLUT_ENTERED ) );
1862 /* printf("WM_KILLFOCUS: %p\n", window ); */
1863 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1864 INVOKE_WCB( *window, Entry, ( GLUT_LEFT ) );
1866 if( window->IsMenu &&
1867 window->ActiveMenu && window->ActiveMenu->IsActive )
1868 fgUpdateMenuHighlight( window->ActiveMenu );
1874 if (LOWORD(wParam) != WA_INACTIVE)
1876 /* printf("WM_ACTIVATE: fgSetCursor( %p, %d)\n", window,
1877 window->State.Cursor ); */
1878 fgSetCursor( window, window->State.Cursor );
1881 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1886 /* printf ( "Cursor event %x %x %x %x\n", window, window->State.Cursor, lParam, wParam ) ; */
1887 if( LOWORD( lParam ) == HTCLIENT )
1888 fgSetCursor ( window, window->State.Cursor ) ;
1890 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1894 window->State.Visible = GL_TRUE;
1895 window->State.Redisplay = GL_TRUE;
1899 /* Turn on the visibility in case it was turned off somehow */
1900 window->State.Visible = GL_TRUE;
1901 BeginPaint( hWnd, &ps );
1902 fghRedrawWindow( window );
1903 EndPaint( hWnd, &ps );
1907 fgDestroyWindow ( window );
1908 if ( fgState.ActionOnWindowClose != GLUT_ACTION_CONTINUE_EXECUTION )
1914 * The window already got destroyed, so don't bother with it.
1920 #if defined(_WIN32_WCE)
1921 window->State.MouseX = 320-HIWORD( lParam );
1922 window->State.MouseY = LOWORD( lParam );
1924 window->State.MouseX = LOWORD( lParam );
1925 window->State.MouseY = HIWORD( lParam );
1926 #endif /* defined(_WIN32_WCE) */
1927 /* Restrict to [-32768, 32767] to match X11 behaviour */
1928 /* See comment in "freeglut_developer" mailing list 10/4/04 */
1929 if ( window->State.MouseX > 32767 ) window->State.MouseX -= 65536;
1930 if ( window->State.MouseY > 32767 ) window->State.MouseY -= 65536;
1932 if ( window->ActiveMenu )
1934 fgUpdateMenuHighlight( window->ActiveMenu );
1937 SetFocus(window->Window.Handle);
1939 fgState.Modifiers = fghGetWin32Modifiers( );
1941 if( ( wParam & MK_LBUTTON ) ||
1942 ( wParam & MK_MBUTTON ) ||
1943 ( wParam & MK_RBUTTON ) )
1944 INVOKE_WCB( *window, Motion, ( window->State.MouseX,
1945 window->State.MouseY ) );
1947 INVOKE_WCB( *window, Passive, ( window->State.MouseX,
1948 window->State.MouseY ) );
1950 fgState.Modifiers = INVALID_MODIFIERS;
1954 case WM_LBUTTONDOWN:
1955 case WM_MBUTTONDOWN:
1956 case WM_RBUTTONDOWN:
1961 GLboolean pressed = GL_TRUE;
1964 #if defined(_WIN32_WCE)
1965 window->State.MouseX = 320-HIWORD( lParam );
1966 window->State.MouseY = LOWORD( lParam );
1968 window->State.MouseX = LOWORD( lParam );
1969 window->State.MouseY = HIWORD( lParam );
1970 #endif /* defined(_WIN32_WCE) */
1972 /* Restrict to [-32768, 32767] to match X11 behaviour */
1973 /* See comment in "freeglut_developer" mailing list 10/4/04 */
1974 if ( window->State.MouseX > 32767 ) window->State.MouseX -= 65536;
1975 if ( window->State.MouseY > 32767 ) window->State.MouseY -= 65536;
1979 case WM_LBUTTONDOWN:
1981 button = GLUT_LEFT_BUTTON;
1983 case WM_MBUTTONDOWN:
1985 button = GLUT_MIDDLE_BUTTON;
1987 case WM_RBUTTONDOWN:
1989 button = GLUT_RIGHT_BUTTON;
1993 button = GLUT_LEFT_BUTTON;
1997 button = GLUT_MIDDLE_BUTTON;
2001 button = GLUT_RIGHT_BUTTON;
2009 #if !defined(_WIN32_WCE)
2010 if( GetSystemMetrics( SM_SWAPBUTTON ) )
2012 if( button == GLUT_LEFT_BUTTON )
2013 button = GLUT_RIGHT_BUTTON;
2015 if( button == GLUT_RIGHT_BUTTON )
2016 button = GLUT_LEFT_BUTTON;
2018 #endif /* !defined(_WIN32_WCE) */
2021 return DefWindowProc( hWnd, uMsg, lParam, wParam );
2024 * Do not execute the application's mouse callback if a menu
2025 * is hooked to this button. In that case an appropriate
2026 * private call should be generated.
2028 if( fgCheckActiveMenu( window, button, pressed,
2029 window->State.MouseX, window->State.MouseY ) )
2032 /* Set capture so that the window captures all the mouse messages */
2034 * XXX - Multiple button support: Under X11, the mouse is not released
2035 * XXX - from the window until all buttons have been released, even if the
2036 * XXX - user presses a button in another window. This will take more
2037 * XXX - code changes than I am up to at the moment (10/5/04). The present
2038 * XXX - is a 90 percent solution.
2040 if ( pressed == GL_TRUE )
2041 SetCapture ( window->Window.Handle ) ;
2045 if( ! FETCH_WCB( *window, Mouse ) )
2048 fgSetWindow( window );
2049 fgState.Modifiers = fghGetWin32Modifiers( );
2054 pressed ? GLUT_DOWN : GLUT_UP,
2055 window->State.MouseX,
2056 window->State.MouseY
2060 fgState.Modifiers = INVALID_MODIFIERS;
2065 /* Should be WM_MOUSEWHEEL but my compiler doesn't recognize it */
2067 int wheel_number = LOWORD( wParam );
2068 short ticks = ( short )HIWORD( wParam );
2069 fgState.MouseWheelTicks += ticks;
2072 * XXX Should use WHEEL_DELTA instead of 120
2074 if ( abs ( fgState.MouseWheelTicks ) > 120 )
2076 int direction = ( fgState.MouseWheelTicks > 0 ) ? 1 : -1;
2078 if( ! FETCH_WCB( *window, MouseWheel ) &&
2079 ! FETCH_WCB( *window, Mouse ) )
2082 fgSetWindow( window );
2083 fgState.Modifiers = fghGetWin32Modifiers( );
2086 * XXX Should use WHEEL_DELTA instead of 120
2088 while( abs ( fgState.MouseWheelTicks ) > 120 )
2090 if( FETCH_WCB( *window, MouseWheel ) )
2091 INVOKE_WCB( *window, MouseWheel,
2094 window->State.MouseX,
2095 window->State.MouseY
2098 else /* No mouse wheel, call the mouse button callback twice */
2101 * Map wheel zero to button 3 and 4; +1 to 3, -1 to 4
2102 * " " one +1 to 5, -1 to 6, ...
2104 * XXX The below assumes that you have no more than 3 mouse
2105 * XXX buttons. Sorry.
2107 int button = wheel_number * 2 + 3;
2110 INVOKE_WCB( *window, Mouse,
2111 ( button, GLUT_DOWN,
2112 window->State.MouseX, window->State.MouseY )
2114 INVOKE_WCB( *window, Mouse,
2116 window->State.MouseX, window->State.MouseY )
2121 * XXX Should use WHEEL_DELTA instead of 120
2123 fgState.MouseWheelTicks -= 120 * direction;
2126 fgState.Modifiers = INVALID_MODIFIERS;
2137 if( ( fgState.KeyRepeat==GLUT_KEY_REPEAT_OFF || window->State.IgnoreKeyRepeat==GL_TRUE ) && (HIWORD(lParam) & KF_REPEAT) )
2141 * Remember the current modifiers state. This is done here in order
2142 * to make sure the VK_DELETE keyboard callback is executed properly.
2144 fgState.Modifiers = fghGetWin32Modifiers( );
2146 GetCursorPos( &mouse_pos );
2147 ScreenToClient( window->Window.Handle, &mouse_pos );
2149 window->State.MouseX = mouse_pos.x;
2150 window->State.MouseY = mouse_pos.y;
2152 /* Convert the Win32 keystroke codes to GLUTtish way */
2153 # define KEY(a,b) case a: keypress = b; break;
2157 KEY( VK_F1, GLUT_KEY_F1 );
2158 KEY( VK_F2, GLUT_KEY_F2 );
2159 KEY( VK_F3, GLUT_KEY_F3 );
2160 KEY( VK_F4, GLUT_KEY_F4 );
2161 KEY( VK_F5, GLUT_KEY_F5 );
2162 KEY( VK_F6, GLUT_KEY_F6 );
2163 KEY( VK_F7, GLUT_KEY_F7 );
2164 KEY( VK_F8, GLUT_KEY_F8 );
2165 KEY( VK_F9, GLUT_KEY_F9 );
2166 KEY( VK_F10, GLUT_KEY_F10 );
2167 KEY( VK_F11, GLUT_KEY_F11 );
2168 KEY( VK_F12, GLUT_KEY_F12 );
2169 KEY( VK_PRIOR, GLUT_KEY_PAGE_UP );
2170 KEY( VK_NEXT, GLUT_KEY_PAGE_DOWN );
2171 KEY( VK_HOME, GLUT_KEY_HOME );
2172 KEY( VK_END, GLUT_KEY_END );
2173 KEY( VK_LEFT, GLUT_KEY_LEFT );
2174 KEY( VK_UP, GLUT_KEY_UP );
2175 KEY( VK_RIGHT, GLUT_KEY_RIGHT );
2176 KEY( VK_DOWN, GLUT_KEY_DOWN );
2177 KEY( VK_INSERT, GLUT_KEY_INSERT );
2178 KEY( VK_LCONTROL, GLUT_KEY_CTRL_L );
2179 KEY( VK_RCONTROL, GLUT_KEY_CTRL_R );
2180 KEY( VK_LSHIFT, GLUT_KEY_SHIFT_L );
2181 KEY( VK_RSHIFT, GLUT_KEY_SHIFT_R );
2182 KEY( VK_LMENU, GLUT_KEY_ALT_L );
2183 KEY( VK_RMENU, GLUT_KEY_ALT_R );
2186 /* The delete key should be treated as an ASCII keypress: */
2187 INVOKE_WCB( *window, Keyboard,
2188 ( 127, window->State.MouseX, window->State.MouseY )
2192 #if defined(_WIN32_WCE)
2193 if(!(lParam & 0x40000000)) /* Prevent auto-repeat */
2195 if(wParam==(unsigned)gxKeyList.vkRight)
2196 keypress = GLUT_KEY_RIGHT;
2197 else if(wParam==(unsigned)gxKeyList.vkLeft)
2198 keypress = GLUT_KEY_LEFT;
2199 else if(wParam==(unsigned)gxKeyList.vkUp)
2200 keypress = GLUT_KEY_UP;
2201 else if(wParam==(unsigned)gxKeyList.vkDown)
2202 keypress = GLUT_KEY_DOWN;
2203 else if(wParam==(unsigned)gxKeyList.vkA)
2204 keypress = GLUT_KEY_F1;
2205 else if(wParam==(unsigned)gxKeyList.vkB)
2206 keypress = GLUT_KEY_F2;
2207 else if(wParam==(unsigned)gxKeyList.vkC)
2208 keypress = GLUT_KEY_F3;
2209 else if(wParam==(unsigned)gxKeyList.vkStart)
2210 keypress = GLUT_KEY_F4;
2214 if( keypress != -1 )
2215 INVOKE_WCB( *window, Special,
2217 window->State.MouseX, window->State.MouseY )
2220 fgState.Modifiers = INVALID_MODIFIERS;
2231 * Remember the current modifiers state. This is done here in order
2232 * to make sure the VK_DELETE keyboard callback is executed properly.
2234 fgState.Modifiers = fghGetWin32Modifiers( );
2236 GetCursorPos( &mouse_pos );
2237 ScreenToClient( window->Window.Handle, &mouse_pos );
2239 window->State.MouseX = mouse_pos.x;
2240 window->State.MouseY = mouse_pos.y;
2243 * Convert the Win32 keystroke codes to GLUTtish way.
2244 * "KEY(a,b)" was defined under "WM_KEYDOWN"
2249 KEY( VK_F1, GLUT_KEY_F1 );
2250 KEY( VK_F2, GLUT_KEY_F2 );
2251 KEY( VK_F3, GLUT_KEY_F3 );
2252 KEY( VK_F4, GLUT_KEY_F4 );
2253 KEY( VK_F5, GLUT_KEY_F5 );
2254 KEY( VK_F6, GLUT_KEY_F6 );
2255 KEY( VK_F7, GLUT_KEY_F7 );
2256 KEY( VK_F8, GLUT_KEY_F8 );
2257 KEY( VK_F9, GLUT_KEY_F9 );
2258 KEY( VK_F10, GLUT_KEY_F10 );
2259 KEY( VK_F11, GLUT_KEY_F11 );
2260 KEY( VK_F12, GLUT_KEY_F12 );
2261 KEY( VK_PRIOR, GLUT_KEY_PAGE_UP );
2262 KEY( VK_NEXT, GLUT_KEY_PAGE_DOWN );
2263 KEY( VK_HOME, GLUT_KEY_HOME );
2264 KEY( VK_END, GLUT_KEY_END );
2265 KEY( VK_LEFT, GLUT_KEY_LEFT );
2266 KEY( VK_UP, GLUT_KEY_UP );
2267 KEY( VK_RIGHT, GLUT_KEY_RIGHT );
2268 KEY( VK_DOWN, GLUT_KEY_DOWN );
2269 KEY( VK_INSERT, GLUT_KEY_INSERT );
2270 KEY( VK_LCONTROL, GLUT_KEY_CTRL_L );
2271 KEY( VK_RCONTROL, GLUT_KEY_CTRL_R );
2272 KEY( VK_LSHIFT, GLUT_KEY_SHIFT_L );
2273 KEY( VK_RSHIFT, GLUT_KEY_SHIFT_R );
2274 KEY( VK_LMENU, GLUT_KEY_ALT_L );
2275 KEY( VK_RMENU, GLUT_KEY_ALT_R );
2278 /* The delete key should be treated as an ASCII keypress: */
2279 INVOKE_WCB( *window, KeyboardUp,
2280 ( 127, window->State.MouseX, window->State.MouseY )
2286 #if !defined(_WIN32_WCE)
2290 GetKeyboardState( state );
2292 if( ToAscii( (UINT)wParam, 0, state, code, 0 ) == 1 )
2295 INVOKE_WCB( *window, KeyboardUp,
2297 window->State.MouseX, window->State.MouseY )
2299 #endif /* !defined(_WIN32_WCE) */
2303 if( keypress != -1 )
2304 INVOKE_WCB( *window, SpecialUp,
2306 window->State.MouseX, window->State.MouseY )
2309 fgState.Modifiers = INVALID_MODIFIERS;
2316 if( (fgState.KeyRepeat==GLUT_KEY_REPEAT_OFF || window->State.IgnoreKeyRepeat==GL_TRUE) && (HIWORD(lParam) & KF_REPEAT) )
2319 fgState.Modifiers = fghGetWin32Modifiers( );
2320 INVOKE_WCB( *window, Keyboard,
2322 window->State.MouseX, window->State.MouseY )
2324 fgState.Modifiers = INVALID_MODIFIERS;
2328 case WM_CAPTURECHANGED:
2329 /* User has finished resizing the window, force a redraw */
2330 INVOKE_WCB( *window, Display, ( ) );
2332 /*lRet = DefWindowProc( hWnd, uMsg, wParam, lParam ); */
2335 /* Other messages that I have seen and which are not handled already */
2336 case WM_SETTEXT: /* 0x000c */
2337 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
2338 /* Pass it on to "DefWindowProc" to set the window text */
2341 case WM_GETTEXT: /* 0x000d */
2342 /* Ideally we would copy the title of the window into "lParam" */
2343 /* strncpy ( (char *)lParam, "Window Title", wParam );
2344 lRet = ( wParam > 12 ) ? 12 : wParam; */
2345 /* the number of characters copied */
2346 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
2349 case WM_GETTEXTLENGTH: /* 0x000e */
2350 /* Ideally we would get the length of the title of the window */
2352 /* the number of characters in "Window Title\0" (see above) */
2355 case WM_ERASEBKGND: /* 0x0014 */
2356 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
2359 #if !defined(_WIN32_WCE)
2360 case WM_SYNCPAINT: /* 0x0088 */
2361 /* Another window has moved, need to update this one */
2362 window->State.Redisplay = GL_TRUE;
2363 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
2364 /* Help screen says this message must be passed to "DefWindowProc" */
2367 case WM_NCPAINT: /* 0x0085 */
2368 /* Need to update the border of this window */
2369 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
2370 /* Pass it on to "DefWindowProc" to repaint a standard border */
2373 case WM_SYSCOMMAND : /* 0x0112 */
2376 * We have received a system command message. Try to act on it.
2377 * The commands are passed in through the "wParam" parameter:
2378 * The least significant digit seems to be which edge of the window
2379 * is being used for a resize event:
2383 * Congratulations and thanks to Richard Rauch for figuring this out..
2385 switch ( wParam & 0xfff0 )
2394 /* User has clicked on the "-" to minimize the window */
2395 /* Turn off the visibility */
2396 window->State.Visible = GL_FALSE ;
2403 case SC_NEXTWINDOW :
2406 case SC_PREVWINDOW :
2410 /* Followed very closely by a WM_CLOSE message */
2434 case SC_SCREENSAVE :
2440 #if(WINVER >= 0x0400)
2444 case SC_MONITORPOWER :
2447 case SC_CONTEXTHELP :
2449 #endif /* WINVER >= 0x0400 */
2453 fgWarning( "Unknown wParam type 0x%x", wParam );
2458 #endif /* !defined(_WIN32_WCE) */
2460 /* We need to pass the message on to the operating system as well */
2461 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
2465 /* handle multi-touch messages */
2468 unsigned int numInputs = (unsigned int)wParam;
2470 TOUCHINPUT* ti = (TOUCHINPUT*)malloc( sizeof(TOUCHINPUT)*numInputs);
2472 if (fghGetTouchInputInfo == (pGetTouchInputInfo)0xDEADBEEF) {
2473 fghGetTouchInputInfo = (pGetTouchInputInfo)GetProcAddress(GetModuleHandle("user32"),"GetTouchInputInfo");
2474 fghCloseTouchInputHandle = (pCloseTouchInputHandle)GetProcAddress(GetModuleHandle("user32"),"CloseTouchInputHandle");
2477 if (!fghGetTouchInputInfo) {
2482 if (fghGetTouchInputInfo( (HTOUCHINPUT)lParam, numInputs, ti, sizeof(TOUCHINPUT) )) {
2483 /* Handle each contact point */
2484 for (i = 0; i < numInputs; ++i ) {
2487 tp.x = TOUCH_COORD_TO_PIXEL(ti[i].x);
2488 tp.y = TOUCH_COORD_TO_PIXEL(ti[i].y);
2489 ScreenToClient( hWnd, &tp );
2491 ti[i].dwID = ti[i].dwID * 2;
2493 if (ti[i].dwFlags & TOUCHEVENTF_DOWN) {
2494 INVOKE_WCB( *window, MultiEntry, ( ti[i].dwID, GLUT_ENTERED ) );
2495 INVOKE_WCB( *window, MultiButton, ( ti[i].dwID, tp.x, tp.y, 0, GLUT_DOWN ) );
2496 } else if (ti[i].dwFlags & TOUCHEVENTF_MOVE) {
2497 INVOKE_WCB( *window, MultiMotion, ( ti[i].dwID, tp.x, tp.y ) );
2498 } else if (ti[i].dwFlags & TOUCHEVENTF_UP) {
2499 INVOKE_WCB( *window, MultiButton, ( ti[i].dwID, tp.x, tp.y, 0, GLUT_UP ) );
2500 INVOKE_WCB( *window, MultiEntry, ( ti[i].dwID, GLUT_LEFT ) );
2504 fghCloseTouchInputHandle((HTOUCHINPUT)lParam);
2506 lRet = 0; /*DefWindowProc( hWnd, uMsg, wParam, lParam );*/
2511 /* Handle unhandled messages */
2512 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
2520 /*** END OF FILE ***/