From 396163c1b7eb584cf6258706cdeef20078d58a3d Mon Sep 17 00:00:00 2001 From: Jinhao Date: Tue, 28 Jul 2015 00:00:15 +0800 Subject: [PATCH] fix mouse left button issues due to breaking changes --- include/nana/filesystem/filesystem.hpp | 51 +++++++++---------- include/nana/gui/detail/general_events.hpp | 6 +++ .../gui/widgets/skeletons/text_editor.hpp | 4 +- source/detail/linux_X11/platform_spec.cpp | 6 +-- source/gui/element.cpp | 3 -- source/gui/widgets/combox.cpp | 4 +- source/gui/widgets/float_listbox.cpp | 18 ++++--- source/gui/widgets/menu.cpp | 23 +++++---- source/gui/widgets/skeletons/text_editor.cpp | 6 +-- source/gui/widgets/spinbox.cpp | 4 +- source/gui/widgets/textbox.cpp | 4 +- source/gui/widgets/toolbar.cpp | 2 +- source/gui/widgets/treebox.cpp | 34 +++++++++---- 13 files changed, 93 insertions(+), 72 deletions(-) diff --git a/include/nana/filesystem/filesystem.hpp b/include/nana/filesystem/filesystem.hpp index 284faea1..f1229fb1 100644 --- a/include/nana/filesystem/filesystem.hpp +++ b/include/nana/filesystem/filesystem.hpp @@ -35,6 +35,7 @@ #include #include #include +#include #include @@ -160,24 +161,24 @@ namespace filesystem struct directory_entry { - path m_path; + using path_type = filesystem::path; + path_type m_path; - attribute attr{}; - //file_status m_status; + attribute attr{}; + //file_status m_status; directory_entry(){} - directory_entry(const nana::string& filename_, bool is_directory, uintmax_t size) - :m_path{filename_}, attr{size, is_directory} - {} + directory_entry(const path_type& p, bool is_directory, uintmax_t size) + :m_path{p}, attr{size, is_directory} + {} - void assign (const path& p){ m_path=p;} - void replace_filename(const path& p){ m_path=p;} + void assign (const path_type& p){ m_path=p;} + void replace_filename(const path_type& p){ m_path=p;} - //file_status status() const; - - operator const path&() const {return m_path;}; - const path& path() const {return m_path;} + //file_status status() const; + operator const path_type&() const {return m_path;}; + const path_type& path() const {return m_path;} }; /// an iterator for a sequence of directory_entry elements representing the files in a directory, not an recursive_directory_iterator @@ -186,10 +187,10 @@ namespace filesystem { public: using value_type = directory_entry ; - typedef ptrdiff_t difference_type; - typedef const directory_entry* pointer; - typedef const directory_entry& reference; - typedef std::input_iterator_tag iterator_category; + typedef ptrdiff_t difference_type; + typedef const directory_entry* pointer; + typedef const directory_entry& reference; + typedef std::input_iterator_tag iterator_category; directory_iterator():end_(true), handle_(nullptr){} @@ -220,8 +221,8 @@ namespace filesystem // enable directory_iterator range-based for statements - directory_iterator begin( ) { return *this; } - directory_iterator end( ) { return {}; } + directory_iterator begin( ) { return *this; } + directory_iterator end( ) { return {}; } private: template @@ -285,16 +286,14 @@ namespace filesystem } struct stat fst; + bool is_directory = false; + unsigned size = 0; if(stat((path_ + dnt->d_name).c_str(), &fst) == 0) { - value_ = value_type(nana::charset(dnt->d_name), 0 != S_ISDIR(fst.st_mode), fst.st_size); - } - else - { - value_.m_path = nana::charset(dnt->d_name); - value_.size = 0; - value_.directory = false; + is_directory = (0 != S_ISDIR(fst.st_mode)); + size = fst.st_size; } + value_ = value_type(static_cast(nana::charset(dnt->d_name)), is_directory, size); end_ = false; } } @@ -342,7 +341,7 @@ namespace filesystem } struct stat fst; if(stat((path_ + "/" + dnt->d_name).c_str(), &fst) == 0) - value_ = value_type(wfd_.cFileName, + value_ = value_type(static_cast(nana::charset(wfd_.cFileName)), (FILE_ATTRIBUTE_DIRECTORY & wfd_.dwFileAttributes) == FILE_ATTRIBUTE_DIRECTORY, wfd_.nFileSizeLow); else diff --git a/include/nana/gui/detail/general_events.hpp b/include/nana/gui/detail/general_events.hpp index 78db3232..cdb6ac3a 100644 --- a/include/nana/gui/detail/general_events.hpp +++ b/include/nana/gui/detail/general_events.hpp @@ -432,6 +432,12 @@ namespace nana bool right_button; ///< mouse right button is pressed? bool shift; ///< keyboard Shift is pressed? bool ctrl; ///< keyboard Ctrl is pressed? + + /// Checks if left button is operated, + bool is_left_button() const + { + return (event_code::mouse_move == evt_code ? left_button : (mouse::left_button == button)); + } }; /// in arg_wheel event_code is event_code::mouse_wheel diff --git a/include/nana/gui/widgets/skeletons/text_editor.hpp b/include/nana/gui/widgets/skeletons/text_editor.hpp index 976c168d..2e6e147d 100644 --- a/include/nana/gui/widgets/skeletons/text_editor.hpp +++ b/include/nana/gui/widgets/skeletons/text_editor.hpp @@ -235,9 +235,9 @@ namespace nana{ namespace widgets nana::upoint caret() const; bool scroll(bool upwards, bool vertical); bool mouse_enter(bool); - bool mouse_down(bool left_button, const point& screen_pos); + bool mouse_down(::nana::mouse, const point& screen_pos); bool mouse_move(bool left_button, const point& screen_pos); - bool mouse_up(bool left_button, const point& screen_pos); + bool mouse_up(::nana::mouse, const point& screen_pos); skeletons::textbase& textbase(); const skeletons::textbase& textbase() const; diff --git a/source/detail/linux_X11/platform_spec.cpp b/source/detail/linux_X11/platform_spec.cpp index c8ccf682..de9ae3aa 100644 --- a/source/detail/linux_X11/platform_spec.cpp +++ b/source/detail/linux_X11/platform_spec.cpp @@ -922,7 +922,7 @@ namespace detail { if(crt.visible && (false == caret_reinstate(crt))) { - crt.rev_graph.bitblt(crt.size, crt.window, crt.pos); + crt.rev_graph.bitblt(rectangle{crt.size}, crt.window, crt.pos); crt.rev.width = crt.size.width; crt.rev.height = crt.size.height; crt.rev.x = crt.pos.x; @@ -948,7 +948,7 @@ namespace detail nana::paint::graphics * crt_graph; if(crt.rev.width && crt.rev.height) { - crt.rev_graph.bitblt(crt.size, root_graph, crt.pos); + crt.rev_graph.bitblt(rectangle{crt.size}, root_graph, crt.pos); crt_graph = &crt.graph; owns_caret = true; } @@ -1132,7 +1132,7 @@ namespace detail { nana::paint::graphics & graph = iconbase_[wd]; graph.make(img.size()); - img.paste(graph, 0, 0); + img.paste(graph, {}); return graph; } diff --git a/source/gui/element.cpp b/source/gui/element.cpp index 88d247c9..1852a554 100644 --- a/source/gui/element.cpp +++ b/source/gui/element.cpp @@ -580,9 +580,6 @@ namespace nana class element_manager : nana::noncopyable, nana::nonmovable { - //VC2012 does not support alias declaration. - //template using factory_interface = element::provider::factory_interface; - template struct item { diff --git a/source/gui/widgets/combox.cpp b/source/gui/widgets/combox.cpp index 5936341a..e088b229 100644 --- a/source/gui/widgets/combox.cpp +++ b/source/gui/widgets/combox.cpp @@ -622,7 +622,7 @@ namespace nana if(drawer_->widget_ptr()->enabled()) { auto * editor = drawer_->editor(); - if(false == editor->mouse_down(arg.left_button, arg.pos)) + if(false == editor->mouse_down(arg.button, arg.pos)) drawer_->open_lister_if_push_button_positioned(); drawer_->draw(); @@ -637,7 +637,7 @@ namespace nana { if (drawer_->widget_ptr()->enabled() && !drawer_->has_lister()) { - drawer_->editor()->mouse_up(arg.left_button, arg.pos); + drawer_->editor()->mouse_up(arg.button, arg.pos); drawer_->set_button_state(element_state::hovered, false); drawer_->draw(); API::lazy_refresh(); diff --git a/source/gui/widgets/float_listbox.cpp b/source/gui/widgets/float_listbox.cpp index 5cdd2cf2..1af70c6c 100644 --- a/source/gui/widgets/float_listbox.cpp +++ b/source/gui/widgets/float_listbox.cpp @@ -34,7 +34,7 @@ namespace nana { if (state == StateHighlighted) { - ::nana::color clr{ 0xaf, 0xc7, 0xe3 }; + ::nana::color clr(static_cast(0xafc7e3)); graph.rectangle(r, false, clr); auto right = r.right() - 1; @@ -276,7 +276,7 @@ namespace nana } } - bool right_area(graph_reference graph, int x, int y) const + static bool right_area(graph_reference graph, int x, int y) { return ((1 < x && 1 < y) && x < static_cast(graph.width()) - 2 && @@ -325,7 +325,7 @@ namespace nana _m_open_scrollbar(*widget_, pages); } else - graph_->string({ 4, 4 }, STR("Empty Listbox, No Module!"), {0x80, 0x80, 0x80}); + graph_->string({ 4, 4 }, STR("Empty Listbox, No Module!"), static_cast(0x808080)); //Draw border graph_->rectangle(false, colors::black); @@ -361,7 +361,7 @@ namespace nana auto fn = [this](const arg_mouse& arg) { - if (arg.left_button && (scrollbar_.value() != state_.offset_y)) + if (arg.is_left_button() && (scrollbar_.value() != state_.offset_y)) { state_.offset_y = static_cast(scrollbar_.value()); draw(); @@ -449,12 +449,16 @@ namespace nana void trigger::mouse_up(graph_reference graph, const arg_mouse& arg) { - if(drawer_->right_area(graph, arg.pos.x, arg.pos.y)) + bool close_wdg = false; + if (drawer_->right_area(graph, arg.pos.x, arg.pos.y)) { drawer_->set_result(); - drawer_->widget_ptr()->close(); + close_wdg = true; } - else if(false == drawer_->ignore_emitting_mouseup()) + else + close_wdg = (false == drawer_->ignore_emitting_mouseup()); + + if (close_wdg) drawer_->widget_ptr()->close(); } //end class trigger diff --git a/source/gui/widgets/menu.cpp b/source/gui/widgets/menu.cpp index 8691c67f..d42f2b79 100644 --- a/source/gui/widgets/menu.cpp +++ b/source/gui/widgets/menu.cpp @@ -754,23 +754,26 @@ namespace nana API::register_menu_window(this->handle(), !owner_menubar); } - events().destroy.connect_unignorable([this]{ + auto & events = this->events(); + events.destroy.connect_unignorable([this]{ _m_destroy(); }); - events().key_press.connect_unignorable([this](const arg_keyboard& arg){ + events.key_press.connect_unignorable([this](const arg_keyboard& arg){ _m_key_down(arg); }); - events().mouse_down.connect_unignorable([this](const arg_mouse& arg) + auto fn = [this](const arg_mouse& arg) { - this->_m_open_sub(0); //Try to open submenu immediately - }); + if (event_code::mouse_down == arg.evt_code) + _m_open_sub(0); //Try to open submenu immediately + else if (event_code::mouse_up == arg.evt_code) + if (arg.button == ::nana::mouse::left_button) + pick(); + }; - events().mouse_up.connect_unignorable([this](const arg_mouse& arg){ - if (arg.left_button) - pick(); - }); + events.mouse_down.connect_unignorable(fn); + events.mouse_up.connect_unignorable(fn); timer_.interval(100); timer_.elapse([this]{ @@ -782,7 +785,7 @@ namespace nana if (want_focus_) { - event_focus_ = events().focus.connect_unignorable([this](const arg_focus& arg) + event_focus_ = events.focus.connect_unignorable([this](const arg_focus& arg) { //when the focus of the menu window is losing, close the menu. //But here is not every menu window may have focus event installed, diff --git a/source/gui/widgets/skeletons/text_editor.cpp b/source/gui/widgets/skeletons/text_editor.cpp index d7a4533f..c23e4a73 100644 --- a/source/gui/widgets/skeletons/text_editor.cpp +++ b/source/gui/widgets/skeletons/text_editor.cpp @@ -1593,12 +1593,12 @@ namespace nana{ namespace widgets return true; } - bool text_editor::mouse_down(bool left_button, const point& scrpos) + bool text_editor::mouse_down(::nana::mouse button, const point& scrpos) { if (!hit_text_area(scrpos)) return false; - if(left_button) + if(::nana::mouse::left_button == button) { API::capture_window(window_, true); text_area_.captured = true; @@ -1646,7 +1646,7 @@ namespace nana{ namespace widgets return false; } - bool text_editor::mouse_up(bool left_button, const point& scrpos) + bool text_editor::mouse_up(::nana::mouse button, const point& scrpos) { auto is_prev_no_selected = (select_.mode_selection == selection::mode_no_selected); diff --git a/source/gui/widgets/spinbox.cpp b/source/gui/widgets/spinbox.cpp index 6be8deb2..1caaf486 100644 --- a/source/gui/widgets/spinbox.cpp +++ b/source/gui/widgets/spinbox.cpp @@ -371,9 +371,9 @@ namespace nana bool refreshed = false; if (pressed) - refreshed = editor_->mouse_down(arg.left_button, arg.pos); + refreshed = editor_->mouse_down(arg.button, arg.pos); else - refreshed = editor_->mouse_up(arg.left_button, arg.pos); + refreshed = editor_->mouse_up(arg.button, arg.pos); if (refreshed) _m_draw_spins(buttons::none); diff --git a/source/gui/widgets/textbox.cpp b/source/gui/widgets/textbox.cpp index 4bb6a670..d11ae632 100644 --- a/source/gui/widgets/textbox.cpp +++ b/source/gui/widgets/textbox.cpp @@ -97,7 +97,7 @@ namespace drawerbase { void drawer::mouse_down(graph_reference, const arg_mouse& arg) { - if(editor_->mouse_down(arg.left_button, arg.pos)) + if(editor_->mouse_down(arg.button, arg.pos)) API::lazy_refresh(); } @@ -109,7 +109,7 @@ namespace drawerbase { void drawer::mouse_up(graph_reference graph, const arg_mouse& arg) { - if(editor_->mouse_up(arg.left_button, arg.pos)) + if(editor_->mouse_up(arg.button, arg.pos)) API::lazy_refresh(); } diff --git a/source/gui/widgets/toolbar.cpp b/source/gui/widgets/toolbar.cpp index 980a80ac..15de2fff 100644 --- a/source/gui/widgets/toolbar.cpp +++ b/source/gui/widgets/toolbar.cpp @@ -277,7 +277,7 @@ namespace nana impl_->which = which; if (which == npos || container.at(which)->enable) { - impl_->state = (arg.left_button ? item_renderer::state_t::selected : item_renderer::state_t::highlighted); + impl_->state = item_renderer::state_t::highlighted; refresh(graph); API::lazy_refresh(); diff --git a/source/gui/widgets/treebox.cpp b/source/gui/widgets/treebox.cpp index 178120f6..1c70e7e6 100644 --- a/source/gui/widgets/treebox.cpp +++ b/source/gui/widgets/treebox.cpp @@ -583,7 +583,7 @@ namespace nana void event_scrollbar(const arg_mouse& arg) { - if((event_code::mouse_wheel == arg.evt_code) || arg.left_button) + if((event_code::mouse_wheel == arg.evt_code) || arg.is_left_button()) { if(shape.prev_first_value != shape.scroll.value()) { @@ -719,17 +719,29 @@ namespace nana node_state.tooltip->impl().assign(node_attr, &data.renderer, &data.comp_placer); node_state.tooltip->show(); - auto & events = node_state.tooltip->events(); - events.mouse_leave.connect([this](const arg_mouse&){ - this->close_tooltip_window(); - }); - events.mouse_move.connect([this](const arg_mouse&){ - this->mouse_move_tooltip_window(); - }); - - auto fn = [this](const arg_mouse& arg){ - this->click_tooltip_window(arg); + auto fn = [this](const arg_mouse& arg) + { + switch (arg.evt_code) + { + case event_code::mouse_leave: + close_tooltip_window(); + break; + case event_code::mouse_move: + mouse_move_tooltip_window(); + break; + case event_code::mouse_down: + case event_code::mouse_up: + case event_code::dbl_click: + click_tooltip_window(arg); + break; + default: //ignore other events + break; + } }; + + auto & events = node_state.tooltip->events(); + events.mouse_leave(fn); + events.mouse_move(fn); events.mouse_down.connect(fn); events.mouse_up.connect(fn); events.dbl_click.connect(fn);