Bug 435739 Poor performance of Firefox 3 with no X RENDER extension
[wine-gecko.git] / embedding / browser / gtk / tests / TestGtkEmbedMDI.cpp
blob89799a8b735937862327a15d52f7c2e158a9e3c6
1 /** simplemdi.c **/
2 /*
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
9 * off to a new window.
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.)
18 #include <gnome.h>
19 #include "gtkmozembed.h"
21 // Testing flags
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.)
42 #define SAMPLE_PIXMAP
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,
54 gpointer data);
56 int main(int argc,char *argv[])
58 GtkObject *mdi;
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");
68 addChild(mdi,"Last");
70 gnome_mdi_set_mode(GNOME_MDI(mdi),GNOME_MDI_NOTEBOOK);
71 //gnome_mdi_open_toplevel(GNOME_MDI(mdi));
73 gtk_main();
74 exit(0);
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,
85 createView,name);
86 gnome_mdi_generic_child_set_label_func(child,setLabel,
87 NULL);
88 gnome_mdi_add_view(GNOME_MDI(mdi),
89 GNOME_MDI_CHILD(child));
91 static GtkWidget *createView(GnomeMDIChild *child,
92 gpointer data)
94 #ifdef USE_MOZILLA_TEST
95 GtkWidget *browser = gtk_moz_embed_new();
96 #else
97 #ifndef SAMPLE_PIXMAP
98 GtkWidget *browser = gtk_label_new("lynx 0.01a");
99 #else
100 /* Another example -- */
101 GtkWidget *browser =
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();
107 char str[80];
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 */
115 #ifndef SIMPLER_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);
121 return (notebook);
122 #else
123 gtk_widget_show(browser);
124 return (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),
135 child->name);
136 return(currentLabel);
138 gint eventDestroy(GtkWidget *widget,
139 GdkEvent *event,gpointer data) {
140 gtk_main_quit();
141 return(0);