diff --git a/xs/src/slic3r/GUI/Field.cpp b/xs/src/slic3r/GUI/Field.cpp index fee08e27e..a7fd8d29e 100644 --- a/xs/src/slic3r/GUI/Field.cpp +++ b/xs/src/slic3r/GUI/Field.cpp @@ -173,8 +173,7 @@ namespace Slic3r { namespace GUI { temp->Bind(wxEVT_KILL_FOCUS, ([this, temp](wxEvent& e) { -// on_kill_focus(e); - e.Skip(); + e.Skip();// on_kill_focus(e); temp->GetToolTip()->Enable(true); }), temp->GetId()); diff --git a/xs/src/slic3r/GUI/Tab.cpp b/xs/src/slic3r/GUI/Tab.cpp index babff7d80..3935dda5a 100644 --- a/xs/src/slic3r/GUI/Tab.cpp +++ b/xs/src/slic3r/GUI/Tab.cpp @@ -20,6 +20,7 @@ #include #include +#include "wxExtensions.hpp" namespace Slic3r { namespace GUI { @@ -38,6 +39,50 @@ void Tab::create_preset_tab(PresetBundle *preset_bundle) // preset chooser m_presets_choice = new wxBitmapComboBox(panel, wxID_ANY, "", wxDefaultPosition, wxSize(270, -1), 0, 0,wxCB_READONLY); + m_cc_presets_choice = new wxComboCtrl(panel, wxID_ANY, L("Presets"), wxDefaultPosition, wxSize(270, -1), wxCB_READONLY); + wxDataViewTreeCtrlComboPopup* popup = new wxDataViewTreeCtrlComboPopup; + if (popup != nullptr) + { + // FIXME If the following line is removed, the combo box popup list will not react to mouse clicks. + // On the other side, with this line the combo box popup cannot be closed by clicking on the combo button on Windows 10. +// comboCtrl->UseAltPopupWindow(); +// comboCtrl->EnablePopupAnimation(false); + m_cc_presets_choice->SetPopupControl(popup); + popup->SetStringValue(from_u8("Text1")); + + popup->Bind(wxEVT_DATAVIEW_SELECTION_CHANGED, [this, popup](wxCommandEvent& evt) + { + auto selected = popup->GetItemText(popup->GetSelection()); + if (selected != _(L("System presets")) && selected != _(L("Default presets"))) + m_cc_presets_choice->SetText(selected); +// popup->OnDataViewTreeCtrlSelection(evt); + }); + popup->Bind(wxEVT_KEY_DOWN, [popup](wxKeyEvent& evt) { popup->OnKeyEvent(evt); }); + popup->Bind(wxEVT_KEY_UP, [popup](wxKeyEvent& evt) { popup->OnKeyEvent(evt); }); + + auto icons = new wxImageList(16, 16, true, 1); + popup->SetImageList(icons); + icons->Add(*new wxIcon(from_u8(Slic3r::var("flag-red-icon.png")), wxBITMAP_TYPE_PNG)); + icons->Add(*new wxIcon(from_u8(Slic3r::var("flag-green-icon.png")), wxBITMAP_TYPE_PNG)); + + Freeze(); + + // get label of the currently selected item + auto selected = popup->GetItemText(popup->GetSelection()); + auto root_sys = popup->AppendContainer(wxDataViewItem(0), _(L("System presets"))); + auto tree_node1 = popup->AppendItem(root_sys, _("Sys1"), 0); + auto tree_node2 = popup->AppendContainer(root_sys, _("Sys2"), 0); + auto tree_node2_1 = popup->AppendItem(tree_node2, _("Sys2_1"), 0); + + auto root_def = popup->AppendContainer(wxDataViewItem(0), _(L("Default presets"))); + auto tree_node01 = popup->AppendContainer(root_def, _("Def1"), 0); + auto tree_node02 = popup->AppendContainer(root_def, _("Def2"), 0); + auto tree_node02_1 = popup->AppendItem(tree_node02, _("Def2_1"), 0); + + Thaw(); + } + + auto color = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW); //buttons @@ -82,6 +127,8 @@ void Tab::create_preset_tab(PresetBundle *preset_bundle) m_hsizer->AddSpacer(64); m_hsizer->Add(m_undo_to_sys_btn, 0, wxALIGN_CENTER_VERTICAL); m_hsizer->Add(m_undo_btn, 0, wxALIGN_CENTER_VERTICAL); + m_hsizer->AddSpacer(64); + m_hsizer->Add(m_cc_presets_choice, 1, wxLEFT | wxRIGHT | wxTOP | wxALIGN_CENTER_VERTICAL, 3); //Horizontal sizer to hold the tree and the selected page. m_hsizer = new wxBoxSizer(wxHORIZONTAL); diff --git a/xs/src/slic3r/GUI/Tab.hpp b/xs/src/slic3r/GUI/Tab.hpp index f39ff728c..075eab218 100644 --- a/xs/src/slic3r/GUI/Tab.hpp +++ b/xs/src/slic3r/GUI/Tab.hpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include @@ -95,6 +96,7 @@ protected: wxButton* m_compatible_printers_btn; wxButton* m_undo_btn; wxButton* m_undo_to_sys_btn; + wxComboCtrl* m_cc_presets_choice; int m_icon_count; std::map m_icon_index; // Map from an icon file name to its index diff --git a/xs/src/slic3r/GUI/wxExtensions.cpp b/xs/src/slic3r/GUI/wxExtensions.cpp index 1ebd7979e..c4dfb7e10 100644 --- a/xs/src/slic3r/GUI/wxExtensions.cpp +++ b/xs/src/slic3r/GUI/wxExtensions.cpp @@ -109,3 +109,47 @@ void wxCheckListBoxComboPopup::OnListBoxSelection(wxCommandEvent& evt) ProcessEvent(event); } } + + +// *** wxDataViewTreeCtrlComboPopup *** + +const unsigned int wxDataViewTreeCtrlComboPopup::DefaultWidth = 270; +const unsigned int wxDataViewTreeCtrlComboPopup::DefaultHeight = 200; +const unsigned int wxDataViewTreeCtrlComboPopup::DefaultItemHeight = 22; + +bool wxDataViewTreeCtrlComboPopup::Create(wxWindow* parent) +{ + return wxDataViewTreeCtrl::Create(parent, wxID_HIGHEST + 1, wxPoint(0, 0), wxSize(270, -1)); +} + +wxSize wxDataViewTreeCtrlComboPopup::GetAdjustedSize(int minWidth, int prefHeight, int maxHeight) +{ + // matches owner wxComboCtrl's width + // and sets height dinamically in dependence of contained items count + return wxSize(DefaultWidth, DefaultHeight); +} + +void wxDataViewTreeCtrlComboPopup::OnKeyEvent(wxKeyEvent& evt) +{ + // filters out all the keys which are not working properly + if (evt.GetKeyCode() == WXK_UP) + { + return; + } + else if (evt.GetKeyCode() == WXK_DOWN) + { + return; + } + else + { + evt.Skip(); + return; + } +} + +void wxDataViewTreeCtrlComboPopup::OnDataViewTreeCtrlSelection(wxCommandEvent& evt) +{ + wxComboCtrl* cmb = GetComboCtrl(); + auto selected = GetItemText(GetSelection()); + cmb->SetText(selected); +} diff --git a/xs/src/slic3r/GUI/wxExtensions.hpp b/xs/src/slic3r/GUI/wxExtensions.hpp index e61c17bbc..bba412cfd 100644 --- a/xs/src/slic3r/GUI/wxExtensions.hpp +++ b/xs/src/slic3r/GUI/wxExtensions.hpp @@ -3,6 +3,7 @@ #include #include +#include class wxCheckListBoxComboPopup : public wxCheckListBox, public wxComboPopup { @@ -25,4 +26,27 @@ public: void OnListBoxSelection(wxCommandEvent& evt); }; + +// *** wxDataViewTreeCtrlComboBox *** + +class wxDataViewTreeCtrlComboPopup: public wxDataViewTreeCtrl, public wxComboPopup +{ + static const unsigned int DefaultWidth; + static const unsigned int DefaultHeight; + static const unsigned int DefaultItemHeight; + + wxString m_text; + int m_cnt_open_items=2; + +public: + virtual bool Create(wxWindow* parent); + virtual wxWindow* GetControl() { return this; } + virtual void SetStringValue(const wxString& value) { m_text = value; } + virtual wxString GetStringValue() const { return m_text; } + virtual wxSize GetAdjustedSize(int minWidth, int prefHeight, int maxHeight); + + virtual void OnKeyEvent(wxKeyEvent& evt); + void OnDataViewTreeCtrlSelection(wxCommandEvent& evt); +}; + #endif // slic3r_GUI_wxExtensions_hpp_