Re: [gtk-list] Return type question ...
- From: "David M. Cook" <davecook home com>
- To: gtk-list redhat com
- Subject: Re: [gtk-list] Return type question ...
- Date: Wed, 20 Jan 1999 00:28:45 -0800
On Wed, Jan 20, 1999 at 01:34:22AM -0600, Andrew P. Lentvorski wrote:
> Why do the gtk_XXXXXX_new() functions return a pointer to GtkWidget instead
> of a pointer to XXXXXX?
It's part of the OO design of Gtk. A GtkButton is a subclass of GtkWidget.
> I presume this was a design decision made somewhere, but is this being carried
> solely for backward compatibility? Or is there a really important reason
> that I should be making everything a GtkWidget rather than casting it
> immediately like:
> button = GTK_BUTTON(gtk_button_new_with_label("button));
Usually it's done the other way round:
GtkWidget *button;
button = gtk_button_new_with_label ("Howdy!");
gtk_widget_set_usize(button, 100,100);
gtk_button_set_relief (GTK_BUTTON (button));
Most of the time you are using the GtkButton "methods" inherited from
GtkWidget, i.e. most of the time in your program a button behaves like a
widget and only part of the time are you using its special button behaviors.
You only cast to GtkButton when you need to invoke specialized GtkButton
methods like set_relief above.
Dave Cook
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]