diff --git a/src/slic3r/GUI/Search.cpp b/src/slic3r/GUI/Search.cpp index 95bf2da3f..eb7c98d87 100644 --- a/src/slic3r/GUI/Search.cpp +++ b/src/slic3r/GUI/Search.cpp @@ -482,8 +482,8 @@ SearchCtrl::SearchCtrl(wxWindow* parent) box_sizer->Add(comboCtrl, 0, wxALIGN_CENTER_VERTICAL); - popupListBox->Bind(wxEVT_LISTBOX, &SearchCtrl::OnSelect, this); - popupListBox->Bind(wxEVT_LEFT_DOWN, &SearchCtrl::OnLeftDownInPopup, this); +// popupListBox->Bind(wxEVT_LEFT_DOWN, &SearchCtrl::OnLeftDownInPopup, this); + popupListBox->Bind(wxEVT_LISTBOX, &SearchCtrl::OnSelect, this); comboCtrl->Bind(wxEVT_TEXT, &SearchCtrl::OnInputText, this); comboCtrl->Bind(wxEVT_TEXT_ENTER, &SearchCtrl::PopupList, this); @@ -559,18 +559,21 @@ void SearchCtrl::msw_rescale() comboCtrl->SetButtonBitmaps(create_scaled_bitmap("search")); } +void SearchCtrl::select(int selection) +{ + if (selection < 0) + return; + + prevent_update = true; + wxGetApp().sidebar().jump_to_option(selection); + prevent_update = false; + +// comboCtrl->Dismiss(); +} void SearchCtrl::OnSelect(wxCommandEvent& event) { - prevent_update = true; - - int selection = event.GetSelection(); - if (selection >= 0) - wxGetApp().sidebar().jump_to_option(selection); - - prevent_update = false; - - comboCtrl->Dismiss(); + select(event.GetSelection()); } void SearchCtrl::update_list(std::vector<SearchOptions::Filter>& filters) @@ -596,7 +599,7 @@ void SearchCtrl::OnLeftUpInTextCtrl(wxEvent &event) void SearchCtrl::OnLeftDownInPopup(wxEvent &event) { wxPoint pt = wxGetMousePosition() - popupListBox->GetScreenPosition(); - int selected_item = popupListBox->HitTest(pt); + select(popupListBox->HitTest(pt)); event.Skip(); } diff --git a/src/slic3r/GUI/Search.hpp b/src/slic3r/GUI/Search.hpp index a27a10380..e695e4ecf 100644 --- a/src/slic3r/GUI/Search.hpp +++ b/src/slic3r/GUI/Search.hpp @@ -156,7 +156,11 @@ class SearchComboPopup : public wxListBox, public wxComboPopup { public: // Initialize member variables - virtual void Init(){} + virtual void Init() + { + this->Bind(wxEVT_MOTION, &SearchComboPopup::OnMouseMove, this); + this->Bind(wxEVT_LEFT_UP, &SearchComboPopup::OnMouseClick, this); + } // Create popup control virtual bool Create(wxWindow* parent) @@ -184,12 +188,20 @@ public: // Do mouse hot-tracking (which is typical in list popups) void OnMouseMove(wxMouseEvent& event) { - // TODO: Move selection to cursor + wxPoint pt = wxGetMousePosition() - this->GetScreenPosition(); + int selection = this->HitTest(pt); + wxListBox::Select(selection); } // On mouse left up, set the value and close the popup void OnMouseClick(wxMouseEvent& WXUNUSED(event)) { - // TODO: Send event as well + int selection = wxListBox::GetSelection(); + SetSelection(wxNOT_FOUND); + wxCommandEvent event(wxEVT_LISTBOX, GetId()); + event.SetInt(selection); + event.SetEventObject(this); + ProcessEvent(event); + Dismiss(); } protected: @@ -226,6 +238,7 @@ public: void set_search_line(const std::string& search_line); void msw_rescale(); + void select(int selection); void update_list(std::vector<SearchOptions::Filter>& filters); };