Opened 5 years ago

Closed 5 years ago

#15095 closed defect (fixed)

Menu events not passed to wxMenuBar

Reported by: RobertBColton Owned by:
Priority: low Milestone:
Component: GUI-all Version: stable-latest
Keywords: menu bar wxmenubar custom inherited class event Cc:
Blocked By: Blocking:
Patch: no


I have created a custom inherited wxMenuBar in the hopes of it handling its own events with a pointer back to the frame, so my frame class does not get any more cluttered. However the events do not register, but if I use the frame to connect them, they register but act like they are being called on the frame, not allowing me to access the custom classes pointers and not allowing me to access the frames pointers and definitions, but it thinks it can because its a member function of my custom class but if it accesses any of them, it immediately throws a segmentation fault.

Change History (4)

comment:1 Changed 5 years ago by RobertBColton

  • Resolution set to fixed
  • Status changed from new to closed

Nevermind I figured it out,

frame->Connect(quitMenuItem->GetId(),wxEVT_COMMAND_MENU_SELECTED,wxCommandEventHandler(MainMenubar::OnQuit), NULL, this);

is the proper way to propagate events to a custom wxMenuBar.

comment:2 Changed 5 years ago by vadz

I believe we fixed the code to use wxMenuBar as the event handler for the menu events some time ago, so if you use current svn it should work. If it doesn't, a patch to the minimal sample showing the problem would be welcome.

In the meanwhile, your workaround in comment:1 does work, of course, but it shouldn't be necessary to catch the events at the frame level.

comment:3 Changed 5 years ago by vadz

  • Component changed from wxGTK to GUI-all
  • Priority changed from critical to low
  • Resolution fixed deleted
  • Status changed from closed to reopened
  • Summary changed from wxMenuBar not registering events to Menu events not passed to wxMenuBar

Let me amend this: we didn't fix it yet, as I just discovered by adding a unit test checking for this. But I'll probably do it soon.

comment:4 Changed 5 years ago by VZ

  • Resolution set to fixed
  • Status changed from reopened to closed

(In [73922]) Pass menu events to the handler in the associated menu bar.

We handled the menu events in the menu itself and the associated window, but
not in the menu bar that the menu belonged to. This was unexpected, so allow
handling the events in the menu bar itself too.

Closes #15095.

Note: See TracTickets for help on using tickets.