Bug/Feature Destroying Widgets



The hard work is really paying off . . . the toolkit is awesome!

A program that worked with a previous version of GTK (0.99.1) no longer
destroys widgets with the gtk_widget_destroy() command.  If I try to
destroy a frame, only things *in* the frame are destroyed, not the frame
itself.  I have attached a program to demonstrate the behavior. The
program can be compiled with:

cc     frame_test.c   -o frame_test -lgtk -lgdk -lglib -lX11
-L/usr/X11R6/lib -lXext -lm

Is there a new way to destroy widgets or is this a bug introduced in
recent releases?

$cott




#include <gtk/gtk.h>

void
destroy_my_widget (GtkWidget *widget, GtkWidget *my_widget)
{
  gtk_widget_destroy(my_widget);
  printf("Destroyed widget\n");
}

int 
main (int argc, char *argv[])
{
  GtkWidget *window;
  GtkWidget *button;
  GtkWidget *frame;
  GtkWidget *vbox;
  GtkWidget *hbox;
  GtkWidget *label;
  
  gtk_init (&argc, &argv);

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  
  gtk_window_set_title (GTK_WINDOW (window), "Dial");
  
  gtk_signal_connect (GTK_OBJECT (window), "destroy",
		      GTK_SIGNAL_FUNC (gtk_exit), NULL);
  
  gtk_container_border_width (GTK_CONTAINER (window), 10);

  vbox = gtk_vbox_new (FALSE, 5);
  gtk_container_add (GTK_CONTAINER (window), vbox);
  gtk_widget_show(vbox);

  frame = gtk_frame_new ("Sample Frame");
  gtk_box_pack_start (GTK_BOX(vbox), frame, TRUE, TRUE, 0);
  gtk_widget_show (frame); 
 
  hbox = gtk_hbox_new (FALSE, 5);
  gtk_container_add (GTK_CONTAINER (frame), hbox);
  gtk_widget_show(hbox);

  label = gtk_label_new ("Label inside frame");
  gtk_box_pack_start (GTK_BOX(hbox), label, TRUE, TRUE, 0);
  gtk_widget_show (label); 
 
  label = gtk_label_new ("Label to be destroyed");
  gtk_box_pack_start (GTK_BOX(vbox), label, TRUE, TRUE, 0);
  gtk_widget_show (label); 
 
  button = gtk_button_new_with_label("Destroy Label");
  gtk_container_add (GTK_CONTAINER (vbox), button);
  gtk_widget_show (button);
  gtk_signal_connect (GTK_OBJECT(button), "clicked",
		      GTK_SIGNAL_FUNC (destroy_my_widget), label);

  button = gtk_button_new_with_label("Destroy Frame");
  gtk_container_add (GTK_CONTAINER (vbox), button);
  gtk_widget_show (button);
  gtk_signal_connect (GTK_OBJECT(button), "clicked",
		      GTK_SIGNAL_FUNC (destroy_my_widget), frame);
  
  gtk_widget_show (window);
  
  gtk_main ();
  
  return 0;
}


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