diff --git a/include/nana/gui/widgets/skeletons/text_editor.hpp b/include/nana/gui/widgets/skeletons/text_editor.hpp index 62da6ab3..cf1f207a 100644 --- a/include/nana/gui/widgets/skeletons/text_editor.hpp +++ b/include/nana/gui/widgets/skeletons/text_editor.hpp @@ -250,9 +250,8 @@ namespace nana{ namespace widgets point caret_screen_pos() const; bool scroll(bool upwards, bool vertical); bool mouse_enter(bool); - bool mouse_down(::nana::mouse, const point& screen_pos); bool mouse_move(bool left_button, const point& screen_pos); - bool mouse_up(::nana::mouse, const point& screen_pos); + bool mouse_pressed(const arg_mouse& arg); skeletons::textbase& textbase(); const skeletons::textbase& textbase() const; @@ -365,6 +364,7 @@ namespace nana{ namespace widgets { nana::point offset; //x stands for pixels, y for lines nana::upoint caret; //position of caret by text, it specifies the position of a new character + nana::upoint shift_begin_caret; unsigned xpos{0}; //This data is used for move up/down }points_; }; diff --git a/source/gui/widgets/combox.cpp b/source/gui/widgets/combox.cpp index 45718364..af007d50 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.button, arg.pos)) + if (!editor->mouse_pressed(arg)) 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.button, arg.pos); + drawer_->editor()->mouse_pressed(arg); drawer_->set_button_state(element_state::hovered, false); drawer_->draw(); API::lazy_refresh(); diff --git a/source/gui/widgets/skeletons/text_editor.cpp b/source/gui/widgets/skeletons/text_editor.cpp index 654e317c..461a734e 100644 --- a/source/gui/widgets/skeletons/text_editor.cpp +++ b/source/gui/widgets/skeletons/text_editor.cpp @@ -1646,30 +1646,6 @@ namespace nana{ namespace widgets return true; } - bool text_editor::mouse_down(::nana::mouse button, const point& scrpos) - { - if (!hit_text_area(scrpos)) - return false; - - if(::nana::mouse::left_button == button) - { - API::capture_window(window_, true); - text_area_.captured = true; - - //Set caret pos by screen point and get the caret pos. - mouse_caret(scrpos); - if(!select(false)) - { - select_.a = points_.caret; //Set begin caret - set_end_caret(); - } - select_.mode_selection = selection::mode_mouse_selected; - } - - text_area_.border_renderer(graph_, _m_bgcolor()); - return true; - } - bool text_editor::mouse_move(bool left_button, const point& scrpos) { cursor cur = cursor::iterm; @@ -1694,31 +1670,70 @@ namespace nana{ namespace widgets return false; } - bool text_editor::mouse_up(::nana::mouse button, const point& scrpos) + bool text_editor::mouse_pressed(const arg_mouse& arg) { - auto is_prev_no_selected = (select_.mode_selection == selection::mode_no_selected); - - if(select_.mode_selection == selection::mode_mouse_selected) + if (event_code::mouse_down == arg.evt_code) { - select_.mode_selection = selection::mode_no_selected; - set_end_caret(); + if (!hit_text_area(arg.pos)) + return false; + + if (::nana::mouse::left_button == arg.button) + { + API::capture_window(window_, true); + text_area_.captured = true; + + //Set caret pos by screen point and get the caret pos. + mouse_caret(arg.pos); + if (arg.shift) + { + if (points_.shift_begin_caret != points_.caret) + { + select_.a = points_.shift_begin_caret; + select_.b = points_.caret; + } + } + else + { + if (!select(false)) + { + select_.a = points_.caret; //Set begin caret + set_end_caret(); + } + points_.shift_begin_caret = points_.caret; + } + select_.mode_selection = selection::mode_mouse_selected; + } + + text_area_.border_renderer(graph_, _m_bgcolor()); + return true; } - else if (is_prev_no_selected) + else if (event_code::mouse_up == arg.evt_code) { - if((!select_.dragged) || (!move_select())) - select(false); + auto is_prev_no_selected = (select_.mode_selection == selection::mode_no_selected); + + if (select_.mode_selection == selection::mode_mouse_selected) + { + select_.mode_selection = selection::mode_no_selected; + set_end_caret(); + } + else if (is_prev_no_selected) + { + if ((!select_.dragged) || (!move_select())) + select(false); + } + select_.dragged = false; + + API::capture_window(window_, false); + text_area_.captured = false; + if (hit_text_area(arg.pos) == false) + API::window_cursor(window_, nana::cursor::arrow); + + text_area_.border_renderer(graph_, _m_bgcolor()); + + //Redraw if is_prev_no_selected is true + return is_prev_no_selected; } - select_.dragged = false; - - API::capture_window(window_, false); - text_area_.captured = false; - if (hit_text_area(scrpos) == false) - API::window_cursor(window_, nana::cursor::arrow); - - text_area_.border_renderer(graph_, _m_bgcolor()); - - //Redraw if is_prev_no_selected is true - return is_prev_no_selected; + return false; } textbase & text_editor::textbase() diff --git a/source/gui/widgets/spinbox.cpp b/source/gui/widgets/spinbox.cpp index a5fddd26..a4d6e08d 100644 --- a/source/gui/widgets/spinbox.cpp +++ b/source/gui/widgets/spinbox.cpp @@ -367,17 +367,13 @@ namespace nana return true; } - - bool refreshed = false; - if (pressed) - refreshed = editor_->mouse_down(arg.button, arg.pos); - else - refreshed = editor_->mouse_up(arg.button, arg.pos); - - if (refreshed) + if (editor_->mouse_pressed(arg)) + { _m_draw_spins(buttons::none); + return true; + } - return refreshed; + return false; } bool mouse_move(bool left_button, const ::nana::point& pos) diff --git a/source/gui/widgets/textbox.cpp b/source/gui/widgets/textbox.cpp index 31602540..c1e402c9 100644 --- a/source/gui/widgets/textbox.cpp +++ b/source/gui/widgets/textbox.cpp @@ -111,8 +111,11 @@ namespace drawerbase { void drawer::mouse_down(graph_reference, const arg_mouse& arg) { - if(editor_->mouse_down(arg.button, arg.pos)) + if (editor_->mouse_pressed(arg)) + { + editor_->render(true); API::lazy_refresh(); + } } void drawer::mouse_move(graph_reference, const arg_mouse& arg) @@ -123,7 +126,7 @@ namespace drawerbase { void drawer::mouse_up(graph_reference graph, const arg_mouse& arg) { - if(editor_->mouse_up(arg.button, arg.pos)) + if(editor_->mouse_pressed(arg)) API::lazy_refresh(); } diff --git a/source/paint/image.cpp b/source/paint/image.cpp index c8a4098e..ddbf317b 100644 --- a/source/paint/image.cpp +++ b/source/paint/image.cpp @@ -161,17 +161,6 @@ namespace paint image::image_impl_interface::~image_impl_interface() {} - /* - namespace detail - { - int toupper(int c) //deprecated - { - return (('a' <= c && c <= 'z') ? - c - ('a' - 'A') - : c); - } - }//end namespace detail - //*/ //class image image::image()