Now you can press a mouse button in a ComboBoxEntry and drag the mouse to the ComboBoxListBox (issue 339)

This commit is contained in:
David Capello 2014-02-08 20:09:42 -03:00
parent 7251f4b70a
commit 3cbf3e122f
4 changed files with 39 additions and 2 deletions

View File

@ -411,8 +411,33 @@ bool ComboBoxEntry::onProcessMessage(Message* msg)
if (m_comboBox->isEditable()) {
getManager()->setFocus(this);
}
else
else {
captureMouse();
return true;
}
break;
case kMouseUpMessage:
if (hasCapture())
releaseMouse();
break;
case kMouseMoveMessage:
if (hasCapture()) {
MouseMessage* mouseMsg = static_cast<MouseMessage*>(msg);
Widget* pick = getManager()->pick(mouseMsg->position());
Widget* listbox = m_comboBox->m_listbox;
if (pick != NULL && (pick == listbox || pick->hasAncestor(listbox))) {
releaseMouse();
MouseMessage mouseMsg(kMouseDownMessage,
mouseMsg->buttons(),
mouseMsg->position());
pick->sendMessage(&mouseMsg);
return true;
}
}
break;
}

View File

@ -22,10 +22,12 @@ namespace ui {
class ListItem;
class Window;
class ComboBoxEntry;
class ComboBoxListBox;
class ComboBox : public Widget
{
friend class ComboBoxEntry;
friend class ComboBoxListBox;
public:
@ -91,7 +93,7 @@ namespace ui {
private:
void onButtonClick(Event& ev);
Entry* m_entry;
ComboBoxEntry* m_entry;
Button* m_button;
Window* m_window;
ComboBoxListBox* m_listbox;

View File

@ -427,6 +427,15 @@ bool Widget::hasChild(Widget* child)
return std::find(m_children.begin(), m_children.end(), child) != m_children.end();
}
bool Widget::hasAncestor(Widget* ancestor)
{
for (Widget* widget=m_parent; widget; widget=widget->m_parent) {
if (widget == ancestor)
return true;
}
return false;
}
Widget* Widget::findChild(const char* id)
{
Widget* child;

View File

@ -208,6 +208,7 @@ namespace ui {
Widget* pick(const gfx::Point& pt);
bool hasChild(Widget* child);
bool hasAncestor(Widget* ancestor);
Widget* findChild(const char* id);
// Returns a widget in the same window that is located "sibling".