From e1cea03cda35418603c948f982e300b2ec9c7d1a Mon Sep 17 00:00:00 2001 From: YuSanka Date: Tue, 11 Dec 2018 13:57:50 +0100 Subject: [PATCH] Added template for the handle of the TextCtrl's focus event --- src/slic3r/GUI/Field.cpp | 11 +++++++++++ src/slic3r/GUI/Field.hpp | 5 +++++ src/slic3r/GUI/GLCanvas3D.hpp | 2 ++ src/slic3r/GUI/GUI_ObjectManipulation.cpp | 5 +++++ src/slic3r/GUI/OptionsGroup.cpp | 11 +++++++++++ src/slic3r/GUI/OptionsGroup.hpp | 2 ++ 6 files changed, 36 insertions(+) diff --git a/src/slic3r/GUI/Field.cpp b/src/slic3r/GUI/Field.cpp index 29218eaf6..ebc7f3665 100644 --- a/src/slic3r/GUI/Field.cpp +++ b/src/slic3r/GUI/Field.cpp @@ -77,6 +77,15 @@ void Field::on_kill_focus(wxEvent& event) m_on_kill_focus(m_opt_id); } +void Field::on_set_focus(wxEvent& event) +{ + // to allow the default behavior + event.Skip(); + // call the registered function if it is available + if (m_on_set_focus!=nullptr) + m_on_set_focus(m_opt_id); +} + void Field::on_change_field() { // std::cerr << "calling Field::_on_change \n"; @@ -220,6 +229,8 @@ void TextCtrl::BUILD() { auto temp = new wxTextCtrl(m_parent, wxID_ANY, text_value, wxDefaultPosition, size, style); temp->SetToolTip(get_tooltip_text(text_value)); + + temp->Bind(wxEVT_SET_FOCUS, ([this](wxEvent& e) { on_set_focus(e); }), temp->GetId()); temp->Bind(wxEVT_LEFT_DOWN, ([temp](wxEvent& event) { diff --git a/src/slic3r/GUI/Field.hpp b/src/slic3r/GUI/Field.hpp index 66a71b34d..0097d3ec0 100644 --- a/src/slic3r/GUI/Field.hpp +++ b/src/slic3r/GUI/Field.hpp @@ -76,6 +76,8 @@ protected: //! in another case we can't unfocused control at all void on_kill_focus(wxEvent& event); /// Call the attached on_change method. + void on_set_focus(wxEvent& event); + /// Call the attached on_change method. void on_change_field(); /// Call the attached m_back_to_initial_value method. void on_back_to_initial_value(); @@ -89,6 +91,9 @@ public: /// Function object to store callback passed in from owning object. t_kill_focus m_on_kill_focus {nullptr}; + /// Function object to store callback passed in from owning object. + t_kill_focus m_on_set_focus {nullptr}; + /// Function object to store callback passed in from owning object. t_change m_on_change {nullptr}; diff --git a/src/slic3r/GUI/GLCanvas3D.hpp b/src/slic3r/GUI/GLCanvas3D.hpp index 3076e3c5d..fc284c595 100644 --- a/src/slic3r/GUI/GLCanvas3D.hpp +++ b/src/slic3r/GUI/GLCanvas3D.hpp @@ -971,6 +971,8 @@ public: void viewport_changed(); #endif // ENABLE_CONSTRAINED_CAMERA_TARGET + void handle_sidebar_focus_event(const std::string& opt_key) {} + private: bool _is_shown_on_screen() const; void _force_zoom_to_bed(); diff --git a/src/slic3r/GUI/GUI_ObjectManipulation.cpp b/src/slic3r/GUI/GUI_ObjectManipulation.cpp index d12aabf9e..d193a11a9 100644 --- a/src/slic3r/GUI/GUI_ObjectManipulation.cpp +++ b/src/slic3r/GUI/GUI_ObjectManipulation.cpp @@ -71,6 +71,11 @@ ObjectManipulation::ObjectManipulation(wxWindow* parent) : m_og->set_value(opt_key, double_to_string(0.0)); }; + m_og->m_set_focus = [this](const std::string& opt_key) + { + wxGetApp().plater()->canvas3D()->handle_sidebar_focus_event(opt_key); + }; + ConfigOptionDef def; // Objects(sub-objects) name diff --git a/src/slic3r/GUI/OptionsGroup.cpp b/src/slic3r/GUI/OptionsGroup.cpp index 512bcb4ac..4701ae20b 100644 --- a/src/slic3r/GUI/OptionsGroup.cpp +++ b/src/slic3r/GUI/OptionsGroup.cpp @@ -78,6 +78,11 @@ const t_field& OptionsGroup::build_field(const t_config_option_key& id, const Co if (!m_disabled) this->on_kill_focus(opt_id); }; + field->m_on_set_focus = [this](const std::string& opt_id) { + //! This function will be called from Field. + if (!m_disabled) + this->on_set_focus(opt_id); + }; field->m_parent = parent(); //! Label to change background color, when option is modified @@ -277,6 +282,12 @@ Line OptionsGroup::create_single_option_line(const Option& option) const { return retval; } +void OptionsGroup::on_set_focus(const std::string& opt_key) +{ + if (m_set_focus != nullptr) + m_set_focus(opt_key); +} + void OptionsGroup::on_change_OG(const t_config_option_key& opt_id, const boost::any& value) { if (m_on_change != nullptr) m_on_change(opt_id, value); diff --git a/src/slic3r/GUI/OptionsGroup.hpp b/src/slic3r/GUI/OptionsGroup.hpp index e80324628..9097dcab6 100644 --- a/src/slic3r/GUI/OptionsGroup.hpp +++ b/src/slic3r/GUI/OptionsGroup.hpp @@ -87,6 +87,7 @@ public: column_t extra_column {nullptr}; t_change m_on_change { nullptr }; t_kill_focus m_fill_empty_value { nullptr }; + t_kill_focus m_set_focus { nullptr }; std::function m_get_initial_config{ nullptr }; std::function m_get_sys_config{ nullptr }; std::function have_sys_config{ nullptr }; @@ -210,6 +211,7 @@ protected: void add_undo_buttuns_to_sizer(wxSizer* sizer, const t_field& field); virtual void on_kill_focus(const std::string& opt_key) {}; + virtual void on_set_focus(const std::string& opt_key); virtual void on_change_OG(const t_config_option_key& opt_id, const boost::any& value); virtual void back_to_initial_value(const std::string& opt_key) {} virtual void back_to_sys_value(const std::string& opt_key) {}