1 /* ***** BEGIN LICENSE BLOCK *****
2 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 * The contents of this file are subject to the Mozilla Public License Version
5 * 1.1 (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
7 * http://www.mozilla.org/MPL/
9 * Software distributed under the License is distributed on an "AS IS" basis,
10 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 * for the specific language governing rights and limitations under the
14 * The Original Code is mozilla.org code.
16 * The Initial Developer of the Original Code is
17 * Christopher Blizzard.
18 * Portions created by the Initial Developer are Copyright (C) 2001
19 * the Initial Developer. All Rights Reserved.
22 * Christopher Blizzard <blizzard@mozilla.org>
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
36 * ***** END LICENSE BLOCK ***** */
38 #include "gtkmozembed.h"
44 #include "nsStringAPI.h"
45 #include "gtkmozembed_glue.cpp"
47 int (*old_handler
) (Display
*, XErrorEvent
*);
49 int error_handler (Display
*d
, XErrorEvent
*e
)
51 if ((e
->error_code
== BadWindow
) || (e
->error_code
== BadDrawable
))
53 XID resourceid
= e
->resourceid
;
54 GdkWindow
*window
= gdk_window_lookup (resourceid
);
58 if (!g_dataset_get_data (window
, "bonobo-error"))
60 g_dataset_set_data_full (window
, "bonobo-error",
62 (GDestroyNotify
)g_free
);
64 g_warning ("Error accessing window %ld", resourceid
);
71 return (*old_handler
)(d
, e
);
76 load_page(gpointer data
);
82 main(int argc
, char **argv
)
91 gtk_init(&argc
, &argv
);
93 static const GREVersionRange greVersion
= {
98 char xpcomPath
[PATH_MAX
];
100 nsresult rv
= GRE_GetGREPathWithProperties(&greVersion
, 1, nsnull
, 0,
101 xpcomPath
, sizeof(xpcomPath
));
103 fprintf(stderr
, "Couldn't find a compatible GRE.\n");
107 rv
= XPCOMGlueStartup(xpcomPath
);
109 fprintf(stderr
, "Couldn't start XPCOM.");
113 rv
= GTKEmbedGlueStartup();
115 fprintf(stderr
, "Couldn't find GTKMozEmbed symbols.");
119 char *lastSlash
= strrchr(xpcomPath
, '/');
123 gtk_moz_embed_set_path(xpcomPath
);
125 old_handler
= XSetErrorHandler (error_handler
);
128 fprintf(stderr
, "Usage: TestGtkEmbedChild WINDOW_ID\n");
132 xid
= strtol (argv
[1], (char **)NULL
, 0);
135 fprintf(stderr
, "Invalid window id '%s'\n", argv
[1]);
139 window
= gtk_plug_new(xid
);
141 gtk_signal_connect(GTK_OBJECT(window
), "destroy",
142 GTK_SIGNAL_FUNC(gtk_main_quit
), NULL
);
144 gtk_container_border_width(GTK_CONTAINER(window
), 0);
146 vbox
= gtk_vbox_new (FALSE
, 0);
147 gtk_container_add(GTK_CONTAINER(window
), vbox
);
148 gtk_widget_show(vbox
);
150 hbox
= gtk_hbox_new (FALSE
, 0);
151 gtk_box_pack_start(GTK_BOX(vbox
), hbox
, FALSE
, TRUE
, 0);
152 gtk_widget_show (hbox
);
154 entry
= gtk_entry_new ();
155 gtk_box_pack_start (GTK_BOX (hbox
), entry
, TRUE
, TRUE
, 0);
156 gtk_widget_show (entry
);
158 button
= gtk_button_new_with_label("Load");
159 gtk_box_pack_start(GTK_BOX(hbox
), button
, TRUE
, TRUE
, 0);
160 gtk_widget_show(button
);
162 gtk_signal_connect(GTK_OBJECT(button
), "clicked",
163 GTK_SIGNAL_FUNC(load_page
), NULL
);
165 embed
= gtk_moz_embed_new();
166 gtk_box_pack_start(GTK_BOX(vbox
), embed
, TRUE
, TRUE
, 0);
167 gtk_widget_set_usize(embed
, 200, 200);
168 gtk_widget_show(embed
);
170 gtk_widget_show(window
);
174 fprintf(stderr
, "exiting.\n");
180 load_page(gpointer data
)
182 gchar
*text
= gtk_editable_get_chars(GTK_EDITABLE(entry
), 0, -1);
183 g_print("load url %s\n", text
);
184 gtk_moz_embed_load_url(GTK_MOZ_EMBED(embed
), text
);