Back to index

lightning-sunbird  0.9+nobinonly
TestGtkEmbedChild.cpp
Go to the documentation of this file.
00001 /* ***** BEGIN LICENSE BLOCK *****
00002  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00003  *
00004  * The contents of this file are subject to the Mozilla Public License Version
00005  * 1.1 (the "License"); you may not use this file except in compliance with
00006  * the License. You may obtain a copy of the License at
00007  * http://www.mozilla.org/MPL/
00008  *
00009  * Software distributed under the License is distributed on an "AS IS" basis,
00010  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00011  * for the specific language governing rights and limitations under the
00012  * License.
00013  *
00014  * The Original Code is mozilla.org code.
00015  *
00016  * The Initial Developer of the Original Code is
00017  * Christopher Blizzard. Portions created by Christopher Blizzard are Copyright (C) Christopher Blizzard.  All Rights Reserved.
00018  * Portions created by the Initial Developer are Copyright (C) 2001
00019  * the Initial Developer. All Rights Reserved.
00020  *
00021  * Contributor(s):
00022  *   Christopher Blizzard <blizzard@mozilla.org>
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #include "gtkmozembed.h"
00039 #include <gtk/gtk.h>
00040 #include <gdk/gdkx.h>
00041 #include <stdio.h>
00042 #include <stdlib.h>
00043 
00044 int (*old_handler) (Display *, XErrorEvent *);
00045 
00046 int error_handler (Display *d, XErrorEvent *e)
00047 {
00048   if ((e->error_code == BadWindow) || (e->error_code == BadDrawable))
00049     {
00050       XID resourceid = e->resourceid;
00051       GdkWindow *window = gdk_window_lookup (resourceid);
00052 
00053       if (window)
00054         {
00055           if (!g_dataset_get_data (window, "bonobo-error"))
00056             {
00057               g_dataset_set_data_full (window, "bonobo-error",
00058                                        g_new (gint, 1),
00059                                        (GDestroyNotify)g_free);
00060 
00061               g_warning ("Error accessing window %ld", resourceid);
00062             }
00063         }
00064       return 0;
00065     }
00066   else
00067     {
00068       return (*old_handler)(d, e);
00069     }
00070 }
00071 
00072 void
00073 load_page(gpointer data);
00074 
00075 GtkWidget *embed = 0;
00076 GtkWidget *entry = 0;
00077 
00078 int
00079 main(int argc, char **argv)
00080 {
00081   guint32 xid;
00082 
00083   GtkWidget *window;
00084   GtkWidget *hbox;
00085   GtkWidget *vbox;
00086   GtkWidget *button;
00087 
00088   gtk_init(&argc, &argv);
00089 
00090   old_handler = XSetErrorHandler (error_handler);
00091 
00092   if (argc < 2) {
00093     fprintf(stderr, "Usage: TestGtkEmbedChild WINDOW_ID\n");
00094     exit(1);
00095   }
00096 
00097   xid = strtol (argv[1], (char **)NULL, 0);
00098 
00099   if (xid == 0) {
00100     fprintf(stderr, "Invalid window id '%s'\n", argv[1]);
00101     exit(1);
00102   }
00103 
00104   window = gtk_plug_new(xid);
00105 
00106   gtk_signal_connect(GTK_OBJECT(window), "destroy",
00107                    GTK_SIGNAL_FUNC(gtk_main_quit), NULL);
00108 
00109   gtk_container_border_width(GTK_CONTAINER(window), 0);
00110 
00111   vbox = gtk_vbox_new (FALSE, 0);
00112   gtk_container_add(GTK_CONTAINER(window), vbox);
00113   gtk_widget_show(vbox);
00114 
00115   hbox = gtk_hbox_new (FALSE, 0);
00116   gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, TRUE, 0);
00117   gtk_widget_show (hbox);
00118 
00119   entry = gtk_entry_new ();
00120   gtk_box_pack_start (GTK_BOX (hbox), entry, TRUE, TRUE, 0);
00121   gtk_widget_show (entry);
00122 
00123   button = gtk_button_new_with_label("Load");
00124   gtk_box_pack_start(GTK_BOX(hbox), button, TRUE, TRUE, 0);
00125   gtk_widget_show(button);
00126 
00127   gtk_signal_connect(GTK_OBJECT(button), "clicked",
00128                    GTK_SIGNAL_FUNC(load_page), NULL);
00129 
00130   embed = gtk_moz_embed_new();
00131   gtk_box_pack_start(GTK_BOX(vbox), embed, TRUE, TRUE, 0);
00132   gtk_widget_set_usize(embed, 200, 200);
00133   gtk_widget_show(embed);
00134 
00135   gtk_widget_show(window);
00136   
00137   gtk_main();
00138 
00139   fprintf(stderr, "exiting.\n");
00140 
00141   return 0;
00142 }
00143 
00144 void
00145 load_page(gpointer data)
00146 {
00147   gchar *text = gtk_editable_get_chars(GTK_EDITABLE(entry), 0, -1);
00148   g_print("load url %s\n", text);
00149   gtk_moz_embed_load_url(GTK_MOZ_EMBED(embed), text);
00150   g_free(text);
00151 }