Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/prusa3d/PrusaSlicer.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuSanka <yusanka@gmail.com>2019-01-08 18:05:49 +0300
committerYuSanka <yusanka@gmail.com>2019-01-08 18:06:58 +0300
commit6efcdd1ddf5bd57b110370cc314f275cded3fb2d (patch)
tree89cd4960ccd6375abf554d0767a330945bb54b75 /src/slic3r/GUI/Field.cpp
parent2ccdfe68531265a51f6f5a7a8788cdbdf765b74f (diff)
Added wxEVT_TEXT_ENTER handling for TextCtrl, SpinCtrl & PointCtrl (but it doesn't work under OSX) (fix of #1518)
Diffstat (limited to 'src/slic3r/GUI/Field.cpp')
-rw-r--r--src/slic3r/GUI/Field.cpp97
1 files changed, 63 insertions, 34 deletions
diff --git a/src/slic3r/GUI/Field.cpp b/src/slic3r/GUI/Field.cpp
index 91052570d..2c7bce613 100644
--- a/src/slic3r/GUI/Field.cpp
+++ b/src/slic3r/GUI/Field.cpp
@@ -66,12 +66,8 @@ void Field::PostInitialize()
BUILD();
}
-void Field::on_kill_focus(wxEvent& event)
+void Field::on_kill_focus()
{
- // 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();
// call the registered function if it is available
if (m_on_kill_focus!=nullptr)
m_on_kill_focus(m_opt_id);
@@ -250,11 +246,23 @@ void TextCtrl::BUILD() {
break;
}
- const long style = m_opt.multiline ? wxTE_MULTILINE : 0;
+ const long style = m_opt.multiline ? wxTE_MULTILINE : wxTE_PROCESS_ENTER/*0*/;
auto temp = new wxTextCtrl(m_parent, wxID_ANY, text_value, wxDefaultPosition, size, style);
temp->SetToolTip(get_tooltip_text(text_value));
+ if (style == wxTE_PROCESS_ENTER) {
+ temp->Bind(wxEVT_TEXT_ENTER, ([this, temp](wxEvent& e)
+ {
+#if !defined(__WXGTK__)
+ e.Skip();
+ temp->GetToolTip()->Enable(true);
+#endif // __WXGTK__
+ propagate_value();
+ bEnterPressed = true;
+ }), temp->GetId());
+ }
+
temp->Bind(wxEVT_SET_FOCUS, ([this](wxEvent& e) { on_set_focus(e); }), temp->GetId());
temp->Bind(wxEVT_LEFT_DOWN, ([temp](wxEvent& event)
@@ -272,14 +280,15 @@ void TextCtrl::BUILD() {
temp->Bind(wxEVT_KILL_FOCUS, ([this, temp](wxEvent& e)
{
-#if !defined(__WXGTK__)
e.Skip();
+#if !defined(__WXGTK__)
temp->GetToolTip()->Enable(true);
#endif // __WXGTK__
- if (is_defined_input_value<wxTextCtrl>(window, m_opt.type))
- on_change_field();
- else
- on_kill_focus(e);
+ if (bEnterPressed) {
+ bEnterPressed = false;
+ return;
+ }
+ propagate_value();
}), temp->GetId());
/*
temp->Bind(wxEVT_TEXT, ([this](wxCommandEvent& evt)
@@ -311,6 +320,14 @@ void TextCtrl::BUILD() {
window = dynamic_cast<wxWindow*>(temp);
}
+void TextCtrl::propagate_value()
+{
+ if (is_defined_input_value<wxTextCtrl>(window, m_opt.type))
+ on_change_field();
+ else
+ on_kill_focus();
+}
+
boost::any& TextCtrl::get_value()
{
wxString ret_str = static_cast<wxTextCtrl*>(window)->GetValue();
@@ -398,7 +415,7 @@ void SpinCtrl::BUILD() {
const int max_val = m_opt.max < 2147483647 ? m_opt.max : 2147483647;
auto temp = new wxSpinCtrl(m_parent, wxID_ANY, text_value, wxDefaultPosition, size,
- 0, min_val, max_val, default_value);
+ 0|wxTE_PROCESS_ENTER, min_val, max_val, default_value);
#ifndef __WXOSX__
// #ys_FIXME_KILL_FOCUS
@@ -407,15 +424,23 @@ void SpinCtrl::BUILD() {
// and on TEXT event under OSX
temp->Bind(wxEVT_KILL_FOCUS, ([this](wxEvent& e)
{
- if (tmp_value < 0)
- on_kill_focus(e);
- else {
- e.Skip();
- on_change_field();
+ e.Skip();
+ if (bEnterPressed) {
+ bEnterPressed = false;
+ return;
}
+
+ propagate_value();
}), temp->GetId());
- temp->Bind(wxEVT_SPINCTRL, ([this](wxCommandEvent e) { on_change_field(); }), temp->GetId());
+ temp->Bind(wxEVT_SPINCTRL, ([this](wxCommandEvent e) { on_change_field(); }), temp->GetId());
+
+ temp->Bind(wxEVT_TEXT_ENTER, ([this](wxCommandEvent e)
+ {
+ e.Skip();
+ propagate_value();
+ bEnterPressed = true;
+ }), temp->GetId());
#endif
temp->Bind(wxEVT_TEXT, ([this](wxCommandEvent e)
@@ -430,12 +455,7 @@ void SpinCtrl::BUILD() {
tmp_value = std::stoi(value);
else tmp_value = -9999;
#ifdef __WXOSX__
- if (tmp_value < 0) {
- if (m_on_kill_focus != nullptr)
- m_on_kill_focus(m_opt_id);
- }
- else
- on_change_field();
+ propagate_value();
#endif
}), temp->GetId());
@@ -445,6 +465,14 @@ void SpinCtrl::BUILD() {
window = dynamic_cast<wxWindow*>(temp);
}
+void SpinCtrl::propagate_value()
+{
+ if (tmp_value < 0)
+ on_kill_focus();
+ else
+ on_change_field();
+}
+
void Choice::BUILD() {
auto size = wxSize(wxDefaultSize);
if (m_opt.height >= 0) size.SetHeight(m_opt.height);
@@ -483,7 +511,7 @@ void Choice::BUILD() {
on_change_field();
}
else
- on_kill_focus(e);
+ on_kill_focus();
}), temp->GetId());
}
@@ -755,8 +783,8 @@ void PointCtrl::BUILD()
val = default_pt(1);
wxString Y = val - int(val) == 0 ? wxString::Format(_T("%i"), int(val)) : wxNumberFormatter::ToString(val, 2, wxNumberFormatter::Style_None);
- x_textctrl = new wxTextCtrl(m_parent, wxID_ANY, X, wxDefaultPosition, field_size);
- y_textctrl = new wxTextCtrl(m_parent, wxID_ANY, Y, wxDefaultPosition, field_size);
+ x_textctrl = new wxTextCtrl(m_parent, wxID_ANY, X, wxDefaultPosition, field_size, wxEVT_TEXT_ENTER);
+ y_textctrl = new wxTextCtrl(m_parent, wxID_ANY, Y, wxDefaultPosition, field_size, wxEVT_TEXT_ENTER);
temp->Add(new wxStaticText(m_parent, wxID_ANY, "x : "), 0, wxALIGN_CENTER_VERTICAL, 0);
temp->Add(x_textctrl);
@@ -766,8 +794,11 @@ void PointCtrl::BUILD()
// x_textctrl->Bind(wxEVT_TEXT, ([this](wxCommandEvent e) { on_change_field(); }), x_textctrl->GetId());
// y_textctrl->Bind(wxEVT_TEXT, ([this](wxCommandEvent e) { on_change_field(); }), y_textctrl->GetId());
- x_textctrl->Bind(wxEVT_KILL_FOCUS, ([this](wxEvent& e) { OnKillFocus(e, x_textctrl); }), x_textctrl->GetId());
- y_textctrl->Bind(wxEVT_KILL_FOCUS, ([this](wxEvent& e) { OnKillFocus(e, x_textctrl); }), y_textctrl->GetId());
+ x_textctrl->Bind(wxEVT_TEXT_ENTER, ([this](wxCommandEvent e) { propagate_value(x_textctrl); }), x_textctrl->GetId());
+ y_textctrl->Bind(wxEVT_TEXT_ENTER, ([this](wxCommandEvent e) { propagate_value(y_textctrl); }), y_textctrl->GetId());
+
+ x_textctrl->Bind(wxEVT_KILL_FOCUS, ([this](wxEvent& e) { e.Skip(); propagate_value(x_textctrl); }), x_textctrl->GetId());
+ y_textctrl->Bind(wxEVT_KILL_FOCUS, ([this](wxEvent& e) { e.Skip(); propagate_value(y_textctrl); }), y_textctrl->GetId());
// // recast as a wxWindow to fit the calling convention
sizer = dynamic_cast<wxSizer*>(temp);
@@ -776,14 +807,12 @@ void PointCtrl::BUILD()
y_textctrl->SetToolTip(get_tooltip_text(X+", "+Y));
}
-void PointCtrl::OnKillFocus(wxEvent& e, wxTextCtrl* win)
+void PointCtrl::propagate_value(wxTextCtrl* win)
{
- e.Skip();
- if (!win->GetValue().empty()) {
+ if (!win->GetValue().empty())
on_change_field();
- }
else
- on_kill_focus(e);
+ on_kill_focus();
}
void PointCtrl::set_value(const Vec2d& value, bool change_event)