Merge remote-tracking branch 'cnjinhao/hotfix-1.5.5' into hotfix-1.5.4
This commit is contained in:
commit
e5fe759c7d
@ -14,7 +14,7 @@ NANAINC = $(NANAPATH)/include
|
|||||||
NANALIB = $(NANAPATH)/build/bin
|
NANALIB = $(NANAPATH)/build/bin
|
||||||
|
|
||||||
INCS = -I$(NANAINC)
|
INCS = -I$(NANAINC)
|
||||||
LIBS = -L$(NANALIB) -lnana -lX11 -lpthread -lrt -lXft -lpng -lasound
|
LIBS = -L$(NANALIB) -lnana -lX11 -lpthread -lrt -lXft -lpng -lasound -lfontconfig
|
||||||
|
|
||||||
LINKOBJ = $(SOURCES:.cpp=.o)
|
LINKOBJ = $(SOURCES:.cpp=.o)
|
||||||
|
|
||||||
|
@ -108,6 +108,7 @@ namespace nana
|
|||||||
virtual window create(window, unsigned label_px) = 0;
|
virtual window create(window, unsigned label_px) = 0;
|
||||||
virtual unsigned fixed_pixels() const;
|
virtual unsigned fixed_pixels() const;
|
||||||
};
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
class boolean
|
class boolean
|
||||||
: public abstract_content
|
: public abstract_content
|
||||||
@ -240,7 +241,6 @@ namespace nana
|
|||||||
{
|
{
|
||||||
std::vector<abstract_content*> contents;
|
std::vector<abstract_content*> contents;
|
||||||
_m_fetch_args(contents, std::forward<Args>(args)...);
|
_m_fetch_args(contents, std::forward<Args>(args)...);
|
||||||
|
|
||||||
if (contents.empty())
|
if (contents.empty())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@ -261,6 +261,14 @@ namespace nana
|
|||||||
|
|
||||||
/// Sets a verifier to verify the user input.
|
/// Sets a verifier to verify the user input.
|
||||||
void verify(std::function<bool(window)> verifier);
|
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:
|
private:
|
||||||
void _m_fetch_args(std::vector<abstract_content*>&);
|
void _m_fetch_args(std::vector<abstract_content*>&);
|
||||||
|
|
||||||
@ -279,6 +287,7 @@ namespace nana
|
|||||||
std::function<bool(window)> verifier_;
|
std::function<bool(window)> verifier_;
|
||||||
::nana::paint::image images_[4];
|
::nana::paint::image images_[4];
|
||||||
::nana::rectangle valid_areas_[4];
|
::nana::rectangle valid_areas_[4];
|
||||||
|
unsigned min_width_entry_field_pixels_;
|
||||||
};
|
};
|
||||||
}//end namespace nana
|
}//end namespace nana
|
||||||
#include <nana/pop_ignore_diagnostic>
|
#include <nana/pop_ignore_diagnostic>
|
||||||
|
@ -57,8 +57,6 @@ namespace nana
|
|||||||
class trigger
|
class trigger
|
||||||
: public drawer_trigger
|
: public drawer_trigger
|
||||||
{
|
{
|
||||||
class itembase;
|
|
||||||
|
|
||||||
struct essence;
|
struct essence;
|
||||||
public:
|
public:
|
||||||
trigger();
|
trigger();
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
/**
|
/**
|
||||||
* A Progress Indicator Implementation
|
* A Progress Indicator Implementation
|
||||||
* 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-2017 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
|
||||||
@ -20,42 +20,37 @@ namespace nana
|
|||||||
{
|
{
|
||||||
namespace progress
|
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:
|
public:
|
||||||
unsigned value() const;
|
trigger();
|
||||||
unsigned value(unsigned);
|
~trigger();
|
||||||
unsigned inc();
|
|
||||||
unsigned Max() const;
|
substance* progress() const;
|
||||||
unsigned Max(unsigned);
|
|
||||||
void unknown(bool);
|
|
||||||
bool unknown() const;
|
|
||||||
bool stop(bool s = true);
|
|
||||||
bool stopped() const;
|
|
||||||
private:
|
private:
|
||||||
void attached(widget_reference, graph_reference) override;
|
void attached(widget_reference, graph_reference) override;
|
||||||
void refresh(graph_reference) override;
|
void refresh(graph_reference) override;
|
||||||
private:
|
private:
|
||||||
void _m_draw_box(graph_reference);
|
substance* const progress_;
|
||||||
void _m_draw_progress(graph_reference);
|
};
|
||||||
bool _m_check_changing(unsigned) const;
|
|
||||||
private:
|
|
||||||
static const unsigned border = 2;
|
|
||||||
|
|
||||||
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
|
|
||||||
}
|
}
|
||||||
}//end namespace drawerbase
|
}//end namespace drawerbase
|
||||||
/// \brief A progressbar widget with two styles: know, and unknow amount value (goal).
|
/// \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.
|
/// In unknow style the amount is ignored and the bar is scrolled when value change.
|
||||||
class progress
|
class progress
|
||||||
: public widget_object<category::widget_tag, drawerbase::progress::trigger>
|
: public widget_object<category::widget_tag, drawerbase::progress::trigger, ::nana::general_events, drawerbase::progress::scheme>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
progress();
|
progress();
|
||||||
@ -69,8 +64,6 @@ namespace nana
|
|||||||
unsigned amount(unsigned value);
|
unsigned amount(unsigned value);
|
||||||
void unknown(bool);
|
void unknown(bool);
|
||||||
bool unknown() const;
|
bool unknown() const;
|
||||||
bool stop(bool s=true); ///< request stop or cancel and return previus stop status
|
|
||||||
bool stopped() const;
|
|
||||||
};
|
};
|
||||||
}//end namespace nana
|
}//end namespace nana
|
||||||
#endif
|
#endif
|
||||||
|
@ -78,7 +78,7 @@ namespace nana{ namespace audio
|
|||||||
void buffer_preparation::revert(meta * m)
|
void buffer_preparation::revert(meta * m)
|
||||||
{
|
{
|
||||||
std::lock_guard<decltype(token_prepared_)> lock(token_prepared_);
|
std::lock_guard<decltype(token_prepared_)> lock(token_prepared_);
|
||||||
bool if_signal = prepared_.empty();
|
auto const if_signal = prepared_.empty();
|
||||||
prepared_.emplace_back(m);
|
prepared_.emplace_back(m);
|
||||||
if(if_signal)
|
if(if_signal)
|
||||||
cond_prepared_.notify_one();
|
cond_prepared_.notify_one();
|
||||||
|
@ -8,6 +8,8 @@
|
|||||||
* http://www.boost.org/LICENSE_1_0.txt)
|
* http://www.boost.org/LICENSE_1_0.txt)
|
||||||
*
|
*
|
||||||
* @file: nana/gui/msgbox.hpp
|
* @file: nana/gui/msgbox.hpp
|
||||||
|
* @Contributors
|
||||||
|
* James Bremner
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <nana/gui.hpp>
|
#include <nana/gui.hpp>
|
||||||
@ -1258,7 +1260,8 @@ namespace nana
|
|||||||
inputbox::inputbox(window owner, ::std::string desc, ::std::string title)
|
inputbox::inputbox(window owner, ::std::string desc, ::std::string title)
|
||||||
: owner_{ owner },
|
: owner_{ owner },
|
||||||
description_(std::move(desc)),
|
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)
|
void inputbox::image(::nana::paint::image img, bool is_left, const rectangle& valid_area)
|
||||||
@ -1280,6 +1283,17 @@ namespace nana
|
|||||||
verifier_ = std::move(verifier);
|
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*>&)
|
void inputbox::_m_fetch_args(std::vector<abstract_content*>&)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
@ -1304,9 +1318,9 @@ namespace nana
|
|||||||
each_pixels.push_back(px.height);
|
each_pixels.push_back(px.height);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Adjust the fixed_px for good looking
|
//Ensure that the entry fields are at least as wide as the minimum
|
||||||
if (has_0_fixed_px && (fixed_px < 100))
|
if (has_0_fixed_px && (fixed_px < min_width_entry_field_pixels_ ))
|
||||||
fixed_px = 100;
|
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);
|
inputbox_window input_wd(owner_, images_, valid_areas_, description_, title_, contents.size(), label_px + 10 + fixed_px, each_pixels);
|
||||||
|
|
||||||
|
@ -30,71 +30,31 @@ namespace nana
|
|||||||
{
|
{
|
||||||
struct item_type
|
struct item_type
|
||||||
{
|
{
|
||||||
item_type(const native_string_type& text, unsigned long shortkey)
|
item_type(std::string&& text, wchar_t shortkey, std::size_t shortkey_pos):
|
||||||
: text(text), shortkey(shortkey)
|
text(std::move(text)),
|
||||||
|
shortkey(shortkey),
|
||||||
|
shortkey_pos(shortkey_pos)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
native_string_type text;
|
std::string text; ///< Transformed text, the shortkey charactor has been proccessed.
|
||||||
unsigned long shortkey;
|
wchar_t shortkey;
|
||||||
|
std::size_t shortkey_pos;
|
||||||
::nana::menu menu_obj;
|
::nana::menu menu_obj;
|
||||||
::nana::point pos;
|
::nana::point pos;
|
||||||
::nana::size size;
|
::nana::size size;
|
||||||
};
|
};
|
||||||
|
|
||||||
class trigger::itembase
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
using container = std::vector<item_type*>;
|
|
||||||
|
|
||||||
~itembase()
|
|
||||||
{
|
|
||||||
for(auto i : cont_)
|
|
||||||
delete i;
|
|
||||||
}
|
|
||||||
|
|
||||||
void append(const native_string_type& text, unsigned long shortkey)
|
|
||||||
{
|
|
||||||
if(shortkey && shortkey < 0x61) shortkey += (0x61 - 0x41);
|
|
||||||
cont_.emplace_back(new item_type(text, shortkey));
|
|
||||||
}
|
|
||||||
|
|
||||||
std::size_t find(unsigned long shortkey) const
|
|
||||||
{
|
|
||||||
if(shortkey)
|
|
||||||
{
|
|
||||||
if(shortkey < 0x61) shortkey += (0x61 - 0x41);
|
|
||||||
|
|
||||||
std::size_t index = 0;
|
|
||||||
for(auto i : cont_)
|
|
||||||
{
|
|
||||||
if(i->shortkey == shortkey)
|
|
||||||
return index;
|
|
||||||
++index;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return npos;
|
|
||||||
}
|
|
||||||
|
|
||||||
const container& cont() const
|
|
||||||
{
|
|
||||||
return cont_;
|
|
||||||
}
|
|
||||||
private:
|
|
||||||
container cont_;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct trigger::essence
|
struct trigger::essence
|
||||||
{
|
{
|
||||||
widget *widget_ptr{ nullptr };
|
|
||||||
//paint::graphics *graph{ nullptr };
|
|
||||||
|
|
||||||
itembase items;
|
|
||||||
|
|
||||||
enum class behavior
|
enum class behavior
|
||||||
{
|
{
|
||||||
none, focus, menu,
|
none, focus, menu,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
widget *widget_ptr{ nullptr };
|
||||||
|
std::vector<item_type*> items;
|
||||||
|
|
||||||
struct state_type
|
struct state_type
|
||||||
{
|
{
|
||||||
std::size_t active{ nana::npos };
|
std::size_t active{ nana::npos };
|
||||||
@ -110,18 +70,30 @@ namespace nana
|
|||||||
}state;
|
}state;
|
||||||
|
|
||||||
//functions
|
//functions
|
||||||
|
|
||||||
|
~essence()
|
||||||
|
{
|
||||||
|
for (auto p : items)
|
||||||
|
delete p;
|
||||||
|
}
|
||||||
|
|
||||||
nana::menu& push_back(const std::string& text)
|
nana::menu& push_back(const std::string& text)
|
||||||
{
|
{
|
||||||
wchar_t shortkey;
|
wchar_t shortkey;
|
||||||
API::transform_shortkey_text(text, shortkey, nullptr);
|
std::size_t shortkey_pos;
|
||||||
|
auto transformed_text = API::transform_shortkey_text(text, shortkey, &shortkey_pos);
|
||||||
|
|
||||||
if (shortkey)
|
if (shortkey)
|
||||||
API::register_shortkey(this->widget_ptr->handle(), shortkey);
|
API::register_shortkey(*widget_ptr, shortkey);
|
||||||
|
|
||||||
this->items.append(to_nstring(text), shortkey);
|
|
||||||
API::refresh_window(this->widget_ptr->handle());
|
|
||||||
|
|
||||||
return this->items.cont()[this->items.cont().size() - 1]->menu_obj;
|
if (shortkey && shortkey < 0x61)
|
||||||
|
shortkey += (0x61 - 0x41);
|
||||||
|
items.emplace_back(new item_type{ std::move(transformed_text), shortkey, shortkey_pos });
|
||||||
|
|
||||||
|
API::refresh_window(*widget_ptr);
|
||||||
|
|
||||||
|
return this->items.back()->menu_obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool cancel()
|
bool cancel()
|
||||||
@ -130,7 +102,6 @@ namespace nana
|
|||||||
return false;
|
return false;
|
||||||
|
|
||||||
this->close_menu();
|
this->close_menu();
|
||||||
state.menu_active = false;
|
|
||||||
state.behave = behavior::none;
|
state.behave = behavior::none;
|
||||||
|
|
||||||
auto pos = API::cursor_position();
|
auto pos = API::cursor_position();
|
||||||
@ -141,13 +112,17 @@ namespace nana
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool open_menu()
|
bool open_menu(bool activate_menu = false)
|
||||||
{
|
{
|
||||||
|
if (activate_menu)
|
||||||
|
state.menu_active = true;
|
||||||
|
|
||||||
auto pos = state.active;
|
auto pos = state.active;
|
||||||
if (pos >= items.cont().size())
|
|
||||||
|
if (pos >= items.size())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
auto item_ptr = items.cont()[pos];
|
auto item_ptr = items[pos];
|
||||||
|
|
||||||
if (state.menu_active && (state.menu != &(item_ptr->menu_obj)))
|
if (state.menu_active && (state.menu != &(item_ptr->menu_obj)))
|
||||||
{
|
{
|
||||||
@ -156,6 +131,9 @@ namespace nana
|
|||||||
API::dev::delay_restore(false);
|
API::dev::delay_restore(false);
|
||||||
state.active = pos;
|
state.active = pos;
|
||||||
|
|
||||||
|
//Resets this flag, because close_menu() deactivates the menu
|
||||||
|
state.menu_active = true;
|
||||||
|
|
||||||
state.menu = &(item_ptr->menu_obj);
|
state.menu = &(item_ptr->menu_obj);
|
||||||
state.menu->destroy_answer([this]
|
state.menu->destroy_answer([this]
|
||||||
{
|
{
|
||||||
@ -177,6 +155,8 @@ namespace nana
|
|||||||
|
|
||||||
bool close_menu()
|
bool close_menu()
|
||||||
{
|
{
|
||||||
|
state.menu_active = false;
|
||||||
|
|
||||||
if (state.menu)
|
if (state.menu)
|
||||||
{
|
{
|
||||||
state.passive_close = false;
|
state.passive_close = false;
|
||||||
@ -188,18 +168,37 @@ namespace nana
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
std::size_t find(wchar_t shortkey) const
|
||||||
|
{
|
||||||
|
if (shortkey)
|
||||||
|
{
|
||||||
|
if (shortkey < 0x61) shortkey += (0x61 - 0x41);
|
||||||
|
|
||||||
|
std::size_t index = 0;
|
||||||
|
for (auto item_ptr : items)
|
||||||
|
{
|
||||||
|
if (item_ptr->shortkey == shortkey)
|
||||||
|
return index;
|
||||||
|
++index;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return npos;
|
||||||
|
}
|
||||||
|
|
||||||
std::size_t find(const ::nana::point& pos)
|
std::size_t find(const ::nana::point& pos)
|
||||||
{
|
{
|
||||||
if ((2 <= pos.x) && (2 <= pos.y) && (pos.y < 25))
|
if ((2 <= pos.x) && (2 <= pos.y) && (pos.y < 25))
|
||||||
{
|
{
|
||||||
int item_x = 2;
|
int item_x = 2;
|
||||||
std::size_t index = 0;
|
std::size_t index = 0;
|
||||||
for (auto i : items.cont())
|
|
||||||
|
for (auto item_ptr : items)
|
||||||
{
|
{
|
||||||
if (item_x <= pos.x && pos.x < item_x + static_cast<int>(i->size.width))
|
if ((item_x <= pos.x) && (pos.x < item_x + static_cast<int>(item_ptr->size.width)))
|
||||||
return index;
|
return index;
|
||||||
|
|
||||||
item_x += i->size.width;
|
item_x += static_cast<int>(item_ptr->size.width);
|
||||||
++index;
|
++index;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -263,7 +262,7 @@ namespace nana
|
|||||||
return *ess_;
|
return *ess_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void trigger::attached(widget_reference widget, graph_reference graph)
|
void trigger::attached(widget_reference widget, graph_reference)
|
||||||
{
|
{
|
||||||
ess_->widget_ptr = &widget;
|
ess_->widget_ptr = &widget;
|
||||||
}
|
}
|
||||||
@ -280,15 +279,10 @@ namespace nana
|
|||||||
nana::size item_s(0, 23);
|
nana::size item_s(0, 23);
|
||||||
|
|
||||||
unsigned long index = 0;
|
unsigned long index = 0;
|
||||||
for (auto pm : ess_->items.cont())
|
|
||||||
|
for (auto pm : ess_->items)
|
||||||
{
|
{
|
||||||
//Transform the text if it contains the hotkey character
|
auto text_s = graph.text_extent_size(pm->text);
|
||||||
wchar_t hotkey;
|
|
||||||
::std::wstring::size_type hotkey_pos;
|
|
||||||
auto text = API::transform_shortkey_text(to_utf8(pm->text), hotkey, &hotkey_pos);
|
|
||||||
|
|
||||||
nana::size text_s = graph.text_extent_size(text);
|
|
||||||
|
|
||||||
item_s.width = text_s.width + 16;
|
item_s.width = text_s.width + 16;
|
||||||
|
|
||||||
pm->pos = item_pos;
|
pm->pos = item_pos;
|
||||||
@ -308,9 +302,9 @@ namespace nana
|
|||||||
|
|
||||||
//Draw text, the text is transformed from orignal for hotkey character
|
//Draw text, the text is transformed from orignal for hotkey character
|
||||||
int text_top_off = (item_s.height - text_s.height) / 2;
|
int text_top_off = (item_s.height - text_s.height) / 2;
|
||||||
ird.caption({ item_pos.x + 8, item_pos.y + text_top_off }, to_nstring(text));
|
ird.caption({ item_pos.x + 8, item_pos.y + text_top_off }, to_nstring(pm->text));
|
||||||
|
|
||||||
API::dev::draw_shortkey_underline(graph, text, hotkey, hotkey_pos, { item_pos.x + 8, item_pos.y + text_top_off }, ird.scheme_ptr()->text_fgcolor);
|
API::dev::draw_shortkey_underline(graph, pm->text, pm->shortkey, pm->shortkey_pos, { item_pos.x + 8, item_pos.y + text_top_off }, ird.scheme_ptr()->text_fgcolor);
|
||||||
|
|
||||||
item_pos.x += pm->size.width;
|
item_pos.x += pm->size.width;
|
||||||
++index;
|
++index;
|
||||||
@ -365,12 +359,7 @@ namespace nana
|
|||||||
ess_->state.active = ess_->find(arg.pos);
|
ess_->state.active = ess_->find(arg.pos);
|
||||||
|
|
||||||
if (npos != ess_->state.active)
|
if (npos != ess_->state.active)
|
||||||
{
|
ess_->open_menu(true);
|
||||||
if (!ess_->state.menu_active)
|
|
||||||
ess_->state.menu_active = true;
|
|
||||||
|
|
||||||
ess_->open_menu();
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
ess_->cancel();
|
ess_->cancel();
|
||||||
|
|
||||||
@ -402,7 +391,6 @@ namespace nana
|
|||||||
{
|
{
|
||||||
ess_->state.behave = essence::behavior::none;
|
ess_->state.behave = essence::behavior::none;
|
||||||
ess_->state.nullify_mouse = true;
|
ess_->state.nullify_mouse = true;
|
||||||
ess_->state.menu_active = false;
|
|
||||||
ess_->close_menu();
|
ess_->close_menu();
|
||||||
ess_->state.active = npos;
|
ess_->state.active = npos;
|
||||||
refresh(graph);
|
refresh(graph);
|
||||||
@ -437,7 +425,6 @@ namespace nana
|
|||||||
{
|
{
|
||||||
ess_->close_menu();
|
ess_->close_menu();
|
||||||
ess_->state.behave = essence::behavior::focus;
|
ess_->state.behave = essence::behavior::focus;
|
||||||
ess_->state.menu_active = false;
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case keyboard::enter:
|
case keyboard::enter:
|
||||||
@ -479,8 +466,7 @@ namespace nana
|
|||||||
case keyboard::os_arrow_up:
|
case keyboard::os_arrow_up:
|
||||||
case keyboard::os_arrow_down:
|
case keyboard::os_arrow_down:
|
||||||
case keyboard::enter:
|
case keyboard::enter:
|
||||||
ess_->state.menu_active = true;
|
if(ess_->open_menu(true))
|
||||||
if(ess_->open_menu())
|
|
||||||
menu_ptr->goto_next(true);
|
menu_ptr->goto_next(true);
|
||||||
break;
|
break;
|
||||||
case keyboard::escape:
|
case keyboard::escape:
|
||||||
@ -491,12 +477,11 @@ namespace nana
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
auto index = ess_->items.find(arg.key);
|
auto index = ess_->find(arg.key);
|
||||||
if(index != npos)
|
if(index != npos)
|
||||||
{
|
{
|
||||||
ess_->state.active = index;
|
ess_->state.active = index;
|
||||||
ess_->state.menu_active = true;
|
if(ess_->open_menu(true))
|
||||||
if(ess_->open_menu())
|
|
||||||
menu_ptr->goto_next(true);
|
menu_ptr->goto_next(true);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -534,15 +519,14 @@ namespace nana
|
|||||||
{
|
{
|
||||||
API::focus_window(ess_->widget_ptr->handle());
|
API::focus_window(ess_->widget_ptr->handle());
|
||||||
|
|
||||||
auto index = ess_->items.find(arg.key);
|
auto index = ess_->find(arg.key);
|
||||||
if(index != npos && (index != ess_->state.active || nullptr == ess_->state.menu))
|
if(index != npos && (index != ess_->state.active || nullptr == ess_->state.menu))
|
||||||
{
|
{
|
||||||
ess_->close_menu();
|
ess_->close_menu();
|
||||||
ess_->state.menu_active = true;
|
|
||||||
ess_->state.nullify_mouse = true;
|
ess_->state.nullify_mouse = true;
|
||||||
ess_->state.active = index;
|
ess_->state.active = index;
|
||||||
|
|
||||||
if(ess_->open_menu())
|
if(ess_->open_menu(true))
|
||||||
ess_->state.menu->goto_next(true);
|
ess_->state.menu->goto_next(true);
|
||||||
|
|
||||||
refresh(graph);
|
refresh(graph);
|
||||||
@ -553,9 +537,10 @@ namespace nana
|
|||||||
|
|
||||||
void trigger::_m_move(graph_reference graph, bool to_left)
|
void trigger::_m_move(graph_reference graph, bool to_left)
|
||||||
{
|
{
|
||||||
if(ess_->items.cont().empty()) return;
|
if (ess_->items.empty()) return;
|
||||||
|
|
||||||
|
const std::size_t last_pos = ess_->items.size() - 1;
|
||||||
|
|
||||||
const std::size_t last_pos = ess_->items.cont().size() - 1;
|
|
||||||
auto index = ess_->state.active;
|
auto index = ess_->state.active;
|
||||||
if(to_left)
|
if(to_left)
|
||||||
{
|
{
|
||||||
@ -617,12 +602,12 @@ namespace nana
|
|||||||
|
|
||||||
menu& menubar::at(std::size_t pos) const
|
menu& menubar::at(std::size_t pos) const
|
||||||
{
|
{
|
||||||
return get_drawer_trigger().ess().items.cont().at(pos)->menu_obj;
|
return get_drawer_trigger().ess().items.at(pos)->menu_obj;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::size_t menubar::length() const
|
std::size_t menubar::length() const
|
||||||
{
|
{
|
||||||
return get_drawer_trigger().ess().items.cont().size();
|
return get_drawer_trigger().ess().items.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool menubar::cancel()
|
bool menubar::cancel()
|
||||||
@ -639,7 +624,7 @@ namespace nana
|
|||||||
if (wd == this->handle())
|
if (wd == this->handle())
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
auto & items = get_drawer_trigger().ess().items.cont();
|
auto & items = get_drawer_trigger().ess().items;
|
||||||
while (wd)
|
while (wd)
|
||||||
{
|
{
|
||||||
auto owner = API::get_owner_window(wd);
|
auto owner = API::get_owner_window(wd);
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
/*
|
/*
|
||||||
* A Progress Indicator Implementation
|
* 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.
|
* 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
|
||||||
@ -17,136 +17,185 @@ namespace nana
|
|||||||
{
|
{
|
||||||
namespace progress
|
namespace progress
|
||||||
{
|
{
|
||||||
//class trigger
|
scheme::scheme()
|
||||||
void trigger::attached(widget_reference wd, graph_reference graph)
|
|
||||||
{
|
{
|
||||||
widget_ = &wd;
|
foreground = static_cast<color_rgb>(0x107515);
|
||||||
graph_ = &graph;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned trigger::value() const
|
class substance
|
||||||
{
|
{
|
||||||
|
public:
|
||||||
|
static const unsigned border_px = 1;
|
||||||
|
|
||||||
|
void set_widget(widget& wdg)
|
||||||
|
{
|
||||||
|
widget_ = static_cast<nana::progress*>(&wdg);
|
||||||
|
}
|
||||||
|
|
||||||
|
nana::progress* widget_ptr() const
|
||||||
|
{
|
||||||
|
return widget_;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned inc()
|
||||||
|
{
|
||||||
|
auto val = value(nullptr) + 1;
|
||||||
|
return value(&val);
|
||||||
|
}
|
||||||
|
|
||||||
|
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_;
|
return value_;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned trigger::value(unsigned v)
|
void reset_value()
|
||||||
{
|
{
|
||||||
internal_scope_guard isg;
|
value_ = 0;
|
||||||
if(false == unknown_)
|
|
||||||
{
|
|
||||||
if(value_ != v)
|
|
||||||
value_ = v > max_?max_:v;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
value_ += (v?10:v);
|
|
||||||
|
|
||||||
if(_m_check_changing(value_))
|
|
||||||
{
|
|
||||||
refresh(*graph_);
|
|
||||||
API::update_window(widget_->handle());
|
|
||||||
}
|
|
||||||
return v;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned trigger::inc()
|
unsigned maximum(const unsigned * value_ptr)
|
||||||
{
|
{
|
||||||
internal_scope_guard isg;
|
//Sets new maximum if value_ptr is not a nullptr
|
||||||
if(false == unknown_)
|
if (value_ptr)
|
||||||
{
|
{
|
||||||
if(value_ < max_)
|
max_ = (*value_ptr > 0 ? *value_ptr : 1);
|
||||||
++value_;
|
_m_try_refresh();
|
||||||
}
|
}
|
||||||
else
|
|
||||||
value_ += 5;
|
|
||||||
|
|
||||||
if(_m_check_changing(value_))
|
|
||||||
API::refresh_window(widget_->handle());
|
|
||||||
return value_;
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned trigger::Max() const
|
|
||||||
{
|
|
||||||
return max_;
|
return max_;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned trigger::Max(unsigned value)
|
bool unknown(const bool* state_ptr)
|
||||||
{
|
{
|
||||||
max_ = value;
|
if (state_ptr)
|
||||||
if(max_ == 0) ++max_;
|
{
|
||||||
|
unknown_ = *state_ptr;
|
||||||
API::refresh_window(widget_->handle());
|
if (unknown_)
|
||||||
return max_;
|
value_px_ = 0;
|
||||||
|
else
|
||||||
|
value_ = (std::min)(value_, max_);
|
||||||
}
|
}
|
||||||
|
|
||||||
void trigger::unknown(bool enb)
|
|
||||||
{
|
|
||||||
unknown_ = enb;
|
|
||||||
if(enb)
|
|
||||||
draw_width_ = static_cast<unsigned>(-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool trigger::unknown() const
|
|
||||||
{
|
|
||||||
return unknown_;
|
return unknown_;
|
||||||
}
|
}
|
||||||
bool trigger::stopped() const
|
|
||||||
|
unsigned value_px() const
|
||||||
{
|
{
|
||||||
return stop_;
|
return value_px_;
|
||||||
}
|
}
|
||||||
bool trigger::stop(bool s)
|
private:
|
||||||
|
void _m_try_refresh()
|
||||||
{
|
{
|
||||||
std::swap(s,stop_);
|
if (nullptr == widget_)
|
||||||
return s;
|
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_;
|
||||||
|
}
|
||||||
|
|
||||||
|
substance* trigger::progress() const
|
||||||
|
{
|
||||||
|
return progress_;
|
||||||
|
}
|
||||||
|
|
||||||
|
void trigger::attached(widget_reference wdg, graph_reference)
|
||||||
|
{
|
||||||
|
progress_->set_widget(wdg);
|
||||||
}
|
}
|
||||||
|
|
||||||
void trigger::refresh(graph_reference graph)
|
void trigger::refresh(graph_reference graph)
|
||||||
{
|
{
|
||||||
if (false == unknown_)
|
const unsigned border_px = substance::border_px;
|
||||||
draw_width_ = static_cast<unsigned>((graph.width() - border * 2) * (double(value_) / max_));
|
|
||||||
|
|
||||||
_m_draw_box(graph);
|
rectangle rt_val{ graph.size() };
|
||||||
_m_draw_progress(graph);
|
auto const width = rt_val.width - border_px * 2;
|
||||||
}
|
|
||||||
|
|
||||||
void trigger::_m_draw_box(graph_reference graph)
|
rt_val.pare_off(static_cast<int>(border_px));
|
||||||
|
|
||||||
|
auto rt_bground = rt_val;
|
||||||
|
if (false == progress_->unknown(nullptr))
|
||||||
{
|
{
|
||||||
rectangle r{ graph.size() };
|
rt_bground.x = static_cast<int>(progress_->value_px()) + static_cast<int>(border_px);
|
||||||
graph.gradual_rectangle(r, colors::button_face_shadow_end, colors::button_face_shadow_start, true);
|
rt_bground.width -= progress_->value_px();
|
||||||
::nana::color lt{ colors::gray }, rb{colors::white};
|
|
||||||
graph.frame_rectangle(r, lt, lt, rb, rb);
|
|
||||||
}
|
|
||||||
|
|
||||||
void trigger::_m_draw_progress(graph_reference graph)
|
rt_val.width = progress_->value_px();
|
||||||
{
|
|
||||||
unsigned width = graph.width() - border * 2;
|
|
||||||
unsigned height = graph.height() - border * 2;
|
|
||||||
|
|
||||||
if(false == unknown_)
|
|
||||||
{
|
|
||||||
if(draw_width_)
|
|
||||||
graph.gradual_rectangle({ static_cast<int>(border), static_cast<int>(border), draw_width_, height }, { 0x6F, 0xFF, 0xA8 }, { 0x10, 0x75, 0x15 }, true);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
unsigned block = width / 3;
|
auto const block = width / 3;
|
||||||
|
|
||||||
int left = (value_ < block ? 0 : value_ - block) + border;
|
auto const value = progress_->value(nullptr);
|
||||||
int right = (value_ >= width - 1 + border? width - 1 + border: value_);
|
|
||||||
|
|
||||||
if(right >= left)
|
auto left = (std::max)(0, static_cast<int>(value - block)) + static_cast<int>(border_px);
|
||||||
graph.gradual_rectangle({ left, static_cast<int>(border), static_cast<unsigned>(right - left + 1), height }, { 0x6F, 0xFF, 0xA8 }, { 0x10, 0x75, 0x15 }, true);
|
auto right = static_cast<int>((std::min)(value, width + border_px -1));
|
||||||
|
|
||||||
if(value_ >= width + block) value_ = 0;
|
if (right > left)
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool trigger::_m_check_changing(unsigned newvalue) const
|
|
||||||
{
|
{
|
||||||
if(graph_)
|
rt_val.x = left;
|
||||||
return (((graph_->width() - border * 2) * newvalue / max_) != draw_width_);
|
rt_val.width = static_cast<unsigned>(right - left + 1);
|
||||||
return false;
|
}
|
||||||
|
else
|
||||||
|
rt_val.width = 0;
|
||||||
|
|
||||||
|
if (value >= width + block)
|
||||||
|
progress_->reset_value();
|
||||||
|
}
|
||||||
|
|
||||||
|
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 progress
|
||||||
}//end namespace drawerbase
|
}//end namespace drawerbase
|
||||||
|
|
||||||
@ -165,49 +214,42 @@ namespace nana
|
|||||||
|
|
||||||
unsigned progress::value() const
|
unsigned progress::value() const
|
||||||
{
|
{
|
||||||
return get_drawer_trigger().value();
|
return get_drawer_trigger().progress()->value(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned progress::value(unsigned val)
|
unsigned progress::value(unsigned val)
|
||||||
{
|
{
|
||||||
internal_scope_guard isg;
|
internal_scope_guard lock;
|
||||||
if(API::empty_window(this->handle()) == false)
|
if(API::empty_window(this->handle()) == false)
|
||||||
return get_drawer_trigger().value(val);
|
return get_drawer_trigger().progress()->value(&val);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned progress::inc()
|
unsigned progress::inc()
|
||||||
{
|
{
|
||||||
internal_scope_guard isg;
|
internal_scope_guard lock;
|
||||||
return get_drawer_trigger().inc();
|
return get_drawer_trigger().progress()->inc();
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned progress::amount() const
|
unsigned progress::amount() const
|
||||||
{
|
{
|
||||||
return get_drawer_trigger().Max();
|
return get_drawer_trigger().progress()->maximum(nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
unsigned progress::amount(unsigned value)
|
unsigned progress::amount(unsigned value)
|
||||||
{
|
{
|
||||||
return get_drawer_trigger().Max(value);
|
return get_drawer_trigger().progress()->maximum(&value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void progress::unknown(bool enb)
|
void progress::unknown(bool enb)
|
||||||
{
|
{
|
||||||
get_drawer_trigger().unknown(enb);
|
internal_scope_guard lock;
|
||||||
|
get_drawer_trigger().progress()->unknown(&enb);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool progress::unknown() const
|
bool progress::unknown() const
|
||||||
{
|
{
|
||||||
return get_drawer_trigger().unknown();
|
return get_drawer_trigger().progress()->unknown(nullptr);
|
||||||
}
|
|
||||||
bool progress::stop(bool s)
|
|
||||||
{
|
|
||||||
return get_drawer_trigger().stop(s);
|
|
||||||
}
|
|
||||||
bool progress::stopped() const
|
|
||||||
{
|
|
||||||
return get_drawer_trigger().stopped();
|
|
||||||
}
|
}
|
||||||
//end class progress
|
//end class progress
|
||||||
}//end namespace nana
|
}//end namespace nana
|
||||||
|
Loading…
x
Reference in New Issue
Block a user