use UTF-8 for string representation

This commit is contained in:
Jinhao
2015-12-15 21:46:24 +08:00
parent 8fc84938bf
commit c260eebbc3
11 changed files with 178 additions and 165 deletions

View File

@@ -708,7 +708,7 @@ namespace nana
impl->spinbox.create(impl->dock, rectangle{ static_cast<int>(label_px + 10), 0, value_px, 0 });
impl->spinbox.range(impl->begin, impl->last, impl->step);
impl->spinbox.value(std::to_wstring(impl->value));
impl->spinbox.value(std::to_string(impl->value));
impl->dock.events().resized.connect_unignorable([impl, label_px, value_px](const ::nana::arg_resized& arg)
{
@@ -786,7 +786,7 @@ namespace nana
impl->spinbox.create(impl->dock, rectangle{ static_cast<int>(label_px + 10), 0, value_px, 0 });
impl->spinbox.range(impl->begin, impl->last, impl->step);
impl->spinbox.value(std::to_wstring(impl->value));
impl->spinbox.value(std::to_string(impl->value));
impl->dock.events().resized.connect_unignorable([impl, label_px, value_px](const ::nana::arg_resized& arg)
{
@@ -1017,8 +1017,8 @@ namespace nana
impl->wdg_month.option(today.month - 1);
impl->wdg_day.value(std::to_wstring(today.day));
impl->wdg_year.value(std::to_wstring(today.year));
impl->wdg_day.value(std::to_string(today.day));
impl->wdg_year.value(std::to_string(today.year));
impl->dock.events().resized.connect_unignorable([impl, label_px](const ::nana::arg_resized& arg)
{
@@ -1059,7 +1059,7 @@ namespace nana
if (day > days)
day = days;
impl->wdg_day.value(std::to_wstring(day));
impl->wdg_day.value(std::to_string(day));
};
impl->wdg_year.events().text_changed.connect_unignorable(make_days);

View File

@@ -61,7 +61,7 @@ namespace nana{ namespace widgets
text_editor & editor_;
upoint pos_;
upoint sel_a_, sel_b_;
nana::string selected_text_;
std::wstring selected_text_;
private:
const EnumCommand cmd_;
};
@@ -75,7 +75,7 @@ namespace nana{ namespace widgets
{
}
void set_removed(nana::string str)
void set_removed(std::wstring str)
{
//use selected_text_ as removed text
selected_text_ = str;
@@ -136,7 +136,7 @@ namespace nana{ namespace widgets
: public basic_undoable <command>
{
public:
undo_input_text(text_editor & editor, const nana::string& text)
undo_input_text(text_editor & editor, const std::wstring& text)
: basic_undoable<command>(editor, command::input_text),
text_(text)
{
@@ -199,7 +199,7 @@ namespace nana{ namespace widgets
editor_.move_caret(editor_.points_.caret);
}
private:
nana::string text_;
std::wstring text_;
};
class text_editor::undo_move_text
@@ -325,9 +325,9 @@ namespace nana{ namespace widgets
if (pos.y > static_cast<unsigned>(textbase.lines()))
pos.y = static_cast<unsigned>(textbase.lines());
std::unique_ptr<nana::string> mask_str;
std::unique_ptr<std::wstring> mask_str;
if (editor_.mask_char_)
mask_str.reset(new nana::string(textbase.getline(pos.y).size(), editor_.mask_char_));
mask_str.reset(new std::wstring(textbase.getline(pos.y).size(), editor_.mask_char_));
auto & lnstr = editor_.mask_char_ ? *mask_str : textbase.getline(pos.y);
@@ -345,9 +345,9 @@ namespace nana{ namespace widgets
//Convert the screen point to text caret point
const string_type& real_str = editor_.textbase_.getline(res.y);
std::unique_ptr<nana::string> mask_str;
std::unique_ptr<std::wstring> mask_str;
if (editor_.mask_char_)
mask_str.reset(new nana::string(real_str.size(), editor_.mask_char_));
mask_str.reset(new std::wstring(real_str.size(), editor_.mask_char_));
auto & lnstr = (editor_.mask_char_ ? *mask_str : real_str);
if (lnstr.size() > 0)
@@ -539,8 +539,8 @@ namespace nana{ namespace widgets
std::size_t line = 0;
for (auto & mtr: linemtr_)
{
const nana::string& linestr = editor_.textbase_.getline(line);
const nana::char_t * p = mtr.line_sections.front().begin;
auto& linestr = editor_.textbase_.getline(line);
auto p = mtr.line_sections.front().begin;
if (p < linestr.data() || (linestr.data() + linestr.size() < p))
pre_calc_line(line, editor_.width_pixels());
@@ -562,8 +562,8 @@ namespace nana{ namespace widgets
{
if (line < pos || (pos + lines) <= line)
{
const nana::string& linestr = editor_.textbase_.getline(line);
const nana::char_t * p = mtr.line_sections.front().begin;
auto & linestr = editor_.textbase_.getline(line);
auto p = mtr.line_sections.front().begin;
if (p < linestr.data() || (linestr.data() + linestr.size() < p))
pre_calc_line(line, editor_.width_pixels());
}
@@ -697,7 +697,7 @@ namespace nana{ namespace widgets
for (std::size_t pos = 0; pos < secondary_before; ++pos, top+=pixels)
{
auto & sct = linemtr_[textline].line_sections[pos];
editor_._m_draw_string(top, fgcolor, nana::upoint(static_cast<unsigned>(sct.begin - text_ptr), editor_.points_.caret.y), nana::string(sct.begin, sct.end), true);
editor_._m_draw_string(top, fgcolor, nana::upoint(static_cast<unsigned>(sct.begin - text_ptr), editor_.points_.caret.y), std::wstring(sct.begin, sct.end), true);
}
}
else
@@ -727,7 +727,7 @@ namespace nana{ namespace widgets
auto & mtr = linemtr_[primary];
auto & section = mtr.line_sections[secondary];
nana::string text(section.begin, section.end);
std::wstring text(section.begin, section.end);
editor_._m_draw_string(top, fgcolor, str_pos, text, true);
line_index.push_back(str_pos);
++secondary;
@@ -767,7 +767,7 @@ namespace nana{ namespace widgets
nana::point scrpos;
if (0 != pos.x)
{
nana::string str;
std::wstring str;
for (auto & sec : mtr.line_sections)
{
std::size_t chsize = sec.end - sec.begin;
@@ -812,9 +812,9 @@ namespace nana{ namespace widgets
//First of all, find the text of secondary.
auto real_str = mtr.line_sections[secondary];
std::unique_ptr<nana::string> mask_str;
std::unique_ptr<std::wstring> mask_str;
if (editor_.mask_char_)
mask_str.reset(new nana::string(real_str.end - real_str.begin, editor_.mask_char_));
mask_str.reset(new std::wstring(real_str.end - real_str.begin, editor_.mask_char_));
const ::nana::char_t * str = (editor_.mask_char_ ? mask_str->data() : real_str.begin);
@@ -925,7 +925,7 @@ namespace nana{ namespace widgets
return true;
}
private:
void _m_text_section(const nana::string& str, std::vector<text_section>& tsec)
void _m_text_section(const std::wstring& str, std::vector<text_section>& tsec)
{
if (str.empty())
{
@@ -1148,12 +1148,12 @@ namespace nana{ namespace widgets
struct keyword_desc
{
::nana::string text;
std::wstring text;
std::string scheme;
bool case_sensitive;
bool whole_word_matched;
keyword_desc(const ::nana::string& txt, const std::string& schm, bool cs, bool wwm)
keyword_desc(const std::wstring& txt, const std::string& schm, bool cs, bool wwm)
: text(txt), scheme(schm), case_sensitive(cs), whole_word_matched(wwm)
{}
};
@@ -1174,12 +1174,12 @@ namespace nana{ namespace widgets
class text_editor::keyword_parser
{
public:
void parse(const ::nana::string& text, const keywords* kwptr)
void parse(const std::wstring& text, const keywords* kwptr)
{
if ( kwptr->kwbase.empty() || text.empty() )
return;
using index = ::nana::string::size_type;
using index = std::wstring::size_type;
std::vector<entity> entities;
@@ -1329,7 +1329,7 @@ namespace nana{ namespace widgets
keywords_->schemes.erase(name);
}
void text_editor::set_keyword(const ::nana::string& kw, const std::string& name, bool case_sensitive, bool whole_word_matched)
void text_editor::set_keyword(const ::std::wstring& kw, const std::string& name, bool case_sensitive, bool whole_word_matched)
{
for (auto & ds : keywords_->kwbase)
{
@@ -1344,7 +1344,7 @@ namespace nana{ namespace widgets
keywords_->kwbase.emplace_back(kw, name, case_sensitive, whole_word_matched);
}
void text_editor::erase_keyword(const ::nana::string& kw)
void text_editor::erase_keyword(const ::std::wstring& kw)
{
for (auto i = keywords_->kwbase.begin(); i != keywords_->kwbase.end(); ++i)
if (i->text == kw)
@@ -1446,7 +1446,7 @@ namespace nana{ namespace widgets
behavior_->pre_calc_lines(width_pixels());
}
void text_editor::indent(bool enb, std::function<nana::string()> generator)
void text_editor::indent(bool enb, std::function<std::string()> generator)
{
indent_.enabled = enb;
indent_.generator.swap(generator);
@@ -1493,7 +1493,7 @@ namespace nana{ namespace widgets
text_area_.border_renderer = f;
}
bool text_editor::load(const nana::char_t* fs)
bool text_editor::load(const char* fs)
{
if (!textbase_.load(fs))
return false;
@@ -1533,7 +1533,7 @@ namespace nana{ namespace widgets
return r;
}
bool text_editor::tip_string(nana::string&& str)
bool text_editor::tip_string(::std::string&& str)
{
if(attributes_.tip_string == str)
return false;
@@ -1739,7 +1739,7 @@ namespace nana{ namespace widgets
return textbase_;
}
bool text_editor::getline(std::size_t pos, nana::string& text) const
bool text_editor::getline(std::size_t pos, std::wstring& text) const
{
if (textbase_.lines() <= pos)
return false;
@@ -1748,16 +1748,16 @@ namespace nana{ namespace widgets
return true;
}
void text_editor::text(nana::string str)
void text_editor::text(std::wstring str)
{
textbase_.erase_all();
_m_reset();
put(std::move(str));
}
nana::string text_editor::text() const
std::wstring text_editor::text() const
{
nana::string str;
std::wstring str;
std::size_t lines = textbase_.lines();
if(lines > 0)
{
@@ -1984,7 +1984,7 @@ namespace nana{ namespace widgets
text_area_.border_renderer(graph_, bgcolor);
}
//public:
void text_editor::put(nana::string text)
void text_editor::put(std::wstring text)
{
auto undo_ptr = std::unique_ptr<undo_input_text>{ new undo_input_text(*this, text) };
@@ -2010,9 +2010,11 @@ namespace nana{ namespace widgets
}
}
void text_editor::put(nana::char_t c)
void text_editor::put(wchar_t ch)
{
auto undo_ptr = std::unique_ptr < undo_input_text > {new undo_input_text(*this, nana::string(1, c))};
std::wstring ch_str(1, ch);
auto undo_ptr = std::unique_ptr < undo_input_text > {new undo_input_text(*this, ch_str)};
bool refresh = (select_.a != select_.b);
undo_ptr->set_selected_text();
@@ -2023,7 +2025,7 @@ namespace nana{ namespace widgets
undo_.push(std::move(undo_ptr));
auto secondary_before = behavior_->take_lines(points_.caret.y);
textbase_.insert(points_.caret, nana::string(1, c));
textbase_.insert(points_.caret, std::move(ch_str));
behavior_->pre_calc_line(points_.caret.y, width_pixels());
points_.caret.x ++;
@@ -2039,7 +2041,7 @@ namespace nana{ namespace widgets
void text_editor::copy() const
{
nana::string str;
std::wstring str;
if(_m_make_select_string(str))
nana::system::dataexch().set(str);
}
@@ -2052,7 +2054,7 @@ namespace nana{ namespace widgets
void text_editor::paste()
{
nana::string text;
std::wstring text;
nana::system::dataexch().get(text);
//If it is required check the acceptable
@@ -2077,7 +2079,7 @@ namespace nana{ namespace widgets
if(false == attributes_.multi_lines)
return;
auto undo_ptr = std::unique_ptr<undo_input_text>(new undo_input_text(*this, nana::string(1, '\n')));
auto undo_ptr = std::unique_ptr<undo_input_text>(new undo_input_text(*this, std::wstring(1, '\n')));
bool need_refresh = (select_.a != select_.b);
undo_ptr->set_selected_text();
@@ -2098,8 +2100,8 @@ namespace nana{ namespace widgets
else
{
if (textbase_.lines() == 0)
textbase_.insertln(0, nana::string{});
textbase_.insertln(points_.caret.y, nana::string{});
textbase_.insertln(0, std::wstring{});
textbase_.insertln(points_.caret.y, std::wstring{});
}
if (record_undo)
@@ -2120,10 +2122,10 @@ namespace nana{ namespace widgets
if (indent_.enabled)
{
nana::string indent_text;
std::wstring indent_text;
if (indent_.generator)
{
indent_text = indent_.generator();
indent_text = to_wstring(indent_.generator());
}
else
{
@@ -2203,7 +2205,7 @@ namespace nana{ namespace widgets
textbase_.merge(points_.caret.y);
behavior_->merge_lines(points_.caret.y, points_.caret.y + 1);
undo_ptr->set_caret_pos();
undo_ptr->set_removed(nana::string(1, '\n'));
undo_ptr->set_removed(std::wstring(1, '\n'));
}
else
undo_ptr.reset();
@@ -2658,13 +2660,13 @@ namespace nana{ namespace widgets
select_.a = select_.b;
}
nana::upoint text_editor::_m_put(nana::string text)
nana::upoint text_editor::_m_put(std::wstring text)
{
auto crtpos = points_.caret;
std::vector<std::pair<std::size_t, std::size_t>> lines;
if (_m_resolve_text(text, lines) && attributes_.multi_lines)
{
nana::string str_orig = textbase_.getline(crtpos.y);
auto str_orig = textbase_.getline(crtpos.y);
auto x_orig = crtpos.x;
auto subpos = lines.front();
@@ -2713,7 +2715,7 @@ namespace nana{ namespace widgets
{
if(a.y != b.y)
{
textbase_.erase(a.y, a.x, nana::string::npos);
textbase_.erase(a.y, a.x, std::wstring::npos);
textbase_.erase(a.y + 1, b.y - a.y - 1);
textbase_.erase(a.y + 1, 0, b.x);
@@ -2734,7 +2736,7 @@ namespace nana{ namespace widgets
return points_.caret;
}
bool text_editor::_m_make_select_string(nana::string& text) const
bool text_editor::_m_make_select_string(std::wstring& text) const
{
nana::upoint a, b;
if (!_m_get_sort_select_points(a, b))
@@ -2782,7 +2784,7 @@ namespace nana{ namespace widgets
return pos + 1;
}
bool text_editor::_m_resolve_text(const nana::string& text, std::vector<std::pair<std::size_t, std::size_t>> & lines)
bool text_editor::_m_resolve_text(const std::wstring& text, std::vector<std::pair<std::size_t, std::size_t>> & lines)
{
auto const text_str = text.data();
std::size_t begin = 0;
@@ -2863,7 +2865,7 @@ namespace nana{ namespace widgets
if(mask_char_)
{
nana::string maskstr;
std::wstring maskstr;
maskstr.append(n, mask_char_);
return graph_.text_extent_size(maskstr);
}
@@ -2910,7 +2912,7 @@ namespace nana{ namespace widgets
bool text_editor::_m_move_select(bool record_undo)
{
nana::upoint caret = points_.caret;
nana::string text;
std::wstring text;
if (_m_make_select_string(text))
{
auto undo_ptr = std::unique_ptr<undo_move_text>(new undo_move_text(*this));
@@ -2972,7 +2974,7 @@ namespace nana{ namespace widgets
return static_cast<int>(text_area_.area.y + text_area_.area.height - text_area_.hscroll);
}
void text_editor::_m_draw_parse_string(const keyword_parser& parser, bool rtl, ::nana::point pos, const ::nana::color& fgcolor, const ::nana::char_t* str, std::size_t len) const
void text_editor::_m_draw_parse_string(const keyword_parser& parser, bool rtl, ::nana::point pos, const ::nana::color& fgcolor, const wchar_t* str, std::size_t len) const
{
graph_.set_text_color(fgcolor);
graph_.string(pos, str, len);
@@ -3034,14 +3036,14 @@ namespace nana{ namespace widgets
}
}
void text_editor::_m_draw_string(int top, const ::nana::color& clr, const nana::upoint& str_pos, const nana::string& str, bool if_mask) const
void text_editor::_m_draw_string(int top, const ::nana::color& clr, const nana::upoint& str_pos, const std::wstring& str, bool if_mask) const
{
::nana::point text_pos{ text_area_.area.x - points_.offset.x, top };
const int text_right = text_area_.area.right();
std::unique_ptr<nana::string> mask_str;
std::unique_ptr<std::wstring> mask_str;
if (if_mask && mask_char_)
mask_str.reset(new nana::string(str.size(), mask_char_));
mask_str.reset(new std::wstring(str.size(), mask_char_));
bool focused = API::is_focus_ready(window_);
@@ -3322,7 +3324,7 @@ namespace nana{ namespace widgets
points_.offset.y = y;
}
unsigned text_editor::_m_char_by_pixels(const nana::char_t* str, std::size_t len, unsigned * pxbuf, int str_px, int pixels, bool is_rtl)
unsigned text_editor::_m_char_by_pixels(const wchar_t* str, std::size_t len, unsigned * pxbuf, int str_px, int pixels, bool is_rtl)
{
if (graph_.glyph_pixels(str, len, pxbuf))
{
@@ -3361,7 +3363,7 @@ namespace nana{ namespace widgets
return 0;
}
unsigned text_editor::_m_pixels_by_char(const nana::string& lnstr, std::size_t pos) const
unsigned text_editor::_m_pixels_by_char(const std::wstring& lnstr, std::size_t pos) const
{
if (pos > lnstr.size())
return 0;

View File

@@ -25,6 +25,7 @@ namespace nana
{
namespace spinbox
{
class event_agent
: public widgets::skeletons::textbase_event_agent_interface
{
@@ -53,13 +54,13 @@ namespace nana
public:
virtual ~range_interface() = default;
virtual std::wstring value() const = 0;
virtual std::string value() const = 0;
//sets a new value, the diff indicates whether the new value is different from the current value.
//returns true if the new value is acceptable.
virtual bool value(const std::wstring& new_value, bool& diff) = 0;
virtual bool value(const std::string& new_value, bool& diff) = 0;
virtual bool check_value(const std::wstring&) const = 0;
virtual bool check_value(const std::string&) const = 0;
virtual void spin(bool increase) = 0;
};
@@ -72,14 +73,14 @@ namespace nana
: begin_{ vbegin }, last_{ vlast }, step_{ step }, value_{ vbegin }
{}
std::wstring value() const override
std::string value() const override
{
return std::to_wstring(value_);
return std::to_string(value_);
}
bool value(const std::wstring& value_str, bool & diff) override
bool value(const std::string& value_str, bool & diff) override
{
std::wstringstream ss;
std::stringstream ss;
ss << value_str;
T v;
@@ -92,7 +93,7 @@ namespace nana
return true;
}
bool check_value(const std::wstring& str) const override
bool check_value(const std::string& str) const override
{
if (str.empty())
return true;
@@ -157,6 +158,7 @@ namespace nana
{
public:
range_text(std::initializer_list<std::string> & initlist)
: texts_(initlist)
{
for (auto & s : initlist)
{
@@ -165,10 +167,12 @@ namespace nana
}
range_text(std::initializer_list<std::wstring>& initlist)
: texts_(initlist)
{}
{
for (auto & s : initlist)
texts_.emplace_back(to_utf8(s));
}
std::wstring value() const override
std::string value() const override
{
if (texts_.empty())
return{};
@@ -176,7 +180,7 @@ namespace nana
return texts_[pos_];
}
bool value(const std::wstring& value_str, bool & diff) override
bool value(const std::string& value_str, bool & diff) override
{
auto i = std::find(texts_.cbegin(), texts_.cend(), value_str);
if (i != texts_.cend())
@@ -188,7 +192,7 @@ namespace nana
return false;
}
bool check_value(const std::wstring& str) const override
bool check_value(const std::string& str) const override
{
if (str.empty())
return true;
@@ -219,7 +223,7 @@ namespace nana
}
}
private:
std::vector<std::wstring> texts_;
std::vector<std::string> texts_;
std::size_t pos_{0};
};
@@ -262,7 +266,7 @@ namespace nana
else
str.insert(pos, 1, ch);
return range_->check_value(str);
return range_->check_value(to_utf8(str));
});
evt_agent_.reset(new event_agent(static_cast<nana::spinbox&>(wdg)));
@@ -286,12 +290,12 @@ namespace nana
editor_ = nullptr;
}
::nana::string value() const
std::string value() const
{
return range_->value();
}
bool value(const ::nana::string& value_str)
bool value(const ::std::string& value_str)
{
bool diff;
if (!range_->value(value_str, diff))
@@ -309,7 +313,7 @@ namespace nana
reset_text();
}
void modifier(std::wstring&& prefix, std::wstring&& suffix)
void modifier(std::string&& prefix, std::string&& suffix)
{
modifier_.prefix = std::move(prefix);
modifier_.suffix = std::move(suffix);
@@ -417,9 +421,9 @@ namespace nana
return;
if (API::is_focus_ready(editor_->window_handle()))
editor_->text(range_->value());
editor_->text(to_wstring(range_->value()));
else
editor_->text(modifier_.prefix + range_->value() + modifier_.suffix);
editor_->text(to_wstring(modifier_.prefix + range_->value() + modifier_.suffix));
_m_draw_spins(spin_stated_);
}
@@ -483,8 +487,8 @@ namespace nana
struct modifiers
{
std::wstring prefix;
std::wstring suffix;
std::string prefix;
std::string suffix;
}modifier_;
};
@@ -567,7 +571,7 @@ namespace nana
{
if (impl_->editor()->respond_char(arg))
{
if (!impl_->value(impl_->editor()->text()))
if (!impl_->value(to_utf8(impl_->editor()->text())))
impl_->draw_spins();
API::lazy_refresh();
@@ -639,7 +643,7 @@ namespace nana
API::refresh_window(handle());
}
::nana::string spinbox::value() const
::std::string spinbox::value() const
{
internal_scope_guard lock;
if (handle())
@@ -647,7 +651,7 @@ namespace nana
return{};
}
void spinbox::value(const ::nana::string& s)
void spinbox::value(const ::std::string& s)
{
internal_scope_guard lock;
if (handle())
@@ -667,14 +671,14 @@ namespace nana
return std::stod(value());
}
void spinbox::modifier(std::wstring prefix, std::wstring suffix)
void spinbox::modifier(std::string prefix, std::string suffix)
{
get_drawer_trigger().impl()->modifier(std::move(prefix), std::move(suffix));
}
void spinbox::modifier(const std::string & prefix_utf8, const std::string& suffix_utf8)
void spinbox::modifier(const std::wstring & prefix, const std::wstring& suffix)
{
modifier(static_cast<std::wstring>(::nana::charset(prefix_utf8, ::nana::unicode::utf8)), static_cast<std::wstring>(::nana::charset(suffix_utf8, ::nana::unicode::utf8)));
modifier(to_utf8(prefix), to_utf8(suffix));
}
auto spinbox::_m_caption() const throw() -> native_string_type

View File

@@ -228,7 +228,7 @@ namespace drawerbase {
create(wd, r, visible);
}
void textbox::load(nana::string file)
void textbox::load(std::string file)
{
internal_scope_guard lock;
auto editor = get_drawer_trigger().editor();
@@ -236,7 +236,7 @@ namespace drawerbase {
API::update_window(handle());
}
void textbox::store(nana::string file)
void textbox::store(std::string file)
{
internal_scope_guard lock;
auto editor = get_drawer_trigger().editor();
@@ -244,7 +244,7 @@ namespace drawerbase {
editor->textbase().store(std::move(file), false, nana::unicode::utf8); //3rd parameter is just for syntax, it will be ignored
}
void textbox::store(nana::string file, nana::unicode encoding)
void textbox::store(std::string file, nana::unicode encoding)
{
internal_scope_guard lock;
auto editor = get_drawer_trigger().editor();
@@ -254,7 +254,7 @@ namespace drawerbase {
/// Enables/disables the textbox to indent a line. Idents a new line when it is created by pressing enter.
/// @param generator generates text for identing a line. If it is empty, textbox indents the line according to last line.
textbox& textbox::indention(bool enb, std::function<nana::string()> generator)
textbox& textbox::indention(bool enb, std::function<std::string()> generator)
{
internal_scope_guard lock;
auto editor = get_drawer_trigger().editor();
@@ -263,20 +263,20 @@ namespace drawerbase {
return *this;
}
textbox& textbox::reset(nana::string str)
textbox& textbox::reset(const std::string& str)
{
internal_scope_guard lock;
auto editor = get_drawer_trigger().editor();
if (editor)
{
editor->text(std::move(str));
editor->text(to_wstring(str));
editor->textbase().reset();
API::update_window(this->handle());
}
return *this;
}
nana::string textbox::filename() const
std::string textbox::filename() const
{
internal_scope_guard lock;
auto editor = get_drawer_trigger().editor();
@@ -310,11 +310,20 @@ namespace drawerbase {
return (editor ? editor->textbase().saved() : false);
}
bool textbox::getline(std::size_t line_index, nana::string& text) const
bool textbox::getline(std::size_t line_index, std::string& text) const
{
internal_scope_guard lock;
auto editor = get_drawer_trigger().editor();
return (editor ? editor->getline(line_index, text) : false);
if (editor)
{
std::wstring line_text;
if (editor->getline(line_index, line_text))
{
text = utf8_cast(line_text);
return true;
}
}
return false;
}
/// Gets the caret position
@@ -349,7 +358,7 @@ namespace drawerbase {
return *this;
}
textbox& textbox::append(const nana::string& text, bool at_caret)
textbox& textbox::append(const std::string& text, bool at_caret)
{
internal_scope_guard lock;
auto editor = get_drawer_trigger().editor();
@@ -358,7 +367,7 @@ namespace drawerbase {
if(at_caret == false)
editor->move_caret_end();
editor->put(text);
editor->put(to_wstring(text));
API::update_window(this->handle());
}
return *this;
@@ -423,10 +432,9 @@ namespace drawerbase {
textbox& textbox::tip_string(std::string str)
{
throw_not_utf8(str);
internal_scope_guard lock;
auto editor = get_drawer_trigger().editor();
if(editor && editor->tip_string(utf8_cast(str)))
if(editor && editor->tip_string(std::move(str)))
API::refresh_window(handle());
return *this;
}
@@ -559,12 +567,12 @@ namespace drawerbase {
}
}
void textbox::erase_keyword(const nana::string& kw)
void textbox::erase_keyword(const std::string& kw)
{
internal_scope_guard lock;
auto editor = get_drawer_trigger().editor();
if (editor)
editor->erase_keyword(kw);
editor->erase_keyword(to_wstring(kw));
}
std::vector<upoint> textbox::text_position() const