Added tabbar adding event

Fired when the add button of the tabbar is pressed.
Changing the value of arg.add to false the action can be vetoed.
The value arg.where indicates the position of the new item.
This commit is contained in:
besh81 2018-10-26 17:12:22 +02:00
parent 905c583621
commit bde0d16243
2 changed files with 34 additions and 0 deletions

View File

@ -35,6 +35,19 @@ namespace nana
{}
};
template<typename T>
struct arg_tabbar_adding
: public event_arg
{
arg_tabbar_adding(tabbar<T>& wdg, std::size_t pos)
: widget(wdg), where(pos)
{}
tabbar<T> & widget;
mutable bool add = true; ///< determines whether to add the item
std::size_t where; ///< position where to add the item
};
template<typename T>
struct arg_tabbar_removed : public arg_tabbar<T>
{
@ -56,6 +69,7 @@ namespace nana
{
using value_type = T;
basic_event<arg_tabbar_adding<value_type>> adding;
basic_event<arg_tabbar<value_type>> added;
basic_event<arg_tabbar<value_type>> activated;
basic_event<arg_tabbar_removed<value_type>> removed;
@ -65,6 +79,7 @@ namespace nana
{
public:
virtual ~event_agent_interface() = default;
virtual bool adding(std::size_t) = 0;
virtual void added(std::size_t) = 0;
virtual void activated(std::size_t) = 0;
virtual bool removed(std::size_t, bool & close_attached) = 0;
@ -107,6 +122,13 @@ namespace nana
: tabbar_(tb), drawer_trigger_(dtr)
{}
bool adding(std::size_t pos) override
{
::nana::arg_tabbar_adding<T> arg(tabbar_, pos);
tabbar_.events().adding.emit(arg, tabbar_);
return arg.add;
}
void added(std::size_t pos) override
{
if(pos != npos)

View File

@ -751,15 +751,27 @@ namespace nana
if((pos == npos) || (pos >= list_.size()))
{
pos = list_.size();
if(evt_agent_)
if(!evt_agent_->adding(pos))
return false;
this->list_.emplace_back();
}
else
{
if(evt_agent_)
if(!evt_agent_->adding(pos))
return false;
list_.emplace(iterator_at(pos));
}
basis_.active = pos;
if(evt_agent_)
{
evt_agent_->added(pos);
erase(pos);
evt_agent_->activated(pos);
}
return true;