change textbox event text_position_changed in favor of text_exposed
This commit is contained in:
parent
fb3b1d51d4
commit
09b314b94c
@ -229,8 +229,6 @@ namespace nana{ namespace widgets
|
||||
|
||||
/// Returns text position of each line that currently displays on screen
|
||||
const std::vector<upoint>& text_position() const;
|
||||
|
||||
void set_text_position_changed(std::function<void(const std::vector<upoint>&)>);
|
||||
public:
|
||||
void draw_corner();
|
||||
void render(bool focused);
|
||||
@ -317,7 +315,6 @@ namespace nana{ namespace widgets
|
||||
mutable ext_renderer_tag ext_renderer_;
|
||||
|
||||
std::vector<upoint> text_position_; //position of text from last rendering.
|
||||
std::function<void(const std::vector<upoint>&)> text_position_function_;
|
||||
|
||||
struct indent_rep
|
||||
{
|
||||
|
||||
@ -11,6 +11,9 @@ namespace nana
|
||||
{
|
||||
namespace skeletons
|
||||
{
|
||||
//forward declaration
|
||||
class text_editor;
|
||||
|
||||
struct text_editor_scheme
|
||||
: public ::nana::widget_colors
|
||||
{
|
||||
@ -23,7 +26,7 @@ namespace nana
|
||||
public:
|
||||
virtual ~text_editor_event_interface() = default;
|
||||
|
||||
virtual void text_position_changed(const std::vector<upoint>&) = 0;
|
||||
virtual void text_exposed(const std::vector<upoint>&) = 0;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@ -23,28 +23,11 @@ namespace nana
|
||||
: public event_arg
|
||||
{
|
||||
textbox& widget;
|
||||
const std::vector<upoint>* text_position;
|
||||
const std::vector<upoint>& text_position; ///< position of characters that the first character of line which are displayed
|
||||
|
||||
arg_textbox(textbox&);
|
||||
arg_textbox(textbox&, const std::vector<upoint>&);
|
||||
};
|
||||
|
||||
struct arg_textbox_text_position
|
||||
: public event_arg
|
||||
{
|
||||
textbox& widget;
|
||||
const std::vector<upoint>& text_position;
|
||||
|
||||
arg_textbox_text_position(textbox&, const std::vector<upoint>&);
|
||||
};
|
||||
|
||||
namespace widgets
|
||||
{
|
||||
namespace skeletons
|
||||
{
|
||||
class text_editor;
|
||||
}
|
||||
}
|
||||
|
||||
namespace drawerbase
|
||||
{
|
||||
namespace textbox
|
||||
@ -54,15 +37,7 @@ namespace nana
|
||||
{
|
||||
basic_event<arg_textbox> first_change;
|
||||
basic_event<arg_textbox> text_changed;
|
||||
basic_event<arg_textbox_text_position> text_position_changed;
|
||||
};
|
||||
|
||||
class event_interface
|
||||
{
|
||||
public:
|
||||
virtual ~event_interface() = default;
|
||||
|
||||
virtual void text_position_changed(const std::vector<upoint>&) = 0;
|
||||
basic_event<arg_textbox> text_exposed;
|
||||
};
|
||||
|
||||
class event_agent
|
||||
@ -70,16 +45,17 @@ namespace nana
|
||||
public widgets::skeletons::text_editor_event_interface
|
||||
{
|
||||
public:
|
||||
event_agent(::nana::textbox&);
|
||||
event_agent(::nana::textbox&, const std::vector<upoint>&);
|
||||
private:
|
||||
//Overrides textbase_event_agent_interface
|
||||
void first_change() override;
|
||||
void text_changed() override;
|
||||
private:
|
||||
//Overrides text_editor_event_interface
|
||||
void text_position_changed(const std::vector<upoint>&) override;
|
||||
void text_exposed(const std::vector<upoint>&) override;
|
||||
private:
|
||||
::nana::textbox & widget_;
|
||||
const std::vector<upoint>& text_position_;
|
||||
};
|
||||
|
||||
//class drawer
|
||||
@ -122,6 +98,7 @@ namespace nana
|
||||
:public widget_object<category::widget_tag, drawerbase::textbox::drawer, drawerbase::textbox::textbox_events, ::nana::widgets::skeletons::text_editor_scheme>
|
||||
{
|
||||
public:
|
||||
using text_positions = std::vector<upoint>;
|
||||
/// The default constructor without creating the widget.
|
||||
textbox();
|
||||
|
||||
@ -220,7 +197,7 @@ namespace nana
|
||||
|
||||
|
||||
/// Returns the text position of each line that currently displays on screen.
|
||||
std::vector<upoint> text_position() const;
|
||||
text_positions text_position() const;
|
||||
|
||||
/// Returns the rectangle of text area
|
||||
rectangle text_area() const;
|
||||
|
||||
@ -30,7 +30,7 @@ namespace detail
|
||||
{
|
||||
///@brief Seek a pixel address by using offset bytes
|
||||
///@return the specified pixel address
|
||||
inline pixel_color_t * pixel_at(pixel_color_t * p, std::size_t bytes) //deprecated
|
||||
inline pixel_color_t * pixel_at(pixel_color_t * p, std::size_t bytes)
|
||||
{
|
||||
return reinterpret_cast<pixel_color_t*>(reinterpret_cast<char*>(p) + bytes);
|
||||
}
|
||||
|
||||
@ -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_;
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user