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 );
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 fg_time_t fgPlatformSystemTime ( void )
127 #if defined(_WIN32_WCE)
128 return GetTickCount();
130 /* TODO: do this with QueryPerformanceCounter as timeGetTime has
131 * insufficient resolution (only about 5 ms on system under low load).
133 * http://msdn.microsoft.com/en-us/library/windows/desktop/dd757629(v=vs.85).aspx
134 * Or maybe QueryPerformanceCounter is not a good idea either, see
135 * http://old.nabble.com/Re%3A-glutTimerFunc-does-not-detect-if-system-time-moved-backward-p33479674.html
136 * for some other ideas (at bottom)...
138 return timeGetTime();
143 void fgPlatformSleepForEvents( fg_time_t msec )
145 MsgWaitForMultipleObjects( 0, NULL, FALSE, (DWORD) msec, QS_ALLINPUT );
149 void fgPlatformProcessSingleEvent ( void )
153 FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutMainLoopEvent" );
155 while( PeekMessage( &stMsg, NULL, 0, 0, PM_NOREMOVE ) )
157 if( GetMessage( &stMsg, NULL, 0, 0 ) == 0 )
159 if( fgState.ActionOnWindowClose == GLUT_ACTION_EXIT )
164 else if( fgState.ActionOnWindowClose == GLUT_ACTION_GLUTMAINLOOP_RETURNS )
165 fgState.ExecState = GLUT_EXEC_STATE_STOP;
170 TranslateMessage( &stMsg );
171 DispatchMessage( &stMsg );
177 void fgPlatformMainLoopPreliminaryWork ( void )
179 SFG_Window *window = (SFG_Window *)fgStructure.Windows.First ;
182 * Processing before the main loop: If there is a window which is open and
183 * which has a visibility callback, call it. I know this is an ugly hack,
184 * but I'm not sure what else to do about it. Ideally we should leave
185 * something uninitialized in the create window code and initialize it in
186 * the main loop, and have that initialization create a "WM_ACTIVATE"
187 * message. Then we would put the visibility callback code in the
188 * "case WM_ACTIVATE" block below. - John Fay -- 10/24/02
192 if ( FETCH_WCB( *window, Visibility ) )
194 SFG_Window *current_window = fgStructure.CurrentWindow ;
196 INVOKE_WCB( *window, Visibility, ( window->State.Visible ) );
197 fgSetWindow( current_window );
200 window = (SFG_Window *)window->Node.Next ;
206 * Determine a GLUT modifer mask based on MS-WINDOWS system info.
208 static int fgPlatformGetModifiers (void)
211 ( ( ( GetKeyState( VK_LSHIFT ) < 0 ) ||
212 ( GetKeyState( VK_RSHIFT ) < 0 )) ? GLUT_ACTIVE_SHIFT : 0 ) |
213 ( ( ( GetKeyState( VK_LCONTROL ) < 0 ) ||
214 ( GetKeyState( VK_RCONTROL ) < 0 )) ? GLUT_ACTIVE_CTRL : 0 ) |
215 ( ( ( GetKeyState( VK_LMENU ) < 0 ) ||
216 ( GetKeyState( VK_RMENU ) < 0 )) ? GLUT_ACTIVE_ALT : 0 );
220 * The window procedure for handling Win32 events
222 LRESULT CALLBACK fgPlatformWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam,
225 static unsigned char lControl = 0, rControl = 0, lShift = 0,
226 rShift = 0, lAlt = 0, rAlt = 0;
228 SFG_Window *window, *child_window = NULL;
232 FREEGLUT_INTERNAL_ERROR_EXIT_IF_NOT_INITIALISED ( "Event Handler" ) ;
234 window = fgWindowByHandle( hWnd );
236 if ( ( window == NULL ) && ( uMsg != WM_CREATE ) )
237 return DefWindowProc( hWnd, uMsg, wParam, lParam );
239 /* printf ( "Window %3d message <%04x> %12d %12d\n", window?window->ID:0,
240 uMsg, wParam, lParam ); */
242 /* Some events only sent to main window. Check if the current window that
243 * the mouse is over is a child window. Below whn handling some messages,
244 * we make sure that we process callbacks on the child window instead.
245 * This mirrors how GLUT does things.
247 if (window && window->Children.First)
250 SFG_WindowHandleType hwnd;
251 SFG_Window* temp_window;
253 GetCursorPos( &mouse_pos );
254 ScreenToClient( window->Window.Handle, &mouse_pos );
255 hwnd = ChildWindowFromPoint(window->Window.Handle, mouse_pos);
256 if (hwnd) /* can be NULL if mouse outside parent by the time we get here */
258 temp_window = fgWindowByHandle(hwnd);
259 if (temp_window->Parent) /* Verify we got a child window */
260 child_window = temp_window;
266 SFG_Window* temp_window = child_window?child_window:window;
268 fgState.Modifiers = fgPlatformGetModifiers( );
270 /* Checking for CTRL, ALT, and SHIFT key positions: Key Down! */
271 if ( !lControl && GetAsyncKeyState ( VK_LCONTROL ) )
273 INVOKE_WCB ( *temp_window, Special,
274 ( GLUT_KEY_CTRL_L, temp_window->State.MouseX, temp_window->State.MouseY )
280 if ( !rControl && GetAsyncKeyState ( VK_RCONTROL ) )
282 INVOKE_WCB ( *temp_window, Special,
283 ( GLUT_KEY_CTRL_R, temp_window->State.MouseX, temp_window->State.MouseY )
289 if ( !lShift && GetAsyncKeyState ( VK_LSHIFT ) )
291 INVOKE_WCB ( *temp_window, Special,
292 ( GLUT_KEY_SHIFT_L, temp_window->State.MouseX, temp_window->State.MouseY )
298 if ( !rShift && GetAsyncKeyState ( VK_RSHIFT ) )
300 INVOKE_WCB ( *temp_window, Special,
301 ( GLUT_KEY_SHIFT_R, temp_window->State.MouseX, temp_window->State.MouseY )
307 if ( !lAlt && GetAsyncKeyState ( VK_LMENU ) )
309 INVOKE_WCB ( *temp_window, Special,
310 ( GLUT_KEY_ALT_L, temp_window->State.MouseX, temp_window->State.MouseY )
316 if ( !rAlt && GetAsyncKeyState ( VK_RMENU ) )
318 INVOKE_WCB ( *temp_window, Special,
319 ( GLUT_KEY_ALT_R, temp_window->State.MouseX, temp_window->State.MouseY )
325 /* Checking for CTRL, ALT, and SHIFT key positions: Key Up! */
326 if ( lControl && !GetAsyncKeyState ( VK_LCONTROL ) )
328 INVOKE_WCB ( *temp_window, SpecialUp,
329 ( GLUT_KEY_CTRL_L, temp_window->State.MouseX, temp_window->State.MouseY )
335 if ( rControl && !GetAsyncKeyState ( VK_RCONTROL ) )
337 INVOKE_WCB ( *temp_window, SpecialUp,
338 ( GLUT_KEY_CTRL_R, temp_window->State.MouseX, temp_window->State.MouseY )
344 if ( lShift && !GetAsyncKeyState ( VK_LSHIFT ) )
346 INVOKE_WCB ( *temp_window, SpecialUp,
347 ( GLUT_KEY_SHIFT_L, temp_window->State.MouseX, temp_window->State.MouseY )
353 if ( rShift && !GetAsyncKeyState ( VK_RSHIFT ) )
355 INVOKE_WCB ( *temp_window, SpecialUp,
356 ( GLUT_KEY_SHIFT_R, temp_window->State.MouseX, temp_window->State.MouseY )
362 if ( lAlt && !GetAsyncKeyState ( VK_LMENU ) )
364 INVOKE_WCB ( *temp_window, SpecialUp,
365 ( GLUT_KEY_ALT_L, temp_window->State.MouseX, temp_window->State.MouseY )
371 if ( rAlt && !GetAsyncKeyState ( VK_RMENU ) )
373 INVOKE_WCB ( *temp_window, SpecialUp,
374 ( GLUT_KEY_ALT_R, temp_window->State.MouseX, temp_window->State.MouseY )
380 fgState.Modifiers = INVALID_MODIFIERS;
386 /* The window structure is passed as the creation structure parameter... */
387 window = (SFG_Window *) (((LPCREATESTRUCT) lParam)->lpCreateParams);
388 FREEGLUT_INTERNAL_ERROR_EXIT ( ( window != NULL ), "Cannot create window",
389 "fgPlatformWindowProc" );
391 window->Window.Handle = hWnd;
392 window->Window.pContext.Device = GetDC( hWnd );
395 unsigned int current_DisplayMode = fgState.DisplayMode;
396 fgState.DisplayMode = GLUT_DOUBLE | GLUT_RGB | GLUT_DEPTH;
397 #if !defined(_WIN32_WCE)
398 fgSetupPixelFormat( window, GL_FALSE, PFD_MAIN_PLANE );
400 fgState.DisplayMode = current_DisplayMode;
402 if( fgStructure.MenuContext )
403 wglMakeCurrent( window->Window.pContext.Device,
404 fgStructure.MenuContext->MContext
408 fgStructure.MenuContext =
409 (SFG_MenuContext *)malloc( sizeof(SFG_MenuContext) );
410 fgStructure.MenuContext->MContext =
411 wglCreateContext( window->Window.pContext.Device );
414 /* window->Window.Context = wglGetCurrentContext (); */
415 window->Window.Context = wglCreateContext( window->Window.pContext.Device );
419 #if !defined(_WIN32_WCE)
420 fgSetupPixelFormat( window, GL_FALSE, PFD_MAIN_PLANE );
423 if( ! fgState.UseCurrentContext )
424 window->Window.Context =
425 wglCreateContext( window->Window.pContext.Device );
428 window->Window.Context = wglGetCurrentContext( );
429 if( ! window->Window.Context )
430 window->Window.Context =
431 wglCreateContext( window->Window.pContext.Device );
434 #if !defined(_WIN32_WCE)
435 fgNewWGLCreateContext( window );
439 window->State.NeedToResize = GL_TRUE;
440 /* if we used CW_USEDEFAULT (thats a negative value) for the size
441 * of the window, query the window now for the size at which it
444 if( ( window->State.Width < 0 ) || ( window->State.Height < 0 ) )
446 SFG_Window *current_window = fgStructure.CurrentWindow;
448 fgSetWindow( window );
449 window->State.Width = glutGet( GLUT_WINDOW_WIDTH );
450 window->State.Height = glutGet( GLUT_WINDOW_HEIGHT );
451 fgSetWindow( current_window );
454 ReleaseDC( window->Window.Handle, window->Window.pContext.Device );
456 #if defined(_WIN32_WCE)
457 /* Take over button handling */
459 HINSTANCE dxDllLib=LoadLibrary(_T("gx.dll"));
462 GXGetDefaultKeys_=(GXGETDEFAULTKEYS)GetProcAddress(dxDllLib, _T("?GXGetDefaultKeys@@YA?AUGXKeyList@@H@Z"));
463 GXOpenInput_=(GXOPENINPUT)GetProcAddress(dxDllLib, _T("?GXOpenInput@@YAHXZ"));
468 if(GXGetDefaultKeys_)
469 gxKeyList = (*GXGetDefaultKeys_)(GX_LANDSCAPEKEYS);
472 #endif /* defined(_WIN32_WCE) */
477 * If the window is visible, then it is the user manually resizing it.
478 * If it is not, then it is the system sending us a dummy resize with
479 * zero dimensions on a "glutIconifyWindow" call.
481 if( window->State.Visible )
483 window->State.NeedToResize = GL_TRUE;
484 #if defined(_WIN32_WCE)
485 window->State.Width = HIWORD(lParam);
486 window->State.Height = LOWORD(lParam);
488 window->State.Width = LOWORD(lParam);
489 window->State.Height = HIWORD(lParam);
490 #endif /* defined(_WIN32_WCE) */
496 /* printf("WM_SETFOCUS: %p\n", window ); */
498 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
502 /* If child should have focus instead, set it here. */
503 SetFocus(child_window->Window.Handle);
504 SetActiveWindow( child_window->Window.Handle );
505 INVOKE_WCB( *child_window, Entry, ( GLUT_ENTERED ) );
506 UpdateWindow ( child_window->Window.Handle );
510 SetActiveWindow( window->Window.Handle );
511 INVOKE_WCB( *window, Entry, ( GLUT_ENTERED ) );
513 /* Always request update on main window to be safe */
514 UpdateWindow ( hWnd );
520 SFG_Menu* menu = NULL;
521 /* printf("WM_KILLFOCUS: %p\n", window ); */
522 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
523 INVOKE_WCB( *window, Entry, ( GLUT_LEFT ) );
525 /* If we have an open menu, see if the open menu should be closed
526 * when focus was lost because user either switched
527 * application or FreeGLUT window (if one is running multiple
528 * windows). If so, close menu the active menu.
530 if ( fgStructure.Menus.First )
531 menu = fgGetActiveMenu();
535 SFG_Window* wnd = NULL;
536 HWND hwnd = GetFocus(); /* Get window with current focus - NULL for non freeglut windows */
538 /* See which of our windows it is */
539 wnd = fgWindowByHandle(hwnd);
542 /* User switched to another application*/
543 fgDeactivateMenu(menu->ParentWindow);
544 else if (!wnd->IsMenu) /* Make sure we don't kill the menu when trying to enter a submenu */
546 if (wnd!=menu->ParentWindow)
547 /* User switched to another FreeGLUT window */
548 fgDeactivateMenu(menu->ParentWindow);
551 /* Check if focus lost because non-client area of
552 * window was pressed (pressing on client area is
553 * handled in fgCheckActiveMenu)
556 RECT clientArea = fghGetClientArea(menu->ParentWindow, GL_FALSE);
557 GetCursorPos(&mouse_pos);
558 if ( !PtInRect( &clientArea, mouse_pos ) )
559 fgDeactivateMenu(menu->ParentWindow);
568 if (LOWORD(wParam) != WA_INACTIVE)
570 /* printf("WM_ACTIVATE: fgSetCursor( %p, %d)\n", window,
571 window->State.Cursor ); */
572 fgSetCursor( window, window->State.Cursor );
575 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
580 /* printf ( "Cursor event %x %x %x %x\n", window, window->State.Cursor, lParam, wParam ) ; */
581 if( LOWORD( lParam ) == HTCLIENT )
582 fgSetCursor ( window, window->State.Cursor ) ;
584 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
588 window->State.Visible = GL_TRUE;
589 window->State.Redisplay = GL_TRUE;
593 /* Turn on the visibility in case it was turned off somehow */
594 window->State.Visible = GL_TRUE;
595 BeginPaint( hWnd, &ps );
596 fghRedrawWindow( window );
597 EndPaint( hWnd, &ps );
601 fgDestroyWindow ( window );
602 if ( fgState.ActionOnWindowClose != GLUT_ACTION_CONTINUE_EXECUTION )
608 * The window already got destroyed, so don't bother with it.
614 #if defined(_WIN32_WCE)
615 window->State.MouseX = 320-HIWORD( lParam );
616 window->State.MouseY = LOWORD( lParam );
618 window->State.MouseX = LOWORD( lParam );
619 window->State.MouseY = HIWORD( lParam );
620 #endif /* defined(_WIN32_WCE) */
621 /* Restrict to [-32768, 32767] to match X11 behaviour */
622 /* See comment in "freeglut_developer" mailing list 10/4/04 */
623 if ( window->State.MouseX > 32767 ) window->State.MouseX -= 65536;
624 if ( window->State.MouseY > 32767 ) window->State.MouseY -= 65536;
626 if ( window->ActiveMenu )
628 fgUpdateMenuHighlight( window->ActiveMenu );
632 fgState.Modifiers = fgPlatformGetModifiers( );
634 if( ( wParam & MK_LBUTTON ) ||
635 ( wParam & MK_MBUTTON ) ||
636 ( wParam & MK_RBUTTON ) )
637 INVOKE_WCB( *window, Motion, ( window->State.MouseX,
638 window->State.MouseY ) );
640 INVOKE_WCB( *window, Passive, ( window->State.MouseX,
641 window->State.MouseY ) );
643 fgState.Modifiers = INVALID_MODIFIERS;
654 GLboolean pressed = GL_TRUE;
657 #if defined(_WIN32_WCE)
658 window->State.MouseX = 320-HIWORD( lParam );
659 window->State.MouseY = LOWORD( lParam );
661 window->State.MouseX = LOWORD( lParam );
662 window->State.MouseY = HIWORD( lParam );
663 #endif /* defined(_WIN32_WCE) */
665 /* Restrict to [-32768, 32767] to match X11 behaviour */
666 /* See comment in "freeglut_developer" mailing list 10/4/04 */
667 if ( window->State.MouseX > 32767 ) window->State.MouseX -= 65536;
668 if ( window->State.MouseY > 32767 ) window->State.MouseY -= 65536;
674 button = GLUT_LEFT_BUTTON;
678 button = GLUT_MIDDLE_BUTTON;
682 button = GLUT_RIGHT_BUTTON;
686 button = GLUT_LEFT_BUTTON;
690 button = GLUT_MIDDLE_BUTTON;
694 button = GLUT_RIGHT_BUTTON;
702 #if !defined(_WIN32_WCE)
703 if( GetSystemMetrics( SM_SWAPBUTTON ) )
705 if( button == GLUT_LEFT_BUTTON )
706 button = GLUT_RIGHT_BUTTON;
708 if( button == GLUT_RIGHT_BUTTON )
709 button = GLUT_LEFT_BUTTON;
711 #endif /* !defined(_WIN32_WCE) */
714 return DefWindowProc( hWnd, uMsg, lParam, wParam );
717 * Do not execute the application's mouse callback if a menu
718 * is hooked to this button. In that case an appropriate
719 * private call should be generated.
721 if( fgCheckActiveMenu( window, button, pressed,
722 window->State.MouseX, window->State.MouseY ) )
725 /* Set capture so that the window captures all the mouse messages */
727 * XXX - Multiple button support: Under X11, the mouse is not released
728 * XXX - from the window until all buttons have been released, even if the
729 * XXX - user presses a button in another window. This will take more
730 * XXX - code changes than I am up to at the moment (10/5/04). The present
731 * XXX - is a 90 percent solution.
733 if ( pressed == GL_TRUE )
734 SetCapture ( window->Window.Handle ) ;
738 if( ! FETCH_WCB( *window, Mouse ) )
741 fgSetWindow( window );
742 fgState.Modifiers = fgPlatformGetModifiers( );
747 pressed ? GLUT_DOWN : GLUT_UP,
748 window->State.MouseX,
753 fgState.Modifiers = INVALID_MODIFIERS;
759 int wheel_number = LOWORD( wParam );
760 short ticks = ( short )HIWORD( wParam );
761 fgState.MouseWheelTicks += ticks;
764 * XXX Should use WHEEL_DELTA instead of 120
766 if ( abs ( fgState.MouseWheelTicks ) >= 120 )
768 int direction = ( fgState.MouseWheelTicks > 0 ) ? 1 : -1;
770 if( ! FETCH_WCB( *window, MouseWheel ) &&
771 ! FETCH_WCB( *window, Mouse ) )
774 fgSetWindow( window );
775 fgState.Modifiers = fgPlatformGetModifiers( );
778 * XXX Should use WHEEL_DELTA instead of 120
780 while( abs ( fgState.MouseWheelTicks ) >= 120 )
782 if( FETCH_WCB( *window, MouseWheel ) )
783 INVOKE_WCB( *window, MouseWheel,
786 window->State.MouseX,
790 else /* No mouse wheel, call the mouse button callback twice */
793 * Map wheel zero to button 3 and 4; +1 to 3, -1 to 4
794 * " " one +1 to 5, -1 to 6, ...
796 * XXX The below assumes that you have no more than 3 mouse
797 * XXX buttons. Sorry.
799 int button = wheel_number * 2 + 3;
802 INVOKE_WCB( *window, Mouse,
804 window->State.MouseX, window->State.MouseY )
806 INVOKE_WCB( *window, Mouse,
808 window->State.MouseX, window->State.MouseY )
813 * XXX Should use WHEEL_DELTA instead of 120
815 fgState.MouseWheelTicks -= 120 * direction;
818 fgState.Modifiers = INVALID_MODIFIERS;
830 window = child_window;
832 if( ( fgState.KeyRepeat==GLUT_KEY_REPEAT_OFF || window->State.IgnoreKeyRepeat==GL_TRUE ) && (HIWORD(lParam) & KF_REPEAT) )
836 * Remember the current modifiers state. This is done here in order
837 * to make sure the VK_DELETE keyboard callback is executed properly.
839 fgState.Modifiers = fgPlatformGetModifiers( );
841 GetCursorPos( &mouse_pos );
842 ScreenToClient( window->Window.Handle, &mouse_pos );
844 window->State.MouseX = mouse_pos.x;
845 window->State.MouseY = mouse_pos.y;
847 /* Convert the Win32 keystroke codes to GLUTtish way */
848 # define KEY(a,b) case a: keypress = b; break;
852 KEY( VK_F1, GLUT_KEY_F1 );
853 KEY( VK_F2, GLUT_KEY_F2 );
854 KEY( VK_F3, GLUT_KEY_F3 );
855 KEY( VK_F4, GLUT_KEY_F4 );
856 KEY( VK_F5, GLUT_KEY_F5 );
857 KEY( VK_F6, GLUT_KEY_F6 );
858 KEY( VK_F7, GLUT_KEY_F7 );
859 KEY( VK_F8, GLUT_KEY_F8 );
860 KEY( VK_F9, GLUT_KEY_F9 );
861 KEY( VK_F10, GLUT_KEY_F10 );
862 KEY( VK_F11, GLUT_KEY_F11 );
863 KEY( VK_F12, GLUT_KEY_F12 );
864 KEY( VK_PRIOR, GLUT_KEY_PAGE_UP );
865 KEY( VK_NEXT, GLUT_KEY_PAGE_DOWN );
866 KEY( VK_HOME, GLUT_KEY_HOME );
867 KEY( VK_END, GLUT_KEY_END );
868 KEY( VK_LEFT, GLUT_KEY_LEFT );
869 KEY( VK_UP, GLUT_KEY_UP );
870 KEY( VK_RIGHT, GLUT_KEY_RIGHT );
871 KEY( VK_DOWN, GLUT_KEY_DOWN );
872 KEY( VK_INSERT, GLUT_KEY_INSERT );
874 case VK_LCONTROL: case VK_RCONTROL: case VK_CONTROL:
875 case VK_LSHIFT: case VK_RSHIFT: case VK_SHIFT:
876 case VK_LMENU: case VK_RMENU: case VK_MENU:
877 /* These keypresses and releases are handled earlier in the function */
881 /* The delete key should be treated as an ASCII keypress: */
882 INVOKE_WCB( *window, Keyboard,
883 ( 127, window->State.MouseX, window->State.MouseY )
887 #if defined(_WIN32_WCE)
888 if(!(lParam & 0x40000000)) /* Prevent auto-repeat */
890 if(wParam==(unsigned)gxKeyList.vkRight)
891 keypress = GLUT_KEY_RIGHT;
892 else if(wParam==(unsigned)gxKeyList.vkLeft)
893 keypress = GLUT_KEY_LEFT;
894 else if(wParam==(unsigned)gxKeyList.vkUp)
895 keypress = GLUT_KEY_UP;
896 else if(wParam==(unsigned)gxKeyList.vkDown)
897 keypress = GLUT_KEY_DOWN;
898 else if(wParam==(unsigned)gxKeyList.vkA)
899 keypress = GLUT_KEY_F1;
900 else if(wParam==(unsigned)gxKeyList.vkB)
901 keypress = GLUT_KEY_F2;
902 else if(wParam==(unsigned)gxKeyList.vkC)
903 keypress = GLUT_KEY_F3;
904 else if(wParam==(unsigned)gxKeyList.vkStart)
905 keypress = GLUT_KEY_F4;
910 INVOKE_WCB( *window, Special,
912 window->State.MouseX, window->State.MouseY )
915 fgState.Modifiers = INVALID_MODIFIERS;
926 window = child_window;
929 * Remember the current modifiers state. This is done here in order
930 * to make sure the VK_DELETE keyboard callback is executed properly.
932 fgState.Modifiers = fgPlatformGetModifiers( );
934 GetCursorPos( &mouse_pos );
935 ScreenToClient( window->Window.Handle, &mouse_pos );
937 window->State.MouseX = mouse_pos.x;
938 window->State.MouseY = mouse_pos.y;
941 * Convert the Win32 keystroke codes to GLUTtish way.
942 * "KEY(a,b)" was defined under "WM_KEYDOWN"
947 KEY( VK_F1, GLUT_KEY_F1 );
948 KEY( VK_F2, GLUT_KEY_F2 );
949 KEY( VK_F3, GLUT_KEY_F3 );
950 KEY( VK_F4, GLUT_KEY_F4 );
951 KEY( VK_F5, GLUT_KEY_F5 );
952 KEY( VK_F6, GLUT_KEY_F6 );
953 KEY( VK_F7, GLUT_KEY_F7 );
954 KEY( VK_F8, GLUT_KEY_F8 );
955 KEY( VK_F9, GLUT_KEY_F9 );
956 KEY( VK_F10, GLUT_KEY_F10 );
957 KEY( VK_F11, GLUT_KEY_F11 );
958 KEY( VK_F12, GLUT_KEY_F12 );
959 KEY( VK_PRIOR, GLUT_KEY_PAGE_UP );
960 KEY( VK_NEXT, GLUT_KEY_PAGE_DOWN );
961 KEY( VK_HOME, GLUT_KEY_HOME );
962 KEY( VK_END, GLUT_KEY_END );
963 KEY( VK_LEFT, GLUT_KEY_LEFT );
964 KEY( VK_UP, GLUT_KEY_UP );
965 KEY( VK_RIGHT, GLUT_KEY_RIGHT );
966 KEY( VK_DOWN, GLUT_KEY_DOWN );
967 KEY( VK_INSERT, GLUT_KEY_INSERT );
969 case VK_LCONTROL: case VK_RCONTROL: case VK_CONTROL:
970 case VK_LSHIFT: case VK_RSHIFT: case VK_SHIFT:
971 case VK_LMENU: case VK_RMENU: case VK_MENU:
972 /* These keypresses and releases are handled earlier in the function */
976 /* The delete key should be treated as an ASCII keypress: */
977 INVOKE_WCB( *window, KeyboardUp,
978 ( 127, window->State.MouseX, window->State.MouseY )
984 #if !defined(_WIN32_WCE)
988 GetKeyboardState( state );
990 if( ToAscii( (UINT)wParam, 0, state, code, 0 ) == 1 )
993 INVOKE_WCB( *window, KeyboardUp,
995 window->State.MouseX, window->State.MouseY )
997 #endif /* !defined(_WIN32_WCE) */
1001 if( keypress != -1 )
1002 INVOKE_WCB( *window, SpecialUp,
1004 window->State.MouseX, window->State.MouseY )
1007 fgState.Modifiers = INVALID_MODIFIERS;
1015 window = child_window;
1017 if( (fgState.KeyRepeat==GLUT_KEY_REPEAT_OFF || window->State.IgnoreKeyRepeat==GL_TRUE) && (HIWORD(lParam) & KF_REPEAT) )
1020 fgState.Modifiers = fgPlatformGetModifiers( );
1021 INVOKE_WCB( *window, Keyboard,
1023 window->State.MouseX, window->State.MouseY )
1025 fgState.Modifiers = INVALID_MODIFIERS;
1029 case WM_CAPTURECHANGED:
1030 /* User has finished resizing the window, force a redraw */
1031 INVOKE_WCB( *window, Display, ( ) );
1033 /*lRet = DefWindowProc( hWnd, uMsg, wParam, lParam ); */
1036 /* Other messages that I have seen and which are not handled already */
1037 case WM_SETTEXT: /* 0x000c */
1038 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1039 /* Pass it on to "DefWindowProc" to set the window text */
1042 case WM_GETTEXT: /* 0x000d */
1043 /* Ideally we would copy the title of the window into "lParam" */
1044 /* strncpy ( (char *)lParam, "Window Title", wParam );
1045 lRet = ( wParam > 12 ) ? 12 : wParam; */
1046 /* the number of characters copied */
1047 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1050 case WM_GETTEXTLENGTH: /* 0x000e */
1051 /* Ideally we would get the length of the title of the window */
1053 /* the number of characters in "Window Title\0" (see above) */
1056 case WM_ERASEBKGND: /* 0x0014 */
1057 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1060 #if !defined(_WIN32_WCE)
1061 case WM_SYNCPAINT: /* 0x0088 */
1062 /* Another window has moved, need to update this one */
1063 window->State.Redisplay = GL_TRUE;
1064 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1065 /* Help screen says this message must be passed to "DefWindowProc" */
1068 case WM_NCPAINT: /* 0x0085 */
1069 /* Need to update the border of this window */
1070 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1071 /* Pass it on to "DefWindowProc" to repaint a standard border */
1074 case WM_SYSCOMMAND : /* 0x0112 */
1077 * We have received a system command message. Try to act on it.
1078 * The commands are passed in through the "wParam" parameter:
1079 * The least significant digit seems to be which edge of the window
1080 * is being used for a resize event:
1084 * Congratulations and thanks to Richard Rauch for figuring this out..
1086 switch ( wParam & 0xfff0 )
1095 /* User has clicked on the "-" to minimize the window */
1096 /* Turn off the visibility */
1097 window->State.Visible = GL_FALSE ;
1104 case SC_NEXTWINDOW :
1107 case SC_PREVWINDOW :
1111 /* Followed very closely by a WM_CLOSE message */
1135 case SC_SCREENSAVE :
1141 #if(WINVER >= 0x0400)
1145 case SC_MONITORPOWER :
1148 case SC_CONTEXTHELP :
1150 #endif /* WINVER >= 0x0400 */
1154 fgWarning( "Unknown wParam type 0x%x", wParam );
1159 #endif /* !defined(_WIN32_WCE) */
1161 /* We need to pass the message on to the operating system as well */
1162 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1166 /* handle multi-touch messages */
1169 unsigned int numInputs = (unsigned int)wParam;
1171 TOUCHINPUT* ti = (TOUCHINPUT*)malloc( sizeof(TOUCHINPUT)*numInputs);
1173 if (fghGetTouchInputInfo == (pGetTouchInputInfo)0xDEADBEEF) {
1174 fghGetTouchInputInfo = (pGetTouchInputInfo)GetProcAddress(GetModuleHandle("user32"),"GetTouchInputInfo");
1175 fghCloseTouchInputHandle = (pCloseTouchInputHandle)GetProcAddress(GetModuleHandle("user32"),"CloseTouchInputHandle");
1178 if (!fghGetTouchInputInfo) {
1183 if (fghGetTouchInputInfo( (HTOUCHINPUT)lParam, numInputs, ti, sizeof(TOUCHINPUT) )) {
1184 /* Handle each contact point */
1185 for (i = 0; i < numInputs; ++i ) {
1188 tp.x = TOUCH_COORD_TO_PIXEL(ti[i].x);
1189 tp.y = TOUCH_COORD_TO_PIXEL(ti[i].y);
1190 ScreenToClient( hWnd, &tp );
1192 ti[i].dwID = ti[i].dwID * 2;
1194 if (ti[i].dwFlags & TOUCHEVENTF_DOWN) {
1195 INVOKE_WCB( *window, MultiEntry, ( ti[i].dwID, GLUT_ENTERED ) );
1196 INVOKE_WCB( *window, MultiButton, ( ti[i].dwID, tp.x, tp.y, 0, GLUT_DOWN ) );
1197 } else if (ti[i].dwFlags & TOUCHEVENTF_MOVE) {
1198 INVOKE_WCB( *window, MultiMotion, ( ti[i].dwID, tp.x, tp.y ) );
1199 } else if (ti[i].dwFlags & TOUCHEVENTF_UP) {
1200 INVOKE_WCB( *window, MultiButton, ( ti[i].dwID, tp.x, tp.y, 0, GLUT_UP ) );
1201 INVOKE_WCB( *window, MultiEntry, ( ti[i].dwID, GLUT_LEFT ) );
1205 fghCloseTouchInputHandle((HTOUCHINPUT)lParam);
1207 lRet = 0; /*DefWindowProc( hWnd, uMsg, wParam, lParam );*/
1212 /* Handle unhandled messages */
1213 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );