diff --git a/xs/src/slic3r/GUI/GUI.cpp b/xs/src/slic3r/GUI/GUI.cpp index 518bef5b5..6f121ddb0 100644 --- a/xs/src/slic3r/GUI/GUI.cpp +++ b/xs/src/slic3r/GUI/GUI.cpp @@ -491,6 +491,8 @@ void create_combochecklist(wxComboCtrl* comboCtrl, std::string text, std::string popup->SetStringValue(text); popup->Bind(wxEVT_CHECKLISTBOX, [popup](wxCommandEvent& evt) { popup->OnCheckListBox(evt); }); popup->Bind(wxEVT_LISTBOX, [popup](wxCommandEvent& evt) { popup->OnListBoxSelection(evt); }); + popup->Bind(wxEVT_KEY_DOWN, [popup](wxKeyEvent& evt) { popup->OnKeyEvent(evt); }); + popup->Bind(wxEVT_KEY_UP, [popup](wxKeyEvent& evt) { popup->OnKeyEvent(evt); }); std::vector items_str; boost::split(items_str, items, boost::is_any_of("|"), boost::token_compress_off); diff --git a/xs/src/slic3r/GUI/wxExtensions.cpp b/xs/src/slic3r/GUI/wxExtensions.cpp index b5f0595f8..1bc329648 100644 --- a/xs/src/slic3r/GUI/wxExtensions.cpp +++ b/xs/src/slic3r/GUI/wxExtensions.cpp @@ -1,6 +1,7 @@ #include "wxExtensions.hpp" -const unsigned int wxCheckListBoxComboPopup::Height = 210; +const unsigned int wxCheckListBoxComboPopup::DefaultWidth = 200; +const unsigned int wxCheckListBoxComboPopup::DefaultHeight = 200; bool wxCheckListBoxComboPopup::Create(wxWindow* parent) { @@ -25,16 +26,32 @@ wxString wxCheckListBoxComboPopup::GetStringValue() const wxSize wxCheckListBoxComboPopup::GetAdjustedSize(int minWidth, int prefHeight, int maxHeight) { // matches owner wxComboCtrl's width + // and sets height dinamically in dependence of contained items count wxComboCtrl* cmb = GetComboCtrl(); if (cmb != nullptr) { wxSize size = GetComboCtrl()->GetSize(); - size.SetHeight(Height); + + unsigned int count = GetCount(); + if (count > 0) + { + wxRect first_rect; + GetItemRect(0, first_rect); + size.SetHeight((1 + count) * first_rect.GetHeight()); + } + else + size.SetHeight(DefaultHeight); + return size; } else - return wxSize(200, Height); + return wxSize(DefaultWidth, DefaultHeight); +} + +void wxCheckListBoxComboPopup::OnKeyEvent(wxKeyEvent& evt) +{ + // do nothing, but prevents navigation in the list using arrows keys (which is not working properly) } void wxCheckListBoxComboPopup::OnCheckListBox(wxCommandEvent& evt) diff --git a/xs/src/slic3r/GUI/wxExtensions.hpp b/xs/src/slic3r/GUI/wxExtensions.hpp index 8e62f766c..3fc4c70a7 100644 --- a/xs/src/slic3r/GUI/wxExtensions.hpp +++ b/xs/src/slic3r/GUI/wxExtensions.hpp @@ -6,7 +6,8 @@ class wxCheckListBoxComboPopup : public wxCheckListBox, public wxComboPopup { - static const unsigned int Height; + static const unsigned int DefaultWidth; + static const unsigned int DefaultHeight; wxString m_text; @@ -17,6 +18,8 @@ public: virtual wxString GetStringValue() const; virtual wxSize GetAdjustedSize(int minWidth, int prefHeight, int maxHeight); + virtual void OnKeyEvent(wxKeyEvent& evt); + void OnCheckListBox(wxCommandEvent& evt); void OnListBoxSelection(wxCommandEvent& evt); };