improve dockpane caption

This commit is contained in:
Jinhao
2015-09-21 23:43:00 +08:00
parent c04751ac1a
commit 8dcd730715
10 changed files with 132 additions and 42 deletions

View File

@@ -2829,7 +2829,7 @@ namespace nana
{
auto i = impl_->dock_factoris.find(factory);
if (i == impl_->dock_factoris.end())
throw std::invalid_argument("nana::place - invalid factory name(" + factory + ")");
throw std::invalid_argument("invalid factory name(" + factory + ") of dockpane");
auto dock_ptr = i->second;
dock_ptr->attached->set_display(true);

View File

@@ -85,7 +85,6 @@ namespace nana
//draw caption
auto text = API::window_caption(window_handle_);
text = L"dockarea-caption";
text_rd_->render({ 3, 1 }, text.data(), text.size(), graph.size().width - 20, true);
//draw x button
@@ -303,6 +302,17 @@ namespace nana
if (!tabbar_ && panels_.size() > 0)
{
tabbar_.reset(new tabbar_lite(*this));
tabbar_->events().selected.clear();
tabbar_->events().selected([this]
{
auto handle = tabbar_->attach(tabbar_->selected());
if (handle)
caption_.caption(API::window_caption(handle));
else
caption_.caption(::nana::string());
});
tabbar_->move({ 0, r.bottom() - 20, r.width, 20 });
r.height -= 20;
@@ -319,7 +329,12 @@ namespace nana
if (tabbar_)
{
tabbar_->push_back(::nana::charset(wdg->caption()));
tabbar_->attach(panels_.size(), *wdg);
tabbar_->attach(panels_.size(), wdg->handle());
}
if (panels_.empty())
{
caption_.caption(wdg->caption());
}
panels_.emplace_back();

View File

@@ -344,7 +344,7 @@ namespace nana
{
if(i < list_.size())
return at_no_bound_check(i);
throw std::out_of_range("Nana.GUI.tabbar::at() is out of range");
throw std::out_of_range("invalid position of tabbar");
}
iterator iterator_at(std::size_t pos)
@@ -370,7 +370,7 @@ namespace nana
{
if(pos < list_.size())
return at_no_bound_check(pos);
throw std::out_of_range("Nana.GUI.tabbar::at() const is out of range");
throw std::out_of_range("invalid position of tabbar");
}
const nana::any& at_no_bound_check(std::size_t pos) const
@@ -1345,15 +1345,21 @@ namespace nana
using graph_reference = ::nana::paint::graphics&;
static const std::size_t npos = static_cast<std::size_t>(-1);
void set_widget(widget& wdg)
void set_widget(::nana::tabbar_lite& wdg)
{
widget_ = &wdg;
}
::nana::dev::widget_traits<widget>::scheme_type & scheme()
::nana::tabbar_lite* widget_ptr() const
{
return widget_;
}
/*
::nana::dev::widget_traits<widget>::scheme_type & scheme() //deprecated
{
return API::scheme(*widget_);
}
*/
std::forward_list<item>& items()
{
@@ -1407,7 +1413,7 @@ namespace nana
return indexes_;
}
private:
widget * widget_{ nullptr };
::nana::tabbar_lite * widget_{ nullptr };
std::forward_list<item> items_;
indexes indexes_;
};
@@ -1421,7 +1427,7 @@ namespace nana
{
_m_calc_metrics(graph, model.items());
auto & scheme = model.scheme();
auto & scheme = model.widget_ptr()->scheme();
//draw background
graph.rectangle(true, scheme.background);
@@ -1499,7 +1505,7 @@ namespace nana
void driver::attached(widget_reference wdg, graph_reference)
{
model_->set_widget(wdg);
model_->set_widget(dynamic_cast<nana::tabbar_lite&>(wdg));
}
//Overrides drawer_trigger's method
@@ -1533,11 +1539,17 @@ namespace nana
if ((indexes.hovered_pos == model_->npos) || (indexes.active_pos == indexes.hovered_pos))
return;
indexes.active_pos = indexes.hovered_pos;
model_->show_attached_window();
if (indexes.active_pos != indexes.hovered_pos)
{
indexes.active_pos = indexes.hovered_pos;
model_->show_attached_window();
refresh(graph);
API::lazy_refresh();
refresh(graph);
API::lazy_refresh();
event_arg arg;
model_->widget_ptr()->events().selected.emit(arg);
}
}
//end class driver
}
@@ -1577,6 +1589,20 @@ namespace nana
throw std::out_of_range("invalid position of tabbar_lite");
}
window tabbar_lite::attach(std::size_t pos_set) const
{
auto model = get_drawer_trigger().get_model();
internal_scope_guard lock;
for (auto & m : model->items())
{
if (0 == pos_set--)
return m.attached_window;
}
throw std::out_of_range("invalid position of tabbar_lite");
}
void tabbar_lite::push_back(std::string text, ::nana::any any)
{
auto & items = get_drawer_trigger().get_model()->items();
@@ -1622,10 +1648,12 @@ namespace nana
const auto len = length();
if (len <= pos)
throw std::out_of_range("tabbar_lite: out of range");
throw std::out_of_range("invalid position of tabbar_lite");
auto active_pos = model->get_indexes().active_pos;
//selection_changed is used to determine whether the title will be updated
bool selection_changed = true;
if (pos == active_pos)
{
if (active_pos + 1 == len)
@@ -1638,6 +1666,8 @@ namespace nana
}
else if (pos < active_pos)
--active_pos;
else
selection_changed = false;
model->get_indexes().active_pos = active_pos;
@@ -1653,6 +1683,12 @@ namespace nana
if (close_attached && attached_wd)
API::close_window(attached_wd);
if (selection_changed)
{
event_arg arg;
events().selected.emit(arg);
}
}
//end class tabbar
}//end namespace nana