From a42ebe19b47cf9ba2f499d8b1d7d1013ca371009 Mon Sep 17 00:00:00 2001 From: Jinhao Date: Thu, 31 Dec 2015 01:09:52 +0800 Subject: [PATCH] use UTF-8 for string representation --- include/nana/deploy.hpp | 42 +---- .../nana/detail/linux_X11/platform_spec.hpp | 2 +- include/nana/filesystem/filesystem.hpp | 16 +- include/nana/filesystem/fs_utility.hpp | 27 ---- include/nana/gui/widgets/combox.hpp | 2 +- include/nana/gui/widgets/label.hpp | 2 +- include/nana/gui/widgets/listbox.hpp | 2 +- include/nana/gui/widgets/menu.hpp | 10 +- include/nana/gui/widgets/menubar.hpp | 6 +- .../gui/widgets/skeletons/text_editor.hpp | 6 +- .../widgets/skeletons/text_token_stream.hpp | 24 +-- include/nana/gui/widgets/textbox.hpp | 4 +- include/nana/gui/widgets/widget.hpp | 2 +- .../paint/detail/native_paint_interface.hpp | 6 +- include/nana/paint/graphics.hpp | 2 +- include/nana/paint/text_renderer.hpp | 8 +- include/nana/system/platform.hpp | 2 +- source/deploy.cpp | 17 -- source/detail/platform_spec_windows.cpp | 4 +- source/filesystem/filesystem.cpp | 47 +++--- source/filesystem/fs_utility.cpp | 153 +----------------- source/gui/detail/bedrock_posix.cpp | 10 +- source/gui/detail/bedrock_windows.cpp | 20 +-- source/gui/filebox.cpp | 2 +- source/gui/widgets/button.cpp | 13 +- source/gui/widgets/combox.cpp | 2 +- source/gui/widgets/label.cpp | 27 ++-- source/gui/widgets/listbox.cpp | 4 +- source/gui/widgets/menu.cpp | 14 +- source/gui/widgets/menubar.cpp | 18 +-- source/gui/widgets/skeletons/text_editor.cpp | 43 +++-- source/gui/widgets/spinbox.cpp | 2 +- source/gui/widgets/textbox.cpp | 4 +- source/gui/widgets/widget.cpp | 2 +- .../paint/detail/native_paint_interface.cpp | 6 +- source/paint/graphics.cpp | 6 +- source/paint/text_renderer.cpp | 36 ++--- source/system/platform.cpp | 5 +- 38 files changed, 182 insertions(+), 416 deletions(-) diff --git a/include/nana/deploy.hpp b/include/nana/deploy.hpp index 68bb38f3..694f016d 100644 --- a/include/nana/deploy.hpp +++ b/include/nana/deploy.hpp @@ -1,7 +1,7 @@ /* * The Deploy Implementation * 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 @@ -134,51 +134,11 @@ namespace nana detail::native_string_type to_nstring(std::size_t); } -#ifndef NANA_UNICODE - namespace nana - { - typedef char char_t; - typedef std::string string; ///< An alias of std::wstring or std::string, depending on the macro NANA_UNICODE - } -#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 - } -#endif - -namespace nana -{ - std::size_t strlen(const char_t* str); - char_t* strcpy(char_t* dest, const char_t* source); -#ifdef _MSC_VER - template - inline char* strcpy(char (&dest)[N], const char* source) - { - ::strncpy_s(dest, source, _TRUNCATE); - return dest; - } - template - inline wchar_t* strcpy(wchar_t (&dest)[N], const wchar_t* source) - { - ::wcsncpy_s(dest, source, _TRUNCATE); - return dest; - } -#endif // #ifdef _MSC_VER -} - -#if defined(NANA_WINDOWS) - #define NANA_SHARED_EXPORT extern "C" _declspec(dllexport) -#elif defined(NANA_LINUX) || defined(NANA_MACOS) - #define NANA_SHARED_EXPORT extern "C" -#endif namespace nana { inline unsigned make_rgb(unsigned char red, unsigned char green, unsigned char blue) { - return ((unsigned(red) << 16)|((unsigned(green)<<8))|blue); } } diff --git a/include/nana/detail/linux_X11/platform_spec.hpp b/include/nana/detail/linux_X11/platform_spec.hpp index f2ae61e0..12f4e94a 100644 --- a/include/nana/detail/linux_X11/platform_spec.hpp +++ b/include/nana/detail/linux_X11/platform_spec.hpp @@ -102,7 +102,7 @@ namespace detail #if defined(NANA_UNICODE) XftDraw * xftdraw{nullptr}; XftColor xft_fgcolor; - const std::string charset(const nana::string& str, const std::string& strcode); + const std::string charset(const std::wstring& str, const std::string& strcode); #endif drawable_impl_type(); ~drawable_impl_type(); diff --git a/include/nana/filesystem/filesystem.hpp b/include/nana/filesystem/filesystem.hpp index 12387ede..782ecfea 100644 --- a/include/nana/filesystem/filesystem.hpp +++ b/include/nana/filesystem/filesystem.hpp @@ -279,7 +279,7 @@ namespace filesystem (FILE_ATTRIBUTE_DIRECTORY & wfd_.dwFileAttributes) == FILE_ATTRIBUTE_DIRECTORY, wfd_.nFileSizeLow); - #elif defined(NANA_LINUX) || defined(NANA_MACOS) + #elif defined(NANA_POSIX) if(path_.size() && (path_[path_.size() - 1] != '/')) path_ += '/'; find_handle_t handle = opendir(path_.c_str()); @@ -307,7 +307,7 @@ namespace filesystem is_directory = (0 != S_ISDIR(fst.st_mode)); size = fst.st_size; } - value_ = value_type(static_cast(nana::charset(dnt->d_name)), is_directory, size); + value_ = value_type(static_cast(nana::charset(dnt->d_name)), is_directory, size); end_ = false; } } @@ -354,7 +354,7 @@ namespace filesystem } } - nana::string d_name = nana::charset(dnt->d_name); + std::wstring d_name = nana::charset(dnt->d_name, nana::unicode::utf8); struct stat fst; if(stat((path_ + "/" + dnt->d_name).c_str(), &fst) == 0) value_ = value_type(std::move(d_name), (0 != S_ISDIR(fst.st_mode)), fst.st_size); @@ -433,7 +433,6 @@ namespace filesystem std::uintmax_t file_size(const path& p); //uintmax_t file_size(const path& p, error_code& ec) noexcept; - //long long filesize(const nana::string& file); bool create_directories(const path& p); @@ -442,14 +441,6 @@ namespace filesystem //bool create_directory(const path& p, error_code& ec) noexcept; bool create_directory(const path& p, const path& attributes); //bool create_directory(const path& p, const path& attributes, error_code& ec) noexcept; - - /* - bool create_directory(const std::wstring& p, bool & if_exist); //deprecated - inline bool create_directory(const path& p, bool & if_exist) - { - return create_directory(p.filename(), if_exist); - } - */ bool modified_file_time(const std::wstring& file, struct tm&); path path_user(); @@ -458,7 +449,6 @@ namespace filesystem //path current_path(error_code& ec); void current_path(const path& p); //void current_path(const path& p, error_code& ec) noexcept; - //nana::string path_current(); //bool remove(const path& p); diff --git a/include/nana/filesystem/fs_utility.hpp b/include/nana/filesystem/fs_utility.hpp index 6beb9b73..7ddd4298 100644 --- a/include/nana/filesystem/fs_utility.hpp +++ b/include/nana/filesystem/fs_utility.hpp @@ -27,37 +27,10 @@ namespace filesystem bool modified_file_time(const ::std::string& file, struct tm&); std::wstring path_user(); - std::wstring path_current(); 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 - { - public: - struct type - { enum{not_exist, file, directory}; - }; - - path(); - path(const nana::string&); - - bool empty() const; - path root() const; - int what() const; - - nana::string name() const; - private: -#if defined(NANA_WINDOWS) - nana::string text_; -#else - std::string text_; -#endif - }; - */ - }//end namespace filesystem }//end namespace nana diff --git a/include/nana/gui/widgets/combox.hpp b/include/nana/gui/widgets/combox.hpp index c3033a9c..f31b3a18 100644 --- a/include/nana/gui/widgets/combox.hpp +++ b/include/nana/gui/widgets/combox.hpp @@ -172,7 +172,7 @@ namespace nana void clear(); void editable(bool); bool editable() const; - void set_accept(std::function); + void set_accept(std::function); 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. diff --git a/include/nana/gui/widgets/label.hpp b/include/nana/gui/widgets/label.hpp index f7071914..fef3b661 100644 --- a/include/nana/gui/widgets/label.hpp +++ b/include/nana/gui/widgets/label.hpp @@ -63,7 +63,7 @@ namespace nana label& transparent(bool); ///< Switchs the label widget to the transparent background mode. bool transparent() const throw(); label& format(bool); ///< Switches the format mode of the widget. - label& add_format_listener(std::function); + label& add_format_listener(std::function); label& click_for(window associated_window) throw(); // as same as the "for" attribute of a label diff --git a/include/nana/gui/widgets/listbox.hpp b/include/nana/gui/widgets/listbox.hpp index 2b25d47b..4aa7cfb7 100644 --- a/include/nana/gui/widgets/listbox.hpp +++ b/include/nana/gui/widgets/listbox.hpp @@ -259,7 +259,7 @@ namespace nana for (auto pos = 0u; pos < cols; ++pos) { auto & el = cells[pos]; - if (el.text.size() == 1 && el.text[0] == nana::char_t(0)) + if (el.text.size() == 1 && el.text[0] == '\0') continue; text(pos, std::move(el)); } diff --git a/include/nana/gui/widgets/menu.hpp b/include/nana/gui/widgets/menu.hpp index 9a182a08..335796d4 100644 --- a/include/nana/gui/widgets/menu.hpp +++ b/include/nana/gui/widgets/menu.hpp @@ -25,6 +25,8 @@ namespace nana { struct menu_type; //declaration + using native_string_type = ::nana::detail::native_string_type; + enum class checks { none, @@ -70,7 +72,7 @@ namespace nana event_fn_t functor; checks style{checks::none}; paint::image image; - mutable nana::char_t hotkey{0}; + mutable wchar_t hotkey{0}; }; struct menu_type @@ -89,7 +91,7 @@ namespace nana class renderer_interface { public: - typedef nana::paint::graphics & graph_reference; + using graph_reference = nana::paint::graphics &; enum class state { @@ -109,7 +111,7 @@ namespace nana virtual void background(graph_reference, window) = 0; virtual void item(graph_reference, const nana::rectangle&, const attr&) = 0; virtual void item_image(graph_reference, const nana::point&, unsigned image_px, const paint::image&) = 0; - virtual void item_text(graph_reference, const nana::point&, const nana::string&, unsigned text_pixels, const attr&) = 0; + virtual void item_text(graph_reference, const nana::point&, const std::string&, unsigned text_pixels, const attr&) = 0; virtual void sub_arrow(graph_reference, const nana::point&, unsigned item_pixels, const attr&) = 0; }; }//end namespace menu @@ -158,7 +160,7 @@ namespace nana bool goto_submen();///< Popup the submenu of the current item if it has a sub menu. Returns true if succeeds. bool exit_submenu(); ///< Closes the current window of the sub menu. std::size_t size() const; ///< Return the number of items. - int send_shortkey(nana::char_t key); + int send_shortkey(wchar_t key); void pick(); menu& max_pixels(unsigned); ///< Sets the max width in pixels of the item. diff --git a/include/nana/gui/widgets/menubar.hpp b/include/nana/gui/widgets/menubar.hpp index 0422b6a0..365d9b1c 100644 --- a/include/nana/gui/widgets/menubar.hpp +++ b/include/nana/gui/widgets/menubar.hpp @@ -21,6 +21,8 @@ namespace nana { namespace menubar { + using native_string_type = ::nana::detail::native_string_type; + class item_renderer { public: @@ -33,7 +35,7 @@ namespace nana item_renderer(window, graph_reference); virtual void background(const point&, const ::nana::size&, state); - virtual void caption(const point&, const ::nana::string&); + virtual void caption(const point&, const native_string_type&); private: window handle_; graph_reference graph_; @@ -46,7 +48,7 @@ namespace nana public: trigger(); ~trigger(); - nana::menu* push_back(const nana::string&); + nana::menu* push_back(const std::string&); nana::menu* at(size_t) const; std::size_t size() const; private: diff --git a/include/nana/gui/widgets/skeletons/text_editor.hpp b/include/nana/gui/widgets/skeletons/text_editor.hpp index 8cd2fb93..9da01f8c 100644 --- a/include/nana/gui/widgets/skeletons/text_editor.hpp +++ b/include/nana/gui/widgets/skeletons/text_editor.hpp @@ -221,7 +221,7 @@ namespace nana{ namespace widgets bool hit_select_area(nana::upoint pos) const; bool move_select(); - bool mask(char_t); + bool mask(wchar_t); /// Returns width of text area excluding the vscroll size. unsigned width_pixels() const; @@ -253,8 +253,8 @@ namespace nana{ namespace widgets bool mouse_move(bool left_button, const point& screen_pos); bool mouse_pressed(const arg_mouse& arg); - skeletons::textbase& textbase(); - const skeletons::textbase& textbase() const; + skeletons::textbase& textbase(); + const skeletons::textbase& textbase() const; private: bool _m_accepts(char_type) const; ::nana::color _m_bgcolor() const; diff --git a/include/nana/gui/widgets/skeletons/text_token_stream.hpp b/include/nana/gui/widgets/skeletons/text_token_stream.hpp index 873b23cd..ccd4db37 100644 --- a/include/nana/gui/widgets/skeletons/text_token_stream.hpp +++ b/include/nana/gui/widgets/skeletons/text_token_stream.hpp @@ -1,7 +1,7 @@ /* * Text Token Stream * Nana C++ Library(http://www.nanapro.org) - * Copyright(C) 2003-2013 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 @@ -108,7 +108,7 @@ namespace nana{ namespace widgets{ namespace skeletons return n; } private: - static bool _m_unicode_word_breakable(nana::char_t ch) + static bool _m_unicode_word_breakable(wchar_t ch) { return ((0x4E00 <= ch) && (ch <= 0x9FFF)); } @@ -116,7 +116,7 @@ namespace nana{ namespace widgets{ namespace skeletons //Read the data token token _m_token() { - nana::char_t ch = *iptr_; + wchar_t ch = *iptr_; if(ch > 0xFF) { @@ -150,7 +150,7 @@ namespace nana{ namespace widgets{ namespace skeletons if(('a' <= ch && ch <= 'z') || ('A' <= ch && ch <= 'Z')) { - const nana::char_t * idstr = iptr_; + auto idstr = iptr_; do { ch = *(++iptr_); @@ -172,7 +172,7 @@ namespace nana{ namespace widgets{ namespace skeletons { //pos keeps the current position, and it used for restring //iptr_ when the search is failed. - const nana::char_t * pos = ++iptr_; + auto pos = ++iptr_; _m_eat_whitespace(); if(*iptr_ == '/') { @@ -219,7 +219,7 @@ namespace nana{ namespace widgets{ namespace skeletons { _m_eat_whitespace(); - nana::char_t ch = *iptr_++; + auto ch = *iptr_++; switch(ch) { @@ -232,7 +232,7 @@ namespace nana{ namespace widgets{ namespace skeletons case '"': //Here is a string and all the meta characters will be ignored except " { - const nana::char_t * str = iptr_; + auto str = iptr_; while((iptr_ != endptr_) && (*iptr_ != '"')) ++iptr_; @@ -244,7 +244,7 @@ namespace nana{ namespace widgets{ namespace skeletons _m_eat_whitespace(); if((iptr_ < endptr_) && _m_is_idstr_element(*iptr_)) { - const nana::char_t * pbegin = iptr_; + auto pbegin = iptr_; while((iptr_ < endptr_) && _m_is_idstr_element(*iptr_)) ++iptr_; @@ -335,7 +335,7 @@ namespace nana{ namespace widgets{ namespace skeletons return token::eof; } - static bool _m_is_idstr_element(nana::char_t ch) + static bool _m_is_idstr_element(wchar_t ch) { return (('a' <= ch && ch <= 'z') || ('A' <= ch && ch <= 'Z') || ('_' == ch) || ('0' <= ch && ch <= '9')); } @@ -343,9 +343,9 @@ namespace nana{ namespace widgets{ namespace skeletons //Read the identifier. void _m_read_idstr() { - const nana::char_t * idstr = iptr_; + auto idstr = iptr_; - nana::char_t ch; + wchar_t ch; do { ch = *(++iptr_); @@ -360,7 +360,7 @@ namespace nana{ namespace widgets{ namespace skeletons { idstr_.clear(); - nana::char_t ch = *iptr_; + wchar_t ch = *iptr_; idstr_ += ch; diff --git a/include/nana/gui/widgets/textbox.hpp b/include/nana/gui/widgets/textbox.hpp index 5ebf27ed..69fda830 100644 --- a/include/nana/gui/widgets/textbox.hpp +++ b/include/nana/gui/widgets/textbox.hpp @@ -171,12 +171,12 @@ namespace nana textbox& multi_lines(bool); bool editable() const; textbox& editable(bool); - void set_accept(std::function); + void set_accept(std::function); 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); + textbox& mask(wchar_t); /// Returns true if some text is selected. bool selected() const; diff --git a/include/nana/gui/widgets/widget.hpp b/include/nana/gui/widgets/widget.hpp index b8304031..1fdb48fa 100644 --- a/include/nana/gui/widgets/widget.hpp +++ b/include/nana/gui/widgets/widget.hpp @@ -93,7 +93,7 @@ namespace nana void umake_event(event_handle eh) const; ///< Deletes an event callback by a handle. - widget& register_shortkey(char_t); ///< Registers a shortkey. To remove a registered key, pass 0. + widget& register_shortkey(wchar_t); ///< Registers a shortkey. To remove a registered key, pass 0. widget& take_active(bool activated, window take_if_not_activated); widget& tooltip(const ::std::string&); diff --git a/include/nana/paint/detail/native_paint_interface.hpp b/include/nana/paint/detail/native_paint_interface.hpp index 4281aca1..4a3dba44 100644 --- a/include/nana/paint/detail/native_paint_interface.hpp +++ b/include/nana/paint/detail/native_paint_interface.hpp @@ -32,9 +32,9 @@ namespace detail void blend(drawable_type dw, const nana::rectangle& r, pixel_color_t, double fade_rate); - nana::size raw_text_extent_size(drawable_type, const nana::char_t*, std::size_t len); - nana::size text_extent_size(drawable_type, const nana::char_t*, std::size_t len); - void draw_string(drawable_type, const nana::point&, const nana::char_t *, std::size_t len); + nana::size raw_text_extent_size(drawable_type, const wchar_t*, std::size_t len); + nana::size text_extent_size(drawable_type, const wchar_t*, std::size_t len); + void draw_string(drawable_type, const nana::point&, const wchar_t *, std::size_t len); }//end namespace detail }//end namespace paint }//end namespace nana diff --git a/include/nana/paint/graphics.hpp b/include/nana/paint/graphics.hpp index 301b6f3f..ef2f37f1 100644 --- a/include/nana/paint/graphics.hpp +++ b/include/nana/paint/graphics.hpp @@ -144,7 +144,7 @@ namespace nana ::nana::color palette(bool for_text) const; graphics& palette(bool for_text, const ::nana::color&); - unsigned bidi_string(const nana::point&, const char_t *, std::size_t len); + unsigned bidi_string(const nana::point&, const wchar_t *, std::size_t len); unsigned bidi_string(const point& pos, const char*, std::size_t len); void blend(const ::nana::rectangle& r, const ::nana::color&, double fade_rate); diff --git a/include/nana/paint/text_renderer.hpp b/include/nana/paint/text_renderer.hpp index 28bb4e8f..7234c57c 100644 --- a/include/nana/paint/text_renderer.hpp +++ b/include/nana/paint/text_renderer.hpp @@ -13,11 +13,11 @@ namespace nana text_renderer(graph_reference graph, align = align::left); - nana::size extent_size(int x, int y, const nana::char_t*, std::size_t len, unsigned restricted_pixels) const; + nana::size extent_size(int x, int y, const wchar_t*, std::size_t len, unsigned restricted_pixels) const; - void render(const point&, const char_t*, std::size_t len); - void render(const point&, const char_t*, std::size_t len, unsigned restricted_pixels, bool omitted); - void render(const point&, const char_t*, std::size_t len, unsigned restricted_pixels); + void render(const point&, const wchar_t*, std::size_t len); + void render(const point&, const wchar_t*, std::size_t len, unsigned restricted_pixels, bool omitted); + void render(const point&, const wchar_t*, std::size_t len, unsigned restricted_pixels); private: graph_reference graph_; align text_align_; diff --git a/include/nana/system/platform.hpp b/include/nana/system/platform.hpp index fd74f757..6a5f4ffd 100644 --- a/include/nana/system/platform.hpp +++ b/include/nana/system/platform.hpp @@ -38,7 +38,7 @@ namespace system bool get_async_mouse_state(int button); //open an url through a default browser - void open_url(const nana::string& url); + void open_url(const std::string& url); }//end namespace system }//end namespace nana diff --git a/source/deploy.cpp b/source/deploy.cpp index 0f176f63..5b3140da 100644 --- a/source/deploy.cpp +++ b/source/deploy.cpp @@ -600,22 +600,5 @@ namespace nana #endif - std::size_t strlen(const char_t* str) - { -#if defined(NANA_UNICODE) - return ::wcslen(str); -#else - return ::strlen(str); -#endif - } - - char_t* strcpy(char_t* dest, const char_t* source) - { -#if defined(NANA_UNICODE) - return ::wcscpy(dest, source); -#else - return ::strcpy(dest, source); -#endif - } } diff --git a/source/detail/platform_spec_windows.cpp b/source/detail/platform_spec_windows.cpp index 3ad1a352..de46dbea 100644 --- a/source/detail/platform_spec_windows.cpp +++ b/source/detail/platform_spec_windows.cpp @@ -244,9 +244,9 @@ namespace detail memset(&logfont, 0, sizeof logfont); if (name && *name) - strcpy(logfont.lfFaceName, utf8_cast(name).c_str()); + std::wcscpy(logfont.lfFaceName, utf8_cast(name).c_str()); else - strcpy(logfont.lfFaceName, def_font_ptr_->name.c_str()); + std::wcscpy(logfont.lfFaceName, def_font_ptr_->name.c_str()); logfont.lfCharSet = DEFAULT_CHARSET; HDC hdc = ::GetDC(0); diff --git a/source/filesystem/filesystem.cpp b/source/filesystem/filesystem.cpp index 3cd01865..d0e9b320 100644 --- a/source/filesystem/filesystem.cpp +++ b/source/filesystem/filesystem.cpp @@ -237,28 +237,6 @@ namespace nana { namespace experimental { return rmdir(dir, true); } - bool mkdir_helper(const nana::string& dir, bool & if_exist) - { -#if defined(NANA_WINDOWS) - if (::CreateDirectory(dir.c_str(), 0)) - { - if_exist = false; - return true; - } - - 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_exist = false; - return true; - } - - if_exist = (errno == EEXIST); -#endif - return false; - } - #if defined(NANA_WINDOWS) void filetime_to_c_tm(FILETIME& ft, struct tm& t) { @@ -513,13 +491,34 @@ namespace nana { namespace experimental { } return buf; } -#elif defined(NANA_LINUX) || defined(NANA_MACOS) - auto pstr = ::getenv("PWD"); +#elif defined(NANA_POSIX) + char buf[260]; + auto pstr = ::getcwd(buf, 260); if (pstr) return pstr; + + int bytes = 260 + 260; + while (ERANGE == errno) + { + std::unique_ptr buf(new char[bytes]); + auto pstr = ::getcwd(buf.get(), bytes); + if (pstr) + return path(pstr); + + bytes += 260; + } #endif return path(); } + + void current_path(const path& p) + { +#if defined(NANA_WINDOWS) + ::SetCurrentDirectoryW(p.c_str()); +#elif defined(NANA_POSIX) + ::chdir(p.c_str()); +#endif + } }//end namespace filesystem } //end namespace experimental }//end namespace nana diff --git a/source/filesystem/fs_utility.cpp b/source/filesystem/fs_utility.cpp index 2ed306b6..8b25d289 100644 --- a/source/filesystem/fs_utility.cpp +++ b/source/filesystem/fs_utility.cpp @@ -51,80 +51,6 @@ namespace filesystem const wchar_t* splstr = L"/\\"; #endif - /* - //class path - path::path(){} - - path::path(const nana::string& text) -#if defined(NANA_WINDOWS) - :text_(text) - { -#else - :text_(nana::charset(text)) - { -#endif - auto pos = text_.find_last_of(splstr); - for(; (pos != string_t::npos) && (pos + 1 == text_.size()); pos = text_.find_last_of(splstr)) - text_.erase(pos); - } - - bool path::empty() const - { -#if defined(NANA_WINDOWS) - return (::GetFileAttributes(text_.c_str()) == INVALID_FILE_ATTRIBUTES); -#elif defined(NANA_LINUX) || defined(NANA_MACOS) - struct stat sta; - return (::stat(text_.c_str(), &sta) == -1); -#endif - } - - path path::root() const - { - #if defined(NANA_WINDOWS) - return path(filesystem::root(text_)); - #elif defined(NANA_LINUX) || defined(NANA_MACOS) - return path(filesystem::root(nana::charset(text_))); - #endif - } - - int path::what() const - { -#if defined(NANA_WINDOWS) - unsigned long attr = ::GetFileAttributes(text_.c_str()); - if(INVALID_FILE_ATTRIBUTES == attr) - return type::not_exist; - - if(FILE_ATTRIBUTE_DIRECTORY & attr) - return type::directory; - - return type::file; -#elif defined(NANA_LINUX) || defined(NANA_MACOS) - struct stat sta; - if(-1 == ::stat(text_.c_str(), &sta)) - return type::not_exist; - - if((S_IFDIR & sta.st_mode) == S_IFDIR) - return type::directory; - - if((S_IFREG & sta.st_mode) == S_IFREG) - return type::file; - - return type::not_exist; -#endif - } - - nana::string path::name() const - { - string_t::size_type pos = text_.find_last_of(splstr); -#if defined(NANA_WINDOWS) - return text_.substr(pos + 1); -#else - return nana::charset(text_.substr(pos + 1)); -#endif - } - //end class path - */ - namespace detail { //rm_dir_recursive @@ -148,28 +74,6 @@ namespace filesystem return rmdir(dir.c_str(), true); } - bool mkdir_helper(const std::string& dir, bool & if_exist) - { -#if defined(NANA_WINDOWS) - if(::CreateDirectory(utf8_cast(dir).c_str(), 0)) - { - if_exist = false; - return true; - } - - if_exist = (::GetLastError() == ERROR_ALREADY_EXISTS); -#elif defined(NANA_LINUX) || defined(NANA_MACOS) - if(0 == ::mkdir(dir.c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH)) - { - if_exist = false; - return true; - } - - if_exist = (errno == EEXIST); -#endif - return false; - } - #if defined(NANA_WINDOWS) void filetime_to_c_tm(FILETIME& ft, struct tm& t) { @@ -269,36 +173,10 @@ namespace filesystem return ret; } - nana::string root(const nana::string& path) - { - std::size_t index = path.size(); - - if(index) - { - const nana::char_t * str = path.c_str(); - - for(--index; index > 0; --index) - { - 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; - } - } - - return index?path.substr(0, index + 1):nana::string(); - } - - nana::string path_user() + std::wstring path_user() { #if defined(NANA_WINDOWS) - nana::char_t path[MAX_PATH]; + wchar_t path[MAX_PATH]; if(SUCCEEDED(SHGetFolderPath(0, CSIDL_PROFILE, 0, SHGFP_TYPE_CURRENT, path))) return path; #elif defined(NANA_LINUX) || defined(NANA_MACOS) @@ -306,32 +184,7 @@ namespace filesystem if(s) return nana::charset(std::string(s, std::strlen(s)), nana::unicode::utf8); #endif - return nana::string(); - } - - nana::string path_current() - { -#if defined(NANA_WINDOWS) - nana::char_t buf[MAX_PATH]; - DWORD len = ::GetCurrentDirectory(MAX_PATH, buf); - if(len) - { - if(len > MAX_PATH) - { - nana::char_t * p = new nana::char_t[len + 1]; - ::GetCurrentDirectory(len + 1, p); - nana::string s = p; - delete [] p; - return s; - } - return buf; - } -#elif defined(NANA_LINUX) || defined(NANA_MACOS) - const char * s = ::getenv("PWD"); - if(s) - return nana::charset(std::string(s, std::strlen(s)), nana::unicode::utf8); -#endif - return nana::string(); + return std::wstring(); } }//end namespace filesystem }//end namespace nana diff --git a/source/gui/detail/bedrock_posix.cpp b/source/gui/detail/bedrock_posix.cpp index ad8a8508..9af6c1bd 100644 --- a/source/gui/detail/bedrock_posix.cpp +++ b/source/gui/detail/bedrock_posix.cpp @@ -1017,7 +1017,7 @@ namespace detail } keybuf[len] = 0; - ::nana::char_t os_code = 0; + wchar_t os_code = 0; switch(status) { case XLookupKeySym: @@ -1074,7 +1074,7 @@ namespace detail if(brock.wd_manager().available(msgwnd) && (msgwnd->root_widget->other.attribute.root->menubar == msgwnd)) { - int cmd = (menu_wd && (keyboard::escape == static_cast(arg.key)) ? 1 : 0 ); + int cmd = (menu_wd && (keyboard::escape == static_cast(arg.key)) ? 1 : 0 ); brock.delay_restore(cmd); } } @@ -1087,11 +1087,11 @@ namespace detail case XLookupChars: if (msgwnd->flags.enabled) { - const ::nana::char_t* charbuf; + const wchar_t* charbuf; #if defined(NANA_UNICODE) nana::detail::charset_conv charset("UTF-32", "UTF-8"); const std::string& str = charset.charset(std::string(keybuf, keybuf + len)); - charbuf = reinterpret_cast(str.c_str()) + 1; + charbuf = reinterpret_cast(str.c_str()) + 1; len = str.size() / sizeof(wchar_t) - 1; #else charbuf = keybuf; @@ -1400,4 +1400,4 @@ namespace detail } }//end namespace detail }//end namespace nana -#endif //NANA_POSIX && NANA_X11 \ No newline at end of file +#endif //NANA_POSIX && NANA_X11 diff --git a/source/gui/detail/bedrock_windows.cpp b/source/gui/detail/bedrock_windows.cpp index a524e622..6dba26c5 100644 --- a/source/gui/detail/bedrock_windows.cpp +++ b/source/gui/detail/bedrock_windows.cpp @@ -141,7 +141,7 @@ namespace detail struct platform_detail_tag { - nana::char_t keychar; + wchar_t keychar; }platform; struct cursor_tag @@ -1185,7 +1185,7 @@ namespace detail unsigned reqlen = ::DragQueryFile(drop, i, 0, 0) + 1; if(bufsize < reqlen) { - varbuf.reset(new nana::char_t[reqlen]); + varbuf.reset(new wchar_t[reqlen]); bufsize = reqlen; } @@ -1345,7 +1345,7 @@ namespace detail arg.evt_code = event_code::key_press; arg.window_handle = reinterpret_cast(msgwnd); arg.ignore = false; - arg.key = static_cast(wParam); + arg.key = static_cast(wParam); brock.get_key_state(arg); brock.emit(event_code::key_press, msgwnd, arg, true, &context); @@ -1373,7 +1373,7 @@ namespace detail arg.evt_code = event_code::key_release; arg.window_handle = reinterpret_cast(msgwnd); arg.ignore = false; - arg.key = static_cast(wParam); + arg.key = static_cast(wParam); brock.get_key_state(arg); brock.emit(event_code::key_release, msgwnd, arg, true, &context); @@ -1415,7 +1415,7 @@ namespace detail arg.evt_code = event_code::key_press; arg.window_handle = reinterpret_cast(msgwnd); arg.ignore = false; - arg.key = static_cast(wParam); + arg.key = static_cast(wParam); brock.get_key_state(arg); brock.emit(event_code::key_press, msgwnd, arg, true, &context); @@ -1426,7 +1426,7 @@ namespace detail //If no menu popuped by the menubar, it should enable delay restore to //restore the focus for taken window. - int cmd = (menu_wd && (keyboard::escape == static_cast(wParam)) ? 1 : 0); + int cmd = (menu_wd && (keyboard::escape == static_cast(wParam)) ? 1 : 0); brock.delay_restore(cmd); } } @@ -1443,7 +1443,7 @@ namespace detail arg_keyboard arg; arg.evt_code = event_code::key_char; arg.window_handle = reinterpret_cast(msgwnd); - arg.key = static_cast(wParam); + arg.key = static_cast(wParam); brock.get_key_state(arg); arg.ignore = false; @@ -1464,7 +1464,7 @@ namespace detail arg_keyboard arg; arg.evt_code = event_code::key_release; arg.window_handle = reinterpret_cast(msgwnd); - arg.key = static_cast(wParam); + arg.key = static_cast(wParam); brock.get_key_state(arg); arg.ignore = false; brock.emit(event_code::key_release, msgwnd, arg, true, &context); @@ -1729,9 +1729,9 @@ namespace detail return true; } - const nana::char_t* translate(cursor id) + const wchar_t* translate(cursor id) { - const nana::char_t* name = IDC_ARROW; + const wchar_t* name = IDC_ARROW; switch(id) { diff --git a/source/gui/filebox.cpp b/source/gui/filebox.cpp index bf8ed835..bd63a010 100644 --- a/source/gui/filebox.cpp +++ b/source/gui/filebox.cpp @@ -96,7 +96,7 @@ namespace nana { double cap = bytes / 1024.0; std::size_t uid = 0; - while((cap >= 1024.0) && (uid < (sizeof(ustr) / sizeof(nana::char_t*)))) + while((cap >= 1024.0) && (uid < (sizeof(ustr) / sizeof(char*)))) { cap /= 1024.0; ++uid; diff --git a/source/gui/widgets/button.cpp b/source/gui/widgets/button.cpp index 70883b3b..e091310a 100644 --- a/source/gui/widgets/button.cpp +++ b/source/gui/widgets/button.cpp @@ -164,13 +164,13 @@ namespace nana{ namespace drawerbase void trigger::key_char(graph_reference, const arg_keyboard& arg) { - if (static_cast(keyboard::enter) == arg.key) + if (static_cast(keyboard::enter) == arg.key) emit_click(); } void trigger::key_press(graph_reference graph, const arg_keyboard& arg) { - if (keyboard::space == static_cast(arg.key)) + if (keyboard::space == static_cast(arg.key)) { _m_press(graph, true); return; @@ -193,7 +193,7 @@ namespace nana{ namespace drawerbase void trigger::key_release(graph_reference graph, const arg_keyboard& arg) { - if (arg.key != static_cast(keyboard::space)) + if (arg.key != static_cast(keyboard::space)) return; emit_click(); @@ -259,8 +259,13 @@ namespace nana{ namespace drawerbase { unsigned off_w = (shortkey_pos ? graph.text_extent_size(mbstr.c_str(), static_cast(shortkey_pos)).width : 0); nana::size shortkey_size = graph.text_extent_size(to_wstring(mbstr.c_str() + shortkey_pos), 1); + + unsigned ascent, descent, inleading; + graph.text_metrics(ascent, descent, inleading); + pos.x += off_w; - pos.y += static_cast(shortkey_size.height); + pos.y += static_cast(ascent + 2); + graph.set_color(colors::black); graph.line(pos, point{ pos.x + static_cast(shortkey_size.width) - 1, pos.y }); } diff --git a/source/gui/widgets/combox.cpp b/source/gui/widgets/combox.cpp index bb1d56cf..c5df35f8 100644 --- a/source/gui/widgets/combox.cpp +++ b/source/gui/widgets/combox.cpp @@ -906,7 +906,7 @@ namespace nana return _m_impl().editable(); } - void combox::set_accept(std::function pred) + void combox::set_accept(std::function pred) { internal_scope_guard lock; auto editor = _m_impl().editor(); diff --git a/source/gui/widgets/label.cpp b/source/gui/widgets/label.cpp index f595d39d..c6f0ca1f 100644 --- a/source/gui/widgets/label.cpp +++ b/source/gui/widgets/label.cpp @@ -62,7 +62,7 @@ namespace nana typedef widgets::skeletons::fblock fblock; typedef widgets::skeletons::data data; - void parse(const nana::string& s) + void parse(const std::wstring& s) { dstream_.parse(s, format_enabled_); } @@ -439,7 +439,7 @@ namespace nana bool _m_each_line(graph_reference graph, dstream::linecontainer& line, render_status& rs) { - nana::string text; + std::wstring text; iterator block_start; const int lastpos = static_cast(graph.height()) - 1; @@ -521,7 +521,7 @@ namespace nana return 0; } - void _m_draw_block(graph_reference graph, const nana::string& s, dstream::linecontainer::iterator block_start, render_status& rs) + void _m_draw_block(graph_reference graph, const std::wstring& s, dstream::linecontainer::iterator block_start, render_status& rs) { nana::unicode_bidi bidi; std::vector reordered; @@ -568,7 +568,7 @@ namespace nana } else { - nana::string str = data_ptr->text().substr(text_range.first, text_range.second); + auto str = data_ptr->text().substr(text_range.first, text_range.second); graph.string({ rs.pos.x, y }, str, _m_fgcolor(fblock_ptr)); sz = graph.text_extent_size(str); } @@ -625,23 +625,24 @@ namespace nana class renderer renderer; - nana::string target; //It indicates which target is tracing. - nana::string url; + std::wstring target; //It indicates which target is tracing. + std::wstring url; window for_associated_wd{ nullptr }; - void add_listener(std::function&& fn) + void add_listener(std::function&& fn) { listener_.emplace_back(std::move(fn)); } - void call_listener(command cmd, const nana::string& tar) + void call_listener(command cmd, const std::wstring& tar) { + auto str = to_utf8(tar); for (auto & fn : listener_) - fn(cmd, tar); + fn(cmd, str); } private: - std::vector> listener_; + std::vector> listener_; }; trigger::trigger() @@ -666,7 +667,7 @@ namespace nana void trigger::mouse_move(graph_reference, const arg_mouse& arg) { - nana::string target, url; + std::wstring target, url; if(impl_->renderer.find(arg.pos.x, arg.pos.y, target, url)) { @@ -741,7 +742,7 @@ namespace nana if(impl_->target.size()) impl_->call_listener(command::click, impl_->target); - system::open_url(url); + system::open_url(to_utf8(url)); API::focus_window(impl_->for_associated_wd); } @@ -813,7 +814,7 @@ namespace nana return *this; } - label& label::add_format_listener(std::function f) + label& label::add_format_listener(std::function f) { get_drawer_trigger().impl()->add_listener(std::move(f)); return *this; diff --git a/source/gui/widgets/listbox.cpp b/source/gui/widgets/listbox.cpp index 828bea16..200871b1 100644 --- a/source/gui/widgets/listbox.cpp +++ b/source/gui/widgets/listbox.cpp @@ -197,7 +197,7 @@ namespace nana oresolver& oresolver::operator<<(std::nullptr_t) { cells_.emplace_back(); - cells_.back().text.assign(1, nana::char_t(0)); //means invalid cell + cells_.back().text.assign(1, wchar_t(0)); //means invalid cell return *this; } @@ -4239,7 +4239,7 @@ namespace nana //check invalid cells for (auto & cl : cells) { - if (cl.text.size() == 1 && cl.text[0] == nana::char_t(0)) + if (cl.text.size() == 1 && cl.text[0] == wchar_t(0)) { cl.text.clear(); cl.custom_format.reset(); diff --git a/source/gui/widgets/menu.cpp b/source/gui/widgets/menu.cpp index 93b57240..39665a63 100644 --- a/source/gui/widgets/menu.cpp +++ b/source/gui/widgets/menu.cpp @@ -148,11 +148,13 @@ namespace nana img.stretch(rectangle{ img.size() }, graph, rectangle{ pos, ::nana::size(image_px, image_px) }); } - void item_text(graph_reference graph, const nana::point& pos, const std::wstring& text, unsigned text_pixels, const attr& at) + void item_text(graph_reference graph, const nana::point& pos, const std::string& text, unsigned text_pixels, const attr& at) { graph.set_text_color(at.enabled ? colors::black : colors::gray_border); nana::paint::text_renderer tr(graph); - tr.render(pos, text.c_str(), text.length(), text_pixels, true); + + auto wstr = to_wstring(text); + tr.render(pos, wstr.c_str(), wstr.length(), text_pixels, true); } void sub_arrow(graph_reference graph, const nana::point& pos, unsigned pixels, const attr&) @@ -389,7 +391,7 @@ namespace nana if (m.image.empty() == false) renderer->item_image(graph, nana::point(item_r.x + 5, item_r.y + static_cast(item_h_px - image_px) / 2 - 1), image_px, m.image); - renderer->item_text(graph, nana::point(item_r.x + 40, item_r.y + text_top_off), text, strpixels, attr); + renderer->item_text(graph, nana::point(item_r.x + 40, item_r.y + text_top_off), to_utf8(text), strpixels, attr); if (hotkey) { @@ -546,7 +548,7 @@ namespace nana } //send_shortkey has 3 states, 0 = UNKNOWN KEY, 1 = ITEM, 2 = GOTO SUBMENU - int send_shortkey(nana::char_t key) + int send_shortkey(wchar_t key) { key = std::tolower(key); std::size_t index = 0; @@ -845,7 +847,7 @@ namespace nana return menu_wd->_m_manipulate_sub(0, true); } - int send_shortkey(nana::char_t key) + int send_shortkey(wchar_t key) { menu_window * object = this; while(object->submenu_.child) @@ -1254,7 +1256,7 @@ namespace nana return impl_->mbuilder.data().items.size(); } - int menu::send_shortkey(nana::char_t key) + int menu::send_shortkey(wchar_t key) { return (impl_->uiobj ? impl_->uiobj->send_shortkey(key) : 0); } diff --git a/source/gui/widgets/menubar.cpp b/source/gui/widgets/menubar.cpp index a285afa3..831b633b 100644 --- a/source/gui/widgets/menubar.cpp +++ b/source/gui/widgets/menubar.cpp @@ -30,11 +30,11 @@ namespace nana { struct item_type { - item_type(const ::std::wstring& text, unsigned long shortkey) + item_type(const native_string_type text, unsigned long shortkey) : text(text), shortkey(shortkey) {} - ::std::wstring text; + native_string_type text; unsigned long shortkey; ::nana::menu menu_obj; ::nana::point pos; @@ -52,7 +52,7 @@ namespace nana delete i; } - void append(const ::std::wstring& text, unsigned long shortkey) + void append(const native_string_type& text, unsigned long shortkey) { if(shortkey && shortkey < 0x61) shortkey += (0x61 - 0x41); cont_.push_back(new item_type(text, shortkey)); @@ -122,7 +122,7 @@ namespace nana graph_.rectangle(r.pare_off(1), true, body); } - void item_renderer::caption(const point& pos, const std::wstring& text) + void item_renderer::caption(const point& pos, const native_string_type& text) { graph_.string(pos, text, colors::black); } @@ -138,16 +138,16 @@ namespace nana delete items_; } - nana::menu* trigger::push_back(const ::std::wstring& text) + nana::menu* trigger::push_back(const std::string& text) { wchar_t shkey; - API::transform_shortkey_text(to_utf8(text), shkey, nullptr); + API::transform_shortkey_text(text, shkey, nullptr); if(shkey) API::register_shortkey(widget_->handle(), shkey); auto pos = items_->cont().size(); - items_->append(text, shkey); + items_->append(to_nstring(text), shkey); refresh(*graph_); API::update_window(*widget_); @@ -212,7 +212,7 @@ namespace nana //Draw text, the text is transformed from orignal for hotkey character int text_top_off = (item_s.height - text_s.height) / 2; - ird.caption({ item_pos.x + 8, item_pos.y + text_top_off }, to_wstring(text)); + ird.caption({ item_pos.x + 8, item_pos.y + text_top_off }, to_nstring(text)); if (hotkey) { @@ -619,7 +619,7 @@ namespace nana menu& menubar::push_back(const std::string& text) { - return *(get_drawer_trigger().push_back(to_wstring(text))); + return *(get_drawer_trigger().push_back(text)); } menu& menubar::at(std::size_t index) const diff --git a/source/gui/widgets/skeletons/text_editor.cpp b/source/gui/widgets/skeletons/text_editor.cpp index d061395e..b8ca8286 100644 --- a/source/gui/widgets/skeletons/text_editor.cpp +++ b/source/gui/widgets/skeletons/text_editor.cpp @@ -500,8 +500,8 @@ namespace nana{ namespace widgets { struct text_section { - const nana::char_t* begin; - const nana::char_t* end; + const wchar_t* begin; + const wchar_t* end; unsigned pixels; text_section() @@ -509,7 +509,7 @@ namespace nana{ namespace widgets throw std::runtime_error("text_section default construction is forbidden."); } - text_section(const nana::char_t* ptr, const nana::char_t* endptr) + text_section(const wchar_t* ptr, const wchar_t* endptr) : begin(ptr), end(endptr) {} }; @@ -591,7 +591,7 @@ namespace nana{ namespace widgets std::vector line_sections; unsigned text_px = 0; - const nana::char_t * secondary_begin = nullptr; + const wchar_t * secondary_begin = nullptr; for (auto & ts : sections) { if (!secondary_begin) @@ -627,7 +627,7 @@ namespace nana{ namespace widgets if (text_px < pixels) continue; - const nana::char_t * endptr = ts.begin + (pxi - pxptr) + (text_px == pixels ? 1 : 0); + const wchar_t * endptr = ts.begin + (pxi - pxptr) + (text_px == pixels ? 1 : 0); line_sections.emplace_back(secondary_begin, endptr); line_sections.back().pixels = text_px - (text_px == pixels ? 0 : *pxi); secondary_begin = endptr; @@ -816,7 +816,7 @@ namespace nana{ namespace widgets if (editor_.mask_char_) mask_str.reset(new std::wstring(real_str.end - real_str.begin, editor_.mask_char_)); - const ::nana::char_t * str = (editor_.mask_char_ ? mask_str->data() : real_str.begin); + const wchar_t * str = (editor_.mask_char_ ? mask_str->data() : real_str.begin); std::vector reordered; unicode_bidi bidi; @@ -934,10 +934,10 @@ namespace nana{ namespace widgets } const auto end = str.data() + str.size(); - const nana::char_t * word = nullptr; + const wchar_t * word = nullptr; for (auto i = str.data(); i != end; ++i) { - nana::char_t const ch = *i; + wchar_t const ch = *i; //CKJ characters and whitespace if (' ' == ch || '\t' == ch || (0x4E00 <= ch && ch <= 0x9FCF)) @@ -1166,8 +1166,8 @@ namespace nana{ namespace widgets struct entity { - const ::nana::char_t* begin; - const ::nana::char_t* end; + const wchar_t* begin; + const wchar_t* end; const keyword_scheme * scheme; }; @@ -1388,7 +1388,7 @@ namespace nana{ namespace widgets case keyboard::sync_idel: paste(); break; case keyboard::tab: - put(static_cast(keyboard::tab)); break; + put(static_cast(keyboard::tab)); break; case keyboard::cancel: cut(); break; @@ -1404,11 +1404,6 @@ namespace nana{ namespace widgets if (key > 0x7F || (32 <= key && key <= 126)) put(key); - else if (sizeof(nana::char_t) == sizeof(char)) - { //Non-Unicode Version for Non-English characters - if (key & (1 << (sizeof(nana::char_t) * 8 - 1))) - put(key); - } } reset_caret(); return true; @@ -1729,12 +1724,12 @@ namespace nana{ namespace widgets return false; } - textbase & text_editor::textbase() + textbase & text_editor::textbase() { return textbase_; } - const textbase & text_editor::textbase() const + const textbase & text_editor::textbase() const { return textbase_; } @@ -1896,7 +1891,7 @@ namespace nana{ namespace widgets return false; } - bool text_editor::mask(nana::char_t ch) + bool text_editor::mask(wchar_t ch) { if (mask_char_ == ch) return false; @@ -2315,7 +2310,7 @@ namespace nana{ namespace widgets bool changed = false; nana::upoint caret = points_.caret; - char_t key = arg.key; + wchar_t key = arg.key; size_t nlines = textbase_.lines(); if (arg.ctrl) { switch (key) { @@ -2853,7 +2848,7 @@ namespace nana{ namespace widgets { if(0 == tabs) return 0; - nana::char_t ws[2] = {}; + wchar_t ws[2] = {}; ws[0] = mask_char_ ? mask_char_ : ' '; return static_cast(tabs * graph_.text_extent_size(ws).width * text_area_.tab_space); } @@ -2999,7 +2994,7 @@ namespace nana{ namespace widgets for (auto & ent : entities) { - const ::nana::char_t* ent_begin = nullptr; + const wchar_t* ent_begin = nullptr; int ent_off = 0; if (str <= ent.begin && ent.begin < str_end) @@ -3094,7 +3089,7 @@ namespace nana{ namespace widgets } else { - auto rtl_string = [this, line_h_pixels, &parser, &clr](point strpos, const nana::char_t* str, std::size_t len, std::size_t str_px, unsigned glyph_front, unsigned glyph_selected){ + auto rtl_string = [this, line_h_pixels, &parser, &clr](point strpos, const wchar_t* str, std::size_t len, std::size_t str_px, unsigned glyph_front, unsigned glyph_selected){ this->_m_draw_parse_string(parser, true, strpos, clr, str, len); //Draw selected part @@ -3109,7 +3104,7 @@ namespace nana{ namespace widgets graph_.bitblt(nana::rectangle(strpos.x + sel_xpos, strpos.y, glyph_selected, line_h_pixels), graph); }; - const nana::char_t * strbeg = linestr.c_str(); + const wchar_t * strbeg = linestr.c_str(); if (a.y == b.y) { for (auto & ent : reordered) diff --git a/source/gui/widgets/spinbox.cpp b/source/gui/widgets/spinbox.cpp index f5836f9e..880fa7f1 100644 --- a/source/gui/widgets/spinbox.cpp +++ b/source/gui/widgets/spinbox.cpp @@ -254,7 +254,7 @@ namespace nana auto scheme = static_cast<::nana::widgets::skeletons::text_editor_scheme*>(API::dev::get_scheme(wd)); editor_ = new ::nana::widgets::skeletons::text_editor(wd, graph, scheme); editor_->multi_lines(false); - editor_->set_accept([this](::nana::char_t ch) + editor_->set_accept([this](wchar_t ch) { auto str = editor_->text(); auto pos = editor_->caret().x; diff --git a/source/gui/widgets/textbox.cpp b/source/gui/widgets/textbox.cpp index f53d0222..95dacd30 100644 --- a/source/gui/widgets/textbox.cpp +++ b/source/gui/widgets/textbox.cpp @@ -422,7 +422,7 @@ namespace drawerbase { return *this; } - void textbox::set_accept(std::function fn) + void textbox::set_accept(std::function fn) { internal_scope_guard lock; auto editor = get_drawer_trigger().editor(); @@ -439,7 +439,7 @@ namespace drawerbase { return *this; } - textbox& textbox::mask(nana::char_t ch) + textbox& textbox::mask(wchar_t ch) { internal_scope_guard lock; auto editor = get_drawer_trigger().editor(); diff --git a/source/gui/widgets/widget.cpp b/source/gui/widgets/widget.cpp index 11b65165..5982ea71 100644 --- a/source/gui/widgets/widget.cpp +++ b/source/gui/widgets/widget.cpp @@ -233,7 +233,7 @@ namespace nana API::umake_event(eh); } - widget& widget::register_shortkey(char_t key) + widget& widget::register_shortkey(wchar_t key) { if (key) API::register_shortkey(handle(), static_cast(key)); diff --git a/source/paint/detail/native_paint_interface.cpp b/source/paint/detail/native_paint_interface.cpp index 5a17879c..db3e32ac 100644 --- a/source/paint/detail/native_paint_interface.cpp +++ b/source/paint/detail/native_paint_interface.cpp @@ -154,14 +154,14 @@ namespace detail return nana::size(); } - nana::size text_extent_size(drawable_type dw, const nana::char_t * text, std::size_t len) + nana::size text_extent_size(drawable_type dw, const wchar_t * text, std::size_t len) { if (nullptr == dw || nullptr == text || 0 == len) return{}; nana::size extents = raw_text_extent_size(dw, text, len); - const nana::char_t* const end = text + len; + const wchar_t* const end = text + len; int tabs = 0; for(; text != end; ++text) { @@ -173,7 +173,7 @@ namespace detail return extents; } - void draw_string(drawable_type dw, const nana::point& pos, const nana::char_t * str, std::size_t len) + void draw_string(drawable_type dw, const nana::point& pos, const wchar_t * str, std::size_t len) { #if defined(NANA_WINDOWS) ::TextOut(dw->context, pos.x, pos.y, str, static_cast(len)); diff --git a/source/paint/graphics.cpp b/source/paint/graphics.cpp index 1227daa1..11117f30 100644 --- a/source/paint/graphics.cpp +++ b/source/paint/graphics.cpp @@ -405,8 +405,8 @@ namespace paint ::GetTextExtentExPoint(handle_->context, str, static_cast(len), 0, 0, dx, &extents); sz.width = dx[end - 1] - (begin ? dx[begin - 1] : 0); unsigned tab_pixels = handle_->string.tab_length * handle_->string.whitespace_pixels; - const nana::char_t * pend = str + end; - for(const nana::char_t * p = str + begin; p != pend; ++p) + const wchar_t * pend = str + end; + for(const wchar_t * p = str + begin; p != pend; ++p) { if(*p == '\t') sz.width += tab_pixels; @@ -906,7 +906,7 @@ namespace paint return *this; } - unsigned graphics::bidi_string(const nana::point& pos, const char_t * str, std::size_t len) + unsigned graphics::bidi_string(const nana::point& pos, const wchar_t * str, std::size_t len) { auto moved_pos = pos; unicode_bidi bidi; diff --git a/source/paint/text_renderer.cpp b/source/paint/text_renderer.cpp index 8d98917b..f9f0c77c 100644 --- a/source/paint/text_renderer.cpp +++ b/source/paint/text_renderer.cpp @@ -11,7 +11,7 @@ namespace nana namespace helper { template - void for_each_line(const nana::char_t * str, std::size_t len, int top, F & f) + void for_each_line(const wchar_t * str, std::size_t len, int top, F & f) { auto head = str; auto end = str + len; @@ -39,7 +39,7 @@ namespace nana : dw(dw), x(x), endpos(endpos), text_align(ta) {} - unsigned operator()(const int top, const nana::char_t * buf, std::size_t bufsize) + unsigned operator()(const int top, const wchar_t * buf, std::size_t bufsize) { nana::point pos{ x, top }; unsigned pixels = 0; @@ -131,7 +131,7 @@ namespace nana this->endpos = x; } - unsigned operator()(const int top, const nana::char_t * buf, std::size_t bufsize) + unsigned operator()(const int top, const wchar_t * buf, std::size_t bufsize) { drawable_type dw = graph.handle(); ::nana::point pos{ x, top }; @@ -187,7 +187,7 @@ namespace nana : graph(graph), x(x), endpos(endpos), text_align(ta) {} - unsigned operator()(const int top, const nana::char_t * buf, std::size_t bufsize) + unsigned operator()(const int top, const wchar_t * buf, std::size_t bufsize) { unsigned pixels = 0; @@ -249,8 +249,8 @@ namespace nana else { //Search the splittable character from idx_head to idx_splitted - const nana::char_t * u = i.begin + idx_splitted; - const nana::char_t * head = i.begin + idx_head; + const wchar_t * u = i.begin + idx_splitted; + const wchar_t * head = i.begin + idx_head; for(; head < u; --u) { @@ -269,7 +269,7 @@ namespace nana else { u = i.begin + idx_splitted; - const nana::char_t * end = i.begin + len; + const wchar_t * end = i.begin + len; for(; u < end; ++u) { if(splittable(head, u - head)) @@ -372,12 +372,12 @@ namespace nana return end; } - static bool splittable(const nana::char_t * str, std::size_t index) + static bool splittable(const wchar_t * str, std::size_t index) { - nana::char_t ch = str[index]; + wchar_t ch = str[index]; if(('0' <= ch && ch <= '9') || ('a' <= ch && ch <= 'z') || ('A' <= ch && ch <= 'Z')) { - nana::char_t prch; + wchar_t prch; if(index) { prch = str[index - 1]; @@ -406,7 +406,7 @@ namespace nana : graph(graph), x(x), endpos(endpos), extents(0) {} - unsigned operator()(int top, const nana::char_t * buf, std::size_t bufsize) + unsigned operator()(int top, const wchar_t * buf, std::size_t bufsize) { unsigned pixels = 0; @@ -467,8 +467,8 @@ namespace nana else { //Search the splittable character from idx_head to idx_splitted - const nana::char_t * u = i.begin + idx_splitted; - const nana::char_t * head = i.begin + idx_head; + const wchar_t * u = i.begin + idx_splitted; + const wchar_t * head = i.begin + idx_head; for(; head < u; --u) { @@ -486,7 +486,7 @@ namespace nana else { u = i.begin + idx_splitted; - const nana::char_t * end = i.begin + len; + const wchar_t * end = i.begin + len; for(; u < end; ++u) { if(draw_string_auto_changing_lines::splittable(head, u - head)) @@ -542,7 +542,7 @@ namespace nana : graph_(graph), text_align_(ta) {} - nana::size text_renderer::extent_size(int x, int y, const char_t* str, std::size_t len, unsigned restricted_pixels) const + nana::size text_renderer::extent_size(int x, int y, const wchar_t* str, std::size_t len, unsigned restricted_pixels) const { nana::size extents; if(graph_) @@ -555,7 +555,7 @@ namespace nana return extents; } - void text_renderer::render(const point& pos, const char_t * str, std::size_t len) + void text_renderer::render(const point& pos, const wchar_t * str, std::size_t len) { if (graph_) { @@ -564,7 +564,7 @@ namespace nana } } - void text_renderer::render(const point& pos, const char_t* str, std::size_t len, unsigned restricted_pixels, bool omitted) + void text_renderer::render(const point& pos, const wchar_t* str, std::size_t len, unsigned restricted_pixels, bool omitted) { if (graph_) { @@ -573,7 +573,7 @@ namespace nana } } - void text_renderer::render(const point& pos, const char_t * str, std::size_t len, unsigned restricted_pixels) + void text_renderer::render(const point& pos, const wchar_t * str, std::size_t len, unsigned restricted_pixels) { if (graph_) { diff --git a/source/system/platform.cpp b/source/system/platform.cpp index d486f368..042c5892 100644 --- a/source/system/platform.cpp +++ b/source/system/platform.cpp @@ -98,12 +98,13 @@ namespace system } //open an url through a default browser - void open_url(const std::wstring& url) + void open_url(const std::string& url_utf8) { - if(url.empty()) + if(url_utf8.empty()) return; #if defined(NANA_WINDOWS) + std::wstring url = to_wstring(url_utf8); 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,