Re: wxEuphoria - set_event_handler

new topic     » goto parent     » topic index » view thread      » older message » newer message

Mario Steele wrote:
> 
> Hey Jim,
> sixs wrote:
> > 
> > Hi. I'm having some trouble with clicking on a wxlistbox  and I am 
> > confused  about the event handler. I  am thinking that  within set event 
> > handler  that the "this"  is the wxFrame name, "id" is thename of the 
> > listbox, the "event" is ?, " rid" is the name of the procedure. I can 
> > get the buttons to work.
> > Thanks for any help
> > Jim
> 
> Okay, I know this can be a bit confusing at first, but it's actually quite
> simple.  With wxEuphoria, most controls, can have a ID assigned to it, but
> the thing to note about wxEuphoria, is that it's an Object Oriented library.
> 
> In the set_event_handler() routine, this refers to the instance of the
> control you created, for example:
> 
> constant MyFrame = create(wxWindow,{0,-1,"Hello World",-1,-1,-1,-1})
> 
> set_event_handler(MyFrame,-1,wxEVT_PAINT,routine_id("myPaintRoutine"))
> 
> Notice, that the 'this' is being passed as MyFrame.  the 'id' is -1.
> The 'event' is wxEVT_PAINT, and the 'rid' is "routine_id("myPaintRoutine")"

I can see that I need to sharpen the docs with regard to ids. :)
Actually, when you create a control with an id of -1, it's really telling
wxWidgets to automatically assign an id.  Usually, this is what you want
to do.  There are some conveniently pre-assigned ids, such as wxID_OPEN, 
wxID_EXIT, etc.  In the docs, look at Controls->IDs for some more info.
Note that wxMenuItems won't automatically generate an id, so you either
need to use one of the pre-assigned, or make a new one using new_id().

When you set an event handler, however, -1 means something else.  When an
event is triggered, wxWidgets notifies the objects 'responsible' for the
event.  Any normal control has wxEventHandler in its ancestry.  Usually,
if the control itself (e.g., the wxButton) doesn't handle the event, then
the event is passed to the control's parent.  The parent needs to know
who is doing the event (could be lots of buttons), so the id of the 
source of the event is passed.  This is especially important for menus,
since they don't have their own event handlers--the wxFrame parent has
to handle their events.  So for your buttons, you could set up the handler
in any of several ways:
set_event_handler( MyFrame, buttonID, wxEVT_COMMAND_BUTTON_CLICKED,
routine_id("on_click"))
set_event_handler( MyFrame, -1, wxEVT_COMMAND_BUTTON_CLICKED,
routine_id("on_click"))
set_event_handler( MyButton, buttonID, wxEVT_COMMAND_BUTTON_CLICKED,
routine_id("on_click"))
set_event_handler( MyButton, -1, wxEVT_COMMAND_BUTTON_CLICKED,
routine_id("on_click"))

 

Matt Lewis

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu