/* * Check whether an active menu absorbs a mouse click */ GLboolean fgCheckActiveMenu ( SFG_Window *window, int button, GLboolean pressed, int mouse_x, int mouse_y ) { /* * 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 * Since menus can have submenus, we need to check this recursively. */ if( window->ActiveMenu ) { if( window == window->ActiveMenu->ParentWindow ) { window->ActiveMenu->Window->State.MouseX = mouse_x - window->ActiveMenu->X; window->ActiveMenu->Window->State.MouseY = mouse_y - window->ActiveMenu->Y; } /* In the menu, invoke the callback and deactivate the menu */ if( fghCheckMenuStatus( window->ActiveMenu ) ) { /* * Save the current window and menu and set the current * window to the window whose menu this is */ SFG_Window *save_window = fgStructure.CurrentWindow; SFG_Menu *save_menu = fgStructure.CurrentMenu; SFG_Window *parent_window = window->ActiveMenu->ParentWindow; fgSetWindow( parent_window ); fgStructure.CurrentMenu = window->ActiveMenu; /* Execute the menu callback */ fghExecuteMenuCallback( window->ActiveMenu ); fgDeactivateMenu( parent_window ); /* Restore the current window and menu */ fgSetWindow( save_window ); fgStructure.CurrentMenu = save_menu; } else if( pressed ) /* * Outside the menu, deactivate if it's a downclick * * A downclick outside of the interior of our freeglut windows * is dealt with in the WM_KILLFOCUS handler of fgPlatformWindowProc */ fgDeactivateMenu( window->ActiveMenu->ParentWindow ); /* * XXX Why does an active menu require a redisplay at * XXX this point? If this can come out cleanly, then * XXX it probably should do so; if not, a comment should * XXX explain it. */ if( ! window->IsMenu ) window->State.Redisplay = GL_TRUE; return GL_TRUE; } /* No active menu, let's check whether we need to activate one. */ if( ( 0 <= button ) && ( FREEGLUT_MAX_MENUS > button ) && ( window->Menu[ button ] ) && pressed ) { /* XXX Posting a requisite Redisplay seems bogus. */ window->State.Redisplay = GL_TRUE; fghActivateMenu( window, button ); return GL_TRUE; } return GL_FALSE; }
/* * Check whether an active menu absorbs a mouse click */ GLboolean fgCheckActiveMenu ( SFG_Window *window, int button, GLboolean pressed, int mouse_x, int mouse_y ) { GLboolean is_handled = GL_FALSE; GLboolean is_clicked = GL_FALSE; /* * 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, and potentially activate a new menu * at the new mouse location. This includes clicks in * different windows of course * - 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 * Since menus can have submenus, we need to check this recursively. */ if( window->ActiveMenu ) { if( window == window->ActiveMenu->ParentWindow ) { window->ActiveMenu->Window->State.MouseX = mouse_x - window->ActiveMenu->X; window->ActiveMenu->Window->State.MouseY = mouse_y - window->ActiveMenu->Y; } /* In the menu, deactivate the menu and invoke the callback */ if( fghCheckMenuStatus( window->ActiveMenu ) ) { /* * Save the current window and menu and set the current * window to the window whose menu this is */ SFG_Window *save_window = fgStructure.CurrentWindow; SFG_Menu *save_menu = fgStructure.CurrentMenu, *active_menu = window->ActiveMenu; /* active menu is always the one with the mouse in it, due to fghCheckMenuStatus */ SFG_MenuEntry *active_entry = active_menu->ActiveEntry; /* currently highlighted item -> must be the one that was just clicked */ SFG_Window *parent_window = window->ActiveMenu->ParentWindow; /* ignore clicks on the submenu entry */ if (!active_entry->SubMenu) { fgSetWindow( parent_window ); fgStructure.CurrentMenu = active_menu; /* Deactivate menu and then call callback (we don't want menu to stay in view while callback is executing, and user should be able to change menus in callback) */ fgDeactivateMenu( parent_window ); active_menu->Callback( active_entry->ID ); /* Restore the current window and menu */ fgSetWindow( save_window ); fgStructure.CurrentMenu = save_menu; } is_clicked = GL_TRUE; /* Don't reopen... */ } else if( pressed ) /* * Outside the menu, deactivate if it's a downclick * * A downclick outside of the interior of our freeglut windows * is dealt with in the WM_KILLFOCUS handler of fgPlatformWindowProc */ { fgDeactivateMenu( window->ActiveMenu->ParentWindow ); /* Could reopen again in different location, as is_clicked remains false */ } is_handled = GL_TRUE; } else if ( fgState.ActiveMenus ) /* Don't have to check whether this was a downpress or an uppress, there is no way to get an uppress in another window before a downpress... */ { /* if another window than the one clicked in has an open menu, close it */ SFG_Menu *menu = fgGetActiveMenu(); if ( menu ) /* any open menu? */ fgDeactivateMenu( menu->ParentWindow ); /* Leave is_handled to false, we didn't do anything relevant from the perspective of the window that was clicked */ } /* No active menu, let's check whether we need to activate one. */ if( !is_clicked && ( 0 <= button ) && ( FREEGLUT_MAX_MENUS > button ) && ( window->Menu[ button ] ) && pressed ) { /* If mouseclick was outside the parent window, ignore. This can * happen when another mouse button is already depressed and the * window thus has mouse capture */ if (window->State.MouseX>0 && window->State.MouseY>0 && window->State.MouseX<window->State.Width && window->State.MouseY<window->State.Height) { fghActivateMenu( window, button ); is_handled = GL_TRUE; } } return is_handled; }