3 * Sample code from "GNOME/GTK+ Programming Bible" by Arthur Griffith
4 * Modified by Kevin Gibbs (kgibbs@stanford.edu) to provide sample of
5 * GtkMozEmbed realization/unrealization crashes.
7 * To get a fatal crash, simply run the program, click on the "Mozilla"
8 * tab to display the MozEmbed widget, and then try to drag that MDI tab
11 * Although this test might seem elaborate, it is really only a convenient
12 * to create a situation where the widget is realized, unrealized, and
13 * realized again at some point. (Dragging the MDI tab off to a new window
14 * causes all widgets to be unrealized in the old window, and then realized
15 * again in the new window.)
19 #include "gtkmozembed.h"
24 // Define this flag to have the test program use the gtkmozembed widget.
25 // Without this flag, mozilla is never loaded in the program, and a simple
26 // widget is used in place of the mozembed widget.
27 #define USE_MOZILLA_TEST
29 // Define this flag to have a simpler test than the usual one. The normal
30 // test builds a notebook inside of each MDI view, with one page being a label
31 // and the other page being a browser widget. The simpler test does not
32 // build a notebook and simply puts the browser widget in the MDI view itself.
33 // Currently, this test is not very interesting, since for some reason all
34 // the webshells just create and destroy themselves. (???)
35 //#define SIMPLER_TEST
37 // Define this flag to use a GnomePixmap instead of a GtkLabel as the
38 // replacement for the gtkmozembed widget when USE_MOZILLA_TEST is
39 // undefined. This is to stress test the program a bit more by providing a
40 // replacement widget slightly more complex than GtkLabel.
41 // (Has no effect when USE_MOZILLA_TEST is defined.)
45 gint
eventDelete(GtkWidget
*widget
,
46 GdkEvent
*event
,gpointer data
);
47 gint
eventDestroy(GtkWidget
*widget
,
48 GdkEvent
*event
,gpointer data
);
50 static void addChild(GtkObject
*mdi
,gchar
*name
);
51 static GtkWidget
*setLabel(GnomeMDIChild
*child
,
52 GtkWidget
*currentLabel
,gpointer data
);
53 static GtkWidget
*createView(GnomeMDIChild
*child
,
56 int main(int argc
,char *argv
[])
60 gnome_init("simplemdi","1.0",argc
,argv
);
61 mdi
= gnome_mdi_new("simplemdi","Simple MDI");
62 gtk_signal_connect(mdi
,"destroy",
63 GTK_SIGNAL_FUNC(eventDestroy
),NULL
);
65 addChild(mdi
,"First");
66 addChild(mdi
,"Second");
67 addChild(mdi
,"Third");
70 gnome_mdi_set_mode(GNOME_MDI(mdi
),GNOME_MDI_NOTEBOOK
);
71 //gnome_mdi_open_toplevel(GNOME_MDI(mdi));
76 static void addChild(GtkObject
*mdi
,gchar
*name
)
78 GnomeMDIGenericChild
*child
;
80 child
= gnome_mdi_generic_child_new(name
);
81 gnome_mdi_add_child(GNOME_MDI(mdi
),
82 GNOME_MDI_CHILD(child
));
84 gnome_mdi_generic_child_set_view_creator(child
,
86 gnome_mdi_generic_child_set_label_func(child
,setLabel
,
88 gnome_mdi_add_view(GNOME_MDI(mdi
),
89 GNOME_MDI_CHILD(child
));
91 static GtkWidget
*createView(GnomeMDIChild
*child
,
94 #ifdef USE_MOZILLA_TEST
95 GtkWidget
*browser
= gtk_moz_embed_new();
98 GtkWidget
*browser
= gtk_label_new("lynx 0.01a");
100 /* Another example -- */
102 gnome_pixmap_new_from_file("/usr/share/pixmaps/emacs.png");
103 #endif /* SAMPLE_PIXMAP */
104 #endif /* USE_MOZILLA_TEST */
106 GtkWidget
*notebook
= gtk_notebook_new();
109 sprintf(str
,"View of the\n%s widget",(gchar
*)data
);
111 #ifdef USE_MOZILLA_TEST
112 gtk_moz_embed_load_url(GTK_MOZ_EMBED(browser
), "http://www.mozilla.org");
113 #endif /* USE_MOZILLA_TEST */
116 gtk_notebook_append_page(GTK_NOTEBOOK(notebook
), gtk_label_new(str
),
117 gtk_label_new("Label"));
118 gtk_notebook_append_page(GTK_NOTEBOOK(notebook
), browser
,
119 gtk_label_new("Mozilla"));
120 gtk_widget_show_all(notebook
);
123 gtk_widget_show(browser
);
125 #endif /* SIMPLER_TEST */
128 static GtkWidget
*setLabel(GnomeMDIChild
*child
,
129 GtkWidget
*currentLabel
,gpointer data
)
131 if(currentLabel
== NULL
)
132 return(gtk_label_new(child
->name
));
134 gtk_label_set_text(GTK_LABEL(currentLabel
),
136 return(currentLabel
);
138 gint
eventDestroy(GtkWidget
*widget
,
139 GdkEvent
*event
,gpointer data
) {