Back to index

lightning-sunbird  0.9+nobinonly
TestGtkEmbedMDI.cpp
Go to the documentation of this file.
00001 
00002 /*
00003  * Sample code from "GNOME/GTK+ Programming Bible" by Arthur Griffith
00004  * Modified by Kevin Gibbs (kgibbs@stanford.edu) to provide sample of
00005  * GtkMozEmbed realization/unrealization crashes.
00006  *
00007  * To get a fatal crash, simply run the program, click on the "Mozilla"
00008  * tab to display the MozEmbed widget, and then try to drag that MDI tab
00009  * off to a new window.
00010  * 
00011  * Although this test might seem elaborate, it is really only a convenient
00012  * to create a situation where the widget is realized, unrealized, and
00013  * realized again at some point. (Dragging the MDI tab off to a new window
00014  * causes all widgets to be unrealized in the old window, and then realized
00015  * again in the new window.) 
00016  */
00017 
00018 #include <gnome.h>
00019 #include "gtkmozembed.h"
00020 
00021 // Testing flags
00022 //
00023 
00024 // Define this flag to have the test program use the gtkmozembed widget.
00025 // Without this flag, mozilla is never loaded in the program, and a simple
00026 // widget is used in place of the mozembed widget.
00027 #define USE_MOZILLA_TEST
00028 
00029 // Define this flag to have a simpler test than the usual one. The normal
00030 // test builds a notebook inside of each MDI view, with one page being a label
00031 // and the other page being a browser widget. The simpler test does not
00032 // build a notebook and simply puts the browser widget in the MDI view itself.
00033 // Currently, this test is not very interesting, since for some reason all
00034 // the webshells just create and destroy themselves. (???)
00035 //#define SIMPLER_TEST
00036 
00037 // Define this flag to use a GnomePixmap instead of a GtkLabel as the
00038 // replacement for the gtkmozembed widget when USE_MOZILLA_TEST is
00039 // undefined. This is to stress test the program a bit more by providing a
00040 // replacement widget slightly more complex than GtkLabel.
00041 // (Has no effect when USE_MOZILLA_TEST is defined.)
00042 #define SAMPLE_PIXMAP
00043 
00044 
00045 gint eventDelete(GtkWidget *widget,
00046         GdkEvent *event,gpointer data);
00047 gint eventDestroy(GtkWidget *widget,
00048         GdkEvent *event,gpointer data);
00049 
00050 static void addChild(GtkObject *mdi,gchar *name);
00051 static GtkWidget *setLabel(GnomeMDIChild *child,
00052         GtkWidget *currentLabel,gpointer data);
00053 static GtkWidget *createView(GnomeMDIChild *child,
00054         gpointer data);
00055 
00056 int main(int argc,char *argv[])
00057 {
00058     GtkObject *mdi;
00059 
00060     gnome_init("simplemdi","1.0",argc,argv);
00061     mdi = gnome_mdi_new("simplemdi","Simple MDI");
00062     gtk_signal_connect(mdi,"destroy",
00063             GTK_SIGNAL_FUNC(eventDestroy),NULL);
00064 
00065     addChild(mdi,"First");
00066     addChild(mdi,"Second");
00067     addChild(mdi,"Third");
00068     addChild(mdi,"Last");
00069 
00070     gnome_mdi_set_mode(GNOME_MDI(mdi),GNOME_MDI_NOTEBOOK);
00071     //gnome_mdi_open_toplevel(GNOME_MDI(mdi));
00072 
00073     gtk_main();
00074     exit(0);
00075 }
00076 static void addChild(GtkObject *mdi,gchar *name)
00077 {
00078     GnomeMDIGenericChild *child;
00079 
00080     child = gnome_mdi_generic_child_new(name);
00081     gnome_mdi_add_child(GNOME_MDI(mdi),
00082             GNOME_MDI_CHILD(child));
00083 
00084     gnome_mdi_generic_child_set_view_creator(child,
00085             createView,name);
00086     gnome_mdi_generic_child_set_label_func(child,setLabel,
00087             NULL);
00088     gnome_mdi_add_view(GNOME_MDI(mdi),
00089             GNOME_MDI_CHILD(child));
00090 }
00091 static GtkWidget *createView(GnomeMDIChild *child,
00092         gpointer data)
00093 {
00094 #ifdef USE_MOZILLA_TEST
00095     GtkWidget *browser = gtk_moz_embed_new();
00096 #else
00097 #ifndef SAMPLE_PIXMAP
00098     GtkWidget *browser = gtk_label_new("lynx 0.01a");
00099 #else
00100     /* Another example -- */
00101     GtkWidget *browser =
00102       gnome_pixmap_new_from_file("/usr/share/pixmaps/emacs.png");
00103 #endif /* SAMPLE_PIXMAP */
00104 #endif /* USE_MOZILLA_TEST */
00105 
00106     GtkWidget *notebook = gtk_notebook_new();
00107     char str[80];
00108 
00109     sprintf(str,"View of the\n%s widget",(gchar *)data);
00110 
00111 #ifdef USE_MOZILLA_TEST
00112     gtk_moz_embed_load_url(GTK_MOZ_EMBED(browser), "http://www.mozilla.org");
00113 #endif /* USE_MOZILLA_TEST */
00114 
00115 #ifndef SIMPLER_TEST
00116     gtk_notebook_append_page(GTK_NOTEBOOK(notebook), gtk_label_new(str),
00117                           gtk_label_new("Label"));
00118     gtk_notebook_append_page(GTK_NOTEBOOK(notebook), browser,
00119                           gtk_label_new("Mozilla"));
00120     gtk_widget_show_all(notebook);
00121     return (notebook);
00122 #else
00123     gtk_widget_show(browser);
00124     return (browser);
00125 #endif /* SIMPLER_TEST */
00126 }
00127 
00128 static GtkWidget *setLabel(GnomeMDIChild *child,
00129         GtkWidget *currentLabel,gpointer data)
00130 {
00131     if(currentLabel == NULL)
00132         return(gtk_label_new(child->name));
00133 
00134     gtk_label_set_text(GTK_LABEL(currentLabel),
00135             child->name);
00136     return(currentLabel);
00137 }
00138 gint eventDestroy(GtkWidget *widget,
00139         GdkEvent *event,gpointer data) {
00140     gtk_main_quit();
00141     return(0);
00142 }