trouble writing destroy function for new widget



	I'm having some problems in getting the destroy function
to work properly in a new widget I'm writing. The root of
the problem lies in the fact that this widget is descended from
an GtkAlignment, and contains an GtkEventBox. I put the GtkEventBox
inside the GtkAlignment, and redirect gtk_container_add and
gtk_container_remove to put the `child' of the new widget
inside the GtkEventBox. Naturally, this requires some care
in placing the GtkEventBox inside the GtkAlignment.
	Adding the GtkEventBox to the GtkAlignment
goes smoothly, but when I try to remove the GtkEventBox
in the destroy function, things go strange. The
offending piece of code is (please excuse the printf's):

  /* Get rid of the event box */

  printf("About to destroy event box.\n");

  if(GTK_IS_EVENT_BOX(mmm->event_box))
    printf("It's still an event box.\n");

  if (GTK_CONTAINER_CLASS (parent_class)->remove)
    (* GTK_CONTAINER_CLASS (parent_class)->remove)
      (GTK_CONTAINER(mmm), GTK_WIDGET(mmm->event_box));

  printf("Removed it from its parent.\n");

  if(!GTK_IS_EVENT_BOX(mmm->event_box))
    printf("We don't have an event box anymore.\n");

  gtk_widget_destroy(GTK_WIDGET(mmm->event_box));

All the printf's in the if statements print. That is, before I
call the remove function, I have a valid event box, but
afterwards I don't. The analogus code for add in the
widget creation function works fine, allowing me to
later insert a GtkPixmap in the event box and display it.
The call to gtk_widget_destroy causes the following two
errors,

Gtk-WARNING **: invalid cast from `(unknown)' to `GtkWidget'

Gtk-CRITICAL **: file gtkwidget.c: line 1385 (gtk_widget_destroy): assertion `GTK_IS_WIDGET (widget)' failed.

as mmm->event_box is no longer a valid widget, but otherwise
there are no errors. Any ideas as to what went wrong?

						Ron Steinke




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