1 | /* |
---|
2 | * bonobo-canvas-item.c: GnomeCanvasItem implementation to serve as a client- |
---|
3 | * proxy for embedding remote canvas-items. |
---|
4 | * |
---|
5 | * Author: |
---|
6 | * Miguel de Icaza (miguel@kernel.org) |
---|
7 | * |
---|
8 | * (C) 1999, 2000 Helix Code, Inc. |
---|
9 | */ |
---|
10 | #include <config.h> |
---|
11 | #include <bonobo/Bonobo.h> |
---|
12 | #include <bonobo/bonobo-exception.h> |
---|
13 | #include <bonobo/bonobo-canvas-item.h> |
---|
14 | #include <bonobo/bonobo-object.h> |
---|
15 | #include <bonobo/bonobo-main.h> |
---|
16 | #include <gdk/gdkprivate.h> |
---|
17 | #include <gdk/gdkx.h> |
---|
18 | #include <gtk/gtksignal.h> |
---|
19 | #include <stdio.h> |
---|
20 | #include <libgnomeui/gnome-canvas-util.h> |
---|
21 | |
---|
22 | static GnomeCanvasItemClass *gbi_parent_class; |
---|
23 | |
---|
24 | typedef struct { |
---|
25 | POA_Bonobo_Canvas_ComponentProxy proxy_servant; |
---|
26 | GnomeCanvasItem *item_bound; |
---|
27 | PortableServer_ObjectId *oid; |
---|
28 | Bonobo_UIContainer ui_container; |
---|
29 | } ComponentProxyServant; |
---|
30 | |
---|
31 | struct _BonoboCanvasItemPrivate { |
---|
32 | Bonobo_Canvas_Component object; |
---|
33 | ComponentProxyServant *proxy; |
---|
34 | int realize_pending; |
---|
35 | }; |
---|
36 | |
---|
37 | enum { |
---|
38 | ARG_0, |
---|
39 | ARG_CORBA_EMBEDDABLE, |
---|
40 | ARG_CORBA_UI_CONTAINER, |
---|
41 | }; |
---|
42 | |
---|
43 | /* |
---|
44 | * Horizontal space saver |
---|
45 | */ |
---|
46 | #define GBI(x) BONOBO_CANVAS_ITEM(x) |
---|
47 | typedef BonoboCanvasItem Gbi; |
---|
48 | |
---|
49 | /* |
---|
50 | * Creates a Bonobo_Canvas_SVPSegment structure representing the ArtSVPSeg |
---|
51 | * structure, suitable for sending over the network |
---|
52 | */ |
---|
53 | static gboolean |
---|
54 | art_svp_segment_to_CORBA_SVP_Segment (ArtSVPSeg *seg, Bonobo_Canvas_SVPSegment *segment) |
---|
55 | { |
---|
56 | int i; |
---|
57 | |
---|
58 | segment->points._buffer = CORBA_sequence_Bonobo_Canvas_Point_allocbuf (seg->n_points); |
---|
59 | if (segment->points._buffer == NULL) |
---|
60 | return FALSE; |
---|
61 | |
---|
62 | segment->points._maximum = seg->n_points; |
---|
63 | segment->points._length = seg->n_points; |
---|
64 | |
---|
65 | if (seg->dir == 0) |
---|
66 | segment->up = CORBA_TRUE; |
---|
67 | else |
---|
68 | segment->up = CORBA_FALSE; |
---|
69 | |
---|
70 | segment->bbox.x0 = seg->bbox.x0; |
---|
71 | segment->bbox.x1 = seg->bbox.x1; |
---|
72 | segment->bbox.y0 = seg->bbox.y0; |
---|
73 | segment->bbox.y1 = seg->bbox.y1; |
---|
74 | |
---|
75 | for (i = 0; i < seg->n_points; i++){ |
---|
76 | segment->points._buffer [i].x = seg->points [i].x; |
---|
77 | segment->points._buffer [i].y = seg->points [i].y; |
---|
78 | } |
---|
79 | |
---|
80 | return TRUE; |
---|
81 | } |
---|
82 | |
---|
83 | /* |
---|
84 | * Creates a Bonobo_Canvas_SVP CORBA structure from the art_svp, suitable |
---|
85 | * for sending over the wire |
---|
86 | */ |
---|
87 | static Bonobo_Canvas_SVP * |
---|
88 | art_svp_to_CORBA_SVP (ArtSVP *art_svp) |
---|
89 | { |
---|
90 | Bonobo_Canvas_SVP *svp; |
---|
91 | int i; |
---|
92 | |
---|
93 | svp = Bonobo_Canvas_SVP__alloc (); |
---|
94 | if (!svp) |
---|
95 | return NULL; |
---|
96 | |
---|
97 | if (art_svp){ |
---|
98 | svp->_buffer = CORBA_sequence_Bonobo_Canvas_SVPSegment_allocbuf (art_svp->n_segs); |
---|
99 | if (svp->_buffer == NULL){ |
---|
100 | svp->_length = 0; |
---|
101 | svp->_maximum = 0; |
---|
102 | return svp; |
---|
103 | } |
---|
104 | svp->_maximum = art_svp->n_segs; |
---|
105 | svp->_length = art_svp->n_segs; |
---|
106 | |
---|
107 | for (i = 0; i < art_svp->n_segs; i++){ |
---|
108 | gboolean ok; |
---|
109 | |
---|
110 | ok = art_svp_segment_to_CORBA_SVP_Segment ( |
---|
111 | &art_svp->segs [i], &svp->_buffer [i]); |
---|
112 | if (!ok){ |
---|
113 | int j; |
---|
114 | |
---|
115 | for (j = 0; j < i; j++) |
---|
116 | CORBA_free (&svp->_buffer [j]); |
---|
117 | CORBA_free (svp); |
---|
118 | return NULL; |
---|
119 | } |
---|
120 | } |
---|
121 | } else { |
---|
122 | svp->_maximum = 0; |
---|
123 | svp->_length = 0; |
---|
124 | } |
---|
125 | |
---|
126 | return svp; |
---|
127 | } |
---|
128 | |
---|
129 | static ArtUta * |
---|
130 | uta_from_cuta (Bonobo_Canvas_ArtUTA *cuta) |
---|
131 | { |
---|
132 | ArtUta *uta; |
---|
133 | |
---|
134 | uta = art_uta_new (cuta->x0, cuta->y0, cuta->x0 + cuta->width, cuta->y0 + cuta->height); |
---|
135 | memcpy (uta->utiles, cuta->utiles._buffer, cuta->width * cuta->height * sizeof (ArtUtaBbox)); |
---|
136 | |
---|
137 | return uta; |
---|
138 | } |
---|
139 | |
---|
140 | static void |
---|
141 | prepare_state (GnomeCanvasItem *item, Bonobo_Canvas_State *target) |
---|
142 | { |
---|
143 | double item_affine [6]; |
---|
144 | GnomeCanvas *canvas = item->canvas; |
---|
145 | int i; |
---|
146 | |
---|
147 | gnome_canvas_item_i2w_affine (item, item_affine); |
---|
148 | for (i = 0; i < 6; i++) |
---|
149 | target->item_aff [i] = item_affine [i]; |
---|
150 | |
---|
151 | target->pixels_per_unit = canvas->pixels_per_unit; |
---|
152 | target->canvas_scroll_x1 = canvas->scroll_x1; |
---|
153 | target->canvas_scroll_y1 = canvas->scroll_y1; |
---|
154 | target->zoom_xofs = canvas->zoom_xofs; |
---|
155 | target->zoom_yofs = canvas->zoom_yofs; |
---|
156 | target->xoffset = GTK_LAYOUT (canvas)->xoffset; |
---|
157 | target->yoffset = GTK_LAYOUT (canvas)->yoffset; |
---|
158 | } |
---|
159 | |
---|
160 | static void |
---|
161 | gbi_update (GnomeCanvasItem *item, double *item_affine, ArtSVP *item_clip_path, int item_flags) |
---|
162 | { |
---|
163 | Gbi *gbi = GBI (item); |
---|
164 | Bonobo_Canvas_affine affine; |
---|
165 | Bonobo_Canvas_State state; |
---|
166 | Bonobo_Canvas_SVP *clip_path = NULL; |
---|
167 | CORBA_Environment ev; |
---|
168 | CORBA_double x1, y1, x2, y2; |
---|
169 | Bonobo_Canvas_ArtUTA *cuta; |
---|
170 | int i; |
---|
171 | |
---|
172 | if (getenv ("DEBUG_BI")) |
---|
173 | g_message ("gbi_update"); |
---|
174 | |
---|
175 | if (gbi_parent_class) |
---|
176 | (*gbi_parent_class->update)(item, item_affine, item_clip_path, item_flags); |
---|
177 | |
---|
178 | for (i = 0; i < 6; i++) |
---|
179 | affine [i] = item_affine [i]; |
---|
180 | |
---|
181 | clip_path = art_svp_to_CORBA_SVP (item_clip_path); |
---|
182 | if (!clip_path) |
---|
183 | return; |
---|
184 | |
---|
185 | CORBA_exception_init (&ev); |
---|
186 | prepare_state (item, &state); |
---|
187 | cuta = Bonobo_Canvas_Component_update ( |
---|
188 | gbi->priv->object, |
---|
189 | &state, affine, clip_path, item_flags, |
---|
190 | &x1, &y1, &x2, &y2, |
---|
191 | &ev); |
---|
192 | |
---|
193 | if (!BONOBO_EX (&ev)){ |
---|
194 | if (cuta->width > 0 && cuta->height > 0){ |
---|
195 | ArtUta *uta; |
---|
196 | |
---|
197 | uta = uta_from_cuta (cuta); |
---|
198 | gnome_canvas_request_redraw_uta (item->canvas, uta); |
---|
199 | } |
---|
200 | |
---|
201 | gnome_canvas_update_bbox (item, x1, y1, x2, y2); |
---|
202 | |
---|
203 | if (getenv ("DEBUG_BI")) |
---|
204 | g_message ("Bbox: %g %g %g %g", x1, y1, x2, y2); |
---|
205 | |
---|
206 | CORBA_free (cuta); |
---|
207 | } |
---|
208 | |
---|
209 | CORBA_exception_free (&ev); |
---|
210 | |
---|
211 | CORBA_free (clip_path); |
---|
212 | } |
---|
213 | |
---|
214 | static void |
---|
215 | proxy_size_allocate (GnomeCanvas *canvas, GtkAllocation *allocation, BonoboCanvasItem *bonobo_item) |
---|
216 | { |
---|
217 | CORBA_Environment ev; |
---|
218 | |
---|
219 | CORBA_exception_init (&ev); |
---|
220 | Bonobo_Canvas_Component_setCanvasSize ( |
---|
221 | bonobo_item->priv->object, |
---|
222 | allocation->x, allocation->y, |
---|
223 | allocation->width, allocation->height, &ev); |
---|
224 | CORBA_exception_free (&ev); |
---|
225 | } |
---|
226 | |
---|
227 | static void |
---|
228 | gbi_realize (GnomeCanvasItem *item) |
---|
229 | { |
---|
230 | Gbi *gbi = GBI (item); |
---|
231 | CORBA_Environment ev; |
---|
232 | |
---|
233 | if (getenv ("DEBUG_BI")) |
---|
234 | g_message ("gbi_realize"); |
---|
235 | |
---|
236 | if (gbi_parent_class) |
---|
237 | (*gbi_parent_class->realize) (item); |
---|
238 | |
---|
239 | if (gbi->priv->object == CORBA_OBJECT_NIL){ |
---|
240 | gbi->priv->realize_pending = 1; |
---|
241 | return; |
---|
242 | } |
---|
243 | |
---|
244 | gtk_signal_connect ( |
---|
245 | GTK_OBJECT (item->canvas), "size_allocate", |
---|
246 | proxy_size_allocate, item); |
---|
247 | |
---|
248 | CORBA_exception_init (&ev); |
---|
249 | gdk_flush (); |
---|
250 | Bonobo_Canvas_Component_realize ( |
---|
251 | gbi->priv->object, |
---|
252 | GDK_WINDOW_XWINDOW (item->canvas->layout.bin_window), |
---|
253 | &ev); |
---|
254 | CORBA_exception_free (&ev); |
---|
255 | } |
---|
256 | |
---|
257 | static void |
---|
258 | gbi_unrealize (GnomeCanvasItem *item) |
---|
259 | { |
---|
260 | Gbi *gbi = GBI (item); |
---|
261 | CORBA_Environment ev; |
---|
262 | |
---|
263 | if (getenv ("DEBUG_BI")) |
---|
264 | g_message ("gbi_unrealize"); |
---|
265 | |
---|
266 | if (gbi->priv->object != CORBA_OBJECT_NIL){ |
---|
267 | CORBA_exception_init (&ev); |
---|
268 | Bonobo_Canvas_Component_unrealize (gbi->priv->object, &ev); |
---|
269 | CORBA_exception_free (&ev); |
---|
270 | } |
---|
271 | |
---|
272 | if (gbi_parent_class) |
---|
273 | (*gbi_parent_class->unrealize) (item); |
---|
274 | } |
---|
275 | |
---|
276 | static void |
---|
277 | gbi_draw (GnomeCanvasItem *item, GdkDrawable *drawable, int x, int y, int width, int height) |
---|
278 | { |
---|
279 | Gbi *gbi = GBI (item); |
---|
280 | CORBA_Environment ev; |
---|
281 | Bonobo_Canvas_State state; |
---|
282 | |
---|
283 | if (getenv ("DEBUG_BI")) |
---|
284 | g_message ("draw: %d %d %d %d", x, y, width, height); |
---|
285 | |
---|
286 | /* |
---|
287 | * This call ensures the drawable XID is allocated on the X server |
---|
288 | */ |
---|
289 | gdk_flush (); |
---|
290 | CORBA_exception_init (&ev); |
---|
291 | |
---|
292 | prepare_state (item, &state); |
---|
293 | Bonobo_Canvas_Component_draw ( |
---|
294 | gbi->priv->object, |
---|
295 | &state, |
---|
296 | GDK_WINDOW_XWINDOW (drawable), |
---|
297 | x, y, width, height, |
---|
298 | &ev); |
---|
299 | CORBA_exception_free (&ev); |
---|
300 | } |
---|
301 | |
---|
302 | static double |
---|
303 | gbi_point (GnomeCanvasItem *item, double x, double y, int cx, int cy, GnomeCanvasItem **actual) |
---|
304 | { |
---|
305 | Gbi *gbi = GBI (item); |
---|
306 | CORBA_Environment ev; |
---|
307 | |
---|
308 | if (getenv ("DEBUG_BI")) |
---|
309 | g_message ("gbi_point %g %g", x, y); |
---|
310 | |
---|
311 | CORBA_exception_init (&ev); |
---|
312 | if (Bonobo_Canvas_Component_contains (gbi->priv->object, x, y, &ev)){ |
---|
313 | CORBA_exception_free (&ev); |
---|
314 | *actual = item; |
---|
315 | if (getenv ("DEBUG_BI")) |
---|
316 | g_message ("event inside"); |
---|
317 | return 0.0; |
---|
318 | } |
---|
319 | CORBA_exception_free (&ev); |
---|
320 | |
---|
321 | if (getenv ("DEBUG_BI")) |
---|
322 | g_message ("event outside"); |
---|
323 | *actual = NULL; |
---|
324 | return 1000.0; |
---|
325 | } |
---|
326 | |
---|
327 | static void |
---|
328 | gbi_bounds (GnomeCanvasItem *item, double *x1, double *y1, double *x2, double *y2) |
---|
329 | { |
---|
330 | Gbi *gbi = GBI (item); |
---|
331 | CORBA_Environment ev; |
---|
332 | Bonobo_Canvas_State state; |
---|
333 | |
---|
334 | if (getenv ("DEBUG_BI")) |
---|
335 | g_message ("gbi_bounds"); |
---|
336 | |
---|
337 | CORBA_exception_init (&ev); |
---|
338 | prepare_state (item, &state); |
---|
339 | Bonobo_Canvas_Component_bounds (gbi->priv->object, &state, x1, y1, x2, y2, &ev); |
---|
340 | CORBA_exception_free (&ev); |
---|
341 | |
---|
342 | if (getenv ("DEBUG_BI")) |
---|
343 | g_message ("gbi_bounds %g %g %g %g", *x1, *y1, *x2, *y2); |
---|
344 | } |
---|
345 | |
---|
346 | static void |
---|
347 | gbi_render (GnomeCanvasItem *item, GnomeCanvasBuf *buf) |
---|
348 | { |
---|
349 | Gbi *gbi = GBI (item); |
---|
350 | Bonobo_Canvas_Buf *cbuf; |
---|
351 | CORBA_Environment ev; |
---|
352 | |
---|
353 | if (getenv ("DEBUG_BI")) |
---|
354 | g_message ("gbi_render (%d %d)-(%d %d)", |
---|
355 | buf->rect.x0, buf->rect.y0, |
---|
356 | buf->rect.x1, buf->rect.y1); |
---|
357 | |
---|
358 | cbuf = Bonobo_Canvas_Buf__alloc (); |
---|
359 | if (!cbuf) |
---|
360 | return; |
---|
361 | |
---|
362 | cbuf->rgb_buf._buffer = buf->buf; |
---|
363 | |
---|
364 | #if 0 |
---|
365 | /* |
---|
366 | * Inneficient! |
---|
367 | */ |
---|
368 | if (!buf->is_buf) |
---|
369 | gnome_canvas_buf_ensure_buf (buf); |
---|
370 | #endif |
---|
371 | |
---|
372 | if (buf->is_buf){ |
---|
373 | cbuf->rgb_buf._maximum = buf->buf_rowstride * (buf->rect.y1 - buf->rect.y0); |
---|
374 | cbuf->rgb_buf._length = buf->buf_rowstride * (buf->rect.y1 - buf->rect.y0); |
---|
375 | cbuf->rgb_buf._buffer = buf->buf; |
---|
376 | CORBA_sequence_set_release (&cbuf->rgb_buf, FALSE); |
---|
377 | } else { |
---|
378 | cbuf->rgb_buf._maximum = 0; |
---|
379 | cbuf->rgb_buf._length = 0; |
---|
380 | cbuf->rgb_buf._buffer = NULL; |
---|
381 | } |
---|
382 | cbuf->row_stride = buf->buf_rowstride; |
---|
383 | |
---|
384 | cbuf->rect.x0 = buf->rect.x0; |
---|
385 | cbuf->rect.x1 = buf->rect.x1; |
---|
386 | cbuf->rect.y0 = buf->rect.y0; |
---|
387 | cbuf->rect.y1 = buf->rect.y1; |
---|
388 | cbuf->bg_color = buf->bg_color; |
---|
389 | cbuf->flags = |
---|
390 | (buf->is_bg ? Bonobo_Canvas_IS_BG : 0) | |
---|
391 | (buf->is_buf ? Bonobo_Canvas_IS_BUF : 0); |
---|
392 | |
---|
393 | CORBA_exception_init (&ev); |
---|
394 | Bonobo_Canvas_Component_render (gbi->priv->object, cbuf, &ev); |
---|
395 | if (BONOBO_EX (&ev)){ |
---|
396 | CORBA_exception_free (&ev); |
---|
397 | return; |
---|
398 | } |
---|
399 | CORBA_exception_free (&ev); |
---|
400 | |
---|
401 | memcpy (buf->buf, cbuf->rgb_buf._buffer, cbuf->rgb_buf._length); |
---|
402 | buf->is_bg = (cbuf->flags & Bonobo_Canvas_IS_BG) != 0; |
---|
403 | buf->is_buf = (cbuf->flags & Bonobo_Canvas_IS_BUF) != 0; |
---|
404 | |
---|
405 | CORBA_free (cbuf); |
---|
406 | } |
---|
407 | |
---|
408 | static Bonobo_Gdk_Event * |
---|
409 | gdk_event_to_bonobo_event (GdkEvent *event) |
---|
410 | { |
---|
411 | Bonobo_Gdk_Event *e = Bonobo_Gdk_Event__alloc (); |
---|
412 | |
---|
413 | if (e == NULL) |
---|
414 | return NULL; |
---|
415 | |
---|
416 | switch (event->type){ |
---|
417 | |
---|
418 | case GDK_FOCUS_CHANGE: |
---|
419 | e->_d = Bonobo_Gdk_FOCUS; |
---|
420 | e->_u.focus.inside = event->focus_change.in; |
---|
421 | return e; |
---|
422 | |
---|
423 | case GDK_KEY_PRESS: |
---|
424 | case GDK_KEY_RELEASE: |
---|
425 | e->_d = Bonobo_Gdk_KEY; |
---|
426 | |
---|
427 | if (event->type == GDK_KEY_PRESS) |
---|
428 | e->_u.key.type = Bonobo_Gdk_KEY_PRESS; |
---|
429 | else |
---|
430 | e->_u.key.type = Bonobo_Gdk_KEY_RELEASE; |
---|
431 | e->_u.key.time = event->key.time; |
---|
432 | e->_u.key.state = event->key.state; |
---|
433 | e->_u.key.keyval = event->key.keyval; |
---|
434 | e->_u.key.length = event->key.length; |
---|
435 | e->_u.key.str = CORBA_string_dup (event->key.string); |
---|
436 | return e; |
---|
437 | |
---|
438 | case GDK_MOTION_NOTIFY: |
---|
439 | e->_d = Bonobo_Gdk_MOTION; |
---|
440 | e->_u.motion.time = event->motion.time; |
---|
441 | e->_u.motion.x = event->motion.x; |
---|
442 | e->_u.motion.y = event->motion.x; |
---|
443 | e->_u.motion.x_root = event->motion.x_root; |
---|
444 | e->_u.motion.y_root = event->motion.y_root; |
---|
445 | e->_u.motion.xtilt = event->motion.xtilt; |
---|
446 | e->_u.motion.ytilt = event->motion.ytilt; |
---|
447 | e->_u.motion.state = event->motion.state; |
---|
448 | e->_u.motion.is_hint = event->motion.is_hint != 0; |
---|
449 | return e; |
---|
450 | |
---|
451 | case GDK_BUTTON_PRESS: |
---|
452 | case GDK_2BUTTON_PRESS: |
---|
453 | case GDK_3BUTTON_PRESS: |
---|
454 | case GDK_BUTTON_RELEASE: |
---|
455 | e->_d = Bonobo_Gdk_BUTTON; |
---|
456 | if (event->type == GDK_BUTTON_PRESS) |
---|
457 | e->_u.button.type = Bonobo_Gdk_BUTTON_PRESS; |
---|
458 | else if (event->type == GDK_BUTTON_RELEASE) |
---|
459 | e->_u.button.type = Bonobo_Gdk_BUTTON_RELEASE; |
---|
460 | else if (event->type == GDK_2BUTTON_PRESS) |
---|
461 | e->_u.button.type = Bonobo_Gdk_BUTTON_2_PRESS; |
---|
462 | else if (event->type == GDK_3BUTTON_PRESS) |
---|
463 | e->_u.button.type = Bonobo_Gdk_BUTTON_3_PRESS; |
---|
464 | e->_u.button.time = event->button.time; |
---|
465 | e->_u.button.x = event->button.x; |
---|
466 | e->_u.button.y = event->button.y; |
---|
467 | e->_u.button.x_root = event->button.x_root; |
---|
468 | e->_u.button.y_root = event->button.y_root; |
---|
469 | e->_u.button.button = event->button.button; |
---|
470 | return e; |
---|
471 | |
---|
472 | case GDK_ENTER_NOTIFY: |
---|
473 | case GDK_LEAVE_NOTIFY: |
---|
474 | e->_d = Bonobo_Gdk_CROSSING; |
---|
475 | if (event->type == GDK_ENTER_NOTIFY) |
---|
476 | e->_u.crossing.type = Bonobo_Gdk_ENTER; |
---|
477 | else |
---|
478 | e->_u.crossing.type = Bonobo_Gdk_LEAVE; |
---|
479 | e->_u.crossing.time = event->crossing.time; |
---|
480 | e->_u.crossing.x = event->crossing.x; |
---|
481 | e->_u.crossing.y = event->crossing.y; |
---|
482 | e->_u.crossing.x_root = event->crossing.x_root; |
---|
483 | e->_u.crossing.y_root = event->crossing.y_root; |
---|
484 | |
---|
485 | switch (event->crossing.mode){ |
---|
486 | case GDK_CROSSING_NORMAL: |
---|
487 | e->_u.crossing.mode = Bonobo_Gdk_NORMAL; |
---|
488 | break; |
---|
489 | |
---|
490 | case GDK_CROSSING_GRAB: |
---|
491 | e->_u.crossing.mode = Bonobo_Gdk_GRAB; |
---|
492 | break; |
---|
493 | |
---|
494 | case GDK_CROSSING_UNGRAB: |
---|
495 | e->_u.crossing.mode = Bonobo_Gdk_UNGRAB; |
---|
496 | break; |
---|
497 | } |
---|
498 | return e; |
---|
499 | |
---|
500 | default: |
---|
501 | g_warning ("Unsupported event received"); |
---|
502 | } |
---|
503 | return NULL; |
---|
504 | } |
---|
505 | |
---|
506 | static gint |
---|
507 | gbi_event (GnomeCanvasItem *item, GdkEvent *event) |
---|
508 | { |
---|
509 | Gbi *gbi = GBI (item); |
---|
510 | CORBA_Environment ev; |
---|
511 | Bonobo_Gdk_Event *corba_event; |
---|
512 | Bonobo_Canvas_State state; |
---|
513 | CORBA_boolean ret; |
---|
514 | |
---|
515 | if (getenv ("DEBUG_BI")) |
---|
516 | g_message ("gbi_event"); |
---|
517 | |
---|
518 | corba_event = gdk_event_to_bonobo_event (event); |
---|
519 | if (corba_event == NULL) |
---|
520 | return FALSE; |
---|
521 | |
---|
522 | CORBA_exception_init (&ev); |
---|
523 | prepare_state (item, &state); |
---|
524 | ret = Bonobo_Canvas_Component_event (gbi->priv->object, &state, corba_event, &ev); |
---|
525 | CORBA_exception_free (&ev); |
---|
526 | CORBA_free (corba_event); |
---|
527 | |
---|
528 | return (gint) ret; |
---|
529 | } |
---|
530 | |
---|
531 | static void |
---|
532 | gbi_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) |
---|
533 | { |
---|
534 | Gbi *gbi = GBI (o); |
---|
535 | Bonobo_Canvas_ComponentProxy proxy_ref; |
---|
536 | Bonobo_Embeddable corba_emb; |
---|
537 | CORBA_Environment ev; |
---|
538 | |
---|
539 | switch (arg_id){ |
---|
540 | case ARG_CORBA_EMBEDDABLE: |
---|
541 | |
---|
542 | CORBA_exception_init (&ev); |
---|
543 | |
---|
544 | if (gbi->priv->object) |
---|
545 | Bonobo_Canvas_Component_unref (gbi->priv->object, &ev); |
---|
546 | |
---|
547 | gbi->priv->object = CORBA_OBJECT_NIL; |
---|
548 | corba_emb = GTK_VALUE_POINTER (*arg); |
---|
549 | |
---|
550 | g_return_if_fail (corba_emb != CORBA_OBJECT_NIL); |
---|
551 | |
---|
552 | proxy_ref = PortableServer_POA_servant_to_reference ( |
---|
553 | bonobo_poa (), (void *) gbi->priv->proxy, &ev); |
---|
554 | |
---|
555 | gbi->priv->object = Bonobo_Embeddable_createCanvasItem ( |
---|
556 | corba_emb, |
---|
557 | GNOME_CANVAS_ITEM (gbi)->canvas->aa, |
---|
558 | proxy_ref, &ev); |
---|
559 | |
---|
560 | CORBA_exception_free (&ev); |
---|
561 | |
---|
562 | if (gbi->priv->object == CORBA_OBJECT_NIL) { |
---|
563 | gtk_object_unref (GTK_OBJECT (gbi)); |
---|
564 | return; |
---|
565 | } |
---|
566 | |
---|
567 | /* Initial size notification */ |
---|
568 | proxy_size_allocate (GNOME_CANVAS_ITEM (gbi)->canvas, |
---|
569 | &(GTK_WIDGET (GNOME_CANVAS_ITEM (gbi)->canvas)->allocation), gbi); |
---|
570 | |
---|
571 | if (gbi->priv->realize_pending){ |
---|
572 | gbi->priv->realize_pending = 0; |
---|
573 | gbi_realize (GNOME_CANVAS_ITEM (gbi)); |
---|
574 | } |
---|
575 | break; |
---|
576 | |
---|
577 | case ARG_CORBA_UI_CONTAINER: |
---|
578 | |
---|
579 | gbi->priv->proxy->ui_container = GTK_VALUE_POINTER (*arg); |
---|
580 | |
---|
581 | g_return_if_fail (gbi->priv->proxy->ui_container != CORBA_OBJECT_NIL); |
---|
582 | |
---|
583 | bonobo_object_dup_ref (gbi->priv->proxy->ui_container, NULL); |
---|
584 | |
---|
585 | break; |
---|
586 | |
---|
587 | default: |
---|
588 | g_warning ("Unexpected arg_id %u", arg_id); |
---|
589 | break; |
---|
590 | } |
---|
591 | } |
---|
592 | |
---|
593 | static void |
---|
594 | gbi_finalize (GtkObject *object) |
---|
595 | { |
---|
596 | Gbi *gbi = GBI (object); |
---|
597 | CORBA_Environment ev; |
---|
598 | |
---|
599 | if (getenv ("DEBUG_BI")) |
---|
600 | g_message ("gbi_finalize"); |
---|
601 | |
---|
602 | CORBA_exception_init (&ev); |
---|
603 | |
---|
604 | if (gbi->priv->object != CORBA_OBJECT_NIL) |
---|
605 | Bonobo_Canvas_Component_unref (gbi->priv->object, &ev); |
---|
606 | |
---|
607 | if (gbi->priv->proxy){ |
---|
608 | ComponentProxyServant *proxy = gbi->priv->proxy; |
---|
609 | |
---|
610 | PortableServer_POA_deactivate_object (bonobo_poa (), proxy->oid, &ev); |
---|
611 | POA_Bonobo_Unknown__fini ((void *) proxy, &ev); |
---|
612 | CORBA_free (proxy->oid); |
---|
613 | g_free (proxy); |
---|
614 | } |
---|
615 | |
---|
616 | g_free (gbi->priv); |
---|
617 | CORBA_exception_free (&ev); |
---|
618 | |
---|
619 | (*GTK_OBJECT_CLASS (gbi_parent_class)->finalize)(object); |
---|
620 | } |
---|
621 | |
---|
622 | static void |
---|
623 | gbi_class_init (GtkObjectClass *object_class) |
---|
624 | { |
---|
625 | GnomeCanvasItemClass *item_class = (GnomeCanvasItemClass *) object_class; |
---|
626 | |
---|
627 | gbi_parent_class = gtk_type_class (gnome_canvas_item_get_type ()); |
---|
628 | |
---|
629 | gtk_object_add_arg_type ( |
---|
630 | "BonoboCanvasItem::corba_embeddable", |
---|
631 | GTK_TYPE_POINTER, |
---|
632 | GTK_ARG_WRITABLE, ARG_CORBA_EMBEDDABLE); |
---|
633 | |
---|
634 | gtk_object_add_arg_type ( |
---|
635 | "BonoboCanvasItem::corba_ui_container", |
---|
636 | GTK_TYPE_POINTER, |
---|
637 | GTK_ARG_WRITABLE, ARG_CORBA_UI_CONTAINER); |
---|
638 | |
---|
639 | object_class->set_arg = gbi_set_arg; |
---|
640 | object_class->finalize = gbi_finalize; |
---|
641 | item_class->update = gbi_update; |
---|
642 | item_class->realize = gbi_realize; |
---|
643 | item_class->unrealize = gbi_unrealize; |
---|
644 | item_class->draw = gbi_draw; |
---|
645 | item_class->point = gbi_point; |
---|
646 | item_class->bounds = gbi_bounds; |
---|
647 | item_class->render = gbi_render; |
---|
648 | item_class->event = gbi_event; |
---|
649 | } |
---|
650 | |
---|
651 | static void |
---|
652 | impl_Bonobo_Canvas_ComponentProxy_requestUpdate (PortableServer_Servant servant, |
---|
653 | CORBA_Environment *ev) |
---|
654 | { |
---|
655 | ComponentProxyServant *item_proxy = (ComponentProxyServant *) servant; |
---|
656 | |
---|
657 | if (getenv ("DEBUG_BI")) |
---|
658 | g_message ("Proxy_requestUpdate: item=%p", |
---|
659 | item_proxy->item_bound); |
---|
660 | |
---|
661 | gnome_canvas_item_request_update (item_proxy->item_bound); |
---|
662 | |
---|
663 | } |
---|
664 | |
---|
665 | static void |
---|
666 | impl_Bonobo_Canvas_ComponentProxy_requestRedraw (PortableServer_Servant servant, |
---|
667 | gint x1, gint y1, |
---|
668 | gint x2, gint y2, |
---|
669 | CORBA_Environment *ev) |
---|
670 | { |
---|
671 | ComponentProxyServant *item_proxy = (ComponentProxyServant *) servant; |
---|
672 | GnomeCanvas *canvas; |
---|
673 | |
---|
674 | g_return_if_fail (item_proxy->item_bound != NULL); |
---|
675 | |
---|
676 | canvas = item_proxy->item_bound->canvas; |
---|
677 | |
---|
678 | if (getenv ("DEBUG_BI")) |
---|
679 | g_message ("Proxy_requestRedraw: item=%p", |
---|
680 | item_proxy->item_bound); |
---|
681 | |
---|
682 | /* |
---|
683 | * Nasty re-enterany bug in the canvas in gnome-canvas.c (paint) |
---|
684 | * we need to set redraw_area = NULL and need_redraw = FALSE |
---|
685 | * concurrently, and deal with the re-enterancy. For now - |
---|
686 | * we try to correct the canvas: |
---|
687 | */ |
---|
688 | if (canvas->redraw_area == NULL && canvas->need_redraw) { |
---|
689 | /* Re-entered during paint */ |
---|
690 | g_warning ("Discarding redraw request"); |
---|
691 | } else |
---|
692 | gnome_canvas_request_redraw ( |
---|
693 | item_proxy->item_bound->canvas, |
---|
694 | x1, y1, x2, y2); |
---|
695 | } |
---|
696 | |
---|
697 | static void |
---|
698 | impl_Bonobo_Canvas_ComponentProxy_grabFocus (PortableServer_Servant servant, |
---|
699 | guint32 mask, |
---|
700 | gint32 cursor_type, |
---|
701 | guint32 time, |
---|
702 | CORBA_Environment *ev) |
---|
703 | { |
---|
704 | ComponentProxyServant *item_proxy = (ComponentProxyServant *) servant; |
---|
705 | GdkCursor *cursor; |
---|
706 | |
---|
707 | cursor = gdk_cursor_new ((GdkCursorType) cursor_type); |
---|
708 | |
---|
709 | gnome_canvas_item_grab (item_proxy->item_bound, mask, cursor, time); |
---|
710 | } |
---|
711 | |
---|
712 | static void |
---|
713 | impl_Bonobo_Canvas_ComponentProxy_ungrabFocus (PortableServer_Servant servant, |
---|
714 | guint32 time, |
---|
715 | CORBA_Environment *ev) |
---|
716 | { |
---|
717 | ComponentProxyServant *item_proxy = (ComponentProxyServant *) servant; |
---|
718 | |
---|
719 | gnome_canvas_item_ungrab (item_proxy->item_bound, time); |
---|
720 | } |
---|
721 | |
---|
722 | static Bonobo_UIContainer |
---|
723 | impl_Bonobo_Canvas_ComponentProxy_getUIContainer (PortableServer_Servant servant, |
---|
724 | CORBA_Environment *ev) |
---|
725 | { |
---|
726 | ComponentProxyServant *item_proxy = (ComponentProxyServant *) servant; |
---|
727 | |
---|
728 | g_return_val_if_fail (item_proxy->ui_container != CORBA_OBJECT_NIL, |
---|
729 | CORBA_OBJECT_NIL); |
---|
730 | |
---|
731 | return bonobo_object_dup_ref (item_proxy->ui_container, NULL); |
---|
732 | } |
---|
733 | |
---|
734 | static POA_Bonobo_Canvas_ComponentProxy__epv item_proxy_epv; |
---|
735 | |
---|
736 | static POA_Bonobo_Canvas_ComponentProxy__vepv item_proxy_vepv = { |
---|
737 | NULL, |
---|
738 | &item_proxy_epv |
---|
739 | }; |
---|
740 | |
---|
741 | /* |
---|
742 | * Creates a CORBA server to handle the ComponentProxy requests, it is not |
---|
743 | * activated by default |
---|
744 | */ |
---|
745 | static ComponentProxyServant * |
---|
746 | create_proxy (GnomeCanvasItem *item) |
---|
747 | { |
---|
748 | ComponentProxyServant *item_proxy = g_new0 (ComponentProxyServant, 1); |
---|
749 | CORBA_Environment ev; |
---|
750 | |
---|
751 | CORBA_exception_init (&ev); |
---|
752 | POA_Bonobo_Canvas_ComponentProxy__init ((PortableServer_Servant) item_proxy, &ev); |
---|
753 | |
---|
754 | item_proxy_epv.requestUpdate = impl_Bonobo_Canvas_ComponentProxy_requestUpdate; |
---|
755 | item_proxy_epv.requestRedraw = impl_Bonobo_Canvas_ComponentProxy_requestRedraw; |
---|
756 | item_proxy_epv.grabFocus = impl_Bonobo_Canvas_ComponentProxy_grabFocus; |
---|
757 | item_proxy_epv.ungrabFocus = impl_Bonobo_Canvas_ComponentProxy_ungrabFocus; |
---|
758 | item_proxy_epv.getUIContainer = impl_Bonobo_Canvas_ComponentProxy_getUIContainer; |
---|
759 | |
---|
760 | item_proxy->proxy_servant.vepv = &item_proxy_vepv; |
---|
761 | item_proxy->item_bound = item; |
---|
762 | |
---|
763 | item_proxy->oid = PortableServer_POA_activate_object ( |
---|
764 | bonobo_poa (), (void *) item_proxy, &ev); |
---|
765 | |
---|
766 | CORBA_exception_free (&ev); |
---|
767 | |
---|
768 | return item_proxy; |
---|
769 | } |
---|
770 | |
---|
771 | static void |
---|
772 | gbi_init (BonoboCanvasItem *gbi) |
---|
773 | { |
---|
774 | gbi->priv = g_new0 (BonoboCanvasItemPrivate, 1); |
---|
775 | gbi->priv->proxy = create_proxy (GNOME_CANVAS_ITEM (gbi)); |
---|
776 | } |
---|
777 | |
---|
778 | /** |
---|
779 | * bonobo_canvas_item_get_type: |
---|
780 | * |
---|
781 | * Returns the GtkType associated with a #BonoboCanvasItem canvas item |
---|
782 | */ |
---|
783 | GtkType |
---|
784 | bonobo_canvas_item_get_type (void) |
---|
785 | { |
---|
786 | static GtkType type = 0; |
---|
787 | |
---|
788 | if (!type) { |
---|
789 | GtkTypeInfo info = { |
---|
790 | "BonoboCanvasItem", |
---|
791 | sizeof (BonoboCanvasItem), |
---|
792 | sizeof (BonoboCanvasItemClass), |
---|
793 | (GtkClassInitFunc) gbi_class_init, |
---|
794 | (GtkObjectInitFunc) gbi_init, |
---|
795 | NULL, /* reserved_1 */ |
---|
796 | NULL, /* reserved_2 */ |
---|
797 | (GtkClassInitFunc) NULL |
---|
798 | }; |
---|
799 | |
---|
800 | type = gtk_type_unique (gnome_canvas_item_get_type (), &info); |
---|
801 | } |
---|
802 | |
---|
803 | return type; |
---|
804 | } |
---|
805 | |
---|
806 | void |
---|
807 | bonobo_canvas_item_set_bounds (BonoboCanvasItem *item, double x1, double y1, double x2, double y2) |
---|
808 | { |
---|
809 | |
---|
810 | } |
---|