f



wxMenuBar :: encapsulating event handling :: seems that only parent frame handles these events

Hi.

Isn't it possible to process menu events from within a wxMenuBar 
subclass ? wxMenuBar is derived from wxEvtHandler ...

It seems these events are only treated within the parent frame. Code is 
below.


Explaining :

I'm trying to encapsulating the event handling from menu selection 
within a menubar derived from wxMenuBar.

I've created a event table mapping the events to the menubar class' 
handlers.

Unfortunatelly, it seems the events aren't treated within the menubar class.

I've created a event table at this class parent (a wxFrame subclass) and 
it functions.


--- InshapeMenu.h --->

#include "wx/menu.h"
#include "wx/menuitem.h"
#include "wx/event.h"


*class* InshapeMenu : *public* wxMenuBar {


*public*:

	InshapeMenu();

	void OnQuit(wxCommandEvent& event);
	void OnAbout(wxCommandEvent& event);


*private*:

	wxMenu* m_pMenuFile;
	wxMenu* m_pMenuHelp;

	DECLARE_EVENT_TABLE()


};

<--- InshapeMenu.h ---


--- InshapeMenu.cpp --->

#include "InshapeMenu.h"
#include "wx/defs.h"
#include "wx/msgdlg.h"


InshapeMenu::InshapeMenu() :

 	m_pMenuFile(*new* wxMenu),
	m_pMenuHelp(*new* wxMenu) {

	m_pMenuFile->Append(wxID_EXIT, "E&xit");
	m_pMenuHelp->Append(wxID_ABOUT, "&About ...");

	*this*->Append(m_pMenuFile, "&File");
	*this*->Append(m_pMenuHelp, "&Help");

}


void InshapeMenu::OnAbout(wxCommandEvent& event) {

	wxMessageBox("Bar message !", "Bar title", wxOK);

}

void InshapeMenu::OnQuit(wxCommandEvent& event) {

	wxMessageBox("Foo message !", "Foo title", wxOK);

}

BEGIN_EVENT_TABLE(InshapeMenu, wxMenuBar)
	EVT_MENU(wxID_EXIT, InshapeMenu::OnQuit)
	EVT_MENU(wxID_ABOUT, InshapeMenu::OnAbout)
END_EVENT_TABLE()

<--- InshapeMenu.cpp ---



--- InshapeFrame.h --->

#ifndef INSHAPEFRAME_H
#define INSHAPEFRAME_H

#include "wx/frame.h"
#include "InshapeMenu.h"


*class* InshapeFrame : *public* wxFrame {

*public*:

	InshapeFrame(const wxString& title, const wxPoint& position, const wxSize& size);
	void foobar(wxCommandEvent& event);

*private*:

	InshapeMenu* m_pMenuBar;

	////
	DECLARE_EVENT_TABLE()
	////

};

#endif ///INSHAPEFRAME_H/

<--- Inshape.Frame.h ---


--- InshapeFrame.cpp --->

#include "InshapeFrame.h"
#include "wx/msgdlg.h"

InshapeFrame::InshapeFrame(const wxString& title, const wxPoint& position, const wxSize& size) :

	wxFrame((wxFrame*)NULL, wxID_ANY, title, position, size),
	m_pMenuBar(*new* InshapeMenu) {

	*this*->SetMenuBar(m_pMenuBar);

}

void InshapeFrame::foobar(wxCommandEvent& event) {

	wxMessageBox("Blah !", "Bleh !", wxOK);

}

BEGIN_EVENT_TABLE(InshapeFrame, wxFrame)
	EVT_MENU(wxID_ABOUT, InshapeFrame::foobar)
END_EVENT_TABLE()

<--- Inshape.Frame.cpp ---

Thanks in advance.
Joao Macaiba.






---------------------------------------------------------------------
To unsubscribe, e-mail: wx-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wx-users-help@lists.wxwidgets.org

0
joao
1/30/2006 5:01:32 AM
comp.soft-sys.wxwindows 21076 articles. 0 followers. Post Follow

1 Replies
355 Views

Similar Articles

[PageSpeed] 55

On Mon, 30 Jan 2006 03:01:32 -0200 Joao Macaiba <joao.macaiba@gmail.com> wrote:

JM> Isn't it possible to process menu events from within a wxMenuBar
JM> subclass ?

 I'm afraid it isn't. I do agree that it would be better/more logical if it
were possible so patches in this direction would be appreciated.

 Regards,
VZ

-- 
TT-Solutions: wxWidgets consultancy and technical support
               http://www.tt-solutions.com/


---------------------------------------------------------------------
To unsubscribe, e-mail: wx-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wx-users-help@lists.wxwidgets.org

0
vadim
2/5/2006 11:30:47 AM
Reply: