fix issue where value of spinbox wouldn't update in text_changed
This commit is contained in:
parent
8182d93b9a
commit
40030f7740
@ -25,25 +25,6 @@ namespace nana
|
||||
{
|
||||
namespace spinbox
|
||||
{
|
||||
|
||||
class event_agent
|
||||
: public widgets::skeletons::textbase_event_agent_interface
|
||||
{
|
||||
public:
|
||||
event_agent(::nana::spinbox& wdg)
|
||||
: widget_(wdg)
|
||||
{}
|
||||
|
||||
void first_change() override{} //empty, because spinbox does not have this event.
|
||||
|
||||
void text_changed() override
|
||||
{
|
||||
widget_.events().text_changed.emit(::nana::arg_spinbox{ widget_ }, widget_.handle());
|
||||
}
|
||||
private:
|
||||
::nana::spinbox & widget_;
|
||||
};
|
||||
|
||||
enum class buttons
|
||||
{
|
||||
none, increase, decrease
|
||||
@ -85,7 +66,8 @@ namespace nana
|
||||
|
||||
T v;
|
||||
ss >> v;
|
||||
if (v < begin_ || last_ < v)
|
||||
|
||||
if (ss.fail() || v < begin_ || last_ < v)
|
||||
return false;
|
||||
|
||||
diff = (value_ != v);
|
||||
@ -229,6 +211,29 @@ namespace nana
|
||||
|
||||
class implementation
|
||||
{
|
||||
class event_agent
|
||||
: public widgets::skeletons::textbase_event_agent_interface
|
||||
{
|
||||
public:
|
||||
event_agent(implementation* impl)
|
||||
: impl_(impl)
|
||||
{}
|
||||
|
||||
void first_change() override {} //empty, because spinbox does not have this event.
|
||||
|
||||
void text_changed() override
|
||||
{
|
||||
auto wdg = static_cast<nana::spinbox*>(API::get_widget(impl_->editor_->window_handle()));
|
||||
|
||||
if (!impl_->value(to_utf8(impl_->editor_->text()), false))
|
||||
API::refresh_window(wdg->handle());
|
||||
|
||||
wdg->events().text_changed.emit(*wdg, wdg->handle());
|
||||
}
|
||||
private:
|
||||
implementation* const impl_;
|
||||
};
|
||||
|
||||
public:
|
||||
implementation()
|
||||
{
|
||||
@ -269,7 +274,7 @@ namespace nana
|
||||
return range_->check_value(to_utf8(str));
|
||||
});
|
||||
|
||||
evt_agent_.reset(new event_agent(static_cast<nana::spinbox&>(wdg)));
|
||||
evt_agent_.reset(new event_agent{this});
|
||||
editor_->textbase().set_event_agent(evt_agent_.get());
|
||||
|
||||
if (!range_)
|
||||
@ -421,10 +426,15 @@ namespace nana
|
||||
if (!editor_)
|
||||
return;
|
||||
|
||||
std::wstring text;
|
||||
|
||||
if (API::is_focus_ready(editor_->window_handle()))
|
||||
editor_->text(to_wstring(range_->value()), false);
|
||||
text = to_wstring(range_->value());
|
||||
else
|
||||
editor_->text(to_wstring(modifier_.prefix + range_->value() + modifier_.suffix), false);
|
||||
text = to_wstring(modifier_.prefix + range_->value() + modifier_.suffix);
|
||||
|
||||
if (editor_->text() != text)
|
||||
editor_->text(text, false);
|
||||
|
||||
_m_draw_spins(spin_stated_);
|
||||
}
|
||||
@ -572,9 +582,6 @@ namespace nana
|
||||
{
|
||||
if (impl_->editor()->respond_char(arg))
|
||||
{
|
||||
if (!impl_->value(to_utf8(impl_->editor()->text()), false))
|
||||
impl_->draw_spins();
|
||||
|
||||
API::dev::lazy_refresh();
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user