Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/src/goocanvas/src/goocanvasitemsimple.c
blob: 46544ed948caf8b8dbfceec41efb6237c90f27d8 (plain)
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
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
/*
 * GooCanvas. Copyright (C) 2005-6 Damon Chaplin.
 * Released under the GNU LGPL license. See COPYING for details.
 *
 * goocanvasitemsimple.c - abstract base class for canvas items.
 */

/**
 * SECTION:goocanvasitemsimple
 * @Title: GooCanvasItemSimple
 * @Short_Description: the base class for the standard canvas items.
 * @Stability_Level: 
 * @See_Also: 
 *
 * #GooCanvasItemSimple is used as a base class for all of the standard canvas
 * items. It can also be used as the base class for new custom canvas items.
 *
 * It provides default implementations for many of the #GooCanvasItem
 * methods.
 *
 * For very simple items, all that is needed is to implement the create_path()
 * method. (#GooCanvasEllipse, #GooCanvasRect and #GooCanvasPath do this.)
 *
 * More complicated items need to implement the update(), paint() and
 * is_item_at() methods instead. (#GooCanvasImage, #GooCanvasPolyline,
 * #GooCanvasText and #GooCanvasWidget do this.) They may also need to
 * override some of the other GooCanvasItem methods such as set_canvas(),
 * set_parent() or allocate_area() if special code is needed. (#GooCanvasWidget
 * does this to make sure the #GtkWidget is embedded in the #GooCanvas widget
 * correctly.)
 */
#include <config.h>
#include <glib/gi18n-lib.h>
#include <gtk/gtk.h>
#include "goocanvasprivate.h"
#include "goocanvasitemsimple.h"
#include "goocanvas.h"
#include "goocanvasatk.h"


enum {
  PROP_0,

  /* Basic drawing properties. */
  PROP_STROKE_PATTERN,
  PROP_FILL_PATTERN,
  PROP_FILL_RULE,
  PROP_OPERATOR,
  PROP_ANTIALIAS,

  /* Line style & width properties. */
  PROP_LINE_WIDTH,
  PROP_LINE_CAP,
  PROP_LINE_JOIN,
  PROP_LINE_JOIN_MITER_LIMIT,
  PROP_LINE_DASH,

  /* Font properties. */
  PROP_FONT,
  PROP_FONT_DESC,
  PROP_HINT_METRICS,

  /* Convenience properties. */
  PROP_STROKE_COLOR,
  PROP_STROKE_COLOR_RGBA,
  PROP_STROKE_PIXBUF,
  PROP_FILL_COLOR,
  PROP_FILL_COLOR_RGBA,
  PROP_FILL_PIXBUF,

  /* Other properties. Note that the order here is important PROP_TRANSFORM
     must be the first non-style property. see set_property(). */
  PROP_TRANSFORM,
  PROP_PARENT,
  PROP_VISIBILITY,
  PROP_VISIBILITY_THRESHOLD,
  PROP_POINTER_EVENTS,
  PROP_TITLE,
  PROP_DESCRIPTION,
  PROP_CAN_FOCUS,
  PROP_CLIP_PATH,
  PROP_CLIP_FILL_RULE,
  PROP_TOOLTIP
};

static gboolean accessibility_enabled = FALSE;

static void canvas_item_interface_init          (GooCanvasItemIface   *iface);
static void goo_canvas_item_simple_dispose      (GObject              *object);
static void goo_canvas_item_simple_finalize     (GObject              *object);
static void goo_canvas_item_simple_get_property (GObject              *object,
						 guint                 prop_id,
						 GValue               *value,
						 GParamSpec           *pspec);
static void goo_canvas_item_simple_set_property (GObject              *object,
						 guint                 prop_id,
						 const GValue         *value,
						 GParamSpec           *pspec);

static void     goo_canvas_item_simple_default_create_path (GooCanvasItemSimple   *simple,
							    cairo_t               *cr);
static void     goo_canvas_item_simple_default_update      (GooCanvasItemSimple   *simple,
							    cairo_t               *cr);
static void     goo_canvas_item_simple_default_paint       (GooCanvasItemSimple   *simple,
							    cairo_t               *cr,
							    const GooCanvasBounds *bounds);
static gboolean goo_canvas_item_simple_default_is_item_at  (GooCanvasItemSimple   *simple,
							    double                 x,
							    double                 y,
							    cairo_t               *cr,
							    gboolean               is_pointer_event);


G_DEFINE_TYPE_WITH_CODE (GooCanvasItemSimple, goo_canvas_item_simple,
			 G_TYPE_OBJECT,
			 G_IMPLEMENT_INTERFACE (GOO_TYPE_CANVAS_ITEM,
						canvas_item_interface_init))


static void
goo_canvas_item_simple_install_common_properties (GObjectClass *gobject_class)
{
  /* Basic drawing properties. */
  g_object_class_install_property (gobject_class, PROP_STROKE_PATTERN,
                                   g_param_spec_boxed ("stroke-pattern",
						       _("Stroke Pattern"),
						       _("The pattern to use to paint the perimeter of the item, or NULL disable painting"),
						       GOO_TYPE_CAIRO_PATTERN,
						       G_PARAM_READWRITE));

  g_object_class_install_property (gobject_class, PROP_FILL_PATTERN,
                                   g_param_spec_boxed ("fill-pattern",
						       _("Fill Pattern"),
						       _("The pattern to use to paint the interior of the item, or NULL to disable painting"),
						       GOO_TYPE_CAIRO_PATTERN,
						       G_PARAM_READWRITE));

  g_object_class_install_property (gobject_class, PROP_FILL_RULE,
				   g_param_spec_enum ("fill-rule",
						      _("Fill Rule"),
						      _("The fill rule used to determine which parts of the item are filled"),
						      GOO_TYPE_CAIRO_FILL_RULE,
						      CAIRO_FILL_RULE_WINDING,
						      G_PARAM_READWRITE));

  g_object_class_install_property (gobject_class, PROP_OPERATOR,
				   g_param_spec_enum ("operator",
						      _("Operator"),
						      _("The compositing operator to use"),
						      GOO_TYPE_CAIRO_OPERATOR,
						      CAIRO_OPERATOR_OVER,
						      G_PARAM_READWRITE));

  g_object_class_install_property (gobject_class, PROP_ANTIALIAS,
				   g_param_spec_enum ("antialias",
						      _("Antialias"),
						      _("The antialiasing mode to use"),
						      GOO_TYPE_CAIRO_ANTIALIAS,
						      CAIRO_ANTIALIAS_GRAY,
						      G_PARAM_READWRITE));

  /* Line style & width properties. */
  g_object_class_install_property (gobject_class, PROP_LINE_WIDTH,
				   g_param_spec_double ("line-width",
							_("Line Width"),
							_("The line width to use for the item's perimeter"),
							0.0, G_MAXDOUBLE, 2.0,
							G_PARAM_READWRITE));

  g_object_class_install_property (gobject_class, PROP_LINE_CAP,
				   g_param_spec_enum ("line-cap",
						      _("Line Cap"),
						      _("The line cap style to use"),
						      GOO_TYPE_CAIRO_LINE_CAP,
						      CAIRO_LINE_CAP_BUTT,
						      G_PARAM_READWRITE));

  g_object_class_install_property (gobject_class, PROP_LINE_JOIN,
				   g_param_spec_enum ("line-join",
						      _("Line Join"),
						      _("The line join style to use"),
						      GOO_TYPE_CAIRO_LINE_JOIN,
						      CAIRO_LINE_JOIN_MITER,
						      G_PARAM_READWRITE));

  g_object_class_install_property (gobject_class, PROP_LINE_JOIN_MITER_LIMIT,
				   g_param_spec_double ("line-join-miter-limit",
							_("Miter Limit"),
							_("The smallest angle to use with miter joins, in degrees. Bevel joins will be used below this limit"),
							0.0, G_MAXDOUBLE, 10.0,
							G_PARAM_READWRITE));

  g_object_class_install_property (gobject_class, PROP_LINE_DASH,
				   g_param_spec_boxed ("line-dash",
						       _("Line Dash"),
						       _("The dash pattern to use"),
						       GOO_TYPE_CANVAS_LINE_DASH,
						       G_PARAM_READWRITE));

  /* Font properties. */
  g_object_class_install_property (gobject_class, PROP_FONT,
				   g_param_spec_string ("font",
							_("Font"),
							_("The base font to use for the text"),
							NULL,
							G_PARAM_READWRITE));

  g_object_class_install_property (gobject_class, PROP_FONT_DESC,
				   g_param_spec_boxed ("font-desc",
						       _("Font Description"),
						       _("The attributes specifying which font to use"),
						       PANGO_TYPE_FONT_DESCRIPTION,
						       G_PARAM_READWRITE));

  g_object_class_install_property (gobject_class, PROP_HINT_METRICS,
				   g_param_spec_enum ("hint-metrics",
						      _("Hint Metrics"),
						      _("The hinting to be used for font metrics"),
						      GOO_TYPE_CAIRO_HINT_METRICS,
						      CAIRO_HINT_METRICS_OFF,
						      G_PARAM_READWRITE));

  /* Convenience properties - writable only. */
  g_object_class_install_property (gobject_class, PROP_STROKE_COLOR,
				   g_param_spec_string ("stroke-color",
							_("Stroke Color"),
							_("The color to use for the item's perimeter. To disable painting set the 'stroke-pattern' property to NULL"),
							NULL,
							G_PARAM_WRITABLE));

  g_object_class_install_property (gobject_class, PROP_STROKE_COLOR_RGBA,
				   g_param_spec_uint ("stroke-color-rgba",
						      _("Stroke Color RGBA"),
						      _("The color to use for the item's perimeter, specified as a 32-bit integer value. To disable painting set the 'stroke-pattern' property to NULL"),
						      0, G_MAXUINT, 0,
						      G_PARAM_READWRITE));

  g_object_class_install_property (gobject_class, PROP_STROKE_PIXBUF,
                                   g_param_spec_object ("stroke-pixbuf",
							_("Stroke Pixbuf"),
							_("The pixbuf to use to draw the item's perimeter. To disable painting set the 'stroke-pattern' property to NULL"),
                                                        GDK_TYPE_PIXBUF,
                                                        G_PARAM_WRITABLE));

  g_object_class_install_property (gobject_class, PROP_FILL_COLOR,
				   g_param_spec_string ("fill-color",
							_("Fill Color"),
							_("The color to use to paint the interior of the item. To disable painting set the 'fill-pattern' property to NULL"),
							NULL,
							G_PARAM_WRITABLE));

  g_object_class_install_property (gobject_class, PROP_FILL_COLOR_RGBA,
				   g_param_spec_uint ("fill-color-rgba",
						      _("Fill Color RGBA"),
						      _("The color to use to paint the interior of the item, specified as a 32-bit integer value. To disable painting set the 'fill-pattern' property to NULL"),
						      0, G_MAXUINT, 0,
						      G_PARAM_READWRITE));

  g_object_class_install_property (gobject_class, PROP_FILL_PIXBUF,
                                   g_param_spec_object ("fill-pixbuf",
							_("Fill Pixbuf"),
							_("The pixbuf to use to paint the interior of the item. To disable painting set the 'fill-pattern' property to NULL"),
                                                        GDK_TYPE_PIXBUF,
                                                        G_PARAM_WRITABLE));

  /* Other properties. */
  g_object_class_override_property (gobject_class, PROP_PARENT,
				    "parent");

  g_object_class_override_property (gobject_class, PROP_VISIBILITY,
				    "visibility");

  g_object_class_override_property (gobject_class, PROP_VISIBILITY_THRESHOLD,
				    "visibility-threshold");

  g_object_class_override_property (gobject_class, PROP_TRANSFORM,
				    "transform");

  g_object_class_override_property (gobject_class, PROP_POINTER_EVENTS,
				    "pointer-events");

  g_object_class_override_property (gobject_class, PROP_TITLE,
				    "title");

  g_object_class_override_property (gobject_class, PROP_DESCRIPTION,
				    "description");

  g_object_class_override_property (gobject_class, PROP_CAN_FOCUS,
				    "can-focus");

  g_object_class_override_property (gobject_class, PROP_TOOLTIP,
				    "tooltip");

  /**
   * GooCanvasItemSimple:clip-path
   *
   * The sequence of commands describing the clip path of the item, specified
   * as a string using the same syntax
   * as in the <ulink url="http://www.w3.org/Graphics/SVG/">Scalable Vector
   * Graphics (SVG)</ulink> path element.
   */
  /**
   * GooCanvasItemModelSimple:clip-path
   *
   * The sequence of commands describing the clip path of the item, specified
   * as a string using the same syntax
   * as in the <ulink url="http://www.w3.org/Graphics/SVG/">Scalable Vector
   * Graphics (SVG)</ulink> path element.
   */
  g_object_class_install_property (gobject_class, PROP_CLIP_PATH,
				   g_param_spec_string ("clip-path",
							_("Clip Path"),
							_("The sequence of path commands specifying the clip path"),
							NULL,
							G_PARAM_WRITABLE));

  g_object_class_install_property (gobject_class, PROP_CLIP_FILL_RULE,
				   g_param_spec_enum ("clip-fill-rule",
						      _("Clip Fill Rule"),
						      _("The fill rule used to determine which parts of the item are clipped"),
						      GOO_TYPE_CAIRO_FILL_RULE,
						      CAIRO_FILL_RULE_WINDING,
						      G_PARAM_READWRITE));

}


static void
goo_canvas_item_simple_class_init (GooCanvasItemSimpleClass *klass)
{
  GObjectClass *gobject_class = (GObjectClass*) klass;

  gobject_class->dispose  = goo_canvas_item_simple_dispose;
  gobject_class->finalize = goo_canvas_item_simple_finalize;

  gobject_class->get_property = goo_canvas_item_simple_get_property;
  gobject_class->set_property = goo_canvas_item_simple_set_property;

  /* Register our accessible factory, but only if accessibility is enabled. */
  if (!ATK_IS_NO_OP_OBJECT_FACTORY (atk_registry_get_factory (atk_get_default_registry (), GTK_TYPE_WIDGET)))
    {
      accessibility_enabled = TRUE;
      atk_registry_set_factory_type (atk_get_default_registry (),
				     GOO_TYPE_CANVAS_ITEM_SIMPLE,
				     goo_canvas_item_accessible_factory_get_type ());
    }

  goo_canvas_item_simple_install_common_properties (gobject_class);

  klass->simple_create_path = goo_canvas_item_simple_default_create_path;
  klass->simple_update      = goo_canvas_item_simple_default_update;
  klass->simple_paint       = goo_canvas_item_simple_default_paint;
  klass->simple_is_item_at  = goo_canvas_item_simple_default_is_item_at;
}


static void
goo_canvas_item_simple_init (GooCanvasItemSimple *item)
{
  GooCanvasBounds *bounds = &item->bounds;

  bounds->x1 = bounds->y1 = bounds->x2 = bounds->y2 = 0.0;
  item->simple_data = g_slice_new0 (GooCanvasItemSimpleData);
  item->simple_data->visibility = GOO_CANVAS_ITEM_VISIBLE;
  item->simple_data->pointer_events = GOO_CANVAS_EVENTS_VISIBLE_PAINTED;
  item->simple_data->clip_fill_rule = CAIRO_FILL_RULE_WINDING;
  item->need_update = TRUE;
  item->need_entire_subtree_update = TRUE;
}


static void
goo_canvas_item_simple_reset_model (GooCanvasItemSimple *simple)
{
  if (simple->model)
    {
      g_signal_handlers_disconnect_matched (simple->model, G_SIGNAL_MATCH_DATA,
					    0, 0, NULL, NULL, simple);
      g_object_unref (simple->model);
      simple->model = NULL;
      simple->simple_data = NULL;
    }
}


/* Frees the contents of the GooCanvasItemSimpleData, but not the struct. */
static void
goo_canvas_item_simple_free_data (GooCanvasItemSimpleData *simple_data)
{
  if (simple_data)
    {
      if (simple_data->style)
	{
	  g_object_unref (simple_data->style);
	  simple_data->style = NULL;
	}

      if (simple_data->clip_path_commands)
	{
	  g_array_free (simple_data->clip_path_commands, TRUE);
	  simple_data->clip_path_commands = NULL;
	}

      g_slice_free (cairo_matrix_t, simple_data->transform);
      simple_data->transform = NULL;
    }
}


static void
goo_canvas_item_simple_dispose (GObject *object)
{
  GooCanvasItemSimple *simple = (GooCanvasItemSimple*) object;

  /* Remove the view from the GooCanvas hash table. */
  if (simple->canvas && simple->model)
    goo_canvas_unregister_item (simple->canvas,
				(GooCanvasItemModel*) simple->model);

  goo_canvas_item_simple_reset_model (simple);
  goo_canvas_item_simple_free_data (simple->simple_data);

  G_OBJECT_CLASS (goo_canvas_item_simple_parent_class)->dispose (object);
}


static void
goo_canvas_item_simple_finalize (GObject *object)
{
  GooCanvasItemSimple *simple = (GooCanvasItemSimple*) object;

  g_slice_free (GooCanvasItemSimpleData, simple->simple_data);
  simple->simple_data = NULL;

  G_OBJECT_CLASS (goo_canvas_item_simple_parent_class)->finalize (object);
}


static void
goo_canvas_item_simple_get_common_property (GObject                 *object,
					    GooCanvasItemSimpleData *simple_data,
					    GooCanvas               *canvas,
					    guint                    prop_id,
					    GValue                  *value,
					    GParamSpec              *pspec)
{
  GooCanvasStyle *style = simple_data->style;
  GValue *svalue;
  gdouble line_width = 2.0;
  gchar *font = NULL;

  switch (prop_id)
    {
      /* Basic drawing properties. */
    case PROP_STROKE_PATTERN:
      svalue = goo_canvas_style_get_property (style, goo_canvas_style_stroke_pattern_id);
      g_value_set_boxed (value, svalue ? svalue->data[0].v_pointer : NULL);
      break;
    case PROP_FILL_PATTERN:
      svalue = goo_canvas_style_get_property (style, goo_canvas_style_fill_pattern_id);
      g_value_set_boxed (value, svalue ? svalue->data[0].v_pointer : NULL);
      break;
    case PROP_FILL_RULE:
      svalue = goo_canvas_style_get_property (style, goo_canvas_style_fill_rule_id);
      g_value_set_enum (value, svalue ? svalue->data[0].v_long : CAIRO_FILL_RULE_WINDING);
      break;
    case PROP_OPERATOR:
      svalue = goo_canvas_style_get_property (style, goo_canvas_style_operator_id);
      g_value_set_enum (value, svalue ? svalue->data[0].v_long : CAIRO_OPERATOR_OVER);
      break;
    case PROP_ANTIALIAS:
      svalue = goo_canvas_style_get_property (style, goo_canvas_style_antialias_id);
      g_value_set_enum (value, svalue ? svalue->data[0].v_long : CAIRO_ANTIALIAS_GRAY);
      break;

      /* Line style & width properties. */
    case PROP_LINE_WIDTH:
      svalue = goo_canvas_style_get_property (style, goo_canvas_style_line_width_id);
      if (svalue)
	line_width = svalue->data[0].v_double;
      else if (canvas)
	line_width = goo_canvas_get_default_line_width (canvas);
      g_value_set_double (value, line_width);
      break;
    case PROP_LINE_CAP:
      svalue = goo_canvas_style_get_property (style, goo_canvas_style_line_cap_id);
      g_value_set_enum (value, svalue ? svalue->data[0].v_long : CAIRO_LINE_CAP_BUTT);
      break;
    case PROP_LINE_JOIN:
      svalue = goo_canvas_style_get_property (style, goo_canvas_style_line_join_id);
      g_value_set_enum (value, svalue ? svalue->data[0].v_long : CAIRO_LINE_JOIN_MITER);
      break;
    case PROP_LINE_JOIN_MITER_LIMIT:
      svalue = goo_canvas_style_get_property (style, goo_canvas_style_line_join_miter_limit_id);
      g_value_set_double (value, svalue ? svalue->data[0].v_double : 10.0);
      break;
    case PROP_LINE_DASH:
      svalue = goo_canvas_style_get_property (style, goo_canvas_style_line_dash_id);
      g_value_set_boxed (value, svalue ? svalue->data[0].v_pointer : NULL);
      break;

      /* Font properties. */
    case PROP_FONT:
      svalue = goo_canvas_style_get_property (style, goo_canvas_style_font_desc_id);
      if (svalue)
	font = pango_font_description_to_string (svalue->data[0].v_pointer);
      g_value_set_string (value, font);
      g_free (font);
      break;
    case PROP_FONT_DESC:
      svalue = goo_canvas_style_get_property (style, goo_canvas_style_font_desc_id);
      g_value_set_boxed (value, svalue ? svalue->data[0].v_pointer : NULL);
      break;
    case PROP_HINT_METRICS:
      svalue = goo_canvas_style_get_property (style, goo_canvas_style_hint_metrics_id);
      g_value_set_enum (value, svalue ? svalue->data[0].v_long : CAIRO_HINT_METRICS_OFF);
      break;

      /* Convenience properties. */
    case PROP_STROKE_COLOR_RGBA:
      svalue = goo_canvas_style_get_property (style, goo_canvas_style_stroke_pattern_id);
      if (svalue)
	goo_canvas_get_rgba_value_from_pattern (svalue->data[0].v_pointer,
						value);
      break;
    case PROP_FILL_COLOR_RGBA:
      svalue = goo_canvas_style_get_property (style, goo_canvas_style_fill_pattern_id);
      if (svalue)
	goo_canvas_get_rgba_value_from_pattern (svalue->data[0].v_pointer,
						value);
      break;

      /* Other properties. */
    case PROP_TRANSFORM:
      g_value_set_boxed (value, simple_data->transform);
      break;
    case PROP_VISIBILITY:
      g_value_set_enum (value, simple_data->visibility);
      break;
    case PROP_VISIBILITY_THRESHOLD:
      g_value_set_double (value, simple_data->visibility_threshold);
      break;
    case PROP_POINTER_EVENTS:
      g_value_set_flags (value, simple_data->pointer_events);
      break;
    case PROP_CAN_FOCUS:
      g_value_set_boolean (value, simple_data->can_focus);
      break;
    case PROP_CLIP_FILL_RULE:
      g_value_set_enum (value, simple_data->clip_fill_rule);
      break;
    case PROP_TOOLTIP:
      g_value_set_string (value, simple_data->tooltip);
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
    }
}


static void
goo_canvas_item_simple_get_property (GObject              *object,
				     guint                 prop_id,
				     GValue               *value,
				     GParamSpec           *pspec)
{
  GooCanvasItemSimple *simple = (GooCanvasItemSimple*) object;
  GooCanvasItemSimpleData *simple_data = simple->simple_data;
  AtkObject *accessible;

  switch (prop_id)
    {
    case PROP_PARENT:
      g_value_set_object (value, simple->parent);
      break;
    case PROP_TITLE:
      accessible = atk_gobject_accessible_for_object (object);
      g_value_set_string (value, atk_object_get_name (accessible));
      break;
    case PROP_DESCRIPTION:
      accessible = atk_gobject_accessible_for_object (object);
      g_value_set_string (value, atk_object_get_description (accessible));
      break;
    default:
      goo_canvas_item_simple_get_common_property (object, simple_data,
						  simple->canvas, prop_id,
						  value, pspec);
      break;
    }
}


static gboolean
goo_canvas_item_simple_set_common_property (GObject                 *object,
					    GooCanvasItemSimpleData *simple_data,
					    guint                    prop_id,
					    const GValue            *value,
					    GParamSpec              *pspec)
{
  GooCanvasStyle *style;
  cairo_pattern_t *pattern;
  gboolean recompute_bounds = FALSE;
  cairo_matrix_t *transform;
  GValue tmpval = { 0 };
  const char *font_name;
  PangoFontDescription *font_desc = NULL;

  /* See if we need to create our own style. */
  if (prop_id < PROP_TRANSFORM)
    {
      if (!simple_data->style)
	{
	  simple_data->style = goo_canvas_style_new ();
	}
      else if (!simple_data->own_style)
	{
	  g_object_unref (simple_data->style);
	  simple_data->style = goo_canvas_style_new ();
	}
      simple_data->own_style = TRUE;
    }

  style = simple_data->style;

  switch (prop_id)
    {
      /* Basic drawing properties. */
    case PROP_STROKE_PATTERN:
      goo_canvas_style_set_property (style, goo_canvas_style_stroke_pattern_id, value);
      break;
    case PROP_FILL_PATTERN:
      goo_canvas_style_set_property (style, goo_canvas_style_fill_pattern_id, value);
      break;
    case PROP_FILL_RULE:
      goo_canvas_style_set_property (style, goo_canvas_style_fill_rule_id, value);
      break;
    case PROP_OPERATOR:
      goo_canvas_style_set_property (style, goo_canvas_style_operator_id, value);
      break;
    case PROP_ANTIALIAS:
      goo_canvas_style_set_property (style, goo_canvas_style_antialias_id, value);
      break;

      /* Line style & width properties. */
    case PROP_LINE_WIDTH:
      goo_canvas_style_set_property (style, goo_canvas_style_line_width_id, value);
      recompute_bounds = TRUE;
      break;
    case PROP_LINE_CAP:
      goo_canvas_style_set_property (style, goo_canvas_style_line_cap_id, value);
      recompute_bounds = TRUE;
      break;
    case PROP_LINE_JOIN:
      goo_canvas_style_set_property (style, goo_canvas_style_line_join_id, value);
      recompute_bounds = TRUE;
      break;
    case PROP_LINE_JOIN_MITER_LIMIT:
      goo_canvas_style_set_property (style, goo_canvas_style_line_join_miter_limit_id,
				     value);
      recompute_bounds = TRUE;
      break;
    case PROP_LINE_DASH:
      goo_canvas_style_set_property (style, goo_canvas_style_line_dash_id, value);
      recompute_bounds = TRUE;
      break;

      /* Font properties. */
    case PROP_FONT:
      font_name = g_value_get_string (value);
      if (font_name)
	font_desc = pango_font_description_from_string (font_name);
      g_value_init (&tmpval, PANGO_TYPE_FONT_DESCRIPTION);
      g_value_take_boxed (&tmpval, font_desc);
      goo_canvas_style_set_property (style, goo_canvas_style_font_desc_id, &tmpval);
      g_value_unset (&tmpval);
      recompute_bounds = TRUE;
      break;
    case PROP_FONT_DESC:
      goo_canvas_style_set_property (style, goo_canvas_style_font_desc_id, value);
      recompute_bounds = TRUE;
      break;
    case PROP_HINT_METRICS:
      goo_canvas_style_set_property (style, goo_canvas_style_hint_metrics_id, value);
      recompute_bounds = TRUE;
      break;

      /* Convenience properties. */
    case PROP_STROKE_COLOR:
      pattern = goo_canvas_create_pattern_from_color_value (value);
      goo_canvas_set_style_property_from_pattern (style, goo_canvas_style_stroke_pattern_id, pattern);
      break;
    case PROP_STROKE_COLOR_RGBA:
      pattern = goo_canvas_create_pattern_from_rgba_value (value);
      goo_canvas_set_style_property_from_pattern (style, goo_canvas_style_stroke_pattern_id, pattern);
      break;
    case PROP_STROKE_PIXBUF:
      pattern = goo_canvas_create_pattern_from_pixbuf_value (value);
      goo_canvas_set_style_property_from_pattern (style, goo_canvas_style_stroke_pattern_id, pattern);
      break;

    case PROP_FILL_COLOR:
      pattern = goo_canvas_create_pattern_from_color_value (value);
      goo_canvas_set_style_property_from_pattern (style, goo_canvas_style_fill_pattern_id, pattern);
      break;
    case PROP_FILL_COLOR_RGBA:
      pattern = goo_canvas_create_pattern_from_rgba_value (value);
      goo_canvas_set_style_property_from_pattern (style, goo_canvas_style_fill_pattern_id, pattern);
      break;
    case PROP_FILL_PIXBUF:
      pattern = goo_canvas_create_pattern_from_pixbuf_value (value);
      goo_canvas_set_style_property_from_pattern (style, goo_canvas_style_fill_pattern_id, pattern);
      break;

      /* Other properties. */
    case PROP_TRANSFORM:
      g_slice_free (cairo_matrix_t, simple_data->transform);
      transform = g_value_get_boxed (value);
      simple_data->transform = goo_cairo_matrix_copy (transform);
      recompute_bounds = TRUE;
      break;
    case PROP_VISIBILITY:
      simple_data->visibility = g_value_get_enum (value);
      break;
    case PROP_VISIBILITY_THRESHOLD:
      simple_data->visibility_threshold = g_value_get_double (value);
      break;
    case PROP_POINTER_EVENTS:
      simple_data->pointer_events = g_value_get_flags (value);
      break;
    case PROP_CAN_FOCUS:
      simple_data->can_focus = g_value_get_boolean (value);
      break;
    case PROP_CLIP_PATH:
      if (simple_data->clip_path_commands)
	g_array_free (simple_data->clip_path_commands, TRUE);
      simple_data->clip_path_commands = goo_canvas_parse_path_data (g_value_get_string (value));
      recompute_bounds = TRUE;
      break;
    case PROP_CLIP_FILL_RULE:
      simple_data->clip_fill_rule = g_value_get_enum (value);
      recompute_bounds = TRUE;
      break;
    case PROP_TOOLTIP:
      simple_data->tooltip = g_value_dup_string (value);
      break;
    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
      break;
    }

  return recompute_bounds;
}


static void
goo_canvas_item_simple_set_property (GObject              *object,
				     guint                 prop_id,
				     const GValue         *value,
				     GParamSpec           *pspec)
{
  GooCanvasItem *item = (GooCanvasItem*) object;
  GooCanvasItemSimple *simple = (GooCanvasItemSimple*) object;
  GooCanvasItemSimpleData *simple_data = simple->simple_data;
  GooCanvasItem *parent;
  AtkObject *accessible;
  gboolean recompute_bounds;

  if (simple->model)
    {
      g_warning ("Can't set property of a canvas item with a model - set the model property instead");
      return;
    }

  switch (prop_id)
    {
    case PROP_PARENT:
      parent = g_value_get_object (value);
      goo_canvas_item_remove (item);
      goo_canvas_item_add_child (parent, item, -1);
      break;
    case PROP_TITLE:
      accessible = atk_gobject_accessible_for_object (object);
      atk_object_set_name (accessible, g_value_get_string (value));
      break;
    case PROP_DESCRIPTION:
      accessible = atk_gobject_accessible_for_object (object);
      atk_object_set_description (accessible, g_value_get_string (value));
      break;
    default:
      recompute_bounds = goo_canvas_item_simple_set_common_property (object,
								     simple_data,
								     prop_id,
								     value,
								     pspec);
      goo_canvas_item_simple_changed (simple, recompute_bounds);
      break;
    }
}


static GooCanvas*
goo_canvas_item_simple_get_canvas  (GooCanvasItem *item)
{
  GooCanvasItemSimple *simple = (GooCanvasItemSimple*) item;
  return simple->canvas;
}


static void
goo_canvas_item_simple_set_canvas  (GooCanvasItem *item,
				    GooCanvas     *canvas)
{
  GooCanvasItemSimple *simple = (GooCanvasItemSimple*) item;
  simple->canvas = canvas;
}


static GooCanvasItem*
goo_canvas_item_simple_get_parent (GooCanvasItem   *item)
{
  GooCanvasItemSimple *simple = (GooCanvasItemSimple*) item;
  return simple->parent;
}


static void
goo_canvas_item_simple_set_parent (GooCanvasItem  *item,
				   GooCanvasItem  *parent)
{
  GooCanvasItemSimple *simple = (GooCanvasItemSimple*) item;
  GooCanvas *canvas;

  simple->parent = parent;
  canvas = parent ? goo_canvas_item_get_canvas (parent) : NULL;
  goo_canvas_item_set_canvas (item, canvas);
  simple->need_update = TRUE;
  simple->need_entire_subtree_update = TRUE;
}


/**
 * goo_canvas_item_simple_changed:
 * @item: a #GooCanvasItemSimple.
 * @recompute_bounds: if the item's bounds need to be recomputed.
 * 
 * This function is intended to be used by subclasses of #GooCanvasItemSimple.
 *
 * It is used as a callback for the "changed" signal of the item models.
 * It requests an update or redraw of the item as appropriate.
 **/
void
goo_canvas_item_simple_changed    (GooCanvasItemSimple *item,
				   gboolean             recompute_bounds)
{
  GooCanvasItemSimple *simple = (GooCanvasItemSimple*) item;
  GooCanvasItemSimpleData *simple_data = simple->simple_data;

  if (recompute_bounds)
    {
      item->need_entire_subtree_update = TRUE;
      if (!item->need_update)
	{
	  goo_canvas_item_request_update ((GooCanvasItem*) item);

	  /* Do this after requesting an update, since GooCanvasGroup will
	     ignore the update request if we do this first. */
	  item->need_update = TRUE;
	}
    }
  else
    {
      if (item->canvas)
	goo_canvas_request_item_redraw (item->canvas, &item->bounds, simple_data->is_static);
    }
}


static gboolean
goo_canvas_item_simple_get_transform (GooCanvasItem       *item,
				      cairo_matrix_t      *matrix)
{
  GooCanvasItemSimple *simple = (GooCanvasItemSimple*) item;
  GooCanvasItemSimpleData *simple_data = simple->simple_data;

  if (!simple_data->transform)
    return FALSE;

  *matrix = *simple_data->transform;
  return TRUE;
}


static void
goo_canvas_item_simple_set_transform (GooCanvasItem        *item,
				      const cairo_matrix_t *transform)
{
  GooCanvasItemSimple *simple = (GooCanvasItemSimple*) item;
  GooCanvasItemSimpleData *simple_data = simple->simple_data;

  if (transform)
    {
      if (!simple_data->transform)
	simple_data->transform = g_slice_new (cairo_matrix_t);

      *simple_data->transform = *transform;
    }
  else
    {
      g_slice_free (cairo_matrix_t, simple_data->transform);
      simple_data->transform = NULL;
    }

  goo_canvas_item_simple_changed (simple, TRUE);
}


static GooCanvasStyle*
goo_canvas_item_simple_get_style (GooCanvasItem       *item)
{
  GooCanvasItemSimple *simple = (GooCanvasItemSimple*) item;

  return simple->simple_data->style;
}


static void
goo_canvas_item_simple_set_style (GooCanvasItem  *item,
				  GooCanvasStyle *style)
{
  GooCanvasItemSimple *simple = (GooCanvasItemSimple*) item;
  GooCanvasItemSimpleData *simple_data = simple->simple_data;

  if (simple_data->style)
    g_object_unref (simple_data->style);

  if (style)
    {
      simple_data->style = goo_canvas_style_copy (style);
      simple_data->own_style = TRUE;
    }
  else
    {
      simple_data->style = NULL;
      simple_data->own_style = FALSE;
    }

  goo_canvas_item_simple_changed (simple, TRUE);
}


static void
goo_canvas_item_simple_get_bounds  (GooCanvasItem   *item,
				    GooCanvasBounds *bounds)
{
  GooCanvasItemSimple *simple = (GooCanvasItemSimple*) item;

  if (simple->need_update)
    goo_canvas_item_ensure_updated (item);
    
  *bounds = simple->bounds;
}


static GList*
goo_canvas_item_simple_get_items_at (GooCanvasItem  *item,
				     gdouble         x,
				     gdouble         y,
				     cairo_t        *cr,
				     gboolean        is_pointer_event,
				     gboolean        parent_visible,
				     GList          *found_items)
{
  GooCanvasItemSimpleClass *class = GOO_CANVAS_ITEM_SIMPLE_GET_CLASS (item);
  GooCanvasItemSimple *simple = (GooCanvasItemSimple*) item;
  GooCanvasItemSimpleData *simple_data = simple->simple_data;
  double user_x = x, user_y = y;
  cairo_matrix_t matrix;
  gboolean add_item = FALSE;

  if (simple->need_update)
    goo_canvas_item_ensure_updated (item);

  /* Skip the item if the point isn't in the item's bounds. */
  if (simple->bounds.x1 > x || simple->bounds.x2 < x
      || simple->bounds.y1 > y || simple->bounds.y2 < y)
    return found_items;

  /* Check if the item should receive events. */
  if (is_pointer_event)
    {
      if (simple_data->pointer_events == GOO_CANVAS_EVENTS_NONE)
	return found_items;
      if (simple_data->pointer_events & GOO_CANVAS_EVENTS_VISIBLE_MASK
	  && (!parent_visible
	      || simple_data->visibility <= GOO_CANVAS_ITEM_INVISIBLE
	      || (simple_data->visibility == GOO_CANVAS_ITEM_VISIBLE_ABOVE_THRESHOLD
		  && simple->canvas->scale < simple_data->visibility_threshold)))
	return found_items;
    }

  cairo_save (cr);
  if (simple_data->transform)
    cairo_transform (cr, simple_data->transform);

  cairo_device_to_user (cr, &user_x, &user_y);

  /* Remove any current translation, to avoid the 16-bit cairo limit. */
  cairo_get_matrix (cr, &matrix);
  matrix.x0 = matrix.y0 = 0.0;
  cairo_set_matrix (cr, &matrix);

  /* If the item has a clip path, check if the point is inside it. */
  if (simple_data->clip_path_commands)
    {
      goo_canvas_create_path (simple_data->clip_path_commands, cr);
      cairo_set_fill_rule (cr, simple_data->clip_fill_rule);
      if (!cairo_in_fill (cr, user_x, user_y))
	{
	  cairo_restore (cr);
	  return found_items;
	}
    }

  add_item = class->simple_is_item_at (simple, user_x, user_y, cr,
                                       is_pointer_event);

  cairo_restore (cr);

  if (add_item)
    return g_list_prepend (found_items, item);
  else
    return found_items;
}


static gboolean
goo_canvas_item_simple_default_is_item_at (GooCanvasItemSimple *simple,
					   double               x,
					   double               y,
					   cairo_t             *cr,
					   gboolean             is_pointer_event)
{
  GooCanvasItemSimpleClass *class = GOO_CANVAS_ITEM_SIMPLE_GET_CLASS (simple);

  GooCanvasItemSimpleData *simple_data = simple->simple_data;
  GooCanvasPointerEvents pointer_events = GOO_CANVAS_EVENTS_ALL;

  if (is_pointer_event)
    pointer_events = simple_data->pointer_events;

  /* Use the virtual method subclasses define to create the path. */
  class->simple_create_path (simple, cr);

  if (goo_canvas_item_simple_check_in_path (simple, x, y, cr, pointer_events))
    return TRUE;

  return FALSE;
}


static gboolean
goo_canvas_item_simple_is_visible  (GooCanvasItem   *item)
{
  GooCanvasItemSimple *simple = (GooCanvasItemSimple*) item;
  GooCanvasItemSimpleData *simple_data = simple->simple_data;

  if (simple_data->visibility <= GOO_CANVAS_ITEM_INVISIBLE
      || (simple_data->visibility == GOO_CANVAS_ITEM_VISIBLE_ABOVE_THRESHOLD
	  && simple->canvas->scale < simple_data->visibility_threshold))
    return FALSE;

  if (simple->parent)
    return goo_canvas_item_is_visible (simple->parent);

  return TRUE;
}


static gboolean
goo_canvas_item_simple_get_is_static  (GooCanvasItem   *item)
{
  GooCanvasItemSimple *simple = (GooCanvasItemSimple*) item;
  GooCanvasItemSimpleData *simple_data = simple->simple_data;

  return simple_data->is_static;
}


static void
goo_canvas_item_simple_set_is_static  (GooCanvasItem   *item,
				       gboolean         is_static)
{
  GooCanvasItemSimple *simple = (GooCanvasItemSimple*) item;
  GooCanvasItemSimpleData *simple_data = simple->simple_data;

  simple_data->is_static = is_static;
}


/**
 * goo_canvas_item_simple_check_style:
 * @item: a #GooCanvasItemSimple.
 * 
 * This function is intended to be used by subclasses of #GooCanvasItemSimple,
 * typically in their update() or get_requested_area() methods.
 *
 * It ensures that the item's style is setup correctly. If the item has its
 * own #GooCanvasStyle it makes sure the parent is set correctly. If it
 * doesn't have its own style it uses the parent item's style.
 **/
void
goo_canvas_item_simple_check_style (GooCanvasItemSimple *item)
{
  GooCanvasItemSimpleData *simple_data = item->simple_data;
  GooCanvasStyle *parent_style = NULL;

  if (item->parent)
    parent_style = goo_canvas_item_get_style (item->parent);

  if (simple_data->own_style)
    {
      goo_canvas_style_set_parent (simple_data->style, parent_style);
    }
  else if (simple_data->style != parent_style)
    {
      /* The item doesn't have its own style so we use the parent's (though
	 that may also be NULL). */
      if (simple_data->style)
	g_object_unref (simple_data->style);

      simple_data->style = parent_style;

      if (parent_style)
	g_object_ref (parent_style);
    }
}


static void
goo_canvas_item_simple_update_internal  (GooCanvasItemSimple *simple,
					 cairo_t             *cr)
{
  GooCanvasItemSimpleClass *class = GOO_CANVAS_ITEM_SIMPLE_GET_CLASS (simple);
  GooCanvasItemSimpleData *simple_data = simple->simple_data;
  GooCanvasBounds tmp_bounds;
  cairo_matrix_t transform;

  simple->need_update = FALSE;

  goo_canvas_item_simple_check_style (simple);

  cairo_get_matrix (cr, &transform);

  class->simple_update (simple, cr);

  /* Modify the extents by the item's clip path. */
  if (simple_data->clip_path_commands)
    {
      cairo_identity_matrix (cr);
      goo_canvas_create_path (simple_data->clip_path_commands, cr);
      cairo_set_fill_rule (cr, simple_data->clip_fill_rule);
      cairo_fill_extents (cr, &tmp_bounds.x1, &tmp_bounds.y1,
			  &tmp_bounds.x2, &tmp_bounds.y2);
      simple->bounds.x1 = MAX (simple->bounds.x1, tmp_bounds.x1);
      simple->bounds.y1 = MAX (simple->bounds.y1, tmp_bounds.y1);
      simple->bounds.x2 = MIN (simple->bounds.x2, tmp_bounds.x2);
      simple->bounds.y2 = MIN (simple->bounds.y2, tmp_bounds.y2);

      if (simple->bounds.x1 > simple->bounds.x2)
	simple->bounds.x2 = simple->bounds.x1;
      if (simple->bounds.y1 > simple->bounds.y2)
	simple->bounds.y2 = simple->bounds.y1;
    }

  cairo_set_matrix (cr, &transform);
}


static void
goo_canvas_item_simple_default_update (GooCanvasItemSimple   *simple,
				       cairo_t               *cr)
{
  GooCanvasItemSimpleClass *class = GOO_CANVAS_ITEM_SIMPLE_GET_CLASS (simple);

  /* Use the identity matrix to get the bounds completely in user space. */
  cairo_identity_matrix (cr);

  class->simple_create_path (simple, cr);
  goo_canvas_item_simple_get_path_bounds (simple, cr, &simple->bounds);
}


static void
goo_canvas_item_simple_update  (GooCanvasItem   *item,
				gboolean         entire_tree,
				cairo_t         *cr,
				GooCanvasBounds *bounds)
{
  GooCanvasItemSimple *simple = (GooCanvasItemSimple*) item;
  GooCanvasItemSimpleData *simple_data = simple->simple_data;
  cairo_matrix_t matrix;
  double x_offset, y_offset;

  if (entire_tree || simple->need_update)
    {
      /* Request a redraw of the existing bounds. */
      goo_canvas_request_item_redraw (simple->canvas, &simple->bounds, simple_data->is_static);

      cairo_save (cr);
      if (simple_data->transform)
	cairo_transform (cr, simple_data->transform);

      /* Remove any current translation, to avoid the 16-bit cairo limit. */
      cairo_get_matrix (cr, &matrix);
      x_offset = matrix.x0;
      y_offset = matrix.y0;
      matrix.x0 = matrix.y0 = 0.0;
      cairo_set_matrix (cr, &matrix);

      goo_canvas_item_simple_update_internal (simple, cr);

      goo_canvas_item_simple_user_bounds_to_device (simple, cr,
						    &simple->bounds);

      /* Add the translation back to the bounds. */
      simple->bounds.x1 += x_offset;
      simple->bounds.y1 += y_offset;
      simple->bounds.x2 += x_offset;
      simple->bounds.y2 += y_offset;

      cairo_restore (cr);

      /* Request a redraw of the new bounds. */
      goo_canvas_request_item_redraw (simple->canvas, &simple->bounds, simple_data->is_static);
    }

  *bounds = simple->bounds;
}


static gboolean
goo_canvas_item_simple_get_requested_area (GooCanvasItem    *item,
					   cairo_t          *cr,
					   GooCanvasBounds  *requested_area)
{
  GooCanvasItemSimple *simple = (GooCanvasItemSimple*) item;
  GooCanvasItemSimpleData *simple_data = simple->simple_data;
  cairo_matrix_t matrix;
  double x_offset, y_offset;

  /* Request a redraw of the existing bounds. */
  goo_canvas_request_item_redraw (simple->canvas, &simple->bounds, simple_data->is_static);

  cairo_save (cr);
  if (simple_data->transform)
    cairo_transform (cr, simple_data->transform);

  /* Remove any current translation, to avoid the 16-bit cairo limit. */
  cairo_get_matrix (cr, &matrix);
  x_offset = matrix.x0;
  y_offset = matrix.y0;
  matrix.x0 = matrix.y0 = 0.0;
  cairo_set_matrix (cr, &matrix);

  goo_canvas_item_simple_update_internal (simple, cr);

  if (simple->simple_data->visibility == GOO_CANVAS_ITEM_HIDDEN)
    {
      simple->bounds.x1 = simple->bounds.x2 = 0.0;
      simple->bounds.y1 = simple->bounds.y2 = 0.0;
      cairo_restore (cr);
      return FALSE;
    }

  /* FIXME: Maybe optimize by just converting the offsets to user space
     and adding them? */

  /* Convert to device space. */
  cairo_user_to_device (cr, &simple->bounds.x1, &simple->bounds.y1);
  cairo_user_to_device (cr, &simple->bounds.x2, &simple->bounds.y2);

  /* Add the translation back to the bounds. */
  simple->bounds.x1 += x_offset;
  simple->bounds.y1 += y_offset;
  simple->bounds.x2 += x_offset;
  simple->bounds.y2 += y_offset;

  /* Restore the item's proper transformation matrix. */
  matrix.x0 = x_offset;
  matrix.y0 = y_offset;
  cairo_set_matrix (cr, &matrix);

  /* Convert back to user space. */
  cairo_device_to_user (cr, &simple->bounds.x1, &simple->bounds.y1);
  cairo_device_to_user (cr, &simple->bounds.x2, &simple->bounds.y2);


  /* Copy the user bounds to the requested area. */
  *requested_area = simple->bounds;

  /* Convert to the parent's coordinate space. */
  goo_canvas_item_simple_user_bounds_to_parent (simple, cr, requested_area);

  /* Convert the item's bounds to device space. */
  goo_canvas_item_simple_user_bounds_to_device (simple, cr, &simple->bounds);

  cairo_restore (cr);

  return TRUE;
}


static void
goo_canvas_item_simple_allocate_area      (GooCanvasItem         *item,
					   cairo_t               *cr,
					   const GooCanvasBounds *requested_area,
					   const GooCanvasBounds *allocated_area,
					   gdouble                x_offset,
					   gdouble                y_offset)
{
  GooCanvasItemSimple *simple = (GooCanvasItemSimple*) item;
  GooCanvasItemSimpleData *simple_data = simple->simple_data;

  /* Simple items can't resize at all, so we just adjust the bounds x & y
     positions here, and let the item be clipped if necessary. */
  simple->bounds.x1 += x_offset;
  simple->bounds.y1 += y_offset;
  simple->bounds.x2 += x_offset;
  simple->bounds.y2 += y_offset;

  /* Request a redraw of the new bounds. */
  goo_canvas_request_item_redraw (simple->canvas, &simple->bounds, simple_data->is_static);
}


static void
goo_canvas_item_simple_paint (GooCanvasItem         *item,
			      cairo_t               *cr,
			      const GooCanvasBounds *bounds,
			      gdouble                scale)
{
  GooCanvasItemSimpleClass *class = GOO_CANVAS_ITEM_SIMPLE_GET_CLASS (item);
  GooCanvasItemSimple *simple = (GooCanvasItemSimple*) item;
  GooCanvasItemSimpleData *simple_data = simple->simple_data;

  /* Skip the item if the bounds don't intersect the expose rectangle. */
  if (simple->bounds.x1 > bounds->x2 || simple->bounds.x2 < bounds->x1
      || simple->bounds.y1 > bounds->y2 || simple->bounds.y2 < bounds->y1)
    return;

  /* Check if the item should be visible. */
  if (simple_data->visibility <= GOO_CANVAS_ITEM_INVISIBLE
      || (simple_data->visibility == GOO_CANVAS_ITEM_VISIBLE_ABOVE_THRESHOLD
	  && scale < simple_data->visibility_threshold))
    return;

  cairo_save (cr);
  if (simple_data->transform)
    cairo_transform (cr, simple_data->transform);

  /* Clip with the item's clip path, if it is set. */
  if (simple_data->clip_path_commands)
    {
      goo_canvas_create_path (simple_data->clip_path_commands, cr);
      cairo_set_fill_rule (cr, simple_data->clip_fill_rule);
      cairo_clip (cr);
    }

  class->simple_paint (simple, cr, bounds);

  cairo_restore (cr);
}


static void
goo_canvas_item_simple_default_paint (GooCanvasItemSimple   *simple,
				      cairo_t               *cr,
				      const GooCanvasBounds *bounds)
{
  GooCanvasItemSimpleClass *class = GOO_CANVAS_ITEM_SIMPLE_GET_CLASS (simple);

  class->simple_create_path (simple, cr);
  goo_canvas_item_simple_paint_path (simple, cr);
}


static void
goo_canvas_item_simple_default_create_path (GooCanvasItemSimple   *simple,
					    cairo_t               *cr)
{
  /* Do nothing. */
}


static void
goo_canvas_item_simple_title_changed (GooCanvasItemModelSimple *smodel,
				      GParamSpec               *pspec,
				      GooCanvasItemSimple      *item)
{
  AtkObject *accessible;

  accessible = atk_gobject_accessible_for_object (G_OBJECT (item));
  atk_object_set_name (accessible, smodel->title);
}


static void
goo_canvas_item_simple_description_changed (GooCanvasItemModelSimple *smodel,
					    GParamSpec               *pspec,
					    GooCanvasItemSimple      *item)
{
  AtkObject *accessible;

  accessible = atk_gobject_accessible_for_object (G_OBJECT (item));
  atk_object_set_description (accessible, smodel->description);
}


static void
goo_canvas_item_simple_setup_accessibility (GooCanvasItemSimple      *item)
{
  GooCanvasItemModelSimple *smodel = item->model;
  AtkObject *accessible;

  accessible = atk_gobject_accessible_for_object (G_OBJECT (item));
  if (!ATK_IS_NO_OP_OBJECT (accessible))
    {
      if (smodel->title)
	atk_object_set_name (accessible, smodel->title);
      if (smodel->description)
	atk_object_set_description (accessible, smodel->description);

      g_signal_connect (smodel, "notify::title",
			G_CALLBACK (goo_canvas_item_simple_title_changed),
			item);
      g_signal_connect (smodel, "notify::description",
			G_CALLBACK (goo_canvas_item_simple_description_changed),
			item);
    }
}


static void
goo_canvas_item_model_simple_changed (GooCanvasItemModelSimple *smodel,
				      gboolean                  recompute_bounds,
				      GooCanvasItemSimple      *simple)
{
  goo_canvas_item_simple_changed (simple, recompute_bounds);
}


static GooCanvasItemModel*
goo_canvas_item_simple_get_model    (GooCanvasItem      *item)
{
  GooCanvasItemSimple *simple = (GooCanvasItemSimple*) item;
  return (GooCanvasItemModel*) simple->model;
}


/**
 * goo_canvas_item_simple_set_model:
 * @item: a #GooCanvasItemSimple.
 * @model: the model that @item will view.
 * 
 * This function should be called by subclasses of #GooCanvasItemSimple
 * in their set_model() method.
 **/
void
goo_canvas_item_simple_set_model (GooCanvasItemSimple  *item,
				  GooCanvasItemModel   *model)
{
  g_return_if_fail (model != NULL);

  goo_canvas_item_simple_reset_model (item);
  goo_canvas_item_simple_free_data (item->simple_data);
  g_slice_free (GooCanvasItemSimpleData, item->simple_data);

  item->model = g_object_ref (model);
  item->simple_data = &item->model->simple_data;

  if (accessibility_enabled)
    goo_canvas_item_simple_setup_accessibility (item);

  g_signal_connect (model, "changed",
		    G_CALLBACK (goo_canvas_item_model_simple_changed),
		    item);
}


static void
goo_canvas_item_simple_set_model_internal    (GooCanvasItem      *item,
					      GooCanvasItemModel *model)
{
  goo_canvas_item_simple_set_model ((GooCanvasItemSimple*) item, model);
}


static gboolean
goo_canvas_item_simple_query_tooltip (GooCanvasItem  *item,
				      gdouble         x,
				      gdouble         y,
				      gboolean        keyboard_tip,
				      GtkTooltip     *tooltip)
{
  GooCanvasItemSimple *simple = (GooCanvasItemSimple*) item;
  GooCanvasItemSimpleData *simple_data = simple->simple_data;

  if (simple_data->tooltip)
    {
      gtk_tooltip_set_markup (tooltip, simple_data->tooltip);
      return TRUE;
    }

  return FALSE;
}


static void
canvas_item_interface_init (GooCanvasItemIface *iface)
{
  iface->get_canvas         = goo_canvas_item_simple_get_canvas;
  iface->set_canvas         = goo_canvas_item_simple_set_canvas;

  iface->get_parent	    = goo_canvas_item_simple_get_parent;
  iface->set_parent	    = goo_canvas_item_simple_set_parent;
  iface->get_bounds         = goo_canvas_item_simple_get_bounds;
  iface->get_items_at	    = goo_canvas_item_simple_get_items_at;
  iface->update             = goo_canvas_item_simple_update;
  iface->get_requested_area = goo_canvas_item_simple_get_requested_area;
  iface->allocate_area      = goo_canvas_item_simple_allocate_area;
  iface->paint              = goo_canvas_item_simple_paint;

  iface->get_transform      = goo_canvas_item_simple_get_transform;
  iface->set_transform      = goo_canvas_item_simple_set_transform;
  iface->get_style          = goo_canvas_item_simple_get_style;
  iface->set_style          = goo_canvas_item_simple_set_style;
  iface->is_visible         = goo_canvas_item_simple_is_visible;
  iface->get_is_static	    = goo_canvas_item_simple_get_is_static;
  iface->set_is_static	    = goo_canvas_item_simple_set_is_static;

  iface->get_model          = goo_canvas_item_simple_get_model;
  iface->set_model          = goo_canvas_item_simple_set_model_internal;

  iface->query_tooltip	    = goo_canvas_item_simple_query_tooltip;
}


/**
 * goo_canvas_item_simple_paint_path:
 * @item: a #GooCanvasItemSimple.
 * @cr: a cairo context.
 * 
 * This function is intended to be used by subclasses of #GooCanvasItemSimple.
 *
 * It paints the current path, using the item's style settings.
 **/
void
goo_canvas_item_simple_paint_path (GooCanvasItemSimple *item,
				   cairo_t             *cr)
{
  GooCanvasStyle *style = item->simple_data->style;

  if (goo_canvas_style_set_fill_options (style, cr))
    cairo_fill_preserve (cr);

  if (goo_canvas_style_set_stroke_options (style, cr))
    cairo_stroke (cr);

  cairo_new_path (cr);
}


/* Returns the bounds of the path, using the item's stroke and fill options,
   in device coords. Note that the bounds include both the stroke and the
   fill extents, even if they will not be painted. (We need this to handle
   the "pointer-events" property.) */
/**
 * goo_canvas_item_simple_get_path_bounds:
 * @item: a #GooCanvasItemSimple.
 * @cr: a cairo context.
 * @bounds: the #GooCanvasBounds struct to store the resulting bounding box.
 * 
 * This function is intended to be used by subclasses of #GooCanvasItemSimple,
 * typically in their update() or get_requested_area() methods.
 *
 * It calculates the bounds of the current path, using the item's style
 * settings, and stores the results in the given #GooCanvasBounds struct.
 *
 * The returned bounds contains the bounding box of the path in device space,
 * converted to user space coordinates. To calculate the bounds completely in
 * user space, use cairo_identity_matrix() to temporarily reset the current
 * transformation matrix to the identity matrix.
 **/
void
goo_canvas_item_simple_get_path_bounds (GooCanvasItemSimple *item,
					cairo_t             *cr,
					GooCanvasBounds     *bounds)
{
  GooCanvasStyle *style = item->simple_data->style;
  GooCanvasBounds fill_bounds, stroke_bounds;

  /* Calculate the filled extents. */
  goo_canvas_style_set_fill_options (style, cr);
  cairo_fill_extents (cr, &fill_bounds.x1, &fill_bounds.y1,
		      &fill_bounds.x2, &fill_bounds.y2);

  /* Check the stroke. */
  goo_canvas_style_set_stroke_options (style, cr);
  cairo_stroke_extents (cr, &stroke_bounds.x1, &stroke_bounds.y1,
			&stroke_bounds.x2, &stroke_bounds.y2);

  /* Workaround for cairo < 1.4.0. It used to just return odd values
     if the path had empty bounds. This fix will work, but only if there is
     no transform currently set, since cairo will convert to user space. */
  if (cairo_version () < CAIRO_VERSION_ENCODE (1, 4, 0))
    {
      if (fill_bounds.x1 == 32767.0 && fill_bounds.x2 == -32768.0)
	fill_bounds.x1 = fill_bounds.x2 = 0.0;
      if (stroke_bounds.x1 == 32767.0 && stroke_bounds.x2 == -32768.0)
	stroke_bounds.x1 = stroke_bounds.x2 = 0.0;
    }

  if (fill_bounds.x1 == 0.0 && fill_bounds.x2 == 0.0)
    {
      /* The fill bounds are empty so just use the stroke bounds.
	 If the stroke bounds are also empty the bounds will be all 0.0. */
      bounds->x1 = MIN (stroke_bounds.x1, stroke_bounds.x2);
      bounds->x2 = MAX (stroke_bounds.x1, stroke_bounds.x2);
      bounds->y1 = MIN (stroke_bounds.y1, stroke_bounds.y2);
      bounds->y2 = MAX (stroke_bounds.y1, stroke_bounds.y2);
    }
  else if (stroke_bounds.x1 == 0.0 && stroke_bounds.x2 == 0.0)
    {
      /* The stroke bounds are empty so just use the fill bounds. */
      bounds->x1 = MIN (fill_bounds.x1, fill_bounds.x2);
      bounds->x2 = MAX (fill_bounds.x1, fill_bounds.x2);
      bounds->y1 = MIN (fill_bounds.y1, fill_bounds.y2);
      bounds->y2 = MAX (fill_bounds.y1, fill_bounds.y2);
    }
  else
    {
      /* Both fill & stoke bounds are non-empty so combine them. */
      bounds->x1 = MIN (fill_bounds.x1, fill_bounds.x2);
      bounds->x2 = MAX (fill_bounds.x1, fill_bounds.x2);
      bounds->y1 = MIN (fill_bounds.y1, fill_bounds.y2);
      bounds->y2 = MAX (fill_bounds.y1, fill_bounds.y2);

      bounds->x1 = MIN (bounds->x1, stroke_bounds.x1);
      bounds->x1 = MIN (bounds->x1, stroke_bounds.x2);

      bounds->x2 = MAX (bounds->x2, stroke_bounds.x1);
      bounds->x2 = MAX (bounds->x2, stroke_bounds.x2);

      bounds->y1 = MIN (bounds->y1, stroke_bounds.y1);
      bounds->y1 = MIN (bounds->y1, stroke_bounds.y2);

      bounds->y2 = MAX (bounds->y2, stroke_bounds.y1);
      bounds->y2 = MAX (bounds->y2, stroke_bounds.y2);
    }
}


/**
 * goo_canvas_item_simple_user_bounds_to_device:
 * @item: a #GooCanvasItemSimple.
 * @cr: a cairo context.
 * @bounds: the bounds of the item, in the item's coordinate space.
 * 
 * This function is intended to be used by subclasses of #GooCanvasItemSimple,
 * typically in their update() or get_requested_area() methods.
 *
 * It converts the item's bounds to a bounding box in the canvas (device)
 * coordinate space.
 **/
void
goo_canvas_item_simple_user_bounds_to_device (GooCanvasItemSimple *item,
					      cairo_t             *cr,
					      GooCanvasBounds     *bounds)
{
  GooCanvasBounds tmp_bounds = *bounds, tmp_bounds2 = *bounds;

  /* Convert the top-left and bottom-right corners to device coords. */
  cairo_user_to_device (cr, &tmp_bounds.x1, &tmp_bounds.y1);
  cairo_user_to_device (cr, &tmp_bounds.x2, &tmp_bounds.y2);

  /* Now convert the top-right and bottom-left corners. */
  cairo_user_to_device (cr, &tmp_bounds2.x1, &tmp_bounds2.y2);
  cairo_user_to_device (cr, &tmp_bounds2.x2, &tmp_bounds2.y1);

  /* Calculate the minimum x coordinate seen and put in x1. */
  bounds->x1 = MIN (tmp_bounds.x1, tmp_bounds.x2);
  bounds->x1 = MIN (bounds->x1, tmp_bounds2.x1);
  bounds->x1 = MIN (bounds->x1, tmp_bounds2.x2);

  /* Calculate the maximum x coordinate seen and put in x2. */
  bounds->x2 = MAX (tmp_bounds.x1, tmp_bounds.x2);
  bounds->x2 = MAX (bounds->x2, tmp_bounds2.x1);
  bounds->x2 = MAX (bounds->x2, tmp_bounds2.x2);

  /* Calculate the minimum y coordinate seen and put in y1. */
  bounds->y1 = MIN (tmp_bounds.y1, tmp_bounds.y2);
  bounds->y1 = MIN (bounds->y1, tmp_bounds2.y1);
  bounds->y1 = MIN (bounds->y1, tmp_bounds2.y2);

  /* Calculate the maximum y coordinate seen and put in y2. */
  bounds->y2 = MAX (tmp_bounds.y1, tmp_bounds.y2);
  bounds->y2 = MAX (bounds->y2, tmp_bounds2.y1);
  bounds->y2 = MAX (bounds->y2, tmp_bounds2.y2);
}


/**
 * goo_canvas_item_simple_user_bounds_to_parent:
 * @item: a #GooCanvasItemSimple.
 * @cr: a cairo context.
 * @bounds: the bounds of the item, in the item's coordinate space.
 * 
 * This function is intended to be used by subclasses of #GooCanvasItemSimple,
 * typically in their get_requested_area() method.
 *
 * It converts the item's bounds to a bounding box in its parent's coordinate
 * space. If the item has no transformation matrix set then no conversion is
 * needed.
 **/
void
goo_canvas_item_simple_user_bounds_to_parent (GooCanvasItemSimple *item,
					      cairo_t             *cr,
					      GooCanvasBounds     *bounds)
{
  GooCanvasItemSimpleData *simple_data = item->simple_data;
  cairo_matrix_t *transform = simple_data->transform;
  GooCanvasBounds tmp_bounds, tmp_bounds2;

  if (!transform)
    return;

  tmp_bounds = tmp_bounds2 = *bounds;

  /* Convert the top-left and bottom-right corners to parent coords. */
  cairo_matrix_transform_point (transform, &tmp_bounds.x1, &tmp_bounds.y1);
  cairo_matrix_transform_point (transform, &tmp_bounds.x2, &tmp_bounds.y2);

  /* Now convert the top-right and bottom-left corners. */
  cairo_matrix_transform_point (transform, &tmp_bounds2.x1, &tmp_bounds2.y2);
  cairo_matrix_transform_point (transform, &tmp_bounds2.x2, &tmp_bounds2.y1);

  /* Calculate the minimum x coordinate seen and put in x1. */
  bounds->x1 = MIN (tmp_bounds.x1, tmp_bounds.x2);
  bounds->x1 = MIN (bounds->x1, tmp_bounds2.x1);
  bounds->x1 = MIN (bounds->x1, tmp_bounds2.x2);

  /* Calculate the maximum x coordinate seen and put in x2. */
  bounds->x2 = MAX (tmp_bounds.x1, tmp_bounds.x2);
  bounds->x2 = MAX (bounds->x2, tmp_bounds2.x1);
  bounds->x2 = MAX (bounds->x2, tmp_bounds2.x2);

  /* Calculate the minimum y coordinate seen and put in y1. */
  bounds->y1 = MIN (tmp_bounds.y1, tmp_bounds.y2);
  bounds->y1 = MIN (bounds->y1, tmp_bounds2.y1);
  bounds->y1 = MIN (bounds->y1, tmp_bounds2.y2);

  /* Calculate the maximum y coordinate seen and put in y2. */
  bounds->y2 = MAX (tmp_bounds.y1, tmp_bounds.y2);
  bounds->y2 = MAX (bounds->y2, tmp_bounds2.y1);
  bounds->y2 = MAX (bounds->y2, tmp_bounds2.y2);
}


/**
 * goo_canvas_item_simple_check_in_path:
 * @item: a #GooCanvasItemSimple.
 * @x: the x coordinate of the point.
 * @y: the y coordinate of the point.
 * @cr: a cairo context.
 * @pointer_events: specifies which parts of the path to check.
 * 
 * This function is intended to be used by subclasses of #GooCanvasItemSimple.
 *
 * It checks if the given point is in the current path, using the item's
 * style settings.
 * 
 * Returns: %TRUE if the given point is in the current path.
 **/
gboolean
goo_canvas_item_simple_check_in_path (GooCanvasItemSimple   *item,
				      gdouble                x,
				      gdouble                y,
				      cairo_t               *cr,
				      GooCanvasPointerEvents pointer_events)
{
  GooCanvasStyle *style = item->simple_data->style;
  gboolean do_fill, do_stroke;

  /* Check the filled path, if required. */
  if (pointer_events & GOO_CANVAS_EVENTS_FILL_MASK)
    {
      do_fill = goo_canvas_style_set_fill_options (style, cr);
      if (!(pointer_events & GOO_CANVAS_EVENTS_PAINTED_MASK) || do_fill)
	{
	  if (cairo_in_fill (cr, x, y))
	    return TRUE;
	}
    }

  /* Check the stroke, if required. */
  if (pointer_events & GOO_CANVAS_EVENTS_STROKE_MASK)
    {
      do_stroke = goo_canvas_style_set_stroke_options (style, cr);
      if (!(pointer_events & GOO_CANVAS_EVENTS_PAINTED_MASK) || do_stroke)
	{
	  if (cairo_in_stroke (cr, x, y))
	    return TRUE;
	}
    }

  return FALSE;
}


/**
 * goo_canvas_item_simple_get_line_width:
 * @item: a #GooCanvasItemSimple.
 * 
 * Gets the item's line width.
 * 
 * Returns: the item's line width.
 **/
gdouble
goo_canvas_item_simple_get_line_width (GooCanvasItemSimple   *item)
{
  GValue *value;

  value = goo_canvas_style_get_property (item->simple_data->style,
					 goo_canvas_style_line_width_id);
  if (value)
    return value->data[0].v_double;
  else if (item->canvas)
    return goo_canvas_get_default_line_width (item->canvas);
  else
    return 2.0;
}


/**
 * SECTION:goocanvasitemmodelsimple
 * @Title: GooCanvasItemModelSimple
 * @Short_Description: the base class for the standard canvas item models.
 * @Stability_Level: 
 * @See_Also: 
 *
 * #GooCanvasItemModelSimple is used as a base class for the standard canvas
 * item models. It can also be used as the base class for new custom canvas
 * item models.
 *
 * It provides default implementations for many of the #GooCanvasItemModel
 * methods.
 *
 * Subclasses of #GooCanvasItemModelSimple only need to implement the
 * create_item() method of the #GooCanvasItemModel interface, to create
 * the default canvas item to view the item model.
 */


static void item_model_interface_init  (GooCanvasItemModelIface *iface);
static void goo_canvas_item_model_simple_dispose  (GObject *object);
static void goo_canvas_item_model_simple_finalize (GObject *object);
static void goo_canvas_item_model_simple_get_property (GObject              *object,
						       guint                 prop_id,
						       GValue               *value,
						       GParamSpec           *pspec);
static void goo_canvas_item_model_simple_set_property (GObject              *object,
						       guint                 prop_id,
						       const GValue         *value,
						       GParamSpec           *pspec);

G_DEFINE_TYPE_WITH_CODE (GooCanvasItemModelSimple,
			 goo_canvas_item_model_simple, G_TYPE_OBJECT,
			 G_IMPLEMENT_INTERFACE (GOO_TYPE_CANVAS_ITEM_MODEL,
						item_model_interface_init))


static void
goo_canvas_item_model_simple_class_init (GooCanvasItemModelSimpleClass *klass)
{
  GObjectClass *gobject_class = (GObjectClass*) klass;

  gobject_class->dispose  = goo_canvas_item_model_simple_dispose;
  gobject_class->finalize = goo_canvas_item_model_simple_finalize;

  gobject_class->get_property = goo_canvas_item_model_simple_get_property;
  gobject_class->set_property = goo_canvas_item_model_simple_set_property;

  goo_canvas_item_simple_install_common_properties (gobject_class);
}


static void
goo_canvas_item_model_simple_init (GooCanvasItemModelSimple *smodel)
{
  smodel->simple_data.visibility = GOO_CANVAS_ITEM_VISIBLE;
  smodel->simple_data.pointer_events = GOO_CANVAS_EVENTS_VISIBLE_PAINTED;
  smodel->simple_data.clip_fill_rule = CAIRO_FILL_RULE_WINDING;
}


static void
goo_canvas_item_model_simple_dispose (GObject *object)
{
  GooCanvasItemModelSimple *smodel = (GooCanvasItemModelSimple*) object;

  goo_canvas_item_simple_free_data (&smodel->simple_data);

  G_OBJECT_CLASS (goo_canvas_item_model_simple_parent_class)->dispose (object);
}


static void
goo_canvas_item_model_simple_finalize (GObject *object)
{
  /*GooCanvasItemModelSimple *smodel = (GooCanvasItemModelSimple*) object;*/

  G_OBJECT_CLASS (goo_canvas_item_model_simple_parent_class)->finalize (object);
}


static void
goo_canvas_item_model_simple_get_property (GObject              *object,
					   guint                 prop_id,
					   GValue               *value,
					   GParamSpec           *pspec)
{
  GooCanvasItemModelSimple *smodel = (GooCanvasItemModelSimple*) object;
  GooCanvasItemSimpleData *simple_data = &smodel->simple_data;

  switch (prop_id)
    {
    case PROP_PARENT:
      g_value_set_object (value, smodel->parent);
      break;
    case PROP_TITLE:
      g_value_set_string (value, smodel->title);
      break;
    case PROP_DESCRIPTION:
      g_value_set_string (value, smodel->description);
      break;
    default:
      goo_canvas_item_simple_get_common_property (object, simple_data, NULL,
						  prop_id, value, pspec);
      break;
    }
}


extern void _goo_canvas_item_model_emit_changed (GooCanvasItemModel *model,
						 gboolean            recompute_bounds);

static void
goo_canvas_item_model_simple_set_property (GObject              *object,
					   guint                 prop_id,
					   const GValue         *value,
					   GParamSpec           *pspec)
{
  GooCanvasItemModel *model = (GooCanvasItemModel*) object;
  GooCanvasItemModelSimple *smodel = (GooCanvasItemModelSimple*) object;
  GooCanvasItemSimpleData *simple_data = &smodel->simple_data;
  GooCanvasItemModel *parent;
  gboolean recompute_bounds;

  switch (prop_id)
    {
    case PROP_PARENT:
      parent = g_value_get_object (value);
      goo_canvas_item_model_remove (model);
      goo_canvas_item_model_add_child (parent, model, -1);
      break;
    case PROP_TITLE:
      g_free (smodel->title);
      smodel->title = g_value_dup_string (value);
      break;
    case PROP_DESCRIPTION:
      g_free (smodel->description);
      smodel->description = g_value_dup_string (value);
      break;
    default:
      recompute_bounds = goo_canvas_item_simple_set_common_property (object,
								     simple_data,
								     prop_id,
								     value,
								     pspec);
      _goo_canvas_item_model_emit_changed (model, recompute_bounds);
      break;
    }
}


static GooCanvasItemModel*
goo_canvas_item_model_simple_get_parent (GooCanvasItemModel   *model)
{
  GooCanvasItemModelSimple *smodel = (GooCanvasItemModelSimple*) model;
  return smodel->parent;
}


static void
goo_canvas_item_model_simple_set_parent (GooCanvasItemModel   *model,
					 GooCanvasItemModel   *parent)
{
  GooCanvasItemModelSimple *smodel = (GooCanvasItemModelSimple*) model;
  smodel->parent = parent;
}


static gboolean
goo_canvas_item_model_simple_get_transform (GooCanvasItemModel  *model,
					    cairo_matrix_t      *matrix)
{
  GooCanvasItemModelSimple *smodel = (GooCanvasItemModelSimple*) model;
  GooCanvasItemSimpleData *simple_data = &smodel->simple_data;

  if (!simple_data->transform)
    return FALSE;

  *matrix = *simple_data->transform;
  return TRUE;
}


static void
goo_canvas_item_model_simple_set_transform (GooCanvasItemModel   *model,
					    const cairo_matrix_t *transform)
{
  GooCanvasItemModelSimple *smodel = (GooCanvasItemModelSimple*) model;
  GooCanvasItemSimpleData *simple_data = &smodel->simple_data;

  if (transform)
    {
      if (!simple_data->transform)
	simple_data->transform = g_slice_new (cairo_matrix_t);

      *simple_data->transform = *transform;
    }
  else
    {
      g_slice_free (cairo_matrix_t, simple_data->transform);
      simple_data->transform = NULL;
    }

  _goo_canvas_item_model_emit_changed (model, TRUE);
}


static GooCanvasStyle*
goo_canvas_item_model_simple_get_style (GooCanvasItemModel  *model)
{
  GooCanvasItemModelSimple *smodel = (GooCanvasItemModelSimple*) model;

  return smodel->simple_data.style;
}


static void
goo_canvas_item_model_simple_set_style (GooCanvasItemModel *model,
					GooCanvasStyle     *style)
{
  GooCanvasItemModelSimple *smodel = (GooCanvasItemModelSimple*) model;
  GooCanvasItemSimpleData *simple_data = &smodel->simple_data;

  if (simple_data->style)
    g_object_unref (simple_data->style);

  if (style)
    {
      simple_data->style = goo_canvas_style_copy (style);
      simple_data->own_style = TRUE;
    }
  else
    {
      simple_data->style = NULL;
      simple_data->own_style = FALSE;
    }

  _goo_canvas_item_model_emit_changed (model, TRUE);
}


static void
item_model_interface_init  (GooCanvasItemModelIface *iface)
{
  iface->get_parent     = goo_canvas_item_model_simple_get_parent;
  iface->set_parent     = goo_canvas_item_model_simple_set_parent;
  iface->get_transform  = goo_canvas_item_model_simple_get_transform;
  iface->set_transform  = goo_canvas_item_model_simple_set_transform;
  iface->get_style      = goo_canvas_item_model_simple_get_style;
  iface->set_style      = goo_canvas_item_model_simple_set_style;
}