[fxruby-users] Painting a custom control

Lyle Johnson lyle at knology.net
Sat Oct 21 20:53:38 EDT 2006

On Oct 21, 2006, at 2:22 PM, Wayne Conrad wrote:

> It sure does.  My custom control is now drawing itself just fine.


> It took me a small bit of fiddling, but not much, to figure out that
> "include Responder" is required before I can call FXMAPFUNC.

Whoops. Sorry about that.

> I had thought that FXMAPFUNC was legacy stuff...  I misunderstood this
> page:
>         http://www.fxruby.org/doc/events.htm
> FXMAPFUNC is mentioned in the discussion of flaws with earlier
> releases of FXRuby, and not mentioned again after that.
> One of the examples using FXMAPFUNC was called "scribble-orig.rb", and
> the "scribble.rb" doesn't use it.  That's another thing that made me
> think that FXMAPFUNC was strictly a legacy function.
> FXMAPFUNC doesn't appear (that I can find) in the API docs for FXRuby
> 1.4 or 1.6-- another reason I thought it was deprecated.  Neither does
> Responder.  Should they be in the API docs?

Probably so, until the problem is completely solved.

FXMAPFUNC() is used to set up an instance's message map (i.e. which  
messages it responds to, and which methods implement those message  
handlers). Now, for most of the "interesting" message types, a widget  
will give its message target the "first shot" at handling any message  
that it receives. So, for example, if an FXButton receives a  
SEL_LEFTBUTTONPRESS message from the application event loop, the  
first thing it does is send that message to its target, to see if the  
target wants to handle the message:

	class FXButton
		# this is pseudo-code
		def onLeftBtnPress(sender, sel, event)
			if (target != nil) && (target handles the message)
				# then we're done
				# do default handling

If the target doesn't handle it, FXButton's default handling kicks  
in. Now, in order for the FXButton's target to handle the message,  
the target's message map has to be set up to declare that it can  
handle SEL_LEFTBUTTONPRESS messages and so forth. This is where the  
connect() method comes in -- it creates an anonymous object behind  
the scenes, and sets up that object's message map appropriately,  
relieving you of the hassle.

The problem (as you ran into) is that not all messages are deemed  
"interesting" enough to forward to a widget's target. FXFrame is a  
good example; that's basically a container class for *other* widgets,  
and it by itself doesn't have any really interesting behavior. (You  
hit on an exceptional case of course, which FOX can handle too.)

> I'm not complaining... just explaining where a newby got misled.

No, no need to apologize -- it's still somewhat of a mess for cases  
like yours. Luckily those are somewhat rare. I need to come up with  
some simple way for a widget to register handlers for messages that  
it *receives* (as opposed to connect(), which has to do with handlers  
for messages that it *sends*).

> You've been very helpful, and FXRuby has been the most enjoyable GUI
> framework I've tried so far.  I've done Windows, OS/2 PM, TK, and both
> flavors of Java GUI.  The reason I don't do GUIs is because the
> frameworks drive me to drink.  FXRuby might change that.


More information about the fxruby-users mailing list