From 01bd43f960d4deeef7bee5d6cd1fa6d4f942f0ec Mon Sep 17 00:00:00 2001 From: Jinhao Date: Fri, 28 Jun 2019 06:32:34 +0800 Subject: [PATCH] refactoring --- include/nana/deploy.hpp | 2 -- include/nana/gui/notifier.hpp | 4 --- source/detail/mswin/platform_spec.hpp | 11 +++++- source/detail/platform_spec_posix.cpp | 48 ++++++++++++------------- source/detail/platform_spec_windows.cpp | 16 ++++++--- source/detail/posix/platform_spec.hpp | 35 ++++-------------- source/filesystem/filesystem.cpp | 36 ------------------- source/gui/detail/bedrock_posix.cpp | 7 ---- source/paint/graphics.cpp | 19 +++++----- 9 files changed, 62 insertions(+), 116 deletions(-) diff --git a/include/nana/deploy.hpp b/include/nana/deploy.hpp index 168358c5..e3091d23 100644 --- a/include/nana/deploy.hpp +++ b/include/nana/deploy.hpp @@ -118,7 +118,5 @@ namespace nana } } -#define NANA_RGB(a) (((DWORD)(a) & 0xFF)<<16) | ((DWORD)(a) & 0xFF00) | (((DWORD)(a) & 0xFF0000) >> 16 ) - #include #endif //NANA_DEPLOY_HPP diff --git a/include/nana/gui/notifier.hpp b/include/nana/gui/notifier.hpp index 31cf28f1..d0d87efa 100644 --- a/include/nana/gui/notifier.hpp +++ b/include/nana/gui/notifier.hpp @@ -59,11 +59,7 @@ namespace nana void text(const ::std::string&); void icon(const ::std::string& icon_file); void insert_icon(const ::std::string& icon_file); -#if 0 //deprecated - void period(unsigned millisecond); -#else void period(std::chrono::milliseconds time); -#endif detail::notifier_events& events(); window handle() const; private: diff --git a/source/detail/mswin/platform_spec.hpp b/source/detail/mswin/platform_spec.hpp index 1a44ce8b..5c0ad5ab 100644 --- a/source/detail/mswin/platform_spec.hpp +++ b/source/detail/mswin/platform_spec.hpp @@ -1,7 +1,7 @@ /** * Platform Specification Implementation * Nana C++ Library(http://www.nanapro.org) - * Copyright(C) 2003-2018 Jinhao(cnjinhao@hotmail.com) + * Copyright(C) 2003-2019 Jinhao(cnjinhao@hotmail.com) * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at @@ -96,19 +96,28 @@ namespace detail unsigned whitespace_pixels; }string; + unsigned fgcolor_rgb{ 0xFFFFFFFF }; + unsigned bgcolor_rgb{ 0xFFFFFFFF }; + unsigned fgcolor_native{ 0xFFFFFFFF }; //Windows RGB format: 0xBBGGRR + unsigned bgcolor_native{ 0xFFFFFFFF }; //Windows RGB format + drawable_impl_type(const drawable_impl_type&) = delete; drawable_impl_type& operator=(const drawable_impl_type&) = delete; drawable_impl_type(); ~drawable_impl_type(); +#if 0 //deprecated unsigned get_color() const; unsigned get_text_color() const; +#endif void set_color(const ::nana::color&); void set_text_color(const ::nana::color&); +#if 0 //deprecated private: unsigned color_{ 0xffffffff }; unsigned text_color_{0xffffffff}; +#endif }; class platform_spec diff --git a/source/detail/platform_spec_posix.cpp b/source/detail/platform_spec_posix.cpp index cad5b82e..5f74dc67 100644 --- a/source/detail/platform_spec_posix.cpp +++ b/source/detail/platform_spec_posix.cpp @@ -1,7 +1,7 @@ /* * Platform Specification Implementation * Nana C++ Library(http://www.nanapro.org) - * Copyright(C) 2003-2018 Jinhao(cnjinhao@hotmail.com) + * Copyright(C) 2003-2019 Jinhao(cnjinhao@hotmail.com) * * Distributed under the Nana Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at @@ -339,24 +339,9 @@ namespace detail string.tab_length = 4; string.tab_pixels = 0; string.whitespace_pixels = 0; - -#if 0 //deprecated -#if defined(NANA_USE_XFT) - conv_.handle = ::iconv_open("UTF-8", NANA_UNICODE); - conv_.code = NANA_UNICODE; -#endif -#endif } - drawable_impl_type::~drawable_impl_type() - { #if 0 //deprecated -#if defined(NANA_USE_XFT) - ::iconv_close(conv_.handle); -#endif -#endif - } - unsigned drawable_impl_type::get_color() const { return color_; @@ -366,27 +351,28 @@ namespace detail { return text_color_; } +#endif void drawable_impl_type::set_color(const ::nana::color& clr) { - color_ = (clr.px_color().value & 0xFFFFFF); + bgcolor_rgb = (clr.px_color().value & 0xFFFFFF); } void drawable_impl_type::set_text_color(const ::nana::color& clr) { - text_color_ = (clr.px_color().value & 0xFFFFFF); + fgcolor_rgb = (clr.px_color().value & 0xFFFFFF); update_text_color(); } void drawable_impl_type::update_color() { - if (color_ != current_color_) + if (bgcolor_rgb != current_color_) { auto & spec = nana::detail::platform_spec::instance(); platform_scope_guard lock; - current_color_ = color_; - auto col = color_; + current_color_ = bgcolor_rgb; + auto col = bgcolor_rgb; switch (spec.screen_depth()) { case 16: @@ -397,18 +383,32 @@ namespace detail } ::XSetForeground(spec.open_display(), context, col); ::XSetBackground(spec.open_display(), context, col); + +#if defined(NANA_USE_XFT) + //xft_fgcolor also needs to be assigned. + //assumes the xft_fgcolor is not assigned in update_color. There is a situation that causes a bug. + // + //update_text_color ( if fgcolor_rgb = A, then current_color = A and xft_fgcolor = A) + //update_color (if bgcolor_rgb = B, then current_color = B and xft_fgcolor is still A) + //update_text_color ( if fgcolor_rgb = B, then current_color = B, xft_fgcolor is still A) + + xft_fgcolor.color.red = ((0xFF0000 & col) >> 16) * 0x101; + xft_fgcolor.color.green = ((0xFF00 & col) >> 8) * 0x101; + xft_fgcolor.color.blue = (0xFF & col) * 0x101; + xft_fgcolor.color.alpha = 0xFFFF; +#endif } } void drawable_impl_type::update_text_color() { - if (text_color_ != current_color_) + if (fgcolor_rgb != current_color_) { auto & spec = nana::detail::platform_spec::instance(); platform_scope_guard lock; - current_color_ = text_color_; - auto col = text_color_; + current_color_ = fgcolor_rgb; + auto col = fgcolor_rgb; switch (spec.screen_depth()) { case 16: diff --git a/source/detail/platform_spec_windows.cpp b/source/detail/platform_spec_windows.cpp index 812c2ed0..f659b054 100644 --- a/source/detail/platform_spec_windows.cpp +++ b/source/detail/platform_spec_windows.cpp @@ -1,7 +1,7 @@ /** * Platform Specification Implementation * Nana C++ Library(http://www.nanapro.org) - * Copyright(C) 2003-2018 Jinhao(cnjinhao@hotmail.com) + * Copyright(C) 2003-2019 Jinhao(cnjinhao@hotmail.com) * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at @@ -42,6 +42,7 @@ namespace detail ::DeleteObject(pixmap); } +#if 0 //deprecated unsigned drawable_impl_type::get_color() const { return color_; @@ -51,19 +52,24 @@ namespace detail { return text_color_; } +#endif + +#define NANA_WINDOWS_RGB(a) (((DWORD)(a) & 0xFF)<<16) | ((DWORD)(a) & 0xFF00) | (((DWORD)(a) & 0xFF0000) >> 16 ) void drawable_impl_type::set_color(const ::nana::color& clr) { - color_ = (clr.px_color().value & 0xFFFFFF); + bgcolor_rgb = (clr.px_color().value & 0xFFFFFF); + bgcolor_native = NANA_WINDOWS_RGB(bgcolor_rgb); } void drawable_impl_type::set_text_color(const ::nana::color& clr) { auto rgb = (clr.px_color().value & 0xFFFFFF); - if (text_color_ != rgb) + if (fgcolor_rgb != rgb) { - ::SetTextColor(context, NANA_RGB(rgb)); - text_color_ = rgb; + fgcolor_rgb = rgb; + fgcolor_native = NANA_WINDOWS_RGB(rgb); + ::SetTextColor(context, fgcolor_native); } } diff --git a/source/detail/posix/platform_spec.hpp b/source/detail/posix/platform_spec.hpp index 9c21625c..57a61d1e 100644 --- a/source/detail/posix/platform_spec.hpp +++ b/source/detail/posix/platform_spec.hpp @@ -1,7 +1,7 @@ /* * Platform Specification Implementation * Nana C++ Library(http://www.nanapro.org) - * Copyright(C) 2003-2018 Jinhao(cnjinhao@hotmail.com) + * Copyright(C) 2003-2019 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,6 @@ #if defined(NANA_USE_XFT) #include -// #include //deprecated #include #endif @@ -62,21 +61,6 @@ namespace detail private: std::ifstream ifs_; }; - -#if 0 //deprecated - class charset_conv - { - charset_conv(const charset_conv&) = delete; - charset_conv& operator=(const charset_conv*) = delete; - public: - charset_conv(const char* tocode, const char* fromcode); - ~charset_conv(); - std::string charset(const std::string& str) const; - std::string charset(const char * buf, std::size_t len) const; - private: - iconv_t handle_; - }; -#endif #endif struct drawable_impl_type @@ -97,16 +81,19 @@ namespace detail unsigned whitespace_pixels; }string; + unsigned fgcolor_rgb{ 0xFFFFFFFF }; + unsigned bgcolor_rgb{ 0xFFFFFFFF }; + #if defined(NANA_USE_XFT) XftDraw * xftdraw{nullptr}; XftColor xft_fgcolor; - const std::string charset(const std::wstring& str, const std::string& strcode); #endif drawable_impl_type(); - ~drawable_impl_type(); +#if 0 //deprecated unsigned get_color() const; unsigned get_text_color() const; +#endif void set_color(const ::nana::color&); void set_text_color(const ::nana::color&); @@ -117,17 +104,9 @@ namespace detail drawable_impl_type& operator=(const drawable_impl_type&) = delete; unsigned current_color_{ 0xFFFFFF }; +#if 0 //deprecated unsigned color_{ 0xFFFFFFFF }; unsigned text_color_{ 0xFFFFFFFF }; - -#if 0 //deprecated -#if defined(NANA_USE_XFT) - struct conv_tag - { - iconv_t handle; - std::string code; - }conv_; -#endif #endif }; diff --git a/source/filesystem/filesystem.cpp b/source/filesystem/filesystem.cpp index 8be0cce9..9180f084 100644 --- a/source/filesystem/filesystem.cpp +++ b/source/filesystem/filesystem.cpp @@ -110,42 +110,6 @@ namespace nana return tm.str(); } return {}; - -/* - // Deprecated - //Windows stores file times using the FILETIME structure, which is a 64 bit value of 100ns intervals from January 1, 1601. - //What's worse is that this 1601 date is fairly common to see given that it's the all zeroes value, and it is far before the - //earliest date representable with time_t.std::filesystem can't change the reality of the underlying platform. - - - try { -#if NANA_USING_BOOST_FILESYSTEM - // The return type of boost::filesystem::last_write_time isn't - // the same as in nana and std implementations of this function - auto ftime = std::chrono::system_clock::from_time_t(fs::last_write_time(path)); -#else - auto ftime = fs::last_write_time(path); -#endif - - // crash: VS2015 will not read the time for some files (for example: C:/hiberfil.sys) - // and will return file_time_type(-1) without throwing - // https://msdn.microsoft.com/en-us/library/dn823784.aspx - - if (ftime == ((fs::file_time_type::min)())) return{}; - - //A workaround for VC2013 - using time_point = decltype(ftime); - auto cftime = time_point::clock::to_time_t(ftime); - - std::stringstream tm; - tm << std::put_time(std::localtime(&cftime), "%Y-%m-%d, %H:%M:%S"); - return tm.str(); - } - catch (...) { - return{}; - } -#endif -*/ } bool modified_file_time(const fs::path& p, struct tm& t) diff --git a/source/gui/detail/bedrock_posix.cpp b/source/gui/detail/bedrock_posix.cpp index 6ad96318..9839ac6a 100644 --- a/source/gui/detail/bedrock_posix.cpp +++ b/source/gui/detail/bedrock_posix.cpp @@ -512,16 +512,9 @@ namespace detail auto const native_window = rruntime->window->root; -#if 0 //deprecated - nana::detail::charset_conv charset(NANA_UNICODE, "UTF-8"); - const std::string& str = charset.charset(std::string(keybuf, keybuf + keybuf_len)); - auto const charbuf = reinterpret_cast(str.c_str()); - auto const len = str.size() / sizeof(wchar_t); -#else auto wstr = nana::to_wstring(std::string{keybuf, keybuf + keybuf_len}); auto const charbuf = wstr.c_str(); auto const len = wstr.length(); -#endif for(std::size_t i = 0; i < len; ++i) { diff --git a/source/paint/graphics.cpp b/source/paint/graphics.cpp index 9a89ba03..c3c4b97e 100644 --- a/source/paint/graphics.cpp +++ b/source/paint/graphics.cpp @@ -1108,7 +1108,7 @@ namespace paint ::nana::color graphics::palette(bool for_text) const { if (impl_->handle) - return static_cast(for_text ? impl_->handle->get_text_color() : impl_->handle->get_color()); + return static_cast(for_text ? impl_->handle->fgcolor_rgb : impl_->handle->bgcolor_rgb); return{}; } @@ -1140,7 +1140,7 @@ namespace paint if (impl_->handle) { #if defined(NANA_WINDOWS) - ::SetPixel(impl_->handle->context, x, y, NANA_RGB(impl_->handle->get_color())); + ::SetPixel(impl_->handle->context, x, y, impl_->handle->bgcolor_native); #elif defined(NANA_X11) Display* disp = nana::detail::platform_spec::instance().open_display(); impl_->handle->update_color(); @@ -1336,14 +1336,14 @@ namespace paint #if defined(NANA_WINDOWS) if (pos1 != pos2) { - auto prv_pen = ::SelectObject(impl_->handle->context, ::CreatePen(PS_SOLID, 1, NANA_RGB(impl_->handle->get_color()))); + auto prv_pen = ::SelectObject(impl_->handle->context, ::CreatePen(PS_SOLID, 1, impl_->handle->bgcolor_native)); ::MoveToEx(impl_->handle->context, pos1.x, pos1.y, 0); ::LineTo(impl_->handle->context, pos2.x, pos2.y); ::DeleteObject(::SelectObject(impl_->handle->context, prv_pen)); } - ::SetPixel(impl_->handle->context, pos2.x, pos2.y, NANA_RGB(impl_->handle->get_color())); + ::SetPixel(impl_->handle->context, pos2.x, pos2.y, impl_->handle->bgcolor_native); #elif defined(NANA_X11) Display* disp = nana::detail::platform_spec::instance().open_display(); impl_->handle->update_color(); @@ -1369,7 +1369,7 @@ namespace paint { if (!impl_->handle) return; #if defined(NANA_WINDOWS) - auto prv_pen = ::SelectObject(impl_->handle->context, ::CreatePen(PS_SOLID, 1, NANA_RGB(impl_->handle->get_color()))); + auto prv_pen = ::SelectObject(impl_->handle->context, ::CreatePen(PS_SOLID, 1, impl_->handle->bgcolor_native)); ::LineTo(impl_->handle->context, pos.x, pos.y); @@ -1402,7 +1402,7 @@ namespace paint { #if defined(NANA_WINDOWS) - auto brush = ::CreateSolidBrush(NANA_RGB(impl_->handle->get_color())); + auto brush = ::CreateSolidBrush(impl_->handle->bgcolor_native); ::RECT native_r = { r.x, r.y, r.right(), r.bottom()}; @@ -1527,6 +1527,7 @@ namespace paint if (impl_->changed == false) impl_->changed = true; } +#define NANA_WINDOWS_RGB(a) (((DWORD)(a) & 0xFF)<<16) | ((DWORD)(a) & 0xFF00) | (((DWORD)(a) & 0xFF0000) >> 16 ) void graphics::round_rectangle(const ::nana::rectangle& r, unsigned radius_x, unsigned radius_y, const color& clr, bool solid, const color& solid_clr) { if (impl_->handle) @@ -1536,8 +1537,8 @@ namespace paint if (solid) { - auto prv_pen = ::SelectObject(impl_->handle->context, ::CreatePen(PS_SOLID, 1, NANA_RGB(impl_->handle->get_color()))); - auto prv_brush = ::SelectObject(impl_->handle->context, ::CreateSolidBrush(NANA_RGB(solid_clr.px_color().value))); + auto prv_pen = ::SelectObject(impl_->handle->context, ::CreatePen(PS_SOLID, 1, impl_->handle->bgcolor_native)); + auto prv_brush = ::SelectObject(impl_->handle->context, ::CreateSolidBrush(NANA_WINDOWS_RGB(solid_clr.px_color().value))); ::RoundRect(impl_->handle->context, r.x, r.y, r.right(), r.bottom(), static_cast(radius_x * 2), static_cast(radius_y * 2)); @@ -1546,7 +1547,7 @@ namespace paint } else { - auto brush = ::CreateSolidBrush(NANA_RGB(impl_->handle->get_color())); + auto brush = ::CreateSolidBrush(impl_->handle->bgcolor_native); auto region = ::CreateRoundRectRgn(r.x, r.y, r.x + static_cast(r.width) + 1, r.y + static_cast(r.height) + 1, static_cast(radius_x + 1), static_cast(radius_y + 1));