2 * freeglut_main_mswin.c
4 * The Windows-specific mouse cursor related stuff.
6 * Copyright (c) 2012 Stephen J. Baker. All Rights Reserved.
7 * Written by John F. Fay, <fayjf@sourceforge.net>
8 * Creation date: Sat Jan 21, 2012
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 "../fg_internal.h"
32 extern void fghRedrawWindow ( SFG_Window *window );
34 extern void fgNewWGLCreateContext( SFG_Window* window );
35 extern GLboolean fgSetupPixelFormat( SFG_Window* window, GLboolean checkOnly,
36 unsigned char layer_type );
38 extern void fgPlatformCheckMenuDeactivate();
41 typedef BOOL (WINAPI *pGetTouchInputInfo)(HTOUCHINPUT,UINT,PTOUCHINPUT,int);
42 typedef BOOL (WINAPI *pCloseTouchInputHandle)(HTOUCHINPUT);
43 static pGetTouchInputInfo fghGetTouchInputInfo = (pGetTouchInputInfo)0xDEADBEEF;
44 static pCloseTouchInputHandle fghCloseTouchInputHandle = (pCloseTouchInputHandle)0xDEADBEEF;
48 typedef struct GXDisplayProperties GXDisplayProperties;
49 typedef struct GXKeyList GXKeyList;
52 typedef struct GXKeyList (*GXGETDEFAULTKEYS)(int);
53 typedef int (*GXOPENINPUT)();
55 GXGETDEFAULTKEYS GXGetDefaultKeys_ = NULL;
56 GXOPENINPUT GXOpenInput_ = NULL;
58 struct GXKeyList gxKeyList;
59 #endif /* _WIN32_WCE */
62 * Helper functions for getting client area from the window rect
63 * and the window rect from the client area given the style of the window
64 * (or a valid window pointer from which the style can be queried).
66 extern void fghComputeWindowRectFromClientArea_QueryWindow( RECT *clientRect, const SFG_Window *window, BOOL posIsOutside );
67 extern void fghGetClientArea ( RECT *clientRect, const SFG_Window *window, BOOL wantPosOutside );
70 void fgPlatformReshapeWindow ( SFG_Window *window, int width, int height )
75 * For windowed mode, get the current position of the
76 * window and resize taking the size of the frame
77 * decorations into account.
79 * Note on maximizing behavior of Windows: the resize borders are off
80 * the screen such that the client area extends all the way from the
81 * leftmost corner to the rightmost corner to maximize screen real
82 * estate. A caption is still shown however to allow interaction with
83 * the window controls. This is default behavior of Windows that
84 * FreeGLUT sticks with. To alter, one would have to check if
85 * WS_MAXIMIZE style is set when a resize event is triggered, and
86 * then manually correct the windowRect to put the borders back on
90 /* "GetWindowRect" returns the pixel coordinates of the outside of the window */
91 GetWindowRect( window->Window.Handle, &windowRect );
93 /* Create rect in FreeGLUT format, (X,Y) topleft outside window, WxH of client area */
94 windowRect.right = windowRect.left+width;
95 windowRect.bottom = windowRect.top+height;
97 if (window->Parent == NULL)
98 /* get the window rect from this to feed to SetWindowPos, correct for window decorations */
99 fghComputeWindowRectFromClientArea_QueryWindow(&windowRect,window,TRUE);
102 /* correct rect for position client area of parent window
103 * (SetWindowPos input for child windows is in coordinates
104 * relative to the parent's client area).
105 * Child windows don't have decoration, so no need to correct
109 fghGetClientArea( &parentRect, window->Parent, FALSE );
110 OffsetRect(&windowRect,-parentRect.left,-parentRect.top);
113 /* Do the actual resizing */
114 SetWindowPos( window->Window.Handle,
116 windowRect.left, windowRect.top,
117 windowRect.right - windowRect.left,
118 windowRect.bottom- windowRect.top,
119 SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOSENDCHANGING |
125 void fgPlatformDisplayWindow ( SFG_Window *window )
128 window->Window.Handle, NULL, NULL,
129 RDW_NOERASE | RDW_INTERNALPAINT | RDW_INVALIDATE | RDW_UPDATENOW
134 fg_time_t fgPlatformSystemTime ( void )
136 #if defined(_WIN32_WCE)
137 return GetTickCount();
139 /* TODO: do this with QueryPerformanceCounter as timeGetTime has
140 * insufficient resolution (only about 5 ms on system under low load).
142 * http://msdn.microsoft.com/en-us/library/windows/desktop/dd757629(v=vs.85).aspx
143 * Or maybe QueryPerformanceCounter is not a good idea either, see
144 * http://old.nabble.com/Re%3A-glutTimerFunc-does-not-detect-if-system-time-moved-backward-p33479674.html
145 * for some other ideas (at bottom)...
147 return timeGetTime();
152 void fgPlatformSleepForEvents( fg_time_t msec )
154 MsgWaitForMultipleObjects( 0, NULL, FALSE, (DWORD) msec, QS_ALLINPUT );
158 void fgPlatformProcessSingleEvent ( void )
162 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutMainLoopEvent" );
164 while( PeekMessage( &stMsg, NULL, 0, 0, PM_NOREMOVE ) )
166 if( GetMessage( &stMsg, NULL, 0, 0 ) == 0 )
168 if( fgState.ActionOnWindowClose == GLUT_ACTION_EXIT )
173 else if( fgState.ActionOnWindowClose == GLUT_ACTION_GLUTMAINLOOP_RETURNS )
174 fgState.ExecState = GLUT_EXEC_STATE_STOP;
179 TranslateMessage( &stMsg );
180 DispatchMessage( &stMsg );
186 void fgPlatformMainLoopPreliminaryWork ( void )
188 SFG_Window *window = (SFG_Window *)fgStructure.Windows.First ;
191 * Processing before the main loop: If there is a window which is open and
192 * which has a visibility callback, call it. I know this is an ugly hack,
193 * but I'm not sure what else to do about it. Ideally we should leave
194 * something uninitialized in the create window code and initialize it in
195 * the main loop, and have that initialization create a "WM_ACTIVATE"
196 * message. Then we would put the visibility callback code in the
197 * "case WM_ACTIVATE" block below. - John Fay -- 10/24/02
201 if ( FETCH_WCB( *window, Visibility ) )
203 SFG_Window *current_window = fgStructure.CurrentWindow ;
205 INVOKE_WCB( *window, Visibility, ( window->State.Visible ) );
206 fgSetWindow( current_window );
209 window = (SFG_Window *)window->Node.Next ;
215 * Determine a GLUT modifier mask based on MS-WINDOWS system info.
217 static int fgPlatformGetModifiers (void)
220 ( ( ( GetKeyState( VK_LSHIFT ) < 0 ) ||
221 ( GetKeyState( VK_RSHIFT ) < 0 )) ? GLUT_ACTIVE_SHIFT : 0 ) |
222 ( ( ( GetKeyState( VK_LCONTROL ) < 0 ) ||
223 ( GetKeyState( VK_RCONTROL ) < 0 )) ? GLUT_ACTIVE_CTRL : 0 ) |
224 ( ( ( GetKeyState( VK_LMENU ) < 0 ) ||
225 ( GetKeyState( VK_RMENU ) < 0 )) ? GLUT_ACTIVE_ALT : 0 );
229 * The window procedure for handling Win32 events
231 LRESULT CALLBACK fgPlatformWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam,
234 static unsigned char lControl = 0, rControl = 0, lShift = 0,
235 rShift = 0, lAlt = 0, rAlt = 0;
237 SFG_Window *window, *child_window = NULL;
241 FREEGLUT_INTERNAL_ERROR_EXIT_IF_NOT_INITIALISED ( "Event Handler" ) ;
243 window = fgWindowByHandle( hWnd );
245 if ( ( window == NULL ) && ( uMsg != WM_CREATE ) )
246 return DefWindowProc( hWnd, uMsg, wParam, lParam );
248 /* printf ( "Window %3d message <%04x> %12d %12d\n", window?window->ID:0,
249 uMsg, wParam, lParam ); */
251 /* Some events only sent to main window. Check if the current window that
252 * the mouse is over is a child window. Below when handling some messages,
253 * we make sure that we process callbacks on the child window instead.
254 * This mirrors how GLUT does things.
256 if (window && window->Children.First)
259 SFG_WindowHandleType hwnd;
260 SFG_Window* temp_window;
262 GetCursorPos( &mouse_pos );
263 ScreenToClient( window->Window.Handle, &mouse_pos );
264 hwnd = ChildWindowFromPoint(window->Window.Handle, mouse_pos);
265 if (hwnd) /* can be NULL if mouse outside parent by the time we get here */
267 temp_window = fgWindowByHandle(hwnd);
268 if (temp_window->Parent) /* Verify we got a child window */
269 child_window = temp_window;
275 SFG_Window* temp_window = child_window?child_window:window;
277 fgState.Modifiers = fgPlatformGetModifiers( );
279 /* Checking for CTRL, ALT, and SHIFT key positions: Key Down! */
280 #define SPECIAL_KEY_DOWN(winKey,glutKey,winProcVar)\
281 if ( !winProcVar && GetAsyncKeyState ( winKey ) )\
283 INVOKE_WCB ( *temp_window, Special,\
284 ( glutKey, temp_window->State.MouseX, temp_window->State.MouseY )\
289 SPECIAL_KEY_DOWN(VK_LCONTROL,GLUT_KEY_CTRL_L ,lControl);
290 SPECIAL_KEY_DOWN(VK_RCONTROL,GLUT_KEY_CTRL_R ,rControl);
291 SPECIAL_KEY_DOWN(VK_LSHIFT ,GLUT_KEY_SHIFT_L,lShift);
292 SPECIAL_KEY_DOWN(VK_RSHIFT ,GLUT_KEY_SHIFT_R,rShift);
293 SPECIAL_KEY_DOWN(VK_LMENU ,GLUT_KEY_ALT_L ,lAlt);
294 SPECIAL_KEY_DOWN(VK_RMENU ,GLUT_KEY_ALT_R ,rAlt);
295 #undef SPECIAL_KEY_DOWN
297 /* Checking for CTRL, ALT, and SHIFT key positions: Key Up! */
298 #define SPECIAL_KEY_UP(winKey,glutKey,winProcVar)\
299 if ( winProcVar && !GetAsyncKeyState ( winKey ) )\
301 INVOKE_WCB ( *temp_window, SpecialUp,\
302 ( glutKey, temp_window->State.MouseX, temp_window->State.MouseY )\
307 SPECIAL_KEY_UP(VK_LCONTROL,GLUT_KEY_CTRL_L ,lControl);
308 SPECIAL_KEY_UP(VK_RCONTROL,GLUT_KEY_CTRL_R ,rControl);
309 SPECIAL_KEY_UP(VK_LSHIFT ,GLUT_KEY_SHIFT_L,lShift);
310 SPECIAL_KEY_UP(VK_RSHIFT ,GLUT_KEY_SHIFT_R,rShift);
311 SPECIAL_KEY_UP(VK_LMENU ,GLUT_KEY_ALT_L ,lAlt);
312 SPECIAL_KEY_UP(VK_RMENU ,GLUT_KEY_ALT_R ,rAlt);
313 #undef SPECIAL_KEY_UP
315 fgState.Modifiers = INVALID_MODIFIERS;
321 /* The window structure is passed as the creation structure parameter... */
322 window = (SFG_Window *) (((LPCREATESTRUCT) lParam)->lpCreateParams);
323 FREEGLUT_INTERNAL_ERROR_EXIT ( ( window != NULL ), "Cannot create window",
324 "fgPlatformWindowProc" );
326 window->Window.Handle = hWnd;
327 window->Window.pContext.Device = GetDC( hWnd );
330 unsigned int current_DisplayMode = fgState.DisplayMode;
331 fgState.DisplayMode = GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH;
332 #if !defined(_WIN32_WCE)
333 fgSetupPixelFormat( window, GL_FALSE, PFD_MAIN_PLANE );
335 fgState.DisplayMode = current_DisplayMode;
337 if( fgStructure.MenuContext )
338 wglMakeCurrent( window->Window.pContext.Device,
339 fgStructure.MenuContext->MContext
343 fgStructure.MenuContext =
344 (SFG_MenuContext *)malloc( sizeof(SFG_MenuContext) );
345 fgStructure.MenuContext->MContext =
346 wglCreateContext( window->Window.pContext.Device );
349 /* window->Window.Context = wglGetCurrentContext (); */
350 window->Window.Context = wglCreateContext( window->Window.pContext.Device );
354 #if !defined(_WIN32_WCE)
355 fgSetupPixelFormat( window, GL_FALSE, PFD_MAIN_PLANE );
358 if( ! fgState.UseCurrentContext )
359 window->Window.Context =
360 wglCreateContext( window->Window.pContext.Device );
363 window->Window.Context = wglGetCurrentContext( );
364 if( ! window->Window.Context )
365 window->Window.Context =
366 wglCreateContext( window->Window.pContext.Device );
369 #if !defined(_WIN32_WCE)
370 fgNewWGLCreateContext( window );
374 window->State.NeedToResize = GL_TRUE;
375 /* if we used CW_USEDEFAULT (thats a negative value) for the size
376 * of the window, query the window now for the size at which it
379 if( ( window->State.Width < 0 ) || ( window->State.Height < 0 ) )
381 SFG_Window *current_window = fgStructure.CurrentWindow;
383 fgSetWindow( window );
384 window->State.Width = glutGet( GLUT_WINDOW_WIDTH );
385 window->State.Height = glutGet( GLUT_WINDOW_HEIGHT );
386 fgSetWindow( current_window );
389 ReleaseDC( window->Window.Handle, window->Window.pContext.Device );
391 #if defined(_WIN32_WCE)
392 /* Take over button handling */
394 HINSTANCE dxDllLib=LoadLibrary(_T("gx.dll"));
397 GXGetDefaultKeys_=(GXGETDEFAULTKEYS)GetProcAddress(dxDllLib, _T("?GXGetDefaultKeys@@YA?AUGXKeyList@@H@Z"));
398 GXOpenInput_=(GXOPENINPUT)GetProcAddress(dxDllLib, _T("?GXOpenInput@@YAHXZ"));
403 if(GXGetDefaultKeys_)
404 gxKeyList = (*GXGetDefaultKeys_)(GX_LANDSCAPEKEYS);
407 #endif /* defined(_WIN32_WCE) */
412 * If the window is visible, then it is the user manually resizing it.
413 * If it is not, then it is the system sending us a dummy resize with
414 * zero dimensions on a "glutIconifyWindow" call.
416 if( window->State.Visible )
418 window->State.NeedToResize = GL_TRUE;
419 #if defined(_WIN32_WCE)
420 window->State.Width = HIWORD(lParam);
421 window->State.Height = LOWORD(lParam);
423 window->State.Width = LOWORD(lParam);
424 window->State.Height = HIWORD(lParam);
425 #endif /* defined(_WIN32_WCE) */
431 /* printf("WM_SETFOCUS: %p\n", window ); */
433 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
437 /* If we're dealing with a child window, make sure it has input focus instead, set it here. */
438 SetFocus(child_window->Window.Handle);
439 SetActiveWindow( child_window->Window.Handle );
440 INVOKE_WCB( *child_window, Entry, ( GLUT_ENTERED ) );
441 UpdateWindow ( child_window->Window.Handle );
445 SetActiveWindow( window->Window.Handle );
446 INVOKE_WCB( *window, Entry, ( GLUT_ENTERED ) );
448 /* Always request update on main window to be safe */
449 UpdateWindow ( hWnd );
455 SFG_Window* saved_window = fgStructure.CurrentWindow;
456 /* printf("WM_KILLFOCUS: %p\n", window ); */
457 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
458 INVOKE_WCB( *window, Entry, ( GLUT_LEFT ) );
459 fgSetWindow(saved_window);
461 /* Check if there are any open menus that need to be closed */
462 fgPlatformCheckMenuDeactivate();
468 if (LOWORD(wParam) != WA_INACTIVE)
470 /* printf("WM_ACTIVATE: fgSetCursor( %p, %d)\n", window,
471 window->State.Cursor ); */
472 fgSetCursor( window, window->State.Cursor );
475 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
480 /* printf ( "Cursor event %x %x %x %x\n", window, window->State.Cursor, lParam, wParam ) ; */
481 if( LOWORD( lParam ) == HTCLIENT )
482 fgSetCursor ( window, window->State.Cursor ) ;
484 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
488 window->State.Visible = GL_TRUE;
489 window->State.Redisplay = GL_TRUE;
493 /* Turn on the visibility in case it was turned off somehow */
494 window->State.Visible = GL_TRUE;
495 InvalidateRect( hWnd, NULL, GL_FALSE ); /* Make sure whole window is repainted. Bit of a hack, but a safe one from what google turns up... */
496 BeginPaint( hWnd, &ps );
497 fghRedrawWindow( window );
498 EndPaint( hWnd, &ps );
502 fgDestroyWindow ( window );
503 if ( fgState.ActionOnWindowClose != GLUT_ACTION_CONTINUE_EXECUTION )
509 * The window already got destroyed, so don't bother with it.
515 #if defined(_WIN32_WCE)
516 window->State.MouseX = 320-HIWORD( lParam );
517 window->State.MouseY = LOWORD( lParam );
519 window->State.MouseX = LOWORD( lParam );
520 window->State.MouseY = HIWORD( lParam );
521 #endif /* defined(_WIN32_WCE) */
522 /* Restrict to [-32768, 32767] to match X11 behaviour */
523 /* See comment in "freeglut_developer" mailing list 10/4/04 */
524 if ( window->State.MouseX > 32767 ) window->State.MouseX -= 65536;
525 if ( window->State.MouseY > 32767 ) window->State.MouseY -= 65536;
527 if ( window->ActiveMenu )
529 fgUpdateMenuHighlight( window->ActiveMenu );
533 fgState.Modifiers = fgPlatformGetModifiers( );
535 if( ( wParam & MK_LBUTTON ) ||
536 ( wParam & MK_MBUTTON ) ||
537 ( wParam & MK_RBUTTON ) )
538 INVOKE_WCB( *window, Motion, ( window->State.MouseX,
539 window->State.MouseY ) );
541 INVOKE_WCB( *window, Passive, ( window->State.MouseX,
542 window->State.MouseY ) );
544 fgState.Modifiers = INVALID_MODIFIERS;
555 GLboolean pressed = GL_TRUE;
558 #if defined(_WIN32_WCE)
559 window->State.MouseX = 320-HIWORD( lParam );
560 window->State.MouseY = LOWORD( lParam );
562 window->State.MouseX = LOWORD( lParam );
563 window->State.MouseY = HIWORD( lParam );
564 #endif /* defined(_WIN32_WCE) */
566 /* Restrict to [-32768, 32767] to match X11 behaviour */
567 /* See comment in "freeglut_developer" mailing list 10/4/04 */
568 if ( window->State.MouseX > 32767 ) window->State.MouseX -= 65536;
569 if ( window->State.MouseY > 32767 ) window->State.MouseY -= 65536;
575 button = GLUT_LEFT_BUTTON;
579 button = GLUT_MIDDLE_BUTTON;
583 button = GLUT_RIGHT_BUTTON;
587 button = GLUT_LEFT_BUTTON;
591 button = GLUT_MIDDLE_BUTTON;
595 button = GLUT_RIGHT_BUTTON;
603 #if !defined(_WIN32_WCE)
604 if( GetSystemMetrics( SM_SWAPBUTTON ) )
606 if( button == GLUT_LEFT_BUTTON )
607 button = GLUT_RIGHT_BUTTON;
609 if( button == GLUT_RIGHT_BUTTON )
610 button = GLUT_LEFT_BUTTON;
612 #endif /* !defined(_WIN32_WCE) */
615 return DefWindowProc( hWnd, uMsg, lParam, wParam );
618 * Do not execute the application's mouse callback if a menu
619 * is hooked to this button. In that case an appropriate
620 * private call should be generated.
622 if( fgCheckActiveMenu( window, button, pressed,
623 window->State.MouseX, window->State.MouseY ) )
626 /* Set capture so that the window captures all the mouse messages */
628 * XXX - Multiple button support: Under X11, the mouse is not released
629 * XXX - from the window until all buttons have been released, even if the
630 * XXX - user presses a button in another window. This will take more
631 * XXX - code changes than I am up to at the moment (10/5/04). The present
632 * XXX - is a 90 percent solution.
634 if ( pressed == GL_TRUE )
635 SetCapture ( window->Window.Handle ) ;
639 if( ! FETCH_WCB( *window, Mouse ) )
642 fgSetWindow( window );
643 fgState.Modifiers = fgPlatformGetModifiers( );
648 pressed ? GLUT_DOWN : GLUT_UP,
649 window->State.MouseX,
654 fgState.Modifiers = INVALID_MODIFIERS;
660 int wheel_number = LOWORD( wParam );
661 short ticks = ( short )HIWORD( wParam );
662 fgState.MouseWheelTicks += ticks;
664 if ( abs ( fgState.MouseWheelTicks ) >= WHEEL_DELTA )
666 int direction = ( fgState.MouseWheelTicks > 0 ) ? 1 : -1;
668 if( ! FETCH_WCB( *window, MouseWheel ) &&
669 ! FETCH_WCB( *window, Mouse ) )
672 fgSetWindow( window );
673 fgState.Modifiers = fgPlatformGetModifiers( );
675 while( abs ( fgState.MouseWheelTicks ) >= WHEEL_DELTA )
677 if( FETCH_WCB( *window, MouseWheel ) )
678 INVOKE_WCB( *window, MouseWheel,
681 window->State.MouseX,
685 else /* No mouse wheel, call the mouse button callback twice */
688 * Map wheel zero to button 3 and 4; +1 to 3, -1 to 4
689 * " " one +1 to 5, -1 to 6, ...
691 * XXX The below assumes that you have no more than 3 mouse
692 * XXX buttons. Sorry.
694 int button = wheel_number * 2 + 3;
697 INVOKE_WCB( *window, Mouse,
699 window->State.MouseX, window->State.MouseY )
701 INVOKE_WCB( *window, Mouse,
703 window->State.MouseX, window->State.MouseY )
707 fgState.MouseWheelTicks -= WHEEL_DELTA * direction;
710 fgState.Modifiers = INVALID_MODIFIERS;
722 window = child_window;
724 if( ( fgState.KeyRepeat==GLUT_KEY_REPEAT_OFF || window->State.IgnoreKeyRepeat==GL_TRUE ) && (HIWORD(lParam) & KF_REPEAT) )
728 * Remember the current modifiers state. This is done here in order
729 * to make sure the VK_DELETE keyboard callback is executed properly.
731 fgState.Modifiers = fgPlatformGetModifiers( );
733 GetCursorPos( &mouse_pos );
734 ScreenToClient( window->Window.Handle, &mouse_pos );
736 window->State.MouseX = mouse_pos.x;
737 window->State.MouseY = mouse_pos.y;
739 /* Convert the Win32 keystroke codes to GLUTtish way */
740 # define KEY(a,b) case a: keypress = b; break;
744 KEY( VK_F1, GLUT_KEY_F1 );
745 KEY( VK_F2, GLUT_KEY_F2 );
746 KEY( VK_F3, GLUT_KEY_F3 );
747 KEY( VK_F4, GLUT_KEY_F4 );
748 KEY( VK_F5, GLUT_KEY_F5 );
749 KEY( VK_F6, GLUT_KEY_F6 );
750 KEY( VK_F7, GLUT_KEY_F7 );
751 KEY( VK_F8, GLUT_KEY_F8 );
752 KEY( VK_F9, GLUT_KEY_F9 );
753 KEY( VK_F10, GLUT_KEY_F10 );
754 KEY( VK_F11, GLUT_KEY_F11 );
755 KEY( VK_F12, GLUT_KEY_F12 );
756 KEY( VK_PRIOR, GLUT_KEY_PAGE_UP );
757 KEY( VK_NEXT, GLUT_KEY_PAGE_DOWN );
758 KEY( VK_HOME, GLUT_KEY_HOME );
759 KEY( VK_END, GLUT_KEY_END );
760 KEY( VK_LEFT, GLUT_KEY_LEFT );
761 KEY( VK_UP, GLUT_KEY_UP );
762 KEY( VK_RIGHT, GLUT_KEY_RIGHT );
763 KEY( VK_DOWN, GLUT_KEY_DOWN );
764 KEY( VK_INSERT, GLUT_KEY_INSERT );
766 case VK_LCONTROL: case VK_RCONTROL: case VK_CONTROL:
767 case VK_LSHIFT: case VK_RSHIFT: case VK_SHIFT:
768 case VK_LMENU: case VK_RMENU: case VK_MENU:
769 /* These keypresses and releases are handled earlier in the function */
773 /* The delete key should be treated as an ASCII keypress: */
774 INVOKE_WCB( *window, Keyboard,
775 ( 127, window->State.MouseX, window->State.MouseY )
779 #if defined(_WIN32_WCE)
780 if(!(lParam & 0x40000000)) /* Prevent auto-repeat */
782 if(wParam==(unsigned)gxKeyList.vkRight)
783 keypress = GLUT_KEY_RIGHT;
784 else if(wParam==(unsigned)gxKeyList.vkLeft)
785 keypress = GLUT_KEY_LEFT;
786 else if(wParam==(unsigned)gxKeyList.vkUp)
787 keypress = GLUT_KEY_UP;
788 else if(wParam==(unsigned)gxKeyList.vkDown)
789 keypress = GLUT_KEY_DOWN;
790 else if(wParam==(unsigned)gxKeyList.vkA)
791 keypress = GLUT_KEY_F1;
792 else if(wParam==(unsigned)gxKeyList.vkB)
793 keypress = GLUT_KEY_F2;
794 else if(wParam==(unsigned)gxKeyList.vkC)
795 keypress = GLUT_KEY_F3;
796 else if(wParam==(unsigned)gxKeyList.vkStart)
797 keypress = GLUT_KEY_F4;
802 INVOKE_WCB( *window, Special,
804 window->State.MouseX, window->State.MouseY )
807 fgState.Modifiers = INVALID_MODIFIERS;
818 window = child_window;
821 * Remember the current modifiers state. This is done here in order
822 * to make sure the VK_DELETE keyboard callback is executed properly.
824 fgState.Modifiers = fgPlatformGetModifiers( );
826 GetCursorPos( &mouse_pos );
827 ScreenToClient( window->Window.Handle, &mouse_pos );
829 window->State.MouseX = mouse_pos.x;
830 window->State.MouseY = mouse_pos.y;
833 * Convert the Win32 keystroke codes to GLUTtish way.
834 * "KEY(a,b)" was defined under "WM_KEYDOWN"
839 KEY( VK_F1, GLUT_KEY_F1 );
840 KEY( VK_F2, GLUT_KEY_F2 );
841 KEY( VK_F3, GLUT_KEY_F3 );
842 KEY( VK_F4, GLUT_KEY_F4 );
843 KEY( VK_F5, GLUT_KEY_F5 );
844 KEY( VK_F6, GLUT_KEY_F6 );
845 KEY( VK_F7, GLUT_KEY_F7 );
846 KEY( VK_F8, GLUT_KEY_F8 );
847 KEY( VK_F9, GLUT_KEY_F9 );
848 KEY( VK_F10, GLUT_KEY_F10 );
849 KEY( VK_F11, GLUT_KEY_F11 );
850 KEY( VK_F12, GLUT_KEY_F12 );
851 KEY( VK_PRIOR, GLUT_KEY_PAGE_UP );
852 KEY( VK_NEXT, GLUT_KEY_PAGE_DOWN );
853 KEY( VK_HOME, GLUT_KEY_HOME );
854 KEY( VK_END, GLUT_KEY_END );
855 KEY( VK_LEFT, GLUT_KEY_LEFT );
856 KEY( VK_UP, GLUT_KEY_UP );
857 KEY( VK_RIGHT, GLUT_KEY_RIGHT );
858 KEY( VK_DOWN, GLUT_KEY_DOWN );
859 KEY( VK_INSERT, GLUT_KEY_INSERT );
861 case VK_LCONTROL: case VK_RCONTROL: case VK_CONTROL:
862 case VK_LSHIFT: case VK_RSHIFT: case VK_SHIFT:
863 case VK_LMENU: case VK_RMENU: case VK_MENU:
864 /* These keypresses and releases are handled earlier in the function */
868 /* The delete key should be treated as an ASCII keypress: */
869 INVOKE_WCB( *window, KeyboardUp,
870 ( 127, window->State.MouseX, window->State.MouseY )
876 #if !defined(_WIN32_WCE)
880 GetKeyboardState( state );
882 if( ToAscii( (UINT)wParam, 0, state, code, 0 ) == 1 )
885 INVOKE_WCB( *window, KeyboardUp,
887 window->State.MouseX, window->State.MouseY )
889 #endif /* !defined(_WIN32_WCE) */
894 INVOKE_WCB( *window, SpecialUp,
896 window->State.MouseX, window->State.MouseY )
899 fgState.Modifiers = INVALID_MODIFIERS;
907 window = child_window;
909 if( (fgState.KeyRepeat==GLUT_KEY_REPEAT_OFF || window->State.IgnoreKeyRepeat==GL_TRUE) && (HIWORD(lParam) & KF_REPEAT) )
912 fgState.Modifiers = fgPlatformGetModifiers( );
913 INVOKE_WCB( *window, Keyboard,
915 window->State.MouseX, window->State.MouseY )
917 fgState.Modifiers = INVALID_MODIFIERS;
921 case WM_CAPTURECHANGED:
922 /* User has finished resizing the window, force a redraw */
923 INVOKE_WCB( *window, Display, ( ) );
925 /*lRet = DefWindowProc( hWnd, uMsg, wParam, lParam ); */
928 /* Other messages that I have seen and which are not handled already */
929 case WM_SETTEXT: /* 0x000c */
930 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
931 /* Pass it on to "DefWindowProc" to set the window text */
934 case WM_GETTEXT: /* 0x000d */
935 /* Ideally we would copy the title of the window into "lParam" */
936 /* strncpy ( (char *)lParam, "Window Title", wParam );
937 lRet = ( wParam > 12 ) ? 12 : wParam; */
938 /* the number of characters copied */
939 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
942 case WM_GETTEXTLENGTH: /* 0x000e */
943 /* Ideally we would get the length of the title of the window */
945 /* the number of characters in "Window Title\0" (see above) */
948 case WM_ERASEBKGND: /* 0x0014 */
949 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
952 #if !defined(_WIN32_WCE)
953 case WM_SYNCPAINT: /* 0x0088 */
954 /* Another window has moved, need to update this one */
955 window->State.Redisplay = GL_TRUE;
956 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
957 /* Help screen says this message must be passed to "DefWindowProc" */
960 case WM_NCPAINT: /* 0x0085 */
961 /* Need to update the border of this window */
962 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
963 /* Pass it on to "DefWindowProc" to repaint a standard border */
966 case WM_SYSCOMMAND : /* 0x0112 */
969 * We have received a system command message. Try to act on it.
970 * The commands are passed in through the "wParam" parameter:
971 * The least significant digit seems to be which edge of the window
972 * is being used for a resize event:
976 * Congratulations and thanks to Richard Rauch for figuring this out..
978 switch ( wParam & 0xfff0 )
987 /* User has clicked on the "-" to minimize the window */
988 /* Turn off the visibility */
989 window->State.Visible = GL_FALSE ;
1003 /* Followed very closely by a WM_CLOSE message */
1027 case SC_SCREENSAVE :
1033 #if(WINVER >= 0x0400)
1037 case SC_MONITORPOWER :
1040 case SC_CONTEXTHELP :
1042 #endif /* WINVER >= 0x0400 */
1046 fgWarning( "Unknown wParam type 0x%x", wParam );
1051 #endif /* !defined(_WIN32_WCE) */
1053 /* We need to pass the message on to the operating system as well */
1054 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1058 /* handle multi-touch messages */
1061 unsigned int numInputs = (unsigned int)wParam;
1063 TOUCHINPUT* ti = (TOUCHINPUT*)malloc( sizeof(TOUCHINPUT)*numInputs);
1065 if (fghGetTouchInputInfo == (pGetTouchInputInfo)0xDEADBEEF) {
1066 fghGetTouchInputInfo = (pGetTouchInputInfo)GetProcAddress(GetModuleHandle("user32"),"GetTouchInputInfo");
1067 fghCloseTouchInputHandle = (pCloseTouchInputHandle)GetProcAddress(GetModuleHandle("user32"),"CloseTouchInputHandle");
1070 if (!fghGetTouchInputInfo) {
1075 if (fghGetTouchInputInfo( (HTOUCHINPUT)lParam, numInputs, ti, sizeof(TOUCHINPUT) )) {
1076 /* Handle each contact point */
1077 for (i = 0; i < numInputs; ++i ) {
1080 tp.x = TOUCH_COORD_TO_PIXEL(ti[i].x);
1081 tp.y = TOUCH_COORD_TO_PIXEL(ti[i].y);
1082 ScreenToClient( hWnd, &tp );
1084 ti[i].dwID = ti[i].dwID * 2;
1086 if (ti[i].dwFlags & TOUCHEVENTF_DOWN) {
1087 INVOKE_WCB( *window, MultiEntry, ( ti[i].dwID, GLUT_ENTERED ) );
1088 INVOKE_WCB( *window, MultiButton, ( ti[i].dwID, tp.x, tp.y, 0, GLUT_DOWN ) );
1089 } else if (ti[i].dwFlags & TOUCHEVENTF_MOVE) {
1090 INVOKE_WCB( *window, MultiMotion, ( ti[i].dwID, tp.x, tp.y ) );
1091 } else if (ti[i].dwFlags & TOUCHEVENTF_UP) {
1092 INVOKE_WCB( *window, MultiButton, ( ti[i].dwID, tp.x, tp.y, 0, GLUT_UP ) );
1093 INVOKE_WCB( *window, MultiEntry, ( ti[i].dwID, GLUT_LEFT ) );
1097 fghCloseTouchInputHandle((HTOUCHINPUT)lParam);
1099 lRet = 0; /*DefWindowProc( hWnd, uMsg, wParam, lParam );*/
1104 /* Handle unhandled messages */
1105 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );