Fix ToolBar behavior to avoid changing tools unintentionally

- Avoid opening other groups if the user is not with the mouse down
- A second MouseUp closes the group
This commit is contained in:
David Capello 2014-05-04 20:56:36 -03:00
parent 6414e37f9a
commit ddf894867a
2 changed files with 14 additions and 6 deletions

View File

@ -94,6 +94,7 @@ ToolBar::ToolBar()
: Widget(kGenericWidget)
, m_tipTimer(300, this)
, m_closeSlot(NULL)
, m_openedRecently(false)
{
m_instance = this;
@ -199,9 +200,9 @@ bool ToolBar::onProcessMessage(Message* msg)
new_hot_tool = tool;
new_hot_index = c;
if ((m_openOnHot) && (m_hotTool != new_hot_tool))
if ((m_openOnHot) && (m_hotTool != new_hot_tool) && hasCapture()) {
openPopupWindow(c, tool_group);
}
break;
}
}
@ -264,6 +265,12 @@ bool ToolBar::onProcessMessage(Message* msg)
if (!hasCapture())
break;
if (!m_openedRecently) {
if (m_popupWindow && m_popupWindow->isVisible())
m_popupWindow->closeWindow(this);
}
m_openedRecently = false;
releaseMouse();
// fallthrough
@ -440,6 +447,7 @@ void ToolBar::openPopupWindow(int group_index, ToolGroup* tool_group)
// In case this tool contains more than just one tool, show the popup window
m_popupWindow = new PopupWindow("", PopupWindow::kCloseOnClickOutsideHotRegion);
m_closeSlot = m_popupWindow->Close.connect(Bind<void, ToolBar, ToolBar>(&ToolBar::onClosePopup, this));
m_openedRecently = true;
ToolStrip* toolstrip = new ToolStrip(tool_group, this);
m_currentStrip = toolstrip;
@ -586,10 +594,6 @@ void ToolBar::closeTipWindow()
m_tipWindow->closeWindow(NULL);
delete m_tipWindow;
m_tipWindow = NULL;
// Flush kPaintMessage messages and send them
getManager()->flushRedraw();
getManager()->dispatchMessages();
}
}

View File

@ -84,6 +84,10 @@ namespace app {
// True if the popup-window must be opened when a tool-button is hot
bool m_openOnHot;
// True if the last MouseDown opened the popup. This is used to
// close the popup with a second MouseUp event.
bool m_openedRecently;
// Window displayed to show a tool-group
ui::PopupWindow* m_popupWindow;
class ToolStrip;