From 98c5cea5f59180a80d322cb9e45d0d9ea5381444 Mon Sep 17 00:00:00 2001 From: Mark Tiefenbruck Date: Mon, 17 Dec 2007 22:52:30 -0800 Subject: fix torn menus --- src/FbTk/Menu.cc | 27 ++++++++++++++++----------- src/FbTk/Menu.hh | 2 +- 2 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/FbTk/Menu.cc b/src/FbTk/Menu.cc index bb51d92..485b56c 100644 --- a/src/FbTk/Menu.cc +++ b/src/FbTk/Menu.cc @@ -515,24 +515,28 @@ void Menu::show() { menu.window.show(); raise(); - if (shown && shown != this && shown != m_parent) + if (shown && shown != this) shown->hide(); shown = this; } -void Menu::hide() { +void Menu::hide(bool force) { if (!isVisible()) return; // if parent is visible, go to first parent and hide it Menu *p = this; - while (p->m_parent && p->m_parent->isVisible()) - p = p->m_parent; - - p->internal_hide(); + while (p && p->isVisible()) { + Menu *tmp = p->m_parent; + if (force || !p->m_torn) + p->internal_hide(); + else + p->m_parent = 0; + p = tmp; + } } @@ -570,12 +574,10 @@ void Menu::redrawFrame(FbDrawable &drawable) { void Menu::internal_hide(bool first) { - if (!first && m_torn) - return; - if (validIndex(m_which_sub)) { MenuItem *tmp = menuitems[m_which_sub]; - tmp->submenu()->internal_hide(false); + if (tmp && tmp->submenu() && tmp->submenu()->isVisible()) + tmp->submenu()->internal_hide(false); } // if we have an active index we need to redraw it @@ -719,6 +721,7 @@ void Menu::drawSubmenu(unsigned int index) { clearItem(index); if (! item->submenu()->isVisible()) { + shown = item->submenu(); item->showSubmenu(); item->submenu()->raise(); } @@ -908,6 +911,8 @@ void Menu::motionNotifyEvent(XMotionEvent &me) { if (! m_moving) { // if not m_moving: start m_moving operation m_moving = m_torn = true; + if (m_parent) + m_parent->m_which_sub = -1; // clear current highlighted item clearItem(m_active_index); @@ -1033,7 +1038,7 @@ void Menu::keyPressEvent(XKeyEvent &event) { case XK_Escape: // close menu m_type_ahead.reset(); m_torn = false; - hide(); + hide(true); break; case XK_BackSpace: if (m_type_ahead.stringSize() == 0) { diff --git a/src/FbTk/Menu.hh b/src/FbTk/Menu.hh index 53dc494..f16c443 100644 --- a/src/FbTk/Menu.hh +++ b/src/FbTk/Menu.hh @@ -124,7 +124,7 @@ public: /// show menu virtual void show(); /// hide menu - virtual void hide(); + virtual void hide(bool force = false); virtual void clearWindow(); #ifdef NOT_USED void setActiveIndex(int index) { m_active_index = index; } -- cgit v0.11.2