1 | /* |
---|
2 | * bonobo-ui-container.c: The server side CORBA impl. for BonoboWindow. |
---|
3 | * |
---|
4 | * Author: |
---|
5 | * Michael Meeks (michael@helixcode.com) |
---|
6 | * |
---|
7 | * Copyright 2000 Helix Code, Inc. |
---|
8 | */ |
---|
9 | |
---|
10 | #include "config.h" |
---|
11 | #include <gnome.h> |
---|
12 | #include <liboaf/liboaf.h> |
---|
13 | |
---|
14 | #include <bonobo/Bonobo.h> |
---|
15 | #include <bonobo/bonobo-ui-xml.h> |
---|
16 | #include <bonobo/bonobo-ui-util.h> |
---|
17 | #include <bonobo/bonobo-win.h> |
---|
18 | #include <bonobo/bonobo-ui-container.h> |
---|
19 | |
---|
20 | #define PARENT_TYPE BONOBO_X_OBJECT_TYPE |
---|
21 | |
---|
22 | static GtkObjectClass *bonobo_ui_container_parent_class; |
---|
23 | |
---|
24 | struct _BonoboUIContainerPrivate { |
---|
25 | BonoboUIEngine *engine; |
---|
26 | int flags; |
---|
27 | }; |
---|
28 | |
---|
29 | #define WIN_DESTROYED 0x1 |
---|
30 | |
---|
31 | static BonoboUIEngine * |
---|
32 | get_engine (PortableServer_Servant servant) |
---|
33 | { |
---|
34 | BonoboUIContainer *container; |
---|
35 | |
---|
36 | container = BONOBO_UI_CONTAINER (bonobo_object_from_servant (servant)); |
---|
37 | g_return_val_if_fail (container != NULL, NULL); |
---|
38 | |
---|
39 | if (container->priv->engine == NULL) { |
---|
40 | if (!container->priv->flags & WIN_DESTROYED) |
---|
41 | g_warning ("Trying to invoke CORBA method " |
---|
42 | "on unbound UIContainer"); |
---|
43 | return NULL; |
---|
44 | } else |
---|
45 | return container->priv->engine; |
---|
46 | } |
---|
47 | |
---|
48 | static void |
---|
49 | impl_Bonobo_UIContainer_registerComponent (PortableServer_Servant servant, |
---|
50 | const CORBA_char *component_name, |
---|
51 | const Bonobo_Unknown object, |
---|
52 | CORBA_Environment *ev) |
---|
53 | { |
---|
54 | BonoboUIEngine *engine = get_engine (servant); |
---|
55 | |
---|
56 | bonobo_ui_engine_register_component (engine, component_name, object); |
---|
57 | } |
---|
58 | |
---|
59 | static void |
---|
60 | impl_Bonobo_UIContainer_deregisterComponent (PortableServer_Servant servant, |
---|
61 | const CORBA_char *component_name, |
---|
62 | CORBA_Environment *ev) |
---|
63 | { |
---|
64 | BonoboUIEngine *engine = get_engine (servant); |
---|
65 | |
---|
66 | if (!engine) |
---|
67 | return; |
---|
68 | |
---|
69 | bonobo_ui_engine_deregister_component (engine, component_name); |
---|
70 | } |
---|
71 | |
---|
72 | static void |
---|
73 | impl_Bonobo_UIContainer_setNode (PortableServer_Servant servant, |
---|
74 | const CORBA_char *path, |
---|
75 | const CORBA_char *xml, |
---|
76 | const CORBA_char *component_name, |
---|
77 | CORBA_Environment *ev) |
---|
78 | { |
---|
79 | BonoboUIEngine *engine = get_engine (servant); |
---|
80 | BonoboUIError err; |
---|
81 | BonoboUINode *node; |
---|
82 | const CORBA_char *property; |
---|
83 | |
---|
84 | /* fprintf (stderr, "Merging :\n%s\n", xml);*/ |
---|
85 | |
---|
86 | if (!xml) |
---|
87 | err = BONOBO_UI_ERROR_BAD_PARAM; |
---|
88 | else { |
---|
89 | if ((property = strrchr (path, '#'))) { |
---|
90 | char *real_path; |
---|
91 | real_path = g_strdup (path); |
---|
92 | real_path [property-path] = 0; |
---|
93 | property = property + 1; /* Skip the '#' */ |
---|
94 | |
---|
95 | err = bonobo_ui_engine_xml_set_prop (engine, |
---|
96 | real_path, |
---|
97 | property, |
---|
98 | xml, |
---|
99 | component_name); |
---|
100 | g_free (real_path); |
---|
101 | } else { |
---|
102 | if (xml [0] == '\0') |
---|
103 | err = BONOBO_UI_ERROR_OK; |
---|
104 | |
---|
105 | else { |
---|
106 | node = bonobo_ui_node_from_string (xml); |
---|
107 | |
---|
108 | if (!node) |
---|
109 | err = BONOBO_UI_ERROR_INVALID_XML; |
---|
110 | else |
---|
111 | err = bonobo_ui_engine_xml_merge_tree ( |
---|
112 | engine, path, node, component_name); |
---|
113 | } |
---|
114 | } |
---|
115 | } |
---|
116 | |
---|
117 | |
---|
118 | if (err) { |
---|
119 | if (err == BONOBO_UI_ERROR_INVALID_PATH) |
---|
120 | CORBA_exception_set ( |
---|
121 | ev, CORBA_USER_EXCEPTION, |
---|
122 | ex_Bonobo_UIContainer_InvalidPath, NULL); |
---|
123 | else |
---|
124 | CORBA_exception_set ( |
---|
125 | ev, CORBA_USER_EXCEPTION, |
---|
126 | ex_Bonobo_UIContainer_MalFormedXML, NULL); |
---|
127 | } |
---|
128 | } |
---|
129 | |
---|
130 | static CORBA_char * |
---|
131 | impl_Bonobo_UIContainer_getNode (PortableServer_Servant servant, |
---|
132 | const CORBA_char *path, |
---|
133 | const CORBA_boolean nodeOnly, |
---|
134 | CORBA_Environment *ev) |
---|
135 | { |
---|
136 | BonoboUIEngine *engine = get_engine (servant); |
---|
137 | CORBA_char *xml; |
---|
138 | const CORBA_char *property; |
---|
139 | |
---|
140 | if ((property = strrchr (path, '#'))) { |
---|
141 | char *real_path; |
---|
142 | real_path = g_strdup (path); |
---|
143 | real_path [property-path] = 0; |
---|
144 | property = property + 1; /* Skip the '#' */ |
---|
145 | |
---|
146 | xml = bonobo_ui_engine_xml_get_prop (engine, real_path, property); |
---|
147 | g_free (real_path); |
---|
148 | |
---|
149 | if (!xml) { |
---|
150 | CORBA_exception_set (ev, CORBA_USER_EXCEPTION, |
---|
151 | ex_Bonobo_UIContainer_InvalidPath, NULL); |
---|
152 | return NULL; |
---|
153 | } |
---|
154 | } else { |
---|
155 | xml = bonobo_ui_engine_xml_get (engine, path, nodeOnly); |
---|
156 | |
---|
157 | if (!xml) { |
---|
158 | CORBA_exception_set (ev, CORBA_USER_EXCEPTION, |
---|
159 | ex_Bonobo_UIContainer_InvalidPath, NULL); |
---|
160 | return NULL; |
---|
161 | } |
---|
162 | } |
---|
163 | |
---|
164 | return xml; |
---|
165 | } |
---|
166 | |
---|
167 | static void |
---|
168 | impl_Bonobo_UIContainer_removeNode (PortableServer_Servant servant, |
---|
169 | const CORBA_char *path, |
---|
170 | const CORBA_char *component_name, |
---|
171 | CORBA_Environment *ev) |
---|
172 | { |
---|
173 | BonoboUIEngine *engine = get_engine (servant); |
---|
174 | BonoboUIError err; |
---|
175 | |
---|
176 | if (!engine) |
---|
177 | return; |
---|
178 | |
---|
179 | /* g_warning ("Node remove '%s' for '%s'", path, component_name);*/ |
---|
180 | |
---|
181 | err = bonobo_ui_engine_xml_rm (engine, path, component_name); |
---|
182 | |
---|
183 | if (err) |
---|
184 | CORBA_exception_set (ev, CORBA_USER_EXCEPTION, |
---|
185 | ex_Bonobo_UIContainer_InvalidPath, NULL); |
---|
186 | } |
---|
187 | |
---|
188 | static CORBA_boolean |
---|
189 | impl_Bonobo_UIContainer_exists (PortableServer_Servant servant, |
---|
190 | const CORBA_char *path, |
---|
191 | CORBA_Environment *ev) |
---|
192 | { |
---|
193 | BonoboUIEngine *engine = get_engine (servant); |
---|
194 | |
---|
195 | return bonobo_ui_engine_xml_node_exists (engine, path); |
---|
196 | } |
---|
197 | |
---|
198 | static void |
---|
199 | impl_Bonobo_UIContainer_setObject (PortableServer_Servant servant, |
---|
200 | const CORBA_char *path, |
---|
201 | const Bonobo_Unknown control, |
---|
202 | CORBA_Environment *ev) |
---|
203 | { |
---|
204 | BonoboUIEngine *engine = get_engine (servant); |
---|
205 | BonoboUIError err; |
---|
206 | |
---|
207 | err = bonobo_ui_engine_object_set (engine, path, control, ev); |
---|
208 | |
---|
209 | if (err) |
---|
210 | CORBA_exception_set (ev, CORBA_USER_EXCEPTION, |
---|
211 | ex_Bonobo_UIContainer_InvalidPath, NULL); |
---|
212 | } |
---|
213 | |
---|
214 | static Bonobo_Unknown |
---|
215 | impl_Bonobo_UIContainer_getObject (PortableServer_Servant servant, |
---|
216 | const CORBA_char *path, |
---|
217 | CORBA_Environment *ev) |
---|
218 | { |
---|
219 | BonoboUIEngine *engine = get_engine (servant); |
---|
220 | BonoboUIError err; |
---|
221 | Bonobo_Unknown object; |
---|
222 | |
---|
223 | err = bonobo_ui_engine_object_get (engine, path, &object, ev); |
---|
224 | |
---|
225 | if (err) |
---|
226 | CORBA_exception_set (ev, CORBA_USER_EXCEPTION, |
---|
227 | ex_Bonobo_UIContainer_InvalidPath, NULL); |
---|
228 | |
---|
229 | return object; |
---|
230 | } |
---|
231 | |
---|
232 | static void |
---|
233 | impl_Bonobo_UIContainer_freeze (PortableServer_Servant servant, |
---|
234 | CORBA_Environment *ev) |
---|
235 | { |
---|
236 | BonoboUIEngine *engine = get_engine (servant); |
---|
237 | |
---|
238 | bonobo_ui_engine_freeze (engine); |
---|
239 | } |
---|
240 | |
---|
241 | static void |
---|
242 | impl_Bonobo_UIContainer_thaw (PortableServer_Servant servant, |
---|
243 | CORBA_Environment *ev) |
---|
244 | { |
---|
245 | BonoboUIEngine *engine = get_engine (servant); |
---|
246 | |
---|
247 | bonobo_ui_engine_thaw (engine); |
---|
248 | } |
---|
249 | |
---|
250 | static void |
---|
251 | bonobo_ui_container_destroy (GtkObject *object) |
---|
252 | { |
---|
253 | bonobo_ui_container_parent_class->destroy (object); |
---|
254 | } |
---|
255 | |
---|
256 | static void |
---|
257 | bonobo_ui_container_finalize (GtkObject *object) |
---|
258 | { |
---|
259 | BonoboUIContainer *container = (BonoboUIContainer *) object; |
---|
260 | |
---|
261 | g_free (container->priv); |
---|
262 | container->priv = NULL; |
---|
263 | |
---|
264 | bonobo_ui_container_parent_class->finalize (object); |
---|
265 | } |
---|
266 | |
---|
267 | static void |
---|
268 | bonobo_ui_container_init (GtkObject *object) |
---|
269 | { |
---|
270 | BonoboUIContainer *container = (BonoboUIContainer *) object; |
---|
271 | |
---|
272 | container->priv = g_new0 (BonoboUIContainerPrivate, 1); |
---|
273 | } |
---|
274 | |
---|
275 | static void |
---|
276 | bonobo_ui_container_class_init (BonoboUIContainerClass *klass) |
---|
277 | { |
---|
278 | GtkObjectClass *gtk_class = (GtkObjectClass *) klass; |
---|
279 | POA_Bonobo_UIContainer__epv *epv = &klass->epv; |
---|
280 | |
---|
281 | bonobo_ui_container_parent_class = gtk_type_class (PARENT_TYPE); |
---|
282 | |
---|
283 | gtk_class->destroy = bonobo_ui_container_destroy; |
---|
284 | gtk_class->finalize = bonobo_ui_container_finalize; |
---|
285 | |
---|
286 | epv->registerComponent = impl_Bonobo_UIContainer_registerComponent; |
---|
287 | epv->deregisterComponent = impl_Bonobo_UIContainer_deregisterComponent; |
---|
288 | |
---|
289 | epv->setNode = impl_Bonobo_UIContainer_setNode; |
---|
290 | epv->getNode = impl_Bonobo_UIContainer_getNode; |
---|
291 | epv->removeNode = impl_Bonobo_UIContainer_removeNode; |
---|
292 | epv->exists = impl_Bonobo_UIContainer_exists; |
---|
293 | |
---|
294 | epv->setObject = impl_Bonobo_UIContainer_setObject; |
---|
295 | epv->getObject = impl_Bonobo_UIContainer_getObject; |
---|
296 | |
---|
297 | epv->freeze = impl_Bonobo_UIContainer_freeze; |
---|
298 | epv->thaw = impl_Bonobo_UIContainer_thaw; |
---|
299 | } |
---|
300 | |
---|
301 | BONOBO_X_TYPE_FUNC_FULL (BonoboUIContainer, |
---|
302 | Bonobo_UIContainer, |
---|
303 | PARENT_TYPE, |
---|
304 | bonobo_ui_container); |
---|
305 | |
---|
306 | /** |
---|
307 | * bonobo_ui_container_new: |
---|
308 | * @void: |
---|
309 | * |
---|
310 | * Return value: a newly created BonoboUIContainer |
---|
311 | **/ |
---|
312 | BonoboUIContainer * |
---|
313 | bonobo_ui_container_new (void) |
---|
314 | { |
---|
315 | return gtk_type_new (BONOBO_UI_CONTAINER_TYPE); |
---|
316 | } |
---|
317 | |
---|
318 | static void |
---|
319 | blank_engine (GtkObject *win, BonoboUIContainer *container) |
---|
320 | { |
---|
321 | container->priv->engine = NULL; |
---|
322 | container->win = NULL; |
---|
323 | container->priv->flags |= WIN_DESTROYED; |
---|
324 | } |
---|
325 | |
---|
326 | /** |
---|
327 | * bonobo_ui_container_set_engine: |
---|
328 | * @container: the container |
---|
329 | * @engine: the engine |
---|
330 | * |
---|
331 | * Associates the BonoboUIContainer with a #BonoboUIEngine |
---|
332 | * that it will use to handle all the UI merging requests. |
---|
333 | **/ |
---|
334 | void |
---|
335 | bonobo_ui_container_set_engine (BonoboUIContainer *container, |
---|
336 | BonoboUIEngine *engine) |
---|
337 | { |
---|
338 | g_return_if_fail (BONOBO_IS_UI_CONTAINER (container)); |
---|
339 | |
---|
340 | container->priv->engine = engine; |
---|
341 | bonobo_ui_engine_set_ui_container ( |
---|
342 | engine, BONOBO_OBJECT (container)); |
---|
343 | |
---|
344 | gtk_signal_connect_while_alive ( |
---|
345 | GTK_OBJECT (engine), "destroy", |
---|
346 | (GtkSignalFunc) blank_engine, |
---|
347 | container, GTK_OBJECT (container)); |
---|
348 | } |
---|
349 | |
---|
350 | /** |
---|
351 | * bonobo_ui_container_get_engine: |
---|
352 | * @container: the UI container |
---|
353 | * |
---|
354 | * Get the associated #BonoboUIEngine |
---|
355 | * |
---|
356 | * Return value: the engine |
---|
357 | **/ |
---|
358 | BonoboUIEngine * |
---|
359 | bonobo_ui_container_get_engine (BonoboUIContainer *container) |
---|
360 | { |
---|
361 | g_return_val_if_fail (BONOBO_IS_UI_CONTAINER (container), NULL); |
---|
362 | |
---|
363 | return container->priv->engine; |
---|
364 | } |
---|
365 | |
---|
366 | /** |
---|
367 | * bonobo_ui_container_set_win: |
---|
368 | * @container: the container |
---|
369 | * @win: a #BonoboWindow widget |
---|
370 | * |
---|
371 | * This function is deprecated, please use |
---|
372 | * bonobo_ui_container_set_engine instead, we plan to |
---|
373 | * allow UIContainers to be associated with many things |
---|
374 | * apart from BonoboWindows. |
---|
375 | **/ |
---|
376 | void |
---|
377 | bonobo_ui_container_set_win (BonoboUIContainer *container, |
---|
378 | BonoboWindow *win) |
---|
379 | { |
---|
380 | g_return_if_fail (BONOBO_IS_UI_CONTAINER (container)); |
---|
381 | |
---|
382 | container->win = win; |
---|
383 | |
---|
384 | bonobo_ui_container_set_engine ( |
---|
385 | container, bonobo_window_get_ui_engine (win)); |
---|
386 | |
---|
387 | gtk_signal_connect_while_alive ( |
---|
388 | GTK_OBJECT (win), "destroy", |
---|
389 | (GtkSignalFunc) blank_engine, |
---|
390 | container, GTK_OBJECT (container)); |
---|
391 | } |
---|
392 | |
---|
393 | /** |
---|
394 | * bonobo_ui_container_get_win: |
---|
395 | * @container: the BonoboUIContainer |
---|
396 | * |
---|
397 | * This is _extremely_ deprecated, there is no garentee |
---|
398 | * that a BonoboUIContainer has an associated window, this |
---|
399 | * function will spew warnings. |
---|
400 | * |
---|
401 | * If you find yourself wanting to use this function, |
---|
402 | * you probably want to be passing a BonoboWindow ( or |
---|
403 | * derivative ) around and then using: |
---|
404 | * |
---|
405 | * bonobo_window_get_ui_engine (window) |
---|
406 | * |
---|
407 | * Return value: a BonoboWindow if it is associated. |
---|
408 | **/ |
---|
409 | BonoboWindow * |
---|
410 | bonobo_ui_container_get_win (BonoboUIContainer *container) |
---|
411 | { |
---|
412 | g_return_val_if_fail (BONOBO_IS_UI_CONTAINER (container), NULL); |
---|
413 | |
---|
414 | /* g_warning ("bonobo_ui_container_get_win is deprecated");*/ |
---|
415 | |
---|
416 | return container->win; |
---|
417 | } |
---|