Re: [gtk-list] On object types



On Thu, 2 Jul 1998, Didimo Emilio Grimaldo Tunon wrote:

> 
>   A simple question, do all the widgets have to be declared as GtkWidget *
>   or is that merely a convenience? I mean, is it valid to declare an
>   entry widget as such, i.e.
> 
>   		GtkEntry *oneEntry;
> 
>   the reason for the question is that I see a lot of casting being
>   used like GTK_ENTRY(oneEntry) and wonder if so much programmatical
>   orthopedics is actually needed. Answers anybody?

usually you use e.g. a button like this:

button = gtk_button_new_with_label ("huhu");
gtk_widget_show (button);
gtk_container_add (GTK_CONTAINER (some_box), button);
gtk_widget_grab_default (button);
gtk_widget_freeze_accelerators (button);

since most of these functions expect a GtkWidget* as argument,
it is more convenient to declare a button like GtkWidget*button; in
the first place.
however there might be exceptions, e.g. if you do some heavy object-type
bound operations on a certain widget. in such cases it is sometimes more
convenient to declare a widget as its real type, e.g.:

GtkEntry *entry;

entry = (GtkEntry*)
  gtk_widget_new (GTK_TYPE_ENTRY,
                  "GtkWidget::visible", TRUE,
                  "GtkWidget::parent", some_box,
                  NULL);
gtk_entry_set_text (entry, "huhu");
gtk_entry_set_position (entry, 5);
gtk_entry_select_region (entry, 0, -1);
gtk_entry_set_visibility (entry, TRUE);
gtk_entry_set_max_length (entry, 25);

in general you'd declare a widget with that type, that you are most likely
to need more often, so as to reduce the amount of needed type casts, might
that be GTK_WIDGET () or GTK_ENTRY () or even GTK_BUTTON ().

> 
>   		Cheers,
> 			Emilio
> 

---
ciaoTJ



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]