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

@@ -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,74 +1346,77 @@ 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;
begin_point_ = splitter_.pos();
auto px_ptr = &nana::rectangle::width;
//Use field_area of leaf, not margin_area. Otherwise splitter would be at wrong position
auto area_left = _m_leaf_left()->field_area;
auto area_right = _m_leaf_right()->field_area;
if (nana::cursor::size_we != splitter_cursor_)
if (event_code::mouse_down == arg.evt_code)
{
left_pos_ = area_left.y;
right_pos_ = area_right.bottom();
px_ptr = &nana::rectangle::height;
begin_point_ = splitter_.pos();
auto px_ptr = &nana::rectangle::width;
//Use field_area of leaf, not margin_area. Otherwise splitter would be at wrong position
auto area_left = _m_leaf_left()->field_area;
auto area_right = _m_leaf_right()->field_area;
if (nana::cursor::size_we != splitter_cursor_)
{
left_pos_ = area_left.y;
right_pos_ = area_right.bottom();
px_ptr = &nana::rectangle::height;
}
else
{
left_pos_ = area_left.x;
right_pos_ = area_right.right();
}
left_pixels_ = area_left.*px_ptr;
right_pixels_ = area_right.*px_ptr;
}
else
else if (event_code::mouse_move == arg.evt_code)
{
left_pos_ = area_left.x;
right_pos_ = area_right.right();
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);
int total_pixels = static_cast<int>(left_pixels_ + right_pixels_);
auto left_px = static_cast<int>(left_pixels_) + delta;
if (left_px > total_pixels)
left_px = total_pixels;
else if (left_px < 0)
left_px = 0;
double imd_rate = 100.0 / area_px;
left_px = static_cast<int>(limit_px(_m_leaf_left(), left_px, area_px));
_m_leaf_left()->weight.assign_percent(imd_rate * left_px);
auto right_px = static_cast<int>(right_pixels_) - delta;
if (right_px > total_pixels)
right_px = total_pixels;
else if (right_px < 0)
right_px = 0;
right_px = static_cast<int>(limit_px(_m_leaf_right(), right_px, area_px));
_m_leaf_right()->weight.assign_percent(imd_rate * right_px);
pause_move_collocate_ = true;
div_owner->collocate(splitter_.parent());
//After the collocating, the splitter keeps the calculated weight of left division,
//and clear the weight of right division.
_m_leaf_right()->weight.reset();
pause_move_collocate_ = false;
}
};
left_pixels_ = area_left.*px_ptr;
right_pixels_ = area_right.*px_ptr;
});
splitter_.events().mouse_move.connect_unignorable([this](const arg_mouse& arg)
{
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);
int total_pixels = static_cast<int>(left_pixels_ + right_pixels_);
auto left_px = static_cast<int>(left_pixels_)+delta;
if (left_px > total_pixels)
left_px = total_pixels;
else if (left_px < 0)
left_px = 0;
double imd_rate = 100.0 / area_px;
left_px = static_cast<int>(limit_px(_m_leaf_left(), left_px, area_px));
_m_leaf_left()->weight.assign_percent(imd_rate * left_px);
auto right_px = static_cast<int>(right_pixels_)-delta;
if (right_px > total_pixels)
right_px = total_pixels;
else if (right_px < 0)
right_px = 0;
right_px = static_cast<int>(limit_px(_m_leaf_right(), right_px, area_px));
_m_leaf_right()->weight.assign_percent(imd_rate * right_px);
pause_move_collocate_ = true;
div_owner->collocate(splitter_.parent());
//After the collocating, the splitter keeps the calculated weight of left division,
//and clear the weight of right division.
_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,81 +1767,86 @@ 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 (arg.button != ::nana::mouse::left_button)
return;
bool is_vert = _m_is_vert(dir_);
API::capture_window(this->handle(), true);
auto basepos = API::cursor_position();
base_pos_.x = (is_vert ? basepos.y : basepos.x);
basepos = this->pos();
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)
{
if (!arg.is_left_button())
return;
auto now_pos = API::cursor_position();
int delta = (_m_is_vert(dir_) ? now_pos.y : now_pos.x) - base_pos_.x;
int new_pos = base_pos_.y + delta;
if (new_pos < range_.x)
if (event_code::mouse_down == arg.evt_code) //press mouse button
{
new_pos = range_.x;
delta = new_pos - base_pos_.y;
}
else if (new_pos >= range_.y)
{
new_pos = range_.y - 1;
delta = new_pos - base_pos_.y;
}
if (arg.button != ::nana::mouse::left_button)
return;
now_pos = this->pos();
if (_m_is_vert(dir_))
now_pos.y = new_pos;
bool is_vert = _m_is_vert(dir_);
API::capture_window(this->handle(), true);
auto basepos = API::cursor_position();
base_pos_.x = (is_vert ? basepos.y : basepos.x);
basepos = this->pos();
base_pos_.y = (is_vert ? basepos.y : basepos.x);
base_px_ = (is_vert ? pane_dv_->field_area.height : pane_dv_->field_area.width);
}
else if (event_code::mouse_move == arg.evt_code) //hover
{
if (!arg.is_left_button())
return;
auto now_pos = API::cursor_position();
int delta = (_m_is_vert(dir_) ? now_pos.y : now_pos.x) - base_pos_.x;
int new_pos = base_pos_.y + delta;
if (new_pos < range_.x)
{
new_pos = range_.x;
delta = new_pos - base_pos_.y;
}
else if (new_pos >= range_.y)
{
new_pos = range_.y - 1;
delta = new_pos - base_pos_.y;
}
now_pos = this->pos();
if (_m_is_vert(dir_))
now_pos.y = new_pos;
else
now_pos.x = new_pos;
this->move(now_pos);
auto px = base_px_;
switch (dir_)
{
case ::nana::direction::west:
case ::nana::direction::north:
if (delta < 0)
px -= static_cast<unsigned>(-delta);
else
px += static_cast<unsigned>(delta);
break;
case ::nana::direction::east:
case ::nana::direction::south:
if (delta < 0)
px += static_cast<unsigned>(-delta);
else
px -= static_cast<unsigned>(delta);
break;
default:
break;
}
auto dock_px = (_m_is_vert(dir_) ? dock_dv_->field_area.height : dock_dv_->field_area.width);
pane_dv_->weight.assign_percent(double(px) / double(dock_px) * 100);
dock_dv_->collocate(wd);
}
else
now_pos.x = new_pos;
this->move(now_pos);
API::capture_window(this->handle(), false); //release mouse button
};
auto px = base_px_;
switch (dir_)
{
case ::nana::direction::west:
case ::nana::direction::north:
if (delta < 0)
px -= static_cast<unsigned>(-delta);
else
px += static_cast<unsigned>(delta);
break;
case ::nana::direction::east:
case ::nana::direction::south:
if (delta < 0)
px += static_cast<unsigned>(-delta);
else
px -= static_cast<unsigned>(delta);
break;
default:
break;
}
auto dock_px = (_m_is_vert(dir_) ? dock_dv_->field_area.height : dock_dv_->field_area.width);
pane_dv_->weight.assign_percent(double(px) / double(dock_px) * 100);
dock_dv_->collocate(wd);
});
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,45 +233,50 @@ namespace nana
}
});
caption_.events().mouse_down([this](const arg_mouse& arg)
auto grab_fn = [this](const arg_mouse& arg)
{
if (::nana::mouse::left_button == arg.button)
if (event_code::mouse_down == arg.evt_code)
{
moves_.started = true;
moves_.start_pos = API::cursor_position();
moves_.start_container_pos = (floating() ? container_->pos() : this->pos());
API::capture_window(caption_, true);
}
});
caption_.events().mouse_move([this](const arg_mouse& arg)
{
if (arg.left_button && moves_.started)
{
auto move_pos = API::cursor_position() - moves_.start_pos;
if (!floating())
if (::nana::mouse::left_button == arg.button)
{
if (std::abs(move_pos.x) > 4 || std::abs(move_pos.y) > 4)
float_away(move_pos);
}
else
{
move_pos += moves_.start_container_pos;
API::move_window(container_->handle(), move_pos);
notifier_->notify_move();
moves_.started = true;
moves_.start_pos = API::cursor_position();
moves_.start_container_pos = (floating() ? container_->pos() : this->pos());
API::capture_window(caption_, true);
}
}
});
caption_.events().mouse_up([this](const arg_mouse& arg)
{
if ((::nana::mouse::left_button == arg.button) && moves_.started)
else if (event_code::mouse_move == arg.evt_code)
{
moves_.started = false;
API::capture_window(caption_, false);
notifier_->notify_move_stopped();
if (arg.left_button && moves_.started)
{
auto move_pos = API::cursor_position() - moves_.start_pos;
if (!floating())
{
if (std::abs(move_pos.x) > 4 || std::abs(move_pos.y) > 4)
float_away(move_pos);
}
else
{
move_pos += moves_.start_container_pos;
API::move_window(container_->handle(), move_pos);
notifier_->notify_move();
}
}
}
});
else if (event_code::mouse_up == arg.evt_code)
{
if ((::nana::mouse::left_button == arg.button) && moves_.started)
{
moves_.started = false;
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)
caption_.caption(API::window_caption(handle));
else
caption_.caption(::std::string());
//Set caption through a caption of window specified by handle
//Empty if handle is null
caption_.caption(API::window_caption(handle));
});
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