From 77f845b0be1e42c3f45c093c023ac1c4682ea4e5 Mon Sep 17 00:00:00 2001 From: YuSanka Date: Tue, 24 Nov 2020 18:44:13 +0100 Subject: [PATCH] Added a possibility to suppress scrolling for some ComboBoxes --- src/slic3r/GUI/Field.cpp | 31 ++++++++++++++++++++++++++++--- src/slic3r/GUI/Field.hpp | 7 ++++++- src/slic3r/GUI/Plater.cpp | 3 +++ 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/src/slic3r/GUI/Field.cpp b/src/slic3r/GUI/Field.cpp index a92a98844..a0176ad4a 100644 --- a/src/slic3r/GUI/Field.cpp +++ b/src/slic3r/GUI/Field.cpp @@ -862,7 +862,19 @@ void Choice::BUILD() { #endif // temp->Bind(wxEVT_TEXT, ([this](wxCommandEvent e) { on_change_field(); }), temp->GetId()); - temp->Bind(wxEVT_COMBOBOX, ([this](wxCommandEvent e) { on_change_field(); }), temp->GetId()); + temp->Bind(wxEVT_COMBOBOX_DROPDOWN, [this](wxCommandEvent&) { m_is_dropped = true; }); + temp->Bind(wxEVT_COMBOBOX_CLOSEUP, [this](wxCommandEvent&) { m_is_dropped = false; }); + + temp->Bind(wxEVT_COMBOBOX, ([this, temp](wxCommandEvent evt) { + if (m_suppress_scroll) { + if (!m_is_dropped) { + temp->SetSelection(m_last_selected); + return; + } + m_last_selected = evt.GetSelection(); + } + on_change_field(); + }), temp->GetId()); if (m_is_editable) { temp->Bind(wxEVT_KILL_FOCUS, ([this](wxEvent& e) { @@ -876,8 +888,7 @@ void Choice::BUILD() { if (is_defined_input_value(window, m_opt.type)) { if (fabs(old_val - boost::any_cast(get_value())) <= 0.0001) return; - else - on_change_field(); + on_change_field(); } else on_kill_focus(); @@ -887,6 +898,13 @@ void Choice::BUILD() { temp->SetToolTip(get_tooltip_text(temp->GetValue())); } +void Choice::suppress_scroll() +{ + m_suppress_scroll = true; + choice_ctrl* ctrl = dynamic_cast(window); + m_last_selected = ctrl->GetSelection(); +} + void Choice::set_selection() { /* To prevent earlier control updating under OSX set m_disable_change_event to true @@ -901,6 +919,7 @@ void Choice::set_selection() case coEnum:{ int id_value = m_opt.get_default_value>()->value; //!! field->SetSelection(id_value); + if (m_suppress_scroll) m_last_selected = id_value; break; } case coFloat: @@ -934,6 +953,8 @@ void Choice::set_selection() ++idx; } idx == m_opt.enum_values.size() ? field->SetValue(text_value) : field->SetSelection(idx); + + if (m_suppress_scroll && idx < m_opt.enum_values.size()) m_last_selected = idx; } } @@ -953,6 +974,7 @@ void Choice::set_value(const std::string& value, bool change_event) //! Redunda idx == m_opt.enum_values.size() ? field->SetValue(value) : field->SetSelection(idx); + if (m_suppress_scroll && idx < m_opt.enum_values.size()) m_last_selected = idx; m_disable_change_event = false; } @@ -990,6 +1012,7 @@ void Choice::set_value(const boost::any& value, bool change_event) } else field->SetSelection(idx); + if (m_suppress_scroll && idx < m_opt.enum_values.size()) m_last_selected = idx; break; } case coEnum: { @@ -1020,6 +1043,7 @@ void Choice::set_value(const boost::any& value, bool change_event) val = 0; } field->SetSelection(val); + if (m_suppress_scroll) m_last_selected = val; break; } default: @@ -1179,6 +1203,7 @@ void Choice::msw_rescale() idx == m_opt.enum_values.size() ? field->SetValue(selection) : field->SetSelection(idx); + if (m_suppress_scroll && idx < m_opt.enum_values.size()) m_last_selected = idx; #else auto size = wxSize(def_width_wider() * m_em_unit, wxDefaultCoord); if (m_opt.height >= 0) size.SetHeight(m_opt.height * m_em_unit); diff --git a/src/slic3r/GUI/Field.hpp b/src/slic3r/GUI/Field.hpp index b4bcf9f33..6cadb607d 100644 --- a/src/slic3r/GUI/Field.hpp +++ b/src/slic3r/GUI/Field.hpp @@ -385,7 +385,10 @@ public: /* Under OSX: wxBitmapComboBox->GetWindowStyle() returns some weard value, * so let use a flag, which has TRUE value for a control without wxCB_READONLY style */ - bool m_is_editable { false }; + bool m_is_editable { false }; + bool m_is_dropped { false }; + bool m_suppress_scroll { false }; + int m_last_selected { wxNOT_FOUND }; void set_selection(); void set_value(const std::string& value, bool change_event = false); @@ -399,6 +402,8 @@ public: void enable() override ;//{ dynamic_cast(window)->Enable(); }; void disable() override;//{ dynamic_cast(window)->Disable(); }; wxWindow* getWindow() override { return window; } + + void suppress_scroll(); }; class ColourPicker : public Field { diff --git a/src/slic3r/GUI/Plater.cpp b/src/slic3r/GUI/Plater.cpp index 763a906f5..c2facfc06 100644 --- a/src/slic3r/GUI/Plater.cpp +++ b/src/slic3r/GUI/Plater.cpp @@ -439,6 +439,9 @@ FreqChangedParams::FreqChangedParams(wxWindow* parent) : m_og->activate(); + Choice* choice = dynamic_cast(m_og->get_field("support")); + choice->suppress_scroll(); + // Frequently changed parameters for SLA_technology m_og_sla = std::make_shared(parent, ""); m_og_sla->hide_labels();