From e721cfa51f121aa497b9cbb4a1009229d5ee7100 Mon Sep 17 00:00:00 2001 From: Jinhao Date: Wed, 25 Feb 2015 22:15:02 +0800 Subject: [PATCH 1/3] support of unimplemented std::regex --- source/basic_types.cpp | 141 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 141 insertions(+) diff --git a/source/basic_types.cpp b/source/basic_types.cpp index f8bb0823..d02d497f 100644 --- a/source/basic_types.cpp +++ b/source/basic_types.cpp @@ -11,7 +11,11 @@ */ #include +#if defined(USE_STD_REGEX) #include +#else +#include +#endif #include namespace nana @@ -60,10 +64,46 @@ namespace nana a_ = 1.0; } +#if !defined(USE_STD_REGEX) + std::string read_number(std::string& str, std::size_t& pos) + { + pos = str.find_first_of("0123456789", pos); + if (pos == str.npos) + return{}; + + auto end = str.find_first_not_of("0123456789", pos + 1); + //integer part + if (end == str.npos) + { + pos = end; + return str.substr(pos); + } + + if (str[end] == '.') + { + auto decimal_end = str.find_first_not_of("0123456789", end + 1); + if ((decimal_end == str.npos) || (decimal_end == end + 1)) //Because of missing % + return{}; + + end = decimal_end; + } + + auto ch = str[end]; + if (ch == '%' || ch == ' ' || ch == ',' || ch == ')') + { + auto start = pos; + pos = end + (ch == '%' ? 1 : 0); + return str.substr(start, pos - start); + } + return{}; + } +#endif + //Initializes the color with a CSS-like string //contributor: BigDave(mortis2007 at hotmail co uk) //date: February 3, 2015 //maintainor: Jinhao, extended the support of CSS-spec + color::color(std::string css_color) : a_(1.0) { @@ -135,6 +175,7 @@ namespace nana has_alpha = true; } +#if defined(USE_STD_REGEX) std::regex pat; std::regex_iterator i, end; auto type_name = css_color.substr(pos, 3); @@ -222,6 +263,106 @@ namespace nana throw std::invalid_argument(excpt_what); //invalid alpha value a_ = ::nana::stod(i->str()); } +#else + auto type_name = css_color.substr(pos, 3); + pos = css_color.find_first_not_of(' ', type_end); + if (pos == css_color.npos || css_color[pos] != '(') + throw std::invalid_argument(excpt_what); + + auto str = read_number(css_color, ++pos); + if (str.empty()) + throw std::invalid_argument(excpt_what); + + if ("rgb" == type_name) + { + std::vector rgb; + + rgb.emplace_back(std::move(str)); + + const bool is_real = (rgb.back().back() == '%'); + + for (int i = 0; i < 2; ++i) + { + pos = css_color.find_first_not_of(' ', pos); + if (pos == css_color.npos || css_color[pos] != ',') + throw std::invalid_argument(excpt_what); + + str = read_number(css_color, ++pos); + if (str.empty()) + throw std::invalid_argument(excpt_what); + + rgb.emplace_back(std::move(str)); + if (rgb.size() == 3) + break; + } + + if (rgb.size() != 3) + throw std::invalid_argument(excpt_what); + + if (is_real) + { + auto pr = ::nana::stod(rgb[0].substr(0, rgb[0].size() - 1)); + r_ = (pr > 100 ? 255.0 : 2.55 * pr); + + pr = ::nana::stod(rgb[1].substr(0, rgb[1].size() - 1)); + g_ = (pr > 100 ? 255.0 : 2.55 * pr); + + pr = ::nana::stod(rgb[2].substr(0, rgb[2].size() - 1)); + b_ = (pr > 100 ? 255.0 : 2.55 * pr); + } + else + { + r_ = ::nana::stod(rgb[0]); + if (r_ > 255.0) r_ = 255; + + g_ = ::nana::stod(rgb[1]); + if (g_ > 255.0) g_ = 255; + + b_ = ::nana::stod(rgb[2]); + if (b_ > 255.0) b_ = 255; + } + } + else if ("hsl" == type_name) + { + if (str.back() == '%') + throw std::invalid_argument(excpt_what); + + auto h = ::nana::stod(str); + + pos = css_color.find_first_not_of(' ', pos); + if (pos == css_color.npos || css_color[pos] != ',') + throw std::invalid_argument(excpt_what); + + str = read_number(css_color, ++pos); + if (str.empty() || str.back() != '%') + throw std::invalid_argument(excpt_what); + + auto s = ::nana::stod(str.substr(0, str.size() - 1)); + + pos = css_color.find_first_not_of(' ', pos); + if (pos == css_color.npos || css_color[pos] != ',') + throw std::invalid_argument(excpt_what); + + str = read_number(css_color, ++pos); + if (str.empty() || str.back() != '%') + throw std::invalid_argument(excpt_what); + + auto l = ::nana::stod(str.substr(0, str.size() - 1)); + + from_hsl(h, s / 100, l / 100); + } + else + throw std::invalid_argument(excpt_what); //invalid color type + + if (has_alpha) + { + str = read_number(css_color, ++pos); + if (str.empty() || str.back() == '%') + throw std::invalid_argument(excpt_what); //invalid alpha value + + a_ = ::nana::stod(str); + } +#endif } color& color::from_rgb(unsigned red, unsigned green, unsigned blue) From 9fbe14e2debeeac9a57f0a89c3a6496c3bf97c88 Mon Sep 17 00:00:00 2001 From: Jinhao Date: Thu, 26 Feb 2015 02:35:19 +0800 Subject: [PATCH 2/3] code reviews --- include/nana/deploy.hpp | 71 +++++-- include/nana/gui/widgets/listbox.hpp | 1 - source/basic_types.cpp | 22 +- source/deploy.cpp | 301 ++++++++++++++++++++------- source/gui/msgbox.cpp | 16 +- source/gui/widgets/date_chooser.cpp | 4 +- source/gui/widgets/listbox.cpp | 102 +++------ source/gui/widgets/spinbox.cpp | 6 +- source/gui/widgets/textbox.cpp | 4 +- source/internationalization.cpp | 2 +- 10 files changed, 329 insertions(+), 200 deletions(-) diff --git a/include/nana/deploy.hpp b/include/nana/deploy.hpp index e59e0d85..0862a7a3 100644 --- a/include/nana/deploy.hpp +++ b/include/nana/deploy.hpp @@ -21,6 +21,56 @@ #undef NANA_WINDOWS #endif +//Implement workarounds for MinGW +#if defined(NANA_MINGW) +namespace std +{ + //Workaround for no implemenation of std::stoi in MinGW. + int stoi(const std::string&, std::size_t * pos = nullptr, int base = 10); + int stoi(const std::wstring&, std::size_t* pos = nullptr, int base = 10); + + //Workaround for no implemenation of std::stof in MinGW. + float stof(const std::string&, std::size_t * pos = nullptr); + float stof(const std::wstring&, std::size_t* pos = nullptr); + + //Workaround for no implemenation of std::stod in MinGW. + double stod(const std::string&, std::size_t * pos = nullptr); + double stod(const std::wstring&, std::size_t* pos = nullptr); + + //Workaround for no implemenation of std::stold in MinGW. + long double stold(const std::string&, std::size_t * pos = nullptr); + long double stold(const std::wstring&, std::size_t* pos = nullptr); + + //Workaround for no implemenation of std::stol in MinGW. + long stol(const std::string&, std::size_t* pos = nullptr, int base = 10); + long stol(const std::wstring&, std::size_t* pos = nullptr, int base = 10); + + //Workaround for no implemenation of std::stoll in MinGW. + long long stoll(const std::string&, std::size_t* pos = nullptr, int base = 10); + long long stoll(const std::wstring&, std::size_t* pos = nullptr, int base = 10); + + //Workaround for no implemenation of std::stoul in MinGW. + unsigned long stoul(const std::string&, std::size_t* pos = nullptr, int base = 10); + unsigned long stoul(const std::wstring&, std::size_t* pos = nullptr, int base = 10); + + //Workaround for no implemenation of std::stoull in MinGW. + unsigned long long stoull(const std::string&, std::size_t* pos = nullptr, int base = 10); + unsigned long long stoull(const std::wstring&, std::size_t* pos = nullptr, int base = 10); + + //Workaround for no implemenation of std::to_wstring in MinGW. + std::wstring to_wstring(long double); + std::wstring to_wstring(double); + std::wstring to_wstring(unsigned); + std::wstring to_wstring(int); + std::wstring to_wstring(long); + std::wstring to_wstring(unsigned long); + std::wstring to_wstring(long long); + std::wstring to_wstring(unsigned long long); + std::wstring to_wstring(float); +} +#endif + + #ifndef NANA_UNICODE namespace nana { @@ -40,28 +90,7 @@ namespace nana { std::size_t strlen(const char_t* str); - double strtod(const char_t* str, char_t** endptr); char_t* strcpy(char_t* dest, const char_t* source); - - //Workaround for no implemenation of std::stoi in MinGW. - int stoi(const std::string&, std::size_t * pos = nullptr, int base = 10); - int stoi(const std::wstring&, std::size_t* pos = nullptr, int base = 10); - - //Workaround for no implemenation of std::stod in MinGW. - double stod(const std::string&, std::size_t * pos = nullptr); - double stod(const std::wstring&, std::size_t* pos = nullptr); - - //Workaround for no implemenation of std::to_wstring in MinGW. - std::wstring to_wstring(long double); - std::wstring to_wstring(double); - std::wstring to_wstring(unsigned); - std::wstring to_wstring(int); - std::wstring to_wstring(long); - std::wstring to_wstring(unsigned long); - std::wstring to_wstring(long long); - std::wstring to_wstring(unsigned long long); - std::wstring to_wstring(float); - } #if defined(NANA_WINDOWS) diff --git a/include/nana/gui/widgets/listbox.hpp b/include/nana/gui/widgets/listbox.hpp index 8274d3e3..1bc087be 100644 --- a/include/nana/gui/widgets/listbox.hpp +++ b/include/nana/gui/widgets/listbox.hpp @@ -558,7 +558,6 @@ By \a clicking on a header the list get \a reordered, first up, and then down al private: drawerbase::listbox::essence_t & _m_ess() const; nana::any* _m_anyobj(size_type cat, size_type index, bool allocate_if_empty) const; - size_type _m_headers() const; drawerbase::listbox::category_t* _m_at_key(std::shared_ptr); void _m_ease_key(nana::detail::key_interface*); }; diff --git a/source/basic_types.cpp b/source/basic_types.cpp index d02d497f..b49dc0bb 100644 --- a/source/basic_types.cpp +++ b/source/basic_types.cpp @@ -125,7 +125,7 @@ namespace nana if ((endpos - pos != 4) && (endpos - pos != 7)) throw std::invalid_argument(excpt_what); - auto n = ::nana::stoi(css_color.substr(pos + 1, endpos - pos - 1), nullptr, 16); + auto n = std::stoi(css_color.substr(pos + 1, endpos - pos - 1), nullptr, 16); if (endpos - pos == 4) { @@ -301,24 +301,24 @@ namespace nana if (is_real) { - auto pr = ::nana::stod(rgb[0].substr(0, rgb[0].size() - 1)); + auto pr = std::stod(rgb[0].substr(0, rgb[0].size() - 1)); r_ = (pr > 100 ? 255.0 : 2.55 * pr); - pr = ::nana::stod(rgb[1].substr(0, rgb[1].size() - 1)); + pr = std::stod(rgb[1].substr(0, rgb[1].size() - 1)); g_ = (pr > 100 ? 255.0 : 2.55 * pr); - pr = ::nana::stod(rgb[2].substr(0, rgb[2].size() - 1)); + pr = std::stod(rgb[2].substr(0, rgb[2].size() - 1)); b_ = (pr > 100 ? 255.0 : 2.55 * pr); } else { - r_ = ::nana::stod(rgb[0]); + r_ = std::stod(rgb[0]); if (r_ > 255.0) r_ = 255; - g_ = ::nana::stod(rgb[1]); + g_ = std::stod(rgb[1]); if (g_ > 255.0) g_ = 255; - b_ = ::nana::stod(rgb[2]); + b_ = std::stod(rgb[2]); if (b_ > 255.0) b_ = 255; } } @@ -327,7 +327,7 @@ namespace nana if (str.back() == '%') throw std::invalid_argument(excpt_what); - auto h = ::nana::stod(str); + auto h = std::stod(str); pos = css_color.find_first_not_of(' ', pos); if (pos == css_color.npos || css_color[pos] != ',') @@ -337,7 +337,7 @@ namespace nana if (str.empty() || str.back() != '%') throw std::invalid_argument(excpt_what); - auto s = ::nana::stod(str.substr(0, str.size() - 1)); + auto s = std::stod(str.substr(0, str.size() - 1)); pos = css_color.find_first_not_of(' ', pos); if (pos == css_color.npos || css_color[pos] != ',') @@ -347,7 +347,7 @@ namespace nana if (str.empty() || str.back() != '%') throw std::invalid_argument(excpt_what); - auto l = ::nana::stod(str.substr(0, str.size() - 1)); + auto l = std::stod(str.substr(0, str.size() - 1)); from_hsl(h, s / 100, l / 100); } @@ -360,7 +360,7 @@ namespace nana if (str.empty() || str.back() == '%') throw std::invalid_argument(excpt_what); //invalid alpha value - a_ = ::nana::stod(str); + a_ = std::stod(str); } #endif } diff --git a/source/deploy.cpp b/source/deploy.cpp index e9e0d5d2..b2d053f4 100644 --- a/source/deploy.cpp +++ b/source/deploy.cpp @@ -15,6 +15,7 @@ #include #include #include + #if defined(NANA_WINDOWS) #include #elif defined(NANA_LINUX) @@ -22,38 +23,12 @@ #include PLATFORM_SPEC_HPP #endif -namespace nana +#if defined(NANA_MINGW) +#include +namespace std { - std::size_t strlen(const char_t* str) - { -#if defined(NANA_UNICODE) - return ::wcslen(str); -#else - return ::strlen(str); -#endif - } - - double strtod(const char_t* str, char_t** endptr) - { -#if defined(NANA_UNICODE) - return ::wcstod(str, endptr); -#else - return ::strtod(str, endptr); -#endif - } - - char_t* strcpy(char_t* dest, const char_t* source) - { -#if defined(NANA_UNICODE) - return ::wcscpy(dest, source); -#else - return ::strcpy(dest, source); -#endif - } - int stoi(const std::string& str, std::size_t * pos, int base) { -#if defined(NANA_MINGW) auto sptr = str.c_str(); char *end; errno = 0; @@ -67,14 +42,10 @@ namespace nana if (pos) *pos = (std::size_t)(end - sptr); return ((int)result); -#else - return std::stoi(str, pos, base); -#endif } int stoi(const std::wstring& str, std::size_t* pos, int base) { -#if defined(NANA_MINGW) auto sptr = str.data(); wchar_t *end; errno = 0; @@ -88,14 +59,42 @@ namespace nana if (pos) *pos = (std::size_t)(end - sptr); return ((int)result); -#else - return std::stoi(str, pos, base); -#endif + } + + float stof(const std::string& str, std::size_t * pos) + { + auto *ptr = str.data(); + errno = 0; + char *end; + auto result = std::strtof(ptr, &end); + + if (ptr == end) + throw std::invalid_argument("invalid stod argument"); + if (errno == ERANGE) + throw std::out_of_range("stof argument out of range"); + if (pos) + *pos = (std::size_t)(end - ptr); + return result; + } + + float stof(const std::wstring& str, std::size_t* pos) + { + auto *ptr = str.data(); + errno = 0; + wchar_t *end; + auto result = std::wcstof(ptr, &end); + + if (ptr == end) + throw std::invalid_argument("invalid stod argument"); + if (errno == ERANGE) + throw std::out_of_range("stof argument out of range"); + if (pos) + *pos = (std::size_t)(end - ptr); + return result; } double stod(const std::string& str, std::size_t * pos) { -#ifdef NANA_MINGW auto *ptr = str.data(); errno = 0; char *end; @@ -108,14 +107,10 @@ namespace nana if (pos) *pos = (std::size_t)(end - ptr); return result; -#else - return std::stod(str, pos); -#endif } double stod(const std::wstring& str, std::size_t* pos) { -#ifdef NANA_MINGW auto *ptr = str.data(); errno = 0; wchar_t *end; @@ -128,110 +123,258 @@ namespace nana if (pos) *pos = (std::size_t)(end - ptr); return result; -#else - return std::stod(str, pos); -#endif + } + + long double stold(const std::string& str, std::size_t * pos) + { + auto *ptr = str.data(); + errno = 0; + char *end; + auto result = std::strtold(ptr, &end); + + if (ptr == end) + throw std::invalid_argument("invalid stod argument"); + if (errno == ERANGE) + throw std::out_of_range("stold argument out of range"); + if (pos) + *pos = (std::size_t)(end - ptr); + return result; + } + + long double stold(const std::wstring& str, std::size_t* pos) + { + auto *ptr = str.data(); + errno = 0; + wchar_t *end; + auto result = std::wcstold(ptr, &end); + + if (ptr == end) + throw std::invalid_argument("invalid stod argument"); + if (errno == ERANGE) + throw std::out_of_range("stold argument out of range"); + if (pos) + *pos = (std::size_t)(end - ptr); + return result; + } + + long stol(const std::string& str, std::size_t* pos, int base) + { + auto *ptr = str.data(); + errno = 0; + char *end; + auto result = std::strtol(ptr, &end, base); + + if (ptr == end) + throw std::invalid_argument("invalid stod argument"); + if (errno == ERANGE) + throw std::out_of_range("stol argument out of range"); + if (pos) + *pos = (std::size_t)(end - ptr); + return result; + } + + long stol(const std::wstring& str, std::size_t* pos, int base) + { + auto *ptr = str.data(); + errno = 0; + wchar_t *end; + auto result = std::wcstol(ptr, &end, base); + + if (ptr == end) + throw std::invalid_argument("invalid stod argument"); + if (errno == ERANGE) + throw std::out_of_range("stol argument out of range"); + if (pos) + *pos = (std::size_t)(end - ptr); + return result; + } + + //Workaround for no implemenation of std::stoll in MinGW. + long long stoll(const std::string& str, std::size_t* pos, int base) + { + auto *ptr = str.data(); + errno = 0; + char* end; + auto result = std::strtoll(ptr, &end, base); + + if (ptr == end) + throw std::invalid_argument("invalid stod argument"); + if (errno == ERANGE) + throw std::out_of_range("stoll argument out of range"); + if (pos) + *pos = (std::size_t)(end - ptr); + return result; + } + + long long stoll(const std::wstring& str, std::size_t* pos, int base) + { + auto *ptr = str.data(); + errno = 0; + wchar_t* end; + auto result = std::wcstoll(ptr, &end, base); + + if (ptr == end) + throw std::invalid_argument("invalid stod argument"); + if (errno == ERANGE) + throw std::out_of_range("stoll argument out of range"); + if (pos) + *pos = (std::size_t)(end - ptr); + return result; + } + + unsigned long long stoull(const std::string& str, std::size_t* pos, int base) + { + auto *ptr = str.data(); + errno = 0; + char* end; + auto result = std::strtoull(ptr, &end, base); + + if (ptr == end) + throw std::invalid_argument("invalid stod argument"); + if (errno == ERANGE) + throw std::out_of_range("stoull argument out of range"); + if (pos) + *pos = (std::size_t)(end - ptr); + return result; + } + + unsigned long long stoull(const std::wstring& str, std::size_t* pos, int base) + { + auto *ptr = str.data(); + errno = 0; + wchar_t* end; + auto result = std::wcstoull(ptr, &end, base); + + if (ptr == end) + throw std::invalid_argument("invalid stod argument"); + if (errno == ERANGE) + throw std::out_of_range("stoull argument out of range"); + if (pos) + *pos = (std::size_t)(end - ptr); + return result; + } + + //Workaround for no implemenation of std::stoul in MinGW. + unsigned long stoul(const std::string& str, std::size_t* pos, int base) + { + auto *ptr = str.data(); + errno = 0; + char* end; + auto result = std::strtoul(ptr, &end, base); + + if (ptr == end) + throw std::invalid_argument("invalid stod argument"); + if (errno == ERANGE) + throw std::out_of_range("stoul argument out of range"); + if (pos) + *pos = (std::size_t)(end - ptr); + return result; + } + + unsigned long stoul(const std::wstring& str, std::size_t* pos, int base) + { + auto *ptr = str.data(); + errno = 0; + wchar_t* end; + auto result = std::wcstoul(ptr, &end, base); + + if (ptr == end) + throw std::invalid_argument("invalid stod argument"); + if (errno == ERANGE) + throw std::out_of_range("stoul argument out of range"); + if (pos) + *pos = (std::size_t)(end - ptr); + return result; } std::wstring to_wstring(double v) { -#ifdef NANA_MINGW std::wstringstream ss; ss << v; return ss.str(); -#else - return std::to_wstring(v); -#endif } std::wstring to_wstring(long double v) { -#ifdef NANA_MINGW std::wstringstream ss; ss << v; return ss.str(); -#else - return std::to_wstring(v); -#endif } std::wstring to_wstring(unsigned v) { -#ifdef NANA_MINGW std::wstringstream ss; ss << v; return ss.str(); -#else - return std::to_wstring(v); -#endif } std::wstring to_wstring(int v) { -#ifdef NANA_MINGW std::wstringstream ss; ss << v; return ss.str(); -#else - return std::to_wstring(v); -#endif } std::wstring to_wstring(long v) { -#ifdef NANA_MINGW std::wstringstream ss; ss << v; return ss.str(); -#else - return std::to_wstring(v); -#endif } std::wstring to_wstring(unsigned long v) { -#ifdef NANA_MINGW std::wstringstream ss; ss << v; return ss.str(); -#else - return std::to_wstring(v); -#endif } std::wstring to_wstring(long long v) { -#ifdef NANA_MINGW std::wstringstream ss; ss << v; return ss.str(); -#else - return std::to_wstring(v); -#endif } std::wstring to_wstring(unsigned long long v) { -#ifdef NANA_MINGW std::wstringstream ss; ss << v; return ss.str(); -#else - return std::to_wstring(v); -#endif } std::wstring to_wstring(float v) { -#ifdef NANA_MINGW std::wstringstream ss; ss << v; return ss.str(); + } +} +#endif + +namespace nana +{ + std::size_t strlen(const char_t* str) + { +#if defined(NANA_UNICODE) + return ::wcslen(str); #else - return std::to_wstring(v); -#endif + return ::strlen(str); +#endif } + char_t* strcpy(char_t* dest, const char_t* source) + { +#if defined(NANA_UNICODE) + return ::wcscpy(dest, source); +#else + return ::strcpy(dest, source); +#endif + } +} + +namespace nana +{ bool is_incomplete(const nana::string& str, unsigned pos) { #ifndef NANA_UNICODE diff --git a/source/gui/msgbox.cpp b/source/gui/msgbox.cpp index 7f71376b..e43a5ee7 100644 --- a/source/gui/msgbox.cpp +++ b/source/gui/msgbox.cpp @@ -701,12 +701,12 @@ namespace nana //get the longest value int longest = (std::abs((impl->begin < 0 ? impl->begin * 10 : impl->begin)) < std::abs(impl->last < 0 ? impl->last * 10 : impl->last) ? impl->last : impl->begin); paint::graphics graph{ ::nana::size{ 10, 10 } }; - auto value_px = graph.text_extent_size(::nana::to_wstring(longest)).width + 34; + auto value_px = graph.text_extent_size(std::to_wstring(longest)).width + 34; 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(::nana::to_wstring(impl->value)); + impl->spinbox.value(std::to_wstring(impl->value)); impl->dock.events().resized.connect_unignorable([impl, label_px, value_px](const ::nana::arg_resized& arg) { @@ -779,12 +779,12 @@ namespace nana //get the longest value auto longest = (std::abs((impl->begin < 0 ? impl->begin * 10 : impl->begin)) < std::abs(impl->last < 0 ? impl->last * 10 : impl->last) ? impl->last : impl->begin); paint::graphics graph{ ::nana::size{ 10, 10 } }; - auto value_px = graph.text_extent_size(::nana::to_wstring(longest)).width + 34; + auto value_px = graph.text_extent_size(std::to_wstring(longest)).width + 34; 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(::nana::to_wstring(impl->value)); + impl->spinbox.value(std::to_wstring(impl->value)); impl->dock.events().resized.connect_unignorable([impl, label_px, value_px](const ::nana::arg_resized& arg) { @@ -947,7 +947,7 @@ namespace nana ::nana::string inputbox::date::value() const { - return nana::to_wstring(impl_->month) + L'-' + nana::to_wstring(impl_->day) + L", " + nana::to_wstring(impl_->year); + return std::to_wstring(impl_->month) + L'-' + std::to_wstring(impl_->day) + L", " + std::to_wstring(impl_->year); } int inputbox::date::year() const @@ -1008,8 +1008,8 @@ namespace nana impl->wdg_month.option(today.month - 1); - impl->wdg_day.value(::nana::to_wstring(today.day)); - impl->wdg_year.value(::nana::to_wstring(today.year)); + impl->wdg_day.value(std::to_wstring(today.day)); + impl->wdg_year.value(std::to_wstring(today.year)); impl->dock.events().resized.connect_unignorable([impl, label_px](const ::nana::arg_resized& arg) { @@ -1050,7 +1050,7 @@ namespace nana if (day > days) day = days; - impl->wdg_day.value(::nana::to_wstring(day)); + impl->wdg_day.value(std::to_wstring(day)); }; impl->wdg_year.events().text_changed.connect_unignorable(make_days); diff --git a/source/gui/widgets/date_chooser.cpp b/source/gui/widgets/date_chooser.cpp index 16b493c3..3f1818ca 100644 --- a/source/gui/widgets/date_chooser.cpp +++ b/source/gui/widgets/date_chooser.cpp @@ -133,7 +133,7 @@ namespace nana str = ::nana::internationalization()(monthstr[chmonth_.month - 1]); str += STR(" "); } - str += ::nana::to_wstring(chmonth_.year); + str += std::to_wstring(chmonth_.year); nana::size txt_s = graph.text_extent_size(str); @@ -203,7 +203,7 @@ namespace nana void trigger::_m_draw_pos(drawing_basis & dbasis, graph_reference graph, int x, int y, int number, bool primary, bool sel) { - _m_draw_pos(dbasis, graph, x, y, ::nana::to_wstring(number), primary, sel); + _m_draw_pos(dbasis, graph, x, y, std::to_wstring(number), primary, sel); } void trigger::_m_draw_ex_days(drawing_basis & dbasis, graph_reference graph, int begx, int begy, bool before) diff --git a/source/gui/widgets/listbox.cpp b/source/gui/widgets/listbox.cpp index 8d3ab0c4..7d1bec1b 100644 --- a/source/gui/widgets/listbox.cpp +++ b/source/gui/widgets/listbox.cpp @@ -18,7 +18,6 @@ #include #include #include -#include #include namespace nana @@ -87,66 +86,66 @@ namespace nana } oresolver& oresolver::operator<<(short n) { - cells_.emplace_back(::nana::to_wstring(n)); + cells_.emplace_back(std::to_wstring(n)); return *this; } oresolver& oresolver::operator<<(unsigned short n) { - cells_.emplace_back(::nana::to_wstring(n)); + cells_.emplace_back(std::to_wstring(n)); return *this; } oresolver& oresolver::operator<<(int n) { - cells_.emplace_back(::nana::to_wstring(n)); + cells_.emplace_back(std::to_wstring(n)); return *this; } oresolver& oresolver::operator<<(unsigned int n) { - cells_.emplace_back(::nana::to_wstring(n)); + cells_.emplace_back(std::to_wstring(n)); return *this; } oresolver& oresolver::operator<<(long n) { - cells_.emplace_back(::nana::to_wstring(n)); + cells_.emplace_back(std::to_wstring(n)); return *this; } oresolver& oresolver::operator<<(unsigned long n) { - cells_.emplace_back(::nana::to_wstring(n)); + cells_.emplace_back(std::to_wstring(n)); return *this; } oresolver& oresolver::operator<<(long long n) { - cells_.emplace_back(::nana::to_wstring(n)); + cells_.emplace_back(std::to_wstring(n)); return *this; } oresolver& oresolver::operator<<(unsigned long long n) { - cells_.emplace_back(::nana::to_wstring(n)); + cells_.emplace_back(std::to_wstring(n)); return *this; } oresolver& oresolver::operator<<(float f) { - cells_.emplace_back(::nana::to_wstring(f)); + cells_.emplace_back(std::to_wstring(f)); return *this; } oresolver& oresolver::operator<<(double f) { - cells_.emplace_back(::nana::to_wstring(f)); + cells_.emplace_back(std::to_wstring(f)); return *this; } oresolver& oresolver::operator<<(long double f) { - cells_.emplace_back(::nana::to_wstring(f)); + cells_.emplace_back(std::to_wstring(f)); return *this; } @@ -201,117 +200,82 @@ namespace nana iresolver& iresolver::operator>>(bool& n) { if (pos_ < cells_.size()) - { - std::wstringstream ss(cells_[pos_++].text); - ss >> n; - } + n = (std::stoi(cells_[pos_++].text) == 0); return *this; } iresolver& iresolver::operator>>(short& n) { if (pos_ < cells_.size()) - { - std::wstringstream ss(cells_[pos_++].text); - ss >> n; - } + n = std::stoi(cells_[pos_++].text); return *this; } iresolver& iresolver::operator>>(unsigned short& n) { if (pos_ < cells_.size()) - { - std::wstringstream ss(cells_[pos_++].text); - ss >> n; - } + n = static_cast(std::stoul(cells_[pos_++].text)); return *this; } iresolver& iresolver::operator>>(int& n) { if (pos_ < cells_.size()) - { - std::wstringstream ss(cells_[pos_++].text); - ss >> n; - } + n = std::stoi(cells_[pos_++].text); return *this; } iresolver& iresolver::operator>>(unsigned int& n) { if (pos_ < cells_.size()) - { - std::wstringstream ss(cells_[pos_++].text); - ss >> n; - } + n = std::stoul(cells_[pos_++].text); return *this; } iresolver& iresolver::operator>>(long& n) { if (pos_ < cells_.size()) - { - std::wstringstream ss(cells_[pos_++].text); - ss >> n; - } + n = std::stol(cells_[pos_++].text); return *this; } + iresolver& iresolver::operator>>(unsigned long& n) { if (pos_ < cells_.size()) - { - std::wstringstream ss(cells_[pos_++].text); - ss >> n; - } + n = std::stoul(cells_[pos_++].text); return *this; } iresolver& iresolver::operator>>(long long& n) { if (pos_ < cells_.size()) - { - std::wstringstream ss(cells_[pos_++].text); - ss >> n; - } + n = std::stoll(cells_[pos_++].text); return *this; } iresolver& iresolver::operator>>(unsigned long long& n) { if (pos_ < cells_.size()) - { - std::wstringstream ss(cells_[pos_++].text); - ss >> n; - } + n = std::stoull(cells_[pos_++].text); return *this; } iresolver& iresolver::operator>>(float& f) { if (pos_ < cells_.size()) - { - std::wstringstream ss(cells_[pos_++].text); - ss >> f; - } + f = std::stof(cells_[pos_++].text); return *this; } iresolver& iresolver::operator>>(double& f) { if (pos_ < cells_.size()) - { - std::wstringstream ss(cells_[pos_++].text); - ss >> f; - } + f = std::stod(cells_[pos_++].text); return *this; } iresolver& iresolver::operator>>(long double& f) { if (pos_ < cells_.size()) - { - std::wstringstream ss(cells_[pos_++].text); - ss >> f; - } + f = std::stold(cells_[pos_++].text); return *this; } @@ -1183,8 +1147,9 @@ namespace nana } } - void item_checked(selection& vec) const + selection item_checked() const { + selection vec; index_pair id; for(auto & cat : list_) { @@ -1197,6 +1162,7 @@ namespace nana } ++id.cat; } + return vec; } void select_range(index_pair fr, index_pair to, bool sel) @@ -2595,7 +2561,7 @@ namespace nana graph->string({ x + 20, y + txtoff }, categ.text, txt_color); - ::nana::string str = L'(' + ::nana::to_wstring(categ.items.size()) + L')'; + ::nana::string str = L'(' + std::to_wstring(categ.items.size()) + L')'; unsigned str_w = graph->text_extent_size(str).width; @@ -3699,8 +3665,7 @@ namespace nana auto & ess = _m_ess(); if (ess.lister.insert(pos, std::move(text))) { - window wd = handle(); - if (false == API::empty_window(wd)) + if (! empty()) { auto & item = ess.lister.at(pos); item.bgcolor = bgcolor(); @@ -3722,9 +3687,7 @@ namespace nana auto listbox::checked() const -> selection { - selection s; - _m_ess().lister.item_checked(s); - return std::move(s); + return _m_ess().lister.item_checked(); } void listbox::clear(size_type cat) @@ -3891,11 +3854,6 @@ namespace nana return _m_ess().lister.anyobj(index_pair{cat, index}, allocate_if_empty); } - auto listbox::_m_headers() const -> size_type - { - return _m_ess().header.cont().size(); - } - drawerbase::listbox::category_t* listbox::_m_at_key(std::shared_ptr ptr) { auto & ess = _m_ess(); diff --git a/source/gui/widgets/spinbox.cpp b/source/gui/widgets/spinbox.cpp index a662d294..c99367ae 100644 --- a/source/gui/widgets/spinbox.cpp +++ b/source/gui/widgets/spinbox.cpp @@ -73,7 +73,7 @@ namespace nana std::wstring value() const override { - return ::nana::to_wstring(value_); + return std::to_wstring(value_); } bool value(const std::wstring& value_str, bool & diff) override @@ -663,12 +663,12 @@ namespace nana int spinbox::to_int() const { - return ::nana::stoi(value()); + return std::stoi(value()); } double spinbox::to_double() const { - return ::nana::stod(value()); + return std::stod(value()); } void spinbox::modifier(std::wstring prefix, std::wstring suffix) diff --git a/source/gui/widgets/textbox.cpp b/source/gui/widgets/textbox.cpp index ffbacb05..cd30dafe 100644 --- a/source/gui/widgets/textbox.cpp +++ b/source/gui/widgets/textbox.cpp @@ -456,13 +456,13 @@ namespace drawerbase { textbox& textbox::from(int n) { - _m_caption(::nana::to_wstring(n)); + _m_caption(std::to_wstring(n)); return *this; } textbox& textbox::from(double d) { - _m_caption(::nana::to_wstring(d)); + _m_caption(std::to_wstring(d)); return *this; } diff --git a/source/internationalization.cpp b/source/internationalization.cpp index 30908ce7..fd8a9b9c 100644 --- a/source/internationalization.cpp +++ b/source/internationalization.cpp @@ -343,7 +343,7 @@ namespace nana erase_n = str.size() - offset; //If there is not a parameter for %argNNN, the %argNNN will be erased. - std::size_t arg = static_cast(::nana::stoi(str.substr(offset + 4, arg_n))); + std::size_t arg = static_cast(std::stoi(str.substr(offset + 4, arg_n))); if (arg_strs && arg < arg_strs->size()) str.replace(offset, erase_n, (*arg_strs)[arg]); From 42af0010201c982a7625d49af94548fe949f5326 Mon Sep 17 00:00:00 2001 From: Ryan Gonzalez Date: Thu, 26 Feb 2015 19:00:03 -0600 Subject: [PATCH 3/3] Fix Linux builds --- include/nana/paint/detail/image_bmp.hpp | 10 +++++----- source/gui/layout_utility.cpp | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/include/nana/paint/detail/image_bmp.hpp b/include/nana/paint/detail/image_bmp.hpp index e7b27c35..f5493881 100644 --- a/include/nana/paint/detail/image_bmp.hpp +++ b/include/nana/paint/detail/image_bmp.hpp @@ -82,7 +82,7 @@ namespace nana{ namespace paint return false; std::unique_ptr buffer(new char[static_cast(size)]); - + ifs.read(buffer.get(), size); if(size == ifs.gcount()) { @@ -94,7 +94,7 @@ namespace nana{ namespace paint //Bitmap file is 4byte-aligned for each line. std::size_t bytes_per_line; - const std::size_t height_pixels = abs(info->bmiHeader.biHeight); + const std::size_t height_pixels = std::abs(info->bmiHeader.biHeight); if(0 == info->bmiHeader.biSizeImage) bytes_per_line = (((info->bmiHeader.biWidth * info->bmiHeader.biBitCount + 31) & ~31) >> 3); else @@ -204,7 +204,7 @@ namespace nana{ namespace paint d = dpend; s -= bytes_per_line; } - } + } } else if(2 == info->bmiHeader.biBitCount) { @@ -257,7 +257,7 @@ namespace nana{ namespace paint d = dpend; s -= bytes_per_line; } - } + } } else if(1 == info->bmiHeader.biBitCount) { @@ -310,7 +310,7 @@ namespace nana{ namespace paint d = dpend; s -= bytes_per_line; } - } + } } } } diff --git a/source/gui/layout_utility.cpp b/source/gui/layout_utility.cpp index 7f72db0c..d59e89c3 100644 --- a/source/gui/layout_utility.cpp +++ b/source/gui/layout_utility.cpp @@ -18,11 +18,11 @@ namespace nana //overlap test if overlaped between r1 and r2 bool overlap(const rectangle& r1, const rectangle& r2) { - if (r1.y + long long(r1.height) <= r2.y) return false; - if(r1.y >= r2.y + long long(r2.height)) return false; + if (r1.y + (long long)(r1.height) <= r2.y) return false; + if(r1.y >= r2.y + (long long)(r2.height)) return false; - if(r1.x + long long(r1.width) <= r2.x) return false; - if(r1.x >= r2.x + long long(r2.width)) return false; + if(r1.x + (long long)(r1.width) <= r2.x) return false; + if(r1.x >= r2.x + (long long)(r2.width)) return false; return true; } @@ -255,7 +255,7 @@ namespace nana ref_s.width = static_cast(ref_s.height * rate_input); else if (rate_input > rate_ref) ref_s.height = static_cast(ref_s.width / rate_input); - + return ref_s; }