Hi all,
I want to create a custom control which changes the background color
of the slider
whenever an update happens. What’s the best way to do this? The
control should behave exactly like FXSilder, so I can not use
connect(). And while I am at it: why doesn’t connect() support
multiple message handlers?
regards,
Martin
Martin wrote:
I want to create a custom control which changes the background color
of the slider whenever an update happens.
By “whenever an update happens”, I assume you mean “whenever the
slider’s value changes”.
What’s the best way to do this? The
control should behave exactly like FXSilder, so I can not use
connect().
In that case you could subclass FXSlider and override the default
messages handlers for the SEL_MOTION, SEL_LEFTBUTTONPRESS and
SEL_LEFTBUTTONRELEASE messages.
And while I am at it: why doesn’t connect() support
multiple message handlers?
This may be changed in the near future; someone has recently posted some
code to the fxruby-users mailing list which address that very problem.
In that case you could subclass FXSlider and override the default
messages handlers for the SEL_MOTION, SEL_LEFTBUTTONPRESS and
SEL_LEFTBUTTONRELEASE messages.
using connect(), or is there another way?
And while I am at it: why doesn’t connect() support
multiple message handlers?
This may be changed in the near future; someone has recently posted some
code to the fxruby-users mailing list which address that very problem.
I have written a simple solution, which works quite well for me. It
took me exactly 10 minutes - yet another example how elegant Ruby is

class MultiConnectSlider < FXSlider
def initialize(*params)
super(*params)
@sigHandler = Hash.new do |h, n|
h[n] = Array.new
end
end
def connect(signal)
@sigHandler[signal].push Proc.new
super(signal) do |sender, selector, data|
@sigHandler[signal].each do |proc|
proc.call(sender, selector, data)
end
end
end
end
Martinus wrote:
using connect(), or is there another way?
No, you’d need to use the FXMAPFUNC() method to intercept those messages
that the application sends to FXSlider and provide your own message
handler methods.