Page 1 of 1
disable wxMenu entry
Posted: Thu Jun 15, 2006 11:19 am
by MoonKid
I got an context menu. How can I disable a entry of this context menu?
wxMenuItem::Enable(false) does not work. The entry is shown normal and I can activate it.
Posted: Thu Jun 15, 2006 11:27 am
by Cursor
As all MenuItem or ToolbarItem, you can disable (or check or other) a menu item with a wxUpdateUIEvent [1].
It is the same as
http://forums.wxwidgets.org/viewtopic.php?t=8594
(first accepted answer).
[1] :
http://www.wxwidgets.org/manuals/2.6.3/ ... ateuievent
Posted: Thu Jun 15, 2006 11:47 am
by MoonKid
It looks very complicated for only disabling an menu entry. I do not understand how to use it. Is there a sample for that? The code in the referenced topic does not help me.
Why does wxMenuItem::Enable() does not work? For what is it?
Posted: Thu Jun 15, 2006 11:59 am
by dsk
MoonKid wrote:It looks very complicated for only disabling an menu entry. I do not understand how to use it. Is there a sample for that? The code in the referenced topic does not help me.
Why does wxMenuItem::Enable() does not work? For what is it?
Could you post a piece of code where you want to use it ?
Posted: Thu Jun 15, 2006 1:54 pm
by MoonKid
dsk wrote:Could you post a piece of code where you want to use it ?
Code: Select all
void OBBackupTree::OnItemMenu(wxTreeEvent& event)
{
wxTreeItemId item (event.GetItem());
wxPoint point (event.GetPoint());
// right click on root item
if (GetRootItem() == item)
{
wxMenu menu;
wxMenuItem mItem1(&menu, OBID_BACKUPCTRL_ADDDESTINATION, _("add destination directory"));
mItem1.Enable(false);
menu.Append(&mItem1);
PopupMenu(&menu, point);
}
}
Posted: Thu Jun 15, 2006 2:10 pm
by benedicte
MoonKid wrote:dsk wrote:Could you post a piece of code where you want to use it ?
Code: Select all
void OBBackupTree::OnItemMenu(wxTreeEvent& event)
{
wxTreeItemId item (event.GetItem());
wxPoint point (event.GetPoint());
// right click on root item
if (GetRootItem() == item)
{
wxMenu menu;
wxMenuItem mItem1(&menu, OBID_BACKUPCTRL_ADDDESTINATION, _("add destination directory"));
mItem1.Enable(false);
menu.Append(&mItem1);
PopupMenu(&menu, point);
}
}
The wxWindow::PopupMenu documentation says:
Just before the menu is popped up, wxMenu::UpdateUI is called to ensure that the menu items are in the correct state. The menu does not get deleted by the window.
You can handle the EVT_UPDATE_UI event for identifier OBID_BACKUPCTRL_ADDDESTINATION.
Posted: Thu Jun 15, 2006 2:16 pm
by MoonKid
benedicte wrote:You can handle the EVT_UPDATE_UI event for identifier OBID_BACKUPCTRL_ADDDESTINATION.
Sorry that is agains all my personal rules. Implementing an event handling for such a simple task is OVERHEAD. If such a event handling is needed for that the framework should handle it internaly without bother me with that.
I ask again: What is wxMenuItem::Enable() ? Why does n it work?
Posted: Thu Jun 15, 2006 2:41 pm
by doublemax
try putting the
mItem1.Enable(false);
after
menu.Append(&mItem1);
Code: Select all
menu.Append(&mItem1);
mItem1.Enable(false);
Posted: Thu Jun 15, 2006 2:50 pm
by MoonKid
doublemax wrote:try...
No it works. But it is unlogical. A behavior like this should be in the docs.