- case ButtonRelease:
- case ButtonPress:
- {
- GLboolean pressed = TRUE ;
- int button;
-
- if ( event.type == ButtonRelease ) pressed = FALSE ;
-
- /*
- * 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 ;
- SFG_Window *parent_window = window->ActiveMenu->ParentWindow ;
- fgSetWindow ( window ) ;
- fgStructure.Menu = window->ActiveMenu ;
-
- /* Execute the menu callback */
- fgExecuteMenuCallback ( window->ActiveMenu ) ;
- fgDeactivateMenu ( parent_window ) ;
-
- /* 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 ) ;
- }
-
- /*
- * Let's make the window redraw as a result of the mouse click and menu activity.
- */
- window->State.Redisplay = TRUE ;
-
- break ;
- }
-
- /*
- * No active menu, let's check whether we need to activate one.
- */
- if ( ( window->Menu[ button ] != NULL ) && ( pressed == TRUE ) )
- {
- /*
- * Let's make the window redraw as a result of the mouse click.
- */
- window->State.Redisplay = 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( 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 );
+ /*
+ * Finally execute the mouse or mouse wheel callback
+ *
+ * XXX Use a symbolic constant, *not* "4"!
+ */
+ if( ( button < 3 ) || ( ! FETCH_WCB( *window, MouseWheel ) ) )
+ INVOKE_WCB( *window, Mouse, ( button,
+ pressed ? GLUT_DOWN : GLUT_UP,
+ event.xbutton.x,
+ event.xbutton.y )
+ );
+ else
+ {
+ /*
+ * Map 4 and 5 to wheel zero; EVEN to +1, ODD to -1
+ * " 6 and 7 " " one; ...
+ *
+ * XXX This *should* be behind some variables/macros,
+ * XXX since the order and numbering isn't certain
+ * XXX See XFree86 configuration docs (even back in the
+ * XXX 3.x days, and especially with 4.x).
+ *
+ * XXX Note that {button} has already been decremeted
+ * XXX in mapping from X button numbering to GLUT.
+ */
+ int wheel_number = ( button - 3 ) / 2;
+ int direction = -1;
+ if( button % 2 )
+ direction = 1;
+
+ if( pressed )
+ INVOKE_WCB( *window, MouseWheel, ( wheel_number,
+ direction,
+ event.xbutton.x,
+ event.xbutton.y )
+ );
+ }