use UTF-8 for string representation
This commit is contained in:
parent
8fc84938bf
commit
c260eebbc3
@ -22,7 +22,7 @@ namespace detail
|
|||||||
Window window;
|
Window window;
|
||||||
int x;
|
int x;
|
||||||
int y;
|
int y;
|
||||||
std::vector<nana::string> * files;
|
std::vector<std::string> * files;
|
||||||
}mouse_drop;
|
}mouse_drop;
|
||||||
}u;
|
}u;
|
||||||
};
|
};
|
||||||
|
@ -70,7 +70,7 @@ namespace detail
|
|||||||
|
|
||||||
struct font_tag
|
struct font_tag
|
||||||
{
|
{
|
||||||
nana::string name;
|
std::string name;
|
||||||
unsigned height;
|
unsigned height;
|
||||||
unsigned weight;
|
unsigned weight;
|
||||||
bool italic;
|
bool italic;
|
||||||
|
@ -131,7 +131,7 @@ namespace nana{ namespace widgets
|
|||||||
struct keywords;
|
struct keywords;
|
||||||
class keyword_parser;
|
class keyword_parser;
|
||||||
public:
|
public:
|
||||||
using char_type = ::nana::char_t;
|
using char_type = wchar_t;
|
||||||
using size_type = textbase<char_type>::size_type;
|
using size_type = textbase<char_type>::size_type;
|
||||||
using string_type = textbase<char_type>::string_type;
|
using string_type = textbase<char_type>::string_type;
|
||||||
|
|
||||||
@ -152,10 +152,10 @@ namespace nana{ namespace widgets
|
|||||||
text_editor(window, graph_reference, const text_editor_scheme*);
|
text_editor(window, graph_reference, const text_editor_scheme*);
|
||||||
~text_editor();
|
~text_editor();
|
||||||
|
|
||||||
void set_highlight(const std::string& name, const ::nana::color&, const ::nana::color&);
|
void set_highlight(const ::std::string& name, const ::nana::color&, const ::nana::color&);
|
||||||
void erase_highlight(const std::string& name);
|
void erase_highlight(const ::std::string& name);
|
||||||
void set_keyword(const ::nana::string& kw, const std::string& name, bool case_sensitive, bool whole_word_matched);
|
void set_keyword(const ::std::wstring& kw, const std::string& name, bool case_sensitive, bool whole_word_matched);
|
||||||
void erase_keyword(const ::nana::string& kw);
|
void erase_keyword(const ::std::wstring& kw);
|
||||||
|
|
||||||
void set_accept(std::function<bool(char_type)>);
|
void set_accept(std::function<bool(char_type)>);
|
||||||
void set_accept(accepts);
|
void set_accept(accepts);
|
||||||
@ -164,7 +164,7 @@ namespace nana{ namespace widgets
|
|||||||
|
|
||||||
void typeface_changed();
|
void typeface_changed();
|
||||||
|
|
||||||
void indent(bool, std::function<nana::string()> generator);
|
void indent(bool, std::function<std::string()> generator);
|
||||||
void set_event(event_interface*);
|
void set_event(event_interface*);
|
||||||
|
|
||||||
/// Determine whether the text_editor is line wrapped.
|
/// Determine whether the text_editor is line wrapped.
|
||||||
@ -174,7 +174,7 @@ namespace nana{ namespace widgets
|
|||||||
|
|
||||||
void border_renderer(std::function<void(graph_reference, const ::nana::color& bgcolor)>);
|
void border_renderer(std::function<void(graph_reference, const ::nana::color& bgcolor)>);
|
||||||
|
|
||||||
bool load(const nana::char_t*);
|
bool load(const char*);
|
||||||
|
|
||||||
/// Sets the text area.
|
/// Sets the text area.
|
||||||
/// @return true if the area is changed with the new value.
|
/// @return true if the area is changed with the new value.
|
||||||
@ -183,7 +183,7 @@ namespace nana{ namespace widgets
|
|||||||
/// Returns the text area
|
/// Returns the text area
|
||||||
rectangle text_area(bool including_scroll) const;
|
rectangle text_area(bool including_scroll) const;
|
||||||
|
|
||||||
bool tip_string(nana::string&&);
|
bool tip_string(::std::string&&);
|
||||||
|
|
||||||
const attributes & attr() const;
|
const attributes & attr() const;
|
||||||
bool multi_lines(bool);
|
bool multi_lines(bool);
|
||||||
@ -201,9 +201,9 @@ namespace nana{ namespace widgets
|
|||||||
unsigned line_height() const;
|
unsigned line_height() const;
|
||||||
unsigned screen_lines() const;
|
unsigned screen_lines() const;
|
||||||
|
|
||||||
bool getline(std::size_t pos, nana::string&) const;
|
bool getline(std::size_t pos, ::std::wstring&) const;
|
||||||
void text(nana::string);
|
void text(std::wstring);
|
||||||
nana::string text() const;
|
std::wstring text() const;
|
||||||
|
|
||||||
/// Sets caret position through text coordinate.
|
/// Sets caret position through text coordinate.
|
||||||
void move_caret(const upoint&);
|
void move_caret(const upoint&);
|
||||||
@ -233,8 +233,8 @@ namespace nana{ namespace widgets
|
|||||||
void draw_corner();
|
void draw_corner();
|
||||||
void render(bool focused);
|
void render(bool focused);
|
||||||
public:
|
public:
|
||||||
void put(nana::string);
|
void put(std::wstring);
|
||||||
void put(nana::char_t);
|
void put(wchar_t);
|
||||||
void copy() const;
|
void copy() const;
|
||||||
void cut();
|
void cut();
|
||||||
void paste();
|
void paste();
|
||||||
@ -264,11 +264,11 @@ namespace nana{ namespace widgets
|
|||||||
::nana::size _m_text_area() const;
|
::nana::size _m_text_area() const;
|
||||||
void _m_get_scrollbar_size();
|
void _m_get_scrollbar_size();
|
||||||
void _m_reset();
|
void _m_reset();
|
||||||
::nana::upoint _m_put(nana::string);
|
::nana::upoint _m_put(::std::wstring);
|
||||||
::nana::upoint _m_erase_select();
|
::nana::upoint _m_erase_select();
|
||||||
|
|
||||||
bool _m_make_select_string(nana::string&) const;
|
bool _m_make_select_string(::std::wstring&) const;
|
||||||
static bool _m_resolve_text(const nana::string&, std::vector<std::pair<std::size_t, std::size_t>> & lines);
|
static bool _m_resolve_text(const ::std::wstring&, std::vector<std::pair<std::size_t, std::size_t>> & lines);
|
||||||
|
|
||||||
bool _m_cancel_select(int align);
|
bool _m_cancel_select(int align);
|
||||||
unsigned _m_tabs_pixels(size_type tabs) const;
|
unsigned _m_tabs_pixels(size_type tabs) const;
|
||||||
@ -283,10 +283,10 @@ namespace nana{ namespace widgets
|
|||||||
/// Returns the right/bottom point of text area.
|
/// Returns the right/bottom point of text area.
|
||||||
int _m_end_pos(bool right) const;
|
int _m_end_pos(bool right) const;
|
||||||
|
|
||||||
void _m_draw_parse_string(const keyword_parser&, bool rtl, ::nana::point pos, const ::nana::color& fgcolor, const ::nana::char_t*, std::size_t len) const;
|
void _m_draw_parse_string(const keyword_parser&, bool rtl, ::nana::point pos, const ::nana::color& fgcolor, const wchar_t*, std::size_t len) const;
|
||||||
//_m_draw_string
|
//_m_draw_string
|
||||||
//@brief: Draw a line of string
|
//@brief: Draw a line of string
|
||||||
void _m_draw_string(int top, const ::nana::color&, const nana::upoint& str_pos, const nana::string&, bool if_mask) const;
|
void _m_draw_string(int top, const ::nana::color&, const nana::upoint& str_pos, const ::std::wstring&, bool if_mask) const;
|
||||||
//_m_update_caret_line
|
//_m_update_caret_line
|
||||||
//@brief: redraw whole line specified by caret pos.
|
//@brief: redraw whole line specified by caret pos.
|
||||||
//@return: true if caret overs the border
|
//@return: true if caret overs the border
|
||||||
@ -295,8 +295,8 @@ namespace nana{ namespace widgets
|
|||||||
|
|
||||||
void _m_offset_y(int y);
|
void _m_offset_y(int y);
|
||||||
|
|
||||||
unsigned _m_char_by_pixels(const nana::char_t*, std::size_t len, unsigned* pxbuf, int str_px, int pixels, bool is_rtl);
|
unsigned _m_char_by_pixels(const wchar_t*, std::size_t len, unsigned* pxbuf, int str_px, int pixels, bool is_rtl);
|
||||||
unsigned _m_pixels_by_char(const nana::string&, std::size_t pos) const;
|
unsigned _m_pixels_by_char(const ::std::wstring&, std::size_t pos) const;
|
||||||
void _handle_move_key(const arg_keyboard& arg);
|
void _handle_move_key(const arg_keyboard& arg);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@ -308,8 +308,8 @@ namespace nana{ namespace widgets
|
|||||||
event_interface * event_handler_{ nullptr };
|
event_interface * event_handler_{ nullptr };
|
||||||
std::unique_ptr<keywords> keywords_;
|
std::unique_ptr<keywords> keywords_;
|
||||||
|
|
||||||
skeletons::textbase<nana::char_t> textbase_;
|
skeletons::textbase<wchar_t> textbase_;
|
||||||
nana::char_t mask_char_{0};
|
wchar_t mask_char_{0};
|
||||||
|
|
||||||
mutable ext_renderer_tag ext_renderer_;
|
mutable ext_renderer_tag ext_renderer_;
|
||||||
|
|
||||||
@ -318,7 +318,7 @@ namespace nana{ namespace widgets
|
|||||||
struct indent_rep
|
struct indent_rep
|
||||||
{
|
{
|
||||||
bool enabled{ false };
|
bool enabled{ false };
|
||||||
std::function<nana::string()> generator;
|
std::function<std::string()> generator;
|
||||||
}indent_;
|
}indent_;
|
||||||
|
|
||||||
struct attributes
|
struct attributes
|
||||||
@ -326,7 +326,7 @@ namespace nana{ namespace widgets
|
|||||||
accepts acceptive{ accepts::no_restrict };
|
accepts acceptive{ accepts::no_restrict };
|
||||||
std::function<bool(char_type)> pred_acceptive;
|
std::function<bool(char_type)> pred_acceptive;
|
||||||
|
|
||||||
nana::string tip_string;
|
::std::string tip_string;
|
||||||
|
|
||||||
bool line_wrapped{false};
|
bool line_wrapped{false};
|
||||||
bool multi_lines{true};
|
bool multi_lines{true};
|
||||||
|
@ -57,13 +57,12 @@ namespace skeletons
|
|||||||
((text_cont_.size() == 1) && (text_cont_[0].empty())));
|
((text_cont_.size() == 1) && (text_cont_[0].empty())));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool load(const nana::char_t* fs)
|
bool load(const char* file_utf8)
|
||||||
{
|
{
|
||||||
if (nullptr == fs)
|
if (!file_utf8)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
std::string fs_mbs = nana::charset(fs);
|
std::ifstream ifs(to_osmbstr(file_utf8));
|
||||||
std::ifstream ifs(fs_mbs.data());
|
|
||||||
if (!ifs)
|
if (!ifs)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@ -81,7 +80,7 @@ namespace skeletons
|
|||||||
if(0xBB == ch && 0xBF == ifs.get())
|
if(0xBB == ch && 0xBF == ifs.get())
|
||||||
{
|
{
|
||||||
ifs.close();
|
ifs.close();
|
||||||
return load(fs, nana::unicode::utf8);
|
return load(file_utf8, nana::unicode::utf8);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(0xFF == ch)
|
else if(0xFF == ch)
|
||||||
@ -94,11 +93,11 @@ namespace skeletons
|
|||||||
if(ifs.get() == 0 && ifs.get() == 0)
|
if(ifs.get() == 0 && ifs.get() == 0)
|
||||||
{
|
{
|
||||||
ifs.close();
|
ifs.close();
|
||||||
return load(fs, nana::unicode::utf32);
|
return load(file_utf8, nana::unicode::utf32);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ifs.close();
|
ifs.close();
|
||||||
return load(fs, nana::unicode::utf16);
|
return load(file_utf8, nana::unicode::utf16);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(0xFE == ch)
|
else if(0xFE == ch)
|
||||||
@ -107,7 +106,7 @@ namespace skeletons
|
|||||||
{
|
{
|
||||||
//UTF16(big-endian)
|
//UTF16(big-endian)
|
||||||
ifs.close();
|
ifs.close();
|
||||||
return load(fs, nana::unicode::utf16);
|
return load(file_utf8, nana::unicode::utf16);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(0 == ch)
|
else if(0 == ch)
|
||||||
@ -119,7 +118,7 @@ namespace skeletons
|
|||||||
{
|
{
|
||||||
//UTF32(big_endian)
|
//UTF32(big_endian)
|
||||||
ifs.close();
|
ifs.close();
|
||||||
return load(fs, nana::unicode::utf32);
|
return load(file_utf8, nana::unicode::utf32);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -143,7 +142,7 @@ namespace skeletons
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_m_saved(fs);
|
_m_saved(file_utf8);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -175,13 +174,12 @@ namespace skeletons
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool load(const nana::char_t * fs, nana::unicode encoding)
|
bool load(const char* file_utf8, nana::unicode encoding)
|
||||||
{
|
{
|
||||||
if (nullptr == fs)
|
if (!file_utf8)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
std::string fs_mbs = nana::charset(fs);
|
std::ifstream ifs(to_osmbstr(file_utf8));
|
||||||
std::ifstream ifs(fs_mbs.data());
|
|
||||||
|
|
||||||
if (!ifs)
|
if (!ifs)
|
||||||
return false;
|
return false;
|
||||||
@ -245,14 +243,13 @@ namespace skeletons
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_m_saved(fs);
|
_m_saved(file_utf8);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void store(nana::string fs, bool is_unicode, ::nana::unicode encoding) const
|
void store(std::string fs, bool is_unicode, ::nana::unicode encoding) const
|
||||||
{
|
{
|
||||||
std::string fs_mbs = nana::charset(fs);
|
std::ofstream ofs(to_osmbstr(fs), std::ios::binary);
|
||||||
std::ofstream ofs(fs_mbs.data(), std::ios::binary);
|
|
||||||
if(ofs && text_cont_.size())
|
if(ofs && text_cont_.size())
|
||||||
{
|
{
|
||||||
std::string last_mbs;
|
std::string last_mbs;
|
||||||
@ -410,7 +407,7 @@ namespace skeletons
|
|||||||
{
|
{
|
||||||
std::deque<string_type>().swap(text_cont_);
|
std::deque<string_type>().swap(text_cont_);
|
||||||
attr_max_.reset();
|
attr_max_.reset();
|
||||||
_m_saved(nana::string());
|
_m_saved(std::string());
|
||||||
}
|
}
|
||||||
|
|
||||||
void merge(size_type pos)
|
void merge(size_type pos)
|
||||||
@ -427,7 +424,7 @@ namespace skeletons
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const nana::string& filename() const
|
const std::string& filename() const
|
||||||
{
|
{
|
||||||
return filename_;
|
return filename_;
|
||||||
}
|
}
|
||||||
@ -489,7 +486,7 @@ namespace skeletons
|
|||||||
evt_agent_->first_change();
|
evt_agent_->first_change();
|
||||||
}
|
}
|
||||||
|
|
||||||
void _m_saved(nana::string && filename) const
|
void _m_saved(std::string && filename) const
|
||||||
{
|
{
|
||||||
if(filename_ != filename)
|
if(filename_ != filename)
|
||||||
{
|
{
|
||||||
@ -518,7 +515,7 @@ namespace skeletons
|
|||||||
textbase_event_agent_interface* evt_agent_{ nullptr };
|
textbase_event_agent_interface* evt_agent_{ nullptr };
|
||||||
|
|
||||||
mutable bool changed_{ false };
|
mutable bool changed_{ false };
|
||||||
mutable nana::string filename_; //A string for the saved filename.
|
mutable std::string filename_; //A string for the saved filename.
|
||||||
const string_type nullstr_;
|
const string_type nullstr_;
|
||||||
|
|
||||||
struct attr_max
|
struct attr_max
|
||||||
|
@ -97,14 +97,14 @@ namespace nana
|
|||||||
void range(std::initializer_list<std::wstring> values);
|
void range(std::initializer_list<std::wstring> values);
|
||||||
|
|
||||||
/// Gets the spined value
|
/// Gets the spined value
|
||||||
::nana::string value() const;
|
::std::string value() const;
|
||||||
void value(const ::nana::string&);
|
void value(const ::std::string&);
|
||||||
int to_int() const;
|
int to_int() const;
|
||||||
double to_double() const;
|
double to_double() const;
|
||||||
|
|
||||||
/// Sets the modifiers
|
/// Sets the modifiers
|
||||||
void modifier(std::wstring prefix, std::wstring suffix);
|
void modifier(std::string prefix_utf8, std::string suffix_utf8);
|
||||||
void modifier(const std::string & prefix_utf8, const std::string& suffix_utf8);
|
void modifier(const std::wstring & prefix, const std::wstring& suffix);
|
||||||
private:
|
private:
|
||||||
native_string_type _m_caption() const throw();
|
native_string_type _m_caption() const throw();
|
||||||
void _m_caption(native_string_type&&);
|
void _m_caption(native_string_type&&);
|
||||||
|
@ -126,19 +126,19 @@ namespace nana
|
|||||||
textbox(window, const rectangle& = rectangle(), bool visible = true);
|
textbox(window, const rectangle& = rectangle(), bool visible = true);
|
||||||
|
|
||||||
/// \brief Loads a text file. When attempt to load a unicode encoded text file, be sure the file have a BOM header.
|
/// \brief Loads a text file. When attempt to load a unicode encoded text file, be sure the file have a BOM header.
|
||||||
void load(nana::string file);
|
void load(std::string file);
|
||||||
void store(nana::string file);
|
void store(std::string file);
|
||||||
void store(nana::string file, nana::unicode encoding);
|
void store(std::string file, nana::unicode encoding);
|
||||||
|
|
||||||
/// Enables/disables the textbox to indent a line. Idents a new line when it is created by pressing enter.
|
/// 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.
|
/// @param generator generates text for identing a line. If it is empty, textbox indents the line according to last line.
|
||||||
textbox& indention(bool, std::function<nana::string()> generator = {});
|
textbox& indention(bool, std::function<std::string()> generator = {});
|
||||||
|
|
||||||
//A workaround for reset, explicit default constructor syntax, because VC2013 incorrectly treats {} as {0}.
|
//A workaround for reset, explicit default constructor syntax, because VC2013 incorrectly treats {} as {0}.
|
||||||
textbox& reset(nana::string = nana::string()); ///< discard the old text and set a new text
|
textbox& reset(const std::string& = std::string()); ///< discard the old text and set a new text
|
||||||
|
|
||||||
/// The file of last store operation.
|
/// The file of last store operation.
|
||||||
nana::string filename() const;
|
std::string filename() const;
|
||||||
|
|
||||||
/// Determine whether the text was edited.
|
/// Determine whether the text was edited.
|
||||||
bool edited() const;
|
bool edited() const;
|
||||||
@ -150,7 +150,7 @@ namespace nana
|
|||||||
bool saved() const;
|
bool saved() const;
|
||||||
|
|
||||||
/// Read the text from a specified line. It returns true for success.
|
/// Read the text from a specified line. It returns true for success.
|
||||||
bool getline(std::size_t pos, nana::string&) const;
|
bool getline(std::size_t pos, std::string&) const;
|
||||||
|
|
||||||
/// Gets the caret position
|
/// Gets the caret position
|
||||||
/// Returns true if the caret is in the area of display, false otherwise.
|
/// Returns true if the caret is in the area of display, false otherwise.
|
||||||
@ -160,7 +160,7 @@ namespace nana
|
|||||||
textbox& caret_pos(const upoint&);
|
textbox& caret_pos(const upoint&);
|
||||||
|
|
||||||
/// Appends an string. If `at_caret` is `true`, the string is inserted at the position of caret, otherwise, it is appended at end of the textbox.
|
/// Appends an string. If `at_caret` is `true`, the string is inserted at the position of caret, otherwise, it is appended at end of the textbox.
|
||||||
textbox& append(const nana::string& text, bool at_caret);
|
textbox& append(const std::string& text, bool at_caret);
|
||||||
|
|
||||||
/// Determine wheter the text is line wrapped.
|
/// Determine wheter the text is line wrapped.
|
||||||
bool line_wrapped() const;
|
bool line_wrapped() const;
|
||||||
@ -197,7 +197,7 @@ namespace nana
|
|||||||
void erase_highlight(const std::string& name);
|
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);
|
void set_keywords(const std::string& name, bool case_sensitive, bool whole_word_match, std::initializer_list<std::wstring> kw_list);
|
||||||
void set_keywords(const std::string& name, bool case_sensitive, bool whole_word_match, std::initializer_list<std::string> kw_list_utf8);
|
void set_keywords(const std::string& name, bool case_sensitive, bool whole_word_match, std::initializer_list<std::string> kw_list_utf8);
|
||||||
void erase_keyword(const nana::string& kw);
|
void erase_keyword(const std::string& kw);
|
||||||
|
|
||||||
/// Returns the text position of each line that currently displays on screen.
|
/// Returns the text position of each line that currently displays on screen.
|
||||||
text_positions text_position() const;
|
text_positions text_position() const;
|
||||||
|
@ -50,6 +50,7 @@ namespace filesystem
|
|||||||
typedef nana::string string_t;
|
typedef nana::string string_t;
|
||||||
const nana::char_t* splstr = L"/\\";
|
const nana::char_t* splstr = L"/\\";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
//class path
|
//class path
|
||||||
path::path(){}
|
path::path(){}
|
||||||
|
|
||||||
@ -122,6 +123,7 @@ namespace filesystem
|
|||||||
}
|
}
|
||||||
//end class path
|
//end class path
|
||||||
|
|
||||||
|
|
||||||
namespace detail
|
namespace detail
|
||||||
{
|
{
|
||||||
//rm_dir_recursive
|
//rm_dir_recursive
|
||||||
|
@ -708,7 +708,7 @@ namespace nana
|
|||||||
impl->spinbox.create(impl->dock, rectangle{ static_cast<int>(label_px + 10), 0, value_px, 0 });
|
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.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)
|
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.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.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)
|
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_month.option(today.month - 1);
|
||||||
|
|
||||||
impl->wdg_day.value(std::to_wstring(today.day));
|
impl->wdg_day.value(std::to_string(today.day));
|
||||||
impl->wdg_year.value(std::to_wstring(today.year));
|
impl->wdg_year.value(std::to_string(today.year));
|
||||||
|
|
||||||
impl->dock.events().resized.connect_unignorable([impl, label_px](const ::nana::arg_resized& arg)
|
impl->dock.events().resized.connect_unignorable([impl, label_px](const ::nana::arg_resized& arg)
|
||||||
{
|
{
|
||||||
@ -1059,7 +1059,7 @@ namespace nana
|
|||||||
if (day > days)
|
if (day > days)
|
||||||
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);
|
impl->wdg_year.events().text_changed.connect_unignorable(make_days);
|
||||||
|
@ -61,7 +61,7 @@ namespace nana{ namespace widgets
|
|||||||
text_editor & editor_;
|
text_editor & editor_;
|
||||||
upoint pos_;
|
upoint pos_;
|
||||||
upoint sel_a_, sel_b_;
|
upoint sel_a_, sel_b_;
|
||||||
nana::string selected_text_;
|
std::wstring selected_text_;
|
||||||
private:
|
private:
|
||||||
const EnumCommand cmd_;
|
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
|
//use selected_text_ as removed text
|
||||||
selected_text_ = str;
|
selected_text_ = str;
|
||||||
@ -136,7 +136,7 @@ namespace nana{ namespace widgets
|
|||||||
: public basic_undoable <command>
|
: public basic_undoable <command>
|
||||||
{
|
{
|
||||||
public:
|
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),
|
: basic_undoable<command>(editor, command::input_text),
|
||||||
text_(text)
|
text_(text)
|
||||||
{
|
{
|
||||||
@ -199,7 +199,7 @@ namespace nana{ namespace widgets
|
|||||||
editor_.move_caret(editor_.points_.caret);
|
editor_.move_caret(editor_.points_.caret);
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
nana::string text_;
|
std::wstring text_;
|
||||||
};
|
};
|
||||||
|
|
||||||
class text_editor::undo_move_text
|
class text_editor::undo_move_text
|
||||||
@ -325,9 +325,9 @@ namespace nana{ namespace widgets
|
|||||||
if (pos.y > static_cast<unsigned>(textbase.lines()))
|
if (pos.y > static_cast<unsigned>(textbase.lines()))
|
||||||
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_)
|
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);
|
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
|
//Convert the screen point to text caret point
|
||||||
const string_type& real_str = editor_.textbase_.getline(res.y);
|
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_)
|
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);
|
auto & lnstr = (editor_.mask_char_ ? *mask_str : real_str);
|
||||||
if (lnstr.size() > 0)
|
if (lnstr.size() > 0)
|
||||||
@ -539,8 +539,8 @@ namespace nana{ namespace widgets
|
|||||||
std::size_t line = 0;
|
std::size_t line = 0;
|
||||||
for (auto & mtr: linemtr_)
|
for (auto & mtr: linemtr_)
|
||||||
{
|
{
|
||||||
const nana::string& linestr = editor_.textbase_.getline(line);
|
auto& linestr = editor_.textbase_.getline(line);
|
||||||
const nana::char_t * p = mtr.line_sections.front().begin;
|
auto p = mtr.line_sections.front().begin;
|
||||||
if (p < linestr.data() || (linestr.data() + linestr.size() < p))
|
if (p < linestr.data() || (linestr.data() + linestr.size() < p))
|
||||||
pre_calc_line(line, editor_.width_pixels());
|
pre_calc_line(line, editor_.width_pixels());
|
||||||
|
|
||||||
@ -562,8 +562,8 @@ namespace nana{ namespace widgets
|
|||||||
{
|
{
|
||||||
if (line < pos || (pos + lines) <= line)
|
if (line < pos || (pos + lines) <= line)
|
||||||
{
|
{
|
||||||
const nana::string& linestr = editor_.textbase_.getline(line);
|
auto & linestr = editor_.textbase_.getline(line);
|
||||||
const nana::char_t * p = mtr.line_sections.front().begin;
|
auto p = mtr.line_sections.front().begin;
|
||||||
if (p < linestr.data() || (linestr.data() + linestr.size() < p))
|
if (p < linestr.data() || (linestr.data() + linestr.size() < p))
|
||||||
pre_calc_line(line, editor_.width_pixels());
|
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)
|
for (std::size_t pos = 0; pos < secondary_before; ++pos, top+=pixels)
|
||||||
{
|
{
|
||||||
auto & sct = linemtr_[textline].line_sections[pos];
|
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
|
else
|
||||||
@ -727,7 +727,7 @@ namespace nana{ namespace widgets
|
|||||||
auto & mtr = linemtr_[primary];
|
auto & mtr = linemtr_[primary];
|
||||||
auto & section = mtr.line_sections[secondary];
|
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);
|
editor_._m_draw_string(top, fgcolor, str_pos, text, true);
|
||||||
line_index.push_back(str_pos);
|
line_index.push_back(str_pos);
|
||||||
++secondary;
|
++secondary;
|
||||||
@ -767,7 +767,7 @@ namespace nana{ namespace widgets
|
|||||||
nana::point scrpos;
|
nana::point scrpos;
|
||||||
if (0 != pos.x)
|
if (0 != pos.x)
|
||||||
{
|
{
|
||||||
nana::string str;
|
std::wstring str;
|
||||||
for (auto & sec : mtr.line_sections)
|
for (auto & sec : mtr.line_sections)
|
||||||
{
|
{
|
||||||
std::size_t chsize = sec.end - sec.begin;
|
std::size_t chsize = sec.end - sec.begin;
|
||||||
@ -812,9 +812,9 @@ namespace nana{ namespace widgets
|
|||||||
//First of all, find the text of secondary.
|
//First of all, find the text of secondary.
|
||||||
auto real_str = mtr.line_sections[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_)
|
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);
|
const ::nana::char_t * str = (editor_.mask_char_ ? mask_str->data() : real_str.begin);
|
||||||
|
|
||||||
@ -925,7 +925,7 @@ namespace nana{ namespace widgets
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
private:
|
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())
|
if (str.empty())
|
||||||
{
|
{
|
||||||
@ -1148,12 +1148,12 @@ namespace nana{ namespace widgets
|
|||||||
|
|
||||||
struct keyword_desc
|
struct keyword_desc
|
||||||
{
|
{
|
||||||
::nana::string text;
|
std::wstring text;
|
||||||
std::string scheme;
|
std::string scheme;
|
||||||
bool case_sensitive;
|
bool case_sensitive;
|
||||||
bool whole_word_matched;
|
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)
|
: text(txt), scheme(schm), case_sensitive(cs), whole_word_matched(wwm)
|
||||||
{}
|
{}
|
||||||
};
|
};
|
||||||
@ -1174,12 +1174,12 @@ namespace nana{ namespace widgets
|
|||||||
class text_editor::keyword_parser
|
class text_editor::keyword_parser
|
||||||
{
|
{
|
||||||
public:
|
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() )
|
if ( kwptr->kwbase.empty() || text.empty() )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
using index = ::nana::string::size_type;
|
using index = std::wstring::size_type;
|
||||||
|
|
||||||
std::vector<entity> entities;
|
std::vector<entity> entities;
|
||||||
|
|
||||||
@ -1329,7 +1329,7 @@ namespace nana{ namespace widgets
|
|||||||
keywords_->schemes.erase(name);
|
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)
|
for (auto & ds : keywords_->kwbase)
|
||||||
{
|
{
|
||||||
@ -1344,7 +1344,7 @@ namespace nana{ namespace widgets
|
|||||||
keywords_->kwbase.emplace_back(kw, name, case_sensitive, whole_word_matched);
|
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)
|
for (auto i = keywords_->kwbase.begin(); i != keywords_->kwbase.end(); ++i)
|
||||||
if (i->text == kw)
|
if (i->text == kw)
|
||||||
@ -1446,7 +1446,7 @@ namespace nana{ namespace widgets
|
|||||||
behavior_->pre_calc_lines(width_pixels());
|
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_.enabled = enb;
|
||||||
indent_.generator.swap(generator);
|
indent_.generator.swap(generator);
|
||||||
@ -1493,7 +1493,7 @@ namespace nana{ namespace widgets
|
|||||||
text_area_.border_renderer = f;
|
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))
|
if (!textbase_.load(fs))
|
||||||
return false;
|
return false;
|
||||||
@ -1533,7 +1533,7 @@ namespace nana{ namespace widgets
|
|||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool text_editor::tip_string(nana::string&& str)
|
bool text_editor::tip_string(::std::string&& str)
|
||||||
{
|
{
|
||||||
if(attributes_.tip_string == str)
|
if(attributes_.tip_string == str)
|
||||||
return false;
|
return false;
|
||||||
@ -1739,7 +1739,7 @@ namespace nana{ namespace widgets
|
|||||||
return textbase_;
|
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)
|
if (textbase_.lines() <= pos)
|
||||||
return false;
|
return false;
|
||||||
@ -1748,16 +1748,16 @@ namespace nana{ namespace widgets
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void text_editor::text(nana::string str)
|
void text_editor::text(std::wstring str)
|
||||||
{
|
{
|
||||||
textbase_.erase_all();
|
textbase_.erase_all();
|
||||||
_m_reset();
|
_m_reset();
|
||||||
put(std::move(str));
|
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();
|
std::size_t lines = textbase_.lines();
|
||||||
if(lines > 0)
|
if(lines > 0)
|
||||||
{
|
{
|
||||||
@ -1984,7 +1984,7 @@ namespace nana{ namespace widgets
|
|||||||
text_area_.border_renderer(graph_, bgcolor);
|
text_area_.border_renderer(graph_, bgcolor);
|
||||||
}
|
}
|
||||||
//public:
|
//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) };
|
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);
|
bool refresh = (select_.a != select_.b);
|
||||||
|
|
||||||
undo_ptr->set_selected_text();
|
undo_ptr->set_selected_text();
|
||||||
@ -2023,7 +2025,7 @@ namespace nana{ namespace widgets
|
|||||||
undo_.push(std::move(undo_ptr));
|
undo_.push(std::move(undo_ptr));
|
||||||
|
|
||||||
auto secondary_before = behavior_->take_lines(points_.caret.y);
|
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());
|
behavior_->pre_calc_line(points_.caret.y, width_pixels());
|
||||||
points_.caret.x ++;
|
points_.caret.x ++;
|
||||||
|
|
||||||
@ -2039,7 +2041,7 @@ namespace nana{ namespace widgets
|
|||||||
|
|
||||||
void text_editor::copy() const
|
void text_editor::copy() const
|
||||||
{
|
{
|
||||||
nana::string str;
|
std::wstring str;
|
||||||
if(_m_make_select_string(str))
|
if(_m_make_select_string(str))
|
||||||
nana::system::dataexch().set(str);
|
nana::system::dataexch().set(str);
|
||||||
}
|
}
|
||||||
@ -2052,7 +2054,7 @@ namespace nana{ namespace widgets
|
|||||||
|
|
||||||
void text_editor::paste()
|
void text_editor::paste()
|
||||||
{
|
{
|
||||||
nana::string text;
|
std::wstring text;
|
||||||
nana::system::dataexch().get(text);
|
nana::system::dataexch().get(text);
|
||||||
|
|
||||||
//If it is required check the acceptable
|
//If it is required check the acceptable
|
||||||
@ -2077,7 +2079,7 @@ namespace nana{ namespace widgets
|
|||||||
if(false == attributes_.multi_lines)
|
if(false == attributes_.multi_lines)
|
||||||
return;
|
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);
|
bool need_refresh = (select_.a != select_.b);
|
||||||
|
|
||||||
undo_ptr->set_selected_text();
|
undo_ptr->set_selected_text();
|
||||||
@ -2098,8 +2100,8 @@ namespace nana{ namespace widgets
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (textbase_.lines() == 0)
|
if (textbase_.lines() == 0)
|
||||||
textbase_.insertln(0, nana::string{});
|
textbase_.insertln(0, std::wstring{});
|
||||||
textbase_.insertln(points_.caret.y, nana::string{});
|
textbase_.insertln(points_.caret.y, std::wstring{});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (record_undo)
|
if (record_undo)
|
||||||
@ -2120,10 +2122,10 @@ namespace nana{ namespace widgets
|
|||||||
|
|
||||||
if (indent_.enabled)
|
if (indent_.enabled)
|
||||||
{
|
{
|
||||||
nana::string indent_text;
|
std::wstring indent_text;
|
||||||
if (indent_.generator)
|
if (indent_.generator)
|
||||||
{
|
{
|
||||||
indent_text = indent_.generator();
|
indent_text = to_wstring(indent_.generator());
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -2203,7 +2205,7 @@ namespace nana{ namespace widgets
|
|||||||
textbase_.merge(points_.caret.y);
|
textbase_.merge(points_.caret.y);
|
||||||
behavior_->merge_lines(points_.caret.y, points_.caret.y + 1);
|
behavior_->merge_lines(points_.caret.y, points_.caret.y + 1);
|
||||||
undo_ptr->set_caret_pos();
|
undo_ptr->set_caret_pos();
|
||||||
undo_ptr->set_removed(nana::string(1, '\n'));
|
undo_ptr->set_removed(std::wstring(1, '\n'));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
undo_ptr.reset();
|
undo_ptr.reset();
|
||||||
@ -2658,13 +2660,13 @@ namespace nana{ namespace widgets
|
|||||||
select_.a = select_.b;
|
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;
|
auto crtpos = points_.caret;
|
||||||
std::vector<std::pair<std::size_t, std::size_t>> lines;
|
std::vector<std::pair<std::size_t, std::size_t>> lines;
|
||||||
if (_m_resolve_text(text, lines) && attributes_.multi_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 x_orig = crtpos.x;
|
||||||
|
|
||||||
auto subpos = lines.front();
|
auto subpos = lines.front();
|
||||||
@ -2713,7 +2715,7 @@ namespace nana{ namespace widgets
|
|||||||
{
|
{
|
||||||
if(a.y != b.y)
|
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, b.y - a.y - 1);
|
||||||
|
|
||||||
textbase_.erase(a.y + 1, 0, b.x);
|
textbase_.erase(a.y + 1, 0, b.x);
|
||||||
@ -2734,7 +2736,7 @@ namespace nana{ namespace widgets
|
|||||||
return points_.caret;
|
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;
|
nana::upoint a, b;
|
||||||
if (!_m_get_sort_select_points(a, b))
|
if (!_m_get_sort_select_points(a, b))
|
||||||
@ -2782,7 +2784,7 @@ namespace nana{ namespace widgets
|
|||||||
return pos + 1;
|
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();
|
auto const text_str = text.data();
|
||||||
std::size_t begin = 0;
|
std::size_t begin = 0;
|
||||||
@ -2863,7 +2865,7 @@ namespace nana{ namespace widgets
|
|||||||
|
|
||||||
if(mask_char_)
|
if(mask_char_)
|
||||||
{
|
{
|
||||||
nana::string maskstr;
|
std::wstring maskstr;
|
||||||
maskstr.append(n, mask_char_);
|
maskstr.append(n, mask_char_);
|
||||||
return graph_.text_extent_size(maskstr);
|
return graph_.text_extent_size(maskstr);
|
||||||
}
|
}
|
||||||
@ -2910,7 +2912,7 @@ namespace nana{ namespace widgets
|
|||||||
bool text_editor::_m_move_select(bool record_undo)
|
bool text_editor::_m_move_select(bool record_undo)
|
||||||
{
|
{
|
||||||
nana::upoint caret = points_.caret;
|
nana::upoint caret = points_.caret;
|
||||||
nana::string text;
|
std::wstring text;
|
||||||
if (_m_make_select_string(text))
|
if (_m_make_select_string(text))
|
||||||
{
|
{
|
||||||
auto undo_ptr = std::unique_ptr<undo_move_text>(new undo_move_text(*this));
|
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);
|
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_.set_text_color(fgcolor);
|
||||||
graph_.string(pos, str, len);
|
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 };
|
::nana::point text_pos{ text_area_.area.x - points_.offset.x, top };
|
||||||
const int text_right = text_area_.area.right();
|
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_)
|
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_);
|
bool focused = API::is_focus_ready(window_);
|
||||||
|
|
||||||
@ -3322,7 +3324,7 @@ namespace nana{ namespace widgets
|
|||||||
points_.offset.y = y;
|
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))
|
if (graph_.glyph_pixels(str, len, pxbuf))
|
||||||
{
|
{
|
||||||
@ -3361,7 +3363,7 @@ namespace nana{ namespace widgets
|
|||||||
return 0;
|
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())
|
if (pos > lnstr.size())
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -25,6 +25,7 @@ namespace nana
|
|||||||
{
|
{
|
||||||
namespace spinbox
|
namespace spinbox
|
||||||
{
|
{
|
||||||
|
|
||||||
class event_agent
|
class event_agent
|
||||||
: public widgets::skeletons::textbase_event_agent_interface
|
: public widgets::skeletons::textbase_event_agent_interface
|
||||||
{
|
{
|
||||||
@ -53,13 +54,13 @@ namespace nana
|
|||||||
public:
|
public:
|
||||||
virtual ~range_interface() = default;
|
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.
|
//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.
|
//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;
|
virtual void spin(bool increase) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -72,14 +73,14 @@ namespace nana
|
|||||||
: begin_{ vbegin }, last_{ vlast }, step_{ step }, value_{ vbegin }
|
: 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;
|
ss << value_str;
|
||||||
|
|
||||||
T v;
|
T v;
|
||||||
@ -92,7 +93,7 @@ namespace nana
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool check_value(const std::wstring& str) const override
|
bool check_value(const std::string& str) const override
|
||||||
{
|
{
|
||||||
if (str.empty())
|
if (str.empty())
|
||||||
return true;
|
return true;
|
||||||
@ -157,6 +158,7 @@ namespace nana
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
range_text(std::initializer_list<std::string> & initlist)
|
range_text(std::initializer_list<std::string> & initlist)
|
||||||
|
: texts_(initlist)
|
||||||
{
|
{
|
||||||
for (auto & s : initlist)
|
for (auto & s : initlist)
|
||||||
{
|
{
|
||||||
@ -165,10 +167,12 @@ namespace nana
|
|||||||
}
|
}
|
||||||
|
|
||||||
range_text(std::initializer_list<std::wstring>& initlist)
|
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())
|
if (texts_.empty())
|
||||||
return{};
|
return{};
|
||||||
@ -176,7 +180,7 @@ namespace nana
|
|||||||
return texts_[pos_];
|
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);
|
auto i = std::find(texts_.cbegin(), texts_.cend(), value_str);
|
||||||
if (i != texts_.cend())
|
if (i != texts_.cend())
|
||||||
@ -188,7 +192,7 @@ namespace nana
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool check_value(const std::wstring& str) const override
|
bool check_value(const std::string& str) const override
|
||||||
{
|
{
|
||||||
if (str.empty())
|
if (str.empty())
|
||||||
return true;
|
return true;
|
||||||
@ -219,7 +223,7 @@ namespace nana
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
std::vector<std::wstring> texts_;
|
std::vector<std::string> texts_;
|
||||||
std::size_t pos_{0};
|
std::size_t pos_{0};
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -262,7 +266,7 @@ namespace nana
|
|||||||
else
|
else
|
||||||
str.insert(pos, 1, ch);
|
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)));
|
evt_agent_.reset(new event_agent(static_cast<nana::spinbox&>(wdg)));
|
||||||
@ -286,12 +290,12 @@ namespace nana
|
|||||||
editor_ = nullptr;
|
editor_ = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
::nana::string value() const
|
std::string value() const
|
||||||
{
|
{
|
||||||
return range_->value();
|
return range_->value();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool value(const ::nana::string& value_str)
|
bool value(const ::std::string& value_str)
|
||||||
{
|
{
|
||||||
bool diff;
|
bool diff;
|
||||||
if (!range_->value(value_str, diff))
|
if (!range_->value(value_str, diff))
|
||||||
@ -309,7 +313,7 @@ namespace nana
|
|||||||
reset_text();
|
reset_text();
|
||||||
}
|
}
|
||||||
|
|
||||||
void modifier(std::wstring&& prefix, std::wstring&& suffix)
|
void modifier(std::string&& prefix, std::string&& suffix)
|
||||||
{
|
{
|
||||||
modifier_.prefix = std::move(prefix);
|
modifier_.prefix = std::move(prefix);
|
||||||
modifier_.suffix = std::move(suffix);
|
modifier_.suffix = std::move(suffix);
|
||||||
@ -417,9 +421,9 @@ namespace nana
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
if (API::is_focus_ready(editor_->window_handle()))
|
if (API::is_focus_ready(editor_->window_handle()))
|
||||||
editor_->text(range_->value());
|
editor_->text(to_wstring(range_->value()));
|
||||||
else
|
else
|
||||||
editor_->text(modifier_.prefix + range_->value() + modifier_.suffix);
|
editor_->text(to_wstring(modifier_.prefix + range_->value() + modifier_.suffix));
|
||||||
|
|
||||||
_m_draw_spins(spin_stated_);
|
_m_draw_spins(spin_stated_);
|
||||||
}
|
}
|
||||||
@ -483,8 +487,8 @@ namespace nana
|
|||||||
|
|
||||||
struct modifiers
|
struct modifiers
|
||||||
{
|
{
|
||||||
std::wstring prefix;
|
std::string prefix;
|
||||||
std::wstring suffix;
|
std::string suffix;
|
||||||
}modifier_;
|
}modifier_;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -567,7 +571,7 @@ namespace nana
|
|||||||
{
|
{
|
||||||
if (impl_->editor()->respond_char(arg))
|
if (impl_->editor()->respond_char(arg))
|
||||||
{
|
{
|
||||||
if (!impl_->value(impl_->editor()->text()))
|
if (!impl_->value(to_utf8(impl_->editor()->text())))
|
||||||
impl_->draw_spins();
|
impl_->draw_spins();
|
||||||
|
|
||||||
API::lazy_refresh();
|
API::lazy_refresh();
|
||||||
@ -639,7 +643,7 @@ namespace nana
|
|||||||
API::refresh_window(handle());
|
API::refresh_window(handle());
|
||||||
}
|
}
|
||||||
|
|
||||||
::nana::string spinbox::value() const
|
::std::string spinbox::value() const
|
||||||
{
|
{
|
||||||
internal_scope_guard lock;
|
internal_scope_guard lock;
|
||||||
if (handle())
|
if (handle())
|
||||||
@ -647,7 +651,7 @@ namespace nana
|
|||||||
return{};
|
return{};
|
||||||
}
|
}
|
||||||
|
|
||||||
void spinbox::value(const ::nana::string& s)
|
void spinbox::value(const ::std::string& s)
|
||||||
{
|
{
|
||||||
internal_scope_guard lock;
|
internal_scope_guard lock;
|
||||||
if (handle())
|
if (handle())
|
||||||
@ -667,14 +671,14 @@ namespace nana
|
|||||||
return std::stod(value());
|
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));
|
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
|
auto spinbox::_m_caption() const throw() -> native_string_type
|
||||||
|
@ -228,7 +228,7 @@ namespace drawerbase {
|
|||||||
create(wd, r, visible);
|
create(wd, r, visible);
|
||||||
}
|
}
|
||||||
|
|
||||||
void textbox::load(nana::string file)
|
void textbox::load(std::string file)
|
||||||
{
|
{
|
||||||
internal_scope_guard lock;
|
internal_scope_guard lock;
|
||||||
auto editor = get_drawer_trigger().editor();
|
auto editor = get_drawer_trigger().editor();
|
||||||
@ -236,7 +236,7 @@ namespace drawerbase {
|
|||||||
API::update_window(handle());
|
API::update_window(handle());
|
||||||
}
|
}
|
||||||
|
|
||||||
void textbox::store(nana::string file)
|
void textbox::store(std::string file)
|
||||||
{
|
{
|
||||||
internal_scope_guard lock;
|
internal_scope_guard lock;
|
||||||
auto editor = get_drawer_trigger().editor();
|
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
|
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;
|
internal_scope_guard lock;
|
||||||
auto editor = get_drawer_trigger().editor();
|
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.
|
/// 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.
|
/// @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;
|
internal_scope_guard lock;
|
||||||
auto editor = get_drawer_trigger().editor();
|
auto editor = get_drawer_trigger().editor();
|
||||||
@ -263,20 +263,20 @@ namespace drawerbase {
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
textbox& textbox::reset(nana::string str)
|
textbox& textbox::reset(const std::string& str)
|
||||||
{
|
{
|
||||||
internal_scope_guard lock;
|
internal_scope_guard lock;
|
||||||
auto editor = get_drawer_trigger().editor();
|
auto editor = get_drawer_trigger().editor();
|
||||||
if (editor)
|
if (editor)
|
||||||
{
|
{
|
||||||
editor->text(std::move(str));
|
editor->text(to_wstring(str));
|
||||||
editor->textbase().reset();
|
editor->textbase().reset();
|
||||||
API::update_window(this->handle());
|
API::update_window(this->handle());
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
nana::string textbox::filename() const
|
std::string textbox::filename() const
|
||||||
{
|
{
|
||||||
internal_scope_guard lock;
|
internal_scope_guard lock;
|
||||||
auto editor = get_drawer_trigger().editor();
|
auto editor = get_drawer_trigger().editor();
|
||||||
@ -310,11 +310,20 @@ namespace drawerbase {
|
|||||||
return (editor ? editor->textbase().saved() : false);
|
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;
|
internal_scope_guard lock;
|
||||||
auto editor = get_drawer_trigger().editor();
|
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
|
/// Gets the caret position
|
||||||
@ -349,7 +358,7 @@ namespace drawerbase {
|
|||||||
return *this;
|
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;
|
internal_scope_guard lock;
|
||||||
auto editor = get_drawer_trigger().editor();
|
auto editor = get_drawer_trigger().editor();
|
||||||
@ -358,7 +367,7 @@ namespace drawerbase {
|
|||||||
if(at_caret == false)
|
if(at_caret == false)
|
||||||
editor->move_caret_end();
|
editor->move_caret_end();
|
||||||
|
|
||||||
editor->put(text);
|
editor->put(to_wstring(text));
|
||||||
API::update_window(this->handle());
|
API::update_window(this->handle());
|
||||||
}
|
}
|
||||||
return *this;
|
return *this;
|
||||||
@ -423,10 +432,9 @@ namespace drawerbase {
|
|||||||
|
|
||||||
textbox& textbox::tip_string(std::string str)
|
textbox& textbox::tip_string(std::string str)
|
||||||
{
|
{
|
||||||
throw_not_utf8(str);
|
|
||||||
internal_scope_guard lock;
|
internal_scope_guard lock;
|
||||||
auto editor = get_drawer_trigger().editor();
|
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());
|
API::refresh_window(handle());
|
||||||
return *this;
|
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;
|
internal_scope_guard lock;
|
||||||
auto editor = get_drawer_trigger().editor();
|
auto editor = get_drawer_trigger().editor();
|
||||||
if (editor)
|
if (editor)
|
||||||
editor->erase_keyword(kw);
|
editor->erase_keyword(to_wstring(kw));
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<upoint> textbox::text_position() const
|
std::vector<upoint> textbox::text_position() const
|
||||||
|
Loading…
x
Reference in New Issue
Block a user