Merge branch 'PeterAddy960-hotfix-1.4' into hotfix-1.4.1

This commit is contained in:
Jinhao 2016-10-31 06:14:10 +08:00
commit a3de89aab5
6 changed files with 89 additions and 28 deletions

View File

@ -134,6 +134,7 @@ namespace nana{ namespace widgets
std::size_t undo_max_steps() const;
renderers& customized_renderers();
void clear_undo(); ///< same with undo_max_steps(0)
unsigned line_height() const;
unsigned screen_lines() const;
@ -154,8 +155,9 @@ namespace nana{ namespace widgets
void show_caret(bool isshow);
bool selected() const;
bool get_selected_points(nana::upoint&, nana::upoint&) const;
bool select(bool);
bool get_select_points(nana::upoint&, nana::upoint&) const;
/// Sets the end position of a selected string.
void set_end_caret();

View File

@ -162,6 +162,9 @@ namespace nana
/// Read the text from a specified line. It returns true for success.
bool getline(std::size_t pos, std::string&) const;
/// Read the text from a specified line with a set offset. It returns true for success.
bool getline(std::size_t line_index,std::size_t offset,std::string& text) const;
/// Gets the caret position
/// Returns true if the caret is in the area of display, false otherwise.
bool caret_pos(point& pos, bool text_coordinate) const;
@ -196,6 +199,7 @@ namespace nana
/// Returns true if some text is selected.
bool selected() const;
bool get_selected_points(nana::upoint &a, nana::upoint &b) const;
/// Selects/unselects all text.
void select(bool);
@ -215,6 +219,8 @@ namespace nana
textbox& from(int);
textbox& from(double);
void clear_undo();
void set_highlight(const std::string& name, const ::nana::color& fgcolor, const ::nana::color& bgcolor);
void erase_highlight(const std::string& name);
void set_keywords(const std::string& name, bool case_sensitive, bool whole_word_match, std::initializer_list<std::wstring> kw_list);

View File

@ -51,6 +51,8 @@ namespace nana
bool italic() const;
native_font_type handle() const;
void release();
bool strikeout() const;
bool underline() const;
font& operator=(const font&);
bool operator==(const font&) const;

View File

@ -1574,7 +1574,8 @@ namespace nana{ namespace widgets
_m_handle_move_key(arg);
break;
case keyboard::os_del:
if (this->attr().editable)
// send delete to set_accept function
if (this->attr().editable && (!impl_->capacities.pred_acceptive || impl_->capacities.pred_acceptive(key)))
del();
break;
default:
@ -1746,6 +1747,13 @@ namespace nana{ namespace widgets
return impl_->undo.max_steps();
}
void text_editor::clear_undo()
{
auto size = impl_->undo.max_steps();
impl_->undo.max_steps(0);
impl_->undo.max_steps(size);
}
auto text_editor::customized_renderers() -> renderers&
{
return impl_->customized_renderers;
@ -2065,6 +2073,25 @@ namespace nana{ namespace widgets
return (select_.a != select_.b);
}
bool text_editor::get_selected_points(nana::upoint &a, nana::upoint &b) const
{
if (select_.a == select_.b)
return false;
if (select_.a < select_.b)
{
a = select_.a;
b = select_.b;
}
else
{
a = select_.b;
b = select_.a;
}
return true;
}
void text_editor::set_end_caret()
{
bool new_sel_end = (select_.b != points_.caret);
@ -2097,25 +2124,6 @@ namespace nana{ namespace widgets
return false;
}
bool text_editor::get_select_points(nana::upoint& a, nana::upoint& b) const
{
if (select_.a == select_.b)
return false;
if (select_.a < select_.b)
{
a = select_.a;
b = select_.b;
}
else
{
a = select_.b;
b = select_.a;
}
return true;
}
bool text_editor::hit_text_area(const point& pos) const
{
return _m_text_area().is_hit(pos);
@ -2124,7 +2132,7 @@ namespace nana{ namespace widgets
bool text_editor::hit_select_area(nana::upoint pos, bool ignore_when_select_all) const
{
nana::upoint a, b;
if(get_select_points(a, b))
if (get_selected_points(a, b))
{
if (ignore_when_select_all)
{
@ -3046,7 +3054,7 @@ namespace nana{ namespace widgets
nana::upoint text_editor::_m_erase_select()
{
nana::upoint a, b;
if (get_select_points(a, b))
if (get_selected_points(a, b))
{
auto & textbase = this->textbase();
if(a.y != b.y)
@ -3077,7 +3085,7 @@ namespace nana{ namespace widgets
std::wstring text;
nana::upoint a, b;
if (get_select_points(a, b))
if (get_selected_points(a, b))
{
auto & textbase = this->textbase();
if (a.y != b.y)
@ -3168,7 +3176,7 @@ namespace nana{ namespace widgets
bool text_editor::_m_cancel_select(int align)
{
nana::upoint a, b;
if (get_select_points(a, b))
if (get_selected_points(a, b))
{
switch(align)
{
@ -3263,7 +3271,7 @@ namespace nana{ namespace widgets
const bool at_left = (select_.b < select_.a);
nana::upoint a, b;
get_select_points(a, b);
get_selected_points(a, b);
if (caret.y < a.y || (caret.y == a.y && caret.x < a.x))
{//forward
undo_ptr->set_caret_pos();
@ -3459,7 +3467,7 @@ namespace nana{ namespace widgets
const wchar_t *sbegin = nullptr, *send = nullptr;
nana::upoint a, b;
if (get_select_points(a, b))
if (get_selected_points(a, b))
{
if (a.y < text_coord.y && text_coord.y < b.y)
{

View File

@ -322,6 +322,25 @@ namespace drawerbase {
return false;
}
bool textbox::getline(std::size_t line_index,std::size_t start_point,std::string& text) const
{
internal_scope_guard lock;
auto editor = get_drawer_trigger().editor();
if(editor)
{
std::wstring line_text;
if(editor->getline(line_index,line_text))
{
if(line_text.length() >= start_point)
{
text = to_utf8(line_text.substr(start_point));
return true;
}
}
}
return false;
}
/// Gets the caret position
bool textbox::caret_pos(point& pos, bool text_coordinate) const
{
@ -464,6 +483,13 @@ namespace drawerbase {
return (editor ? editor->selected() : false);
}
bool textbox::get_selected_points(nana::upoint &a, nana::upoint &b) const
{
internal_scope_guard lock;
auto editor = get_drawer_trigger().editor();
return (editor ? editor->get_selected_points(a, b) : false);
}
void textbox::select(bool yes)
{
internal_scope_guard lock;
@ -479,7 +505,7 @@ namespace drawerbase {
internal_scope_guard lock;
auto editor = get_drawer_trigger().editor();
if (editor)
editor->get_select_points(points.first, points.second);
editor->get_selected_points(points.first, points.second);
return points;
}
@ -542,6 +568,11 @@ namespace drawerbase {
return *this;
}
void textbox::clear_undo()
{
get_drawer_trigger().editor()->clear_undo();
}
void textbox::set_highlight(const std::string& name, const ::nana::color& fgcolor, const ::nana::color& bgcolor)
{
internal_scope_guard lock;

View File

@ -156,6 +156,18 @@ namespace paint
return (impl_->font_ptr->italic);
}
bool font::underline() const
{
if(empty()) return false;
return (impl_->font_ptr->underline);
}
bool font::strikeout() const
{
if(empty()) return false;
return (impl_->font_ptr->strikeout);
}
native_font_type font::handle() const
{
if(empty()) return nullptr;