Merge remote-tracking branch 'cnjinhao/develop' into develop

This commit is contained in:
qPCR4vir 2017-08-21 09:11:20 +02:00
commit e1c1976e2f
11 changed files with 285 additions and 233 deletions

View File

@ -46,7 +46,7 @@ namespace nana
/// Construct that creates a message box with a specified title and default button.
msgbox(const ::std::string&);
/// Construct that creates a message box with an owner windoow, a specified title and buttons.
/// Construct that creates a message box with an owner windoow, a specified title and buttons.
msgbox(window, const ::std::string&, button_t = ok);
/// Sets an icon for informing user.
@ -108,6 +108,7 @@ namespace nana
virtual window create(window, unsigned label_px) = 0;
virtual unsigned fixed_pixels() const;
};
public:
class boolean
: public abstract_content
@ -240,7 +241,6 @@ namespace nana
{
std::vector<abstract_content*> contents;
_m_fetch_args(contents, std::forward<Args>(args)...);
if (contents.empty())
return false;
@ -261,6 +261,14 @@ namespace nana
/// Sets a verifier to verify the user input.
void verify(std::function<bool(window)> verifier);
/** Sets the minimum width for the entry fields
@param[in] pixels new minimum width
If not called, the default is 100 pixels
*/
void min_width_entry_field( unsigned pixels );
private:
void _m_fetch_args(std::vector<abstract_content*>&);
@ -279,6 +287,7 @@ namespace nana
std::function<bool(window)> verifier_;
::nana::paint::image images_[4];
::nana::rectangle valid_areas_[4];
int min_width_entry_field_pixels_;
};
}//end namespace nana
#include <nana/pop_ignore_diagnostic>

View File

@ -535,7 +535,7 @@ namespace nana
throw std::invalid_argument("invalid listbox model container type");
if (nullptr == p->pointer())
throw std::runtime_error("the modal is immutable");
throw std::runtime_error("the modal is immutable, please declare model_guard with const");
return *static_cast<stlcontainer*>(p->pointer());
}
@ -1254,8 +1254,9 @@ By \a clicking on one header the list get \a reordered, first up, and then down
}
return false;
}
listbox.anyobj(0, 0, 10); //the type of customer's object is int.
listbox.anyobj(0, 0, 20);
auto cat = listbox.at(0);
cat.at(0).value(10); //10 is custom data.
cat.at(1).value(20); //20 is custom data.
5. listbox is a widget_object, with template parameters drawerbase::listbox::trigger and drawerbase::listbox::scheme
amon others.
That means that listbox have a member trigger_ constructed first and accecible with get_drawer_trigger() and

View File

@ -1,7 +1,7 @@
/**
* A Progress Indicator Implementation
* Nana C++ Library(http://www.nanapro.org)
* Copyright(C) 2003-2015 Jinhao(cnjinhao@hotmail.com)
* Copyright(C) 2003-2017 Jinhao(cnjinhao@hotmail.com)
*
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at
@ -20,42 +20,37 @@ namespace nana
{
namespace progress
{
class trigger: public drawer_trigger
struct scheme
: public widget_geometrics
{
scheme();
color_proxy gradient_bgcolor{ colors::button_face_shadow_start };
color_proxy gradient_fgcolor{ static_cast<color_rgb>(0x6FFFA8) };
};
class substance;
class trigger
: public drawer_trigger
{
public:
unsigned value() const;
unsigned value(unsigned);
unsigned inc();
unsigned Max() const;
unsigned Max(unsigned);
void unknown(bool);
bool unknown() const;
bool stop(bool s = true);
bool stopped() const;
private:
void attached(widget_reference, graph_reference) override;
void refresh(graph_reference) override;
private:
void _m_draw_box(graph_reference);
void _m_draw_progress(graph_reference);
bool _m_check_changing(unsigned) const;
private:
static const unsigned border = 2;
trigger();
~trigger();
widget * widget_{nullptr};
nana::paint::graphics* graph_{nullptr};
unsigned draw_width_{static_cast<unsigned>(-1)};
bool unknown_{false};
bool stop_{false};
unsigned max_{100};
unsigned value_{0};
}; //end class drawer
substance* progress() const;
private:
void attached(widget_reference, graph_reference) override;
void refresh(graph_reference) override;
private:
substance* const progress_;
};
}
}//end namespace drawerbase
/// \brief A progressbar widget with two styles: know, and unknow amount value (goal).
/// In unknow style the amount is ignored and the bar is scrolled when value change.
class progress
: public widget_object<category::widget_tag, drawerbase::progress::trigger>
class progress
: public widget_object<category::widget_tag, drawerbase::progress::trigger, ::nana::general_events, drawerbase::progress::scheme>
{
public:
progress();
@ -69,8 +64,6 @@ namespace nana
unsigned amount(unsigned value);
void unknown(bool);
bool unknown() const;
bool stop(bool s=true); ///< request stop or cancel and return previus stop status
bool stopped() const;
};
}//end namespace nana
#endif

View File

@ -114,8 +114,30 @@ namespace nana
return false;
}
for (auto* parent = wd->parent; parent; parent = parent->parent)
for (auto parent = wd->parent; parent; parent = parent->parent)
{
if (category::flags::root == parent->other.category)
{
//visual rectangle of wd's parent
rectangle vrt_parent{parent->pos_root, parent->dimension};
point pos_root;
while (parent->parent)
{
pos_root -= native_interface::window_position(parent->root);
if (!overlap(rectangle{ pos_root, parent->parent->root_widget->dimension }, vrt_parent, vrt_parent))
return false;
parent = parent->parent->root_widget;
}
if (!overlap(vrt_parent, visual, visual))
return false;
return true;
}
if (!overlap(rectangle{ parent->pos_root, parent->dimension }, visual, visual))
return false;
}

View File

@ -733,30 +733,6 @@ namespace detail
}
}
void sync_child_root_display(window_manager::core_window_t* wd)
{
for (auto & child : wd->children)
{
if (category::flags::root != child->other.category)
{
sync_child_root_display(child);
continue;
}
auto const vs_parents = child->visible_parents();
if (vs_parents != child->visible)
{
native_interface::show_window(child->root, vs_parents, false);
}
else
{
if (child->visible != native_interface::is_window_visible(child->root))
native_interface::show_window(child->root, child->visible, false);
}
}
}
//show
//@brief: show or hide a window
bool window_manager::show(core_window_t* wd, bool visible)
@ -792,14 +768,7 @@ namespace detail
bedrock::instance().event_expose(wd, visible);
if (nv)
{
if (visible && !wd->visible_parents())
return true;
native_interface::show_window(nv, visible, wd->flags.take_active);
}
sync_child_root_display(wd);
}
return true;
}

View File

@ -8,6 +8,8 @@
* http://www.boost.org/LICENSE_1_0.txt)
*
* @file: nana/gui/msgbox.hpp
* @Contributors
* James Bremner
*/
#include <nana/gui.hpp>
@ -685,7 +687,7 @@ namespace nana
{
return impl_->empty_label_text;
}
window inputbox::boolean::create(window owner, unsigned label_px)
{
auto impl = impl_.get();
@ -1258,7 +1260,8 @@ namespace nana
inputbox::inputbox(window owner, ::std::string desc, ::std::string title)
: owner_{ owner },
description_(std::move(desc)),
title_(std::move(title))
title_(std::move(title)),
min_width_entry_field_pixels_( 100 )
{}
void inputbox::image(::nana::paint::image img, bool is_left, const rectangle& valid_area)
@ -1280,6 +1283,17 @@ namespace nana
verifier_ = std::move(verifier);
}
//Inputbox set minimum width entry field(https://github.com/cnjinhao/nana/pull/234)
//Contributed by James Bremner
void inputbox::min_width_entry_field( unsigned pixels )
{
// don't let the entry fields vanish entirely
if( pixels < 10 )
pixels = 10;
min_width_entry_field_pixels_ = pixels;
}
void inputbox::_m_fetch_args(std::vector<abstract_content*>&)
{}
@ -1304,9 +1318,9 @@ namespace nana
each_pixels.push_back(px.height);
}
//Adjust the fixed_px for good looking
if (has_0_fixed_px && (fixed_px < 100))
fixed_px = 100;
//Ensure that the entry fields are at least as wide as the minimum
if (has_0_fixed_px && (fixed_px < min_width_entry_field_pixels_ ))
fixed_px = min_width_entry_field_pixels_;
inputbox_window input_wd(owner_, images_, valid_areas_, description_, title_, contents.size(), label_px + 10 + fixed_px, each_pixels);

View File

@ -143,6 +143,7 @@ namespace nana
auto scheme = dynamic_cast< ::nana::widgets::skeletons::text_editor_scheme*>(API::dev::get_scheme(wd));
editor_ = new widgets::skeletons::text_editor(widget_->handle(), graph, scheme);
_m_text_area(graph.size());
editor_->multi_lines(false);
editable(false);
graph_ = &graph;
@ -177,21 +178,6 @@ namespace nana
return any_ptr.get();
}
void text_area(const nana::size& s)
{
auto extension = measurer_->extension();
nana::rectangle r(2, 2, s.width > extension.width ? s.width - extension.width : 0, s.height > extension.height ? s.height - extension.height : 0);
if(image_enabled_)
{
unsigned place = image_pixels_ + 2;
r.x += place;
if(r.width > place) r.width -= place;
}
editor_->text_area(r);
editor_->render(state_.focused);
}
widgets::skeletons::text_editor * editor() const
{
return editor_;
@ -364,12 +350,13 @@ namespace nana
void draw()
{
bool enb = widget_->enabled();
if(editor_)
{
text_area(widget_->size());
}
_m_text_area(widget_->size());
editor_->render(state_.focused);
_m_draw_push_button(enb);
_m_draw_image();
}
std::size_t the_number_of_options() const
@ -496,6 +483,20 @@ namespace nana
return true;
}
private:
void _m_text_area(const nana::size& s)
{
auto extension = measurer_->extension();
nana::rectangle r(2, 2, s.width > extension.width ? s.width - extension.width : 0, s.height > extension.height ? s.height - extension.height : 0);
if (image_enabled_)
{
unsigned place = image_pixels_ + 2;
r.x += place;
if (r.width > place) r.width -= place;
}
editor_->text_area(r);
}
void _m_draw_push_button(bool enabled)
{
::nana::rectangle r{graph_->size()};

View File

@ -624,10 +624,14 @@ namespace nana
}
else if (item_ptr->flags.enabled)
{
//A pointer refers to a menu object which owns the menu window.
//After fn_close_tree_(), *this is an invalid object.
auto owner = menu_->owner;
fn_close_tree_();
if (item_ptr->event_handler)
{
item_proxy ip{ index, menu_->owner };
item_proxy ip{ index, owner };
item_ptr->event_handler.operator()(ip);
}
return 1;
@ -1019,13 +1023,18 @@ namespace nana
close();
break;
default:
if (2 != send_shortkey(arg.key))
switch (send_shortkey(arg.key))
{
if (API::empty_window(*this) == false)
case 0:
if (this->empty() == false)
close();
}
else
break;
case 1: //The menu has been closed
break;
case 2:
this->submenu(true);
break;
}
}
}

View File

@ -1,6 +1,6 @@
/*
* A Progress Indicator Implementation
* Copyright(C) 2003-2013 Jinhao(cnjinhao@hotmail.com)
* Copyright(C) 2003-2017 Jinhao(cnjinhao@hotmail.com)
*
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at
@ -17,136 +17,187 @@ namespace nana
{
namespace progress
{
//class trigger
void trigger::attached(widget_reference wd, graph_reference graph)
scheme::scheme()
{
widget_ = &wd;
graph_ = &graph;
foreground = static_cast<color_rgb>(0x107515);
}
unsigned trigger::value() const
class substance
{
return value_;
}
public:
static const unsigned border_px = 1;
unsigned trigger::value(unsigned v)
{
internal_scope_guard isg;
if(false == unknown_)
void set_widget(widget& wdg)
{
if(value_ != v)
value_ = v > max_?max_:v;
widget_ = static_cast<nana::progress*>(&wdg);
}
else
value_ += (v?10:v);
if(_m_check_changing(value_))
nana::progress* widget_ptr() const
{
refresh(*graph_);
API::update_window(widget_->handle());
return widget_;
}
return v;
}
unsigned trigger::inc()
{
internal_scope_guard isg;
if(false == unknown_)
unsigned inc()
{
if(value_ < max_)
++value_;
auto val = value(nullptr) + 1;
return value(&val);
}
else
value_ += 5;
if(_m_check_changing(value_))
API::refresh_window(widget_->handle());
return value_;
unsigned value(const unsigned* value_ptr)
{
//Sets new value if value_ptr is not a nullptr
if (value_ptr)
{
if (unknown_)
value_ += (*value_ptr ? 5 : 0);
else
value_ = (std::min)(max_, *value_ptr);
_m_try_refresh();
}
return value_;
}
void reset_value()
{
value_ = 0;
}
unsigned maximum(const unsigned * value_ptr)
{
//Sets new maximum if value_ptr is not a nullptr
if (value_ptr)
{
max_ = (*value_ptr > 0 ? *value_ptr : 1);
_m_try_refresh();
}
return max_;
}
bool unknown(const bool* state_ptr)
{
if (state_ptr)
{
unknown_ = *state_ptr;
if (unknown_)
value_px_ = 0;
else
value_ = (std::min)(value_, max_);
}
return unknown_;
}
unsigned value_px() const
{
return value_px_;
}
private:
void _m_try_refresh()
{
if (nullptr == widget_)
return;
auto value_px = (widget_->size().width - border_px * 2) * value_ / max_;
if (value_px != value_px_)
{
value_px_ = value_px;
API::refresh_window(*widget_);
}
}
private:
nana::progress * widget_{ nullptr };
unsigned max_{ 100 };
unsigned value_{ 0 };
unsigned value_px_{ 0 };
bool unknown_{ false };
};
trigger::trigger()
: progress_(new substance)
{}
trigger::~trigger()
{
delete progress_;
}
unsigned trigger::Max() const
substance* trigger::progress() const
{
return max_;
return progress_;
}
unsigned trigger::Max(unsigned value)
void trigger::attached(widget_reference wdg, graph_reference)
{
max_ = value;
if(max_ == 0) ++max_;
API::refresh_window(widget_->handle());
return max_;
}
void trigger::unknown(bool enb)
{
unknown_ = enb;
if(enb)
draw_width_ = static_cast<unsigned>(-1);
}
bool trigger::unknown() const
{
return unknown_;
}
bool trigger::stopped() const
{
return stop_;
}
bool trigger::stop(bool s)
{
std::swap(s,stop_);
return s;
progress_->set_widget(wdg);
}
void trigger::refresh(graph_reference graph)
{
if (false == unknown_)
draw_width_ = static_cast<unsigned>((graph.width() - border * 2) * (double(value_) / max_));
{
const unsigned border_px = substance::border_px;
_m_draw_box(graph);
_m_draw_progress(graph);
}
unsigned width = graph.width() - border_px * 2;
unsigned height = graph.height() - border_px * 2;
void trigger::_m_draw_box(graph_reference graph)
{
rectangle r{ graph.size() };
graph.gradual_rectangle(r, colors::button_face_shadow_end, colors::button_face_shadow_start, true);
::nana::color lt{ colors::gray }, rb{colors::white};
graph.frame_rectangle(r, lt, lt, rb, rb);
}
rectangle rt_val{ graph.size() };
void trigger::_m_draw_progress(graph_reference graph)
{
unsigned width = graph.width() - border * 2;
unsigned height = graph.height() - border * 2;
rt_val.pare_off(static_cast<int>(border_px));
if(false == unknown_)
auto rt_bground = rt_val;
if (false == progress_->unknown(nullptr))
{
if(draw_width_)
graph.gradual_rectangle({ static_cast<int>(border), static_cast<int>(border), draw_width_, height }, { 0x6F, 0xFF, 0xA8 }, { 0x10, 0x75, 0x15 }, true);
rt_bground.x = static_cast<int>(progress_->value_px()) + static_cast<int>(border_px);
rt_bground.width -= progress_->value_px();
rt_val.width = progress_->value_px();
}
else
{
unsigned block = width / 3;
auto const block = width / 3;
int left = (value_ < block ? 0 : value_ - block) + border;
int right = (value_ >= width - 1 + border? width - 1 + border: value_);
auto const value = progress_->value(nullptr);
if(right >= left)
graph.gradual_rectangle({ left, static_cast<int>(border), static_cast<unsigned>(right - left + 1), height }, { 0x6F, 0xFF, 0xA8 }, { 0x10, 0x75, 0x15 }, true);
auto left = (std::max)(0, static_cast<int>(value - block)) + static_cast<int>(border_px);
auto right = static_cast<int>((std::min)(value, width + border_px -1));
if(value_ >= width + block) value_ = 0;
if (right > left)
{
rt_val.x = left;
rt_val.width = static_cast<unsigned>(right - left + 1);
}
else
rt_val.width = 0;
if (value >= width + block)
progress_->reset_value();
}
}
bool trigger::_m_check_changing(unsigned newvalue) const
{
if(graph_)
return (((graph_->width() - border * 2) * newvalue / max_) != draw_width_);
return false;
auto & sch = progress_->widget_ptr()->scheme();
//Draw the gradient background if gradient_bgcolor is available.
auto bgcolor = sch.background.get_color();
if (bgcolor.invisible())
bgcolor = colors::button_face;
if (sch.gradient_bgcolor.get_color().invisible())
graph.rectangle(rt_bground, true, bgcolor);
else
graph.gradual_rectangle(rt_bground, bgcolor, sch.gradient_bgcolor.get_color(), true);
//Draw the gradient fgcolor if gradient_fgcolor is available.
auto fgcolor = sch.foreground.get_color();
if (fgcolor.invisible())
fgcolor = static_cast<color_rgb>(0x107515);
if (sch.gradient_fgcolor.get_color().invisible())
graph.rectangle(rt_val, true, fgcolor);
else
graph.gradual_rectangle(rt_val, sch.gradient_fgcolor.get_color(), fgcolor, true);
graph.frame_rectangle(rectangle{ graph.size() }, colors::gray, colors::gray, colors::white, colors::white);
}
//end class drawer
}//end namespace progress
}//end namespace drawerbase
@ -165,49 +216,42 @@ namespace nana
unsigned progress::value() const
{
return get_drawer_trigger().value();
return get_drawer_trigger().progress()->value(nullptr);
}
unsigned progress::value(unsigned val)
{
internal_scope_guard isg;
internal_scope_guard lock;
if(API::empty_window(this->handle()) == false)
return get_drawer_trigger().value(val);
return get_drawer_trigger().progress()->value(&val);
return 0;
}
unsigned progress::inc()
{
internal_scope_guard isg;
return get_drawer_trigger().inc();
internal_scope_guard lock;
return get_drawer_trigger().progress()->inc();
}
unsigned progress::amount() const
{
return get_drawer_trigger().Max();
return get_drawer_trigger().progress()->maximum(nullptr);
}
unsigned progress::amount(unsigned value)
{
return get_drawer_trigger().Max(value);
return get_drawer_trigger().progress()->maximum(&value);
}
void progress::unknown(bool enb)
{
get_drawer_trigger().unknown(enb);
internal_scope_guard lock;
get_drawer_trigger().progress()->unknown(&enb);
}
bool progress::unknown() const
{
return get_drawer_trigger().unknown();
}
bool progress::stop(bool s)
{
return get_drawer_trigger().stop(s);
}
bool progress::stopped() const
{
return get_drawer_trigger().stopped();
return get_drawer_trigger().progress()->unknown(nullptr);
}
//end class progress
}//end namespace nana

View File

@ -887,6 +887,7 @@ namespace nana{ namespace widgets
return (pos < linemtr_.size() ? linemtr_[pos].take_lines : 0);
}
private:
/// Split a text into multiple sections, a section indicates an english word or a CKJ character
void _m_text_section(const std::wstring& str, std::vector<text_section>& tsec)
{
if (str.empty())
@ -1025,14 +1026,14 @@ namespace nana{ namespace widgets
if (pos)
{
auto chr = text[pos - 1];
if ((std::iswalpha(chr) && !std::isspace(chr)) || chr == '_')
if ((std::iswalpha(chr) && !std::iswspace(chr)) || chr == '_')
return false;
}
if (pos + len < text.size())
{
auto chr = text[pos + len];
if ((std::iswalpha(chr) && !std::isspace(chr)) || chr == '_')
if ((std::iswalpha(chr) && !std::iswspace(chr)) || chr == '_')
return false;
}
@ -1596,18 +1597,6 @@ namespace nana{ namespace widgets
if(!attributes_.enable_caret)
return false;
auto is_whitespace = [](wchar_t c) {
switch (c) {
case L' ':
case L'\t':
case L'\n':
case L'\r':
return true;
default:
return false;
}
};
// Set caret pos by screen point and get the caret pos.
mouse_caret(arg.pos, true);
@ -1616,11 +1605,11 @@ namespace nana{ namespace widgets
const auto& line = impl_->textbase.getline(select_.b.y);
// Expand the selection forward to the word's end.
while (select_.b.x < line.size() && !is_whitespace(line[select_.b.x]))
while (select_.b.x < line.size() && !std::iswspace(line[select_.b.x]))
++select_.b.x;
// Expand the selection backward to the word's start.
while (select_.a.x > 0 && !is_whitespace(line[select_.a.x - 1]))
while (select_.a.x > 0 && !std::iswspace(line[select_.a.x - 1]))
--select_.a.x;
select_.mode_selection = selection::mode::method_selected;
@ -2876,7 +2865,6 @@ namespace nana{ namespace widgets
return ('0' <= ch && ch <= '9');
}
::nana::color text_editor::_m_bgcolor() const
{
return (!API::window_enabled(window_) ? static_cast<color_rgb>(0xE0E0E0) : API::bgcolor(window_));

View File

@ -524,14 +524,16 @@ namespace nana
if((::nana::mouse_action::pressed == slider_state_.mouse_state) && (API::capture_window() == this->other_.wd))
return false;
auto state_changed = ((slider_state_.mouse_state != ::nana::mouse_action::normal)
|| (attr_.adorn_pos != attr_.slider.pos));
slider_state_.mouse_state = ::nana::mouse_action::normal;
attr_.is_draw_adorn = false;
if(attr_.adorn_pos != attr_.slider.pos)
{
attr_.adorn_pos = attr_.slider.pos;
return true;
}
return false;
attr_.adorn_pos = attr_.slider.pos;
slider_state_.mouse_state = ::nana::mouse_action::normal;
return state_changed;
}
private: