Fix several menu glitches.

+ Fixed issue #10 (Alt+sequence of underlined letters is working now).
+ Close the whole menu hierarchy when Alt key is released and then
  pressed again.
+ Close all menus when a command is executed.
This commit is contained in:
David Capello 2011-04-30 15:26:04 -03:00
parent 305a824d72
commit 132e246ebf
3 changed files with 31 additions and 9 deletions

View File

@ -474,9 +474,10 @@ bool MenuBox::onProcessMessage(Message* msg)
get_base(this)->was_clicked = false;
// Check for ALT+some letter in menubar and some letter in menuboxes
if (((this->type == JI_MENUBOX) && (!msg->any.shifts)) ||
((this->type == JI_MENUBAR) && (msg->any.shifts & KB_ALT_FLAG))) {
// Check for ALT+some underlined letter
if (((this->type == JI_MENUBOX) && (msg->any.shifts == 0 || // Inside menu-boxes we can use letters without Alt modifier pressed
msg->any.shifts == KB_ALT_FLAG)) ||
((this->type == JI_MENUBAR) && (msg->any.shifts == KB_ALT_FLAG))) {
selected = check_for_letter(menu, scancode_to_ascii(msg->key.scancode));
if (selected) {
menu->highlightItem(selected, true, true, true);
@ -503,17 +504,14 @@ bool MenuBox::onProcessMessage(Message* msg)
if (!highlight && child_with_submenu_opened)
highlight = child_with_submenu_opened;
switch (msg->key.scancode) {
case KEY_ESC:
/* in menu-bar */
if (this->type == JI_MENUBAR) {
if (highlight) {
menu->closeAll();
/* fetch the focus */
jmanager_free_focus();
cancelMenuLoop();
used = true;
}
}
@ -632,7 +630,14 @@ bool MenuBox::onProcessMessage(Message* msg)
break;
}
return used;
// Return true if we've already consumed the key.
if (used) {
return true;
}
// If the user presses the ALT key we close everything.
else if (msg->key.scancode == KEY_ALT) {
cancelMenuLoop();
}
}
}
break;
@ -1192,6 +1197,16 @@ void MenuBox::closePopup()
jmanager_enqueue_message(msg);
}
void MenuBox::cancelMenuLoop()
{
Menu* menu = getMenu();
if (menu)
menu->closeAll();
// Lost focus
jmanager_free_focus();
}
void MenuItem::executeClick()
{
// Send the message

View File

@ -62,6 +62,10 @@ public:
return m_base;
}
// Closes all menu-boxes and goes back to the normal state of the
// menu-bar.
void cancelMenuLoop();
protected:
virtual bool onProcessMessage(Message* msg) OVERRIDE;
MenuBaseData* createBase();

View File

@ -1134,6 +1134,9 @@ static bool manager_msg_proc(JWidget widget, Message* msg)
Shortcut* shortcut = *it;
if (shortcut->is_pressed(msg)) {
// Cancel menu-bar loops (to close any popup menu)
app_get_menubar()->cancelMenuLoop();
switch (shortcut->type) {
case Shortcut_ChangeTool: {