- /* 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 ( parent_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 (( 0 <= button ) && ( 2 >= button ) &&
- ( 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 or mouse wheel callback hooked to the
- * window
- */
- if ( ( window->Callbacks.Mouse == NULL ) &&
- ( window->Callbacks.MouseWheel == NULL ) )
- break;
-
- fgSetWindow ( window );
-
- 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 or mouse wheel callback
- *
- * XXX Use a symbolic constant, *not* "4"!
- */
- if ( button < 4 )
- {
- fgStructure.Window->Callbacks.Mouse(
- button,
- event.type == ButtonPress ? GLUT_DOWN : GLUT_UP,
- event.xbutton.x,
- event.xbutton.y
- );
- }
- else
- {
- if ( window->Callbacks.MouseWheel )
- {
- /*
- * 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).
- */
- int wheel_number = (button - 4) / 2;
- int direction = (button & 1)*2 - 1;
-
- if( ButtonPress )
- fgStructure.Window->Callbacks.MouseWheel(
- wheel_number,
- direction,
- event.xbutton.x,
- event.xbutton.y
- );
- }
- else
- {
- 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;
- }
-
- /*
- * Is there a keyboard/special callback hooked for this window?
- */
- if( (keyboard_cb != NULL) || (special_cb != NULL) )
- {
- XComposeStatus composeStatus;
- char asciiCode[ 32 ];
- KeySym keySym;
- int len;
-
- /*
- * Check for the ASCII/KeySym codes associated with the event:
- */
- len = XLookupString( &event.xkey, asciiCode, sizeof(asciiCode), &keySym, &composeStatus );
-
- /*
- * GLUT API tells us to have two separate callbacks...
- */
- if( len > 0 )
- {
- /*
- * ...one for the ASCII translateable keypresses...
- */
- if( keyboard_cb != NULL )
- {
- /*
- * Set the current window
- */
- fgSetWindow( window );
-
- /*
- * Remember the current modifiers state
- */
- modifiers = 0;
- if (event.xkey.state & (ShiftMask|LockMask))
- modifiers |= GLUT_ACTIVE_SHIFT;
- if (event.xkey.state & ControlMask)
- modifiers |= GLUT_ACTIVE_CTRL;
- if (event.xkey.state & Mod1Mask)
- modifiers |= GLUT_ACTIVE_ALT;
- window->State.Modifiers = modifiers;
-
- /*
- * Execute the callback
- */
- keyboard_cb( asciiCode[ 0 ], event.xkey.x, event.xkey.y );
-
- /*
- * Trash the modifiers state
- */
- window->State.Modifiers = 0xffffffff;