On Fri, Dec 16, 2011 at 04:09:54PM -0700, Michael Torrie wrote: > > 1. Copy an entire GTK widget and give it a unique name. > > Example: GtkButton becomes GtkMyButton > > You really could Create a GtkMyButton by inheriting from GtkButton and > adding your own code. However, just as in C++, the ability to override > specific methods depends on whether they were made as virtual or static > methods. static methods can't be overridden, but you could just shadow > them with your own methods and use them instead.
I wish it was so. What invariably happens in practice is this: (a) You find that the widget implementation either provides some library-level-private _gtk_button_foo() methods or depends on such methods. This is the absolutely worst case because it can easily prevent even copying the code and creating a similarly behaving widget if it needs to use these functions. Unfortunately quite common. (b) Other code in Gtk+ calls the static methods. This means that you cannot substitute your derived widget for the base class if you need different behaviour (but you can happily use the derived widget in your own code). Apparently quite rare, possibly because the devs usually convert this to (a) by making the static method library-private. (c) To extend the virtual methods you would need to access parent widget state which is private. So you need to copy the implementation. If you do not run in to (a) or (b) then consider yourself lucky. Note I do not talk about trivial extensions such as those you posted. Could you write GtkToggleButton derived from GtkButton if it did not exist? Nope. Yeti _______________________________________________ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list