Re: [Fxruby-users] changing overall behavior - was (re: [Foxgui-users]making fox a superior toolkit
Status: Inactive
Brought to you by:
lyle
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. |