diff --git a/src/slic3r/GUI/Search.cpp b/src/slic3r/GUI/Search.cpp index 6cdfc1905..4990b17ee 100644 --- a/src/slic3r/GUI/Search.cpp +++ b/src/slic3r/GUI/Search.cpp @@ -464,16 +464,26 @@ SearchCtrl::SearchCtrl(wxWindow* parent) comboCtrl = new wxComboCtrl(parent, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize(25 * wxGetApp().em_unit(), -1), wxTE_PROCESS_ENTER); comboCtrl->UseAltPopupWindow(); - popupCtrl = new SearchComboPopup(); - // It is important to call SetPopupControl() as soon as possible - comboCtrl->SetPopupControl(popupCtrl); wxBitmap bmp_norm = create_scaled_bitmap("search_gray"); wxBitmap bmp_hov = create_scaled_bitmap("search"); comboCtrl->SetButtonBitmaps(bmp_norm, true, bmp_hov, bmp_hov, bmp_norm); + +// popupListBox = new SearchComboPopup(); + popupListCtrl = new SearchComboPopup_(); + + // It is important to call SetPopupControl() as soon as possible +// comboCtrl->SetPopupControl(popupListBox); + comboCtrl->SetPopupControl(popupListCtrl); + box_sizer->Add(comboCtrl, 0, wxALIGN_CENTER_VERTICAL); - popupCtrl->Bind(wxEVT_LISTBOX, &SearchCtrl::OnSelect, this); +// popupListBox->Bind(wxEVT_LISTBOX, &SearchCtrl::OnSelect, this); +// popupListCtrl->Bind(wxEVT_LIST_ITEM_SELECTED, &SearchCtrl::OnSelectCtrl, this); + popupListCtrl->Bind(wxEVT_LIST_ITEM_SELECTED, [](wxListEvent& event) + { + int i=0; + }); comboCtrl->Bind(wxEVT_TEXT, &SearchCtrl::OnInputText, this); comboCtrl->Bind(wxEVT_TEXT_ENTER, &SearchCtrl::PopupList, this); @@ -557,11 +567,27 @@ void SearchCtrl::OnSelect(wxCommandEvent& event) comboCtrl->Dismiss(); } +void SearchCtrl::OnSelectCtrl(wxListEvent& event) +{ + prevent_update = true; + + int selection = event.GetIndex(); + if (selection >= 0) + wxGetApp().sidebar().jump_to_option(selection); + + prevent_update = false; + + comboCtrl->Dismiss(); +} + void SearchCtrl::update_list(std::vector<SearchOptions::Filter>& filters) { - popupCtrl->Clear(); +/* popupListBox->Clear(); for (const SearchOptions::Filter& item : filters) - popupCtrl->Append(item.label); + popupListBox->Append(item.label);*/ + popupListCtrl->DeleteAllItems(); + for (const SearchOptions::Filter& item : filters) + popupListCtrl->InsertItem(popupListCtrl->GetItemCount(), item.label); } void SearchCtrl::OnLeftDown(wxEvent &event) diff --git a/src/slic3r/GUI/Search.hpp b/src/slic3r/GUI/Search.hpp index 2fa460b01..720171018 100644 --- a/src/slic3r/GUI/Search.hpp +++ b/src/slic3r/GUI/Search.hpp @@ -198,6 +198,52 @@ protected: }; + +class SearchComboPopup_ : public wxListCtrl, public wxComboPopup +{ +public: + // Initialize member variables + virtual void Init() {} + + // Create popup control + virtual bool Create(wxWindow* parent) + { + return wxListCtrl::Create(parent, 1, wxPoint(0, 0), wxDefaultSize, wxLC_LIST | wxLC_NO_HEADER | wxLC_SINGLE_SEL); + } + // Return pointer to the created control + virtual wxWindow* GetControl() { return this; } + // Translate string into a list selection + virtual void SetStringValue(const wxString& s) + { + int n = wxListCtrl::FindItem(0, s); + if (n >= 0 && n < wxListCtrl::GetItemCount()) + wxListCtrl::SetItemState(n, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED); + + // save a combo control's string + m_input_string = s; + } + // Get list selection as a string + virtual wxString GetStringValue() const + { + // we shouldn't change a combo control's string + return m_input_string; + } + // Do mouse hot-tracking (which is typical in list popups) + void OnMouseMove(wxMouseEvent& event) + { + // TODO: Move selection to cursor + } + // On mouse left up, set the value and close the popup + void OnMouseClick(wxMouseEvent& WXUNUSED(event)) + { + // TODO: Send event as well + Dismiss(); + } +protected: + wxString m_input_string; +}; + + class SearchCtrl { wxBoxSizer* box_sizer {nullptr}; @@ -213,10 +259,12 @@ class SearchCtrl void OnInputText(wxCommandEvent& event); wxComboCtrl* comboCtrl {nullptr}; - SearchComboPopup* popupCtrl {nullptr}; + SearchComboPopup* popupListBox {nullptr}; + SearchComboPopup_* popupListCtrl {nullptr}; void OnSelect(wxCommandEvent& event); void OnLeftDown(wxEvent& event); + void OnSelectCtrl(wxListEvent& event); public: SearchCtrl(wxWindow* parent);