Fixed non-correct TextCtrl's update on wxEVT_KILL_FOCUS (partially related to #3482),

when for Parameter validation dialog "Selecting NO caused no change".

OSX:TextCtrl:wxEVT_KILL_FOCUS: Second call is suppressed

+ Under OSX set a little bit more wider width for Fields
This commit is contained in:
YuSanka 2020-02-18 11:09:28 +01:00
parent 1850685431
commit d1e3435956
2 changed files with 34 additions and 11 deletions

View File

@ -79,6 +79,11 @@ void Field::PostInitialize()
BUILD();
}
// Values of width to alignments of fields
int Field::def_width() { return wxOSX ? 8 : 7; }
int Field::def_width_wider() { return 14; }
int Field::def_width_thinner() { return 4; }
void Field::on_kill_focus()
{
// call the registered function if it is available
@ -240,6 +245,8 @@ void Field::get_value_by_opt_type(wxString& str, const bool check_value/* = true
set_value(wxString::Format("%s%%", stVal), false/*true*/);
str += "%%";
}
else
set_value(stVal, false); // it's no needed but can be helpful, when inputted value contained "," instead of "."
}
}
@ -367,13 +374,22 @@ void TextCtrl::BUILD() {
temp->Bind(wxEVT_KILL_FOCUS, ([this, temp](wxEvent& e)
{
e.Skip();
#ifdef __WXOSX__
// OSX issue: For some unknown reason wxEVT_KILL_FOCUS is emitted twice in a row
// Thus, suppress its second call
if (bKilledFocus) {
bKilledFocus = false;
return;
}
bKilledFocus = true;
#endif // __WXOSX__
#if !defined(__WXGTK__)
temp->GetToolTip()->Enable(true);
#endif // __WXGTK__
if (bEnterPressed) {
if (bEnterPressed)
bEnterPressed = false;
return;
}
else
propagate_value();
}), temp->GetId());
@ -423,10 +439,12 @@ bool TextCtrl::value_was_changed()
void TextCtrl::propagate_value()
{
if (is_defined_input_value<wxTextCtrl>(window, m_opt.type) && value_was_changed())
on_change_field();
else
if (!is_defined_input_value<wxTextCtrl>(window, m_opt.type) )
// on_kill_focus() cause a call of OptionsGroup::reload_config(),
// Thus, do it only when it's really needed (when undefined value was input)
on_kill_focus();
else if (value_was_changed())
on_change_field();
}
void TextCtrl::set_value(const boost::any& value, bool change_event/* = false*/) {

View File

@ -225,10 +225,10 @@ public:
bool get_enter_pressed() const { return bEnterPressed; }
void set_enter_pressed(bool pressed) { bEnterPressed = pressed; }
// Values of width to "systematic" alignments of fields
static int def_width() { return 7; }
static int def_width_wider() { return 14; }
static int def_width_thinner() { return 4; }
// Values of width to alignments of fields
static int def_width() ;
static int def_width_wider() ;
static int def_width_thinner() ;
protected:
RevertButton* m_Undo_btn = nullptr;
@ -274,6 +274,11 @@ class TextCtrl : public Field {
bool bChangedValueEvent = true;
void change_field_value(wxEvent& event);
#endif //__WXGTK__
#ifdef __WXOSX__
bool bKilledFocus = false;
#endif // __WXOSX__
public:
TextCtrl(const ConfigOptionDef& opt, const t_config_option_key& id) : Field(opt, id) {}
TextCtrl(wxWindow* parent, const ConfigOptionDef& opt, const t_config_option_key& id) : Field(parent, opt, id) {}