save the orphan




I'm trying to keep a widget alive and undestroyed after the demise of its
parent container.  I attempt this by referencing the child, then
unparenting the child, and finally destroying the parent.

Unfortunately, after this procedure I am unable to reparent the widget and
show it.  I get the following error:
  (gtk_style_attach): assertion `style != NULL' failed.

The following code illustrates the problem.  Thanks in advance.

#include <gtk/gtk.h>

void destroy(GtkWidget *widget, gpointer data)
{
  gtk_main_quit();
}

int main (int argc, char *argv[])
{
  GtkWidget *win;
  GtkWidget *label;
           
  gtk_init (&argc, &argv);
           
  win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  label = gtk_label_new("hello");
  gtk_widget_ref(label);
  gtk_container_add(GTK_CONTAINER(win), label);
  gtk_widget_show(label);
  gtk_widget_show (win);

  gtk_widget_unparent(label);
  gtk_widget_destroy(win);
  
  win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  gtk_signal_connect (GTK_OBJECT (win), "destroy",
				  (GtkSignalFunc) destroy, NULL);
  gtk_container_add(GTK_CONTAINER(win), label);
  gtk_widget_show(label);
  gtk_widget_show (win);
           
  gtk_main();
           
  return(0);
}
       /* example-end */

----------------------------------------------------------------
                       Joshua Richardson
Dept. Cognitive and Neural Systems / Center for Adaptive Systems
                       Boston University
----------------------------------------------------------------



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