disable wxMenu entry Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
MoonKid
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 543
Joined: Wed Apr 05, 2006 9:39 am
Contact:

disable wxMenu entry

Post by MoonKid » Thu Jun 15, 2006 11:19 am

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.

Cursor
Earned some good credits
Earned some good credits
Posts: 120
Joined: Sun Aug 29, 2004 3:09 pm
Location: Grenoble, France
Contact:

Post by Cursor » Thu Jun 15, 2006 11:27 am

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
What is little and green, witch go up and down ??
Yoda playing with the force.

MoonKid
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 543
Joined: Wed Apr 05, 2006 9:39 am
Contact:

Post by MoonKid » Thu Jun 15, 2006 11:47 am

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?

dsk
Experienced Solver
Experienced Solver
Posts: 91
Joined: Sat Jun 25, 2005 12:10 pm
Location: Poland

Post by dsk » Thu Jun 15, 2006 11:59 am

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 ?
Back to wxWidgets and c++, from long time with php projects

MoonKid
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 543
Joined: Wed Apr 05, 2006 9:39 am
Contact:

Post by MoonKid » Thu Jun 15, 2006 1:54 pm

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);
    }
}

benedicte
wxWorld Domination!
wxWorld Domination!
Posts: 1409
Joined: Wed Jan 19, 2005 3:44 pm
Location: Paris, France

Post by benedicte » Thu Jun 15, 2006 2:10 pm

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.

MoonKid
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 543
Joined: Wed Apr 05, 2006 9:39 am
Contact:

Post by MoonKid » Thu Jun 15, 2006 2:16 pm

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?

User avatar
doublemax
Moderator
Moderator
Posts: 15273
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Post by doublemax » Thu Jun 15, 2006 2:41 pm

try putting the
mItem1.Enable(false);
after
menu.Append(&mItem1);

Code: Select all

menu.Append(&mItem1);
mItem1.Enable(false);

MoonKid
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 543
Joined: Wed Apr 05, 2006 9:39 am
Contact:

Post by MoonKid » Thu Jun 15, 2006 2:50 pm

doublemax wrote:try...
No it works. But it is unlogical. A behavior like this should be in the docs.

Post Reply