- /*
- * A mouse button has been pressed or released. Traditionally,
- * break if the window was found within the freeglut structures.
- */
- GETWINDOW( xbutton ); GETMOUSE( xbutton );
-
- /*
- * GLUT API assumes that you can't have more than three mouse buttons, so:
- */
- switch( event.xbutton.button )
- {
- /*
- * WARNING: this might be wrong, if we only have two mouse buttons,
- * Button2 might mean the right button, isn't that right?
- */
- case Button1: button = GLUT_LEFT_BUTTON; break;
- case Button2: button = GLUT_MIDDLE_BUTTON; break;
- case Button3: button = GLUT_RIGHT_BUTTON; break;
- default: button = -1; break;
- }
-
- /*
- * Skip the unwanted mouse buttons...
- */
- if( button == -1 )
- break;
-
- /*
- * Do not execute the application's mouse callback if a menu is hooked to this button.
- * In that case an appropriate private call should be generated.
- * Near as I can tell, this is the menu behaviour:
- * - Down-click the menu button, menu not active: activate the menu with its upper left-hand corner at the mouse location.
- * - Down-click any button outside the menu, menu active: deactivate the menu
- * - Down-click any button inside the menu, menu active: select the menu entry and deactivate the menu
- * - Up-click the menu button, menu not active: nothing happens
- * - Up-click the menu button outside the menu, menu active: nothing happens
- * - Up-click the menu button inside the menu, menu active: select the menu entry and deactivate the menu
- */
- if ( window->ActiveMenu != NULL ) /* Window has an active menu, it absorbs any mouse click */
- {
- if ( fgCheckActiveMenu ( window, window->ActiveMenu ) == TRUE ) /* Inside the menu, invoke the callback and deactivate the menu*/
- {
- /* Save the current window and menu and set the current window to the window whose menu this is */
- SFG_Window *save_window = fgStructure.Window ;
- SFG_Menu *save_menu = fgStructure.Menu ;
- fgSetWindow ( window ) ;
- fgStructure.Menu = window->ActiveMenu ;
-
- /* Execute the menu callback */
- fgExecuteMenuCallback ( window->ActiveMenu ) ;
- fgDeactivateMenu ( window->ActiveMenu->ParentWindow ) ;
-
- /* Restore the current window and menu */
- fgSetWindow ( save_window ) ;
- fgStructure.Menu = save_menu ;
- }
- else /* Outside the menu, deactivate the menu if it's a downclick */
- {
- if ( pressed == TRUE ) fgDeactivateMenu ( window->ActiveMenu->ParentWindow ) ;
- }
-
- break ;
- }
-
- /*
- * No active menu, let's check whether we need to activate one.
- */
- if ( ( window->Menu[ button ] != NULL ) && ( pressed == TRUE ) )
- {
- /*
- * Set the current window
- */
- fgSetWindow( window );
-
- /*
- * Activate the appropriate menu structure...
- */
- fgActivateMenu( window, button );
-
- break;
- }
-
- /*
- * Check if there is a mouse callback hooked to the window
- */
- if( fgStructure.Window->Callbacks.Mouse == NULL )
- break;
-
- /*
- * Set the current window
- */
- fgSetWindow( window );
-
- /*
- * Remember the current modifiers state
- */
- modifiers = 0;
- if (event.xbutton.state & (ShiftMask|LockMask))
- modifiers |= GLUT_ACTIVE_SHIFT;
- if (event.xbutton.state & ControlMask)
- modifiers |= GLUT_ACTIVE_CTRL;
- if (event.xbutton.state & Mod1Mask)
- modifiers |= GLUT_ACTIVE_ALT;
- fgStructure.Window->State.Modifiers = modifiers;
-
- /*
- * Finally execute the mouse callback
- */
- fgStructure.Window->Callbacks.Mouse(
- button,
- event.type == ButtonPress ? GLUT_DOWN : GLUT_UP,
- event.xbutton.x,
- event.xbutton.y
- );
-
- /*
- * Trash the modifiers state
- */
- fgStructure.Window->State.Modifiers = 0xffffffff;
- }
- break;
-
- case KeyRelease:
- case KeyPress:
- {
- FGCBkeyboard keyboard_cb;
- FGCBspecial special_cb;
-
- /*
- * A key has been pressed, find the window that had the focus:
- */
- GETWINDOW( xkey ); GETMOUSE( xkey );
-
- if( event.type == KeyPress )
- {
- keyboard_cb = window->Callbacks.Keyboard;
- special_cb = window->Callbacks.Special;
- }
- else
- {
- keyboard_cb = window->Callbacks.KeyboardUp;
- special_cb = window->Callbacks.SpecialUp;