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 (*pGetTouchInputInfo)(HTOUCHINPUT,UINT,PTOUCHINPUT,int);
75 typedef BOOL (*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 );
105 #if TARGET_HOST_POSIX_X11
107 XResizeWindow( fgDisplay.Display, window->Window.Handle,
109 XFlush( fgDisplay.Display ); /* XXX Shouldn't need this */
111 #elif TARGET_HOST_MS_WINDOWS && !defined(_WIN32_WCE)
117 * For windowed mode, get the current position of the
118 * window and resize taking the size of the frame
119 * decorations into account.
122 /* "GetWindowRect" returns the pixel coordinates of the outside of the window */
123 GetWindowRect( window->Window.Handle, &winRect );
129 if ( window->Parent == NULL )
131 if ( ! window->IsMenu && (window != fgStructure.GameModeWindow) &&
132 !( fgState.DisplayMode & GLUT_BORDERLESS ))
134 w += GetSystemMetrics( SM_CXSIZEFRAME ) * 2;
135 h += GetSystemMetrics( SM_CYSIZEFRAME ) * 2 +
136 GetSystemMetrics( SM_CYCAPTION );
142 GetWindowRect( window->Parent->Window.Handle, &parentRect );
143 x -= parentRect.left + GetSystemMetrics( SM_CXSIZEFRAME ) * 2;
144 y -= parentRect.top + GetSystemMetrics( SM_CYSIZEFRAME ) * 2 +
145 GetSystemMetrics( SM_CYCAPTION );
149 * SWP_NOACTIVATE Do not activate the window
150 * SWP_NOOWNERZORDER Do not change position in z-order
151 * SWP_NOSENDCHANGING Supress WM_WINDOWPOSCHANGING message
152 * SWP_NOZORDER Retains the current Z order (ignore 2nd param)
155 SetWindowPos( window->Window.Handle,
158 SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOSENDCHANGING |
165 * XXX Should update {window->State.OldWidth, window->State.OldHeight}
166 * XXX to keep in lockstep with POSIX_X11 code.
168 if( FETCH_WCB( *window, Reshape ) )
169 INVOKE_WCB( *window, Reshape, ( width, height ) );
172 fgSetWindow( window );
173 glViewport( 0, 0, width, height );
177 * Force a window redraw. In Windows at least this is only a partial
178 * solution: if the window is increasing in size in either dimension,
179 * the already-drawn part does not get drawn again and things look funny.
180 * But without this we get this bad behaviour whenever we resize the
183 window->State.Redisplay = GL_TRUE;
186 fgSetWindow( current_window );
190 * Calls a window's redraw method. This is used when
191 * a redraw is forced by the incoming window messages.
193 static void fghRedrawWindow ( SFG_Window *window )
195 SFG_Window *current_window = fgStructure.CurrentWindow;
197 freeglut_return_if_fail( window );
198 freeglut_return_if_fail( FETCH_WCB ( *window, Display ) );
200 window->State.Redisplay = GL_FALSE;
202 freeglut_return_if_fail( window->State.Visible );
204 fgSetWindow( window );
206 if( window->State.NeedToResize )
214 window->State.NeedToResize = GL_FALSE;
217 INVOKE_WCB( *window, Display, ( ) );
219 fgSetWindow( current_window );
223 * A static helper function to execute display callback for a window
225 static void fghcbDisplayWindow( SFG_Window *window,
226 SFG_Enumerator *enumerator )
228 if( window->State.Redisplay &&
229 window->State.Visible )
231 window->State.Redisplay = GL_FALSE;
233 #if TARGET_HOST_POSIX_X11
234 fghRedrawWindow ( window ) ;
235 #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 paramter... */
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( ( window->State.Width < 0 ) || ( window->State.Height < 0 ) )
1802 SFG_Window *current_window = fgStructure.CurrentWindow;
1804 fgSetWindow( window );
1805 window->State.Width = glutGet( GLUT_WINDOW_WIDTH );
1806 window->State.Height = glutGet( GLUT_WINDOW_HEIGHT );
1807 fgSetWindow( current_window );
1810 ReleaseDC( window->Window.Handle, window->Window.Device );
1812 #if defined(_WIN32_WCE)
1813 /* Take over button handling */
1815 HINSTANCE dxDllLib=LoadLibrary(_T("gx.dll"));
1818 GXGetDefaultKeys_=(GXGETDEFAULTKEYS)GetProcAddress(dxDllLib, _T("?GXGetDefaultKeys@@YA?AUGXKeyList@@H@Z"));
1819 GXOpenInput_=(GXOPENINPUT)GetProcAddress(dxDllLib, _T("?GXOpenInput@@YAHXZ"));
1824 if(GXGetDefaultKeys_)
1825 gxKeyList = (*GXGetDefaultKeys_)(GX_LANDSCAPEKEYS);
1828 #endif /* defined(_WIN32_WCE) */
1833 * If the window is visible, then it is the user manually resizing it.
1834 * If it is not, then it is the system sending us a dummy resize with
1835 * zero dimensions on a "glutIconifyWindow" call.
1837 if( window->State.Visible )
1839 window->State.NeedToResize = GL_TRUE;
1840 #if defined(_WIN32_WCE)
1841 window->State.Width = HIWORD(lParam);
1842 window->State.Height = LOWORD(lParam);
1844 window->State.Width = LOWORD(lParam);
1845 window->State.Height = HIWORD(lParam);
1846 #endif /* defined(_WIN32_WCE) */
1852 /* printf("WM_SETFOCUS: %p\n", window ); */
1853 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1854 INVOKE_WCB( *window, Entry, ( GLUT_ENTERED ) );
1858 /* printf("WM_KILLFOCUS: %p\n", window ); */
1859 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1860 INVOKE_WCB( *window, Entry, ( GLUT_LEFT ) );
1862 if( window->IsMenu &&
1863 window->ActiveMenu && window->ActiveMenu->IsActive )
1864 fgUpdateMenuHighlight( window->ActiveMenu );
1870 if (LOWORD(wParam) != WA_INACTIVE)
1872 /* printf("WM_ACTIVATE: fgSetCursor( %p, %d)\n", window,
1873 window->State.Cursor ); */
1874 fgSetCursor( window, window->State.Cursor );
1877 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1882 /* printf ( "Cursor event %x %x %x %x\n", window, window->State.Cursor, lParam, wParam ) ; */
1883 if( LOWORD( lParam ) == HTCLIENT )
1884 fgSetCursor ( window, window->State.Cursor ) ;
1886 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1890 window->State.Visible = GL_TRUE;
1891 window->State.Redisplay = GL_TRUE;
1895 /* Turn on the visibility in case it was turned off somehow */
1896 window->State.Visible = GL_TRUE;
1897 BeginPaint( hWnd, &ps );
1898 fghRedrawWindow( window );
1899 EndPaint( hWnd, &ps );
1903 fgDestroyWindow ( window );
1904 if ( fgState.ActionOnWindowClose != GLUT_ACTION_CONTINUE_EXECUTION )
1910 * The window already got destroyed, so don't bother with it.
1916 #if defined(_WIN32_WCE)
1917 window->State.MouseX = 320-HIWORD( lParam );
1918 window->State.MouseY = LOWORD( lParam );
1920 window->State.MouseX = LOWORD( lParam );
1921 window->State.MouseY = HIWORD( lParam );
1922 #endif /* defined(_WIN32_WCE) */
1923 /* Restrict to [-32768, 32767] to match X11 behaviour */
1924 /* See comment in "freeglut_developer" mailing list 10/4/04 */
1925 if ( window->State.MouseX > 32767 ) window->State.MouseX -= 65536;
1926 if ( window->State.MouseY > 32767 ) window->State.MouseY -= 65536;
1928 if ( window->ActiveMenu )
1930 fgUpdateMenuHighlight( window->ActiveMenu );
1933 SetFocus(window->Window.Handle);
1935 fgState.Modifiers = fghGetWin32Modifiers( );
1937 if( ( wParam & MK_LBUTTON ) ||
1938 ( wParam & MK_MBUTTON ) ||
1939 ( wParam & MK_RBUTTON ) )
1940 INVOKE_WCB( *window, Motion, ( window->State.MouseX,
1941 window->State.MouseY ) );
1943 INVOKE_WCB( *window, Passive, ( window->State.MouseX,
1944 window->State.MouseY ) );
1946 fgState.Modifiers = INVALID_MODIFIERS;
1950 case WM_LBUTTONDOWN:
1951 case WM_MBUTTONDOWN:
1952 case WM_RBUTTONDOWN:
1957 GLboolean pressed = GL_TRUE;
1960 #if defined(_WIN32_WCE)
1961 window->State.MouseX = 320-HIWORD( lParam );
1962 window->State.MouseY = LOWORD( lParam );
1964 window->State.MouseX = LOWORD( lParam );
1965 window->State.MouseY = HIWORD( lParam );
1966 #endif /* defined(_WIN32_WCE) */
1968 /* Restrict to [-32768, 32767] to match X11 behaviour */
1969 /* See comment in "freeglut_developer" mailing list 10/4/04 */
1970 if ( window->State.MouseX > 32767 ) window->State.MouseX -= 65536;
1971 if ( window->State.MouseY > 32767 ) window->State.MouseY -= 65536;
1975 case WM_LBUTTONDOWN:
1977 button = GLUT_LEFT_BUTTON;
1979 case WM_MBUTTONDOWN:
1981 button = GLUT_MIDDLE_BUTTON;
1983 case WM_RBUTTONDOWN:
1985 button = GLUT_RIGHT_BUTTON;
1989 button = GLUT_LEFT_BUTTON;
1993 button = GLUT_MIDDLE_BUTTON;
1997 button = GLUT_RIGHT_BUTTON;
2005 #if !defined(_WIN32_WCE)
2006 if( GetSystemMetrics( SM_SWAPBUTTON ) )
2008 if( button == GLUT_LEFT_BUTTON )
2009 button = GLUT_RIGHT_BUTTON;
2011 if( button == GLUT_RIGHT_BUTTON )
2012 button = GLUT_LEFT_BUTTON;
2014 #endif /* !defined(_WIN32_WCE) */
2017 return DefWindowProc( hWnd, uMsg, lParam, wParam );
2020 * Do not execute the application's mouse callback if a menu
2021 * is hooked to this button. In that case an appropriate
2022 * private call should be generated.
2024 if( fgCheckActiveMenu( window, button, pressed,
2025 window->State.MouseX, window->State.MouseY ) )
2028 /* Set capture so that the window captures all the mouse messages */
2030 * XXX - Multiple button support: Under X11, the mouse is not released
2031 * XXX - from the window until all buttons have been released, even if the
2032 * XXX - user presses a button in another window. This will take more
2033 * XXX - code changes than I am up to at the moment (10/5/04). The present
2034 * XXX - is a 90 percent solution.
2036 if ( pressed == GL_TRUE )
2037 SetCapture ( window->Window.Handle ) ;
2041 if( ! FETCH_WCB( *window, Mouse ) )
2044 fgSetWindow( window );
2045 fgState.Modifiers = fghGetWin32Modifiers( );
2050 pressed ? GLUT_DOWN : GLUT_UP,
2051 window->State.MouseX,
2052 window->State.MouseY
2056 fgState.Modifiers = INVALID_MODIFIERS;
2061 /* Should be WM_MOUSEWHEEL but my compiler doesn't recognize it */
2063 int wheel_number = LOWORD( wParam );
2064 short ticks = ( short )HIWORD( wParam );
2065 fgState.MouseWheelTicks += ticks;
2068 * XXX Should use WHEEL_DELTA instead of 120
2070 if ( abs ( fgState.MouseWheelTicks ) > 120 )
2072 int direction = ( fgState.MouseWheelTicks > 0 ) ? 1 : -1;
2074 if( ! FETCH_WCB( *window, MouseWheel ) &&
2075 ! FETCH_WCB( *window, Mouse ) )
2078 fgSetWindow( window );
2079 fgState.Modifiers = fghGetWin32Modifiers( );
2082 * XXX Should use WHEEL_DELTA instead of 120
2084 while( abs ( fgState.MouseWheelTicks ) > 120 )
2086 if( FETCH_WCB( *window, MouseWheel ) )
2087 INVOKE_WCB( *window, MouseWheel,
2090 window->State.MouseX,
2091 window->State.MouseY
2094 else /* No mouse wheel, call the mouse button callback twice */
2097 * Map wheel zero to button 3 and 4; +1 to 3, -1 to 4
2098 * " " one +1 to 5, -1 to 6, ...
2100 * XXX The below assumes that you have no more than 3 mouse
2101 * XXX buttons. Sorry.
2103 int button = wheel_number * 2 + 3;
2106 INVOKE_WCB( *window, Mouse,
2107 ( button, GLUT_DOWN,
2108 window->State.MouseX, window->State.MouseY )
2110 INVOKE_WCB( *window, Mouse,
2112 window->State.MouseX, window->State.MouseY )
2117 * XXX Should use WHEEL_DELTA instead of 120
2119 fgState.MouseWheelTicks -= 120 * direction;
2122 fgState.Modifiers = INVALID_MODIFIERS;
2133 if( ( fgState.KeyRepeat==GLUT_KEY_REPEAT_OFF || window->State.IgnoreKeyRepeat==GL_TRUE ) && (HIWORD(lParam) & KF_REPEAT) )
2137 * Remember the current modifiers state. This is done here in order
2138 * to make sure the VK_DELETE keyboard callback is executed properly.
2140 fgState.Modifiers = fghGetWin32Modifiers( );
2142 GetCursorPos( &mouse_pos );
2143 ScreenToClient( window->Window.Handle, &mouse_pos );
2145 window->State.MouseX = mouse_pos.x;
2146 window->State.MouseY = mouse_pos.y;
2148 /* Convert the Win32 keystroke codes to GLUTtish way */
2149 # define KEY(a,b) case a: keypress = b; break;
2153 KEY( VK_F1, GLUT_KEY_F1 );
2154 KEY( VK_F2, GLUT_KEY_F2 );
2155 KEY( VK_F3, GLUT_KEY_F3 );
2156 KEY( VK_F4, GLUT_KEY_F4 );
2157 KEY( VK_F5, GLUT_KEY_F5 );
2158 KEY( VK_F6, GLUT_KEY_F6 );
2159 KEY( VK_F7, GLUT_KEY_F7 );
2160 KEY( VK_F8, GLUT_KEY_F8 );
2161 KEY( VK_F9, GLUT_KEY_F9 );
2162 KEY( VK_F10, GLUT_KEY_F10 );
2163 KEY( VK_F11, GLUT_KEY_F11 );
2164 KEY( VK_F12, GLUT_KEY_F12 );
2165 KEY( VK_PRIOR, GLUT_KEY_PAGE_UP );
2166 KEY( VK_NEXT, GLUT_KEY_PAGE_DOWN );
2167 KEY( VK_HOME, GLUT_KEY_HOME );
2168 KEY( VK_END, GLUT_KEY_END );
2169 KEY( VK_LEFT, GLUT_KEY_LEFT );
2170 KEY( VK_UP, GLUT_KEY_UP );
2171 KEY( VK_RIGHT, GLUT_KEY_RIGHT );
2172 KEY( VK_DOWN, GLUT_KEY_DOWN );
2173 KEY( VK_INSERT, GLUT_KEY_INSERT );
2174 KEY( VK_LCONTROL, GLUT_KEY_CTRL_L );
2175 KEY( VK_RCONTROL, GLUT_KEY_CTRL_R );
2176 KEY( VK_LSHIFT, GLUT_KEY_SHIFT_L );
2177 KEY( VK_RSHIFT, GLUT_KEY_SHIFT_R );
2178 KEY( VK_LMENU, GLUT_KEY_ALT_L );
2179 KEY( VK_RMENU, GLUT_KEY_ALT_R );
2182 /* The delete key should be treated as an ASCII keypress: */
2183 INVOKE_WCB( *window, Keyboard,
2184 ( 127, window->State.MouseX, window->State.MouseY )
2188 #if defined(_WIN32_WCE)
2189 if(!(lParam & 0x40000000)) /* Prevent auto-repeat */
2191 if(wParam==(unsigned)gxKeyList.vkRight)
2192 keypress = GLUT_KEY_RIGHT;
2193 else if(wParam==(unsigned)gxKeyList.vkLeft)
2194 keypress = GLUT_KEY_LEFT;
2195 else if(wParam==(unsigned)gxKeyList.vkUp)
2196 keypress = GLUT_KEY_UP;
2197 else if(wParam==(unsigned)gxKeyList.vkDown)
2198 keypress = GLUT_KEY_DOWN;
2199 else if(wParam==(unsigned)gxKeyList.vkA)
2200 keypress = GLUT_KEY_F1;
2201 else if(wParam==(unsigned)gxKeyList.vkB)
2202 keypress = GLUT_KEY_F2;
2203 else if(wParam==(unsigned)gxKeyList.vkC)
2204 keypress = GLUT_KEY_F3;
2205 else if(wParam==(unsigned)gxKeyList.vkStart)
2206 keypress = GLUT_KEY_F4;
2210 if( keypress != -1 )
2211 INVOKE_WCB( *window, Special,
2213 window->State.MouseX, window->State.MouseY )
2216 fgState.Modifiers = INVALID_MODIFIERS;
2227 * Remember the current modifiers state. This is done here in order
2228 * to make sure the VK_DELETE keyboard callback is executed properly.
2230 fgState.Modifiers = fghGetWin32Modifiers( );
2232 GetCursorPos( &mouse_pos );
2233 ScreenToClient( window->Window.Handle, &mouse_pos );
2235 window->State.MouseX = mouse_pos.x;
2236 window->State.MouseY = mouse_pos.y;
2239 * Convert the Win32 keystroke codes to GLUTtish way.
2240 * "KEY(a,b)" was defined under "WM_KEYDOWN"
2245 KEY( VK_F1, GLUT_KEY_F1 );
2246 KEY( VK_F2, GLUT_KEY_F2 );
2247 KEY( VK_F3, GLUT_KEY_F3 );
2248 KEY( VK_F4, GLUT_KEY_F4 );
2249 KEY( VK_F5, GLUT_KEY_F5 );
2250 KEY( VK_F6, GLUT_KEY_F6 );
2251 KEY( VK_F7, GLUT_KEY_F7 );
2252 KEY( VK_F8, GLUT_KEY_F8 );
2253 KEY( VK_F9, GLUT_KEY_F9 );
2254 KEY( VK_F10, GLUT_KEY_F10 );
2255 KEY( VK_F11, GLUT_KEY_F11 );
2256 KEY( VK_F12, GLUT_KEY_F12 );
2257 KEY( VK_PRIOR, GLUT_KEY_PAGE_UP );
2258 KEY( VK_NEXT, GLUT_KEY_PAGE_DOWN );
2259 KEY( VK_HOME, GLUT_KEY_HOME );
2260 KEY( VK_END, GLUT_KEY_END );
2261 KEY( VK_LEFT, GLUT_KEY_LEFT );
2262 KEY( VK_UP, GLUT_KEY_UP );
2263 KEY( VK_RIGHT, GLUT_KEY_RIGHT );
2264 KEY( VK_DOWN, GLUT_KEY_DOWN );
2265 KEY( VK_INSERT, GLUT_KEY_INSERT );
2266 KEY( VK_LCONTROL, GLUT_KEY_CTRL_L );
2267 KEY( VK_RCONTROL, GLUT_KEY_CTRL_R );
2268 KEY( VK_LSHIFT, GLUT_KEY_SHIFT_L );
2269 KEY( VK_RSHIFT, GLUT_KEY_SHIFT_R );
2270 KEY( VK_LMENU, GLUT_KEY_ALT_L );
2271 KEY( VK_RMENU, GLUT_KEY_ALT_R );
2274 /* The delete key should be treated as an ASCII keypress: */
2275 INVOKE_WCB( *window, KeyboardUp,
2276 ( 127, window->State.MouseX, window->State.MouseY )
2282 #if !defined(_WIN32_WCE)
2286 GetKeyboardState( state );
2288 if( ToAscii( (UINT)wParam, 0, state, code, 0 ) == 1 )
2291 INVOKE_WCB( *window, KeyboardUp,
2293 window->State.MouseX, window->State.MouseY )
2295 #endif /* !defined(_WIN32_WCE) */
2299 if( keypress != -1 )
2300 INVOKE_WCB( *window, SpecialUp,
2302 window->State.MouseX, window->State.MouseY )
2305 fgState.Modifiers = INVALID_MODIFIERS;
2312 if( (fgState.KeyRepeat==GLUT_KEY_REPEAT_OFF || window->State.IgnoreKeyRepeat==GL_TRUE) && (HIWORD(lParam) & KF_REPEAT) )
2315 fgState.Modifiers = fghGetWin32Modifiers( );
2316 INVOKE_WCB( *window, Keyboard,
2318 window->State.MouseX, window->State.MouseY )
2320 fgState.Modifiers = INVALID_MODIFIERS;
2324 case WM_CAPTURECHANGED:
2325 /* User has finished resizing the window, force a redraw */
2326 INVOKE_WCB( *window, Display, ( ) );
2328 /*lRet = DefWindowProc( hWnd, uMsg, wParam, lParam ); */
2331 /* Other messages that I have seen and which are not handled already */
2332 case WM_SETTEXT: /* 0x000c */
2333 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
2334 /* Pass it on to "DefWindowProc" to set the window text */
2337 case WM_GETTEXT: /* 0x000d */
2338 /* Ideally we would copy the title of the window into "lParam" */
2339 /* strncpy ( (char *)lParam, "Window Title", wParam );
2340 lRet = ( wParam > 12 ) ? 12 : wParam; */
2341 /* the number of characters copied */
2342 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
2345 case WM_GETTEXTLENGTH: /* 0x000e */
2346 /* Ideally we would get the length of the title of the window */
2348 /* the number of characters in "Window Title\0" (see above) */
2351 case WM_ERASEBKGND: /* 0x0014 */
2352 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
2355 #if !defined(_WIN32_WCE)
2356 case WM_SYNCPAINT: /* 0x0088 */
2357 /* Another window has moved, need to update this one */
2358 window->State.Redisplay = GL_TRUE;
2359 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
2360 /* Help screen says this message must be passed to "DefWindowProc" */
2363 case WM_NCPAINT: /* 0x0085 */
2364 /* Need to update the border of this window */
2365 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
2366 /* Pass it on to "DefWindowProc" to repaint a standard border */
2369 case WM_SYSCOMMAND : /* 0x0112 */
2372 * We have received a system command message. Try to act on it.
2373 * The commands are passed in through the "wParam" parameter:
2374 * The least significant digit seems to be which edge of the window
2375 * is being used for a resize event:
2379 * Congratulations and thanks to Richard Rauch for figuring this out..
2381 switch ( wParam & 0xfff0 )
2390 /* User has clicked on the "-" to minimize the window */
2391 /* Turn off the visibility */
2392 window->State.Visible = GL_FALSE ;
2399 case SC_NEXTWINDOW :
2402 case SC_PREVWINDOW :
2406 /* Followed very closely by a WM_CLOSE message */
2430 case SC_SCREENSAVE :
2436 #if(WINVER >= 0x0400)
2440 case SC_MONITORPOWER :
2443 case SC_CONTEXTHELP :
2445 #endif /* WINVER >= 0x0400 */
2449 fgWarning( "Unknown wParam type 0x%x", wParam );
2454 #endif /* !defined(_WIN32_WCE) */
2456 /* We need to pass the message on to the operating system as well */
2457 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
2461 /* handle multi-touch messages */
2464 unsigned int numInputs = (unsigned int)wParam;
2466 TOUCHINPUT* ti = (TOUCHINPUT*)malloc( sizeof(TOUCHINPUT)*numInputs);
2468 if (fghGetTouchInputInfo == (pGetTouchInputInfo)0xDEADBEEF) {
2469 fghGetTouchInputInfo = (pGetTouchInputInfo)GetProcAddress(GetModuleHandle("user32"),"GetTouchInputInfo");
2470 fghCloseTouchInputHandle = (pCloseTouchInputHandle)GetProcAddress(GetModuleHandle("user32"),"CloseTouchInputHandle");
2473 if (!fghGetTouchInputInfo) {
2478 if (fghGetTouchInputInfo( (HTOUCHINPUT)lParam, numInputs, ti, sizeof(TOUCHINPUT) )) {
2479 /* Handle each contact point */
2480 for (i = 0; i < numInputs; ++i ) {
2483 tp.x = TOUCH_COORD_TO_PIXEL(ti[i].x);
2484 tp.y = TOUCH_COORD_TO_PIXEL(ti[i].y);
2485 ScreenToClient( hWnd, &tp );
2487 ti[i].dwID = ti[i].dwID * 2;
2489 if (ti[i].dwFlags & TOUCHEVENTF_DOWN) {
2490 INVOKE_WCB( *window, MultiEntry, ( ti[i].dwID, GLUT_ENTERED ) );
2491 INVOKE_WCB( *window, MultiButton, ( ti[i].dwID, tp.x, tp.y, 0, GLUT_DOWN ) );
2492 } else if (ti[i].dwFlags & TOUCHEVENTF_MOVE) {
2493 INVOKE_WCB( *window, MultiMotion, ( ti[i].dwID, tp.x, tp.y ) );
2494 } else if (ti[i].dwFlags & TOUCHEVENTF_UP) {
2495 INVOKE_WCB( *window, MultiButton, ( ti[i].dwID, tp.x, tp.y, 0, GLUT_UP ) );
2496 INVOKE_WCB( *window, MultiEntry, ( ti[i].dwID, GLUT_LEFT ) );
2500 fghCloseTouchInputHandle((HTOUCHINPUT)lParam);
2502 lRet = 0; /*DefWindowProc( hWnd, uMsg, wParam, lParam );*/
2507 /* Handle unhandled messages */
2508 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
2516 /*** END OF FILE ***/