[fxruby-users] FXScrollArea messages

Jannis Pohlmann info at sten-net.de
Thu May 19 07:47:13 EDT 2005


Lyle Johnson schrieb:

>
> On May 16, 2005, at 1:02 PM, Jannis Pohlmann wrote:
>
>> I've got a few problems getting a subclass of FXScrollArea react on 
>> SEL_MOTION and SEL_LEFTBUTTONPRESS.
>>
>> In the constructor I wrote
>>
>>    FXMAPFUNC(SEL_MOTION, 0, "onMouseMove")
>>    FXMAPFUNC(SEL_LEFTBUTTONPRESS, 0, "onLeftClick")
>>
>> I also tried
>>
>>    self.connect(SEL_MOTION, method(:onMouseMove))
>>    self.connect(SEL_LEFTBUTTONPRESS, method(:onLeftClick))
>>
>> But when I use this widget those handler functions are never called, 
>> even
>> if I call .setFocus on it.
>
>
> Could you send me some sample code that demonstrates the problem? The 
> first approach that you mentioned is the right idea, although there 
> may be some piece missing in the bridge from FOX to FXRuby.
>
> The second example definitely wouldn't work, because FXScrollArea 
> doesn't forward those messages to its message target, and that's what 
> connect() is all about: setting up a map the messages that a widget 
> sends to its message target, and some chunk of code to handle that 
> message.
>
Alright, I read your mail concerning "defining events in fox 1.2" and I 
think I got the point about the .connect() method. Thank's for 
explaining that!

Here's my code, originally about 300 lines stripped down to what you 
should need:

require "fox12"
require "fox12/responder"
require "fox12/colors"
include Fox

class CustomTable < FXScrollArea

    include Responder

    ID_SELF,
    ID_INPUT = enum(FXScrollArea::ID_LAST, 2)

    def initialize(parent, tgt, sel)
        super(parent, LAYOUT_FILL_X|LAYOUT_FILL_Y)
       
        setTarget(tgt)
        setSelector(sel)
        initEvents
    end

    def create
        super
    end

    def initEvents
        FXMAPFUNC(SEL_PAINT,        0,            :onPaint)
        FXMAPFUNC(SEL_KEYPRESS,     0,            :onKeyPress)
        FXMAPFUNC(SEL_COMMAND,      ID_INPUT,     :onAcceptInput)
       
        # That's the troublemaker
        FXMAPFUNC(SEL_MOTION,       0,            :onMouseMove)
       
        FXMAPFUNC(SEL_CONFIGURE,    0,            :onConfigure)
        FXMAPFUNC(SEL_CHANGED,        FXWindow::ID_HSCROLLED, 
:onHorizontalScroll)
        FXMAPFUNC(SEL_CHANGED,        FXWindow::ID_VSCROLLED, 
:onVerticalScroll)
    end

    def onMouseMove(sender, sel, event)
        puts "#{self.class}::onMouseMove"
    end
   
end


# Construction of an instance of CustomTable
shopItems = CustomTable.new(border, nil, 0)

Regards,
Jannis


More information about the fxruby-users mailing list