From 3b8e1137450670cbd692f722d637eb96b5e32710 Mon Sep 17 00:00:00 2001 From: Jinhao Date: Thu, 26 Nov 2015 00:53:50 +0800 Subject: [PATCH 01/25] add utf8 check function --- include/nana/charset.hpp | 3 +++ source/charset.cpp | 30 ++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/include/nana/charset.hpp b/include/nana/charset.hpp index 9e109b65..f45a6054 100644 --- a/include/nana/charset.hpp +++ b/include/nana/charset.hpp @@ -9,6 +9,9 @@ namespace nana utf8, utf16, utf32 }; + /// Checks whether a specified text is utf8 encoding + bool is_utf8(const char* str, unsigned len); + namespace detail { class charset_encoding_interface; diff --git a/source/charset.cpp b/source/charset.cpp index 1b57ad29..ed0b9213 100644 --- a/source/charset.cpp +++ b/source/charset.cpp @@ -30,6 +30,36 @@ namespace nana { + bool is_utf8(const char* str, unsigned len) + { + auto ustr = reinterpret_cast(str); + auto end = ustr + len; + + while (ustr < end) + { + const auto uv = *ustr; + if (uv < 0x80) + { + ++ustr; + continue; + } + + if (uv < 0xC0) + return false; + + if ((uv < 0xE0) && (ustr + 1 < end)) + ustr += 2; + else if (uv < 0xF0 && (ustr + 2 <= end)) + ustr += 3; + else if (uv < 0x1F && (ustr + 3 <= end)) + ustr += 4; + else + return false; + } + + return true; + } + namespace detail { class locale_initializer From 12358a5dc06961bc1d3be83f55780f64bde41722 Mon Sep 17 00:00:00 2001 From: Jinhao Date: Fri, 27 Nov 2015 01:54:26 +0800 Subject: [PATCH 02/25] change some APIs for accepting utf8 --- include/nana/charset.hpp | 3 - include/nana/deploy.hpp | 10 ++ include/nana/filesystem/fs_utility.hpp | 2 +- include/nana/gui/detail/basic_window.hpp | 2 +- .../gui/detail/native_window_interface.hpp | 4 +- .../gui/detail/widget_notifier_interface.hpp | 4 +- include/nana/gui/filebox.hpp | 30 +++--- include/nana/gui/msgbox.hpp | 42 ++++----- include/nana/gui/place.hpp | 18 ++-- include/nana/gui/programming_interface.hpp | 6 +- include/nana/gui/tooltip.hpp | 8 +- include/nana/gui/widgets/button.hpp | 6 +- include/nana/gui/widgets/categorize.hpp | 17 ++-- include/nana/gui/widgets/checkbox.hpp | 4 +- include/nana/gui/widgets/combox.hpp | 21 ++--- include/nana/gui/widgets/date_chooser.hpp | 12 +-- include/nana/gui/widgets/float_listbox.hpp | 2 +- include/nana/gui/widgets/group.hpp | 8 +- include/nana/gui/widgets/label.hpp | 8 +- include/nana/gui/widgets/scroll.hpp | 2 +- include/nana/gui/widgets/slider.hpp | 4 +- include/nana/gui/widgets/spinbox.hpp | 4 +- include/nana/gui/widgets/textbox.hpp | 13 ++- include/nana/gui/widgets/toolbar.hpp | 4 +- include/nana/gui/widgets/widget.hpp | 9 +- include/nana/internationalization.hpp | 61 +++++------- include/nana/paint/graphics.hpp | 8 +- source/charset.cpp | 30 ------ source/deploy.cpp | 53 +++++++++++ source/filesystem/fs_utility.cpp | 26 +++--- source/gui/detail/native_window_interface.cpp | 35 +++---- source/gui/detail/win32/bedrock.cpp | 10 +- source/gui/filebox.cpp | 68 +++++++------- source/gui/msgbox.cpp | 92 ++++++++++--------- source/gui/place.cpp | 6 +- source/gui/place_parts.hpp | 4 +- source/gui/programming_interface.cpp | 17 ++-- source/gui/tooltip.cpp | 16 ++-- source/gui/widgets/button.cpp | 22 +++-- source/gui/widgets/categorize.cpp | 37 ++++---- source/gui/widgets/checkbox.cpp | 10 +- source/gui/widgets/combox.cpp | 50 +++++----- source/gui/widgets/date_chooser.cpp | 33 ++++--- source/gui/widgets/group.cpp | 12 +-- source/gui/widgets/label.cpp | 14 +-- source/gui/widgets/menu.cpp | 2 +- source/gui/widgets/panel.cpp | 2 +- source/gui/widgets/slider.cpp | 7 +- source/gui/widgets/spinbox.cpp | 10 +- source/gui/widgets/textbox.cpp | 40 ++++---- source/gui/widgets/toolbar.cpp | 18 ++-- source/gui/widgets/treebox.cpp | 2 +- source/gui/widgets/widget.cpp | 20 ++-- source/internationalization.cpp | 40 ++++---- source/paint/graphics.cpp | 12 +++ 55 files changed, 517 insertions(+), 483 deletions(-) diff --git a/include/nana/charset.hpp b/include/nana/charset.hpp index f45a6054..9e109b65 100644 --- a/include/nana/charset.hpp +++ b/include/nana/charset.hpp @@ -9,9 +9,6 @@ namespace nana utf8, utf16, utf32 }; - /// Checks whether a specified text is utf8 encoding - bool is_utf8(const char* str, unsigned len); - namespace detail { class charset_encoding_interface; diff --git a/include/nana/deploy.hpp b/include/nana/deploy.hpp index b3ac88d0..6488e2e6 100644 --- a/include/nana/deploy.hpp +++ b/include/nana/deploy.hpp @@ -72,6 +72,16 @@ namespace std } #endif +namespace nana +{ + /// Checks whether a specified text is utf8 encoding + bool is_utf8(const char* str, unsigned len); + void throw_not_utf8(const std::string& text); + void throw_not_utf8(const char*, unsigned len); + + std::wstring utf8_cast(const std::string&); + std::string utf8_cast(const std::wstring&); +} #ifndef NANA_UNICODE namespace nana diff --git a/include/nana/filesystem/fs_utility.hpp b/include/nana/filesystem/fs_utility.hpp index d52e54dd..5212b02b 100644 --- a/include/nana/filesystem/fs_utility.hpp +++ b/include/nana/filesystem/fs_utility.hpp @@ -24,7 +24,7 @@ namespace filesystem tm modified; }; - bool file_attrib(const nana::string& file, attribute&); + bool file_attrib(const ::std::string& file, attribute&); long long filesize(const nana::string& file); bool mkdir(const nana::string& dir, bool & if_exist); diff --git a/include/nana/gui/detail/basic_window.hpp b/include/nana/gui/detail/basic_window.hpp index ac5db7c1..b725b6bb 100644 --- a/include/nana/gui/detail/basic_window.hpp +++ b/include/nana/gui/detail/basic_window.hpp @@ -145,7 +145,7 @@ namespace detail basic_window *parent; basic_window *owner; - ::nana::string title; + ::std::string title; ::nana::detail::drawer drawer; //Self Drawer with owen graphics basic_window* root_widget; //A pointer refers to the root basic window, if the window is a root, the pointer refers to itself. paint::graphics* root_graph; //Refer to the root buffer graphics diff --git a/include/nana/gui/detail/native_window_interface.hpp b/include/nana/gui/detail/native_window_interface.hpp index 5db4a645..186d3e68 100644 --- a/include/nana/gui/detail/native_window_interface.hpp +++ b/include/nana/gui/detail/native_window_interface.hpp @@ -65,8 +65,8 @@ namespace detail static void window_size(native_window_type, const size&); static void get_window_rect(native_window_type, rectangle&); - static void window_caption(native_window_type, const nana::string&); - static nana::string window_caption(native_window_type); + static void window_caption(native_window_type, const std::string&); + static std::string window_caption(native_window_type); static void capture_window(native_window_type, bool); static nana::point cursor_position(); static native_window_type get_owner_window(native_window_type); diff --git a/include/nana/gui/detail/widget_notifier_interface.hpp b/include/nana/gui/detail/widget_notifier_interface.hpp index 204bdeea..8439304d 100644 --- a/include/nana/gui/detail/widget_notifier_interface.hpp +++ b/include/nana/gui/detail/widget_notifier_interface.hpp @@ -30,8 +30,8 @@ namespace nana virtual widget* widget_ptr() const = 0; virtual void destroy() = 0; - virtual std::wstring caption() = 0; - virtual void caption(std::wstring) = 0; + virtual std::string caption() = 0; + virtual void caption(std::string) = 0; }; } } diff --git a/include/nana/gui/filebox.hpp b/include/nana/gui/filebox.hpp index d60ec5c2..7d8b1b85 100644 --- a/include/nana/gui/filebox.hpp +++ b/include/nana/gui/filebox.hpp @@ -25,7 +25,7 @@ namespace nana filebox(filebox&&) = delete; filebox& operator=(filebox&&) = delete; public: - using filters = std::vector>; + using filters = std::vector>; filebox(bool is_open_mode); filebox(window owner, bool is_open_mode); @@ -37,21 +37,21 @@ namespace nana /// Change owner window void owner(window); - /** @brief specify a title for the dialog - * @param string a text for title - */ - nana::string title( nana::string new_title); ///< . Set a new title for the dialog and \return the old title + /// specify a title for the dialog + /// @param string a text for title + /// @return old title. + ::std::string title( ::std::string new_title); ///< . Set a new title for the dialog and \return the old title /** @brief specify a suggestion directory * @param string a path of initial directory * @note the behavior of init_path is different between Win7 and Win2K/XP/Vista, but its behavior under Linux is conformed with Win7. */ - filebox& init_path(const nana::string&); ///< Suggested init path used to locate a directory when the filebox starts. - filebox& init_file(const nana::string&); ///< Init file, if it contains a path, the init path is replaced by the path of init file. + filebox& init_path(const ::std::string&); ///< Suggested init path used to locate a directory when the filebox starts. + filebox& init_file(const ::std::string&); ///< Init file, if it contains a path, the init path is replaced by the path of init file. /// \brief Add a filetype filter. /// To specify multiple filter in a single description, use a semicolon to separate the patterns(for example,"*.TXT;*.DOC;*.BAK"). - filebox& add_filter(const nana::string& description, ///< for example. "Text File" - const nana::string& filetype ///< filter pattern(for example, "*.TXT") + filebox& add_filter(const ::std::string& description, ///< for example. "Text File" + const ::std::string& filetype ///< filter pattern(for example, "*.TXT") ); filebox& add_filter(const filters &ftres) @@ -62,16 +62,14 @@ namespace nana }; - nana::string path() const; - nana::string file() const; + ::std::string path() const; + ::std::string file() const; - /** @brief Display the filebox dialog - */ + /// Display the filebox dialog bool show() const; - /** @brief Display the filebox dialog - * @note A function object method alternative to show() - */ + /// Display the filebox dialog + /// A function object method alternative to show() bool operator()() const { return show(); diff --git a/include/nana/gui/msgbox.hpp b/include/nana/gui/msgbox.hpp index 3bebcf79..8c5fc5a6 100644 --- a/include/nana/gui/msgbox.hpp +++ b/include/nana/gui/msgbox.hpp @@ -43,10 +43,10 @@ namespace nana msgbox& operator=(const msgbox&); /// Construct that creates a message box with a specified title and default button. - msgbox(const nana::string&); + msgbox(const ::std::string&); /// Construct that creates a message box with an owner windoow, a specified title and buttons. - msgbox(window, const nana::string&, button_t = ok); + msgbox(window, const ::std::string&, button_t = ok); /// Sets an icon for informing user. msgbox& icon(icon_t); @@ -86,7 +86,7 @@ namespace nana private: std::stringstream sstream_; window wd_; - nana::string title_; + std::string title_; button_t button_; icon_t icon_; }; @@ -97,7 +97,7 @@ namespace nana { virtual ~abstract_content() = default; - virtual const ::nana::string& label() const = 0; + virtual const ::std::string& label() const = 0; virtual window create(window, unsigned label_px) = 0; virtual unsigned fixed_pixels() const; }; @@ -107,13 +107,13 @@ namespace nana { struct implement; public: - integer(::nana::string label, int init_value, int begin, int last, int step); + integer(::std::string label, int init_value, int begin, int last, int step); ~integer(); int value() const; private: //Implementation of abstract_content - const ::nana::string& label() const override; + const ::std::string& label() const override; window create(window, unsigned label_px) override; private: std::unique_ptr impl_; @@ -124,13 +124,13 @@ namespace nana { struct implement; public: - real(::nana::string label, double init_value, double begin, double last, double step); + real(::std::string label, double init_value, double begin, double last, double step); ~real(); double value() const; private: //Implementation of abstract_content - const ::nana::string& label() const override; + const ::std::string& label() const override; window create(window, unsigned label_px) override; private: std::unique_ptr impl_; @@ -144,8 +144,8 @@ namespace nana text(const text&) = delete; text& operator=(const text&) = delete; public: - text(::nana::string label, ::nana::string init_text = ::nana::string()); - text(::nana::string label, std::vector<::nana::string>); + text(::std::string label, ::std::string init_text = ::std::string()); + text(::std::string label, std::vector<::std::string>); ~text(); @@ -154,10 +154,10 @@ namespace nana void mask_character(wchar_t ch); - ::nana::string value() const; + ::std::string value() const; private: //Implementation of abstract_content - const ::nana::string& label() const override; + const ::std::string& label() const override; window create(window, unsigned label_px) override; private: std::unique_ptr impl_; @@ -168,17 +168,17 @@ namespace nana { struct implement; public: - date(::nana::string label); + date(::std::string label); ~date(); - ::nana::string value() const; + ::std::string value() const; int year() const; int month() const; //[1, 12] int day() const; //[1, 31] private: //Implementation of abstract_content - const ::nana::string& label() const override; + const ::std::string& label() const override; window create(window, unsigned label_px) override; unsigned fixed_pixels() const override; private: @@ -190,19 +190,19 @@ namespace nana { struct implement; public: - path(::nana::string label, const ::nana::filebox&); + path(::std::string label, const ::nana::filebox&); ~path(); - ::nana::string value() const; + ::std::string value() const; private: //Implementation of abstract_content - const ::nana::string& label() const override; + const ::std::string& label() const override; window create(window, unsigned label_px) override; private: std::unique_ptr impl_; }; - inputbox(window, ::nana::string description, ::nana::string title = ::nana::string()); + inputbox(window, ::std::string description, ::std::string title = ::std::string()); void image(::nana::paint::image, bool is_left, const rectangle& valid_area = {}); void image_v(::nana::paint::image, bool is_top, const rectangle& valid_area = {}); @@ -246,8 +246,8 @@ namespace nana bool _m_open(std::vector&, bool modal); private: window owner_; - ::nana::string description_; - ::nana::string title_; + ::std::string description_; + ::std::string title_; std::function verifier_; ::nana::paint::image images_[4]; ::nana::rectangle valid_areas_[4]; diff --git a/include/nana/gui/place.hpp b/include/nana/gui/place.hpp index 2e3676de..8f32545b 100644 --- a/include/nana/gui/place.hpp +++ b/include/nana/gui/place.hpp @@ -42,13 +42,17 @@ namespace nana : init_(std::move(initializer)) {} - agent(const nana::char_t* text) + agent(const char* text) : text_(text) - {} + { + throw_not_utf8(text); + } - agent(nana::string text, std::function initializer = {}) + agent(std::string text, std::function initializer = {}) : text_(std::move(text)), init_(std::move(initializer)) - {} + { + throw_not_utf8(text_); + } private: std::unique_ptr create(nana::window handle) const override @@ -60,7 +64,7 @@ namespace nana return std::move(ptr); } private: - nana::string text_; + std::string text_; std::function init_; }; @@ -79,8 +83,8 @@ namespace nana public: field_interface() = default; virtual ~field_interface() = default; - virtual field_interface& operator<<(const nana::char_t* label) = 0; - virtual field_interface& operator<<(nana::string label) = 0; + virtual field_interface& operator<<(const char* label) = 0; + virtual field_interface& operator<<(std::string label) = 0; virtual field_interface& operator<<(window) = 0; virtual field_interface& fasten(window) = 0; diff --git a/include/nana/gui/programming_interface.hpp b/include/nana/gui/programming_interface.hpp index 6227f6bb..0612f664 100644 --- a/include/nana/gui/programming_interface.hpp +++ b/include/nana/gui/programming_interface.hpp @@ -72,8 +72,8 @@ namespace API widget_colors* get_scheme(window); void attach_drawer(widget&, drawer_trigger&); - nana::string window_caption(window) throw(); - void window_caption(window, nana::string); + std::string window_caption(window) throw(); + void window_caption(window, std::string); window create_window(window, bool nested, const rectangle&, const appearance&, widget* attached); window create_widget(window, const rectangle&, widget* attached); @@ -272,7 +272,7 @@ namespace API void window_caption(window, const std::string& title_utf8); void window_caption(window, const nana::string& title); - nana::string window_caption(window); + ::std::string window_caption(window); void window_cursor(window, cursor); cursor window_cursor(window); diff --git a/include/nana/gui/tooltip.hpp b/include/nana/gui/tooltip.hpp index cbe29d0d..a03e0923 100644 --- a/include/nana/gui/tooltip.hpp +++ b/include/nana/gui/tooltip.hpp @@ -24,7 +24,7 @@ namespace nana virtual bool tooltip_empty() const = 0; virtual nana::size tooltip_size() const = 0; - virtual void tooltip_text(const nana::string&) = 0; + virtual void tooltip_text(const ::std::string&) = 0; virtual void tooltip_move(const nana::point& screen_pos, bool ignore_pos) = 0; virtual void duration(std::size_t) = 0; }; @@ -63,11 +63,11 @@ namespace nana } tooltip(){} - tooltip(window w, const nana::string &tip){set(w,tip);} + tooltip(window w, const ::std::string &tip){set(w,tip);} - static void set(window, const nana::string&); - static void show(window, point pos, const nana::string&, std::size_t duration); + static void set(window, const ::std::string&); + static void show(window, point pos, const ::std::string&, std::size_t duration); static void close(); private: static void _m_hold_factory(factory_interface*); diff --git a/include/nana/gui/widgets/button.hpp b/include/nana/gui/widgets/button.hpp index 3c0eaf7d..955de3a3 100644 --- a/include/nana/gui/widgets/button.hpp +++ b/include/nana/gui/widgets/button.hpp @@ -83,8 +83,8 @@ namespace nana{ public: button(); button(window, bool visible); - button(window, const nana::string& caption, bool visible = true); - button(window, const nana::char_t* caption, bool visible = true); + button(window, const ::std::string& caption, bool visible = true); + button(window, const char* caption, bool visible = true); button(window, const nana::rectangle& = rectangle(), bool visible = true); button& icon(const nana::paint::image&); @@ -104,7 +104,7 @@ namespace nana{ private: //Overrides widget virtual functions void _m_complete_creation() override; - void _m_caption(nana::string&&) override; + void _m_caption(std::string&&) override; }; }//end namespace nana #endif diff --git a/include/nana/gui/widgets/categorize.hpp b/include/nana/gui/widgets/categorize.hpp index 7f6b2521..a05b3bc2 100644 --- a/include/nana/gui/widgets/categorize.hpp +++ b/include/nana/gui/widgets/categorize.hpp @@ -108,9 +108,9 @@ namespace nana trigger(); ~trigger(); - void insert(const nana::string&, nana::any); - bool childset(const nana::string&, nana::any); - bool childset_erase(const nana::string&); + void insert(const ::std::string&, nana::any); + bool childset(const ::std::string&, nana::any); + bool childset_erase(const ::std::string&); bool clear(); //splitstr @@ -118,8 +118,8 @@ namespace nana void splitstr(const nana::string&); const nana::string& splitstr() const; - void path(const nana::string&); - nana::string path() const; + void path(const ::std::string&); + ::std::string path() const; template void create_event_agent(::nana::categorize& wdg) @@ -189,7 +189,7 @@ namespace nana /// Insert a new category with a specified name and the object of value type. /// The new category would be inserted as a child in current category, /// and after inserting, the new category is replaced of the current category as a new current one. - categorize& insert(const nana::string& name, const value_type& value) + categorize& insert(const std::string& name, const value_type& value) { this->get_drawer_trigger().insert(name, value); API::update_window(*this); @@ -197,8 +197,9 @@ namespace nana } /// Inserts a child category into current category. - categorize& childset(const nana::string& name, const value_type& value) + categorize& childset(const std::string& name, const value_type& value) { + throw_not_utf8(name); if(this->get_drawer_trigger().childset(name, value)) API::update_window(*this); return *this; @@ -237,7 +238,7 @@ namespace nana } private: //Overrides widget's virtual functions - void _m_caption(nana::string&& str) override + void _m_caption(std::string&& str) override { this->get_drawer_trigger().path(str); API::dev::window_caption(*this, this->get_drawer_trigger().path()); diff --git a/include/nana/gui/widgets/checkbox.hpp b/include/nana/gui/widgets/checkbox.hpp index 7af58e72..16af0d5e 100644 --- a/include/nana/gui/widgets/checkbox.hpp +++ b/include/nana/gui/widgets/checkbox.hpp @@ -56,8 +56,8 @@ namespace drawerbase public: checkbox(); checkbox(window, bool visible); - checkbox(window, const nana::string& text, bool visible = true); - checkbox(window, const nana::char_t* text, bool visible = true); + checkbox(window, const std::string& text, bool visible = true); + checkbox(window, const char* text, bool visible = true); checkbox(window, const rectangle& = rectangle(), bool visible = true); void element_set(const char* name); diff --git a/include/nana/gui/widgets/combox.hpp b/include/nana/gui/widgets/combox.hpp index b7e9286e..3297ee18 100644 --- a/include/nana/gui/widgets/combox.hpp +++ b/include/nana/gui/widgets/combox.hpp @@ -75,8 +75,8 @@ namespace nana { public: item_proxy(drawer_impl*, std::size_t pos); - item_proxy& text(const nana::string&); - nana::string text() const; + item_proxy& text(const ::std::string&); + ::std::string text() const; item_proxy& select(); bool selected() const; item_proxy& icon(const nana::paint::image&); @@ -112,14 +112,13 @@ namespace nana template item_proxy& value(T&& t) { - *_m_anyobj(true) = std::move(t); + *_m_anyobj(true) = ::std::move(t); return *this; } public: /// Behavior of Iterator's value_type - bool operator==(const nana::string&) const; + bool operator==(const ::std::string&) const; bool operator==(const char*) const; - bool operator==(const wchar_t*) const; /// Behavior of Iterator item_proxy & operator=(const item_proxy&); @@ -166,19 +165,19 @@ namespace nana combox(); combox(window, bool visible); - combox(window, nana::string, bool visible = true); - combox(window, const nana::char_t*, bool visible = true); + combox(window, ::std::string, bool visible = true); + combox(window, const char*, bool visible = true); combox(window, const rectangle& r = rectangle(), bool visible = true); void clear(); void editable(bool); bool editable() const; void set_accept(std::function); - combox& push_back(nana::string); + combox& push_back(std::string); std::size_t the_number_of_options() const; std::size_t option() const; ///< Index of the last selected, from drop-down list, item. void option(std::size_t); ///< Select the text specified by index - nana::string text(std::size_t) const; + ::std::string text(std::size_t) const; void erase(std::size_t pos); template @@ -224,8 +223,8 @@ namespace nana const drawerbase::combox::drawer_impl& _m_impl() const; private: //Overrides widget's virtual functions - nana::string _m_caption() const throw() override; - void _m_caption(nana::string&&) override; + ::std::string _m_caption() const throw() override; + void _m_caption(::std::string&&) override; nana::any * _m_anyobj(std::size_t pos, bool alloc_if_empty) const override; }; } diff --git a/include/nana/gui/widgets/date_chooser.hpp b/include/nana/gui/widgets/date_chooser.hpp index 9a168bfb..a4e685e1 100644 --- a/include/nana/gui/widgets/date_chooser.hpp +++ b/include/nana/gui/widgets/date_chooser.hpp @@ -42,12 +42,12 @@ namespace nana trigger(); bool chose() const; nana::date read() const; - void week_name(unsigned index, const nana::string&); + void week_name(unsigned index, const std::string&); private: where _m_pos_where(graph_reference, const ::nana::point& pos); void _m_draw_topbar(graph_reference); void _m_make_drawing_basis(drawing_basis&, graph_reference, const nana::point& refpos); - void _m_draw_pos(drawing_basis &, graph_reference, int x, int y, const nana::string&, bool primary, bool sel); + void _m_draw_pos(drawing_basis &, graph_reference, int x, int y, const ::std::string&, bool primary, bool sel); void _m_draw_pos(drawing_basis &, graph_reference, int x, int y, int number, bool primary, bool sel); void _m_draw_ex_days(drawing_basis &, graph_reference, int begx, int begy, bool before); void _m_draw_days(const nana::point& refpos, graph_reference); @@ -61,7 +61,7 @@ namespace nana void mouse_leave(graph_reference, const arg_mouse&) override; void mouse_up(graph_reference, const arg_mouse&) override; private: - nana::string weekstr_[7]; + ::std::string weekstr_[7]; widget * widget_; @@ -105,13 +105,13 @@ namespace nana public: date_chooser(); date_chooser(window, bool visible); - date_chooser(window, const nana::string& text, bool visible = true); - date_chooser(window, const nana::char_t* text, bool visible = true); + date_chooser(window, const ::std::string& text, bool visible = true); + date_chooser(window, const char* text, bool visible = true); date_chooser(window, const nana::rectangle& r = rectangle(), bool visible = true); bool chose() const; nana::date read() const; - void weekstr(unsigned index, const nana::string&);/// impl_; }; diff --git a/include/nana/gui/widgets/label.hpp b/include/nana/gui/widgets/label.hpp index aa28effc..7f769f27 100644 --- a/include/nana/gui/widgets/label.hpp +++ b/include/nana/gui/widgets/label.hpp @@ -57,8 +57,8 @@ namespace nana typedef drawerbase::label::command command; label(); label(window, bool visible); - label(window, const nana::string& text, bool visible = true); - label(window parent, const nana::char_t* text, bool visible = true) :label(parent, nana::string(text),visible) {}; + label(window, const std::string& text, bool visible = true); + label(window parent, const char* text, bool visible = true) :label(parent, std::string(text),visible) {}; label(window, const rectangle& = {}, bool visible = true); label& transparent(bool); ///< Switchs the label widget to the transparent background mode. bool transparent() const throw(); @@ -71,12 +71,12 @@ namespace nana /// "corrected" size that changes lines to fit the text into the specified width nana::size measure(unsigned allowed_width_in_pixel) const; - static ::nana::size measure(::nana::paint::graphics&, const ::nana::string&, unsigned allowed_width_in_pixel, bool format_enabled, align h_align, align_v v_align); + static ::nana::size measure(::nana::paint::graphics&, const ::std::string&, unsigned allowed_width_in_pixel, bool format_enabled, align h_align, align_v v_align); label& text_align(align horizontal_align, align_v vertical_align= align_v::top); private: //Overrides widget's virtual function - void _m_caption(nana::string&&) override; + void _m_caption(std::string&&) override; }; }//end namespace nana #endif diff --git a/include/nana/gui/widgets/scroll.hpp b/include/nana/gui/widgets/scroll.hpp index f09b2046..96d1b023 100644 --- a/include/nana/gui/widgets/scroll.hpp +++ b/include/nana/gui/widgets/scroll.hpp @@ -186,7 +186,7 @@ namespace nana { graph_ = &graph; widget_ = static_cast< ::nana::scroll*>(&widget); - widget.caption(STR("Nana Scroll")); + widget.caption("nana scroll"); timer_.stop(); timer_.elapse(std::bind(&trigger::_m_tick, this)); diff --git a/include/nana/gui/widgets/slider.hpp b/include/nana/gui/widgets/slider.hpp index 0e32237d..c5372034 100644 --- a/include/nana/gui/widgets/slider.hpp +++ b/include/nana/gui/widgets/slider.hpp @@ -45,7 +45,7 @@ namespace nana { public: virtual ~provider() = default; - virtual nana::string adorn_trace(unsigned vmax, unsigned vadorn) const = 0; + virtual std::string adorn_trace(unsigned vmax, unsigned vadorn) const = 0; }; class renderer @@ -81,7 +81,7 @@ namespace nana virtual void background(window, graph_reference, bool isglass) = 0; virtual void adorn(window, graph_reference, const adorn_t&) = 0; - virtual void adorn_textbox(window, graph_reference, const nana::string&, const nana::rectangle&) = 0; + virtual void adorn_textbox(window, graph_reference, const ::std::string&, const nana::rectangle&) = 0; virtual void bar(window, graph_reference, const bar_t&) = 0; virtual void slider(window, graph_reference, const slider_t&) = 0; }; diff --git a/include/nana/gui/widgets/spinbox.hpp b/include/nana/gui/widgets/spinbox.hpp index dc081018..00fab1d9 100644 --- a/include/nana/gui/widgets/spinbox.hpp +++ b/include/nana/gui/widgets/spinbox.hpp @@ -106,8 +106,8 @@ namespace nana void modifier(std::wstring prefix, std::wstring suffix); void modifier(const std::string & prefix_utf8, const std::string& suffix_utf8); private: - ::nana::string _m_caption() const throw(); - void _m_caption(::nana::string&&); + ::std::string _m_caption() const throw(); + void _m_caption(::std::string&&); }; //end class spinbox }//end namespace nana diff --git a/include/nana/gui/widgets/textbox.hpp b/include/nana/gui/widgets/textbox.hpp index f0d8ff02..9d2d70bc 100644 --- a/include/nana/gui/widgets/textbox.hpp +++ b/include/nana/gui/widgets/textbox.hpp @@ -111,13 +111,13 @@ namespace nana /// @param window A handle to the parent window of the widget being created. /// @param text the text that will be displayed. /// @param visible specifying the visible after creating. - textbox(window, const nana::string& text, bool visible = true); + textbox(window, const std::string& text, bool visible = true); /// \brief The construct that creates a widget with a specified text. /// @param window A handle to the parent window of the widget being created. /// @param text the text that will be displayed. /// @param visible specifying the visible after creating. - textbox(window, const nana::char_t* text, bool visible = true); + textbox(window, const char* text, bool visible = true); /// \brief The construct that creates a widget. /// @param window A handle to the parent window of the widget being created. @@ -173,7 +173,7 @@ namespace nana textbox& editable(bool); void set_accept(std::function); - textbox& tip_string(nana::string); + textbox& tip_string(::std::string); /// Set a mask character. Text is displayed as mask character if a mask character is set. This is used for hiding some special text, such as password. textbox& mask(nana::char_t); @@ -195,11 +195,10 @@ namespace nana 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 kw_list); + void set_keywords(const std::string& name, bool case_sensitive, bool whole_word_match, std::initializer_list kw_list); void set_keywords(const std::string& name, bool case_sensitive, bool whole_word_match, std::initializer_list kw_list_utf8); void erase_keyword(const nana::string& kw); - /// Returns the text position of each line that currently displays on screen. text_positions text_position() const; @@ -210,8 +209,8 @@ namespace nana unsigned line_pixels() const; protected: //Overrides widget's virtual functions - ::nana::string _m_caption() const throw() override; - void _m_caption(::nana::string&&) override; + ::std::string _m_caption() const throw() override; + void _m_caption(::std::string&&) override; void _m_typeface(const paint::font&) override; }; }//end namespace nana diff --git a/include/nana/gui/widgets/toolbar.hpp b/include/nana/gui/widgets/toolbar.hpp index 0b097676..d23efcc6 100644 --- a/include/nana/gui/widgets/toolbar.hpp +++ b/include/nana/gui/widgets/toolbar.hpp @@ -87,8 +87,8 @@ namespace nana toolbar(window, const rectangle& = rectangle(), bool visible = true); void separate(); ///< Adds a separator. - void append(const nana::string& text, const nana::paint::image& img); ///< Adds a control button. - void append(const nana::string& text); ///< Adds a control button. + void append(const ::std::string& text, const nana::paint::image& img); ///< Adds a control button. + void append(const ::std::string& text); ///< Adds a control button. bool enable(size_type index) const; void enable(size_type index, bool enable_state); void scale(unsigned s); ///< Sets the scale of control button. diff --git a/include/nana/gui/widgets/widget.hpp b/include/nana/gui/widgets/widget.hpp index 2da63cda..435e2274 100644 --- a/include/nana/gui/widgets/widget.hpp +++ b/include/nana/gui/widgets/widget.hpp @@ -41,9 +41,8 @@ namespace nana window parent() const; - nana::string caption() const throw(); + ::std::string caption() const throw(); void caption(std::string utf8); - void caption(std::wstring); template void i18n(std::string msgid, Args&&... args) @@ -91,7 +90,7 @@ namespace nana widget& register_shortkey(char_t); ///< Registers a shortkey. To remove a registered key, pass 0. widget& take_active(bool activated, window take_if_not_activated); - widget& tooltip(const nana::string&); + widget& tooltip(const ::std::string&); operator dummy_bool_type() const; operator window() const; @@ -105,8 +104,8 @@ namespace nana virtual void _m_complete_creation(); virtual general_events& _m_get_general_events() const = 0; - virtual nana::string _m_caption() const throw(); - virtual void _m_caption(nana::string&&); + virtual ::std::string _m_caption() const throw(); + virtual void _m_caption(::std::string&&); virtual nana::cursor _m_cursor() const; virtual void _m_cursor(nana::cursor); virtual void _m_close(); diff --git a/include/nana/internationalization.hpp b/include/nana/internationalization.hpp index 341c8e97..e1e2cbe3 100644 --- a/include/nana/internationalization.hpp +++ b/include/nana/internationalization.hpp @@ -28,34 +28,34 @@ namespace nana void load_utf8(const std::string& file); template - nana::string get(std::string msgid_utf8, Args&&... args) const + ::std::string get(std::string msgid_utf8, Args&&... args) const { - std::vector arg_strs; + std::vector arg_strs; _m_fetch_args(arg_strs, std::forward(args)...); - nana::string msgstr; + ::std::string msgstr; if (_m_get(msgid_utf8, msgstr)) _m_replace_args(msgstr, &arg_strs); return msgstr; } - nana::string get(std::string msgid_utf8) const; - void set(std::string msgid_utf8, nana::string msgstr); + ::std::string get(std::string msgid_utf8) const; + void set(std::string msgid_utf8, ::std::string msgstr); template - nana::string operator()(std::string msgid_utf8, Args&&... args) const + ::std::string operator()(std::string msgid_utf8, Args&&... args) const { return get(msgid_utf8, std::forward(args)...); } private: - bool _m_get(std::string& msgid, nana::string& msgstr) const; - void _m_replace_args(nana::string& str, std::vector * arg_strs) const; + bool _m_get(std::string& msgid, ::std::string& msgstr) const; + void _m_replace_args(::std::string& str, std::vector<::std::string> * arg_strs) const; - void _m_fetch_args(std::vector&) const //Termination of _m_fetch_args + void _m_fetch_args(std::vector&) const //Termination of _m_fetch_args {} template - void _m_fetch_args(std::vector& v, Arg&& arg) const + void _m_fetch_args(std::vector& v, Arg&& arg) const { std::wstringstream ss; ss << arg; @@ -63,52 +63,39 @@ namespace nana } template - void _m_fetch_args(std::vector& v, const char* arg, Args&&... args) const + void _m_fetch_args(std::vector& v, const char* arg, Args&&... args) const { - std::wstringstream ss; - ss << nana::string(nana::charset(arg)); - v.emplace_back(ss.str()); - + v.emplace_back(arg); _m_fetch_args(v, std::forward(args)...); } template - void _m_fetch_args(std::vector& v, const std::string& arg, Args&&... args) const + void _m_fetch_args(std::vector& v, const std::string& arg, Args&&... args) const { - std::wstringstream ss; - ss << nana::string(nana::charset(arg)); - v.emplace_back(ss.str()); - + v.emplace_back(arg); _m_fetch_args(v, std::forward(args)...); } template - void _m_fetch_args(std::vector& v, std::string& arg, Args&&... args) const + void _m_fetch_args(std::vector& v, std::string& arg, Args&&... args) const { - std::wstringstream ss; - ss << nana::string(nana::charset(arg)); - v.emplace_back(ss.str()); - + v.emplace_back(arg); _m_fetch_args(v, std::forward(args)...); } template - void _m_fetch_args(std::vector& v, std::string&& arg, Args&&... args) const + void _m_fetch_args(std::vector& v, std::string&& arg, Args&&... args) const { - std::wstringstream ss; - ss << nana::string(nana::charset(arg)); - v.emplace_back(ss.str()); - + v.emplace_back(std::move(arg)); _m_fetch_args(v, std::forward(args)...); } template - void _m_fetch_args(std::vector& v, Arg&& arg, Args&&... args) const + void _m_fetch_args(std::vector& v, Arg&& arg, Args&&... args) const { - std::wstringstream ss; + std::stringstream ss; ss << arg; v.emplace_back(ss.str()); - _m_fetch_args(v, std::forward(args)...); } };//end class internationalization @@ -119,7 +106,7 @@ namespace nana { public: virtual ~eval_arg() = default; - virtual nana::string eval() const = 0; + virtual std::string eval() const = 0; virtual std::unique_ptr clone() const = 0; }; @@ -134,7 +121,7 @@ namespace nana : fn_(fn) {} - nana::string eval() const override + std::string eval() const override { std::wstringstream ss; ss << fn_(); @@ -166,7 +153,7 @@ namespace nana i18n_eval& operator=(const i18n_eval&); i18n_eval& operator=(i18n_eval&& rhs); - nana::string operator()() const; + std::string operator()() const; private: void _m_fetch_args(){} //Termination of _m_fetch_args @@ -180,7 +167,7 @@ namespace nana template void _m_add_args(Arg&& arg) { - std::wstringstream ss; + std::stringstream ss; ss << arg; _m_add_args(ss.str()); } diff --git a/include/nana/paint/graphics.hpp b/include/nana/paint/graphics.hpp index a194aa7e..960e9cd6 100644 --- a/include/nana/paint/graphics.hpp +++ b/include/nana/paint/graphics.hpp @@ -89,12 +89,13 @@ namespace nana void resize(const ::nana::size&); void typeface(const font&); ///< Selects a specified font type into the graphics object. font typeface() const; + ::nana::size text_extent_size(const ::std::string&) const; ::nana::size text_extent_size(const char_t*) const; ///< Computes the width and height of the specified string of text. - ::nana::size text_extent_size(const string&) const; ///< Computes the width and height of the specified string of text. + ::nana::size text_extent_size(const ::std::wstring&) const; ///< Computes the width and height of the specified string of text. ::nana::size text_extent_size(const char_t*, std::size_t length) const; ///< Computes the width and height of the specified string of text with the specified length. - ::nana::size text_extent_size(const string&, std::size_t length) const; ///< Computes the width and height of the specified string of text with the specified length. + ::nana::size text_extent_size(const ::std::wstring&, std::size_t length) const; ///< Computes the width and height of the specified string of text with the specified length. ::nana::size glyph_extent_size(const char_t*, std::size_t length, std::size_t begin, std::size_t end) const; - ::nana::size glyph_extent_size(const string&, std::size_t length, std::size_t begin, std::size_t end) const; + ::nana::size glyph_extent_size(const ::std::wstring&, std::size_t length, std::size_t begin, std::size_t end) const; bool glyph_pixels(const char_t *, std::size_t length, unsigned* pxbuf) const; ::nana::size bidi_extent_size(const std::wstring&) const; ::nana::size bidi_extent_size(const std::string&) const; @@ -150,6 +151,7 @@ namespace nana void set_pixel(int x, int y, const ::nana::color&); void set_pixel(int x, int y); + void string(const point&, const std::string&); void string(point, const char_t*, std::size_t len); void string(const point&, const char_t*); void string(const point&, const ::nana::string&); diff --git a/source/charset.cpp b/source/charset.cpp index ed0b9213..1b57ad29 100644 --- a/source/charset.cpp +++ b/source/charset.cpp @@ -30,36 +30,6 @@ namespace nana { - bool is_utf8(const char* str, unsigned len) - { - auto ustr = reinterpret_cast(str); - auto end = ustr + len; - - while (ustr < end) - { - const auto uv = *ustr; - if (uv < 0x80) - { - ++ustr; - continue; - } - - if (uv < 0xC0) - return false; - - if ((uv < 0xE0) && (ustr + 1 < end)) - ustr += 2; - else if (uv < 0xF0 && (ustr + 2 <= end)) - ustr += 3; - else if (uv < 0x1F && (ustr + 3 <= end)) - ustr += 4; - else - return false; - } - - return true; - } - namespace detail { class locale_initializer diff --git a/source/deploy.cpp b/source/deploy.cpp index d61b0dd5..06eefdd5 100644 --- a/source/deploy.cpp +++ b/source/deploy.cpp @@ -355,6 +355,59 @@ namespace std namespace nana { + bool is_utf8(const char* str, unsigned len) + { + auto ustr = reinterpret_cast(str); + auto end = ustr + len; + + while (ustr < end) + { + const auto uv = *ustr; + if (uv < 0x80) + { + ++ustr; + continue; + } + + if (uv < 0xC0) + return false; + + if ((uv < 0xE0) && (ustr + 1 < end)) + ustr += 2; + else if (uv < 0xF0 && (ustr + 2 <= end)) + ustr += 3; + else if (uv < 0x1F && (ustr + 3 <= end)) + ustr += 4; + else + return false; + } + + return true; + } + + void throw_not_utf8(const std::string& text) + { + if (!is_utf8(text.c_str(), text.length())) + throw std::invalid_argument("The text is not encoded in UTF8"); + } + + void throw_not_utf8(const char* text, unsigned len) + { + if (!is_utf8(text, len)) + throw std::invalid_argument("The text is not encoded in UTF8"); + } + + std::wstring utf8_cast(const std::string& text) + { + return ::nana::charset(text, ::nana::unicode::utf8); + } + + std::string utf8_cast(const std::wstring& text) + { + return ::nana::charset(text).to_bytes(::nana::unicode::utf8); + } + + std::size_t strlen(const char_t* str) { #if defined(NANA_UNICODE) diff --git a/source/filesystem/fs_utility.cpp b/source/filesystem/fs_utility.cpp index c9cfd677..5fb75646 100644 --- a/source/filesystem/fs_utility.cpp +++ b/source/filesystem/fs_utility.cpp @@ -188,11 +188,12 @@ namespace filesystem #endif }//end namespace detail - bool file_attrib(const nana::string& file, attribute& attr) + bool file_attrib(const std::string& file, attribute& attr) { + throw_not_utf8(file); #if defined(NANA_WINDOWS) WIN32_FILE_ATTRIBUTE_DATA fad; - if(::GetFileAttributesEx(file.c_str(), GetFileExInfoStandard, &fad)) + if(::GetFileAttributesEx(utf8_cast(file).c_str(), GetFileExInfoStandard, &fad)) { LARGE_INTEGER li; li.u.LowPart = fad.nFileSizeLow; @@ -204,7 +205,7 @@ namespace filesystem } #elif defined(NANA_LINUX) || defined(NANA_MACOS) struct stat fst; - if(0 == ::stat(static_cast(nana::charset(file)).c_str(), &fst)) + if(0 == ::stat(file.c_str(), &fst)) { attr.bytes = fst.st_size; attr.is_directory = (0 != (040000 & fst.st_mode)); @@ -215,7 +216,7 @@ namespace filesystem return false; } - long long filesize(const nana::string& file) + long long filesize(const std::string& file) { #if defined(NANA_WINDOWS) //Some compilation environment may fail to link to GetFileSizeEx @@ -223,7 +224,7 @@ namespace filesystem GetFileSizeEx_fptr_t get_file_size_ex = reinterpret_cast(::GetProcAddress(::GetModuleHandleA("Kernel32.DLL"), "GetFileSizeEx")); if(get_file_size_ex) { - HANDLE handle = ::CreateFile(file.c_str(), GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); + HANDLE handle = ::CreateFile(utf8_cast(file).c_str(), GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); if(INVALID_HANDLE_VALUE != handle) { LARGE_INTEGER li; @@ -235,23 +236,18 @@ namespace filesystem } } return 0; -#elif defined(NANA_LINUX) - FILE * stream = ::fopen(static_cast(nana::charset(file)).c_str(), "rb"); +#else + auto stream = ::fopen(file.c_str(), "rb"); long long size = 0; if(stream) { + #if defined(NANA_LINUX) fseeko64(stream, 0, SEEK_END); size = ftello64(stream); - fclose(stream); - } - return size; -#elif defined(NANA_MACOS) - FILE * stream = ::fopen(static_cast(nana::charset(file)).c_str(), "rb"); - long long size = 0; - if (stream) - { + #elif defined(NANA_MACOS) fseeko(stream, 0, SEEK_END); size = ftello(stream); + #endif fclose(stream); } return size; diff --git a/source/gui/detail/native_window_interface.cpp b/source/gui/detail/native_window_interface.cpp index fa3c2558..b15001b9 100644 --- a/source/gui/detail/native_window_interface.cpp +++ b/source/gui/detail/native_window_interface.cpp @@ -1076,32 +1076,22 @@ namespace nana{ #endif } - void native_interface::window_caption(native_window_type wd, const nana::string& title) + void native_interface::window_caption(native_window_type wd, const std::string& title) { #if defined(NANA_WINDOWS) + std::wstring wtext = ::nana::charset(title, ::nana::unicode::utf8); if(::GetCurrentThreadId() != ::GetWindowThreadProcessId(reinterpret_cast(wd), 0)) { - wchar_t * wstr; -#if defined(NANA_UNICODE) - wstr = new wchar_t[title.length() + 1]; - wcscpy(wstr, title.c_str()); -#else - std::wstring str = nana::charset(title); - wstr = new wchar_t[str.length() + 1]; - wcscpy(wstr, str.c_str()); -#endif + wchar_t * wstr = new wchar_t[wtext.length() + 1]; + std::wcscpy(wstr, wtext.c_str()); ::PostMessage(reinterpret_cast(wd), nana::detail::messages::remote_thread_set_window_text, reinterpret_cast(wstr), 0); } else - ::SetWindowText(reinterpret_cast(wd), title.c_str()); + ::SetWindowText(reinterpret_cast(wd), wtext.c_str()); #elif defined(NANA_X11) ::XTextProperty name; - #if defined(NANA_UNICODE) - std::string mbstr = nana::charset(title); - char* text = const_cast(mbstr.c_str()); - #else - char* text = const_cast(title.c_str()); - #endif + char * text = const_cast(title.c_str()); + nana::detail::platform_scope_guard psg; ::XStringListToTextProperty(&text, 1, &name); ::XSetWMName(restrict::spec.open_display(), reinterpret_cast(wd), &name); @@ -1111,7 +1101,7 @@ namespace nana{ #endif } - nana::string native_interface::window_caption(native_window_type wd) + std::string native_interface::window_caption(native_window_type wd) { #if defined(NANA_WINDOWS) int length = ::GetWindowTextLength(reinterpret_cast(wd)); @@ -1126,9 +1116,8 @@ namespace nana{ //Remove the null terminator writtien by GetWindowText str.resize(length); - return str; + return ::nana::charset(str); } - return nana::string(); #elif defined(NANA_X11) nana::detail::platform_scope_guard psg; ::XTextProperty txtpro; @@ -1140,14 +1129,14 @@ namespace nana{ { if(size > 1) { - nana::string str = nana::charset(*strlist); + std::string text = *strlist; ::XFreeStringList(strlist); - return str; + return text; } } } - return nana::string(); #endif + return std::string(); } void native_interface::capture_window(native_window_type wd, bool cap) diff --git a/source/gui/detail/win32/bedrock.cpp b/source/gui/detail/win32/bedrock.cpp index 7cdd1b5f..fff32177 100644 --- a/source/gui/detail/win32/bedrock.cpp +++ b/source/gui/detail/win32/bedrock.cpp @@ -440,9 +440,9 @@ namespace detail } catch(std::exception& e) { - (msgbox(modal_window, STR("An uncaptured std::exception during message pumping: ")).icon(msgbox::icon_information) - < filters; }; @@ -885,9 +885,12 @@ namespace nana auto len = ::GetCurrentDirectory(0, nullptr); if(len) { - impl_->path.resize(len + 1); - ::GetCurrentDirectory(len, &(impl_->path[0])); - impl_->path.resize(len); + std::wstring path; + path.resize(len + 1); + ::GetCurrentDirectory(len, &(path[0])); + path.resize(len); + + impl_->path = utf8_cast(path); } #endif } @@ -913,13 +916,13 @@ namespace nana impl_->owner = wd; } - nana::string filebox::title(nana::string s) + std::string filebox::title(std::string s) { impl_->title.swap(s); return s; } - filebox& filebox::init_path(const nana::string& ipstr) + filebox& filebox::init_path(const std::string& ipstr) { if(ipstr.empty()) { @@ -935,25 +938,25 @@ namespace nana return *this; } - filebox& filebox::init_file(const nana::string& ifstr) + filebox& filebox::init_file(const std::string& ifstr) { impl_->file = ifstr; return *this; } - filebox& filebox::add_filter(const nana::string& description, const nana::string& filetype) + filebox& filebox::add_filter(const std::string& description, const std::string& filetype) { implement::filter flt = {description, filetype}; impl_->filters.push_back(flt); return *this; } - nana::string filebox::path() const + std::string filebox::path() const { return impl_->path; } - nana::string filebox::file() const + std::string filebox::file() const { return impl_->file; } @@ -961,36 +964,36 @@ namespace nana bool filebox::show() const { #if defined(NANA_WINDOWS) - if(impl_->file.size() < 520) - impl_->file.resize(520); + std::wstring wfile; + wfile.resize(520); OPENFILENAME ofn; memset(&ofn, 0, sizeof ofn); ofn.lStructSize = sizeof(ofn); ofn.hwndOwner = reinterpret_cast(API::root(impl_->owner)); - ofn.lpstrFile = &(impl_->file[0]); - ofn.nMaxFile = static_cast(impl_->file.size() - 1); + ofn.lpstrFile = &(wfile[0]); + ofn.nMaxFile = static_cast(wfile.size() - 1); - const nana::char_t * filter; - nana::string filter_holder; - nana::string default_extension; + const wchar_t * filter; + std::wstring filter_holder; + std::wstring default_extension; if(impl_->filters.size()) { for(auto & f : impl_->filters) { - filter_holder += f.des; - filter_holder += static_cast('\0'); - nana::string fs = f.type; + filter_holder += utf8_cast(f.des); + filter_holder += static_cast('\0'); + std::wstring fs = utf8_cast(f.type); std::size_t pos = 0; while(true) { - pos = fs.find(STR(" "), pos); + pos = fs.find(L" ", pos); if(pos == fs.npos) break; fs.erase(pos); } filter_holder += fs; - filter_holder += static_cast('\0'); + filter_holder += static_cast('\0'); //Get the default file extentsion if (default_extension.empty()) @@ -1010,14 +1013,16 @@ namespace nana filter = filter_holder.data(); } else - filter = STR("All Files\0*.*\0"); + filter = L"All Files\0*.*\0"; + auto wtitle = utf8_cast(impl_->title); + auto wpath = utf8_cast(impl_->path); ofn.lpstrFilter = filter; - ofn.lpstrTitle = (impl_->title.size() ? impl_->title.c_str() : nullptr); + ofn.lpstrTitle = (wtitle.empty() ? nullptr : wtitle.c_str()); ofn.nFilterIndex = 0; ofn.lpstrFileTitle = nullptr; ofn.nMaxFileTitle = 0; - ofn.lpstrInitialDir = (impl_->path.size() ? impl_->path.c_str() : nullptr); + ofn.lpstrInitialDir = (wpath.empty() ? nullptr : wpath.c_str()); if (!impl_->open_or_save) ofn.Flags = OFN_OVERWRITEPROMPT; //Overwrite prompt if it is save mode @@ -1026,7 +1031,8 @@ namespace nana if(FALSE == (impl_->open_or_save ? ::GetOpenFileName(&ofn) : ::GetSaveFileName(&ofn))) return false; - impl_->file.resize(nana::strlen(impl_->file.data())); + wfile.resize(std::wcslen(wfile.data())); + impl_->file = utf8_cast(wfile); #elif defined(NANA_LINUX) || defined(NANA_MACOS) filebox_implement fb(impl_->owner, impl_->open_or_save, impl_->title); @@ -1055,7 +1061,7 @@ namespace nana if(false == fb.file(impl_->file)) return false; #endif - auto tpos = impl_->file.find_last_of(STR("\\/")); + auto tpos = impl_->file.find_last_of("\\/"); if(tpos != impl_->file.npos) impl_->path = impl_->file.substr(0, tpos); else diff --git a/source/gui/msgbox.cpp b/source/gui/msgbox.cpp index a34fdbe2..adaffb22 100644 --- a/source/gui/msgbox.cpp +++ b/source/gui/msgbox.cpp @@ -352,13 +352,17 @@ namespace nana return *this; } - msgbox::msgbox(const nana::string& title) + msgbox::msgbox(const std::string& title) : wd_(nullptr), title_(title), button_(ok), icon_(icon_none) - {} + { + throw_not_utf8(title_); + } - msgbox::msgbox(window wd, const nana::string& title, button_t b) + msgbox::msgbox(window wd, const std::string& title, button_t b) : wd_(wd), title_(title), button_(b), icon_(icon_none) - {} + { + throw_not_utf8(title_); + } msgbox& msgbox::icon(icon_t ic) { @@ -439,11 +443,8 @@ namespace nana default: break; } - #if defined(NANA_UNICODE) - int bt = ::MessageBoxW(reinterpret_cast(API::root(wd_)), static_cast(nana::charset(sstream_.str())).c_str(), title_.c_str(), type); - #else - int bt = ::MessageBoxA(reinterpret_cast(API::root(wd_), sstream_.str().c_str(), title_.c_str(), type); - #endif + auto bt = ::MessageBoxW(reinterpret_cast(API::root(wd_)), utf8_cast(sstream_.str()).c_str(), utf8_cast(title_).c_str(), type); + switch(bt) { case IDOK: @@ -473,9 +474,12 @@ namespace nana : public ::nana::form { public: - inputbox_window(window owner, paint::image (&imgs)[4], ::nana::rectangle (&valid_areas)[4], const ::nana::string & desc, const ::nana::string& title, std::size_t contents, unsigned fixed_pixels, const std::vector& each_height) + inputbox_window(window owner, paint::image (&imgs)[4], ::nana::rectangle (&valid_areas)[4], const ::std::string & desc, const ::std::string& title, std::size_t contents, unsigned fixed_pixels, const std::vector& each_height) : form(owner, API::make_center(owner, 500, 300), appear::decorate<>()) { + throw_not_utf8(desc); + throw_not_utf8(title); + desc_.create(*this); desc_.format(true).caption(desc); auto desc_extent = desc_.measure(470); @@ -652,13 +656,13 @@ namespace nana int last; int step; - ::nana::string label_text; + ::std::string label_text; ::nana::panel dock; ::nana::label label; ::nana::spinbox spinbox; }; - inputbox::integer::integer(::nana::string label, int init_value, int begin, int last, int step) + inputbox::integer::integer(::std::string label, int init_value, int begin, int last, int step) : impl_(new implement) { auto impl = impl_.get(); @@ -681,7 +685,7 @@ namespace nana } //Implementation of abstract_content - const ::nana::string& inputbox::integer::label() const + const ::std::string& inputbox::integer::label() const { return impl_->label_text; } @@ -730,13 +734,13 @@ namespace nana double last; double step; - ::nana::string label_text; + ::std::string label_text; ::nana::panel dock; ::nana::label label; ::nana::spinbox spinbox; }; - inputbox::real::real(::nana::string label, double init_value, double begin, double last, double step) + inputbox::real::real(::std::string label, double init_value, double begin, double last, double step) : impl_(new implement) { auto impl = impl_.get(); @@ -759,7 +763,7 @@ namespace nana } //Implementation of abstract_content - const ::nana::string& inputbox::real::label() const + const ::std::string& inputbox::real::label() const { return impl_->label_text; } @@ -803,29 +807,33 @@ namespace nana //class text struct inputbox::text::implement { - ::nana::string value; - ::nana::string tip; + ::std::string value; + ::std::string tip; wchar_t mask_character{0}; - std::vector< ::nana::string> options; + std::vector< ::std::string> options; - ::nana::string label_text; - ::nana::string init_text; + ::std::string label_text; + ::std::string init_text; ::nana::panel dock; ::nana::label label; ::nana::combox combox; ::nana::textbox textbox; }; - inputbox::text::text(::nana::string label, ::nana::string init_text) + inputbox::text::text(::std::string label, ::std::string init_text) : impl_(new implement) { impl_->label_text.swap(label); impl_->init_text.swap(init_text); } - inputbox::text::text(::nana::string label, std::vector<::nana::string> options) + inputbox::text::text(::std::string label, std::vector<::std::string> options) : impl_(new implement) { + throw_not_utf8(label); + for (auto & text : options) + throw_not_utf8(text); + impl_->options.swap(options); impl_->label_text.swap(label); } @@ -835,12 +843,12 @@ namespace nana void inputbox::text::tip_string(std::wstring tip) { - impl_->tip.swap(tip); + impl_->tip.swap(utf8_cast(tip)); } void inputbox::text::tip_string(std::string tip_utf8) { - impl_->tip = ::nana::charset(tip_utf8, ::nana::unicode::utf8); + impl_->tip.swap(tip_utf8); } void inputbox::text::mask_character(wchar_t ch) @@ -848,7 +856,7 @@ namespace nana impl_->mask_character = ch; } - ::nana::string inputbox::text::value() const + ::std::string inputbox::text::value() const { if (!impl_->textbox.empty()) return impl_->textbox.caption(); @@ -859,7 +867,7 @@ namespace nana } //Implementation of abstract_content - const ::nana::string& inputbox::text::label() const + const ::std::string& inputbox::text::label() const { return impl_->label_text; } @@ -929,7 +937,7 @@ namespace nana int month; int day; - ::nana::string label_text; + ::std::string label_text; ::nana::panel dock; ::nana::label label; ::nana::combox wdg_month; @@ -937,18 +945,18 @@ namespace nana ::nana::spinbox wdg_year; }; - inputbox::date::date(::nana::string label) + inputbox::date::date(::std::string label) : impl_(new implement) { - impl_->label_text = std::move(label); + impl_->label_text.swap(label); } //Instance for impl_ because implmenet is incomplete type at the point of declaration inputbox::date::~date(){} - ::nana::string inputbox::date::value() const + ::std::string inputbox::date::value() const { - return std::to_wstring(impl_->month) + L'-' + std::to_wstring(impl_->day) + L", " + std::to_wstring(impl_->year); + return std::to_string(impl_->month) + '-' + std::to_string(impl_->day) + ", " + std::to_string(impl_->year); } int inputbox::date::year() const @@ -974,7 +982,7 @@ namespace nana } //Implementation of abstract_content - const ::nana::string& inputbox::date::label() const + const ::std::string& inputbox::date::label() const { return impl_->label_text; } @@ -1071,19 +1079,21 @@ namespace nana { filebox fbox; - ::nana::string value; - ::nana::string label_text; + ::std::string value; + ::std::string label_text; ::nana::panel dock; ::nana::label label; ::nana::textbox path_edit; ::nana::button browse; - implement(const filebox& fb, ::nana::string&& labelstr) + implement(const filebox& fb, ::std::string&& labelstr) : fbox(fb), label_text(std::move(labelstr)) - {} + { + throw_not_utf8(label_text); + } }; - inputbox::path::path(::nana::string label, const filebox& fb) + inputbox::path::path(::std::string label, const filebox& fb) : impl_(new implement(fb, std::move(label))) { } @@ -1091,7 +1101,7 @@ namespace nana //Instance for impl_ because implmenet is incomplete type at the point of declaration inputbox::path::~path(){} - ::nana::string inputbox::path::value() const + ::std::string inputbox::path::value() const { if (!impl_->path_edit.empty()) return impl_->path_edit.caption(); @@ -1100,7 +1110,7 @@ namespace nana } //Implementation of abstract_content - const ::nana::string& inputbox::path::label() const + const ::std::string& inputbox::path::label() const { return impl_->label_text; } @@ -1148,7 +1158,7 @@ namespace nana //end class path - inputbox::inputbox(window owner, ::nana::string desc, ::nana::string title) + inputbox::inputbox(window owner, ::std::string desc, ::std::string title) : owner_{ owner }, description_(std::move(desc)), title_(std::move(title)) diff --git a/source/gui/place.cpp b/source/gui/place.cpp index c31daf36..6b59649c 100644 --- a/source/gui/place.cpp +++ b/source/gui/place.cpp @@ -539,12 +539,12 @@ namespace nana }); } - field_interface& operator<<(const nana::char_t* label_text) override + field_interface& operator<<(const char* label_text) override { - return static_cast(this)->operator<<(agent