diff --git a/include/nana/detail/win32/platform_spec.hpp b/include/nana/detail/win32/platform_spec.hpp index 39f21366..e8db5fff 100644 --- a/include/nana/detail/win32/platform_spec.hpp +++ b/include/nana/detail/win32/platform_spec.hpp @@ -172,6 +172,12 @@ namespace detail HMODULE ole32_; }; + struct window_icons + { + ::nana::paint::image sml_icon; + ::nana::paint::image big_icon; + }; + platform_spec(); const font_ptr_t& default_native_font() const; @@ -182,11 +188,11 @@ namespace detail static platform_spec& instance(); - void keep_window_icon(native_window_type, const nana::paint::image&); + void keep_window_icon(native_window_type, const paint::image&sml_icon, const paint::image& big_icon); void release_window_icon(native_window_type); private: font_ptr_t def_font_ptr_; - std::map iconbase_; + std::map iconbase_; }; }//end namespace detail diff --git a/include/nana/gui/detail/native_window_interface.hpp b/include/nana/gui/detail/native_window_interface.hpp index 66f6ac94..5db4a645 100644 --- a/include/nana/gui/detail/native_window_interface.hpp +++ b/include/nana/gui/detail/native_window_interface.hpp @@ -44,7 +44,6 @@ namespace detail #endif static void enable_dropfiles(native_window_type, bool); static void enable_window(native_window_type, bool); - static bool window_icon(native_window_type, const paint::image&); // (On Windows) The system displays the large icon in the ALT+TAB dialog box, and the small icon in the window caption. static bool window_icon(native_window_type, const paint::image& big_icon, const paint::image& small_icon); static void activate_owner(native_window_type); diff --git a/include/nana/gui/detail/window_manager.hpp b/include/nana/gui/detail/window_manager.hpp index 682c139c..ec91fe1f 100644 --- a/include/nana/gui/detail/window_manager.hpp +++ b/include/nana/gui/detail/window_manager.hpp @@ -106,10 +106,8 @@ namespace detail //@brief: Delete window handle, the handle type must be a root and a frame. void destroy_handle(core_window_t*); - void default_icon(const paint::image&); - void default_icon(const paint::image& big_icon, const paint::image& small_icon); - void icon(core_window_t*, const paint::image&); - void icon(core_window_t*, const paint::image& big_icon, const paint::image& small_icon); + void default_icon(const paint::image& small_icon, const paint::image& big_icon); + void icon(core_window_t*, const paint::image& small_icon, const paint::image& big_icon); //show //@brief: show or hide a window diff --git a/include/nana/gui/programming_interface.hpp b/include/nana/gui/programming_interface.hpp index 6f15f42c..7db38a0a 100644 --- a/include/nana/gui/programming_interface.hpp +++ b/include/nana/gui/programming_interface.hpp @@ -112,10 +112,8 @@ namespace API } } - void window_icon_default(const paint::image&); - void window_icon_default(const paint::image& big_icon, const paint::image& small_icon); - void window_icon(window, const paint::image&); - void window_icon(window, const paint::image& big_icon, const paint::image& small_icon); + void window_icon_default(const paint::image& small_icon, const paint::image& big_icon = {}); + void window_icon(window, const paint::image& small_icon, const paint::image& big_icon = {}); bool empty_window(window); ///< Determines whether a window is existing. bool is_window(window); ///< Determines whether a window is existing, equal to !empty_window. diff --git a/include/nana/gui/widgets/label.hpp b/include/nana/gui/widgets/label.hpp index bd7d31b4..3142beec 100644 --- a/include/nana/gui/widgets/label.hpp +++ b/include/nana/gui/widgets/label.hpp @@ -65,7 +65,7 @@ namespace nana label& format(bool); ///< Switches the format mode of the widget. label& add_format_listener(std::function); - void relate(widget& w); // as same as the "for" attribute of a label + void click_for(window associated_window); // as same as the "for" attribute of a label /// \briefReturn the size of the text. If *allowed_width_in_pixel* is not zero, returns a /// "corrected" size that changes lines to fit the text into the specified width diff --git a/include/nana/paint/detail/image_impl_interface.hpp b/include/nana/paint/detail/image_impl_interface.hpp index ecd2b6b1..6cd604fb 100644 --- a/include/nana/paint/detail/image_impl_interface.hpp +++ b/include/nana/paint/detail/image_impl_interface.hpp @@ -16,7 +16,7 @@ namespace nana{ namespace paint{ 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(void* buff, size_t sz) = 0; // reads image from memory + 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; virtual void close() = 0; diff --git a/include/nana/paint/image.hpp b/include/nana/paint/image.hpp index 2747eee7..b1c237bc 100644 --- a/include/nana/paint/image.hpp +++ b/include/nana/paint/image.hpp @@ -37,7 +37,9 @@ namespace paint image& operator=(const image& rhs); image& operator=(image&&); bool open(const nana::string& filename); - bool open_icon(void* buff, size_t sz); // opens a icon from memory + + /// Opens an icon from a specified buffer + bool open_icon(const void* data, std::size_t bytes); bool empty() const; operator unspecified_bool_t() const; void close(); diff --git a/source/detail/win32/platform_spec.cpp b/source/detail/win32/platform_spec.cpp index 18b85f01..cb064545 100644 --- a/source/detail/win32/platform_spec.cpp +++ b/source/detail/win32/platform_spec.cpp @@ -273,9 +273,11 @@ namespace detail return object; } - void platform_spec::keep_window_icon(native_window_type wd, const paint::image& img) + void platform_spec::keep_window_icon(native_window_type wd, const paint::image& sml_icon, const paint::image& big_icon) { - iconbase_[wd] = img; + auto & icons = iconbase_[wd]; + icons.sml_icon = sml_icon; + icons.big_icon = big_icon; } void platform_spec::release_window_icon(native_window_type wd) diff --git a/source/gui/detail/native_window_interface.cpp b/source/gui/detail/native_window_interface.cpp index fa21a0cd..d706b43d 100644 --- a/source/gui/detail/native_window_interface.cpp +++ b/source/gui/detail/native_window_interface.cpp @@ -509,20 +509,25 @@ namespace nana{ #endif } - bool native_interface::window_icon(native_window_type wd, const nana::paint::image& img) + bool native_interface::window_icon(native_window_type wd, const nana::paint::image& sml_icon, const ::nana::paint::image& big_icon) { #if defined(NANA_WINDOWS) - HICON ico = paint::image_accessor::icon(img); - if(ico) + HICON sml_handle = paint::image_accessor::icon(sml_icon); + HICON big_handle = paint::image_accessor::icon(big_icon); + if(sml_handle || big_handle) { - nana::detail::platform_spec::instance().keep_window_icon(wd, img); - ::SendMessage(reinterpret_cast(wd), WM_SETICON, ICON_BIG, reinterpret_cast(ico)); - ::SendMessage(reinterpret_cast(wd), WM_SETICON, ICON_SMALL, reinterpret_cast(ico)); + nana::detail::platform_spec::instance().keep_window_icon(wd, sml_icon, big_icon); + if (sml_handle) + ::SendMessage(reinterpret_cast(wd), WM_SETICON, ICON_SMALL, reinterpret_cast(sml_handle)); + + if (big_handle) + ::SendMessage(reinterpret_cast(wd), WM_SETICON, ICON_BIG, reinterpret_cast(big_handle)); return true; } #elif defined(NANA_X11) - if(wd && (false == img.empty())) + if(wd && (!sml_icon.empty() || !big_icon.empty())) { + auto & img = (sml_icon.empty() ? big_icon : sml_icon); const nana::paint::graphics & graph = restrict::spec.keep_window_icon(wd, img); XWMHints hints; @@ -537,7 +542,8 @@ namespace nana{ return false; } - bool native_interface::window_icon(native_window_type wd, const paint::image& big_icon, const paint::image& small_icon) + /* + bool native_interface::window_icon(native_window_type wd, const paint::image& big_icon, const paint::image& small_icon) //deprecated { #if defined(NANA_WINDOWS) HICON h_big_icon = paint::image_accessor::icon(big_icon); @@ -558,6 +564,7 @@ namespace nana{ #endif return false; } + */ diff --git a/source/gui/detail/win32/bedrock.cpp b/source/gui/detail/win32/bedrock.cpp index a0013ba1..9d98f2fe 100644 --- a/source/gui/detail/win32/bedrock.cpp +++ b/source/gui/detail/win32/bedrock.cpp @@ -1413,7 +1413,6 @@ namespace detail auto tstop_wd = brock.wd_manager.tabstop(msgwnd, is_forward); if (tstop_wd) { - root_runtime->condition.tabstop_focus_changed = true; brock.wd_manager.set_focus(tstop_wd, false); brock.wd_manager.do_lazy_refresh(msgwnd, false); brock.wd_manager.do_lazy_refresh(tstop_wd, true); diff --git a/source/gui/detail/window_manager.cpp b/source/gui/detail/window_manager.cpp index 89f1cdf8..0bc25362 100644 --- a/source/gui/detail/window_manager.cpp +++ b/source/gui/detail/window_manager.cpp @@ -243,7 +243,7 @@ namespace detail insert_frame(owner, wd); bedrock::inc_window(wd->thread_id); - this->icon(wd, impl_->default_icon_big, impl_->default_icon_small); + this->icon(wd, impl_->default_icon_small, impl_->default_icon_big); return wd; } return nullptr; @@ -390,32 +390,13 @@ namespace detail } } - void window_manager::default_icon(const paint::image& img) - { - impl_->default_icon_big = img; - impl_->default_icon_small = img; - } - - void window_manager::default_icon(const nana::paint::image& big, const nana::paint::image& small) + void window_manager::default_icon(const nana::paint::image& small, const nana::paint::image& big) { impl_->default_icon_big = big; impl_->default_icon_small = small; } - void window_manager::icon(core_window_t* wd, const paint::image& img) - { - if(false == img.empty()) - { - std::lock_guard lock(mutex_); - if (impl_->wd_register.available(wd)) - { - if(wd->other.category == category::root_tag::value) - native_interface::window_icon(wd->root, img); - } - } - } - - void window_manager::icon(core_window_t* wd, const paint::image& big_icon, const paint::image& small_icon) + void window_manager::icon(core_window_t* wd, const paint::image& small_icon, const paint::image& big_icon) { if(!big_icon.empty() || !small_icon.empty()) { @@ -423,7 +404,7 @@ namespace detail if (impl_->wd_register.available(wd)) { if(wd->other.category == category::root_tag::value) - native_interface::window_icon(wd->root, big_icon, small_icon); + native_interface::window_icon(wd->root, small_icon, big_icon); } } } diff --git a/source/gui/programming_interface.cpp b/source/gui/programming_interface.cpp index 3850c0be..3c75b106 100644 --- a/source/gui/programming_interface.cpp +++ b/source/gui/programming_interface.cpp @@ -354,24 +354,14 @@ namespace API return r; } - void window_icon_default(const paint::image& img) + void window_icon_default(const paint::image& small_icon, const paint::image& big_icon) { - restrict::window_manager.default_icon(img); + restrict::window_manager.default_icon(small_icon, big_icon); } - void window_icon_default(const paint::image& big_icon, const paint::image& small_icon) + void window_icon(window wd, const paint::image& small_icon, const paint::image& big_icon) { - restrict::window_manager.default_icon(big_icon, small_icon); - } - - void window_icon(window wd, const paint::image& img) - { - restrict::window_manager.icon(reinterpret_cast(wd), img); - } - - void window_icon(window wd, const paint::image& big_icon, const paint::image& small_icon) - { - restrict::window_manager.icon(reinterpret_cast(wd), big_icon, small_icon); + restrict::window_manager.icon(reinterpret_cast(wd), small_icon, big_icon); } bool empty_window(window wd) diff --git a/source/gui/widgets/label.cpp b/source/gui/widgets/label.cpp index 675e06e5..a7eba8ae 100644 --- a/source/gui/widgets/label.cpp +++ b/source/gui/widgets/label.cpp @@ -628,7 +628,7 @@ namespace nana nana::string target; //It indicates which target is tracing. nana::string url; - widget * buddy {nullptr}; + window for_associated_wd{ nullptr }; void add_listener(std::function&& fn) { @@ -743,9 +743,7 @@ namespace nana system::open_url(url); - if (impl_->buddy) { - impl_->buddy->focus(); - } + API::focus_window(impl_->for_associated_wd); } void trigger::refresh(graph_reference graph) @@ -827,9 +825,9 @@ namespace nana return *this; } - void label::relate(widget& w) + void label::click_for(window associated_window) { - get_drawer_trigger().impl()->buddy = &w; + get_drawer_trigger().impl()->for_associated_wd = associated_window; } nana::size label::measure(unsigned limited) const diff --git a/source/gui/widgets/skeletons/text_editor.cpp b/source/gui/widgets/skeletons/text_editor.cpp index a7afa323..29893989 100644 --- a/source/gui/widgets/skeletons/text_editor.cpp +++ b/source/gui/widgets/skeletons/text_editor.cpp @@ -55,7 +55,6 @@ namespace nana{ namespace widgets virtual bool merge(const undoable_command_interface& rhs) override { - //Implement later return false; } protected: @@ -1620,7 +1619,7 @@ namespace nana{ namespace widgets text_area_.captured = true; //Set caret pos by screen point and get the caret pos. - auto pos = mouse_caret(scrpos); + mouse_caret(scrpos); if(!select(false)) { select_.a = points_.caret; //Set begin caret @@ -2315,7 +2314,7 @@ namespace nana{ namespace widgets } break; case keyboard::os_pageup: - if (caret.y >= (int)screen_lines() && points_.offset.y >= (int)screen_lines()) { + if (caret.y >= screen_lines() && points_.offset.y >= static_cast(screen_lines())) { points_.offset.y -= screen_lines(); caret.y -= screen_lines(); changed = true; @@ -2967,7 +2966,7 @@ namespace nana{ namespace widgets if (if_mask && mask_char_) mask_str.reset(new nana::string(str.size(), mask_char_)); - bool focused = API::is_focus_ready(window_); // do this many times is not efficient... + bool focused = API::is_focus_ready(window_); auto & linestr = (if_mask && mask_char_ ? *mask_str : str); diff --git a/source/gui/widgets/textbox.cpp b/source/gui/widgets/textbox.cpp index 6d7e3380..e5e98068 100644 --- a/source/gui/widgets/textbox.cpp +++ b/source/gui/widgets/textbox.cpp @@ -94,14 +94,8 @@ namespace drawerbase { refresh(graph); if (!editor_->attr().multi_lines && arg.getting) { - static auto& brock = detail::bedrock::instance(); - auto native_window = reinterpret_cast(arg.receiver); - auto* root_runtime = brock.wd_manager.root_runtime(native_window); - if (root_runtime && root_runtime->condition.tabstop_focus_changed) - { - editor_->select(true); - editor_->move_caret_end(); - } + editor_->select(true); + editor_->move_caret_end(); } editor_->show_caret(arg.getting); editor_->reset_caret(); diff --git a/source/paint/detail/image_bmp.hpp b/source/paint/detail/image_bmp.hpp index 43643d6d..f8b08848 100644 --- a/source/paint/detail/image_bmp.hpp +++ b/source/paint/detail/image_bmp.hpp @@ -75,7 +75,7 @@ namespace nana{ namespace paint this->close(); } - bool open(const void* data, std::size_t bytes) + bool open(const void* data, std::size_t bytes) override { // TODO: read a BMP file from memory return false; diff --git a/source/paint/detail/image_ico.hpp b/source/paint/detail/image_ico.hpp index 9bc33dea..5be39454 100644 --- a/source/paint/detail/image_ico.hpp +++ b/source/paint/detail/image_ico.hpp @@ -24,7 +24,7 @@ namespace nana{ namespace paint bool open(const nana::char_t* filename) override; - bool open(const void* data, std::size_t bytes); + bool open(const void* data, std::size_t bytes) override; bool alpha_channel() const override; bool empty() const override; void close() override; diff --git a/source/paint/image.cpp b/source/paint/image.cpp index 46bd547a..f27a55c9 100644 --- a/source/paint/image.cpp +++ b/source/paint/image.cpp @@ -70,11 +70,11 @@ namespace paint return false; } - bool image_ico::open(void* buff, size_t sz) + bool image_ico::open(const void* data, std::size_t bytes) { close(); #if defined(NANA_WINDOWS) - HICON handle = CreateIconFromResource((PBYTE)buff, sz, TRUE, 0x00030000); + HICON handle = ::CreateIconFromResource((PBYTE)data, static_cast(bytes), TRUE, 0x00030000); if(handle) { ICONINFO info; @@ -261,11 +261,11 @@ namespace paint return false; } - bool image::open_icon(void* buff, size_t sz) + bool image::open_icon(const void* data, std::size_t bytes) { image::image_impl_interface * helper = new detail::image_ico(true); image_ptr_ = std::shared_ptr(helper); - return helper->open(buff, sz); + return helper->open(data, bytes); } bool image::empty() const