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 typedef struct GXDisplayProperties GXDisplayProperties;
47 typedef struct GXKeyList GXKeyList;
50 typedef struct GXKeyList (*GXGETDEFAULTKEYS)(int);
51 typedef int (*GXOPENINPUT)();
53 GXGETDEFAULTKEYS GXGetDefaultKeys_ = NULL;
54 GXOPENINPUT GXOpenInput_ = NULL;
56 struct GXKeyList gxKeyList;
57 #endif /* _WIN32_WCE */
60 * Helper functions for getting client area from the window rect
61 * and the window rect from the client area given the style of the window
62 * (or a valid window pointer from which the style can be queried).
64 extern void fghComputeWindowRectFromClientArea_QueryWindow( const SFG_Window *window, RECT *clientRect, BOOL posIsOutside );
65 extern RECT fghGetClientArea ( const SFG_Window *window, BOOL wantPosOutside );
68 void fgPlatformReshapeWindow ( SFG_Window *window, int width, int height )
73 * For windowed mode, get the current position of the
74 * window and resize taking the size of the frame
75 * decorations into account.
78 /* "GetWindowRect" returns the pixel coordinates of the outside of the window */
79 GetWindowRect( window->Window.Handle, &windowRect );
81 /* Create rect in FreeGLUT format, (X,Y) topleft outside window, WxH of client area */
82 windowRect.right = windowRect.left+width;
83 windowRect.bottom = windowRect.top+height;
85 if (window->Parent == NULL)
86 /* get the window rect from this to feed to SetWindowPos, correct for window decorations */
87 fghComputeWindowRectFromClientArea_QueryWindow(window,&windowRect,TRUE);
90 /* correct rect for position client area of parent window
91 * (SetWindowPos input for child windows is in coordinates
92 * relative to the parent's client area).
93 * Child windows don't have decoration, so no need to correct
97 parentRect = fghGetClientArea( window->Parent, FALSE );
98 windowRect.left -= parentRect.left;
99 windowRect.right -= parentRect.left;
100 windowRect.top -= parentRect.top;
101 windowRect.bottom -= parentRect.top;
104 /* Do the actual resizing */
105 SetWindowPos( window->Window.Handle,
107 windowRect.left, windowRect.top,
108 windowRect.right - windowRect.left,
109 windowRect.bottom- windowRect.top,
110 SWP_NOACTIVATE | SWP_NOOWNERZORDER | SWP_NOSENDCHANGING |
116 void fgPlatformDisplayWindow ( SFG_Window *window )
119 window->Window.Handle, NULL, NULL,
120 RDW_NOERASE | RDW_INTERNALPAINT | RDW_INVALIDATE | RDW_UPDATENOW
125 unsigned long fgPlatformSystemTime ( void )
127 #if defined(_WIN32_WCE)
128 return GetTickCount();
130 return timeGetTime();
135 void fgPlatformSleepForEvents( long msec )
137 MsgWaitForMultipleObjects( 0, NULL, FALSE, msec, QS_ALLINPUT );
141 void fgPlatformProcessSingleEvent ( void )
145 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutMainLoopEvent" );
147 while( PeekMessage( &stMsg, NULL, 0, 0, PM_NOREMOVE ) )
149 if( GetMessage( &stMsg, NULL, 0, 0 ) == 0 )
151 if( fgState.ActionOnWindowClose == GLUT_ACTION_EXIT )
156 else if( fgState.ActionOnWindowClose == GLUT_ACTION_GLUTMAINLOOP_RETURNS )
157 fgState.ExecState = GLUT_EXEC_STATE_STOP;
162 TranslateMessage( &stMsg );
163 DispatchMessage( &stMsg );
169 void fgPlatformMainLoopPreliminaryWork ( void )
171 SFG_Window *window = (SFG_Window *)fgStructure.Windows.First ;
174 * Processing before the main loop: If there is a window which is open and
175 * which has a visibility callback, call it. I know this is an ugly hack,
176 * but I'm not sure what else to do about it. Ideally we should leave
177 * something uninitialized in the create window code and initialize it in
178 * the main loop, and have that initialization create a "WM_ACTIVATE"
179 * message. Then we would put the visibility callback code in the
180 * "case WM_ACTIVATE" block below. - John Fay -- 10/24/02
184 if ( FETCH_WCB( *window, Visibility ) )
186 SFG_Window *current_window = fgStructure.CurrentWindow ;
188 INVOKE_WCB( *window, Visibility, ( window->State.Visible ) );
189 fgSetWindow( current_window );
192 window = (SFG_Window *)window->Node.Next ;
198 * Determine a GLUT modifer mask based on MS-WINDOWS system info.
200 static int fgPlatformGetModifiers (void)
203 ( ( ( GetKeyState( VK_LSHIFT ) < 0 ) ||
204 ( GetKeyState( VK_RSHIFT ) < 0 )) ? GLUT_ACTIVE_SHIFT : 0 ) |
205 ( ( ( GetKeyState( VK_LCONTROL ) < 0 ) ||
206 ( GetKeyState( VK_RCONTROL ) < 0 )) ? GLUT_ACTIVE_CTRL : 0 ) |
207 ( ( ( GetKeyState( VK_LMENU ) < 0 ) ||
208 ( GetKeyState( VK_RMENU ) < 0 )) ? GLUT_ACTIVE_ALT : 0 );
212 * The window procedure for handling Win32 events
214 LRESULT CALLBACK fgPlatformWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam,
217 static unsigned char lControl = 0, rControl = 0, lShift = 0,
218 rShift = 0, lAlt = 0, rAlt = 0;
224 FREEGLUT_INTERNAL_ERROR_EXIT_IF_NOT_INITIALISED ( "Event Handler" ) ;
226 window = fgWindowByHandle( hWnd );
228 if ( ( window == NULL ) && ( uMsg != WM_CREATE ) )
229 return DefWindowProc( hWnd, uMsg, wParam, lParam );
231 /* printf ( "Window %3d message <%04x> %12d %12d\n", window?window->ID:0,
232 uMsg, wParam, lParam ); */
236 /* Checking for CTRL, ALT, and SHIFT key positions: Key Down! */
237 if ( !lControl && GetAsyncKeyState ( VK_LCONTROL ) )
239 INVOKE_WCB ( *window, Special,
240 ( GLUT_KEY_CTRL_L, window->State.MouseX, window->State.MouseY )
246 if ( !rControl && GetAsyncKeyState ( VK_RCONTROL ) )
248 INVOKE_WCB ( *window, Special,
249 ( GLUT_KEY_CTRL_R, window->State.MouseX, window->State.MouseY )
255 if ( !lShift && GetAsyncKeyState ( VK_LSHIFT ) )
257 INVOKE_WCB ( *window, Special,
258 ( GLUT_KEY_SHIFT_L, window->State.MouseX, window->State.MouseY )
264 if ( !rShift && GetAsyncKeyState ( VK_RSHIFT ) )
266 INVOKE_WCB ( *window, Special,
267 ( GLUT_KEY_SHIFT_R, window->State.MouseX, window->State.MouseY )
273 if ( !lAlt && GetAsyncKeyState ( VK_LMENU ) )
275 INVOKE_WCB ( *window, Special,
276 ( GLUT_KEY_ALT_L, window->State.MouseX, window->State.MouseY )
282 if ( !rAlt && GetAsyncKeyState ( VK_RMENU ) )
284 INVOKE_WCB ( *window, Special,
285 ( GLUT_KEY_ALT_R, window->State.MouseX, window->State.MouseY )
291 /* Checking for CTRL, ALT, and SHIFT key positions: Key Up! */
292 if ( lControl && !GetAsyncKeyState ( VK_LCONTROL ) )
294 INVOKE_WCB ( *window, SpecialUp,
295 ( GLUT_KEY_CTRL_L, window->State.MouseX, window->State.MouseY )
301 if ( rControl && !GetAsyncKeyState ( VK_RCONTROL ) )
303 INVOKE_WCB ( *window, SpecialUp,
304 ( GLUT_KEY_CTRL_R, window->State.MouseX, window->State.MouseY )
310 if ( lShift && !GetAsyncKeyState ( VK_LSHIFT ) )
312 INVOKE_WCB ( *window, SpecialUp,
313 ( GLUT_KEY_SHIFT_L, window->State.MouseX, window->State.MouseY )
319 if ( rShift && !GetAsyncKeyState ( VK_RSHIFT ) )
321 INVOKE_WCB ( *window, SpecialUp,
322 ( GLUT_KEY_SHIFT_R, window->State.MouseX, window->State.MouseY )
328 if ( lAlt && !GetAsyncKeyState ( VK_LMENU ) )
330 INVOKE_WCB ( *window, SpecialUp,
331 ( GLUT_KEY_ALT_L, window->State.MouseX, window->State.MouseY )
337 if ( rAlt && !GetAsyncKeyState ( VK_RMENU ) )
339 INVOKE_WCB ( *window, SpecialUp,
340 ( GLUT_KEY_ALT_R, window->State.MouseX, window->State.MouseY )
350 /* The window structure is passed as the creation structure parameter... */
351 window = (SFG_Window *) (((LPCREATESTRUCT) lParam)->lpCreateParams);
352 FREEGLUT_INTERNAL_ERROR_EXIT ( ( window != NULL ), "Cannot create window",
353 "fgPlatformWindowProc" );
355 window->Window.Handle = hWnd;
356 window->Window.pContext.Device = GetDC( hWnd );
359 unsigned int current_DisplayMode = fgState.DisplayMode;
360 fgState.DisplayMode = GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH;
361 #if !defined(_WIN32_WCE)
362 fgSetupPixelFormat( window, GL_FALSE, PFD_MAIN_PLANE );
364 fgState.DisplayMode = current_DisplayMode;
366 if( fgStructure.MenuContext )
367 wglMakeCurrent( window->Window.pContext.Device,
368 fgStructure.MenuContext->MContext
372 fgStructure.MenuContext =
373 (SFG_MenuContext *)malloc( sizeof(SFG_MenuContext) );
374 fgStructure.MenuContext->MContext =
375 wglCreateContext( window->Window.pContext.Device );
378 /* window->Window.Context = wglGetCurrentContext (); */
379 window->Window.Context = wglCreateContext( window->Window.pContext.Device );
383 #if !defined(_WIN32_WCE)
384 fgSetupPixelFormat( window, GL_FALSE, PFD_MAIN_PLANE );
387 if( ! fgState.UseCurrentContext )
388 window->Window.Context =
389 wglCreateContext( window->Window.pContext.Device );
392 window->Window.Context = wglGetCurrentContext( );
393 if( ! window->Window.Context )
394 window->Window.Context =
395 wglCreateContext( window->Window.pContext.Device );
398 #if !defined(_WIN32_WCE)
399 fgNewWGLCreateContext( window );
403 window->State.NeedToResize = GL_TRUE;
404 /* if we used CW_USEDEFAULT (thats a negative value) for the size
405 * of the window, query the window now for the size at which it
408 if( ( window->State.Width < 0 ) || ( window->State.Height < 0 ) )
410 SFG_Window *current_window = fgStructure.CurrentWindow;
412 fgSetWindow( window );
413 window->State.Width = glutGet( GLUT_WINDOW_WIDTH );
414 window->State.Height = glutGet( GLUT_WINDOW_HEIGHT );
415 fgSetWindow( current_window );
418 ReleaseDC( window->Window.Handle, window->Window.pContext.Device );
420 #if defined(_WIN32_WCE)
421 /* Take over button handling */
423 HINSTANCE dxDllLib=LoadLibrary(_T("gx.dll"));
426 GXGetDefaultKeys_=(GXGETDEFAULTKEYS)GetProcAddress(dxDllLib, _T("?GXGetDefaultKeys@@YA?AUGXKeyList@@H@Z"));
427 GXOpenInput_=(GXOPENINPUT)GetProcAddress(dxDllLib, _T("?GXOpenInput@@YAHXZ"));
432 if(GXGetDefaultKeys_)
433 gxKeyList = (*GXGetDefaultKeys_)(GX_LANDSCAPEKEYS);
436 #endif /* defined(_WIN32_WCE) */
441 * If the window is visible, then it is the user manually resizing it.
442 * If it is not, then it is the system sending us a dummy resize with
443 * zero dimensions on a "glutIconifyWindow" call.
445 if( window->State.Visible )
447 window->State.NeedToResize = GL_TRUE;
448 #if defined(_WIN32_WCE)
449 window->State.Width = HIWORD(lParam);
450 window->State.Height = LOWORD(lParam);
452 window->State.Width = LOWORD(lParam);
453 window->State.Height = HIWORD(lParam);
454 #endif /* defined(_WIN32_WCE) */
460 /* printf("WM_SETFOCUS: %p\n", window ); */
461 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
462 INVOKE_WCB( *window, Entry, ( GLUT_ENTERED ) );
464 UpdateWindow ( hWnd );
468 /* printf("WM_KILLFOCUS: %p\n", window ); */
469 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
470 INVOKE_WCB( *window, Entry, ( GLUT_LEFT ) );
472 if( window->IsMenu &&
473 window->ActiveMenu && window->ActiveMenu->IsActive )
474 fgUpdateMenuHighlight( window->ActiveMenu );
480 if (LOWORD(wParam) != WA_INACTIVE)
482 /* printf("WM_ACTIVATE: fgSetCursor( %p, %d)\n", window,
483 window->State.Cursor ); */
484 fgSetCursor( window, window->State.Cursor );
487 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
492 /* printf ( "Cursor event %x %x %x %x\n", window, window->State.Cursor, lParam, wParam ) ; */
493 if( LOWORD( lParam ) == HTCLIENT )
494 fgSetCursor ( window, window->State.Cursor ) ;
496 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
500 window->State.Visible = GL_TRUE;
501 window->State.Redisplay = GL_TRUE;
505 /* Turn on the visibility in case it was turned off somehow */
506 window->State.Visible = GL_TRUE;
507 BeginPaint( hWnd, &ps );
508 fghRedrawWindow( window );
509 EndPaint( hWnd, &ps );
513 fgDestroyWindow ( window );
514 if ( fgState.ActionOnWindowClose != GLUT_ACTION_CONTINUE_EXECUTION )
520 * The window already got destroyed, so don't bother with it.
526 #if defined(_WIN32_WCE)
527 window->State.MouseX = 320-HIWORD( lParam );
528 window->State.MouseY = LOWORD( lParam );
530 window->State.MouseX = LOWORD( lParam );
531 window->State.MouseY = HIWORD( lParam );
532 #endif /* defined(_WIN32_WCE) */
533 /* Restrict to [-32768, 32767] to match X11 behaviour */
534 /* See comment in "freeglut_developer" mailing list 10/4/04 */
535 if ( window->State.MouseX > 32767 ) window->State.MouseX -= 65536;
536 if ( window->State.MouseY > 32767 ) window->State.MouseY -= 65536;
538 if ( window->ActiveMenu )
540 fgUpdateMenuHighlight( window->ActiveMenu );
543 SetFocus(window->Window.Handle);
545 fgState.Modifiers = fgPlatformGetModifiers( );
547 if( ( wParam & MK_LBUTTON ) ||
548 ( wParam & MK_MBUTTON ) ||
549 ( wParam & MK_RBUTTON ) )
550 INVOKE_WCB( *window, Motion, ( window->State.MouseX,
551 window->State.MouseY ) );
553 INVOKE_WCB( *window, Passive, ( window->State.MouseX,
554 window->State.MouseY ) );
556 fgState.Modifiers = INVALID_MODIFIERS;
567 GLboolean pressed = GL_TRUE;
570 #if defined(_WIN32_WCE)
571 window->State.MouseX = 320-HIWORD( lParam );
572 window->State.MouseY = LOWORD( lParam );
574 window->State.MouseX = LOWORD( lParam );
575 window->State.MouseY = HIWORD( lParam );
576 #endif /* defined(_WIN32_WCE) */
578 /* Restrict to [-32768, 32767] to match X11 behaviour */
579 /* See comment in "freeglut_developer" mailing list 10/4/04 */
580 if ( window->State.MouseX > 32767 ) window->State.MouseX -= 65536;
581 if ( window->State.MouseY > 32767 ) window->State.MouseY -= 65536;
587 button = GLUT_LEFT_BUTTON;
591 button = GLUT_MIDDLE_BUTTON;
595 button = GLUT_RIGHT_BUTTON;
599 button = GLUT_LEFT_BUTTON;
603 button = GLUT_MIDDLE_BUTTON;
607 button = GLUT_RIGHT_BUTTON;
615 #if !defined(_WIN32_WCE)
616 if( GetSystemMetrics( SM_SWAPBUTTON ) )
618 if( button == GLUT_LEFT_BUTTON )
619 button = GLUT_RIGHT_BUTTON;
621 if( button == GLUT_RIGHT_BUTTON )
622 button = GLUT_LEFT_BUTTON;
624 #endif /* !defined(_WIN32_WCE) */
627 return DefWindowProc( hWnd, uMsg, lParam, wParam );
630 * Do not execute the application's mouse callback if a menu
631 * is hooked to this button. In that case an appropriate
632 * private call should be generated.
634 if( fgCheckActiveMenu( window, button, pressed,
635 window->State.MouseX, window->State.MouseY ) )
638 /* Set capture so that the window captures all the mouse messages */
640 * XXX - Multiple button support: Under X11, the mouse is not released
641 * XXX - from the window until all buttons have been released, even if the
642 * XXX - user presses a button in another window. This will take more
643 * XXX - code changes than I am up to at the moment (10/5/04). The present
644 * XXX - is a 90 percent solution.
646 if ( pressed == GL_TRUE )
647 SetCapture ( window->Window.Handle ) ;
651 if( ! FETCH_WCB( *window, Mouse ) )
654 fgSetWindow( window );
655 fgState.Modifiers = fgPlatformGetModifiers( );
660 pressed ? GLUT_DOWN : GLUT_UP,
661 window->State.MouseX,
666 fgState.Modifiers = INVALID_MODIFIERS;
671 /* Should be WM_MOUSEWHEEL but my compiler doesn't recognize it */
673 int wheel_number = LOWORD( wParam );
674 short ticks = ( short )HIWORD( wParam );
675 fgState.MouseWheelTicks += ticks;
678 * XXX Should use WHEEL_DELTA instead of 120
680 if ( abs ( fgState.MouseWheelTicks ) > 120 )
682 int direction = ( fgState.MouseWheelTicks > 0 ) ? 1 : -1;
684 if( ! FETCH_WCB( *window, MouseWheel ) &&
685 ! FETCH_WCB( *window, Mouse ) )
688 fgSetWindow( window );
689 fgState.Modifiers = fgPlatformGetModifiers( );
692 * XXX Should use WHEEL_DELTA instead of 120
694 while( abs ( fgState.MouseWheelTicks ) > 120 )
696 if( FETCH_WCB( *window, MouseWheel ) )
697 INVOKE_WCB( *window, MouseWheel,
700 window->State.MouseX,
704 else /* No mouse wheel, call the mouse button callback twice */
707 * Map wheel zero to button 3 and 4; +1 to 3, -1 to 4
708 * " " one +1 to 5, -1 to 6, ...
710 * XXX The below assumes that you have no more than 3 mouse
711 * XXX buttons. Sorry.
713 int button = wheel_number * 2 + 3;
716 INVOKE_WCB( *window, Mouse,
718 window->State.MouseX, window->State.MouseY )
720 INVOKE_WCB( *window, Mouse,
722 window->State.MouseX, window->State.MouseY )
727 * XXX Should use WHEEL_DELTA instead of 120
729 fgState.MouseWheelTicks -= 120 * direction;
732 fgState.Modifiers = INVALID_MODIFIERS;
743 if( ( fgState.KeyRepeat==GLUT_KEY_REPEAT_OFF || window->State.IgnoreKeyRepeat==GL_TRUE ) && (HIWORD(lParam) & KF_REPEAT) )
747 * Remember the current modifiers state. This is done here in order
748 * to make sure the VK_DELETE keyboard callback is executed properly.
750 fgState.Modifiers = fgPlatformGetModifiers( );
752 GetCursorPos( &mouse_pos );
753 ScreenToClient( window->Window.Handle, &mouse_pos );
755 window->State.MouseX = mouse_pos.x;
756 window->State.MouseY = mouse_pos.y;
758 /* Convert the Win32 keystroke codes to GLUTtish way */
759 # define KEY(a,b) case a: keypress = b; break;
763 KEY( VK_F1, GLUT_KEY_F1 );
764 KEY( VK_F2, GLUT_KEY_F2 );
765 KEY( VK_F3, GLUT_KEY_F3 );
766 KEY( VK_F4, GLUT_KEY_F4 );
767 KEY( VK_F5, GLUT_KEY_F5 );
768 KEY( VK_F6, GLUT_KEY_F6 );
769 KEY( VK_F7, GLUT_KEY_F7 );
770 KEY( VK_F8, GLUT_KEY_F8 );
771 KEY( VK_F9, GLUT_KEY_F9 );
772 KEY( VK_F10, GLUT_KEY_F10 );
773 KEY( VK_F11, GLUT_KEY_F11 );
774 KEY( VK_F12, GLUT_KEY_F12 );
775 KEY( VK_PRIOR, GLUT_KEY_PAGE_UP );
776 KEY( VK_NEXT, GLUT_KEY_PAGE_DOWN );
777 KEY( VK_HOME, GLUT_KEY_HOME );
778 KEY( VK_END, GLUT_KEY_END );
779 KEY( VK_LEFT, GLUT_KEY_LEFT );
780 KEY( VK_UP, GLUT_KEY_UP );
781 KEY( VK_RIGHT, GLUT_KEY_RIGHT );
782 KEY( VK_DOWN, GLUT_KEY_DOWN );
783 KEY( VK_INSERT, GLUT_KEY_INSERT );
784 KEY( VK_LCONTROL, GLUT_KEY_CTRL_L );
785 KEY( VK_RCONTROL, GLUT_KEY_CTRL_R );
786 KEY( VK_LSHIFT, GLUT_KEY_SHIFT_L );
787 KEY( VK_RSHIFT, GLUT_KEY_SHIFT_R );
788 KEY( VK_LMENU, GLUT_KEY_ALT_L );
789 KEY( VK_RMENU, GLUT_KEY_ALT_R );
792 /* The delete key should be treated as an ASCII keypress: */
793 INVOKE_WCB( *window, Keyboard,
794 ( 127, window->State.MouseX, window->State.MouseY )
798 #if defined(_WIN32_WCE)
799 if(!(lParam & 0x40000000)) /* Prevent auto-repeat */
801 if(wParam==(unsigned)gxKeyList.vkRight)
802 keypress = GLUT_KEY_RIGHT;
803 else if(wParam==(unsigned)gxKeyList.vkLeft)
804 keypress = GLUT_KEY_LEFT;
805 else if(wParam==(unsigned)gxKeyList.vkUp)
806 keypress = GLUT_KEY_UP;
807 else if(wParam==(unsigned)gxKeyList.vkDown)
808 keypress = GLUT_KEY_DOWN;
809 else if(wParam==(unsigned)gxKeyList.vkA)
810 keypress = GLUT_KEY_F1;
811 else if(wParam==(unsigned)gxKeyList.vkB)
812 keypress = GLUT_KEY_F2;
813 else if(wParam==(unsigned)gxKeyList.vkC)
814 keypress = GLUT_KEY_F3;
815 else if(wParam==(unsigned)gxKeyList.vkStart)
816 keypress = GLUT_KEY_F4;
821 INVOKE_WCB( *window, Special,
823 window->State.MouseX, window->State.MouseY )
826 fgState.Modifiers = INVALID_MODIFIERS;
837 * Remember the current modifiers state. This is done here in order
838 * to make sure the VK_DELETE keyboard callback is executed properly.
840 fgState.Modifiers = fgPlatformGetModifiers( );
842 GetCursorPos( &mouse_pos );
843 ScreenToClient( window->Window.Handle, &mouse_pos );
845 window->State.MouseX = mouse_pos.x;
846 window->State.MouseY = mouse_pos.y;
849 * Convert the Win32 keystroke codes to GLUTtish way.
850 * "KEY(a,b)" was defined under "WM_KEYDOWN"
855 KEY( VK_F1, GLUT_KEY_F1 );
856 KEY( VK_F2, GLUT_KEY_F2 );
857 KEY( VK_F3, GLUT_KEY_F3 );
858 KEY( VK_F4, GLUT_KEY_F4 );
859 KEY( VK_F5, GLUT_KEY_F5 );
860 KEY( VK_F6, GLUT_KEY_F6 );
861 KEY( VK_F7, GLUT_KEY_F7 );
862 KEY( VK_F8, GLUT_KEY_F8 );
863 KEY( VK_F9, GLUT_KEY_F9 );
864 KEY( VK_F10, GLUT_KEY_F10 );
865 KEY( VK_F11, GLUT_KEY_F11 );
866 KEY( VK_F12, GLUT_KEY_F12 );
867 KEY( VK_PRIOR, GLUT_KEY_PAGE_UP );
868 KEY( VK_NEXT, GLUT_KEY_PAGE_DOWN );
869 KEY( VK_HOME, GLUT_KEY_HOME );
870 KEY( VK_END, GLUT_KEY_END );
871 KEY( VK_LEFT, GLUT_KEY_LEFT );
872 KEY( VK_UP, GLUT_KEY_UP );
873 KEY( VK_RIGHT, GLUT_KEY_RIGHT );
874 KEY( VK_DOWN, GLUT_KEY_DOWN );
875 KEY( VK_INSERT, GLUT_KEY_INSERT );
876 KEY( VK_LCONTROL, GLUT_KEY_CTRL_L );
877 KEY( VK_RCONTROL, GLUT_KEY_CTRL_R );
878 KEY( VK_LSHIFT, GLUT_KEY_SHIFT_L );
879 KEY( VK_RSHIFT, GLUT_KEY_SHIFT_R );
880 KEY( VK_LMENU, GLUT_KEY_ALT_L );
881 KEY( VK_RMENU, GLUT_KEY_ALT_R );
884 /* The delete key should be treated as an ASCII keypress: */
885 INVOKE_WCB( *window, KeyboardUp,
886 ( 127, window->State.MouseX, window->State.MouseY )
892 #if !defined(_WIN32_WCE)
896 GetKeyboardState( state );
898 if( ToAscii( (UINT)wParam, 0, state, code, 0 ) == 1 )
901 INVOKE_WCB( *window, KeyboardUp,
903 window->State.MouseX, window->State.MouseY )
905 #endif /* !defined(_WIN32_WCE) */
910 INVOKE_WCB( *window, SpecialUp,
912 window->State.MouseX, window->State.MouseY )
915 fgState.Modifiers = INVALID_MODIFIERS;
922 if( (fgState.KeyRepeat==GLUT_KEY_REPEAT_OFF || window->State.IgnoreKeyRepeat==GL_TRUE) && (HIWORD(lParam) & KF_REPEAT) )
925 fgState.Modifiers = fgPlatformGetModifiers( );
926 INVOKE_WCB( *window, Keyboard,
928 window->State.MouseX, window->State.MouseY )
930 fgState.Modifiers = INVALID_MODIFIERS;
934 case WM_CAPTURECHANGED:
935 /* User has finished resizing the window, force a redraw */
936 INVOKE_WCB( *window, Display, ( ) );
938 /*lRet = DefWindowProc( hWnd, uMsg, wParam, lParam ); */
941 /* Other messages that I have seen and which are not handled already */
942 case WM_SETTEXT: /* 0x000c */
943 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
944 /* Pass it on to "DefWindowProc" to set the window text */
947 case WM_GETTEXT: /* 0x000d */
948 /* Ideally we would copy the title of the window into "lParam" */
949 /* strncpy ( (char *)lParam, "Window Title", wParam );
950 lRet = ( wParam > 12 ) ? 12 : wParam; */
951 /* the number of characters copied */
952 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
955 case WM_GETTEXTLENGTH: /* 0x000e */
956 /* Ideally we would get the length of the title of the window */
958 /* the number of characters in "Window Title\0" (see above) */
961 case WM_ERASEBKGND: /* 0x0014 */
962 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
965 #if !defined(_WIN32_WCE)
966 case WM_SYNCPAINT: /* 0x0088 */
967 /* Another window has moved, need to update this one */
968 window->State.Redisplay = GL_TRUE;
969 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
970 /* Help screen says this message must be passed to "DefWindowProc" */
973 case WM_NCPAINT: /* 0x0085 */
974 /* Need to update the border of this window */
975 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
976 /* Pass it on to "DefWindowProc" to repaint a standard border */
979 case WM_SYSCOMMAND : /* 0x0112 */
982 * We have received a system command message. Try to act on it.
983 * The commands are passed in through the "wParam" parameter:
984 * The least significant digit seems to be which edge of the window
985 * is being used for a resize event:
989 * Congratulations and thanks to Richard Rauch for figuring this out..
991 switch ( wParam & 0xfff0 )
1000 /* User has clicked on the "-" to minimize the window */
1001 /* Turn off the visibility */
1002 window->State.Visible = GL_FALSE ;
1009 case SC_NEXTWINDOW :
1012 case SC_PREVWINDOW :
1016 /* Followed very closely by a WM_CLOSE message */
1040 case SC_SCREENSAVE :
1046 #if(WINVER >= 0x0400)
1050 case SC_MONITORPOWER :
1053 case SC_CONTEXTHELP :
1055 #endif /* WINVER >= 0x0400 */
1059 fgWarning( "Unknown wParam type 0x%x", wParam );
1064 #endif /* !defined(_WIN32_WCE) */
1066 /* We need to pass the message on to the operating system as well */
1067 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1071 /* handle multi-touch messages */
1074 unsigned int numInputs = (unsigned int)wParam;
1076 TOUCHINPUT* ti = (TOUCHINPUT*)malloc( sizeof(TOUCHINPUT)*numInputs);
1078 if (fghGetTouchInputInfo == (pGetTouchInputInfo)0xDEADBEEF) {
1079 fghGetTouchInputInfo = (pGetTouchInputInfo)GetProcAddress(GetModuleHandle("user32"),"GetTouchInputInfo");
1080 fghCloseTouchInputHandle = (pCloseTouchInputHandle)GetProcAddress(GetModuleHandle("user32"),"CloseTouchInputHandle");
1083 if (!fghGetTouchInputInfo) {
1088 if (fghGetTouchInputInfo( (HTOUCHINPUT)lParam, numInputs, ti, sizeof(TOUCHINPUT) )) {
1089 /* Handle each contact point */
1090 for (i = 0; i < numInputs; ++i ) {
1093 tp.x = TOUCH_COORD_TO_PIXEL(ti[i].x);
1094 tp.y = TOUCH_COORD_TO_PIXEL(ti[i].y);
1095 ScreenToClient( hWnd, &tp );
1097 ti[i].dwID = ti[i].dwID * 2;
1099 if (ti[i].dwFlags & TOUCHEVENTF_DOWN) {
1100 INVOKE_WCB( *window, MultiEntry, ( ti[i].dwID, GLUT_ENTERED ) );
1101 INVOKE_WCB( *window, MultiButton, ( ti[i].dwID, tp.x, tp.y, 0, GLUT_DOWN ) );
1102 } else if (ti[i].dwFlags & TOUCHEVENTF_MOVE) {
1103 INVOKE_WCB( *window, MultiMotion, ( ti[i].dwID, tp.x, tp.y ) );
1104 } else if (ti[i].dwFlags & TOUCHEVENTF_UP) {
1105 INVOKE_WCB( *window, MultiButton, ( ti[i].dwID, tp.x, tp.y, 0, GLUT_UP ) );
1106 INVOKE_WCB( *window, MultiEntry, ( ti[i].dwID, GLUT_LEFT ) );
1110 fghCloseTouchInputHandle((HTOUCHINPUT)lParam);
1112 lRet = 0; /*DefWindowProc( hWnd, uMsg, wParam, lParam );*/
1117 /* Handle unhandled messages */
1118 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );