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>
* Improved mouse and keyboard handling in sub-menus

View File

@ -401,15 +401,10 @@ bool FMenu::selectPrevItem()
//----------------------------------------------------------------------
void FMenu::keypressMenuBar (FKeyEvent*& ev)
{
FWidget* super = getSuperMenu();
if ( super )
{
if ( isMenuBar(super) )
{
FMenuBar* mbar = reinterpret_cast<FMenuBar*>(super);
FMenuBar* mbar = menuBar();
if ( mbar )
mbar->onKeyPress(ev);
}
}
}
//----------------------------------------------------------------------
@ -436,6 +431,18 @@ bool FMenu::hotkeyMenu (FKeyEvent*& ev)
found = true;
if ( found )
{
if ( (*iter)->hasMenu() )
{
FMenu* sub_menu = (*iter)->getMenu();
unselectItem();
(*iter)->setSelected();
setSelectedItem (*iter);
redraw();
openSubMenu (sub_menu);
sub_menu->redraw();
}
else
{
unselectItem();
hideSubMenus();
@ -445,6 +452,7 @@ bool FMenu::hotkeyMenu (FKeyEvent*& ev)
flush_out();
ev->accept();
(*iter)->processClicked();
}
return true;
}
}
@ -1180,10 +1188,11 @@ void FMenu::onMouseMove (FMouseEvent* ev)
const FPoint& g = ev->getGlobalPos();
const FPoint& p = open_sub_menu->globalToLocalPos(g);
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;
setClickedWidget(open_sub_menu);
open_sub_menu->onMouseMove(ev);
open_sub_menu->onMouseMove(_ev);
delete _ev;
}
else if ( ! mouse_over_menu && mouse_over_supermenu )
{
@ -1191,10 +1200,11 @@ void FMenu::onMouseMove (FMouseEvent* ev)
const FPoint& g = ev->getGlobalPos();
const FPoint& p = smenu->globalToLocalPos(g);
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;
setClickedWidget(smenu);
smenu->onMouseMove(ev);
smenu->onMouseMove(_ev);
delete _ev;
}
else if ( mouse_over_menubar )
{
@ -1203,12 +1213,12 @@ void FMenu::onMouseMove (FMouseEvent* ev)
const FPoint& g = ev->getGlobalPos();
const FPoint& p = menubar->globalToLocalPos(g);
int b = ev->getButton();
ev = new FMouseEvent (MouseMove_Event, p, g, b);
FMouseEvent* _ev = new FMouseEvent (MouseMove_Event, p, g, b);
setClickedWidget(menubar);
FMenuBar* mbar = reinterpret_cast<FMenuBar*>(menubar);
mbar->mouse_down = true;
mbar->onMouseMove(ev);
delete ev;
mbar->onMouseMove(_ev);
delete _ev;
}
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& p = menu->globalToLocalPos(g);
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;
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);
if ( menubar_ptr )
{
menubar_ptr->menu_dimension();
// Meta + hotkey
if ( hotkey )
if ( hotkey ) // Meta + hotkey
menubar_ptr->addAccelerator (fc::Fmkey_meta + tolower(hotkey), this);
}
this->addCallback
(
@ -382,9 +383,9 @@ void FMenuItem::onMouseDown (FMouseEvent* ev)
if ( smenu )
{
const FPoint& p2 = smenu->globalToLocalPos(g);
ev = new FMouseEvent (MouseMove_Event, p2, g, b);
smenu->onMouseDown(ev);
delete ev;
FMouseEvent* _ev = new FMouseEvent (MouseDown_Event, p2, g, b);
smenu->onMouseDown(_ev);
delete _ev;
}
}
@ -394,9 +395,9 @@ void FMenuItem::onMouseDown (FMouseEvent* ev)
if ( mbar )
{
const FPoint& p2 = mbar->globalToLocalPos(g);
ev = new FMouseEvent (MouseMove_Event, p2, g, b);
mbar->onMouseDown(ev);
delete ev;
FMouseEvent* _ev = new FMouseEvent (MouseDown_Event, p2, g, b);
mbar->onMouseDown(_ev);
delete _ev;
}
}
}
@ -416,9 +417,9 @@ void FMenuItem::onMouseUp (FMouseEvent* ev)
if ( smenu )
{
const FPoint& p2 = smenu->globalToLocalPos(g);
ev = new FMouseEvent (MouseMove_Event, p2, g, b);
smenu->onMouseUp(ev);
delete ev;
FMouseEvent* _ev = new FMouseEvent (MouseUp_Event, p2, g, b);
smenu->onMouseUp(_ev);
delete _ev;
}
}
@ -428,9 +429,9 @@ void FMenuItem::onMouseUp (FMouseEvent* ev)
if ( mbar )
{
const FPoint& p2 = mbar->globalToLocalPos(g);
ev = new FMouseEvent (MouseMove_Event, p2, g, b);
mbar->onMouseUp(ev);
delete ev;
FMouseEvent* _ev = new FMouseEvent (MouseUp_Event, p2, g, b);
mbar->onMouseUp(_ev);
delete _ev;
}
}
}
@ -450,9 +451,9 @@ void FMenuItem::onMouseMove (FMouseEvent* ev)
if ( smenu )
{
const FPoint& p2 = smenu->globalToLocalPos(g);
ev = new FMouseEvent (MouseMove_Event, p2, g, b);
smenu->onMouseMove(ev);
delete ev;
FMouseEvent* _ev = new FMouseEvent (MouseMove_Event, p2, g, b);
smenu->onMouseMove(_ev);
delete _ev;
}
}
@ -462,9 +463,9 @@ void FMenuItem::onMouseMove (FMouseEvent* ev)
if ( mbar )
{
const FPoint& p2 = mbar->globalToLocalPos(g);
ev = new FMouseEvent (MouseMove_Event, p2, g, b);
mbar->onMouseMove(ev);
delete ev;
FMouseEvent* _ev = new FMouseEvent (MouseMove_Event, p2, g, b);
mbar->onMouseMove(_ev);
delete _ev;
}
}
@ -650,27 +651,27 @@ void FMenuItem::unsetSelected()
//----------------------------------------------------------------------
void FMenuItem::openMenu()
{
FMenu* menu;
FMenu* dd_menu; // Drop-down menu
FMenu* open_menu;
if ( hasMenu() )
{
menu = getMenu();
if ( menu->isVisible() )
dd_menu = getMenu();
if ( dd_menu->isVisible() )
return;
open_menu = static_cast<FMenu*>(getOpenMenu());
if ( open_menu && open_menu != menu )
if ( open_menu && open_menu != dd_menu )
{
open_menu->hide();
open_menu->hideSubMenus();
}
setOpenMenu(menu);
setOpenMenu(dd_menu);
menu->setVisible();
menu->show();
menu->raiseWindow(menu);
menu->redraw();
dd_menu->setVisible();
dd_menu->show();
dd_menu->raiseWindow(dd_menu);
dd_menu->redraw();
updateTerminal();
flush_out();
}