a bool param to determines whether the caret move to end of text

This commit is contained in:
Jinhao
2016-05-10 15:52:06 +08:00
parent 79f484dd2e
commit df68cfa3ad
7 changed files with 61 additions and 35 deletions

View File

@@ -351,7 +351,7 @@ namespace nana
if (calc_where(*graph_, pos.x, pos.y))
state_.button_state = element_state::normal;
editor_->text(::nana::charset(items_[index]->item_text, ::nana::unicode::utf8));
editor_->text(::nana::charset(items_[index]->item_text, ::nana::unicode::utf8), false);
_m_draw_push_button(widget_->enabled());
_m_draw_image();
@@ -993,7 +993,7 @@ namespace nana
auto editor = _m_impl().editor();
if (editor)
editor->text(to_wstring(str));
editor->text(to_wstring(str), false);
API::refresh_window(*this);
}

View File

@@ -18,7 +18,6 @@
#include <numeric>
#include <cwctype>
#include <cstring>
#include <set>
#include <algorithm>
namespace nana{ namespace widgets
@@ -442,11 +441,8 @@ namespace nana{ namespace widgets
editor_._m_get_scrollbar_size();
auto x = points.caret.x;
auto& lnstr = textbase.getline(points.caret.y);
if (x > lnstr.size()) x = static_cast<unsigned>(lnstr.size());
const auto x = (points.caret.x > lnstr.size() ? static_cast<decltype(points.caret.x)>(lnstr.size()) : points.caret.x);
auto const text_w = editor_._m_pixels_by_char(lnstr, x);
unsigned area_w = editor_._m_text_area().width;
@@ -515,11 +511,12 @@ namespace nana{ namespace widgets
const wchar_t* begin;
const wchar_t* end;
unsigned pixels;
text_section()
/*
text_section() //deprecated
{
throw std::runtime_error("text_section default construction is forbidden.");
}
*/
text_section(const wchar_t* ptr, const wchar_t* endptr)
: begin(ptr), end(endptr)
@@ -1808,12 +1805,34 @@ namespace nana{ namespace widgets
return true;
}
void text_editor::text(std::wstring str)
void text_editor::text(std::wstring str, bool end_caret)
{
undo_.clear();
textbase_.erase_all();
_m_reset();
behavior_->pre_calc_lines(width_pixels());
put(std::move(str));
if (!end_caret)
{
auto undo_ptr = std::unique_ptr<undo_input_text>{ new undo_input_text(*this, str) };
undo_ptr->set_caret_pos();
_m_put(std::move(str));
undo_.push(std::move(undo_ptr));
if (graph_)
{
behavior_->adjust_caret_into_screen();
reset_caret();
render(API::is_focus_ready(window_));
_m_scrollbar();
points_.xpos = 0;
}
}
else
put(std::move(str));
}
std::wstring text_editor::text() const
@@ -2324,7 +2343,6 @@ namespace nana{ namespace widgets
behavior_->adjust_caret_into_screen();
render(true);
_m_scrollbar();
}
void text_editor::move_ns(bool to_north)
@@ -2965,9 +2983,6 @@ namespace nana{ namespace widgets
nana::size text_editor::_m_text_extent_size(const char_type* str, size_type n) const
{
if (!graph_)
return{};
if(mask_char_)
{
std::wstring maskstr;

View File

@@ -422,9 +422,9 @@ namespace nana
return;
if (API::is_focus_ready(editor_->window_handle()))
editor_->text(to_wstring(range_->value()));
editor_->text(to_wstring(range_->value()), false);
else
editor_->text(to_wstring(modifier_.prefix + range_->value() + modifier_.suffix));
editor_->text(to_wstring(modifier_.prefix + range_->value() + modifier_.suffix), false);
_m_draw_spins(spin_stated_);
}
@@ -697,7 +697,7 @@ namespace nana
auto editor = get_drawer_trigger().impl()->editor();
if (editor)
{
editor->text(to_wstring(text));
editor->text(to_wstring(text), false);
API::refresh_window(*this);
}
}

View File

@@ -254,13 +254,14 @@ namespace drawerbase {
return *this;
}
textbox& textbox::reset(const std::string& str)
textbox& textbox::reset(const std::string& str, bool end_caret)
{
internal_scope_guard lock;
auto editor = get_drawer_trigger().editor();
if (editor)
{
editor->text(to_wstring(str));
{
editor->text(to_wstring(str), end_caret);
editor->textbase().reset();
API::update_window(this->handle());
}
@@ -622,7 +623,7 @@ namespace drawerbase {
auto editor = get_drawer_trigger().editor();
if (editor)
{
editor->text(to_wstring(str));
editor->text(to_wstring(str), false);
API::update_window(this->handle());
}
}