change parameter type of click event from arg_mouse to arg_click

This commit is contained in:
Jinhao 2015-07-21 01:14:23 +08:00
parent d8a964d8f0
commit 5bc1568f3e
13 changed files with 214 additions and 151 deletions

View File

@ -46,7 +46,7 @@ namespace nana
virtual void resizing(graph_reference, const arg_resizing&); virtual void resizing(graph_reference, const arg_resizing&);
virtual void resized(graph_reference, const arg_resized&); virtual void resized(graph_reference, const arg_resized&);
virtual void move(graph_reference, const arg_move&); virtual void move(graph_reference, const arg_move&);
virtual void click(graph_reference, const arg_mouse&); virtual void click(graph_reference, const arg_click&);
virtual void dbl_click(graph_reference, const arg_mouse&); virtual void dbl_click(graph_reference, const arg_mouse&);
virtual void mouse_enter(graph_reference, const arg_mouse&); virtual void mouse_enter(graph_reference, const arg_mouse&);
virtual void mouse_move(graph_reference, const arg_mouse&); virtual void mouse_move(graph_reference, const arg_mouse&);
@ -100,7 +100,7 @@ namespace nana
void bind(basic_window*); void bind(basic_window*);
void typeface_changed(); void typeface_changed();
void click(const arg_mouse&); void click(const arg_click&);
void dbl_click(const arg_mouse&); void dbl_click(const arg_mouse&);
void mouse_enter(const arg_mouse&); void mouse_enter(const arg_mouse&);
void mouse_move(const arg_mouse&); void mouse_move(const arg_mouse&);

View File

@ -512,6 +512,12 @@ namespace nana
::nana::window window_handle; ///< A handle to the event window ::nana::window window_handle; ///< A handle to the event window
}; };
struct arg_click : public event_arg
{
::nana::window window_handle; ///< A handle to the event window
bool by_mouse; ///< Determines whether the event is emitted by clicking mouse button
};
/// provides some fundamental events that every widget owns. /// provides some fundamental events that every widget owns.
struct general_events struct general_events
{ {
@ -521,7 +527,7 @@ namespace nana
basic_event<arg_mouse> mouse_leave; ///< the cursor leaves the window basic_event<arg_mouse> mouse_leave; ///< the cursor leaves the window
basic_event<arg_mouse> mouse_down; ///< the user presses the mouse button basic_event<arg_mouse> mouse_down; ///< the user presses the mouse button
basic_event<arg_mouse> mouse_up; ///< the user presses the mouse button basic_event<arg_mouse> mouse_up; ///< the user presses the mouse button
basic_event<arg_mouse> click; ///< the window is clicked, but occurs after mouse_down and before mouse_up basic_event<arg_click> click; ///< the window is clicked, but occurs after mouse_down and before mouse_up
basic_event<arg_mouse> dbl_click; ///< the window is double clicked basic_event<arg_mouse> dbl_click; ///< the window is double clicked
basic_event<arg_wheel> mouse_wheel; ///< the mouse wheel rotates while the window has focus basic_event<arg_wheel> mouse_wheel; ///< the mouse wheel rotates while the window has focus
basic_event<arg_dropfiles> mouse_dropfiles; ///< the mouse drops some external data while the window enable accepting files basic_event<arg_dropfiles> mouse_dropfiles; ///< the mouse drops some external data while the window enable accepting files

View File

@ -45,6 +45,7 @@ namespace nana{
void mouse_up(graph_reference, const arg_mouse&) override; void mouse_up(graph_reference, const arg_mouse&) override;
void key_char(graph_reference, const arg_keyboard&) override; void key_char(graph_reference, const arg_keyboard&) override;
void key_press(graph_reference, const arg_keyboard&) override; void key_press(graph_reference, const arg_keyboard&) override;
void key_release(graph_reference, const arg_keyboard&) override;
void focus(graph_reference, const arg_focus&) override; void focus(graph_reference, const arg_focus&) override;
private: private:
void _m_draw(graph_reference); void _m_draw(graph_reference);

View File

@ -89,7 +89,7 @@ namespace drawerbase
std::size_t checked() const; ///< Retrieves the index of the checkbox which is checked. std::size_t checked() const; ///< Retrieves the index of the checkbox which is checked.
std::size_t size() const; std::size_t size() const;
private: private:
void _m_checked(const arg_mouse&); void _m_checked(const arg_click&);
void _m_destroy(const arg_destroy&); void _m_destroy(const arg_destroy&);
private: private:
std::vector<element_tag> ui_container_; std::vector<element_tag> ui_container_;

View File

@ -40,7 +40,7 @@ namespace nana
void refresh(graph_reference) override; void refresh(graph_reference) override;
void mouse_move(graph_reference, const arg_mouse&) override; void mouse_move(graph_reference, const arg_mouse&) override;
void mouse_leave(graph_reference, const arg_mouse&) override; void mouse_leave(graph_reference, const arg_mouse&) override;
void click(graph_reference, const arg_mouse&) override; void click(graph_reference, const arg_click&) override;
private: private:
impl_t * impl_; impl_t * impl_;
}; };

View File

@ -195,6 +195,16 @@ namespace nana
switch (evt_code) switch (evt_code)
{ {
case event_code::click: case event_code::click:
{
auto arg = dynamic_cast<const arg_click*>(&event_arg);
if (nullptr == arg)
return;
wd->drawer.click(*arg);
if (!draw_only)
evts_ptr->click.emit(*arg);
}
break;
case event_code::dbl_click: case event_code::dbl_click:
case event_code::mouse_enter: case event_code::mouse_enter:
case event_code::mouse_move: case event_code::mouse_move:
@ -211,10 +221,6 @@ namespace nana
switch (evt_code) switch (evt_code)
{ {
case event_code::click:
drawer_event_fn = &drawer::click;
evt_addr = &evts_ptr->click;
break;
case event_code::dbl_click: case event_code::dbl_click:
drawer_event_fn = &drawer::dbl_click; drawer_event_fn = &drawer::dbl_click;
evt_addr = &evts_ptr->dbl_click; evt_addr = &evts_ptr->dbl_click;

View File

@ -49,7 +49,7 @@ namespace nana
overrided_ &= ~(1 << static_cast<int>(event_code::move)); overrided_ &= ~(1 << static_cast<int>(event_code::move));
} }
void drawer_trigger::click(graph_reference, const arg_mouse&) void drawer_trigger::click(graph_reference, const arg_click&)
{ {
overrided_ &= ~(1 << static_cast<int>(event_code::click)); overrided_ &= ~(1 << static_cast<int>(event_code::click));
} }
@ -155,7 +155,7 @@ namespace nana
realizer_->typeface_changed(graphics); realizer_->typeface_changed(graphics);
} }
void drawer::click(const arg_mouse& arg) void drawer::click(const arg_click& arg)
{ {
_m_emit(event_code::click, arg, &drawer_trigger::click); _m_emit(event_code::click, arg, &drawer_trigger::click);
} }

View File

@ -699,15 +699,18 @@ namespace detail
bool dbl_click = (last_mouse_down_window == msgwnd) && (xevent.xbutton.time - last_mouse_down_time <= 400); bool dbl_click = (last_mouse_down_window == msgwnd) && (xevent.xbutton.time - last_mouse_down_time <= 400);
last_mouse_down_time = xevent.xbutton.time; last_mouse_down_time = xevent.xbutton.time;
last_mouse_down_window = msgwnd; last_mouse_down_window = msgwnd;
auto new_focus = (msgwnd->flags.take_active ? msgwnd : msgwnd->other.active_window);
if(new_focus && !new_focus->flags.ignore_mouse_focus) if (Button1 == xevent.xbutton.button) //Sets the focus only if left button is pressed
{
auto new_focus = (msgwnd->flags.take_active ? msgwnd : msgwnd->other.active_window);
if (new_focus && !new_focus->flags.ignore_mouse_focus)
{ {
context.event_window = new_focus; context.event_window = new_focus;
auto kill_focus = brock.wd_manager.set_focus(new_focus, false); auto kill_focus = brock.wd_manager.set_focus(new_focus, false);
if(kill_focus != new_focus) if (kill_focus != new_focus)
brock.wd_manager.do_lazy_refresh(kill_focus, false); brock.wd_manager.do_lazy_refresh(kill_focus, false);
} }
}
auto retain = msgwnd->together.events_ptr; auto retain = msgwnd->together.events_ptr;
context.event_window = msgwnd; context.event_window = msgwnd;
@ -774,7 +777,9 @@ namespace detail
if((arg.button == ::nana::mouse::left_button) && hit) if((arg.button == ::nana::mouse::left_button) && hit)
{ {
msgwnd->flags.action = mouse_action::over; msgwnd->flags.action = mouse_action::over;
arg.evt_code = event_code::click; arg_click arg;
arg.window_handle = reinterpret_cast<window>(msgwnd);
arg.by_mouse = true;
emit_drawer(&drawer::click, msgwnd, arg, &context); emit_drawer(&drawer::click, msgwnd, arg, &context);
fire_click = true; fire_click = true;
} }
@ -794,7 +799,9 @@ namespace detail
if(fire_click) if(fire_click)
{ {
arg.evt_code = event_code::click; arg_click arg;
arg.window_handle = reinterpret_cast<window>(msgwnd);
arg.by_mouse = true;
evt_ptr->click.emit(arg); evt_ptr->click.emit(arg);
} }
@ -806,7 +813,9 @@ namespace detail
} }
else if(fire_click) else if(fire_click)
{ {
arg.evt_code = event_code::click; arg_click arg;
arg.window_handle = reinterpret_cast<window>(msgwnd);
arg.by_mouse = true;
msgwnd->together.events_ptr->click.emit(arg); msgwnd->together.events_ptr->click.emit(arg);
} }
brock.wd_manager.do_lazy_refresh(msgwnd, false); brock.wd_manager.do_lazy_refresh(msgwnd, false);

View File

@ -949,13 +949,17 @@ namespace detail
if(msgwnd->flags.enabled) if(msgwnd->flags.enabled)
{ {
pressed_wd = msgwnd; pressed_wd = msgwnd;
if (WM_LBUTTONDOWN == message) //Sets focus only if left button is pressed
{
auto new_focus = (msgwnd->flags.take_active ? msgwnd : msgwnd->other.active_window); auto new_focus = (msgwnd->flags.take_active ? msgwnd : msgwnd->other.active_window);
if(new_focus && (!new_focus->flags.ignore_mouse_focus)) if (new_focus && (!new_focus->flags.ignore_mouse_focus))
{ {
auto kill_focus = brock.wd_manager.set_focus(new_focus, false); auto kill_focus = brock.wd_manager.set_focus(new_focus, false);
if(kill_focus != new_focus) if (kill_focus != new_focus)
brock.wd_manager.do_lazy_refresh(kill_focus, false); brock.wd_manager.do_lazy_refresh(kill_focus, false);
} }
}
arg_mouse arg; arg_mouse arg;
assign_arg(arg, msgwnd, message, pmdec); assign_arg(arg, msgwnd, message, pmdec);
@ -1007,7 +1011,9 @@ namespace detail
msgwnd->flags.action = mouse_action::over; msgwnd->flags.action = mouse_action::over;
if (::nana::mouse::left_button == arg.button) if (::nana::mouse::left_button == arg.button)
{ {
arg.evt_code = event_code::click; arg_click arg;
arg.window_handle = reinterpret_cast<window>(msgwnd);
arg.by_mouse = true;
emit_drawer(&drawer::click, msgwnd, arg, &context); emit_drawer(&drawer::click, msgwnd, arg, &context);
fire_click = true; fire_click = true;
} }
@ -1021,7 +1027,9 @@ namespace detail
if (fire_click) if (fire_click)
{ {
arg.evt_code = event_code::click; arg_click arg;
arg.window_handle = reinterpret_cast<window>(msgwnd);
arg.by_mouse = true;
retain->click.emit(arg); retain->click.emit(arg);
} }
@ -1033,7 +1041,9 @@ namespace detail
} }
else if (fire_click) else if (fire_click)
{ {
arg.evt_code = event_code::click; arg_click arg;
arg.window_handle = reinterpret_cast<window>(msgwnd);
arg.by_mouse = true;
retain->click.emit(arg); retain->click.emit(arg);
} }
brock.wd_manager.do_lazy_refresh(msgwnd, false); brock.wd_manager.do_lazy_refresh(msgwnd, false);

View File

@ -126,7 +126,6 @@ namespace nana{ namespace drawerbase
attr_.e_state = element_state::pressed; attr_.e_state = element_state::pressed;
attr_.keep_pressed = true; attr_.keep_pressed = true;
_m_draw(graph); _m_draw(graph);
API::capture_window(*wdg_, true); API::capture_window(*wdg_, true);
API::lazy_refresh(); API::lazy_refresh();
@ -158,12 +157,20 @@ namespace nana{ namespace drawerbase
void trigger::key_char(graph_reference, const arg_keyboard& arg) void trigger::key_char(graph_reference, const arg_keyboard& arg)
{ {
if (static_cast<char_t>(keyboard::enter) == arg.key || static_cast<char_t>(keyboard::space) == arg.key) if (static_cast<char_t>(keyboard::enter) == arg.key)
emit_click(); emit_click();
} }
void trigger::key_press(graph_reference, const arg_keyboard& arg) void trigger::key_press(graph_reference graph, const arg_keyboard& arg)
{ {
if (keyboard::space == static_cast<char_t>(arg.key))
{
attr_.e_state = element_state::pressed;
attr_.keep_pressed = true;
_m_draw(graph);
API::lazy_refresh();
return;
}
bool ch_tabstop_next; bool ch_tabstop_next;
switch(arg.key) switch(arg.key)
{ {
@ -179,6 +186,25 @@ namespace nana{ namespace drawerbase
API::move_tabstop(*wdg_, ch_tabstop_next); API::move_tabstop(*wdg_, ch_tabstop_next);
} }
void trigger::key_release(graph_reference graph, const arg_keyboard& arg)
{
if (arg.key != static_cast<char_t>(keyboard::space))
return;
emit_click();
attr_.keep_pressed = false;
if (element_state::pressed == attr_.e_state)
attr_.e_state = element_state::hovered;
else
attr_.e_state = element_state::normal;
attr_.pushed = false;
_m_draw(graph);
API::lazy_refresh();
}
void trigger::focus(graph_reference graph, const arg_focus& arg) void trigger::focus(graph_reference graph, const arg_focus& arg)
{ {
attr_.focused = arg.getting; attr_.focused = arg.getting;
@ -343,14 +369,20 @@ namespace nana{ namespace drawerbase
void trigger::emit_click() void trigger::emit_click()
{ {
/*
arg_mouse arg; arg_mouse arg;
arg.evt_code = event_code::click; arg.evt_code = event_code::click;
arg.window_handle = wdg_->handle(); arg.window_handle = wdg_->handle(); //deprecated
arg.ctrl = arg.shift = false; arg.ctrl = arg.shift = false;
arg.button = ::nana::mouse::left_button; arg.button = ::nana::mouse::left_button;
arg.mid_button = arg.right_button = false; arg.mid_button = arg.right_button = false;
arg.left_button = true; arg.left_button = true;
arg.pos.x = arg.pos.y = 1; arg.pos.x = arg.pos.y = 1;
*/
arg_click arg;
arg.window_handle = wdg_->handle();
arg.by_mouse = false;
API::emit_event(event_code::click, arg.window_handle, arg); API::emit_event(event_code::click, arg.window_handle, arg);
} }

View File

@ -231,7 +231,7 @@ namespace checkbox
return ui_container_.size(); return ui_container_.size();
} }
void radio_group::_m_checked(const arg_mouse& arg) void radio_group::_m_checked(const arg_click& arg)
{ {
for (auto & i : ui_container_) for (auto & i : ui_container_)
i.uiobj->check(arg.window_handle == i.uiobj->handle()); i.uiobj->check(arg.window_handle == i.uiobj->handle());

View File

@ -730,7 +730,7 @@ namespace nana
} }
} }
void trigger::click(graph_reference, const arg_mouse&) void trigger::click(graph_reference, const arg_click&)
{ {
//make a copy, because the listener may popup a window, and then //make a copy, because the listener may popup a window, and then
//user moves the mouse. it will reset the url when the mouse is moving out from the element. //user moves the mouse. it will reset the url when the mouse is moving out from the element.

View File

@ -371,13 +371,12 @@ namespace nana
bool visible(bool v) bool visible(bool v)
{ {
if(visible_ != v) if (visible_ == v)
{ return false;
visible_ = v; visible_ = v;
return true; return true;
} }
return false;
}
bool sortable() const bool sortable() const
{ {
@ -635,16 +634,18 @@ namespace nana
nana::string to_string(const export_options& exp_opt) const nana::string to_string(const export_options& exp_opt) const
{ {
nana::string item_str; nana::string item_str;
bool first{true};
for( size_type idx{}; idx<exp_opt.columns_order.size(); ++idx) bool ignore_first = true;
for (size_type idx{}; idx < exp_opt.columns_order.size(); ++idx)
{ {
if(first) if (ignore_first)
first=false; ignore_first = false;
else else
item_str += exp_opt.sep; item_str += exp_opt.sep;
item_str += cells[exp_opt.columns_order[idx]].text; item_str += cells[exp_opt.columns_order[idx]].text;
} }
return item_str; return item_str;
} }
}; };
@ -2416,7 +2417,6 @@ namespace nana
const std::size_t column_pos_; const std::size_t column_pos_;
}; };
void es_lister::scroll_refresh() void es_lister::scroll_refresh()
{ {
ess_->scroll_y_dpl_refresh(); ess_->scroll_y_dpl_refresh();
@ -2567,7 +2567,7 @@ namespace nana
{ {
if(hd.visible) if(hd.visible)
{ {
if((static_cast<int>(hd.pixels) - 2 < x) && (x < static_cast<int>(hd.pixels) + 3)) if((static_cast<int>(hd.pixels) < x + 2) && (x < static_cast<int>(hd.pixels) + 3))
{ {
item_spliter_ = hd.index; // original index item_spliter_ = hd.index; // original index
return true; return true;
@ -2617,9 +2617,8 @@ namespace nana
essence_->header.item_width(item_spliter_, (new_w < static_cast<int>(essence_->suspension_width + 20) ? essence_->suspension_width + 20 : new_w)); essence_->header.item_width(item_spliter_, (new_w < static_cast<int>(essence_->suspension_width + 20) ? essence_->suspension_width + 20 : new_w));
auto new_w = essence_->header.pixels(); auto new_w = essence_->header.pixels();
if(new_w < (rect.width + essence_->scroll.offset_x)) if(new_w < (rect.width + essence_->scroll.offset_x))
{
essence_->scroll.offset_x = (new_w > rect.width ? new_w - rect.width : 0); essence_->scroll.offset_x = (new_w > rect.width ? new_w - rect.width : 0);
}
essence_->adjust_scroll_life(); essence_->adjust_scroll_life();
return 2; return 2;
} }