Filter:   InfoImg
download bonobo-ui-main.c
Language: C
Copyright: Copyright 1999, 2001 Ximian, Inc.
LOC: 195
Project Info
libbonoboui
Server: Gnome
Type: cvs
...onoboui\libbonoboui\bonobo\
   .cvsignore
   bonobo-a11y.c
   bonobo-a11y.h
   bonobo-canvas-component.c
   bonobo-canvas-component.h
   bonobo-canvas-item.c
   bonobo-canvas-item.h
   bonobo-control-frame.c
   bonobo-control-frame.h
   bonobo-control-internal.h
   bonobo-control.c
   bonobo-control.h
   bonobo-dock-band.c
   bonobo-dock-band.h
   bonobo-dock-item-grip.c
   bonobo-dock-item-grip.h
   bonobo-dock-item.c
   bonobo-dock-item.h
   bonobo-dock-layout.c
   bonobo-dock-layout.h
   bonobo-dock.c
   bonobo-dock.h
   ...bo-embeddable-factory.h
   ...bo-file-selector-util.c
   ...bo-file-selector-util.h
   ...bo-insert-component.xpm
   bonobo-plug.c
   bonobo-plug.h
   bonobo-property-control.c
   bonobo-property-control.h
   bonobo-selector-widget.c
   bonobo-selector-widget.h
   bonobo-selector.c
   bonobo-selector.h
   bonobo-socket.c
   bonobo-socket.h
   bonobo-ui-component.c
   bonobo-ui-component.h
   bonobo-ui-config-widget.c
   bonobo-ui-config-widget.h
   bonobo-ui-container.c
   bonobo-ui-container.h
   bonobo-ui-engine-config.c
   bonobo-ui-engine-config.h
   bonobo-ui-engine-private.h
   bonobo-ui-engine.c
   bonobo-ui-engine.h
   bonobo-ui-init-gtk.c
   ...o-ui-internal-toolbar.c
   bonobo-ui-main.c
   bonobo-ui-main.h
   bonobo-ui-marshal-main.c
   bonobo-ui-marshal.list
   bonobo-ui-node-private.h
   bonobo-ui-node.c
   bonobo-ui-node.h
   bonobo-ui-preferences.c
   bonobo-ui-preferences.h
   bonobo-ui-private.h
   bonobo-ui-sync-keys.c
   bonobo-ui-sync-keys.h
   bonobo-ui-sync-menu.c
   bonobo-ui-sync-menu.h
   bonobo-ui-sync-status.c
   bonobo-ui-sync-status.h
   bonobo-ui-sync-toolbar.c
   bonobo-ui-sync-toolbar.h
   bonobo-ui-sync.c
   bonobo-ui-sync.h
   ...i-toolbar-button-item.c
   ...i-toolbar-button-item.h
   ...-toolbar-control-item.c
   ...-toolbar-control-item.h
   bonobo-ui-toolbar-item.c
   bonobo-ui-toolbar-item.h
   ...ui-toolbar-popup-item.c
   ...ui-toolbar-popup-item.h
   ...ar-toggle-button-item.c
   ...ar-toggle-button-item.h
   bonobo-ui-toolbar.c
   bonobo-ui-toolbar.h
   bonobo-ui-util.c
   bonobo-ui-util.h
   bonobo-ui-win32.c
   bonobo-ui-xml.c
   bonobo-ui-xml.h
   bonobo-widget.c
   bonobo-widget.h
   bonobo-window.c
   bonobo-window.h
   bonobo-wrapper.h
   bonobo-zoomable-frame.c
   bonobo-zoomable-frame.h
   bonobo-zoomable.c
   bonobo-zoomable.h
   ...i-2.0-uninstalled.pc.in
   libbonoboui-2.0.pc.in
   Makefile.am

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/**
 * bonobo-main.c: Bonobo Main
 *
 * Author:
 *    Miguel de Icaza  (miguel@gnu.org)
 *    Nat Friedman     (nat@nat.org)
 *    Peter Wainwright (prw@wainpr.demo.co.uk)
 *
 * Copyright 1999, 2001 Ximian, Inc.
 */
#include <config.h>

#include <bonobo/bonobo-i18n.h>
#include <bonobo/bonobo-exception.h>
#include <bonobo/bonobo-ui-private.h>
#include <bonobo/bonobo-ui-main.h>
#include <bonobo/bonobo-main.h>
#include <bonobo/bonobo-a11y.h>

#include <libgnome/gnome-init.h>

#include <gtk/gtkmain.h>

#ifdef G_OS_WIN32
#include <string.h>
#include <libxml/xmlIO.h>
#include <libxml/uri.h>
#include <glib/gstdio.h>
#endif

#ifdef GDK_WINDOWING_X11
#include <gdk/gdkx.h>
#include <X11/Xlib.h>

static int (*gdk_x_error_func) (Display *, XErrorEvent *);

static int
bonobo_x_error_handler (Display *display, XErrorEvent *error)
{
	if (!error->error_code)
		return 0;

	/*
	 * If we got a BadDrawable or a BadWindow, we ignore it for
	 * now.  FIXME: We need to somehow distinguish real errors
	 * from X-server-induced errors.  Keeping a list of windows
	 * for which we will ignore BadDrawables would be a good idea.
	 */
	if (error->error_code == BadDrawable ||
	    error->error_code == BadWindow)
		return 0;

	/*
	 * Otherwise, let gdk deal.
	 */

	return gdk_x_error_func (display, error);
}

/**
 * bonobo_setup_x_error_handler:
 *
 * To do graphical embedding in the X window system, Bonobo
 * uses the classic foreign-window-reparenting trick.  The
 * GtkPlug/GtkSocket widgets are used for this purpose.  However,
 * serious robustness problems arise if the GtkSocket end of the
 * connection unexpectedly dies.  The X server sends out DestroyNotify
 * events for the descendants of the GtkPlug (i.e., your embedded
 * component's windows) in effectively random order.  Furthermore, if
 * you happened to be drawing on any of those windows when the
 * GtkSocket was destroyed (a common state of affairs), an X error
 * will kill your application.
 *
 * To solve this latter problem, Bonobo sets up its own X error
 * handler which ignores certain X errors that might have been
 * caused by such a scenario.  Other X errors get passed to gdk_x_error
 * normally.
 */
void
bonobo_setup_x_error_handler (void)
{
	static gboolean error_handler_setup = FALSE;

	if (error_handler_setup)
		return;

	error_handler_setup = TRUE;

	gdk_x_error_func = XSetErrorHandler (bonobo_x_error_handler);
}

#endif

static gboolean bonobo_ui_inited = FALSE;

gboolean
bonobo_ui_is_initialized (void)
{
	return bonobo_ui_inited;
}

#ifdef G_OS_WIN32

static void *
utf8_file_open_real (const char *filename)
{
    const char *path = NULL;
    FILE *fd;

    if (filename == NULL)
        return (NULL);

    if (!strcmp (filename, "-")) {
	fd = stdin;
	return ((void *) fd);
    }

    if (!xmlStrncasecmp (filename, "file://localhost/", 17))
	    path = &filename[17];
    else if (!xmlStrncasecmp (filename, "file:///", 8)) {
	    path = &filename[8];
    } else 
	    path = filename;

    if (path == NULL)
	    return (NULL);
    if (!g_file_test (path, G_FILE_TEST_IS_REGULAR))
	    return (NULL);

    fd = g_fopen (path, "rb");
    if (fd == NULL)
	    return (NULL);

    return ((void *) fd);
}

static void *
utf8_file_open (const char *filename)
{
	char *unescaped;
	void *retval;

	unescaped = xmlURIUnescapeString (filename, 0, NULL);
	if (unescaped != NULL) {
		retval = utf8_file_open_real (unescaped);
		xmlFree (unescaped);
	} else {
		retval = utf8_file_open_real (filename);
	}
	return retval;
	
}

#endif

static void
do_low_level_init (void)
{
#ifdef GDK_WINDOWING_X11
	CORBA_Context context;
	CORBA_Environment ev;
	GdkDisplay *display;
	Display *xdisplay;
#endif

	if (bonobo_ui_inited)
		return;

	bonobo_ui_inited = TRUE;

	gtk_set_locale ();
	bindtextdomain (GETTEXT_PACKAGE, BONOBO_LOCALEDIR);
	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");

#ifdef G_OS_WIN32
	/* This is a suitable place to register our own libxml2 file
	 * open callback that takes UTF-8 filenames.
	 */
	xmlRegisterInputCallbacks (xmlFileMatch, utf8_file_open,
				   xmlFileRead, xmlFileClose);
#endif

#ifdef GDK_WINDOWING_X11
	bonobo_setup_x_error_handler ();

	display = gdk_display_get_default ();
	xdisplay = gdk_x11_display_get_xdisplay (display);
		
	CORBA_exception_init (&ev);

	/* FIXME: nasty contractual bonobo-activation issues here */
	context = bonobo_activation_context_get ();
	CORBA_Context_set_one_value (
		context, "display",
		DisplayString (xdisplay),
		&ev);

	CORBA_exception_free (&ev);
#endif
}

/* compat */
gboolean
bonobo_ui_init (const gchar *app_name, const gchar *app_version,
		int *argc, char **argv)
{
	return bonobo_ui_init_full (app_name, app_version, argc, argv,
				    NULL, NULL, NULL, TRUE);
}

/* compat */
gboolean
bonobo_ui_init_full (const gchar *app_name, const gchar *app_version,
		     int *argc, char **argv, CORBA_ORB orb,
		     PortableServer_POA poa, PortableServer_POAManager manager,
		     gboolean full_init)
{
	if (bonobo_ui_inited)
		return TRUE;
	else
		bonobo_ui_inited = TRUE;

	if (!bonobo_init (argc, argv))
		return FALSE;

	g_set_prgname (app_name);

	if (full_init) {
		/* Initialize all our dependencies. */

		gtk_set_locale ();
		bindtextdomain (GETTEXT_PACKAGE, BONOBO_LOCALEDIR);
		bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");

		gnome_program_init (
			app_name, app_version,
			libgnome_module_info_get (),
			*argc, argv, NULL);
	}

	gtk_init (argc, &argv);

	do_low_level_init ();

	return TRUE;
}

void
bonobo_ui_main (void)
{
	bonobo_activate ();

	gtk_main ();
}

int
bonobo_ui_debug_shutdown (void)
{
	if (bonobo_ui_preferences_shutdown ())
		return 1;
	
	return bonobo_debug_shutdown ();
}

static void
libbonoboui_post_args_parse (GnomeProgram    *program,
			     GnomeModuleInfo *mod_info)
{
	do_low_level_init ();
}

const GnomeModuleInfo *
libbonobo_ui_module_info_get (void)
{
	static GnomeModuleInfo module_info = {
		"libbonoboui", VERSION,
		N_("Bonobo GUI support"),
		NULL, NULL,
		NULL, libbonoboui_post_args_parse,
		NULL, NULL, NULL, NULL
	};

	if (module_info.requirements == NULL) {
		static GnomeModuleRequirement req[6];

		req[0].required_version = "1.3.7";
		req[0].module_info = bonobo_ui_gtk_module_info_get ();

		req[1].required_version = "1.102.0";
		req[1].module_info = LIBGNOME_MODULE;

		req[2].required_version = "1.101.2";
		req[2].module_info = GNOME_BONOBO_MODULE;

		req[5].required_version = NULL;
		req[5].module_info = NULL;

		module_info.requirements = req;
	}

	return &module_info;
}