From 3863a0dc604742ab623dad418a0fed95094845eb Mon Sep 17 00:00:00 2001 From: Jinhao Date: Sat, 5 Dec 2015 14:03:46 +0800 Subject: [PATCH 1/4] improve the detection for GCC --- include/nana/config.hpp | 83 ++++++++++++------------- include/nana/deploy.hpp | 17 ++++- source/deploy.cpp | 68 ++++++++++++++++++++ source/gui/detail/linux_X11/bedrock.cpp | 6 +- source/gui/place.cpp | 7 +-- 5 files changed, 128 insertions(+), 53 deletions(-) diff --git a/include/nana/config.hpp b/include/nana/config.hpp index 806a0fd1..8f519e9b 100644 --- a/include/nana/config.hpp +++ b/include/nana/config.hpp @@ -20,40 +20,9 @@ #define NANA_WINDOWS 1 - // compilers in Windows... - - // MSVC++ versions - #if defined(_MSC_VER) - #define _SCL_SECURE_NO_WARNNGS - #define _CRT_SECURE_NO_DEPRECATE - #pragma warning(disable : 4996) - - #if (_MSC_VER == 1900) - // google: break any code that tries to use codecvt or codecvt. - // google: It appears the C++ libs haven't been compiled with native char16_t/char32_t support. - // google: Those definitions are for codecvt::id, codecvt::id and codecvt::id respectively. - // However, the codecvt::id and codecvt::id definitions aren't there, and indeed, if you look at locale0.cpp in the CRT source code you'll see they're not defined at all. - // google: That's a known issue, tracked by an active bug (DevDiv#1060849). We were able to update the STL's headers in response to char16_t/char32_t, but we still need to update the separately compiled sources. - #define STD_CODECVT_NOT_SUPPORTED - #endif // _MSC_VER == 1900 - #endif // _MSVC - // MINGW ... #if defined(__MINGW32__) || defined(__MINGW64__) || defined(MINGW) #define NANA_MINGW - //#define STD_THREAD_NOT_SUPPORTED // don't works? why? where __GNUC__, etc. are set? by CLion ?? - //Use this flag if MinGW version is older than 4.8.1 - #if ((__GNUC__ == 4) && ((__GNUC_MINOR__ < 8) || (__GNUC_MINOR__ == 8 && __GNUC_PATCHLEVEL__ < 2))) - // don't works? why? where __GNUC__, etc. are set? by CLion ?? - // ?? - #define UNDEFINED_to_string - - // https://github.com/meganz/mingw-std-threads - #define STD_THREAD_NOT_SUPPORTED - #define USE_github_com_meganz_mingw_std_threads - - #endif - #endif // MINGW // end Windows @@ -85,24 +54,52 @@ // compilers ... -// temp -//#define STD_NUMERIC_CONVERSIONS_NOT_SUPPORTED // don't works? -//#define STD_CODECVT_NOT_SUPPORTED +// MSVC++ versions +#if defined(_MSC_VER) + #define _SCL_SECURE_NO_WARNNGS + #define _CRT_SECURE_NO_DEPRECATE + #pragma warning(disable : 4996) - // GCC ... - #if defined(__GNU__) - #if (__GNUC__ == 4) && (__GNUC_MINOR__ == 8) && (__GNUC_PATCHLEVEL__ <= 1) - // don't works? + #if (_MSC_VER == 1900) + // google: break any code that tries to use codecvt or codecvt. + // google: It appears the C++ libs haven't been compiled with native char16_t/char32_t support. + // google: Those definitions are for codecvt::id, codecvt::id and codecvt::id respectively. + // However, the codecvt::id and codecvt::id definitions aren't there, and indeed, if you look at locale0.cpp in the CRT source code you'll see they're not defined at all. + // google: That's a known issue, tracked by an active bug (DevDiv#1060849). We were able to update the STL's headers in response to char16_t/char32_t, but we still need to update the separately compiled sources. + #define STD_CODECVT_NOT_SUPPORTED + #endif // _MSC_VER == 1900 +#endif // _MSVC - //GCC 4.7.0 does not implement the and codecvt_utfx classes ?? - #define STD_CODECVT_NOT_SUPPORTED +//GCC +#if defined(__GNUC__) + #if defined(__GLIBCPP__) || defined(__GLIBCXX__) + // is a known issue on libstdc++, it works on libc++ + #define STD_CODECVT_NOT_SUPPORTED + #endif - //Some functions which are specified in 21.5 Numeric conversions in Strings library have not yet implemented + #if (__GNUC__ == 4) + #if ((__GNUC_MINOR__ < 8) || (__GNUC_MINOR__ == 8 && __GNUC_PATCHLEVEL__ < 1)) + #define STD_THREAD_NOT_SUPPORTED - //Implement workarounds for GCC/MinGW which version is below 4.8.2 + //boost.thread is preferred + //but if USE_github_com_meganz_mingw_std_threads is enabled, + //boost.thread will be replaced with meganz's mingw-std-threads. + // https://github.com/meganz/mingw-std-threads + //#define USE_github_com_meganz_mingw_std_threads + #endif + + #if defined(NANA_MINGW) + //It's a known issue under MinGW #define STD_NUMERIC_CONVERSIONS_NOT_SUPPORTED #endif - #endif // GCC + + #if ((__GNUC_MINOR__ < 8) || defined(NANA_MINGW)) + #define STD_TO_STRING_NOT_SUPPORTED + #endif + #endif +#endif + + // End compilers ... diff --git a/include/nana/deploy.hpp b/include/nana/deploy.hpp index e1f15d7d..30d87935 100644 --- a/include/nana/deploy.hpp +++ b/include/nana/deploy.hpp @@ -56,8 +56,23 @@ namespace std //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); +} +#endif //STD_NUMERIC_CONVERSIONS_NOT_SUPPORTED - //Workaround for no implemenation of std::to_wstring in MinGW. +#ifdef STD_TO_STRING_NOT_SUPPORTED +namespace std +{ + //Workaround for no implemenation of std::to_string/std::to_wstring in MinGW. + std::string to_string(long double); + std::string to_string(double); + std::string to_string(unsigned); + std::string to_string(int); + std::string to_string(long); + std::string to_string(unsigned long); + std::string to_string(long long); + std::string to_string(unsigned long long); + std::string to_string(float); + std::wstring to_wstring(long double); std::wstring to_wstring(double); std::wstring to_wstring(unsigned); diff --git a/source/deploy.cpp b/source/deploy.cpp index 817721ec..ce92982a 100644 --- a/source/deploy.cpp +++ b/source/deploy.cpp @@ -294,6 +294,74 @@ namespace std *pos = (std::size_t)(end - ptr); return result; } +}//end namespace std +#endif //STD_NUMERIC_CONVERSIONS_NOT_SUPPORTED + +#ifdef STD_TO_STRING_NOT_SUPPORTED +namespace std +{ + std::string to_string(double v) + { + std::stringstream ss; + ss << v; + return ss.str(); + } + + std::string to_string(long double v) + { + std::stringstream ss; + ss << v; + return ss.str(); + } + + std::string to_string(unsigned v) + { + std::stringstream ss; + ss << v; + return ss.str(); + } + + std::string to_string(int v) + { + std::stringstream ss; + ss << v; + return ss.str(); + } + + std::string to_string(long v) + { + std::stringstream ss; + ss << v; + return ss.str(); + } + + std::string to_string(unsigned long v) + { + std::stringstream ss; + ss << v; + return ss.str(); + } + + std::string to_string(long long v) + { + std::stringstream ss; + ss << v; + return ss.str(); + } + + std::string to_string(unsigned long long v) + { + std::stringstream ss; + ss << v; + return ss.str(); + } + + std::string to_string(float v) + { + std::stringstream ss; + ss << v; + return ss.str(); + } std::wstring to_wstring(double v) { diff --git a/source/gui/detail/linux_X11/bedrock.cpp b/source/gui/detail/linux_X11/bedrock.cpp index 991cf8ef..5a69ab34 100644 --- a/source/gui/detail/linux_X11/bedrock.cpp +++ b/source/gui/detail/linux_X11/bedrock.cpp @@ -468,8 +468,8 @@ namespace detail arg.right_button = ((Button2Mask & mask_state) != 0) || (::nana::mouse::right_button == arg.button); arg.mid_button = ((Button3Mask & mask_state) != 0) || (::nana::mouse::middle_button == arg.button); arg.alt = ((Mod1Mask & mask_state) != 0); - arg.shift = ги(ShiftMask & mask_state) != 0); - arg.ctrl = ги(ControlMask & mask_state) != 0); + arg.shift = ((ShiftMask & mask_state) != 0); + arg.ctrl = ((ControlMask & mask_state) != 0); } @@ -833,7 +833,7 @@ namespace detail msgwnd->flags.action = mouse_action::over; click_arg.window_handle = reinterpret_cast(msgwnd); - emit_drawer(&drawer::click, msgwnd, arg, &context); + emit_drawer(&drawer::click, msgwnd, click_arg, &context); } } diff --git a/source/gui/place.cpp b/source/gui/place.cpp index da742af5..88ea8dd7 100644 --- a/source/gui/place.cpp +++ b/source/gui/place.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -95,13 +96,7 @@ namespace nana std::string pos_str() const { -#ifdef UNDEFINED_to_string - std::stringstream ss; - ss< Date: Sat, 5 Dec 2015 15:52:31 +0800 Subject: [PATCH 2/4] remove platform_spec_selector.cpp and bedrock_selector.cpp --- build/codeblocks/nana.cbp | 6 +++-- build/vc2013/nana.vcxproj | 4 ++-- build/vc2013/nana.vcxproj.filters | 18 +++++---------- build/vc2015/nana.sln | 18 +++++++-------- build/vc2015/nana.vcxproj | 4 ++-- build/vc2015/nana.vcxproj.filters | 18 +++++---------- include/nana/config.hpp | 15 ++++++------ include/nana/filesystem/file_iterator.hpp | 2 +- ...tform_spec.cpp => platform_spec_posix.cpp} | 4 +++- source/detail/platform_spec_selector.cpp | 22 ------------------ ...orm_spec.cpp => platform_spec_windows.cpp} | 5 ++++ .../{linux_X11 => x11}/msg_dispatcher.hpp | 0 .../bedrock.cpp => bedrock_posix.cpp} | 2 ++ source/gui/detail/bedrock_selector.cpp | 23 ------------------- .../bedrock.cpp => bedrock_windows.cpp} | 2 ++ 15 files changed, 49 insertions(+), 94 deletions(-) rename source/detail/{linux_X11/platform_spec.cpp => platform_spec_posix.cpp} (99%) delete mode 100644 source/detail/platform_spec_selector.cpp rename source/detail/{win32/platform_spec.cpp => platform_spec_windows.cpp} (99%) rename source/detail/{linux_X11 => x11}/msg_dispatcher.hpp (100%) rename source/gui/detail/{linux_X11/bedrock.cpp => bedrock_posix.cpp} (99%) delete mode 100644 source/gui/detail/bedrock_selector.cpp rename source/gui/detail/{win32/bedrock.cpp => bedrock_windows.cpp} (99%) diff --git a/build/codeblocks/nana.cbp b/build/codeblocks/nana.cbp index 03e6b72f..49f61ad7 100644 --- a/build/codeblocks/nana.cbp +++ b/build/codeblocks/nana.cbp @@ -49,14 +49,16 @@ - + + - + + diff --git a/build/vc2013/nana.vcxproj b/build/vc2013/nana.vcxproj index 41477943..01db0e79 100644 --- a/build/vc2013/nana.vcxproj +++ b/build/vc2013/nana.vcxproj @@ -187,7 +187,7 @@ - + @@ -195,12 +195,12 @@ + - diff --git a/build/vc2013/nana.vcxproj.filters b/build/vc2013/nana.vcxproj.filters index 418bbf46..d2c700e8 100644 --- a/build/vc2013/nana.vcxproj.filters +++ b/build/vc2013/nana.vcxproj.filters @@ -25,9 +25,6 @@ {e2569be2-9e68-477d-8b59-e248595de6c7} - - {52ed7f8e-fa48-495e-af1f-4df013205a35} - {87d14798-9015-4162-b9ab-72c741cff063} @@ -37,9 +34,6 @@ {85c9c1bb-d87b-4481-bf3c-7425f680a12d} - - {8058b530-86ec-4d72-890d-345aa30db056} - {87b124cb-408d-460b-a81b-8a788bbae0d9} @@ -114,9 +108,6 @@ Source Files\nana\audio - - Source Files\nana\detail\win32 - Source Files\nana\filesystem @@ -126,9 +117,6 @@ Source Files\nana\filesystem - - Source Files\nana\gui\detail\win32 - Source Files\nana\gui\detail @@ -339,6 +327,12 @@ Source Files\nana\gui\widgets + + Source Files\nana\detail + + + Source Files\nana\gui\detail + diff --git a/build/vc2015/nana.sln b/build/vc2015/nana.sln index 6de06997..6aec89c0 100644 --- a/build/vc2015/nana.sln +++ b/build/vc2015/nana.sln @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 14 VisualStudioVersion = 14.0.23107.0 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "nana", "nana.vcxproj", "{98091380-2EC4-44B4-82A2-F0A6393BA908}" +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "nana", "nana.vcxproj", "{25B21068-491B-4A9F-B99F-6C27BF31BAAD}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -13,14 +13,14 @@ Global Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {98091380-2EC4-44B4-82A2-F0A6393BA908}.Debug|x64.ActiveCfg = Debug|x64 - {98091380-2EC4-44B4-82A2-F0A6393BA908}.Debug|x64.Build.0 = Debug|x64 - {98091380-2EC4-44B4-82A2-F0A6393BA908}.Debug|x86.ActiveCfg = Debug|Win32 - {98091380-2EC4-44B4-82A2-F0A6393BA908}.Debug|x86.Build.0 = Debug|Win32 - {98091380-2EC4-44B4-82A2-F0A6393BA908}.Release|x64.ActiveCfg = Release|x64 - {98091380-2EC4-44B4-82A2-F0A6393BA908}.Release|x64.Build.0 = Release|x64 - {98091380-2EC4-44B4-82A2-F0A6393BA908}.Release|x86.ActiveCfg = Release|Win32 - {98091380-2EC4-44B4-82A2-F0A6393BA908}.Release|x86.Build.0 = Release|Win32 + {25B21068-491B-4A9F-B99F-6C27BF31BAAD}.Debug|x64.ActiveCfg = Debug|x64 + {25B21068-491B-4A9F-B99F-6C27BF31BAAD}.Debug|x64.Build.0 = Debug|x64 + {25B21068-491B-4A9F-B99F-6C27BF31BAAD}.Debug|x86.ActiveCfg = Debug|Win32 + {25B21068-491B-4A9F-B99F-6C27BF31BAAD}.Debug|x86.Build.0 = Debug|Win32 + {25B21068-491B-4A9F-B99F-6C27BF31BAAD}.Release|x64.ActiveCfg = Release|x64 + {25B21068-491B-4A9F-B99F-6C27BF31BAAD}.Release|x64.Build.0 = Release|x64 + {25B21068-491B-4A9F-B99F-6C27BF31BAAD}.Release|x86.ActiveCfg = Release|Win32 + {25B21068-491B-4A9F-B99F-6C27BF31BAAD}.Release|x86.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/build/vc2015/nana.vcxproj b/build/vc2015/nana.vcxproj index 0f5dd3d3..89ceaaa3 100644 --- a/build/vc2015/nana.vcxproj +++ b/build/vc2015/nana.vcxproj @@ -181,7 +181,7 @@ - + @@ -189,12 +189,12 @@ + - diff --git a/build/vc2015/nana.vcxproj.filters b/build/vc2015/nana.vcxproj.filters index fab8ae53..8130c2bc 100644 --- a/build/vc2015/nana.vcxproj.filters +++ b/build/vc2015/nana.vcxproj.filters @@ -37,18 +37,12 @@ {b3023f5e-2759-409d-b6e8-5ef2fe6601ae} - - {2ce139f3-ef8e-48b7-a82a-68003eac75da} - {b9f9a5a8-fd1a-4b99-b530-d8a4c45e62ec} {4b04c197-4a1e-41f9-bfa3-d82c18bcad51} - - {cd6e7f3f-fe5b-44c6-ae8d-15554f926055} - {60f588f2-bdb9-4b1d-9e23-40a73f327283} @@ -93,9 +87,6 @@ Source Files\audio - - Source Files\detail\win32 - Source Files\filesystem @@ -132,9 +123,6 @@ Source Files\gui\detail - - Source Files\gui\detail\win32 - Source Files\gui\widgets\skeletons @@ -294,5 +282,11 @@ Source Files\paint + + Source Files\detail + + + Source Files\gui\detail + \ No newline at end of file diff --git a/include/nana/config.hpp b/include/nana/config.hpp index 8f519e9b..d9ac719b 100644 --- a/include/nana/config.hpp +++ b/include/nana/config.hpp @@ -18,7 +18,7 @@ // Windows: #if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) - #define NANA_WINDOWS 1 + #define NANA_WINDOWS // MINGW ... #if defined(__MINGW32__) || defined(__MINGW64__) || defined(MINGW) @@ -31,24 +31,23 @@ // MacOS: who define APPLE ?? //#define APPLE #elif defined(APPLE) - #define NANA_MACOS 1 - #define NANA_X11 1 + #define NANA_MACOS + #define NANA_X11 // how to add this: include_directories(/opt/X11/include/) // end MacOS // Linux: (not sure about __GNU__ ??) #elif (defined(linux) || defined(__linux) || defined(__linux__) || defined(__GNU__) || defined(__GLIBC__)) && !defined(_CRAYC) - #define NANA_LINUX 1 - #define NANA_X11 1 + #define NANA_LINUX + #define NANA_X11 // end Linux - - #else # static_assert(false, "Only Windows and Unix are supported now (Mac OS is experimental)"); #endif // Select platform #if defined(NANA_LINUX) || defined(NANA_MACOS) - #undef NANA_WINDOWS + #define NANA_POSIX + #undef NANA_WINDOWS #endif // End Select platform ...... diff --git a/include/nana/filesystem/file_iterator.hpp b/include/nana/filesystem/file_iterator.hpp index b884638f..94f37001 100644 --- a/include/nana/filesystem/file_iterator.hpp +++ b/include/nana/filesystem/file_iterator.hpp @@ -38,7 +38,7 @@ namespace filesystem fileinfo(); #ifdef NANA_WINDOWS fileinfo(const WIN32_FIND_DATA& wfd); -#elif NANA_LINUX or NANA_MACOS +#elif defined(NANA_POSIX) fileinfo(const nana::string& filename, const struct stat &); #endif nana::string name; diff --git a/source/detail/linux_X11/platform_spec.cpp b/source/detail/platform_spec_posix.cpp similarity index 99% rename from source/detail/linux_X11/platform_spec.cpp rename to source/detail/platform_spec_posix.cpp index 43fde207..33d81a75 100644 --- a/source/detail/linux_X11/platform_spec.cpp +++ b/source/detail/platform_spec_posix.cpp @@ -15,6 +15,7 @@ */ #include +#if defined(NANA_POSIX) && defined(NANA_X11) #include #include #include @@ -28,7 +29,7 @@ #include #include -#include "msg_dispatcher.hpp" +#include "x11/msg_dispatcher.hpp" namespace nana { @@ -1412,3 +1413,4 @@ namespace detail } }//end namespace detail }//end namespace nana +#endif //NANA_POSIX && NANA_X11 diff --git a/source/detail/platform_spec_selector.cpp b/source/detail/platform_spec_selector.cpp deleted file mode 100644 index b09fbfe4..00000000 --- a/source/detail/platform_spec_selector.cpp +++ /dev/null @@ -1,22 +0,0 @@ -/* - * Platform Specification Selector - * Nana C++ Library(http://www.nanapro.org) - * Copyright(C) 2003-2014 Jinhao(cnjinhao@hotmail.com) - * - * Distributed under the Nana Software License, Version 1.0. - * (See accompanying file LICENSE_1_0.txt or copy at - * http://nanapro.org/LICENSE_1_0.txt) - * - * @file: nana/detail/platform_spec_selector.cpp - * - * This file is used to support the Nana project of some cross-platform IDE, - * - */ - -#include - -#if defined(NANA_WINDOWS) - #include "win32/platform_spec.cpp" -#elif defined(NANA_LINUX) || defined(NANA_MACOS) - #include "linux_X11/platform_spec.cpp" -#endif \ No newline at end of file diff --git a/source/detail/win32/platform_spec.cpp b/source/detail/platform_spec_windows.cpp similarity index 99% rename from source/detail/win32/platform_spec.cpp rename to source/detail/platform_spec_windows.cpp index f7ac9917..0323dfc1 100644 --- a/source/detail/win32/platform_spec.cpp +++ b/source/detail/platform_spec_windows.cpp @@ -13,6 +13,9 @@ */ #include + +#if defined(NANA_WINDOWS) + #include #include @@ -290,3 +293,5 @@ namespace detail } }//end namespace detail }//end namespace nana + +#endif //NANA_WINDOWS diff --git a/source/detail/linux_X11/msg_dispatcher.hpp b/source/detail/x11/msg_dispatcher.hpp similarity index 100% rename from source/detail/linux_X11/msg_dispatcher.hpp rename to source/detail/x11/msg_dispatcher.hpp diff --git a/source/gui/detail/linux_X11/bedrock.cpp b/source/gui/detail/bedrock_posix.cpp similarity index 99% rename from source/gui/detail/linux_X11/bedrock.cpp rename to source/gui/detail/bedrock_posix.cpp index 5a69ab34..ad8a8508 100644 --- a/source/gui/detail/linux_X11/bedrock.cpp +++ b/source/gui/detail/bedrock_posix.cpp @@ -11,6 +11,7 @@ */ #include +#if defined(NANA_POSIX) && defined(NANA_X11) #include #include #include @@ -1399,3 +1400,4 @@ namespace detail } }//end namespace detail }//end namespace nana +#endif //NANA_POSIX && NANA_X11 \ No newline at end of file diff --git a/source/gui/detail/bedrock_selector.cpp b/source/gui/detail/bedrock_selector.cpp deleted file mode 100644 index 986d3538..00000000 --- a/source/gui/detail/bedrock_selector.cpp +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Bedrock Selector - * Nana C++ Library(http://www.nanapro.org) - * Copyright(C) 2003-2015 Jinhao(cnjinhao@hotmail.com) - * - * Distributed under the Nana Software License, Version 1.0. - * (See accompanying file LICENSE_1_0.txt or copy at - * http://nanapro.sourceforge.net/LICENSE_1_0.txt) - * - * @file: nana/gui/detail/bedrock_selector.cpp - * - * This file is used to support the Nana project of some cross-platform IDE, - * - */ - -#include - -#if defined(NANA_WINDOWS) - #include "win32/bedrock.cpp" -#elif defined(NANA_LINUX) || defined(NANA_MACOS) - #include "linux_X11/bedrock.cpp" -#endif - diff --git a/source/gui/detail/win32/bedrock.cpp b/source/gui/detail/bedrock_windows.cpp similarity index 99% rename from source/gui/detail/win32/bedrock.cpp rename to source/gui/detail/bedrock_windows.cpp index 7cdd1b5f..eb48b9e9 100644 --- a/source/gui/detail/win32/bedrock.cpp +++ b/source/gui/detail/bedrock_windows.cpp @@ -12,6 +12,7 @@ */ #include +#if defined(NANA_WINDOWS) #include #include #include @@ -1894,3 +1895,4 @@ namespace detail } }//end namespace detail }//end namespace nana +#endif //NANA_WINDOWS From 8a243ad0d75978345edfd8b77b971e89e242d133 Mon Sep 17 00:00:00 2001 From: Jinhao Date: Mon, 7 Dec 2015 02:52:30 +0800 Subject: [PATCH 3/4] add detection of clang --- include/nana/config.hpp | 10 ++++-- include/nana/gui/widgets/tabbar.hpp | 51 +++++++++++--------------- source/gui/widgets/tabbar.cpp | 56 ++++++++++++++--------------- 3 files changed, 56 insertions(+), 61 deletions(-) diff --git a/include/nana/config.hpp b/include/nana/config.hpp index d9ac719b..acef5d8c 100644 --- a/include/nana/config.hpp +++ b/include/nana/config.hpp @@ -69,8 +69,13 @@ #endif // _MSC_VER == 1900 #endif // _MSVC -//GCC -#if defined(__GNUC__) +#if defined(__clang__) + #if defined(__GLIBCPP__) || defined(__GLIBCXX__) + // is a known issue on libstdc++, it works on libc++ + #define STD_CODECVT_NOT_SUPPORTED + #endif + +#elif defined(__GNUC__) //GCC #if defined(__GLIBCPP__) || defined(__GLIBCXX__) // is a known issue on libstdc++, it works on libc++ #define STD_CODECVT_NOT_SUPPORTED @@ -99,6 +104,7 @@ #endif + // End compilers ... diff --git a/include/nana/gui/widgets/tabbar.hpp b/include/nana/gui/widgets/tabbar.hpp index 2b7193cf..f0bcb3b2 100644 --- a/include/nana/gui/widgets/tabbar.hpp +++ b/include/nana/gui/widgets/tabbar.hpp @@ -228,18 +228,6 @@ namespace nana this->create(wd, rectangle(), visible); } - tabbar(window wd, const nana::char_t* text, bool visible) - : tabbar(wd, ::nana::string(text), visible) - { - } - - tabbar(window wd, const nana::string& text, bool visible) - : tabbar() - { - this->create(wd, rectangle(), visible); - this->caption(text); - } - tabbar(window wd, const rectangle& r = rectangle(), bool visible = true) : tabbar() { @@ -256,7 +244,7 @@ namespace nana return static_cast(this->get_drawer_trigger().at_no_bound_check(pos)); } - void activate(std::size_t pos) /// Activates a tab specified by i. + void activated(std::size_t pos) /// Activates a tab specified by pos. { this->get_drawer_trigger().activate(pos); } @@ -266,9 +254,9 @@ namespace nana return this->get_drawer_trigger().activated(); } - value_type & at(std::size_t i) const /// Returns i'th element + value_type & at(std::size_t pos) const /// Returns pos'th element { - return static_cast(this->get_drawer_trigger().at(i)); + return static_cast(this->get_drawer_trigger().at(pos)); } void close_fly(bool fly) /// Draw or not a close button in each tab. @@ -277,12 +265,12 @@ namespace nana API::refresh_window(this->handle()); } - pat::cloneable& ext_renderer() const + pat::cloneable& renderer() const { return this->get_drawer_trigger().ext_renderer(); } - void ext_renderer(const pat::cloneable& ir) + void renderer(const pat::cloneable& ir) { this->get_drawer_trigger().ext_renderer(ir); } @@ -292,14 +280,14 @@ namespace nana return this->get_drawer_trigger().length(); } - void append(const std::string& text, window attach_wd, value_type value = {}) + tabbar& append(std::string text, window attach_wd, value_type value = {}) { - this->append(static_cast(nana::charset(text, nana::unicode::utf8)), attach_wd); + return this->append(static_cast(nana::charset(text, nana::unicode::utf8)), attach_wd); } - void append(const std::wstring& text, window attach_wd, value_type value = {}) + tabbar& append(std::wstring text, window attach_wd, value_type value = {}) { - this->get_drawer_trigger().insert(::nana::npos, std::wstring(text), std::move(value)); + this->get_drawer_trigger().insert(::nana::npos, std::move(text), std::move(value)); if (attach_wd) { auto pos = this->get_drawer_trigger().length(); @@ -307,6 +295,7 @@ namespace nana } API::update_window(*this); + return *this; } void push_back(nana::string text) /// Append a new item. @@ -315,17 +304,17 @@ namespace nana API::update_window(*this); } - void insert(std::size_t pos, const std::string& text, const value_type& value = {}) + void insert(std::size_t pos, std::string text, value_type value = {}) { - this->insert(pos, static_cast(nana::charset(text, nana::unicode::utf8)), value); + return this->insert(pos, static_cast(nana::charset(text, nana::unicode::utf8)), std::move(value)); } - void insert(std::size_t pos, const std::wstring& text, const value_type& value = {}) + void insert(std::size_t pos, std::wstring text, value_type value = {}) { if (pos > length()) throw std::out_of_range("tabbar::insert invalid position"); - this->get_drawer_trigger().insert(pos, std::wstring(text), value_type(value)); + this->get_drawer_trigger().insert(pos, std::move(text), std::move(value)); API::update_window(*this); } @@ -345,19 +334,19 @@ namespace nana this->get_drawer_trigger().erase(pos); } - void tab_bgcolor(std::size_t i, const ::nana::color& clr) + void tab_bgcolor(std::size_t pos, const ::nana::color& clr) { - this->get_drawer_trigger().tab_color(i, true, clr); + this->get_drawer_trigger().tab_color(pos, true, clr); } - void tab_fgcolor(std::size_t i, const ::nana::color& clr) + void tab_fgcolor(std::size_t pos, const ::nana::color& clr) { - this->get_drawer_trigger().tab_color(i, false, clr); + this->get_drawer_trigger().tab_color(pos, false, clr); } - void tab_image(std::size_t i, const nana::paint::image& img) + void tab_image(std::size_t pos, const nana::paint::image& img) { - this->get_drawer_trigger().tab_image(i, img); + this->get_drawer_trigger().tab_image(pos, img); } /// Sets buttons of the tabbar's toolbox, refer to notes for more details. template diff --git a/source/gui/widgets/tabbar.cpp b/source/gui/widgets/tabbar.cpp index d2a8cb2a..19d18391 100644 --- a/source/gui/widgets/tabbar.cpp +++ b/source/gui/widgets/tabbar.cpp @@ -605,60 +605,60 @@ namespace nana void attach(std::size_t pos, window wd) { - if(pos < list_.size()) - { - iterator_at(pos)->relative = wd; - API::show_window(wd, basis_.active == pos); - } + if (pos >= list_.size()) + throw std::out_of_range("tabbar: invalid position"); + + API::show_window(wd, basis_.active == pos); } bool tab_color(std::size_t pos, bool is_bgcolor, const ::nana::color& clr) { - if(pos < list_.size()) + if (pos >= list_.size()) + throw std::out_of_range("tabbar: invalid position"); + + auto & m = *iterator_at(pos); + auto & m_clr = (is_bgcolor ? m.bgcolor : m.fgcolor); + if (m_clr != clr) { - auto & m = *iterator_at(pos); - auto & m_clr = (is_bgcolor ? m.bgcolor : m.fgcolor); - if (m_clr != clr) - { - m_clr = clr; - return true; - } + m_clr = clr; + return true; } return false; } - bool tab_image(std::size_t pos, const nana::paint::image& img) + void tab_image(std::size_t pos, const nana::paint::image& img) { - if(pos > list_.size()) return false; + if (pos >= list_.size()) + throw std::out_of_range("tabbar: invalid position"); auto & m = *iterator_at(pos); if(img) m.img = img; else m.img.close(); - return true; } bool text(std::size_t pos, const nana::string& str) { - if(pos < list_.size()) + if (pos >= list_.size()) + throw std::out_of_range("tabbar: invalid position"); + + auto & m = *iterator_at(pos); + if(m.text != str) { - auto & m = *iterator_at(pos); - if(m.text != str) - { - m.text = str; - return true; - } + m.text = str; + return true; } + return false; } nana::string text(std::size_t pos) const { - if(pos < list_.size()) - return iterator_at(pos)->text; + if (pos >= list_.size()) + throw std::out_of_range("tabbar: invalid position"); - return nana::string(); + return iterator_at(pos)->text; } bool toolbox_answer(const arg_mouse& arg) @@ -1195,8 +1195,8 @@ namespace nana void trigger::tab_image(std::size_t i, const nana::paint::image& img) { - if(layouter_->tab_image(i, img)) - API::refresh_window(layouter_->widget_handle()); + layouter_->tab_image(i, img); + API::refresh_window(layouter_->widget_handle()); } void trigger::text(std::size_t i, const nana::string& str) From e189d6559ea3c6b97fde85ec373c5a9bf6508ac6 Mon Sep 17 00:00:00 2001 From: Jinhao Date: Tue, 8 Dec 2015 00:42:07 +0800 Subject: [PATCH 4/4] remove warning for preprocessor --- include/nana/config.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/nana/config.hpp b/include/nana/config.hpp index acef5d8c..e97c70f6 100644 --- a/include/nana/config.hpp +++ b/include/nana/config.hpp @@ -117,7 +117,7 @@ //#define NANA_ENABLE_PNG //! //#define USE_LIBPNG_FROM_OS // Un-Comment it to use libpng from operating system. #if defined(NANA_ENABLE_PNG) - #if not defined(USE_LIBPNG_FROM_OS) + #if !defined(USE_LIBPNG_FROM_OS) #define NANA_LIBPNG #endif #endif @@ -129,7 +129,7 @@ //#define NANA_ENABLE_JPEG //! //#define USE_LIBJPEG_FROM_OS // Un-Comment it to use libjpeg from operating system. #if defined(NANA_ENABLE_JPEG) - #if not defined(USE_LIBJPEG_FROM_OS) + #if !defined(USE_LIBJPEG_FROM_OS) #define NANA_LIBJPEG #endif #endif