~ubuntu-branches/ubuntu/gutsy/goocanvas/gutsy

« back to all changes in this revision

Viewing changes to src/goocanvasgroupview.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2006-08-28 11:47:12 UTC
  • Revision ID: james.westby@ubuntu.com-20060828114712-ejoo9vy6ckao9cvs
Tags: upstream-0.4
ImportĀ upstreamĀ versionĀ 0.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * GooCanvas. Copyright (C) 2005 Damon Chaplin.
 
3
 * Released under the GNU LGPL license. See COPYING for details.
 
4
 *
 
5
 * goocanvasgroupview.c - view for group item.
 
6
 */
 
7
 
 
8
/**
 
9
 * SECTION:goocanvasgroupview
 
10
 * @Title: GooCanvasGroupView
 
11
 * @Short_Description: a view for a group #GooCanvasItem.
 
12
 *
 
13
 * #GooCanvasGroupView represents a view of a group #GooCanvasItem (typically
 
14
 * a #GooCanvasGroup).
 
15
 *
 
16
 * It implements the #GooCanvasItemView interface, so you can use the
 
17
 * #GooCanvasItemView functions such as goo_canvas_item_view_get_item()
 
18
 * and goo_canvas_item_view_get_bounds().
 
19
 *
 
20
 * Applications do not normally need to create item views themselves, as
 
21
 * they are created automatically by #GooCanvasView when needed.
 
22
 *
 
23
 * To respond to events such as mouse clicks in the ellipse view you can
 
24
 * connect to one of the #GooCanvasItemView signals such as
 
25
 * #GooCanvasItemView::button-press-event. You can connect to these signals
 
26
 * when the view is created. (See goo_canvas_view_get_item_view() and
 
27
 * #GooCanvasView::item-view-created.)
 
28
 */
 
29
#include <config.h>
 
30
#include <gtk/gtk.h>
 
31
#include "goocanvasprivate.h"
 
32
#include "goocanvasgroupview.h"
 
33
#include "goocanvasgroup.h"
 
34
#include "goocanvasview.h"
 
35
#include "goocanvasutils.h"
 
36
#include "goocanvasatk.h"
 
37
 
 
38
 
 
39
enum {
 
40
  PROP_0,
 
41
 
 
42
  PROP_CAN_FOCUS
 
43
};
 
44
 
 
45
 
 
46
static void canvas_item_view_interface_init (GooCanvasItemViewIface *iface);
 
47
static void goo_canvas_group_view_finalize  (GObject              *object);
 
48
static void goo_canvas_group_view_get_property (GObject              *object,
 
49
                                                guint                 prop_id,
 
50
                                                GValue               *value,
 
51
                                                GParamSpec           *pspec);
 
52
static void goo_canvas_group_view_set_property (GObject              *object,
 
53
                                                guint                 prop_id,
 
54
                                                const GValue         *value,
 
55
                                                GParamSpec           *pspec);
 
56
static void add_child_views_recursively     (GooCanvasGroupView   *group_view);
 
57
static void connect_group_signals           (GooCanvasGroupView   *group_view);
 
58
static void on_group_changed                (GooCanvasItem        *group,
 
59
                                             gboolean              recompute_bounds,
 
60
                                             GooCanvasGroupView   *view);
 
61
 
 
62
G_DEFINE_TYPE_WITH_CODE (GooCanvasGroupView, goo_canvas_group_view,
 
63
                         G_TYPE_OBJECT,
 
64
                         G_IMPLEMENT_INTERFACE (GOO_TYPE_CANVAS_ITEM_VIEW,
 
65
                                                canvas_item_view_interface_init))
 
66
 
 
67
 
 
68
static void
 
69
goo_canvas_group_view_class_init (GooCanvasGroupViewClass *klass)
 
70
{
 
71
  GObjectClass *gobject_class = (GObjectClass*) klass;
 
72
 
 
73
  gobject_class->finalize = goo_canvas_group_view_finalize;
 
74
 
 
75
  gobject_class->get_property = goo_canvas_group_view_get_property;
 
76
  gobject_class->set_property = goo_canvas_group_view_set_property;
 
77
 
 
78
  atk_registry_set_factory_type (atk_get_default_registry (),
 
79
                                 GOO_TYPE_CANVAS_GROUP_VIEW,
 
80
                                 goo_canvas_item_view_accessible_factory_get_type ());
 
81
 
 
82
  g_object_class_override_property (gobject_class, PROP_CAN_FOCUS,
 
83
                                    "can-focus");
 
84
}
 
85
 
 
86
 
 
87
static void
 
88
goo_canvas_group_view_init (GooCanvasGroupView *group_view)
 
89
{
 
90
  group_view->item_views = g_ptr_array_sized_new (8);
 
91
 
 
92
  group_view->flags = GOO_CANVAS_ITEM_VIEW_NEED_UPDATE
 
93
    | GOO_CANVAS_ITEM_VIEW_NEED_ENTIRE_SUBTREE_UPDATE;
 
94
}
 
95
 
 
96
 
 
97
static void
 
98
goo_canvas_group_view_title_changed (GooCanvasItem      *group,
 
99
                                     GParamSpec         *pspec,
 
100
                                     GooCanvasGroupView *group_view)
 
101
{
 
102
  AtkObject *accessible;
 
103
  gchar *title;
 
104
 
 
105
  accessible = atk_gobject_accessible_for_object (G_OBJECT (group_view));
 
106
  g_object_get (group, "title", &title, NULL);
 
107
  atk_object_set_name (accessible, title);
 
108
  g_free (title);
 
109
}
 
110
 
 
111
 
 
112
static void
 
113
goo_canvas_group_view_description_changed (GooCanvasItem      *group,
 
114
                                           GParamSpec         *pspec,
 
115
                                           GooCanvasGroupView *group_view)
 
116
{
 
117
  AtkObject *accessible;
 
118
  gchar *description;
 
119
 
 
120
  accessible = atk_gobject_accessible_for_object (G_OBJECT (group_view));
 
121
  g_object_get (group, "description", &description, NULL);
 
122
  atk_object_set_description (accessible, description);
 
123
  g_free (description);
 
124
}
 
125
 
 
126
 
 
127
/**
 
128
 * goo_canvas_group_view_set_group:
 
129
 * @group_view: a #GooCanvasGroupView.
 
130
 * @group: a #GooCanvasItem.
 
131
 * 
 
132
 * This function is only intended to be used by subclasses during construction
 
133
 * of the item views.
 
134
 *
 
135
 * It sets the underlying group item, creates any necessary child views, and
 
136
 * sets up signal handlers to update child views as the underlying items
 
137
 * are changed.
 
138
 **/
 
139
void
 
140
goo_canvas_group_view_set_group (GooCanvasGroupView *group_view,
 
141
                                 GooCanvasItem      *group)
 
142
{
 
143
  AtkObject *accessible;
 
144
  gchar *title, *description;
 
145
 
 
146
  if (group_view->group)
 
147
    {
 
148
      g_signal_handlers_disconnect_matched (group_view->group,
 
149
                                            G_SIGNAL_MATCH_DATA,
 
150
                                            0, 0, NULL, NULL, group_view);
 
151
 
 
152
      g_object_unref (group_view->group);
 
153
    }
 
154
 
 
155
  group_view->group = g_object_ref (group);
 
156
 
 
157
  g_object_get (group,
 
158
                "title", &title,
 
159
                "description", &description,
 
160
                NULL);
 
161
 
 
162
  accessible = atk_gobject_accessible_for_object (G_OBJECT (group_view));
 
163
  if (title)
 
164
    atk_object_set_name (accessible, title);
 
165
  if (description)
 
166
    atk_object_set_description (accessible, description);
 
167
  g_free (title);
 
168
  g_free (description);
 
169
 
 
170
  g_signal_connect (group, "notify::title",
 
171
                    G_CALLBACK (goo_canvas_group_view_title_changed),
 
172
                    group_view);
 
173
  g_signal_connect (group, "notify::description",
 
174
                    G_CALLBACK (goo_canvas_group_view_description_changed),
 
175
                    group_view);
 
176
 
 
177
  add_child_views_recursively (group_view);
 
178
  connect_group_signals (group_view);
 
179
 
 
180
  g_signal_connect (group, "changed", G_CALLBACK (on_group_changed),
 
181
                    group_view);
 
182
}
 
183
 
 
184
 
 
185
/**
 
186
 * goo_canvas_group_view_new:
 
187
 * @canvas_view: the canvas view.
 
188
 * @parent_view: the parent view.
 
189
 * @group: the group item.
 
190
 * 
 
191
 * Creates a new #GooCanvasGroupView for the given #GooCanvasItem.
 
192
 *
 
193
 * This is not normally used by application code, as the views are created
 
194
 * automatically by #GooCanvasView.
 
195
 * 
 
196
 * Returns: a new #GooCanvasGroupView.
 
197
 **/
 
198
GooCanvasItemView*
 
199
goo_canvas_group_view_new      (GooCanvasView     *canvas_view,
 
200
                                GooCanvasItemView *parent_view,
 
201
                                GooCanvasItem     *group)
 
202
{
 
203
  GooCanvasGroupView *group_view;
 
204
 
 
205
  group_view = g_object_new (GOO_TYPE_CANVAS_GROUP_VIEW, NULL);
 
206
 
 
207
  group_view->canvas_view = canvas_view;
 
208
  group_view->parent_view = parent_view;
 
209
 
 
210
  goo_canvas_group_view_set_group (group_view, group);
 
211
 
 
212
  return GOO_CANVAS_ITEM_VIEW (group_view);
 
213
}
 
214
 
 
215
 
 
216
static void
 
217
goo_canvas_group_view_finalize (GObject *object)
 
218
{
 
219
  GooCanvasGroupView *group_view = (GooCanvasGroupView*) object;
 
220
  gint i;
 
221
 
 
222
  /* Unref all the items in the group. */
 
223
  for (i = 0; i < group_view->item_views->len; i++)
 
224
    {
 
225
      GooCanvasItemView *item_view = group_view->item_views->pdata[i];
 
226
      goo_canvas_item_view_set_parent_view (item_view, NULL);
 
227
      g_object_unref (item_view);
 
228
    }
 
229
 
 
230
  g_ptr_array_free (group_view->item_views, TRUE);
 
231
 
 
232
  /* Remove the view from the GooCanvasView hash table. */
 
233
  goo_canvas_view_unregister_item_view (group_view->canvas_view,
 
234
                                        group_view->group);
 
235
 
 
236
  /* Unref the group. */
 
237
  g_object_unref (group_view->group);
 
238
  group_view->group = NULL;
 
239
 
 
240
  G_OBJECT_CLASS (goo_canvas_group_view_parent_class)->finalize (object);
 
241
}
 
242
 
 
243
 
 
244
static void
 
245
goo_canvas_group_view_get_property (GObject              *object,
 
246
                                    guint                 prop_id,
 
247
                                    GValue               *value,
 
248
                                    GParamSpec           *pspec)
 
249
{
 
250
  GooCanvasGroupView *group_view = (GooCanvasGroupView*) object;
 
251
 
 
252
  switch (prop_id)
 
253
    {
 
254
    case PROP_CAN_FOCUS:
 
255
      g_value_set_boolean (value,
 
256
                           group_view->flags & GOO_CANVAS_ITEM_VIEW_CAN_FOCUS);
 
257
      break;
 
258
    default:
 
259
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 
260
      break;
 
261
    }
 
262
}
 
263
 
 
264
 
 
265
static void
 
266
goo_canvas_group_view_set_property (GObject              *object,
 
267
                                    guint                 prop_id,
 
268
                                    const GValue         *value,
 
269
                                    GParamSpec           *pspec)
 
270
{
 
271
  GooCanvasGroupView *group_view = (GooCanvasGroupView*) object;
 
272
 
 
273
  switch (prop_id)
 
274
    {
 
275
    case PROP_CAN_FOCUS:
 
276
      if (g_value_get_boolean (value))
 
277
        group_view->flags |= GOO_CANVAS_ITEM_VIEW_CAN_FOCUS;
 
278
      else
 
279
        group_view->flags &= ~GOO_CANVAS_ITEM_VIEW_CAN_FOCUS;
 
280
      break;
 
281
    default:
 
282
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
 
283
      break;
 
284
    }
 
285
}
 
286
 
 
287
 
 
288
static void
 
289
on_child_item_added (GooCanvasItem      *group,
 
290
                     gint                position,
 
291
                     GooCanvasGroupView *group_view)
 
292
{
 
293
  GooCanvasItem *item;
 
294
  GooCanvasItemView *view;
 
295
 
 
296
  /* Get a view for the item. */
 
297
  item = goo_canvas_item_get_child (group, position);
 
298
  view = goo_canvas_view_create_item_view (group_view->canvas_view, item,
 
299
                                           (GooCanvasItemView*) group_view);
 
300
 
 
301
  if (position >= 0)
 
302
    goo_canvas_util_ptr_array_insert (group_view->item_views, view, position);
 
303
  else
 
304
    g_ptr_array_add (group_view->item_views, view);
 
305
 
 
306
  goo_canvas_item_view_request_update ((GooCanvasItemView*) group_view);
 
307
}
 
308
 
 
309
 
 
310
static void
 
311
on_child_item_moved (GooCanvasItem      *group,
 
312
                     gint                old_position,
 
313
                     gint                new_position,
 
314
                     GooCanvasGroupView *group_view)
 
315
{
 
316
  GooCanvasItemView *view;
 
317
  GooCanvasBounds bounds;
 
318
 
 
319
  /* Request a redraw of the item's bounds. */
 
320
  view = group_view->item_views->pdata[old_position];
 
321
  goo_canvas_item_view_get_bounds (view, &bounds);
 
322
  goo_canvas_view_request_redraw (group_view->canvas_view, &bounds);
 
323
 
 
324
  goo_canvas_util_ptr_array_move (group_view->item_views, old_position,
 
325
                                  new_position);
 
326
 
 
327
  goo_canvas_item_view_request_update ((GooCanvasItemView*) group_view);
 
328
}
 
329
 
 
330
 
 
331
static void
 
332
on_child_item_removed (GooCanvasItem      *group,
 
333
                       gint                item_num,
 
334
                       GooCanvasGroupView *group_view)
 
335
{
 
336
  GooCanvasItemView *view;
 
337
  GooCanvasBounds bounds;
 
338
 
 
339
  view = group_view->item_views->pdata[item_num];
 
340
 
 
341
  /* Request a redraw of the item's bounds. */
 
342
  goo_canvas_item_view_get_bounds (view, &bounds);
 
343
  goo_canvas_view_request_redraw (group_view->canvas_view, &bounds);
 
344
 
 
345
  /* Reset the item's parent to NULL, in case it is kept around. */
 
346
  goo_canvas_item_view_set_parent_view (view, NULL);
 
347
  g_object_unref (view);
 
348
 
 
349
  g_ptr_array_remove_index (group_view->item_views, item_num);
 
350
 
 
351
  goo_canvas_item_view_request_update ((GooCanvasItemView*) group_view);
 
352
}
 
353
 
 
354
 
 
355
static void
 
356
add_child_views_recursively (GooCanvasGroupView *group_view)
 
357
{
 
358
  gint n_children, i;
 
359
 
 
360
  n_children = goo_canvas_item_get_n_children (group_view->group);
 
361
 
 
362
  for (i = 0; i < n_children; i++)
 
363
    {
 
364
      on_child_item_added (group_view->group, i, group_view);
 
365
    }
 
366
}
 
367
 
 
368
 
 
369
static void
 
370
connect_group_signals (GooCanvasGroupView *group_view)
 
371
{
 
372
  GooCanvasItem *group = group_view->group;
 
373
 
 
374
  g_signal_connect (group, "child-added", G_CALLBACK (on_child_item_added),
 
375
                    group_view);
 
376
  g_signal_connect (group, "child-moved", G_CALLBACK (on_child_item_moved),
 
377
                    group_view);
 
378
  g_signal_connect (group, "child-removed", G_CALLBACK (on_child_item_removed),
 
379
                    group_view);
 
380
}
 
381
 
 
382
 
 
383
static GooCanvasView*
 
384
goo_canvas_group_view_get_canvas_view (GooCanvasItemView *view)
 
385
{
 
386
  GooCanvasGroupView *group_view = (GooCanvasGroupView*) view;
 
387
  return group_view->canvas_view;
 
388
}
 
389
 
 
390
 
 
391
static gint
 
392
goo_canvas_group_view_get_n_children (GooCanvasItemView       *view)
 
393
{
 
394
  GooCanvasGroupView *group_view = (GooCanvasGroupView*) view;
 
395
  return group_view->item_views->len;
 
396
}
 
397
 
 
398
 
 
399
static GooCanvasItemView*
 
400
goo_canvas_group_view_get_child   (GooCanvasItemView    *view,
 
401
                                   gint                  child_num)
 
402
{
 
403
  GooCanvasGroupView *group_view = (GooCanvasGroupView*) view;
 
404
  return group_view->item_views->pdata[child_num];
 
405
}
 
406
 
 
407
 
 
408
static void
 
409
goo_canvas_group_view_request_update  (GooCanvasItemView *view)
 
410
{
 
411
  GooCanvasGroupView *group_view = (GooCanvasGroupView*) view;
 
412
 
 
413
  if (!(group_view->flags & GOO_CANVAS_ITEM_VIEW_NEED_UPDATE))
 
414
    {
 
415
      group_view->flags |= GOO_CANVAS_ITEM_VIEW_NEED_UPDATE;
 
416
 
 
417
      if (group_view->parent_view)
 
418
        goo_canvas_item_view_request_update (group_view->parent_view);
 
419
      else
 
420
        goo_canvas_view_request_update (group_view->canvas_view);
 
421
    }
 
422
}
 
423
 
 
424
 
 
425
static void
 
426
goo_canvas_group_view_update  (GooCanvasItemView  *view,
 
427
                               gboolean            entire_tree,
 
428
                               cairo_t            *cr,
 
429
                               GooCanvasBounds    *bounds)
 
430
{
 
431
  GooCanvasGroupView *group_view = (GooCanvasGroupView*) view;
 
432
  GooCanvasBounds child_bounds;
 
433
  cairo_matrix_t transform;
 
434
  gint i;
 
435
 
 
436
  if (entire_tree || (group_view->flags & GOO_CANVAS_ITEM_VIEW_NEED_UPDATE))
 
437
    {
 
438
      if (group_view->flags & GOO_CANVAS_ITEM_VIEW_NEED_ENTIRE_SUBTREE_UPDATE)
 
439
        entire_tree = TRUE;
 
440
 
 
441
      group_view->flags &= ~GOO_CANVAS_ITEM_VIEW_NEED_UPDATE;
 
442
      group_view->flags &= ~GOO_CANVAS_ITEM_VIEW_NEED_ENTIRE_SUBTREE_UPDATE;
 
443
 
 
444
      group_view->bounds.x1 = group_view->bounds.y1 = 0.0;
 
445
      group_view->bounds.x2 = group_view->bounds.y2 = 0.0;
 
446
 
 
447
      cairo_save (cr);
 
448
 
 
449
      if (goo_canvas_item_view_get_combined_transform (view, &transform))
 
450
        cairo_transform (cr, &transform);
 
451
 
 
452
      for (i = 0; i < group_view->item_views->len; i++)
 
453
        {
 
454
          GooCanvasItemView *child_view = group_view->item_views->pdata[i];
 
455
 
 
456
          goo_canvas_item_view_update (child_view, entire_tree, cr,
 
457
                                       &child_bounds);
 
458
          
 
459
          if (i == 0)
 
460
            {
 
461
              group_view->bounds.x1 = child_bounds.x1;
 
462
              group_view->bounds.y1 = child_bounds.y1;
 
463
              group_view->bounds.x2 = child_bounds.x2;
 
464
              group_view->bounds.y2 = child_bounds.y2;
 
465
            }
 
466
          else
 
467
            {
 
468
              group_view->bounds.x1 = MIN (group_view->bounds.x1,
 
469
                                           child_bounds.x1);
 
470
              group_view->bounds.y1 = MIN (group_view->bounds.y1,
 
471
                                           child_bounds.y1);
 
472
              group_view->bounds.x2 = MAX (group_view->bounds.x2,
 
473
                                           child_bounds.x2);
 
474
              group_view->bounds.y2 = MAX (group_view->bounds.y2,
 
475
                                           child_bounds.y2);
 
476
            }
 
477
        }
 
478
      cairo_restore (cr);
 
479
    }
 
480
 
 
481
  *bounds = group_view->bounds;
 
482
}
 
483
 
 
484
 
 
485
static GooCanvasItemView*
 
486
goo_canvas_group_view_get_parent_view (GooCanvasItemView   *view)
 
487
{
 
488
  GooCanvasGroupView *group_view = (GooCanvasGroupView*) view;
 
489
  return group_view->parent_view;
 
490
}
 
491
 
 
492
 
 
493
static void
 
494
goo_canvas_group_view_set_parent_view (GooCanvasItemView  *view,
 
495
                                       GooCanvasItemView  *parent_view)
 
496
{
 
497
  GooCanvasGroupView *group_view = (GooCanvasGroupView*) view;
 
498
  group_view->parent_view = parent_view;
 
499
}
 
500
 
 
501
 
 
502
static GooCanvasItem*
 
503
goo_canvas_group_view_get_item (GooCanvasItemView  *view)
 
504
{
 
505
  GooCanvasGroupView *group_view = (GooCanvasGroupView*) view;
 
506
  return (GooCanvasItem*) group_view->group;
 
507
}
 
508
 
 
509
 
 
510
static void
 
511
goo_canvas_group_view_get_bounds  (GooCanvasItemView  *view,
 
512
                                   GooCanvasBounds    *bounds)
 
513
{
 
514
  GooCanvasGroupView *group_view = (GooCanvasGroupView*) view;
 
515
 
 
516
  if (group_view->flags & GOO_CANVAS_ITEM_VIEW_NEED_UPDATE)
 
517
    goo_canvas_item_view_ensure_updated (view);
 
518
 
 
519
  *bounds = group_view->bounds;
 
520
}
 
521
 
 
522
 
 
523
static GooCanvasItemView*
 
524
goo_canvas_group_view_get_item_view_at (GooCanvasItemView  *view,
 
525
                                        gdouble             x,
 
526
                                        gdouble             y,
 
527
                                        cairo_t            *cr,
 
528
                                        gboolean            is_pointer_event,
 
529
                                        gboolean            parent_visible)
 
530
{
 
531
  GooCanvasGroupView *group_view = (GooCanvasGroupView*) view;
 
532
  GooCanvasBounds child_bounds;
 
533
  GooCanvasItemView *found_item = NULL;
 
534
  GooCanvasItemVisibility visibility;
 
535
  gboolean visible = parent_visible;
 
536
  cairo_matrix_t transform;
 
537
  int i;
 
538
 
 
539
  if (group_view->flags & GOO_CANVAS_ITEM_VIEW_NEED_UPDATE)
 
540
    goo_canvas_item_view_ensure_updated (view);
 
541
 
 
542
  g_object_get (group_view->group, "visibility", &visibility, NULL);
 
543
 
 
544
  if (visibility == GOO_CANVAS_ITEM_INVISIBLE)
 
545
    {
 
546
      visible = FALSE;
 
547
    }
 
548
  else if (visibility == GOO_CANVAS_ITEM_VISIBLE_ABOVE_THRESHOLD)
 
549
    {
 
550
      gdouble visibility_threshold;
 
551
      g_object_get (group_view->group,
 
552
                    "visibility-threshold", &visibility_threshold,
 
553
                    NULL);
 
554
      if (group_view->canvas_view->scale < visibility_threshold)
 
555
        visible = FALSE;
 
556
    }
 
557
 
 
558
  /* Check if the group should receive events. */
 
559
  if (is_pointer_event)
 
560
    {
 
561
      GooCanvasPointerEvents pointer_events;
 
562
      g_object_get (group_view->group,
 
563
                    "pointer-events", &pointer_events,
 
564
                    NULL);
 
565
      if (pointer_events == GOO_CANVAS_EVENTS_NONE
 
566
          || ((pointer_events & GOO_CANVAS_EVENTS_VISIBLE_MASK) && !visible))
 
567
        return NULL;
 
568
    }
 
569
 
 
570
  /* Step down from the top item to the bottom in the stack/layer, and return
 
571
     the first item found that contains the given point. */
 
572
  cairo_save (cr);
 
573
 
 
574
  if (goo_canvas_item_view_get_combined_transform (view, &transform))
 
575
    cairo_transform (cr, &transform);
 
576
 
 
577
  for (i = group_view->item_views->len - 1; i >= 0; i--)
 
578
    {
 
579
      GooCanvasItemView *child_view = group_view->item_views->pdata[i];
 
580
      goo_canvas_item_view_get_bounds (child_view, &child_bounds);
 
581
 
 
582
      /* Skip the item if the bounds don't contain the point. */
 
583
      if (child_bounds.x1 > x || child_bounds.x2 < x
 
584
          || child_bounds.y1 > y || child_bounds.y2 < y)
 
585
        continue;
 
586
 
 
587
      found_item = goo_canvas_item_view_get_item_view_at (child_view, x, y, cr,
 
588
                                                          is_pointer_event,
 
589
                                                          visible);
 
590
      if (found_item)
 
591
        break;
 
592
    }
 
593
  cairo_restore (cr);
 
594
 
 
595
  return found_item;
 
596
}
 
597
 
 
598
 
 
599
static gboolean
 
600
goo_canvas_group_view_is_visible  (GooCanvasItemView   *view)
 
601
{
 
602
  GooCanvasGroupView *group_view = (GooCanvasGroupView*) view;
 
603
  GooCanvasItemVisibility visibility;
 
604
 
 
605
  g_object_get (group_view->group, "visibility", &visibility, NULL);
 
606
 
 
607
  if (visibility == GOO_CANVAS_ITEM_INVISIBLE)
 
608
    return FALSE;
 
609
 
 
610
  if (visibility == GOO_CANVAS_ITEM_VISIBLE_ABOVE_THRESHOLD)
 
611
    {
 
612
      gdouble visibility_threshold;
 
613
      g_object_get (group_view->group,
 
614
                    "visibility-threshold", &visibility_threshold,
 
615
                    NULL);
 
616
      if (group_view->canvas_view->scale < visibility_threshold)
 
617
        return FALSE;
 
618
    }
 
619
 
 
620
  if (group_view->parent_view)
 
621
    return goo_canvas_item_view_is_visible (group_view->parent_view);
 
622
 
 
623
  return TRUE;
 
624
}
 
625
 
 
626
 
 
627
static void
 
628
goo_canvas_group_view_paint (GooCanvasItemView *view,
 
629
                             cairo_t           *cr,
 
630
                             GooCanvasBounds   *bounds,
 
631
                             gdouble            scale)
 
632
{
 
633
  GooCanvasGroupView *group_view = (GooCanvasGroupView*) view;
 
634
  GooCanvasBounds child_bounds;
 
635
  GooCanvasItemVisibility visibility;
 
636
  cairo_matrix_t transform;
 
637
  gint i;
 
638
 
 
639
  /* Check if the item should be visible. */
 
640
  g_object_get (group_view->group, "visibility", &visibility, NULL);
 
641
 
 
642
  if (visibility == GOO_CANVAS_ITEM_INVISIBLE)
 
643
    return;
 
644
 
 
645
  if (visibility == GOO_CANVAS_ITEM_VISIBLE_ABOVE_THRESHOLD)
 
646
    {
 
647
      gdouble visibility_threshold;
 
648
      g_object_get (group_view->group,
 
649
                    "visibility-threshold", &visibility_threshold,
 
650
                    NULL);
 
651
      if (group_view->canvas_view->scale < visibility_threshold)
 
652
        return;
 
653
    }
 
654
 
 
655
  /* Paint all the items in the group. */
 
656
  cairo_save (cr);
 
657
 
 
658
  if (goo_canvas_item_view_get_combined_transform (view, &transform))
 
659
    cairo_transform (cr, &transform);
 
660
 
 
661
  for (i = 0; i < group_view->item_views->len; i++)
 
662
    {
 
663
      GooCanvasItemView *child_view = group_view->item_views->pdata[i];
 
664
 
 
665
      goo_canvas_item_view_get_bounds (child_view, &child_bounds);
 
666
 
 
667
      /* Skip the item if the bounds don't intersect the expose rectangle. */
 
668
      if (child_bounds.x1 > bounds->x2 || child_bounds.x2 < bounds->x1
 
669
          || child_bounds.y1 > bounds->y2 || child_bounds.y2 < bounds->y1)
 
670
        continue;
 
671
 
 
672
      goo_canvas_item_view_paint (child_view, cr, bounds, scale);
 
673
    }
 
674
  cairo_restore (cr);
 
675
}
 
676
 
 
677
 
 
678
static void
 
679
canvas_item_view_interface_init (GooCanvasItemViewIface *iface)
 
680
{
 
681
  iface->get_canvas_view  = goo_canvas_group_view_get_canvas_view;
 
682
  iface->get_n_children   = goo_canvas_group_view_get_n_children;
 
683
  iface->get_child        = goo_canvas_group_view_get_child;
 
684
  iface->request_update   = goo_canvas_group_view_request_update;
 
685
 
 
686
  iface->get_parent_view  = goo_canvas_group_view_get_parent_view;
 
687
  iface->set_parent_view  = goo_canvas_group_view_set_parent_view;
 
688
  iface->get_item         = goo_canvas_group_view_get_item;
 
689
  iface->get_bounds       = goo_canvas_group_view_get_bounds;
 
690
  iface->get_item_view_at = goo_canvas_group_view_get_item_view_at;
 
691
  iface->is_visible       = goo_canvas_group_view_is_visible;
 
692
  iface->update           = goo_canvas_group_view_update;
 
693
  iface->paint            = goo_canvas_group_view_paint;
 
694
}
 
695
 
 
696
 
 
697
static void
 
698
on_group_changed                (GooCanvasItem      *group,
 
699
                                 gboolean            recompute_bounds,
 
700
                                 GooCanvasGroupView *view)
 
701
{
 
702
  view->flags |= GOO_CANVAS_ITEM_VIEW_NEED_ENTIRE_SUBTREE_UPDATE;
 
703
  goo_canvas_item_view_request_update ((GooCanvasItemView*) view);
 
704
}