code refine

This commit is contained in:
Jinhao
2016-08-11 02:26:47 +08:00
parent 6e86b6ae6c
commit 9b28c96e9b
11 changed files with 225 additions and 125 deletions

View File

@@ -29,6 +29,7 @@
#include <nana/gui/detail/basic_window.hpp>
#include <nana/gui/detail/window_manager.hpp>
#include <nana/system/platform.hpp>
#include <nana/paint/pixel_buffer.hpp>
#include <errno.h>
#include <sstream>

View File

@@ -17,7 +17,7 @@
#include <sstream>
#include <nana/system/timepiece.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/layout_utility.hpp>
#include <nana/gui/detail/element_store.hpp>
@@ -25,6 +25,7 @@
namespace nana
{
//class internal_scope_guard
internal_scope_guard::internal_scope_guard()
{

View File

@@ -13,9 +13,9 @@
#include <nana/config.hpp>
#include <nana/gui/detail/bedrock.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/basic_window.hpp>
#include "dynamic_drawing_object.hpp"
#if defined(NANA_X11)
#include <nana/detail/linux_X11/platform_spec.hpp>

View File

@@ -0,0 +1,69 @@
/*
* Dynamic Drawing Object Implementation
* Copyright(C) 2003-2013 Jinhao(cnjinhao@hotmail.com)
*
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*
* @file: nana/gui/detail/dynamic_drawing_object.hpp
*
* !DON'T INCLUDE THIS HEADER FILE IN YOUR SOURCE CODE
*/
#ifndef NANA_GUI_DETAIL_DYNAMIC_DRAWING_OBJECT_HPP
#define NANA_GUI_DETAIL_DYNAMIC_DRAWING_OBJECT_HPP
#include <nana/paint/graphics.hpp>
#include <nana/paint/image.hpp>
namespace nana
{
namespace detail
{
namespace dynamic_drawing
{
class object
{
object(const object&) = delete;
object& operator=(const object&) = delete;
public:
object(){}
virtual ~object(){}
virtual bool diehard() const
{
return false;
}
virtual void draw(nana::paint::graphics&) const = 0;
};
//user_draw_function
class user_draw_function
: public object
{
public:
user_draw_function(std::function<void(paint::graphics&)> && f, bool diehard)
: diehard_(diehard), fn_(std::move(f))
{}
void draw(paint::graphics& graph) const
{
fn_(graph);
}
bool diehard() const
{
return diehard_;
}
private:
bool diehard_;
std::function<void(paint::graphics&)> fn_;
};
}//end namespace dynamic_drawing
}
}//end namespace nana
#endif

View File

@@ -32,6 +32,178 @@
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
{
template<typename Key, typename Value>

View File

@@ -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();

View File

@@ -272,7 +272,7 @@ namespace nana
if(item.sub_menu == nullptr)
{
item.sub_menu = &sub;
sub.owner.push_back(&root_);
sub.owner.emplace_back(&root_);
return true;
}
}

View File

@@ -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

View File

@@ -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<unsigned>(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;
}

View File

@@ -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;