add functions to menubar for auto-close when mouse leave

This commit is contained in:
Jinhao
2017-08-28 21:09:04 +08:00
parent 5c28e72320
commit 64899a3d6a
4 changed files with 61 additions and 0 deletions

View File

@@ -165,6 +165,15 @@ namespace nana
return items_->cont().size();
}
bool trigger::cancel()
{
if (nana::npos == state_.active)
return false;
_m_total_close();
return true;
}
void trigger::attached(widget_reference widget, graph_reference graph)
{
graph_ = &graph;
@@ -624,5 +633,36 @@ namespace nana
{
return get_drawer_trigger().size();
}
bool menubar::cancel()
{
return get_drawer_trigger().cancel();
}
bool menubar::hovered() const
{
auto const native_handle = API::root(this->handle());
if (native_handle)
{
auto wd = API::find_window(API::cursor_position());
if (wd == this->handle())
return true;
while (wd)
{
auto owner = API::get_owner_window(wd);
if (API::root(owner) == native_handle)
{
for (std::size_t i = 0; i < get_drawer_trigger().size(); ++i)
{
if(get_drawer_trigger().at(i)->handle() == wd)
return true;
}
}
wd = owner;
}
}
return false;
}
//end class menubar
}//end namespace nana