optimize generated binary size

This commit is contained in:
Jinhao 2016-02-18 01:01:55 +08:00
parent 0ed51a7a21
commit d3120cbf35
15 changed files with 274 additions and 285 deletions

View File

@ -95,9 +95,9 @@ namespace std
namespace nana
{
/// Checks whether a specified text is utf8 encoding
bool is_utf8(const char* str, unsigned len);
bool is_utf8(const char* str, std::size_t len);
void throw_not_utf8(const std::string& text);
void throw_not_utf8(const char*, unsigned len);
void throw_not_utf8(const char*, std::size_t len);
void throw_not_utf8(const char*);
const std::string& to_utf8(const std::string&);

View File

@ -1,7 +1,7 @@
/*
* A Bedrock Implementation
* 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
@ -78,8 +78,8 @@ namespace detail
void define_state_cursor(core_window_t*, nana::cursor, thread_context*);
void undefine_state_cursor(core_window_t*, thread_context*);
widget_colors& get_scheme_template(scheme_factory_base&&);
widget_colors* make_scheme(scheme_factory_base&&);
widget_colors& get_scheme_template(scheme_factory_interface&&);
widget_colors* make_scheme(scheme_factory_interface&&);
events_operation& evt_operation();
window_manager& wd_manager();

View File

@ -1,7 +1,7 @@
/*
* Color Schemes
* Nana C++ Library(http://www.nanapro.org)
* Copyright(C) 2003-2014 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
@ -19,20 +19,21 @@ namespace nana
{
namespace detail
{
class scheme_factory_base
class scheme_factory_interface
{
public:
struct factory_identifier{};
virtual ~scheme_factory_base() = default;
virtual ~scheme_factory_interface() = default;
virtual factory_identifier* get_id() const = 0;
virtual widget_colors* create() = 0;
virtual widget_colors* create(widget_colors&) = 0;
};
template<typename Scheme>
class scheme_factory
: public scheme_factory_base
: public scheme_factory_interface
{
private:
factory_identifier* get_id() const override
@ -54,7 +55,7 @@ namespace nana
};
template<typename Scheme>
scheme_factory_base::factory_identifier scheme_factory<Scheme>::fid_;
scheme_factory_interface::factory_identifier scheme_factory<Scheme>::fid_;
class color_schemes
{
@ -69,8 +70,8 @@ namespace nana
color_schemes();
~color_schemes();
scheme& scheme_template(scheme_factory_base&&);
scheme* create(scheme_factory_base&&);
scheme& scheme_template(scheme_factory_interface&&);
scheme* create(scheme_factory_interface&&);
private:
implement * impl_;
};

View File

@ -4,6 +4,7 @@
#include <nana/gui/detail/general_events.hpp>
#include <unordered_set>
#include <unordered_map>
#include <memory>
#if defined(STD_THREAD_NOT_SUPPORTED)
#include <nana/std_mutex.hpp>

View File

@ -17,7 +17,6 @@
#include "internal_scope_guard.hpp"
#include <type_traits>
#include <functional>
#include <memory>
#include <vector>
namespace nana
@ -67,7 +66,7 @@ namespace nana
protected:
//class emit_counter is a RAII helper for emitting count
//It is used for avoiding a try{}catch block which is required for some finial works when
//event handlers throw exceptions.
//event handlers throw exceptions. Precondition event_base.dockers_ != nullptr.
class emit_counter
{
public:
@ -77,12 +76,10 @@ namespace nana
event_base * const evt_;
};
//event_handle _m_emplace(::std::unique_ptr<detail::docker_interface>& docker_ptr, bool in_front);
event_handle _m_emplace(detail::docker_interface*, bool in_front);
protected:
unsigned emitting_count_{ 0 };
bool deleted_flags_{ false };
//std::unique_ptr<std::vector<std::unique_ptr<detail::docker_interface>>> dockers_;
std::vector<detail::docker_interface*> * dockers_{ nullptr };
};
}//end namespace detail
@ -172,27 +169,26 @@ namespace nana
emit_counter ec(this);
auto& dockers = *dockers_;
const auto dockers_len = dockers_->size();
//The dockers may resize when a new event handler is created by a calling handler.
//Traverses with position can avaid crash error which caused by a iterator which becomes invalid.
for (std::size_t pos = 0; pos < dockers_len; ++pos)
auto i = dockers_->data();
auto const end = i + dockers_->size();
for (; i != end; ++i)
{
auto docker_ptr = static_cast<docker*>(dockers[pos]);
if (docker_ptr->flag_deleted)
if (static_cast<docker*>(*i)->flag_deleted)
continue;
docker_ptr->invoke(arg);
static_cast<docker*>(*i)->invoke(arg);
if (arg.propagation_stopped())
{
for (++pos; pos < dockers_len; ++pos)
for (++i; i != end; ++i)
{
auto docker_ptr = static_cast<docker*>(dockers[pos]);
if (!docker_ptr->unignorable || docker_ptr->flag_deleted)
if (!static_cast<docker*>(*i)->unignorable || static_cast<docker*>(*i)->flag_deleted)
continue;
docker_ptr->invoke(arg);
static_cast<docker*>(*i)->invoke(arg);
}
break;
}

View File

@ -1,7 +1,7 @@
/*
* Elements of GUI Gadgets
* Nana C++ Library(http://www.nanapro.org)
* Copyright(C) 2003-2014 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
@ -88,7 +88,6 @@ namespace nana
struct factory_interface
: public detail::factory_abstract
{
virtual ~factory_interface(){}
virtual ElementInterface* create() const = 0;
};

View File

@ -46,7 +46,7 @@ namespace API
{
namespace detail
{
::nana::widget_colors* make_scheme(::nana::detail::scheme_factory_base&&);
::nana::widget_colors* make_scheme(::nana::detail::scheme_factory_interface&&);
}
void effects_edge_nimbus(window, effects::edge_nimbus);

View File

@ -1,7 +1,7 @@
/**
* The fundamental widget class implementation
* 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
@ -132,9 +132,25 @@ namespace nana
virtual nana::color _m_bgcolor() const;
};
namespace detail
{
class widget_base
: public widget
{
public:
~widget_base();
window handle() const override;
private:
void _m_notify_destroy() override final;
protected:
window handle_{ nullptr };
};
}
/// Base class of all the classes defined as a widget window. Defaultly a widget_tag
template<typename Category, typename DrawerTrigger, typename Events = ::nana::general_events, typename Scheme = ::nana::widget_colors>
class widget_object: public widget
class widget_object: public detail::widget_base
{
protected:
typedef DrawerTrigger drawer_trigger_t;
@ -147,12 +163,6 @@ namespace nana
scheme_{ API::dev::make_scheme<Scheme>() }
{}
~widget_object()
{
if(handle_)
API::close_window(handle_);
}
event_type& events() const
{
return *events_;
@ -179,11 +189,6 @@ namespace nana
return (this->empty() == false);
}
window handle() const override
{
return handle_;
}
widget_object& borderless(bool enable)
{
API::widget_borderless(handle_, enable);
@ -214,13 +219,7 @@ namespace nana
{
return *events_;
}
void _m_notify_destroy() override final
{
handle_ = nullptr;
}
private:
window handle_{nullptr};
DrawerTrigger trigger_;
std::shared_ptr<Events> events_;
std::unique_ptr<scheme_type> scheme_;
@ -228,7 +227,7 @@ namespace nana
/// Base class of all the classes defined as a non-graphics-buffer widget window. The second template parameter DrawerTrigger is always ignored.\see nana::panel
template<typename DrawerTrigger, typename Events, typename Scheme>
class widget_object<category::lite_widget_tag, DrawerTrigger, Events, Scheme>: public widget
class widget_object<category::lite_widget_tag, DrawerTrigger, Events, Scheme>: public detail::widget_base
{
protected:
typedef DrawerTrigger drawer_trigger_t;
@ -240,12 +239,6 @@ namespace nana
: events_{ std::make_shared<Events>() }, scheme_{ API::dev::make_scheme<scheme_type>() }
{}
~widget_object()
{
if(handle_)
API::close_window(handle_);
}
event_type& events() const
{
return *events_;
@ -270,11 +263,6 @@ namespace nana
return (this->empty() == false);
}
window handle() const override
{
return handle_;
}
scheme_type& scheme() const
{
return *scheme_;
@ -284,13 +272,7 @@ namespace nana
{
return *events_;
}
void _m_notify_destroy() override final
{
handle_ = nullptr;
}
private:
window handle_{nullptr};
std::shared_ptr<Events> events_;
std::unique_ptr<scheme_type> scheme_;
};//end class widget_object
@ -298,7 +280,7 @@ namespace nana
/// Base class of all the classes defined as a root window. \see nana::form
template<typename DrawerTrigger, typename Events, typename Scheme>
class widget_object<category::root_tag, DrawerTrigger, Events, Scheme>: public widget
class widget_object<category::root_tag, DrawerTrigger, Events, Scheme>: public detail::widget_base
{
protected:
typedef DrawerTrigger drawer_trigger_t;
@ -324,12 +306,6 @@ namespace nana
_m_bind_and_attach();
}
~widget_object()
{
if(handle_)
API::close_window(handle_);
}
event_type& events() const
{
return *events_;
@ -340,11 +316,6 @@ namespace nana
API::activate_window(handle_);
}
window handle() const override
{
return handle_;
}
native_window_type native_handle() const
{
return API::root(handle_);
@ -435,13 +406,7 @@ namespace nana
{
return *events_;
}
void _m_notify_destroy() override final
{
handle_ = nullptr;
}
private:
window handle_;
DrawerTrigger trigger_;
std::shared_ptr<Events> events_;
std::unique_ptr<scheme_type> scheme_;
@ -453,7 +418,7 @@ namespace nana
/// Especialization. Base class of all the classes defined as a frame window. \see nana::frame
template<typename Events, typename Scheme>
class widget_object<category::frame_tag, int, Events, Scheme>: public widget
class widget_object<category::frame_tag, int, Events, Scheme>: public detail::widget_base
{
protected:
typedef int drawer_trigger_t;
@ -465,12 +430,6 @@ namespace nana
: events_{ std::make_shared<Events>() }, scheme_{ API::dev::make_scheme<scheme_type>() }
{}
~widget_object()
{
if(handle_)
API::close_window(handle_);
}
event_type& events() const
{
return *events_;
@ -494,11 +453,6 @@ namespace nana
return (this->empty() == false);
}
window handle() const override
{
return handle_;
}
scheme_type& scheme() const
{
return *scheme_;
@ -513,13 +467,7 @@ namespace nana
{
return *events_;
}
void _m_notify_destroy() override final
{
handle_ = nullptr;
}
private:
window handle_{nullptr};
std::shared_ptr<Events> events_;
std::unique_ptr<scheme_type> scheme_;
};//end class widget_object<category::frame_tag>

View File

@ -438,7 +438,7 @@ namespace std
namespace nana
{
bool is_utf8(const char* str, unsigned len)
bool is_utf8(const char* str, std::size_t len)
{
auto ustr = reinterpret_cast<const unsigned char*>(str);
auto end = ustr + len;
@ -474,7 +474,7 @@ namespace nana
throw std::invalid_argument("The text is not encoded in UTF8");
}
void throw_not_utf8(const char* text, unsigned len)
void throw_not_utf8(const char* text, std::size_t len)
{
if (!is_utf8(text, len))
throw std::invalid_argument("The text is not encoded in UTF8");

View File

@ -1,7 +1,7 @@
/*
* A Bedrock Platform-Independent Implementation
* 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
@ -198,12 +198,12 @@ namespace nana
}
}
widget_colors& bedrock::get_scheme_template(scheme_factory_base&& factory)
widget_colors& bedrock::get_scheme_template(scheme_factory_interface&& factory)
{
return pi_data_->scheme.scheme_template(std::move(factory));
}
widget_colors* bedrock::make_scheme(scheme_factory_base&& factory)
widget_colors* bedrock::make_scheme(scheme_factory_interface&& factory)
{
return pi_data_->scheme.create(std::move(factory));
}

View File

@ -1,3 +1,15 @@
/*
* Color Schemes
* Nana C++ Library(http://www.nanapro.org)
* 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
* http://www.boost.org/LICENSE_1_0.txt)
*
* @file: nana/gui/color_schemes.cpp
*/
#include <nana/gui/detail/color_schemes.hpp>
#include <map>
@ -57,7 +69,7 @@ namespace nana
//class color_schemes
struct color_schemes::implement
{
std::map<scheme_factory_base::factory_identifier*, std::unique_ptr<scheme>> scheme_template;
std::map<scheme_factory_interface::factory_identifier*, std::unique_ptr<scheme>> scheme_template;
};
color_schemes::color_schemes()
@ -70,7 +82,7 @@ namespace nana
delete impl_;
}
auto color_schemes::scheme_template(scheme_factory_base&& factory) -> scheme&
auto color_schemes::scheme_template(scheme_factory_interface&& factory) -> scheme&
{
auto & tmpl_scheme = impl_->scheme_template[factory.get_id()];
@ -81,7 +93,7 @@ namespace nana
return *tmpl_scheme.get();
}
widget_colors* color_schemes::create(scheme_factory_base&& factory)
widget_colors* color_schemes::create(scheme_factory_interface&& factory)
{
return factory.create(scheme_template(std::move(factory)));
}

View File

@ -1346,11 +1346,14 @@ namespace nana
splitter_.cursor(splitter_cursor_);
dragger_.trigger(splitter_);
splitter_.events().mouse_down.connect_unignorable([this](const arg_mouse& arg)
auto grab_fn = [this](const arg_mouse& arg)
{
if (false == arg.left_button)
return;
if (event_code::mouse_down == arg.evt_code)
{
begin_point_ = splitter_.pos();
auto px_ptr = &nana::rectangle::width;
@ -1373,13 +1376,9 @@ namespace nana
left_pixels_ = area_left.*px_ptr;
right_pixels_ = area_right.*px_ptr;
});
splitter_.events().mouse_move.connect_unignorable([this](const arg_mouse& arg)
}
else if (event_code::mouse_move == arg.evt_code)
{
if (false == arg.left_button)
return;
const bool vert = (::nana::cursor::size_we != splitter_cursor_);
auto area_px = rectangle_rotator(vert, div_owner->margin_area()).w();
int delta = (vert ? splitter_.pos().y - begin_point_.y : splitter_.pos().x - begin_point_.x);
@ -1413,7 +1412,11 @@ namespace nana
_m_leaf_right()->weight.reset();
pause_move_collocate_ = false;
});
}
};
splitter_.events().mouse_down.connect_unignorable(grab_fn);
splitter_.events().mouse_move.connect_unignorable(grab_fn);
}
auto limited_range = _m_update_splitter_range();
@ -1621,7 +1624,7 @@ namespace nana
indicator_.docker->z_order(nullptr, ::nana::z_order_action::topmost);
indicator_.docker->show();
indicator_.docker->events().destroy([this]
indicator_.docker->events().destroy([this](const arg_destroy&)
{
if (indicator_.dock_area)
{
@ -1764,7 +1767,10 @@ namespace nana
this->bgcolor(colors::alice_blue);
this->cursor(_m_is_vert(dir_) ? ::nana::cursor::size_ns : ::nana::cursor::size_we);
this->events().mouse_down([this](const arg_mouse& arg)
auto grab_fn = [this, wd](const arg_mouse& arg)
{
if (event_code::mouse_down == arg.evt_code) //press mouse button
{
if (arg.button != ::nana::mouse::left_button)
return;
@ -1779,14 +1785,8 @@ namespace nana
base_pos_.y = (is_vert ? basepos.y : basepos.x);
base_px_ = (is_vert ? pane_dv_->field_area.height : pane_dv_->field_area.width);
});
this->events().mouse_up([this]
{
API::capture_window(this->handle(), false);
});
this->events().mouse_move([this, wd](const arg_mouse& arg)
}
else if (event_code::mouse_move == arg.evt_code) //hover
{
if (!arg.is_left_button())
return;
@ -1838,7 +1838,15 @@ namespace nana
pane_dv_->weight.assign_percent(double(px) / double(dock_px) * 100);
dock_dv_->collocate(wd);
});
}
else
API::capture_window(this->handle(), false); //release mouse button
};
auto & evt = this->events();
evt.mouse_down(grab_fn);
evt.mouse_up(grab_fn);
evt.mouse_move(grab_fn);
}
void range(int begin, int end)
@ -1867,6 +1875,7 @@ namespace nana
if (i->get()->display)
return i->get();
}
return nullptr;
}

View File

@ -1,7 +1,7 @@
/*
* Parts of Class Place
* 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
@ -233,7 +233,9 @@ namespace nana
}
});
caption_.events().mouse_down([this](const arg_mouse& arg)
auto grab_fn = [this](const arg_mouse& arg)
{
if (event_code::mouse_down == arg.evt_code)
{
if (::nana::mouse::left_button == arg.button)
{
@ -242,9 +244,8 @@ namespace nana
moves_.start_container_pos = (floating() ? container_->pos() : this->pos());
API::capture_window(caption_, true);
}
});
caption_.events().mouse_move([this](const arg_mouse& arg)
}
else if (event_code::mouse_move == arg.evt_code)
{
if (arg.left_button && moves_.started)
{
@ -261,9 +262,8 @@ namespace nana
notifier_->notify_move();
}
}
});
caption_.events().mouse_up([this](const arg_mouse& arg)
}
else if (event_code::mouse_up == arg.evt_code)
{
if ((::nana::mouse::left_button == arg.button) && moves_.started)
{
@ -271,7 +271,12 @@ namespace nana
API::capture_window(caption_, false);
notifier_->notify_move_stopped();
}
});
}
};
caption_.events().mouse_down(grab_fn);
caption_.events().mouse_move(grab_fn);
caption_.events().mouse_up(grab_fn);
}
@ -293,13 +298,13 @@ namespace nana
tabbar_.reset(new tabbar_lite(*this));
tabbar_->events().selected.clear();
tabbar_->events().selected([this]
tabbar_->events().selected([this](const event_arg&)
{
auto handle = tabbar_->attach(tabbar_->selected());
if (handle)
//Set caption through a caption of window specified by handle
//Empty if handle is null
caption_.caption(API::window_caption(handle));
else
caption_.caption(::std::string());
});
tabbar_->move({ 0, r.bottom() - 20, r.width, 20 });
@ -320,7 +325,7 @@ namespace nana
if (tabbar_)
{
tabbar_->push_back(::nana::charset(wdg->caption()));
tabbar_->push_back(wdg->caption());
tabbar_->attach(panels_.size(), wdg->handle());
}

View File

@ -55,9 +55,9 @@ namespace API
namespace detail
{
::nana::widget_colors* make_scheme(::nana::detail::scheme_factory_base&& factory)
::nana::widget_colors* make_scheme(::nana::detail::scheme_factory_interface&& factory)
{
return restrict::bedrock.make_scheme(static_cast<::nana::detail::scheme_factory_base&&>(factory));
return restrict::bedrock.make_scheme(static_cast<::nana::detail::scheme_factory_interface&&>(factory));
}
bool emit_event(event_code evt_code, window wd, const ::nana::event_arg& arg)

View File

@ -1,6 +1,6 @@
/*
* The fundamental widget class implementation
* 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
@ -370,6 +370,24 @@ namespace nana
{
return std::unique_ptr<widget_notifier_interface>(new widget::inner_widget_notifier(*wdg));
}
//class widget_base
widget_base::~widget_base()
{
if (handle_)
API::close_window(handle_);
}
window widget_base::handle() const
{
return handle_;
}
void widget_base::_m_notify_destroy()
{
handle_ = nullptr;
}
//end class widget_base
}
}//end namespace nana