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 "../Common/freeglut_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 );
39 typedef BOOL (WINAPI *pGetTouchInputInfo)(HTOUCHINPUT,UINT,PTOUCHINPUT,int);
40 typedef BOOL (WINAPI *pCloseTouchInputHandle)(HTOUCHINPUT);
41 static pGetTouchInputInfo fghGetTouchInputInfo = (pGetTouchInputInfo)0xDEADBEEF;
42 static pCloseTouchInputHandle fghCloseTouchInputHandle = (pCloseTouchInputHandle)0xDEADBEEF;
46 * Helper functions for getting client area from the window rect
47 * and the window rect from the client area given the style of the window
48 * (or a valid window pointer from which the style can be queried).
50 extern void fghComputeWindowRectFromClientArea_QueryWindow( const SFG_Window *window, RECT *clientRect, BOOL posIsOutside );
51 extern RECT fghGetClientArea ( const SFG_Window *window, BOOL wantPosOutside );
54 void fgPlatformReshapeWindow ( SFG_Window *window, int width, int height )
59 * For windowed mode, get the current position of the
60 * window and resize taking the size of the frame
61 * decorations into account.
64 /* "GetWindowRect" returns the pixel coordinates of the outside of the window */
65 GetWindowRect( window->Window.Handle, &windowRect );
67 /* Create rect in FreeGLUT format, (X,Y) topleft outside window, WxH of client area */
68 windowRect.right = windowRect.left+width;
69 windowRect.bottom = windowRect.top+height;
71 if (window->Parent == NULL)
72 /* get the window rect from this to feed to SetWindowPos, correct for window decorations */
73 fghComputeWindowRectFromClientArea_QueryWindow(window,&windowRect,TRUE);
76 /* correct rect for position client area of parent window
77 * (SetWindowPos input for child windows is in coordinates
78 * relative to the parent's client area).
79 * Child windows don't have decoration, so no need to correct
83 parentRect = fghGetClientArea( window->Parent, FALSE );
84 windowRect.left -= parentRect.left;
85 windowRect.right -= parentRect.left;
86 windowRect.top -= parentRect.top;
87 windowRect.bottom -= parentRect.top;
90 /* Do the actual resizing */
91 SetWindowPos( window->Window.Handle,
93 windowRect.left, windowRect.top,
94 windowRect.right - windowRect.left,
95 windowRect.bottom- windowRect.top,
96 SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOSENDCHANGING |
102 void fgPlatformDisplayWindow ( SFG_Window *window )
105 window->Window.Handle, NULL, NULL,
106 RDW_NOERASE | RDW_INTERNALPAINT | RDW_INVALIDATE | RDW_UPDATENOW
111 unsigned long fgPlatformSystemTime ( void )
113 #if defined(_WIN32_WCE)
114 return GetTickCount();
116 return timeGetTime();
121 void fgPlatformSleepForEvents( long msec )
123 MsgWaitForMultipleObjects( 0, NULL, FALSE, msec, QS_ALLINPUT );
127 void fgPlatformProcessSingleEvent ( void )
131 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutMainLoopEvent" );
133 while( PeekMessage( &stMsg, NULL, 0, 0, PM_NOREMOVE ) )
135 if( GetMessage( &stMsg, NULL, 0, 0 ) == 0 )
137 if( fgState.ActionOnWindowClose == GLUT_ACTION_EXIT )
142 else if( fgState.ActionOnWindowClose == GLUT_ACTION_GLUTMAINLOOP_RETURNS )
143 fgState.ExecState = GLUT_EXEC_STATE_STOP;
148 TranslateMessage( &stMsg );
149 DispatchMessage( &stMsg );
155 void fgPlatformMainLoopPreliminaryWork ( void )
157 SFG_Window *window = (SFG_Window *)fgStructure.Windows.First ;
160 * Processing before the main loop: If there is a window which is open and
161 * which has a visibility callback, call it. I know this is an ugly hack,
162 * but I'm not sure what else to do about it. Ideally we should leave
163 * something uninitialized in the create window code and initialize it in
164 * the main loop, and have that initialization create a "WM_ACTIVATE"
165 * message. Then we would put the visibility callback code in the
166 * "case WM_ACTIVATE" block below. - John Fay -- 10/24/02
170 if ( FETCH_WCB( *window, Visibility ) )
172 SFG_Window *current_window = fgStructure.CurrentWindow ;
174 INVOKE_WCB( *window, Visibility, ( window->State.Visible ) );
175 fgSetWindow( current_window );
178 window = (SFG_Window *)window->Node.Next ;
184 * Determine a GLUT modifer mask based on MS-WINDOWS system info.
186 static int fgPlatformGetModifiers (void)
189 ( ( ( GetKeyState( VK_LSHIFT ) < 0 ) ||
190 ( GetKeyState( VK_RSHIFT ) < 0 )) ? GLUT_ACTIVE_SHIFT : 0 ) |
191 ( ( ( GetKeyState( VK_LCONTROL ) < 0 ) ||
192 ( GetKeyState( VK_RCONTROL ) < 0 )) ? GLUT_ACTIVE_CTRL : 0 ) |
193 ( ( ( GetKeyState( VK_LMENU ) < 0 ) ||
194 ( GetKeyState( VK_RMENU ) < 0 )) ? GLUT_ACTIVE_ALT : 0 );
198 * The window procedure for handling Win32 events
200 LRESULT CALLBACK fgPlatformWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam,
203 static unsigned char lControl = 0, rControl = 0, lShift = 0,
204 rShift = 0, lAlt = 0, rAlt = 0;
210 FREEGLUT_INTERNAL_ERROR_EXIT_IF_NOT_INITIALISED ( "Event Handler" ) ;
212 window = fgWindowByHandle( hWnd );
214 if ( ( window == NULL ) && ( uMsg != WM_CREATE ) )
215 return DefWindowProc( hWnd, uMsg, wParam, lParam );
217 /* printf ( "Window %3d message <%04x> %12d %12d\n", window?window->ID:0,
218 uMsg, wParam, lParam ); */
222 /* Checking for CTRL, ALT, and SHIFT key positions: Key Down! */
223 if ( !lControl && GetAsyncKeyState ( VK_LCONTROL ) )
225 INVOKE_WCB ( *window, Special,
226 ( GLUT_KEY_CTRL_L, window->State.MouseX, window->State.MouseY )
232 if ( !rControl && GetAsyncKeyState ( VK_RCONTROL ) )
234 INVOKE_WCB ( *window, Special,
235 ( GLUT_KEY_CTRL_R, window->State.MouseX, window->State.MouseY )
241 if ( !lShift && GetAsyncKeyState ( VK_LSHIFT ) )
243 INVOKE_WCB ( *window, Special,
244 ( GLUT_KEY_SHIFT_L, window->State.MouseX, window->State.MouseY )
250 if ( !rShift && GetAsyncKeyState ( VK_RSHIFT ) )
252 INVOKE_WCB ( *window, Special,
253 ( GLUT_KEY_SHIFT_R, window->State.MouseX, window->State.MouseY )
259 if ( !lAlt && GetAsyncKeyState ( VK_LMENU ) )
261 INVOKE_WCB ( *window, Special,
262 ( GLUT_KEY_ALT_L, window->State.MouseX, window->State.MouseY )
268 if ( !rAlt && GetAsyncKeyState ( VK_RMENU ) )
270 INVOKE_WCB ( *window, Special,
271 ( GLUT_KEY_ALT_R, window->State.MouseX, window->State.MouseY )
277 /* Checking for CTRL, ALT, and SHIFT key positions: Key Up! */
278 if ( lControl && !GetAsyncKeyState ( VK_LCONTROL ) )
280 INVOKE_WCB ( *window, SpecialUp,
281 ( GLUT_KEY_CTRL_L, window->State.MouseX, window->State.MouseY )
287 if ( rControl && !GetAsyncKeyState ( VK_RCONTROL ) )
289 INVOKE_WCB ( *window, SpecialUp,
290 ( GLUT_KEY_CTRL_R, window->State.MouseX, window->State.MouseY )
296 if ( lShift && !GetAsyncKeyState ( VK_LSHIFT ) )
298 INVOKE_WCB ( *window, SpecialUp,
299 ( GLUT_KEY_SHIFT_L, window->State.MouseX, window->State.MouseY )
305 if ( rShift && !GetAsyncKeyState ( VK_RSHIFT ) )
307 INVOKE_WCB ( *window, SpecialUp,
308 ( GLUT_KEY_SHIFT_R, window->State.MouseX, window->State.MouseY )
314 if ( lAlt && !GetAsyncKeyState ( VK_LMENU ) )
316 INVOKE_WCB ( *window, SpecialUp,
317 ( GLUT_KEY_ALT_L, window->State.MouseX, window->State.MouseY )
323 if ( rAlt && !GetAsyncKeyState ( VK_RMENU ) )
325 INVOKE_WCB ( *window, SpecialUp,
326 ( GLUT_KEY_ALT_R, window->State.MouseX, window->State.MouseY )
336 /* The window structure is passed as the creation structure parameter... */
337 window = (SFG_Window *) (((LPCREATESTRUCT) lParam)->lpCreateParams);
338 FREEGLUT_INTERNAL_ERROR_EXIT ( ( window != NULL ), "Cannot create window",
339 "fgPlatformWindowProc" );
341 window->Window.Handle = hWnd;
342 window->Window.pContext.Device = GetDC( hWnd );
345 unsigned int current_DisplayMode = fgState.DisplayMode;
346 fgState.DisplayMode = GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH;
347 #if !defined(_WIN32_WCE)
348 fgSetupPixelFormat( window, GL_FALSE, PFD_MAIN_PLANE );
350 fgState.DisplayMode = current_DisplayMode;
352 if( fgStructure.MenuContext )
353 wglMakeCurrent( window->Window.pContext.Device,
354 fgStructure.MenuContext->MContext
358 fgStructure.MenuContext =
359 (SFG_MenuContext *)malloc( sizeof(SFG_MenuContext) );
360 fgStructure.MenuContext->MContext =
361 wglCreateContext( window->Window.pContext.Device );
364 /* window->Window.Context = wglGetCurrentContext (); */
365 window->Window.Context = wglCreateContext( window->Window.pContext.Device );
369 #if !defined(_WIN32_WCE)
370 fgSetupPixelFormat( window, GL_FALSE, PFD_MAIN_PLANE );
373 if( ! fgState.UseCurrentContext )
374 window->Window.Context =
375 wglCreateContext( window->Window.pContext.Device );
378 window->Window.Context = wglGetCurrentContext( );
379 if( ! window->Window.Context )
380 window->Window.Context =
381 wglCreateContext( window->Window.pContext.Device );
384 #if !defined(_WIN32_WCE)
385 fgNewWGLCreateContext( window );
389 window->State.NeedToResize = GL_TRUE;
390 /* if we used CW_USEDEFAULT (thats a negative value) for the size
391 * of the window, query the window now for the size at which it
394 if( ( window->State.Width < 0 ) || ( window->State.Height < 0 ) )
396 SFG_Window *current_window = fgStructure.CurrentWindow;
398 fgSetWindow( window );
399 window->State.Width = glutGet( GLUT_WINDOW_WIDTH );
400 window->State.Height = glutGet( GLUT_WINDOW_HEIGHT );
401 fgSetWindow( current_window );
404 ReleaseDC( window->Window.Handle, window->Window.pContext.Device );
406 #if defined(_WIN32_WCE)
407 /* Take over button handling */
409 HINSTANCE dxDllLib=LoadLibrary(_T("gx.dll"));
412 GXGetDefaultKeys_=(GXGETDEFAULTKEYS)GetProcAddress(dxDllLib, _T("?GXGetDefaultKeys@@YA?AUGXKeyList@@H@Z"));
413 GXOpenInput_=(GXOPENINPUT)GetProcAddress(dxDllLib, _T("?GXOpenInput@@YAHXZ"));
418 if(GXGetDefaultKeys_)
419 gxKeyList = (*GXGetDefaultKeys_)(GX_LANDSCAPEKEYS);
422 #endif /* defined(_WIN32_WCE) */
427 * If the window is visible, then it is the user manually resizing it.
428 * If it is not, then it is the system sending us a dummy resize with
429 * zero dimensions on a "glutIconifyWindow" call.
431 if( window->State.Visible )
433 window->State.NeedToResize = GL_TRUE;
434 #if defined(_WIN32_WCE)
435 window->State.Width = HIWORD(lParam);
436 window->State.Height = LOWORD(lParam);
438 window->State.Width = LOWORD(lParam);
439 window->State.Height = HIWORD(lParam);
440 #endif /* defined(_WIN32_WCE) */
446 /* printf("WM_SETFOCUS: %p\n", window ); */
447 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
448 INVOKE_WCB( *window, Entry, ( GLUT_ENTERED ) );
450 UpdateWindow ( hWnd );
454 /* printf("WM_KILLFOCUS: %p\n", window ); */
455 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
456 INVOKE_WCB( *window, Entry, ( GLUT_LEFT ) );
458 if( window->IsMenu &&
459 window->ActiveMenu && window->ActiveMenu->IsActive )
460 fgUpdateMenuHighlight( window->ActiveMenu );
466 if (LOWORD(wParam) != WA_INACTIVE)
468 /* printf("WM_ACTIVATE: fgSetCursor( %p, %d)\n", window,
469 window->State.Cursor ); */
470 fgSetCursor( window, window->State.Cursor );
473 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
478 /* printf ( "Cursor event %x %x %x %x\n", window, window->State.Cursor, lParam, wParam ) ; */
479 if( LOWORD( lParam ) == HTCLIENT )
480 fgSetCursor ( window, window->State.Cursor ) ;
482 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
486 window->State.Visible = GL_TRUE;
487 window->State.Redisplay = GL_TRUE;
491 /* Turn on the visibility in case it was turned off somehow */
492 window->State.Visible = GL_TRUE;
493 BeginPaint( hWnd, &ps );
494 fghRedrawWindow( window );
495 EndPaint( hWnd, &ps );
499 fgDestroyWindow ( window );
500 if ( fgState.ActionOnWindowClose != GLUT_ACTION_CONTINUE_EXECUTION )
506 * The window already got destroyed, so don't bother with it.
512 #if defined(_WIN32_WCE)
513 window->State.MouseX = 320-HIWORD( lParam );
514 window->State.MouseY = LOWORD( lParam );
516 window->State.MouseX = LOWORD( lParam );
517 window->State.MouseY = HIWORD( lParam );
518 #endif /* defined(_WIN32_WCE) */
519 /* Restrict to [-32768, 32767] to match X11 behaviour */
520 /* See comment in "freeglut_developer" mailing list 10/4/04 */
521 if ( window->State.MouseX > 32767 ) window->State.MouseX -= 65536;
522 if ( window->State.MouseY > 32767 ) window->State.MouseY -= 65536;
524 if ( window->ActiveMenu )
526 fgUpdateMenuHighlight( window->ActiveMenu );
529 SetFocus(window->Window.Handle);
531 fgState.Modifiers = fgPlatformGetModifiers( );
533 if( ( wParam & MK_LBUTTON ) ||
534 ( wParam & MK_MBUTTON ) ||
535 ( wParam & MK_RBUTTON ) )
536 INVOKE_WCB( *window, Motion, ( window->State.MouseX,
537 window->State.MouseY ) );
539 INVOKE_WCB( *window, Passive, ( window->State.MouseX,
540 window->State.MouseY ) );
542 fgState.Modifiers = INVALID_MODIFIERS;
553 GLboolean pressed = GL_TRUE;
556 #if defined(_WIN32_WCE)
557 window->State.MouseX = 320-HIWORD( lParam );
558 window->State.MouseY = LOWORD( lParam );
560 window->State.MouseX = LOWORD( lParam );
561 window->State.MouseY = HIWORD( lParam );
562 #endif /* defined(_WIN32_WCE) */
564 /* Restrict to [-32768, 32767] to match X11 behaviour */
565 /* See comment in "freeglut_developer" mailing list 10/4/04 */
566 if ( window->State.MouseX > 32767 ) window->State.MouseX -= 65536;
567 if ( window->State.MouseY > 32767 ) window->State.MouseY -= 65536;
573 button = GLUT_LEFT_BUTTON;
577 button = GLUT_MIDDLE_BUTTON;
581 button = GLUT_RIGHT_BUTTON;
585 button = GLUT_LEFT_BUTTON;
589 button = GLUT_MIDDLE_BUTTON;
593 button = GLUT_RIGHT_BUTTON;
601 #if !defined(_WIN32_WCE)
602 if( GetSystemMetrics( SM_SWAPBUTTON ) )
604 if( button == GLUT_LEFT_BUTTON )
605 button = GLUT_RIGHT_BUTTON;
607 if( button == GLUT_RIGHT_BUTTON )
608 button = GLUT_LEFT_BUTTON;
610 #endif /* !defined(_WIN32_WCE) */
613 return DefWindowProc( hWnd, uMsg, lParam, wParam );
616 * Do not execute the application's mouse callback if a menu
617 * is hooked to this button. In that case an appropriate
618 * private call should be generated.
620 if( fgCheckActiveMenu( window, button, pressed,
621 window->State.MouseX, window->State.MouseY ) )
624 /* Set capture so that the window captures all the mouse messages */
626 * XXX - Multiple button support: Under X11, the mouse is not released
627 * XXX - from the window until all buttons have been released, even if the
628 * XXX - user presses a button in another window. This will take more
629 * XXX - code changes than I am up to at the moment (10/5/04). The present
630 * XXX - is a 90 percent solution.
632 if ( pressed == GL_TRUE )
633 SetCapture ( window->Window.Handle ) ;
637 if( ! FETCH_WCB( *window, Mouse ) )
640 fgSetWindow( window );
641 fgState.Modifiers = fgPlatformGetModifiers( );
646 pressed ? GLUT_DOWN : GLUT_UP,
647 window->State.MouseX,
652 fgState.Modifiers = INVALID_MODIFIERS;
657 /* Should be WM_MOUSEWHEEL but my compiler doesn't recognize it */
659 int wheel_number = LOWORD( wParam );
660 short ticks = ( short )HIWORD( wParam );
661 fgState.MouseWheelTicks += ticks;
664 * XXX Should use WHEEL_DELTA instead of 120
666 if ( abs ( fgState.MouseWheelTicks ) > 120 )
668 int direction = ( fgState.MouseWheelTicks > 0 ) ? 1 : -1;
670 if( ! FETCH_WCB( *window, MouseWheel ) &&
671 ! FETCH_WCB( *window, Mouse ) )
674 fgSetWindow( window );
675 fgState.Modifiers = fgPlatformGetModifiers( );
678 * XXX Should use WHEEL_DELTA instead of 120
680 while( abs ( fgState.MouseWheelTicks ) > 120 )
682 if( FETCH_WCB( *window, MouseWheel ) )
683 INVOKE_WCB( *window, MouseWheel,
686 window->State.MouseX,
690 else /* No mouse wheel, call the mouse button callback twice */
693 * Map wheel zero to button 3 and 4; +1 to 3, -1 to 4
694 * " " one +1 to 5, -1 to 6, ...
696 * XXX The below assumes that you have no more than 3 mouse
697 * XXX buttons. Sorry.
699 int button = wheel_number * 2 + 3;
702 INVOKE_WCB( *window, Mouse,
704 window->State.MouseX, window->State.MouseY )
706 INVOKE_WCB( *window, Mouse,
708 window->State.MouseX, window->State.MouseY )
713 * XXX Should use WHEEL_DELTA instead of 120
715 fgState.MouseWheelTicks -= 120 * direction;
718 fgState.Modifiers = INVALID_MODIFIERS;
729 if( ( fgState.KeyRepeat==GLUT_KEY_REPEAT_OFF || window->State.IgnoreKeyRepeat==GL_TRUE ) && (HIWORD(lParam) & KF_REPEAT) )
733 * Remember the current modifiers state. This is done here in order
734 * to make sure the VK_DELETE keyboard callback is executed properly.
736 fgState.Modifiers = fgPlatformGetModifiers( );
738 GetCursorPos( &mouse_pos );
739 ScreenToClient( window->Window.Handle, &mouse_pos );
741 window->State.MouseX = mouse_pos.x;
742 window->State.MouseY = mouse_pos.y;
744 /* Convert the Win32 keystroke codes to GLUTtish way */
745 # define KEY(a,b) case a: keypress = b; break;
749 KEY( VK_F1, GLUT_KEY_F1 );
750 KEY( VK_F2, GLUT_KEY_F2 );
751 KEY( VK_F3, GLUT_KEY_F3 );
752 KEY( VK_F4, GLUT_KEY_F4 );
753 KEY( VK_F5, GLUT_KEY_F5 );
754 KEY( VK_F6, GLUT_KEY_F6 );
755 KEY( VK_F7, GLUT_KEY_F7 );
756 KEY( VK_F8, GLUT_KEY_F8 );
757 KEY( VK_F9, GLUT_KEY_F9 );
758 KEY( VK_F10, GLUT_KEY_F10 );
759 KEY( VK_F11, GLUT_KEY_F11 );
760 KEY( VK_F12, GLUT_KEY_F12 );
761 KEY( VK_PRIOR, GLUT_KEY_PAGE_UP );
762 KEY( VK_NEXT, GLUT_KEY_PAGE_DOWN );
763 KEY( VK_HOME, GLUT_KEY_HOME );
764 KEY( VK_END, GLUT_KEY_END );
765 KEY( VK_LEFT, GLUT_KEY_LEFT );
766 KEY( VK_UP, GLUT_KEY_UP );
767 KEY( VK_RIGHT, GLUT_KEY_RIGHT );
768 KEY( VK_DOWN, GLUT_KEY_DOWN );
769 KEY( VK_INSERT, GLUT_KEY_INSERT );
770 KEY( VK_LCONTROL, GLUT_KEY_CTRL_L );
771 KEY( VK_RCONTROL, GLUT_KEY_CTRL_R );
772 KEY( VK_LSHIFT, GLUT_KEY_SHIFT_L );
773 KEY( VK_RSHIFT, GLUT_KEY_SHIFT_R );
774 KEY( VK_LMENU, GLUT_KEY_ALT_L );
775 KEY( VK_RMENU, GLUT_KEY_ALT_R );
778 /* The delete key should be treated as an ASCII keypress: */
779 INVOKE_WCB( *window, Keyboard,
780 ( 127, window->State.MouseX, window->State.MouseY )
784 #if defined(_WIN32_WCE)
785 if(!(lParam & 0x40000000)) /* Prevent auto-repeat */
787 if(wParam==(unsigned)gxKeyList.vkRight)
788 keypress = GLUT_KEY_RIGHT;
789 else if(wParam==(unsigned)gxKeyList.vkLeft)
790 keypress = GLUT_KEY_LEFT;
791 else if(wParam==(unsigned)gxKeyList.vkUp)
792 keypress = GLUT_KEY_UP;
793 else if(wParam==(unsigned)gxKeyList.vkDown)
794 keypress = GLUT_KEY_DOWN;
795 else if(wParam==(unsigned)gxKeyList.vkA)
796 keypress = GLUT_KEY_F1;
797 else if(wParam==(unsigned)gxKeyList.vkB)
798 keypress = GLUT_KEY_F2;
799 else if(wParam==(unsigned)gxKeyList.vkC)
800 keypress = GLUT_KEY_F3;
801 else if(wParam==(unsigned)gxKeyList.vkStart)
802 keypress = GLUT_KEY_F4;
807 INVOKE_WCB( *window, Special,
809 window->State.MouseX, window->State.MouseY )
812 fgState.Modifiers = INVALID_MODIFIERS;
823 * Remember the current modifiers state. This is done here in order
824 * to make sure the VK_DELETE keyboard callback is executed properly.
826 fgState.Modifiers = fgPlatformGetModifiers( );
828 GetCursorPos( &mouse_pos );
829 ScreenToClient( window->Window.Handle, &mouse_pos );
831 window->State.MouseX = mouse_pos.x;
832 window->State.MouseY = mouse_pos.y;
835 * Convert the Win32 keystroke codes to GLUTtish way.
836 * "KEY(a,b)" was defined under "WM_KEYDOWN"
841 KEY( VK_F1, GLUT_KEY_F1 );
842 KEY( VK_F2, GLUT_KEY_F2 );
843 KEY( VK_F3, GLUT_KEY_F3 );
844 KEY( VK_F4, GLUT_KEY_F4 );
845 KEY( VK_F5, GLUT_KEY_F5 );
846 KEY( VK_F6, GLUT_KEY_F6 );
847 KEY( VK_F7, GLUT_KEY_F7 );
848 KEY( VK_F8, GLUT_KEY_F8 );
849 KEY( VK_F9, GLUT_KEY_F9 );
850 KEY( VK_F10, GLUT_KEY_F10 );
851 KEY( VK_F11, GLUT_KEY_F11 );
852 KEY( VK_F12, GLUT_KEY_F12 );
853 KEY( VK_PRIOR, GLUT_KEY_PAGE_UP );
854 KEY( VK_NEXT, GLUT_KEY_PAGE_DOWN );
855 KEY( VK_HOME, GLUT_KEY_HOME );
856 KEY( VK_END, GLUT_KEY_END );
857 KEY( VK_LEFT, GLUT_KEY_LEFT );
858 KEY( VK_UP, GLUT_KEY_UP );
859 KEY( VK_RIGHT, GLUT_KEY_RIGHT );
860 KEY( VK_DOWN, GLUT_KEY_DOWN );
861 KEY( VK_INSERT, GLUT_KEY_INSERT );
862 KEY( VK_LCONTROL, GLUT_KEY_CTRL_L );
863 KEY( VK_RCONTROL, GLUT_KEY_CTRL_R );
864 KEY( VK_LSHIFT, GLUT_KEY_SHIFT_L );
865 KEY( VK_RSHIFT, GLUT_KEY_SHIFT_R );
866 KEY( VK_LMENU, GLUT_KEY_ALT_L );
867 KEY( VK_RMENU, GLUT_KEY_ALT_R );
870 /* The delete key should be treated as an ASCII keypress: */
871 INVOKE_WCB( *window, KeyboardUp,
872 ( 127, window->State.MouseX, window->State.MouseY )
878 #if !defined(_WIN32_WCE)
882 GetKeyboardState( state );
884 if( ToAscii( (UINT)wParam, 0, state, code, 0 ) == 1 )
887 INVOKE_WCB( *window, KeyboardUp,
889 window->State.MouseX, window->State.MouseY )
891 #endif /* !defined(_WIN32_WCE) */
896 INVOKE_WCB( *window, SpecialUp,
898 window->State.MouseX, window->State.MouseY )
901 fgState.Modifiers = INVALID_MODIFIERS;
908 if( (fgState.KeyRepeat==GLUT_KEY_REPEAT_OFF || window->State.IgnoreKeyRepeat==GL_TRUE) && (HIWORD(lParam) & KF_REPEAT) )
911 fgState.Modifiers = fgPlatformGetModifiers( );
912 INVOKE_WCB( *window, Keyboard,
914 window->State.MouseX, window->State.MouseY )
916 fgState.Modifiers = INVALID_MODIFIERS;
920 case WM_CAPTURECHANGED:
921 /* User has finished resizing the window, force a redraw */
922 INVOKE_WCB( *window, Display, ( ) );
924 /*lRet = DefWindowProc( hWnd, uMsg, wParam, lParam ); */
927 /* Other messages that I have seen and which are not handled already */
928 case WM_SETTEXT: /* 0x000c */
929 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
930 /* Pass it on to "DefWindowProc" to set the window text */
933 case WM_GETTEXT: /* 0x000d */
934 /* Ideally we would copy the title of the window into "lParam" */
935 /* strncpy ( (char *)lParam, "Window Title", wParam );
936 lRet = ( wParam > 12 ) ? 12 : wParam; */
937 /* the number of characters copied */
938 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
941 case WM_GETTEXTLENGTH: /* 0x000e */
942 /* Ideally we would get the length of the title of the window */
944 /* the number of characters in "Window Title\0" (see above) */
947 case WM_ERASEBKGND: /* 0x0014 */
948 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
951 #if !defined(_WIN32_WCE)
952 case WM_SYNCPAINT: /* 0x0088 */
953 /* Another window has moved, need to update this one */
954 window->State.Redisplay = GL_TRUE;
955 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
956 /* Help screen says this message must be passed to "DefWindowProc" */
959 case WM_NCPAINT: /* 0x0085 */
960 /* Need to update the border of this window */
961 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
962 /* Pass it on to "DefWindowProc" to repaint a standard border */
965 case WM_SYSCOMMAND : /* 0x0112 */
968 * We have received a system command message. Try to act on it.
969 * The commands are passed in through the "wParam" parameter:
970 * The least significant digit seems to be which edge of the window
971 * is being used for a resize event:
975 * Congratulations and thanks to Richard Rauch for figuring this out..
977 switch ( wParam & 0xfff0 )
986 /* User has clicked on the "-" to minimize the window */
987 /* Turn off the visibility */
988 window->State.Visible = GL_FALSE ;
1002 /* Followed very closely by a WM_CLOSE message */
1026 case SC_SCREENSAVE :
1032 #if(WINVER >= 0x0400)
1036 case SC_MONITORPOWER :
1039 case SC_CONTEXTHELP :
1041 #endif /* WINVER >= 0x0400 */
1045 fgWarning( "Unknown wParam type 0x%x", wParam );
1050 #endif /* !defined(_WIN32_WCE) */
1052 /* We need to pass the message on to the operating system as well */
1053 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1057 /* handle multi-touch messages */
1060 unsigned int numInputs = (unsigned int)wParam;
1062 TOUCHINPUT* ti = (TOUCHINPUT*)malloc( sizeof(TOUCHINPUT)*numInputs);
1064 if (fghGetTouchInputInfo == (pGetTouchInputInfo)0xDEADBEEF) {
1065 fghGetTouchInputInfo = (pGetTouchInputInfo)GetProcAddress(GetModuleHandle("user32"),"GetTouchInputInfo");
1066 fghCloseTouchInputHandle = (pCloseTouchInputHandle)GetProcAddress(GetModuleHandle("user32"),"CloseTouchInputHandle");
1069 if (!fghGetTouchInputInfo) {
1074 if (fghGetTouchInputInfo( (HTOUCHINPUT)lParam, numInputs, ti, sizeof(TOUCHINPUT) )) {
1075 /* Handle each contact point */
1076 for (i = 0; i < numInputs; ++i ) {
1079 tp.x = TOUCH_COORD_TO_PIXEL(ti[i].x);
1080 tp.y = TOUCH_COORD_TO_PIXEL(ti[i].y);
1081 ScreenToClient( hWnd, &tp );
1083 ti[i].dwID = ti[i].dwID * 2;
1085 if (ti[i].dwFlags & TOUCHEVENTF_DOWN) {
1086 INVOKE_WCB( *window, MultiEntry, ( ti[i].dwID, GLUT_ENTERED ) );
1087 INVOKE_WCB( *window, MultiButton, ( ti[i].dwID, tp.x, tp.y, 0, GLUT_DOWN ) );
1088 } else if (ti[i].dwFlags & TOUCHEVENTF_MOVE) {
1089 INVOKE_WCB( *window, MultiMotion, ( ti[i].dwID, tp.x, tp.y ) );
1090 } else if (ti[i].dwFlags & TOUCHEVENTF_UP) {
1091 INVOKE_WCB( *window, MultiButton, ( ti[i].dwID, tp.x, tp.y, 0, GLUT_UP ) );
1092 INVOKE_WCB( *window, MultiEntry, ( ti[i].dwID, GLUT_LEFT ) );
1096 fghCloseTouchInputHandle((HTOUCHINPUT)lParam);
1098 lRet = 0; /*DefWindowProc( hWnd, uMsg, wParam, lParam );*/
1103 /* Handle unhandled messages */
1104 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );