change textbox event text_position_changed in favor of text_exposed

This commit is contained in:
Jinhao
2015-10-23 00:51:58 +08:00
parent fb3b1d51d4
commit 09b314b94c
7 changed files with 47 additions and 94 deletions

View File

@@ -26,13 +26,17 @@ namespace nana
event_handle destroy;
};
public:
dragger_impl_t()
: dragging_(false)
{}
~dragger_impl_t()
{
_m_clear_triggers();
//Clear triggers
for (auto & t : triggers_)
{
API::umake_event(t.press);
API::umake_event(t.over);
API::umake_event(t.release);
API::umake_event(t.destroy);
API::capture_window(t.wd, false);
}
}
void drag_target(window wd, const rectangle& restrict_area, arrange arg)
@@ -128,40 +132,23 @@ namespace nana
tg.press = events.mouse_down.connect(fn);
tg.over = events.mouse_move.connect(fn);
tg.release = events.mouse_up.connect(fn);
tg.destroy = events.destroy.connect([this](const arg_destroy& arg){
_m_destroy(arg.window_handle);
tg.destroy = events.destroy.connect([this](const arg_destroy& arg)
{
for (auto i = triggers_.begin(), end = triggers_.end(); i != end; ++i)
{
if (i->wd == arg.window_handle)
{
triggers_.erase(i);
API::capture_window(arg.window_handle, false);
return;
}
}
});
triggers_.push_back(tg);
}
private:
void _m_clear_triggers()
{
for(auto & t : triggers_)
{
API::umake_event(t.press);
API::umake_event(t.over);
API::umake_event(t.release);
API::umake_event(t.destroy);
API::capture_window(t.wd, false);
}
triggers_.clear();
}
void _m_destroy(::nana::window wd)
{
for(auto i = triggers_.begin(), end = triggers_.end(); i != end; ++i)
{
if(i->wd == wd)
{
triggers_.erase(i);
API::capture_window(wd, false);
return;
}
}
}
void _m_check_restrict_area(nana::point & pos, const nana::size & size, const nana::rectangle& restr_area)
static void _m_check_restrict_area(nana::point & pos, const nana::size & size, const nana::rectangle& restr_area)
{
if ((pos.x > 0) && (static_cast<int>(size.width) + pos.x > restr_area.right()))
pos.x = restr_area.right() - static_cast<int>(size.width);
@@ -176,7 +163,7 @@ namespace nana
pos.y = restr_area.y;
}
private:
bool dragging_;
bool dragging_{ false };
nana::point origin_;
std::vector<drag_target_t> targets_;
std::vector<trigger_t> triggers_;

View File

@@ -435,7 +435,7 @@ namespace nana{ namespace widgets
if (x > lnstr.size()) x = static_cast<unsigned>(lnstr.size());
unsigned text_w = editor_._m_pixels_by_char(lnstr, x);
auto const text_w = editor_._m_pixels_by_char(lnstr, x);
unsigned area_w = editor_._m_text_area().width;
@@ -1918,11 +1918,6 @@ namespace nana{ namespace widgets
return text_position_;
}
void text_editor::set_text_position_changed(std::function<void(const std::vector<upoint>&)> fn)
{
text_position_function_.swap(fn);
}
void text_editor::draw_corner()
{
if(text_area_.vscroll && text_area_.hscroll)
@@ -1967,7 +1962,7 @@ namespace nana{ namespace widgets
{
text_position_.swap(text_pos);
if (event_handler_)
event_handler_->text_position_changed(text_position_);
event_handler_->text_exposed(text_position_);
}
}
else //Draw tip string

View File

@@ -20,38 +20,32 @@
namespace nana
{
arg_textbox::arg_textbox(textbox& wdg)
: widget(wdg)
arg_textbox::arg_textbox(textbox& wdg, const std::vector<upoint>& text_pos)
: widget(wdg), text_position(text_pos)
{}
arg_textbox_text_position::arg_textbox_text_position(textbox& wdg, const std::vector<upoint>& text_pos)
: widget(wdg),
text_position(text_pos)
{
}
namespace drawerbase {
namespace textbox
{
//class event_agent
event_agent::event_agent(::nana::textbox& wdg)
:widget_(wdg)
event_agent::event_agent(::nana::textbox& wdg, const std::vector<upoint>& text_pos)
:widget_(wdg), text_position_(text_pos)
{}
void event_agent::first_change()
{
widget_.events().first_change.emit(::nana::arg_textbox{ widget_ });
widget_.events().first_change.emit(::nana::arg_textbox{ widget_, text_position_ });
}
void event_agent::text_changed()
{
widget_.events().text_changed.emit(::nana::arg_textbox{ widget_ });
widget_.events().text_changed.emit(::nana::arg_textbox{ widget_, text_position_ });
}
void event_agent::text_position_changed(const std::vector<upoint>& text_pos)
void event_agent::text_exposed(const std::vector<upoint>& text_pos)
{
::nana::arg_textbox_text_position arg(widget_, text_pos);
widget_.events().text_position_changed.emit(arg);
::nana::arg_textbox arg(widget_, text_pos);
widget_.events().text_exposed.emit(arg);
}
//end class event_agent
@@ -75,7 +69,7 @@ namespace drawerbase {
{
auto wd = wdg.handle();
widget_ = &wdg;
evt_agent_.reset(new event_agent(static_cast< ::nana::textbox&>(wdg)));
evt_agent_.reset(new event_agent(static_cast<::nana::textbox&>(wdg), editor_->text_position()));
auto scheme = API::dev::get_scheme(wdg);