[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: General widget programming questions
Pavel A. Romashkin (pavel.romashkin@noaa.gov) writes:
> P.S. Let's just say I am not advanced enough. David, you'll have to
> expand your widget and object sections do move me forward and develop
> the need in direct calls to event handlers :-)
One of the places I frequently use direct calls to
event handlers is in my compound widget objects.
As you know, most events in compound widgets are
handled by an internal event handler. But occasionally
you want to send the internal event (after
extensive remodelling, usually) to some other event
handler.
Normally, the internal event handler is associated with
the top-level base of the compound widget (identified
in the event handler as event.handler, by the way,
NOT event.top). One way to send events on is to write
the internal event handler as a function. You get the
internal event into the function, re-arrange it, maybe
add some fields to it, etc. and pass it along as the result
of the function, where it merrily makes its way up
the widget hierarchy.
This works great so long as the user doesn't want to
assign an event handler procedure or function to the
compound widget. (See any RSI-supplied compound widget,
for example.) It doesn't work so great when you would
like to re-direct the event somewhere else.
Since I want my compound widget to look and feel as much
as possible like a simple widget, I usually define
Event_Pro and Event_Func keywords for them. What I do,
then, in the event handler method function (remember, I always
write these as objects these days) is, when I am finished
processing the event, and have the new event packaged up
the way I want it, is call the specified event handler
procedure or function directly. (I use Call_Procedure
or Call_Function, of course, but you get the idea.)
If I *do* make the call directly, I turn the event
structure into a 0 and return that as the result of
the method function. The event is "swallowed". If the user
hasn't specified an event handler, then I just return
the event structure as the result of the method function, and
the event bubbles up the hierarchy. This way I can have
my cake and eat it too. :-)
Cheers,
David
--
David Fanning, Ph.D.
Fanning Software Consulting
Phone: 970-221-0438 E-Mail: davidf@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155