[Glade-users] Question about gtk_widget pixmap and imlib



Roberto Diaz wrote:

  pixmap = gtk_pixmap_new (gdkpixmap, mask);
  gdk_pixmap_unref (gdkpixmap);
  gdk_bitmap_unref (mask);

In this code I have another question...

When we create the pixmap (or whatever other widget) with:

pixmap = gtk_pixmap_new (..);

dont we have the pointer pixmap with its reference count sets to 1?

This is because in the glade generated code I'm always seeing things like
this:

GtkWidget *togglebutton1;
togglebutton1 = gtk_toggle_button_new_with_label (_("togglebutton1"));
gtk_widget_ref (togglebutton1);
..........

Well.. Why do we need to ref togglebutton1? dont we have its reference
count incremented in the constructor
gtk_toggle_button_new_with_label() already?

Glade adds a ref to the widget as it stores a pointer to the widget in the
toplevel widget's datalist. This is so you can use lookup_widget() to get
a pointer to any widget in the window. If we didn't ref the widget and it was
destroyed somehow, our pointer would be invalid and the app may crash.

Glade also adds code to unref the widget when the toplevel widget is destroyed:

  gtk_widget_ref (fixed1);
  gtk_object_set_data_full (GTK_OBJECT (window1), "fixed1", fixed1,
                            (GtkDestroyNotify) gtk_widget_unref);


You don't normally ref widgets after creating them.

Damon






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