code refine
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* Implementations of Inner Forward Declaration
|
* Implementations of Inner Forward Declaration
|
||||||
* Nana C++ Library(http://www.nanapro.org)
|
* 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.
|
* Distributed under the Boost Software License, Version 1.0.
|
||||||
* (See accompanying file LICENSE_1_0.txt or copy at
|
* (See accompanying file LICENSE_1_0.txt or copy at
|
||||||
@@ -26,87 +26,32 @@ namespace nana{
|
|||||||
{
|
{
|
||||||
class shortkey_container
|
class shortkey_container
|
||||||
{
|
{
|
||||||
struct item_type
|
struct item_type;
|
||||||
{
|
|
||||||
window handle;
|
//Noncopyable
|
||||||
std::vector<unsigned long> keys;
|
shortkey_container(const shortkey_container&) = delete;
|
||||||
};
|
shortkey_container& operator=(const shortkey_container&) = delete;
|
||||||
|
|
||||||
|
shortkey_container& operator=(shortkey_container&&) = delete;
|
||||||
public:
|
public:
|
||||||
void clear()
|
shortkey_container();
|
||||||
{
|
|
||||||
keybase_.clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool make(window wd, unsigned long key)
|
shortkey_container(shortkey_container&&);
|
||||||
{
|
|
||||||
if (wd == nullptr) return false;
|
|
||||||
if (key < 0x61) key += (0x61 - 0x41);
|
|
||||||
|
|
||||||
for (auto & m : keybase_)
|
~shortkey_container();
|
||||||
{
|
|
||||||
if (m.handle == wd)
|
|
||||||
{
|
|
||||||
m.keys.push_back(key);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
item_type m;
|
void clear();
|
||||||
m.handle = wd;
|
|
||||||
m.keys.push_back(key);
|
|
||||||
keybase_.push_back(m);
|
|
||||||
|
|
||||||
return true;
|
bool make(window wd, unsigned long key);
|
||||||
}
|
|
||||||
|
|
||||||
void umake(window wd)
|
void umake(window wd);
|
||||||
{
|
|
||||||
if (wd == nullptr) return;
|
|
||||||
|
|
||||||
for (auto i = keybase_.begin(), end = keybase_.end(); i != end; ++i)
|
std::vector<unsigned long> keys(window wd) const;
|
||||||
{
|
|
||||||
if (i->handle == wd)
|
|
||||||
{
|
|
||||||
keybase_.erase(i);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<unsigned long> keys(window wd) const
|
window find(unsigned long key) const;
|
||||||
{
|
|
||||||
std::vector<unsigned long> 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;
|
|
||||||
}
|
|
||||||
private:
|
private:
|
||||||
std::vector<item_type> keybase_;
|
struct implementation;
|
||||||
|
implementation * impl_;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
@@ -118,57 +63,39 @@ namespace nana{
|
|||||||
|
|
||||||
struct condition_rep
|
struct condition_rep
|
||||||
{
|
{
|
||||||
bool ignore_tab{ false }; //ignore tab when the focus is changed by TAB key.
|
bool ignore_tab; //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; //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* pressed_by_space; //The handle to a window which has been pressed by SPACEBAR key.
|
||||||
basic_window* hovered{ nullptr }; //the latest window that mouse moved
|
basic_window* hovered; //the latest window that mouse moved
|
||||||
}condition;
|
}condition;
|
||||||
|
|
||||||
root_misc(basic_window * wd, unsigned width, unsigned height)
|
root_misc(root_misc&&);
|
||||||
: window(wd),
|
root_misc(basic_window * wd, unsigned width, unsigned height);
|
||||||
root_graph({ width, height })
|
|
||||||
{}
|
|
||||||
};//end struct root_misc
|
};//end struct root_misc
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class root_register
|
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:
|
public:
|
||||||
root_misc* insert(native_window_type wd, root_misc&& misc)
|
root_register();
|
||||||
{
|
~root_register();
|
||||||
recent_ = wd;
|
|
||||||
auto ret = table_.emplace(wd, std::move(misc));
|
|
||||||
misc_ptr_ = &(ret.first->second);
|
|
||||||
return misc_ptr_;
|
|
||||||
}
|
|
||||||
|
|
||||||
root_misc * find(native_window_type wd)
|
root_misc* insert(native_window_type, root_misc&&);
|
||||||
{
|
|
||||||
if (wd == recent_)
|
|
||||||
return misc_ptr_;
|
|
||||||
|
|
||||||
recent_ = wd;
|
root_misc * find(native_window_type);
|
||||||
|
|
||||||
auto i = table_.find(wd);
|
void erase(native_window_type);
|
||||||
if (i != table_.end())
|
|
||||||
misc_ptr_ = &(i->second);
|
|
||||||
else
|
|
||||||
misc_ptr_ = nullptr;
|
|
||||||
|
|
||||||
return misc_ptr_;
|
|
||||||
}
|
|
||||||
|
|
||||||
void erase(native_window_type wd)
|
|
||||||
{
|
|
||||||
table_.erase(wd);
|
|
||||||
recent_ = wd;
|
|
||||||
misc_ptr_ = nullptr;
|
|
||||||
}
|
|
||||||
private:
|
private:
|
||||||
//Cached
|
struct implementation;
|
||||||
mutable native_window_type recent_{nullptr};
|
implementation * const impl_;
|
||||||
mutable root_misc * misc_ptr_{nullptr};
|
|
||||||
|
|
||||||
std::map<native_window_type, root_misc> table_;
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}//end namespace nana
|
}//end namespace nana
|
||||||
|
|||||||
@@ -29,6 +29,7 @@
|
|||||||
#include <nana/gui/detail/basic_window.hpp>
|
#include <nana/gui/detail/basic_window.hpp>
|
||||||
#include <nana/gui/detail/window_manager.hpp>
|
#include <nana/gui/detail/window_manager.hpp>
|
||||||
#include <nana/system/platform.hpp>
|
#include <nana/system/platform.hpp>
|
||||||
|
#include <nana/paint/pixel_buffer.hpp>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <nana/system/timepiece.hpp>
|
#include <nana/system/timepiece.hpp>
|
||||||
#include <nana/gui/wvl.hpp>
|
#include <nana/gui/wvl.hpp>
|
||||||
#include <nana/gui/detail/inner_fwd_implement.hpp>
|
#include <nana/gui/detail/basic_window.hpp>
|
||||||
#include <nana/gui/detail/native_window_interface.hpp>
|
#include <nana/gui/detail/native_window_interface.hpp>
|
||||||
#include <nana/gui/layout_utility.hpp>
|
#include <nana/gui/layout_utility.hpp>
|
||||||
#include <nana/gui/detail/element_store.hpp>
|
#include <nana/gui/detail/element_store.hpp>
|
||||||
@@ -25,6 +25,7 @@
|
|||||||
|
|
||||||
namespace nana
|
namespace nana
|
||||||
{
|
{
|
||||||
|
|
||||||
//class internal_scope_guard
|
//class internal_scope_guard
|
||||||
internal_scope_guard::internal_scope_guard()
|
internal_scope_guard::internal_scope_guard()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -13,9 +13,9 @@
|
|||||||
#include <nana/config.hpp>
|
#include <nana/config.hpp>
|
||||||
#include <nana/gui/detail/bedrock.hpp>
|
#include <nana/gui/detail/bedrock.hpp>
|
||||||
#include <nana/gui/detail/drawer.hpp>
|
#include <nana/gui/detail/drawer.hpp>
|
||||||
#include <nana/gui/detail/dynamic_drawing_object.hpp>
|
|
||||||
#include <nana/gui/detail/effects_renderer.hpp>
|
#include <nana/gui/detail/effects_renderer.hpp>
|
||||||
#include <nana/gui/detail/basic_window.hpp>
|
#include <nana/gui/detail/basic_window.hpp>
|
||||||
|
#include "dynamic_drawing_object.hpp"
|
||||||
|
|
||||||
#if defined(NANA_X11)
|
#if defined(NANA_X11)
|
||||||
#include <nana/detail/linux_X11/platform_spec.hpp>
|
#include <nana/detail/linux_X11/platform_spec.hpp>
|
||||||
|
|||||||
@@ -32,6 +32,178 @@
|
|||||||
namespace nana
|
namespace nana
|
||||||
{
|
{
|
||||||
|
|
||||||
|
namespace detail
|
||||||
|
{
|
||||||
|
//class shortkey_container
|
||||||
|
struct shortkey_rep
|
||||||
|
{
|
||||||
|
window handle;
|
||||||
|
std::vector<unsigned long> keys;
|
||||||
|
};
|
||||||
|
|
||||||
|
struct shortkey_container::implementation
|
||||||
|
{
|
||||||
|
std::vector<shortkey_rep> 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<unsigned long> 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<native_window_type, root_misc> 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
|
namespace detail
|
||||||
{
|
{
|
||||||
template<typename Key, typename Value>
|
template<typename Key, typename Value>
|
||||||
|
|||||||
@@ -1176,7 +1176,7 @@ namespace nana
|
|||||||
}
|
}
|
||||||
|
|
||||||
bground::bground(const bground& rhs)
|
bground::bground(const bground& rhs)
|
||||||
: impl_{ new implementation }
|
: impl_{ new implementation(*rhs.impl_) }
|
||||||
{
|
{
|
||||||
if (impl_->method)
|
if (impl_->method)
|
||||||
impl_->method = impl_->method->clone();
|
impl_->method = impl_->method->clone();
|
||||||
|
|||||||
@@ -272,7 +272,7 @@ namespace nana
|
|||||||
if(item.sub_menu == nullptr)
|
if(item.sub_menu == nullptr)
|
||||||
{
|
{
|
||||||
item.sub_menu = ⊂
|
item.sub_menu = ⊂
|
||||||
sub.owner.push_back(&root_);
|
sub.owner.emplace_back(&root_);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ namespace nana
|
|||||||
void append(const native_string_type& text, unsigned long shortkey)
|
void append(const native_string_type& text, unsigned long shortkey)
|
||||||
{
|
{
|
||||||
if(shortkey && shortkey < 0x61) shortkey += (0x61 - 0x41);
|
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
|
std::size_t find(unsigned long shortkey) const
|
||||||
|
|||||||
@@ -748,14 +748,13 @@ namespace nana
|
|||||||
|
|
||||||
bool _m_add_tab(std::size_t pos)
|
bool _m_add_tab(std::size_t pos)
|
||||||
{
|
{
|
||||||
item_t m;
|
|
||||||
if((pos == npos) || (pos >= list_.size()))
|
if((pos == npos) || (pos >= list_.size()))
|
||||||
{
|
{
|
||||||
this->list_.push_back(m);
|
this->list_.emplace_back();
|
||||||
pos = static_cast<unsigned>(list_.size() - 1);
|
pos = static_cast<unsigned>(list_.size() - 1);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
list_.insert(iterator_at(pos), m);
|
list_.emplace(iterator_at(pos));
|
||||||
|
|
||||||
basis_.active = pos;
|
basis_.active = pos;
|
||||||
if(evt_agent_)
|
if(evt_agent_)
|
||||||
@@ -1505,7 +1504,7 @@ namespace nana
|
|||||||
for (auto & m : items)
|
for (auto & m : items)
|
||||||
{
|
{
|
||||||
auto ts = graph.bidi_extent_size(m.text);
|
auto ts = graph.bidi_extent_size(m.text);
|
||||||
pxs.push_back(ts.width + 12);
|
pxs.emplace_back(ts.width + 12);
|
||||||
pixels += ts.width + 12;
|
pixels += ts.width + 12;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -973,7 +973,7 @@ namespace paint
|
|||||||
#elif defined(NANA_X11)
|
#elif defined(NANA_X11)
|
||||||
Display* disp = nana::detail::platform_spec::instance().open_display();
|
Display* disp = nana::detail::platform_spec::instance().open_display();
|
||||||
impl_->handle->update_color();
|
impl_->handle->update_color();
|
||||||
::XDrawPoint(disp, impl_->handle->pixmap, handle_->context, x, y);
|
::XDrawPoint(disp, impl_->handle->pixmap, impl_->handle->context, x, y);
|
||||||
#endif
|
#endif
|
||||||
if (impl_->changed == false) impl_->changed = true;
|
if (impl_->changed == false) impl_->changed = true;
|
||||||
}
|
}
|
||||||
@@ -997,7 +997,7 @@ namespace paint
|
|||||||
auto const end = str + len;
|
auto const end = str + len;
|
||||||
auto i = std::find(str, end, '\t');
|
auto i = std::find(str, end, '\t');
|
||||||
#if defined(NANA_LINUX) || defined(NANA_MACOS)
|
#if defined(NANA_LINUX) || defined(NANA_MACOS)
|
||||||
handle_->update_text_color();
|
impl_->handle->update_text_color();
|
||||||
#endif
|
#endif
|
||||||
if (i != end)
|
if (i != end)
|
||||||
{
|
{
|
||||||
@@ -1177,7 +1177,7 @@ namespace paint
|
|||||||
impl_->pxbuf.paste(impl_->handle, point{});
|
impl_->pxbuf.paste(impl_->handle, point{});
|
||||||
}
|
}
|
||||||
#elif defined(NANA_X11)
|
#elif defined(NANA_X11)
|
||||||
if (nullptr == handle_) return;
|
if (nullptr == impl_->handle) return;
|
||||||
|
|
||||||
double deltapx = double(vertical ? rct.height : rct.width);
|
double deltapx = double(vertical ? rct.height : rct.width);
|
||||||
double r, g, b;
|
double r, g, b;
|
||||||
|
|||||||
Reference in New Issue
Block a user