Re: [Fxruby-users] implementing connect()
Status: Inactive
Brought to you by:
lyle
|
From: Claus S. <Doc...@gm...> - 2004-05-13 03:46:05
|
First of all, sorry for my earlier vague question, and thanks for the
reply. Now, what I was trying to do:
I'm still working on the program that you previously helped me with
(the canvas stuff). Got the canvas part down, added a few extra
features. Still the same concept basically.
What the whole thing is supposed to be is a lightweight replacement
for FXTable to match my requirements, which are:
* custom cell colors (hence the canvas)
* bring up a FXMessageBox when certain areas of the canvas are clicked
* etc
item #2 is what I'm wanting the connect() for... my previous program,
which was loosely based on the ListView class by Jamey Cribbs borrowed
his method of placing
connect( SEL_LEFTBUTTONPRESS, method( :onClick ) )
connect( SEL_LEFTBUTTONRELEASE, method( :onClick ) )
in the ListView (and in my case, CellView) class, and then have the
onClick method handle the different events
def onClick( sender, sel, event )
...
if event.click_count > 1
@win.onCmdDoubleClick
return 1
end
...
Now I'm assuming that the make_it_so method in your example is the
equivalent of my onClick method... right? However, nothing is
happening, and I've got a sneaking suspicion that it's because I've
omitted something crucial. Like using the parent FXWindow instead for
the connect() method. But I thought I'd better ask before banging my
head against the wall repeatedly.
I've attached the source in case you want to take a look at it... take
your time, I've got tons of other work that I can do on it in the
meantime (like adding other needed features and fixing the programming
horrors in there - I've been busy documenting many of them as such so
that should ease the urge to kill me). But eventually, I'd like to
handle these and other types of events.
-CWSpitzer
PS: the onClick method should crash when executed, as I have commented
out some the methods it relies on... I know, sloppy work, but I'm just
working on things as they bubble to the top of my to do list.
On Wed, 12 May 2004 20:55:55 -0500, Lyle Johnson <ly...@kn...> wrote:
>
8< ----- snip -----
> OK, first let's try to pin down what it is that you want to do. You
> want your class to be able to have a message target, i.e. to be able to
> call connect() on that object and provide a block to handle that
> message?
>
> If that's the case, your class needs to provide a "target" accessor
> method that returns a reference to the message target (an FXObject
> instance) for that object. If your class is a subclass of FXWindow or
> FXDataTarget you've already got that. Otherwise, do something like:
>
> class MyClass < FXObject
> include Responder2
> attr_accessor :target
> def initialize
> @target = nil
> end
> end
>
> You also need to mix-in the Responder2 module to get the connect()
> method, as shown.
>
> Now you should be able to do something like this:
>
> obj = MyClass.new
> obj.connect(SEL_COMMAND) { puts "hey hey hey" }
>
> And inside your class, when you want to "trigger" that callback, send a
> SEL_COMMAND message to the message target, e.g.
>
> class MyClass
> def make_it_so
> target.handle(self, MKUINT(0, SEL_COMMAND), nil)
> end
> end
>
> I'm sort of rushing through this, so I may have omitted some details.
> Let me know how it goes and if you have some follow-up questions.
>
> Hope this helps,
>
> Lyle
>
>
|