Prev: IEHtmlWindow
Next: wxAccelerator Control vs Command?
From: abirbasak on 23 Aug 2006 03:08 Hi, I want to seperate event handling from gui. Thus I have, class FileEventHandler :public wxEvtHandler{ public: //ctor public: //My events DECLARE_EVENT_TABLE() }; Now I want to call this event in the FileMenu , which extends wxMenu also in FileToolBar So I bind them like, BEGIN_EVENT_TABLE(FileEventHandler,wxEvtHandler) EVT_MENU(ID_INK_COLOR,FileEventHandler::OnInkColor) END_EVENT_TABLE() & Push the event handlers in the wxFrame object. Now, 1) can it be added in the FileMenu itself, rather than the wxFrame ? 2) If FileEventhandler & FileMenu are in different namespace it is causing error, InkRecognizer error LNK2001: unresolved external symbol "protected: virtual class wxEventHashTable & __thiscall com::readink::ui::HelpEventHandler::GetEventHashTable(void)const " etc. ut works if they are in same namespace. How to solve it? thanks abir
From: Vadim Zeitlin on 23 Aug 2006 06:34 On 23 Aug 2006 00:08:40 -0700 abirbasak(a)gmail.com wrote: > I want to seperate event handling from gui. Good idea. > Thus I have, > class FileEventHandler :public wxEvtHandler{ > public: > //ctor > public: > //My events > DECLARE_EVENT_TABLE() > }; > > Now I want to call this event in the FileMenu , which extends wxMenu > also in FileToolBar > So I bind them like, > > BEGIN_EVENT_TABLE(FileEventHandler,wxEvtHandler) > EVT_MENU(ID_INK_COLOR,FileEventHandler::OnInkColor) > END_EVENT_TABLE() Ok so far, although it's not really necessary to have an event table in FileEventHandler class. > & Push the event handlers in the wxFrame object. A better way would be to directly Connect() wxEVT_COMMAND_MENU_SELECTED event to FileEventHandler::OnInkColor from wxFrame code. Then you don't need the event table above nor to call Push/PopEventHandler(). > 1) can it be added in the FileMenu itself, rather than the wxFrame ? I believe this should work although to be honest I never used wxMenu objects to process events, this doesn't seem right somehow. > 2) If FileEventhandler & FileMenu are in different namespace it is > causing error, > InkRecognizer error LNK2001: unresolved external symbol "protected: > virtual class wxEventHashTable & __thiscall > com::readink::ui::HelpEventHandler::GetEventHashTable(void)const " It'sa bit difficult to understand where does this error come from, e.g. what is HelpEventHandler and what are all those namespaces? But in any case I'm quite sure that Connect() method works with namespaces just fine and as it doesn't involve macros, if you get any errors it's going to be much easier to understand where are they coming from. Good luck, VZ -- TT-Solutions: wxWidgets consultancy and technical support http://www.tt-solutions.com/ --------------------------------------------------------------------- To unsubscribe, e-mail: wx-users-unsubscribe(a)lists.wxwidgets.org For additional commands, e-mail: wx-users-help(a)lists.wxwidgets.org
From: abirbasak on 28 Aug 2006 09:35 Vadim Zeitlin wrote: > On 23 Aug 2006 00:08:40 -0700 abirbasak(a)gmail.com wrote: > > > I want to seperate event handling from gui. > > Good idea. > > > Thus I have, > > class FileEventHandler :public wxEvtHandler{ > > public: > > //ctor > > public: > > //My events > > DECLARE_EVENT_TABLE() > > }; > > > > Now I want to call this event in the FileMenu , which extends wxMenu > > also in FileToolBar > > So I bind them like, > > > > BEGIN_EVENT_TABLE(FileEventHandler,wxEvtHandler) > > EVT_MENU(ID_INK_COLOR,FileEventHandler::OnInkColor) > > END_EVENT_TABLE() > > Ok so far, although it's not really necessary to have an event table in > FileEventHandler class. > > > & Push the event handlers in the wxFrame object. > > A better way would be to directly Connect() wxEVT_COMMAND_MENU_SELECTED > event to FileEventHandler::OnInkColor from wxFrame code. Then you don't > need the event table above nor to call Push/PopEventHandler(). > > > 1) can it be added in the FileMenu itself, rather than the wxFrame ? > > I believe this should work although to be honest I never used wxMenu > objects to process events, this doesn't seem right somehow. why PushEventHandler etc ahould be needed in the Main wxFrame? I don't beleve it a good way. a wxMenu needs its own event handler or may share with another one. That is a better way, and increases reusability rather than defining all of the Commands at main frame. The wxWidgets samples are poor in that way, also the Code::Blocks source code. I wanted to have a bunch of event from a wxEvtHandler class, latter can be mapped into a wxMenu ot whatever , but not in main form. One can check how it is implemented in VCF Action (or Java Action class) . That is very elegant way to have a seperation & use of event handler rather than putting all things in same class. Anyway using my custom wxEvtHandler & pushing all of them in main form do the seperation to some extent. > > 2) If FileEventhandler & FileMenu are in different namespace it is > > causing error, > > InkRecognizer error LNK2001: unresolved external symbol "protected: > > virtual class wxEventHashTable & __thiscall > > com::readink::ui::HelpEventHandler::GetEventHashTable(void)const " > > It'sa bit difficult to understand where does this error come from, e.g. > what is HelpEventHandler and what are all those namespaces? But in any case > I'm quite sure that Connect() method works with namespaces just fine and as > it doesn't involve macros, if you get any errors it's going to be much > easier to understand where are they coming from. I got the error. It was a dumb error :) . as a common nomencleature I used BEGIN_EVENT_TABLE etc macros inside the class namespace, whereas the functions are defined in another namespace. (clearly shows macro's are bad, thow wxWidgets use them heavily). pulling the macros ouside namespace works fine. Never used Connect to connect event dynamically... will look at it. > Good luck, > VZ > -- > TT-Solutions: wxWidgets consultancy and technical support > http://www.tt-solutions.com/ > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: wx-users-unsubscribe(a)lists.wxwidgets.org > For additional commands, e-mail: wx-users-help(a)lists.wxwidgets.org
|
Pages: 1 Prev: IEHtmlWindow Next: wxAccelerator Control vs Command? |