add selection of text by using shift+mouse click
This commit is contained in:
parent
8da183cfab
commit
9fd1a594cb
@ -250,9 +250,8 @@ namespace nana{ namespace widgets
|
|||||||
point caret_screen_pos() const;
|
point caret_screen_pos() const;
|
||||||
bool scroll(bool upwards, bool vertical);
|
bool scroll(bool upwards, bool vertical);
|
||||||
bool mouse_enter(bool);
|
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_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<nana::char_t>& textbase();
|
skeletons::textbase<nana::char_t>& textbase();
|
||||||
const skeletons::textbase<nana::char_t>& textbase() const;
|
const skeletons::textbase<nana::char_t>& textbase() const;
|
||||||
@ -365,6 +364,7 @@ namespace nana{ namespace widgets
|
|||||||
{
|
{
|
||||||
nana::point offset; //x stands for pixels, y for lines
|
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 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
|
unsigned xpos{0}; //This data is used for move up/down
|
||||||
}points_;
|
}points_;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -622,7 +622,7 @@ namespace nana
|
|||||||
if(drawer_->widget_ptr()->enabled())
|
if(drawer_->widget_ptr()->enabled())
|
||||||
{
|
{
|
||||||
auto * editor = drawer_->editor();
|
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_->open_lister_if_push_button_positioned();
|
||||||
|
|
||||||
drawer_->draw();
|
drawer_->draw();
|
||||||
@ -637,7 +637,7 @@ namespace nana
|
|||||||
{
|
{
|
||||||
if (drawer_->widget_ptr()->enabled() && !drawer_->has_lister())
|
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_->set_button_state(element_state::hovered, false);
|
||||||
drawer_->draw();
|
drawer_->draw();
|
||||||
API::lazy_refresh();
|
API::lazy_refresh();
|
||||||
|
|||||||
@ -1646,30 +1646,6 @@ namespace nana{ namespace widgets
|
|||||||
return true;
|
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)
|
bool text_editor::mouse_move(bool left_button, const point& scrpos)
|
||||||
{
|
{
|
||||||
cursor cur = cursor::iterm;
|
cursor cur = cursor::iterm;
|
||||||
@ -1694,31 +1670,70 @@ namespace nana{ namespace widgets
|
|||||||
return false;
|
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 (event_code::mouse_down == arg.evt_code)
|
||||||
|
|
||||||
if(select_.mode_selection == selection::mode_mouse_selected)
|
|
||||||
{
|
{
|
||||||
select_.mode_selection = selection::mode_no_selected;
|
if (!hit_text_area(arg.pos))
|
||||||
set_end_caret();
|
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()))
|
auto is_prev_no_selected = (select_.mode_selection == selection::mode_no_selected);
|
||||||
select(false);
|
|
||||||
|
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;
|
return 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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
textbase<nana::char_t> & text_editor::textbase()
|
textbase<nana::char_t> & text_editor::textbase()
|
||||||
|
|||||||
@ -367,17 +367,13 @@ namespace nana
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (editor_->mouse_pressed(arg))
|
||||||
bool refreshed = false;
|
{
|
||||||
if (pressed)
|
|
||||||
refreshed = editor_->mouse_down(arg.button, arg.pos);
|
|
||||||
else
|
|
||||||
refreshed = editor_->mouse_up(arg.button, arg.pos);
|
|
||||||
|
|
||||||
if (refreshed)
|
|
||||||
_m_draw_spins(buttons::none);
|
_m_draw_spins(buttons::none);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
return refreshed;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool mouse_move(bool left_button, const ::nana::point& pos)
|
bool mouse_move(bool left_button, const ::nana::point& pos)
|
||||||
|
|||||||
@ -111,8 +111,11 @@ namespace drawerbase {
|
|||||||
|
|
||||||
void drawer::mouse_down(graph_reference, const arg_mouse& arg)
|
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();
|
API::lazy_refresh();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void drawer::mouse_move(graph_reference, const arg_mouse& arg)
|
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)
|
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();
|
API::lazy_refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -161,17 +161,6 @@ namespace paint
|
|||||||
|
|
||||||
image::image_impl_interface::~image_impl_interface()
|
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
|
//class image
|
||||||
image::image()
|
image::image()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user