4 * The windows message processing methods.
6 * Copyright (c) 1999-2000 Pawel W. Olszta. All Rights Reserved.
7 * Written by Pawel W. Olszta, <olszta@sourceforge.net>
8 * Creation date: Fri Dec 3 1999
10 * Permission is hereby granted, free of charge, to any person obtaining a
11 * copy of this software and associated documentation files (the "Software"),
12 * to deal in the Software without restriction, including without limitation
13 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 * and/or sell copies of the Software, and to permit persons to whom the
15 * Software is furnished to do so, subject to the following conditions:
17 * The above copyright notice and this permission notice shall be included
18 * in all copies or substantial portions of the Software.
20 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23 * PAWEL W. OLSZTA BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
24 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
25 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32 #define G_LOG_DOMAIN "freeglut-main"
34 #include "../include/GL/freeglut.h"
35 #include "../include/GL/freeglut_internal.h"
38 * TODO BEFORE THE STABLE RELEASE:
40 * There are some issues concerning window redrawing under X11, and maybe
41 * some events are not handled. The Win32 version lacks some more features,
42 * but seems acceptable for not demanding purposes.
44 * Need to investigate why the X11 version breaks out with an error when
45 * closing a window (using the window manager, not glutDestroyWindow)...
48 /* -- PRIVATE FUNCTIONS ---------------------------------------------------- */
51 * Calls a window's redraw method. This is used when
52 * a redraw is forced by the incoming window messages.
54 static void fghRedrawWindowByHandle
55 #if TARGET_HOST_UNIX_X11
57 #elif TARGET_HOST_WIN32
62 * Find the window we have to redraw...
64 SFG_Window* window = fgWindowByHandle( handle );
65 freeglut_return_if_fail( window != NULL );
68 * Check if there is a display callback hooked to it
70 freeglut_return_if_fail( window->Callbacks.Display != NULL );
73 * Return if the window is not visible
75 freeglut_return_if_fail( window->State.Visible == TRUE );
78 * Set the window as the current one. Calling glutSetWindow()
79 * might seem slow and generally redundant, but it is portable.
81 glutSetWindow( window->ID );
84 * Have the callback executed now. The buffers should
85 * be swapped by the glutSwapBuffers() execution inside
86 * the callback itself.
88 window->Callbacks.Display();
92 * Handle a window configuration change. When no reshape
93 * callback is hooked, the viewport size is updated to
94 * match the new window size.
96 static void fghReshapeWindowByHandle
97 #if TARGET_HOST_UNIX_X11
98 ( Window handle, int width, int height )
99 #elif TARGET_HOST_WIN32
100 ( HWND handle, int width, int height )
104 * Find the window that received the reshape event
106 SFG_Window* window = fgWindowByHandle( handle );
107 freeglut_return_if_fail( window != NULL );
110 * Remember about setting the current window...
112 glutSetWindow( window->ID );
115 * Check if there is a reshape callback hooked
117 if( window->Callbacks.Reshape != NULL )
120 * OKi, have it called immediately
122 window->Callbacks.Reshape( width, height );
127 * Otherwise just resize the viewport
129 glViewport( 0, 0, width, height );
134 * A static helper function to execute display callback for a window
136 static void fghcbDisplayWindow( SFG_Window *window, SFG_Enumerator *enumerator )
138 #if TARGET_HOST_UNIX_X11
140 * Check if there is an idle callback hooked
142 if( (window->Callbacks.Display != NULL) &&
143 (window->State.Redisplay == TRUE) &&
144 (window->State.Visible == TRUE) )
147 * OKi, this is the case: have the window set as the current one
149 glutSetWindow( window->ID );
152 * Do not exagerate with the redisplaying
154 window->State.Redisplay = FALSE;
157 * And execute the display callback immediately after
159 window->Callbacks.Display();
162 #elif TARGET_HOST_WIN32
165 * Do we need to explicitly resize the window?
167 if( window->State.NeedToResize )
169 glutSetWindow( window->ID );
171 fghReshapeWindowByHandle(
172 window->Window.Handle,
173 glutGet( GLUT_WINDOW_WIDTH ),
174 glutGet( GLUT_WINDOW_HEIGHT )
178 * Never ever do that again:
180 window->State.NeedToResize = FALSE;
184 * This is done in a bit different way under Windows
187 window->Window.Handle, NULL, NULL,
188 RDW_NOERASE | RDW_INTERNALPAINT | RDW_INVALIDATE
194 * Process this window's children (if any)
196 fgEnumSubWindows( window, fghcbDisplayWindow, enumerator );
200 * Make all windows perform a display call
202 static void fghDisplayAll( void )
204 SFG_Enumerator enumerator;
207 * Uses a method very similiar for fgWindowByHandle...
209 enumerator.found = FALSE;
210 enumerator.data = NULL;
213 * Start the enumeration now:
215 fgEnumWindows( fghcbDisplayWindow, &enumerator );
219 * Window enumerator callback to check for the joystick polling code
221 static void fghcbCheckJoystickPolls( SFG_Window *window, SFG_Enumerator *enumerator )
223 double checkTime = fgElapsedTime();
226 * Check if actually need to do the poll for the currently enumerated window:
228 if( window->State.JoystickLastPoll + window->State.JoystickPollRate >= checkTime )
231 * Yeah, that's it. Poll the joystick...
233 fgJoystickPollWindow( window );
236 * ...and reset the polling counters:
238 window->State.JoystickLastPoll = checkTime;
242 * Process this window's children (if any)
244 fgEnumSubWindows( window, fghcbCheckJoystickPolls, enumerator );
248 * Check all windows for joystick polling
250 static void fghCheckJoystickPolls( void )
252 SFG_Enumerator enumerator;
255 * Uses a method very similiar for fgWindowByHandle...
257 enumerator.found = FALSE;
258 enumerator.data = NULL;
261 * Start the enumeration now:
263 fgEnumWindows( fghcbCheckJoystickPolls, &enumerator );
267 * Check the global timers
269 static void fghCheckTimers( void )
271 long checkTime = fgElapsedTime();
272 SFG_Timer *timer, *next;
275 fgListInit(&timedOut);
278 * For every timer that is waiting for triggering
280 for( timer = fgState.Timers.First; timer; timer = next )
282 next = timer->Node.Next;
285 * Check for the timeout:
287 if( timer->TriggerTime <= checkTime )
290 * Add the timer to the timed out timers list
292 fgListRemove( &fgState.Timers, &timer->Node );
293 fgListAppend( &timedOut, &timer->Node );
298 * Now feel free to execute all the hooked and timed out timer callbacks
299 * And delete the timed out timers...
301 while ( (timer = timedOut.First) )
303 if( timer->Callback != NULL )
304 timer->Callback( timer->ID );
305 fgListRemove( &timedOut, &timer->Node );
313 long fgElapsedTime( void )
319 gettimeofday( &now, NULL );
321 elapsed = (now.tv_usec - fgState.Time.Value.tv_usec) / 1000;
322 elapsed += (now.tv_sec - fgState.Time.Value.tv_sec) * 1000;
326 return (timeGetTime() - fgState.Time.Value);
333 void fgError( const char *fmt, ... )
339 fprintf( stderr, "freeglut: ");
340 vfprintf( stderr, fmt, ap );
341 fprintf( stderr, "\n" );
348 void fgWarning( const char *fmt, ... )
354 fprintf( stderr, "freeglut: ");
355 vfprintf( stderr, fmt, ap );
356 fprintf( stderr, "\n" );
361 /* -- INTERFACE FUNCTIONS -------------------------------------------------- */
364 * Enters the FreeGLUT processing loop. Never returns.
366 void FGAPIENTRY glutMainLoop( void )
368 #if TARGET_HOST_UNIX_X11
374 * This code was repeated constantly, so here it goes into a definition:
376 # define GETWINDOW(a) window = fgWindowByHandle( event.a.window );if( window == NULL ) break;
377 # define GETMOUSE(a) window->State.MouseX = event.a.x; window->State.MouseY = event.a.y;
380 * Make sure the display has been created etc.
382 freeglut_assert_ready;
385 * Enter the loop. Iterate as long as there are
386 * any windows in the freeglut structure.
388 while( fgStructure.Windows.First != NULL )
391 * Do we have any event messages pending?
393 if( XPending( fgDisplay.Display ) )
396 * Grab the next event to be processed...
398 XNextEvent( fgDisplay.Display, &event );
401 * Check the event's type
407 * The window creation confirmation
413 * This is sent to confirm the XDestroyWindow call. Ignore it.
419 * Destroy the window when the WM_DELETE_WINDOW message arrives
421 if( (Atom) event.xclient.data.l[ 0 ] == fgDisplay.DeleteWindow )
424 * I wonder if the window still exists ;-)
426 fgDestroyWindow( fgWindowByHandle( event.xclient.window ), TRUE );
432 * A window of ours has been unmapped...
438 * We are too dumb to process partial exposes...
440 if( event.xexpose.count == 0 )
441 fghRedrawWindowByHandle( event.xexpose.window );
444 case ConfigureNotify:
446 * The window gets resized
448 fghReshapeWindowByHandle(
449 event.xconfigure.window,
450 event.xconfigure.width,
451 event.xconfigure.height
457 * Have the client's keyboard knowledge updated (xlib.ps,
458 * page 206, says that's a good thing to do)
460 XRefreshKeyboardMapping( (XMappingEvent *) &event );
463 case VisibilityNotify:
466 * The window's visiblity might have changed
468 GETWINDOW( xvisibility );
471 * Break now if no window status callback has been hooked to that window
473 if( window->Callbacks.WindowStatus == NULL )
477 * We're going to send a callback to a window. Make it current.
479 glutSetWindow( window->ID );
482 * Sending this event, the X server can notify us that the window has just
483 * acquired one of the three possible visibility states: VisibilityUnobscured,
484 * VisibilityPartiallyObscured or VisibilityFullyObscured
486 switch( event.xvisibility.state )
488 case VisibilityUnobscured:
490 * We are fully visible...
492 window->Callbacks.WindowStatus( GLUT_FULLY_RETAINED );
493 window->State.Visible = TRUE;
496 case VisibilityPartiallyObscured:
498 * The window is partially visible
500 window->Callbacks.WindowStatus( GLUT_PARTIALLY_RETAINED );
501 window->State.Visible = TRUE;
504 case VisibilityFullyObscured:
506 * The window is totally obscured
508 window->Callbacks.WindowStatus( GLUT_FULLY_COVERED );
509 window->State.Visible = FALSE;
518 * Mouse is over one of our windows
520 GETWINDOW( xcrossing ); GETMOUSE( xcrossing );
523 * Is there an entry callback hooked to the window?
525 if( window->Callbacks.Entry != NULL )
528 * Yeah. Notify the window about having the mouse cursor over
530 window->Callbacks.Entry( GLUT_ENTERED );
538 * Mouse is no longer over one of our windows
540 GETWINDOW( xcrossing ); GETMOUSE( xcrossing );
543 * Is there an entry callback hooked to the window?
545 if( window->Callbacks.Entry != NULL )
548 * Yeah. Notify the window about having the mouse cursor over
550 window->Callbacks.Entry( GLUT_LEFT );
558 * The mouse cursor was moved...
560 GETWINDOW( xmotion ); GETMOUSE( xmotion );
563 * What kind of a movement was it?
565 if( (event.xmotion.state & Button1Mask) || (event.xmotion.state & Button2Mask) ||
566 (event.xmotion.state & Button3Mask) || (event.xmotion.state & Button4Mask) ||
567 (event.xmotion.state & Button5Mask) )
570 * A mouse button was pressed during the movement...
571 * Is there a motion callback hooked to the window?
573 if( window->Callbacks.Motion != NULL )
576 * Yup. Have it executed immediately
578 window->Callbacks.Motion( event.xmotion.x, event.xmotion.y );
584 * Otherwise it was a passive movement...
586 if( window->Callbacks.Passive != NULL )
589 * That's right, and there is a passive callback, too.
591 window->Callbacks.Passive( event.xmotion.x, event.xmotion.y );
603 * A mouse button has been pressed or released. Traditionally,
604 * break if the window was found within the freeglut structures.
606 GETWINDOW( xbutton ); GETMOUSE( xbutton );
609 * GLUT API assumes that you can't have more than three mouse buttons, so:
611 switch( event.xbutton.button )
614 * WARNING: this might be wrong, if we only have two mouse buttons,
615 * Button2 might mean the right button, isn't that right?
617 case Button1: button = GLUT_LEFT_BUTTON; break;
618 case Button2: button = GLUT_MIDDLE_BUTTON; break;
619 case Button3: button = GLUT_RIGHT_BUTTON; break;
620 default: button = -1; break;
624 * Skip the unwanted mouse buttons...
630 * Do not execute the callback if a menu is hooked to this key.
631 * In that case an appropriate private call should be generated
633 if( window->Menu[ button ] != NULL )
636 * Set the current window
638 glutSetWindow( window->ID );
640 if( event.type == ButtonPress )
643 * Activate the appropriate menu structure...
645 fgActivateMenu( button );
650 * There are two general cases generated when a menu button
651 * is released -- it can provoke a menu call (when released
652 * over a menu area) or just deactivate the menu (when released
653 * somewhere else). Unfortunately, both cases must be checked
654 * recursively due to the submenu possibilities.
656 fgDeactivateMenu( button );
662 * Check if there is a mouse callback hooked to the window
664 if( window->Callbacks.Mouse == NULL )
668 * Set the current window
670 glutSetWindow( window->ID );
673 * Remember the current modifiers state
676 if (event.xbutton.state & (ShiftMask|LockMask))
677 modifiers |= GLUT_ACTIVE_SHIFT;
678 if (event.xbutton.state & ControlMask)
679 modifiers |= GLUT_ACTIVE_CTRL;
680 if (event.xbutton.state & Mod1Mask)
681 modifiers |= GLUT_ACTIVE_ALT;
682 window->State.Modifiers = modifiers;
685 * Finally execute the mouse callback
687 window->Callbacks.Mouse(
689 event.type == ButtonPress ? GLUT_DOWN : GLUT_UP,
695 * Trash the modifiers state
697 window->State.Modifiers = 0xffffffff;
704 * A key has been pressed, find the window that had the focus:
706 GETWINDOW( xkey ); GETMOUSE( xkey );
709 * Is there a keyboard/special callback hooked for this window?
711 if( (window->Callbacks.Keyboard != NULL) || (window->Callbacks.Special != NULL) )
713 XComposeStatus composeStatus;
714 char asciiCode[ 32 ];
719 * Check for the ASCII/KeySym codes associated with the event:
721 len = XLookupString( &event.xkey, asciiCode, sizeof(asciiCode), &keySym, &composeStatus );
724 * Get ready to calling the keyboard/special callbacks
726 glutSetWindow( window->ID );
729 * GLUT API tells us to have two separate callbacks...
734 * ...one for the ASCII translateable keypresses...
736 if( window->Callbacks.Keyboard != NULL )
739 * Remember the current modifiers state
742 if (event.xkey.state & (ShiftMask|LockMask))
743 modifiers |= GLUT_ACTIVE_SHIFT;
744 if (event.xkey.state & ControlMask)
745 modifiers |= GLUT_ACTIVE_CTRL;
746 if (event.xkey.state & Mod1Mask)
747 modifiers |= GLUT_ACTIVE_ALT;
748 window->State.Modifiers = modifiers;
751 * Execute the callback
753 window->Callbacks.Keyboard( asciiCode[ 0 ], event.xkey.x, event.xkey.y );
756 * Trash the modifiers state
758 window->State.Modifiers = 0xffffffff;
766 * ...and one for all the others, which need to be translated to GLUT_KEY_Xs...
771 * First the function keys come:
773 case XK_F1: special = GLUT_KEY_F1; break;
774 case XK_F2: special = GLUT_KEY_F2; break;
775 case XK_F3: special = GLUT_KEY_F3; break;
776 case XK_F4: special = GLUT_KEY_F4; break;
777 case XK_F5: special = GLUT_KEY_F5; break;
778 case XK_F6: special = GLUT_KEY_F6; break;
779 case XK_F7: special = GLUT_KEY_F7; break;
780 case XK_F8: special = GLUT_KEY_F8; break;
781 case XK_F9: special = GLUT_KEY_F9; break;
782 case XK_F10: special = GLUT_KEY_F10; break;
783 case XK_F11: special = GLUT_KEY_F11; break;
784 case XK_F12: special = GLUT_KEY_F12; break;
787 * Then the arrows and stuff:
789 case XK_Left: special = GLUT_KEY_LEFT; break;
790 case XK_Right: special = GLUT_KEY_RIGHT; break;
791 case XK_Up: special = GLUT_KEY_UP; break;
792 case XK_Down: special = GLUT_KEY_DOWN; break;
796 * Execute the callback (if one has been specified),
797 * given that the special code seems to be valid...
799 if( (window->Callbacks.Special != NULL) && (special != -1) )
802 * Remember the current modifiers state
805 if (event.xkey.state & (ShiftMask|LockMask))
806 modifiers |= GLUT_ACTIVE_SHIFT;
807 if (event.xkey.state & ControlMask)
808 modifiers |= GLUT_ACTIVE_CTRL;
809 if (event.xkey.state & Mod1Mask)
810 modifiers |= GLUT_ACTIVE_ALT;
811 window->State.Modifiers = modifiers;
813 window->Callbacks.Special( special, event.xkey.x, event.xkey.y );
816 * Trash the modifiers state
818 window->State.Modifiers = 0xffffffff;
829 * Have all the timers checked.
834 * Poll the joystick and notify all windows that want to be notified...
836 fghCheckJoystickPolls();
839 * No messages in the queue, which means we are idling...
841 if( fgState.IdleCallback != NULL )
842 fgState.IdleCallback();
845 * Remember about displaying all the windows that have
846 * been marked for a redisplay (possibly in the idle call):
852 #elif TARGET_HOST_WIN32
854 GLboolean bLoop = TRUE;
858 * The windows main loop is considerably smaller
862 if( PeekMessage( &stMsg, NULL, 0, 0, PM_NOREMOVE ) )
865 * Grab the message now, checking for WM_QUIT
867 if( GetMessage( &stMsg, NULL, 0, 0 ) == 0 )
871 * Translate virtual-key messages and send them to the window...
873 TranslateMessage( &stMsg );
874 DispatchMessage( &stMsg );
879 * Have all the timers checked.
884 * Poll the joystick and notify all windows that want to be notified...
886 fghCheckJoystickPolls();
889 * No messages in the queue, which means we are idling...
891 if( fgState.IdleCallback != NULL )
892 fgState.IdleCallback();
895 * Remember about displaying all the windows that have
896 * been marked for a redisplay (possibly in the idle call):
901 * We need to terminate the main loop if no windows are left
903 bLoop = (g_list_length( fgStructure.Windows ) != 0);
910 * When this loop terminates, destroy the display, state and structure
911 * of a freeglut session, so that another glutInit() call can happen
917 * The window procedure for handling Win32 events
919 #if TARGET_HOST_WIN32
920 LRESULT CALLBACK fgWindowProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam )
922 SFG_Window* window = fgWindowByHandle( hWnd );
926 # define assert_window_registered if( window == NULL ) return( DefWindowProc( hWnd, uMsg, wParam, lParam ) );
929 * Check what type of message are we receiving
935 * The window structure is passed as the creation structure paramter...
937 window = (SFG_Window *) (((LPCREATESTRUCT) lParam)->lpCreateParams);
938 assert( window != NULL );
941 * We can safely store the window's handle now:
943 window->Window.Handle = hWnd;
946 * Get the window's device context
948 window->Window.Device = GetDC( hWnd );
951 * Setup the pixel format of our window
953 fgSetupPixelFormat( window, FALSE );
956 * Create the OpenGL rendering context now
958 window->Window.Context = wglCreateContext( window->Window.Device );
961 * Still, we'll be needing to explicitly resize the window
963 window->State.NeedToResize = TRUE;
966 * Finally, have the window's device context released
968 ReleaseDC( window->Window.Handle, window->Window.Device );
973 * We got resized... But check if the window has been already added...
975 fghReshapeWindowByHandle( hWnd, LOWORD(lParam), HIWORD(lParam) );
980 * Start the painting job
982 BeginPaint( hWnd, &ps );
985 * Call the engine's main frame drawing method
987 fghRedrawWindowByHandle( hWnd );
990 * End the painting job, release the device context
992 EndPaint( hWnd, &ps );
997 * Make sure we don't close a window with current context active
999 if( fgStructure.Window == window )
1001 wglMakeCurrent( NULL, NULL );
1002 wglDeleteContext( window->Window.Context );
1006 * Proceed with the window destruction
1008 DestroyWindow( window->Window.Handle );
1013 * The window already got destroyed, so forget about it's existence:
1015 fgDestroyWindow( window, FALSE );
1020 assert_window_registered;
1023 * The mouse cursor has moved. Remember the new mouse cursor's position
1025 window->State.MouseX = LOWORD( lParam );
1026 window->State.MouseY = HIWORD( lParam );
1029 * Fallback if there's an active menu hooked to this window
1031 if( window->MenuActive[ 0 ] || window->MenuActive[ 1 ] || window->MenuActive[ 2 ] )
1035 * Remember the current modifiers state.
1037 window->State.Modifiers =
1038 (GetKeyState( VK_LSHIFT ) || GetKeyState( VK_RSHIFT )) ? GLUT_ACTIVE_SHIFT : 0 |
1039 (GetKeyState( VK_LCONTROL ) || GetKeyState( VK_RCONTROL )) ? GLUT_ACTIVE_CTRL : 0 |
1040 (GetKeyState( VK_LMENU ) || GetKeyState( VK_RMENU )) ? GLUT_ACTIVE_ALT : 0;
1043 * Check if any of the mouse buttons is pressed...
1045 if( (wParam & MK_LBUTTON) || (wParam & MK_MBUTTON) || (wParam & MK_RBUTTON) )
1048 * Yeah, indeed. We need to use the motion callback then:
1050 if( window->Callbacks.Motion != NULL )
1053 * Make sure the current window is set...
1055 glutSetWindow( window->ID );
1058 * Execute the active mouse motion callback now
1060 window->Callbacks.Motion( window->State.MouseX, window->State.MouseY );
1066 * All mouse buttons are up, execute the passive mouse motion callback
1068 if( window->Callbacks.Passive != NULL )
1071 * Make sure the current window is set
1073 glutSetWindow( window->ID );
1076 * Execute the passive mouse motion callback
1078 window->Callbacks.Passive( window->State.MouseX, window->State.MouseY );
1083 * Thrash the current modifiers state now
1085 window->State.Modifiers = 0xffffffff;
1089 case WM_LBUTTONDOWN:
1090 case WM_MBUTTONDOWN:
1091 case WM_RBUTTONDOWN:
1096 GLboolean pressed = TRUE;
1100 * A mouse button has been pressed *or* released. Again, break off
1101 * if the message was not directed towards a freeglut window...
1103 assert_window_registered;
1106 * The mouse cursor has moved. Remember the new mouse cursor's position
1108 window->State.MouseX = LOWORD( lParam );
1109 window->State.MouseY = HIWORD( lParam );
1112 * We're curious about the GLUT API button name...
1116 case WM_LBUTTONDOWN: pressed = TRUE; button = GLUT_LEFT_BUTTON; break;
1117 case WM_MBUTTONDOWN: pressed = TRUE; button = GLUT_MIDDLE_BUTTON; break;
1118 case WM_RBUTTONDOWN: pressed = TRUE; button = GLUT_RIGHT_BUTTON; break;
1119 case WM_LBUTTONUP: pressed = FALSE; button = GLUT_LEFT_BUTTON; break;
1120 case WM_MBUTTONUP: pressed = FALSE; button = GLUT_MIDDLE_BUTTON; break;
1121 case WM_RBUTTONUP: pressed = FALSE; button = GLUT_RIGHT_BUTTON; break;
1122 default: pressed = FALSE; button = -1; break;
1126 * The left and right mouse buttons might have been swapped...
1128 if( GetSystemMetrics( SM_SWAPBUTTON ) )
1129 if( button == GLUT_LEFT_BUTTON ) button = GLUT_RIGHT_BUTTON;
1130 else if( button == GLUT_RIGHT_BUTTON ) button = GLUT_LEFT_BUTTON;
1133 * Hey, what's up with you?
1136 return( DefWindowProc( hWnd, uMsg, lParam, wParam ) );
1139 * Do not execute the callback if a menu is hooked to this key.
1140 * In that case an appropriate private call should be generated
1142 if( window->Menu[ button ] != NULL )
1145 * Set the current window
1147 glutSetWindow( window->ID );
1149 if( pressed == TRUE )
1152 * Activate the appropriate menu structure...
1154 fgActivateMenu( button );
1159 * There are two general cases generated when a menu button
1160 * is released -- it can provoke a menu call (when released
1161 * over a menu area) or just deactivate the menu (when released
1162 * somewhere else). Unfortunately, both cases must be checked
1163 * recursively due to the submenu possibilities.
1165 fgDeactivateMenu( button );
1171 * Check if there is a mouse callback hooked to the window
1173 if( window->Callbacks.Mouse == NULL )
1177 * Set the current window
1179 glutSetWindow( window->ID );
1182 * Remember the current modifiers state.
1184 window->State.Modifiers =
1185 (GetKeyState( VK_LSHIFT ) || GetKeyState( VK_RSHIFT )) ? GLUT_ACTIVE_SHIFT : 0 |
1186 (GetKeyState( VK_LCONTROL ) || GetKeyState( VK_RCONTROL )) ? GLUT_ACTIVE_CTRL : 0 |
1187 (GetKeyState( VK_LMENU ) || GetKeyState( VK_RMENU )) ? GLUT_ACTIVE_ALT : 0;
1190 * Finally execute the mouse callback
1192 window->Callbacks.Mouse(
1194 pressed == TRUE ? GLUT_DOWN : GLUT_UP,
1195 window->State.MouseX,
1196 window->State.MouseY
1200 * Trash the modifiers state
1202 window->State.Modifiers = 0xffffffff;
1212 * First of all, make sure that there is a window to be notified of this
1214 assert_window_registered;
1217 * Ignore the automatic key repetition if needed:
1219 if( fgState.IgnoreKeyRepeat && (lParam & KF_REPEAT) )
1223 * Remember the current modifiers state. This is done here in order
1224 * to make sure the VK_DELETE keyboard callback is executed properly.
1226 window->State.Modifiers =
1227 (GetKeyState( VK_LSHIFT ) || GetKeyState( VK_RSHIFT )) ? GLUT_ACTIVE_SHIFT : 0 |
1228 (GetKeyState( VK_LCONTROL ) || GetKeyState( VK_RCONTROL )) ? GLUT_ACTIVE_CTRL : 0 |
1229 (GetKeyState( VK_LMENU ) || GetKeyState( VK_RMENU )) ? GLUT_ACTIVE_ALT : 0;
1232 * Convert the Win32 keystroke codes to GLUTtish way
1234 # define KEY(a,b) case a: keypress = b; break;
1239 * Most of the special characters can be handled automagically...
1241 KEY( VK_F1, GLUT_KEY_F1 ); KEY( VK_F2, GLUT_KEY_F2 );
1242 KEY( VK_F3, GLUT_KEY_F3 ); KEY( VK_F4, GLUT_KEY_F4 );
1243 KEY( VK_F5, GLUT_KEY_F5 ); KEY( VK_F6, GLUT_KEY_F6 );
1244 KEY( VK_F7, GLUT_KEY_F7 ); KEY( VK_F8, GLUT_KEY_F8 );
1245 KEY( VK_F9, GLUT_KEY_F9 ); KEY( VK_F10, GLUT_KEY_F10 );
1246 KEY( VK_F11, GLUT_KEY_F11 ); KEY( VK_F12, GLUT_KEY_F12 );
1247 KEY( VK_PRIOR, GLUT_KEY_PAGE_UP ); KEY( VK_NEXT, GLUT_KEY_PAGE_DOWN );
1248 KEY( VK_HOME, GLUT_KEY_HOME ); KEY( VK_END, GLUT_KEY_END );
1249 KEY( VK_LEFT, GLUT_KEY_LEFT ); KEY( VK_UP, GLUT_KEY_UP );
1250 KEY( VK_RIGHT, GLUT_KEY_RIGHT ); KEY( VK_DOWN, GLUT_KEY_DOWN );
1251 KEY( VK_INSERT, GLUT_KEY_INSERT );
1254 * ...yet there is a small exception we need to have handled...
1258 * The delete key should be treated as an ASCII keypress:
1260 if( window->Callbacks.Keyboard != NULL )
1261 window->Callbacks.Keyboard( 127, window->State.MouseX, window->State.MouseY );
1265 * Execute the special callback, if present, given the conversion was a success:
1267 if( (keypress != -1) && (window->Callbacks.Special != NULL) )
1270 * Have the special callback executed:
1272 window->Callbacks.Special( keypress, window->State.MouseX, window->State.MouseY );
1276 * Thrash the modifiers register now
1278 window->State.Modifiers = 0xffffffff;
1286 * First of all, make sure that there is a window to be notified of this
1288 assert_window_registered;
1291 * Ignore the automatic key repetition if needed:
1293 if( fgState.IgnoreKeyRepeat && (lParam & KF_REPEAT) )
1297 * Clear to go with the keyboard callback, if registered:
1299 if( window->Callbacks.Keyboard != NULL )
1302 * Remember the current modifiers state
1304 window->State.Modifiers =
1305 (GetKeyState( VK_LSHIFT ) || GetKeyState( VK_RSHIFT )) ? GLUT_ACTIVE_SHIFT : 0 |
1306 (GetKeyState( VK_LCONTROL ) || GetKeyState( VK_RCONTROL )) ? GLUT_ACTIVE_CTRL : 0 |
1307 (GetKeyState( VK_LMENU ) || GetKeyState( VK_RMENU )) ? GLUT_ACTIVE_ALT : 0;
1310 * Have the special callback executed:
1312 window->Callbacks.Keyboard( wParam, window->State.MouseX, window->State.MouseY );
1315 * Thrash the modifiers register now
1317 window->State.Modifiers = 0xffffffff;
1324 * Handle unhandled messages
1326 lRet = DefWindowProc( hWnd, uMsg, wParam, lParam );
1334 /*** END OF FILE ***/