diff --git a/xs/src/slic3r/GUI/Field.cpp b/xs/src/slic3r/GUI/Field.cpp index c0e907be3..63dee1be3 100644 --- a/xs/src/slic3r/GUI/Field.cpp +++ b/xs/src/slic3r/GUI/Field.cpp @@ -9,15 +9,15 @@ namespace Slic3r { namespace GUI { - void Field::_on_kill_focus(wxFocusEvent& event) { + void Field::on_kill_focus(wxEvent& event) { // Without this, there will be nasty focus bugs on Windows. // Also, docs for wxEvent::Skip() say "In general, it is recommended to skip all // non-command events to allow the default handling to take place." - event.Skip(1); - + event.Skip(); + std::cerr << "calling Field::on_kill_focus from " << m_opt_id<< "\n"; // call the registered function if it is available - if (on_kill_focus) - on_kill_focus(m_opt_id); + if (m_on_kill_focus!=nullptr) + m_on_kill_focus(); } void Field::on_change_field(wxCommandEvent& event) { // std::cerr << "calling Field::_on_change \n"; @@ -146,7 +146,8 @@ namespace Slic3r { namespace GUI { temp->SetToolTip(get_tooltip_text(text_value)); temp->Bind(wxEVT_TEXT, ([=](wxCommandEvent e) { on_change_field(e); }), temp->GetId()); - temp->Bind(wxEVT_KILL_FOCUS, ([this](wxFocusEvent e) { _on_kill_focus(e); }), temp->GetId()); + + temp->Bind(wxEVT_KILL_FOCUS, ([this](wxEvent& e) { on_kill_focus(e); }), temp->GetId()); // recast as a wxWindow to fit the calling convention window = dynamic_cast(temp); @@ -228,7 +229,7 @@ void SpinCtrl::BUILD() { 0, m_opt.min >0 ? m_opt.min : 0, m_opt.max < 2147483647 ? m_opt.max : 2147483647, default_value); temp->Bind(wxEVT_SPINCTRL, ([=](wxCommandEvent e) { tmp_value = undef_spin_val; on_change_field(e); }), temp->GetId()); - temp->Bind(wxEVT_KILL_FOCUS, ([this](wxFocusEvent e) { tmp_value = undef_spin_val; _on_kill_focus(e); }), temp->GetId()); + temp->Bind(wxEVT_KILL_FOCUS, ([this](wxEvent& e) { tmp_value = undef_spin_val; on_kill_focus(e); }), temp->GetId()); temp->Bind(wxEVT_TEXT, ([=](wxCommandEvent e) { // # On OSX / Cocoa, wxSpinCtrl::GetValue() doesn't return the new value diff --git a/xs/src/slic3r/GUI/Field.hpp b/xs/src/slic3r/GUI/Field.hpp index 21f5dba45..7f22785ae 100644 --- a/xs/src/slic3r/GUI/Field.hpp +++ b/xs/src/slic3r/GUI/Field.hpp @@ -23,7 +23,7 @@ namespace Slic3r { namespace GUI { class Field; using t_field = std::unique_ptr; -using t_kill_focus = std::function; +using t_kill_focus = std::function; using t_change = std::function; class Field { @@ -35,7 +35,9 @@ protected: virtual void BUILD() = 0; /// Call the attached on_kill_focus method. - void _on_kill_focus(wxFocusEvent& event); + //! It's important to use wxEvent instead of wxFocusEvent, + //! in another case we can't unfocused control at all + void on_kill_focus(wxEvent& event); /// Call the attached on_change method. void on_change_field(wxCommandEvent& event); @@ -44,7 +46,7 @@ public: wxWindow* m_parent {nullptr}; /// Function object to store callback passed in from owning object. - t_kill_focus on_kill_focus {nullptr}; + t_kill_focus m_on_kill_focus {nullptr}; /// Function object to store callback passed in from owning object. t_change m_on_change {nullptr}; diff --git a/xs/src/slic3r/GUI/OptionsGroup.cpp b/xs/src/slic3r/GUI/OptionsGroup.cpp index 8f5051b36..7f3b4ee66 100644 --- a/xs/src/slic3r/GUI/OptionsGroup.cpp +++ b/xs/src/slic3r/GUI/OptionsGroup.cpp @@ -67,6 +67,11 @@ const t_field& OptionsGroup::build_field(const t_config_option_key& id, const Co if (!this->m_disabled) this->on_change_OG(opt_id, value); }; + field->m_on_kill_focus = [this](){ + //! This function will be called from Field. + if (!this->m_disabled) + this->on_kill_focus(); + }; field->m_parent = parent(); // assign function objects for callbacks, etc. return field; @@ -194,10 +199,6 @@ void OptionsGroup::on_change_OG(t_config_option_key id, /*config_value*/boost::a m_on_change(id, value); } -void OptionsGroup::_on_kill_focus (t_config_option_key id) { - // do nothing. -} - Option ConfigOptionsGroup::get_option(const std::string opt_key, int opt_index /*= -1*/) { if (!m_config->has(opt_key)) { diff --git a/xs/src/slic3r/GUI/OptionsGroup.hpp b/xs/src/slic3r/GUI/OptionsGroup.hpp index 0aaee59e3..42b0b5344 100644 --- a/xs/src/slic3r/GUI/OptionsGroup.hpp +++ b/xs/src/slic3r/GUI/OptionsGroup.hpp @@ -11,8 +11,6 @@ #include "libslic3r/libslic3r.h" #include "Field.hpp" -//#include "slic3r_gui.hpp" -#include "GUI.hpp" // Translate the ifdef #ifdef __WXOSX__ @@ -129,7 +127,7 @@ protected: const t_field& build_field(const t_config_option_key& id); const t_field& build_field(const Option& opt); - virtual void _on_kill_focus (t_config_option_key id); + virtual void on_kill_focus (){}; virtual void on_change_OG(t_config_option_key opt_id, boost::any value); }; @@ -158,6 +156,10 @@ public: } void on_change_OG(t_config_option_key opt_id, boost::any value) override; + void on_kill_focus() override + { + reload_config(); + } void reload_config(); boost::any config_value(std::string opt_key, int opt_index, bool deserialize); // return option value from config diff --git a/xs/src/slic3r/GUI/TabIface.hpp b/xs/src/slic3r/GUI/TabIface.hpp index 2b5bfce9a..8c07ba90a 100644 --- a/xs/src/slic3r/GUI/TabIface.hpp +++ b/xs/src/slic3r/GUI/TabIface.hpp @@ -1,4 +1,5 @@ #include +#include namespace Slic3r { class DynamicPrintConfig; @@ -22,9 +23,9 @@ public: void load_config(DynamicPrintConfig* config); void load_key_value(char* opt_key, char* value); bool current_preset_is_dirty(); - DynamicPrintConfig* get_config(); - PresetCollection* TabIface::get_presets(); - std::vector TabIface::get_dependent_tabs(); + DynamicPrintConfig* get_config(); + PresetCollection* get_presets(); + std::vector get_dependent_tabs(); protected: GUI::Tab *m_tab;