Fixed strange behavior of Text- and Spin- control on KillFocus event

This commit is contained in:
YuSanka 2018-01-31 14:59:44 +01:00
parent 667ffa6101
commit 54dbc916a8
5 changed files with 27 additions and 20 deletions

View file

@ -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<wxWindow*>(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

View file

@ -23,7 +23,7 @@ namespace Slic3r { namespace GUI {
class Field;
using t_field = std::unique_ptr<Field>;
using t_kill_focus = std::function<void(t_config_option_key)>;
using t_kill_focus = std::function<void()>;
using t_change = std::function<void(t_config_option_key, boost::any)>;
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};

View file

@ -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)) {

View file

@ -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

View file

@ -1,4 +1,5 @@
#include <vector>
#include <string>
namespace Slic3r {
class DynamicPrintConfig;
@ -23,8 +24,8 @@ public:
void load_key_value(char* opt_key, char* value);
bool current_preset_is_dirty();
DynamicPrintConfig* get_config();
PresetCollection* TabIface::get_presets();
std::vector<std::string> TabIface::get_dependent_tabs();
PresetCollection* get_presets();
std::vector<std::string> get_dependent_tabs();
protected:
GUI::Tab *m_tab;