35 using namespace Drawing;
39 Menu::Menu(const Rect& r, const shared_ptr<ListType>&
h,
ID id)
42 id(
id), pParent(
nullptr), mSubMenus(), vDisabled(h ? h->size() : 0)
45 Margin = Padding(6, 18, 4, 4);
46 CyclicTraverse =
true;
48 FetchEvent<KeyDown>(*
this) += [
this](KeyEventArgs&& e){
51 const auto& k(e.GetKeys());
58 if(
const auto pMnu = ShowSub(GetSelectedIndex()))
63 if(
const auto pMnu = GetParentPtr())
65 else if(k[KeyCodes::Esc])
71 FetchEvent<LostFocus>(*this) += [
this](UIEventArgs&& e){
75 const auto i(pHost->Roots.find(&e.GetSender()));
77 if(i != pHost->Roots.end())
81 while(
const auto pParent = pMnu->GetParentPtr())
83 if(i->second == pMnu->id)
87 if(
const auto pMnu = dynamic_cast<Menu*>(&e.GetSender()))
89 if(pMnu->GetParentPtr() !=
this)
90 pHost->HideUnrelated(*
this, *pMnu);
97 if(
Contains(e) && pHost && !ShowSub(e.Value))
108 if(val.second &&
IsInInterval(val.first, GetList().size()))
110 val.second->pParent =
this;
111 mSubMenus.insert(val);
120 const auto i(mSubMenus.find(idx));
122 if(i != mSubMenus.end() && i->second)
124 i->second->pParent =
nullptr;
134 Menu::IsItemEnabled(ListType::size_type idx)
const
139 return !vDisabled[idx];
143 Menu::SetItemEnabled(Menu::ListType::size_type idx,
bool b)
152 Menu::AdjustSize()
const
154 const auto list_size(GetList().size());
156 if(vDisabled.size() != list_size)
157 vDisabled.resize(list_size);
161 Menu::CheckConfirmed(Menu::ListType::size_type idx)
const
163 return TextList::CheckConfirmed(idx) && IsItemEnabled(idx);
182 const auto i(mSubMenus.find(idx));
184 if(i != mSubMenus.end())
186 auto& mnu(*i->second);
209 ListType::size_type i)
211 Color t(tsList.Color);
215 if(!IsItemEnabled(i))
217 TextList::DrawItem(g, mask, unit, i);
220 if(mSubMenus.find(i) != mSubMenus.end())
230 src.GetY() + src.GetItemHeight() * idx));
235 :
Frame(frm), mMenus(), Roots()
246 YAssert(val.second,
"Null pointer found.");
249 val.second->id = val.first, val.second->pHost =
this);
262 const auto i(
mMenus.find(
id));
266 auto& mnu(*i->second);
278 const auto i(
mMenus.find(
id));
302 const auto i(
mMenus.find(
id));
332 const auto i(
mMenus.find(
id));
366 while(pMnu && pMnu != &mnuParent)
368 const auto i(
mMenus.find(pMnu->GetID()));
372 pMnu = pMnu->GetParentPtr();