diff --git a/CMakeLists.txt b/CMakeLists.txt index e416d60c..f2024d27 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,7 +7,7 @@ #https://cmake.org/cmake-tutorial/ #https://cmake.org/cmake/help/v3.3/module/CMakeDependentOption.html?highlight=cmakedependentoption -# use CACHE FORCE or set(USE_meganz_mingw_std_threads ON) or delete CMakecache.txt or the entirely build dir +# use CACHE FORCE or set(USE_meganz_mingw_std_threads ON) or delete CMakecache.txt or the entirely build dir # if your changes don't execute option(USE_meganz_mingw_std_threads "replaced boost.thread with meganz's mingw-std-threads." OFF) option(USE_UNICODE "Use Unicode Character Set" ON) @@ -143,16 +143,15 @@ aux_source_directory(${NANA_SOURCE_DIR}/paint/detail NANA_PAINT_DETAIL_SOURCE) aux_source_directory(${NANA_SOURCE_DIR}/system NANA_SYSTEM_SOURCE) aux_source_directory(${NANA_SOURCE_DIR}/threads NANA_THREADS_SOURCE) -#To show .h files in Visual Studio, add them to the list of sources in add_executable / add_library -#and Use SOURCE_GROUP if all your sources are in the same directory +#To show .h files in Visual Studio, add them to the list of sources in add_executable / add_library +#and Use SOURCE_GROUP if all your sources are in the same directory +if(NOT APPLE) add_library(${PROJECT_NAME} ${NANA_SOURCE} ${NANA_DETAIL_SOURCE} ${NANA_FILESYSTEM_SOURCE} -if(NOT APPLE) ${NANA_AUDIO_SOURCE} ${NANA_AUDIO_DETAIL_SOURCE} -endif (NOT APPLE) ${NANA_GUI_SOURCE} ${NANA_GUI_DETAIL_SOURCE} ${NANA_GUI_WIDGETS_SOURCE} @@ -160,11 +159,26 @@ endif (NOT APPLE) ${NANA_PAINT_SOURCE} ${NANA_PAINT_DETAIL_SOURCE} ${NANA_SYSTEM_SOURCE} - ${NANA_THREADS_SOURCE}) + ${NANA_THREADS_SOURCE}) +endif (NOT APPLE) + if(APPLE) - #Headers: use INCLUDE_DIRECTORIES - # Libraries: use FIND_LIBRARY and link with the result of it (try to avoid LINK_DIRECTORIES +add_library(${PROJECT_NAME} ${NANA_SOURCE} + ${NANA_DETAIL_SOURCE} + ${NANA_FILESYSTEM_SOURCE} + ${NANA_AUDIO_SOURCE} + ${NANA_AUDIO_DETAIL_SOURCE} + ${NANA_GUI_SOURCE} + ${NANA_GUI_DETAIL_SOURCE} + ${NANA_GUI_WIDGETS_SOURCE} + ${NANA_GUI_WIDGETS_SKELETONS_SOURCE} + ${NANA_PAINT_SOURCE} + ${NANA_PAINT_DETAIL_SOURCE} + ${NANA_SYSTEM_SOURCE} + ${NANA_THREADS_SOURCE}) + #Headers: use INCLUDE_DIRECTORIES + # Libraries: use FIND_LIBRARY and link with the result of it (try to avoid LINK_DIRECTORIES target_link_libraries(${PROJECT_NAME} -L/opt/X11/lib/ -lX11 -lXft -lpng -liconv) endif(APPLE) diff --git a/build/codeblocks/nana.cbp b/build/codeblocks/nana.cbp index 49f61ad7..e0d020a6 100644 --- a/build/codeblocks/nana.cbp +++ b/build/codeblocks/nana.cbp @@ -119,7 +119,6 @@ - diff --git a/build/vc2013/nana.vcxproj b/build/vc2013/nana.vcxproj index 01db0e79..82ed86e6 100644 --- a/build/vc2013/nana.vcxproj +++ b/build/vc2013/nana.vcxproj @@ -256,7 +256,6 @@ - diff --git a/build/vc2013/nana.vcxproj.filters b/build/vc2013/nana.vcxproj.filters index d2c700e8..1d5d8d11 100644 --- a/build/vc2013/nana.vcxproj.filters +++ b/build/vc2013/nana.vcxproj.filters @@ -291,9 +291,6 @@ Source Files\nana - - Source Files\nana - Source Files\nana diff --git a/build/vc2015/nana.vcxproj b/build/vc2015/nana.vcxproj index 89ceaaa3..139797f3 100644 --- a/build/vc2015/nana.vcxproj +++ b/build/vc2015/nana.vcxproj @@ -249,7 +249,6 @@ - diff --git a/build/vc2015/nana.vcxproj.filters b/build/vc2015/nana.vcxproj.filters index 8130c2bc..9781e955 100644 --- a/build/vc2015/nana.vcxproj.filters +++ b/build/vc2015/nana.vcxproj.filters @@ -69,9 +69,6 @@ Source Files - - Source Files - Source Files diff --git a/include/nana/audio/detail/audio_stream.hpp b/include/nana/audio/detail/audio_stream.hpp index 5fe9d39c..d148f98f 100644 --- a/include/nana/audio/detail/audio_stream.hpp +++ b/include/nana/audio/detail/audio_stream.hpp @@ -59,7 +59,7 @@ namespace nana{ namespace audio{ unsigned cksize; }; public: - bool open(const nana::string& file); + bool open(const std::string& file); void close(); bool empty() const; const wave_spec::format_chunck & format() const; diff --git a/include/nana/audio/player.hpp b/include/nana/audio/player.hpp index 24378214..3fc1acca 100644 --- a/include/nana/audio/player.hpp +++ b/include/nana/audio/player.hpp @@ -14,10 +14,10 @@ namespace nana{ namespace audio struct implementation; public: player(); - player(const nana::string& file); + player(const std::string& file); ~player(); - bool open(const nana::string& file); + bool open(const std::string& file); void play(); void close(); private: diff --git a/include/nana/basic_types.hpp b/include/nana/basic_types.hpp index da37272d..e990a681 100644 --- a/include/nana/basic_types.hpp +++ b/include/nana/basic_types.hpp @@ -67,7 +67,8 @@ namespace nana } }; - typedef std::basic_string > cistring; + using cistring = std::basic_string>; + using ciwstring = std::basic_string>; namespace detail diff --git a/include/nana/charset.hpp b/include/nana/charset.hpp index 6c36159b..725fdf96 100644 --- a/include/nana/charset.hpp +++ b/include/nana/charset.hpp @@ -18,6 +18,24 @@ namespace nana { + namespace utf + { + /// Attempt to get a pointer to a character of UTF-8 string by a specifed character index. + /// @param text_utf8 A string encoded as UTF-8. + /// @param pos The unicode character index. + /// @returns A pointer to the unicode character. It returns a null if pos is out of range. + const char* char_ptr(const char* text_utf8, unsigned pos); + const char* char_ptr(const ::std::string& text_utf8, unsigned pos); + + /// Get the unicode character by a specified character index. + /// @param text_utf8 A string encoded as UTF-8. + /// @param pos The unicode character index. + /// @param len A unsigned pointer to receive the number of bytes it takes in UTF-8 encoded. If len is a nullptr, it is ignored. + /// @returns A unicode character. '\0' if pos is out of range. + wchar_t char_at(const char* text_utf8, unsigned pos, unsigned * len); + wchar_t char_at(const ::std::string& text_utf8, unsigned pos, unsigned * len); + } + enum class unicode { utf8, utf16, utf32 diff --git a/include/nana/deploy.hpp b/include/nana/deploy.hpp index a4414ac9..8d9f2cb3 100644 --- a/include/nana/deploy.hpp +++ b/include/nana/deploy.hpp @@ -23,7 +23,6 @@ #include #include - //Implement workarounds for GCC/MinGW which version is below 4.8.2 #if defined(STD_NUMERIC_CONVERSIONS_NOT_SUPPORTED) namespace std @@ -93,56 +92,61 @@ namespace std } #endif - -#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 - } - #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 { - 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 -} + /// Checks whether a specified text is utf8 encoding + bool is_utf8(const char* str, unsigned len); + void throw_not_utf8(const std::string& text); + void throw_not_utf8(const char*, unsigned len); + void throw_not_utf8(const char*); + + std::wstring utf8_cast(const std::string&); + std::string utf8_cast(const std::wstring&); + + const std::string& to_utf8(const std::string&); + std::string to_utf8(const std::wstring&); + + std::wstring to_wstring(const std::string& utf8_str); + const std::wstring& to_wstring(const std::wstring& wstr); + std::wstring&& to_wstring(std::wstring&& wstr); #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" + std::string to_osmbstr(const std::string& text_utf8); +#else + std::string to_osmbstr(std::string text_utf8); #endif + + namespace detail + { +#if defined(NANA_WINDOWS) + using native_string_type = std::wstring; +#else //POSIX + using native_string_type = std::string; +#endif + } + +#if defined(NANA_WINDOWS) + const detail::native_string_type to_nstring(const std::string&); + const detail::native_string_type& to_nstring(const std::wstring&); + detail::native_string_type to_nstring(std::string&&); + detail::native_string_type&& to_nstring(std::wstring&&); +#else //POSIX + const detail::native_string_type& to_nstring(const std::string&); + const detail::native_string_type to_nstring(const std::wstring&); + detail::native_string_type&& to_nstring(std::string&&); + detail::native_string_type to_nstring(std::wstring&&); +#endif + detail::native_string_type to_nstring(int); + detail::native_string_type to_nstring(double); + detail::native_string_type to_nstring(std::size_t); +} + + namespace nana { - bool is_incomplete(const nana::string& str, unsigned pos); - 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/msg_packet.hpp b/include/nana/detail/linux_X11/msg_packet.hpp index b1fc3dec..ea24091f 100644 --- a/include/nana/detail/linux_X11/msg_packet.hpp +++ b/include/nana/detail/linux_X11/msg_packet.hpp @@ -22,7 +22,7 @@ namespace detail Window window; int x; int y; - std::vector * files; + std::vector * files; }mouse_drop; }u; }; diff --git a/include/nana/detail/linux_X11/platform_spec.hpp b/include/nana/detail/linux_X11/platform_spec.hpp index 0a013ed6..12f4e94a 100644 --- a/include/nana/detail/linux_X11/platform_spec.hpp +++ b/include/nana/detail/linux_X11/platform_spec.hpp @@ -70,7 +70,7 @@ namespace detail struct font_tag { - nana::string name; + std::string name; unsigned height; unsigned weight; bool italic; @@ -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(); @@ -203,7 +203,7 @@ namespace detail void default_native_font(const font_ptr_t&); unsigned font_size_to_height(unsigned) const; unsigned font_height_to_size(unsigned) const; - font_ptr_t make_native_font(const nana::char_t* name, unsigned height, unsigned weight, bool italic, bool underline, bool strick_out); + font_ptr_t make_native_font(const char* name, unsigned height, unsigned weight, bool italic, bool underline, bool strick_out); Display* open_display(); void close_display(); diff --git a/include/nana/detail/win32/platform_spec.hpp b/include/nana/detail/win32/platform_spec.hpp index b129406b..dc6329fe 100644 --- a/include/nana/detail/win32/platform_spec.hpp +++ b/include/nana/detail/win32/platform_spec.hpp @@ -80,7 +80,7 @@ namespace detail struct font_tag { - nana::string name; + native_string_type name; unsigned height; unsigned weight; bool italic; @@ -186,7 +186,7 @@ namespace detail void default_native_font(const font_ptr_t&); unsigned font_size_to_height(unsigned) const; unsigned font_height_to_size(unsigned) const; - font_ptr_t make_native_font(const nana::char_t* name, unsigned height, unsigned weight, bool italic, bool underline, bool strike_out); + font_ptr_t make_native_font(const char* name, unsigned height, unsigned weight, bool italic, bool underline, bool strike_out); static platform_spec& instance(); diff --git a/include/nana/filesystem/file_iterator.hpp b/include/nana/filesystem/file_iterator.hpp index 94f37001..26df3f10 100644 --- a/include/nana/filesystem/file_iterator.hpp +++ b/include/nana/filesystem/file_iterator.hpp @@ -1,12 +1,12 @@ /* * A File Iterator Implementation - * Copyright(C) 2003 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 * http://www.boost.org/LICENSE_1_0.txt) * - * @file: stdex/filesystem/file_iterator.hpp + * @file: filesystem/file_iterator.hpp * @description: * file_iterator is a toolkit for applying each file and directory in a * specified path. @@ -39,9 +39,9 @@ namespace filesystem #ifdef NANA_WINDOWS fileinfo(const WIN32_FIND_DATA& wfd); #elif defined(NANA_POSIX) - 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_ = file_path; + if(path_.size() && path_.back() != '/') path_ += '/'; - find_handle_t handle = opendir(path_.c_str()); + auto handle = opendir(path_.c_str()); + end_ = true; if(handle) { @@ -143,7 +143,7 @@ namespace filesystem struct stat fst; if(stat((path_ + dnt->d_name).c_str(), &fst) == 0) { - value_ = value_type(nana::charset(dnt->d_name), fst); + value_ = value_type(dnt->d_name, fst); } else { @@ -226,9 +226,8 @@ namespace filesystem #if defined(NANA_WINDOWS) WIN32_FIND_DATA wfd_; - nana::string path_; -#elif defined(NANA_LINUX) || defined(NANA_MACOS) - std::string path_; +#else + 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..6425f922 100644 --- a/include/nana/filesystem/filesystem.hpp +++ b/include/nana/filesystem/filesystem.hpp @@ -1,7 +1,7 @@ /* * A ISO C++ filesystem Implementation * Nana C++ Library(http://www.nanapro.org) - * Copyright(C) 2003-2015 Jinhao(cnjinhao@hotmail.com) + * Copyright(C) 2003-2016 Jinhao(cnjinhao@hotmail.com) * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at @@ -36,6 +36,7 @@ #include #include #include +#include #include @@ -55,25 +56,27 @@ namespace nana { namespace experimental { namespace filesystem { - enum class file_type - { - none = 0, ///< has not been determined or an error occurred while trying to determine - not_found = -1, ///< Pseudo-type: file was not found. Is not considered an error - regular = 1, - directory = 2 , - symlink =3, ///< Symbolic link file - block =4, ///< Block special file - character= 5 , ///< Character special file - fifo = 6 , ///< FIFO or pipe file - socket =7, - unknown= 8 ///< The file does exist, but is of an operating system dependent type not covered by any of the other - }; + enum class file_type + { + none = 0, ///< has not been determined or an error occurred while trying to determine + not_found = -1, ///< Pseudo-type: file was not found. Is not considered an error + regular = 1, + directory = 2 , + symlink =3, ///< Symbolic link file + block =4, ///< Block special file + character= 5 , ///< Character special file + fifo = 6 , ///< FIFO or pipe file + socket =7, + unknown= 8 ///< The file does exist, but is of an operating system dependent type not covered by any of the other + }; - enum class perms - { - none =0, ///< There are no permissions set for the file. - unknown = 0xFFFF ///< not known, such as when a file_status object is created without specifying the permissions - }; + enum class perms + { + none = 0, ///< There are no permissions set for the file. + all = 0x1FF, ///< owner_all | group_all | others_all + mask = 0xFFF, ///< all | set_uid | set_gid | sticky_bit. + unknown = 0xFFFF ///< not known, such as when a file_status object is created without specifying the permissions + }; //enum class copy_options; //enum class directory_options; @@ -96,35 +99,28 @@ namespace filesystem uintmax_t free; uintmax_t available; }; - using file_time_type = std::chrono::time_point< std::chrono::system_clock>;// trivial-clock> ; - class file_status - { - file_type m_ft = file_type::none; - perms m_prms = perms::unknown; + using file_time_type = std::chrono::time_point;// trivial-clock> ; - public: - explicit file_status(file_type ft = file_type::none, perms prms = perms::unknown) - :m_ft{ft}, m_prms{prms} - {} + class file_status + { + file_type m_ft = file_type::none; + perms m_prms = perms::unknown; - file_status(const file_status& fs) : m_ft{fs.m_ft}, m_prms{fs.m_prms}{} // = default; - file_status(file_status&& fs) : m_ft{fs.m_ft}, m_prms{fs.m_prms}{} // = default; + public: + explicit file_status(file_type ft = file_type::none, perms prms = perms::unknown); - ~file_status(){}; - file_status& operator=(const file_status&) = default; - file_status& operator=(file_status&&fs) // = default; - { - m_ft=fs.m_ft; m_prms = fs.m_prms; - return *this; - } - // observers - file_type type() const { return m_ft;} - perms permissions() const { return m_prms;} - // modifiers - void type (file_type ft) { m_ft=ft ;} - void permissions(perms prms) { m_prms = prms; } - }; + // observers + file_type type() const; + perms permissions() const; + + // modifiers + void type(file_type ft); + void permissions(perms prms); + private: + file_type value_; + perms perms_; + }; /// concerned only with lexical and syntactic aspects and does not necessarily exist in /// external storage, and the pathname is not necessarily valid for the current operating system @@ -136,29 +132,54 @@ 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&); + + template + path(const Source& source) + { + _m_assign(source); + } + + int compare(const path& other) const; bool empty() const; - path root() const; + path extension() 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; + + std::string string() const; + std::wstring wstring() const; + std::string u8string() const; private: - nana::string text_; -#else - public: - std::string to_string() const { return text_; } - operator std::string() const { return text_; } + void _m_assign(const std::string& source_utf8); + void _m_assign(const std::wstring& source); 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 +214,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 +252,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_); @@ -264,8 +283,7 @@ namespace filesystem (FILE_ATTRIBUTE_DIRECTORY & wfd_.dwFileAttributes) == FILE_ATTRIBUTE_DIRECTORY, wfd_.nFileSizeLow); - #elif defined(NANA_LINUX) || defined(NANA_MACOS) - path_ = nana::charset(file_path); + #elif defined(NANA_POSIX) if(path_.size() && (path_[path_.size() - 1] != '/')) path_ += '/'; find_handle_t handle = opendir(path_.c_str()); @@ -293,7 +311,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; } } @@ -340,7 +358,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); @@ -373,10 +391,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_; @@ -401,11 +418,10 @@ namespace filesystem } - // file_status status(const path& p); - bool file_attrib(const nana::string& file, attribute&); + file_status status(const path& p); inline bool is_directory(file_status s) { return s.type() == file_type::directory ;} - inline bool is_directory(const path& p) { return directory_iterator(p)->attr.directory; }//works?? + bool is_directory(const path& p); inline bool is_directory(const directory_entry& d) { return d.attr.directory; } //bool is_directory(const path& p, error_code& ec) noexcept; @@ -419,46 +435,61 @@ namespace filesystem } //bool is_empty(const path& p, error_code& ec) noexcept; - uintmax_t file_size(const nana::string& file); // deprecate? - inline uintmax_t file_size(const path& p){return file_size(p.filename());} - //uintmax_t file_size(const path& p, error_code& ec) noexcept; - //long long filesize(const nana::string& file); + std::uintmax_t file_size(const path& p); + //uintmax_t file_size(const path& p, error_code& ec) noexcept; - bool create_directories(const path& p); - //bool create_directories(const path& p, error_code& ec) noexcept; - bool create_directory(const path& p); - //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 nana::string& dir, bool & if_exist); - inline bool create_directory(const path& p, bool & if_exist) - { - return create_directory(p.filename(), if_exist); - }; - - - bool modified_file_time(const nana::string& file, struct tm&); - - - nana::string path_user(); + bool create_directories(const path& p); + //bool create_directories(const path& p, error_code& ec) noexcept; + bool create_directory(const path& p); + //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; - - path current_path(); - //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 modified_file_time(const std::wstring& file, struct tm&); + path path_user(); + + path current_path(); + //path current_path(error_code& ec); + void current_path(const path& p); + //void current_path(const path& p, error_code& ec) noexcept; - //bool remove(const path& p); - //bool remove(const path& p, error_code& ec) noexcept; - bool rmfile(const nana::char_t* file); + //bool remove(const path& p); + //bool remove(const path& p, error_code& ec) noexcept; + bool rmfile(const path& p); - //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); + //uintmax_t remove_all(const path& p); + //uintmax_t remove_all(const path& p, error_code& ec) noexcept; + + bool rmdir(const path& p, 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 d52e54dd..7ddd4298 100644 --- a/include/nana/filesystem/fs_utility.hpp +++ b/include/nana/filesystem/fs_utility.hpp @@ -24,41 +24,13 @@ namespace filesystem tm modified; }; - bool file_attrib(const nana::string& file, attribute&); - long long filesize(const nana::string& file); + bool modified_file_time(const ::std::string& file, struct tm&); - bool mkdir(const nana::string& dir, bool & if_exist); - bool modified_file_time(const nana::string& file, struct tm&); + std::wstring path_user(); - nana::string path_user(); - nana::string path_current(); + bool rmfile(const char* file_utf8); + bool rmdir(const char* dir, bool fails_if_not_empty); - bool rmfile(const nana::char_t* file); - bool rmdir(const nana::char_t* 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/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/basic_window.hpp b/include/nana/gui/detail/basic_window.hpp index ac5db7c1..207f7e3b 100644 --- a/include/nana/gui/detail/basic_window.hpp +++ b/include/nana/gui/detail/basic_window.hpp @@ -145,7 +145,7 @@ namespace detail basic_window *parent; basic_window *owner; - ::nana::string title; + native_string_type title; ::nana::detail::drawer drawer; //Self Drawer with owen graphics basic_window* root_widget; //A pointer refers to the root basic window, if the window is a root, the pointer refers to itself. paint::graphics* root_graph; //Refer to the root buffer graphics diff --git a/include/nana/gui/detail/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/detail/native_window_interface.hpp b/include/nana/gui/detail/native_window_interface.hpp index 6a88c0a7..aade67a5 100644 --- a/include/nana/gui/detail/native_window_interface.hpp +++ b/include/nana/gui/detail/native_window_interface.hpp @@ -34,6 +34,8 @@ namespace detail unsigned extra_height; //extra border size, it is useful in Windows, ignore in X11 always 0 }; + using native_string_type = ::nana::detail::native_string_type; + static nana::size primary_monitor_size(); static rectangle screen_area_from_point(const point&); static window_result create_window(native_window_type, bool nested, const rectangle&, const appearance&); @@ -65,8 +67,8 @@ namespace detail static void window_size(native_window_type, const size&); static void get_window_rect(native_window_type, rectangle&); - static void window_caption(native_window_type, const nana::string&); - static nana::string window_caption(native_window_type); + static void window_caption(native_window_type, const native_string_type&); + static native_string_type window_caption(native_window_type); static void capture_window(native_window_type, bool); static nana::point cursor_position(); static native_window_type get_owner_window(native_window_type); diff --git a/include/nana/gui/detail/widget_notifier_interface.hpp b/include/nana/gui/detail/widget_notifier_interface.hpp index 204bdeea..81a0a28f 100644 --- a/include/nana/gui/detail/widget_notifier_interface.hpp +++ b/include/nana/gui/detail/widget_notifier_interface.hpp @@ -30,8 +30,8 @@ namespace nana virtual widget* widget_ptr() const = 0; virtual void destroy() = 0; - virtual std::wstring caption() = 0; - virtual void caption(std::wstring) = 0; + virtual ::nana::detail::native_string_type caption() = 0; + virtual void caption(::nana::detail::native_string_type) = 0; }; } } diff --git a/include/nana/gui/dragger.hpp b/include/nana/gui/dragger.hpp index 9846b672..e34094ef 100644 --- a/include/nana/gui/dragger.hpp +++ b/include/nana/gui/dragger.hpp @@ -1,6 +1,20 @@ +/* +* A Dragger Implementation +* Nana C++ Library(http://www.nanapro.org) +* Copyright(C) 2003-2016 Jinhao(cnjinhao@hotmail.com) +* +* Distributed under the Boost Software License, Version 1.0. +* (See accompanying file LICENSE_1_0.txt or copy at +* http://www.boost.org/LICENSE_1_0.txt) +* +* @file: nana/gui/dragger.hpp +*/ + #ifndef NANA_GUI_DRAGGER_HPP #define NANA_GUI_DRAGGER_HPP -#include "programming_interface.hpp" +#include "basis.hpp" +#include "../basic_types.hpp" +#include "../traits.hpp" namespace nana { @@ -18,6 +32,10 @@ namespace nana public: dragger(); ~dragger(); + + dragger(dragger&&); + dragger& operator=(dragger&&); + void target(window); void target(window, const rectangle& restrict_area, nana::arrange); void remove_target(window); diff --git a/include/nana/gui/filebox.hpp b/include/nana/gui/filebox.hpp index d60ec5c2..7d8b1b85 100644 --- a/include/nana/gui/filebox.hpp +++ b/include/nana/gui/filebox.hpp @@ -25,7 +25,7 @@ namespace nana filebox(filebox&&) = delete; filebox& operator=(filebox&&) = delete; public: - using filters = std::vector>; + using filters = std::vector>; filebox(bool is_open_mode); filebox(window owner, bool is_open_mode); @@ -37,21 +37,21 @@ namespace nana /// Change owner window void owner(window); - /** @brief specify a title for the dialog - * @param string a text for title - */ - nana::string title( nana::string new_title); ///< . Set a new title for the dialog and \return the old title + /// specify a title for the dialog + /// @param string a text for title + /// @return old title. + ::std::string title( ::std::string new_title); ///< . Set a new title for the dialog and \return the old title /** @brief specify a suggestion directory * @param string a path of initial directory * @note the behavior of init_path is different between Win7 and Win2K/XP/Vista, but its behavior under Linux is conformed with Win7. */ - filebox& init_path(const nana::string&); ///< Suggested init path used to locate a directory when the filebox starts. - filebox& init_file(const nana::string&); ///< Init file, if it contains a path, the init path is replaced by the path of init file. + filebox& init_path(const ::std::string&); ///< Suggested init path used to locate a directory when the filebox starts. + filebox& init_file(const ::std::string&); ///< Init file, if it contains a path, the init path is replaced by the path of init file. /// \brief Add a filetype filter. /// To specify multiple filter in a single description, use a semicolon to separate the patterns(for example,"*.TXT;*.DOC;*.BAK"). - filebox& add_filter(const nana::string& description, ///< for example. "Text File" - const nana::string& filetype ///< filter pattern(for example, "*.TXT") + filebox& add_filter(const ::std::string& description, ///< for example. "Text File" + const ::std::string& filetype ///< filter pattern(for example, "*.TXT") ); filebox& add_filter(const filters &ftres) @@ -62,16 +62,14 @@ namespace nana }; - nana::string path() const; - nana::string file() const; + ::std::string path() const; + ::std::string file() const; - /** @brief Display the filebox dialog - */ + /// Display the filebox dialog bool show() const; - /** @brief Display the filebox dialog - * @note A function object method alternative to show() - */ + /// Display the filebox dialog + /// A function object method alternative to show() bool operator()() const { return show(); diff --git a/include/nana/gui/msgbox.hpp b/include/nana/gui/msgbox.hpp index 3bebcf79..af5a1437 100644 --- a/include/nana/gui/msgbox.hpp +++ b/include/nana/gui/msgbox.hpp @@ -43,10 +43,10 @@ namespace nana msgbox& operator=(const msgbox&); /// Construct that creates a message box with a specified title and default button. - msgbox(const nana::string&); + msgbox(const ::std::string&); /// Construct that creates a message box with an owner windoow, a specified title and buttons. - msgbox(window, const nana::string&, button_t = ok); + msgbox(window, const ::std::string&, button_t = ok); /// Sets an icon for informing user. msgbox& icon(icon_t); @@ -55,10 +55,10 @@ namespace nana void clear(); /// Writes a string to the buffer. - msgbox & operator<<(const nana::string&); + msgbox & operator<<(const std::wstring&); /// Writes a string to the buffer. - msgbox & operator<<(const nana::char_t*); + msgbox & operator<<(const wchar_t*); /// Writes a string to the buffer. msgbox & operator<<(const nana::charset&); @@ -86,7 +86,7 @@ namespace nana private: std::stringstream sstream_; window wd_; - nana::string title_; + std::string title_; button_t button_; icon_t icon_; }; @@ -97,7 +97,7 @@ namespace nana { virtual ~abstract_content() = default; - virtual const ::nana::string& label() const = 0; + virtual const ::std::string& label() const = 0; virtual window create(window, unsigned label_px) = 0; virtual unsigned fixed_pixels() const; }; @@ -107,13 +107,13 @@ namespace nana { struct implement; public: - integer(::nana::string label, int init_value, int begin, int last, int step); + integer(::std::string label, int init_value, int begin, int last, int step); ~integer(); int value() const; private: //Implementation of abstract_content - const ::nana::string& label() const override; + const ::std::string& label() const override; window create(window, unsigned label_px) override; private: std::unique_ptr impl_; @@ -124,13 +124,13 @@ namespace nana { struct implement; public: - real(::nana::string label, double init_value, double begin, double last, double step); + real(::std::string label, double init_value, double begin, double last, double step); ~real(); double value() const; private: //Implementation of abstract_content - const ::nana::string& label() const override; + const ::std::string& label() const override; window create(window, unsigned label_px) override; private: std::unique_ptr impl_; @@ -144,8 +144,8 @@ namespace nana text(const text&) = delete; text& operator=(const text&) = delete; public: - text(::nana::string label, ::nana::string init_text = ::nana::string()); - text(::nana::string label, std::vector<::nana::string>); + text(::std::string label, ::std::string init_text = ::std::string()); + text(::std::string label, std::vector<::std::string>); ~text(); @@ -154,10 +154,10 @@ namespace nana void mask_character(wchar_t ch); - ::nana::string value() const; + ::std::string value() const; private: //Implementation of abstract_content - const ::nana::string& label() const override; + const ::std::string& label() const override; window create(window, unsigned label_px) override; private: std::unique_ptr impl_; @@ -168,17 +168,17 @@ namespace nana { struct implement; public: - date(::nana::string label); + date(::std::string label); ~date(); - ::nana::string value() const; + ::std::string value() const; int year() const; int month() const; //[1, 12] int day() const; //[1, 31] private: //Implementation of abstract_content - const ::nana::string& label() const override; + const ::std::string& label() const override; window create(window, unsigned label_px) override; unsigned fixed_pixels() const override; private: @@ -190,19 +190,19 @@ namespace nana { struct implement; public: - path(::nana::string label, const ::nana::filebox&); + path(::std::string label, const ::nana::filebox&); ~path(); - ::nana::string value() const; + ::std::string value() const; private: //Implementation of abstract_content - const ::nana::string& label() const override; + const ::std::string& label() const override; window create(window, unsigned label_px) override; private: std::unique_ptr impl_; }; - inputbox(window, ::nana::string description, ::nana::string title = ::nana::string()); + inputbox(window, ::std::string description, ::std::string title = ::std::string()); void image(::nana::paint::image, bool is_left, const rectangle& valid_area = {}); void image_v(::nana::paint::image, bool is_top, const rectangle& valid_area = {}); @@ -246,8 +246,8 @@ namespace nana bool _m_open(std::vector&, bool modal); private: window owner_; - ::nana::string description_; - ::nana::string title_; + ::std::string description_; + ::std::string title_; std::function verifier_; ::nana::paint::image images_[4]; ::nana::rectangle valid_areas_[4]; diff --git a/include/nana/gui/notifier.hpp b/include/nana/gui/notifier.hpp index c6eea9da..a557fd45 100644 --- a/include/nana/gui/notifier.hpp +++ b/include/nana/gui/notifier.hpp @@ -55,9 +55,9 @@ namespace nana notifier(window); ~notifier(); void close(); - void text(const nana::string&); - void icon(const nana::string& icon_file); - void insert_icon(const nana::string& icon_file); + void text(const ::std::string&); + void icon(const ::std::string& icon_file); + void insert_icon(const ::std::string& icon_file); void period(unsigned millisecond); detail::notifier_events& events(); window handle() const; diff --git a/include/nana/gui/place.hpp b/include/nana/gui/place.hpp index 2e3676de..8f32545b 100644 --- a/include/nana/gui/place.hpp +++ b/include/nana/gui/place.hpp @@ -42,13 +42,17 @@ namespace nana : init_(std::move(initializer)) {} - agent(const nana::char_t* text) + agent(const char* text) : text_(text) - {} + { + throw_not_utf8(text); + } - agent(nana::string text, std::function initializer = {}) + agent(std::string text, std::function initializer = {}) : text_(std::move(text)), init_(std::move(initializer)) - {} + { + throw_not_utf8(text_); + } private: std::unique_ptr create(nana::window handle) const override @@ -60,7 +64,7 @@ namespace nana return std::move(ptr); } private: - nana::string text_; + std::string text_; std::function init_; }; @@ -79,8 +83,8 @@ namespace nana public: field_interface() = default; virtual ~field_interface() = default; - virtual field_interface& operator<<(const nana::char_t* label) = 0; - virtual field_interface& operator<<(nana::string label) = 0; + virtual field_interface& operator<<(const char* label) = 0; + virtual field_interface& operator<<(std::string label) = 0; virtual field_interface& operator<<(window) = 0; virtual field_interface& fasten(window) = 0; diff --git a/include/nana/gui/programming_interface.hpp b/include/nana/gui/programming_interface.hpp index 6227f6bb..1faba2a9 100644 --- a/include/nana/gui/programming_interface.hpp +++ b/include/nana/gui/programming_interface.hpp @@ -72,8 +72,8 @@ namespace API widget_colors* get_scheme(window); void attach_drawer(widget&, drawer_trigger&); - nana::string window_caption(window) throw(); - void window_caption(window, nana::string); + ::nana::detail::native_string_type window_caption(window) throw(); + void window_caption(window, ::nana::detail::native_string_type); window create_window(window, bool nested, const rectangle&, const appearance&, widget* attached); window create_widget(window, const rectangle&, widget* attached); @@ -83,6 +83,9 @@ namespace API paint::graphics* window_graphics(window); void delay_restore(bool); + + void register_menu_window(window, bool has_keyboard); + void set_menubar(window wd, bool attach); }//end namespace dev @@ -140,7 +143,7 @@ namespace API void exit(); - nana::string transform_shortkey_text(nana::string text, nana::string::value_type &shortkey, nana::string::size_type *skpos); + std::string transform_shortkey_text(std::string text, wchar_t &shortkey, std::string::size_type *skpos); bool register_shortkey(window, unsigned long); void unregister_shortkey(window); @@ -271,8 +274,8 @@ namespace API void update_window(window); ///< Copies the off-screen buffer to the screen for immediate display. void window_caption(window, const std::string& title_utf8); - void window_caption(window, const nana::string& title); - nana::string window_caption(window); + void window_caption(window, const std::wstring& title); + ::std::string window_caption(window); void window_cursor(window, cursor); cursor window_cursor(window); @@ -310,8 +313,8 @@ namespace API void eat_tabstop(window, bool); window move_tabstop(window, bool next); ///< Sets the focus to the window which tabstop is near to the specified window. - bool glass_window(window); /// \deprecated - bool glass_window(window, bool); /// \deprecated + //bool glass_window(window); //deprecated + //bool glass_window(window, bool); //deprecated /// Sets the window active state. If a window active state is false, the window will not obtain the focus when a mouse clicks on it wich will be obteined by take_if_has_active_false. void take_active(window, bool has_active, window take_if_has_active_false); @@ -328,10 +331,6 @@ namespace API window find_window(const nana::point& mspos); - void register_menu_window(window, bool has_keyboard); - bool attach_menubar(window menubar); - void detach_menubar(window menubar); - bool is_window_zoomed(window, bool ask_for_max); /// void create_event_agent(::nana::categorize& wdg) @@ -155,8 +155,9 @@ namespace nana : public widget_object> { public: - typedef T value_type; ///< The type of objects stored - typedef drawerbase::categorize::renderer renderer; ///< The interface for user-defined renderer. + using native_string_type = widget::native_string_type; + using value_type = T; ///< The type of objects stored + using renderer = drawerbase::categorize::renderer; ///< The interface for user-defined renderer. categorize() { @@ -174,13 +175,25 @@ namespace nana { } - categorize(window wd, const nana::string& text, bool visible = true) + categorize(window wd, const std::string& text_utf8, bool visible = true) + : categorize(wd, ::nana::rectangle(), visible) + { + this->caption(text_utf8); + } + + categorize(window wd, const char* text_utf8, bool visible = true) + : categorize(wd, ::nana::rectangle(), visible) + { + this->caption(text_utf8); + } + + categorize(window wd, const std::wstring& text, bool visible = true) : categorize(wd, ::nana::rectangle(), visible) { this->caption(text); } - categorize(window wd, const nana::char_t* text, bool visible = true) + categorize(window wd, const wchar_t* text, bool visible = true) : categorize(wd, ::nana::rectangle(), visible) { this->caption(text); @@ -189,7 +202,7 @@ namespace nana /// Insert a new category with a specified name and the object of value type. /// The new category would be inserted as a child in current category, /// and after inserting, the new category is replaced of the current category as a new current one. - categorize& insert(const nana::string& name, const value_type& value) + categorize& insert(const std::string& name, const value_type& value) { this->get_drawer_trigger().insert(name, value); API::update_window(*this); @@ -197,15 +210,16 @@ namespace nana } /// Inserts a child category into current category. - categorize& childset(const nana::string& name, const value_type& value) + categorize& childset(const std::string& name, const value_type& value) { + throw_not_utf8(name); if(this->get_drawer_trigger().childset(name, value)) API::update_window(*this); return *this; } /// Erases a child category with a specified name from current category. - categorize& childset_erase(const nana::string& name) + categorize& childset_erase(const std::string& name) { if(this->get_drawer_trigger().childset_erase(name)) API::update_window(*this); @@ -219,13 +233,13 @@ namespace nana } /// Sets the splitter string - categorize& splitstr(const nana::string& sstr) + categorize& splitstr(const std::string& sstr) { this->get_drawer_trigger().splitstr(sstr); return *this; } - nana::string splitstr() const + std::string splitstr() const { return this->get_drawer_trigger().splitstr(); } @@ -237,10 +251,10 @@ namespace nana } private: //Overrides widget's virtual functions - void _m_caption(nana::string&& str) override + void _m_caption(native_string_type&& str) override { - this->get_drawer_trigger().path(str); - API::dev::window_caption(*this, this->get_drawer_trigger().path()); + this->get_drawer_trigger().path(to_utf8(str)); + API::dev::window_caption(*this, to_nstring(this->get_drawer_trigger().path()) ); } }; }//end namespace nana diff --git a/include/nana/gui/widgets/checkbox.hpp b/include/nana/gui/widgets/checkbox.hpp index 7af58e72..16af0d5e 100644 --- a/include/nana/gui/widgets/checkbox.hpp +++ b/include/nana/gui/widgets/checkbox.hpp @@ -56,8 +56,8 @@ namespace drawerbase public: checkbox(); checkbox(window, bool visible); - checkbox(window, const nana::string& text, bool visible = true); - checkbox(window, const nana::char_t* text, bool visible = true); + checkbox(window, const std::string& text, bool visible = true); + checkbox(window, const char* text, bool visible = true); checkbox(window, const rectangle& = rectangle(), bool visible = true); void element_set(const char* name); diff --git a/include/nana/gui/widgets/combox.hpp b/include/nana/gui/widgets/combox.hpp index b7e9286e..f31b3a18 100644 --- a/include/nana/gui/widgets/combox.hpp +++ b/include/nana/gui/widgets/combox.hpp @@ -75,8 +75,8 @@ namespace nana { public: item_proxy(drawer_impl*, std::size_t pos); - item_proxy& text(const nana::string&); - nana::string text() const; + item_proxy& text(const ::std::string&); + ::std::string text() const; item_proxy& select(); bool selected() const; item_proxy& icon(const nana::paint::image&); @@ -112,14 +112,13 @@ namespace nana template item_proxy& value(T&& t) { - *_m_anyobj(true) = std::move(t); + *_m_anyobj(true) = ::std::move(t); return *this; } public: /// Behavior of Iterator's value_type - bool operator==(const nana::string&) const; + bool operator==(const ::std::string&) const; bool operator==(const char*) const; - bool operator==(const wchar_t*) const; /// Behavior of Iterator item_proxy & operator=(const item_proxy&); @@ -166,19 +165,19 @@ namespace nana combox(); combox(window, bool visible); - combox(window, nana::string, bool visible = true); - combox(window, const nana::char_t*, bool visible = true); + combox(window, ::std::string, bool visible = true); + combox(window, const char*, bool visible = true); combox(window, const rectangle& r = rectangle(), bool visible = true); void clear(); void editable(bool); bool editable() const; - void set_accept(std::function); - combox& push_back(nana::string); + 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. void option(std::size_t); ///< Select the text specified by index - nana::string text(std::size_t) const; + ::std::string text(std::size_t) const; void erase(std::size_t pos); template @@ -224,8 +223,8 @@ namespace nana const drawerbase::combox::drawer_impl& _m_impl() const; private: //Overrides widget's virtual functions - nana::string _m_caption() const throw() override; - void _m_caption(nana::string&&) override; + native_string_type _m_caption() const throw() override; + void _m_caption(native_string_type&&) override; nana::any * _m_anyobj(std::size_t pos, bool alloc_if_empty) const override; }; } diff --git a/include/nana/gui/widgets/date_chooser.hpp b/include/nana/gui/widgets/date_chooser.hpp index 9a168bfb..a4e685e1 100644 --- a/include/nana/gui/widgets/date_chooser.hpp +++ b/include/nana/gui/widgets/date_chooser.hpp @@ -42,12 +42,12 @@ namespace nana trigger(); bool chose() const; nana::date read() const; - void week_name(unsigned index, const nana::string&); + void week_name(unsigned index, const std::string&); private: where _m_pos_where(graph_reference, const ::nana::point& pos); void _m_draw_topbar(graph_reference); void _m_make_drawing_basis(drawing_basis&, graph_reference, const nana::point& refpos); - void _m_draw_pos(drawing_basis &, graph_reference, int x, int y, const nana::string&, bool primary, bool sel); + void _m_draw_pos(drawing_basis &, graph_reference, int x, int y, const ::std::string&, bool primary, bool sel); void _m_draw_pos(drawing_basis &, graph_reference, int x, int y, int number, bool primary, bool sel); void _m_draw_ex_days(drawing_basis &, graph_reference, int begx, int begy, bool before); void _m_draw_days(const nana::point& refpos, graph_reference); @@ -61,7 +61,7 @@ namespace nana void mouse_leave(graph_reference, const arg_mouse&) override; void mouse_up(graph_reference, const arg_mouse&) override; private: - nana::string weekstr_[7]; + ::std::string weekstr_[7]; widget * widget_; @@ -105,13 +105,13 @@ namespace nana public: date_chooser(); date_chooser(window, bool visible); - date_chooser(window, const nana::string& text, bool visible = true); - date_chooser(window, const nana::char_t* text, bool visible = true); + date_chooser(window, const ::std::string& text, bool visible = true); + date_chooser(window, const char* text, bool visible = true); date_chooser(window, const nana::rectangle& r = rectangle(), bool visible = true); bool chose() const; nana::date read() const; - void weekstr(unsigned index, const nana::string&);/// 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/float_listbox.hpp b/include/nana/gui/widgets/float_listbox.hpp index f28840ea..79a66e2f 100644 --- a/include/nana/gui/widgets/float_listbox.hpp +++ b/include/nana/gui/widgets/float_listbox.hpp @@ -28,7 +28,7 @@ namespace nana virtual ~item_interface(){} virtual const nana::paint::image & image() const = 0; - virtual const nana::char_t* text() const = 0; + virtual const char* text() const = 0; }; //struct module_def diff --git a/include/nana/gui/widgets/group.hpp b/include/nana/gui/widgets/group.hpp index 82f34a5b..79162f06 100644 --- a/include/nana/gui/widgets/group.hpp +++ b/include/nana/gui/widgets/group.hpp @@ -37,7 +37,7 @@ namespace nana{ /// The construction that creates the widget and set the titel or caption group(window parent, ///< a handle to the parent - ::nana::string titel, ///< caption of the group + ::std::string titel, ///< caption of the group bool formatted = false, ///< Enable/disable the formatted text for the title unsigned gap = 2, ///< betwen the content and the external limit const rectangle& r = {} , @@ -49,7 +49,7 @@ namespace nana{ ~group(); /// Adds an option for user selection - group& add_option(::nana::string); + group& add_option(::std::string); /// Enables/disables the radio mode which is single selection group& radio_mode(bool); @@ -77,8 +77,8 @@ namespace nana{ void _m_add_child(const char* field, widget*); void _m_init(); void _m_complete_creation() override; - ::nana::string _m_caption() const throw() override; - void _m_caption(::nana::string&&) override; + native_string_type _m_caption() const throw() override; + void _m_caption(native_string_type&&) override; private: std::unique_ptr impl_; }; diff --git a/include/nana/gui/widgets/label.hpp b/include/nana/gui/widgets/label.hpp index aa28effc..fef3b661 100644 --- a/include/nana/gui/widgets/label.hpp +++ b/include/nana/gui/widgets/label.hpp @@ -57,13 +57,13 @@ namespace nana typedef drawerbase::label::command command; label(); label(window, bool visible); - label(window, const nana::string& text, bool visible = true); - label(window parent, const nana::char_t* text, bool visible = true) :label(parent, nana::string(text),visible) {}; + label(window, const std::string& text, bool visible = true); + label(window parent, const char* text, bool visible = true) :label(parent, std::string(text),visible) {}; label(window, const rectangle& = {}, bool visible = true); label& transparent(bool); ///< Switchs the label widget to the transparent background mode. bool transparent() const throw(); 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 @@ -71,12 +71,12 @@ namespace nana /// "corrected" size that changes lines to fit the text into the specified width nana::size measure(unsigned allowed_width_in_pixel) const; - static ::nana::size measure(::nana::paint::graphics&, const ::nana::string&, unsigned allowed_width_in_pixel, bool format_enabled, align h_align, align_v v_align); + static ::nana::size measure(::nana::paint::graphics&, const ::std::string&, unsigned allowed_width_in_pixel, bool format_enabled, align h_align, align_v v_align); label& text_align(align horizontal_align, align_v vertical_align= align_v::top); private: //Overrides widget's virtual function - void _m_caption(nana::string&&) override; + void _m_caption(native_string_type&&) override; }; }//end namespace nana #endif diff --git a/include/nana/gui/widgets/listbox.hpp b/include/nana/gui/widgets/listbox.hpp index 59324ef2..4aa7cfb7 100644 --- a/include/nana/gui/widgets/listbox.hpp +++ b/include/nana/gui/widgets/listbox.hpp @@ -31,6 +31,7 @@ namespace nana namespace listbox { using size_type = std::size_t; + using native_string_type = ::nana::detail::native_string_type; /// usefull for both absolute and display (sorted) positions struct index_pair @@ -81,7 +82,7 @@ namespace nana using selection = std::vector; - using inline_notifier_interface = detail::inline_widget_notifier_interface; + using inline_notifier_interface = detail::inline_widget_notifier_interface; struct cell { @@ -94,17 +95,17 @@ namespace nana format(const ::nana::color& bgcolor, const ::nana::color& fgcolor); }; - using format_ptr = std::unique_ptr < format > ; + using format_ptr = ::std::unique_ptr; - ::nana::string text; - format_ptr custom_format; + ::std::string text; + format_ptr custom_format; cell() = default; cell(const cell&); cell(cell&&); - cell(nana::string); - cell(nana::string, const format&); - cell(nana::string, const ::nana::color& bgcolor, const ::nana::color& fgcolor); + cell(::std::string); + cell(::std::string, const format&); + cell(::std::string, const ::nana::color& bgcolor, const ::nana::color& fgcolor); cell& operator=(const cell&); cell& operator=(cell&&); @@ -126,9 +127,9 @@ namespace nana oresolver& operator<<(double); oresolver& operator<<(long double); - oresolver& operator<<(const char*); + oresolver& operator<<(const char* text_utf8); oresolver& operator<<(const wchar_t*); - oresolver& operator<<(const std::string&); + oresolver& operator<<(const std::string& text_utf8); oresolver& operator<<(const std::wstring&); oresolver& operator<<(std::wstring&&); oresolver& operator<<(cell); @@ -157,7 +158,7 @@ namespace nana iresolver& operator>>(double&); iresolver& operator>>(long double&); - iresolver& operator>>(std::string&); + iresolver& operator>>(std::string& utf8_cast); iresolver& operator>>(std::wstring&); iresolver& operator>>(cell&); iresolver& operator>>(std::nullptr_t); @@ -241,8 +242,9 @@ namespace nana size_type columns() const; item_proxy& text(size_type col, cell); - item_proxy& text(size_type col, nana::string); - nana::string text(size_type col) const; + item_proxy& text(size_type col, std::string); + item_proxy& text(size_type col, std::wstring); + std::string text(size_type col) const; void icon(const nana::paint::image&); @@ -257,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)); } @@ -300,9 +302,10 @@ namespace nana } /// Behavior of Iterator's value_type - bool operator==(const nana::string& s) const; bool operator==(const char * s) const; bool operator==(const wchar_t * s) const; + bool operator==(const ::std::string& s) const; + bool operator==(const ::std::wstring& s) const; /// Behavior of Iterator item_proxy & operator=(const item_proxy&); @@ -375,18 +378,20 @@ namespace nana } /// Appends one item at the end of this category with the specifies text in the column fields - void append(std::initializer_list); + void append(std::initializer_list texts_utf8); + void append(std::initializer_list texts); size_type columns() const; - cat_proxy& text(nana::string); - nana::string text() const; + cat_proxy& text(std::string); + cat_proxy& text(std::wstring); + std::string text() const; cat_proxy & select(bool); bool selected() const; /// Behavior of a container - void push_back(nana::string); + void push_back(std::string text_utf8); item_proxy begin() const; item_proxy end() const; @@ -449,8 +454,8 @@ namespace nana struct export_options { - nana::string sep = nana::string {STR("\t" )}, - endl= nana::string {STR("\n")}; + std::string sep = ::std::string {"\t"}, + endl= ::std::string {"\n"}; bool only_selected_items{true}, only_checked_items {false}, only_visible_columns{true}; @@ -510,16 +515,16 @@ By \a clicking on one header the list get \a reordered, first up, and then down and antisymmetry(comp(a, b) != comp(b, a) returns true) A simple example. - bool sort_compare( const nana::string& s1, nana::any*, - const nana::string& s2, nana::any*, bool reverse) + bool sort_compare( const std::string& s1, nana::any*, + const std::string& s2, nana::any*, bool reverse) { return (reverse ? s1 > s2 : s1 < s2); } listbox.set_sort_compare(0, sort_compare); The listbox supports attaching a customer's object for each item, therefore the items can be sorted by comparing these customer's object. - bool sort_compare( const nana::string&, nana::any* o1, - const nana::string&, nana::any* o2, bool reverse) + bool sort_compare( const std::string&, nana::any* o1, + const std::string&, nana::any* o2, bool reverse) { if(o1 && o2) //some items may not attach a customer object. { @@ -565,15 +570,20 @@ By \a clicking on one header the list get \a reordered, first up, and then down void scroll(bool to_bottom, const index_pair& pos); /// Appends a new column with a header text and the specified width at the end, and return it position - size_type append_header(nana::string header_text, unsigned width = 120); + size_type append_header(std::string text_utf8, unsigned width = 120); + size_type append_header(std::wstring text, unsigned width = 120); listbox& header_width(size_type position, unsigned pixels); unsigned header_width(size_type position) const; unsigned auto_width(size_type position, unsigned max=3000); - cat_proxy append(nana::string); ///< Appends a new category at the end - void append(std::initializer_list); ///< Appends categories at the end - cat_proxy insert(cat_proxy, nana::string); + cat_proxy append(std::string); ///< Appends a new category to the end + cat_proxy append(std::wstring); ///< Appends a new category to the end + void append(std::initializer_list); ///< Appends categories to the end + void append(std::initializer_list); ///< Appends categories to the end + + cat_proxy insert(cat_proxy, ::std::string); + cat_proxy insert(cat_proxy, ::std::wstring); cat_proxy at(size_type pos) const; /// add categories in order when use a key? @@ -606,7 +616,8 @@ By \a clicking on one header the list get \a reordered, first up, and then down item_proxy at(const index_pair &abs_pos) const; - void insert(const index_pair&, nana::string); /// strick_ordering); + void set_sort_compare(size_type col, std::function strick_ordering); /// sort() and ivalidate any existing reference from display position to absolute item, that is: after sort() display offset point to different items void sort_col(size_type col, bool reverse = false); diff --git a/include/nana/gui/widgets/menu.hpp b/include/nana/gui/widgets/menu.hpp index 512d30d7..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, @@ -56,7 +58,7 @@ namespace nana //Default constructor initializes the item as a splitter menu_item_type(); - menu_item_type(nana::string, const event_fn_t&); + menu_item_type(std::string, const event_fn_t&); struct { @@ -66,11 +68,11 @@ namespace nana }flags; menu_type *sub_menu{nullptr}; - nana::string text; + std::string text; 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 @@ -134,7 +136,7 @@ namespace nana ~menu(); /// Appends an item to the menu. - item_proxy append(const nana::string& text, const event_fn_t& callback= event_fn_t()); + item_proxy append(const std::string& text, const event_fn_t& callback= event_fn_t()); void append_splitter(); void clear(); ///< Erases all of the items. /// Closes the menu. It does not destroy the menu; just close the window for the 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 8e7270bc..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: @@ -108,7 +110,7 @@ namespace nana menubar(window); ///< Create a menubar at the top of the specified window. ~menubar(); void create(window); ///< Create a menubar at the top of the specified window. - menu& push_back(const nana::string&); ///< Appends a new (empty) menu. + menu& push_back(const std::string&); ///< Appends a new (empty) menu. menu& at(size_t index) const; ///< Gets the menu specified by index. std::size_t length() const; ///< Number of menus. private: diff --git a/include/nana/gui/widgets/scroll.hpp b/include/nana/gui/widgets/scroll.hpp index f09b2046..96d1b023 100644 --- a/include/nana/gui/widgets/scroll.hpp +++ b/include/nana/gui/widgets/scroll.hpp @@ -186,7 +186,7 @@ namespace nana { graph_ = &graph; widget_ = static_cast< ::nana::scroll*>(&widget); - widget.caption(STR("Nana Scroll")); + widget.caption("nana scroll"); timer_.stop(); timer_.elapse(std::bind(&trigger::_m_tick, this)); diff --git a/include/nana/gui/widgets/skeletons/text_editor.hpp b/include/nana/gui/widgets/skeletons/text_editor.hpp index cf1f207a..9da01f8c 100644 --- a/include/nana/gui/widgets/skeletons/text_editor.hpp +++ b/include/nana/gui/widgets/skeletons/text_editor.hpp @@ -131,7 +131,7 @@ namespace nana{ namespace widgets struct keywords; class keyword_parser; public: - using char_type = ::nana::char_t; + using char_type = wchar_t; using size_type = textbase::size_type; using string_type = textbase::string_type; @@ -152,10 +152,10 @@ namespace nana{ namespace widgets text_editor(window, graph_reference, const text_editor_scheme*); ~text_editor(); - void set_highlight(const std::string& name, const ::nana::color&, const ::nana::color&); - void erase_highlight(const std::string& name); - void set_keyword(const ::nana::string& kw, const std::string& name, bool case_sensitive, bool whole_word_matched); - void erase_keyword(const ::nana::string& kw); + void set_highlight(const ::std::string& name, const ::nana::color&, const ::nana::color&); + void erase_highlight(const ::std::string& name); + void set_keyword(const ::std::wstring& kw, const std::string& name, bool case_sensitive, bool whole_word_matched); + void erase_keyword(const ::std::wstring& kw); void set_accept(std::function); void set_accept(accepts); @@ -164,7 +164,7 @@ namespace nana{ namespace widgets void typeface_changed(); - void indent(bool, std::function generator); + void indent(bool, std::function generator); void set_event(event_interface*); /// Determine whether the text_editor is line wrapped. @@ -174,7 +174,7 @@ namespace nana{ namespace widgets void border_renderer(std::function); - bool load(const nana::char_t*); + bool load(const char*); /// Sets the text area. /// @return true if the area is changed with the new value. @@ -183,7 +183,7 @@ namespace nana{ namespace widgets /// Returns the text area rectangle text_area(bool including_scroll) const; - bool tip_string(nana::string&&); + bool tip_string(::std::string&&); const attributes & attr() const; bool multi_lines(bool); @@ -201,9 +201,9 @@ namespace nana{ namespace widgets unsigned line_height() const; unsigned screen_lines() const; - bool getline(std::size_t pos, nana::string&) const; - void text(nana::string); - nana::string text() const; + bool getline(std::size_t pos, ::std::wstring&) const; + void text(std::wstring); + std::wstring text() const; /// Sets caret position through text coordinate. void move_caret(const upoint&); @@ -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; @@ -233,8 +233,8 @@ namespace nana{ namespace widgets void draw_corner(); void render(bool focused); public: - void put(nana::string); - void put(nana::char_t); + void put(std::wstring); + void put(wchar_t); void copy() const; void cut(); void paste(); @@ -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; @@ -264,11 +264,11 @@ namespace nana{ namespace widgets ::nana::size _m_text_area() const; void _m_get_scrollbar_size(); void _m_reset(); - ::nana::upoint _m_put(nana::string); + ::nana::upoint _m_put(::std::wstring); ::nana::upoint _m_erase_select(); - bool _m_make_select_string(nana::string&) const; - static bool _m_resolve_text(const nana::string&, std::vector> & lines); + bool _m_make_select_string(::std::wstring&) const; + static bool _m_resolve_text(const ::std::wstring&, std::vector> & lines); bool _m_cancel_select(int align); unsigned _m_tabs_pixels(size_type tabs) const; @@ -283,10 +283,10 @@ namespace nana{ namespace widgets /// Returns the right/bottom point of text area. int _m_end_pos(bool right) const; - void _m_draw_parse_string(const keyword_parser&, bool rtl, ::nana::point pos, const ::nana::color& fgcolor, const ::nana::char_t*, std::size_t len) const; + void _m_draw_parse_string(const keyword_parser&, bool rtl, ::nana::point pos, const ::nana::color& fgcolor, const wchar_t*, std::size_t len) const; //_m_draw_string //@brief: Draw a line of string - void _m_draw_string(int top, const ::nana::color&, const nana::upoint& str_pos, const nana::string&, bool if_mask) const; + void _m_draw_string(int top, const ::nana::color&, const nana::upoint& str_pos, const ::std::wstring&, bool if_mask) const; //_m_update_caret_line //@brief: redraw whole line specified by caret pos. //@return: true if caret overs the border @@ -295,8 +295,8 @@ namespace nana{ namespace widgets void _m_offset_y(int y); - unsigned _m_char_by_pixels(const nana::char_t*, std::size_t len, unsigned* pxbuf, int str_px, int pixels, bool is_rtl); - unsigned _m_pixels_by_char(const nana::string&, std::size_t pos) const; + unsigned _m_char_by_pixels(const wchar_t*, std::size_t len, unsigned* pxbuf, int str_px, int pixels, bool is_rtl); + unsigned _m_pixels_by_char(const ::std::wstring&, std::size_t pos) const; void _handle_move_key(const arg_keyboard& arg); private: @@ -308,8 +308,8 @@ namespace nana{ namespace widgets event_interface * event_handler_{ nullptr }; std::unique_ptr keywords_; - skeletons::textbase textbase_; - nana::char_t mask_char_{0}; + skeletons::textbase textbase_; + wchar_t mask_char_{0}; mutable ext_renderer_tag ext_renderer_; @@ -318,7 +318,7 @@ namespace nana{ namespace widgets struct indent_rep { bool enabled{ false }; - std::function generator; + std::function generator; }indent_; struct attributes @@ -326,7 +326,7 @@ namespace nana{ namespace widgets accepts acceptive{ accepts::no_restrict }; std::function pred_acceptive; - nana::string tip_string; + ::std::string tip_string; bool line_wrapped{false}; bool multi_lines{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..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 @@ -42,7 +42,7 @@ namespace nana{ namespace widgets{ namespace skeletons class tokenizer { public: - tokenizer(const nana::string& s, bool format_enabled) + tokenizer(const std::wstring& s, bool format_enabled) : iptr_(s.data()), endptr_(s.data() + s.size()), format_enabled_(format_enabled) @@ -74,12 +74,12 @@ namespace nana{ namespace widgets{ namespace skeletons return _m_token(); } - const nana::string& idstr() const + const ::std::wstring& idstr() const { return idstr_; } - const std::pair& binary() const + const std::pair& binary() const { return binary_; } @@ -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_; @@ -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; @@ -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; @@ -412,13 +412,13 @@ namespace nana{ namespace widgets{ namespace skeletons } } private: - const ::nana::char_t * iptr_; - const ::nana::char_t * endptr_; + const wchar_t * iptr_; + const wchar_t * endptr_; const bool format_enabled_; bool format_state_{false}; - ::nana::string idstr_; - std::pair binary_; + std::wstring idstr_; + std::pair binary_; token revert_token_{token::eof}; }; @@ -434,7 +434,7 @@ namespace nana{ namespace widgets{ namespace skeletons }; }; - ::nana::string font; + ::std::string font; std::size_t font_size; bool bold; bool bold_empty; //bold should be ignored if bold_empty is true @@ -442,8 +442,8 @@ namespace nana{ namespace widgets{ namespace skeletons ::nana::color bgcolor; //If the color is not specified, it will be ignored, and the system will search for its parent. ::nana::color fgcolor; //ditto - ::nana::string target; - ::nana::string url; + ::std::wstring target; + ::std::wstring url; fblock * parent; }; @@ -458,7 +458,7 @@ namespace nana{ namespace widgets{ namespace skeletons virtual bool is_text() const = 0; virtual bool is_whitespace() const = 0; - virtual const nana::string& text() const = 0; + virtual const std::wstring& text() const = 0; virtual void measure(graph_reference) = 0; virtual void nontext_render(graph_reference, int x, int y) = 0; virtual const nana::size & size() const = 0; @@ -470,7 +470,7 @@ namespace nana{ namespace widgets{ namespace skeletons : public data { public: - data_text(const nana::string& s) + data_text(const std::wstring& s) : str_(s) {} private: @@ -484,7 +484,7 @@ namespace nana{ namespace widgets{ namespace skeletons return false; } - virtual const nana::string& text() const override + virtual const std::wstring& text() const override { return str_; } @@ -513,7 +513,7 @@ namespace nana{ namespace widgets{ namespace skeletons return ascent_; } private: - nana::string str_; + std::wstring str_; nana::size size_; std::size_t ascent_; }; @@ -522,7 +522,7 @@ namespace nana{ namespace widgets{ namespace skeletons : public data { public: - data_image(const nana::string& imgpath, const nana::size & sz, std::size_t limited) + data_image(const std::wstring& imgpath, const nana::size & sz, std::size_t limited) : image_(imgpath)//, limited_(limited) { size_ = image_.size(); @@ -562,7 +562,7 @@ namespace nana{ namespace widgets{ namespace skeletons return false; } - virtual const nana::string& text() const override + virtual const std::wstring& text() const override { return str_; } @@ -589,7 +589,7 @@ namespace nana{ namespace widgets{ namespace skeletons return size_.height; } private: - nana::string str_; + std::wstring str_; nana::paint::image image_; nana::size size_; }; @@ -626,7 +626,7 @@ namespace nana{ namespace widgets{ namespace skeletons fblocks_.clear(); } - void parse(const nana::string& s, bool format_enabled) + void parse(const std::wstring& s, bool format_enabled) { close(); @@ -706,7 +706,7 @@ namespace nana{ namespace widgets{ namespace skeletons if(token::string != tknizer.read()) throw std::runtime_error(""); - fp->font = tknizer.idstr(); + fp->font = to_utf8(tknizer.idstr()); break; case token::size: if(token::equal != tknizer.read()) @@ -893,7 +893,7 @@ namespace nana{ namespace widgets{ namespace skeletons return fbp; } - void _m_data_factory(token tk, const nana::string& idstr, fblock* fp, std::deque& line) + void _m_data_factory(token tk, const std::wstring& idstr, fblock* fp, std::deque& line) { value v; v.fblock_ptr = fp; @@ -926,7 +926,7 @@ namespace nana{ namespace widgets{ namespace skeletons struct attr_image_tag { - nana::string path; + std::wstring path; nana::size size; std::size_t limited; diff --git a/include/nana/gui/widgets/skeletons/textbase.hpp b/include/nana/gui/widgets/skeletons/textbase.hpp index 32527879..975025e1 100644 --- a/include/nana/gui/widgets/skeletons/textbase.hpp +++ b/include/nana/gui/widgets/skeletons/textbase.hpp @@ -57,13 +57,12 @@ namespace skeletons ((text_cont_.size() == 1) && (text_cont_[0].empty()))); } - bool load(const nana::char_t* fs) + bool load(const char* file_utf8) { - if (nullptr == fs) + if (!file_utf8) return false; - std::string fs_mbs = nana::charset(fs); - std::ifstream ifs(fs_mbs.data()); + std::ifstream ifs(to_osmbstr(file_utf8)); if (!ifs) return false; @@ -81,7 +80,7 @@ namespace skeletons if(0xBB == ch && 0xBF == ifs.get()) { ifs.close(); - return load(fs, nana::unicode::utf8); + return load(file_utf8, nana::unicode::utf8); } } else if(0xFF == ch) @@ -94,11 +93,11 @@ namespace skeletons if(ifs.get() == 0 && ifs.get() == 0) { ifs.close(); - return load(fs, nana::unicode::utf32); + return load(file_utf8, nana::unicode::utf32); } } ifs.close(); - return load(fs, nana::unicode::utf16); + return load(file_utf8, nana::unicode::utf16); } } else if(0xFE == ch) @@ -107,7 +106,7 @@ namespace skeletons { //UTF16(big-endian) ifs.close(); - return load(fs, nana::unicode::utf16); + return load(file_utf8, nana::unicode::utf16); } } else if(0 == ch) @@ -119,7 +118,7 @@ namespace skeletons { //UTF32(big_endian) ifs.close(); - return load(fs, nana::unicode::utf32); + return load(file_utf8, nana::unicode::utf32); } } } @@ -143,7 +142,7 @@ namespace skeletons } } - _m_saved(fs); + _m_saved(file_utf8); return true; } @@ -175,13 +174,12 @@ namespace skeletons } } - bool load(const nana::char_t * fs, nana::unicode encoding) + bool load(const char* file_utf8, nana::unicode encoding) { - if (nullptr == fs) + if (!file_utf8) return false; - std::string fs_mbs = nana::charset(fs); - std::ifstream ifs(fs_mbs.data()); + std::ifstream ifs(to_osmbstr(file_utf8)); if (!ifs) return false; @@ -245,14 +243,13 @@ namespace skeletons } } - _m_saved(fs); + _m_saved(file_utf8); return true; } - void store(nana::string fs, bool is_unicode, ::nana::unicode encoding) const + void store(std::string fs, bool is_unicode, ::nana::unicode encoding) const { - std::string fs_mbs = nana::charset(fs); - std::ofstream ofs(fs_mbs.data(), std::ios::binary); + std::ofstream ofs(to_osmbstr(fs), std::ios::binary); if(ofs && text_cont_.size()) { std::string last_mbs; @@ -410,7 +407,7 @@ namespace skeletons { std::deque().swap(text_cont_); attr_max_.reset(); - _m_saved(nana::string()); + _m_saved(std::string()); } void merge(size_type pos) @@ -427,7 +424,7 @@ namespace skeletons } } - const nana::string& filename() const + const std::string& filename() const { return filename_; } @@ -489,7 +486,7 @@ namespace skeletons evt_agent_->first_change(); } - void _m_saved(nana::string && filename) const + void _m_saved(std::string && filename) const { if(filename_ != filename) { @@ -518,7 +515,7 @@ namespace skeletons textbase_event_agent_interface* evt_agent_{ nullptr }; mutable bool changed_{ false }; - mutable nana::string filename_; //A string for the saved filename. + mutable std::string filename_; //A string for the saved filename. const string_type nullstr_; struct attr_max diff --git a/include/nana/gui/widgets/slider.hpp b/include/nana/gui/widgets/slider.hpp index 0e32237d..c5372034 100644 --- a/include/nana/gui/widgets/slider.hpp +++ b/include/nana/gui/widgets/slider.hpp @@ -45,7 +45,7 @@ namespace nana { public: virtual ~provider() = default; - virtual nana::string adorn_trace(unsigned vmax, unsigned vadorn) const = 0; + virtual std::string adorn_trace(unsigned vmax, unsigned vadorn) const = 0; }; class renderer @@ -81,7 +81,7 @@ namespace nana virtual void background(window, graph_reference, bool isglass) = 0; virtual void adorn(window, graph_reference, const adorn_t&) = 0; - virtual void adorn_textbox(window, graph_reference, const nana::string&, const nana::rectangle&) = 0; + virtual void adorn_textbox(window, graph_reference, const ::std::string&, const nana::rectangle&) = 0; virtual void bar(window, graph_reference, const bar_t&) = 0; virtual void slider(window, graph_reference, const slider_t&) = 0; }; diff --git a/include/nana/gui/widgets/spinbox.hpp b/include/nana/gui/widgets/spinbox.hpp index dc081018..e3d28505 100644 --- a/include/nana/gui/widgets/spinbox.hpp +++ b/include/nana/gui/widgets/spinbox.hpp @@ -97,17 +97,17 @@ namespace nana void range(std::initializer_list values); /// Gets the spined value - ::nana::string value() const; - void value(const ::nana::string&); + ::std::string value() const; + void value(const ::std::string&); int to_int() const; double to_double() const; /// Sets the modifiers - void modifier(std::wstring prefix, std::wstring suffix); - void modifier(const std::string & prefix_utf8, const std::string& suffix_utf8); + void modifier(std::string prefix_utf8, std::string suffix_utf8); + void modifier(const std::wstring & prefix, const std::wstring& suffix); private: - ::nana::string _m_caption() const throw(); - void _m_caption(::nana::string&&); + native_string_type _m_caption() const throw(); + void _m_caption(native_string_type&&); }; //end class spinbox }//end namespace nana diff --git a/include/nana/gui/widgets/tabbar.hpp b/include/nana/gui/widgets/tabbar.hpp index 8236f639..1981c3c7 100644 --- a/include/nana/gui/widgets/tabbar.hpp +++ b/include/nana/gui/widgets/tabbar.hpp @@ -144,12 +144,14 @@ namespace nana : public drawer_trigger { public: + using native_string_type = ::nana::detail::native_string_type; + enum class kits { - add, - scroll, - list, - close + add, ///< The type identifies the add button of the tabbar's toolbox. + scroll, ///< The type identifies the scroll button of the tabbar's toolbox + list, ///< The type identifies the list button of the tabbar's toolbox + close ///< The type identifies the close button of the tabbar's toolbox }; trigger(); @@ -161,15 +163,15 @@ namespace nana const pat::cloneable & ext_renderer() const; void ext_renderer(const pat::cloneable&); void set_event_agent(event_agent_interface*); - void insert(std::size_t, nana::string&&, nana::any&&); + void insert(std::size_t, native_string_type&&, nana::any&&); std::size_t length() const; bool close_fly(bool); void attach(std::size_t, window); void erase(std::size_t); void tab_color(std::size_t, bool is_bgcolor, const ::nana::color&); void tab_image(size_t, const nana::paint::image&); - void text(std::size_t, const nana::string&); - nana::string text(std::size_t) const; + void text(std::size_t, const native_string_type&); + native_string_type text(std::size_t) const; bool toolbox(kits, bool); private: void attached(widget_reference, graph_reference) override; @@ -191,30 +193,9 @@ namespace nana { typedef drawerbase::tabbar::trigger drawer_trigger_t; public: - typedef Type value_type; ///< The type of element data which is stored in the tabbar. - typedef drawerbase::tabbar::item_renderer item_renderer; ///< A user-defined item renderer should be derived from this interface. - - //These member types is deprecated, they will be removed in Nana 1.3 - struct button_add{}; ///< The type identifies the add button of the tabbar's toolbox. - struct button_scroll{}; ///< The type identifies the scroll button of the tabbar's toolbox. - struct button_list{}; ///< The type identifies the list button of the tabbar's toolbox. - struct button_close{}; ///< The type identifies the close button of the tabbar's toolbox. - - //This template class is deprecated, it will be removed in 1.3 - /// A template class identifies the buttons of the tabbar's toolbox. Refer to notes for more details. - template - struct button_container - { - typedef meta::fixed_type_set type_set; - }; - - enum class kits - { - add, ///< The type identifies the add button of the tabbar's toolbox. - scroll, ///< The type identifies the scroll button of the tabbar's toolbox - list, ///< The type identifies the list button of the tabbar's toolbox - close ///< The type identifies the close button of the tabbar's toolbox - }; + using value_type = Type; ///< The type of element data which is stored in the tabbar. + using item_renderer = drawerbase::tabbar::item_renderer; ///< A user-defined item renderer should be derived from this interface. + using kits = drawer_trigger_t::kits; tabbar() { @@ -298,15 +279,19 @@ namespace nana return *this; } - void push_back(nana::string text) /// Append a new item. + void push_back(std::string text) /// Append a new item. { - this->get_drawer_trigger().insert(::nana::npos, std::move(text), value_type()); + this->get_drawer_trigger().insert(::nana::npos, to_nstring(std::move(text)), value_type()); API::update_window(*this); } void insert(std::size_t pos, std::string text, value_type value = {}) { - return this->insert(pos, static_cast(nana::charset(text, nana::unicode::utf8)), std::move(value)); + if (pos > length()) + throw std::out_of_range("tabbar::insert invalid position"); + + this->get_drawer_trigger().insert(pos, to_nstring(text), std::move(value)); + API::update_window(*this); } void insert(std::size_t pos, std::wstring text, value_type value = {}) @@ -314,16 +299,10 @@ namespace nana if (pos > length()) throw std::out_of_range("tabbar::insert invalid position"); - this->get_drawer_trigger().insert(pos, std::move(text), std::move(value)); + this->get_drawer_trigger().insert(pos, to_nstring(text), std::move(value)); API::update_window(*this); } - //deprecated from 1.2.1, removed from 1.3 - void relate(std::size_t pos, window wd) /// Binds a window to an item specified by pos, if the item is selected, shows the window, otherwise, hides it. - { - this->get_drawer_trigger().attach(pos, wd); - } - void attach(std::size_t pos, window attach_wd) { if (attach_wd && API::empty_window(attach_wd)) @@ -351,46 +330,22 @@ namespace nana { this->get_drawer_trigger().tab_image(pos, img); } + /// Sets buttons of the tabbar's toolbox, refer to notes for more details. - template - void toolbox(const button_container&, bool enable) - { - typedef typename button_container::type_set type_set; - auto & tg = this->get_drawer_trigger(); - bool redraw = false; - - using inner_kits = drawerbase::tabbar::trigger::kits; - - if(type_set::template count::value) - redraw |= tg.toolbox(inner_kits::add, enable); - - if(type_set::template count::value) - redraw |= tg.toolbox(inner_kits::scroll, enable); - - if(type_set::template count::value) - redraw |= tg.toolbox(inner_kits::add, enable); - - if(type_set::template count::value) - redraw |= tg.toolbox(inner_kits::close, enable); - - if(redraw) - API::refresh_window(this->handle()); - } - void toolbox(kits kit, bool enable) { if (this->get_drawer_trigger().toolbox(kit, enable)) API::refresh_window(this->handle()); } - void text(std::size_t pos, const nana::string& str) /// Sets the title of the specified item, If pos is invalid, the method throws an std::out_of_range object. + void text(std::size_t pos, const std::string& str) /// Sets the title of the specified item, If pos is invalid, the method throws an std::out_of_range object. { - this->get_drawer_trigger().text(pos, str); + this->get_drawer_trigger().text(pos, to_nstring(str)); } - nana::string text(std::size_t pos) const /// Returns a title of a specified item, If pos is invalid, the method trhows a std::out_of_range object. + std::string text(std::size_t pos) const /// Returns a title of a specified item, If pos is invalid, the method trhows a std::out_of_range object. { - return this->get_drawer_trigger().text(pos); + return to_utf8(this->get_drawer_trigger().text(pos)); } private: std::unique_ptr > evt_agent_; diff --git a/include/nana/gui/widgets/textbox.hpp b/include/nana/gui/widgets/textbox.hpp index f0d8ff02..69fda830 100644 --- a/include/nana/gui/widgets/textbox.hpp +++ b/include/nana/gui/widgets/textbox.hpp @@ -111,13 +111,13 @@ namespace nana /// @param window A handle to the parent window of the widget being created. /// @param text the text that will be displayed. /// @param visible specifying the visible after creating. - textbox(window, const nana::string& text, bool visible = true); + textbox(window, const std::string& text, bool visible = true); /// \brief The construct that creates a widget with a specified text. /// @param window A handle to the parent window of the widget being created. /// @param text the text that will be displayed. /// @param visible specifying the visible after creating. - textbox(window, const nana::char_t* text, bool visible = true); + textbox(window, const char* text, bool visible = true); /// \brief The construct that creates a widget. /// @param window A handle to the parent window of the widget being created. @@ -126,19 +126,19 @@ namespace nana textbox(window, const rectangle& = rectangle(), bool visible = true); /// \brief Loads a text file. When attempt to load a unicode encoded text file, be sure the file have a BOM header. - void load(nana::string file); - void store(nana::string file); - void store(nana::string file, nana::unicode encoding); + void load(std::string file); + void store(std::string file); + void store(std::string file, nana::unicode encoding); /// Enables/disables the textbox to indent a line. Idents a new line when it is created by pressing enter. /// @param generator generates text for identing a line. If it is empty, textbox indents the line according to last line. - textbox& indention(bool, std::function generator = {}); + textbox& indention(bool, std::function generator = {}); //A workaround for reset, explicit default constructor syntax, because VC2013 incorrectly treats {} as {0}. - textbox& reset(nana::string = nana::string()); ///< discard the old text and set a new text + textbox& reset(const std::string& = std::string()); ///< discard the old text and set a new text /// The file of last store operation. - nana::string filename() const; + std::string filename() const; /// Determine whether the text was edited. bool edited() const; @@ -150,7 +150,7 @@ namespace nana bool saved() const; /// Read the text from a specified line. It returns true for success. - bool getline(std::size_t pos, nana::string&) const; + bool getline(std::size_t pos, std::string&) const; /// Gets the caret position /// Returns true if the caret is in the area of display, false otherwise. @@ -160,7 +160,7 @@ namespace nana textbox& caret_pos(const upoint&); /// Appends an string. If `at_caret` is `true`, the string is inserted at the position of caret, otherwise, it is appended at end of the textbox. - textbox& append(const nana::string& text, bool at_caret); + textbox& append(const std::string& text, bool at_caret); /// Determine wheter the text is line wrapped. bool line_wrapped() const; @@ -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(nana::string); + textbox& tip_string(::std::string); /// Set a mask character. Text is displayed as mask character if a mask character is set. This is used for hiding some special text, such as password. - textbox& mask(nana::char_t); + textbox& mask(wchar_t); /// Returns true if some text is selected. bool selected() const; @@ -195,10 +195,9 @@ namespace nana void set_highlight(const std::string& name, const ::nana::color& fgcolor, const ::nana::color& bgcolor); void erase_highlight(const std::string& name); - void set_keywords(const std::string& name, bool case_sensitive, bool whole_word_match, std::initializer_list kw_list); + void set_keywords(const std::string& name, bool case_sensitive, bool whole_word_match, std::initializer_list kw_list); void set_keywords(const std::string& name, bool case_sensitive, bool whole_word_match, std::initializer_list kw_list_utf8); - void erase_keyword(const nana::string& kw); - + void erase_keyword(const std::string& kw); /// Returns the text position of each line that currently displays on screen. text_positions text_position() const; @@ -210,8 +209,8 @@ namespace nana unsigned line_pixels() const; protected: //Overrides widget's virtual functions - ::nana::string _m_caption() const throw() override; - void _m_caption(::nana::string&&) override; + native_string_type _m_caption() const throw() override; + void _m_caption(native_string_type&&) override; void _m_typeface(const paint::font&) override; }; }//end namespace nana diff --git a/include/nana/gui/widgets/toolbar.hpp b/include/nana/gui/widgets/toolbar.hpp index 0b097676..d23efcc6 100644 --- a/include/nana/gui/widgets/toolbar.hpp +++ b/include/nana/gui/widgets/toolbar.hpp @@ -87,8 +87,8 @@ namespace nana toolbar(window, const rectangle& = rectangle(), bool visible = true); void separate(); ///< Adds a separator. - void append(const nana::string& text, const nana::paint::image& img); ///< Adds a control button. - void append(const nana::string& text); ///< Adds a control button. + void append(const ::std::string& text, const nana::paint::image& img); ///< Adds a control button. + void append(const ::std::string& text); ///< Adds a control button. bool enable(size_type index) const; void enable(size_type index, bool enable_state); void scale(unsigned s); ///< Sets the scale of control button. diff --git a/include/nana/gui/widgets/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;/// void i18n(std::string msgid, Args&&... args) @@ -88,10 +93,10 @@ 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 nana::string&); + widget& tooltip(const ::std::string&); operator dummy_bool_type() const; operator window() const; @@ -105,8 +110,8 @@ namespace nana virtual void _m_complete_creation(); virtual general_events& _m_get_general_events() const = 0; - virtual nana::string _m_caption() const throw(); - virtual void _m_caption(nana::string&&); + virtual native_string_type _m_caption() const throw(); + virtual void _m_caption(native_string_type&&); virtual nana::cursor _m_cursor() const; virtual void _m_cursor(nana::cursor); virtual void _m_close(); diff --git a/include/nana/internationalization.hpp b/include/nana/internationalization.hpp index 341c8e97..e1e2cbe3 100644 --- a/include/nana/internationalization.hpp +++ b/include/nana/internationalization.hpp @@ -28,34 +28,34 @@ namespace nana void load_utf8(const std::string& file); template - nana::string get(std::string msgid_utf8, Args&&... args) const + ::std::string get(std::string msgid_utf8, Args&&... args) const { - std::vector arg_strs; + std::vector arg_strs; _m_fetch_args(arg_strs, std::forward(args)...); - nana::string msgstr; + ::std::string msgstr; if (_m_get(msgid_utf8, msgstr)) _m_replace_args(msgstr, &arg_strs); return msgstr; } - nana::string get(std::string msgid_utf8) const; - void set(std::string msgid_utf8, nana::string msgstr); + ::std::string get(std::string msgid_utf8) const; + void set(std::string msgid_utf8, ::std::string msgstr); template - nana::string operator()(std::string msgid_utf8, Args&&... args) const + ::std::string operator()(std::string msgid_utf8, Args&&... args) const { return get(msgid_utf8, std::forward(args)...); } private: - bool _m_get(std::string& msgid, nana::string& msgstr) const; - void _m_replace_args(nana::string& str, std::vector * arg_strs) const; + bool _m_get(std::string& msgid, ::std::string& msgstr) const; + void _m_replace_args(::std::string& str, std::vector<::std::string> * arg_strs) const; - void _m_fetch_args(std::vector&) const //Termination of _m_fetch_args + void _m_fetch_args(std::vector&) const //Termination of _m_fetch_args {} template - void _m_fetch_args(std::vector& v, Arg&& arg) const + void _m_fetch_args(std::vector& v, Arg&& arg) const { std::wstringstream ss; ss << arg; @@ -63,52 +63,39 @@ namespace nana } template - void _m_fetch_args(std::vector& v, const char* arg, Args&&... args) const + void _m_fetch_args(std::vector& v, const char* arg, Args&&... args) const { - std::wstringstream ss; - ss << nana::string(nana::charset(arg)); - v.emplace_back(ss.str()); - + v.emplace_back(arg); _m_fetch_args(v, std::forward(args)...); } template - void _m_fetch_args(std::vector& v, const std::string& arg, Args&&... args) const + void _m_fetch_args(std::vector& v, const std::string& arg, Args&&... args) const { - std::wstringstream ss; - ss << nana::string(nana::charset(arg)); - v.emplace_back(ss.str()); - + v.emplace_back(arg); _m_fetch_args(v, std::forward(args)...); } template - void _m_fetch_args(std::vector& v, std::string& arg, Args&&... args) const + void _m_fetch_args(std::vector& v, std::string& arg, Args&&... args) const { - std::wstringstream ss; - ss << nana::string(nana::charset(arg)); - v.emplace_back(ss.str()); - + v.emplace_back(arg); _m_fetch_args(v, std::forward(args)...); } template - void _m_fetch_args(std::vector& v, std::string&& arg, Args&&... args) const + void _m_fetch_args(std::vector& v, std::string&& arg, Args&&... args) const { - std::wstringstream ss; - ss << nana::string(nana::charset(arg)); - v.emplace_back(ss.str()); - + v.emplace_back(std::move(arg)); _m_fetch_args(v, std::forward(args)...); } template - void _m_fetch_args(std::vector& v, Arg&& arg, Args&&... args) const + void _m_fetch_args(std::vector& v, Arg&& arg, Args&&... args) const { - std::wstringstream ss; + std::stringstream ss; ss << arg; v.emplace_back(ss.str()); - _m_fetch_args(v, std::forward(args)...); } };//end class internationalization @@ -119,7 +106,7 @@ namespace nana { public: virtual ~eval_arg() = default; - virtual nana::string eval() const = 0; + virtual std::string eval() const = 0; virtual std::unique_ptr clone() const = 0; }; @@ -134,7 +121,7 @@ namespace nana : fn_(fn) {} - nana::string eval() const override + std::string eval() const override { std::wstringstream ss; ss << fn_(); @@ -166,7 +153,7 @@ namespace nana i18n_eval& operator=(const i18n_eval&); i18n_eval& operator=(i18n_eval&& rhs); - nana::string operator()() const; + std::string operator()() const; private: void _m_fetch_args(){} //Termination of _m_fetch_args @@ -180,7 +167,7 @@ namespace nana template void _m_add_args(Arg&& arg) { - std::wstringstream ss; + std::stringstream ss; ss << arg; _m_add_args(ss.str()); } diff --git a/include/nana/paint/detail/image_impl_interface.hpp b/include/nana/paint/detail/image_impl_interface.hpp index 6cd604fb..379e8027 100644 --- a/include/nana/paint/detail/image_impl_interface.hpp +++ b/include/nana/paint/detail/image_impl_interface.hpp @@ -15,7 +15,7 @@ namespace nana{ namespace paint{ public: typedef nana::paint::graphics& graph_reference; virtual ~image_impl_interface() = 0; //The destructor is defined in ../image.cpp - virtual bool open(const nana::char_t* filename) = 0; + virtual bool open(const nana::experimental::filesystem::path& file) = 0; virtual bool open(const void* data, std::size_t bytes) = 0; // reads image from memory virtual bool alpha_channel() const = 0; virtual bool empty() const = 0; 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 a194aa7e..501d30fc 100644 --- a/include/nana/paint/graphics.hpp +++ b/include/nana/paint/graphics.hpp @@ -36,14 +36,14 @@ namespace nana font(); font(drawable_type); font(const font&); - font(const char_t* name, unsigned size, bool bold = false, bool italic = false, bool underline = false, bool strike_out = false); + font(const ::std::string& name, unsigned size, bool bold = false, bool italic = false, bool underline = false, bool strike_out = false); ~font(); bool empty() const; - void make(const char_t* name, unsigned size, bool bold = false, bool italic = false, bool underline = false, bool strike_out = false); - void make_raw(const char_t*, unsigned height, unsigned weight, bool italic, bool underline, bool strike_out); + void make(const ::std::string& name, unsigned size, bool bold = false, bool italic = false, bool underline = false, bool strike_out = false); + void make_raw(const ::std::string& name, unsigned height, unsigned weight, bool italic, bool underline, bool strike_out); void set_default() const; - ::nana::string name() const; + ::std::string name() const; unsigned size() const; bool bold() const; unsigned height() const; @@ -89,13 +89,15 @@ namespace nana void resize(const ::nana::size&); void typeface(const font&); ///< Selects a specified font type into the graphics object. font typeface() const; - ::nana::size text_extent_size(const char_t*) const; ///< Computes the width and height of the specified string of text. - ::nana::size text_extent_size(const string&) const; ///< Computes the width and height of the specified string of text. - ::nana::size text_extent_size(const char_t*, std::size_t length) const; ///< Computes the width and height of the specified string of text with the specified length. - ::nana::size text_extent_size(const string&, std::size_t length) const; ///< Computes the width and height of the specified string of text with the specified length. - ::nana::size glyph_extent_size(const char_t*, std::size_t length, std::size_t begin, std::size_t end) const; - ::nana::size glyph_extent_size(const string&, std::size_t length, std::size_t begin, std::size_t end) const; - bool glyph_pixels(const char_t *, std::size_t length, unsigned* pxbuf) const; + ::nana::size text_extent_size(const ::std::string&) const; + ::nana::size text_extent_size(const char*, std::size_t len) const; + ::nana::size text_extent_size(const wchar_t*) const; ///< Computes the width and height of the specified string of text. + ::nana::size text_extent_size(const ::std::wstring&) const; ///< Computes the width and height of the specified string of text. + ::nana::size text_extent_size(const wchar_t*, std::size_t length) const; ///< Computes the width and height of the specified string of text with the specified length. + ::nana::size text_extent_size(const ::std::wstring&, std::size_t length) const; ///< Computes the width and height of the specified string of text with the specified length. + ::nana::size glyph_extent_size(const wchar_t*, std::size_t length, std::size_t begin, std::size_t end) const; + ::nana::size glyph_extent_size(const ::std::wstring&, std::size_t length, std::size_t begin, std::size_t end) const; + bool glyph_pixels(const wchar_t *, std::size_t length, unsigned* pxbuf) const; ::nana::size bidi_extent_size(const std::wstring&) const; ::nana::size bidi_extent_size(const std::string&) const; @@ -136,13 +138,10 @@ namespace nana /// @param file_utf8 A UTF-8 string to a filename void save_as_file(const char* file_utf8) const throw(); - void set_color(const ::nana::color&); //deprecated, graphics::palette() instead - void set_text_color(const ::nana::color&); //deprecated, graphics::palette() instead - ::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); @@ -150,10 +149,13 @@ namespace nana void set_pixel(int x, int y, const ::nana::color&); void set_pixel(int x, int y); - void string(point, const char_t*, std::size_t len); - void string(const point&, const char_t*); - void string(const point&, const ::nana::string&); - void string(const point&, const ::nana::string&, const color&); + void string(const point&, const std::string& text_utf8); + void string(const point&, const std::string& text_utf8, const color&); + + void string(point, const wchar_t*, std::size_t len); + void string(const point&, const wchar_t*); + void string(const point&, const ::std::wstring&); + void string(const point&, const ::std::wstring&, const color&); void line(const point&, const point&); void line(const point&, const point&, const color&); diff --git a/include/nana/paint/image.hpp b/include/nana/paint/image.hpp index b1c237bc..e3f0e37e 100644 --- a/include/nana/paint/image.hpp +++ b/include/nana/paint/image.hpp @@ -15,6 +15,7 @@ #define NANA_PAINT_IMAGE_HPP #include "graphics.hpp" +#include "../filesystem/filesystem.hpp" namespace nana { @@ -31,12 +32,18 @@ namespace paint image(); image(const image&); image(image&&); - image(const nana::char_t* file); - image(const nana::string& filename); + image(const ::nana::experimental::filesystem::path& file); + + template + image(const Source& source) + { + open(source); + } + ~image(); image& operator=(const image& rhs); image& operator=(image&&); - bool open(const nana::string& filename); + bool open(const ::nana::experimental::filesystem::path& file); /// Opens an icon from a specified buffer bool open_icon(const void* data, std::size_t bytes); 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/dataexch.hpp b/include/nana/system/dataexch.hpp index ecfe9b22..575a79c3 100644 --- a/include/nana/system/dataexch.hpp +++ b/include/nana/system/dataexch.hpp @@ -1,6 +1,6 @@ /* * Data Exchanger Implementation - * 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 @@ -21,22 +21,26 @@ namespace paint{ } namespace system{ - /// a data exchange mechanism through Windows Clipboard, X11 Selection. + + /// a data exchange mechanism through Windows Clipboard, X11 Selection. class dataexch { public: - struct format + enum class format { - enum{ text, unicode, pixmap, end}; + text, pixmap }; - void set(const nana::char_t* text); - void set(const nana::string& text); + void set(const std::string & text_utf8); + void set(const std::wstring& text); + bool set(const nana::paint::graphics& g); - void get(nana::string& str); + + void get(std::string& text_utf8); + void get(std::wstring& text); private: - bool _m_set(unsigned type, const void* buf, std::size_t size); - void* _m_get(unsigned type, size_t& size); + bool _m_set(format, const void* buf, std::size_t size); + void* _m_get(format, size_t& size); }; }//end namespace system 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/include/nana/traits.hpp b/include/nana/traits.hpp index d1c5c56e..ae27f9ff 100644 --- a/include/nana/traits.hpp +++ b/include/nana/traits.hpp @@ -1,6 +1,6 @@ /* * Traits Implementation - * Copyright(C) 2003-2013 Jinhao(cnjinhao@hotmail.com) + * Copyright(C) 2003-2016 Jinhao(cnjinhao@hotmail.com) * * @file: nana/traits.hpp */ @@ -13,502 +13,24 @@ namespace nana { class null_type{}; - //The class noncopyable and nonmovable will be deprecated while the compiler - //supports the deleted functions - struct noncopyable + /// Prevent a class to be copyable + class noncopyable { noncopyable(const noncopyable&) = delete; noncopyable& operator=(const noncopyable&) = delete; - noncopyable(); + protected: + noncopyable() = default; }; - struct nonmovable + /// Prevent a class to be movable + class nonmovable { nonmovable(nonmovable&&) = delete; nonmovable& operator=(nonmovable&&) = delete; - nonmovable(); + protected: + nonmovable() = default; }; - namespace traits - { - //traits types for const-volatile specifier - - struct no_specifier{}; - struct const_specifier{}; - struct volatile_specifier{}; - struct const_volatile_specifier{}; - - template - struct cv_specifier - { - typedef no_specifier value_type; - }; - - template - struct cv_specifier - { - typedef const_specifier value_type; - }; - - template - struct cv_specifier - { - typedef volatile_specifier value_type; - }; - - template - struct cv_specifier - { - typedef const_volatile_specifier value_type; - }; - - template - struct is_function_pointer - : public std::integral_constant::value && std::is_function::type>::value> - {}; - - //The traits of pointer to member function - template - struct mfptr_traits - { - typedef void function(); - typedef void return_type; - typedef void concept_type; - enum{parameter = 0}; - }; - - template - struct mfptr_traits - { - typedef Concept concept_type; - typedef R return_type; - typedef return_type function(); - enum{parameter = 0}; - }; - - template - struct mfptr_traits - { - typedef Concept concept_type; - typedef R return_type; - typedef return_type function(); - enum{parameter = 0}; - }; - - template - struct mfptr_traits - { - typedef Concept concept_type; - typedef R return_type; - typedef return_type function(); - enum{parameter = 0}; - }; - - template - struct mfptr_traits - { - typedef Concept concept_type; - typedef R return_type; - typedef return_type function(); - enum{parameter = 0}; - }; - - template - struct mfptr_traits - { - typedef Concept concept_type; - typedef R return_type; - typedef P param0_type; - typedef return_type function(param0_type); - enum{parameter = 1}; - }; - - template - struct mfptr_traits - { - typedef Concept concept_type; - typedef R return_type; - typedef P param0_type; - typedef return_type function(param0_type); - enum{parameter = 1}; - }; - - template - struct mfptr_traits - { - typedef Concept concept_type; - typedef R return_type; - typedef P param0_type; - typedef return_type function(param0_type); - enum{parameter = 1}; - }; - - template - struct mfptr_traits - { - typedef Concept concept_type; - typedef R return_type; - typedef P0 param0_type; - typedef P1 param1_type; - typedef return_type function(param0_type, param1_type); - enum{parameter = 2}; - }; - - template - struct mfptr_traits - { - typedef Concept concept_type; - typedef R return_type; - typedef P0 param0_type; - typedef P1 param1_type; - typedef return_type function(param0_type, param1_type); - enum{parameter = 2}; - }; - - template - struct mfptr_traits - { - typedef Concept concept_type; - typedef R return_type; - typedef P0 param0_type; - typedef P1 param1_type; - typedef return_type function(param0_type, param1_type); - enum{parameter = 2}; - }; - - template - struct mfptr_traits - { - typedef Concept concept_type; - typedef R return_type; - typedef P0 param0_type; - typedef P1 param1_type; - typedef P2 param2_type; - typedef return_type function(param0_type, param1_type, param2_type); - enum{parameter =3}; - }; - - template - struct mfptr_traits - { - typedef Concept concept_type; - typedef R return_type; - typedef P0 param0_type; - typedef P1 param1_type; - typedef P2 param2_type; - typedef return_type function(param0_type, param1_type, param2_type); - enum{parameter =3}; - }; - - template - struct mfptr_traits - { - typedef Concept concept_type; - typedef R return_type; - typedef P0 param0_type; - typedef P1 param1_type; - typedef P2 param2_type; - typedef return_type function(param0_type, param1_type, param2_type); - enum{parameter =3}; - }; - - template - struct mfptr_traits - { - typedef Concept concept_type; - typedef R return_type; - typedef P0 param0_type; - typedef P1 param1_type; - typedef P2 param2_type; - typedef return_type function(param0_type, param1_type, param2_type); - enum{parameter =3}; - }; - - template - struct mfptr_traits - { - typedef Concept concept_type; - typedef R return_type; - typedef P0 param0_type; - typedef P1 param1_type; - typedef P2 param2_type; - typedef P3 param3_type; - typedef return_type function(param0_type, param1_type, param2_type, param3_type); - enum{parameter = 4}; - }; - - template - struct mfptr_traits - { - typedef Concept concept_type; - typedef R return_type; - typedef P0 param0_type; - typedef P1 param1_type; - typedef P2 param2_type; - typedef P3 param3_type; - typedef return_type function(param0_type, param1_type, param2_type, param3_type); - enum{parameter = 4}; - }; - - template - struct mfptr_traits - { - typedef Concept concept_type; - typedef R return_type; - typedef P0 param0_type; - typedef P1 param1_type; - typedef P2 param2_type; - typedef P3 param3_type; - typedef return_type function(param0_type, param1_type, param2_type, param3_type); - enum{parameter = 4}; - }; - - template - struct mfptr_traits - { - typedef Concept concept_type; - typedef R return_type; - typedef P0 param0_type; - typedef P1 param1_type; - typedef P2 param2_type; - typedef P3 param3_type; - typedef return_type function(param0_type, param1_type, param2_type, param3_type); - enum{parameter = 4}; - }; - - template - struct mfptr_traits - { - typedef Concept concept_type; - typedef R return_type; - typedef P0 param0_type; - typedef P1 param1_type; - typedef P2 param2_type; - typedef P3 param3_type; - typedef P4 param4_type; - typedef return_type function(param0_type, param1_type, param2_type, param3_type, param4_type); - enum{parameter = 5}; - }; - - template - struct mfptr_traits - { - typedef Concept concept_type; - typedef R return_type; - typedef P0 param0_type; - typedef P1 param1_type; - typedef P2 param2_type; - typedef P3 param3_type; - typedef P4 param4_type; - typedef return_type function(param0_type, param1_type, param2_type, param3_type, param4_type); - enum{parameter = 5}; - }; - - template - struct mfptr_traits - { - typedef Concept concept_type; - typedef R return_type; - typedef P0 param0_type; - typedef P1 param1_type; - typedef P2 param2_type; - typedef P3 param3_type; - typedef P4 param4_type; - typedef return_type function(param0_type, param1_type, param2_type, param3_type, param4_type); - enum{parameter = 5}; - }; - - template - struct mfptr_traits - { - typedef Concept concept_type; - typedef R return_type; - typedef P0 param0_type; - typedef P1 param1_type; - typedef P2 param2_type; - typedef P3 param3_type; - typedef P4 param4_type; - typedef return_type function(param0_type, param1_type, param2_type, param3_type, param4_type); - enum{parameter = 5}; - }; - - - - template - struct make_mf - { - typedef int type; - }; - - template - struct make_mf - { - typedef R(Concept::*type)(); - }; - - template - struct make_mf - { - typedef R(Concept::*type)() const; - }; - - template - struct make_mf - { - typedef R(Concept::*type)() volatile; - }; - - template - struct make_mf - { - typedef R(Concept::*type)() const volatile; - }; - - template - struct make_mf - { - typedef R(Concept::*type)(P0); - }; - - template - struct make_mf - { - typedef R(Concept::*type)(P0) const; - }; - - template - struct make_mf - { - typedef R(Concept::*type)(P0) volatile; - }; - - template - struct make_mf - { - typedef R(Concept::*type)(P0) const volatile; - }; - - template - struct make_mf - { - typedef R(Concept::*type)(P0, P1); - }; - - template - struct make_mf - { - typedef R(Concept::*type)(P0, P1) const; - }; - - template - struct make_mf - { - typedef R(Concept::*type)(P0, P1) volatile; - }; - - template - struct make_mf - { - typedef R(Concept::*type)(P0, P1) const volatile; - }; - - template - struct make_mf - { - typedef R(Concept::*type)(P0, P1, P2); - }; - - template - struct make_mf - { - typedef R(Concept::*type)(P0, P1, P2) const; - }; - - template - struct make_mf - { - typedef R(Concept::*type)(P0, P1, P2) volatile; - }; - - template - struct make_mf - { - typedef R(Concept::*type)(P0, P1, P2) const volatile; - }; - - template - struct make_mf - { - typedef R(Concept::*type)(P0, P1, P2, P3); - }; - - template - struct make_mf - { - typedef R(Concept::*type)(P0, P1, P2, P3) const; - }; - - template - struct make_mf - { - typedef R(Concept::*type)(P0, P1, P2, P3) volatile; - }; - - template - struct make_mf - { - typedef R(Concept::*type)(P0, P1, P2, P3) const volatile; - }; - - template - struct make_mf - { - typedef R(Concept::*type)(P0, P1, P2, P3, P4); - }; - - template - struct make_mf - { - typedef R(Concept::*type)(P0, P1, P2, P3, P4) const; - }; - - template - struct make_mf - { - typedef R(Concept::*type)(P0, P1, P2, P3, P4) volatile; - }; - - template - struct make_mf - { - typedef R(Concept::*type)(P0, P1, P2, P3, P4) const volatile; - }; - - template - struct make_mf - { - typedef R(Concept::*type)(P0, P1, P2, P3, P4, P5); - }; - - template - struct make_mf - { - typedef R(Concept::*type)(P0, P1, P2, P3, P4, P5) const; - }; - - template - struct make_mf - { - typedef R(Concept::*type)(P0, P1, P2, P3, P4, P5) volatile; - }; - - template - struct make_mf - { - typedef R(Concept::*type)(P0, P1, P2, P3, P4, P5) const volatile; - }; - }//end namespace traits - namespace meta { template< typename Param0 = null_type, typename Param1 = null_type, diff --git a/source/audio/detail/audio_stream.cpp b/source/audio/detail/audio_stream.cpp index 902911a0..3446ac04 100644 --- a/source/audio/detail/audio_stream.cpp +++ b/source/audio/detail/audio_stream.cpp @@ -6,9 +6,9 @@ namespace nana{ namespace audio namespace detail { //class audio_stream - bool audio_stream::open(const nana::string& file) + bool audio_stream::open(const std::string& file) { - fs_.open(static_cast(charset(file)), std::ios::binary); + fs_.open(to_osmbstr(file), std::ios::binary); if(fs_) { wave_spec::master_riff_chunk riff; diff --git a/source/audio/player.cpp b/source/audio/player.cpp index 5941c073..013b331e 100644 --- a/source/audio/player.cpp +++ b/source/audio/player.cpp @@ -17,7 +17,7 @@ namespace nana{ namespace audio : impl_(new implementation) {} - player::player(const nana::string& file) + player::player(const std::string& file) : impl_(new implementation) { open(file); @@ -28,7 +28,7 @@ namespace nana{ namespace audio delete impl_; } - bool player::open(const nana::string& file) + bool player::open(const std::string& file) { if(impl_->stream.open(file)) { diff --git a/source/charset.cpp b/source/charset.cpp index 1b57ad29..eed89a8d 100644 --- a/source/charset.cpp +++ b/source/charset.cpp @@ -18,6 +18,7 @@ #include #include #include +#include //GCC 4.7.0 does not implement the and codecvt_utfx classes #ifndef STD_CODECVT_NOT_SUPPORTED @@ -30,6 +31,183 @@ namespace nana { + namespace utf + { + const char* char_ptr(const char* text, unsigned pos) + { + auto ustr = reinterpret_cast(text); + auto const end = ustr + std::strlen(text); + + for (unsigned i = 0; i != pos; ++i) + { + const auto uch = *ustr; + if (uch < 0x80) + { + ++ustr; + continue; + } + + if (uch < 0xC0) + return nullptr; + + if ((uch < 0xE0) && (ustr + 1 < end)) + ustr += 2; + else if (uch < 0xF0 && (ustr + 2 <= end)) + ustr += 3; + else if (uch < 0x1F && (ustr + 3 <= end)) + ustr += 4; + else + return nullptr; + } + + return reinterpret_cast(ustr); + } + + const char* char_ptr(const std::string& text_utf8, unsigned pos) + { + auto ustr = reinterpret_cast(text_utf8.c_str()); + auto const end = ustr + text_utf8.size(); + + for (unsigned i = 0; i != pos; ++i) + { + const auto uch = *ustr; + if (uch < 0x80) + { + ++ustr; + continue; + } + + if (uch < 0xC0) + return nullptr; + + if ((uch < 0xE0) && (ustr + 1 < end)) + ustr += 2; + else if (uch < 0xF0 && (ustr + 2 <= end)) + ustr += 3; + else if (uch < 0x1F && (ustr + 3 <= end)) + ustr += 4; + else + return nullptr; + } + + return reinterpret_cast(ustr); + } + + wchar_t char_at(const char* text_utf8, unsigned pos, unsigned * len) + { + if (!text_utf8) + return 0; + + if (pos) + { + text_utf8 = char_ptr(text_utf8, pos); + if (!text_utf8) + return 0; + } + + const wchar_t uch = *reinterpret_cast(text_utf8); + if (uch < 0x80) + { + if (len) + *len = 1; + + return *text_utf8; + } + + if (uch < 0xC0) + { + if (len) + *len = 0; + + return 0; + } + + const auto end = text_utf8 + std::strlen(text_utf8); + + if (uch < 0xE0 && (text_utf8 + 1 <= end)) + { + if (len) + *len = 2; + return (wchar_t(uch & 0x1F) << 6) | (reinterpret_cast(text_utf8)[1] & 0x3F); + } + else if (uch < 0xF0 && (text_utf8 + 2 <= end)) + { + if (len) + *len = 3; + + return ((((uch & 0xF) << 6) | (reinterpret_cast(text_utf8)[1] & 0x3F)) << 6) | (reinterpret_cast(text_utf8)[2] & 0x3F); + } + else if (uch < 0x1F && (text_utf8 + 3 <= end)) + { + if (len) + *len = 4; + return ((((((uch & 0x7) << 6) | (reinterpret_cast(text_utf8)[1] & 0x3F)) << 6) | (reinterpret_cast(text_utf8)[2] & 0x3F)) << 6) | (reinterpret_cast(text_utf8)[3] & 0x3F); + } + + if (len) + *len = 0; + + return 0; + } + + wchar_t char_at(const ::std::string& text_utf8, unsigned pos, unsigned * len) + { + const char* ptr; + if (pos) + { + ptr = char_ptr(text_utf8, pos); + if (!ptr) + return 0; + } + else + ptr = text_utf8.c_str(); + + const wchar_t uch = *reinterpret_cast(ptr); + if (uch < 0x80) + { + if (len) + *len = 1; + + return *ptr; + } + + if (uch < 0xC0) + { + if (len) + *len = 0; + + return 0; + } + + const auto end = text_utf8.c_str() + text_utf8.size(); + + if (uch < 0xE0 && (ptr + 1 <= end)) + { + if (len) + *len = 2; + return (wchar_t(uch & 0x1F) << 6) | (reinterpret_cast(ptr)[1] & 0x3F); + } + else if (uch < 0xF0 && (ptr + 2 <= end)) + { + if (len) + *len = 3; + + return ((((uch & 0xF) << 6) | (reinterpret_cast(ptr)[1] & 0x3F)) << 6) | (reinterpret_cast(ptr)[2] & 0x3F); + } + else if (uch < 0x1F && (ptr + 3 <= end)) + { + if (len) + *len = 4; + return ((((((uch & 0x7) << 6) | (reinterpret_cast(ptr)[1] & 0x3F)) << 6) | (reinterpret_cast(ptr)[2] & 0x3F)) << 6) | (reinterpret_cast(ptr)[3] & 0x3F); + } + + if (len) + *len = 0; + + return 0; + } + } + namespace detail { class locale_initializer diff --git a/source/deploy.cpp b/source/deploy.cpp index 0f751352..2594de28 100644 --- a/source/deploy.cpp +++ b/source/deploy.cpp @@ -14,6 +14,7 @@ #include #include +#include //std::strlen #include #if defined(NANA_WINDOWS) @@ -437,46 +438,174 @@ namespace std namespace nana { - std::size_t strlen(const char_t* str) + bool is_utf8(const char* str, unsigned len) { -#if defined(NANA_UNICODE) - return ::wcslen(str); -#else - return ::strlen(str); -#endif - } + auto ustr = reinterpret_cast(str); + auto end = ustr + len; - char_t* strcpy(char_t* dest, const char_t* source) - { -#if defined(NANA_UNICODE) - return ::wcscpy(dest, source); -#else - return ::strcpy(dest, source); -#endif - } -} - -namespace nana -{ - bool is_incomplete(const nana::string& str, unsigned pos) - { -#ifndef NANA_UNICODE - if(pos > str.size()) - pos = static_cast(str.size()); - const nana::char_t * pstr = str.c_str(); - if(pstr[pos] < 0) + while (ustr < end) { - bool incomp = false; - for(unsigned i = 0; i < pos; ++i) + const auto uv = *ustr; + if (uv < 0x80) { - if(pstr[i] < 0) - incomp = !incomp; - else - incomp = false; + ++ustr; + continue; } - return incomp; + + if (uv < 0xC0) + return false; + + if ((uv < 0xE0) && (ustr + 1 < end)) + ustr += 2; + else if (uv < 0xF0 && (ustr + 2 <= end)) + ustr += 3; + else if (uv < 0x1F && (ustr + 3 <= end)) + ustr += 4; + else + return false; } -#endif - return false; + + return true; } + + void throw_not_utf8(const std::string& text) + { + if (!is_utf8(text.c_str(), text.length())) + throw std::invalid_argument("The text is not encoded in UTF8"); + } + + void throw_not_utf8(const char* text, unsigned len) + { + if (!is_utf8(text, len)) + throw std::invalid_argument("The text is not encoded in UTF8"); + } + + void throw_not_utf8(const char* text) + { + if (!is_utf8(text, std::strlen(text))) + throw std::invalid_argument("The text is not encoded in UTF8"); + + } + + std::wstring utf8_cast(const std::string& text) + { + return ::nana::charset(text, ::nana::unicode::utf8); + } + + std::string utf8_cast(const std::wstring& text) + { + return ::nana::charset(text).to_bytes(::nana::unicode::utf8); + } + + const std::string& to_utf8(const std::string& str) + { + return str; + } + + std::string to_utf8(const std::wstring& text) + { + return ::nana::charset(text).to_bytes(::nana::unicode::utf8); + } + + std::wstring to_wstring(const std::string& utf8_str) + { + return ::nana::charset(utf8_str, ::nana::unicode::utf8); + } + + const std::wstring& to_wstring(const std::wstring& wstr) + { + return wstr; + } + + std::wstring&& to_wstring(std::wstring&& wstr) + { + return static_cast(wstr); + } + +#if defined(NANA_WINDOWS) + std::string to_osmbstr(const std::string& text_utf8) + { + return ::nana::charset(text_utf8, ::nana::unicode::utf8); + } +#else + std::string to_osmbstr(std::string text_utf8) + { + return text_utf8; + } +#endif + +#if defined(NANA_WINDOWS) + const detail::native_string_type to_nstring(const std::string& text) + { + return ::nana::charset(text, ::nana::unicode::utf8); + } + + const detail::native_string_type& to_nstring(const std::wstring& text) + { + return text; + } + + detail::native_string_type to_nstring(std::string&& text) + { + return ::nana::charset(text, ::nana::unicode::utf8); + } + + detail::native_string_type&& to_nstring(std::wstring&& text) + { + return std::move(text); + } + + detail::native_string_type to_nstring(int n) + { + return std::to_wstring(n); + } + + detail::native_string_type to_nstring(double d) + { + return std::to_wstring(d); + } + + detail::native_string_type to_nstring(std::size_t d) + { + return std::to_wstring(d); + } +#else //POSIX + const detail::native_string_type& to_nstring(const std::string& text) + { + return text; + } + + const detail::native_string_type to_nstring(const std::wstring& text) + { + return ::nana::charset(text).to_bytes(::nana::unicode::utf8); + } + + detail::native_string_type&& to_nstring(std::string&& text) + { + return std::move(text); + } + + detail::native_string_type to_nstring(std::wstring&& text) + { + return ::nana::charset(text).to_bytes(::nana::unicode::utf8); + } + + detail::native_string_type to_nstring(int n) + { + return std::to_string(n); + } + + detail::native_string_type to_nstring(double d) + { + return std::to_string(d); + } + + detail::native_string_type to_nstring(std::size_t d) + { + return std::to_string(d); + } +#endif + + } + diff --git a/source/detail/platform_spec_posix.cpp b/source/detail/platform_spec_posix.cpp index 33d81a75..4f277518 100644 --- a/source/detail/platform_spec_posix.cpp +++ b/source/detail/platform_spec_posix.cpp @@ -515,7 +515,7 @@ namespace detail atombase_.xdnd_finished = ::XInternAtom(display_, "XdndFinished", False); //Create default font object. - def_font_ptr_ = make_native_font(0, font_size_to_height(10), 400, false, false, false); + def_font_ptr_ = make_native_font(nullptr, font_size_to_height(10), 400, false, false, false); msg_dispatcher_ = new msg_dispatcher(display_); } @@ -550,17 +550,16 @@ namespace detail return height; } - platform_spec::font_ptr_t platform_spec::make_native_font(const nana::char_t* name, unsigned height, unsigned weight, bool italic, bool underline, bool strike_out) + platform_spec::font_ptr_t platform_spec::make_native_font(const char* name, unsigned height, unsigned weight, bool italic, bool underline, bool strike_out) { font_ptr_t ref; -#if defined(NANA_UNICODE) +#if 1 //Xft if(0 == name || *name == 0) - name = STR("*"); + name = "*"; - std::string nmstr = nana::charset(name); XftFont* handle = 0; std::stringstream ss; - ss< * files = new std::vector; + auto files = new std::vector; std::stringstream ss(reinterpret_cast(data)); while(true) { @@ -1235,7 +1234,7 @@ namespace detail break; } - files->push_back(nana::charset(file)); + files->push_back(file); } if(files->size()) { @@ -1244,6 +1243,8 @@ namespace detail msg.u.mouse_drop.y = self.xdnd_.pos.y; msg.u.mouse_drop.files = files; } + else + delete files; accepted = true; ::XFree(data); diff --git a/source/detail/platform_spec_windows.cpp b/source/detail/platform_spec_windows.cpp index 0323dfc1..de46dbea 100644 --- a/source/detail/platform_spec_windows.cpp +++ b/source/detail/platform_spec_windows.cpp @@ -158,7 +158,7 @@ namespace detail //class platform_spec platform_spec::co_initializer::co_initializer() - : ole32_(::LoadLibrary(STR("OLE32.DLL"))) + : ole32_(::LoadLibrary(L"OLE32.DLL")) { if(ole32_) { @@ -207,7 +207,7 @@ namespace detail #endif #endif ::SystemParametersInfo(SPI_GETNONCLIENTMETRICS, sizeof metrics, &metrics, 0); - def_font_ptr_ = make_native_font(metrics.lfMessageFont.lfFaceName, font_size_to_height(9), 400, false, false, false); + def_font_ptr_ = make_native_font(utf8_cast(metrics.lfMessageFont.lfFaceName).c_str(), font_size_to_height(9), 400, false, false, false); } const platform_spec::font_ptr_t& platform_spec::default_native_font() const @@ -238,12 +238,15 @@ namespace detail return height; } - platform_spec::font_ptr_t platform_spec::make_native_font(const nana::char_t* name, unsigned height, unsigned weight, bool italic, bool underline, bool strike_out) + platform_spec::font_ptr_t platform_spec::make_native_font(const char* name, unsigned height, unsigned weight, bool italic, bool underline, bool strike_out) { ::LOGFONT logfont; memset(&logfont, 0, sizeof logfont); - strcpy(logfont.lfFaceName, (name && *name ? name : def_font_ptr_->name.c_str())); + if (name && *name) + std::wcscpy(logfont.lfFaceName, utf8_cast(name).c_str()); + else + std::wcscpy(logfont.lfFaceName, def_font_ptr_->name.c_str()); logfont.lfCharSet = DEFAULT_CHARSET; HDC hdc = ::GetDC(0); diff --git a/source/filesystem/file_iterator.cpp b/source/filesystem/file_iterator.cpp index 8880f77d..c570f5ce 100644 --- a/source/filesystem/file_iterator.cpp +++ b/source/filesystem/file_iterator.cpp @@ -24,12 +24,12 @@ namespace filesystem {} #if defined(NANA_WINDOWS) fileinfo::fileinfo(const WIN32_FIND_DATA& wfd) - : name(wfd.cFileName), size(wfd.nFileSizeLow), + : name(utf8_cast(wfd.cFileName)), size(wfd.nFileSizeLow), directory((FILE_ATTRIBUTE_DIRECTORY & wfd.dwFileAttributes) == FILE_ATTRIBUTE_DIRECTORY) { } #elif defined(NANA_LINUX) || defined(NANA_MACOS) - fileinfo::fileinfo(const nana::string& name, const struct stat& fst) + fileinfo::fileinfo(const ::std::string& name, const struct stat& fst) :name(name), size(fst.st_size), directory(0 != S_ISDIR(fst.st_mode)) { } diff --git a/source/filesystem/filesystem.cpp b/source/filesystem/filesystem.cpp index f83647af..471c718e 100644 --- a/source/filesystem/filesystem.cpp +++ b/source/filesystem/filesystem.cpp @@ -1,6 +1,6 @@ /* * A ISO C++ FileSystem Implementation - * Copyright(C) 2003-2015 Jinhao(cnjinhao@hotmail.com) + * Copyright(C) 2003-2016 Jinhao(cnjinhao@hotmail.com) * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at @@ -36,134 +36,220 @@ #include #endif -namespace nana { - namespace experimental +namespace nana { namespace experimental { + namespace filesystem { - namespace filesystem - { - //Because of No wide character version of POSIX + //Because of No wide character version of POSIX #if defined(NANA_LINUX) || defined(NANA_MACOS) - typedef std::string string_t; - const char* splstr = "/\\"; + const char* splstr = "/"; #else - typedef nana::string string_t; - const nana::char_t* splstr = STR("/\\"); + const wchar_t* splstr = L"/\\"; #endif - //class path - path::path() {} - path::path(const nana::string& text) + //class file_status + file_status::file_status(file_type ft, perms prms) + : value_{ft}, perms_{prms} + {} + + file_type file_status::type() const + { + return value_; + } + + void file_status::type(file_type ft) + { + value_ = ft; + } + + perms file_status::permissions() const + { + return perms_; + } + + void file_status::permissions(perms prms) + { + perms_ = prms; + } + //end filestatus + + //class path + path::path() {} + + int path::compare(const path& p) const + { + return pathstr_.compare(p.pathstr_); + } + + bool path::empty() const + { #if defined(NANA_WINDOWS) - : text_(text) - { + return (::GetFileAttributes(pathstr_.c_str()) == INVALID_FILE_ATTRIBUTES); +#elif defined(NANA_LINUX) || defined(NANA_MACOS) + struct stat sta; + return (::stat(pathstr_.c_str(), &sta) == -1); +#endif + } + + path path::extension() const + { +#if defined(NANA_WINDOWS) + auto pos = pathstr_.find_last_of(L"\\/."); #else - :text_(nana::charset(text)) - { + auto pos = pathstr_.find_last_of("\\/."); #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); - } + if ((pos == pathstr_.npos) || (pathstr_[pos] != '.')) + return path(); - bool path::empty() const - { + + if (pos + 1 == pathstr_.size()) + return path(); + + return path(pathstr_.substr(pos)); + } + + path path::parent_path() const + { + return{filesystem::parent_path(pathstr_)}; + } + + file_type path::what() const + { #if defined(NANA_WINDOWS) - return (::GetFileAttributes(text_.c_str()) == INVALID_FILE_ATTRIBUTES); + unsigned long attr = ::GetFileAttributes(pathstr_.c_str()); + if (INVALID_FILE_ATTRIBUTES == attr) + return file_type::not_found; //?? + + if (FILE_ATTRIBUTE_DIRECTORY & attr) + return file_type::directory; + + return file_type::regular; #elif defined(NANA_LINUX) || defined(NANA_MACOS) - struct stat sta; - return (::stat(text_.c_str(), &sta) == -1); -#endif - } + struct stat sta; + if (-1 == ::stat(pathstr_.c_str(), &sta)) + return file_type::not_found; //?? - 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 - } - - file_type path::what() const - { -#if defined(NANA_WINDOWS) - unsigned long attr = ::GetFileAttributes(text_.c_str()); - if (INVALID_FILE_ATTRIBUTES == attr) - return file_type::not_found; //?? - - if (FILE_ATTRIBUTE_DIRECTORY & attr) - return file_type::directory; + if ((S_IFDIR & sta.st_mode) == S_IFDIR) + return file_type::directory; + if ((S_IFREG & sta.st_mode) == S_IFREG) return file_type::regular; -#elif defined(NANA_LINUX) || defined(NANA_MACOS) - struct stat sta; - if (-1 == ::stat(text_.c_str(), &sta)) - return file_type::not_found; //?? - if ((S_IFDIR & sta.st_mode) == S_IFDIR) - return file_type::directory; - - if ((S_IFREG & sta.st_mode) == S_IFREG) - return file_type::regular; - - return file_type::none; + return file_type::none; #endif + } + + path path::filename() const + { + auto pos = pathstr_.find_last_of(splstr); + if (pos != pathstr_.npos) + { + if (pos + 1 == pathstr_.size()) + { + value_type tmp[2] = {preferred_separator, 0}; + + if (pathstr_.npos != pathstr_.find_last_not_of(splstr, pos)) + tmp[0] = '.'; + + return{ tmp }; + } + return{ pathstr_.substr(pos + 1) }; } - nana::string path::filename() const - { - string_t::size_type pos = text_.find_last_of(splstr); + return{ pathstr_ }; + } + + const path::value_type* path::c_str() const + { + return native().c_str(); + } + + const path::string_type& path::native() const + { + return pathstr_; + } + + path::operator string_type() const + { + return native(); + } + + std::string path::string() const + { + return to_osmbstr(to_utf8(pathstr_)); + } + + std::wstring path::wstring() const + { + return to_wstring(pathstr_); + } + + std::string path::u8string() const + { + return to_utf8(pathstr_); + } + + void path::_m_assign(const std::string& source_utf8) + { #if defined(NANA_WINDOWS) - return text_.substr(pos + 1); + pathstr_ = utf8_cast(source_utf8); #else - return nana::charset(text_.substr(pos + 1)); + pathstr_ = source_utf8; #endif - } - //end class path + } - namespace detail - { + void path::_m_assign(const std::wstring& source) + { +#if defined(NANA_WINDOWS) + pathstr_ = source; +#else + pathstr_ = utf8_cast(source); +#endif + } + //end class path + + bool operator==(const path& lhs, const path& rhs) + { + return (lhs.compare(rhs) == 0); + } + + bool operator!=(const path& lhs, const path& rhs) + { + return (lhs.native() != rhs.native()); + } + + bool operator<(const path& lhs, const path& rhs) + { + return (lhs.compare(rhs) < 0); + } + + bool operator>(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); - } - - 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; + return rmdir(dir, true); } #if defined(NANA_WINDOWS) @@ -188,34 +274,83 @@ namespace nana { #endif }//end namespace detail - bool file_attrib(const nana::string& file, attribute& attr) - { + bool not_found_error(int errval) + { #if defined(NANA_WINDOWS) - WIN32_FILE_ATTRIBUTE_DATA fad; - if (::GetFileAttributesEx(file.c_str(), GetFileExInfoStandard, &fad)) - { - LARGE_INTEGER li; - li.u.LowPart = fad.nFileSizeLow; - li.u.HighPart = fad.nFileSizeHigh; - attr.size = li.QuadPart; - attr.directory = (0 != (fad.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)); - detail::filetime_to_c_tm(fad.ftLastWriteTime, attr.modified); - return true; - } -#elif defined(NANA_LINUX) || defined(NANA_MACOS) - struct stat fst; - if (0 == ::stat(static_cast(nana::charset(file)).c_str(), &fst)) - { - attr.size = fst.st_size; - attr.directory = (0 != (040000 & fst.st_mode)); - attr.modified = *(::localtime(&fst.st_ctime)); - return true; - } + switch (errval) + { + case ERROR_FILE_NOT_FOUND: + case ERROR_PATH_NOT_FOUND: + case ERROR_INVALID_NAME: + case ERROR_INVALID_DRIVE: + case ERROR_NOT_READY: + case ERROR_INVALID_PARAMETER: + case ERROR_BAD_PATHNAME: + case ERROR_BAD_NETPATH: + return true; + } + return false; +#elif defined(NANA_POSIX) + return (errval == ENOENT || errval == ENOTDIR); +#else + static_assert(false, "Only Windows and Unix are supported now (Mac OS is experimental)"); #endif - return false; + } + + file_status status(const path& p) + { +#if defined(NANA_WINDOWS) + auto attr = ::GetFileAttributesW(p.c_str()); + if (INVALID_FILE_ATTRIBUTES == attr) + { + if (not_found_error(static_cast(::GetLastError()))) + return file_status{file_type::not_found}; + return file_status{ file_type::unknown }; + } + return file_status{(FILE_ATTRIBUTE_DIRECTORY & attr) ? file_type::directory : file_type::regular, perms::all}; +#elif defined(NANA_POSIX) + struct stat path_stat; + if(0 != ::stat(p.c_str(), &path_stat)) + { + if(errno == ENOENT || errno == ENOTDIR) + return file_status{file_type::not_found}; + + return file_status{file_type::unknown}; } - uintmax_t file_size(const nana::string& file) + auto prms = static_cast(path_stat.st_mode & static_cast(perms::mask)); + + if(S_ISREG(path_stat.st_mode)) + return file_status{file_type::regular, prms}; + + if(S_ISDIR(path_stat.st_mode)) + return file_status{file_type::directory, prms}; + + if(S_ISLNK(path_stat.st_mode)) + return file_status{file_type::symlink, prms}; + + if(S_ISBLK(path_stat.st_mode)) + return file_status{file_type::block, prms}; + + if(S_ISCHR(path_stat.st_mode)) + return file_status{file_type::character, prms}; + + if(S_ISFIFO(path_stat.st_mode)) + return file_status{file_type::fifo, prms}; + + if(S_ISSOCK(path_stat.st_mode)) + return file_status{file_type::socket, prms}; + + return file_status{file_type::unknown}; +#endif + } + + bool is_directory(const path& p) + { + return (status(p).type() == file_type::directory); + } + + std::uintmax_t file_size(const path& p) { #if defined(NANA_WINDOWS) //Some compilation environment may fail to link to GetFileSizeEx @@ -223,7 +358,7 @@ namespace nana { GetFileSizeEx_fptr_t get_file_size_ex = reinterpret_cast(::GetProcAddress(::GetModuleHandleA("Kernel32.DLL"), "GetFileSizeEx")); if (get_file_size_ex) { - HANDLE handle = ::CreateFile(file.c_str(), GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); + HANDLE handle = ::CreateFile(p.c_str(), GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); if (INVALID_HANDLE_VALUE != handle) { LARGE_INTEGER li; @@ -235,30 +370,26 @@ namespace nana { } } return 0; -#elif defined(NANA_LINUX) - FILE * stream = ::fopen(static_cast(nana::charset(file)).c_str(), "rb"); +#elif defined(NANA_POSIX) + FILE * stream = ::fopen(p.c_str(), "rb"); long long size = 0; if (stream) { +# if defined(NANA_LINUX) fseeko64(stream, 0, SEEK_END); size = ftello64(stream); - fclose(stream); - } - return size; -#elif defined(NANA_MACOS) - FILE * stream = ::fopen(static_cast(nana::charset(file)).c_str(), "rb"); - long long size = 0; - if (stream) - { +# elif defined(NANA_MACOS) fseeko(stream, 0, SEEK_END); size = ftello(stream); - fclose(stream); +# endif + ::fclose(stream); } - return size; + return size; #endif } - bool modified_file_time(const nana::string& file, struct tm& t) + + bool modified_file_time(const std::wstring& file, struct tm& t) { #if defined(NANA_WINDOWS) WIN32_FILE_ATTRIBUTE_DATA attr; @@ -292,162 +423,116 @@ namespace nana { return false; } - bool create_directory(const nana::string& path, bool & if_exist) + + bool create_directory(const path& p) { - if_exist = false; - if (path.size() == 0) return false; - - nana::string root; #if defined(NANA_WINDOWS) - if (path.size() > 3 && path[1] == STR(':')) - root = path.substr(0, 3); -#elif defined(NANA_LINUX) || defined(NANA_MACOS) - if (path[0] == STR('/')) - root = '/'; + return (FALSE != ::CreateDirectoryW(p.c_str(), 0)); +#elif defined(NANA_POSIX) + return (0 == ::mkdir(p.c_str(), static_cast(perms::all))); #endif - bool mkstat = false; - std::size_t beg = root.size(); - - while (true) - { - beg = path.find_first_not_of(STR("/\\"), beg); - if (beg == path.npos) - break; - - std::size_t pos = path.find_first_of(STR("/\\"), beg + 1); - if (pos != path.npos) - { - root += path.substr(beg, pos - beg); - - mkstat = detail::mkdir_helper(root, if_exist); - if (mkstat == false && if_exist == false) - return false; - -#if defined(NANA_WINDOWS) - root += STR('\\'); -#elif defined(NANA_LINUX) || defined(NANA_MACOS) - root += STR('/'); -#endif - } - else - { - if (beg + 1 < path.size()) - { - root += path.substr(beg); - mkstat = detail::mkdir_helper(root, if_exist); - } - break; - } - beg = pos + 1; - } - return mkstat; } - bool rmfile(const nana::char_t* file) + bool rmfile(const path& p) { -#if defined(NANA_WINDOWS) - bool ret = false; - if (file) - { - ret = (::DeleteFile(file) == TRUE); - if (!ret) - ret = (ERROR_FILE_NOT_FOUND == ::GetLastError()); - } + if(p.empty()) + return false; +#if defined(NANA_WINDOWS) + if (FALSE == ::DeleteFileW(p.c_str())) + return (ERROR_FILE_NOT_FOUND == ::GetLastError()); - return ret; -#elif defined(NANA_LINUX) || defined(NANA_MACOS) - if (std::remove(static_cast(nana::charset(file)).c_str())) + return true; +#elif defined(NANA_POSIX) + if (std::remove(p.c_str())) return (errno == ENOENT); return true; #endif } - bool rmdir(const nana::char_t* dir, bool fails_if_not_empty) + + bool rmdir(const path& p, bool fails_if_not_empty) { - bool ret = false; - if (dir) - { + if(p.empty()) + return false; + #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) - std::string mbstr = nana::charset(dir); - if (::rmdir(mbstr.c_str())) - { - if (!fails_if_not_empty && (errno == EEXIST || errno == ENOTEMPTY)) - ret = detail::rm_dir_recursive(dir); - } - else - ret = true; -#endif + if(FALSE != ::RemoveDirectoryW(p.c_str())) + return true; + + if(!fails_if_not_empty && (ERROR_DIR_NOT_EMPTY == ::GetLastError())) + return detail::rm_dir_recursive(p.c_str()); + + return false; +#elif defined(NANA_POSIX) + if(::rmdir(p.c_str())) + { + if (!fails_if_not_empty && (errno == EEXIST || errno == ENOTEMPTY)) + return detail::rm_dir_recursive(p.c_str()); + + return false; } - return ret; + return true; +#endif } - 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() + path path_user() { #if defined(NANA_WINDOWS) - nana::char_t path[MAX_PATH]; - if (SUCCEEDED(SHGetFolderPath(0, CSIDL_PROFILE, 0, SHGFP_TYPE_CURRENT, path))) - return path; + wchar_t pstr[MAX_PATH]; + if (SUCCEEDED(SHGetFolderPath(0, CSIDL_PROFILE, 0, SHGFP_TYPE_CURRENT, pstr))) + return pstr; #elif defined(NANA_LINUX) || defined(NANA_MACOS) - const char * s = ::getenv("HOME"); - if (s) - return nana::charset(std::string(s, std::strlen(s)), nana::unicode::utf8); + const char * pstr = ::getenv("HOME"); + if (pstr) + return pstr; #endif - return nana::string(); + return path(); } path current_path() { #if defined(NANA_WINDOWS) - nana::char_t buf[MAX_PATH]; - DWORD len = ::GetCurrentDirectory(MAX_PATH, buf); + wchar_t buf[MAX_PATH]; + DWORD len = ::GetCurrentDirectoryW(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; + wchar_t * p = new wchar_t[len + 1]; + ::GetCurrentDirectoryW(len + 1, p); + std::wstring s = p; delete[] p; return s; } - return nana::string(buf); + return buf; + } +#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; } -#elif defined(NANA_LINUX) || defined(NANA_MACOS) - const char * s = ::getenv("PWD"); - if (s) - return static_cast(nana::charset(std::string(s, std::strlen(s)), nana::unicode::utf8)); #endif - return nana::string(); + 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 diff --git a/source/filesystem/fs_utility.cpp b/source/filesystem/fs_utility.cpp index c9cfd677..8b25d289 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 @@ -46,89 +47,18 @@ namespace filesystem typedef std::string string_t; const char* splstr = "/\\"; #else - typedef nana::string string_t; - const nana::char_t* splstr = STR("/\\"); + typedef std::wstring string_t; + 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 //@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,28 +74,6 @@ namespace filesystem return rmdir(dir.c_str(), 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) { @@ -188,81 +96,12 @@ namespace filesystem #endif }//end namespace detail - bool file_attrib(const nana::string& file, attribute& attr) - { -#if defined(NANA_WINDOWS) - WIN32_FILE_ATTRIBUTE_DATA fad; - if(::GetFileAttributesEx(file.c_str(), GetFileExInfoStandard, &fad)) - { - LARGE_INTEGER li; - li.u.LowPart = fad.nFileSizeLow; - li.u.HighPart = fad.nFileSizeHigh; - attr.bytes = li.QuadPart; - attr.is_directory = (0 != (fad.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)); - detail::filetime_to_c_tm(fad.ftLastWriteTime, attr.modified); - return true; - } -#elif defined(NANA_LINUX) || defined(NANA_MACOS) - struct stat fst; - if(0 == ::stat(static_cast(nana::charset(file)).c_str(), &fst)) - { - attr.bytes = fst.st_size; - attr.is_directory = (0 != (040000 & fst.st_mode)); - attr.modified = *(::localtime(&fst.st_ctime)); - return true; - } -#endif - return false; - } - long long filesize(const nana::string& file) - { -#if defined(NANA_WINDOWS) - //Some compilation environment may fail to link to GetFileSizeEx - typedef BOOL (__stdcall *GetFileSizeEx_fptr_t)(HANDLE, PLARGE_INTEGER); - GetFileSizeEx_fptr_t get_file_size_ex = reinterpret_cast(::GetProcAddress(::GetModuleHandleA("Kernel32.DLL"), "GetFileSizeEx")); - if(get_file_size_ex) - { - HANDLE handle = ::CreateFile(file.c_str(), GENERIC_READ, 0, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0); - if(INVALID_HANDLE_VALUE != handle) - { - LARGE_INTEGER li; - if(!get_file_size_ex(handle, &li)) - li.QuadPart = 0; - - ::CloseHandle(handle); - return li.QuadPart; - } - } - return 0; -#elif defined(NANA_LINUX) - FILE * stream = ::fopen(static_cast(nana::charset(file)).c_str(), "rb"); - long long size = 0; - if(stream) - { - fseeko64(stream, 0, SEEK_END); - size = ftello64(stream); - fclose(stream); - } - return size; -#elif defined(NANA_MACOS) - FILE * stream = ::fopen(static_cast(nana::charset(file)).c_str(), "rb"); - long long size = 0; - if (stream) - { - fseeko(stream, 0, SEEK_END); - size = ftello(stream); - fclose(stream); - } - return size; -#endif - } - - bool modified_file_time(const nana::string& file, struct tm& t) + bool modified_file_time(const ::std::string& file, struct tm& t) { #if defined(NANA_WINDOWS) WIN32_FILE_ATTRIBUTE_DATA attr; - if(::GetFileAttributesEx(file.c_str(), GetFileExInfoStandard, &attr)) + if(::GetFileAttributesExW(to_nstring(file).c_str(), GetFileExInfoStandard, &attr)) { FILETIME local_file_time; if(::FileTimeToLocalFileTime(&attr.ftLastWriteTime, &local_file_time)) @@ -283,7 +122,7 @@ namespace filesystem } #elif defined(NANA_LINUX) || defined(NANA_MACOS) struct stat attr; - if(0 == ::stat(static_cast(nana::charset(file)).c_str(), &attr)) + if(0 == ::stat(file.c_str(), &attr)) { t = *(::localtime(&attr.st_ctime)); return true; @@ -292,83 +131,32 @@ namespace filesystem return false; } - bool mkdir(const nana::string& path, bool & if_exist) - { - if_exist = false; - if(path.size() == 0) return false; - - nana::string root; -#if defined(NANA_WINDOWS) - if(path.size() > 3 && path[1] == STR(':')) - root = path.substr(0, 3); -#elif defined(NANA_LINUX) || defined(NANA_MACOS) - if(path[0] == STR('/')) - root = '/'; -#endif - bool mkstat = false; - std::size_t beg = root.size(); - - while(true) - { - beg = path.find_first_not_of(STR("/\\"), beg); - if(beg == path.npos) - break; - - std::size_t pos = path.find_first_of(STR("/\\"), beg + 1); - if(pos != path.npos) - { - root += path.substr(beg, pos - beg); - - mkstat = detail::mkdir_helper(root, if_exist); - if(mkstat == false && if_exist == false) - return false; - -#if defined(NANA_WINDOWS) - root += STR('\\'); -#elif defined(NANA_LINUX) || defined(NANA_MACOS) - root += STR('/'); -#endif - } - else - { - if(beg + 1 < path.size()) - { - root += path.substr(beg); - mkstat = detail::mkdir_helper(root, if_exist); - } - break; - } - beg = pos + 1; - } - 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) @@ -385,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) @@ -422,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 eb48b9e9..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 @@ -215,7 +215,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); @@ -441,9 +441,9 @@ namespace detail } catch(std::exception& e) { - (msgbox(modal_window, STR("An uncaptured std::exception during message pumping: ")).icon(msgbox::icon_information) - < varbuf; + std::unique_ptr varbuf; std::size_t bufsize = 0; unsigned size = ::DragQueryFile(drop, 0xFFFFFFFF, 0, 0); @@ -1185,12 +1185,13 @@ 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; } ::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)) @@ -1344,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); @@ -1372,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); @@ -1414,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); @@ -1425,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); } } @@ -1442,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; @@ -1463,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); @@ -1728,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/detail/native_window_interface.cpp b/source/gui/detail/native_window_interface.cpp index 786a5df2..d310d223 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); @@ -378,8 +378,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 @@ -1084,48 +1084,37 @@ namespace nana{ #endif } - void native_interface::window_caption(native_window_type wd, const nana::string& title) + void native_interface::window_caption(native_window_type wd, const native_string_type& title) { #if defined(NANA_WINDOWS) if(::GetCurrentThreadId() != ::GetWindowThreadProcessId(reinterpret_cast(wd), 0)) { - wchar_t * wstr; -#if defined(NANA_UNICODE) - wstr = new wchar_t[title.length() + 1]; - wcscpy(wstr, title.c_str()); -#else - std::wstring str = nana::charset(title); - wstr = new wchar_t[str.length() + 1]; - wcscpy(wstr, str.c_str()); -#endif + wchar_t * wstr = new wchar_t[title.length() + 1]; + std::wcscpy(wstr, title.c_str()); ::PostMessage(reinterpret_cast(wd), nana::detail::messages::remote_thread_set_window_text, reinterpret_cast(wstr), 0); } else ::SetWindowText(reinterpret_cast(wd), title.c_str()); #elif defined(NANA_X11) ::XTextProperty name; - #if defined(NANA_UNICODE) - std::string mbstr = nana::charset(title); - char* text = const_cast(mbstr.c_str()); - #else - char* text = const_cast(title.c_str()); - #endif + char * text = const_cast(title.c_str()); + nana::detail::platform_scope_guard psg; ::XStringListToTextProperty(&text, 1, &name); ::XSetWMName(restrict::spec.open_display(), reinterpret_cast(wd), &name); ::XChangeProperty(restrict::spec.open_display(), reinterpret_cast(wd), restrict::spec.atombase().net_wm_name, restrict::spec.atombase().utf8_string, 8, - PropModeReplace, reinterpret_cast(text), mbstr.size()); + PropModeReplace, reinterpret_cast(text), title.size()); #endif } - nana::string native_interface::window_caption(native_window_type wd) + auto native_interface::window_caption(native_window_type wd) -> native_string_type { #if defined(NANA_WINDOWS) int length = ::GetWindowTextLength(reinterpret_cast(wd)); if(length > 0) { - nana::string str; + native_string_type str; //One for NULL terminator which GetWindowText will write. str.resize(length+1); @@ -1136,7 +1125,6 @@ namespace nana{ return str; } - return nana::string(); #elif defined(NANA_X11) nana::detail::platform_scope_guard psg; ::XTextProperty txtpro; @@ -1148,14 +1136,14 @@ namespace nana{ { if(size > 1) { - nana::string str = nana::charset(*strlist); + std::string text = *strlist; ::XFreeStringList(strlist); - return str; + return text; } } } - return nana::string(); #endif + return native_string_type(); } void native_interface::capture_window(native_window_type wd, bool cap) diff --git a/source/gui/dragger.cpp b/source/gui/dragger.cpp index 8b865891..43a56ba2 100644 --- a/source/gui/dragger.cpp +++ b/source/gui/dragger.cpp @@ -1,5 +1,17 @@ +/* +* A Dragger Implementation +* Nana C++ Library(http://www.nanapro.org) +* Copyright(C) 2003-2016 Jinhao(cnjinhao@hotmail.com) +* +* Distributed under the Boost Software License, Version 1.0. +* (See accompanying file LICENSE_1_0.txt or copy at +* http://www.boost.org/LICENSE_1_0.txt) +* +* @file: nana/gui/dragger.cpp +*/ #include +#include namespace nana { @@ -180,6 +192,23 @@ namespace nana delete impl_; } + dragger::dragger(dragger&& other) + : impl_(other.impl_) + { + other.impl_ = nullptr; + } + + dragger& dragger::operator=(dragger&& other) + { + if (this != &other) + { + delete impl_; + impl_ = other.impl_; + other.impl_ = nullptr; + } + return *this; + } + void dragger::target(window wd) { impl_->drag_target(wd, rectangle(), nana::arrange::horizontal_vertical); diff --git a/source/gui/element.cpp b/source/gui/element.cpp index 4271a4d2..b2fdbb7f 100644 --- a/source/gui/element.cpp +++ b/source/gui/element.cpp @@ -173,11 +173,8 @@ namespace nana const int x = r.x + 1; const int y = r.y + 1; - graph.set_color(bld_bgcolor); - graph.rectangle(rectangle{ x + 1, y + 1, 11, 11 }, true); - - graph.set_color(bld_fgcolor); - graph.rectangle(rectangle{ x, y, 13, 13 }, false); + graph.rectangle(rectangle{ x + 1, y + 1, 11, 11 }, true, bld_bgcolor); + graph.rectangle(rectangle{ x, y, 13, 13 }, false, bld_fgcolor); switch(crook_data.check_state) { @@ -252,11 +249,11 @@ namespace nana int x = r.x + (static_cast(r.width) - 16) / 2; int y = r.y + (static_cast(r.height) - 16) / 2; - graph.set_color(fgcolor); + graph.palette(false, fgcolor); graph.line(point{ x + 3, y + 7 }, point{ x + 6, y + 10 }); graph.line(point{ x + 7, y + 9 }, point{ x + 12, y + 4 }); - graph.set_color(fgcolor.blend(colors::white, 0.5)); + graph.palette(false, fgcolor.blend(colors::white, 0.5)); graph.line(point{ x + 3, y + 8 }, point{ x + 6, y + 11 }); graph.line(point{ x + 7, y + 10 }, point{ x + 12, y + 5 }); graph.line(point{ x + 4, y + 7 }, point{ x + 6, y + 9 }); @@ -515,16 +512,16 @@ namespace nana ::nana::point left_mid{ r.x + 1, r.y + 1 + static_cast(part_px) }, right_mid{ right_top.x, left_mid.y }; ::nana::point left_bottom{ r.x + 1, r.bottom() - 2 }, right_bottom{ r.right() - 2, r.bottom() - 2 }; - graph.set_color(bgcolor.blend(colors::white, 0.9)); + graph.palette(false, bgcolor.blend(colors::white, 0.9)); graph.line(left_top, left_mid); graph.line(right_top, right_mid); - graph.set_color(bgcolor.blend(colors::white, 0.5)); + graph.palette(false, bgcolor.blend(colors::white, 0.5)); graph.line(left_top, right_top); left_mid.y++; right_mid.y++; - graph.set_color(bgcolor.blend(colors::black, 0.8)); + graph.palette(false, bgcolor.blend(colors::black, 0.8)); graph.line(left_mid, left_bottom); graph.line(right_mid, right_bottom); @@ -557,7 +554,7 @@ namespace nana break; } - graph.set_color(clr); + graph.palette(false, clr); const int x = r.x + 4; const int y = r.y + 4; @@ -959,13 +956,13 @@ namespace nana ps[11].x = r.x + gap; ps[11].y = r.y + gap; - graph.set_color(fgcolor.blend(colors::black, true)); + graph.palette(false, fgcolor.blend(colors::black, true)); for (int i = 0; i < 11; ++i) graph.line(ps[i], ps[i + 1]); graph.line(ps[11], ps[0]); - graph.set_color(fgcolor); + graph.palette(false, fgcolor); unsigned thk_minus_2 = thickness_ - 2; graph.rectangle(rectangle{ ps[10].x + 1, ps[10].y + 1, (gap << 1) + thk_minus_2, thk_minus_2 }, true); @@ -1010,7 +1007,7 @@ namespace nana //Implement element_interface bool facade::draw(graph_reference graph, const nana::color& bgcolor, const nana::color& fgcolor, const nana::rectangle& r, element_state estate) { - graph.set_color(fgcolor); + graph.palette(false, fgcolor); return (*cite_)->draw(graph, bgcolor, fgcolor, r, estate, dir_); } //end class facade diff --git a/source/gui/filebox.cpp b/source/gui/filebox.cpp index ef5a4d52..bd63a010 100644 --- a/source/gui/filebox.cpp +++ b/source/gui/filebox.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #if defined(NANA_WINDOWS) #include @@ -38,16 +39,16 @@ namespace nana { struct item_fs { - nana::string name; + std::string name; ::tm modified_time; bool directory; nana::long_long_t bytes; friend listbox::iresolver& operator>>(listbox::iresolver& ires, item_fs& m) { - nana::string type; + std::wstring type; ires>>m.name>>type>>type; - m.directory = (type == STR("Directory")); + m.directory = (type == L"Directory"); return ires; } @@ -65,16 +66,16 @@ namespace nana ores<= 1024) { 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; @@ -108,10 +109,11 @@ namespace nana if(pos + 2 < s.size()) s.erase(pos + 2); } - return static_cast(nana::charset(s)) + ustr[uid]; + + return s + ustr[uid]; } ss<&) { auto path = path_.caption(); - auto root = path.substr(0, path.find(STR('/'))); - if(root == STR("HOME")) - path.replace(0, 4, nana::filesystem::path_user()); - else if(root == STR("FILESYSTEM")) + auto root = path.substr(0, path.find('/')); + if(root == "HOME") + path.replace(0, 4, to_nstring(nana::filesystem::path_user())); + else if(root == "FILESYSTEM") path.erase(0, 10); else throw std::runtime_error("Nana.GUI.Filebox: Wrong categorize path"); - if(path.size() == 0) path = STR("/"); + if(path.size() == 0) path = "/"; _m_load_cat_path(path); }); filter_.create(*this); filter_.multi_lines(false); - filter_.tip_string(STR("Filter")); + filter_.tip_string("Filter"); filter_.events().key_release.connect_unignorable([this](const arg_keyboard&) { @@ -161,23 +163,23 @@ namespace nana }); btn_folder_.create(*this); - btn_folder_.caption(STR("&New Folder")); + btn_folder_.caption("&New Folder"); btn_folder_.events().click.connect_unignorable([this](const arg_click&) { form fm(this->handle(), API::make_center(*this, 300, 35)); - fm.caption(STR("Name the new folder")); + fm.caption("Name the new folder"); textbox folder(fm, nana::rectangle(5, 5, 160, 25)); folder.multi_lines(false); button btn(fm, nana::rectangle(170, 5, 60, 25)); - btn.caption(STR("Create")); + btn.caption("Create"); btn.events().click.connect_unignorable(folder_creator(*this, fm, folder)); button btn_cancel(fm, nana::rectangle(235, 5, 60, 25)); - btn_cancel.caption(STR("Cancel")); + btn_cancel.caption("Cancel"); btn_cancel.events().click.connect_unignorable([&fm](const arg_click&) { @@ -189,17 +191,17 @@ namespace nana tree_.create(*this); ls_file_.create(*this); - ls_file_.append_header(STR("Name"), 190); - ls_file_.append_header(STR("Modified"), 145); - ls_file_.append_header(STR("Type"), 80); - ls_file_.append_header(STR("Size"), 70); + ls_file_.append_header("Name", 190); + ls_file_.append_header("Modified", 145); + ls_file_.append_header("Type", 80); + ls_file_.append_header("Size", 70); auto fn_sel_file = [this](const arg_mouse& arg){ _m_sel_file(arg); }; ls_file_.events().dbl_click.connect_unignorable(fn_sel_file); ls_file_.events().mouse_down.connect_unignorable(fn_sel_file); - ls_file_.set_sort_compare(0, [](const nana::string& a, nana::any* fs_a, const nana::string& b, nana::any* fs_b, bool reverse) -> bool + ls_file_.set_sort_compare(0, [](const std::string& a, nana::any* fs_a, const std::string& b, nana::any* fs_b, bool reverse) -> bool { int dira = fs_a->get()->directory ? 1 : 0; int dirb = fs_b->get()->directory ? 1 : 0; @@ -211,8 +213,8 @@ namespace nana while(true) { - std::size_t pos_a = a.find_first_of(STR("0123456789"), seek_a); - std::size_t pos_b = b.find_first_of(STR("0123456789"), seek_b); + std::size_t pos_a = a.find_first_of("0123456789", seek_a); + std::size_t pos_b = b.find_first_of("0123456789", seek_b); if((pos_a != a.npos) && (pos_a == pos_b)) { @@ -222,11 +224,11 @@ namespace nana if(text_a != text_b) return (reverse ? text_a > text_b : text_a < text_b); - std::size_t end_a = a.find_first_not_of(STR("0123456789"), pos_a + 1); - std::size_t end_b = b.find_first_not_of(STR("0123456789"), pos_b + 1); + std::size_t end_a = a.find_first_not_of("0123456789", pos_a + 1); + std::size_t end_b = b.find_first_not_of("0123456789", pos_b + 1); - nana::string num_a = a.substr(pos_a, end_a != a.npos ? end_a - pos_a : a.npos); - nana::string num_b = b.substr(pos_b, end_b != b.npos ? end_b - pos_b : b.npos); + auto num_a = a.substr(pos_a, end_a != a.npos ? end_a - pos_a : a.npos); + auto num_b = b.substr(pos_b, end_b != b.npos ? end_b - pos_b : b.npos); if(num_a != num_b) { @@ -253,7 +255,7 @@ namespace nana return (reverse ? cia > cib : cia < cib); return (reverse ? cia.substr(seek_a) > cib.substr(seek_b) : cia.substr(seek_a) < cib.substr(seek_b)); }); - ls_file_.set_sort_compare(2, [](const nana::string& a, nana::any* anyptr_a, const nana::string& b, nana::any* anyptr_b, bool reverse) -> bool + ls_file_.set_sort_compare(2, [](const std::string& a, nana::any* anyptr_a, const std::string& b, nana::any* anyptr_b, bool reverse) -> bool { int dir1 = anyptr_a->get()->directory ? 1 : 0; int dir2 = anyptr_b->get()->directory ? 1 : 0; @@ -262,7 +264,7 @@ namespace nana return (reverse ? a > b : a < b); }); - ls_file_.set_sort_compare(3, [this](const nana::string&, nana::any* anyptr_a, const nana::string&, nana::any* anyptr_b, bool reverse) -> bool + ls_file_.set_sort_compare(3, [this](const std::string&, nana::any* anyptr_a, const std::string&, nana::any* anyptr_b, bool reverse) -> bool { item_fs * fsa = anyptr_a->get(); item_fs * fsb = anyptr_b->get(); @@ -270,7 +272,7 @@ namespace nana }); lb_file_.create(*this); - lb_file_.caption(STR("File:")); + lb_file_.caption("File:"); tb_file_.create(*this); tb_file_.multi_lines(false); @@ -286,14 +288,14 @@ namespace nana cb_types_.events().selected.connect_unignorable([this](const arg_combox&){ _m_list_fs(); }); btn_ok_.create(*this); - btn_ok_.caption(STR("&OK")); + btn_ok_.caption("&OK"); btn_ok_.events().click.connect_unignorable([this](const arg_click&) { _m_ok(); }); btn_cancel_.create(*this); - btn_cancel_.caption(STR("&Cancel")); + btn_cancel_.caption("&Cancel"); btn_cancel_.events().click.connect_unignorable([this](const arg_click&) { @@ -305,25 +307,25 @@ namespace nana _m_init_tree(); if(0 == title.size()) - caption(io_read ? STR("Open") : STR("Save As")); + caption(io_read ? "Open" : "Save As"); else caption(title); } - void def_extension(const nana::string& ext) + void def_extension(const std::string& ext) { def_ext_ = ext; } - void load_fs(const nana::string& init_path, const nana::string& init_file) + void load_fs(const std::string& init_path, const std::string& init_file) { //Simulate the behavior like Windows7's lpstrInitialDir(http://msdn.microsoft.com/en-us/library/windows/desktop/ms646839%28v=vs.85%29.aspx) //Phase 1 - nana::string dir; + std::string dir; - auto pos = init_file.find_last_of(STR("\\/")); - nana::string file_with_path_removed = (pos != init_file.npos ? init_file.substr(pos + 1) : init_file); + auto pos = init_file.find_last_of("\\/"); + auto file_with_path_removed = (pos != init_file.npos ? init_file.substr(pos + 1) : init_file); if(saved_init_path != init_path) { @@ -343,29 +345,29 @@ namespace nana else dir = saved_selected_path; - _m_load_cat_path(dir.size() ? dir : nana::filesystem::path_user()); + _m_load_cat_path(dir.size() ? dir : to_nstring(nana::filesystem::path_user())); tb_file_.caption(file_with_path_removed); } - void add_filter(const nana::string& desc, const nana::string& type) + void add_filter(const std::string& desc, const std::string& type) { std::size_t i = cb_types_.the_number_of_options(); cb_types_.push_back(desc); if(0 == i) cb_types_.option(0); - std::vector v; + std::vector v; std::size_t beg = 0; while(true) { - auto pos = type.find(STR(';'), beg); + auto pos = type.find(';', beg); auto ext = type.substr(beg, pos == type.npos ? type.npos : pos - beg); - auto dot = ext.find(STR('.')); + auto dot = ext.find('.'); if((dot != ext.npos) && (dot + 1 < ext.size())) { ext.erase(0, dot + 1); - if(ext == STR("*")) + if(ext == "*") { v.clear(); break; @@ -381,12 +383,12 @@ namespace nana cb_types_.anyobj(i, v); } - bool file(nana::string& fs) const + bool file(std::string& fs) const { if(selection_.type == kind::none) return false; - auto pos = selection_.target.find_last_of(STR("\\/")); + auto pos = selection_.target.find_last_of("\\/"); if(pos != selection_.target.npos) saved_selected_path = selection_.target.substr(0, pos); else @@ -423,13 +425,13 @@ namespace nana //The path in linux is starting with the character '/', the name of root key should be //"FS.HOME", "FS.ROOT". Because a key of the tree widget should not be '/' - nodes_.home = tree_.insert(STR("FS.HOME"), STR("Home")); + nodes_.home = tree_.insert("FS.HOME", "Home"); nodes_.home.value(kind::filesystem); - nodes_.filesystem = tree_.insert(STR("FS.ROOT"), STR("Filesystem")); + nodes_.filesystem = tree_.insert("FS.ROOT", "Filesystem"); nodes_.filesystem.value(kind::filesystem); file_iterator end; - for(file_iterator i(path_user()); i != end; ++i) + for(file_iterator i(to_nstring(path_user())); i != end; ++i) { if((false == i->directory) || (i->name.size() && i->name[0] == '.')) continue; @@ -441,7 +443,7 @@ namespace nana } } - for(file_iterator i(STR("/")); i != end; ++i) + for(file_iterator i("/"); i != end; ++i) { if((false == i->directory) || (i->name.size() && i->name[0] == '.')) continue; @@ -462,56 +464,59 @@ namespace nana { if(arg.operated && (arg.item.value() == kind::filesystem)) { - auto path = tree_.make_key_path(arg.item, STR("/")) + STR("/"); + auto path = tree_.make_key_path(arg.item, "/") + "/"; _m_resolute_path(path); _m_load_cat_path(path); } }); } - nana::string _m_resolute_path(nana::string& path) + std::string _m_resolute_path(std::string& path) { - auto pos = path.find(STR('/')); + auto pos = path.find('/'); if(pos != path.npos) { auto begstr = path.substr(0, pos); - if(begstr == STR("FS.HOME")) - path.replace(0, 7, nana::filesystem::path_user()); + if(begstr == "FS.HOME") + path.replace(0, 7, to_nstring(nana::filesystem::path_user())); else path.erase(0, pos); return begstr; } - return nana::string(); + return std::string(); } - void _m_load_path(const nana::string& path) + void _m_load_path(const std::string& path) { addr_.filesystem = path; - if(addr_.filesystem.size() && addr_.filesystem[addr_.filesystem.size() - 1] != STR('/')) - addr_.filesystem += STR('/'); + if(addr_.filesystem.size() && addr_.filesystem[addr_.filesystem.size() - 1] != '/') + addr_.filesystem += '/'; file_container_.clear(); using namespace nana::filesystem; - attribute fattr; file_iterator end; for(file_iterator i(path); i != end; ++i) { - if((i->name.size() == 0) || (i->name[0] == STR('.'))) + if((i->name.size() == 0) || (i->name[0] == '.')) continue; item_fs m; m.name = i->name; - if(file_attrib(path + m.name, fattr)) + + namespace fs = ::nana::experimental::filesystem; + auto fattr = fs::status(path + m.name); + + if(fattr.type() != fs::file_type::not_found && fattr.type() != fs::file_type::unknown) { - m.bytes = fattr.bytes; - m.directory = fattr.is_directory; - m.modified_time = fattr.modified; + m.bytes = fs::file_size(path + m.name); + m.directory = fs::is_directory(fattr); + modified_file_time(path + m.name, m.modified_time); } else { m.bytes = 0; m.directory = i->directory; - modified_file_time(path + i->name, m.modified_time); + modified_file_time(path + i->name, m.modified_time); } file_container_.push_back(m); @@ -522,32 +527,32 @@ namespace nana std::sort(file_container_.begin(), file_container_.end(), pred_sort_fs()); } - void _m_load_cat_path(nana::string path) + void _m_load_cat_path(std::string path) { - if((path.size() == 0) || (path[path.size() - 1] != STR('/'))) - path += STR('/'); + if((path.size() == 0) || (path[path.size() - 1] != '/')) + path += '/'; auto beg_node = tree_.selected(); while(!beg_node.empty() && (beg_node != nodes_.home) && (beg_node != nodes_.filesystem)) beg_node = beg_node.owner(); - auto head = nana::filesystem::path_user(); + auto head = to_nstring(nana::filesystem::path_user()); if(path.size() >= head.size() && (path.substr(0, head.size()) == head)) {//This is HOME - path_.caption(STR("HOME")); + path_.caption("HOME"); if(beg_node != nodes_.home) nodes_.home->select(true); } else { //Redirect to '/' - path_.caption(STR("FILESYSTEM")); + path_.caption("FILESYSTEM"); if(beg_node != nodes_.filesystem) nodes_.filesystem->select(true); head.clear(); } - if(head.size() == 0 || head[head.size() - 1] != STR('/')) - head += STR('/'); + if(head.size() == 0 || head[head.size() - 1] != '/') + head += '/'; nana::filesystem::file_iterator end; for(nana::filesystem::file_iterator i(head); i != end; ++i) @@ -556,17 +561,17 @@ namespace nana path_.childset(i->name, 0); } auto cat_path = path_.caption(); - if(cat_path.size() && cat_path[cat_path.size() - 1] != STR('/')) - cat_path += STR('/'); + if(cat_path.size() && cat_path[cat_path.size() - 1] != '/') + cat_path += '/'; auto beg = head.size(); while(true) { - auto pos = path.find(STR('/'), beg); + auto pos = path.find('/', beg); auto folder = path.substr(beg, pos != path.npos ? pos - beg: path.npos); if(folder.size() == 0) break; - (cat_path += folder) += STR('/'); - (head += folder) += STR('/'); + (cat_path += folder) += '/'; + (head += folder) += '/'; path_.caption(cat_path); for(nana::filesystem::file_iterator i(head); i != end; ++i) @@ -583,7 +588,7 @@ namespace nana _m_list_fs(); } - bool _m_filter_allowed(const nana::string& name, bool is_dir, const nana::string& filter, const std::vector* extension) const + bool _m_filter_allowed(const std::string& name, bool is_dir, const std::string& filter, const std::vector* extension) const { if(filter.size() && (name.find(filter) == filter.npos)) return false; @@ -601,12 +606,12 @@ namespace nana void _m_list_fs() { - nana::string filter = filter_.caption(); + auto filter = filter_.caption(); ls_file_.auto_draw(false); ls_file_.clear(); - std::vector* ext_types = cb_types_.anyobj >(cb_types_.option()); + auto ext_types = cb_types_.anyobj >(cb_types_.option()); auto cat = ls_file_.at(0); for(auto & fs: file_container_) { @@ -618,7 +623,7 @@ namespace nana ls_file_.auto_draw(true); } - void _m_finish(kind::t type, const nana::string& tar) + void _m_finish(kind::t type, const std::string& tar) { selection_.target = tar; selection_.type = type; @@ -635,25 +640,35 @@ namespace nana { auto path = tx_path_.caption(); - msgbox mb(fm_, STR("Create Folder")); + msgbox mb(fm_, "Create Folder"); mb.icon(msgbox::icon_warning); - if(0 == path.size() || path[0] == STR('.') || path[0] == STR('/')) + if(0 == path.size() || path[0] == '.' || path[0] == '/') { - mb< * exts = cb_types_.anyobj >(cb_types_.option()); + auto exts = cb_types_.anyobj >(cb_types_.option()); if(0 == exts || exts->size() == 0) return false; auto & ext = exts->at(0); - if(def_ext_[0] != STR('.')) - tar += STR('.'); + if(def_ext_[0] != '.') + tar += '.'; tar += ext; return true; } @@ -703,7 +718,7 @@ namespace nana if(event_code::dbl_click == arg.evt_code) { if(m.directory) - _m_load_cat_path(addr_.filesystem + m.name + STR("/")); + _m_load_cat_path(addr_.filesystem + m.name + "/"); else _m_finish(kind::filesystem, addr_.filesystem + m.name); } @@ -724,34 +739,34 @@ namespace nana auto file = tb_file_.caption(); if(file.size()) { - if(file[0] == STR('.')) + if(file[0] == L'.') { msgbox mb(*this, caption()); mb.icon(msgbox::icon_warning); - mb<()) { - nana::string path = tree_.make_key_path(node, STR("/")) + STR("/"); + auto path = tree_.make_key_path(node, "/") + "/"; _m_resolute_path(path); nana::filesystem::file_iterator end; @@ -814,7 +829,7 @@ namespace nana } private: bool io_read_; - nana::string def_ext_; + std::string def_ext_; place place_; categorize path_; @@ -835,22 +850,22 @@ namespace nana }nodes_; std::vector file_container_; - struct path_tag + struct path_rep { - nana::string filesystem; + std::string filesystem; }addr_; - struct selection_tag + struct selection_rep { kind::t type; - nana::string target; + std::string target; }selection_; - static nana::string saved_init_path; - static nana::string saved_selected_path; + static std::string saved_init_path; + static std::string saved_selected_path; };//end class filebox_implement - nana::string filebox_implement::saved_init_path; - nana::string filebox_implement::saved_selected_path; + std::string filebox_implement::saved_init_path; + std::string filebox_implement::saved_selected_path; #endif //class filebox @@ -858,16 +873,16 @@ namespace nana { struct filter { - nana::string des; - nana::string type; + std::string des; + std::string type; }; window owner; bool open_or_save; - nana::string file; - nana::string title; - nana::string path; + std::string file; + std::string title; + std::string path; std::vector filters; }; @@ -885,9 +900,12 @@ namespace nana auto len = ::GetCurrentDirectory(0, nullptr); if(len) { - impl_->path.resize(len + 1); - ::GetCurrentDirectory(len, &(impl_->path[0])); - impl_->path.resize(len); + std::wstring path; + path.resize(len + 1); + ::GetCurrentDirectory(len, &(path[0])); + path.resize(len); + + impl_->path = utf8_cast(path); } #endif } @@ -913,13 +931,13 @@ namespace nana impl_->owner = wd; } - nana::string filebox::title(nana::string s) + std::string filebox::title(std::string s) { impl_->title.swap(s); return s; } - filebox& filebox::init_path(const nana::string& ipstr) + filebox& filebox::init_path(const std::string& ipstr) { if(ipstr.empty()) { @@ -927,33 +945,32 @@ namespace nana } else { - nana::filesystem::attribute attr; - if (nana::filesystem::file_attrib(ipstr, attr)) - if (attr.is_directory) + namespace fs = ::nana::experimental::filesystem; + if (fs::is_directory(ipstr)) impl_->path = ipstr; } return *this; } - filebox& filebox::init_file(const nana::string& ifstr) + filebox& filebox::init_file(const std::string& ifstr) { impl_->file = ifstr; return *this; } - filebox& filebox::add_filter(const nana::string& description, const nana::string& filetype) + filebox& filebox::add_filter(const std::string& description, const std::string& filetype) { implement::filter flt = {description, filetype}; impl_->filters.push_back(flt); return *this; } - nana::string filebox::path() const + std::string filebox::path() const { return impl_->path; } - nana::string filebox::file() const + std::string filebox::file() const { return impl_->file; } @@ -961,36 +978,36 @@ namespace nana bool filebox::show() const { #if defined(NANA_WINDOWS) - if(impl_->file.size() < 520) - impl_->file.resize(520); + std::wstring wfile; + wfile.resize(520); OPENFILENAME ofn; memset(&ofn, 0, sizeof ofn); ofn.lStructSize = sizeof(ofn); ofn.hwndOwner = reinterpret_cast(API::root(impl_->owner)); - ofn.lpstrFile = &(impl_->file[0]); - ofn.nMaxFile = static_cast(impl_->file.size() - 1); + ofn.lpstrFile = &(wfile[0]); + ofn.nMaxFile = static_cast(wfile.size() - 1); - const nana::char_t * filter; - nana::string filter_holder; - nana::string default_extension; + const wchar_t * filter; + std::wstring filter_holder; + std::wstring default_extension; if(impl_->filters.size()) { for(auto & f : impl_->filters) { - filter_holder += f.des; - filter_holder += static_cast('\0'); - nana::string fs = f.type; + filter_holder += utf8_cast(f.des); + filter_holder += static_cast('\0'); + std::wstring fs = utf8_cast(f.type); std::size_t pos = 0; while(true) { - pos = fs.find(STR(" "), pos); + pos = fs.find(L" ", pos); if(pos == fs.npos) break; fs.erase(pos); } filter_holder += fs; - filter_holder += static_cast('\0'); + filter_holder += static_cast('\0'); //Get the default file extentsion if (default_extension.empty()) @@ -1010,14 +1027,16 @@ namespace nana filter = filter_holder.data(); } else - filter = STR("All Files\0*.*\0"); + filter = L"All Files\0*.*\0"; + auto wtitle = utf8_cast(impl_->title); + auto wpath = utf8_cast(impl_->path); ofn.lpstrFilter = filter; - ofn.lpstrTitle = (impl_->title.size() ? impl_->title.c_str() : nullptr); + ofn.lpstrTitle = (wtitle.empty() ? nullptr : wtitle.c_str()); ofn.nFilterIndex = 0; ofn.lpstrFileTitle = nullptr; ofn.nMaxFileTitle = 0; - ofn.lpstrInitialDir = (impl_->path.size() ? impl_->path.c_str() : nullptr); + ofn.lpstrInitialDir = (wpath.empty() ? nullptr : wpath.c_str()); if (!impl_->open_or_save) ofn.Flags = OFN_OVERWRITEPROMPT; //Overwrite prompt if it is save mode @@ -1026,7 +1045,8 @@ namespace nana if(FALSE == (impl_->open_or_save ? ::GetOpenFileName(&ofn) : ::GetSaveFileName(&ofn))) return false; - impl_->file.resize(nana::strlen(impl_->file.data())); + wfile.resize(std::wcslen(wfile.data())); + impl_->file = utf8_cast(wfile); #elif defined(NANA_LINUX) || defined(NANA_MACOS) filebox_implement fb(impl_->owner, impl_->open_or_save, impl_->title); @@ -1034,11 +1054,11 @@ namespace nana { for(auto & f: impl_->filters) { - nana::string fs = f.type; + std::string fs = f.type; std::size_t pos = 0; while(true) { - pos = fs.find(STR(" "), pos); + pos = fs.find(" ", pos); if(pos == fs.npos) break; fs.erase(pos); @@ -1047,7 +1067,7 @@ namespace nana } } else - fb.add_filter(STR("All Files"), STR("*.*")); + fb.add_filter("All Files", "*.*"); fb.load_fs(impl_->path, impl_->file); @@ -1055,7 +1075,7 @@ namespace nana if(false == fb.file(impl_->file)) return false; #endif - auto tpos = impl_->file.find_last_of(STR("\\/")); + auto tpos = impl_->file.find_last_of("\\/"); if(tpos != impl_->file.npos) impl_->path = impl_->file.substr(0, tpos); else diff --git a/source/gui/msgbox.cpp b/source/gui/msgbox.cpp index a34fdbe2..4cd36b0f 100644 --- a/source/gui/msgbox.cpp +++ b/source/gui/msgbox.cpp @@ -38,7 +38,7 @@ namespace nana : public form { public: - msgbox_window(window wd, const ::nana::string& title, msgbox::button_t btn, msgbox::icon_t ico) + msgbox_window(window wd, const std::string& title, msgbox::button_t btn, msgbox::icon_t ico) : form(wd, rectangle(1, 1, 1, 1), appear::decorate<>()), owner_(wd), pick_(msgbox::pick_yes) { @@ -61,14 +61,14 @@ namespace nana { _m_click(arg); }); - yes_.caption(STR("OK")); + yes_.caption("OK"); width_pixel += 77; if(msgbox::yes_no == btn || msgbox::yes_no_cancel == btn) { - yes_.caption(STR("Yes")); + yes_.caption("Yes"); no_.create(*this); - no_.caption(STR("No")); + no_.caption("No"); no_.events().click.connect_unignorable([this](const arg_click& arg) { _m_click(arg); @@ -79,7 +79,7 @@ namespace nana if(msgbox::yes_no_cancel == btn) { cancel_.create(*this); - cancel_.caption(STR("Cancel")); + cancel_.caption("Cancel"); cancel_.events().click.connect_unignorable([this](const arg_click& arg) { _m_click(arg); @@ -108,7 +108,7 @@ namespace nana _m_icon(ico); } - void prompt(const nana::string& text) + void prompt(const std::string& text) { if(text.size()) { @@ -352,13 +352,17 @@ namespace nana return *this; } - msgbox::msgbox(const nana::string& title) + msgbox::msgbox(const std::string& title) : wd_(nullptr), title_(title), button_(ok), icon_(icon_none) - {} + { + throw_not_utf8(title_); + } - msgbox::msgbox(window wd, const nana::string& title, button_t b) + msgbox::msgbox(window wd, const std::string& title, button_t b) : wd_(wd), title_(title), button_(b), icon_(icon_none) - {} + { + throw_not_utf8(title_); + } msgbox& msgbox::icon(icon_t ic) { @@ -372,23 +376,15 @@ namespace nana sstream_.clear(); } - msgbox & msgbox::operator<<(const nana::string& str) + msgbox & msgbox::operator<<(const std::wstring& str) { -#if defined(NANA_UNICODE) - sstream_<(nana::charset(str)); -#else - sstream_<(nana::charset(str));; -#else - sstream_<(API::root(wd_)), static_cast(nana::charset(sstream_.str())).c_str(), title_.c_str(), type); - #else - int bt = ::MessageBoxA(reinterpret_cast(API::root(wd_), sstream_.str().c_str(), title_.c_str(), type); - #endif + auto bt = ::MessageBoxW(reinterpret_cast(API::root(wd_)), utf8_cast(sstream_.str()).c_str(), utf8_cast(title_).c_str(), type); + switch(bt) { case IDOK: @@ -473,9 +466,12 @@ namespace nana : public ::nana::form { public: - inputbox_window(window owner, paint::image (&imgs)[4], ::nana::rectangle (&valid_areas)[4], const ::nana::string & desc, const ::nana::string& title, std::size_t contents, unsigned fixed_pixels, const std::vector& each_height) + inputbox_window(window owner, paint::image (&imgs)[4], ::nana::rectangle (&valid_areas)[4], const ::std::string & desc, const ::std::string& title, std::size_t contents, unsigned fixed_pixels, const std::vector& each_height) : form(owner, API::make_center(owner, 500, 300), appear::decorate<>()) { + throw_not_utf8(desc); + throw_not_utf8(title); + desc_.create(*this); desc_.format(true).caption(desc); auto desc_extent = desc_.measure(470); @@ -652,13 +648,13 @@ namespace nana int last; int step; - ::nana::string label_text; + ::std::string label_text; ::nana::panel dock; ::nana::label label; ::nana::spinbox spinbox; }; - inputbox::integer::integer(::nana::string label, int init_value, int begin, int last, int step) + inputbox::integer::integer(::std::string label, int init_value, int begin, int last, int step) : impl_(new implement) { auto impl = impl_.get(); @@ -681,7 +677,7 @@ namespace nana } //Implementation of abstract_content - const ::nana::string& inputbox::integer::label() const + const ::std::string& inputbox::integer::label() const { return impl_->label_text; } @@ -704,7 +700,7 @@ namespace nana impl->spinbox.create(impl->dock, rectangle{ static_cast(label_px + 10), 0, value_px, 0 }); impl->spinbox.range(impl->begin, impl->last, impl->step); - impl->spinbox.value(std::to_wstring(impl->value)); + impl->spinbox.value(std::to_string(impl->value)); impl->dock.events().resized.connect_unignorable([impl, label_px, value_px](const ::nana::arg_resized& arg) { @@ -730,13 +726,13 @@ namespace nana double last; double step; - ::nana::string label_text; + ::std::string label_text; ::nana::panel dock; ::nana::label label; ::nana::spinbox spinbox; }; - inputbox::real::real(::nana::string label, double init_value, double begin, double last, double step) + inputbox::real::real(::std::string label, double init_value, double begin, double last, double step) : impl_(new implement) { auto impl = impl_.get(); @@ -759,7 +755,7 @@ namespace nana } //Implementation of abstract_content - const ::nana::string& inputbox::real::label() const + const ::std::string& inputbox::real::label() const { return impl_->label_text; } @@ -782,7 +778,7 @@ namespace nana impl->spinbox.create(impl->dock, rectangle{ static_cast(label_px + 10), 0, value_px, 0 }); impl->spinbox.range(impl->begin, impl->last, impl->step); - impl->spinbox.value(std::to_wstring(impl->value)); + impl->spinbox.value(std::to_string(impl->value)); impl->dock.events().resized.connect_unignorable([impl, label_px, value_px](const ::nana::arg_resized& arg) { @@ -803,29 +799,33 @@ namespace nana //class text struct inputbox::text::implement { - ::nana::string value; - ::nana::string tip; + ::std::string value; + ::std::string tip; wchar_t mask_character{0}; - std::vector< ::nana::string> options; + std::vector< ::std::string> options; - ::nana::string label_text; - ::nana::string init_text; + ::std::string label_text; + ::std::string init_text; ::nana::panel dock; ::nana::label label; ::nana::combox combox; ::nana::textbox textbox; }; - inputbox::text::text(::nana::string label, ::nana::string init_text) + inputbox::text::text(::std::string label, ::std::string init_text) : impl_(new implement) { impl_->label_text.swap(label); impl_->init_text.swap(init_text); } - inputbox::text::text(::nana::string label, std::vector<::nana::string> options) + inputbox::text::text(::std::string label, std::vector<::std::string> options) : impl_(new implement) { + throw_not_utf8(label); + for (auto & text : options) + throw_not_utf8(text); + impl_->options.swap(options); impl_->label_text.swap(label); } @@ -835,12 +835,12 @@ namespace nana void inputbox::text::tip_string(std::wstring tip) { - impl_->tip.swap(tip); + impl_->tip = utf8_cast(tip); } void inputbox::text::tip_string(std::string tip_utf8) { - impl_->tip = ::nana::charset(tip_utf8, ::nana::unicode::utf8); + impl_->tip.swap(tip_utf8); } void inputbox::text::mask_character(wchar_t ch) @@ -848,7 +848,7 @@ namespace nana impl_->mask_character = ch; } - ::nana::string inputbox::text::value() const + ::std::string inputbox::text::value() const { if (!impl_->textbox.empty()) return impl_->textbox.caption(); @@ -859,7 +859,7 @@ namespace nana } //Implementation of abstract_content - const ::nana::string& inputbox::text::label() const + const ::std::string& inputbox::text::label() const { return impl_->label_text; } @@ -929,7 +929,7 @@ namespace nana int month; int day; - ::nana::string label_text; + ::std::string label_text; ::nana::panel dock; ::nana::label label; ::nana::combox wdg_month; @@ -937,18 +937,18 @@ namespace nana ::nana::spinbox wdg_year; }; - inputbox::date::date(::nana::string label) + inputbox::date::date(::std::string label) : impl_(new implement) { - impl_->label_text = std::move(label); + impl_->label_text.swap(label); } //Instance for impl_ because implmenet is incomplete type at the point of declaration inputbox::date::~date(){} - ::nana::string inputbox::date::value() const + ::std::string inputbox::date::value() const { - return std::to_wstring(impl_->month) + L'-' + std::to_wstring(impl_->day) + L", " + std::to_wstring(impl_->year); + return std::to_string(impl_->month) + '-' + std::to_string(impl_->day) + ", " + std::to_string(impl_->year); } int inputbox::date::year() const @@ -974,7 +974,7 @@ namespace nana } //Implementation of abstract_content - const ::nana::string& inputbox::date::label() const + const ::std::string& inputbox::date::label() const { return impl_->label_text; } @@ -1009,8 +1009,8 @@ namespace nana impl->wdg_month.option(today.month - 1); - impl->wdg_day.value(std::to_wstring(today.day)); - impl->wdg_year.value(std::to_wstring(today.year)); + impl->wdg_day.value(std::to_string(today.day)); + impl->wdg_year.value(std::to_string(today.year)); impl->dock.events().resized.connect_unignorable([impl, label_px](const ::nana::arg_resized& arg) { @@ -1051,7 +1051,7 @@ namespace nana if (day > days) day = days; - impl->wdg_day.value(std::to_wstring(day)); + impl->wdg_day.value(std::to_string(day)); }; impl->wdg_year.events().text_changed.connect_unignorable(make_days); @@ -1071,19 +1071,21 @@ namespace nana { filebox fbox; - ::nana::string value; - ::nana::string label_text; + ::std::string value; + ::std::string label_text; ::nana::panel dock; ::nana::label label; ::nana::textbox path_edit; ::nana::button browse; - implement(const filebox& fb, ::nana::string&& labelstr) + implement(const filebox& fb, ::std::string&& labelstr) : fbox(fb), label_text(std::move(labelstr)) - {} + { + throw_not_utf8(label_text); + } }; - inputbox::path::path(::nana::string label, const filebox& fb) + inputbox::path::path(::std::string label, const filebox& fb) : impl_(new implement(fb, std::move(label))) { } @@ -1091,7 +1093,7 @@ namespace nana //Instance for impl_ because implmenet is incomplete type at the point of declaration inputbox::path::~path(){} - ::nana::string inputbox::path::value() const + ::std::string inputbox::path::value() const { if (!impl_->path_edit.empty()) return impl_->path_edit.caption(); @@ -1100,7 +1102,7 @@ namespace nana } //Implementation of abstract_content - const ::nana::string& inputbox::path::label() const + const ::std::string& inputbox::path::label() const { return impl_->label_text; } @@ -1148,7 +1150,7 @@ namespace nana //end class path - inputbox::inputbox(window owner, ::nana::string desc, ::nana::string title) + inputbox::inputbox(window owner, ::std::string desc, ::std::string title) : owner_{ owner }, description_(std::move(desc)), title_(std::move(title)) diff --git a/source/gui/notifier.cpp b/source/gui/notifier.cpp index 242b0334..4e98e037 100644 --- a/source/gui/notifier.cpp +++ b/source/gui/notifier.cpp @@ -299,10 +299,10 @@ namespace nana impl_->native_handle = nullptr; } - void notifier::text(const nana::string& str) + void notifier::text(const std::string& str) { #if defined(NANA_WINDOWS) - NOTIFYICONDATA icon_data; + NOTIFYICONDATAW icon_data; memset(&icon_data, 0, sizeof icon_data); icon_data.cbSize = sizeof icon_data; icon_data.hWnd = reinterpret_cast(impl_->native_handle); @@ -310,18 +310,18 @@ namespace nana icon_data.uFlags = NIF_MESSAGE | NIF_TIP; icon_data.uCallbackMessage = nana::detail::messages::tray; - strcpy(icon_data.szTip, str.data()); + std::wcscpy(icon_data.szTip, to_wstring(str).c_str()); ::Shell_NotifyIcon(impl_->icon_added ? NIM_MODIFY : NIM_ADD, &icon_data); impl_->icon_added = true; #endif } - void notifier::icon(const nana::string& icon_file) + void notifier::icon(const std::string& icon_file) { #if defined(NANA_WINDOWS) auto pre_icon = impl_->icon_handle; - auto ico = (HICON)::LoadImage(0, icon_file.data(), IMAGE_ICON, 0, 0, LR_LOADFROMFILE); + auto ico = (HICON)::LoadImageW(0, to_wstring(icon_file).data(), IMAGE_ICON, 0, 0, LR_LOADFROMFILE); if (ico) { impl_->icon_handle = ico; @@ -333,10 +333,10 @@ namespace nana #endif } - void notifier::insert_icon(const nana::string& icon_file) + void notifier::insert_icon(const std::string& icon_file) { #if defined(NANA_WINDOWS) - auto icon = (HICON)::LoadImage(0, icon_file.data(), IMAGE_ICON, 0, 0, LR_LOADFROMFILE); + auto icon = (HICON)::LoadImage(0, to_wstring(icon_file).data(), IMAGE_ICON, 0, 0, LR_LOADFROMFILE); impl_->icons.push_back(icon); #endif } diff --git a/source/gui/place.cpp b/source/gui/place.cpp index 88ea8dd7..0b96dbf1 100644 --- a/source/gui/place.cpp +++ b/source/gui/place.cpp @@ -534,12 +534,12 @@ namespace nana }); } - field_interface& operator<<(const nana::char_t* label_text) override + field_interface& operator<<(const char* label_text) override { - return static_cast(this)->operator<<(agent