diff --git a/include/nana/gui/detail/inner_fwd_implement.hpp b/include/nana/gui/detail/inner_fwd_implement.hpp index 4b7d958a..68937148 100644 --- a/include/nana/gui/detail/inner_fwd_implement.hpp +++ b/include/nana/gui/detail/inner_fwd_implement.hpp @@ -1,7 +1,7 @@ /* * Implementations of Inner Forward Declaration * Nana C++ Library(http://www.nanapro.org) - * Copyright(C) 2003-2015 Jinhao(cnjinhao@hotmail.com) + * Copyright(C) 2003-2016 Jinhao(cnjinhao@hotmail.com) * * Distributed under the Boost Software License, Version 1.0. * (See accompanying file LICENSE_1_0.txt or copy at @@ -26,87 +26,32 @@ namespace nana{ { class shortkey_container { - struct item_type - { - window handle; - std::vector keys; - }; + struct item_type; + + //Noncopyable + shortkey_container(const shortkey_container&) = delete; + shortkey_container& operator=(const shortkey_container&) = delete; + + shortkey_container& operator=(shortkey_container&&) = delete; public: - void clear() - { - keybase_.clear(); - } + shortkey_container(); - bool make(window wd, unsigned long key) - { - if (wd == nullptr) return false; - if (key < 0x61) key += (0x61 - 0x41); + shortkey_container(shortkey_container&&); - for (auto & m : keybase_) - { - if (m.handle == wd) - { - m.keys.push_back(key); - return true; - } - } + ~shortkey_container(); - item_type m; - m.handle = wd; - m.keys.push_back(key); - keybase_.push_back(m); + void clear(); - return true; - } + bool make(window wd, unsigned long key); - void umake(window wd) - { - if (wd == nullptr) return; + void umake(window wd); - for (auto i = keybase_.begin(), end = keybase_.end(); i != end; ++i) - { - if (i->handle == wd) - { - keybase_.erase(i); - break; - } - } - } + std::vector keys(window wd) const; - std::vector keys(window wd) const - { - std::vector v; - if (wd) - { - for (auto & m : keybase_) - { - if (m.handle == wd) - { - v = m.keys; - break; - } - } - } - return v; - - } - - window find(unsigned long key) const - { - if (key < 0x61) key += (0x61 - 0x41); - - for (auto & m : keybase_) - { - for (auto n : m.keys) - { - if (key == n) - return m.handle; - } - } - return nullptr; - } + window find(unsigned long key) const; private: - std::vector keybase_; + struct implementation; + implementation * impl_; }; @@ -118,57 +63,39 @@ namespace nana{ struct condition_rep { - bool ignore_tab{ false }; //ignore tab when the focus is changed by TAB key. - basic_window* pressed{ nullptr }; //The handle to a window which has been pressed by mouse left button. - basic_window* pressed_by_space{ nullptr }; //The handle to a window which has been pressed by SPACEBAR key. - basic_window* hovered{ nullptr }; //the latest window that mouse moved + bool ignore_tab; //ignore tab when the focus is changed by TAB key. + basic_window* pressed; //The handle to a window which has been pressed by mouse left button. + basic_window* pressed_by_space; //The handle to a window which has been pressed by SPACEBAR key. + basic_window* hovered; //the latest window that mouse moved }condition; - root_misc(basic_window * wd, unsigned width, unsigned height) - : window(wd), - root_graph({ width, height }) - {} + root_misc(root_misc&&); + root_misc(basic_window * wd, unsigned width, unsigned height); };//end struct root_misc + + class root_register { + //Noncopyable + root_register(const root_register&) = delete; + root_register& operator=(const root_register&) = delete; + + //Nonmovable + root_register(root_register&&) = delete; + root_register& operator=(root_register&&) = delete; public: - root_misc* insert(native_window_type wd, root_misc&& misc) - { - recent_ = wd; - auto ret = table_.emplace(wd, std::move(misc)); - misc_ptr_ = &(ret.first->second); - return misc_ptr_; - } + root_register(); + ~root_register(); - root_misc * find(native_window_type wd) - { - if (wd == recent_) - return misc_ptr_; + root_misc* insert(native_window_type, root_misc&&); - recent_ = wd; - - auto i = table_.find(wd); - if (i != table_.end()) - misc_ptr_ = &(i->second); - else - misc_ptr_ = nullptr; + root_misc * find(native_window_type); - return misc_ptr_; - } - - void erase(native_window_type wd) - { - table_.erase(wd); - recent_ = wd; - misc_ptr_ = nullptr; - } + void erase(native_window_type); private: - //Cached - mutable native_window_type recent_{nullptr}; - mutable root_misc * misc_ptr_{nullptr}; - - std::map table_; + struct implementation; + implementation * const impl_; }; } }//end namespace nana diff --git a/source/detail/platform_spec_posix.cpp b/source/detail/platform_spec_posix.cpp index 97ce8d19..c737cdf6 100644 --- a/source/detail/platform_spec_posix.cpp +++ b/source/detail/platform_spec_posix.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #include diff --git a/source/gui/detail/bedrock_pi.cpp b/source/gui/detail/bedrock_pi.cpp index 64db05cd..c6617bd7 100644 --- a/source/gui/detail/bedrock_pi.cpp +++ b/source/gui/detail/bedrock_pi.cpp @@ -17,7 +17,7 @@ #include #include #include -#include +#include #include #include #include @@ -25,6 +25,7 @@ namespace nana { + //class internal_scope_guard internal_scope_guard::internal_scope_guard() { diff --git a/source/gui/detail/drawer.cpp b/source/gui/detail/drawer.cpp index e3b7b2fe..0ab725aa 100644 --- a/source/gui/detail/drawer.cpp +++ b/source/gui/detail/drawer.cpp @@ -13,9 +13,9 @@ #include #include #include -#include #include #include +#include "dynamic_drawing_object.hpp" #if defined(NANA_X11) #include diff --git a/include/nana/gui/detail/dynamic_drawing_object.hpp b/source/gui/detail/dynamic_drawing_object.hpp similarity index 100% rename from include/nana/gui/detail/dynamic_drawing_object.hpp rename to source/gui/detail/dynamic_drawing_object.hpp diff --git a/source/gui/detail/window_manager.cpp b/source/gui/detail/window_manager.cpp index 3e5d1d23..eb4efaf9 100644 --- a/source/gui/detail/window_manager.cpp +++ b/source/gui/detail/window_manager.cpp @@ -32,6 +32,178 @@ namespace nana { + namespace detail + { + //class shortkey_container + struct shortkey_rep + { + window handle; + std::vector keys; + }; + + struct shortkey_container::implementation + { + std::vector base; + }; + + shortkey_container::shortkey_container() + :impl_(new implementation) + {} + + shortkey_container::shortkey_container(shortkey_container&& other) + : impl_(other.impl_) + { + other.impl_ = nullptr; + } + + shortkey_container::~shortkey_container() + { + delete impl_; + } + + void shortkey_container::clear() + { + impl_->base.clear(); + } + + bool shortkey_container::make(window wd, unsigned long key) + { + if (wd == nullptr) return false; + if (key < 0x61) key += (0x61 - 0x41); + + for (auto & m : impl_->base) + { + if (m.handle == wd) + { + m.keys.emplace_back(key); + return true; + } + } + + impl_->base.emplace_back(); + auto & rep = impl_->base.back(); + rep.handle = wd; + rep.keys.emplace_back(key); + + return true; + } + + void shortkey_container::umake(window wd) + { + if (wd == nullptr) return; + + for (auto i = impl_->base.begin(); i != impl_->base.end(); ++i) + { + if (i->handle == wd) + { + impl_->base.erase(i); + break; + } + } + } + + std::vector shortkey_container::keys(window wd) const + { + if (wd) + { + for (auto & m : impl_->base) + { + if (m.handle == wd) + return m.keys; + } + } + return{}; + } + + window shortkey_container::find(unsigned long key) const + { + if (key < 0x61) key += (0x61 - 0x41); + + for (auto & m : impl_->base) + { + for (auto n : m.keys) + { + if (key == n) + return m.handle; + } + } + return nullptr; + } + //end class shortkey_container + + + //struct root_misc + root_misc::root_misc(root_misc&& other): + window(other.window), + root_graph(std::move(other.root_graph)), + shortkeys(std::move(other.shortkeys)), + condition(std::move(other.condition)) + { + } + + root_misc::root_misc(basic_window * wd, unsigned width, unsigned height) + : window(wd), + root_graph({ width, height }) + { + condition.ignore_tab = false; + condition.pressed = nullptr; + condition.pressed_by_space = nullptr; + condition.hovered = nullptr; + } + //end struct root_misc + + //class root_register + struct root_register::implementation + { + //Cached + native_window_type recent_access{ nullptr }; + root_misc * misc_ptr{ nullptr }; + + std::map table; + }; + + root_register::root_register() + : impl_(new implementation) + {} + + root_register::~root_register() + { + delete impl_; + } + + root_misc* root_register::insert(native_window_type wd, root_misc&& misc) + { + impl_->recent_access = wd; + auto ret = impl_->table.emplace(wd, std::move(misc)); + impl_->misc_ptr = &(ret.first->second); + return impl_->misc_ptr; + } + + root_misc * root_register::find(native_window_type wd) + { + if (wd == impl_->recent_access) + return impl_->misc_ptr; + + impl_->recent_access = wd; + + auto i = impl_->table.find(wd); + if (i != impl_->table.end()) + impl_->misc_ptr = &(i->second); + else + impl_->misc_ptr = nullptr; + + return impl_->misc_ptr; + } + + void root_register::erase(native_window_type wd) + { + impl_->table.erase(wd); + impl_->recent_access = wd; + impl_->misc_ptr = nullptr; + } + //end class root_register + } + namespace detail { template diff --git a/source/gui/element.cpp b/source/gui/element.cpp index 3886e1f4..8d31a447 100644 --- a/source/gui/element.cpp +++ b/source/gui/element.cpp @@ -1176,7 +1176,7 @@ namespace nana } bground::bground(const bground& rhs) - : impl_{ new implementation } + : impl_{ new implementation(*rhs.impl_) } { if (impl_->method) impl_->method = impl_->method->clone(); diff --git a/source/gui/widgets/menu.cpp b/source/gui/widgets/menu.cpp index 91493d8a..bae7ab51 100644 --- a/source/gui/widgets/menu.cpp +++ b/source/gui/widgets/menu.cpp @@ -272,7 +272,7 @@ namespace nana if(item.sub_menu == nullptr) { item.sub_menu = ⊂ - sub.owner.push_back(&root_); + sub.owner.emplace_back(&root_); return true; } } diff --git a/source/gui/widgets/menubar.cpp b/source/gui/widgets/menubar.cpp index 10bf8814..9d40d9ec 100644 --- a/source/gui/widgets/menubar.cpp +++ b/source/gui/widgets/menubar.cpp @@ -55,7 +55,7 @@ namespace nana void append(const native_string_type& text, unsigned long shortkey) { if(shortkey && shortkey < 0x61) shortkey += (0x61 - 0x41); - cont_.push_back(new item_type(text, shortkey)); + cont_.emplace_back(new item_type(text, shortkey)); } std::size_t find(unsigned long shortkey) const diff --git a/source/gui/widgets/tabbar.cpp b/source/gui/widgets/tabbar.cpp index e731b3ad..61150e9f 100644 --- a/source/gui/widgets/tabbar.cpp +++ b/source/gui/widgets/tabbar.cpp @@ -748,14 +748,13 @@ namespace nana bool _m_add_tab(std::size_t pos) { - item_t m; if((pos == npos) || (pos >= list_.size())) { - this->list_.push_back(m); + this->list_.emplace_back(); pos = static_cast(list_.size() - 1); } else - list_.insert(iterator_at(pos), m); + list_.emplace(iterator_at(pos)); basis_.active = pos; if(evt_agent_) @@ -1505,7 +1504,7 @@ namespace nana for (auto & m : items) { auto ts = graph.bidi_extent_size(m.text); - pxs.push_back(ts.width + 12); + pxs.emplace_back(ts.width + 12); pixels += ts.width + 12; } diff --git a/source/paint/graphics.cpp b/source/paint/graphics.cpp index 4eea00c7..2496a295 100644 --- a/source/paint/graphics.cpp +++ b/source/paint/graphics.cpp @@ -973,7 +973,7 @@ namespace paint #elif defined(NANA_X11) Display* disp = nana::detail::platform_spec::instance().open_display(); impl_->handle->update_color(); - ::XDrawPoint(disp, impl_->handle->pixmap, handle_->context, x, y); + ::XDrawPoint(disp, impl_->handle->pixmap, impl_->handle->context, x, y); #endif if (impl_->changed == false) impl_->changed = true; } @@ -997,7 +997,7 @@ namespace paint auto const end = str + len; auto i = std::find(str, end, '\t'); #if defined(NANA_LINUX) || defined(NANA_MACOS) - handle_->update_text_color(); + impl_->handle->update_text_color(); #endif if (i != end) { @@ -1177,7 +1177,7 @@ namespace paint impl_->pxbuf.paste(impl_->handle, point{}); } #elif defined(NANA_X11) - if (nullptr == handle_) return; + if (nullptr == impl_->handle) return; double deltapx = double(vertical ? rct.height : rct.width); double r, g, b;