Small menu improvements

This commit is contained in:
Markus Gans 2015-11-25 22:10:23 +01:00
parent 692f8248e1
commit 70dd5af0fb
4 changed files with 79 additions and 64 deletions

View File

@ -1,3 +1,6 @@
2015-11-25 Markus Gans <guru.mail@muenster.de>
* Small menu improvements
2015-11-24 Markus Gans <guru.mail@muenster.de> 2015-11-24 Markus Gans <guru.mail@muenster.de>
* Improved mouse and keyboard handling in sub-menus * Improved mouse and keyboard handling in sub-menus

View File

@ -401,15 +401,10 @@ bool FMenu::selectPrevItem()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FMenu::keypressMenuBar (FKeyEvent*& ev) void FMenu::keypressMenuBar (FKeyEvent*& ev)
{ {
FWidget* super = getSuperMenu(); FMenuBar* mbar = menuBar();
if ( super )
{ if ( mbar )
if ( isMenuBar(super) ) mbar->onKeyPress(ev);
{
FMenuBar* mbar = reinterpret_cast<FMenuBar*>(super);
mbar->onKeyPress(ev);
}
}
} }
//---------------------------------------------------------------------- //----------------------------------------------------------------------
@ -437,14 +432,27 @@ bool FMenu::hotkeyMenu (FKeyEvent*& ev)
if ( found ) if ( found )
{ {
unselectItem(); if ( (*iter)->hasMenu() )
hideSubMenus(); {
hide(); FMenu* sub_menu = (*iter)->getMenu();
hideSuperMenus(); unselectItem();
updateTerminal(); (*iter)->setSelected();
flush_out(); setSelectedItem (*iter);
ev->accept(); redraw();
(*iter)->processClicked(); openSubMenu (sub_menu);
sub_menu->redraw();
}
else
{
unselectItem();
hideSubMenus();
hide();
hideSuperMenus();
updateTerminal();
flush_out();
ev->accept();
(*iter)->processClicked();
}
return true; return true;
} }
} }
@ -577,15 +585,15 @@ void FMenu::drawItems()
FString txt; FString txt;
uInt txt_length; uInt txt_length;
int hotkeypos, to_char; int hotkeypos, to_char;
int accel_key = (*iter)->accel_key; int accel_key = (*iter)->accel_key;
bool has_menu = (*iter)->hasMenu(); bool has_menu = (*iter)->hasMenu();
bool is_enabled = (*iter)->isEnabled(); bool is_enabled = (*iter)->isEnabled();
bool is_checked = (*iter)->isChecked(); bool is_checked = (*iter)->isChecked();
bool is_checkable = (*iter)->checkable; bool is_checkable = (*iter)->checkable;
bool is_radio_btn = (*iter)->radio_button; bool is_radio_btn = (*iter)->radio_button;
bool is_selected = (*iter)->isSelected(); bool is_selected = (*iter)->isSelected();
bool is_noUnderline = (((*iter)->getFlags() & NO_UNDERLINE) != 0); bool is_noUnderline = (((*iter)->getFlags() & NO_UNDERLINE) != 0);
bool is_separator = (*iter)->isSeparator(); bool is_separator = (*iter)->isSeparator();
if ( is_separator ) if ( is_separator )
{ {
@ -1180,10 +1188,11 @@ void FMenu::onMouseMove (FMouseEvent* ev)
const FPoint& g = ev->getGlobalPos(); const FPoint& g = ev->getGlobalPos();
const FPoint& p = open_sub_menu->globalToLocalPos(g); const FPoint& p = open_sub_menu->globalToLocalPos(g);
int b = ev->getButton(); int b = ev->getButton();
ev = new FMouseEvent (MouseMove_Event, p, g, b); FMouseEvent* _ev = new FMouseEvent (MouseMove_Event, p, g, b);
open_sub_menu->mouse_down = true; open_sub_menu->mouse_down = true;
setClickedWidget(open_sub_menu); setClickedWidget(open_sub_menu);
open_sub_menu->onMouseMove(ev); open_sub_menu->onMouseMove(_ev);
delete _ev;
} }
else if ( ! mouse_over_menu && mouse_over_supermenu ) else if ( ! mouse_over_menu && mouse_over_supermenu )
{ {
@ -1191,10 +1200,11 @@ void FMenu::onMouseMove (FMouseEvent* ev)
const FPoint& g = ev->getGlobalPos(); const FPoint& g = ev->getGlobalPos();
const FPoint& p = smenu->globalToLocalPos(g); const FPoint& p = smenu->globalToLocalPos(g);
int b = ev->getButton(); int b = ev->getButton();
ev = new FMouseEvent (MouseMove_Event, p, g, b); FMouseEvent* _ev = new FMouseEvent (MouseMove_Event, p, g, b);
smenu->mouse_down = true; smenu->mouse_down = true;
setClickedWidget(smenu); setClickedWidget(smenu);
smenu->onMouseMove(ev); smenu->onMouseMove(_ev);
delete _ev;
} }
else if ( mouse_over_menubar ) else if ( mouse_over_menubar )
{ {
@ -1203,12 +1213,12 @@ void FMenu::onMouseMove (FMouseEvent* ev)
const FPoint& g = ev->getGlobalPos(); const FPoint& g = ev->getGlobalPos();
const FPoint& p = menubar->globalToLocalPos(g); const FPoint& p = menubar->globalToLocalPos(g);
int b = ev->getButton(); int b = ev->getButton();
ev = new FMouseEvent (MouseMove_Event, p, g, b); FMouseEvent* _ev = new FMouseEvent (MouseMove_Event, p, g, b);
setClickedWidget(menubar); setClickedWidget(menubar);
FMenuBar* mbar = reinterpret_cast<FMenuBar*>(menubar); FMenuBar* mbar = reinterpret_cast<FMenuBar*>(menubar);
mbar->mouse_down = true; mbar->mouse_down = true;
mbar->onMouseMove(ev); mbar->onMouseMove(_ev);
delete ev; delete _ev;
} }
else if ( ! hasSelectedItem() && statusBar() && mouse_over_menu ) else if ( ! hasSelectedItem() && statusBar() && mouse_over_menu )
{ {

View File

@ -772,10 +772,11 @@ void FMenuBar::onMouseMove (FMouseEvent* ev)
const FPoint& g = ev->getGlobalPos(); const FPoint& g = ev->getGlobalPos();
const FPoint& p = menu->globalToLocalPos(g); const FPoint& p = menu->globalToLocalPos(g);
int b = ev->getButton(); int b = ev->getButton();
ev = new FMouseEvent (MouseMove_Event, p, g, b); FMouseEvent* _ev = new FMouseEvent (MouseMove_Event, p, g, b);
menu->mouse_down = true; menu->mouse_down = true;
setClickedWidget(menu); setClickedWidget(menu);
menu->onMouseMove(ev); menu->onMouseMove(_ev);
delete _ev;
} }
} }
} }

View File

@ -174,11 +174,12 @@ void FMenuItem::init (FWidget* parent)
{ {
FMenuBar* menubar_ptr = dynamic_cast<FMenuBar*>(parent); FMenuBar* menubar_ptr = dynamic_cast<FMenuBar*>(parent);
if ( menubar_ptr ) if ( menubar_ptr )
{
menubar_ptr->menu_dimension(); menubar_ptr->menu_dimension();
// Meta + hotkey if ( hotkey ) // Meta + hotkey
if ( hotkey ) menubar_ptr->addAccelerator (fc::Fmkey_meta + tolower(hotkey), this);
menubar_ptr->addAccelerator (fc::Fmkey_meta + tolower(hotkey), this); }
this->addCallback this->addCallback
( (
@ -382,9 +383,9 @@ void FMenuItem::onMouseDown (FMouseEvent* ev)
if ( smenu ) if ( smenu )
{ {
const FPoint& p2 = smenu->globalToLocalPos(g); const FPoint& p2 = smenu->globalToLocalPos(g);
ev = new FMouseEvent (MouseMove_Event, p2, g, b); FMouseEvent* _ev = new FMouseEvent (MouseDown_Event, p2, g, b);
smenu->onMouseDown(ev); smenu->onMouseDown(_ev);
delete ev; delete _ev;
} }
} }
@ -394,9 +395,9 @@ void FMenuItem::onMouseDown (FMouseEvent* ev)
if ( mbar ) if ( mbar )
{ {
const FPoint& p2 = mbar->globalToLocalPos(g); const FPoint& p2 = mbar->globalToLocalPos(g);
ev = new FMouseEvent (MouseMove_Event, p2, g, b); FMouseEvent* _ev = new FMouseEvent (MouseDown_Event, p2, g, b);
mbar->onMouseDown(ev); mbar->onMouseDown(_ev);
delete ev; delete _ev;
} }
} }
} }
@ -416,9 +417,9 @@ void FMenuItem::onMouseUp (FMouseEvent* ev)
if ( smenu ) if ( smenu )
{ {
const FPoint& p2 = smenu->globalToLocalPos(g); const FPoint& p2 = smenu->globalToLocalPos(g);
ev = new FMouseEvent (MouseMove_Event, p2, g, b); FMouseEvent* _ev = new FMouseEvent (MouseUp_Event, p2, g, b);
smenu->onMouseUp(ev); smenu->onMouseUp(_ev);
delete ev; delete _ev;
} }
} }
@ -428,9 +429,9 @@ void FMenuItem::onMouseUp (FMouseEvent* ev)
if ( mbar ) if ( mbar )
{ {
const FPoint& p2 = mbar->globalToLocalPos(g); const FPoint& p2 = mbar->globalToLocalPos(g);
ev = new FMouseEvent (MouseMove_Event, p2, g, b); FMouseEvent* _ev = new FMouseEvent (MouseUp_Event, p2, g, b);
mbar->onMouseUp(ev); mbar->onMouseUp(_ev);
delete ev; delete _ev;
} }
} }
} }
@ -450,9 +451,9 @@ void FMenuItem::onMouseMove (FMouseEvent* ev)
if ( smenu ) if ( smenu )
{ {
const FPoint& p2 = smenu->globalToLocalPos(g); const FPoint& p2 = smenu->globalToLocalPos(g);
ev = new FMouseEvent (MouseMove_Event, p2, g, b); FMouseEvent* _ev = new FMouseEvent (MouseMove_Event, p2, g, b);
smenu->onMouseMove(ev); smenu->onMouseMove(_ev);
delete ev; delete _ev;
} }
} }
@ -462,9 +463,9 @@ void FMenuItem::onMouseMove (FMouseEvent* ev)
if ( mbar ) if ( mbar )
{ {
const FPoint& p2 = mbar->globalToLocalPos(g); const FPoint& p2 = mbar->globalToLocalPos(g);
ev = new FMouseEvent (MouseMove_Event, p2, g, b); FMouseEvent* _ev = new FMouseEvent (MouseMove_Event, p2, g, b);
mbar->onMouseMove(ev); mbar->onMouseMove(_ev);
delete ev; delete _ev;
} }
} }
@ -650,27 +651,27 @@ void FMenuItem::unsetSelected()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void FMenuItem::openMenu() void FMenuItem::openMenu()
{ {
FMenu* menu; FMenu* dd_menu; // Drop-down menu
FMenu* open_menu; FMenu* open_menu;
if ( hasMenu() ) if ( hasMenu() )
{ {
menu = getMenu(); dd_menu = getMenu();
if ( menu->isVisible() ) if ( dd_menu->isVisible() )
return; return;
open_menu = static_cast<FMenu*>(getOpenMenu()); open_menu = static_cast<FMenu*>(getOpenMenu());
if ( open_menu && open_menu != menu ) if ( open_menu && open_menu != dd_menu )
{ {
open_menu->hide(); open_menu->hide();
open_menu->hideSubMenus(); open_menu->hideSubMenus();
} }
setOpenMenu(menu); setOpenMenu(dd_menu);
menu->setVisible(); dd_menu->setVisible();
menu->show(); dd_menu->show();
menu->raiseWindow(menu); dd_menu->raiseWindow(dd_menu);
menu->redraw(); dd_menu->redraw();
updateTerminal(); updateTerminal();
flush_out(); flush_out();
} }