File: bonobo-ui-container.c

package info (click to toggle)
bonobo 1.0.22-2.2
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 13,412 kB
  • ctags: 5,445
  • sloc: ansic: 51,714; sh: 7,733; makefile: 1,425; yacc: 318; xml: 266; sed: 16
file content (418 lines) | stat: -rw-r--r-- 10,504 bytes parent folder | download | duplicates (2)
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
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
/*
 * bonobo-ui-container.c: The server side CORBA impl. for BonoboWindow.
 *
 * Author:
 *	Michael Meeks (michael@helixcode.com)
 *
 * Copyright 2000 Helix Code, Inc.
 */

#include "config.h"
#include <gnome.h>
#include <liboaf/liboaf.h>

#include <bonobo/Bonobo.h>
#include <bonobo/bonobo-ui-xml.h>
#include <bonobo/bonobo-ui-util.h>
#include <bonobo/bonobo-win.h>
#include <bonobo/bonobo-ui-container.h>

#define PARENT_TYPE BONOBO_X_OBJECT_TYPE

static GtkObjectClass *bonobo_ui_container_parent_class;

struct _BonoboUIContainerPrivate {
	BonoboUIEngine *engine;
	int             flags;
};

#define WIN_DESTROYED 0x1

static BonoboUIEngine *
get_engine (PortableServer_Servant servant)
{
	BonoboUIContainer *container;

	container = BONOBO_UI_CONTAINER (bonobo_object_from_servant (servant));
	g_return_val_if_fail (container != NULL, NULL);
	g_return_val_if_fail (container->priv != NULL, NULL);

	if (container->priv->engine == NULL) {
		if (!container->priv->flags & WIN_DESTROYED)
			g_warning ("Trying to invoke CORBA method "
				   "on unbound UIContainer");
		return NULL;
	} else
		return container->priv->engine;
}

static void
impl_Bonobo_UIContainer_registerComponent (PortableServer_Servant   servant,
					   const CORBA_char        *component_name,
					   const Bonobo_Unknown     object,
					   CORBA_Environment       *ev)
{
	BonoboUIEngine *engine = get_engine (servant);

	bonobo_ui_engine_register_component (engine, component_name, object);
}

static void
impl_Bonobo_UIContainer_deregisterComponent (PortableServer_Servant servant,
					     const CORBA_char      *component_name,
					     CORBA_Environment     *ev)
{
	BonoboUIEngine *engine = get_engine (servant);

	if (!engine)
		return;

	bonobo_ui_engine_deregister_component (engine, component_name);
}

static void
impl_Bonobo_UIContainer_setNode (PortableServer_Servant   servant,
				 const CORBA_char        *path,
				 const CORBA_char        *xml,
				 const CORBA_char        *component_name,
				 CORBA_Environment       *ev)
{
	BonoboUIEngine *engine = get_engine (servant);
	BonoboUIError   err;
	BonoboUINode   *node;
	const CORBA_char *property;

/*	fprintf (stderr, "Merging :\n%s\n", xml);*/

	if (!xml)
		err = BONOBO_UI_ERROR_BAD_PARAM;
	else {
		if ((property = strrchr (path, '#'))) {
			char *real_path;
			real_path = g_strdup (path);
			real_path [property-path] = 0;
			property = property + 1; /* Skip the '#' */

			err = bonobo_ui_engine_xml_set_prop (engine,
							     real_path,
							     property,
							     xml,
							     component_name);
			g_free (real_path);
		} else {
			if (xml [0] == '\0')
				err = BONOBO_UI_ERROR_OK;

			else {
				node = bonobo_ui_node_from_string (xml);
				
				if (!node)
					err = BONOBO_UI_ERROR_INVALID_XML;
				else
					err = bonobo_ui_engine_xml_merge_tree (
						engine, path, node, component_name);
			}
		}
	}
		

	if (err) {
		if (err == BONOBO_UI_ERROR_INVALID_PATH)
			CORBA_exception_set (
				ev, CORBA_USER_EXCEPTION,
				ex_Bonobo_UIContainer_InvalidPath, NULL);
		else
			CORBA_exception_set (
				ev, CORBA_USER_EXCEPTION,
				ex_Bonobo_UIContainer_MalFormedXML, NULL);
	}
}

static CORBA_char *
impl_Bonobo_UIContainer_getNode (PortableServer_Servant servant,
				 const CORBA_char      *path,
				 const CORBA_boolean    nodeOnly,
				 CORBA_Environment     *ev)
{
	BonoboUIEngine *engine = get_engine (servant);
	CORBA_char *xml;
	const CORBA_char *property;
	
	if ((property = strrchr (path, '#'))) {
		char *real_path;
		real_path = g_strdup (path);
		real_path [property-path] = 0;
		property = property + 1; /* Skip the '#' */
		
		xml = bonobo_ui_engine_xml_get_prop (engine, real_path, property);
		g_free (real_path);
		
		if (!xml) {
			CORBA_exception_set (ev, CORBA_USER_EXCEPTION,
					     ex_Bonobo_UIContainer_InvalidPath, NULL);
			return NULL;
		}
	} else {
		xml = bonobo_ui_engine_xml_get (engine, path, nodeOnly);
	
		if (!xml) {
			CORBA_exception_set (ev, CORBA_USER_EXCEPTION,
					     ex_Bonobo_UIContainer_InvalidPath, NULL);
			return NULL;
		}
	}

	return xml;
}

static void
impl_Bonobo_UIContainer_removeNode (PortableServer_Servant servant,
				    const CORBA_char      *path,
				    const CORBA_char      *component_name,
				    CORBA_Environment     *ev)
{
	BonoboUIEngine *engine = get_engine (servant);
	BonoboUIError err;

	if (!engine)
		return;

/*	g_warning ("Node remove '%s' for '%s'", path, component_name);*/

	err = bonobo_ui_engine_xml_rm (engine, path, component_name);

	if (err)
		CORBA_exception_set (ev, CORBA_USER_EXCEPTION,
				     ex_Bonobo_UIContainer_InvalidPath, NULL);
}

static CORBA_boolean
impl_Bonobo_UIContainer_exists (PortableServer_Servant servant,
				const CORBA_char      *path,
				CORBA_Environment     *ev)
{
	BonoboUIEngine *engine = get_engine (servant);

	return bonobo_ui_engine_xml_node_exists (engine, path);
}

static void
impl_Bonobo_UIContainer_setObject (PortableServer_Servant servant,
				   const CORBA_char      *path,
				   const Bonobo_Unknown   control,
				   CORBA_Environment     *ev)
{
	BonoboUIEngine *engine = get_engine (servant);
	BonoboUIError err;

	err = bonobo_ui_engine_object_set (engine, path, control, ev);

	if (err)
		CORBA_exception_set (ev, CORBA_USER_EXCEPTION,
				     ex_Bonobo_UIContainer_InvalidPath, NULL);
}

static Bonobo_Unknown
impl_Bonobo_UIContainer_getObject (PortableServer_Servant servant,
				   const CORBA_char      *path,
				   CORBA_Environment     *ev)
{
	BonoboUIEngine *engine = get_engine (servant);
	BonoboUIError err;
	Bonobo_Unknown object;

	err = bonobo_ui_engine_object_get (engine, path, &object, ev);

	if (err)
		CORBA_exception_set (ev, CORBA_USER_EXCEPTION,
				     ex_Bonobo_UIContainer_InvalidPath, NULL);

	return object;
}

static void
impl_Bonobo_UIContainer_freeze (PortableServer_Servant   servant,
				CORBA_Environment       *ev)
{
	BonoboUIEngine *engine = get_engine (servant);

	bonobo_ui_engine_freeze (engine);
}

static void
impl_Bonobo_UIContainer_thaw (PortableServer_Servant   servant,
			      CORBA_Environment       *ev)
{
	BonoboUIEngine *engine = get_engine (servant);

	bonobo_ui_engine_thaw (engine);
}

static void
bonobo_ui_container_destroy (GtkObject *object)
{
	bonobo_ui_container_parent_class->destroy (object);
}

static void
bonobo_ui_container_finalize (GtkObject *object)
{
	BonoboUIContainer *container = (BonoboUIContainer *) object;

	g_free (container->priv);
	container->priv = NULL;

	bonobo_ui_container_parent_class->finalize (object);
}

static void
bonobo_ui_container_init (GtkObject *object)
{
	BonoboUIContainer *container = (BonoboUIContainer *) object;

	container->priv = g_new0 (BonoboUIContainerPrivate, 1);
}

static void
bonobo_ui_container_class_init (BonoboUIContainerClass *klass)
{
	GtkObjectClass              *gtk_class = (GtkObjectClass *) klass;
	POA_Bonobo_UIContainer__epv *epv = &klass->epv;

	bonobo_ui_container_parent_class = gtk_type_class (PARENT_TYPE);
	
	gtk_class->destroy  = bonobo_ui_container_destroy;
	gtk_class->finalize = bonobo_ui_container_finalize;

	epv->registerComponent   = impl_Bonobo_UIContainer_registerComponent;
	epv->deregisterComponent = impl_Bonobo_UIContainer_deregisterComponent;

	epv->setNode    = impl_Bonobo_UIContainer_setNode;
	epv->getNode    = impl_Bonobo_UIContainer_getNode;
	epv->removeNode = impl_Bonobo_UIContainer_removeNode;
	epv->exists     = impl_Bonobo_UIContainer_exists;

	epv->setObject  = impl_Bonobo_UIContainer_setObject;
	epv->getObject  = impl_Bonobo_UIContainer_getObject;

	epv->freeze     = impl_Bonobo_UIContainer_freeze;
	epv->thaw       = impl_Bonobo_UIContainer_thaw;
}

BONOBO_X_TYPE_FUNC_FULL (BonoboUIContainer, 
			   Bonobo_UIContainer,
			   PARENT_TYPE,
			   bonobo_ui_container);

/**
 * bonobo_ui_container_new:
 * @void: 
 * 
 * Return value: a newly created BonoboUIContainer
 **/
BonoboUIContainer *
bonobo_ui_container_new (void)
{
	return gtk_type_new (BONOBO_UI_CONTAINER_TYPE);
}

static void
blank_engine (GtkObject *win, BonoboUIContainer *container)
{
	container->priv->engine = NULL;
	container->win          = NULL;
	container->priv->flags |= WIN_DESTROYED;
}

/**
 * bonobo_ui_container_set_engine:
 * @container: the container
 * @engine: the engine
 * 
 * Associates the BonoboUIContainer with a #BonoboUIEngine
 * that it will use to handle all the UI merging requests.
 **/
void
bonobo_ui_container_set_engine (BonoboUIContainer *container,
				BonoboUIEngine    *engine)
{
	g_return_if_fail (BONOBO_IS_UI_CONTAINER (container));

	container->priv->engine = engine;
	bonobo_ui_engine_set_ui_container (
		engine, BONOBO_OBJECT (container));

	gtk_signal_connect_while_alive (
		GTK_OBJECT (engine), "destroy",
		(GtkSignalFunc) blank_engine,
		container, GTK_OBJECT (container));
}

/**
 * bonobo_ui_container_get_engine:
 * @container: the UI container
 * 
 * Get the associated #BonoboUIEngine
 * 
 * Return value: the engine
 **/
BonoboUIEngine *
bonobo_ui_container_get_engine (BonoboUIContainer *container)
{
	g_return_val_if_fail (BONOBO_IS_UI_CONTAINER (container), NULL);

	return container->priv->engine;
}

/**
 * bonobo_ui_container_set_win:
 * @container: the container
 * @win: a #BonoboWindow widget
 * 
 * This function is deprecated, please use
 * bonobo_ui_container_set_engine instead, we plan to
 * allow UIContainers to be associated with many things
 * apart from BonoboWindows.
 **/
void
bonobo_ui_container_set_win (BonoboUIContainer *container,
			     BonoboWindow      *win)
{
	g_return_if_fail (BONOBO_IS_UI_CONTAINER (container));

	container->win = win;

	bonobo_ui_container_set_engine (
		container, bonobo_window_get_ui_engine (win));

	gtk_signal_connect_while_alive (
		GTK_OBJECT (win), "destroy",
		(GtkSignalFunc) blank_engine,
		container, GTK_OBJECT (container));
}

/**
 * bonobo_ui_container_get_win:
 * @container: the BonoboUIContainer
 * 
 * This is _extremely_ deprecated, there is no garentee
 * that a BonoboUIContainer has an associated window, this
 * function will spew warnings.
 *
 * If you find yourself wanting to use this function,
 * you probably want to be passing a BonoboWindow ( or
 * derivative ) around and then using:
 *
 * bonobo_window_get_ui_engine (window)
 * 
 * Return value: a BonoboWindow if it is associated.
 **/
BonoboWindow *
bonobo_ui_container_get_win (BonoboUIContainer *container)
{
	g_return_val_if_fail (BONOBO_IS_UI_CONTAINER (container), NULL);

/*	g_warning ("bonobo_ui_container_get_win is deprecated");*/

	return container->win;
}