diff --git a/src/slic3r/GUI/GUI.cpp b/src/slic3r/GUI/GUI.cpp index 28e24dd8d4..97600925d5 100644 --- a/src/slic3r/GUI/GUI.cpp +++ b/src/slic3r/GUI/GUI.cpp @@ -244,77 +244,6 @@ void show_substitutions_info(const ConfigSubstitutions& config_substitutions, co msg.ShowModal(); } -void create_combochecklist(wxComboCtrl* comboCtrl, const std::string& text, const std::string& items) -{ - if (comboCtrl == nullptr) - return; - wxGetApp().UpdateDarkUI(comboCtrl); - - wxCheckListBoxComboPopup* popup = new wxCheckListBoxComboPopup; - 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(); - - int max_width = 0; - - // the following line messes up the popup size the first time it is shown on wxWidgets 3.1.3 -// comboCtrl->EnablePopupAnimation(false); -#ifdef _WIN32 - popup->SetFont(comboCtrl->GetFont()); -#endif // _WIN32 - comboCtrl->SetPopupControl(popup); - wxString title = from_u8(text); - max_width = std::max(max_width, 60 + comboCtrl->GetTextExtent(title).x); - popup->SetStringValue(title); - 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); - - // each item must be composed by 2 parts - assert(items_str.size() %2 == 0); - - for (size_t i = 0; i < items_str.size(); i += 2) { - wxString label = from_u8(items_str[i]); - max_width = std::max(max_width, 60 + popup->GetTextExtent(label).x); - popup->Append(label); - popup->Check(i / 2, items_str[i + 1] == "1"); - } - - comboCtrl->SetMinClientSize(wxSize(max_width, -1)); - wxGetApp().UpdateDarkUI(popup); - } -} - -unsigned int combochecklist_get_flags(wxComboCtrl* comboCtrl) -{ - unsigned int flags = 0; - - wxCheckListBoxComboPopup* popup = wxDynamicCast(comboCtrl->GetPopupControl(), wxCheckListBoxComboPopup); - if (popup != nullptr) { - for (unsigned int i = 0; i < popup->GetCount(); ++i) { - if (popup->IsChecked(i)) - flags |= 1 << i; - } - } - - return flags; -} - -void combochecklist_set_flags(wxComboCtrl* comboCtrl, unsigned int flags) -{ - wxCheckListBoxComboPopup* popup = wxDynamicCast(comboCtrl->GetPopupControl(), wxCheckListBoxComboPopup); - if (popup != nullptr) { - for (unsigned int i = 0; i < popup->GetCount(); ++i) { - popup->Check(i, (flags & (1 << i)) != 0); - } - } -} - AppConfig* get_app_config() { return wxGetApp().app_config; diff --git a/src/slic3r/GUI/GUI.hpp b/src/slic3r/GUI/GUI.hpp index 968d437ce4..81a6cf5af4 100644 --- a/src/slic3r/GUI/GUI.hpp +++ b/src/slic3r/GUI/GUI.hpp @@ -56,19 +56,6 @@ void warning_catcher(wxWindow* parent, const wxString& message); void show_substitutions_info(const PresetsConfigSubstitutions& presets_config_substitutions); void show_substitutions_info(const ConfigSubstitutions& config_substitutions, const std::string& filename); -// Creates a wxCheckListBoxComboPopup inside the given wxComboCtrl, filled with the given text and items. -// Items data must be separated by '|', and contain the item name to be shown followed by its initial value (0 for false, 1 for true). -// For example "Item1|0|Item2|1|Item3|0", and so on. -void create_combochecklist(wxComboCtrl* comboCtrl, const std::string& text, const std::string& items); - -// Returns the current state of the items listed in the wxCheckListBoxComboPopup contained in the given wxComboCtrl, -// encoded inside an unsigned int. -unsigned int combochecklist_get_flags(wxComboCtrl* comboCtrl); - -// Sets the current state of the items listed in the wxCheckListBoxComboPopup contained in the given wxComboCtrl, -// with the flags encoded in the given unsigned int. -void combochecklist_set_flags(wxComboCtrl* comboCtrl, unsigned int flags); - // wxString conversions: // wxString from std::string in UTF8 diff --git a/src/slic3r/GUI/GUI_Factories.cpp b/src/slic3r/GUI/GUI_Factories.cpp index bed6c6368e..acdd55acfe 100644 --- a/src/slic3r/GUI/GUI_Factories.cpp +++ b/src/slic3r/GUI/GUI_Factories.cpp @@ -27,6 +27,33 @@ #include "slic3r/Utils/MacDarkMode.hpp" #endif +// ---------------------------------------------------------------------------- +// MenuWithSeparators +// ---------------------------------------------------------------------------- + +void MenuWithSeparators::DestroySeparators() +{ + if (m_separator_frst) { + Destroy(m_separator_frst); + m_separator_frst = nullptr; + } + + if (m_separator_scnd) { + Destroy(m_separator_scnd); + m_separator_scnd = nullptr; + } +} + +void MenuWithSeparators::SetFirstSeparator() +{ + m_separator_frst = this->AppendSeparator(); +} + +void MenuWithSeparators::SetSecondSeparator() +{ + m_separator_scnd = this->AppendSeparator(); +} + namespace Slic3r { namespace GUI diff --git a/src/slic3r/GUI/GUI_Factories.hpp b/src/slic3r/GUI/GUI_Factories.hpp index e7706a8a15..86dfcb4628 100644 --- a/src/slic3r/GUI/GUI_Factories.hpp +++ b/src/slic3r/GUI/GUI_Factories.hpp @@ -17,6 +17,30 @@ class wxMenu; class wxMenuItem; +// ---------------------------------------------------------------------------- +// MenuWithSeparators +// ---------------------------------------------------------------------------- + +class MenuWithSeparators : public wxMenu +{ +public: + MenuWithSeparators(const wxString& title, long style = 0) + : wxMenu(title, style) {} + + MenuWithSeparators(long style = 0) + : wxMenu(style) {} + + ~MenuWithSeparators() {} + + void DestroySeparators(); + void SetFirstSeparator(); + void SetSecondSeparator(); + +private: + wxMenuItem* m_separator_frst{ nullptr }; // use like separator before settings item + wxMenuItem* m_separator_scnd{ nullptr }; // use like separator between settings items +}; + namespace Slic3r { enum class ModelVolumeType : int; diff --git a/src/slic3r/GUI/GUI_ObjectList.hpp b/src/slic3r/GUI/GUI_ObjectList.hpp index 28061cef46..b80e92abfa 100644 --- a/src/slic3r/GUI/GUI_ObjectList.hpp +++ b/src/slic3r/GUI/GUI_ObjectList.hpp @@ -22,7 +22,6 @@ class wxBoxSizer; class wxBitmapComboBox; class wxMenuItem; -class MenuWithSeparators; namespace Slic3r { class ConfigOptionsGroup; diff --git a/src/slic3r/GUI/GalleryDialog.cpp b/src/slic3r/GUI/GalleryDialog.cpp index 23c2cc8e08..41972d2db7 100644 --- a/src/slic3r/GUI/GalleryDialog.cpp +++ b/src/slic3r/GUI/GalleryDialog.cpp @@ -18,7 +18,6 @@ #include #include #include -#include #include #include "GUI.hpp" @@ -26,7 +25,6 @@ #include "format.hpp" #include "wxExtensions.hpp" #include "I18N.hpp" -#include "Notebook.hpp" #include "3DScene.hpp" #include "GLCanvas3D.hpp" #include "Plater.hpp" diff --git a/src/slic3r/GUI/Notebook.cpp b/src/slic3r/GUI/Notebook.cpp index ea75c74b36..df2671b22e 100644 --- a/src/slic3r/GUI/Notebook.cpp +++ b/src/slic3r/GUI/Notebook.cpp @@ -14,7 +14,7 @@ wxDEFINE_EVENT(wxCUSTOMEVT_NOTEBOOK_SEL_CHANGED, wxCommandEvent); -ButtonsListCtrl::ButtonsListCtrl(wxWindow *parent, bool add_mode_buttons/* = false*/) : +ButtonsListCtrl::ButtonsListCtrl(wxWindow *parent) : wxControl(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxBORDER_NONE | wxTAB_TRAVERSAL) { #ifdef __WINDOWS__ @@ -31,12 +31,6 @@ ButtonsListCtrl::ButtonsListCtrl(wxWindow *parent, bool add_mode_buttons/* = fal m_buttons_sizer = new wxFlexGridSizer(1, m_btn_margin, m_btn_margin); m_sizer->Add(m_buttons_sizer, 0, wxALIGN_CENTER_VERTICAL | wxLEFT | wxBOTTOM, m_btn_margin); - if (add_mode_buttons) { - m_mode_sizer = new ModeSizer(this, m_btn_margin); - m_sizer->AddStretchSpacer(20); - m_sizer->Add(m_mode_sizer, 0, wxALIGN_CENTER_VERTICAL | wxRIGHT | wxBOTTOM, m_btn_margin); - } - this->Bind(wxEVT_PAINT, &ButtonsListCtrl::OnPaint, this); } @@ -68,23 +62,6 @@ void ButtonsListCtrl::OnPaint(wxPaintEvent&) dc.DrawRectangle(pos.x, pos.y + size.y, size.x, sz.y - size.y); } - // highlight selected mode button - - if (m_mode_sizer) { - const std::vector& mode_btns = m_mode_sizer->get_btns(); - for (int idx = 0; idx < int(mode_btns.size()); idx++) { - ModeButton* btn = mode_btns[idx]; - btn->SetBackgroundColour(btn->is_selected() ? selected_btn_bg : default_btn_bg); - - //wxPoint pos = btn->GetPosition(); - //wxSize size = btn->GetSize(); - //const wxColour& clr = btn->is_selected() ? btn_marker_color : default_btn_bg; - //dc.SetPen(clr); - //dc.SetBrush(clr); - //dc.DrawRectangle(pos.x, pos.y + size.y, size.x, sz.y - size.y); - } - } - // Draw orange bottom line dc.SetPen(btn_marker_color); @@ -92,11 +69,6 @@ void ButtonsListCtrl::OnPaint(wxPaintEvent&) dc.DrawRectangle(1, sz.y - m_line_margin, sz.x, m_line_margin); } -void ButtonsListCtrl::UpdateMode() -{ - m_mode_sizer->SetMode(Slic3r::GUI::wxGetApp().get_mode()); -} - void ButtonsListCtrl::Rescale() { int em = em_unit(this); @@ -113,16 +85,9 @@ void ButtonsListCtrl::OnColorsChanged() for (ScalableButton* btn : m_pageButtons) btn->sys_color_changed(); - m_mode_sizer->sys_color_changed(); - m_sizer->Layout(); } -void ButtonsListCtrl::UpdateModeMarkers() -{ - m_mode_sizer->update_mode_markers(); -} - void ButtonsListCtrl::SetSelection(int sel) { if (m_selection == sel) diff --git a/src/slic3r/GUI/Notebook.hpp b/src/slic3r/GUI/Notebook.hpp index 6d0a8a6edc..62b722f332 100644 --- a/src/slic3r/GUI/Notebook.hpp +++ b/src/slic3r/GUI/Notebook.hpp @@ -9,7 +9,6 @@ #include -class ModeSizer; class ScalableButton; // custom message the ButtonsListCtrl sends to its parent (Notebook) to notify a selection change: @@ -18,15 +17,13 @@ wxDECLARE_EVENT(wxCUSTOMEVT_NOTEBOOK_SEL_CHANGED, wxCommandEvent); class ButtonsListCtrl : public wxControl { public: - ButtonsListCtrl(wxWindow* parent, bool add_mode_buttons = false); + ButtonsListCtrl(wxWindow* parent); ~ButtonsListCtrl() {} void OnPaint(wxPaintEvent&); void SetSelection(int sel); - void UpdateMode(); void Rescale(); void OnColorsChanged(); - void UpdateModeMarkers(); bool InsertPage(size_t n, const wxString& text, bool bSelect = false, const std::string& bmp_name = ""); void RemovePage(size_t n); bool SetPageImage(size_t n, const std::string& bmp_name) const; @@ -41,7 +38,6 @@ private: int m_selection {-1}; int m_btn_margin; int m_line_margin; - ModeSizer* m_mode_sizer {nullptr}; }; class Notebook: public wxBookCtrlBase @@ -51,24 +47,22 @@ public: wxWindowID winid = wxID_ANY, const wxPoint & pos = wxDefaultPosition, const wxSize & size = wxDefaultSize, - long style = 0, - bool add_mode_buttons = false) + long style = 0) { Init(); - Create(parent, winid, pos, size, style, add_mode_buttons); + Create(parent, winid, pos, size, style); } bool Create(wxWindow * parent, wxWindowID winid = wxID_ANY, const wxPoint & pos = wxDefaultPosition, const wxSize & size = wxDefaultSize, - long style = 0, - bool add_mode_buttons = false) + long style = 0) { if (!wxBookCtrlBase::Create(parent, winid, pos, size, style | wxBK_TOP)) return false; - m_bookctrl = new ButtonsListCtrl(this, add_mode_buttons); + m_bookctrl = new ButtonsListCtrl(this); wxSizer* mainSizer = new wxBoxSizer(IsVertical() ? wxVERTICAL : wxHORIZONTAL); @@ -241,11 +235,6 @@ public: ButtonsListCtrl* GetBtnsListCtrl() const { return static_cast(m_bookctrl); } - void UpdateMode() - { - GetBtnsListCtrl()->UpdateMode(); - } - void Rescale() { GetBtnsListCtrl()->Rescale(); @@ -256,11 +245,6 @@ public: GetBtnsListCtrl()->OnColorsChanged(); } - void UpdateModeMarkers() - { - GetBtnsListCtrl()->UpdateModeMarkers(); - } - void OnNavigationKey(wxNavigationKeyEvent& event) { if (event.IsWindowChange()) { diff --git a/src/slic3r/GUI/OptionsGroup.cpp b/src/slic3r/GUI/OptionsGroup.cpp index 71bcecdb12..5577c98352 100644 --- a/src/slic3r/GUI/OptionsGroup.cpp +++ b/src/slic3r/GUI/OptionsGroup.cpp @@ -11,12 +11,9 @@ ///|/ PrusaSlicer is released under the terms of the AGPLv3 or higher ///|/ #include "OptionsGroup.hpp" -#include "ConfigExceptions.hpp" -#include "Plater.hpp" +#include "Search.hpp" #include "GUI_App.hpp" -#include "MainFrame.hpp" #include "OG_CustomCtrl.hpp" -#include "MsgDialog.hpp" #include "format.hpp" #include @@ -271,7 +268,9 @@ Option::Option(const ConfigOptionDef& _opt, t_config_option_key id) : opt(_opt), tooltip = _L("Unavailable for this method.") + "\n"; tooltip += _(opt.tooltip); - edit_tooltip(tooltip); + // edit tooltip : change Slic3r to SLIC3R_APP_KEY + // Temporary workaround for localization + tooltip.Replace("Slic3r", SLIC3R_APP_KEY, true); opt.tooltip = into_u8(tooltip); } diff --git a/src/slic3r/GUI/Tab.cpp b/src/slic3r/GUI/Tab.cpp index 017de90fcd..26795a515b 100644 --- a/src/slic3r/GUI/Tab.cpp +++ b/src/slic3r/GUI/Tab.cpp @@ -67,7 +67,6 @@ #include "SavePresetDialog.hpp" #include "EditGCodeDialog.hpp" #include "MsgDialog.hpp" -//#include "Notebook.hpp" #include "TopBar.hpp" #include "Widgets/CheckBox.hpp" diff --git a/src/slic3r/GUI/Tab.hpp b/src/slic3r/GUI/Tab.hpp index 1c4ffed861..1266ff357b 100644 --- a/src/slic3r/GUI/Tab.hpp +++ b/src/slic3r/GUI/Tab.hpp @@ -475,7 +475,6 @@ class TabFilament : public Tab std::map m_overrides_options; public: TabFilament(wxBookCtrlBase* parent) : -// Tab(parent, _(L("Filament Settings")), Slic3r::Preset::TYPE_FILAMENT) {} Tab(parent, _L("Filaments"), Slic3r::Preset::TYPE_FILAMENT) {} ~TabFilament() {} @@ -534,7 +533,6 @@ public: PrinterTechnology m_printer_technology = ptFFF; TabPrinter(wxBookCtrlBase* parent) : -// Tab(parent, _L("Printer Settings"), Slic3r::Preset::TYPE_PRINTER) {} Tab(parent, _L("Printers"), Slic3r::Preset::TYPE_PRINTER) {} ~TabPrinter() {} @@ -573,7 +571,6 @@ class TabSLAMaterial : public Tab std::map m_overrides_options; public: TabSLAMaterial(wxBookCtrlBase* parent) : -// Tab(parent, _(L("Material Settings")), Slic3r::Preset::TYPE_SLA_MATERIAL) {} Tab(parent, _L("Materials"), Slic3r::Preset::TYPE_SLA_MATERIAL) {} ~TabSLAMaterial() {} diff --git a/src/slic3r/GUI/wxExtensions.cpp b/src/slic3r/GUI/wxExtensions.cpp index a0c73cdb01..5ab0bfca03 100644 --- a/src/slic3r/GUI/wxExtensions.cpp +++ b/src/slic3r/GUI/wxExtensions.cpp @@ -215,200 +215,6 @@ wxMenuItem* append_menu_check_item(wxMenu* menu, int id, const wxString& string, return item; } -const unsigned int wxCheckListBoxComboPopup::DefaultWidth = 200; -const unsigned int wxCheckListBoxComboPopup::DefaultHeight = 200; - -bool wxCheckListBoxComboPopup::Create(wxWindow* parent) -{ - return wxCheckListBox::Create(parent, wxID_HIGHEST + 1, wxPoint(0, 0)); -} - -wxWindow* wxCheckListBoxComboPopup::GetControl() -{ - return this; -} - -void wxCheckListBoxComboPopup::SetStringValue(const wxString& value) -{ - m_text = value; -} - -wxString wxCheckListBoxComboPopup::GetStringValue() const -{ - return m_text; -} - -wxSize wxCheckListBoxComboPopup::GetAdjustedSize(int minWidth, int prefHeight, int maxHeight) -{ - // set width dinamically in dependence of items text - // and set height dinamically in dependence of items count - - wxComboCtrl* cmb = GetComboCtrl(); - if (cmb != nullptr) { - wxSize size = GetComboCtrl()->GetSize(); - - unsigned int count = GetCount(); - if (count > 0) { - int max_width = size.x; - for (unsigned int i = 0; i < count; ++i) { - max_width = std::max(max_width, 60 + GetTextExtent(GetString(i)).x); - } - size.SetWidth(max_width); - size.SetHeight(count * cmb->GetCharHeight()); - } - else - size.SetHeight(DefaultHeight); - - return size; - } - else - return wxSize(DefaultWidth, DefaultHeight); -} - -void wxCheckListBoxComboPopup::OnKeyEvent(wxKeyEvent& evt) -{ - // filters out all the keys which are not working properly - switch (evt.GetKeyCode()) - { - case WXK_LEFT: - case WXK_UP: - case WXK_RIGHT: - case WXK_DOWN: - case WXK_PAGEUP: - case WXK_PAGEDOWN: - case WXK_END: - case WXK_HOME: - case WXK_NUMPAD_LEFT: - case WXK_NUMPAD_UP: - case WXK_NUMPAD_RIGHT: - case WXK_NUMPAD_DOWN: - case WXK_NUMPAD_PAGEUP: - case WXK_NUMPAD_PAGEDOWN: - case WXK_NUMPAD_END: - case WXK_NUMPAD_HOME: - { - break; - } - default: - { - evt.Skip(); - break; - } - } -} - -void wxCheckListBoxComboPopup::OnCheckListBox(wxCommandEvent& evt) -{ - // forwards the checklistbox event to the owner wxComboCtrl - - if (m_check_box_events_status == OnCheckListBoxFunction::FreeToProceed ) - { - wxComboCtrl* cmb = GetComboCtrl(); - if (cmb != nullptr) { - wxCommandEvent event(wxEVT_CHECKLISTBOX, cmb->GetId()); - event.SetEventObject(cmb); - cmb->ProcessWindowEvent(event); - } - } - - evt.Skip(); - - #ifndef _WIN32 // events are sent differently on OSX+Linux vs Win (more description in header file) - if ( m_check_box_events_status == OnCheckListBoxFunction::RefuseToProceed ) - // this happens if the event was resent by OnListBoxSelection - next call to OnListBoxSelection is due to user clicking the text, so the function should - // explicitly change the state on the checkbox - m_check_box_events_status = OnCheckListBoxFunction::WasRefusedLastTime; - else - // if the user clicked the checkbox square, this event was sent before OnListBoxSelection was called, so we don't want it to resend it - m_check_box_events_status = OnCheckListBoxFunction::RefuseToProceed; - #endif -} - -void wxCheckListBoxComboPopup::OnListBoxSelection(wxCommandEvent& evt) -{ - // transforms list box item selection event into checklistbox item toggle event - - int selId = GetSelection(); - if (selId != wxNOT_FOUND) - { - #ifndef _WIN32 - if (m_check_box_events_status == OnCheckListBoxFunction::RefuseToProceed) - #endif - Check((unsigned int)selId, !IsChecked((unsigned int)selId)); - - m_check_box_events_status = OnCheckListBoxFunction::FreeToProceed; // so the checkbox reacts to square-click the next time - - SetSelection(wxNOT_FOUND); - wxCommandEvent event(wxEVT_CHECKLISTBOX, GetId()); - event.SetInt(selId); - event.SetEventObject(this); - 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_ANY/*HIGHEST + 1*/, wxPoint(0, 0), wxDefaultSize/*wxSize(270, -1)*/, wxDV_NO_HEADER); -} -/* -wxSize wxDataViewTreeCtrlComboPopup::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(); - if (m_cnt_open_items > 0) - size.SetHeight(m_cnt_open_items * DefaultItemHeight); - else - size.SetHeight(DefaultHeight); - - return size; - } - else - 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); -} - -// edit tooltip : change Slic3r to SLIC3R_APP_KEY -// Temporary workaround for localization -void edit_tooltip(wxString& tooltip) -{ - tooltip.Replace("Slic3r", SLIC3R_APP_KEY, true); -} - /* Function for rescale of buttons in Dialog under MSW if dpi is changed. * btn_ids - vector of buttons identifiers */ @@ -636,196 +442,6 @@ void LockButton::update_button_bitmaps() Update(); } - - -// ---------------------------------------------------------------------------- -// ModeButton -// ---------------------------------------------------------------------------- - -ModeButton::ModeButton( wxWindow * parent, - wxWindowID id, - const std::string& icon_name /* = ""*/, - const wxString& mode /* = wxEmptyString*/, - const wxSize& size /* = wxDefaultSize*/, - const wxPoint& pos /* = wxDefaultPosition*/) : - ScalableButton(parent, id, icon_name, mode, size, pos, wxBU_EXACTFIT) -{ - Init(mode); -} - -ModeButton::ModeButton( wxWindow* parent, - const wxString& mode/* = wxEmptyString*/, - const std::string& icon_name/* = ""*/, - int px_cnt/* = 16*/) : - ScalableButton(parent, wxID_ANY, icon_name, mode, wxDefaultSize, wxDefaultPosition, wxBU_EXACTFIT, px_cnt) -{ - Init(mode); -} - -ModeButton::ModeButton( wxWindow* parent, - int mode_id,/*ConfigOptionMode*/ - const wxString& mode /*= wxEmptyString*/, - int px_cnt /*= = 16*/) : - ScalableButton(parent, wxID_ANY, "", mode, wxDefaultSize, wxDefaultPosition, wxBU_EXACTFIT, px_cnt), - m_mode_id(mode_id) -{ - update_bitmap(); - Init(mode); -} - -void ModeButton::Init(const wxString &mode) -{ - m_tt_focused = Slic3r::GUI::format_wxstr(_L("Switch to the %s mode"), mode); - m_tt_selected = Slic3r::GUI::format_wxstr(_L("Current mode is %s"), mode); - - SetBitmapMargins(3, 0); - - //button events - Bind(wxEVT_BUTTON, &ModeButton::OnButton, this); - Bind(wxEVT_ENTER_WINDOW, &ModeButton::OnEnterBtn, this); - Bind(wxEVT_LEAVE_WINDOW, &ModeButton::OnLeaveBtn, this); -} - -void ModeButton::OnButton(wxCommandEvent& event) -{ - m_is_selected = true; - focus_button(m_is_selected); - - event.Skip(); -} - -void ModeButton::SetState(const bool state) -{ - m_is_selected = state; - focus_button(m_is_selected); - SetToolTip(state ? m_tt_selected : m_tt_focused); -} - -void ModeButton::update_bitmap() -{ - m_bmp = *get_bmp_bundle("mode", m_bmp_width, m_bmp_height, Slic3r::GUI::wxGetApp().get_mode_btn_color(m_mode_id)); - - SetBitmap(m_bmp); - SetBitmapCurrent(m_bmp); - SetBitmapPressed(m_bmp); -} - -void ModeButton::focus_button(const bool focus) -{ - const wxFont& new_font = focus ? - Slic3r::GUI::wxGetApp().bold_font() : - Slic3r::GUI::wxGetApp().normal_font(); - - SetFont(new_font); -#ifdef _WIN32 - GetParent()->Refresh(); // force redraw a background of the selected mode button -#else - SetForegroundColour(wxSystemSettings::GetColour(focus ? wxSYS_COLOUR_BTNTEXT : -#if defined (__linux__) && defined (__WXGTK3__) - wxSYS_COLOUR_GRAYTEXT -#elif defined (__linux__) && defined (__WXGTK2__) - wxSYS_COLOUR_BTNTEXT -#else - wxSYS_COLOUR_BTNSHADOW -#endif - )); -#endif /* no _WIN32 */ - - Refresh(); - Update(); -} - -void ModeButton::sys_color_changed() -{ - Slic3r::GUI::wxGetApp().UpdateDarkUI(this, m_has_border); - update_bitmap(); -} - - -// ---------------------------------------------------------------------------- -// ModeSizer -// ---------------------------------------------------------------------------- - -ModeSizer::ModeSizer(wxWindow *parent, int hgap/* = 0*/) : - wxFlexGridSizer(3, 0, hgap), - m_hgap_unscaled((double)(hgap)/em_unit(parent)) -{ - SetFlexibleDirection(wxHORIZONTAL); - - auto modebtnfn = [this](wxCommandEvent &event, int mode_id) { - if (Slic3r::GUI::wxGetApp().save_mode(mode_id)) - event.Skip(); - else - SetMode(Slic3r::GUI::wxGetApp().get_mode()); - }; - - m_mode_btns.reserve(3); - int mode_id = 0; - for (const wxString& label : {_L("Simple"), _CTX(L_CONTEXT("Advanced", "Mode"), "Mode"),_L("Expert")}) { - m_mode_btns.push_back(new ModeButton(parent, mode_id++, label, mode_icon_px_size())); - - m_mode_btns.back()->Bind(wxEVT_BUTTON, std::bind(modebtnfn, std::placeholders::_1, int(m_mode_btns.size() - 1))); - Add(m_mode_btns.back()); - } -} - -void ModeSizer::SetMode(const int mode) -{ - for (size_t m = 0; m < m_mode_btns.size(); m++) - m_mode_btns[m]->SetState(int(m) == mode); -} - -void ModeSizer::set_items_flag(int flag) -{ - for (wxSizerItem* item : this->GetChildren()) - item->SetFlag(flag); -} - -void ModeSizer::set_items_border(int border) -{ - for (wxSizerItem* item : this->GetChildren()) - item->SetBorder(border); -} - -void ModeSizer::sys_color_changed() -{ - for (ModeButton* btn : m_mode_btns) - btn->sys_color_changed(); -} - -void ModeSizer::update_mode_markers() -{ - for (ModeButton* btn : m_mode_btns) - btn->update_bitmap(); -} - -// ---------------------------------------------------------------------------- -// MenuWithSeparators -// ---------------------------------------------------------------------------- - -void MenuWithSeparators::DestroySeparators() -{ - if (m_separator_frst) { - Destroy(m_separator_frst); - m_separator_frst = nullptr; - } - - if (m_separator_scnd) { - Destroy(m_separator_scnd); - m_separator_scnd = nullptr; - } -} - -void MenuWithSeparators::SetFirstSeparator() -{ - m_separator_frst = this->AppendSeparator(); -} - -void MenuWithSeparators::SetSecondSeparator() -{ - m_separator_scnd = this->AppendSeparator(); -} - // ---------------------------------------------------------------------------- // PrusaBitmap // ---------------------------------------------------------------------------- diff --git a/src/slic3r/GUI/wxExtensions.hpp b/src/slic3r/GUI/wxExtensions.hpp index 621d346915..d64e7abdf1 100644 --- a/src/slic3r/GUI/wxExtensions.hpp +++ b/src/slic3r/GUI/wxExtensions.hpp @@ -55,7 +55,6 @@ void enable_menu_item(wxUpdateUIEvent& evt, std::function const cb_condi class wxDialog; -void edit_tooltip(wxString& tooltip); void msw_buttons_rescale(wxDialog* dlg, const int em_unit, const std::vector& btn_ids, double height_koef = 1.); int em_unit(wxWindow* win); int mode_icon_px_size(); @@ -78,65 +77,6 @@ void apply_extruder_selector(Slic3r::GUI::BitmapComboBox** ctrl, wxSize size = wxDefaultSize, bool use_thin_icon = false); -class wxCheckListBoxComboPopup : public wxCheckListBox, public wxComboPopup -{ - static const unsigned int DefaultWidth; - static const unsigned int DefaultHeight; - - wxString m_text; - - // Events sent on mouseclick are quite complex. Function OnListBoxSelection is supposed to pass the event to the checkbox, which works fine on - // Win. On OSX and Linux the events are generated differently - clicking on the checkbox square generates the event twice (and the square - // therefore seems not to respond). - // This enum is meant to save current state of affairs, i.e., if the event forwarding is ok to do or not. It is only used on Linux - // and OSX by some #ifdefs. It also stores information whether OnListBoxSelection is supposed to change the checkbox status, - // or if it changed status on its own already (which happens when the square is clicked). More comments in OnCheckListBox(...) - // There indeed is a better solution, maybe making a custom event used for the event passing to distinguish the original and passed message - // and blocking one of them on OSX and Linux. Feel free to refactor, but carefully test on all platforms. - enum class OnCheckListBoxFunction{ - FreeToProceed, - RefuseToProceed, - WasRefusedLastTime - } m_check_box_events_status = OnCheckListBoxFunction::FreeToProceed; - - -public: - virtual bool Create(wxWindow* parent); - virtual wxWindow* GetControl(); - virtual void SetStringValue(const wxString& value); - 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); -}; - - -// *** 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{0}; - -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); - void SetItemsCnt(int cnt) { m_cnt_open_items = cnt; } -}; - inline wxSize get_preferred_size(const wxBitmapBundle& bmp, wxWindow* parent) { if (!bmp.IsOk()) @@ -288,111 +228,6 @@ protected: }; -// ---------------------------------------------------------------------------- -// ModeButton -// ---------------------------------------------------------------------------- - -class ModeButton : public ScalableButton -{ -public: - ModeButton( - wxWindow* parent, - wxWindowID id, - const std::string& icon_name = "", - const wxString& mode = wxEmptyString, - const wxSize& size = wxDefaultSize, - const wxPoint& pos = wxDefaultPosition); - - ModeButton( - wxWindow* parent, - const wxString& mode = wxEmptyString, - const std::string& icon_name = "", - int px_cnt = 16); - - ModeButton( - wxWindow* parent, - int mode_id,/*ConfigOptionMode*/ - const wxString& mode = wxEmptyString, - int px_cnt = 16); - - ~ModeButton() {} - - void Init(const wxString& mode); - - void OnButton(wxCommandEvent& event); - void OnEnterBtn(wxMouseEvent& event) { focus_button(true); event.Skip(); } - void OnLeaveBtn(wxMouseEvent& event) { focus_button(m_is_selected); event.Skip(); } - - void SetState(const bool state); - void update_bitmap(); - bool is_selected() { return m_is_selected; } - void sys_color_changed() override; - -protected: - void focus_button(const bool focus); - -private: - bool m_is_selected {false}; - int m_mode_id {-1}; - - wxString m_tt_selected; - wxString m_tt_focused; - wxBitmapBundle m_bmp; -}; - - - -// ---------------------------------------------------------------------------- -// ModeSizer -// ---------------------------------------------------------------------------- - -class ModeSizer : public wxFlexGridSizer -{ -public: - ModeSizer( wxWindow *parent, int hgap = 0); - ~ModeSizer() {} - - void SetMode(const /*ConfigOptionMode*/int mode); - - void set_items_flag(int flag); - void set_items_border(int border); - - void sys_color_changed(); - void update_mode_markers(); - const std::vector& get_btns() { return m_mode_btns; } - -private: - std::vector m_mode_btns; - double m_hgap_unscaled; -}; - - - -// ---------------------------------------------------------------------------- -// MenuWithSeparators -// ---------------------------------------------------------------------------- - -class MenuWithSeparators : public wxMenu -{ -public: - MenuWithSeparators(const wxString& title, long style = 0) - : wxMenu(title, style) {} - - MenuWithSeparators(long style = 0) - : wxMenu(style) {} - - ~MenuWithSeparators() {} - - void DestroySeparators(); - void SetFirstSeparator(); - void SetSecondSeparator(); - -private: - wxMenuItem* m_separator_frst { nullptr }; // use like separator before settings item - wxMenuItem* m_separator_scnd { nullptr }; // use like separator between settings items -}; - - // ---------------------------------------------------------------------------- // BlinkingBitmap // ----------------------------------------------------------------------------