Re: [Fxruby-users] OO documentation issues.
Status: Inactive
Brought to you by:
lyle
From: Lyle J. <jl...@cf...> - 2003-06-12 15:17:11
|
Hugh Sasse Staff Elec Eng wrote: > Things that have puzzled me about this target message sytem include: > the target is fixed at construction time. No. The target is initialized at construction time, but it is not "fixed". You can change it at any time using the setTarget() method, or by "re-connecting" the widget to some other proc, or whatever. It is (can be) very dynamic if that makes sense for your application. > The messages have types and ids. > Is this how global scope of message ids is avoided, so that > Multiple Inheritance (C++) or Mixin (Ruby) is achievable? Only > the case of direct ancestry makes it necessary to adjust > LAST_ID, then? > and that selector seems to be used for message. I'm not sure I follow, so I'll just give you my summary of how message types and identifiers are used in the C++ library. But before you get too bogged down in that discussion, let me note that in many cases, this mess is easier to work with in FXRuby applications due to some magic I added awhile back (i.e. the #connect method). First, the boring part. Message types are used to distinguish between the different kinds of messages that a widget can *send*. If we consider the FXButton widget as an example: http://www.fxruby.org/doc/api/classes/Fox/FXButton.html we see that it can send one of five different message types (SEL_KEYPRESS, SEL_KEYRELEASE, SEL_LEFTBUTTONPRESS, SEL_LEFTBUTTONRELEASE or SEL_COMMAND) to its target object. Of course, the button's target may getting messages from *other* widgets as well. So it needs some way to distinguish between SEL_KEYPRESS messages coming from, say, button #1, and SEL_KEYPRESS messages coming from button #2. And that's where the message identifier comes in. Message identifiers are most often used to distinguish between different senders of the same type of message. Since the message identifiers are used by the receiver of the message (i.e. the target), they just need to be unique for that class of objects and do not need to be globally unique. Now, the less boring part. For many FXRuby applications, you don't need to get *too* hung up on the details of how FOX's message-target system works under the hood. As discussed in detail here: http://www.fxruby.org/doc/events.html A lot of the ugly details have been hidden for the most common applications in FXRuby. > I suppose there is > an analogy here with the Ruby send() method, except that one must > setup the mapping between the message and the recipient's method in > FOX, whereas this is mapping is implicit in the Ruby send command. Yes, and this is largely due to some fundamental differences between C++ and Ruby. The C++ language doesn't have any way to "send" a message to an object other than explicitly calling one of its member functions, i.e. this binding must occur at compile time. So Jeroen had to invent this somewhat elaborate scaffolding to pull off FOX's message-target system. It is no secret that he would have preferred to have written FOX in Objective-C, where this kind of messaging would have been more natural, but for pragmatic reasons he went with C++ ;) |