add some extra test cases for the embedding widget

This commit is contained in:
blizzard%redhat.com 2000-08-09 02:52:09 +00:00
Родитель f3b71a95e8
Коммит 3a62c82e10
3 изменённых файлов: 218 добавлений и 1 удалений

Просмотреть файл

@ -26,10 +26,27 @@ VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
CPPSRCS = \
TestGtkEmbed.cpp
TestGtkEmbed.cpp \
TestGtkEmbedNotebook.cpp
SIMPLE_PROGRAMS = $(CPPSRCS:.cpp=)
# ENABLE_GNOME=1
ifdef ENABLE_GNOME
CPPSRCS += TestGtkEmbedMDI.cpp
LIBS = \
$(MOZ_COMPONENT_LIBS) \
-lgtkembedmoz \
-lgtksuperwin \
`gnome-config --libs gnomeui` \
$(TK_LIBS) \
$(NULL)
else
LIBS = \
$(MOZ_COMPONENT_LIBS) \
-lgtkembedmoz \
@ -37,7 +54,16 @@ LIBS = \
$(TK_LIBS) \
$(NULL)
endif
include $(topsrcdir)/config/rules.mk
ifdef ENABLE_GNOME
CXXFLAGS += $(MOZ_GTK_CFLAGS) `gnome-config --cflags gnomeui`
else
CXXFLAGS += $(MOZ_GTK_CFLAGS)
endif

Просмотреть файл

@ -0,0 +1,142 @@
/** simplemdi.c **/
/*
* Sample code from "GNOME/GTK+ Programming Bible" by Arthur Griffith
* Modified by Kevin Gibbs (kgibbs@stanford.edu) to provide sample of
* GtkMozEmbed realization/unrealization crashes.
*
* To get a fatal crash, simply run the program, click on the "Mozilla"
* tab to display the MozEmbed widget, and then try to drag that MDI tab
* off to a new window.
*
* Although this test might seem elaborate, it is really only a convenient
* to create a situation where the widget is realized, unrealized, and
* realized again at some point. (Dragging the MDI tab off to a new window
* causes all widgets to be unrealized in the old window, and then realized
* again in the new window.)
*/
#include <gnome.h>
#include "gtkmozembed.h"
// Testing flags
//
// Define this flag to have the test program use the gtkmozembed widget.
// Without this flag, mozilla is never loaded in the program, and a simple
// widget is used in place of the mozembed widget.
#define USE_MOZILLA_TEST
// Define this flag to have a simpler test than the usual one. The normal
// test builds a notebook inside of each MDI view, with one page being a label
// and the other page being a browser widget. The simpler test does not
// build a notebook and simply puts the browser widget in the MDI view itself.
// Currently, this test is not very interesting, since for some reason all
// the webshells just create and destroy themselves. (???)
//#define SIMPLER_TEST
// Define this flag to use a GnomePixmap instead of a GtkLabel as the
// replacement for the gtkmozembed widget when USE_MOZILLA_TEST is
// undefined. This is to stress test the program a bit more by providing a
// replacement widget slightly more complex than GtkLabel.
// (Has no effect when USE_MOZILLA_TEST is defined.)
#define SAMPLE_PIXMAP
gint eventDelete(GtkWidget *widget,
GdkEvent *event,gpointer data);
gint eventDestroy(GtkWidget *widget,
GdkEvent *event,gpointer data);
static void addChild(GtkObject *mdi,gchar *name);
static GtkWidget *setLabel(GnomeMDIChild *child,
GtkWidget *currentLabel,gpointer data);
static GtkWidget *createView(GnomeMDIChild *child,
gpointer data);
int main(int argc,char *argv[])
{
GtkObject *mdi;
gnome_init("simplemdi","1.0",argc,argv);
mdi = gnome_mdi_new("simplemdi","Simple MDI");
gtk_signal_connect(mdi,"destroy",
GTK_SIGNAL_FUNC(eventDestroy),NULL);
addChild(mdi,"First");
addChild(mdi,"Second");
addChild(mdi,"Third");
addChild(mdi,"Last");
gnome_mdi_set_mode(GNOME_MDI(mdi),GNOME_MDI_NOTEBOOK);
//gnome_mdi_open_toplevel(GNOME_MDI(mdi));
gtk_main();
exit(0);
}
static void addChild(GtkObject *mdi,gchar *name)
{
GnomeMDIGenericChild *child;
child = gnome_mdi_generic_child_new(name);
gnome_mdi_add_child(GNOME_MDI(mdi),
GNOME_MDI_CHILD(child));
gnome_mdi_generic_child_set_view_creator(child,
createView,name);
gnome_mdi_generic_child_set_label_func(child,setLabel,
NULL);
gnome_mdi_add_view(GNOME_MDI(mdi),
GNOME_MDI_CHILD(child));
}
static GtkWidget *createView(GnomeMDIChild *child,
gpointer data)
{
#ifdef USE_MOZILLA_TEST
GtkWidget *browser = gtk_moz_embed_new();
#else
#ifndef SAMPLE_PIXMAP
GtkWidget *browser = gtk_label_new("lynx 0.01a");
#else
/* Another example -- */
GtkWidget *browser =
gnome_pixmap_new_from_file("/usr/share/pixmaps/emacs.png");
#endif /* SAMPLE_PIXMAP */
#endif /* USE_MOZILLA_TEST */
GtkWidget *notebook = gtk_notebook_new();
char str[80];
sprintf(str,"View of the\n%s widget",(gchar *)data);
#ifdef USE_MOZILLA_TEST
gtk_moz_embed_load_url(GTK_MOZ_EMBED(browser), "http://www.mozilla.org");
#endif /* USE_MOZILLA_TEST */
#ifndef SIMPLER_TEST
gtk_notebook_append_page(GTK_NOTEBOOK(notebook), gtk_label_new(str),
gtk_label_new("Label"));
gtk_notebook_append_page(GTK_NOTEBOOK(notebook), browser,
gtk_label_new("Mozilla"));
gtk_widget_show_all(notebook);
return (notebook);
#else
gtk_widget_show(browser);
return (browser);
#endif /* SIMPLER_TEST */
}
static GtkWidget *setLabel(GnomeMDIChild *child,
GtkWidget *currentLabel,gpointer data)
{
if(currentLabel == NULL)
return(gtk_label_new(child->name));
gtk_label_set_text(GTK_LABEL(currentLabel),
child->name);
return(currentLabel);
}
gint eventDestroy(GtkWidget *widget,
GdkEvent *event,gpointer data) {
gtk_main_quit();
return(0);
}

Просмотреть файл

@ -0,0 +1,49 @@
#include <gtk/gtk.h>
#include <gtkmozembed.h>
int main(int argc, char *argv[])
{
GtkWidget *window;
GtkWidget *label;
GtkWidget *mozembed;
GtkWidget *container;
char *url;
gtk_init(&argc, &argv);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
container = gtk_notebook_new();
mozembed = gtk_moz_embed_new();
label = gtk_label_new("Can you see this message?\n"
"Once you switch to mozembed page "
"you never see this message.");
gtk_signal_connect(GTK_OBJECT(mozembed), "destroy",
GTK_SIGNAL_FUNC(gtk_main_quit),
NULL);
gtk_container_add(GTK_CONTAINER(window), container);
gtk_notebook_append_page(GTK_NOTEBOOK(container),
label,
gtk_label_new("gtk label"));
gtk_notebook_append_page(GTK_NOTEBOOK(container),
mozembed,
gtk_label_new("mozembed"));
gtk_widget_set_usize(window, 400, 300);
gtk_widget_show(mozembed);
gtk_widget_show(label);
gtk_widget_show_all(window);
url = (argc > 1) ? argv[1] : "localhost";
gtk_moz_embed_load_url(GTK_MOZ_EMBED(mozembed), url);
gtk_main();
return 0;
}