Thread: [Fxruby-users] changing overall behavior - was (re: [Foxgui-users]making fox a superior toolkit)
Status: Inactive
Brought to you by:
lyle
From: Recheis M. <Mei...@av...> - 2003-08-22 09:53:30
|
hi lyle, i have asked you several times about this(changing the behavior of a = widget) but it seems that you have misunderstood me or i have = misunderstood you, or both. what about this "first chance callbacks" jeroen talks about (see his = post below)? i would like to know whether these can be used in FXRuby too. you once said (in other words for you, if i got you right):=20 > fox widgets catch events react and then block them. > so it is not possible to overwrite the default behavior for these = events. it seems possible to override the default behavior in C++. A possibility = that arises from that: you could=20 override the default behavior of all widgets (for right mouse click, for = instance) this would be very useful to me. but it's not useful if i cannot pop up = a menu on every widget (using right click). hope you know what i am trying to say, and excuse for my bad english. regards, - Henon jeroen wrote (on the Foxgui_users ML): [snip] > - giving the user a possibility to change the default behavior of = widgets > (this is very frustrating to ruby programmers, because we can simply > overwrite behavior in base classes. but in fox, if i overwrite > onLeftButtonPress in FXWindow to get the same behavior for any widget = in > the toolkit doesn't work with FXRuby. Don't know whether this is = possible > somehow in C++) Most widgets bounce a "first chance callback" to their target (i.e. = *your* code), so that your own handler may override the normal widget = translation. You can do this without subclassing the C++ class so (and I have to = defer to Lyle here) if FXRuby allows for the handler to be caught you may = actually be able to do quite a bit of 'behaviour modification". For example, if you press, move, release the left mouse button in some widget then these messages are bounced of the widget's target first; if the target's message handler returns 0, the translation of the messages proceeds according to the widget's own internal logic. However if the target's handlers return 1 then the widget doesn't "see" these events and your message handlers are basically in charge. While you do need to be fairly familiar with the toolkit to use this productively, it is certainly very nice to be able to do this as it won't involve subclassing the widget (which, working form Ruby, you are not able to do so easily). [snip] |
Re: [Fxruby-users] changing overall behavior - was (re: [Foxgui-users]making
fox a superior toolkit)
From: Lyle J. <jl...@cf...> - 2003-08-22 17:22:58
|
Recheis Meinrad wrote: > i have asked you several times about this(changing the behavior of a widget) but it seems that you have misunderstood me or i have misunderstood you, or both. Yes. > what about this "first chance callbacks" jeroen talks about (see his post below)? > i would like to know whether these can be used in FXRuby too. Yes, this refers to the connect() method that I've referred to several times now. > you once said (in other words for you, if i got you right): >> fox widgets catch events react and then block them. >> so it is not possible to overwrite the default behavior for these events. If I said this, I misspoke. Let me describe the typical pattern for how events get processed by FOX, as I understand it. I will specifically focus on the things that happen when a user clicks on an FXButton widget, but I think this pattern is generally true for other kinds of events. When you "click" on an FXButton in a FOX GUI with the left mouse button, two events are generated: a "left mouse button down" event and a "left mouse button up". FOX assigns the names SEL_LEFTBUTTONPRESS and SEL_LEFTBUTTONRELEASE, respectively. The SEL_LEFTBUTTONPRESS message is always sent *directly* to the FXButton widget, first thing. And if you don't do anything special in your program, the FXButton *does* implement some default behavior in response to that message. But you can circumvent this default behavior for SEL_LEFTBUTTONPRESS by taking advantage of what Jeroen referred to as "first-chance" callbacks, and you do this in your programs by attaching a handler block or method to the FXButton widget: theButton = FXButton.new(...) theButton.connect(SEL_LEFTBUTTONPRESS) { } When you use the #connect method to attach a handler to the widget, you are asking the FXButton to call this block of code to handle the message, instead of relying on the default behavior. In other words, your code gets the "first chance" to handle the SEL_LEFTBUTTONPRESS message. > it seems possible to override the default behavior in C++. A possibility that arises from that: you could > override the default behavior of all widgets (for right mouse click, for instance) > this would be very useful to me. but it's not useful if i cannot pop up a menu on every widget (using right click). I think I'm correct in saying that you can't override the default behavior for *all* widgets in one fell swoop, either in C++ or in Ruby. That is because most widgets already have customized behavior for those messages. To use a non-FOX example, pretend you've designed a library representing animals, with this base class: class Animal def speak "" end end Then you start subclassing that for various animals: class Cat < Animal def speak "Meow!" end end class Dog < Animal def speak "Woof!" end end class Cow < Animal def speak "Moo!" end end So now each of the subclasses has a customized behavior for #speak, with the result: Cat.new.speak # answers "Meow!" Dog.new.speak # answers "Woof!" Cow.new.speak # answers "Moo!" But what if a user of your library decides that he wants each of the animals to instead stomp its foot on the ground when he calls #speak? You can't just change this behavior in one place -- you would need to modify each of the subclasses to update their behavior. |