From c86a00bea51a6a1772e522891eefaa244803b604 Mon Sep 17 00:00:00 2001 From: Jinhao Date: Sun, 29 Nov 2015 22:38:22 +0800 Subject: [PATCH] remove macro STR --- include/nana/deploy.hpp | 2 - include/nana/filesystem/file_iterator.hpp | 27 ++- include/nana/filesystem/filesystem.hpp | 93 +++++++--- include/nana/filesystem/fs_utility.hpp | 6 +- include/nana/fwd.hpp | 2 +- include/nana/gui/detail/general_events.hpp | 4 +- include/nana/gui/widgets/categorize.hpp | 6 +- include/nana/gui/widgets/detail/tree_cont.hpp | 38 ++-- include/nana/gui/widgets/listbox.hpp | 4 +- .../widgets/skeletons/text_token_stream.hpp | 40 ++-- include/nana/gui/widgets/tabbar.hpp | 2 - include/nana/gui/widgets/treebox.hpp | 67 ++++--- include/nana/paint/graphics.hpp | 4 +- source/detail/win32/platform_spec.cpp | 2 +- source/filesystem/file_iterator.cpp | 4 +- source/filesystem/filesystem.cpp | 172 +++++++++++------- source/filesystem/fs_utility.cpp | 37 ++-- source/gui/detail/native_window_interface.cpp | 6 +- source/gui/detail/win32/bedrock.cpp | 7 +- source/gui/widgets/categorize.cpp | 54 +++--- source/gui/widgets/checkbox.cpp | 2 +- source/gui/widgets/float_listbox.cpp | 4 +- source/gui/widgets/label.cpp | 4 +- source/gui/widgets/listbox.cpp | 8 +- source/gui/widgets/menu.cpp | 2 +- source/gui/widgets/skeletons/text_editor.cpp | 16 +- source/gui/widgets/treebox.cpp | 94 +++++----- source/paint/graphics.cpp | 20 +- source/paint/image.cpp | 6 +- source/paint/text_renderer.cpp | 4 +- source/system/platform.cpp | 4 +- 31 files changed, 410 insertions(+), 331 deletions(-) diff --git a/include/nana/deploy.hpp b/include/nana/deploy.hpp index 6488e2e6..44d579c5 100644 --- a/include/nana/deploy.hpp +++ b/include/nana/deploy.hpp @@ -89,14 +89,12 @@ namespace nana typedef char char_t; typedef std::string string; ///< An alias of std::wstring or std::string, depending on the macro NANA_UNICODE } - #define STR(string) string #else namespace nana { typedef wchar_t char_t; typedef std::wstring string; ///< An alias of std::wstring or std::string, depending on the macro NANA_UNICODE } - #define STR(string) L##string #endif namespace nana diff --git a/include/nana/filesystem/file_iterator.hpp b/include/nana/filesystem/file_iterator.hpp index b884638f..a7fa4da4 100644 --- a/include/nana/filesystem/file_iterator.hpp +++ b/include/nana/filesystem/file_iterator.hpp @@ -39,9 +39,9 @@ namespace filesystem #ifdef NANA_WINDOWS fileinfo(const WIN32_FIND_DATA& wfd); #elif NANA_LINUX or NANA_MACOS - fileinfo(const nana::string& filename, const struct stat &); + fileinfo(const ::std::string& filename, const struct stat &); #endif - nana::string name; + ::std::string name; unsigned long size; bool directory; @@ -56,7 +56,7 @@ namespace filesystem basic_file_iterator():end_(true), handle_(nullptr){} - basic_file_iterator(const nana::string& file_path) + basic_file_iterator(const std::string& file_path) :end_(false), handle_(nullptr) { _m_prepare(file_path); @@ -92,14 +92,13 @@ namespace filesystem return (*p == 0); } - void _m_prepare(const nana::string& file_path) + void _m_prepare(const std::string& file_path) { #if defined(NANA_WINDOWS) - path_ = file_path; - auto pat = file_path; + auto pat = utf8_cast(file_path); DWORD attr = ::GetFileAttributes(pat.data()); if((attr != INVALID_FILE_ATTRIBUTES) && (attr & FILE_ATTRIBUTE_DIRECTORY)) - pat += STR("\\*"); + pat += L"\\*"; ::HANDLE handle = ::FindFirstFile(pat.data(), &wfd_); @@ -120,10 +119,11 @@ namespace filesystem } value_ = value_type(wfd_); #elif defined(NANA_LINUX) || defined(NANA_MACOS) - path_ = nana::charset(file_path); - if(path_.size() && (path_[path_.size() - 1] != '/')) - path_ += '/'; - find_handle_t handle = opendir(path_.c_str()); + auto path = file_path; + if(path.size() && path.back() != '/') + path += '/'; + auto handle = opendir(path.c_str()); + end_ = true; if(handle) { @@ -141,7 +141,7 @@ namespace filesystem } struct stat fst; - if(stat((path_ + dnt->d_name).c_str(), &fst) == 0) + if(stat((path + dnt->d_name).c_str(), &fst) == 0) { value_ = value_type(nana::charset(dnt->d_name), fst); } @@ -226,9 +226,6 @@ namespace filesystem #if defined(NANA_WINDOWS) WIN32_FIND_DATA wfd_; - nana::string path_; -#elif defined(NANA_LINUX) || defined(NANA_MACOS) - std::string path_; #endif std::shared_ptr find_ptr_; diff --git a/include/nana/filesystem/filesystem.hpp b/include/nana/filesystem/filesystem.hpp index dda69c98..785b3c5c 100644 --- a/include/nana/filesystem/filesystem.hpp +++ b/include/nana/filesystem/filesystem.hpp @@ -136,29 +136,41 @@ namespace filesystem class path { public: +#if defined(NANA_WINDOWS) + using value_type = wchar_t; + const static value_type preferred_separator = '\\'; +#else + using value_type = char; + const static value_type preferred_separator = '/'; +#endif + using string_type = std::basic_string; + path(); - path(const nana::string&); + path(const value_type* source); + path(const string_type& source); + + int compare(const path& other) const; bool empty() const; - path root() const; + path parent_path() const; file_type what() const; - nana::string filename() const; -#if defined(NANA_WINDOWS) - public: - nana::string to_string() const { return text_; } - operator nana::string() const { return text_; } + path filename() const; + + const value_type*c_str() const; + const string_type& native() const; + operator string_type() const; private: - nana::string text_; -#else - public: - std::string to_string() const { return text_; } - operator std::string() const { return text_; } - private: - std::string text_; -#endif + string_type pathstr_; }; + bool operator==(const path& lhs, const path& rhs); + bool operator!=(const path& lhs, const path& rhs); + bool operator<(const path& lhs, const path& rhs); + bool operator>(const path& lhs, const path& rhs); + + + struct directory_entry { using path_type = filesystem::path; @@ -193,9 +205,7 @@ namespace filesystem typedef std::input_iterator_tag iterator_category; directory_iterator():end_(true), handle_(nullptr){} - - directory_iterator(const nana::string& file_path) { _m_prepare(file_path); } - directory_iterator(const path& file_path) { _m_prepare(file_path.filename()); } + directory_iterator(const path& file_path) { _m_prepare(file_path); } const value_type& operator*() const { return value_; } @@ -233,14 +243,14 @@ namespace filesystem return (*p == 0); } - void _m_prepare(const nana::string& file_path) + void _m_prepare(const path& file_path) { + auto path_ = file_path.native(); #if defined(NANA_WINDOWS) - path_ = file_path; - auto pat = file_path; + auto pat = path_; DWORD attr = ::GetFileAttributes(pat.data()); if((attr != INVALID_FILE_ATTRIBUTES) && (attr & FILE_ATTRIBUTE_DIRECTORY)) - pat += STR("\\*"); + pat += L"\\*"; ::HANDLE handle = ::FindFirstFile(pat.data(), &wfd_); @@ -265,7 +275,6 @@ namespace filesystem wfd_.nFileSizeLow); #elif defined(NANA_LINUX) || defined(NANA_MACOS) - path_ = nana::charset(file_path); if(path_.size() && (path_[path_.size() - 1] != '/')) path_ += '/'; find_handle_t handle = opendir(path_.c_str()); @@ -373,10 +382,9 @@ namespace filesystem #if defined(NANA_WINDOWS) WIN32_FIND_DATA wfd_; - nana::string path_; -#elif defined(NANA_LINUX) || defined(NANA_MACOS) - std::string path_; #endif + path::string_type path_; + std::shared_ptr find_ptr_; find_handle_t handle_{nullptr}; value_type value_; @@ -453,12 +461,39 @@ namespace filesystem //bool remove(const path& p); //bool remove(const path& p, error_code& ec) noexcept; - bool rmfile(const nana::char_t* file); + bool rmfile(const char* file); //uintmax_t remove_all(const path& p); //uintmax_t remove_all(const path& p, error_code& ec) noexcept; - bool rmdir(const nana::char_t* dir, bool fails_if_not_empty); - nana::string root(const nana::string& path); + bool rmdir(const char* dir, bool fails_if_not_empty); + bool rmdir(const wchar_t* dir, bool fails_if_not_empty); + + template + std::basic_string parent_path(const std::basic_string& path) + { + auto index = path.size(); + + if (index) + { + auto str = path.c_str(); + + for (--index; index > 0; --index) + { + auto c = str[index]; + if (c != '\\' && c != '/') + break; + } + + for (--index; index > 0; --index) + { + auto c = str[index]; + if (c == '\\' || c == '/') + break; + } + } + + return index ? path.substr(0, index + 1) : std::basic_string(); + } }//end namespace filesystem diff --git a/include/nana/filesystem/fs_utility.hpp b/include/nana/filesystem/fs_utility.hpp index 5212b02b..6870fce7 100644 --- a/include/nana/filesystem/fs_utility.hpp +++ b/include/nana/filesystem/fs_utility.hpp @@ -27,14 +27,14 @@ namespace filesystem bool file_attrib(const ::std::string& file, attribute&); long long filesize(const nana::string& file); - bool mkdir(const nana::string& dir, bool & if_exist); + bool mkdir(const ::std::string& dir, bool & if_exist); bool modified_file_time(const nana::string& file, struct tm&); nana::string path_user(); nana::string path_current(); - bool rmfile(const nana::char_t* file); - bool rmdir(const nana::char_t* dir, bool fails_if_not_empty); + bool rmfile(const char* file_utf8); + bool rmdir(const char* dir, bool fails_if_not_empty); nana::string root(const nana::string& path); class path diff --git a/include/nana/fwd.hpp b/include/nana/fwd.hpp index 62d824cb..c3795e3a 100644 --- a/include/nana/fwd.hpp +++ b/include/nana/fwd.hpp @@ -1,7 +1,7 @@ /* * Forward Declarations * Nana C++ Library(http://www.nanapro.org) - * Copyright(C) 2003-2014 Jinhao(cnjinhao@hotmail.com) + * Copyright(C) 2003-2015 Jinhao(cnjinhao@hotmail.com) * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at diff --git a/include/nana/gui/detail/general_events.hpp b/include/nana/gui/detail/general_events.hpp index a6f17bc6..8437f84d 100644 --- a/include/nana/gui/detail/general_events.hpp +++ b/include/nana/gui/detail/general_events.hpp @@ -460,7 +460,7 @@ namespace nana { ::nana::window window_handle; ///< A handle to the event window ::nana::point pos; ///< cursor position in the event window - std::vector files; ///< external filenames + std::vector files; ///< external filenames }; struct arg_expose : public event_arg @@ -480,7 +480,7 @@ namespace nana { event_code evt_code; ///< it is event_code::key_press in current event ::nana::window window_handle; ///< A handle to the event window - mutable nana::char_t key; ///< the key corresponding to the key pressed + mutable wchar_t key; ///< the key corresponding to the key pressed mutable bool ignore; ///< this member is not used bool ctrl; ///< keyboard Ctrl is pressed? bool shift; ///< keyboard Shift is pressed diff --git a/include/nana/gui/widgets/categorize.hpp b/include/nana/gui/widgets/categorize.hpp index a05b3bc2..6d685e8c 100644 --- a/include/nana/gui/widgets/categorize.hpp +++ b/include/nana/gui/widgets/categorize.hpp @@ -94,7 +94,7 @@ namespace nana virtual ~renderer() = 0; virtual void background(graph_reference, window wd, const nana::rectangle&, const ui_element&) = 0; virtual void root_arrow(graph_reference, const nana::rectangle&, mouse_action) = 0; - virtual void item(graph_reference, const nana::rectangle&, std::size_t index, const nana::string& name, unsigned textheight, bool has_child, mouse_action) = 0; + virtual void item(graph_reference, const nana::rectangle&, std::size_t index, const ::std::string& name, unsigned textheight, bool has_child, mouse_action) = 0; virtual void border(graph_reference) = 0; }; @@ -115,8 +115,8 @@ namespace nana //splitstr //@brief: Sets the splitstr. If the parameter will be ingored if it is an empty string. - void splitstr(const nana::string&); - const nana::string& splitstr() const; + void splitstr(const ::std::string&); + const ::std::string& splitstr() const; void path(const ::std::string&); ::std::string path() const; diff --git a/include/nana/gui/widgets/detail/tree_cont.hpp b/include/nana/gui/widgets/detail/tree_cont.hpp index 0c5e5423..23a8a027 100644 --- a/include/nana/gui/widgets/detail/tree_cont.hpp +++ b/include/nana/gui/widgets/detail/tree_cont.hpp @@ -22,7 +22,7 @@ namespace detail template struct tree_node { - typedef std::pair value_type; + typedef std::pair value_type; value_type value; @@ -108,7 +108,7 @@ namespace detail return (verify(node) && (node->owner != &root_) ? node->owner : nullptr); } - node_type * node(node_type* node, const nana::string& key) + node_type * node(node_type* node, const std::string& key) { if(node) { @@ -121,7 +121,7 @@ namespace detail return nullptr; } - node_type* insert(node_type* node, const nana::string& key, const element_type& elem) + node_type* insert(node_type* node, const std::string& key, const element_type& elem) { if(nullptr == node) return insert(key, elem); @@ -159,7 +159,7 @@ namespace detail return nullptr; } - node_type* insert(const nana::string& key, const element_type& elem) + node_type* insert(const std::string& key, const element_type& elem) { auto node = _m_locate(key); if(node) @@ -173,12 +173,12 @@ namespace detail delete node; } - node_type* find(const nana::string& path) const + node_type* find(const std::string& path) const { return _m_locate(path); } - node_type* ref(const nana::string& path) + node_type* ref(const std::string& path) { return _m_locate(path); } @@ -303,7 +303,7 @@ namespace detail } template - unsigned child_size_if(const nana::string& key, PredAllowChild pac) const + unsigned child_size_if(const ::std::string& key, PredAllowChild pac) const { auto node = _m_locate(key); return (node ? child_size_if(*node, pac) : 0); @@ -392,7 +392,7 @@ namespace detail :node(&(self.root_)) {} - bool operator()(const nana::string& key_node) + bool operator()(const ::std::string& key_node) { node_type *child = node->child; node_type *tail = nullptr; @@ -428,7 +428,7 @@ namespace detail :node(&self.root_) {} - bool operator()(const nana::string& key_node) + bool operator()(const ::std::string& key_node) { return ((node = _m_find(node->child, key_node)) != nullptr); } @@ -436,7 +436,7 @@ namespace detail node_type *node; }; private: - static node_type* _m_find(node_type* node, const nana::string& key_node) + static node_type* _m_find(node_type* node, const ::std::string& key_node) { while(node) { @@ -449,14 +449,14 @@ namespace detail } template - void _m_for_each(const nana::string& key, Function function) const + void _m_for_each(const ::std::string& key, Function function) const { if(key.size()) { - nana::string::size_type beg = 0; - auto end = key.find_first_of(STR("\\/")); + ::std::string::size_type beg = 0; + auto end = key.find_first_of("\\/"); - while(end != nana::string::npos) + while(end != ::std::string::npos) { if(beg != end) { @@ -464,11 +464,11 @@ namespace detail return; } - auto next = key.find_first_not_of(STR("\\/"), end); - if(next != nana::string::npos) + auto next = key.find_first_not_of("\\/", end); + if(next != ::std::string::npos) { beg = next; - end = key.find_first_of(STR("\\/"), beg); + end = key.find_first_of("\\/", beg); } else return; @@ -479,7 +479,7 @@ namespace detail } template - node_type* _m_locate(const nana::string& key) + node_type* _m_locate(const ::std::string& key) { if(key.size()) { @@ -499,7 +499,7 @@ namespace detail return &root_; } - node_type* _m_locate(const nana::string& key) const + node_type* _m_locate(const std::string& key) const { if(key.size()) { diff --git a/include/nana/gui/widgets/listbox.hpp b/include/nana/gui/widgets/listbox.hpp index 59324ef2..30f19503 100644 --- a/include/nana/gui/widgets/listbox.hpp +++ b/include/nana/gui/widgets/listbox.hpp @@ -449,8 +449,8 @@ namespace nana struct export_options { - nana::string sep = nana::string {STR("\t" )}, - endl= nana::string {STR("\n")}; + nana::string sep = nana::string {L"\t"}, + endl= nana::string {L"\n"}; bool only_selected_items{true}, only_checked_items {false}, only_visible_columns{true}; diff --git a/include/nana/gui/widgets/skeletons/text_token_stream.hpp b/include/nana/gui/widgets/skeletons/text_token_stream.hpp index eef80358..3cd91195 100644 --- a/include/nana/gui/widgets/skeletons/text_token_stream.hpp +++ b/include/nana/gui/widgets/skeletons/text_token_stream.hpp @@ -281,45 +281,45 @@ namespace nana{ namespace widgets{ namespace skeletons //Here is a identifier _m_read_idstr(); - if(STR("font") == idstr_) + if(L"font" == idstr_) return token::font; - else if(STR("bold") == idstr_) + else if(L"bold" == idstr_) return token::bold; - else if(STR("size") == idstr_) + else if(L"size" == idstr_) return token::size; - else if(STR("baseline") == idstr_) + else if(L"baseline" == idstr_) return token::baseline; - else if(STR("top") == idstr_) + else if(L"top" == idstr_) return token::top; - else if(STR("center") == idstr_) + else if(L"center" == idstr_) return token::center; - else if(STR("bottom") == idstr_) + else if(L"bottom" == idstr_) return token::bottom; - else if(STR("color") == idstr_) + else if(L"color" == idstr_) return token::color; - else if(STR("image") == idstr_) + else if(L"image" == idstr_) return token::image; - else if(STR("true") == idstr_) + else if(L"true" == idstr_) return token::_true; - else if(STR("url") == idstr_) + else if(L"url" == idstr_) return token::url; - else if(STR("target") == idstr_) + else if(L"target" == idstr_) return token::target; - else if(STR("false") == idstr_) + else if(L"false" == idstr_) return token::_false; - else if(STR("red") == idstr_) + else if(L"red" == idstr_) return token::red; - else if(STR("green") == idstr_) + else if(L"green" == idstr_) return token::green; - else if(STR("blue") == idstr_) + else if(L"blue" == idstr_) return token::blue; - else if(STR("white") == idstr_) + else if(L"white" == idstr_) return token::white; - else if(STR("black") == idstr_) + else if(L"black" == idstr_) return token::black; - else if(STR("min_limited") == idstr_) + else if(L"min_limited" == idstr_) return token::min_limited; - else if(STR("max_limited") == idstr_) + else if(L"max_limited" == idstr_) return token::max_limited; return token::string; diff --git a/include/nana/gui/widgets/tabbar.hpp b/include/nana/gui/widgets/tabbar.hpp index 2ed73ab4..a491cdf2 100644 --- a/include/nana/gui/widgets/tabbar.hpp +++ b/include/nana/gui/widgets/tabbar.hpp @@ -140,8 +140,6 @@ namespace nana : public drawer_trigger { public: - //enum toolbox_button_t{ButtonAdd, ButtonScroll, ButtonList, ButtonClose}; //deprecated - enum class kits { add, diff --git a/include/nana/gui/widgets/treebox.hpp b/include/nana/gui/widgets/treebox.hpp index db445daf..5fd7a27a 100644 --- a/include/nana/gui/widgets/treebox.hpp +++ b/include/nana/gui/widgets/treebox.hpp @@ -55,7 +55,7 @@ namespace nana nana::paint::image icon_normal; nana::paint::image icon_hover; nana::paint::image icon_expanded; - nana::string text; + ::std::string text; }; typedef widgets::detail::compset compset_interface; @@ -98,14 +98,14 @@ namespace nana struct treebox_node_type { treebox_node_type(); - treebox_node_type(nana::string); + treebox_node_type(std::string); treebox_node_type& operator=(const treebox_node_type&); - nana::string text; + ::std::string text; nana::any value; bool expanded; checkstate checked; - nana::string img_idstr; + ::std::string img_idstr; }; struct pseudo_node_type{}; @@ -133,8 +133,8 @@ namespace nana const ::nana::pat::cloneable& placer() const; nana::any & value(node_type*) const; - node_type* insert(node_type*, const nana::string& key, nana::string&&); - node_type* insert(const nana::string& path, nana::string&&); + node_type* insert(node_type*, const std::string& key, std::string&&); + node_type* insert(const std::string& path, std::string&&); bool verify(const void*) const; bool verify_kinship(node_type* parent, node_type* child) const; @@ -143,16 +143,15 @@ namespace nana node_type * selected() const; void selected(node_type*); void set_expand(node_type*, bool); - void set_expand(const nana::string& path, bool); + void set_expand(const ::std::string& path, bool); - //void image(const nana::string& id, const node_image_tag&); - node_image_tag& icon(const nana::string&) const; - void icon_erase(const nana::string&); - void node_icon(node_type*, const nana::string& id); + node_image_tag& icon(const ::std::string&) const; + void icon_erase(const ::std::string&); + void node_icon(node_type*, const ::std::string& id); unsigned node_width(const node_type*) const; - bool rename(node_type*, const nana::char_t* key, const nana::char_t* name); + bool rename(node_type*, const char* key, const char* name); private: //Overrides drawer_trigger methods void attached(widget_reference, graph_reference) override; @@ -182,11 +181,11 @@ namespace nana item_proxy(trigger*, trigger::node_type*); /// Append a child. - item_proxy append(const nana::string& key, nana::string name); + item_proxy append(const ::std::string& key, ::std::string name); /// Append a child with a specified value (user object.). template - item_proxy append(const nana::string& key, nana::string name, const T&t) + item_proxy append(const ::std::string& key, ::std::string name, const T&t) { item_proxy ip = append(key, std::move(name)); if(false == ip.empty()) @@ -220,22 +219,22 @@ namespace nana item_proxy& select(bool); /// Return the icon. - const nana::string& icon() const; + const ::std::string& icon() const; /// Set the icon, and returns itself.. - item_proxy& icon(const nana::string& id); + item_proxy& icon(const ::std::string& id); /// Return the text. - const nana::string& text() const; - - /// Set a new key, and returns itself.. - item_proxy& key(const nana::string& s); - - /// Return the key. - const nana::string& key() const; + const ::std::string& text() const; /// Set the text, and returns itself. - item_proxy& text(const nana::string&); + item_proxy& text(const ::std::string&); + + /// Set a new key, and returns itself.. + item_proxy& key(const ::std::string& s); + + /// Return the key. + const ::std::string& key() const; std::size_t size() const; ///< Returns the number of child nodes. @@ -257,7 +256,7 @@ namespace nana /// Makes an action for each sub item recursively, returns the item that stops the action where action returns false. item_proxy visit_recursively(std::function action); - bool operator==(const nana::string& s) const; ///< Compare the text of node with s. + bool operator==(const ::std::string& s) const; ///< Compare the text of node with s. bool operator==(const char* s ) const; ///< Compare the text of node with s. bool operator==(const wchar_t* s ) const; ///< Compare the text of node with s. @@ -428,28 +427,28 @@ namespace nana /// These states are 'normal', 'hovered' and 'expanded'. /// If 'hovered' or 'expanded' are not set, it uses 'normal' state image for these 2 states. /// See also in [documentation](http://nanapro.org/en-us/help/widgets/treebox.htm) - node_image_type& icon(const nana::string& id ///< the name of an icon scheme. If the name is not existing, it creates a new scheme for the name. + node_image_type& icon(const ::std::string& id ///< the name of an icon scheme. If the name is not existing, it creates a new scheme for the name. ) const; - void icon_erase(const nana::string& id); + void icon_erase(const ::std::string& id); - item_proxy find(const nana::string& keypath); ///< Find an item though a specified keypath. + item_proxy find(const ::std::string& keypath); ///< Find an item though a specified keypath. /// Inserts a new node to treebox, but if the keypath exists returns the existing node. - item_proxy insert(const nana::string& path_key, ///< specifies the node hierarchy - nana::string title ///< used for displaying + item_proxy insert(const ::std::string& path_key, ///< specifies the node hierarchy + ::std::string title ///< used for displaying ); /// Inserts a new node to treebox, but if the keypath exists returns the existing node. item_proxy insert( item_proxy pos, ///< the parent item node - const nana::string& key, ///< specifies the new node - nana::string title ///< title used for displaying in the new node. + const ::std::string& key, ///< specifies the new node + ::std::string title ///< title used for displaying in the new node. ); item_proxy erase(item_proxy i); ///< Removes the node at pos and return the Item proxy following the removed node - void erase(const nana::string& keypath); ///< Removes the node by the key path. + void erase(const ::std::string& keypath); ///< Removes the node by the key path. - nana::string make_key_path(item_proxy i, const nana::string& splitter) const;///(const path& lhs, const path& rhs) + { + return (rhs.compare(lhs) < 0); + } + namespace detail { //rm_dir_recursive //@brief: remove a directory, if it is not empty, recursively remove it's subfiles and sub directories - bool rm_dir_recursive(nana::string&& dir) + template + bool rm_dir_recursive(const CharT* dir) { std::vector files; - nana::string path = dir; + std::basic_string path = dir; path += '\\'; std::copy(directory_iterator(dir), directory_iterator(), std::back_inserter(files)); for (auto & f : files) { + auto subpath = path + f.path().filename().native(); if (f.attr.directory) - rm_dir_recursive(path + f.path().filename()); + rm_dir_recursive(subpath.c_str()); else - rmfile((path + f.path().filename()).c_str()); + rmfile(subpath.c_str()); } - return rmdir(dir.c_str(), true); + return rmdir(dir, true); } bool mkdir_helper(const nana::string& dir, bool & if_exist) @@ -299,7 +345,7 @@ namespace nana { nana::string root; #if defined(NANA_WINDOWS) - if (path.size() > 3 && path[1] == STR(':')) + if (path.size() > 3 && path[1] == L':') root = path.substr(0, 3); #elif defined(NANA_LINUX) || defined(NANA_MACOS) if (path[0] == STR('/')) @@ -310,11 +356,11 @@ namespace nana { while (true) { - beg = path.find_first_not_of(STR("/\\"), beg); + beg = path.find_first_not_of(L"/\\", beg); if (beg == path.npos) break; - std::size_t pos = path.find_first_of(STR("/\\"), beg + 1); + std::size_t pos = path.find_first_of(L"/\\", beg + 1); if (pos != path.npos) { root += path.substr(beg, pos - beg); @@ -324,9 +370,9 @@ namespace nana { return false; #if defined(NANA_WINDOWS) - root += STR('\\'); + root += L'\\'; #elif defined(NANA_LINUX) || defined(NANA_MACOS) - root += STR('/'); + root += L'/'; #endif } else @@ -362,18 +408,18 @@ namespace nana { #endif } - bool rmdir(const nana::char_t* dir, bool fails_if_not_empty) + bool rmdir(const char* dir_utf8, bool fails_if_not_empty) { bool ret = false; - if (dir) + if (dir_utf8) { #if defined(NANA_WINDOWS) - ret = (::RemoveDirectory(dir) == TRUE); + auto dir = utf8_cast(dir_utf8); + ret = (::RemoveDirectory(dir.c_str()) == TRUE); if (!fails_if_not_empty && (::GetLastError() == ERROR_DIR_NOT_EMPTY)) - ret = detail::rm_dir_recursive(dir); + ret = detail::rm_dir_recursive(dir.c_str()); #elif defined(NANA_LINUX) || defined(NANA_MACOS) - std::string mbstr = nana::charset(dir); - if (::rmdir(mbstr.c_str())) + if (::rmdir(dir_utf8)) { if (!fails_if_not_empty && (errno == EEXIST || errno == ENOTEMPTY)) ret = detail::rm_dir_recursive(dir); @@ -385,30 +431,26 @@ namespace nana { return ret; } - nana::string root(const nana::string& path) + bool rmdir(const wchar_t* dir, bool fails_if_not_empty) { - std::size_t index = path.size(); - - if (index) + bool ret = false; + if (dir) { - const nana::char_t * str = path.c_str(); - - for (--index; index > 0; --index) +#if defined(NANA_WINDOWS) + ret = (::RemoveDirectory(dir) == TRUE); + if (!fails_if_not_empty && (::GetLastError() == ERROR_DIR_NOT_EMPTY)) + ret = detail::rm_dir_recursive(dir); +#elif defined(NANA_LINUX) || defined(NANA_MACOS) + if (::rmdir(utf8_cast(dir).c_str())) { - nana::char_t c = str[index]; - if (c != '\\' && c != '/') - break; - } - - for (--index; index > 0; --index) - { - nana::char_t c = str[index]; - if (c == '\\' || c == '/') - break; + if (!fails_if_not_empty && (errno == EEXIST || errno == ENOTEMPTY)) + ret = detail::rm_dir_recursive(dir); } + else + ret = true; +#endif } - - return index ? path.substr(0, index + 1) : nana::string(); + return ret; } nana::string path_user() diff --git a/source/filesystem/fs_utility.cpp b/source/filesystem/fs_utility.cpp index 5fb75646..19b5f408 100644 --- a/source/filesystem/fs_utility.cpp +++ b/source/filesystem/fs_utility.cpp @@ -13,6 +13,7 @@ #include #include +#include #include #if defined(NANA_WINDOWS) #include @@ -47,7 +48,7 @@ namespace filesystem const char* splstr = "/\\"; #else typedef nana::string string_t; - const nana::char_t* splstr = STR("/\\"); + const nana::char_t* splstr = L"/\\"; #endif //class path path::path(){} @@ -125,10 +126,10 @@ namespace filesystem { //rm_dir_recursive //@brief: remove a directory, if it is not empty, recursively remove it's subfiles and sub directories - bool rm_dir_recursive(nana::string&& dir) + bool rm_dir_recursive(std::string&& dir) { std::vector files; - nana::string path = dir; + auto path = dir; path += '\\'; std::copy(file_iterator(dir), file_iterator(), std::back_inserter(files)); @@ -144,10 +145,10 @@ namespace filesystem return rmdir(dir.c_str(), true); } - bool mkdir_helper(const nana::string& dir, bool & if_exist) + bool mkdir_helper(const std::string& dir, bool & if_exist) { #if defined(NANA_WINDOWS) - if(::CreateDirectory(dir.c_str(), 0)) + if(::CreateDirectory(utf8_cast(dir).c_str(), 0)) { if_exist = false; return true; @@ -155,7 +156,7 @@ namespace filesystem if_exist = (::GetLastError() == ERROR_ALREADY_EXISTS); #elif defined(NANA_LINUX) || defined(NANA_MACOS) - if(0 == ::mkdir(static_cast(nana::charset(dir)).c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH)) + if(0 == ::mkdir(dir.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH)) { if_exist = false; return true; @@ -288,14 +289,14 @@ namespace filesystem return false; } - bool mkdir(const nana::string& path, bool & if_exist) + bool mkdir(const std::string& path, bool & if_exist) { if_exist = false; if(path.size() == 0) return false; - nana::string root; + std::string root; #if defined(NANA_WINDOWS) - if(path.size() > 3 && path[1] == STR(':')) + if(path.size() > 3 && path[1] == ':') root = path.substr(0, 3); #elif defined(NANA_LINUX) || defined(NANA_MACOS) if(path[0] == STR('/')) @@ -306,11 +307,11 @@ namespace filesystem while(true) { - beg = path.find_first_not_of(STR("/\\"), beg); + beg = path.find_first_not_of("/\\", beg); if(beg == path.npos) break; - std::size_t pos = path.find_first_of(STR("/\\"), beg + 1); + std::size_t pos = path.find_first_of("/\\", beg + 1); if(pos != path.npos) { root += path.substr(beg, pos - beg); @@ -320,9 +321,9 @@ namespace filesystem return false; #if defined(NANA_WINDOWS) - root += STR('\\'); + root += L'\\'; #elif defined(NANA_LINUX) || defined(NANA_MACOS) - root += STR('/'); + root += L'/'; #endif } else @@ -339,32 +340,32 @@ namespace filesystem return mkstat; } - bool rmfile(const nana::char_t* file) + bool rmfile(const char* file) { #if defined(NANA_WINDOWS) bool ret = false; if(file) { - ret = (::DeleteFile(file) == TRUE); + ret = (::DeleteFile(utf8_cast(file).c_str()) == TRUE); if(!ret) ret = (ERROR_FILE_NOT_FOUND == ::GetLastError()); } return ret; #elif defined(NANA_LINUX) || defined(NANA_MACOS) - if(std::remove(static_cast(nana::charset(file)).c_str())) + if(std::remove(file)) return (errno == ENOENT); return true; #endif } - bool rmdir(const nana::char_t* dir, bool fails_if_not_empty) + bool rmdir(const char* dir, bool fails_if_not_empty) { bool ret = false; if(dir) { #if defined(NANA_WINDOWS) - ret = (::RemoveDirectory(dir) == TRUE); + ret = (::RemoveDirectory(utf8_cast(dir).c_str()) == TRUE); if(!fails_if_not_empty && (::GetLastError() == ERROR_DIR_NOT_EMPTY)) ret = detail::rm_dir_recursive(dir); #elif defined(NANA_LINUX) || defined(NANA_MACOS) diff --git a/source/gui/detail/native_window_interface.cpp b/source/gui/detail/native_window_interface.cpp index b15001b9..e97b318b 100644 --- a/source/gui/detail/native_window_interface.cpp +++ b/source/gui/detail/native_window_interface.cpp @@ -202,7 +202,7 @@ namespace nana{ if(owner && (nested == false)) ::ClientToScreen(reinterpret_cast(owner), &pt); - HWND native_wd = ::CreateWindowEx(style_ex, STR("NanaWindowInternal"), STR("Nana Window"), + HWND native_wd = ::CreateWindowEx(style_ex, L"NanaWindowInternal", L"Nana Window", style, pt.x, pt.y, 100, 100, reinterpret_cast(owner), 0, ::GetModuleHandle(0), 0); @@ -377,8 +377,8 @@ namespace nana{ if(nullptr == parent) return nullptr; #if defined(NANA_WINDOWS) HWND handle = ::CreateWindowEx(WS_EX_CONTROLPARENT, // Extended possibilites for variation - STR("NanaWindowInternal"), - STR("Nana Child Window"), // Title Text + L"NanaWindowInternal", + L"Nana Child Window", // Title Text WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_CLIPSIBLINGS, r.x, r.y, r.width, r.height, reinterpret_cast(parent), // The window is a child-window to desktop diff --git a/source/gui/detail/win32/bedrock.cpp b/source/gui/detail/win32/bedrock.cpp index fff32177..ba42cdf8 100644 --- a/source/gui/detail/win32/bedrock.cpp +++ b/source/gui/detail/win32/bedrock.cpp @@ -214,7 +214,7 @@ namespace detail WNDCLASSEX wincl; wincl.hInstance = ::GetModuleHandle(0); - wincl.lpszClassName = STR("NanaWindowInternal"); + wincl.lpszClassName = L"NanaWindowInternal"; wincl.lpfnWndProc = &Bedrock_WIN32_WindowProc; wincl.style = CS_DBLCLKS | CS_OWNDC; wincl.cbSize = sizeof(wincl); @@ -1175,7 +1175,7 @@ namespace detail { arg_dropfiles dropfiles; - std::unique_ptr varbuf; + std::unique_ptr varbuf; std::size_t bufsize = 0; unsigned size = ::DragQueryFile(drop, 0xFFFFFFFF, 0, 0); @@ -1189,7 +1189,8 @@ namespace detail } ::DragQueryFile(drop, i, varbuf.get(), reqlen); - dropfiles.files.emplace_back(varbuf.get()); + + dropfiles.files.emplace_back(utf8_cast(varbuf.get())); } while(msgwnd && (msgwnd->flags.dropable == false)) diff --git a/source/gui/widgets/categorize.cpp b/source/gui/widgets/categorize.cpp index 4a6632a8..135087a9 100644 --- a/source/gui/widgets/categorize.cpp +++ b/source/gui/widgets/categorize.cpp @@ -105,7 +105,7 @@ namespace nana arrow.draw(graph, {}, style_.fgcolor, arrow_r, element_state::normal); } - void item(graph_reference graph, const nana::rectangle& r, std::size_t index, const nana::string& name, unsigned txtheight, bool has_child, mouse_action state) + void item(graph_reference graph, const nana::rectangle& r, std::size_t index, const std::string& name_utf8, unsigned txtheight, bool has_child, mouse_action state) { nana::point strpos(r.x + 5, r.y + static_cast(r.height - txtheight) / 2); @@ -141,7 +141,7 @@ namespace nana _m_item_bground(graph, r.x + 1, top, width, height, state_name); graph.rectangle(r, false, clr); } - graph.string(strpos, name, style_.fgcolor); + graph.string(strpos, name_utf8, style_.fgcolor); if(has_child) { @@ -218,7 +218,7 @@ namespace nana using node_handle = container::node_type*; tree_wrapper() - :splitstr_(STR("\\")), cur_(nullptr) + : splitstr_("\\") {} bool seq(std::size_t index, std::vector & seqv) const @@ -234,23 +234,23 @@ namespace nana return false; } - void splitstr(const nana::string& ss) + void splitstr(const std::string& ss) { if(ss.size()) splitstr_ = ss; } - const nana::string& splitstr() const + const std::string& splitstr() const { return splitstr_; } - nana::string path() const + std::string path() const { std::vector v; _m_read_node_path(v); - nana::string str; + std::string str; bool not_head = false; for(auto i : v) { @@ -263,7 +263,7 @@ namespace nana return str; } - void path(const nana::string& key) + void path(const std::string& key) { cur_ = tree_.ref(key); } @@ -292,7 +292,7 @@ namespace nana cur_ = i; } - void insert(const nana::string& name, const nana::any& value) + void insert(const std::string& name, const nana::any& value) { item_tag m; m.pixels = 0; @@ -300,7 +300,7 @@ namespace nana cur_ = tree_.insert(cur_, name, m); } - bool childset(const nana::string& name, const nana::any& value) + bool childset(const std::string& name, const nana::any& value) { if(cur_) { @@ -313,7 +313,7 @@ namespace nana return false; } - bool childset_erase(const nana::string& name) + bool childset_erase(const std::string& name) { if(cur_) { @@ -329,7 +329,7 @@ namespace nana return false; } - node_handle find_child(const nana::string& name) const + node_handle find_child(const std::string& name) const { if(cur_) { @@ -360,8 +360,8 @@ namespace nana } private: container tree_; - nana::string splitstr_; - node_handle cur_; + std::string splitstr_ ; + node_handle cur_{ nullptr }; }; //class scheme @@ -543,7 +543,7 @@ namespace nana { if(node) { - API::dev::window_caption(window_handle(), utf8_cast(tree().path())); + API::dev::window_caption(window_handle(), tree().path()); if(evt_holder_.selected) evt_holder_.selected(node->value.second.value); } @@ -565,7 +565,7 @@ namespace nana if(i) { for(node_handle child = i->child; child; child = child->next) - style_.module.items.emplace_back(std::make_shared(utf8_cast(child->value.first))); + style_.module.items.emplace_back(std::make_shared(child->value.first)); } r = style_.active_item_rectangle; } @@ -576,7 +576,7 @@ namespace nana { auto end = v.cbegin() + head_; for(auto i = v.cbegin(); i != end; ++i) - style_.module.items.emplace_back(std::make_shared(utf8_cast((*i)->value.first))); + style_.module.items.emplace_back(std::make_shared((*i)->value.first)); } r = style_.active_item_rectangle; } @@ -603,8 +603,7 @@ namespace nana case ui_element::item_arrow: { treebase_.tail(style_.active); - nana::string name = utf8_cast(style_.module.items[style_.module.index]->text()); - node_handle node = treebase_.find_child(name); + node_handle node = treebase_.find_child(style_.module.items[style_.module.index]->text()); if(node) { treebase_.cur(node); @@ -769,7 +768,6 @@ namespace nana private: window window_{nullptr}; nana::paint::graphics * graph_{nullptr}; - nana::string splitstr_; std::size_t head_; unsigned item_height_; std::size_t item_lines_; @@ -808,14 +806,14 @@ namespace nana void trigger::insert(const std::string& str, nana::any value) { throw_not_utf8(str); - scheme_->tree().insert(utf8_cast(str), value); - API::dev::window_caption(scheme_->window_handle(), utf8_cast(scheme_->tree().path())); + scheme_->tree().insert(str, value); + API::dev::window_caption(scheme_->window_handle(), scheme_->tree().path()); scheme_->draw(); } bool trigger::childset(const std::string& str, nana::any value) { - if(scheme_->tree().childset(utf8_cast(str), value)) + if(scheme_->tree().childset(str, value)) { scheme_->draw(); return true; @@ -825,7 +823,7 @@ namespace nana bool trigger::childset_erase(const std::string& str) { - if(scheme_->tree().childset_erase(utf8_cast(str))) + if(scheme_->tree().childset_erase(str)) { scheme_->draw(); return true; @@ -843,24 +841,24 @@ namespace nana return false; } - void trigger::splitstr(const nana::string& sstr) + void trigger::splitstr(const std::string& sstr) { scheme_->tree().splitstr(sstr); } - const nana::string& trigger::splitstr() const + const std::string& trigger::splitstr() const { return scheme_->tree().splitstr(); } void trigger::path(const std::string& str) { - scheme_->tree().path(utf8_cast(str)); + scheme_->tree().path(str); } std::string trigger::path() const { - return utf8_cast(scheme_->tree().path()); + return scheme_->tree().path(); } nana::any& trigger::value() const diff --git a/source/gui/widgets/checkbox.cpp b/source/gui/widgets/checkbox.cpp index 4ab4af48..0323a50d 100644 --- a/source/gui/widgets/checkbox.cpp +++ b/source/gui/widgets/checkbox.cpp @@ -49,7 +49,7 @@ namespace checkbox { _m_draw_background(graph); _m_draw_title(graph); - _m_draw_checkbox(graph, graph.text_extent_size(STR("jN"), 2).height + 2); + _m_draw_checkbox(graph, graph.text_extent_size(L"jN", 2).height + 2); } void drawer::mouse_down(graph_reference graph, const arg_mouse&) diff --git a/source/gui/widgets/float_listbox.cpp b/source/gui/widgets/float_listbox.cpp index 1af70c6c..1fde5065 100644 --- a/source/gui/widgets/float_listbox.cpp +++ b/source/gui/widgets/float_listbox.cpp @@ -109,7 +109,7 @@ namespace nana unsigned item_pixels(graph_reference graph) const { - return graph.text_extent_size(STR("jHWn/?\\{[(0569")).height + 4; + return graph.text_extent_size(L"jHWn/?\\{[(0569").height + 4; } };//end class item_renderer @@ -325,7 +325,7 @@ namespace nana _m_open_scrollbar(*widget_, pages); } else - graph_->string({ 4, 4 }, STR("Empty Listbox, No Module!"), static_cast(0x808080)); + graph_->string({ 4, 4 }, L"Empty Listbox, No Module!", static_cast(0x808080)); //Draw border graph_->rectangle(false, colors::black); diff --git a/source/gui/widgets/label.cpp b/source/gui/widgets/label.cpp index f7eb638a..b1d2191e 100644 --- a/source/gui/widgets/label.cpp +++ b/source/gui/widgets/label.cpp @@ -82,7 +82,7 @@ namespace nana nana::paint::font ft = graph.typeface(); //used for restoring the font - const unsigned def_line_pixels = graph.text_extent_size(STR(" "), 1).height; + const unsigned def_line_pixels = graph.text_extent_size(L" ", 1).height; font_ = ft; fblock_ = nullptr; @@ -169,7 +169,7 @@ namespace nana auto ft = graph.typeface(); //used for restoring the font - const unsigned def_line_pixels = graph.text_extent_size(STR(" "), 1).height; + const unsigned def_line_pixels = graph.text_extent_size(L" ", 1).height; font_ = ft; fblock_ = nullptr; diff --git a/source/gui/widgets/listbox.cpp b/source/gui/widgets/listbox.cpp index cb748b0d..d6b56c73 100644 --- a/source/gui/widgets/listbox.cpp +++ b/source/gui/widgets/listbox.cpp @@ -3146,7 +3146,7 @@ namespace nana graph->set_color(it_bgcolor); // litter rect with the item bg end ... graph->rectangle(rectangle{ xpos, y + 2, essence_->suspension_width, essence_->item_size - 4 }, true); - graph->string(point{ xpos, y + 2 }, STR("...")); + graph->string(point{ xpos, y + 2 }, L"..."); //Erase the part that over the next subitem. if (display_order + 1 < seqs.size()) // this is not the last column @@ -3284,9 +3284,9 @@ namespace nana void trigger::typeface_changed(graph_reference graph) { - essence_->text_height = graph.text_extent_size(STR("jHWn0123456789/text_height = graph.text_extent_size(L"jHWn0123456789/item_size = essence_->text_height + 6; - essence_->suspension_width = graph.text_extent_size(STR("...")).width; + essence_->suspension_width = graph.text_extent_size(L"...").width; } void trigger::refresh(graph_reference) @@ -3581,7 +3581,7 @@ namespace nana case keyboard::os_arrow_down: essence_->lister.move_select(up, !arg.shift, true); break; - case STR(' ') : + case L' ': { selection s; bool ck = ! essence_->lister.item_selected_all_checked(s); diff --git a/source/gui/widgets/menu.cpp b/source/gui/widgets/menu.cpp index 63ee91ec..065245b3 100644 --- a/source/gui/widgets/menu.cpp +++ b/source/gui/widgets/menu.cpp @@ -363,7 +363,7 @@ namespace nana unsigned strpixels = item_r.width - 60; - int text_top_off = (item_h_px - graph.text_extent_size(STR("jh({[")).height) / 2; + int text_top_off = (item_h_px - graph.text_extent_size(L"jh({[").height) / 2; std::size_t pos = 0; for (auto & m : menu_->items) diff --git a/source/gui/widgets/skeletons/text_editor.cpp b/source/gui/widgets/skeletons/text_editor.cpp index 6a0ab074..daeab694 100644 --- a/source/gui/widgets/skeletons/text_editor.cpp +++ b/source/gui/widgets/skeletons/text_editor.cpp @@ -442,7 +442,7 @@ namespace nana{ namespace widgets bool adjusted_cond = true; if (static_cast(text_w) < points.offset.x) { - auto delta_pixels = editor_._m_text_extent_size(STR(" "), 4).width; + auto delta_pixels = editor_._m_text_extent_size(L" ", 4).width; points.offset.x = (text_w > delta_pixels ? text_w - delta_pixels : 0); } else if (area_w && (text_w >= points.offset.x + area_w)) @@ -1614,7 +1614,7 @@ namespace nana{ namespace widgets unsigned text_editor::line_height() const { - return (graph_ ? (graph_.text_extent_size(STR("jH{")).height) : 0); + return (graph_ ? (graph_.text_extent_size(L"jH{").height) : 0); } unsigned text_editor::screen_lines() const @@ -1764,7 +1764,7 @@ namespace nana{ namespace widgets str = textbase_.getline(0); for(std::size_t i = 1; i < lines; ++i) { - str += STR("\n\r"); + str += L"\n\r"; str += textbase_.getline(i); } } @@ -2756,11 +2756,11 @@ namespace nana{ namespace widgets if(a.y != b.y) { text = textbase_.getline(a.y).substr(a.x); - text += STR("\r\n"); + text += L"\r\n"; for(unsigned i = a.y + 1; i < b.y; ++i) { text += textbase_.getline(i); - text += STR("\r\n"); + text += L"\r\n"; } text += textbase_.getline(b.y).substr(0, b.x); } @@ -2801,7 +2801,7 @@ namespace nana{ namespace widgets std::size_t begin = 0; while (true) { - auto pos = text.find_first_of(STR("\r\n"), begin); + auto pos = text.find_first_of(L"\r\n", begin); if (text.npos == pos) { if (!lines.empty()) @@ -2813,7 +2813,7 @@ namespace nana{ namespace widgets pos = eat_endl(text_str, pos); - begin = text.find_first_not_of(STR("\r\n"), pos); + begin = text.find_first_not_of(L"\r\n", pos); //The number of new lines minus one const auto chp_end = text_str + (begin == text.npos ? text.size() : begin); @@ -3068,7 +3068,7 @@ namespace nana{ namespace widgets keyword_parser parser; parser.parse(linestr, keywords_.get()); - auto whitespace_w = graph_.text_extent_size(STR(" "), 1).width; + auto whitespace_w = graph_.text_extent_size(L" ", 1).width; const auto line_h_pixels = line_height(); diff --git a/source/gui/widgets/treebox.cpp b/source/gui/widgets/treebox.cpp index 72138759..704d39c6 100644 --- a/source/gui/widgets/treebox.cpp +++ b/source/gui/widgets/treebox.cpp @@ -29,11 +29,11 @@ namespace nana { using node_type = trigger::node_type; - bool no_sensitive_compare(const nana::string& text, const nana::char_t *pattern, std::size_t len) + bool no_sensitive_compare(const std::string& text, const char *pattern, std::size_t len) { if(len <= text.length()) { - const nana::char_t * s = text.c_str(); + auto s = text.c_str(); for(std::size_t i = 0; i < len; ++i) { if('a' <= s[i] && s[i] <= 'z') @@ -49,7 +49,7 @@ namespace nana return false; } - const node_type* find_track_child_node(const node_type* node, const node_type * end, const nana::char_t* pattern, std::size_t len, bool &finish) + const node_type* find_track_child_node(const node_type* node, const node_type * end, const char* pattern, std::size_t len, bool &finish) { if(node->value.second.expanded) { @@ -217,7 +217,7 @@ namespace nana nana::scroll scroll; std::size_t prev_first_value; - mutable std::map image_table; + mutable std::map image_table; tree_cont_type::node_type * first; int indent_pixels; @@ -241,7 +241,7 @@ namespace nana struct track_node_tag { - nana::string key_buf; + ::std::string key_buf; std::size_t key_time; }track_node; @@ -320,9 +320,9 @@ namespace nana return false; } - const trigger::node_type* find_track_node(nana::char_t key) + const trigger::node_type* find_track_node(wchar_t key) { - nana::string pattern; + std::string pattern; if('a' <= key && key <= 'z') key -= 'a' - 'A'; @@ -334,8 +334,18 @@ namespace nana pattern = track_node.key_buf; track_node.key_time = now; - pattern += key; - track_node.key_buf += key; + + if (key <= 0x7f) + { + pattern += static_cast(key); + track_node.key_buf += static_cast(key); + } + else + { + wchar_t wstr[2] = { key, 0 }; + pattern += utf8_cast(wstr); + track_node.key_buf += utf8_cast(wstr); + } const node_type *begin = node_state.selected ? node_state.selected : attr.tree_cont.get_root()->child; @@ -604,7 +614,7 @@ namespace nana std::size_t visual_item_size() const { - return attr.tree_cont.child_size_if(nana::string{}, pred_allow_child{}); + return attr.tree_cont.child_size_if(std::string(), pred_allow_child{}); } int visible_w_pixels() const @@ -820,7 +830,7 @@ namespace nana } } - item_proxy item_proxy::append(const nana::string& key, nana::string name) + item_proxy item_proxy::append(const std::string& key, std::string name) { if(nullptr == trigger_ || nullptr == node_) return item_proxy(); @@ -892,34 +902,34 @@ namespace nana return *this; } - const nana::string& item_proxy::icon() const + const std::string& item_proxy::icon() const { return node_->value.second.img_idstr; } - item_proxy& item_proxy::icon(const nana::string& id) + item_proxy& item_proxy::icon(const std::string& id) { node_->value.second.img_idstr = id; return *this; } - item_proxy& item_proxy::key(const nana::string& kstr) + item_proxy& item_proxy::key(const std::string& kstr) { trigger_->rename(node_, kstr.data(), nullptr); return *this; } - const nana::string& item_proxy::key() const + const std::string& item_proxy::key() const { return node_->value.first; } - const nana::string& item_proxy::text() const + const std::string& item_proxy::text() const { return node_->value.second.text; } - item_proxy& item_proxy::text(const nana::string& id) + item_proxy& item_proxy::text(const std::string& id) { trigger_->rename(node_, nullptr, id.data()); return *this; @@ -973,27 +983,19 @@ namespace nana return end(); } - bool item_proxy::operator==(const nana::string& s) const + bool item_proxy::operator==(const std::string& s) const { return (node_ && (node_->value.second.text == s)); } bool item_proxy::operator==(const char* s) const { -#if defined(NANA_UNICODE) - return (node_ && (node_->value.second.text == nana::string(nana::charset(s)))); -#else - return (node_ && s && (node_->value.second.text == s)); -#endif + return (node_ && (node_->value.second.text == s)); } bool item_proxy::operator==(const wchar_t* s) const { -#if defined(NANA_UNICODE) - return (node_ && s && (node_->value.second.text == s)); -#else - return (node_ && (node_->value.second.text == nana::string(nana::charset(s)))); -#endif + return (node_ && s && (node_->value.second.text == utf8_cast(s))); } // Behavior of Iterator @@ -1114,7 +1116,7 @@ namespace nana virtual unsigned item_height(graph_reference graph) const override { - return graph.text_extent_size(STR("jH{"), 3).height + 8; + return graph.text_extent_size(L"jH{", 3).height + 8; } virtual unsigned item_width(graph_reference graph, const item_attribute_t& attr) const override @@ -1468,7 +1470,7 @@ namespace nana :expanded(false), checked(checkstate::unchecked) {} - trigger::treebox_node_type::treebox_node_type(nana::string text) + trigger::treebox_node_type::treebox_node_type(std::string text) :text(std::move(text)), expanded(false), checked(checkstate::unchecked) {} @@ -1702,7 +1704,7 @@ namespace nana return node->value.second.value; } - trigger::node_type* trigger::insert(node_type* node, const nana::string& key, nana::string&& title) + trigger::node_type* trigger::insert(node_type* node, const std::string& key, std::string&& title) { node_type * p = impl_->attr.tree_cont.node(node, key); if(p) @@ -1715,7 +1717,7 @@ namespace nana return p; } - trigger::node_type* trigger::insert(const nana::string& path, nana::string&& title) + trigger::node_type* trigger::insert(const std::string& path, std::string&& title) { auto x = impl_->attr.tree_cont.insert(path, treebox_node_type(std::move(title))); if(x && impl_->attr.auto_draw && impl_->draw(true)) @@ -1781,7 +1783,7 @@ namespace nana } } - void trigger::set_expand(const nana::string& path, bool exp) + void trigger::set_expand(const std::string& path, bool exp) { if(impl_->set_expanded(impl_->attr.tree_cont.find(path), exp)) { @@ -1790,7 +1792,7 @@ namespace nana } } - node_image_tag& trigger::icon(const nana::string& id) const + node_image_tag& trigger::icon(const std::string& id) const { auto i = impl_->shape.image_table.find(id); if(i != impl_->shape.image_table.end()) @@ -1801,14 +1803,14 @@ namespace nana return impl_->shape.image_table[id]; } - void trigger::icon_erase(const nana::string& id) + void trigger::icon_erase(const std::string& id) { impl_->shape.image_table.erase(id); if(0 == impl_->shape.image_table.size()) impl_->data.comp_placer->enable(component::icon, false); } - void trigger::node_icon(node_type* node, const nana::string& id) + void trigger::node_icon(node_type* node, const std::string& id) { if(tree().verify(node)) { @@ -1826,7 +1828,7 @@ namespace nana return impl_->data.comp_placer->item_width(*impl_->data.graph, node_attr); } - bool trigger::rename(node_type *node, const nana::char_t* key, const nana::char_t* name) + bool trigger::rename(node_type *node, const char* key, const char* name) { if((key || name ) && tree().verify(node)) { @@ -2194,28 +2196,28 @@ namespace nana return get_drawer_trigger().checkable(); } - treebox::node_image_type& treebox::icon(const nana::string& id) const + treebox::node_image_type& treebox::icon(const std::string& id) const { return get_drawer_trigger().icon(id); } - void treebox::icon_erase(const nana::string& id) + void treebox::icon_erase(const std::string& id) { get_drawer_trigger().icon_erase(id); } - auto treebox::find(const nana::string& keypath) -> item_proxy + auto treebox::find(const std::string& keypath) -> item_proxy { auto * trg = &get_drawer_trigger(); return item_proxy(trg, trg->tree().find(keypath)); } - treebox::item_proxy treebox::insert(const nana::string& path_key, nana::string title) + treebox::item_proxy treebox::insert(const std::string& path_key, std::string title) { return item_proxy(&get_drawer_trigger(), get_drawer_trigger().insert(path_key, std::move(title))); } - treebox::item_proxy treebox::insert(item_proxy i, const nana::string& key, nana::string title) + treebox::item_proxy treebox::insert(item_proxy i, const std::string& key, std::string title) { return item_proxy(&get_drawer_trigger(), get_drawer_trigger().insert(i._m_node(), key, std::move(title))); } @@ -2227,22 +2229,22 @@ namespace nana return next; } - void treebox::erase(const nana::string& keypath) + void treebox::erase(const std::string& keypath) { auto i = find(keypath); if(!i.empty()) get_drawer_trigger().remove(i._m_node()); } - nana::string treebox::make_key_path(item_proxy i, const nana::string& splitter) const + std::string treebox::make_key_path(item_proxy i, const std::string& splitter) const { auto & tree = get_drawer_trigger().tree(); auto pnode = i._m_node(); if(tree.verify(pnode)) { auto root = tree.get_root(); - nana::string path; - nana::string temp; + std::string path; + std::string temp; while(pnode->owner != root) { temp = splitter; diff --git a/source/paint/graphics.cpp b/source/paint/graphics.cpp index b87dfef0..ab4b1121 100644 --- a/source/paint/graphics.cpp +++ b/source/paint/graphics.cpp @@ -322,8 +322,8 @@ namespace paint handle_ = dw; size_ = sz; - handle_->string.tab_pixels = detail::raw_text_extent_size(handle_, STR("\t"), 1).width; - handle_->string.whitespace_pixels = detail::raw_text_extent_size(handle_, STR(" "), 1).width; + handle_->string.tab_pixels = detail::raw_text_extent_size(handle_, L"\t", 1).width; + handle_->string.whitespace_pixels = detail::raw_text_extent_size(handle_, L" ", 1).width; } } @@ -348,8 +348,8 @@ namespace paint #if defined(NANA_WINDOWS) ::SelectObject(handle_->context, reinterpret_cast(f.impl_->font_ptr->handle)); #endif - handle_->string.tab_pixels = detail::raw_text_extent_size(handle_, STR("\t"), 1).width; - handle_->string.whitespace_pixels = detail::raw_text_extent_size(handle_, STR(" "), 1).width; + handle_->string.tab_pixels = detail::raw_text_extent_size(handle_, L"\t", 1).width; + handle_->string.whitespace_pixels = detail::raw_text_extent_size(handle_, L" ", 1).width; if(changed_ == false) changed_ = true; } } @@ -953,10 +953,16 @@ namespace paint } } - void graphics::string(const point& pos, const std::string& text) + void graphics::string(const point& pos, const std::string& text_utf8) { - throw_not_utf8(text); - string(pos, static_cast(::nana::charset(text, ::nana::unicode::utf8))); + throw_not_utf8(text_utf8); + string(pos, utf8_cast(text_utf8)); + } + + void graphics::string(const point& pos, const std::string& text_utf8, const color& clr) + { + set_text_color(clr); + string(pos, text_utf8); } void graphics::string(nana::point pos, const char_t* str, std::size_t len) diff --git a/source/paint/image.cpp b/source/paint/image.cpp index 8d75a555..6dbf465b 100644 --- a/source/paint/image.cpp +++ b/source/paint/image.cpp @@ -218,7 +218,7 @@ namespace paint do { - if (STR("ICO") == type_str) + if (L"ICO" == type_str) { #if defined(NANA_WINDOWS) helper = new detail::image_ico(true); @@ -228,7 +228,7 @@ namespace paint break; } - if (STR("PNG") == type_str) + if (L"PNG" == type_str) { #if defined(NANA_ENABLE_PNG) helper = new detail::image_png; @@ -238,7 +238,7 @@ namespace paint break; } - if (STR("JPG") == type_str || STR("JPEG") == type_str) + if (L"JPG" == type_str || L"JPEG" == type_str) { #if defined(NANA_ENABLE_JPEG) helper = new detail::image_jpeg; diff --git a/source/paint/text_renderer.cpp b/source/paint/text_renderer.cpp index affefba7..8d98917b 100644 --- a/source/paint/text_renderer.cpp +++ b/source/paint/text_renderer.cpp @@ -124,7 +124,7 @@ namespace nana draw_string_omitted(graphics& graph, int x, int endpos, bool omitted) : graph(graph), x(x), endpos(endpos) { - omitted_pixels = (omitted ? graph.text_extent_size(STR("..."), 3).width : 0); + omitted_pixels = (omitted ? graph.text_extent_size(L"...", 3).width : 0); if (endpos - x > static_cast(omitted_pixels)) this->endpos -= omitted_pixels; else @@ -165,7 +165,7 @@ namespace nana r.y = top; graph.bitblt(r, dum_graph); if(omitted_pixels) - detail::draw_string(dw, point{ endpos, top }, STR("..."), 3); + detail::draw_string(dw, point{ endpos, top }, L"...", 3); break; } } diff --git a/source/system/platform.cpp b/source/system/platform.cpp index b9da7367..38b59398 100644 --- a/source/system/platform.cpp +++ b/source/system/platform.cpp @@ -104,14 +104,14 @@ namespace system return; #if defined(NANA_WINDOWS) - if(::ShellExecute(0, STR("open"), url.c_str(), 0, 0, SW_SHOWNORMAL) < reinterpret_cast(32)) + if(::ShellExecute(0, L"open", url.c_str(), 0, 0, SW_SHOWNORMAL) < reinterpret_cast(32)) { //Because ShellExecute can delegate execution to Shell extensions (data sources, context menu handlers, //verb implementations) that are activated using Component Object Model (COM), COM should be initialized //before ShellExecute is called. Some Shell extensions require the COM single-threaded apartment (STA) type. //In that case, COM should be initialized under WinXP. nana::detail::platform_spec::co_initializer co_init; - ::ShellExecute(0, STR("open"), url.c_str(), 0, 0, SW_SHOWNORMAL); + ::ShellExecute(0, L"open", url.c_str(), 0, 0, SW_SHOWNORMAL); } #elif defined(NANA_LINUX) || defined(NANA_MACOS) #endif