[fxruby-users] defining events in fox 1.2
info at sten-net.de
Fri May 13 07:11:52 EDT 2005
Jacob Hanson schrieb:
>Thanks to the list I'm back to progressing with my custom control.
>Now, what I can't find after an hour of RTFM is how to define events
>so that something can .connect to them.
>I read how the older, C++ Fox-like .enum/FXMAPFUNC/Responder interface was
>replaced with the .connect interface for handling events in your
>applications. But when you're building a widget, how do you define those
>Say I have a widget that should do nothing else but change the background
>color of itself when clicked. The only thing that I can fathom at this point
>is that you have to use Responder's .enum to define your desired custom message
>IDs (perhaps ID_RED, ID_BLUE for background colors) and then use FXMAPFUNC to map
>the message type + message ID combinations to actual methods inside
>the widget (e.g. FXMAPFUNC(SEL_COMMAND, ID_RED, :onSetRedBackground))
>Is this the correct way to do it with FXRuby 1.2?
I'm still a little uncertain about the use of .connect since it doesn't
completely replace the old C++-style
mechanism. Example: If you have a widget and want to overload the paint
handler you have to call
FXMAPFUNC(SEL_PAINT, 0, "onPaint")
doesn't do the job (although it actually should).
However, you can also create objects this way:
FXButton.new(...) do |btn|
If you have more than one button calling the :OnClick method you can
which button was clicked later:
def OnClick(sender, sel, event)
puts "Red button clicked"
puts "Yellow button clicked"
This sometimes makes code a little more compact and allows you to react
objects the same way (and spares duplicating code to a certain extend).
Hope this helps,
More information about the fxruby-users