[goocanvas/new-api: 1/7] removed model/view split
- From: Damon Chaplin <damon src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [goocanvas/new-api: 1/7] removed model/view split
- Date: Thu, 24 Jun 2010 14:54:22 +0000 (UTC)
commit 71a05f88d465a6a1719eec330a49f4da775330ed
Author: Damon Chaplin <damon gnome org>
Date: Thu Jun 24 14:30:52 2010 +0100
removed model/view split
demo/Makefile.am | 32 +--
demo/demo-item.c | 2 +-
demo/demo-large-line.c | 2 +-
demo/scalability-demo.c | 2 +-
docs/goocanvas-docs.sgml | 16 -
docs/goocanvas-sections.txt | 274 ----------
docs/goocanvas.types | 11 -
docs/overview.xml | 2 -
src/Makefile.am | 2 -
src/goocanvas.c | 452 ++---------------
src/goocanvas.h | 44 +--
src/goocanvasellipse.c | 476 ++++--------------
src/goocanvasellipse.h | 56 +--
src/goocanvasgrid.c | 964 +++++++++++------------------------
src/goocanvasgrid.h | 96 +---
src/goocanvasgroup.c | 613 ++++-------------------
src/goocanvasgroup.h | 46 +--
src/goocanvasimage.c | 536 ++++----------------
src/goocanvasimage.h | 61 +--
src/goocanvasitem.c | 166 ++-----
src/goocanvasitem.h | 12 -
src/goocanvasitemmodel.c | 1182 -------------------------------------------
src/goocanvasitemmodel.h | 275 ----------
src/goocanvasitemsimple.c | 800 ++++++-----------------------
src/goocanvasitemsimple.h | 144 ++-----
src/goocanvaspath.c | 449 +++-------------
src/goocanvaspath.h | 56 +--
src/goocanvaspolyline.c | 799 ++++++++---------------------
src/goocanvaspolyline.h | 76 +---
src/goocanvasrect.c | 431 +++-------------
src/goocanvasrect.h | 57 +--
src/goocanvastable.c | 841 ++++++++-----------------------
src/goocanvastable.h | 77 +---
src/goocanvastext.c | 639 ++++++------------------
src/goocanvastext.h | 71 +---
src/goocanvasutils.c | 4 -
src/goocanvaswidget.c | 11 +-
37 files changed, 1685 insertions(+), 8092 deletions(-)
---
diff --git a/demo/Makefile.am b/demo/Makefile.am
index 4fe8d49..2dada07 100644
--- a/demo/Makefile.am
+++ b/demo/Makefile.am
@@ -4,14 +4,14 @@ INCLUDES = \
-I$(top_srcdir)/src \
-I$(top_builddir)/src \
@PACKAGE_CFLAGS@
-
+
DEMO_LIBS = $(top_builddir)/src/libgoocanvas-2.0.la @PACKAGE_LIBS@ $(INTLLIBS)
# -DG_DISABLE_DEPRECATED -DPANGO_DISABLE_DEPRECATED \
# -DGDK_DISABLE_DEPRECATED -DGDK_PIXBUF_DISABLE_DEPRECATED \
# -DGTK_DISABLE_DEPRECATED
-noinst_PROGRAMS = demo table-demo generic-position-demo simple-demo scalability-demo units-demo widgets-demo mv-demo mv-table-demo mv-generic-position-demo mv-simple-demo mv-scalability-demo
+noinst_PROGRAMS = demo table-demo generic-position-demo simple-demo scalability-demo units-demo widgets-demo
demo_SOURCES = \
demo.c demo-fifteen.c demo-scalability.c demo-grabs.c \
@@ -22,44 +22,21 @@ demo_SOURCES = \
demo_LDADD = $(DEMO_LIBS)
-mv_demo_SOURCES = \
- mv-demo.c mv-demo-fifteen.c mv-demo-scalability.c mv-demo-grabs.c \
- mv-demo-arrowhead.c mv-demo-features.c mv-demo-events.c \
- mv-demo-paths.c mv-demo-focus.c mv-demo-animation.c \
- mv-demo-clipping.c mv-demo-table.c
-
-mv_demo_LDADD = $(DEMO_LIBS)
-
table_demo_SOURCES = \
table-demo.c
table_demo_LDADD = $(DEMO_LIBS)
-mv_table_demo_SOURCES = \
- mv-table-demo.c
-
-mv_table_demo_LDADD = $(DEMO_LIBS)
-
simple_demo_SOURCES = \
simple-demo.c
simple_demo_LDADD = $(DEMO_LIBS)
-mv_simple_demo_SOURCES = \
- mv-simple-demo.c
-
-mv_simple_demo_LDADD = $(DEMO_LIBS)
-
scalability_demo_SOURCES = \
scalability-demo.c
scalability_demo_LDADD = $(DEMO_LIBS)
-mv_scalability_demo_SOURCES = \
- mv-scalability-demo.c
-
-mv_scalability_demo_LDADD = $(DEMO_LIBS)
-
units_demo_SOURCES = \
units-demo.c
@@ -75,10 +52,5 @@ generic_position_demo_SOURCES = \
generic_position_demo_LDADD = $(DEMO_LIBS)
-mv_generic_position_demo_SOURCES = \
- mv-generic-position-demo.c
-
-mv_generic_position_demo_LDADD = $(DEMO_LIBS)
-
EXTRA_DIST = flower.png toroid.png
diff --git a/demo/demo-item.c b/demo/demo-item.c
index 9f5b049..a057a14 100644
--- a/demo/demo-item.c
+++ b/demo/demo-item.c
@@ -99,7 +99,7 @@ goo_demo_item_paint (GooCanvasItemSimple *simple,
demo_item->y + demo_item->height);
cairo_line_to (cr, demo_item->x + demo_item->width, demo_item->y);
cairo_close_path (cr);
- goo_canvas_style_set_fill_options (simple->simple_data->style, cr);
+ goo_canvas_style_set_fill_options (simple->style, cr);
cairo_fill (cr);
}
diff --git a/demo/demo-large-line.c b/demo/demo-large-line.c
index 2c868da..8f109f5 100644
--- a/demo/demo-large-line.c
+++ b/demo/demo-large-line.c
@@ -210,7 +210,7 @@ goo_demo_large_line_paint (GooCanvasItemSimple *simple,
GooDemoLargeLine *item = (GooDemoLargeLine*) simple;
gdouble line_width;
- goo_canvas_style_set_stroke_options (simple->simple_data->style, cr);
+ goo_canvas_style_set_stroke_options (simple->style, cr);
line_width = goo_canvas_item_simple_get_line_width (simple);
paint_large_line (item, cr, bounds, line_width,
item->x1, item->y1, item->x2, item->y2);
diff --git a/demo/scalability-demo.c b/demo/scalability-demo.c
index 1be0463..bbf4a1f 100644
--- a/demo/scalability-demo.c
+++ b/demo/scalability-demo.c
@@ -3,7 +3,7 @@
#if 1
#define N_GROUP_COLS 25
-#define N_GROUP_ROWS 20
+#define N_GROUP_ROWS 200
#define N_COLS 10
#define N_ROWS 10
#define ITEM_WIDTH 400
diff --git a/docs/goocanvas-docs.sgml b/docs/goocanvas-docs.sgml
index 1e4aaa7..00e2cd8 100644
--- a/docs/goocanvas-docs.sgml
+++ b/docs/goocanvas-docs.sgml
@@ -10,7 +10,6 @@
<title>Introduction</title>
<xi:include href="xml/overview.xml"/>
<xi:include href="xml/simple-canvas.xml"/>
- <xi:include href="xml/model-view-canvas.xml"/>
<xi:include href="xml/architecture.xml"/>
<xi:include href="xml/coordinates.xml"/>
<xi:include href="xml/creating-items.xml"/>
@@ -21,9 +20,7 @@
<title>Core Objects</title>
<xi:include href="xml/goocanvas.xml"/>
<xi:include href="xml/goocanvasitem.xml"/>
- <xi:include href="xml/goocanvasitemmodel.xml"/>
<xi:include href="xml/goocanvasitemsimple.xml"/>
- <xi:include href="xml/goocanvasitemmodelsimple.xml"/>
<xi:include href="xml/goocanvasstyle.xml"/>
</chapter>
@@ -42,19 +39,6 @@
</chapter>
<chapter>
- <title>Standard Canvas Item Models</title>
- <xi:include href="xml/goocanvasgroupmodel.xml"/>
- <xi:include href="xml/goocanvasellipsemodel.xml"/>
- <xi:include href="xml/goocanvasgridmodel.xml"/>
- <xi:include href="xml/goocanvasimagemodel.xml"/>
- <xi:include href="xml/goocanvaspathmodel.xml"/>
- <xi:include href="xml/goocanvaspolylinemodel.xml"/>
- <xi:include href="xml/goocanvasrectmodel.xml"/>
- <xi:include href="xml/goocanvastextmodel.xml"/>
- <xi:include href="xml/goocanvastablemodel.xml"/>
- </chapter>
-
- <chapter>
<title>Miscellaneous</title>
<xi:include href="xml/goocanvasutils.xml"/>
</chapter>
diff --git a/docs/goocanvas-sections.txt b/docs/goocanvas-sections.txt
index 32f506d..e94f4ac 100644
--- a/docs/goocanvas-sections.txt
+++ b/docs/goocanvas-sections.txt
@@ -14,32 +14,12 @@ GOO_IS_CANVAS_TABLE_CLASS
GOO_CANVAS_TABLE_GET_CLASS
<SUBSECTION Private>
-GooCanvasTableData
GooCanvasTableDimension
GooCanvasTableLayoutData
GooCanvasTableClass
</SECTION>
<SECTION>
-<FILE>goocanvastablemodel</FILE>
-<TITLE>GooCanvasTableModel</TITLE>
-GooCanvasTableModel
-goo_canvas_table_model_new
-
-<SUBSECTION Standard>
-GOO_TYPE_CANVAS_TABLE_MODEL
-goo_canvas_table_model_get_type
-GOO_CANVAS_TABLE_MODEL
-GOO_CANVAS_TABLE_MODEL_CLASS
-GOO_IS_CANVAS_TABLE_MODEL
-GOO_IS_CANVAS_TABLE_MODEL_CLASS
-GOO_CANVAS_TABLE_MODEL_GET_CLASS
-
-<SUBSECTION Private>
-GooCanvasTableModelClass
-</SECTION>
-
-<SECTION>
<FILE>goocanvasrect</FILE>
<TITLE>GooCanvasRect</TITLE>
GooCanvasRect
@@ -55,30 +35,10 @@ GOO_IS_CANVAS_RECT_CLASS
GOO_CANVAS_RECT_GET_CLASS
<SUBSECTION Private>
-GooCanvasRectData
GooCanvasRectClass
</SECTION>
<SECTION>
-<FILE>goocanvasrectmodel</FILE>
-<TITLE>GooCanvasRectModel</TITLE>
-GooCanvasRectModel
-goo_canvas_rect_model_new
-
-<SUBSECTION Standard>
-GOO_TYPE_CANVAS_RECT_MODEL
-goo_canvas_rect_model_get_type
-GOO_CANVAS_RECT_MODEL
-GOO_CANVAS_RECT_MODEL_CLASS
-GOO_IS_CANVAS_RECT_MODEL
-GOO_IS_CANVAS_RECT_MODEL_CLASS
-GOO_CANVAS_RECT_MODEL_GET_CLASS
-
-<SUBSECTION Private>
-GooCanvasRectModelClass
-</SECTION>
-
-<SECTION>
<FILE>goocanvasitem</FILE>
GooCanvasItem
GooCanvasItemIface
@@ -118,10 +78,6 @@ goo_canvas_item_get_parent
goo_canvas_item_set_parent
<SUBSECTION>
-goo_canvas_item_get_model
-goo_canvas_item_set_model
-
-<SUBSECTION>
goo_canvas_item_is_container
goo_canvas_item_get_n_children
goo_canvas_item_get_child
@@ -165,69 +121,6 @@ GOO_CANVAS_ITEM_GET_IFACE
</SECTION>
<SECTION>
-<FILE>goocanvasitemmodel</FILE>
-GooCanvasItemModel
-GooCanvasItemModelIface
-
-<SUBSECTION>
-goo_canvas_item_model_translate
-goo_canvas_item_model_scale
-goo_canvas_item_model_rotate
-goo_canvas_item_model_skew_x
-goo_canvas_item_model_skew_y
-goo_canvas_item_model_get_transform
-goo_canvas_item_model_set_transform
-goo_canvas_item_model_get_simple_transform
-goo_canvas_item_model_set_simple_transform
-
-<SUBSECTION>
-goo_canvas_item_model_animate
-goo_canvas_item_model_stop_animation
-
-<SUBSECTION>
-goo_canvas_item_model_raise
-goo_canvas_item_model_lower
-
-<SUBSECTION>
-goo_canvas_item_model_remove
-
-<SUBSECTION>
-goo_canvas_item_model_get_parent
-goo_canvas_item_model_set_parent
-
-<SUBSECTION>
-goo_canvas_item_model_is_container
-goo_canvas_item_model_get_n_children
-goo_canvas_item_model_get_child
-goo_canvas_item_model_add_child
-goo_canvas_item_model_move_child
-goo_canvas_item_model_remove_child
-goo_canvas_item_model_find_child
-
-<SUBSECTION>
-goo_canvas_item_model_get_style
-goo_canvas_item_model_set_style
-
-<SUBSECTION>
-goo_canvas_item_model_class_install_child_property
-goo_canvas_item_model_class_list_child_properties
-goo_canvas_item_model_class_find_child_property
-goo_canvas_item_model_get_child_property
-goo_canvas_item_model_set_child_property
-goo_canvas_item_model_get_child_properties
-goo_canvas_item_model_get_child_properties_valist
-goo_canvas_item_model_set_child_properties
-goo_canvas_item_model_set_child_properties_valist
-
-<SUBSECTION Standard>
-GOO_CANVAS_ITEM_MODEL
-GOO_IS_CANVAS_ITEM_MODEL
-GOO_TYPE_CANVAS_ITEM_MODEL
-goo_canvas_item_model_get_type
-GOO_CANVAS_ITEM_MODEL_GET_IFACE
-</SECTION>
-
-<SECTION>
<FILE>goocanvasgroup</FILE>
<TITLE>GooCanvasGroup</TITLE>
GooCanvasGroup
@@ -247,25 +140,6 @@ GooCanvasGroupClass
</SECTION>
<SECTION>
-<FILE>goocanvasgroupmodel</FILE>
-<TITLE>GooCanvasGroupModel</TITLE>
-GooCanvasGroupModel
-goo_canvas_group_model_new
-
-<SUBSECTION Standard>
-GOO_TYPE_CANVAS_GROUP_MODEL
-goo_canvas_group_model_get_type
-GOO_CANVAS_GROUP_MODEL
-GOO_CANVAS_GROUP_MODEL_CLASS
-GOO_IS_CANVAS_GROUP_MODEL
-GOO_IS_CANVAS_GROUP_MODEL_CLASS
-GOO_CANVAS_GROUP_MODEL_GET_CLASS
-
-<SUBSECTION Private>
-GooCanvasGroupModelClass
-</SECTION>
-
-<SECTION>
<FILE>goocanvaspath</FILE>
<TITLE>GooCanvasPath</TITLE>
GooCanvasPath
@@ -281,32 +155,12 @@ GOO_IS_CANVAS_PATH_CLASS
GOO_CANVAS_PATH_GET_CLASS
<SUBSECTION Private>
-GooCanvasPathData
goo_canvas_path_command_type_get_type
GOO_TYPE_CANVAS_PATH_COMMAND_TYPE
GooCanvasPathClass
</SECTION>
<SECTION>
-<FILE>goocanvaspathmodel</FILE>
-<TITLE>GooCanvasPathModel</TITLE>
-GooCanvasPathModel
-goo_canvas_path_model_new
-
-<SUBSECTION Standard>
-GOO_TYPE_CANVAS_PATH_MODEL
-GOO_CANVAS_PATH_MODEL
-goo_canvas_path_model_get_type
-GOO_CANVAS_PATH_MODEL_CLASS
-GOO_IS_CANVAS_PATH_MODEL
-GOO_IS_CANVAS_PATH_MODEL_CLASS
-GOO_CANVAS_PATH_MODEL_GET_CLASS
-
-<SUBSECTION Private>
-GooCanvasPathModelClass
-</SECTION>
-
-<SECTION>
<FILE>goocanvasellipse</FILE>
<TITLE>GooCanvasEllipse</TITLE>
GooCanvasEllipse
@@ -322,30 +176,10 @@ GOO_IS_CANVAS_ELLIPSE_CLASS
GOO_CANVAS_ELLIPSE_GET_CLASS
<SUBSECTION Private>
-GooCanvasEllipseData
GooCanvasEllipseClass
</SECTION>
<SECTION>
-<FILE>goocanvasellipsemodel</FILE>
-<TITLE>GooCanvasEllipseModel</TITLE>
-GooCanvasEllipseModel
-goo_canvas_ellipse_model_new
-
-<SUBSECTION Standard>
-GOO_TYPE_CANVAS_ELLIPSE_MODEL
-GOO_CANVAS_ELLIPSE_MODEL
-goo_canvas_ellipse_model_get_type
-GOO_CANVAS_ELLIPSE_MODEL_CLASS
-GOO_IS_CANVAS_ELLIPSE_MODEL
-GOO_IS_CANVAS_ELLIPSE_MODEL_CLASS
-GOO_CANVAS_ELLIPSE_MODEL_GET_CLASS
-
-<SUBSECTION Private>
-GooCanvasEllipseModelClass
-</SECTION>
-
-<SECTION>
<FILE>goocanvas</FILE>
<TITLE>GooCanvas</TITLE>
GooCanvas
@@ -357,14 +191,10 @@ goo_canvas_new
<SUBSECTION>
goo_canvas_get_root_item
goo_canvas_set_root_item
-goo_canvas_get_root_item_model
-goo_canvas_set_root_item_model
<SUBSECTION>
goo_canvas_get_static_root_item
goo_canvas_set_static_root_item
-goo_canvas_get_static_root_item_model
-goo_canvas_set_static_root_item_model
<SUBSECTION>
goo_canvas_get_bounds
@@ -373,7 +203,6 @@ goo_canvas_get_scale
goo_canvas_set_scale
<SUBSECTION>
-goo_canvas_get_item
goo_canvas_get_item_at
goo_canvas_get_items_at
goo_canvas_get_items_in_area
@@ -400,8 +229,6 @@ goo_canvas_keyboard_ungrab
<SUBSECTION>
goo_canvas_create_cairo_context
-goo_canvas_create_item
-goo_canvas_unregister_item
goo_canvas_register_widget_item
goo_canvas_unregister_widget_item
goo_canvas_update
@@ -439,30 +266,10 @@ GOO_IS_CANVAS_TEXT_CLASS
GOO_CANVAS_TEXT_GET_CLASS
<SUBSECTION Private>
-GooCanvasTextData
GooCanvasTextClass
</SECTION>
<SECTION>
-<FILE>goocanvastextmodel</FILE>
-<TITLE>GooCanvasTextModel</TITLE>
-GooCanvasTextModel
-goo_canvas_text_model_new
-
-<SUBSECTION Standard>
-GOO_TYPE_CANVAS_TEXT_MODEL
-GOO_CANVAS_TEXT_MODEL
-goo_canvas_text_model_get_type
-GOO_CANVAS_TEXT_MODEL_CLASS
-GOO_IS_CANVAS_TEXT_MODEL
-GOO_IS_CANVAS_TEXT_MODEL_CLASS
-GOO_CANVAS_TEXT_MODEL_GET_CLASS
-
-<SUBSECTION Private>
-GooCanvasTextModelClass
-</SECTION>
-
-<SECTION>
<FILE>goocanvaspolyline</FILE>
<TITLE>GooCanvasPolyline</TITLE>
GooCanvasPolyline
@@ -479,37 +286,15 @@ GOO_IS_CANVAS_POLYLINE_CLASS
GOO_CANVAS_POLYLINE_GET_CLASS
<SUBSECTION Private>
-GooCanvasPolylineData
NUM_ARROW_POINTS
GooCanvasPolylineArrowData
GooCanvasPolylineClass
</SECTION>
<SECTION>
-<FILE>goocanvaspolylinemodel</FILE>
-<TITLE>GooCanvasPolylineModel</TITLE>
-GooCanvasPolylineModel
-goo_canvas_polyline_model_new
-goo_canvas_polyline_model_new_line
-
-<SUBSECTION Standard>
-GOO_TYPE_CANVAS_POLYLINE_MODEL
-GOO_CANVAS_POLYLINE_MODEL
-goo_canvas_polyline_model_get_type
-GOO_CANVAS_POLYLINE_MODEL_CLASS
-GOO_IS_CANVAS_POLYLINE_MODEL
-GOO_IS_CANVAS_POLYLINE_MODEL_CLASS
-GOO_CANVAS_POLYLINE_MODEL_GET_CLASS
-
-<SUBSECTION Private>
-GooCanvasPolylineModelClass
-</SECTION>
-
-<SECTION>
<FILE>goocanvasitemsimple</FILE>
<TITLE>GooCanvasItemSimple</TITLE>
GooCanvasItemSimple
-GooCanvasItemSimpleData
GooCanvasItemSimpleClass
<SUBSECTION>
@@ -521,7 +306,6 @@ goo_canvas_item_simple_user_bounds_to_parent
goo_canvas_item_simple_check_in_path
goo_canvas_item_simple_paint_path
goo_canvas_item_simple_changed
-goo_canvas_item_simple_set_model
<SUBSECTION Standard>
GOO_CANVAS_ITEM_SIMPLE
@@ -536,24 +320,6 @@ GOO_CANVAS_ITEM_SIMPLE_GET_CLASS
</SECTION>
<SECTION>
-<FILE>goocanvasitemmodelsimple</FILE>
-<TITLE>GooCanvasItemModelSimple</TITLE>
-GooCanvasItemModelSimple
-
-<SUBSECTION Standard>
-GOO_TYPE_CANVAS_ITEM_MODEL_SIMPLE
-goo_canvas_item_model_simple_get_type
-GOO_CANVAS_ITEM_MODEL_SIMPLE
-GOO_CANVAS_ITEM_MODEL_SIMPLE_CLASS
-GOO_IS_CANVAS_ITEM_MODEL_SIMPLE
-GOO_IS_CANVAS_ITEM_MODEL_SIMPLE_CLASS
-GOO_CANVAS_ITEM_MODEL_SIMPLE_GET_CLASS
-
-<SUBSECTION Private>
-GooCanvasItemModelSimpleClass
-</SECTION>
-
-<SECTION>
<FILE>goocanvasimage</FILE>
<TITLE>GooCanvasImage</TITLE>
GooCanvasImage
@@ -569,30 +335,10 @@ GOO_IS_CANVAS_IMAGE_CLASS
GOO_CANVAS_IMAGE_GET_CLASS
<SUBSECTION Private>
-GooCanvasImageData
GooCanvasImageClass
</SECTION>
<SECTION>
-<FILE>goocanvasimagemodel</FILE>
-<TITLE>GooCanvasImageModel</TITLE>
-GooCanvasImageModel
-goo_canvas_image_model_new
-
-<SUBSECTION Standard>
-GOO_TYPE_CANVAS_IMAGE_MODEL
-GOO_CANVAS_IMAGE_MODEL
-goo_canvas_image_model_get_type
-GOO_CANVAS_IMAGE_MODEL_CLASS
-GOO_IS_CANVAS_IMAGE_MODEL
-GOO_IS_CANVAS_IMAGE_MODEL_CLASS
-GOO_CANVAS_IMAGE_MODEL_GET_CLASS
-
-<SUBSECTION Private>
-GooCanvasImageModelClass
-</SECTION>
-
-<SECTION>
<FILE>goocanvasgrid</FILE>
<TITLE>GooCanvasGrid</TITLE>
GooCanvasGrid
@@ -608,30 +354,10 @@ GOO_IS_CANVAS_GRID_CLASS
GOO_CANVAS_GRID_GET_CLASS
<SUBSECTION Private>
-GooCanvasGridData
GooCanvasGridClass
</SECTION>
<SECTION>
-<FILE>goocanvasgridmodel</FILE>
-<TITLE>GooCanvasGridModel</TITLE>
-GooCanvasGridModel
-goo_canvas_grid_model_new
-
-<SUBSECTION Standard>
-GOO_CANVAS_GRID_MODEL
-GOO_IS_CANVAS_GRID_MODEL
-GOO_TYPE_CANVAS_GRID_MODEL
-goo_canvas_grid_model_get_type
-GOO_CANVAS_GRID_MODEL_CLASS
-GOO_IS_CANVAS_GRID_MODEL_CLASS
-GOO_CANVAS_GRID_MODEL_GET_CLASS
-
-<SUBSECTION Private>
-GooCanvasGridModelClass
-</SECTION>
-
-<SECTION>
<FILE>goocanvaswidget</FILE>
<TITLE>GooCanvasWidget</TITLE>
GooCanvasWidget
diff --git a/docs/goocanvas.types b/docs/goocanvas.types
index dbe9b53..8c87fd4 100644
--- a/docs/goocanvas.types
+++ b/docs/goocanvas.types
@@ -8,34 +8,23 @@ goo_cairo_line_cap_get_type
goo_cairo_line_join_get_type
goo_canvas_widget_get_type
goo_canvas_rect_get_type
-goo_canvas_rect_model_get_type
goo_canvas_item_get_type
goo_canvas_animate_type_get_type
goo_canvas_path_command_type_get_type
goo_canvas_pointer_events_get_type
goo_canvas_item_visibility_get_type
-goo_canvas_item_model_get_type
goo_canvas_group_get_type
-goo_canvas_group_model_get_type
goo_canvas_path_get_type
-goo_canvas_path_model_get_type
goo_canvas_accessible_factory_get_type
goo_canvas_item_accessible_factory_get_type
goo_canvas_widget_accessible_factory_get_type
goo_canvas_ellipse_get_type
-goo_canvas_ellipse_model_get_type
goo_canvas_style_get_type
goo_canvas_get_type
goo_canvas_text_get_type
-goo_canvas_text_model_get_type
goo_canvas_points_get_type
goo_canvas_polyline_get_type
-goo_canvas_polyline_model_get_type
goo_canvas_item_simple_get_type
-goo_canvas_item_model_simple_get_type
goo_canvas_image_get_type
-goo_canvas_image_model_get_type
goo_canvas_table_get_type
-goo_canvas_table_model_get_type
goo_canvas_grid_get_type
-goo_canvas_grid_model_get_type
diff --git a/docs/overview.xml b/docs/overview.xml
index 08846f8..2adbc0c 100644
--- a/docs/overview.xml
+++ b/docs/overview.xml
@@ -17,8 +17,6 @@
<title>Features</title>
<itemizedlist>
<listitem><para>
- Optional model/view split.
- </para></listitem><listitem><para>
Uses interfaces for items and views.
</para></listitem><listitem><para>
Basic items - rect/ellipse/polyline/text/image/grid/group.
diff --git a/src/Makefile.am b/src/Makefile.am
index 4abd1e2..4fb8f25 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -33,7 +33,6 @@ libgoocanvas_public_headers = \
goocanvasgroup.h \
goocanvasimage.h \
goocanvasitem.h \
- goocanvasitemmodel.h \
goocanvasitemsimple.h \
goocanvaspolyline.h \
goocanvaspath.h \
@@ -54,7 +53,6 @@ libgoocanvas_2_0_la_SOURCES = \
goocanvasgroup.c \
goocanvasimage.c \
goocanvasitem.c \
- goocanvasitemmodel.c \
goocanvasitemsimple.c \
goocanvasmarshal.c \
goocanvaspolyline.c \
diff --git a/src/goocanvas.c b/src/goocanvas.c
index cfa51a5..4b7659b 100644
--- a/src/goocanvas.c
+++ b/src/goocanvas.c
@@ -99,23 +99,11 @@
#include <gtk/gtk.h>
#include "goocanvasatk.h"
#include "goocanvas.h"
-#include "goocanvasitemmodel.h"
#include "goocanvasitem.h"
#include "goocanvasgroup.h"
#include "goocanvasmarshal.h"
-#define GOO_CANVAS_GET_PRIVATE(canvas) \
- (G_TYPE_INSTANCE_GET_PRIVATE ((canvas), GOO_TYPE_CANVAS, GooCanvasPrivate))
-
-typedef struct _GooCanvasPrivate GooCanvasPrivate;
-struct _GooCanvasPrivate {
- GooCanvasItem *static_root_item;
- GooCanvasItemModel *static_root_item_model;
- gint window_x, window_y;
-};
-
-
enum {
PROP_0,
@@ -140,14 +128,6 @@ enum {
PROP_REDRAW_WHEN_SCROLLED
};
-enum {
- ITEM_CREATED,
-
- LAST_SIGNAL
-};
-
-
-static guint canvas_signals[LAST_SIGNAL] = { 0 };
static void goo_canvas_dispose (GObject *object);
static void goo_canvas_finalize (GObject *object);
@@ -238,8 +218,6 @@ goo_canvas_class_init (GooCanvasClass *klass)
GtkWidgetClass *widget_class = (GtkWidgetClass*) klass;
GtkContainerClass *container_class = (GtkContainerClass*) klass;
- g_type_class_add_private (gobject_class, sizeof (GooCanvasPrivate));
-
gobject_class->dispose = goo_canvas_dispose;
gobject_class->finalize = goo_canvas_finalize;
gobject_class->get_property = goo_canvas_get_property;
@@ -445,37 +423,12 @@ goo_canvas_class_init (GooCanvasClass *klass)
G_TYPE_NONE, 2,
GTK_TYPE_ADJUSTMENT,
GTK_TYPE_ADJUSTMENT);
-
- /* Signals. */
-
- /**
- * GooCanvas::item-created
- * @canvas: the canvas.
- * @item: the new item.
- * @model: the item's model.
- *
- * This is emitted when a new canvas item is created, in model/view mode.
- *
- * Applications can set up signal handlers for the new items here.
- */
- canvas_signals[ITEM_CREATED] =
- g_signal_new ("item-created",
- G_TYPE_FROM_CLASS (gobject_class),
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (GooCanvasClass, item_created),
- NULL, NULL,
- goo_canvas_marshal_VOID__OBJECT_OBJECT,
- G_TYPE_NONE, 2,
- GOO_TYPE_CANVAS_ITEM,
- GOO_TYPE_CANVAS_ITEM_MODEL);
}
static void
goo_canvas_init (GooCanvas *canvas)
{
- GooCanvasPrivate *priv = GOO_CANVAS_GET_PRIVATE (canvas);
-
/* We set GTK_CAN_FOCUS by default, so it works as people expect.
Though developers can turn this off if not needed for efficiency. */
GTK_WIDGET_SET_FLAGS (canvas, GTK_CAN_FOCUS);
@@ -513,20 +466,17 @@ goo_canvas_init (GooCanvas *canvas)
g_object_ref_sink (canvas->hadjustment);
g_object_ref_sink (canvas->vadjustment);
- canvas->model_to_item = g_hash_table_new (g_direct_hash, g_direct_equal);
-
/* Use a simple group as the default root item, which is fine 99% of the
time. Apps can set their own root item if required. */
canvas->root_item = goo_canvas_group_new (NULL, NULL);
goo_canvas_item_set_canvas (canvas->root_item, canvas);
- priv->static_root_item = goo_canvas_group_new (NULL, NULL);
- goo_canvas_item_set_canvas (priv->static_root_item, canvas);
- goo_canvas_item_set_is_static (priv->static_root_item, TRUE);
- priv->static_root_item_model = NULL;
+ canvas->static_root_item = goo_canvas_group_new (NULL, NULL);
+ goo_canvas_item_set_canvas (canvas->static_root_item, canvas);
+ goo_canvas_item_set_is_static (canvas->static_root_item, TRUE);
- priv->window_x = 0;
- priv->window_y = 0;
+ canvas->window_x = 0;
+ canvas->window_y = 0;
}
@@ -536,8 +486,7 @@ goo_canvas_init (GooCanvas *canvas)
* Creates a new #GooCanvas widget.
*
* A #GooCanvasGroup is created automatically as the root item of the canvas,
- * though this can be overriden with goo_canvas_set_root_item() or
- * goo_canvas_set_root_item_model().
+ * though this can be overriden with goo_canvas_set_root_item().
*
* Returns: a new #GooCanvas widget.
**/
@@ -551,13 +500,6 @@ static void
goo_canvas_dispose (GObject *object)
{
GooCanvas *canvas = (GooCanvas*) object;
- GooCanvasPrivate *priv = GOO_CANVAS_GET_PRIVATE (canvas);
-
- if (canvas->model_to_item)
- {
- g_hash_table_destroy (canvas->model_to_item);
- canvas->model_to_item = NULL;
- }
if (canvas->root_item)
{
@@ -565,22 +507,10 @@ goo_canvas_dispose (GObject *object)
canvas->root_item = NULL;
}
- if (canvas->root_item_model)
- {
- g_object_unref (canvas->root_item_model);
- canvas->root_item_model = NULL;
- }
-
- if (priv->static_root_item)
- {
- g_object_unref (priv->static_root_item);
- priv->static_root_item = NULL;
- }
-
- if (priv->static_root_item_model)
+ if (canvas->static_root_item)
{
- g_object_unref (priv->static_root_item_model);
- priv->static_root_item_model = NULL;
+ g_object_unref (canvas->static_root_item);
+ canvas->static_root_item = NULL;
}
if (canvas->idle_id)
@@ -887,78 +817,6 @@ goo_canvas_set_property (GObject *object,
/**
- * goo_canvas_get_root_item_model:
- * @canvas: a #GooCanvas.
- *
- * Gets the root item model of the canvas.
- *
- * Returns: the root item model, or %NULL if there is no root item model.
- **/
-GooCanvasItemModel*
-goo_canvas_get_root_item_model (GooCanvas *canvas)
-{
- g_return_val_if_fail (GOO_IS_CANVAS (canvas), NULL);
-
- return canvas->root_item_model;
-}
-
-
-/**
- * goo_canvas_set_root_item_model:
- * @canvas: a #GooCanvas.
- * @model: a #GooCanvasItemModel.
- *
- * Sets the root item model of the canvas.
- *
- * A hierarchy of canvas items will be created, corresponding to the hierarchy
- * of items in the model. Any current canvas items will be removed.
- **/
-void
-goo_canvas_set_root_item_model (GooCanvas *canvas,
- GooCanvasItemModel *model)
-{
- g_return_if_fail (GOO_IS_CANVAS (canvas));
- g_return_if_fail (GOO_IS_CANVAS_ITEM_MODEL (model));
-
- if (canvas->root_item_model == model)
- return;
-
- if (canvas->root_item_model)
- {
- g_object_unref (canvas->root_item_model);
- canvas->root_item_model = NULL;
- }
-
- if (canvas->root_item)
- {
- g_object_unref (canvas->root_item);
- canvas->root_item = NULL;
- }
-
- if (model)
- {
- canvas->root_item_model = g_object_ref (model);
-
- /* Create a hierarchy of canvas items for all the items in the model. */
- canvas->root_item = goo_canvas_create_item (canvas, model);
- }
- else
- {
- /* The model has been reset so we go back to a default root group. */
- canvas->root_item = goo_canvas_group_new (NULL, NULL);
- }
-
- goo_canvas_item_set_canvas (canvas->root_item, canvas);
- canvas->need_update = TRUE;
-
- if (gtk_widget_get_realized (GTK_WIDGET (canvas)))
- goo_canvas_update (canvas);
-
- gtk_widget_queue_draw (GTK_WIDGET (canvas));
-}
-
-
-/**
* goo_canvas_get_root_item:
* @canvas: a #GooCanvas.
*
@@ -992,13 +850,6 @@ goo_canvas_set_root_item (GooCanvas *canvas,
if (canvas->root_item == item)
return;
- /* Remove any current model. */
- if (canvas->root_item_model)
- {
- g_object_unref (canvas->root_item_model);
- canvas->root_item_model = NULL;
- }
-
if (canvas->root_item)
g_object_unref (canvas->root_item);
@@ -1034,7 +885,7 @@ goo_canvas_get_static_root_item (GooCanvas *canvas)
{
g_return_val_if_fail (GOO_IS_CANVAS (canvas), NULL);
- return GOO_CANVAS_GET_PRIVATE (canvas)->static_root_item;
+ return canvas->static_root_item;
}
@@ -1056,29 +907,18 @@ void
goo_canvas_set_static_root_item (GooCanvas *canvas,
GooCanvasItem *item)
{
- GooCanvasPrivate *priv;
-
g_return_if_fail (GOO_IS_CANVAS (canvas));
g_return_if_fail (GOO_IS_CANVAS_ITEM (item));
- priv = GOO_CANVAS_GET_PRIVATE (canvas);
-
- if (priv->static_root_item == item)
+ if (canvas->static_root_item == item)
return;
- /* Remove any current model. */
- if (priv->static_root_item_model)
- {
- g_object_unref (priv->static_root_item_model);
- priv->static_root_item_model = NULL;
- }
-
- if (priv->static_root_item)
- g_object_unref (priv->static_root_item);
+ if (canvas->static_root_item)
+ g_object_unref (canvas->static_root_item);
- priv->static_root_item = g_object_ref (item);
- goo_canvas_item_set_canvas (priv->static_root_item, canvas);
- goo_canvas_item_set_is_static (priv->static_root_item, TRUE);
+ canvas->static_root_item = g_object_ref (item);
+ goo_canvas_item_set_canvas (canvas->static_root_item, canvas);
+ goo_canvas_item_set_is_static (canvas->static_root_item, TRUE);
canvas->need_update = TRUE;
@@ -1090,138 +930,6 @@ goo_canvas_set_static_root_item (GooCanvas *canvas,
/**
- * goo_canvas_get_static_root_item_model:
- * @canvas: a #GooCanvas.
- *
- * Gets the static root item model of the canvas.
- *
- * Static item models are exactly the same as ordinary item models, except that
- * the corresponding items do not move or change size when the canvas is
- * scrolled or the scale changes.
- *
- * Static items models are added to the static root item model in exactly the
- * same way that ordinary item models are added to the root item model.
- *
- * Returns: the static root item model, or %NULL.
- **/
-GooCanvasItemModel*
-goo_canvas_get_static_root_item_model (GooCanvas *canvas)
-{
- g_return_val_if_fail (GOO_IS_CANVAS (canvas), NULL);
-
- return GOO_CANVAS_GET_PRIVATE (canvas)->static_root_item_model;
-}
-
-
-/**
- * goo_canvas_set_static_root_item_model:
- * @canvas: a #GooCanvas.
- * @model: the static root item model.
- *
- * Sets the static root item model. Any existing static item models are
- * removed.
- *
- * Static item models are exactly the same as ordinary item models, except that
- * the corresponding items do not move or change size when the canvas is
- * scrolled or the scale changes.
- *
- * Static items models are added to the static root item model in exactly the
- * same way that ordinary item models are added to the root item model.
- **/
-void
-goo_canvas_set_static_root_item_model (GooCanvas *canvas,
- GooCanvasItemModel *model)
-{
- GooCanvasPrivate *priv;
-
- g_return_if_fail (GOO_IS_CANVAS (canvas));
- g_return_if_fail (GOO_IS_CANVAS_ITEM_MODEL (model));
-
- priv = GOO_CANVAS_GET_PRIVATE (canvas);
-
- if (priv->static_root_item_model == model)
- return;
-
- if (priv->static_root_item_model)
- {
- g_object_unref (priv->static_root_item_model);
- priv->static_root_item_model = NULL;
- }
-
- if (priv->static_root_item)
- {
- g_object_unref (priv->static_root_item);
- priv->static_root_item = NULL;
- }
-
- if (model)
- {
- priv->static_root_item_model = g_object_ref (model);
-
- /* Create a hierarchy of canvas items for all the items in the model. */
- priv->static_root_item = goo_canvas_create_item (canvas, model);
- }
- else
- {
- /* The model has been reset so we go back to a default root group. */
- priv->static_root_item = goo_canvas_group_new (NULL, NULL);
- }
-
- goo_canvas_item_set_canvas (priv->static_root_item, canvas);
- goo_canvas_item_set_is_static (priv->static_root_item, TRUE);
- canvas->need_update = TRUE;
-
- if (gtk_widget_get_realized (GTK_WIDGET (canvas)))
- goo_canvas_update (canvas);
-
- gtk_widget_queue_draw (GTK_WIDGET (canvas));
-}
-
-
-/**
- * goo_canvas_get_item:
- * @canvas: a #GooCanvas.
- * @model: a #GooCanvasItemModel.
- *
- * Gets the canvas item associated with the given #GooCanvasItemModel.
- * This is only useful when goo_canvas_set_root_item_model() has been used to
- * set a model for the canvas.
- *
- * For simple applications you can use goo_canvas_get_item() to set up
- * signal handlers for your items, e.g.
- *
- * <informalexample><programlisting>
- * item = goo_canvas_get_item (GOO_CANVAS (canvas), my_item);
- * g_signal_connect (item, "button_press_event",
- * (GtkSignalFunc) on_my_item_button_press, NULL);
- * </programlisting></informalexample>
- *
- * More complex applications may want to use the #GooCanvas::item-created
- * signal to hook up their signal handlers.
- *
- * Returns: the canvas item corresponding to the given #GooCanvasItemModel,
- * or %NULL if no canvas item has been created for it yet.
- **/
-GooCanvasItem*
-goo_canvas_get_item (GooCanvas *canvas,
- GooCanvasItemModel *model)
-{
- GooCanvasItem *item = NULL;
-
- g_return_val_if_fail (GOO_IS_CANVAS (canvas), NULL);
- g_return_val_if_fail (GOO_IS_CANVAS_ITEM_MODEL (model), NULL);
-
- if (canvas->model_to_item)
- item = g_hash_table_lookup (canvas->model_to_item, model);
-
- /* If the item model has a canvas item check it is valid. */
- g_return_val_if_fail (!item || GOO_IS_CANVAS_ITEM (item), NULL);
-
- return item;
-}
-
-
-/**
* goo_canvas_get_item_at:
* @canvas: a #GooCanvas.
* @x: the x coordinate of the point.
@@ -1239,26 +947,24 @@ goo_canvas_get_item_at (GooCanvas *canvas,
gdouble y,
gboolean is_pointer_event)
{
- GooCanvasPrivate *priv;
cairo_t *cr;
GooCanvasItem *result = NULL;
GList *list = NULL;
g_return_val_if_fail (GOO_IS_CANVAS (canvas), NULL);
- priv = GOO_CANVAS_GET_PRIVATE (canvas);
cr = goo_canvas_create_cairo_context (canvas);
if (canvas->root_item)
list = goo_canvas_item_get_items_at (canvas->root_item, x, y, cr,
is_pointer_event, TRUE, NULL);
- if (!list && priv->static_root_item)
+ if (!list && canvas->static_root_item)
{
gdouble static_x = x, static_y = y;
goo_canvas_convert_to_static_item_space (canvas, &static_x, &static_y);
- list = goo_canvas_item_get_items_at (priv->static_root_item,
+ list = goo_canvas_item_get_items_at (canvas->static_root_item,
static_x, static_y, cr,
is_pointer_event, TRUE, NULL);
}
@@ -1295,25 +1001,23 @@ goo_canvas_get_items_at (GooCanvas *canvas,
gdouble y,
gboolean is_pointer_event)
{
- GooCanvasPrivate *priv;
cairo_t *cr;
GList *result = NULL;
g_return_val_if_fail (GOO_IS_CANVAS (canvas), NULL);
- priv = GOO_CANVAS_GET_PRIVATE (canvas);
cr = goo_canvas_create_cairo_context (canvas);
if (canvas->root_item)
result = goo_canvas_item_get_items_at (canvas->root_item, x, y, cr,
is_pointer_event, TRUE, NULL);
- if (priv->static_root_item)
+ if (canvas->static_root_item)
{
gdouble static_x = x, static_y = y;
goo_canvas_convert_to_static_item_space (canvas, &static_x, &static_y);
- result = goo_canvas_item_get_items_at (priv->static_root_item,
+ result = goo_canvas_item_get_items_at (canvas->static_root_item,
static_x, static_y, cr,
is_pointer_event, TRUE, result);
}
@@ -1428,7 +1132,6 @@ static void
goo_canvas_realize (GtkWidget *widget)
{
GooCanvas *canvas;
- GooCanvasPrivate *priv;
GdkWindowAttr attributes;
gint attributes_mask;
gint width_pixels, height_pixels;
@@ -1437,7 +1140,6 @@ goo_canvas_realize (GtkWidget *widget)
g_return_if_fail (GOO_IS_CANVAS (widget));
canvas = GOO_CANVAS (widget);
- priv = GOO_CANVAS_GET_PRIVATE (canvas);
GTK_WIDGET_SET_FLAGS (canvas, GTK_REALIZED);
attributes.window_type = GDK_WINDOW_CHILD;
@@ -1477,8 +1179,8 @@ goo_canvas_realize (GtkWidget *widget)
| GDK_FOCUS_CHANGE_MASK
| gtk_widget_get_events (widget);
- priv->window_x = attributes.x;
- priv->window_y = attributes.y;
+ canvas->window_x = attributes.x;
+ canvas->window_y = attributes.y;
canvas->canvas_window = gdk_window_new (widget->window,
&attributes, attributes_mask);
@@ -1696,7 +1398,6 @@ static void
request_static_redraw (GooCanvas *canvas,
const GooCanvasBounds *bounds)
{
- GooCanvasPrivate *priv = GOO_CANVAS_GET_PRIVATE (canvas);
GdkRectangle rect;
if (!gtk_widget_is_drawable (GTK_WIDGET (canvas)) || (bounds->x1 == bounds->x2))
@@ -1704,13 +1405,13 @@ request_static_redraw (GooCanvas *canvas,
/* We subtract one from the left & top edges, in case anti-aliasing makes
the drawing use an extra pixel. */
- rect.x = (double) bounds->x1 - priv->window_x - 1;
- rect.y = (double) bounds->y1 - priv->window_y - 1;
+ rect.x = (double) bounds->x1 - canvas->window_x - 1;
+ rect.y = (double) bounds->y1 - canvas->window_y - 1;
/* We add an extra one here for the same reason. (The other extra one is to
round up to the next pixel.) And one for luck! */
- rect.width = (double) bounds->x2 - priv->window_x - rect.x + 2 + 1;
- rect.height = (double) bounds->y2 - priv->window_y - rect.y + 2 + 1;
+ rect.width = (double) bounds->x2 - canvas->window_x - rect.x + 2 + 1;
+ rect.height = (double) bounds->y2 - canvas->window_y - rect.y + 2 + 1;
gdk_window_invalidate_rect (canvas->canvas_window, &rect, FALSE);
}
@@ -1725,21 +1426,20 @@ redraw_static_items_at_position (GooCanvas *canvas,
gint x,
gint y)
{
- GooCanvasPrivate *priv = GOO_CANVAS_GET_PRIVATE (canvas);
GooCanvasBounds bounds;
GooCanvasItem *item;
gint n_children, i, window_x_copy, window_y_copy;
- if (!priv->static_root_item)
+ if (!canvas->static_root_item)
return;
- window_x_copy = priv->window_x;
- window_y_copy = priv->window_y;
+ window_x_copy = canvas->window_x;
+ window_y_copy = canvas->window_y;
- n_children = goo_canvas_item_get_n_children (priv->static_root_item);
+ n_children = goo_canvas_item_get_n_children (canvas->static_root_item);
for (i = 0; i < n_children; i++)
{
- item = goo_canvas_item_get_child (priv->static_root_item, i);
+ item = goo_canvas_item_get_child (canvas->static_root_item, i);
/* Get the bounds of all the static items, relative to the window. */
goo_canvas_item_get_bounds (item, &bounds);
@@ -1748,14 +1448,14 @@ redraw_static_items_at_position (GooCanvas *canvas,
request_static_redraw (canvas, &bounds);
/* Redraw the item in its new position. */
- priv->window_x = x;
- priv->window_y = y;
+ canvas->window_x = x;
+ canvas->window_y = y;
gdk_window_process_updates (canvas->canvas_window, TRUE);
/* Now reset the window position. */
- priv->window_x = window_x_copy;
- priv->window_y = window_y_copy;
+ canvas->window_x = window_x_copy;
+ canvas->window_y = window_y_copy;
}
}
@@ -1968,7 +1668,6 @@ static void
goo_canvas_adjustment_value_changed (GtkAdjustment *adjustment,
GooCanvas *canvas)
{
- GooCanvasPrivate *priv = GOO_CANVAS_GET_PRIVATE (canvas);
AtkObject *accessible;
if (!canvas->freeze_count && gtk_widget_get_realized (GTK_WIDGET(canvas)))
@@ -1990,8 +1689,8 @@ goo_canvas_adjustment_value_changed (GtkAdjustment *adjustment,
-canvas->hadjustment->value);
/* Move the static items to the new position. */
- priv->window_x = -canvas->hadjustment->value;
- priv->window_y = -canvas->vadjustment->value;
+ canvas->window_x = -canvas->hadjustment->value;
+ canvas->window_y = -canvas->vadjustment->value;
}
gdk_window_move (canvas->canvas_window,
@@ -2011,8 +1710,8 @@ goo_canvas_adjustment_value_changed (GtkAdjustment *adjustment,
gdk_window_process_updates (canvas->canvas_window, TRUE);
/* Now ensure the static items are redrawn in their new position. */
- redraw_static_items_at_position (canvas, priv->window_x,
- priv->window_y);
+ redraw_static_items_at_position (canvas, canvas->window_x,
+ canvas->window_y);
}
/* Notify any accessibility modules that the view has changed. */
@@ -2338,71 +2037,6 @@ goo_canvas_set_scale (GooCanvas *canvas,
}
-/**
- * goo_canvas_unregister_item:
- * @canvas: a #GooCanvas.
- * @model: the item model whose canvas item is being finalized.
- *
- * This function is only intended to be used when implementing new canvas
- * items.
- *
- * It should be called in the finalize method of #GooCanvasItem
- * objects, to remove the canvas item from the #GooCanvas's hash table.
- **/
-void
-goo_canvas_unregister_item (GooCanvas *canvas,
- GooCanvasItemModel *model)
-{
- if (canvas->model_to_item)
- g_hash_table_remove (canvas->model_to_item, model);
-}
-
-
-/**
- * goo_canvas_create_item:
- * @canvas: a #GooCanvas.
- * @model: the item model to create a canvas item for.
- *
- * This function is only intended to be used when implementing new canvas
- * items, typically container items such as #GooCanvasGroup.
- *
- * It creates a new canvas item for the given item model, and recursively
- * creates items for any children.
- *
- * It uses the create_item() virtual method if it has been set.
- * Subclasses of #GooCanvas can define this method if they want to use
- * custom views for items.
- *
- * It emits the #GooCanvas::item-created signal after creating the view, so
- * application code can connect signal handlers to the new view if desired.
- *
- * Returns: a new canvas item.
- **/
-GooCanvasItem*
-goo_canvas_create_item (GooCanvas *canvas,
- GooCanvasItemModel *model)
-{
- GooCanvasItem *item = NULL;
-
- /* Use the virtual method if it has been set. */
- if (GOO_CANVAS_GET_CLASS (canvas)->create_item)
- item = GOO_CANVAS_GET_CLASS (canvas)->create_item (canvas, model);
-
- /* The virtual method can return NULL to use the default view for an item. */
- if (!item)
- item = GOO_CANVAS_ITEM_MODEL_GET_IFACE (model)->create_item (model,
- canvas);
-
- if (canvas->model_to_item)
- g_hash_table_insert (canvas->model_to_item, model, item);
-
- /* Emit a signal so apps can hook up signal handlers if they want. */
- g_signal_emit (canvas, canvas_signals[ITEM_CREATED], 0, item, model);
-
- return item;
-}
-
-
static void
goo_canvas_update_automatic_bounds (GooCanvas *canvas)
{
@@ -2453,7 +2087,6 @@ static void
goo_canvas_update_internal (GooCanvas *canvas,
cairo_t *cr)
{
- GooCanvasPrivate *priv = GOO_CANVAS_GET_PRIVATE (canvas);
GooCanvasBounds bounds, static_bounds;
/* It is possible that processing the first set of updates causes other
@@ -2468,8 +2101,8 @@ goo_canvas_update_internal (GooCanvas *canvas,
if (canvas->root_item)
goo_canvas_item_update (canvas->root_item, entire_tree, cr, &bounds);
- if (priv->static_root_item)
- goo_canvas_item_update (priv->static_root_item, entire_tree, cr,
+ if (canvas->static_root_item)
+ goo_canvas_item_update (canvas->static_root_item, entire_tree, cr,
&static_bounds);
}
@@ -2621,7 +2254,6 @@ paint_static_items (GooCanvas *canvas,
GdkEventExpose *event,
cairo_t *cr)
{
- GooCanvasPrivate *priv = GOO_CANVAS_GET_PRIVATE (canvas);
GooCanvasBounds static_bounds;
double static_x_offset, static_y_offset;
@@ -2635,7 +2267,7 @@ paint_static_items (GooCanvas *canvas,
static_bounds.y1 = event->area.y - static_y_offset;
static_bounds.x2 = event->area.width + static_bounds.x1;
static_bounds.y2 = event->area.height + static_bounds.y1;
- goo_canvas_item_paint (priv->static_root_item, cr, &static_bounds, 1.0);
+ goo_canvas_item_paint (canvas->static_root_item, cr, &static_bounds, 1.0);
cairo_restore (cr);
}
diff --git a/src/goocanvas.h b/src/goocanvas.h
index 780b585..b9d1833 100644
--- a/src/goocanvas.h
+++ b/src/goocanvas.h
@@ -42,12 +42,12 @@ struct _GooCanvas
{
GtkContainer container;
- /* The model for the root item, in model/view mode. */
- GooCanvasItemModel *root_item_model;
-
/* The root canvas item. */
GooCanvasItem *root_item;
+ /* The root item for the static items. */
+ GooCanvasItem *static_root_item;
+
/* The bounds of the canvas, in canvas units (not pixels). */
GooCanvasBounds bounds;
@@ -136,9 +136,6 @@ struct _GooCanvas
the contents unnecessarily (i.e. when we zoom in/out). */
GdkWindow *tmp_window;
- /* A hash table mapping canvas item models to canvas items. */
- GHashTable *model_to_item;
-
/* The units of the canvas, which applies to all item coords. */
GtkUnit units;
@@ -152,17 +149,15 @@ struct _GooCanvas
/* The list of child widgets (using GooCanvasWidget items). */
GList *widget_items;
+
+ /* The last window position, used for static items. */
+ gint window_x, window_y;
};
/**
* GooCanvasClass
- * @create_item: a virtual method that subclasses may override to create custom
- * canvas items for item models.
- * @item_created: signal emitted when a new canvas item has been created.
- * Applications can connect to this to setup signal handlers for the new item.
*
- * The #GooCanvasClass-struct struct contains one virtual method that
- * subclasses may override.
+ * The #GooCanvasClass-struct struct contains private data only.
*/
struct _GooCanvasClass
{
@@ -173,18 +168,7 @@ struct _GooCanvasClass
GtkAdjustment *hadjustment,
GtkAdjustment *vadjustment);
- /* Virtual methods. */
- /*< public >*/
- GooCanvasItem* (* create_item) (GooCanvas *canvas,
- GooCanvasItemModel *model);
-
- /* Signals. */
- void (* item_created) (GooCanvas *canvas,
- GooCanvasItem *item,
- GooCanvasItemModel *model);
-
/*< private >*/
-
/* Padding for future expansion */
void (*_goo_canvas_reserved1) (void);
void (*_goo_canvas_reserved2) (void);
@@ -204,20 +188,10 @@ GooCanvasItem* goo_canvas_get_root_item (GooCanvas *canvas);
void goo_canvas_set_root_item (GooCanvas *canvas,
GooCanvasItem *item);
-GooCanvasItemModel* goo_canvas_get_root_item_model (GooCanvas *canvas);
-void goo_canvas_set_root_item_model (GooCanvas *canvas,
- GooCanvasItemModel *model);
-
GooCanvasItem* goo_canvas_get_static_root_item (GooCanvas *canvas);
void goo_canvas_set_static_root_item (GooCanvas *canvas,
GooCanvasItem *item);
-GooCanvasItemModel* goo_canvas_get_static_root_item_model (GooCanvas *canvas);
-void goo_canvas_set_static_root_item_model (GooCanvas *canvas,
- GooCanvasItemModel *model);
-
-GooCanvasItem* goo_canvas_get_item (GooCanvas *canvas,
- GooCanvasItemModel *model);
GooCanvasItem* goo_canvas_get_item_at (GooCanvas *canvas,
gdouble x,
gdouble y,
@@ -306,10 +280,6 @@ void goo_canvas_keyboard_ungrab (GooCanvas *canvas,
* Internal functions, mainly for canvas subclasses and item implementations.
*/
cairo_t* goo_canvas_create_cairo_context (GooCanvas *canvas);
-GooCanvasItem* goo_canvas_create_item (GooCanvas *canvas,
- GooCanvasItemModel *model);
-void goo_canvas_unregister_item (GooCanvas *canvas,
- GooCanvasItemModel *model);
void goo_canvas_update (GooCanvas *canvas);
void goo_canvas_request_update (GooCanvas *canvas);
void goo_canvas_request_redraw (GooCanvas *canvas,
diff --git a/src/goocanvasellipse.c b/src/goocanvasellipse.c
index 6653f50..e7ec438 100644
--- a/src/goocanvasellipse.c
+++ b/src/goocanvasellipse.c
@@ -50,111 +50,13 @@ enum {
};
-static void canvas_item_interface_init (GooCanvasItemIface *iface);
-static void goo_canvas_ellipse_finalize (GObject *object);
-static void goo_canvas_ellipse_get_property (GObject *object,
- guint param_id,
- GValue *value,
- GParamSpec *pspec);
-static void goo_canvas_ellipse_set_property (GObject *object,
- guint param_id,
- const GValue *value,
- GParamSpec *pspec);
-static void goo_canvas_ellipse_create_path (GooCanvasItemSimple *simple,
- cairo_t *cr);
-
-G_DEFINE_TYPE_WITH_CODE (GooCanvasEllipse, goo_canvas_ellipse,
- GOO_TYPE_CANVAS_ITEM_SIMPLE,
- G_IMPLEMENT_INTERFACE (GOO_TYPE_CANVAS_ITEM,
- canvas_item_interface_init))
-
-
-static void
-goo_canvas_ellipse_install_common_properties (GObjectClass *gobject_class)
-{
- g_object_class_install_property (gobject_class, PROP_CENTER_X,
- g_param_spec_double ("center-x",
- _("Center X"),
- _("The x coordinate of the center of the ellipse"),
- -G_MAXDOUBLE,
- G_MAXDOUBLE, 0.0,
- G_PARAM_READWRITE));
-
- g_object_class_install_property (gobject_class, PROP_CENTER_Y,
- g_param_spec_double ("center-y",
- _("Center Y"),
- _("The y coordinate of the center of the ellipse"),
- -G_MAXDOUBLE,
- G_MAXDOUBLE, 0.0,
- G_PARAM_READWRITE));
-
- g_object_class_install_property (gobject_class, PROP_RADIUS_X,
- g_param_spec_double ("radius-x",
- _("Radius X"),
- _("The horizontal radius of the ellipse"),
- 0.0, G_MAXDOUBLE, 0.0,
- G_PARAM_READWRITE));
-
- g_object_class_install_property (gobject_class, PROP_RADIUS_Y,
- g_param_spec_double ("radius-y",
- _("Radius Y"),
- _("The vertical radius of the ellipse"),
- 0.0, G_MAXDOUBLE, 0.0,
- G_PARAM_READWRITE));
-
- g_object_class_install_property (gobject_class, PROP_X,
- g_param_spec_double ("x",
- "X",
- _("The x coordinate of the left side of the ellipse"),
- -G_MAXDOUBLE,
- G_MAXDOUBLE, 0.0,
- G_PARAM_READWRITE));
-
- g_object_class_install_property (gobject_class, PROP_Y,
- g_param_spec_double ("y",
- "Y",
- _("The y coordinate of the top of the ellipse"),
- -G_MAXDOUBLE,
- G_MAXDOUBLE, 0.0,
- G_PARAM_READWRITE));
-
- g_object_class_install_property (gobject_class, PROP_WIDTH,
- g_param_spec_double ("width",
- _("Width"),
- _("The width of the ellipse"),
- 0.0, G_MAXDOUBLE, 0.0,
- G_PARAM_READWRITE));
-
- g_object_class_install_property (gobject_class, PROP_HEIGHT,
- g_param_spec_double ("height",
- _("Height"),
- _("The height of the ellipse"),
- 0.0, G_MAXDOUBLE, 0.0,
- G_PARAM_READWRITE));
-}
-
-
-static void
-goo_canvas_ellipse_class_init (GooCanvasEllipseClass *klass)
-{
- GObjectClass *gobject_class = (GObjectClass*) klass;
- GooCanvasItemSimpleClass *simple_class = (GooCanvasItemSimpleClass*) klass;
-
- gobject_class->finalize = goo_canvas_ellipse_finalize;
-
- gobject_class->get_property = goo_canvas_ellipse_get_property;
- gobject_class->set_property = goo_canvas_ellipse_set_property;
-
- simple_class->simple_create_path = goo_canvas_ellipse_create_path;
-
- goo_canvas_ellipse_install_common_properties (gobject_class);
-}
+G_DEFINE_TYPE (GooCanvasEllipse, goo_canvas_ellipse, GOO_TYPE_CANVAS_ITEM_SIMPLE)
static void
goo_canvas_ellipse_init (GooCanvasEllipse *ellipse)
{
- ellipse->ellipse_data = g_slice_new0 (GooCanvasEllipseData);
+
}
@@ -197,18 +99,16 @@ goo_canvas_ellipse_new (GooCanvasItem *parent,
{
GooCanvasItem *item;
GooCanvasEllipse *ellipse;
- GooCanvasEllipseData *ellipse_data;
const char *first_property;
va_list var_args;
item = g_object_new (GOO_TYPE_CANVAS_ELLIPSE, NULL);
ellipse = (GooCanvasEllipse*) item;
- ellipse_data = ellipse->ellipse_data;
- ellipse_data->center_x = center_x;
- ellipse_data->center_y = center_y;
- ellipse_data->radius_x = radius_x;
- ellipse_data->radius_y = radius_y;
+ ellipse->center_x = center_x;
+ ellipse->center_y = center_y;
+ ellipse->radius_x = radius_x;
+ ellipse->radius_y = radius_y;
va_start (var_args, radius_y);
first_property = va_arg (var_args, char*);
@@ -227,53 +127,38 @@ goo_canvas_ellipse_new (GooCanvasItem *parent,
static void
-goo_canvas_ellipse_finalize (GObject *object)
+goo_canvas_ellipse_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
{
- GooCanvasItemSimple *simple = (GooCanvasItemSimple*) object;
GooCanvasEllipse *ellipse = (GooCanvasEllipse*) object;
- /* Free our data if we didn't have a model. (If we had a model it would
- have been reset in dispose() and simple_data will be NULL.) */
- if (simple->simple_data)
- g_slice_free (GooCanvasEllipseData, ellipse->ellipse_data);
- ellipse->ellipse_data = NULL;
-
- G_OBJECT_CLASS (goo_canvas_ellipse_parent_class)->finalize (object);
-}
-
-
-static void
-goo_canvas_ellipse_get_common_property (GObject *object,
- GooCanvasEllipseData *ellipse_data,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
switch (prop_id)
{
case PROP_CENTER_X:
- g_value_set_double (value, ellipse_data->center_x);
+ g_value_set_double (value, ellipse->center_x);
break;
case PROP_CENTER_Y:
- g_value_set_double (value, ellipse_data->center_y);
+ g_value_set_double (value, ellipse->center_y);
break;
case PROP_RADIUS_X:
- g_value_set_double (value, ellipse_data->radius_x);
+ g_value_set_double (value, ellipse->radius_x);
break;
case PROP_RADIUS_Y:
- g_value_set_double (value, ellipse_data->radius_y);
+ g_value_set_double (value, ellipse->radius_y);
break;
case PROP_X:
- g_value_set_double (value, ellipse_data->center_x - ellipse_data->radius_x);
+ g_value_set_double (value, ellipse->center_x - ellipse->radius_x);
break;
case PROP_Y:
- g_value_set_double (value, ellipse_data->center_y - ellipse_data->radius_y);
+ g_value_set_double (value, ellipse->center_y - ellipse->radius_y);
break;
case PROP_WIDTH:
- g_value_set_double (value, 2.0 * ellipse_data->radius_x);
+ g_value_set_double (value, 2.0 * ellipse->radius_x);
break;
case PROP_HEIGHT:
- g_value_set_double (value, 2.0 * ellipse_data->radius_y);
+ g_value_set_double (value, 2.0 * ellipse->radius_y);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -283,71 +168,59 @@ goo_canvas_ellipse_get_common_property (GObject *object,
static void
-goo_canvas_ellipse_get_property (GObject *object,
+goo_canvas_ellipse_set_property (GObject *object,
guint prop_id,
- GValue *value,
+ const GValue *value,
GParamSpec *pspec)
{
+ GooCanvasItemSimple *simple = (GooCanvasItemSimple*) object;
GooCanvasEllipse *ellipse = (GooCanvasEllipse*) object;
-
- goo_canvas_ellipse_get_common_property (object, ellipse->ellipse_data,
- prop_id, value, pspec);
-}
-
-
-static void
-goo_canvas_ellipse_set_common_property (GObject *object,
- GooCanvasEllipseData *ellipse_data,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
gdouble x, y;
switch (prop_id)
{
case PROP_CENTER_X:
- ellipse_data->center_x = g_value_get_double (value);
+ ellipse->center_x = g_value_get_double (value);
g_object_notify (object, "x");
break;
case PROP_CENTER_Y:
- ellipse_data->center_y = g_value_get_double (value);
+ ellipse->center_y = g_value_get_double (value);
g_object_notify (object, "y");
break;
case PROP_RADIUS_X:
- ellipse_data->radius_x = g_value_get_double (value);
+ ellipse->radius_x = g_value_get_double (value);
g_object_notify (object, "width");
break;
case PROP_RADIUS_Y:
- ellipse_data->radius_y = g_value_get_double (value);
+ ellipse->radius_y = g_value_get_double (value);
g_object_notify (object, "height");
break;
case PROP_X:
- ellipse_data->center_x = g_value_get_double (value) + ellipse_data->radius_x;
+ ellipse->center_x = g_value_get_double (value) + ellipse->radius_x;
g_object_notify (object, "center-x");
break;
case PROP_Y:
- ellipse_data->center_y = g_value_get_double (value) + ellipse_data->radius_y;
+ ellipse->center_y = g_value_get_double (value) + ellipse->radius_y;
g_object_notify (object, "center-y");
break;
case PROP_WIDTH:
/* Calculate the current x coordinate. */
- x = ellipse_data->center_x - ellipse_data->radius_x;
+ x = ellipse->center_x - ellipse->radius_x;
/* Calculate the new radius_x, which is half the width. */
- ellipse_data->radius_x = g_value_get_double (value) / 2.0;
+ ellipse->radius_x = g_value_get_double (value) / 2.0;
/* Now calculate the new center_x. */
- ellipse_data->center_x = x + ellipse_data->radius_x;
+ ellipse->center_x = x + ellipse->radius_x;
g_object_notify (object, "center-x");
g_object_notify (object, "radius-x");
break;
case PROP_HEIGHT:
/* Calculate the current y coordinate. */
- y = ellipse_data->center_y - ellipse_data->radius_y;
+ y = ellipse->center_y - ellipse->radius_y;
/* Calculate the new radius_y, which is half the height. */
- ellipse_data->radius_y = g_value_get_double (value) / 2.0;
+ ellipse->radius_y = g_value_get_double (value) / 2.0;
/* Now calculate the new center_y. */
- ellipse_data->center_y = y + ellipse_data->radius_y;
+ ellipse->center_y = y + ellipse->radius_y;
g_object_notify (object, "center-y");
g_object_notify (object, "radius-y");
@@ -356,26 +229,7 @@ goo_canvas_ellipse_set_common_property (GObject *object,
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
-}
-
-static void
-goo_canvas_ellipse_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- GooCanvasItemSimple *simple = (GooCanvasItemSimple*) object;
- GooCanvasEllipse *ellipse = (GooCanvasEllipse*) object;
-
- if (simple->model)
- {
- g_warning ("Can't set property of a canvas item with a model - set the model property instead");
- return;
- }
-
- goo_canvas_ellipse_set_common_property (object, ellipse->ellipse_data,
- prop_id, value, pspec);
goo_canvas_item_simple_changed (simple, TRUE);
}
@@ -385,230 +239,84 @@ goo_canvas_ellipse_create_path (GooCanvasItemSimple *simple,
cairo_t *cr)
{
GooCanvasEllipse *ellipse = (GooCanvasEllipse*) simple;
- GooCanvasEllipseData *ellipse_data = ellipse->ellipse_data;
cairo_new_path (cr);
cairo_save (cr);
- cairo_translate (cr, ellipse_data->center_x, ellipse_data->center_y);
- cairo_scale (cr, ellipse_data->radius_x, ellipse_data->radius_y);
+ cairo_translate (cr, ellipse->center_x, ellipse->center_y);
+ cairo_scale (cr, ellipse->radius_x, ellipse->radius_y);
cairo_arc (cr, 0.0, 0.0, 1.0, 0.0, 2.0 * M_PI);
cairo_restore (cr);
}
-
-static void
-goo_canvas_ellipse_set_model (GooCanvasItem *item,
- GooCanvasItemModel *model)
-{
- GooCanvasItemSimple *simple = (GooCanvasItemSimple*) item;
- GooCanvasEllipse *ellipse = (GooCanvasEllipse*) item;
- GooCanvasEllipseModel *emodel = (GooCanvasEllipseModel*) model;
-
- /* If our ellipse_data was allocated, free it. */
- if (!simple->model)
- g_slice_free (GooCanvasEllipseData, ellipse->ellipse_data);
-
- /* Now use the new model's ellipse_data instead. */
- ellipse->ellipse_data = &emodel->ellipse_data;
-
- /* Let the parent GooCanvasItemSimple code do the rest. */
- goo_canvas_item_simple_set_model (simple, model);
-}
-
-
static void
-canvas_item_interface_init (GooCanvasItemIface *iface)
-{
- iface->set_model = goo_canvas_ellipse_set_model;
-}
-
-
-/**
- * SECTION:goocanvasellipsemodel
- * @Title: GooCanvasEllipseModel
- * @Short_Description: a model for ellipse items.
- *
- * GooCanvasEllipseModel represents a model for ellipse items.
- *
- * It is a subclass of #GooCanvasItemModelSimple and so inherits all of the
- * style properties such as "stroke-color", "fill-color" and "line-width".
- *
- * It also implements the #GooCanvasItemModel interface, so you can use the
- * #GooCanvasItemModel functions such as goo_canvas_item_model_raise() and
- * goo_canvas_item_model_rotate().
- *
- * To create a #GooCanvasEllipseModel use goo_canvas_ellipse_model_new().
- *
- * To get or set the properties of an existing #GooCanvasEllipseModel, use
- * g_object_get() and g_object_set().
- *
- * The ellipse can be specified either with the "center-x", "center-y",
- * "radius-x" and "radius-y" properties, or with the "x", "y", "width" and
- * "height" properties.
- *
- * To respond to events such as mouse clicks on the ellipse you must connect
- * to the signal handlers of the corresponding #GooCanvasEllipse objects.
- * (See goo_canvas_get_item() and #GooCanvas::item-created.)
- */
-
-static void item_model_interface_init (GooCanvasItemModelIface *iface);
-static void goo_canvas_ellipse_model_finalize (GObject *object);
-static void goo_canvas_ellipse_model_get_property (GObject *object,
- guint param_id,
- GValue *value,
- GParamSpec *pspec);
-static void goo_canvas_ellipse_model_set_property (GObject *object,
- guint param_id,
- const GValue *value,
- GParamSpec *pspec);
-
-G_DEFINE_TYPE_WITH_CODE (GooCanvasEllipseModel, goo_canvas_ellipse_model,
- GOO_TYPE_CANVAS_ITEM_MODEL_SIMPLE,
- G_IMPLEMENT_INTERFACE (GOO_TYPE_CANVAS_ITEM_MODEL,
- item_model_interface_init))
-
-
-static void
-goo_canvas_ellipse_model_class_init (GooCanvasEllipseModelClass *klass)
+goo_canvas_ellipse_class_init (GooCanvasEllipseClass *klass)
{
GObjectClass *gobject_class = (GObjectClass*) klass;
+ GooCanvasItemSimpleClass *simple_class = (GooCanvasItemSimpleClass*) klass;
- gobject_class->finalize = goo_canvas_ellipse_model_finalize;
-
- gobject_class->get_property = goo_canvas_ellipse_model_get_property;
- gobject_class->set_property = goo_canvas_ellipse_model_set_property;
-
- goo_canvas_ellipse_install_common_properties (gobject_class);
-}
-
-
-static void
-goo_canvas_ellipse_model_init (GooCanvasEllipseModel *emodel)
-{
-
-}
-
-
-/**
- * goo_canvas_ellipse_model_new:
- * @parent: the parent model, or %NULL. If a parent is specified, it will
- * assume ownership of the item, and the item will automatically be freed when
- * it is removed from the parent. Otherwise call g_object_unref() to free it.
- * @center_x: the x coordinate of the center of the ellipse.
- * @center_y: the y coordinate of the center of the ellipse.
- * @radius_x: the horizontal radius of the ellipse.
- * @radius_y: the vertical radius of the ellipse.
- * @...: optional pairs of property names and values, and a terminating %NULL.
- *
- * Creates a new ellipse model.
- *
- * <!--PARAMETERS-->
- *
- * Here's an example showing how to create an ellipse centered at (100.0,
- * 100.0), with a horizontal radius of 50.0 and a vertical radius of 30.0.
- * It is drawn with a red outline with a width of 5.0 and filled with blue:
- *
- * <informalexample><programlisting>
- * GooCanvasItemModel *ellipse = goo_canvas_ellipse_model_new (mygroup, 100.0, 100.0, 50.0, 30.0,
- * "stroke-color", "red",
- * "line-width", 5.0,
- * "fill-color", "blue",
- * NULL);
- * </programlisting></informalexample>
- *
- * Returns: a new ellipse model.
- **/
-GooCanvasItemModel*
-goo_canvas_ellipse_model_new (GooCanvasItemModel *parent,
- gdouble center_x,
- gdouble center_y,
- gdouble radius_x,
- gdouble radius_y,
- ...)
-{
- GooCanvasItemModel *model;
- GooCanvasEllipseModel *emodel;
- GooCanvasEllipseData *ellipse_data;
- const char *first_property;
- va_list var_args;
-
- model = g_object_new (GOO_TYPE_CANVAS_ELLIPSE_MODEL, NULL);
- emodel = (GooCanvasEllipseModel*) model;
-
- ellipse_data = &emodel->ellipse_data;
- ellipse_data->center_x = center_x;
- ellipse_data->center_y = center_y;
- ellipse_data->radius_x = radius_x;
- ellipse_data->radius_y = radius_y;
-
- va_start (var_args, radius_y);
- first_property = va_arg (var_args, char*);
- if (first_property)
- g_object_set_valist ((GObject*) model, first_property, var_args);
- va_end (var_args);
-
- if (parent)
- {
- goo_canvas_item_model_add_child (parent, model, -1);
- g_object_unref (model);
- }
-
- return model;
-}
-
-
-static void
-goo_canvas_ellipse_model_finalize (GObject *object)
-{
- /*GooCanvasEllipseModel *emodel = (GooCanvasEllipseModel*) object;*/
-
- G_OBJECT_CLASS (goo_canvas_ellipse_model_parent_class)->finalize (object);
-}
-
-
-static void
-goo_canvas_ellipse_model_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- GooCanvasEllipseModel *emodel = (GooCanvasEllipseModel*) object;
-
- goo_canvas_ellipse_get_common_property (object, &emodel->ellipse_data,
- prop_id, value, pspec);
-}
+ gobject_class->get_property = goo_canvas_ellipse_get_property;
+ gobject_class->set_property = goo_canvas_ellipse_set_property;
+ simple_class->simple_create_path = goo_canvas_ellipse_create_path;
-static void
-goo_canvas_ellipse_model_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- GooCanvasEllipseModel *emodel = (GooCanvasEllipseModel*) object;
+ g_object_class_install_property (gobject_class, PROP_CENTER_X,
+ g_param_spec_double ("center-x",
+ _("Center X"),
+ _("The x coordinate of the center of the ellipse"),
+ -G_MAXDOUBLE,
+ G_MAXDOUBLE, 0.0,
+ G_PARAM_READWRITE));
- goo_canvas_ellipse_set_common_property (object, &emodel->ellipse_data,
- prop_id, value, pspec);
- g_signal_emit_by_name (emodel, "changed", TRUE);
-}
+ g_object_class_install_property (gobject_class, PROP_CENTER_Y,
+ g_param_spec_double ("center-y",
+ _("Center Y"),
+ _("The y coordinate of the center of the ellipse"),
+ -G_MAXDOUBLE,
+ G_MAXDOUBLE, 0.0,
+ G_PARAM_READWRITE));
+ g_object_class_install_property (gobject_class, PROP_RADIUS_X,
+ g_param_spec_double ("radius-x",
+ _("Radius X"),
+ _("The horizontal radius of the ellipse"),
+ 0.0, G_MAXDOUBLE, 0.0,
+ G_PARAM_READWRITE));
-static GooCanvasItem*
-goo_canvas_ellipse_model_create_item (GooCanvasItemModel *model,
- GooCanvas *canvas)
-{
- GooCanvasItem *item;
+ g_object_class_install_property (gobject_class, PROP_RADIUS_Y,
+ g_param_spec_double ("radius-y",
+ _("Radius Y"),
+ _("The vertical radius of the ellipse"),
+ 0.0, G_MAXDOUBLE, 0.0,
+ G_PARAM_READWRITE));
- item = g_object_new (GOO_TYPE_CANVAS_ELLIPSE, NULL);
- goo_canvas_item_set_model (item, model);
+ g_object_class_install_property (gobject_class, PROP_X,
+ g_param_spec_double ("x",
+ "X",
+ _("The x coordinate of the left side of the ellipse"),
+ -G_MAXDOUBLE,
+ G_MAXDOUBLE, 0.0,
+ G_PARAM_READWRITE));
- return item;
-}
+ g_object_class_install_property (gobject_class, PROP_Y,
+ g_param_spec_double ("y",
+ "Y",
+ _("The y coordinate of the top of the ellipse"),
+ -G_MAXDOUBLE,
+ G_MAXDOUBLE, 0.0,
+ G_PARAM_READWRITE));
+ g_object_class_install_property (gobject_class, PROP_WIDTH,
+ g_param_spec_double ("width",
+ _("Width"),
+ _("The width of the ellipse"),
+ 0.0, G_MAXDOUBLE, 0.0,
+ G_PARAM_READWRITE));
-static void
-item_model_interface_init (GooCanvasItemModelIface *iface)
-{
- iface->create_item = goo_canvas_ellipse_model_create_item;
+ g_object_class_install_property (gobject_class, PROP_HEIGHT,
+ g_param_spec_double ("height",
+ _("Height"),
+ _("The height of the ellipse"),
+ 0.0, G_MAXDOUBLE, 0.0,
+ G_PARAM_READWRITE));
}
diff --git a/src/goocanvasellipse.h b/src/goocanvasellipse.h
index 0b15263..144e9dc 100644
--- a/src/goocanvasellipse.h
+++ b/src/goocanvasellipse.h
@@ -13,14 +13,6 @@
G_BEGIN_DECLS
-/* This is the data used by both model and view classes. */
-typedef struct _GooCanvasEllipseData GooCanvasEllipseData;
-struct _GooCanvasEllipseData
-{
- gdouble center_x, center_y, radius_x, radius_y;
-};
-
-
#define GOO_TYPE_CANVAS_ELLIPSE (goo_canvas_ellipse_get_type ())
#define GOO_CANVAS_ELLIPSE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GOO_TYPE_CANVAS_ELLIPSE, GooCanvasEllipse))
#define GOO_CANVAS_ELLIPSE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GOO_TYPE_CANVAS_ELLIPSE, GooCanvasEllipseClass))
@@ -41,7 +33,7 @@ struct _GooCanvasEllipse
{
GooCanvasItemSimple parent_object;
- GooCanvasEllipseData *ellipse_data;
+ gdouble center_x, center_y, radius_x, radius_y;
};
struct _GooCanvasEllipseClass
@@ -69,52 +61,6 @@ GooCanvasItem* goo_canvas_ellipse_new (GooCanvasItem *parent,
-#define GOO_TYPE_CANVAS_ELLIPSE_MODEL (goo_canvas_ellipse_model_get_type ())
-#define GOO_CANVAS_ELLIPSE_MODEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GOO_TYPE_CANVAS_ELLIPSE_MODEL, GooCanvasEllipseModel))
-#define GOO_CANVAS_ELLIPSE_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GOO_TYPE_CANVAS_ELLIPSE_MODEL, GooCanvasEllipseModelClass))
-#define GOO_IS_CANVAS_ELLIPSE_MODEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GOO_TYPE_CANVAS_ELLIPSE_MODEL))
-#define GOO_IS_CANVAS_ELLIPSE_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GOO_TYPE_CANVAS_ELLIPSE_MODEL))
-#define GOO_CANVAS_ELLIPSE_MODEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GOO_TYPE_CANVAS_ELLIPSE_MODEL, GooCanvasEllipseModelClass))
-
-
-typedef struct _GooCanvasEllipseModel GooCanvasEllipseModel;
-typedef struct _GooCanvasEllipseModelClass GooCanvasEllipseModelClass;
-
-/**
- * GooCanvasEllipseModel
- *
- * The #GooCanvasEllipseModel-struct struct contains private data only.
- */
-struct _GooCanvasEllipseModel
-{
- GooCanvasItemModelSimple parent_object;
-
- GooCanvasEllipseData ellipse_data;
-};
-
-struct _GooCanvasEllipseModelClass
-{
- GooCanvasItemModelSimpleClass parent_class;
-
- /*< private >*/
-
- /* Padding for future expansion */
- void (*_goo_canvas_reserved1) (void);
- void (*_goo_canvas_reserved2) (void);
- void (*_goo_canvas_reserved3) (void);
- void (*_goo_canvas_reserved4) (void);
-};
-
-
-GType goo_canvas_ellipse_model_get_type (void) G_GNUC_CONST;
-
-GooCanvasItemModel* goo_canvas_ellipse_model_new (GooCanvasItemModel *parent,
- gdouble center_x,
- gdouble center_y,
- gdouble radius_x,
- gdouble radius_y,
- ...);
-
G_END_DECLS
#endif /* __GOO_CANVAS_ELLIPSE_H__ */
diff --git a/src/goocanvasgrid.c b/src/goocanvasgrid.c
index 80190dd..9ecc7f4 100644
--- a/src/goocanvasgrid.c
+++ b/src/goocanvasgrid.c
@@ -90,247 +90,29 @@ enum {
};
-GooCanvasItemIface *goo_canvas_grid_parent_iface;
-
-static void canvas_item_interface_init (GooCanvasItemIface *iface);
-
-G_DEFINE_TYPE_WITH_CODE (GooCanvasGrid, goo_canvas_grid,
- GOO_TYPE_CANVAS_ITEM_SIMPLE,
- G_IMPLEMENT_INTERFACE (GOO_TYPE_CANVAS_ITEM,
- canvas_item_interface_init))
-
-
-static void
-goo_canvas_grid_install_common_properties (GObjectClass *gobject_class)
-{
- g_object_class_install_property (gobject_class, PROP_X,
- g_param_spec_double ("x",
- "X",
- _("The x coordinate of the grid"),
- -G_MAXDOUBLE,
- G_MAXDOUBLE, 0.0,
- G_PARAM_READWRITE));
-
- g_object_class_install_property (gobject_class, PROP_Y,
- g_param_spec_double ("y",
- "Y",
- _("The y coordinate of the grid"),
- -G_MAXDOUBLE,
- G_MAXDOUBLE, 0.0,
- G_PARAM_READWRITE));
-
- g_object_class_install_property (gobject_class, PROP_WIDTH,
- g_param_spec_double ("width",
- _("Width"),
- _("The width of the grid"),
- 0.0, G_MAXDOUBLE, 0.0,
- G_PARAM_READWRITE));
-
- g_object_class_install_property (gobject_class, PROP_HEIGHT,
- g_param_spec_double ("height",
- _("Height"),
- _("The height of the grid"),
- 0.0, G_MAXDOUBLE, 0.0,
- G_PARAM_READWRITE));
-
- g_object_class_install_property (gobject_class, PROP_X_STEP,
- g_param_spec_double ("x-step",
- "X Step",
- _("The distance between the vertical grid lines"),
- 0.0, G_MAXDOUBLE, 10.0,
- G_PARAM_READWRITE));
-
- g_object_class_install_property (gobject_class, PROP_Y_STEP,
- g_param_spec_double ("y-step",
- "Y Step",
- _("The distance between the horizontal grid lines"),
- 0.0, G_MAXDOUBLE, 10.0,
- G_PARAM_READWRITE));
-
- g_object_class_install_property (gobject_class, PROP_X_OFFSET,
- g_param_spec_double ("x-offset",
- "X Offset",
- _("The distance before the first vertical grid line"),
- 0.0, G_MAXDOUBLE, 0.0,
- G_PARAM_READWRITE));
-
- g_object_class_install_property (gobject_class, PROP_Y_OFFSET,
- g_param_spec_double ("y-offset",
- "Y Offset",
- _("The distance before the first horizontal grid line"),
- 0.0, G_MAXDOUBLE, 0.0,
- G_PARAM_READWRITE));
-
- g_object_class_install_property (gobject_class, PROP_HORZ_GRID_LINE_WIDTH,
- g_param_spec_double ("horz-grid-line-width",
- _("Horizontal Grid Line Width"),
- _("The width of the horizontal grid lines"),
- -G_MAXDOUBLE,
- G_MAXDOUBLE, -1.0,
- G_PARAM_READWRITE));
-
- g_object_class_install_property (gobject_class, PROP_VERT_GRID_LINE_WIDTH,
- g_param_spec_double ("vert-grid-line-width",
- _("Vertical Grid Line Width"),
- _("The width of the vertical grid lines"),
- -G_MAXDOUBLE,
- G_MAXDOUBLE, -1.0,
- G_PARAM_READWRITE));
-
- g_object_class_install_property (gobject_class, PROP_HORZ_GRID_LINE_PATTERN,
- g_param_spec_boxed ("horz-grid-line-pattern",
- _("Horizontal Grid Line Pattern"),
- _("The cairo pattern to paint the horizontal grid lines with"),
- GOO_TYPE_CAIRO_PATTERN,
- G_PARAM_READWRITE));
-
- g_object_class_install_property (gobject_class, PROP_VERT_GRID_LINE_PATTERN,
- g_param_spec_boxed ("vert-grid-line-pattern",
- _("Vertical Grid Line Pattern"),
- _("The cairo pattern to paint the vertical grid lines with"),
- GOO_TYPE_CAIRO_PATTERN,
- G_PARAM_READWRITE));
-
- g_object_class_install_property (gobject_class, PROP_BORDER_WIDTH,
- g_param_spec_double ("border-width",
- _("Border Width"),
- _("The width of the border around the grid"),
- -G_MAXDOUBLE,
- G_MAXDOUBLE, -1.0,
- G_PARAM_READWRITE));
-
- g_object_class_install_property (gobject_class, PROP_BORDER_PATTERN,
- g_param_spec_boxed ("border-pattern",
- _("Border Pattern"),
- _("The cairo pattern to paint the border with"),
- GOO_TYPE_CAIRO_PATTERN,
- G_PARAM_READWRITE));
-
- g_object_class_install_property (gobject_class, PROP_SHOW_HORZ_GRID_LINES,
- g_param_spec_boolean ("show-horz-grid-lines",
- _("Show Horizontal Grid Lines"),
- _("If the horizontal grid lines are shown"),
- TRUE,
- G_PARAM_READWRITE));
-
- g_object_class_install_property (gobject_class, PROP_SHOW_VERT_GRID_LINES,
- g_param_spec_boolean ("show-vert-grid-lines",
- _("Show Vertical Grid Lines"),
- _("If the vertical grid lines are shown"),
- TRUE,
- G_PARAM_READWRITE));
-
- g_object_class_install_property (gobject_class, PROP_VERT_GRID_LINES_ON_TOP,
- g_param_spec_boolean ("vert-grid-lines-on-top",
- _("Vertical Grid Lines On Top"),
- _("If the vertical grid lines are painted above the horizontal grid lines"),
- FALSE,
- G_PARAM_READWRITE));
-
-
- /* Convenience properties - some are writable only. */
- g_object_class_install_property (gobject_class, PROP_HORZ_GRID_LINE_COLOR,
- g_param_spec_string ("horz-grid-line-color",
- _("Horizontal Grid Line Color"),
- _("The color to use for the horizontal grid lines"),
- NULL,
- G_PARAM_WRITABLE));
-
- g_object_class_install_property (gobject_class, PROP_HORZ_GRID_LINE_COLOR_RGBA,
- g_param_spec_uint ("horz-grid-line-color-rgba",
- _("Horizontal Grid Line Color RGBA"),
- _("The color to use for the horizontal grid lines, specified as a 32-bit integer value"),
- 0, G_MAXUINT, 0,
- G_PARAM_READWRITE));
-
- g_object_class_install_property (gobject_class, PROP_HORZ_GRID_LINE_PIXBUF,
- g_param_spec_object ("horz-grid-line-pixbuf",
- _("Horizontal Grid Line Pixbuf"),
- _("The pixbuf to use to draw the horizontal grid lines"),
- GDK_TYPE_PIXBUF,
- G_PARAM_WRITABLE));
-
- g_object_class_install_property (gobject_class, PROP_VERT_GRID_LINE_COLOR,
- g_param_spec_string ("vert-grid-line-color",
- _("Vertical Grid Line Color"),
- _("The color to use for the vertical grid lines"),
- NULL,
- G_PARAM_WRITABLE));
-
- g_object_class_install_property (gobject_class, PROP_VERT_GRID_LINE_COLOR_RGBA,
- g_param_spec_uint ("vert-grid-line-color-rgba",
- _("Vertical Grid Line Color RGBA"),
- _("The color to use for the vertical grid lines, specified as a 32-bit integer value"),
- 0, G_MAXUINT, 0,
- G_PARAM_READWRITE));
-
- g_object_class_install_property (gobject_class, PROP_VERT_GRID_LINE_PIXBUF,
- g_param_spec_object ("vert-grid-line-pixbuf",
- _("Vertical Grid Line Pixbuf"),
- _("The pixbuf to use to draw the vertical grid lines"),
- GDK_TYPE_PIXBUF,
- G_PARAM_WRITABLE));
-
- g_object_class_install_property (gobject_class, PROP_BORDER_COLOR,
- g_param_spec_string ("border-color",
- _("Border Color"),
- _("The color to use for the border"),
- NULL,
- G_PARAM_WRITABLE));
-
- g_object_class_install_property (gobject_class, PROP_BORDER_COLOR_RGBA,
- g_param_spec_uint ("border-color-rgba",
- _("Border Color RGBA"),
- _("The color to use for the border, specified as a 32-bit integer value"),
- 0, G_MAXUINT, 0,
- G_PARAM_READWRITE));
-
- g_object_class_install_property (gobject_class, PROP_BORDER_PIXBUF,
- g_param_spec_object ("border-pixbuf",
- _("Border Pixbuf"),
- _("The pixbuf to use to draw the border"),
- GDK_TYPE_PIXBUF,
- G_PARAM_WRITABLE));
-}
-
-
-/* This initializes the common grid data. */
-static void
-goo_canvas_grid_init_data (GooCanvasGridData *grid_data)
-{
- grid_data->x = 0.0;
- grid_data->y = 0.0;
- grid_data->width = 0.0;
- grid_data->height = 0.0;
- grid_data->x_step = 10.0;
- grid_data->y_step = 10.0;
- grid_data->x_offset = 0.0;
- grid_data->y_offset = 0.0;
- grid_data->horz_grid_line_width = -1.0;
- grid_data->vert_grid_line_width = -1.0;
- grid_data->horz_grid_line_pattern = NULL;
- grid_data->vert_grid_line_pattern = NULL;
- grid_data->border_width = -1.0;
- grid_data->border_pattern = NULL;
- grid_data->show_horz_grid_lines = TRUE;
- grid_data->show_vert_grid_lines = TRUE;
- grid_data->vert_grid_lines_on_top = FALSE;
-}
-
-
-/* This frees the contents of the grid data, but not the struct itself. */
-static void
-goo_canvas_grid_free_data (GooCanvasGridData *grid_data)
-{
-
-}
+G_DEFINE_TYPE (GooCanvasGrid, goo_canvas_grid, GOO_TYPE_CANVAS_ITEM_SIMPLE)
static void
goo_canvas_grid_init (GooCanvasGrid *grid)
{
- grid->grid_data = g_slice_new0 (GooCanvasGridData);
- goo_canvas_grid_init_data (grid->grid_data);
+ grid->x = 0.0;
+ grid->y = 0.0;
+ grid->width = 0.0;
+ grid->height = 0.0;
+ grid->x_step = 10.0;
+ grid->y_step = 10.0;
+ grid->x_offset = 0.0;
+ grid->y_offset = 0.0;
+ grid->horz_grid_line_width = -1.0;
+ grid->vert_grid_line_width = -1.0;
+ grid->horz_grid_line_pattern = NULL;
+ grid->vert_grid_line_pattern = NULL;
+ grid->border_width = -1.0;
+ grid->border_pattern = NULL;
+ grid->show_horz_grid_lines = TRUE;
+ grid->show_vert_grid_lines = TRUE;
+ grid->vert_grid_lines_on_top = FALSE;
}
@@ -384,22 +166,20 @@ goo_canvas_grid_new (GooCanvasItem *parent,
{
GooCanvasItem *item;
GooCanvasGrid *grid;
- GooCanvasGridData *grid_data;
va_list var_args;
const char *first_property;
item = g_object_new (GOO_TYPE_CANVAS_GRID, NULL);
grid = (GooCanvasGrid*) item;
- grid_data = grid->grid_data;
- grid_data->x = x;
- grid_data->y = y;
- grid_data->width = width;
- grid_data->height = height;
- grid_data->x_step = x_step;
- grid_data->y_step = y_step;
- grid_data->x_offset = x_offset;
- grid_data->y_offset = y_offset;
+ grid->x = x;
+ grid->y = y;
+ grid->width = width;
+ grid->height = height;
+ grid->x_step = x_step;
+ grid->y_step = y_step;
+ grid->x_offset = x_offset;
+ grid->y_offset = y_offset;
va_start (var_args, y_offset);
first_property = va_arg (var_args, char*);
@@ -418,94 +198,76 @@ goo_canvas_grid_new (GooCanvasItem *parent,
static void
-goo_canvas_grid_finalize (GObject *object)
+goo_canvas_grid_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
{
- GooCanvasItemSimple *simple = (GooCanvasItemSimple*) object;
GooCanvasGrid *grid = (GooCanvasGrid*) object;
- /* Free our data if we didn't have a model. (If we had a model it would
- have been reset in dispose() and simple_data will be NULL.) */
- if (simple->simple_data)
- {
- goo_canvas_grid_free_data (grid->grid_data);
- g_slice_free (GooCanvasGridData, grid->grid_data);
- }
- grid->grid_data = NULL;
-
- G_OBJECT_CLASS (goo_canvas_grid_parent_class)->finalize (object);
-}
-
-
-static void
-goo_canvas_grid_get_common_property (GObject *object,
- GooCanvasGridData *grid_data,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
switch (prop_id)
{
case PROP_X:
- g_value_set_double (value, grid_data->x);
+ g_value_set_double (value, grid->x);
break;
case PROP_Y:
- g_value_set_double (value, grid_data->y);
+ g_value_set_double (value, grid->y);
break;
case PROP_WIDTH:
- g_value_set_double (value, grid_data->width);
+ g_value_set_double (value, grid->width);
break;
case PROP_HEIGHT:
- g_value_set_double (value, grid_data->height);
+ g_value_set_double (value, grid->height);
break;
case PROP_X_STEP:
- g_value_set_double (value, grid_data->x_step);
+ g_value_set_double (value, grid->x_step);
break;
case PROP_Y_STEP:
- g_value_set_double (value, grid_data->y_step);
+ g_value_set_double (value, grid->y_step);
break;
case PROP_X_OFFSET:
- g_value_set_double (value, grid_data->x_offset);
+ g_value_set_double (value, grid->x_offset);
break;
case PROP_Y_OFFSET:
- g_value_set_double (value, grid_data->y_offset);
+ g_value_set_double (value, grid->y_offset);
break;
case PROP_HORZ_GRID_LINE_WIDTH:
- g_value_set_double (value, grid_data->horz_grid_line_width);
+ g_value_set_double (value, grid->horz_grid_line_width);
break;
case PROP_VERT_GRID_LINE_WIDTH:
- g_value_set_double (value, grid_data->vert_grid_line_width);
+ g_value_set_double (value, grid->vert_grid_line_width);
break;
case PROP_HORZ_GRID_LINE_PATTERN:
- g_value_set_boxed (value, grid_data->horz_grid_line_pattern);
+ g_value_set_boxed (value, grid->horz_grid_line_pattern);
break;
case PROP_VERT_GRID_LINE_PATTERN:
- g_value_set_boxed (value, grid_data->vert_grid_line_pattern);
+ g_value_set_boxed (value, grid->vert_grid_line_pattern);
break;
case PROP_BORDER_WIDTH:
- g_value_set_double (value, grid_data->border_width);
+ g_value_set_double (value, grid->border_width);
break;
case PROP_BORDER_PATTERN:
- g_value_set_boxed (value, grid_data->border_pattern);
+ g_value_set_boxed (value, grid->border_pattern);
break;
case PROP_SHOW_HORZ_GRID_LINES:
- g_value_set_boolean (value, grid_data->show_horz_grid_lines);
+ g_value_set_boolean (value, grid->show_horz_grid_lines);
break;
case PROP_SHOW_VERT_GRID_LINES:
- g_value_set_boolean (value, grid_data->show_vert_grid_lines);
+ g_value_set_boolean (value, grid->show_vert_grid_lines);
break;
case PROP_VERT_GRID_LINES_ON_TOP:
- g_value_set_boolean (value, grid_data->vert_grid_lines_on_top);
+ g_value_set_boolean (value, grid->vert_grid_lines_on_top);
break;
/* Convenience properties. */
case PROP_HORZ_GRID_LINE_COLOR_RGBA:
- goo_canvas_get_rgba_value_from_pattern (grid_data->horz_grid_line_pattern, value);
+ goo_canvas_get_rgba_value_from_pattern (grid->horz_grid_line_pattern, value);
break;
case PROP_VERT_GRID_LINE_COLOR_RGBA:
- goo_canvas_get_rgba_value_from_pattern (grid_data->vert_grid_line_pattern, value);
+ goo_canvas_get_rgba_value_from_pattern (grid->vert_grid_line_pattern, value);
break;
case PROP_BORDER_COLOR_RGBA:
- goo_canvas_get_rgba_value_from_pattern (grid_data->border_pattern, value);
+ goo_canvas_get_rgba_value_from_pattern (grid->border_pattern, value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -515,149 +277,119 @@ goo_canvas_grid_get_common_property (GObject *object,
static void
-goo_canvas_grid_get_property (GObject *object,
+goo_canvas_grid_set_property (GObject *object,
guint prop_id,
- GValue *value,
+ const GValue *value,
GParamSpec *pspec)
{
+ GooCanvasItemSimple *simple = (GooCanvasItemSimple*) object;
GooCanvasGrid *grid = (GooCanvasGrid*) object;
- goo_canvas_grid_get_common_property (object, grid->grid_data,
- prop_id, value, pspec);
-}
-
-
-static void
-goo_canvas_grid_set_common_property (GObject *object,
- GooCanvasGridData *grid_data,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
switch (prop_id)
{
case PROP_X:
- grid_data->x = g_value_get_double (value);
+ grid->x = g_value_get_double (value);
break;
case PROP_Y:
- grid_data->y = g_value_get_double (value);
+ grid->y = g_value_get_double (value);
break;
case PROP_WIDTH:
- grid_data->width = g_value_get_double (value);
+ grid->width = g_value_get_double (value);
break;
case PROP_HEIGHT:
- grid_data->height = g_value_get_double (value);
+ grid->height = g_value_get_double (value);
break;
case PROP_X_STEP:
- grid_data->x_step = g_value_get_double (value);
+ grid->x_step = g_value_get_double (value);
break;
case PROP_Y_STEP:
- grid_data->y_step = g_value_get_double (value);
+ grid->y_step = g_value_get_double (value);
break;
case PROP_X_OFFSET:
- grid_data->x_offset = g_value_get_double (value);
+ grid->x_offset = g_value_get_double (value);
break;
case PROP_Y_OFFSET:
- grid_data->y_offset = g_value_get_double (value);
+ grid->y_offset = g_value_get_double (value);
break;
case PROP_HORZ_GRID_LINE_WIDTH:
- grid_data->horz_grid_line_width = g_value_get_double (value);
+ grid->horz_grid_line_width = g_value_get_double (value);
break;
case PROP_VERT_GRID_LINE_WIDTH:
- grid_data->vert_grid_line_width = g_value_get_double (value);
+ grid->vert_grid_line_width = g_value_get_double (value);
break;
case PROP_HORZ_GRID_LINE_PATTERN:
- cairo_pattern_destroy (grid_data->horz_grid_line_pattern);
- grid_data->horz_grid_line_pattern = g_value_get_boxed (value);
- cairo_pattern_reference (grid_data->horz_grid_line_pattern);
+ cairo_pattern_destroy (grid->horz_grid_line_pattern);
+ grid->horz_grid_line_pattern = g_value_get_boxed (value);
+ cairo_pattern_reference (grid->horz_grid_line_pattern);
break;
case PROP_VERT_GRID_LINE_PATTERN:
- cairo_pattern_destroy (grid_data->vert_grid_line_pattern);
- grid_data->vert_grid_line_pattern = g_value_get_boxed (value);
- cairo_pattern_reference (grid_data->vert_grid_line_pattern);
+ cairo_pattern_destroy (grid->vert_grid_line_pattern);
+ grid->vert_grid_line_pattern = g_value_get_boxed (value);
+ cairo_pattern_reference (grid->vert_grid_line_pattern);
break;
case PROP_BORDER_WIDTH:
- grid_data->border_width = g_value_get_double (value);
+ grid->border_width = g_value_get_double (value);
break;
case PROP_BORDER_PATTERN:
- cairo_pattern_destroy (grid_data->border_pattern);
- grid_data->border_pattern = g_value_get_boxed (value);
- cairo_pattern_reference (grid_data->border_pattern);
+ cairo_pattern_destroy (grid->border_pattern);
+ grid->border_pattern = g_value_get_boxed (value);
+ cairo_pattern_reference (grid->border_pattern);
break;
case PROP_SHOW_HORZ_GRID_LINES:
- grid_data->show_horz_grid_lines = g_value_get_boolean (value);
+ grid->show_horz_grid_lines = g_value_get_boolean (value);
break;
case PROP_SHOW_VERT_GRID_LINES:
- grid_data->show_vert_grid_lines = g_value_get_boolean (value);
+ grid->show_vert_grid_lines = g_value_get_boolean (value);
break;
case PROP_VERT_GRID_LINES_ON_TOP:
- grid_data->vert_grid_lines_on_top = g_value_get_boolean (value);
+ grid->vert_grid_lines_on_top = g_value_get_boolean (value);
break;
/* Convenience properties. */
case PROP_HORZ_GRID_LINE_COLOR:
- cairo_pattern_destroy (grid_data->horz_grid_line_pattern);
- grid_data->horz_grid_line_pattern = goo_canvas_create_pattern_from_color_value (value);
+ cairo_pattern_destroy (grid->horz_grid_line_pattern);
+ grid->horz_grid_line_pattern = goo_canvas_create_pattern_from_color_value (value);
break;
case PROP_HORZ_GRID_LINE_COLOR_RGBA:
- cairo_pattern_destroy (grid_data->horz_grid_line_pattern);
- grid_data->horz_grid_line_pattern = goo_canvas_create_pattern_from_rgba_value (value);
+ cairo_pattern_destroy (grid->horz_grid_line_pattern);
+ grid->horz_grid_line_pattern = goo_canvas_create_pattern_from_rgba_value (value);
break;
case PROP_HORZ_GRID_LINE_PIXBUF:
- cairo_pattern_destroy (grid_data->horz_grid_line_pattern);
- grid_data->horz_grid_line_pattern = goo_canvas_create_pattern_from_pixbuf_value (value);
+ cairo_pattern_destroy (grid->horz_grid_line_pattern);
+ grid->horz_grid_line_pattern = goo_canvas_create_pattern_from_pixbuf_value (value);
break;
case PROP_VERT_GRID_LINE_COLOR:
- cairo_pattern_destroy (grid_data->vert_grid_line_pattern);
- grid_data->vert_grid_line_pattern = goo_canvas_create_pattern_from_color_value (value);
+ cairo_pattern_destroy (grid->vert_grid_line_pattern);
+ grid->vert_grid_line_pattern = goo_canvas_create_pattern_from_color_value (value);
break;
case PROP_VERT_GRID_LINE_COLOR_RGBA:
- cairo_pattern_destroy (grid_data->vert_grid_line_pattern);
- grid_data->vert_grid_line_pattern = goo_canvas_create_pattern_from_rgba_value (value);
+ cairo_pattern_destroy (grid->vert_grid_line_pattern);
+ grid->vert_grid_line_pattern = goo_canvas_create_pattern_from_rgba_value (value);
break;
case PROP_VERT_GRID_LINE_PIXBUF:
- cairo_pattern_destroy (grid_data->vert_grid_line_pattern);
- grid_data->vert_grid_line_pattern = goo_canvas_create_pattern_from_pixbuf_value (value);
+ cairo_pattern_destroy (grid->vert_grid_line_pattern);
+ grid->vert_grid_line_pattern = goo_canvas_create_pattern_from_pixbuf_value (value);
break;
case PROP_BORDER_COLOR:
- cairo_pattern_destroy (grid_data->border_pattern);
- grid_data->border_pattern = goo_canvas_create_pattern_from_color_value (value);
+ cairo_pattern_destroy (grid->border_pattern);
+ grid->border_pattern = goo_canvas_create_pattern_from_color_value (value);
break;
case PROP_BORDER_COLOR_RGBA:
- cairo_pattern_destroy (grid_data->border_pattern);
- grid_data->border_pattern = goo_canvas_create_pattern_from_rgba_value (value);
+ cairo_pattern_destroy (grid->border_pattern);
+ grid->border_pattern = goo_canvas_create_pattern_from_rgba_value (value);
break;
case PROP_BORDER_PIXBUF:
- cairo_pattern_destroy (grid_data->border_pattern);
- grid_data->border_pattern = goo_canvas_create_pattern_from_pixbuf_value (value);
+ cairo_pattern_destroy (grid->border_pattern);
+ grid->border_pattern = goo_canvas_create_pattern_from_pixbuf_value (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
-}
-
-
-static void
-goo_canvas_grid_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- GooCanvasItemSimple *simple = (GooCanvasItemSimple*) object;
- GooCanvasGrid *grid = (GooCanvasGrid*) object;
-
- if (simple->model)
- {
- g_warning ("Can't set property of a canvas item with a model - set the model property instead");
- return;
- }
- goo_canvas_grid_set_common_property (object, grid->grid_data,
- prop_id, value, pspec);
goo_canvas_item_simple_changed (simple, TRUE);
}
@@ -667,18 +399,17 @@ goo_canvas_grid_update (GooCanvasItemSimple *simple,
cairo_t *cr)
{
GooCanvasGrid *grid = (GooCanvasGrid*) simple;
- GooCanvasGridData *grid_data = grid->grid_data;
gdouble border_width = 0.0;
/* We can quickly compute the bounds as being just the grid's size
plus the border width around each edge. */
- if (grid_data->border_width > 0.0)
- border_width = grid_data->border_width;
+ if (grid->border_width > 0.0)
+ border_width = grid->border_width;
- simple->bounds.x1 = grid_data->x - border_width;
- simple->bounds.y1 = grid_data->y - border_width;
- simple->bounds.x2 = grid_data->x + grid_data->width + border_width;
- simple->bounds.y2 = grid_data->y + grid_data->height + border_width;
+ simple->bounds.x1 = grid->x - border_width;
+ simple->bounds.y1 = grid->y - border_width;
+ simple->bounds.x2 = grid->x + grid->width + border_width;
+ simple->bounds.y2 = grid->y + grid->height + border_width;
}
@@ -711,59 +442,57 @@ paint_vertical_lines (GooCanvasItemSimple *simple,
cairo_t *cr,
const GooCanvasBounds *bounds)
{
- GooCanvasItemSimpleData *simple_data = simple->simple_data;
GooCanvasGrid *grid = (GooCanvasGrid*) simple;
- GooCanvasGridData *grid_data = grid->grid_data;
double x, max_x, max_y, max_bounds_x, line_width;
gboolean has_stroke;
- if (!grid_data->show_vert_grid_lines)
+ if (!grid->show_vert_grid_lines)
return;
- max_x = grid_data->x + grid_data->width;
- max_y = grid_data->y + grid_data->height;
+ max_x = grid->x + grid->width;
+ max_y = grid->y + grid->height;
- has_stroke = goo_canvas_style_set_stroke_options (simple_data->style, cr);
+ has_stroke = goo_canvas_style_set_stroke_options (simple->style, cr);
line_width = goo_canvas_item_simple_get_line_width (simple);
/* If the grid's vertical grid line pattern/color has been set, use that.
If not, and we don't have a stroke color just return. */
- if (grid_data->vert_grid_line_pattern)
- cairo_set_source (cr, grid_data->vert_grid_line_pattern);
+ if (grid->vert_grid_line_pattern)
+ cairo_set_source (cr, grid->vert_grid_line_pattern);
else if (!has_stroke)
return;
/* If the grid's vertical grid line width has been set, use that. */
- if (grid_data->vert_grid_line_width > 0.0)
+ if (grid->vert_grid_line_width > 0.0)
{
- line_width = grid_data->vert_grid_line_width;
+ line_width = grid->vert_grid_line_width;
cairo_set_line_width (cr, line_width);
}
cairo_set_line_cap (cr, CAIRO_LINE_CAP_BUTT);
/* Calculate the first grid line that intersects the bounds to redraw. */
- x = calculate_start_position (grid_data->x + grid_data->x_offset,
- grid_data->x_step, bounds->x1, line_width);
+ x = calculate_start_position (grid->x + grid->x_offset,
+ grid->x_step, bounds->x1, line_width);
/* Calculate the last possible line position. */
max_bounds_x = bounds->x2 + (line_width / 2.0);
max_x = MIN (max_x, max_bounds_x);
/* Add on a tiny fraction of step to avoid any double comparison issues. */
- max_x += grid_data->x_step * 0.00001;
+ max_x += grid->x_step * 0.00001;
while (x <= max_x)
{
- cairo_move_to (cr, x, grid_data->y);
+ cairo_move_to (cr, x, grid->y);
cairo_line_to (cr, x, max_y);
cairo_stroke (cr);
/* Avoid an infinite loop. */
- if (grid_data->x_step <= 0.0)
+ if (grid->x_step <= 0.0)
break;
- x += grid_data->x_step;
+ x += grid->x_step;
}
}
@@ -773,59 +502,57 @@ paint_horizontal_lines (GooCanvasItemSimple *simple,
cairo_t *cr,
const GooCanvasBounds *bounds)
{
- GooCanvasItemSimpleData *simple_data = simple->simple_data;
GooCanvasGrid *grid = (GooCanvasGrid*) simple;
- GooCanvasGridData *grid_data = grid->grid_data;
double y, max_x, max_y, max_bounds_y, line_width;
gboolean has_stroke;
- if (!grid_data->show_horz_grid_lines)
+ if (!grid->show_horz_grid_lines)
return;
- max_x = grid_data->x + grid_data->width;
- max_y = grid_data->y + grid_data->height;
+ max_x = grid->x + grid->width;
+ max_y = grid->y + grid->height;
- has_stroke = goo_canvas_style_set_stroke_options (simple_data->style, cr);
+ has_stroke = goo_canvas_style_set_stroke_options (simple->style, cr);
line_width = goo_canvas_item_simple_get_line_width (simple);
/* If the grid's horizontal grid line pattern/color has been set, use that.
If not, and we don't have a stroke color just return. */
- if (grid_data->horz_grid_line_pattern)
- cairo_set_source (cr, grid_data->horz_grid_line_pattern);
+ if (grid->horz_grid_line_pattern)
+ cairo_set_source (cr, grid->horz_grid_line_pattern);
else if (!has_stroke)
return;
/* If the grid's horizontal grid line width has been set, use that. */
- if (grid_data->horz_grid_line_width > 0.0)
+ if (grid->horz_grid_line_width > 0.0)
{
- line_width = grid_data->horz_grid_line_width;
- cairo_set_line_width (cr, grid_data->horz_grid_line_width);
+ line_width = grid->horz_grid_line_width;
+ cairo_set_line_width (cr, grid->horz_grid_line_width);
}
cairo_set_line_cap (cr, CAIRO_LINE_CAP_BUTT);
/* Calculate the first grid line that intersects the bounds to redraw. */
- y = calculate_start_position (grid_data->y + grid_data->y_offset,
- grid_data->y_step, bounds->y1, line_width);
+ y = calculate_start_position (grid->y + grid->y_offset,
+ grid->y_step, bounds->y1, line_width);
/* Calculate the last possible line position. */
max_bounds_y = bounds->y2 + (line_width / 2.0);
max_y = MIN (max_y, max_bounds_y);
/* Add on a tiny fraction of step to avoid any double comparison issues. */
- max_y += grid_data->y_step * 0.00001;
+ max_y += grid->y_step * 0.00001;
while (y <= max_y)
{
- cairo_move_to (cr, grid_data->x, y);
+ cairo_move_to (cr, grid->x, y);
cairo_line_to (cr, max_x, y);
cairo_stroke (cr);
/* Avoid an infinite loop. */
- if (grid_data->y_step <= 0.0)
+ if (grid->y_step <= 0.0)
break;
- y += grid_data->y_step;
+ y += grid->y_step;
}
}
@@ -835,24 +562,22 @@ goo_canvas_grid_paint (GooCanvasItemSimple *simple,
cairo_t *cr,
const GooCanvasBounds *bounds)
{
- GooCanvasItemSimpleData *simple_data = simple->simple_data;
GooCanvasGrid *grid = (GooCanvasGrid*) simple;
- GooCanvasGridData *grid_data = grid->grid_data;
GooCanvasBounds redraw_bounds = *bounds;
gdouble half_border_width;
/* Paint the background in the fill pattern/color, if one is set. */
- if (goo_canvas_style_set_fill_options (simple_data->style, cr))
+ if (goo_canvas_style_set_fill_options (simple->style, cr))
{
- cairo_rectangle (cr, grid_data->x, grid_data->y,
- grid_data->width, grid_data->height);
+ cairo_rectangle (cr, grid->x, grid->y,
+ grid->width, grid->height);
cairo_fill (cr);
}
/* Clip to the grid's area while painting the grid lines. */
cairo_save (cr);
- cairo_rectangle (cr, grid_data->x, grid_data->y,
- grid_data->width, grid_data->height);
+ cairo_rectangle (cr, grid->x, grid->y,
+ grid->width, grid->height);
cairo_clip (cr);
/* Convert the bounds to be redrawn from device space to item space. */
@@ -861,7 +586,7 @@ goo_canvas_grid_paint (GooCanvasItemSimple *simple,
&redraw_bounds);
/* Paint the grid lines, in the required order. */
- if (grid_data->vert_grid_lines_on_top)
+ if (grid->vert_grid_lines_on_top)
{
paint_horizontal_lines (simple, cr, &redraw_bounds);
paint_vertical_lines (simple, cr, &redraw_bounds);
@@ -875,296 +600,223 @@ goo_canvas_grid_paint (GooCanvasItemSimple *simple,
cairo_restore (cr);
/* Paint the border. */
- if (grid_data->border_width > 0)
+ if (grid->border_width > 0)
{
- if (grid_data->border_pattern)
- cairo_set_source (cr, grid_data->border_pattern);
+ if (grid->border_pattern)
+ cairo_set_source (cr, grid->border_pattern);
else
- goo_canvas_style_set_stroke_options (simple_data->style, cr);
-
- cairo_set_line_width (cr, grid_data->border_width);
- half_border_width = grid_data->border_width / 2.0;
- cairo_rectangle (cr, grid_data->x - half_border_width,
- grid_data->y - half_border_width,
- grid_data->width + grid_data->border_width,
- grid_data->height + grid_data->border_width);
+ goo_canvas_style_set_stroke_options (simple->style, cr);
+
+ cairo_set_line_width (cr, grid->border_width);
+ half_border_width = grid->border_width / 2.0;
+ cairo_rectangle (cr, grid->x - half_border_width,
+ grid->y - half_border_width,
+ grid->width + grid->border_width,
+ grid->height + grid->border_width);
cairo_stroke (cr);
}
}
static void
-goo_canvas_grid_set_model (GooCanvasItem *item,
- GooCanvasItemModel *model)
-{
- GooCanvasItemSimple *simple = (GooCanvasItemSimple*) item;
- GooCanvasGrid *grid = (GooCanvasGrid*) item;
- GooCanvasGridModel *gmodel = (GooCanvasGridModel*) model;
-
- /* If our grid_data was allocated, free it. */
- if (!simple->model)
- {
- goo_canvas_grid_free_data (grid->grid_data);
- g_slice_free (GooCanvasGridData, grid->grid_data);
- }
-
- /* Now use the new model's grid_data instead. */
- grid->grid_data = &gmodel->grid_data;
-
- /* Let the parent class do the rest. */
- goo_canvas_grid_parent_iface->set_model (item, model);
-}
-
-
-static void
-canvas_item_interface_init (GooCanvasItemIface *iface)
-{
- iface->set_model = goo_canvas_grid_set_model;
-}
-
-
-static void
goo_canvas_grid_class_init (GooCanvasGridClass *klass)
{
GObjectClass *gobject_class = (GObjectClass*) klass;
GooCanvasItemSimpleClass *simple_class = (GooCanvasItemSimpleClass*) klass;
- goo_canvas_grid_parent_iface = g_type_interface_peek (goo_canvas_grid_parent_class, GOO_TYPE_CANVAS_ITEM);
-
- gobject_class->finalize = goo_canvas_grid_finalize;
-
gobject_class->get_property = goo_canvas_grid_get_property;
gobject_class->set_property = goo_canvas_grid_set_property;
simple_class->simple_update = goo_canvas_grid_update;
simple_class->simple_paint = goo_canvas_grid_paint;
- goo_canvas_grid_install_common_properties (gobject_class);
-}
-
-
-
-/**
- * SECTION:goocanvasgridmodel
- * @Title: GooCanvasGridModel
- * @Short_Description: a model for grid items.
- *
- * GooCanvasGridModel represents a model for grid items.
- * A grid consists of a number of equally-spaced horizontal and vertical
- * grid lines, plus an optional border.
- *
- * It is a subclass of #GooCanvasItemModelSimple and so inherits all of the
- * style properties such as "stroke-color", "fill-color" and "line-width".
- *
- * It also implements the #GooCanvasItemModel interface, so you can use the
- * #GooCanvasItemModel functions such as goo_canvas_item_model_raise() and
- * goo_canvas_item_model_rotate().
- *
- * To create a #GooCanvasGridModel use goo_canvas_grid_model_new().
- *
- * To get or set the properties of an existing #GooCanvasGridModel, use
- * g_object_get() and g_object_set().
- *
- * To respond to events such as mouse clicks on the grid you must connect
- * to the signal handlers of the corresponding #GooCanvasGrid objects.
- * (See goo_canvas_get_item() and #GooCanvas::item-created.)
- *
- * The grid's position and size is specified with the #GooCanvasGridModel:x,
- * #GooCanvasGridModel:y, #GooCanvasGridModel:width and
- * #GooCanvasGridModel:height properties.
- *
- * The #GooCanvasGridModel:x-step and #GooCanvasGridModel:y-step properties
- * specify the distance between grid lines. The #GooCanvasGridModel:x-offset
- * and #GooCanvasGridModel:y-offset properties specify the distance before the
- * first grid lines.
- *
- * The horizontal or vertical grid lines can be hidden using the
- * #GooCanvasGridModel:show-horz-grid-lines and
- * #GooCanvasGridModel:show-vert-grid-lines properties.
- *
- * The width of the border can be set using the #GooCanvasGridModel:border-width
- * property. The border is drawn outside the area specified with the
- * #GooCanvasGridModel:x, #GooCanvasGridModel:y, #GooCanvasGridModel:width and
- * #GooCanvasGridModel:height properties.
- *
- * Other properties allow the colors and widths of the grid lines to be set.
- * The grid line color and width properties override the standard
- * #GooCanvasItemModelSimple:stroke-color and
- * #GooCanvasItemModelSimple:line-width properties, enabling different styles
- * for horizontal and vertical grid lines.
- */
-
-GooCanvasItemModelIface *goo_canvas_grid_model_parent_iface;
-
-static void item_model_interface_init (GooCanvasItemModelIface *iface);
-
-G_DEFINE_TYPE_WITH_CODE (GooCanvasGridModel, goo_canvas_grid_model,
- GOO_TYPE_CANVAS_ITEM_MODEL_SIMPLE,
- G_IMPLEMENT_INTERFACE (GOO_TYPE_CANVAS_ITEM_MODEL,
- item_model_interface_init))
-
-
-static void
-goo_canvas_grid_model_init (GooCanvasGridModel *gmodel)
-{
- goo_canvas_grid_init_data (&gmodel->grid_data);
-}
-
-
-/**
- * goo_canvas_grid_model_new:
- * @parent: the parent model, or %NULL. If a parent is specified, it will assume
- * ownership of the item, and the item will automatically be freed when it is
- * removed from the parent. Otherwise call g_object_unref() to free it.
- * @x: the x coordinate of the left of the grid.
- * @y: the y coordinate of the top of the grid.
- * @width: the width of the grid.
- * @height: the height of the grid.
- * @x_step: the distance between the vertical grid lines.
- * @y_step: the distance between the horizontal grid lines.
- * @x_offset: the distance before the first vertical grid line.
- * @y_offset: the distance before the first horizontal grid line.
- * @...: optional pairs of property names and values, and a terminating %NULL.
- *
- * Creates a new grid model.
- *
- * <!--PARAMETERS-->
- *
- * Here's an example showing how to create a grid:
- *
- * <informalexample><programlisting>
- * GooCanvasItemModel *grid = goo_canvas_grid_model_new (mygroup, 100.0, 100.0, 400.0, 200.0,
- * 20.0, 20.0, 10.0, 10.0,
- * "horz-grid-line-width", 4.0,
- * "horz-grid-line-color", "yellow",
- * "vert-grid-line-width", 2.0,
- * "vert-grid-line-color", "red",
- * "border-width", 3.0,
- * "border-color", "white",
- * "fill-color", "blue",
- * NULL);
- * </programlisting></informalexample>
- *
- * Returns: a new grid model.
- **/
-GooCanvasItemModel*
-goo_canvas_grid_model_new (GooCanvasItemModel *parent,
- gdouble x,
- gdouble y,
- gdouble width,
- gdouble height,
- gdouble x_step,
- gdouble y_step,
- gdouble x_offset,
- gdouble y_offset,
- ...)
-{
- GooCanvasItemModel *model;
- GooCanvasGridModel *gmodel;
- GooCanvasGridData *grid_data;
- const char *first_property;
- va_list var_args;
-
- model = g_object_new (GOO_TYPE_CANVAS_GRID_MODEL, NULL);
- gmodel = (GooCanvasGridModel*) model;
+ g_object_class_install_property (gobject_class, PROP_X,
+ g_param_spec_double ("x",
+ "X",
+ _("The x coordinate of the grid"),
+ -G_MAXDOUBLE,
+ G_MAXDOUBLE, 0.0,
+ G_PARAM_READWRITE));
- grid_data = &gmodel->grid_data;
- grid_data->x = x;
- grid_data->y = y;
- grid_data->width = width;
- grid_data->height = height;
- grid_data->x_step = x_step;
- grid_data->y_step = y_step;
- grid_data->x_offset = x_offset;
- grid_data->y_offset = y_offset;
+ g_object_class_install_property (gobject_class, PROP_Y,
+ g_param_spec_double ("y",
+ "Y",
+ _("The y coordinate of the grid"),
+ -G_MAXDOUBLE,
+ G_MAXDOUBLE, 0.0,
+ G_PARAM_READWRITE));
- va_start (var_args, y_offset);
- first_property = va_arg (var_args, char*);
- if (first_property)
- g_object_set_valist ((GObject*) model, first_property, var_args);
- va_end (var_args);
+ g_object_class_install_property (gobject_class, PROP_WIDTH,
+ g_param_spec_double ("width",
+ _("Width"),
+ _("The width of the grid"),
+ 0.0, G_MAXDOUBLE, 0.0,
+ G_PARAM_READWRITE));
- if (parent)
- {
- goo_canvas_item_model_add_child (parent, model, -1);
- g_object_unref (model);
- }
+ g_object_class_install_property (gobject_class, PROP_HEIGHT,
+ g_param_spec_double ("height",
+ _("Height"),
+ _("The height of the grid"),
+ 0.0, G_MAXDOUBLE, 0.0,
+ G_PARAM_READWRITE));
- return model;
-}
+ g_object_class_install_property (gobject_class, PROP_X_STEP,
+ g_param_spec_double ("x-step",
+ "X Step",
+ _("The distance between the vertical grid lines"),
+ 0.0, G_MAXDOUBLE, 10.0,
+ G_PARAM_READWRITE));
+ g_object_class_install_property (gobject_class, PROP_Y_STEP,
+ g_param_spec_double ("y-step",
+ "Y Step",
+ _("The distance between the horizontal grid lines"),
+ 0.0, G_MAXDOUBLE, 10.0,
+ G_PARAM_READWRITE));
-static void
-goo_canvas_grid_model_finalize (GObject *object)
-{
- GooCanvasGridModel *gmodel = (GooCanvasGridModel*) object;
+ g_object_class_install_property (gobject_class, PROP_X_OFFSET,
+ g_param_spec_double ("x-offset",
+ "X Offset",
+ _("The distance before the first vertical grid line"),
+ 0.0, G_MAXDOUBLE, 0.0,
+ G_PARAM_READWRITE));
- goo_canvas_grid_free_data (&gmodel->grid_data);
+ g_object_class_install_property (gobject_class, PROP_Y_OFFSET,
+ g_param_spec_double ("y-offset",
+ "Y Offset",
+ _("The distance before the first horizontal grid line"),
+ 0.0, G_MAXDOUBLE, 0.0,
+ G_PARAM_READWRITE));
- G_OBJECT_CLASS (goo_canvas_grid_model_parent_class)->finalize (object);
-}
+ g_object_class_install_property (gobject_class, PROP_HORZ_GRID_LINE_WIDTH,
+ g_param_spec_double ("horz-grid-line-width",
+ _("Horizontal Grid Line Width"),
+ _("The width of the horizontal grid lines"),
+ -G_MAXDOUBLE,
+ G_MAXDOUBLE, -1.0,
+ G_PARAM_READWRITE));
+ g_object_class_install_property (gobject_class, PROP_VERT_GRID_LINE_WIDTH,
+ g_param_spec_double ("vert-grid-line-width",
+ _("Vertical Grid Line Width"),
+ _("The width of the vertical grid lines"),
+ -G_MAXDOUBLE,
+ G_MAXDOUBLE, -1.0,
+ G_PARAM_READWRITE));
-static void
-goo_canvas_grid_model_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- GooCanvasGridModel *gmodel = (GooCanvasGridModel*) object;
+ g_object_class_install_property (gobject_class, PROP_HORZ_GRID_LINE_PATTERN,
+ g_param_spec_boxed ("horz-grid-line-pattern",
+ _("Horizontal Grid Line Pattern"),
+ _("The cairo pattern to paint the horizontal grid lines with"),
+ GOO_TYPE_CAIRO_PATTERN,
+ G_PARAM_READWRITE));
- goo_canvas_grid_get_common_property (object, &gmodel->grid_data,
- prop_id, value, pspec);
-}
+ g_object_class_install_property (gobject_class, PROP_VERT_GRID_LINE_PATTERN,
+ g_param_spec_boxed ("vert-grid-line-pattern",
+ _("Vertical Grid Line Pattern"),
+ _("The cairo pattern to paint the vertical grid lines with"),
+ GOO_TYPE_CAIRO_PATTERN,
+ G_PARAM_READWRITE));
+ g_object_class_install_property (gobject_class, PROP_BORDER_WIDTH,
+ g_param_spec_double ("border-width",
+ _("Border Width"),
+ _("The width of the border around the grid"),
+ -G_MAXDOUBLE,
+ G_MAXDOUBLE, -1.0,
+ G_PARAM_READWRITE));
-static void
-goo_canvas_grid_model_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- GooCanvasGridModel *gmodel = (GooCanvasGridModel*) object;
+ g_object_class_install_property (gobject_class, PROP_BORDER_PATTERN,
+ g_param_spec_boxed ("border-pattern",
+ _("Border Pattern"),
+ _("The cairo pattern to paint the border with"),
+ GOO_TYPE_CAIRO_PATTERN,
+ G_PARAM_READWRITE));
- goo_canvas_grid_set_common_property (object, &gmodel->grid_data,
- prop_id, value, pspec);
- g_signal_emit_by_name (gmodel, "changed", TRUE);
-}
+ g_object_class_install_property (gobject_class, PROP_SHOW_HORZ_GRID_LINES,
+ g_param_spec_boolean ("show-horz-grid-lines",
+ _("Show Horizontal Grid Lines"),
+ _("If the horizontal grid lines are shown"),
+ TRUE,
+ G_PARAM_READWRITE));
+ g_object_class_install_property (gobject_class, PROP_SHOW_VERT_GRID_LINES,
+ g_param_spec_boolean ("show-vert-grid-lines",
+ _("Show Vertical Grid Lines"),
+ _("If the vertical grid lines are shown"),
+ TRUE,
+ G_PARAM_READWRITE));
-static GooCanvasItem*
-goo_canvas_grid_model_create_item (GooCanvasItemModel *model,
- GooCanvas *canvas)
-{
- GooCanvasItem *item;
+ g_object_class_install_property (gobject_class, PROP_VERT_GRID_LINES_ON_TOP,
+ g_param_spec_boolean ("vert-grid-lines-on-top",
+ _("Vertical Grid Lines On Top"),
+ _("If the vertical grid lines are painted above the horizontal grid lines"),
+ FALSE,
+ G_PARAM_READWRITE));
- item = g_object_new (GOO_TYPE_CANVAS_GRID, NULL);
- goo_canvas_item_set_model (item, model);
- return item;
-}
+ /* Convenience properties - some are writable only. */
+ g_object_class_install_property (gobject_class, PROP_HORZ_GRID_LINE_COLOR,
+ g_param_spec_string ("horz-grid-line-color",
+ _("Horizontal Grid Line Color"),
+ _("The color to use for the horizontal grid lines"),
+ NULL,
+ G_PARAM_WRITABLE));
+ g_object_class_install_property (gobject_class, PROP_HORZ_GRID_LINE_COLOR_RGBA,
+ g_param_spec_uint ("horz-grid-line-color-rgba",
+ _("Horizontal Grid Line Color RGBA"),
+ _("The color to use for the horizontal grid lines, specified as a 32-bit integer value"),
+ 0, G_MAXUINT, 0,
+ G_PARAM_READWRITE));
-static void
-item_model_interface_init (GooCanvasItemModelIface *iface)
-{
- iface->create_item = goo_canvas_grid_model_create_item;
-}
+ g_object_class_install_property (gobject_class, PROP_HORZ_GRID_LINE_PIXBUF,
+ g_param_spec_object ("horz-grid-line-pixbuf",
+ _("Horizontal Grid Line Pixbuf"),
+ _("The pixbuf to use to draw the horizontal grid lines"),
+ GDK_TYPE_PIXBUF,
+ G_PARAM_WRITABLE));
+ g_object_class_install_property (gobject_class, PROP_VERT_GRID_LINE_COLOR,
+ g_param_spec_string ("vert-grid-line-color",
+ _("Vertical Grid Line Color"),
+ _("The color to use for the vertical grid lines"),
+ NULL,
+ G_PARAM_WRITABLE));
-static void
-goo_canvas_grid_model_class_init (GooCanvasGridModelClass *klass)
-{
- GObjectClass *gobject_class = (GObjectClass*) klass;
+ g_object_class_install_property (gobject_class, PROP_VERT_GRID_LINE_COLOR_RGBA,
+ g_param_spec_uint ("vert-grid-line-color-rgba",
+ _("Vertical Grid Line Color RGBA"),
+ _("The color to use for the vertical grid lines, specified as a 32-bit integer value"),
+ 0, G_MAXUINT, 0,
+ G_PARAM_READWRITE));
- goo_canvas_grid_model_parent_iface = g_type_interface_peek (goo_canvas_grid_model_parent_class, GOO_TYPE_CANVAS_ITEM_MODEL);
+ g_object_class_install_property (gobject_class, PROP_VERT_GRID_LINE_PIXBUF,
+ g_param_spec_object ("vert-grid-line-pixbuf",
+ _("Vertical Grid Line Pixbuf"),
+ _("The pixbuf to use to draw the vertical grid lines"),
+ GDK_TYPE_PIXBUF,
+ G_PARAM_WRITABLE));
- gobject_class->finalize = goo_canvas_grid_model_finalize;
+ g_object_class_install_property (gobject_class, PROP_BORDER_COLOR,
+ g_param_spec_string ("border-color",
+ _("Border Color"),
+ _("The color to use for the border"),
+ NULL,
+ G_PARAM_WRITABLE));
- gobject_class->get_property = goo_canvas_grid_model_get_property;
- gobject_class->set_property = goo_canvas_grid_model_set_property;
+ g_object_class_install_property (gobject_class, PROP_BORDER_COLOR_RGBA,
+ g_param_spec_uint ("border-color-rgba",
+ _("Border Color RGBA"),
+ _("The color to use for the border, specified as a 32-bit integer value"),
+ 0, G_MAXUINT, 0,
+ G_PARAM_READWRITE));
- goo_canvas_grid_install_common_properties (gobject_class);
+ g_object_class_install_property (gobject_class, PROP_BORDER_PIXBUF,
+ g_param_spec_object ("border-pixbuf",
+ _("Border Pixbuf"),
+ _("The pixbuf to use to draw the border"),
+ GDK_TYPE_PIXBUF,
+ G_PARAM_WRITABLE));
}
-
diff --git a/src/goocanvasgrid.h b/src/goocanvasgrid.h
index fa70e2e..496e1a6 100644
--- a/src/goocanvasgrid.h
+++ b/src/goocanvasgrid.h
@@ -13,10 +13,26 @@
G_BEGIN_DECLS
-/* This is the data used by both model and view classes. */
-typedef struct _GooCanvasGridData GooCanvasGridData;
-struct _GooCanvasGridData
+#define GOO_TYPE_CANVAS_GRID (goo_canvas_grid_get_type ())
+#define GOO_CANVAS_GRID(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GOO_TYPE_CANVAS_GRID, GooCanvasGrid))
+#define GOO_CANVAS_GRID_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GOO_TYPE_CANVAS_GRID, GooCanvasGridClass))
+#define GOO_IS_CANVAS_GRID(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GOO_TYPE_CANVAS_GRID))
+#define GOO_IS_CANVAS_GRID_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GOO_TYPE_CANVAS_GRID))
+#define GOO_CANVAS_GRID_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GOO_TYPE_CANVAS_GRID, GooCanvasGridClass))
+
+
+typedef struct _GooCanvasGrid GooCanvasGrid;
+typedef struct _GooCanvasGridClass GooCanvasGridClass;
+
+/**
+ * GooCanvasGrid
+ *
+ * The #GooCanvasGrid-struct struct contains private data only.
+ */
+struct _GooCanvasGrid
{
+ GooCanvasItemSimple parent_object;
+
/* The area that the grid covers. */
gdouble x, y, width, height;
@@ -46,30 +62,6 @@ struct _GooCanvasGridData
guint vert_grid_lines_on_top : 1;
};
-
-#define GOO_TYPE_CANVAS_GRID (goo_canvas_grid_get_type ())
-#define GOO_CANVAS_GRID(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GOO_TYPE_CANVAS_GRID, GooCanvasGrid))
-#define GOO_CANVAS_GRID_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GOO_TYPE_CANVAS_GRID, GooCanvasGridClass))
-#define GOO_IS_CANVAS_GRID(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GOO_TYPE_CANVAS_GRID))
-#define GOO_IS_CANVAS_GRID_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GOO_TYPE_CANVAS_GRID))
-#define GOO_CANVAS_GRID_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GOO_TYPE_CANVAS_GRID, GooCanvasGridClass))
-
-
-typedef struct _GooCanvasGrid GooCanvasGrid;
-typedef struct _GooCanvasGridClass GooCanvasGridClass;
-
-/**
- * GooCanvasGrid
- *
- * The #GooCanvasGrid-struct struct contains private data only.
- */
-struct _GooCanvasGrid
-{
- GooCanvasItemSimple parent_object;
-
- GooCanvasGridData *grid_data;
-};
-
struct _GooCanvasGridClass
{
GooCanvasItemSimpleClass parent_class;
@@ -98,56 +90,6 @@ GooCanvasItem* goo_canvas_grid_new (GooCanvasItem *parent,
-#define GOO_TYPE_CANVAS_GRID_MODEL (goo_canvas_grid_model_get_type ())
-#define GOO_CANVAS_GRID_MODEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GOO_TYPE_CANVAS_GRID_MODEL, GooCanvasGridModel))
-#define GOO_CANVAS_GRID_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GOO_TYPE_CANVAS_GRID_MODEL, GooCanvasGridModelClass))
-#define GOO_IS_CANVAS_GRID_MODEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GOO_TYPE_CANVAS_GRID_MODEL))
-#define GOO_IS_CANVAS_GRID_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GOO_TYPE_CANVAS_GRID_MODEL))
-#define GOO_CANVAS_GRID_MODEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GOO_TYPE_CANVAS_GRID_MODEL, GooCanvasGridModelClass))
-
-
-typedef struct _GooCanvasGridModel GooCanvasGridModel;
-typedef struct _GooCanvasGridModelClass GooCanvasGridModelClass;
-
-/**
- * GooCanvasGridModel
- *
- * The #GooCanvasGridModel-struct struct contains private data only.
- */
-struct _GooCanvasGridModel
-{
- GooCanvasItemModelSimple parent_object;
-
- GooCanvasGridData grid_data;
-};
-
-struct _GooCanvasGridModelClass
-{
- GooCanvasItemModelSimpleClass parent_class;
-
- /*< private >*/
-
- /* Padding for future expansion */
- void (*_goo_canvas_reserved1) (void);
- void (*_goo_canvas_reserved2) (void);
- void (*_goo_canvas_reserved3) (void);
- void (*_goo_canvas_reserved4) (void);
-};
-
-
-GType goo_canvas_grid_model_get_type (void) G_GNUC_CONST;
-GooCanvasItemModel* goo_canvas_grid_model_new (GooCanvasItemModel *parent,
- gdouble x,
- gdouble y,
- gdouble width,
- gdouble height,
- gdouble x_step,
- gdouble y_step,
- gdouble x_offset,
- gdouble y_offset,
- ...);
-
-
G_END_DECLS
#endif /* __GOO_CANVAS_GRID_H__ */
diff --git a/src/goocanvasgroup.c b/src/goocanvasgroup.c
index 0f709ac..1c187b1 100644
--- a/src/goocanvasgroup.c
+++ b/src/goocanvasgroup.c
@@ -38,23 +38,10 @@
#include <gtk/gtk.h>
#include "goocanvasprivate.h"
#include "goocanvasgroup.h"
-#include "goocanvasitemmodel.h"
#include "goocanvas.h"
#include "goocanvasmarshal.h"
#include "goocanvasatk.h"
-typedef struct _GooCanvasGroupPrivate GooCanvasGroupPrivate;
-struct _GooCanvasGroupPrivate {
- gdouble x;
- gdouble y;
- gdouble width;
- gdouble height;
-};
-
-#define GOO_CANVAS_GROUP_GET_PRIVATE(group) \
- (G_TYPE_INSTANCE_GET_PRIVATE ((group), GOO_TYPE_CANVAS_GROUP, GooCanvasGroupPrivate))
-#define GOO_CANVAS_GROUP_MODEL_GET_PRIVATE(group) \
- (G_TYPE_INSTANCE_GET_PRIVATE ((group), GOO_TYPE_CANVAS_GROUP_MODEL, GooCanvasGroupPrivate))
enum {
PROP_0,
@@ -65,16 +52,6 @@ enum {
PROP_HEIGHT
};
-static void goo_canvas_group_dispose (GObject *object);
-static void goo_canvas_group_finalize (GObject *object);
-static void goo_canvas_group_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec);
-static void goo_canvas_group_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec);
static void canvas_item_interface_init (GooCanvasItemIface *iface);
G_DEFINE_TYPE_WITH_CODE (GooCanvasGroup, goo_canvas_group,
@@ -82,77 +59,16 @@ G_DEFINE_TYPE_WITH_CODE (GooCanvasGroup, goo_canvas_group,
G_IMPLEMENT_INTERFACE (GOO_TYPE_CANVAS_ITEM,
canvas_item_interface_init))
-static void
-goo_canvas_group_install_common_properties (GObjectClass *gobject_class)
-{
- g_object_class_install_property (gobject_class, PROP_X,
- g_param_spec_double ("x",
- "X",
- _("The x coordinate of the group"),
- -G_MAXDOUBLE,
- G_MAXDOUBLE, 0.0,
- G_PARAM_READWRITE));
-
- g_object_class_install_property (gobject_class, PROP_Y,
- g_param_spec_double ("y",
- "Y",
- _("The y coordinate of the group"),
- -G_MAXDOUBLE,
- G_MAXDOUBLE, 0.0,
- G_PARAM_READWRITE));
-
- g_object_class_install_property (gobject_class, PROP_WIDTH,
- g_param_spec_double ("width",
- _("Width"),
- _("The width of the group, or -1 to use the default width"),
- -G_MAXDOUBLE,
- G_MAXDOUBLE, -1.0,
- G_PARAM_READWRITE));
-
- g_object_class_install_property (gobject_class, PROP_HEIGHT,
- g_param_spec_double ("height",
- _("Height"),
- _("The height of the group, or -1 to use the default height"),
- -G_MAXDOUBLE,
- G_MAXDOUBLE, -1.0,
- G_PARAM_READWRITE));
-}
-
-static void
-goo_canvas_group_class_init (GooCanvasGroupClass *klass)
-{
- GObjectClass *gobject_class = (GObjectClass*) klass;
-
- g_type_class_add_private (gobject_class, sizeof (GooCanvasGroupPrivate));
-
- gobject_class->dispose = goo_canvas_group_dispose;
- gobject_class->finalize = goo_canvas_group_finalize;
- gobject_class->get_property = goo_canvas_group_get_property;
- gobject_class->set_property = goo_canvas_group_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)))
- {
- atk_registry_set_factory_type (atk_get_default_registry (),
- GOO_TYPE_CANVAS_GROUP,
- goo_canvas_item_accessible_factory_get_type ());
- }
-
- goo_canvas_group_install_common_properties (gobject_class);
-}
-
static void
goo_canvas_group_init (GooCanvasGroup *group)
{
- GooCanvasGroupPrivate* priv = GOO_CANVAS_GROUP_GET_PRIVATE (group);
-
group->items = g_ptr_array_sized_new (8);
- priv->x = 0.0;
- priv->y = 0.0;
- priv->width = -1.0;
- priv->height = -1.0;
+ group->x = 0.0;
+ group->y = 0.0;
+ group->width = -1.0;
+ group->height = -1.0;
}
@@ -226,39 +142,27 @@ goo_canvas_group_finalize (GObject *object)
}
-/* Gets the private data to use, from the model or from the item itself. */
-static GooCanvasGroupPrivate*
-goo_canvas_group_get_private (GooCanvasGroup *group)
-{
- GooCanvasItemSimple *simple = (GooCanvasItemSimple*) group;
-
- if (simple->model)
- return GOO_CANVAS_GROUP_MODEL_GET_PRIVATE (simple->model);
- else
- return GOO_CANVAS_GROUP_GET_PRIVATE (group);
-}
-
-
static void
-goo_canvas_group_get_common_property (GObject *object,
- GooCanvasGroupPrivate *priv,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
+goo_canvas_group_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
{
+ GooCanvasGroup *group = (GooCanvasGroup*) object;
+
switch (prop_id)
{
case PROP_X:
- g_value_set_double (value, priv->x);
+ g_value_set_double (value, group->x);
break;
case PROP_Y:
- g_value_set_double (value, priv->y);
+ g_value_set_double (value, group->y);
break;
case PROP_WIDTH:
- g_value_set_double (value, priv->width);
+ g_value_set_double (value, group->width);
break;
case PROP_HEIGHT:
- g_value_set_double (value, priv->height);
+ g_value_set_double (value, group->height);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -266,65 +170,39 @@ goo_canvas_group_get_common_property (GObject *object,
}
}
+
static void
-goo_canvas_group_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
+goo_canvas_group_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
+ GooCanvasItemSimple *simple = (GooCanvasItemSimple*) object;
GooCanvasGroup *group = (GooCanvasGroup*) object;
- GooCanvasGroupPrivate *priv = goo_canvas_group_get_private (group);
- goo_canvas_group_get_common_property (object, priv, prop_id, value, pspec);
-}
-
-static void
-goo_canvas_group_set_common_property (GObject *object,
- GooCanvasGroupPrivate *priv,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
switch (prop_id)
{
case PROP_X:
- priv->x = g_value_get_double (value);
+ group->x = g_value_get_double (value);
break;
case PROP_Y:
- priv->y = g_value_get_double (value);
+ group->y = g_value_get_double (value);
break;
case PROP_WIDTH:
- priv->width = g_value_get_double (value);
+ group->width = g_value_get_double (value);
break;
case PROP_HEIGHT:
- priv->height = g_value_get_double (value);
+ group->height = g_value_get_double (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
-}
-
-static void
-goo_canvas_group_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- GooCanvasItemSimple *simple = (GooCanvasItemSimple*) object;
- GooCanvasGroup *group = (GooCanvasGroup*) object;
- GooCanvasGroupPrivate *priv = goo_canvas_group_get_private (group);
-
- if (simple->model)
- {
- g_warning ("Can't set property of a canvas item with a model - set the model property instead");
- return;
- }
- goo_canvas_group_set_common_property (object, priv, prop_id, value, pspec);
goo_canvas_item_simple_changed (simple, TRUE);
}
+
static void
goo_canvas_group_add_child (GooCanvasItem *item,
GooCanvasItem *child,
@@ -347,7 +225,7 @@ goo_canvas_group_add_child (GooCanvasItem *item,
}
goo_canvas_item_set_parent (child, item);
- goo_canvas_item_set_is_static (child, simple->simple_data->is_static);
+ goo_canvas_item_set_is_static (child, simple->is_static);
/* Emit the "children_changed" ATK signal, if ATK is enabled. */
atk_obj = atk_gobject_accessible_for_object (G_OBJECT (item));
@@ -378,7 +256,7 @@ goo_canvas_group_move_child (GooCanvasItem *item,
{
goo_canvas_item_get_bounds (child, &bounds);
goo_canvas_request_item_redraw (simple->canvas, &bounds,
- simple->simple_data->is_static);
+ simple->is_static);
}
goo_canvas_util_ptr_array_move (group->items, old_position, new_position);
@@ -405,7 +283,7 @@ goo_canvas_group_remove_child (GooCanvasItem *item,
{
goo_canvas_item_get_bounds (child, &bounds);
goo_canvas_request_item_redraw (simple->canvas, &bounds,
- simple->simple_data->is_static);
+ simple->is_static);
}
/* Emit the "children_changed" ATK signal, if ATK is enabled. */
@@ -476,14 +354,13 @@ goo_canvas_group_set_is_static (GooCanvasItem *item,
gboolean is_static)
{
GooCanvasItemSimple *simple = (GooCanvasItemSimple*) item;
- GooCanvasItemSimpleData *simple_data = simple->simple_data;
GooCanvasGroup *group = (GooCanvasGroup*) item;
gint i;
- if (simple_data->is_static == is_static)
+ if (simple->is_static == is_static)
return;
- simple_data->is_static = is_static;
+ simple->is_static = is_static;
/* Recursively set the canvas of all child items. */
for (i = 0; i < group->items->len; i++)
@@ -495,71 +372,6 @@ goo_canvas_group_set_is_static (GooCanvasItem *item,
static void
-on_model_child_added (GooCanvasGroupModel *model,
- gint position,
- GooCanvasGroup *group)
-{
- GooCanvasItemSimple *simple = (GooCanvasItemSimple*) group;
- GooCanvasItem *item = (GooCanvasItem*) group;
- GooCanvasItemModel *child_model;
- GooCanvasItem *child;
-
- /* Create a canvas item for the model. */
- child_model = goo_canvas_item_model_get_child ((GooCanvasItemModel*) model,
- position);
- child = goo_canvas_create_item (simple->canvas, child_model);
- goo_canvas_item_add_child (item, child, position);
- g_object_unref (child);
-}
-
-
-static void
-on_model_child_moved (GooCanvasGroupModel *model,
- gint old_position,
- gint new_position,
- GooCanvasGroup *group)
-{
- goo_canvas_item_move_child ((GooCanvasItem*) group, old_position,
- new_position);
-}
-
-
-static void
-on_model_child_removed (GooCanvasGroupModel *model,
- gint child_num,
- GooCanvasGroup *group)
-{
- goo_canvas_item_remove_child ((GooCanvasItem*) group, child_num);
-}
-
-
-static void
-goo_canvas_group_set_model (GooCanvasItem *item,
- GooCanvasItemModel *model)
-{
- GooCanvasItemSimple *simple = (GooCanvasItemSimple*) item;
- GooCanvasGroup *group = (GooCanvasGroup*) item;
- gint n_children, i;
-
- /* Do the default GooCanvasItemSimple code first. */
- goo_canvas_item_simple_set_model (simple, model);
-
- /* Now add our own handlers. */
- g_signal_connect (model, "child-added",
- G_CALLBACK (on_model_child_added), group);
- g_signal_connect (model, "child-moved",
- G_CALLBACK (on_model_child_moved), group);
- g_signal_connect (model, "child-removed",
- G_CALLBACK (on_model_child_removed), group);
-
- /* Recursively create child items for any children. */
- n_children = goo_canvas_item_model_get_n_children (model);
- for (i = 0; i < n_children; i++)
- on_model_child_added ((GooCanvasGroupModel*) simple->model, i, group);
-}
-
-
-static void
goo_canvas_group_request_update (GooCanvasItem *item)
{
GooCanvasItemSimple *simple = (GooCanvasItemSimple*) item;
@@ -584,7 +396,6 @@ goo_canvas_group_update (GooCanvasItem *item,
{
GooCanvasItemSimple *simple = (GooCanvasItemSimple*) item;
GooCanvasGroup *group = (GooCanvasGroup*) item;
- GooCanvasGroupPrivate *priv = goo_canvas_group_get_private (group);
GooCanvasBounds child_bounds;
gboolean initial_bounds = TRUE;
gint i;
@@ -603,10 +414,10 @@ goo_canvas_group_update (GooCanvasItem *item,
simple->bounds.x2 = simple->bounds.y2 = 0.0;
cairo_save (cr);
- if (simple->simple_data->transform)
- cairo_transform (cr, simple->simple_data->transform);
+ if (simple->transform)
+ cairo_transform (cr, simple->transform);
- cairo_translate (cr, priv->x, priv->y);
+ cairo_translate (cr, group->x, group->y);
for (i = 0; i < group->items->len; i++)
{
@@ -653,9 +464,7 @@ goo_canvas_group_get_items_at (GooCanvasItem *item,
GList *found_items)
{
GooCanvasItemSimple *simple = (GooCanvasItemSimple*) item;
- GooCanvasItemSimpleData *simple_data = simple->simple_data;
GooCanvasGroup *group = (GooCanvasGroup*) item;
- GooCanvasGroupPrivate *priv = goo_canvas_group_get_private (group);
gboolean visible = parent_visible;
int i;
@@ -667,32 +476,32 @@ goo_canvas_group_get_items_at (GooCanvasItem *item,
|| simple->bounds.y1 > y || simple->bounds.y2 < y)
return found_items;
- if (simple_data->visibility <= GOO_CANVAS_ITEM_INVISIBLE
- || (simple_data->visibility == GOO_CANVAS_ITEM_VISIBLE_ABOVE_THRESHOLD
- && simple->canvas->scale < simple_data->visibility_threshold))
+ if (simple->visibility <= GOO_CANVAS_ITEM_INVISIBLE
+ || (simple->visibility == GOO_CANVAS_ITEM_VISIBLE_ABOVE_THRESHOLD
+ && simple->canvas->scale < simple->visibility_threshold))
visible = FALSE;
/* Check if the group should receive events. */
if (is_pointer_event
- && (simple_data->pointer_events == GOO_CANVAS_EVENTS_NONE
- || ((simple_data->pointer_events & GOO_CANVAS_EVENTS_VISIBLE_MASK)
+ && (simple->pointer_events == GOO_CANVAS_EVENTS_NONE
+ || ((simple->pointer_events & GOO_CANVAS_EVENTS_VISIBLE_MASK)
&& !visible)))
return found_items;
cairo_save (cr);
- if (simple_data->transform)
- cairo_transform (cr, simple_data->transform);
+ if (simple->transform)
+ cairo_transform (cr, simple->transform);
- cairo_translate (cr, priv->x, priv->y);
+ cairo_translate (cr, group->x, group->y);
/* If the group has a clip path, check if the point is inside it. */
- if (simple_data->clip_path_commands)
+ if (simple->clip_path_commands)
{
double user_x = x, user_y = y;
cairo_device_to_user (cr, &user_x, &user_y);
- goo_canvas_create_path (simple_data->clip_path_commands, cr);
- cairo_set_fill_rule (cr, simple_data->clip_fill_rule);
+ goo_canvas_create_path (simple->clip_path_commands, cr);
+ cairo_set_fill_rule (cr, simple->clip_fill_rule);
if (!cairo_in_fill (cr, user_x, user_y))
{
cairo_restore (cr);
@@ -700,13 +509,13 @@ goo_canvas_group_get_items_at (GooCanvasItem *item,
}
}
- if (priv->width > 0.0 && priv->height > 0.0)
+ if (group->width > 0.0 && group->height > 0.0)
{
double user_x = x, user_y = y;
cairo_device_to_user (cr, &user_x, &user_y);
- if (user_x < 0.0 || user_x >= priv->width
- || user_y < 0.0 || user_y >= priv->height)
+ if (user_x < 0.0 || user_x >= group->width
+ || user_y < 0.0 || user_y >= group->height)
{
cairo_restore (cr);
return found_items;
@@ -736,9 +545,7 @@ goo_canvas_group_paint (GooCanvasItem *item,
gdouble scale)
{
GooCanvasItemSimple *simple = (GooCanvasItemSimple*) item;
- GooCanvasItemSimpleData *simple_data = simple->simple_data;
GooCanvasGroup *group = (GooCanvasGroup*) item;
- GooCanvasGroupPrivate *priv = goo_canvas_group_get_private (group);
gint i;
/* Skip the item if the bounds don't intersect the expose rectangle. */
@@ -747,29 +554,29 @@ goo_canvas_group_paint (GooCanvasItem *item,
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
- && simple->canvas->scale < simple_data->visibility_threshold))
+ if (simple->visibility <= GOO_CANVAS_ITEM_INVISIBLE
+ || (simple->visibility == GOO_CANVAS_ITEM_VISIBLE_ABOVE_THRESHOLD
+ && simple->canvas->scale < simple->visibility_threshold))
return;
/* Paint all the items in the group. */
cairo_save (cr);
- if (simple_data->transform)
- cairo_transform (cr, simple_data->transform);
+ if (simple->transform)
+ cairo_transform (cr, simple->transform);
- cairo_translate (cr, priv->x, priv->y);
+ cairo_translate (cr, group->x, group->y);
/* Clip with the group's clip path, if it is set. */
- if (simple_data->clip_path_commands)
+ if (simple->clip_path_commands)
{
- goo_canvas_create_path (simple_data->clip_path_commands, cr);
- cairo_set_fill_rule (cr, simple_data->clip_fill_rule);
+ goo_canvas_create_path (simple->clip_path_commands, cr);
+ cairo_set_fill_rule (cr, simple->clip_fill_rule);
cairo_clip (cr);
}
- if (priv->width > 0.0 && priv->height > 0.0)
+ if (group->width > 0.0 && group->height > 0.0)
{
- cairo_rectangle (cr, 0.0, 0.0, priv->width, priv->height);
+ cairo_rectangle (cr, 0.0, 0.0, group->width, group->height);
cairo_clip (cr);
}
@@ -798,285 +605,57 @@ canvas_item_interface_init (GooCanvasItemIface *iface)
iface->update = goo_canvas_group_update;
iface->paint = goo_canvas_group_paint;
- iface->set_model = goo_canvas_group_set_model;
iface->set_is_static = goo_canvas_group_set_is_static;
}
-/**
- * SECTION:goocanvasgroupmodel
- * @Title: GooCanvasGroupModel
- * @Short_Description: a model for a group of items.
- *
- * #GooCanvasGroupModel represents a group of items. Groups can be nested to
- * any depth, to create a hierarchy of items. Items are ordered within each
- * group, with later items being displayed above earlier items.
- *
- * #GooCanvasGroupModel is a subclass of #GooCanvasItemModelSimple and so
- * inherits all of the style properties such as "stroke-color", "fill-color"
- * and "line-width". Setting a style property on a #GooCanvasGroupModel will
- * affect all children of the #GooCanvasGroupModel (unless the children
- * override the property setting).
- *
- * #GooCanvasGroupModel implements the #GooCanvasItemModel interface, so you
- * can use the #GooCanvasItemModel functions such as
- * goo_canvas_item_model_raise() and goo_canvas_item_model_rotate(), and the
- * properties such as "visibility" and "pointer-events".
- *
- * To create a #GooCanvasGroupModel use goo_canvas_group_model_new().
- *
- * To get or set the properties of an existing #GooCanvasGroupModel, use
- * g_object_get() and g_object_set().
- *
- * To respond to events such as mouse clicks on the group you must connect
- * to the signal handlers of the corresponding #GooCanvasGroup objects.
- * (See goo_canvas_get_item() and #GooCanvas::item-created.)
- */
-static void item_model_interface_init (GooCanvasItemModelIface *iface);
-static void goo_canvas_group_model_dispose (GObject *object);
-static void goo_canvas_group_model_finalize (GObject *object);
-static void goo_canvas_group_model_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec);
-static void goo_canvas_group_model_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec);
-
-G_DEFINE_TYPE_WITH_CODE (GooCanvasGroupModel, goo_canvas_group_model,
- GOO_TYPE_CANVAS_ITEM_MODEL_SIMPLE,
- G_IMPLEMENT_INTERFACE (GOO_TYPE_CANVAS_ITEM_MODEL,
- item_model_interface_init))
-
-
static void
-goo_canvas_group_model_class_init (GooCanvasGroupModelClass *klass)
+goo_canvas_group_class_init (GooCanvasGroupClass *klass)
{
GObjectClass *gobject_class = (GObjectClass*) klass;
- g_type_class_add_private (gobject_class, sizeof (GooCanvasGroupPrivate));
-
- gobject_class->dispose = goo_canvas_group_model_dispose;
- gobject_class->finalize = goo_canvas_group_model_finalize;
- gobject_class->get_property = goo_canvas_group_model_get_property;
- gobject_class->set_property = goo_canvas_group_model_set_property;
-
- goo_canvas_group_install_common_properties (gobject_class);
-}
-
-
-static void
-goo_canvas_group_model_init (GooCanvasGroupModel *gmodel)
-{
- GooCanvasGroupPrivate *priv = GOO_CANVAS_GROUP_MODEL_GET_PRIVATE (gmodel);
- gmodel->children = g_ptr_array_sized_new (8);
-
- priv->x = 0.0;
- priv->y = 0.0;
- priv->width = -1.0;
- priv->height = -1.0;
-}
-
-
-/**
- * goo_canvas_group_model_new:
- * @parent: the parent model, or %NULL. If a parent is specified, it will
- * assume ownership of the item, and the item will automatically be freed when
- * it is removed from the parent. Otherwise call g_object_unref() to free it.
- * @...: optional pairs of property names and values, and a terminating %NULL.
- *
- * Creates a new group item.
- *
- * Return value: a new group model.
- **/
-GooCanvasItemModel*
-goo_canvas_group_model_new (GooCanvasItemModel *parent,
- ...)
-{
- GooCanvasItemModel *model;
- GooCanvasGroupModel *gmodel;
- va_list var_args;
- const char *first_property;
-
- model = g_object_new (GOO_TYPE_CANVAS_GROUP_MODEL, NULL);
- gmodel = (GooCanvasGroupModel*) model;
-
- va_start (var_args, parent);
- first_property = va_arg (var_args, char*);
- if (first_property)
- g_object_set_valist (G_OBJECT (model), first_property, var_args);
- va_end (var_args);
-
- if (parent)
- {
- goo_canvas_item_model_add_child (parent, model, -1);
- g_object_unref (model);
- }
-
- return model;
-}
-
-
-static void
-goo_canvas_group_model_dispose (GObject *object)
-{
- GooCanvasGroupModel *gmodel = (GooCanvasGroupModel*) object;
- gint i;
-
- /* Unref all the items in the group. */
- for (i = 0; i < gmodel->children->len; i++)
- {
- GooCanvasItemModel *child = gmodel->children->pdata[i];
- goo_canvas_item_model_set_parent (child, NULL);
- g_object_unref (child);
- }
- g_ptr_array_set_size (gmodel->children, 0);
-
- G_OBJECT_CLASS (goo_canvas_group_model_parent_class)->dispose (object);
-}
-
-
-static void
-goo_canvas_group_model_finalize (GObject *object)
-{
- GooCanvasGroupModel *gmodel = (GooCanvasGroupModel*) object;
-
- g_ptr_array_free (gmodel->children, TRUE);
-
- G_OBJECT_CLASS (goo_canvas_group_model_parent_class)->finalize (object);
-}
-
-static void goo_canvas_group_model_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- GooCanvasGroupModel *model = (GooCanvasGroupModel*) object;
- GooCanvasGroupPrivate *priv = GOO_CANVAS_GROUP_MODEL_GET_PRIVATE (model);
-
- goo_canvas_group_get_common_property (object, priv, prop_id, value, pspec);
-}
-
-static void goo_canvas_group_model_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- GooCanvasGroupModel *model = (GooCanvasGroupModel*) object;
- GooCanvasGroupPrivate *priv = GOO_CANVAS_GROUP_MODEL_GET_PRIVATE (model);
-
- goo_canvas_group_set_common_property (object, priv, prop_id, value, pspec);
- g_signal_emit_by_name (model, "changed", TRUE);
-}
-
-extern void _goo_canvas_item_model_emit_child_added (GooCanvasItemModel *model,
- gint position);
-
-static void
-goo_canvas_group_model_add_child (GooCanvasItemModel *model,
- GooCanvasItemModel *child,
- gint position)
-{
- GooCanvasGroupModel *gmodel = (GooCanvasGroupModel*) model;
-
- g_object_ref (child);
+ gobject_class->dispose = goo_canvas_group_dispose;
+ gobject_class->finalize = goo_canvas_group_finalize;
+ gobject_class->get_property = goo_canvas_group_get_property;
+ gobject_class->set_property = goo_canvas_group_set_property;
- if (position >= 0)
- {
- goo_canvas_util_ptr_array_insert (gmodel->children, child, position);
- }
- else
+ /* 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)))
{
- position = gmodel->children->len;
- g_ptr_array_add (gmodel->children, child);
+ atk_registry_set_factory_type (atk_get_default_registry (),
+ GOO_TYPE_CANVAS_GROUP,
+ goo_canvas_item_accessible_factory_get_type ());
}
- goo_canvas_item_model_set_parent (child, model);
-
- _goo_canvas_item_model_emit_child_added (model, position);
-}
-
-
-static void
-goo_canvas_group_model_move_child (GooCanvasItemModel *model,
- gint old_position,
- gint new_position)
-{
- GooCanvasGroupModel *gmodel = (GooCanvasGroupModel*) model;
-
- goo_canvas_util_ptr_array_move (gmodel->children, old_position,
- new_position);
-
- g_signal_emit_by_name (gmodel, "child-moved", old_position, new_position);
-}
-
-
-static void
-goo_canvas_group_model_remove_child (GooCanvasItemModel *model,
- gint child_num)
-{
- GooCanvasGroupModel *gmodel = (GooCanvasGroupModel*) model;
- GooCanvasItemModel *child;
-
- child = gmodel->children->pdata[child_num];
- goo_canvas_item_model_set_parent (child, NULL);
-
- g_ptr_array_remove_index (gmodel->children, child_num);
-
- g_signal_emit_by_name (gmodel, "child-removed", child_num);
-
- g_object_unref (child);
-}
-
-
-static gint
-goo_canvas_group_model_get_n_children (GooCanvasItemModel *model)
-{
- GooCanvasGroupModel *gmodel = (GooCanvasGroupModel*) model;
-
- return gmodel->children->len;
-}
-
-
-static GooCanvasItemModel*
-goo_canvas_group_model_get_child (GooCanvasItemModel *model,
- gint child_num)
-{
- GooCanvasGroupModel *gmodel = (GooCanvasGroupModel*) model;
-
- if (child_num < gmodel->children->len)
- return gmodel->children->pdata[child_num];
- return NULL;
-}
-
-
-static GooCanvasItem*
-goo_canvas_group_model_create_item (GooCanvasItemModel *model,
- GooCanvas *canvas)
-{
- GooCanvasItem *item;
-
- item = goo_canvas_group_new (NULL, NULL);
- /* Note that we set the canvas before the model, since we may need the
- canvas to create any child items. */
- goo_canvas_item_set_canvas (item, canvas);
- goo_canvas_item_set_model (item, model);
-
- return item;
-}
+ g_object_class_install_property (gobject_class, PROP_X,
+ g_param_spec_double ("x",
+ "X",
+ _("The x coordinate of the group"),
+ -G_MAXDOUBLE,
+ G_MAXDOUBLE, 0.0,
+ G_PARAM_READWRITE));
+ g_object_class_install_property (gobject_class, PROP_Y,
+ g_param_spec_double ("y",
+ "Y",
+ _("The y coordinate of the group"),
+ -G_MAXDOUBLE,
+ G_MAXDOUBLE, 0.0,
+ G_PARAM_READWRITE));
-static void
-item_model_interface_init (GooCanvasItemModelIface *iface)
-{
- iface->add_child = goo_canvas_group_model_add_child;
- iface->move_child = goo_canvas_group_model_move_child;
- iface->remove_child = goo_canvas_group_model_remove_child;
- iface->get_n_children = goo_canvas_group_model_get_n_children;
- iface->get_child = goo_canvas_group_model_get_child;
+ g_object_class_install_property (gobject_class, PROP_WIDTH,
+ g_param_spec_double ("width",
+ _("Width"),
+ _("The width of the group, or -1 to use the default width"),
+ -G_MAXDOUBLE,
+ G_MAXDOUBLE, -1.0,
+ G_PARAM_READWRITE));
- iface->create_item = goo_canvas_group_model_create_item;
+ g_object_class_install_property (gobject_class, PROP_HEIGHT,
+ g_param_spec_double ("height",
+ _("Height"),
+ _("The height of the group, or -1 to use the default height"),
+ -G_MAXDOUBLE,
+ G_MAXDOUBLE, -1.0,
+ G_PARAM_READWRITE));
}
-
-
diff --git a/src/goocanvasgroup.h b/src/goocanvasgroup.h
index 75e28cd..aa0e189 100644
--- a/src/goocanvasgroup.h
+++ b/src/goocanvasgroup.h
@@ -25,8 +25,6 @@ G_BEGIN_DECLS
typedef struct _GooCanvasGroup GooCanvasGroup;
typedef struct _GooCanvasGroupClass GooCanvasGroupClass;
-typedef struct _GooCanvasGroupModel GooCanvasGroupModel;
-typedef struct _GooCanvasGroupModelClass GooCanvasGroupModelClass;
/**
* GooCanvasGroup
@@ -40,6 +38,8 @@ struct _GooCanvasGroup
/* An array of pointers to GooCanvasItems. The first element is at the
bottom of the display stack and the last element is at the top. */
GPtrArray *items;
+
+ gdouble x, y, width, height;
};
struct _GooCanvasGroupClass
@@ -62,48 +62,6 @@ GooCanvasItem* goo_canvas_group_new (GooCanvasItem *parent,
-#define GOO_TYPE_CANVAS_GROUP_MODEL (goo_canvas_group_model_get_type ())
-#define GOO_CANVAS_GROUP_MODEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GOO_TYPE_CANVAS_GROUP_MODEL, GooCanvasGroupModel))
-#define GOO_CANVAS_GROUP_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GOO_TYPE_CANVAS_GROUP_MODEL, GooCanvasGroupModelClass))
-#define GOO_IS_CANVAS_GROUP_MODEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GOO_TYPE_CANVAS_GROUP_MODEL))
-#define GOO_IS_CANVAS_GROUP_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GOO_TYPE_CANVAS_GROUP_MODEL))
-#define GOO_CANVAS_GROUP_MODEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GOO_TYPE_CANVAS_GROUP_MODEL, GooCanvasGroupModelClass))
-
-
-
-/**
- * GooCanvasGroupModel
- *
- * The #GooCanvasGroupModel-struct struct contains private data only.
- */
-struct _GooCanvasGroupModel
-{
- GooCanvasItemModelSimple parent_object;
-
- /* An array of pointers to GooCanvasItemModels. The first element is at the
- bottom of the display stack and the last element is at the top. */
- GPtrArray *children;
-};
-
-struct _GooCanvasGroupModelClass
-{
- GooCanvasItemModelSimpleClass parent_class;
-
- /*< private >*/
-
- /* Padding for future expansion */
- void (*_goo_canvas_reserved1) (void);
- void (*_goo_canvas_reserved2) (void);
- void (*_goo_canvas_reserved3) (void);
- void (*_goo_canvas_reserved4) (void);
-};
-
-
-GType goo_canvas_group_model_get_type (void) G_GNUC_CONST;
-GooCanvasItemModel* goo_canvas_group_model_new (GooCanvasItemModel *parent,
- ...);
-
-
G_END_DECLS
#endif /* __GOO_CANVAS_GROUP_H__ */
diff --git a/src/goocanvasimage.c b/src/goocanvasimage.c
index a91ae62..4164c20 100644
--- a/src/goocanvasimage.c
+++ b/src/goocanvasimage.c
@@ -33,17 +33,6 @@
#include "goocanvasutils.h"
-typedef struct _GooCanvasImagePrivate GooCanvasImagePrivate;
-struct _GooCanvasImagePrivate {
- gboolean scale_to_fit;
-};
-
-#define GOO_CANVAS_IMAGE_GET_PRIVATE(image) \
- (G_TYPE_INSTANCE_GET_PRIVATE ((image), GOO_TYPE_CANVAS_IMAGE, GooCanvasImagePrivate))
-#define GOO_CANVAS_IMAGE_MODEL_GET_PRIVATE(image) \
- (G_TYPE_INSTANCE_GET_PRIVATE ((image), GOO_TYPE_CANVAS_IMAGE_MODEL, GooCanvasImagePrivate))
-
-
enum {
PROP_0,
@@ -58,105 +47,14 @@ enum {
PROP_PIXBUF
};
-static void goo_canvas_image_dispose (GObject *object);
-static void goo_canvas_image_finalize (GObject *object);
-static void canvas_item_interface_init (GooCanvasItemIface *iface);
-static void goo_canvas_image_get_property (GObject *object,
- guint param_id,
- GValue *value,
- GParamSpec *pspec);
-static void goo_canvas_image_set_property (GObject *object,
- guint param_id,
- const GValue *value,
- GParamSpec *pspec);
-G_DEFINE_TYPE_WITH_CODE (GooCanvasImage, goo_canvas_image,
- GOO_TYPE_CANVAS_ITEM_SIMPLE,
- G_IMPLEMENT_INTERFACE (GOO_TYPE_CANVAS_ITEM,
- canvas_item_interface_init))
-
-
-static void
-goo_canvas_image_install_common_properties (GObjectClass *gobject_class)
-{
- g_object_class_install_property (gobject_class, PROP_PATTERN,
- g_param_spec_boxed ("pattern",
- _("Pattern"),
- _("The cairo pattern to paint"),
- GOO_TYPE_CAIRO_PATTERN,
- G_PARAM_READWRITE));
-
- g_object_class_install_property (gobject_class, PROP_X,
- g_param_spec_double ("x",
- "X",
- _("The x coordinate of the image"),
- -G_MAXDOUBLE,
- G_MAXDOUBLE, 0.0,
- G_PARAM_READWRITE));
-
- g_object_class_install_property (gobject_class, PROP_Y,
- g_param_spec_double ("y",
- "Y",
- _("The y coordinate of the image"),
- -G_MAXDOUBLE,
- G_MAXDOUBLE, 0.0,
- G_PARAM_READWRITE));
-
- g_object_class_install_property (gobject_class, PROP_WIDTH,
- g_param_spec_double ("width",
- _("Width"),
- _("The width of the image"),
- 0.0, G_MAXDOUBLE, 0.0,
- G_PARAM_READWRITE));
-
- g_object_class_install_property (gobject_class, PROP_HEIGHT,
- g_param_spec_double ("height",
- _("Height"),
- _("The height of the image"),
- 0.0, G_MAXDOUBLE, 0.0,
- G_PARAM_READWRITE));
-
- g_object_class_install_property (gobject_class, PROP_SCALE_TO_FIT,
- g_param_spec_boolean ("scale-to-fit",
- _("Scale To Fit"),
- _("If the image is scaled to fit the width and height settings"),
- FALSE,
- G_PARAM_READWRITE));
-
- g_object_class_install_property (gobject_class, PROP_PIXBUF,
- g_param_spec_object ("pixbuf",
- _("Pixbuf"),
- _("The GdkPixbuf to display"),
- GDK_TYPE_PIXBUF,
- G_PARAM_WRITABLE));
-}
-
-
-/* Gets the private data to use, from the model or from the item itself. */
-static GooCanvasImagePrivate*
-goo_canvas_image_get_private (gpointer object)
-{
- GooCanvasItemSimple *simple;
-
- if (GOO_IS_CANVAS_IMAGE (object))
- {
- simple = (GooCanvasItemSimple*) object;
- if (simple->model)
- return GOO_CANVAS_IMAGE_MODEL_GET_PRIVATE (simple->model);
- else
- return GOO_CANVAS_IMAGE_GET_PRIVATE (object);
- }
- else
- {
- return GOO_CANVAS_IMAGE_MODEL_GET_PRIVATE (object);
- }
-}
+G_DEFINE_TYPE (GooCanvasImage, goo_canvas_image, GOO_TYPE_CANVAS_ITEM_SIMPLE)
static void
goo_canvas_image_init (GooCanvasImage *image)
{
- image->image_data = g_slice_new0 (GooCanvasImageData);
+
}
@@ -193,22 +91,20 @@ goo_canvas_image_new (GooCanvasItem *parent,
{
GooCanvasItem *item;
GooCanvasImage *image;
- GooCanvasImageData *image_data;
const char *first_property;
va_list var_args;
item = g_object_new (GOO_TYPE_CANVAS_IMAGE, NULL);
image = (GooCanvasImage*) item;
- image_data = image->image_data;
- image_data->x = x;
- image_data->y = y;
+ image->x = x;
+ image->y = y;
if (pixbuf)
{
- image_data->pattern = goo_canvas_cairo_pattern_from_pixbuf (pixbuf);
- image_data->width = gdk_pixbuf_get_width (pixbuf);
- image_data->height = gdk_pixbuf_get_height (pixbuf);
+ image->pattern = goo_canvas_cairo_pattern_from_pixbuf (pixbuf);
+ image->width = gdk_pixbuf_get_width (pixbuf);
+ image->height = gdk_pixbuf_get_height (pixbuf);
}
va_start (var_args, y);
@@ -230,63 +126,42 @@ goo_canvas_image_new (GooCanvasItem *parent,
static void
goo_canvas_image_dispose (GObject *object)
{
- GooCanvasItemSimple *simple = (GooCanvasItemSimple*) object;
GooCanvasImage *image = (GooCanvasImage*) object;
- if (!simple->model)
- {
- cairo_pattern_destroy (image->image_data->pattern);
- image->image_data->pattern = NULL;
- }
+ cairo_pattern_destroy (image->pattern);
+ image->pattern = NULL;
G_OBJECT_CLASS (goo_canvas_image_parent_class)->dispose (object);
}
static void
-goo_canvas_image_finalize (GObject *object)
+goo_canvas_image_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
{
- GooCanvasItemSimple *simple = (GooCanvasItemSimple*) object;
GooCanvasImage *image = (GooCanvasImage*) object;
- /* Free our data if we didn't have a model. (If we had a model it would
- have been reset in dispose() and simple_data will be NULL.) */
- if (simple->simple_data)
- g_slice_free (GooCanvasImageData, image->image_data);
- image->image_data = NULL;
-
- G_OBJECT_CLASS (goo_canvas_image_parent_class)->finalize (object);
-}
-
-
-static void
-goo_canvas_image_get_common_property (GObject *object,
- GooCanvasImageData *image_data,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- GooCanvasImagePrivate *priv = goo_canvas_image_get_private (object);
-
switch (prop_id)
{
case PROP_PATTERN:
- g_value_set_boxed (value, image_data->pattern);
+ g_value_set_boxed (value, image->pattern);
break;
case PROP_X:
- g_value_set_double (value, image_data->x);
+ g_value_set_double (value, image->x);
break;
case PROP_Y:
- g_value_set_double (value, image_data->y);
+ g_value_set_double (value, image->y);
break;
case PROP_WIDTH:
- g_value_set_double (value, image_data->width);
+ g_value_set_double (value, image->width);
break;
case PROP_HEIGHT:
- g_value_set_double (value, image_data->height);
+ g_value_set_double (value, image->height);
break;
case PROP_SCALE_TO_FIT:
- g_value_set_boolean (value, priv->scale_to_fit);
+ g_value_set_boolean (value, image->scale_to_fit);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -295,83 +170,50 @@ goo_canvas_image_get_common_property (GObject *object,
}
-
static void
-goo_canvas_image_get_property (GObject *object,
+goo_canvas_image_set_property (GObject *object,
guint prop_id,
- GValue *value,
+ const GValue *value,
GParamSpec *pspec)
{
+ GooCanvasItemSimple *simple = (GooCanvasItemSimple*) object;
GooCanvasImage *image = (GooCanvasImage*) object;
-
- goo_canvas_image_get_common_property (object, image->image_data, prop_id,
- value, pspec);
-}
-
-
-static void
-goo_canvas_image_set_common_property (GObject *object,
- GooCanvasImageData *image_data,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- GooCanvasImagePrivate *priv = goo_canvas_image_get_private (object);
GdkPixbuf *pixbuf;
switch (prop_id)
{
case PROP_PATTERN:
- cairo_pattern_destroy (image_data->pattern);
- image_data->pattern = g_value_get_boxed (value);
- cairo_pattern_reference (image_data->pattern);
+ cairo_pattern_destroy (image->pattern);
+ image->pattern = g_value_get_boxed (value);
+ cairo_pattern_reference (image->pattern);
break;
case PROP_X:
- image_data->x = g_value_get_double (value);
+ image->x = g_value_get_double (value);
break;
case PROP_Y:
- image_data->y = g_value_get_double (value);
+ image->y = g_value_get_double (value);
break;
case PROP_WIDTH:
- image_data->width = g_value_get_double (value);
+ image->width = g_value_get_double (value);
break;
case PROP_HEIGHT:
- image_data->height = g_value_get_double (value);
+ image->height = g_value_get_double (value);
break;
case PROP_SCALE_TO_FIT:
- priv->scale_to_fit = g_value_get_boolean (value);
+ image->scale_to_fit = g_value_get_boolean (value);
break;
case PROP_PIXBUF:
- cairo_pattern_destroy (image_data->pattern);
+ cairo_pattern_destroy (image->pattern);
pixbuf = g_value_get_object (value);
- image_data->pattern = pixbuf ? goo_canvas_cairo_pattern_from_pixbuf (pixbuf) : NULL;
- image_data->width = pixbuf ? gdk_pixbuf_get_width (pixbuf) : 0;
- image_data->height = pixbuf ? gdk_pixbuf_get_height (pixbuf) : 0;
+ image->pattern = pixbuf ? goo_canvas_cairo_pattern_from_pixbuf (pixbuf) : NULL;
+ image->width = pixbuf ? gdk_pixbuf_get_width (pixbuf) : 0;
+ image->height = pixbuf ? gdk_pixbuf_get_height (pixbuf) : 0;
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
-}
-
-
-static void
-goo_canvas_image_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- GooCanvasItemSimple *simple = (GooCanvasItemSimple*) object;
- GooCanvasImage *image = (GooCanvasImage*) object;
- if (simple->model)
- {
- g_warning ("Can't set property of a canvas item with a model - set the model property instead");
- return;
- }
-
- goo_canvas_image_set_common_property (object, image->image_data, prop_id,
- value, pspec);
goo_canvas_item_simple_changed (simple, TRUE);
}
@@ -384,10 +226,9 @@ goo_canvas_image_is_item_at (GooCanvasItemSimple *simple,
gboolean is_pointer_event)
{
GooCanvasImage *image = (GooCanvasImage*) simple;
- GooCanvasImageData *image_data = image->image_data;
- if (x < image_data->x || (x > image_data->x + image_data->width)
- || y < image_data->y || (y > image_data->y + image_data->height))
+ if (x < image->x || (x > image->x + image->width)
+ || y < image->y || (y > image->y + image->height))
return FALSE;
return TRUE;
@@ -399,13 +240,12 @@ goo_canvas_image_update (GooCanvasItemSimple *simple,
cairo_t *cr)
{
GooCanvasImage *image = (GooCanvasImage*) simple;
- GooCanvasImageData *image_data = image->image_data;
/* Compute the new bounds. */
- simple->bounds.x1 = image_data->x;
- simple->bounds.y1 = image_data->y;
- simple->bounds.x2 = image_data->x + image_data->width;
- simple->bounds.y2 = image_data->y + image_data->height;
+ simple->bounds.x1 = image->x;
+ simple->bounds.y1 = image->y;
+ simple->bounds.x2 = image->x + image->width;
+ simple->bounds.y2 = image->y + image->height;
}
@@ -414,90 +254,55 @@ goo_canvas_image_paint (GooCanvasItemSimple *simple,
cairo_t *cr,
const GooCanvasBounds *bounds)
{
- GooCanvasImagePrivate *priv = goo_canvas_image_get_private (simple);
GooCanvasImage *image = (GooCanvasImage*) simple;
- GooCanvasImageData *image_data = image->image_data;
cairo_matrix_t matrix = { 1, 0, 0, 1, 0, 0 };
cairo_surface_t *surface;
gdouble width, height;
- if (!image_data->pattern)
+ if (!image->pattern)
return;
#if 1
- if (priv->scale_to_fit)
+ if (image->scale_to_fit)
{
- if (cairo_pattern_get_surface (image_data->pattern, &surface)
+ if (cairo_pattern_get_surface (image->pattern, &surface)
== CAIRO_STATUS_SUCCESS
&& cairo_surface_get_type (surface) == CAIRO_SURFACE_TYPE_IMAGE)
{
width = cairo_image_surface_get_width (surface);
height = cairo_image_surface_get_height (surface);
- cairo_matrix_scale (&matrix, width / image_data->width,
- height / image_data->height);
+ cairo_matrix_scale (&matrix, width / image->width,
+ height / image->height);
}
}
- cairo_matrix_translate (&matrix, -image_data->x, -image_data->y);
+ cairo_matrix_translate (&matrix, -image->x, -image->y);
- cairo_pattern_set_matrix (image_data->pattern, &matrix);
- goo_canvas_style_set_fill_options (simple->simple_data->style, cr);
- cairo_set_source (cr, image_data->pattern);
- cairo_rectangle (cr, image_data->x, image_data->y,
- image_data->width, image_data->height);
+ cairo_pattern_set_matrix (image->pattern, &matrix);
+ goo_canvas_style_set_fill_options (simple->style, cr);
+ cairo_set_source (cr, image->pattern);
+ cairo_rectangle (cr, image->x, image->y,
+ image->width, image->height);
cairo_fill (cr);
#else
/* Using cairo_paint() used to be much slower than cairo_fill(), though
they seem similar now. I'm not sure if it matters which we use. */
- cairo_matrix_init_translate (&matrix, -image_data->x, -image_data->y);
- cairo_pattern_set_matrix (image_data->pattern, &matrix);
- goo_canvas_style_set_fill_options (simple->simple_data->style, cr);
- cairo_set_source (cr, image_data->pattern);
+ cairo_matrix_init_translate (&matrix, -image->x, -image->y);
+ cairo_pattern_set_matrix (image->pattern, &matrix);
+ goo_canvas_style_set_fill_options (simple->style, cr);
+ cairo_set_source (cr, image->pattern);
cairo_paint (cr);
#endif
}
static void
-goo_canvas_image_set_model (GooCanvasItem *item,
- GooCanvasItemModel *model)
-{
- GooCanvasItemSimple *simple = (GooCanvasItemSimple*) item;
- GooCanvasImage *image = (GooCanvasImage*) item;
- GooCanvasImageModel *imodel = (GooCanvasImageModel*) model;
-
- /* If our data was allocated, free it. */
- if (!simple->model)
- {
- cairo_pattern_destroy (image->image_data->pattern);
- g_slice_free (GooCanvasImageData, image->image_data);
- }
-
- /* Now use the new model's data instead. */
- image->image_data = &imodel->image_data;
-
- /* Let the parent GooCanvasItemSimple code do the rest. */
- goo_canvas_item_simple_set_model (simple, model);
-}
-
-
-static void
-canvas_item_interface_init (GooCanvasItemIface *iface)
-{
- iface->set_model = goo_canvas_image_set_model;
-}
-
-
-static void
goo_canvas_image_class_init (GooCanvasImageClass *klass)
{
GObjectClass *gobject_class = (GObjectClass*) klass;
GooCanvasItemSimpleClass *simple_class = (GooCanvasItemSimpleClass*) klass;
- g_type_class_add_private (gobject_class, sizeof (GooCanvasImagePrivate));
-
gobject_class->dispose = goo_canvas_image_dispose;
- gobject_class->finalize = goo_canvas_image_finalize;
gobject_class->get_property = goo_canvas_image_get_property;
gobject_class->set_property = goo_canvas_image_set_property;
@@ -506,197 +311,54 @@ goo_canvas_image_class_init (GooCanvasImageClass *klass)
simple_class->simple_paint = goo_canvas_image_paint;
simple_class->simple_is_item_at = goo_canvas_image_is_item_at;
- goo_canvas_image_install_common_properties (gobject_class);
-}
-
-
-
-/**
- * SECTION:goocanvasimagemodel
- * @Title: GooCanvasImageModel
- * @Short_Description: a model for image items.
- *
- * GooCanvasImageModel represent a model for image items.
- *
- * It is a subclass of #GooCanvasItemModelSimple and so inherits all of the
- * style properties such as "operator" and "pointer-events".
- *
- * It also implements the #GooCanvasItemModel interface, so you can use the
- * #GooCanvasItemModel functions such as goo_canvas_item_model_raise() and
- * goo_canvas_item_model_rotate().
- *
- * To create a #GooCanvasImageModel use goo_canvas_image_model_new().
- *
- * To get or set the properties of an existing #GooCanvasImageModel, use
- * g_object_get() and g_object_set().
- *
- * To respond to events such as mouse clicks on the image you must connect
- * to the signal handlers of the corresponding #GooCanvasImage objects.
- * (See goo_canvas_get_item() and #GooCanvas::item-created.)
- */
-
-static void item_model_interface_init (GooCanvasItemModelIface *iface);
-static void goo_canvas_image_model_dispose (GObject *object);
-static void goo_canvas_image_model_get_property (GObject *object,
- guint param_id,
- GValue *value,
- GParamSpec *pspec);
-static void goo_canvas_image_model_set_property (GObject *object,
- guint param_id,
- const GValue *value,
- GParamSpec *pspec);
-
-G_DEFINE_TYPE_WITH_CODE (GooCanvasImageModel, goo_canvas_image_model,
- GOO_TYPE_CANVAS_ITEM_MODEL_SIMPLE,
- G_IMPLEMENT_INTERFACE (GOO_TYPE_CANVAS_ITEM_MODEL,
- item_model_interface_init))
-
-
-static void
-goo_canvas_image_model_class_init (GooCanvasImageModelClass *klass)
-{
- GObjectClass *gobject_class = (GObjectClass*) klass;
-
- g_type_class_add_private (gobject_class, sizeof (GooCanvasImagePrivate));
-
- gobject_class->dispose = goo_canvas_image_model_dispose;
-
- gobject_class->get_property = goo_canvas_image_model_get_property;
- gobject_class->set_property = goo_canvas_image_model_set_property;
-
- goo_canvas_image_install_common_properties (gobject_class);
-}
-
-
-static void
-goo_canvas_image_model_init (GooCanvasImageModel *emodel)
-{
-
-}
-
-
-/**
- * goo_canvas_image_model_new:
- * @parent: the parent model, or %NULL. If a parent is specified, it will
- * assume ownership of the item, and the item will automatically be freed when
- * it is removed from the parent. Otherwise call g_object_unref() to free it.
- * @pixbuf: the #GdkPixbuf containing the image data, or %NULL.
- * @x: the x coordinate of the image.
- * @y: the y coordinate of the image.
- * @...: optional pairs of property names and values, and a terminating %NULL.
- *
- * Creates a new image model.
- *
- * <!--PARAMETERS-->
- *
- * Here's an example showing how to create an image at (100.0, 100.0), using
- * the given pixbuf at its natural width and height:
- *
- * <informalexample><programlisting>
- * GooCanvasItemModel *image = goo_canvas_image_model_new (mygroup, pixbuf, 100.0, 100.0,
- * NULL);
- * </programlisting></informalexample>
- *
- * Returns: a new image model.
- **/
-GooCanvasItemModel*
-goo_canvas_image_model_new (GooCanvasItemModel *parent,
- GdkPixbuf *pixbuf,
- gdouble x,
- gdouble y,
- ...)
-{
- GooCanvasItemModel *model;
- GooCanvasImageModel *imodel;
- GooCanvasImageData *image_data;
- const char *first_property;
- va_list var_args;
-
- model = g_object_new (GOO_TYPE_CANVAS_IMAGE_MODEL, NULL);
- imodel = (GooCanvasImageModel*) model;
-
- image_data = &imodel->image_data;
- image_data->x = x;
- image_data->y = y;
-
- if (pixbuf)
- {
- image_data->pattern = goo_canvas_cairo_pattern_from_pixbuf (pixbuf);
- image_data->width = gdk_pixbuf_get_width (pixbuf);
- image_data->height = gdk_pixbuf_get_height (pixbuf);
- }
-
- va_start (var_args, y);
- first_property = va_arg (var_args, char*);
- if (first_property)
- g_object_set_valist ((GObject*) model, first_property, var_args);
- va_end (var_args);
-
- if (parent)
- {
- goo_canvas_item_model_add_child (parent, model, -1);
- g_object_unref (model);
- }
-
- return model;
-}
-
-
-static void
-goo_canvas_image_model_dispose (GObject *object)
-{
- GooCanvasImageModel *imodel = (GooCanvasImageModel*) object;
-
- cairo_pattern_destroy (imodel->image_data.pattern);
- imodel->image_data.pattern = NULL;
-
- G_OBJECT_CLASS (goo_canvas_image_model_parent_class)->dispose (object);
-}
-
-
-static void
-goo_canvas_image_model_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- GooCanvasImageModel *imodel = (GooCanvasImageModel*) object;
-
- goo_canvas_image_get_common_property (object, &imodel->image_data, prop_id,
- value, pspec);
-}
-
-
-static void
-goo_canvas_image_model_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- GooCanvasImageModel *imodel = (GooCanvasImageModel*) object;
-
- goo_canvas_image_set_common_property (object, &imodel->image_data, prop_id,
- value, pspec);
- g_signal_emit_by_name (imodel, "changed", TRUE);
-}
+ g_object_class_install_property (gobject_class, PROP_PATTERN,
+ g_param_spec_boxed ("pattern",
+ _("Pattern"),
+ _("The cairo pattern to paint"),
+ GOO_TYPE_CAIRO_PATTERN,
+ G_PARAM_READWRITE));
+ g_object_class_install_property (gobject_class, PROP_X,
+ g_param_spec_double ("x",
+ "X",
+ _("The x coordinate of the image"),
+ -G_MAXDOUBLE,
+ G_MAXDOUBLE, 0.0,
+ G_PARAM_READWRITE));
-static GooCanvasItem*
-goo_canvas_image_model_create_item (GooCanvasItemModel *model,
- GooCanvas *canvas)
-{
- GooCanvasItem *item;
+ g_object_class_install_property (gobject_class, PROP_Y,
+ g_param_spec_double ("y",
+ "Y",
+ _("The y coordinate of the image"),
+ -G_MAXDOUBLE,
+ G_MAXDOUBLE, 0.0,
+ G_PARAM_READWRITE));
- item = g_object_new (GOO_TYPE_CANVAS_IMAGE, NULL);
- goo_canvas_item_set_model (item, model);
+ g_object_class_install_property (gobject_class, PROP_WIDTH,
+ g_param_spec_double ("width",
+ _("Width"),
+ _("The width of the image"),
+ 0.0, G_MAXDOUBLE, 0.0,
+ G_PARAM_READWRITE));
- return item;
-}
+ g_object_class_install_property (gobject_class, PROP_HEIGHT,
+ g_param_spec_double ("height",
+ _("Height"),
+ _("The height of the image"),
+ 0.0, G_MAXDOUBLE, 0.0,
+ G_PARAM_READWRITE));
+ g_object_class_install_property (gobject_class, PROP_SCALE_TO_FIT,
+ g_param_spec_boolean ("scale-to-fit",
+ _("Scale To Fit"),
+ _("If the image is scaled to fit the width and height settings"),
+ FALSE,
+ G_PARAM_READWRITE));
-static void
-item_model_interface_init (GooCanvasItemModelIface *iface)
-{
- iface->create_item = goo_canvas_image_model_create_item;
+ g_object_class_install_property (gobject_class, PROP_PIXBUF,
+ g_param_spec_object ("pixbuf",
+ _("Pixbuf"),
+ _("The GdkPixbuf to display"),
+ GDK_TYPE_PIXBUF,
+ G_PARAM_WRITABLE));
}
-
diff --git a/src/goocanvasimage.h b/src/goocanvasimage.h
index a97364f..27d8a5e 100644
--- a/src/goocanvasimage.h
+++ b/src/goocanvasimage.h
@@ -13,16 +13,6 @@
G_BEGIN_DECLS
-/* This is the data used by both model and view classes. */
-typedef struct _GooCanvasImageData GooCanvasImageData;
-struct _GooCanvasImageData
-{
- cairo_pattern_t *pattern;
-
- gdouble x, y, width, height;
-};
-
-
#define GOO_TYPE_CANVAS_IMAGE (goo_canvas_image_get_type ())
#define GOO_CANVAS_IMAGE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GOO_TYPE_CANVAS_IMAGE, GooCanvasImage))
#define GOO_CANVAS_IMAGE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GOO_TYPE_CANVAS_IMAGE, GooCanvasImageClass))
@@ -43,7 +33,10 @@ struct _GooCanvasImage
{
GooCanvasItemSimple parent_object;
- GooCanvasImageData *image_data;
+ cairo_pattern_t *pattern;
+
+ gdouble x, y, width, height;
+ gboolean scale_to_fit;
};
struct _GooCanvasImageClass
@@ -70,52 +63,6 @@ GooCanvasItem* goo_canvas_image_new (GooCanvasItem *parent,
-#define GOO_TYPE_CANVAS_IMAGE_MODEL (goo_canvas_image_model_get_type ())
-#define GOO_CANVAS_IMAGE_MODEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GOO_TYPE_CANVAS_IMAGE_MODEL, GooCanvasImageModel))
-#define GOO_CANVAS_IMAGE_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GOO_TYPE_CANVAS_IMAGE_MODEL, GooCanvasImageModelClass))
-#define GOO_IS_CANVAS_IMAGE_MODEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GOO_TYPE_CANVAS_IMAGE_MODEL))
-#define GOO_IS_CANVAS_IMAGE_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GOO_TYPE_CANVAS_IMAGE_MODEL))
-#define GOO_CANVAS_IMAGE_MODEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GOO_TYPE_CANVAS_IMAGE_MODEL, GooCanvasImageModelClass))
-
-
-typedef struct _GooCanvasImageModel GooCanvasImageModel;
-typedef struct _GooCanvasImageModelClass GooCanvasImageModelClass;
-
-/**
- * GooCanvasImageModel
- *
- * The #GooCanvasImageModel-struct struct contains private data only.
- */
-struct _GooCanvasImageModel
-{
- GooCanvasItemModelSimple parent_object;
-
- GooCanvasImageData image_data;
-};
-
-struct _GooCanvasImageModelClass
-{
- GooCanvasItemModelSimpleClass parent_class;
-
- /*< private >*/
-
- /* Padding for future expansion */
- void (*_goo_canvas_reserved1) (void);
- void (*_goo_canvas_reserved2) (void);
- void (*_goo_canvas_reserved3) (void);
- void (*_goo_canvas_reserved4) (void);
-};
-
-
-GType goo_canvas_image_model_get_type (void) G_GNUC_CONST;
-
-GooCanvasItemModel* goo_canvas_image_model_new (GooCanvasItemModel *parent,
- GdkPixbuf *pixbuf,
- gdouble x,
- gdouble y,
- ...);
-
-
G_END_DECLS
#endif /* __GOO_CANVAS_IMAGE_H__ */
diff --git a/src/goocanvasitem.c b/src/goocanvasitem.c
index 57db899..243310f 100644
--- a/src/goocanvasitem.c
+++ b/src/goocanvasitem.c
@@ -1238,7 +1238,6 @@ struct _GooCanvasItemAnimation
{
GooCanvasAnimateType type;
GooCanvasItem *item;
- GooCanvasItemModel *model;
int step, total_steps;
cairo_matrix_t start;
gdouble x_start, y_start, scale_start, radians_start;
@@ -1266,10 +1265,8 @@ static gboolean
goo_canvas_item_animate_cb (GooCanvasItemAnimation *anim)
{
GooCanvasItem *item = anim->item;
- GooCanvasItemModel *model = anim->model;
GooCanvasAnimateType type = anim->type;
GooCanvasItemIface *iface = NULL;
- GooCanvasItemModelIface *model_iface = NULL;
cairo_matrix_t new_matrix;
gboolean keep_source = TRUE;
gdouble scale;
@@ -1277,10 +1274,7 @@ goo_canvas_item_animate_cb (GooCanvasItemAnimation *anim)
GDK_THREADS_ENTER ();
- if (model)
- model_iface = GOO_CANVAS_ITEM_MODEL_GET_IFACE (model);
- else
- iface = GOO_CANVAS_ITEM_GET_IFACE (item);
+ iface = GOO_CANVAS_ITEM_GET_IFACE (item);
if (++anim->step > anim->total_steps)
{
@@ -1288,10 +1282,7 @@ goo_canvas_item_animate_cb (GooCanvasItemAnimation *anim)
{
case GOO_CANVAS_ANIMATE_RESET:
/* Reset the transform to the initial value. */
- if (model)
- model_iface->set_transform (model, &anim->start);
- else
- iface->set_transform (item, &anim->start);
+ iface->set_transform (item, &anim->start);
/* Fall through.. */
case GOO_CANVAS_ANIMATE_FREEZE:
@@ -1299,16 +1290,8 @@ goo_canvas_item_animate_cb (GooCanvasItemAnimation *anim)
anim->timeout_id = 0;
/* This will result in a call to goo_canvas_item_free_animation()
above. We've set the timeout_id to 0 so it isn't removed twice. */
- if (model)
- {
- g_object_set_data (G_OBJECT (model), animation_key, NULL);
- g_signal_emit_by_name (model, "animation-finished", FALSE);
- }
- else
- {
- g_object_set_data (G_OBJECT (item), animation_key, NULL);
- g_signal_emit_by_name (item, "animation-finished", FALSE);
- }
+ g_object_set_data (G_OBJECT (item), animation_key, NULL);
+ g_signal_emit_by_name (item, "animation-finished", FALSE);
break;
case GOO_CANVAS_ANIMATE_RESTART:
@@ -1347,10 +1330,7 @@ goo_canvas_item_animate_cb (GooCanvasItemAnimation *anim)
cairo_matrix_rotate (&new_matrix, anim->radians_step * step);
}
- if (model)
- model_iface->set_transform (model, &new_matrix);
- else
- iface->set_transform (item, &new_matrix);
+ iface->set_transform (item, &new_matrix);
}
GDK_THREADS_LEAVE ();
@@ -1362,7 +1342,6 @@ goo_canvas_item_animate_cb (GooCanvasItemAnimation *anim)
void
_goo_canvas_item_animate_internal (GooCanvasItem *item,
- GooCanvasItemModel *model,
gdouble x,
gdouble y,
gdouble scale,
@@ -1375,24 +1354,14 @@ _goo_canvas_item_animate_internal (GooCanvasItem *item,
GObject *object;
cairo_matrix_t matrix = { 1, 0, 0, 1, 0, 0 };
GooCanvasItemAnimation *anim;
+ GooCanvasItemIface *iface = GOO_CANVAS_ITEM_GET_IFACE (item);
- if (item)
- {
- GooCanvasItemIface *iface = GOO_CANVAS_ITEM_GET_IFACE (item);
- iface->get_transform (item, &matrix);
- object = (GObject*) item;
- }
- else
- {
- GooCanvasItemModelIface *iface = GOO_CANVAS_ITEM_MODEL_GET_IFACE (model);
- iface->get_transform (model, &matrix);
- object = (GObject*) model;
- }
+ iface->get_transform (item, &matrix);
+ object = (GObject*) item;
anim = g_new (GooCanvasItemAnimation, 1);
anim->type = type;
anim->item = item;
- anim->model = model;
anim->step = 0;
anim->total_steps = duration / step_time;
anim->start = matrix;
@@ -1472,7 +1441,7 @@ goo_canvas_item_animate (GooCanvasItem *item,
gint step_time,
GooCanvasAnimateType type)
{
- _goo_canvas_item_animate_internal (item, NULL, x, y, scale, degrees,
+ _goo_canvas_item_animate_internal (item, x, y, scale, degrees,
absolute, duration, step_time, type);
}
@@ -1611,41 +1580,6 @@ goo_canvas_item_is_visible (GooCanvasItem *item)
/**
- * goo_canvas_item_get_model:
- * @item: a #GooCanvasItem.
- *
- * Gets the model of the given canvas item.
- *
- * Returns: the item's model, or %NULL if it has no model.
- **/
-GooCanvasItemModel*
-goo_canvas_item_get_model (GooCanvasItem *item)
-{
- GooCanvasItemIface *iface = GOO_CANVAS_ITEM_GET_IFACE (item);
-
- return iface->get_model ? iface->get_model (item) : NULL;
-}
-
-
-/**
- * goo_canvas_item_set_model:
- * @item: a #GooCanvasItem.
- * @model: a #GooCanvasItemModel.
- *
- * Sets the model of the given canvas item.
- **/
-void
-goo_canvas_item_set_model (GooCanvasItem *item,
- GooCanvasItemModel *model)
-{
- GooCanvasItemIface *iface = GOO_CANVAS_ITEM_GET_IFACE (item);
-
- if (iface->set_model)
- iface->set_model (item, model);
-}
-
-
-/**
* goo_canvas_item_ensure_updated:
* @item: a #GooCanvasItem.
*
@@ -1822,31 +1756,17 @@ static inline void
item_get_child_property (GObject *object,
GObject *child,
GParamSpec *pspec,
- GValue *value,
- gboolean is_model)
+ GValue *value)
{
GObjectClass *class;
+ GooCanvasItemIface *iface;
class = g_type_class_peek (pspec->owner_type);
- if (is_model)
- {
- GooCanvasItemModelIface *iface;
-
- iface = g_type_interface_peek (class, GOO_TYPE_CANVAS_ITEM_MODEL);
- iface->get_child_property ((GooCanvasItemModel*) object,
- (GooCanvasItemModel*) child,
- pspec->param_id, value, pspec);
- }
- else
- {
- GooCanvasItemIface *iface;
-
- iface = g_type_interface_peek (class, GOO_TYPE_CANVAS_ITEM);
- iface->get_child_property ((GooCanvasItem*) object,
- (GooCanvasItem*) child,
- pspec->param_id, value, pspec);
- }
+ iface = g_type_interface_peek (class, GOO_TYPE_CANVAS_ITEM);
+ iface->get_child_property ((GooCanvasItem*) object,
+ (GooCanvasItem*) child,
+ pspec->param_id, value, pspec);
}
@@ -1855,8 +1775,7 @@ _goo_canvas_item_get_child_property_internal (GObject *object,
GObject *child,
const gchar *property_name,
GValue *value,
- GParamSpecPool *property_pool,
- gboolean is_model)
+ GParamSpecPool *property_pool)
{
GParamSpec *pspec;
@@ -1900,7 +1819,7 @@ _goo_canvas_item_get_child_property_internal (GObject *object,
g_value_init (&tmp_value, G_PARAM_SPEC_VALUE_TYPE (pspec));
prop_value = &tmp_value;
}
- item_get_child_property (object, child, pspec, prop_value, is_model);
+ item_get_child_property (object, child, pspec, prop_value);
if (prop_value != value)
{
g_value_transform (prop_value, value);
@@ -1917,8 +1836,7 @@ _goo_canvas_item_get_child_properties_internal (GObject *object,
GObject *child,
va_list var_args,
GParamSpecPool *property_pool,
- GObjectNotifyContext *notify_context,
- gboolean is_model)
+ GObjectNotifyContext *notify_context)
{
g_object_ref (object);
g_object_ref (child);
@@ -1948,7 +1866,7 @@ _goo_canvas_item_get_child_properties_internal (GObject *object,
break;
}
g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (pspec));
- item_get_child_property (object, child, pspec, &value, is_model);
+ item_get_child_property (object, child, pspec, &value);
G_VALUE_LCOPY (&value, var_args, 0, &error);
if (error)
{
@@ -1970,8 +1888,7 @@ canvas_item_set_child_property (GObject *object,
GObject *child,
GParamSpec *pspec,
const GValue *value,
- GObjectNotifyQueue *nqueue,
- gboolean is_model)
+ GObjectNotifyQueue *nqueue)
{
GValue tmp_value = { 0, };
@@ -1996,25 +1913,12 @@ canvas_item_set_child_property (GObject *object,
else
{
GObjectClass *class = g_type_class_peek (pspec->owner_type);
+ GooCanvasItemIface *iface;
- if (is_model)
- {
- GooCanvasItemModelIface *iface;
-
- iface = g_type_interface_peek (class, GOO_TYPE_CANVAS_ITEM_MODEL);
- iface->set_child_property ((GooCanvasItemModel*) object,
- (GooCanvasItemModel*) child,
- pspec->param_id, &tmp_value, pspec);
- }
- else
- {
- GooCanvasItemIface *iface;
-
- iface = g_type_interface_peek (class, GOO_TYPE_CANVAS_ITEM);
- iface->set_child_property ((GooCanvasItem*) object,
- (GooCanvasItem*) child,
- pspec->param_id, &tmp_value, pspec);
- }
+ iface = g_type_interface_peek (class, GOO_TYPE_CANVAS_ITEM);
+ iface->set_child_property ((GooCanvasItem*) object,
+ (GooCanvasItem*) child,
+ pspec->param_id, &tmp_value, pspec);
g_object_notify_queue_add (G_OBJECT (child), nqueue, pspec);
}
@@ -2028,8 +1932,7 @@ _goo_canvas_item_set_child_property_internal (GObject *object,
const gchar *property_name,
const GValue *value,
GParamSpecPool *property_pool,
- GObjectNotifyContext *notify_context,
- gboolean is_model)
+ GObjectNotifyContext *notify_context)
{
GObjectNotifyQueue *nqueue;
GParamSpec *pspec;
@@ -2052,8 +1955,7 @@ _goo_canvas_item_set_child_property_internal (GObject *object,
G_OBJECT_TYPE_NAME (object));
else
{
- canvas_item_set_child_property (object, child, pspec,
- value, nqueue, is_model);
+ canvas_item_set_child_property (object, child, pspec, value, nqueue);
}
g_object_notify_queue_thaw (child, nqueue);
g_object_unref (object);
@@ -2066,8 +1968,7 @@ _goo_canvas_item_set_child_properties_internal (GObject *object,
GObject *child,
va_list var_args,
GParamSpecPool *property_pool,
- GObjectNotifyContext *notify_context,
- gboolean is_model)
+ GObjectNotifyContext *notify_context)
{
GObjectNotifyQueue *nqueue;
@@ -2112,8 +2013,7 @@ _goo_canvas_item_set_child_properties_internal (GObject *object,
*/
break;
}
- canvas_item_set_child_property (object, child, pspec, &value, nqueue,
- is_model);
+ canvas_item_set_child_property (object, child, pspec, &value, nqueue);
g_value_unset (&value);
}
g_object_notify_queue_thaw (G_OBJECT (child), nqueue);
@@ -2143,7 +2043,7 @@ goo_canvas_item_get_child_property (GooCanvasItem *item,
g_return_if_fail (property_name != NULL);
g_return_if_fail (G_IS_VALUE (value));
- _goo_canvas_item_get_child_property_internal ((GObject*) item, (GObject*) child, property_name, value, _goo_canvas_item_child_property_pool, FALSE);
+ _goo_canvas_item_get_child_property_internal ((GObject*) item, (GObject*) child, property_name, value, _goo_canvas_item_child_property_pool);
}
@@ -2167,7 +2067,7 @@ goo_canvas_item_set_child_property (GooCanvasItem *item,
g_return_if_fail (property_name != NULL);
g_return_if_fail (G_IS_VALUE (value));
- _goo_canvas_item_set_child_property_internal ((GObject*) item, (GObject*) child, property_name, value, _goo_canvas_item_child_property_pool, _goo_canvas_item_child_property_notify_context, FALSE);
+ _goo_canvas_item_set_child_property_internal ((GObject*) item, (GObject*) child, property_name, value, _goo_canvas_item_child_property_pool, _goo_canvas_item_child_property_notify_context);
}
@@ -2188,7 +2088,7 @@ goo_canvas_item_get_child_properties_valist (GooCanvasItem *item,
g_return_if_fail (GOO_IS_CANVAS_ITEM (item));
g_return_if_fail (GOO_IS_CANVAS_ITEM (child));
- _goo_canvas_item_get_child_properties_internal ((GObject*) item, (GObject*) child, var_args, _goo_canvas_item_child_property_pool, _goo_canvas_item_child_property_notify_context, FALSE);
+ _goo_canvas_item_get_child_properties_internal ((GObject*) item, (GObject*) child, var_args, _goo_canvas_item_child_property_pool, _goo_canvas_item_child_property_notify_context);
}
@@ -2208,7 +2108,7 @@ goo_canvas_item_set_child_properties_valist (GooCanvasItem *item,
g_return_if_fail (GOO_IS_CANVAS_ITEM (item));
g_return_if_fail (GOO_IS_CANVAS_ITEM (child));
- _goo_canvas_item_set_child_properties_internal ((GObject*) item, (GObject*) child, var_args, _goo_canvas_item_child_property_pool, _goo_canvas_item_child_property_notify_context, FALSE);
+ _goo_canvas_item_set_child_properties_internal ((GObject*) item, (GObject*) child, var_args, _goo_canvas_item_child_property_pool, _goo_canvas_item_child_property_notify_context);
}
diff --git a/src/goocanvasitem.h b/src/goocanvasitem.h
index 76c61ec..658904f 100644
--- a/src/goocanvasitem.h
+++ b/src/goocanvasitem.h
@@ -61,7 +61,6 @@ GType goo_canvas_bounds_get_type (void) G_GNUC_CONST;
/* Workaround for circular dependencies. Include this file first. */
typedef struct _GooCanvas GooCanvas;
-typedef struct _GooCanvasItemModel GooCanvasItemModel;
/**
@@ -113,8 +112,6 @@ typedef struct _GooCanvasItem GooCanvasItem;
* @set_is_static: notifies the item whether it is static or not.
* @get_requested_height: returns the requested height of the item,
* given a particular allocated width, using the parent's coordinate space.
- * @get_model: gets the model that the canvas item is viewing.
- * @set_model: sets the model that the canvas item will view.
* @enter_notify_event: signal emitted when the mouse enters the item.
* @leave_notify_event: signal emitted when the mouse leaves the item.
* @motion_notify_event: signal emitted when the mouse moves within the item.
@@ -236,11 +233,6 @@ struct _GooCanvasItemIface
cairo_t *cr,
gdouble width);
- /* Virtual methods that model/view items must implement. */
- GooCanvasItemModel* (* get_model) (GooCanvasItem *item);
- void (* set_model) (GooCanvasItem *item,
- GooCanvasItemModel *model);
-
/* Signals. */
gboolean (* enter_notify_event) (GooCanvasItem *item,
@@ -427,10 +419,6 @@ GList* goo_canvas_item_get_items_at (GooCanvasItem *item,
GList *found_items);
gboolean goo_canvas_item_is_visible (GooCanvasItem *item);
-GooCanvasItemModel* goo_canvas_item_get_model (GooCanvasItem *item);
-void goo_canvas_item_set_model (GooCanvasItem *item,
- GooCanvasItemModel *model);
-
void goo_canvas_item_request_update (GooCanvasItem *item);
void goo_canvas_item_ensure_updated (GooCanvasItem *item);
void goo_canvas_item_update (GooCanvasItem *item,
diff --git a/src/goocanvasitemsimple.c b/src/goocanvasitemsimple.c
index 46544ed..2376dd3 100644
--- a/src/goocanvasitemsimple.c
+++ b/src/goocanvasitemsimple.c
@@ -87,7 +87,6 @@ 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,
@@ -299,14 +298,6 @@ goo_canvas_item_simple_install_common_properties (GObjectClass *gobject_class)
* 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"),
@@ -331,7 +322,6 @@ 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;
@@ -355,102 +345,70 @@ goo_canvas_item_simple_class_init (GooCanvasItemSimpleClass *klass)
static void
-goo_canvas_item_simple_init (GooCanvasItemSimple *item)
+goo_canvas_item_simple_init (GooCanvasItemSimple *simple)
{
- GooCanvasBounds *bounds = &item->bounds;
+ GooCanvasBounds *bounds = &simple->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;
+ simple->visibility = GOO_CANVAS_ITEM_VISIBLE;
+ simple->pointer_events = GOO_CANVAS_EVENTS_VISIBLE_PAINTED;
+ simple->clip_fill_rule = CAIRO_FILL_RULE_WINDING;
+ simple->need_update = TRUE;
+ simple->need_entire_subtree_update = TRUE;
}
static void
-goo_canvas_item_simple_reset_model (GooCanvasItemSimple *simple)
+goo_canvas_item_simple_dispose (GObject *object)
{
- if (simple->model)
+ GooCanvasItemSimple *simple = (GooCanvasItemSimple*) object;
+
+ if (simple->style)
{
- 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;
+ g_object_unref (simple->style);
+ simple->style = 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->clip_path_commands)
{
- 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;
+ g_array_free (simple->clip_path_commands, TRUE);
+ simple->clip_path_commands = 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_slice_free (cairo_matrix_t, simple->transform);
+ simple->transform = NULL;
G_OBJECT_CLASS (goo_canvas_item_simple_parent_class)->dispose (object);
}
static void
-goo_canvas_item_simple_finalize (GObject *object)
+goo_canvas_item_simple_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
{
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;
+ AtkObject *accessible;
+ GooCanvasStyle *style = simple->style;
GValue *svalue;
gdouble line_width = 2.0;
gchar *font = NULL;
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;
+
/* Basic drawing properties. */
case PROP_STROKE_PATTERN:
svalue = goo_canvas_style_get_property (style, goo_canvas_style_stroke_pattern_id);
@@ -478,8 +436,8 @@ goo_canvas_item_simple_get_common_property (GObject *object,
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);
+ else if (simple->canvas)
+ line_width = goo_canvas_get_default_line_width (simple->canvas);
g_value_set_double (value, line_width);
break;
case PROP_LINE_CAP:
@@ -532,25 +490,25 @@ goo_canvas_item_simple_get_common_property (GObject *object,
/* Other properties. */
case PROP_TRANSFORM:
- g_value_set_boxed (value, simple_data->transform);
+ g_value_set_boxed (value, simple->transform);
break;
case PROP_VISIBILITY:
- g_value_set_enum (value, simple_data->visibility);
+ g_value_set_enum (value, simple->visibility);
break;
case PROP_VISIBILITY_THRESHOLD:
- g_value_set_double (value, simple_data->visibility_threshold);
+ g_value_set_double (value, simple->visibility_threshold);
break;
case PROP_POINTER_EVENTS:
- g_value_set_flags (value, simple_data->pointer_events);
+ g_value_set_flags (value, simple->pointer_events);
break;
case PROP_CAN_FOCUS:
- g_value_set_boolean (value, simple_data->can_focus);
+ g_value_set_boolean (value, simple->can_focus);
break;
case PROP_CLIP_FILL_RULE:
- g_value_set_enum (value, simple_data->clip_fill_rule);
+ g_value_set_enum (value, simple->clip_fill_rule);
break;
case PROP_TOOLTIP:
- g_value_set_string (value, simple_data->tooltip);
+ g_value_set_string (value, simple->tooltip);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -560,47 +518,18 @@ goo_canvas_item_simple_get_common_property (GObject *object,
static void
-goo_canvas_item_simple_get_property (GObject *object,
+goo_canvas_item_simple_set_property (GObject *object,
guint prop_id,
- GValue *value,
+ const GValue *value,
GParamSpec *pspec)
{
+ GooCanvasItem *item = (GooCanvasItem*) object;
GooCanvasItemSimple *simple = (GooCanvasItemSimple*) object;
- GooCanvasItemSimpleData *simple_data = simple->simple_data;
+ GooCanvasItem *parent;
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;
+ gboolean need_update = TRUE, recompute_bounds = FALSE;
cairo_matrix_t *transform;
GValue tmpval = { 0 };
const char *font_name;
@@ -609,22 +538,39 @@ goo_canvas_item_simple_set_common_property (GObject *object,
/* See if we need to create our own style. */
if (prop_id < PROP_TRANSFORM)
{
- if (!simple_data->style)
+ if (!simple->style)
{
- simple_data->style = goo_canvas_style_new ();
+ simple->style = goo_canvas_style_new ();
}
- else if (!simple_data->own_style)
+ else if (!simple->own_style)
{
- g_object_unref (simple_data->style);
- simple_data->style = goo_canvas_style_new ();
+ g_object_unref (simple->style);
+ simple->style = goo_canvas_style_new ();
}
- simple_data->own_style = TRUE;
+ simple->own_style = TRUE;
}
- style = simple_data->style;
+ style = simple->style;
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);
+ need_update = FALSE;
+ break;
+ case PROP_TITLE:
+ accessible = atk_gobject_accessible_for_object (object);
+ atk_object_set_name (accessible, g_value_get_string (value));
+ need_update = FALSE;
+ break;
+ case PROP_DESCRIPTION:
+ accessible = atk_gobject_accessible_for_object (object);
+ atk_object_set_description (accessible, g_value_get_string (value));
+ need_update = FALSE;
+ break;
+
/* Basic drawing properties. */
case PROP_STROKE_PATTERN:
goo_canvas_style_set_property (style, goo_canvas_style_stroke_pattern_id, value);
@@ -714,88 +660,43 @@ goo_canvas_item_simple_set_common_property (GObject *object,
/* Other properties. */
case PROP_TRANSFORM:
- g_slice_free (cairo_matrix_t, simple_data->transform);
+ g_slice_free (cairo_matrix_t, simple->transform);
transform = g_value_get_boxed (value);
- simple_data->transform = goo_cairo_matrix_copy (transform);
+ simple->transform = goo_cairo_matrix_copy (transform);
recompute_bounds = TRUE;
break;
case PROP_VISIBILITY:
- simple_data->visibility = g_value_get_enum (value);
+ simple->visibility = g_value_get_enum (value);
break;
case PROP_VISIBILITY_THRESHOLD:
- simple_data->visibility_threshold = g_value_get_double (value);
+ simple->visibility_threshold = g_value_get_double (value);
break;
case PROP_POINTER_EVENTS:
- simple_data->pointer_events = g_value_get_flags (value);
+ simple->pointer_events = g_value_get_flags (value);
break;
case PROP_CAN_FOCUS:
- simple_data->can_focus = g_value_get_boolean (value);
+ simple->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));
+ if (simple->clip_path_commands)
+ g_array_free (simple->clip_path_commands, TRUE);
+ simple->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);
+ simple->clip_fill_rule = g_value_get_enum (value);
recompute_bounds = TRUE;
break;
case PROP_TOOLTIP:
- simple_data->tooltip = g_value_dup_string (value);
+ simple->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;
- }
+ if (need_update)
+ goo_canvas_item_simple_changed (simple, recompute_bounds);
}
@@ -846,7 +747,6 @@ goo_canvas_item_simple_set_parent (GooCanvasItem *item,
*
* 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
@@ -854,7 +754,6 @@ goo_canvas_item_simple_changed (GooCanvasItemSimple *item,
gboolean recompute_bounds)
{
GooCanvasItemSimple *simple = (GooCanvasItemSimple*) item;
- GooCanvasItemSimpleData *simple_data = simple->simple_data;
if (recompute_bounds)
{
@@ -871,7 +770,7 @@ goo_canvas_item_simple_changed (GooCanvasItemSimple *item,
else
{
if (item->canvas)
- goo_canvas_request_item_redraw (item->canvas, &item->bounds, simple_data->is_static);
+ goo_canvas_request_item_redraw (item->canvas, &item->bounds, simple->is_static);
}
}
@@ -881,12 +780,11 @@ 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)
+ if (!simple->transform)
return FALSE;
- *matrix = *simple_data->transform;
+ *matrix = *simple->transform;
return TRUE;
}
@@ -896,19 +794,18 @@ 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);
+ if (!simple->transform)
+ simple->transform = g_slice_new (cairo_matrix_t);
- *simple_data->transform = *transform;
+ *simple->transform = *transform;
}
else
{
- g_slice_free (cairo_matrix_t, simple_data->transform);
- simple_data->transform = NULL;
+ g_slice_free (cairo_matrix_t, simple->transform);
+ simple->transform = NULL;
}
goo_canvas_item_simple_changed (simple, TRUE);
@@ -920,7 +817,7 @@ goo_canvas_item_simple_get_style (GooCanvasItem *item)
{
GooCanvasItemSimple *simple = (GooCanvasItemSimple*) item;
- return simple->simple_data->style;
+ return simple->style;
}
@@ -929,20 +826,19 @@ 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 (simple->style)
+ g_object_unref (simple->style);
if (style)
{
- simple_data->style = goo_canvas_style_copy (style);
- simple_data->own_style = TRUE;
+ simple->style = goo_canvas_style_copy (style);
+ simple->own_style = TRUE;
}
else
{
- simple_data->style = NULL;
- simple_data->own_style = FALSE;
+ simple->style = NULL;
+ simple->own_style = FALSE;
}
goo_canvas_item_simple_changed (simple, TRUE);
@@ -973,7 +869,6 @@ goo_canvas_item_simple_get_items_at (GooCanvasItem *item,
{
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;
@@ -989,19 +884,19 @@ goo_canvas_item_simple_get_items_at (GooCanvasItem *item,
/* Check if the item should receive events. */
if (is_pointer_event)
{
- if (simple_data->pointer_events == GOO_CANVAS_EVENTS_NONE)
+ if (simple->pointer_events == GOO_CANVAS_EVENTS_NONE)
return found_items;
- if (simple_data->pointer_events & GOO_CANVAS_EVENTS_VISIBLE_MASK
+ if (simple->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)))
+ || simple->visibility <= GOO_CANVAS_ITEM_INVISIBLE
+ || (simple->visibility == GOO_CANVAS_ITEM_VISIBLE_ABOVE_THRESHOLD
+ && simple->canvas->scale < simple->visibility_threshold)))
return found_items;
}
cairo_save (cr);
- if (simple_data->transform)
- cairo_transform (cr, simple_data->transform);
+ if (simple->transform)
+ cairo_transform (cr, simple->transform);
cairo_device_to_user (cr, &user_x, &user_y);
@@ -1011,10 +906,10 @@ goo_canvas_item_simple_get_items_at (GooCanvasItem *item,
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)
+ if (simple->clip_path_commands)
{
- goo_canvas_create_path (simple_data->clip_path_commands, cr);
- cairo_set_fill_rule (cr, simple_data->clip_fill_rule);
+ goo_canvas_create_path (simple->clip_path_commands, cr);
+ cairo_set_fill_rule (cr, simple->clip_fill_rule);
if (!cairo_in_fill (cr, user_x, user_y))
{
cairo_restore (cr);
@@ -1042,12 +937,10 @@ goo_canvas_item_simple_default_is_item_at (GooCanvasItemSimple *simple,
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;
+ pointer_events = simple->pointer_events;
/* Use the virtual method subclasses define to create the path. */
class->simple_create_path (simple, cr);
@@ -1063,11 +956,10 @@ 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))
+ if (simple->visibility <= GOO_CANVAS_ITEM_INVISIBLE
+ || (simple->visibility == GOO_CANVAS_ITEM_VISIBLE_ABOVE_THRESHOLD
+ && simple->canvas->scale < simple->visibility_threshold))
return FALSE;
if (simple->parent)
@@ -1081,9 +973,8 @@ 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;
+ return simple->is_static;
}
@@ -1092,9 +983,8 @@ 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;
+ simple->is_static = is_static;
}
@@ -1110,26 +1000,25 @@ goo_canvas_item_simple_set_is_static (GooCanvasItem *item,
* doesn't have its own style it uses the parent item's style.
**/
void
-goo_canvas_item_simple_check_style (GooCanvasItemSimple *item)
+goo_canvas_item_simple_check_style (GooCanvasItemSimple *simple)
{
- GooCanvasItemSimpleData *simple_data = item->simple_data;
GooCanvasStyle *parent_style = NULL;
- if (item->parent)
- parent_style = goo_canvas_item_get_style (item->parent);
+ if (simple->parent)
+ parent_style = goo_canvas_item_get_style (simple->parent);
- if (simple_data->own_style)
+ if (simple->own_style)
{
- goo_canvas_style_set_parent (simple_data->style, parent_style);
+ goo_canvas_style_set_parent (simple->style, parent_style);
}
- else if (simple_data->style != parent_style)
+ else if (simple->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);
+ if (simple->style)
+ g_object_unref (simple->style);
- simple_data->style = parent_style;
+ simple->style = parent_style;
if (parent_style)
g_object_ref (parent_style);
@@ -1142,7 +1031,6 @@ 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;
@@ -1155,11 +1043,11 @@ goo_canvas_item_simple_update_internal (GooCanvasItemSimple *simple,
class->simple_update (simple, cr);
/* Modify the extents by the item's clip path. */
- if (simple_data->clip_path_commands)
+ if (simple->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);
+ goo_canvas_create_path (simple->clip_path_commands, cr);
+ cairo_set_fill_rule (cr, simple->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);
@@ -1198,18 +1086,17 @@ goo_canvas_item_simple_update (GooCanvasItem *item,
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);
+ goo_canvas_request_item_redraw (simple->canvas, &simple->bounds, simple->is_static);
cairo_save (cr);
- if (simple_data->transform)
- cairo_transform (cr, simple_data->transform);
+ if (simple->transform)
+ cairo_transform (cr, simple->transform);
/* Remove any current translation, to avoid the 16-bit cairo limit. */
cairo_get_matrix (cr, &matrix);
@@ -1232,7 +1119,7 @@ goo_canvas_item_simple_update (GooCanvasItem *item,
cairo_restore (cr);
/* Request a redraw of the new bounds. */
- goo_canvas_request_item_redraw (simple->canvas, &simple->bounds, simple_data->is_static);
+ goo_canvas_request_item_redraw (simple->canvas, &simple->bounds, simple->is_static);
}
*bounds = simple->bounds;
@@ -1245,16 +1132,15 @@ goo_canvas_item_simple_get_requested_area (GooCanvasItem *item,
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);
+ goo_canvas_request_item_redraw (simple->canvas, &simple->bounds, simple->is_static);
cairo_save (cr);
- if (simple_data->transform)
- cairo_transform (cr, simple_data->transform);
+ if (simple->transform)
+ cairo_transform (cr, simple->transform);
/* Remove any current translation, to avoid the 16-bit cairo limit. */
cairo_get_matrix (cr, &matrix);
@@ -1265,7 +1151,7 @@ goo_canvas_item_simple_get_requested_area (GooCanvasItem *item,
goo_canvas_item_simple_update_internal (simple, cr);
- if (simple->simple_data->visibility == GOO_CANVAS_ITEM_HIDDEN)
+ if (simple->visibility == GOO_CANVAS_ITEM_HIDDEN)
{
simple->bounds.x1 = simple->bounds.x2 = 0.0;
simple->bounds.y1 = simple->bounds.y2 = 0.0;
@@ -1320,7 +1206,6 @@ goo_canvas_item_simple_allocate_area (GooCanvasItem *item,
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. */
@@ -1330,7 +1215,7 @@ goo_canvas_item_simple_allocate_area (GooCanvasItem *item,
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);
+ goo_canvas_request_item_redraw (simple->canvas, &simple->bounds, simple->is_static);
}
@@ -1342,7 +1227,6 @@ goo_canvas_item_simple_paint (GooCanvasItem *item,
{
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
@@ -1350,20 +1234,20 @@ goo_canvas_item_simple_paint (GooCanvasItem *item,
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))
+ if (simple->visibility <= GOO_CANVAS_ITEM_INVISIBLE
+ || (simple->visibility == GOO_CANVAS_ITEM_VISIBLE_ABOVE_THRESHOLD
+ && scale < simple->visibility_threshold))
return;
cairo_save (cr);
- if (simple_data->transform)
- cairo_transform (cr, simple_data->transform);
+ if (simple->transform)
+ cairo_transform (cr, simple->transform);
/* Clip with the item's clip path, if it is set. */
- if (simple_data->clip_path_commands)
+ if (simple->clip_path_commands)
{
- goo_canvas_create_path (simple_data->clip_path_commands, cr);
- cairo_set_fill_rule (cr, simple_data->clip_fill_rule);
+ goo_canvas_create_path (simple->clip_path_commands, cr);
+ cairo_set_fill_rule (cr, simple->clip_fill_rule);
cairo_clip (cr);
}
@@ -1393,109 +1277,6 @@ goo_canvas_item_simple_default_create_path (GooCanvasItemSimple *simple,
}
-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,
@@ -1504,11 +1285,10 @@ goo_canvas_item_simple_query_tooltip (GooCanvasItem *item,
GtkTooltip *tooltip)
{
GooCanvasItemSimple *simple = (GooCanvasItemSimple*) item;
- GooCanvasItemSimpleData *simple_data = simple->simple_data;
- if (simple_data->tooltip)
+ if (simple->tooltip)
{
- gtk_tooltip_set_markup (tooltip, simple_data->tooltip);
+ gtk_tooltip_set_markup (tooltip, simple->tooltip);
return TRUE;
}
@@ -1539,9 +1319,6 @@ canvas_item_interface_init (GooCanvasItemIface *iface)
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;
}
@@ -1556,10 +1333,10 @@ canvas_item_interface_init (GooCanvasItemIface *iface)
* It paints the current path, using the item's style settings.
**/
void
-goo_canvas_item_simple_paint_path (GooCanvasItemSimple *item,
+goo_canvas_item_simple_paint_path (GooCanvasItemSimple *simple,
cairo_t *cr)
{
- GooCanvasStyle *style = item->simple_data->style;
+ GooCanvasStyle *style = simple->style;
if (goo_canvas_style_set_fill_options (style, cr))
cairo_fill_preserve (cr);
@@ -1593,11 +1370,11 @@ goo_canvas_item_simple_paint_path (GooCanvasItemSimple *item,
* transformation matrix to the identity matrix.
**/
void
-goo_canvas_item_simple_get_path_bounds (GooCanvasItemSimple *item,
+goo_canvas_item_simple_get_path_bounds (GooCanvasItemSimple *simple,
cairo_t *cr,
GooCanvasBounds *bounds)
{
- GooCanvasStyle *style = item->simple_data->style;
+ GooCanvasStyle *style = simple->style;
GooCanvasBounds fill_bounds, stroke_bounds;
/* Calculate the filled extents. */
@@ -1724,12 +1501,11 @@ goo_canvas_item_simple_user_bounds_to_device (GooCanvasItemSimple *item,
* needed.
**/
void
-goo_canvas_item_simple_user_bounds_to_parent (GooCanvasItemSimple *item,
+goo_canvas_item_simple_user_bounds_to_parent (GooCanvasItemSimple *simple,
cairo_t *cr,
GooCanvasBounds *bounds)
{
- GooCanvasItemSimpleData *simple_data = item->simple_data;
- cairo_matrix_t *transform = simple_data->transform;
+ cairo_matrix_t *transform = simple->transform;
GooCanvasBounds tmp_bounds, tmp_bounds2;
if (!transform)
@@ -1783,13 +1559,13 @@ goo_canvas_item_simple_user_bounds_to_parent (GooCanvasItemSimple *item,
* Returns: %TRUE if the given point is in the current path.
**/
gboolean
-goo_canvas_item_simple_check_in_path (GooCanvasItemSimple *item,
+goo_canvas_item_simple_check_in_path (GooCanvasItemSimple *simple,
gdouble x,
gdouble y,
cairo_t *cr,
GooCanvasPointerEvents pointer_events)
{
- GooCanvasStyle *style = item->simple_data->style;
+ GooCanvasStyle *style = simple->style;
gboolean do_fill, do_stroke;
/* Check the filled path, if required. */
@@ -1827,270 +1603,16 @@ goo_canvas_item_simple_check_in_path (GooCanvasItemSimple *item,
* Returns: the item's line width.
**/
gdouble
-goo_canvas_item_simple_get_line_width (GooCanvasItemSimple *item)
+goo_canvas_item_simple_get_line_width (GooCanvasItemSimple *simple)
{
GValue *value;
- value = goo_canvas_style_get_property (item->simple_data->style,
+ value = goo_canvas_style_get_property (simple->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 if (simple->canvas)
+ return goo_canvas_get_default_line_width (simple->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;
-}
diff --git a/src/goocanvasitemsimple.h b/src/goocanvasitemsimple.h
index 39ad00f..9955785 100644
--- a/src/goocanvasitemsimple.h
+++ b/src/goocanvasitemsimple.h
@@ -9,59 +9,12 @@
#include <gtk/gtk.h>
#include "goocanvasitem.h"
-#include "goocanvasitemmodel.h"
#include "goocanvasstyle.h"
#include "goocanvasutils.h"
G_BEGIN_DECLS
-/**
- * GooCanvasItemSimpleData
- * @style: the style to draw with.
- * @transform: the transformation matrix of the item, or %NULL.
- * @clip_path_commands: an array of #GooCanvasPathCommand specifying the clip
- * path of the item, or %NULL.
- * @tooltip: the item's tooltip.
- * @visibility_threshold: the threshold scale setting at which to show the item
- * (if the @visibility setting is set to %VISIBLE_ABOVE_THRESHOLD).
- * @visibility: the #GooCanvasItemVisibility setting specifying whether the
- * item is visible, invisible, or visible above a given canvas scale setting.
- * @pointer_events: the #GooCanvasPointerEvents setting specifying the events
- * the item should receive.
- * @can_focus: if the item can take the keyboard focus.
- * @own_style: if the item has its own style, rather than using its parent's.
- * @clip_fill_rule: the #cairo_fill_rule_t setting specifying the fill rule
- * used for the clip path.
- * @is_static: if the item is static.
- *
- * This is the data common to both the model and view classes.
- */
-typedef struct _GooCanvasItemSimpleData GooCanvasItemSimpleData;
-struct _GooCanvasItemSimpleData
-{
- GooCanvasStyle *style;
- cairo_matrix_t *transform;
- GArray *clip_path_commands;
- gchar *tooltip;
-
- /*< public >*/
- gdouble visibility_threshold;
- guint visibility : 2;
- guint pointer_events : 4;
- guint can_focus : 1;
- guint own_style : 1;
- guint clip_fill_rule : 4;
- guint is_static : 1;
-
- /*< private >*/
- /* We might use this in future for a cache setting - never/always/visible. */
- guint cache_setting : 2;
- /* We might need this for tooltips in future. */
- guint has_tooltip : 1;
-};
-
-
#define GOO_TYPE_CANVAS_ITEM_SIMPLE (goo_canvas_item_simple_get_type ())
#define GOO_CANVAS_ITEM_SIMPLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GOO_TYPE_CANVAS_ITEM_SIMPLE, GooCanvasItemSimple))
#define GOO_CANVAS_ITEM_SIMPLE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GOO_TYPE_CANVAS_ITEM_SIMPLE, GooCanvasItemSimpleClass))
@@ -73,20 +26,30 @@ struct _GooCanvasItemSimpleData
typedef struct _GooCanvasItemSimple GooCanvasItemSimple;
typedef struct _GooCanvasItemSimpleClass GooCanvasItemSimpleClass;
-typedef struct _GooCanvasItemModelSimple GooCanvasItemModelSimple;
/**
* GooCanvasItemSimple
* @canvas: the canvas.
* @parent: the parent item.
- * @model: the item's model, if it has one.
- * @simple_data: data that is common to both the model and view classes. If
- * the canvas item has a model, this will point to the model's
- * #GooCanvasItemSimpleData, otherwise the canvas item will have its own
- * #GooCanvasItemSimpleData.
* @bounds: the bounds of the item, in device space.
* @need_update: if the item needs to recompute its bounds and redraw.
* @need_entire_subtree_update: if all descendants need to be updated.
+ * @style: the style to draw with.
+ * @transform: the transformation matrix of the item, or %NULL.
+ * @clip_path_commands: an array of #GooCanvasPathCommand specifying the clip
+ * path of the item, or %NULL.
+ * @tooltip: the item's tooltip.
+ * @visibility_threshold: the threshold scale setting at which to show the item
+ * (if the @visibility setting is set to %VISIBLE_ABOVE_THRESHOLD).
+ * @visibility: the #GooCanvasItemVisibility setting specifying whether the
+ * item is visible, invisible, or visible above a given canvas scale setting.
+ * @pointer_events: the #GooCanvasPointerEvents setting specifying the events
+ * the item should receive.
+ * @can_focus: if the item can take the keyboard focus.
+ * @own_style: if the item has its own style, rather than using its parent's.
+ * @clip_fill_rule: the #cairo_fill_rule_t setting specifying the fill rule
+ * used for the clip path.
+ * @is_static: if the item is static.
*
* The #GooCanvasItemSimple-struct struct contains the basic data needed to
* implement canvas items.
@@ -99,15 +62,23 @@ struct _GooCanvasItemSimple
/* <public> */
GooCanvas *canvas;
GooCanvasItem *parent;
- GooCanvasItemModelSimple *model;
- GooCanvasItemSimpleData *simple_data;
+ GooCanvasStyle *style;
+ cairo_matrix_t *transform;
+ GArray *clip_path_commands;
+ gchar *tooltip;
+
GooCanvasBounds bounds;
+
+ gdouble visibility_threshold;
+
guint need_update : 1;
guint need_entire_subtree_update : 1;
-
- /* <private> */
- /* We might use this in future for things like a cache. */
- gpointer priv;
+ guint visibility : 2;
+ guint pointer_events : 4;
+ guint can_focus : 1;
+ guint own_style : 1;
+ guint clip_fill_rule : 4;
+ guint is_static : 1;
};
/**
@@ -184,62 +155,7 @@ void goo_canvas_item_simple_changed (GooCanvasItemSimple *item,
gboolean recompute_bounds);
void goo_canvas_item_simple_check_style (GooCanvasItemSimple *item);
gdouble goo_canvas_item_simple_get_line_width (GooCanvasItemSimple *item);
-void goo_canvas_item_simple_set_model (GooCanvasItemSimple *item,
- GooCanvasItemModel *model);
-
-
-
-
-
-#define GOO_TYPE_CANVAS_ITEM_MODEL_SIMPLE (goo_canvas_item_model_simple_get_type ())
-#define GOO_CANVAS_ITEM_MODEL_SIMPLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GOO_TYPE_CANVAS_ITEM_MODEL_SIMPLE, GooCanvasItemModelSimple))
-#define GOO_CANVAS_ITEM_MODEL_SIMPLE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GOO_TYPE_CANVAS_ITEM_MODEL_SIMPLE, GooCanvasItemModelSimpleClass))
-#define GOO_IS_CANVAS_ITEM_MODEL_SIMPLE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GOO_TYPE_CANVAS_ITEM_MODEL_SIMPLE))
-#define GOO_IS_CANVAS_ITEM_MODEL_SIMPLE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GOO_TYPE_CANVAS_ITEM_MODEL_SIMPLE))
-#define GOO_CANVAS_ITEM_MODEL_SIMPLE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GOO_TYPE_CANVAS_ITEM_MODEL_SIMPLE, GooCanvasItemModelSimpleClass))
-
-
-typedef struct _GooCanvasItemModelSimpleClass GooCanvasItemModelSimpleClass;
-
-/**
- * GooCanvasItemModelSimple
- * @parent: the parent model.
- * @simple_data: data used by the canvas item for viewing the model.
- *
- * The #GooCanvasItemModelSimple-struct struct contains the basic data needed
- * to implement canvas item models.
- */
-struct _GooCanvasItemModelSimple
-{
- GObject parent_object;
-
- /*< public >*/
- GooCanvasItemModel *parent;
- GooCanvasItemSimpleData simple_data;
-
- /*< private >*/
-
- /* The title and description of the item for accessibility. */
- gchar *title;
- gchar *description;
-};
-
-
-struct _GooCanvasItemModelSimpleClass
-{
- GObjectClass parent_class;
-
- /*< private >*/
-
- /* Padding for future expansion */
- void (*_goo_canvas_reserved1) (void);
- void (*_goo_canvas_reserved2) (void);
- void (*_goo_canvas_reserved3) (void);
- void (*_goo_canvas_reserved4) (void);
-};
-
-GType goo_canvas_item_model_simple_get_type (void) G_GNUC_CONST;
G_END_DECLS
diff --git a/src/goocanvaspath.c b/src/goocanvaspath.c
index 0254a66..801360c 100644
--- a/src/goocanvaspath.c
+++ b/src/goocanvaspath.c
@@ -47,67 +47,14 @@ enum {
PROP_HEIGHT
};
-static void canvas_item_interface_init (GooCanvasItemIface *iface);
-G_DEFINE_TYPE_WITH_CODE (GooCanvasPath, goo_canvas_path,
- GOO_TYPE_CANVAS_ITEM_SIMPLE,
- G_IMPLEMENT_INTERFACE (GOO_TYPE_CANVAS_ITEM,
- canvas_item_interface_init))
-
-
-static void
-goo_canvas_path_install_common_properties (GObjectClass *gobject_class)
-{
- /**
- * GooCanvasPath:data
- *
- * The sequence of path commands, 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_DATA,
- g_param_spec_string ("data",
- _("Path Data"),
- _("The sequence of path commands"),
- NULL,
- G_PARAM_WRITABLE));
-
- g_object_class_install_property (gobject_class, PROP_X,
- g_param_spec_double ("x",
- "X",
- _("The x coordinate of the path"),
- -G_MAXDOUBLE,
- G_MAXDOUBLE, 0.0,
- G_PARAM_READWRITE));
-
- g_object_class_install_property (gobject_class, PROP_Y,
- g_param_spec_double ("y",
- "Y",
- _("The y coordinate of the path"),
- -G_MAXDOUBLE,
- G_MAXDOUBLE, 0.0,
- G_PARAM_READWRITE));
-
- g_object_class_install_property (gobject_class, PROP_WIDTH,
- g_param_spec_double ("width",
- _("Width"),
- _("The width of the path"),
- 0.0, G_MAXDOUBLE, 0.0,
- G_PARAM_READWRITE));
-
- g_object_class_install_property (gobject_class, PROP_HEIGHT,
- g_param_spec_double ("height",
- _("Height"),
- _("The height of the path"),
- 0.0, G_MAXDOUBLE, 0.0,
- G_PARAM_READWRITE));
-}
+G_DEFINE_TYPE (GooCanvasPath, goo_canvas_path, GOO_TYPE_CANVAS_ITEM_SIMPLE)
static void
goo_canvas_path_init (GooCanvasPath *path)
{
- path->path_data = g_slice_new0 (GooCanvasPathData);
+
}
@@ -171,7 +118,7 @@ goo_canvas_path_new (GooCanvasItem *parent,
item = g_object_new (GOO_TYPE_CANVAS_PATH, NULL);
path = (GooCanvasPath*) item;
- path->path_data->path_commands = goo_canvas_parse_path_data (path_data);
+ path->path_commands = goo_canvas_parse_path_data (path_data);
va_start (var_args, path_data);
first_property = va_arg (var_args, char*);
@@ -192,31 +139,27 @@ goo_canvas_path_new (GooCanvasItem *parent,
static void
goo_canvas_path_finalize (GObject *object)
{
- GooCanvasItemSimple *simple = (GooCanvasItemSimple*) object;
GooCanvasPath *path = (GooCanvasPath*) object;
- /* Free our data if we didn't have a model. (If we had a model it would
- have been reset in dispose() and simple_data will be NULL.) */
- if (simple->simple_data)
+ if (path->path_commands)
{
- if (path->path_data->path_commands)
- g_array_free (path->path_data->path_commands, TRUE);
- g_slice_free (GooCanvasPathData, path->path_data);
+ g_array_free (path->path_commands, TRUE);
+ path->path_commands = NULL;
}
- path->path_data = NULL;
G_OBJECT_CLASS (goo_canvas_path_parent_class)->finalize (object);
}
+
static void
goo_canvas_path_common_get_extent (GooCanvas *canvas,
- GooCanvasPathData *path_data,
+ GooCanvasPath *path,
GooCanvasBounds *bounds)
{
cairo_t *cr;
cr = goo_canvas_create_cairo_context (canvas);
- goo_canvas_create_path (path_data->path_commands, cr);
+ goo_canvas_create_path (path->path_commands, cr);
cairo_fill_extents (cr, &bounds->x1, &bounds->y1, &bounds->x2, &bounds->y2);
cairo_destroy (cr);
}
@@ -338,32 +281,33 @@ goo_canvas_path_scale_command (GooCanvasPathCommand *cmd,
}
}
+
static void
-goo_canvas_path_get_common_property (GObject *object,
- GooCanvas *canvas,
- GooCanvasPathData *path_data,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
+goo_canvas_path_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
{
+ GooCanvasItemSimple *simple = (GooCanvasItemSimple*) object;
+ GooCanvasPath *path = (GooCanvasPath*) object;
GooCanvasBounds extent;
switch (prop_id)
{
case PROP_X:
- goo_canvas_path_common_get_extent (canvas, path_data, &extent);
+ goo_canvas_path_common_get_extent (simple->canvas, path, &extent);
g_value_set_double (value, extent.x1);
break;
case PROP_Y:
- goo_canvas_path_common_get_extent (canvas, path_data, &extent);
+ goo_canvas_path_common_get_extent (simple->canvas, path, &extent);
g_value_set_double (value, extent.y1);
break;
case PROP_WIDTH:
- goo_canvas_path_common_get_extent (canvas, path_data, &extent);
+ goo_canvas_path_common_get_extent (simple->canvas, path, &extent);
g_value_set_double (value, extent.x2 - extent.x1);
break;
case PROP_HEIGHT:
- goo_canvas_path_common_get_extent (canvas, path_data, &extent);
+ goo_canvas_path_common_get_extent (simple->canvas, path, &extent);
g_value_set_double (value, extent.y2 - extent.y1);
break;
default:
@@ -374,27 +318,13 @@ goo_canvas_path_get_common_property (GObject *object,
static void
-goo_canvas_path_get_property (GObject *object,
+goo_canvas_path_set_property (GObject *object,
guint prop_id,
- GValue *value,
+ const GValue *value,
GParamSpec *pspec)
{
GooCanvasItemSimple *simple = (GooCanvasItemSimple*) object;
GooCanvasPath *path = (GooCanvasPath*) object;
-
- goo_canvas_path_get_common_property (object, simple->canvas,
- path->path_data, prop_id, value, pspec);
-}
-
-
-static void
-goo_canvas_path_set_common_property (GObject *object,
- GooCanvas *canvas,
- GooCanvasPathData *path_data,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
GooCanvasBounds extent;
GooCanvasPathCommand *cmd;
gdouble x_offset, y_offset, x_scale, y_scale;
@@ -403,25 +333,25 @@ goo_canvas_path_set_common_property (GObject *object,
switch (prop_id)
{
case PROP_DATA:
- if (path_data->path_commands)
- g_array_free (path_data->path_commands, TRUE);
- path_data->path_commands = goo_canvas_parse_path_data (g_value_get_string (value));
+ if (path->path_commands)
+ g_array_free (path->path_commands, TRUE);
+ path->path_commands = goo_canvas_parse_path_data (g_value_get_string (value));
g_object_notify (object, "x");
g_object_notify (object, "y");
g_object_notify (object, "width");
g_object_notify (object, "height");
break;
case PROP_X:
- if (path_data->path_commands->len > 0)
+ if (path->path_commands->len > 0)
{
/* Calculate the x offset from the current position. */
- goo_canvas_path_common_get_extent (canvas, path_data, &extent);
+ goo_canvas_path_common_get_extent (simple->canvas, path, &extent);
x_offset = g_value_get_double (value) - extent.x1;
/* Add the offset to all the absolute x coordinates. */
- for (i = 0; i < path_data->path_commands->len; i++)
+ for (i = 0; i < path->path_commands->len; i++)
{
- cmd = &g_array_index (path_data->path_commands,
+ cmd = &g_array_index (path->path_commands,
GooCanvasPathCommand, i);
goo_canvas_path_move_command (cmd, x_offset, 0.0);
}
@@ -429,16 +359,16 @@ goo_canvas_path_set_common_property (GObject *object,
}
break;
case PROP_Y:
- if (path_data->path_commands->len > 0)
+ if (path->path_commands->len > 0)
{
/* Calculate the y offset from the current position. */
- goo_canvas_path_common_get_extent (canvas, path_data, &extent);
+ goo_canvas_path_common_get_extent (simple->canvas, path, &extent);
y_offset = g_value_get_double (value) - extent.y1;
/* Add the offset to all the absolute y coordinates. */
- for (i = 0; i < path_data->path_commands->len; i++)
+ for (i = 0; i < path->path_commands->len; i++)
{
- cmd = &g_array_index (path_data->path_commands,
+ cmd = &g_array_index (path->path_commands,
GooCanvasPathCommand, i);
goo_canvas_path_move_command (cmd, 0.0, y_offset);
}
@@ -446,18 +376,18 @@ goo_canvas_path_set_common_property (GObject *object,
}
break;
case PROP_WIDTH:
- if (path_data->path_commands->len >= 2)
+ if (path->path_commands->len >= 2)
{
- goo_canvas_path_common_get_extent (canvas, path_data, &extent);
+ goo_canvas_path_common_get_extent (simple->canvas, path, &extent);
if (extent.x2 - extent.x1 != 0.0)
{
/* Calculate the amount to scale the path. */
x_scale = g_value_get_double (value) / (extent.x2 - extent.x1);
/* Scale the x coordinates, relative to the left-most point. */
- for (i = 0; i < path_data->path_commands->len; i++)
+ for (i = 0; i < path->path_commands->len; i++)
{
- cmd = &g_array_index (path_data->path_commands,
+ cmd = &g_array_index (path->path_commands,
GooCanvasPathCommand, i);
goo_canvas_path_scale_command (cmd, extent.x1, 0.0,
x_scale, 1.0);
@@ -467,18 +397,18 @@ goo_canvas_path_set_common_property (GObject *object,
}
break;
case PROP_HEIGHT:
- if (path_data->path_commands->len >= 2)
+ if (path->path_commands->len >= 2)
{
- goo_canvas_path_common_get_extent (canvas, path_data, &extent);
+ goo_canvas_path_common_get_extent (simple->canvas, path, &extent);
if (extent.y2 - extent.y1 != 0.0)
{
/* Calculate the amount to scale the polyline. */
y_scale = g_value_get_double (value) / (extent.y2 - extent.y1);
/* Scale the y coordinates, relative to the top-most point. */
- for (i = 0; i < path_data->path_commands->len; i++)
+ for (i = 0; i < path->path_commands->len; i++)
{
- cmd = &g_array_index (path_data->path_commands,
+ cmd = &g_array_index (path->path_commands,
GooCanvasPathCommand, i);
goo_canvas_path_scale_command (cmd, 0.0, extent.y1,
1.0, y_scale);
@@ -491,26 +421,7 @@ goo_canvas_path_set_common_property (GObject *object,
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
-}
-
-
-static void
-goo_canvas_path_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- GooCanvasItemSimple *simple = (GooCanvasItemSimple*) object;
- GooCanvasPath *path = (GooCanvasPath*) object;
-
- if (simple->model)
- {
- g_warning ("Can't set property of a canvas item with a model - set the model property instead");
- return;
- }
- goo_canvas_path_set_common_property (object, simple->canvas, path->path_data,
- prop_id, value, pspec);
goo_canvas_item_simple_changed (simple, TRUE);
}
@@ -521,7 +432,7 @@ goo_canvas_path_create_path (GooCanvasItemSimple *simple,
{
GooCanvasPath *path = (GooCanvasPath*) simple;
- goo_canvas_create_path (path->path_data->path_commands, cr);
+ goo_canvas_create_path (path->path_commands, cr);
}
@@ -532,18 +443,17 @@ goo_canvas_path_is_item_at (GooCanvasItemSimple *simple,
cairo_t *cr,
gboolean is_pointer_event)
{
- GooCanvasItemSimpleData *simple_data = simple->simple_data;
GooCanvasPointerEvents pointer_events = GOO_CANVAS_EVENTS_ALL;
gboolean do_fill;
/* By default only check the fill if a fill color/pattern is specified. */
- do_fill = goo_canvas_style_set_fill_options (simple_data->style, cr);
+ do_fill = goo_canvas_style_set_fill_options (simple->style, cr);
if (!do_fill)
pointer_events &= ~GOO_CANVAS_EVENTS_FILL_MASK;
/* If is_pointer_event is set use the pointer_events property instead. */
if (is_pointer_event)
- pointer_events = simple_data->pointer_events;
+ pointer_events = simple->pointer_events;
goo_canvas_path_create_path (simple, cr);
if (goo_canvas_item_simple_check_in_path (simple, x, y, cr, pointer_events))
@@ -554,37 +464,6 @@ goo_canvas_path_is_item_at (GooCanvasItemSimple *simple,
static void
-goo_canvas_path_set_model (GooCanvasItem *item,
- GooCanvasItemModel *model)
-{
- GooCanvasItemSimple *simple = (GooCanvasItemSimple*) item;
- GooCanvasPath *path = (GooCanvasPath*) item;
- GooCanvasPathModel *emodel = (GooCanvasPathModel*) model;
-
- /* If our data was allocated, free it. */
- if (!simple->model)
- {
- if (path->path_data->path_commands)
- g_array_free (path->path_data->path_commands, TRUE);
- g_slice_free (GooCanvasPathData, path->path_data);
- }
-
- /* Now use the new model's data instead. */
- path->path_data = &emodel->path_data;
-
- /* Let the parent GooCanvasItemSimple code do the rest. */
- goo_canvas_item_simple_set_model (simple, model);
-}
-
-
-static void
-canvas_item_interface_init (GooCanvasItemIface *iface)
-{
- iface->set_model = goo_canvas_path_set_model;
-}
-
-
-static void
goo_canvas_path_class_init (GooCanvasPathClass *klass)
{
GObjectClass *gobject_class = (GObjectClass*) klass;
@@ -598,209 +477,47 @@ goo_canvas_path_class_init (GooCanvasPathClass *klass)
simple_class->simple_create_path = goo_canvas_path_create_path;
simple_class->simple_is_item_at = goo_canvas_path_is_item_at;
- goo_canvas_path_install_common_properties (gobject_class);
-}
-
-
-/**
- * SECTION:goocanvaspathmodel
- * @Title: GooCanvasPathModel
- * @Short_Description: a model for path items (a series of lines and curves).
- *
- * GooCanvasPathModel represents a model for path items, which are a series of
- * one or more lines, bezier curves, or elliptical arcs.
- *
- * It is a subclass of #GooCanvasItemModelSimple and so inherits all of the
- * style properties such as "stroke-color", "fill-color" and "line-width".
- *
- * It also implements the #GooCanvasItemModel interface, so you can use the
- * #GooCanvasItemModel functions such as goo_canvas_item_model_raise() and
- * goo_canvas_item_model_rotate().
- *
- * #GooCanvasPathModel uses the same path specification strings as the Scalable
- * Vector Graphics (SVG) path element. For details see the
- * <ulink url="http://www.w3.org/Graphics/SVG/">SVG specification</ulink>.
- *
- * To create a #GooCanvasPathModel use goo_canvas_path_model_new().
- *
- * To get or set the properties of an existing #GooCanvasPathModel, use
- * g_object_get() and g_object_set().
- *
- * To respond to events such as mouse clicks on the path you must connect
- * to the signal handlers of the corresponding #GooCanvasPath objects.
- * (See goo_canvas_get_item() and #GooCanvas::item-created.)
- */
-
-static void item_model_interface_init (GooCanvasItemModelIface *iface);
-static void goo_canvas_path_model_finalize (GObject *object);
-static void goo_canvas_path_model_get_property (GObject *object,
- guint param_id,
- GValue *value,
- GParamSpec *pspec);
-static void goo_canvas_path_model_set_property (GObject *object,
- guint param_id,
- const GValue *value,
- GParamSpec *pspec);
-
-G_DEFINE_TYPE_WITH_CODE (GooCanvasPathModel, goo_canvas_path_model,
- GOO_TYPE_CANVAS_ITEM_MODEL_SIMPLE,
- G_IMPLEMENT_INTERFACE (GOO_TYPE_CANVAS_ITEM_MODEL,
- item_model_interface_init))
-
-
-static void
-goo_canvas_path_model_class_init (GooCanvasPathModelClass *klass)
-{
- GObjectClass *gobject_class = (GObjectClass*) klass;
-
- gobject_class->finalize = goo_canvas_path_model_finalize;
-
- gobject_class->get_property = goo_canvas_path_model_get_property;
- gobject_class->set_property = goo_canvas_path_model_set_property;
-
- goo_canvas_path_install_common_properties (gobject_class);
-}
-
-
-static void
-goo_canvas_path_model_init (GooCanvasPathModel *pmodel)
-{
-
-}
-
-
-/**
- * goo_canvas_path_model_new:
- * @parent: the parent model, or %NULL. If a parent is specified, it will
- * assume ownership of the item, and the item will automatically be freed when
- * it is removed from the parent. Otherwise call g_object_unref() to free it.
- * @path_data: the sequence of path commands, 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.
- * @...: optional pairs of property names and values, and a terminating %NULL.
- *
- * Creates a new path model.
- *
- * <!--PARAMETERS-->
- *
- * Here's an example showing how to create a red line from (20,20) to (40,40):
- *
- * <informalexample><programlisting>
- * GooCanvasItemModel *path = goo_canvas_path_model_new (mygroup,
- * "M 20 20 L 40 40",
- * "stroke-color", "red",
- * NULL);
- * </programlisting></informalexample>
- *
- * This example creates a cubic bezier curve from (20,100) to (100,100) with
- * the control points at (20,50) and (100,50):
- *
- * <informalexample><programlisting>
- * GooCanvasItemModel *path = goo_canvas_path_model_new (mygroup,
- * "M20,100 C20,50 100,50 100,100",
- * "stroke-color", "blue",
- * NULL);
- * </programlisting></informalexample>
- *
- * This example uses an elliptical arc to create a filled circle with one
- * quarter missing:
- *
- * <informalexample><programlisting>
- * GooCanvasItemModel *path = goo_canvas_path_model_new (mygroup,
- * "M200,500 h-150 a150,150 0 1,0 150,-150 z",
- * "fill-color", "red",
- * "stroke-color", "blue",
- * "line-width", 5.0,
- * NULL);
- * </programlisting></informalexample>
- *
- * Returns: a new path model.
- **/
-GooCanvasItemModel*
-goo_canvas_path_model_new (GooCanvasItemModel *parent,
- const gchar *path_data,
- ...)
-{
- GooCanvasItemModel *model;
- GooCanvasPathModel *pmodel;
- const char *first_property;
- va_list var_args;
-
- model = g_object_new (GOO_TYPE_CANVAS_PATH_MODEL, NULL);
- pmodel = (GooCanvasPathModel*) model;
-
- pmodel->path_data.path_commands = goo_canvas_parse_path_data (path_data);
-
- va_start (var_args, path_data);
- first_property = va_arg (var_args, char*);
- if (first_property)
- g_object_set_valist ((GObject*) model, first_property, var_args);
- va_end (var_args);
-
- if (parent)
- {
- goo_canvas_item_model_add_child (parent, model, -1);
- g_object_unref (model);
- }
-
- return model;
-}
-
-
-static void
-goo_canvas_path_model_finalize (GObject *object)
-{
- GooCanvasPathModel *pmodel = (GooCanvasPathModel*) object;
-
- if (pmodel->path_data.path_commands)
- g_array_free (pmodel->path_data.path_commands, TRUE);
-
- G_OBJECT_CLASS (goo_canvas_path_model_parent_class)->finalize (object);
-}
-
-
-static void
-goo_canvas_path_model_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- GooCanvasPathModel *pmodel = (GooCanvasPathModel*) object;
-
- goo_canvas_path_get_common_property (object, NULL, &pmodel->path_data,
- prop_id, value, pspec);
-}
-
-
-static void
-goo_canvas_path_model_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- GooCanvasPathModel *pmodel = (GooCanvasPathModel*) object;
-
- goo_canvas_path_set_common_property (object, NULL, &pmodel->path_data,
- prop_id, value, pspec);
- g_signal_emit_by_name (pmodel, "changed", TRUE);
-}
-
-
-static GooCanvasItem*
-goo_canvas_path_model_create_item (GooCanvasItemModel *model,
- GooCanvas *canvas)
-{
- GooCanvasItem *item;
+ /**
+ * GooCanvasPath:data
+ *
+ * The sequence of path commands, 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_DATA,
+ g_param_spec_string ("data",
+ _("Path Data"),
+ _("The sequence of path commands"),
+ NULL,
+ G_PARAM_WRITABLE));
- item = g_object_new (GOO_TYPE_CANVAS_PATH, NULL);
- goo_canvas_item_set_model (item, model);
+ g_object_class_install_property (gobject_class, PROP_X,
+ g_param_spec_double ("x",
+ "X",
+ _("The x coordinate of the path"),
+ -G_MAXDOUBLE,
+ G_MAXDOUBLE, 0.0,
+ G_PARAM_READWRITE));
- return item;
-}
+ g_object_class_install_property (gobject_class, PROP_Y,
+ g_param_spec_double ("y",
+ "Y",
+ _("The y coordinate of the path"),
+ -G_MAXDOUBLE,
+ G_MAXDOUBLE, 0.0,
+ G_PARAM_READWRITE));
+ g_object_class_install_property (gobject_class, PROP_WIDTH,
+ g_param_spec_double ("width",
+ _("Width"),
+ _("The width of the path"),
+ 0.0, G_MAXDOUBLE, 0.0,
+ G_PARAM_READWRITE));
-static void
-item_model_interface_init (GooCanvasItemModelIface *iface)
-{
- iface->create_item = goo_canvas_path_model_create_item;
+ g_object_class_install_property (gobject_class, PROP_HEIGHT,
+ g_param_spec_double ("height",
+ _("Height"),
+ _("The height of the path"),
+ 0.0, G_MAXDOUBLE, 0.0,
+ G_PARAM_READWRITE));
}
diff --git a/src/goocanvaspath.h b/src/goocanvaspath.h
index 5b11e61..10c4a19 100644
--- a/src/goocanvaspath.h
+++ b/src/goocanvaspath.h
@@ -13,15 +13,6 @@
G_BEGIN_DECLS
-/* This is the data used by both model and view classes. */
-typedef struct _GooCanvasPathData GooCanvasPathData;
-struct _GooCanvasPathData
-{
- /* An array of GooCanvasPathCommand. */
- GArray *path_commands;
-};
-
-
#define GOO_TYPE_CANVAS_PATH (goo_canvas_path_get_type ())
#define GOO_CANVAS_PATH(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GOO_TYPE_CANVAS_PATH, GooCanvasPath))
#define GOO_CANVAS_PATH_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GOO_TYPE_CANVAS_PATH, GooCanvasPathClass))
@@ -42,7 +33,8 @@ struct _GooCanvasPath
{
GooCanvasItemSimple parent;
- GooCanvasPathData *path_data;
+ /* An array of GooCanvasPathCommand. */
+ GArray *path_commands;
};
struct _GooCanvasPathClass
@@ -67,50 +59,6 @@ GooCanvasItem* goo_canvas_path_new (GooCanvasItem *parent,
-#define GOO_TYPE_CANVAS_PATH_MODEL (goo_canvas_path_model_get_type ())
-#define GOO_CANVAS_PATH_MODEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GOO_TYPE_CANVAS_PATH_MODEL, GooCanvasPathModel))
-#define GOO_CANVAS_PATH_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GOO_TYPE_CANVAS_PATH_MODEL, GooCanvasPathModelClass))
-#define GOO_IS_CANVAS_PATH_MODEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GOO_TYPE_CANVAS_PATH_MODEL))
-#define GOO_IS_CANVAS_PATH_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GOO_TYPE_CANVAS_PATH_MODEL))
-#define GOO_CANVAS_PATH_MODEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GOO_TYPE_CANVAS_PATH_MODEL, GooCanvasPathModelClass))
-
-
-typedef struct _GooCanvasPathModel GooCanvasPathModel;
-typedef struct _GooCanvasPathModelClass GooCanvasPathModelClass;
-
-/**
- * GooCanvasPathModel
- *
- * The #GooCanvasPathModel-struct struct contains private data only.
- */
-struct _GooCanvasPathModel
-{
- GooCanvasItemModelSimple parent_object;
-
- GooCanvasPathData path_data;
-};
-
-struct _GooCanvasPathModelClass
-{
- GooCanvasItemModelSimpleClass parent_class;
-
- /*< private >*/
-
- /* Padding for future expansion */
- void (*_goo_canvas_reserved1) (void);
- void (*_goo_canvas_reserved2) (void);
- void (*_goo_canvas_reserved3) (void);
- void (*_goo_canvas_reserved4) (void);
-};
-
-
-GType goo_canvas_path_model_get_type (void) G_GNUC_CONST;
-
-GooCanvasItemModel* goo_canvas_path_model_new (GooCanvasItemModel *parent,
- const gchar *path_data,
- ...);
-
-
G_END_DECLS
#endif /* __GOO_CANVAS_PATH_H__ */
diff --git a/src/goocanvaspolyline.c b/src/goocanvaspolyline.c
index d6c98fd..bd0dd11 100644
--- a/src/goocanvaspolyline.c
+++ b/src/goocanvaspolyline.c
@@ -126,213 +126,121 @@ enum {
};
-static void canvas_item_interface_init (GooCanvasItemIface *iface);
-
-G_DEFINE_TYPE_WITH_CODE (GooCanvasPolyline, goo_canvas_polyline,
- GOO_TYPE_CANVAS_ITEM_SIMPLE,
- G_IMPLEMENT_INTERFACE (GOO_TYPE_CANVAS_ITEM,
- canvas_item_interface_init))
-
-
-static void
-goo_canvas_polyline_install_common_properties (GObjectClass *gobject_class)
-{
- g_object_class_install_property (gobject_class, PROP_POINTS,
- g_param_spec_boxed ("points",
- _("Points"),
- _("The array of points"),
- GOO_TYPE_CANVAS_POINTS,
- G_PARAM_READWRITE));
-
- g_object_class_install_property (gobject_class, PROP_CLOSE_PATH,
- g_param_spec_boolean ("close-path",
- _("Close Path"),
- _("If the last point should be connected to the first"),
- FALSE,
- G_PARAM_READWRITE));
-
- g_object_class_install_property (gobject_class, PROP_START_ARROW,
- g_param_spec_boolean ("start-arrow",
- _("Start Arrow"),
- _("If an arrow should be displayed at the start of the polyline"),
- FALSE,
- G_PARAM_READWRITE));
-
- g_object_class_install_property (gobject_class, PROP_END_ARROW,
- g_param_spec_boolean ("end-arrow",
- _("End Arrow"),
- _("If an arrow should be displayed at the end of the polyline"),
- FALSE,
- G_PARAM_READWRITE));
-
- g_object_class_install_property (gobject_class, PROP_ARROW_LENGTH,
- g_param_spec_double ("arrow-length",
- _("Arrow Length"),
- _("The length of the arrows, as a multiple of the line width"),
- 0.0, G_MAXDOUBLE, 5.0,
- G_PARAM_READWRITE));
-
- g_object_class_install_property (gobject_class, PROP_ARROW_WIDTH,
- g_param_spec_double ("arrow-width",
- _("Arrow Width"),
- _("The width of the arrows, as a multiple of the line width"),
- 0.0, G_MAXDOUBLE, 4.0,
- G_PARAM_READWRITE));
-
- g_object_class_install_property (gobject_class, PROP_ARROW_TIP_LENGTH,
- g_param_spec_double ("arrow-tip-length",
- _("Arrow Tip Length"),
- _("The length of the arrow tip, as a multiple of the line width"),
- 0.0, G_MAXDOUBLE, 4.0,
- G_PARAM_READWRITE));
-
- g_object_class_install_property (gobject_class, PROP_X,
- g_param_spec_double ("x",
- "X",
- _("The x coordinate of the left-most point of the polyline"),
- -G_MAXDOUBLE,
- G_MAXDOUBLE, 0.0,
- G_PARAM_READWRITE));
-
- g_object_class_install_property (gobject_class, PROP_Y,
- g_param_spec_double ("y",
- "Y",
- _("The y coordinate of the top-most point of the polyline"),
- -G_MAXDOUBLE,
- G_MAXDOUBLE, 0.0,
- G_PARAM_READWRITE));
-
- g_object_class_install_property (gobject_class, PROP_WIDTH,
- g_param_spec_double ("width",
- _("Width"),
- _("The width of the polyline"),
- 0.0, G_MAXDOUBLE, 0.0,
- G_PARAM_READWRITE));
-
- g_object_class_install_property (gobject_class, PROP_HEIGHT,
- g_param_spec_double ("height",
- _("Height"),
- _("The height of the polyline"),
- 0.0, G_MAXDOUBLE, 0.0,
- G_PARAM_READWRITE));
-}
+G_DEFINE_TYPE (GooCanvasPolyline, goo_canvas_polyline,
+ GOO_TYPE_CANVAS_ITEM_SIMPLE)
static void
goo_canvas_polyline_init (GooCanvasPolyline *polyline)
{
- polyline->polyline_data = g_slice_new0 (GooCanvasPolylineData);
+
}
static void
goo_canvas_polyline_finalize (GObject *object)
{
- GooCanvasItemSimple *simple = (GooCanvasItemSimple*) object;
GooCanvasPolyline *polyline = (GooCanvasPolyline*) object;
- /* Free our data if we didn't have a model. (If we had a model it would
- have been reset in dispose() and simple_data will be NULL.) */
- if (simple->simple_data)
- {
- g_slice_free1 (polyline->polyline_data->num_points * 2 * sizeof (gdouble),
- polyline->polyline_data->coords);
- g_slice_free (GooCanvasPolylineArrowData, polyline->polyline_data->arrow_data);
- g_slice_free (GooCanvasPolylineData, polyline->polyline_data);
- }
- polyline->polyline_data = NULL;
+ g_slice_free1 (polyline->num_points * 2 * sizeof (gdouble),
+ polyline->coords);
+ polyline->coords = NULL;
+
+ g_slice_free (GooCanvasPolylineArrowData, polyline->arrow_data);
+ polyline->arrow_data = NULL;
G_OBJECT_CLASS (goo_canvas_polyline_parent_class)->finalize (object);
}
static void
-goo_canvas_polyline_get_extent (GooCanvasPolylineData *polyline_data,
+goo_canvas_polyline_get_extent (GooCanvasPolyline *polyline,
GooCanvasBounds *bounds)
{
guint i;
- if (polyline_data->num_points == 0)
+ if (polyline->num_points == 0)
{
bounds->x1 = bounds->y1 = bounds->x2 = bounds->y2 = 0.0;
}
else
{
- bounds->x1 = bounds->x2 = polyline_data->coords[0];
- bounds->y1 = bounds->y2 = polyline_data->coords[1];
+ bounds->x1 = bounds->x2 = polyline->coords[0];
+ bounds->y1 = bounds->y2 = polyline->coords[1];
- for (i = 1; i < polyline_data->num_points; i++)
+ for (i = 1; i < polyline->num_points; i++)
{
- bounds->x1 = MIN (bounds->x1, polyline_data->coords[2 * i]);
- bounds->y1 = MIN (bounds->y1, polyline_data->coords[2 * i + 1]);
- bounds->x2 = MAX (bounds->x2, polyline_data->coords[2 * i]);
- bounds->y2 = MAX (bounds->y2, polyline_data->coords[2 * i + 1]);
+ bounds->x1 = MIN (bounds->x1, polyline->coords[2 * i]);
+ bounds->y1 = MIN (bounds->y1, polyline->coords[2 * i + 1]);
+ bounds->x2 = MAX (bounds->x2, polyline->coords[2 * i]);
+ bounds->y2 = MAX (bounds->y2, polyline->coords[2 * i + 1]);
}
}
}
static void
-goo_canvas_polyline_get_common_property (GObject *object,
- GooCanvasPolylineData *polyline_data,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
+goo_canvas_polyline_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
{
+ GooCanvasPolyline *polyline = (GooCanvasPolyline*) object;
+
GooCanvasPoints *points;
GooCanvasBounds extent;
switch (prop_id)
{
case PROP_POINTS:
- if (polyline_data->num_points == 0)
+ if (polyline->num_points == 0)
{
g_value_set_boxed (value, NULL);
}
else
{
- points = goo_canvas_points_new (polyline_data->num_points);
- memcpy (points->coords, polyline_data->coords,
- polyline_data->num_points * 2 * sizeof (double));
+ points = goo_canvas_points_new (polyline->num_points);
+ memcpy (points->coords, polyline->coords,
+ polyline->num_points * 2 * sizeof (double));
g_value_set_boxed (value, points);
goo_canvas_points_unref (points);
}
break;
case PROP_CLOSE_PATH:
- g_value_set_boolean (value, polyline_data->close_path);
+ g_value_set_boolean (value, polyline->close_path);
break;
case PROP_START_ARROW:
- g_value_set_boolean (value, polyline_data->start_arrow);
+ g_value_set_boolean (value, polyline->start_arrow);
break;
case PROP_END_ARROW:
- g_value_set_boolean (value, polyline_data->end_arrow);
+ g_value_set_boolean (value, polyline->end_arrow);
break;
case PROP_ARROW_LENGTH:
- g_value_set_double (value, polyline_data->arrow_data
- ? polyline_data->arrow_data->arrow_length : 5.0);
+ g_value_set_double (value, polyline->arrow_data
+ ? polyline->arrow_data->arrow_length : 5.0);
break;
case PROP_ARROW_WIDTH:
- g_value_set_double (value, polyline_data->arrow_data
- ? polyline_data->arrow_data->arrow_width : 4.0);
+ g_value_set_double (value, polyline->arrow_data
+ ? polyline->arrow_data->arrow_width : 4.0);
break;
case PROP_ARROW_TIP_LENGTH:
- g_value_set_double (value, polyline_data->arrow_data
- ? polyline_data->arrow_data->arrow_tip_length : 4.0);
+ g_value_set_double (value, polyline->arrow_data
+ ? polyline->arrow_data->arrow_tip_length : 4.0);
break;
case PROP_X:
- goo_canvas_polyline_get_extent (polyline_data, &extent);
+ goo_canvas_polyline_get_extent (polyline, &extent);
g_value_set_double (value, extent.x1);
break;
case PROP_Y:
- goo_canvas_polyline_get_extent (polyline_data, &extent);
+ goo_canvas_polyline_get_extent (polyline, &extent);
g_value_set_double (value, extent.y1);
break;
case PROP_WIDTH:
- goo_canvas_polyline_get_extent (polyline_data, &extent);
+ goo_canvas_polyline_get_extent (polyline, &extent);
g_value_set_double (value, extent.x2 - extent.x1);
break;
case PROP_HEIGHT:
- goo_canvas_polyline_get_extent (polyline_data, &extent);
+ goo_canvas_polyline_get_extent (polyline, &extent);
g_value_set_double (value, extent.y2 - extent.y1);
break;
default:
@@ -343,52 +251,39 @@ goo_canvas_polyline_get_common_property (GObject *object,
static void
-goo_canvas_polyline_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- GooCanvasPolyline *polyline = (GooCanvasPolyline*) object;
-
- goo_canvas_polyline_get_common_property (object, polyline->polyline_data,
- prop_id, value, pspec);
-}
-
-
-static void
-ensure_arrow_data (GooCanvasPolylineData *polyline_data)
+ensure_arrow_data (GooCanvasPolyline *polyline)
{
- if (!polyline_data->arrow_data)
+ if (!polyline->arrow_data)
{
- polyline_data->arrow_data = g_slice_new (GooCanvasPolylineArrowData);
+ polyline->arrow_data = g_slice_new (GooCanvasPolylineArrowData);
/* These seem like reasonable defaults for the arrow dimensions.
They are specified in multiples of the line width so they scale OK. */
- polyline_data->arrow_data->arrow_width = 4.0;
- polyline_data->arrow_data->arrow_length = 5.0;
- polyline_data->arrow_data->arrow_tip_length = 4.0;
+ polyline->arrow_data->arrow_width = 4.0;
+ polyline->arrow_data->arrow_length = 5.0;
+ polyline->arrow_data->arrow_tip_length = 4.0;
}
}
#define GOO_CANVAS_EPSILON 1e-10
static void
-reconfigure_arrow (GooCanvasPolylineData *polyline_data,
+reconfigure_arrow (GooCanvasPolyline *polyline,
gint end_point,
gint prev_point,
gdouble line_width,
gdouble *line_coords,
gdouble *arrow_coords)
{
- GooCanvasPolylineArrowData *arrow = polyline_data->arrow_data;
+ GooCanvasPolylineArrowData *arrow = polyline->arrow_data;
double dx, dy, length, sin_theta, cos_theta;
double half_arrow_width, arrow_length, arrow_tip_length;
double arrow_end_center_x, arrow_end_center_y;
double arrow_tip_center_x, arrow_tip_center_y;
double x_offset, y_offset, half_line_width, line_trim;
- dx = polyline_data->coords[prev_point] - polyline_data->coords[end_point];
- dy = polyline_data->coords[prev_point + 1] - polyline_data->coords[end_point + 1];
+ dx = polyline->coords[prev_point] - polyline->coords[end_point];
+ dy = polyline->coords[prev_point + 1] - polyline->coords[end_point + 1];
length = sqrt (dx * dx + dy * dy);
if (length < GOO_CANVAS_EPSILON)
@@ -410,8 +305,8 @@ reconfigure_arrow (GooCanvasPolylineData *polyline_data,
arrow_tip_length = arrow->arrow_tip_length * line_width;
/* The arrow tip is at the end point of the line. */
- arrow_coords[0] = polyline_data->coords[end_point];
- arrow_coords[1] = polyline_data->coords[end_point + 1];
+ arrow_coords[0] = polyline->coords[end_point];
+ arrow_coords[1] = polyline->coords[end_point + 1];
/* Calculate the end of the arrow, along the center line. */
arrow_end_center_x = arrow_coords[0] + (arrow_length * cos_theta);
@@ -456,50 +351,51 @@ static void
goo_canvas_polyline_reconfigure_arrows (GooCanvasPolyline *polyline)
{
GooCanvasItemSimple *simple = (GooCanvasItemSimple*) polyline;
- GooCanvasPolylineData *polyline_data = polyline->polyline_data;
double line_width;
- if (polyline_data->num_points < 2
- || (!polyline_data->start_arrow && !polyline_data->end_arrow))
+ if (polyline->num_points < 2
+ || (!polyline->start_arrow && !polyline->end_arrow))
return;
line_width = goo_canvas_item_simple_get_line_width (simple);
- ensure_arrow_data (polyline_data);
+ ensure_arrow_data (polyline);
- if (polyline_data->start_arrow)
- reconfigure_arrow (polyline_data, 0, 2, line_width,
- polyline_data->arrow_data->line_start,
- polyline_data->arrow_data->start_arrow_coords);
+ if (polyline->start_arrow)
+ reconfigure_arrow (polyline, 0, 2, line_width,
+ polyline->arrow_data->line_start,
+ polyline->arrow_data->start_arrow_coords);
- if (polyline_data->end_arrow)
+ if (polyline->end_arrow)
{
int end_point, prev_point;
- if (polyline_data->close_path)
+ if (polyline->close_path)
{
end_point = 0;
- prev_point = polyline_data->num_points - 1;
+ prev_point = polyline->num_points - 1;
}
else
{
- end_point = polyline_data->num_points - 1;
- prev_point = polyline_data->num_points - 2;
+ end_point = polyline->num_points - 1;
+ prev_point = polyline->num_points - 2;
}
- reconfigure_arrow (polyline_data, end_point * 2, prev_point * 2,
- line_width, polyline_data->arrow_data->line_end,
- polyline_data->arrow_data->end_arrow_coords);
+ reconfigure_arrow (polyline, end_point * 2, prev_point * 2,
+ line_width, polyline->arrow_data->line_end,
+ polyline->arrow_data->end_arrow_coords);
}
}
static void
-goo_canvas_polyline_set_common_property (GObject *object,
- GooCanvasPolylineData *polyline_data,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
+goo_canvas_polyline_set_property (GObject *object,
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
+ GooCanvasItemSimple *simple = (GooCanvasItemSimple*) object;
+ GooCanvasPolyline *polyline = (GooCanvasPolyline*) object;
+
GooCanvasPoints *points;
GooCanvasBounds extent;
gdouble x_offset, y_offset, x_scale, y_scale;
@@ -510,22 +406,22 @@ goo_canvas_polyline_set_common_property (GObject *object,
case PROP_POINTS:
points = g_value_get_boxed (value);
- if (polyline_data->coords)
+ if (polyline->coords)
{
- g_slice_free1 (polyline_data->num_points * 2 * sizeof (double), polyline_data->coords);
- polyline_data->coords = NULL;
+ g_slice_free1 (polyline->num_points * 2 * sizeof (double), polyline->coords);
+ polyline->coords = NULL;
}
if (!points)
{
- polyline_data->num_points = 0;
+ polyline->num_points = 0;
}
else
{
- polyline_data->num_points = points->num_points;
- polyline_data->coords = g_slice_alloc (polyline_data->num_points * 2 * sizeof (double));
- memcpy (polyline_data->coords, points->coords,
- polyline_data->num_points * 2 * sizeof (double));
+ polyline->num_points = points->num_points;
+ polyline->coords = g_slice_alloc (polyline->num_points * 2 * sizeof (double));
+ memcpy (polyline->coords, points->coords,
+ polyline->num_points * 2 * sizeof (double));
}
g_object_notify (object, "x");
g_object_notify (object, "y");
@@ -533,83 +429,83 @@ goo_canvas_polyline_set_common_property (GObject *object,
g_object_notify (object, "height");
break;
case PROP_CLOSE_PATH:
- polyline_data->close_path = g_value_get_boolean (value);
+ polyline->close_path = g_value_get_boolean (value);
break;
case PROP_START_ARROW:
- polyline_data->start_arrow = g_value_get_boolean (value);
+ polyline->start_arrow = g_value_get_boolean (value);
break;
case PROP_END_ARROW:
- polyline_data->end_arrow = g_value_get_boolean (value);
+ polyline->end_arrow = g_value_get_boolean (value);
break;
case PROP_ARROW_LENGTH:
- ensure_arrow_data (polyline_data);
- polyline_data->arrow_data->arrow_length = g_value_get_double (value);
+ ensure_arrow_data (polyline);
+ polyline->arrow_data->arrow_length = g_value_get_double (value);
break;
case PROP_ARROW_WIDTH:
- ensure_arrow_data (polyline_data);
- polyline_data->arrow_data->arrow_width = g_value_get_double (value);
+ ensure_arrow_data (polyline);
+ polyline->arrow_data->arrow_width = g_value_get_double (value);
break;
case PROP_ARROW_TIP_LENGTH:
- ensure_arrow_data (polyline_data);
- polyline_data->arrow_data->arrow_tip_length = g_value_get_double (value);
+ ensure_arrow_data (polyline);
+ polyline->arrow_data->arrow_tip_length = g_value_get_double (value);
break;
case PROP_X:
- if (polyline_data->num_points > 0)
+ if (polyline->num_points > 0)
{
/* Calculate the x offset from the current position. */
- goo_canvas_polyline_get_extent (polyline_data, &extent);
+ goo_canvas_polyline_get_extent (polyline, &extent);
x_offset = g_value_get_double (value) - extent.x1;
/* Add the offset to all the x coordinates. */
- for (i = 0; i < polyline_data->num_points; i++)
- polyline_data->coords[2 * i] += x_offset;
+ for (i = 0; i < polyline->num_points; i++)
+ polyline->coords[2 * i] += x_offset;
g_object_notify (object, "points");
}
break;
case PROP_Y:
- if (polyline_data->num_points > 0)
+ if (polyline->num_points > 0)
{
/* Calculate the y offset from the current position. */
- goo_canvas_polyline_get_extent (polyline_data, &extent);
+ goo_canvas_polyline_get_extent (polyline, &extent);
y_offset = g_value_get_double (value) - extent.y1;
/* Add the offset to all the y coordinates. */
- for (i = 0; i < polyline_data->num_points; i++)
- polyline_data->coords[2 * i + 1] += y_offset;
+ for (i = 0; i < polyline->num_points; i++)
+ polyline->coords[2 * i + 1] += y_offset;
g_object_notify (object, "points");
}
break;
case PROP_WIDTH:
- if (polyline_data->num_points >= 2)
+ if (polyline->num_points >= 2)
{
- goo_canvas_polyline_get_extent (polyline_data, &extent);
+ goo_canvas_polyline_get_extent (polyline, &extent);
if (extent.x2 - extent.x1 != 0.0)
{
/* Calculate the amount to scale the polyline. */
x_scale = g_value_get_double (value) / (extent.x2 - extent.x1);
/* Scale the x coordinates, relative to the left-most point. */
- for (i = 0; i < polyline_data->num_points; i++)
- polyline_data->coords[2 * i] = extent.x1 + (polyline_data->coords[2 * i] - extent.x1) * x_scale;
+ for (i = 0; i < polyline->num_points; i++)
+ polyline->coords[2 * i] = extent.x1 + (polyline->coords[2 * i] - extent.x1) * x_scale;
g_object_notify (object, "points");
}
}
break;
case PROP_HEIGHT:
- if (polyline_data->num_points >= 2)
+ if (polyline->num_points >= 2)
{
- goo_canvas_polyline_get_extent (polyline_data, &extent);
+ goo_canvas_polyline_get_extent (polyline, &extent);
if (extent.y2 - extent.y1 != 0.0)
{
/* Calculate the amount to scale the polyline. */
y_scale = g_value_get_double (value) / (extent.y2 - extent.y1);
/* Scale the y coordinates, relative to the top-most point. */
- for (i = 0; i < polyline_data->num_points; i++)
- polyline_data->coords[2 * i + 1] = extent.y1 + (polyline_data->coords[2 * i + 1] - extent.y1) * y_scale;
+ for (i = 0; i < polyline->num_points; i++)
+ polyline->coords[2 * i + 1] = extent.y1 + (polyline->coords[2 * i + 1] - extent.y1) * y_scale;
g_object_notify (object, "points");
}
@@ -619,26 +515,7 @@ goo_canvas_polyline_set_common_property (GObject *object,
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
-}
-
-static void
-goo_canvas_polyline_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- GooCanvasItemSimple *simple = (GooCanvasItemSimple*) object;
- GooCanvasPolyline *polyline = (GooCanvasPolyline*) object;
-
- if (simple->model)
- {
- g_warning ("Can't set property of a canvas item with a model - set the model property instead");
- return;
- }
-
- goo_canvas_polyline_set_common_property (object, polyline->polyline_data,
- prop_id, value, pspec);
goo_canvas_item_simple_changed (simple, TRUE);
}
@@ -681,7 +558,6 @@ goo_canvas_polyline_new (GooCanvasItem *parent,
{
GooCanvasItem *item;
GooCanvasPolyline *polyline;
- GooCanvasPolylineData *polyline_data;
const char *first_property;
va_list var_args;
gint i;
@@ -689,15 +565,14 @@ goo_canvas_polyline_new (GooCanvasItem *parent,
item = g_object_new (GOO_TYPE_CANVAS_POLYLINE, NULL);
polyline = (GooCanvasPolyline*) item;
- polyline_data = polyline->polyline_data;
- polyline_data->close_path = close_path;
- polyline_data->num_points = num_points;
+ polyline->close_path = close_path;
+ polyline->num_points = num_points;
if (num_points)
- polyline_data->coords = g_slice_alloc (num_points * 2 * sizeof (gdouble));
+ polyline->coords = g_slice_alloc (num_points * 2 * sizeof (gdouble));
va_start (var_args, num_points);
for (i = 0; i < num_points * 2; i++)
- polyline_data->coords[i] = va_arg (var_args, gdouble);
+ polyline->coords[i] = va_arg (var_args, gdouble);
first_property = va_arg (var_args, char*);
if (first_property)
@@ -750,21 +625,19 @@ goo_canvas_polyline_new_line (GooCanvasItem *parent,
{
GooCanvasItem *item;
GooCanvasPolyline *polyline;
- GooCanvasPolylineData *polyline_data;
const char *first_property;
va_list var_args;
item = g_object_new (GOO_TYPE_CANVAS_POLYLINE, NULL);
polyline = (GooCanvasPolyline*) item;
- polyline_data = polyline->polyline_data;
- polyline_data->close_path = FALSE;
- polyline_data->num_points = 2;
- polyline_data->coords = g_slice_alloc (4 * sizeof (gdouble));
- polyline_data->coords[0] = x1;
- polyline_data->coords[1] = y1;
- polyline_data->coords[2] = x2;
- polyline_data->coords[3] = y2;
+ polyline->close_path = FALSE;
+ polyline->num_points = 2;
+ polyline->coords = g_slice_alloc (4 * sizeof (gdouble));
+ polyline->coords[0] = x1;
+ polyline->coords[1] = y1;
+ polyline->coords[2] = x2;
+ polyline->coords[3] = y2;
va_start (var_args, y2);
first_property = va_arg (var_args, char*);
@@ -786,42 +659,41 @@ static void
goo_canvas_polyline_create_path (GooCanvasPolyline *polyline,
cairo_t *cr)
{
- GooCanvasPolylineData *polyline_data = polyline->polyline_data;
- GooCanvasPolylineArrowData *arrow = polyline_data->arrow_data;
+ GooCanvasPolylineArrowData *arrow = polyline->arrow_data;
gint i;
cairo_new_path (cr);
- if (polyline_data->num_points == 0)
+ if (polyline->num_points == 0)
return;
/* If there is an arrow at the start of the polyline, we need to move the
start of the line slightly to avoid drawing over the arrow tip. */
- if (polyline_data->start_arrow && polyline_data->num_points >= 2)
+ if (polyline->start_arrow && polyline->num_points >= 2)
cairo_move_to (cr, arrow->line_start[0], arrow->line_start[1]);
else
- cairo_move_to (cr, polyline_data->coords[0], polyline_data->coords[1]);
+ cairo_move_to (cr, polyline->coords[0], polyline->coords[1]);
- if (polyline_data->end_arrow && polyline_data->num_points >= 2)
+ if (polyline->end_arrow && polyline->num_points >= 2)
{
- gint last_point = polyline_data->num_points - 1;
+ gint last_point = polyline->num_points - 1;
- if (!polyline_data->close_path)
+ if (!polyline->close_path)
last_point--;
for (i = 1; i <= last_point; i++)
- cairo_line_to (cr, polyline_data->coords[i * 2],
- polyline_data->coords[i * 2 + 1]);
+ cairo_line_to (cr, polyline->coords[i * 2],
+ polyline->coords[i * 2 + 1]);
cairo_line_to (cr, arrow->line_end[0], arrow->line_end[1]);
}
else
{
- for (i = 1; i < polyline_data->num_points; i++)
- cairo_line_to (cr, polyline_data->coords[i * 2],
- polyline_data->coords[i * 2 + 1]);
+ for (i = 1; i < polyline->num_points; i++)
+ cairo_line_to (cr, polyline->coords[i * 2],
+ polyline->coords[i * 2 + 1]);
- if (polyline_data->close_path)
+ if (polyline->close_path)
cairo_close_path (cr);
}
}
@@ -831,13 +703,12 @@ static void
goo_canvas_polyline_create_start_arrow_path (GooCanvasPolyline *polyline,
cairo_t *cr)
{
- GooCanvasPolylineData *polyline_data = polyline->polyline_data;
- GooCanvasPolylineArrowData *arrow = polyline_data->arrow_data;
+ GooCanvasPolylineArrowData *arrow = polyline->arrow_data;
gint i;
cairo_new_path (cr);
- if (polyline_data->num_points < 2)
+ if (polyline->num_points < 2)
return;
cairo_move_to (cr, arrow->start_arrow_coords[0],
@@ -855,13 +726,12 @@ static void
goo_canvas_polyline_create_end_arrow_path (GooCanvasPolyline *polyline,
cairo_t *cr)
{
- GooCanvasPolylineData *polyline_data = polyline->polyline_data;
- GooCanvasPolylineArrowData *arrow = polyline_data->arrow_data;
+ GooCanvasPolylineArrowData *arrow = polyline->arrow_data;
gint i;
cairo_new_path (cr);
- if (polyline_data->num_points < 2)
+ if (polyline->num_points < 2)
return;
cairo_move_to (cr, arrow->end_arrow_coords[0],
@@ -882,21 +752,19 @@ goo_canvas_polyline_is_item_at (GooCanvasItemSimple *simple,
cairo_t *cr,
gboolean is_pointer_event)
{
- GooCanvasItemSimpleData *simple_data = simple->simple_data;
GooCanvasPolyline *polyline = (GooCanvasPolyline*) simple;
- GooCanvasPolylineData *polyline_data = polyline->polyline_data;
GooCanvasPointerEvents pointer_events = GOO_CANVAS_EVENTS_ALL;
gboolean do_stroke;
- if (polyline_data->num_points == 0)
+ if (polyline->num_points == 0)
return FALSE;
/* Check if the item should receive events. */
if (is_pointer_event)
- pointer_events = simple_data->pointer_events;
+ pointer_events = simple->pointer_events;
/* If the path isn't closed, we never check the fill. */
- if (!(polyline_data->close_path && polyline_data->num_points > 2))
+ if (!(polyline->close_path && polyline->num_points > 2))
pointer_events &= ~GOO_CANVAS_EVENTS_FILL_MASK;
goo_canvas_polyline_create_path (polyline, cr);
@@ -904,22 +772,22 @@ goo_canvas_polyline_is_item_at (GooCanvasItemSimple *simple,
return TRUE;
/* Check the arrows, if the polyline has them. */
- if ((polyline_data->start_arrow || polyline_data->end_arrow)
- && polyline_data->num_points >= 2
+ if ((polyline->start_arrow || polyline->end_arrow)
+ && polyline->num_points >= 2
&& (pointer_events & GOO_CANVAS_EVENTS_STROKE_MASK))
{
/* We use the stroke pattern to match the style of the line. */
- do_stroke = goo_canvas_style_set_stroke_options (simple_data->style, cr);
+ do_stroke = goo_canvas_style_set_stroke_options (simple->style, cr);
if (!(pointer_events & GOO_CANVAS_EVENTS_PAINTED_MASK) || do_stroke)
{
- if (polyline_data->start_arrow)
+ if (polyline->start_arrow)
{
goo_canvas_polyline_create_start_arrow_path (polyline, cr);
if (cairo_in_fill (cr, x, y))
return TRUE;
}
- if (polyline_data->end_arrow)
+ if (polyline->end_arrow)
{
goo_canvas_polyline_create_end_arrow_path (polyline, cr);
if (cairo_in_fill (cr, x, y))
@@ -938,12 +806,10 @@ goo_canvas_polyline_compute_bounds (GooCanvasPolyline *polyline,
GooCanvasBounds *bounds)
{
GooCanvasItemSimple *simple = (GooCanvasItemSimple*) polyline;
- GooCanvasItemSimpleData *simple_data = simple->simple_data;
- GooCanvasPolylineData *polyline_data = polyline->polyline_data;
GooCanvasBounds tmp_bounds;
cairo_matrix_t transform;
- if (polyline_data->num_points == 0)
+ if (polyline->num_points == 0)
{
bounds->x1 = bounds->x2 = bounds->y1 = bounds->y2 = 0.0;
return;
@@ -957,13 +823,13 @@ goo_canvas_polyline_compute_bounds (GooCanvasPolyline *polyline,
goo_canvas_item_simple_get_path_bounds (simple, cr, bounds);
/* Add on the arrows, if required. */
- if ((polyline_data->start_arrow || polyline_data->end_arrow)
- && polyline_data->num_points >= 2)
+ if ((polyline->start_arrow || polyline->end_arrow)
+ && polyline->num_points >= 2)
{
/* We use the stroke pattern to match the style of the line. */
- goo_canvas_style_set_stroke_options (simple_data->style, cr);
+ goo_canvas_style_set_stroke_options (simple->style, cr);
- if (polyline_data->start_arrow)
+ if (polyline->start_arrow)
{
goo_canvas_polyline_create_start_arrow_path (polyline, cr);
cairo_fill_extents (cr, &tmp_bounds.x1, &tmp_bounds.y1,
@@ -974,7 +840,7 @@ goo_canvas_polyline_compute_bounds (GooCanvasPolyline *polyline,
bounds->y2 = MAX (bounds->y2, tmp_bounds.y2);
}
- if (polyline_data->end_arrow)
+ if (polyline->end_arrow)
{
goo_canvas_polyline_create_end_arrow_path (polyline, cr);
cairo_fill_extents (cr, &tmp_bounds.x1, &tmp_bounds.y1,
@@ -995,7 +861,6 @@ goo_canvas_polyline_update (GooCanvasItemSimple *simple,
cairo_t *cr)
{
GooCanvasPolyline *polyline = (GooCanvasPolyline*) simple;
- GooCanvasPolylineData *polyline_data = polyline->polyline_data;
goo_canvas_polyline_reconfigure_arrows (polyline);
@@ -1009,30 +874,28 @@ goo_canvas_polyline_paint (GooCanvasItemSimple *simple,
cairo_t *cr,
const GooCanvasBounds *bounds)
{
- GooCanvasItemSimpleData *simple_data = simple->simple_data;
GooCanvasPolyline *polyline = (GooCanvasPolyline*) simple;
- GooCanvasPolylineData *polyline_data = polyline->polyline_data;
- if (polyline_data->num_points == 0)
+ if (polyline->num_points == 0)
return;
goo_canvas_polyline_create_path (polyline, cr);
goo_canvas_item_simple_paint_path (simple, cr);
/* Paint the arrows, if required. */
- if ((polyline_data->start_arrow || polyline_data->end_arrow)
- && polyline_data->num_points >= 2)
+ if ((polyline->start_arrow || polyline->end_arrow)
+ && polyline->num_points >= 2)
{
/* We use the stroke pattern to match the style of the line. */
- goo_canvas_style_set_stroke_options (simple_data->style, cr);
+ goo_canvas_style_set_stroke_options (simple->style, cr);
- if (polyline_data->start_arrow)
+ if (polyline->start_arrow)
{
goo_canvas_polyline_create_start_arrow_path (polyline, cr);
cairo_fill (cr);
}
- if (polyline_data->end_arrow)
+ if (polyline->end_arrow)
{
goo_canvas_polyline_create_end_arrow_path (polyline, cr);
cairo_fill (cr);
@@ -1042,33 +905,6 @@ goo_canvas_polyline_paint (GooCanvasItemSimple *simple,
static void
-goo_canvas_polyline_set_model (GooCanvasItem *item,
- GooCanvasItemModel *model)
-{
- GooCanvasItemSimple *simple = (GooCanvasItemSimple*) item;
- GooCanvasPolyline *polyline = (GooCanvasPolyline*) item;
- GooCanvasPolylineModel *pmodel = (GooCanvasPolylineModel*) model;
-
- /* If our polyline_data was allocated, free it. */
- if (!simple->model)
- g_slice_free (GooCanvasPolylineData, polyline->polyline_data);
-
- /* Now use the new model's polyline_data instead. */
- polyline->polyline_data = &pmodel->polyline_data;
-
- /* Let the parent GooCanvasItemSimple code do the rest. */
- goo_canvas_item_simple_set_model (simple, model);
-}
-
-
-static void
-canvas_item_interface_init (GooCanvasItemIface *iface)
-{
- iface->set_model = goo_canvas_polyline_set_model;
-}
-
-
-static void
goo_canvas_polyline_class_init (GooCanvasPolylineClass *klass)
{
GObjectClass *gobject_class = (GObjectClass*) klass;
@@ -1083,269 +919,82 @@ goo_canvas_polyline_class_init (GooCanvasPolylineClass *klass)
simple_class->simple_paint = goo_canvas_polyline_paint;
simple_class->simple_is_item_at = goo_canvas_polyline_is_item_at;
- goo_canvas_polyline_install_common_properties (gobject_class);
-}
-
-
-/**
- * SECTION:goocanvaspolylinemodel
- * @Title: GooCanvasPolylineModel
- * @Short_Description: a model for polyline items (a series of lines with
- * optional arrows).
- *
- * GooCanvasPolylineModel represents a model for polyline items, which are a
- * series of one or more lines, with optional arrows at either end.
- *
- * It is a subclass of #GooCanvasItemModelSimple and so inherits all of the
- * style properties such as "stroke-color", "fill-color" and "line-width".
- *
- * It also implements the #GooCanvasItemModel interface, so you can use the
- * #GooCanvasItemModel functions such as goo_canvas_item_model_raise() and
- * goo_canvas_item_model_rotate().
- *
- * To create a #GooCanvasPolylineModel use goo_canvas_polyline_model_new(), or
- * goo_canvas_polyline_model_new_line() for a simple line between two points.
- *
- * To get or set the properties of an existing #GooCanvasPolylineModel, use
- * g_object_get() and g_object_set().
- *
- * To respond to events such as mouse clicks on the polyline you must connect
- * to the signal handlers of the corresponding #GooCanvasPolyline objects.
- * (See goo_canvas_get_item() and #GooCanvas::item-created.)
- */
-
-static void item_model_interface_init (GooCanvasItemModelIface *iface);
-static void goo_canvas_polyline_model_finalize (GObject *object);
-static void goo_canvas_polyline_model_get_property (GObject *object,
- guint param_id,
- GValue *value,
- GParamSpec *pspec);
-static void goo_canvas_polyline_model_set_property (GObject *object,
- guint param_id,
- const GValue *value,
- GParamSpec *pspec);
-
-G_DEFINE_TYPE_WITH_CODE (GooCanvasPolylineModel, goo_canvas_polyline_model,
- GOO_TYPE_CANVAS_ITEM_MODEL_SIMPLE,
- G_IMPLEMENT_INTERFACE (GOO_TYPE_CANVAS_ITEM_MODEL,
- item_model_interface_init))
-
-
-static void
-goo_canvas_polyline_model_class_init (GooCanvasPolylineModelClass *klass)
-{
- GObjectClass *gobject_class = (GObjectClass*) klass;
-
- gobject_class->finalize = goo_canvas_polyline_model_finalize;
-
- gobject_class->get_property = goo_canvas_polyline_model_get_property;
- gobject_class->set_property = goo_canvas_polyline_model_set_property;
-
- goo_canvas_polyline_install_common_properties (gobject_class);
-}
-
-
-static void
-goo_canvas_polyline_model_init (GooCanvasPolylineModel *pmodel)
-{
-
-}
-
-
-/**
- * goo_canvas_polyline_model_new:
- * @parent: the parent model, or %NULL. If a parent is specified, it will
- * assume ownership of the item, and the item will automatically be freed when
- * it is removed from the parent. Otherwise call g_object_unref() to free it.
- * @close_path: if the last point should be connected to the first.
- * @num_points: the number of points in the polyline.
- * @...: the pairs of coordinates for each point in the line, followed by
- * optional pairs of property names and values, and a terminating %NULL.
- *
- * Creates a new polyline model.
- *
- * <!--PARAMETERS-->
- *
- * Here's an example showing how to create a filled triangle with vertices
- * at (100,100), (300,100), and (200,300).
- *
- * <informalexample><programlisting>
- * GooCanvasItemModel *polyline = goo_canvas_polyline_model_new (mygroup, TRUE, 3,
- * 100.0, 100.0,
- * 300.0, 100.0,
- * 200.0, 300.0,
- * "stroke-color", "red",
- * "line-width", 5.0,
- * "fill-color", "blue",
- * NULL);
- * </programlisting></informalexample>
- *
- * Returns: a new polyline model.
- **/
-GooCanvasItemModel*
-goo_canvas_polyline_model_new (GooCanvasItemModel *parent,
- gboolean close_path,
- gint num_points,
- ...)
-{
- GooCanvasItemModel *model;
- GooCanvasPolylineModel *pmodel;
- GooCanvasPolylineData *polyline_data;
- const char *first_property;
- va_list var_args;
- gint i;
-
- model = g_object_new (GOO_TYPE_CANVAS_POLYLINE_MODEL, NULL);
- pmodel = (GooCanvasPolylineModel*) model;
-
- polyline_data = &pmodel->polyline_data;
- polyline_data->close_path = close_path;
- polyline_data->num_points = num_points;
- if (num_points)
- polyline_data->coords = g_slice_alloc (num_points * 2 * sizeof (gdouble));
-
- va_start (var_args, num_points);
- for (i = 0; i < num_points * 2; i++)
- polyline_data->coords[i] = va_arg (var_args, gdouble);
-
- first_property = va_arg (var_args, char*);
- if (first_property)
- g_object_set_valist ((GObject*) model, first_property, var_args);
- va_end (var_args);
-
- if (parent)
- {
- goo_canvas_item_model_add_child (parent, model, -1);
- g_object_unref (model);
- }
-
- return model;
-}
-
-
-/**
- * goo_canvas_polyline_model_new_line:
- * @parent: the parent model, or %NULL.
- * @x1: the x coordinate of the start of the line.
- * @y1: the y coordinate of the start of the line.
- * @x2: the x coordinate of the end of the line.
- * @y2: the y coordinate of the end of the line.
- * @...: optional pairs of property names and values, and a terminating %NULL.
- *
- * Creates a new polyline model with a single line.
- *
- * <!--PARAMETERS-->
- *
- * Here's an example showing how to create a line from (100,100) to (300,300).
- *
- * <informalexample><programlisting>
- * GooCanvasItemModel *polyline = goo_canvas_polyline_model_new_line (mygroup,
- * 100.0, 100.0,
- * 300.0, 300.0,
- * "stroke-color", "red",
- * "line-width", 5.0,
- * NULL);
- * </programlisting></informalexample>
- *
- * Returns: a new polyline model.
- **/
-GooCanvasItemModel*
-goo_canvas_polyline_model_new_line (GooCanvasItemModel *parent,
- gdouble x1,
- gdouble y1,
- gdouble x2,
- gdouble y2,
- ...)
-{
- GooCanvasItemModel *model;
- GooCanvasPolylineModel *pmodel;
- GooCanvasPolylineData *polyline_data;
- const char *first_property;
- va_list var_args;
-
- model = g_object_new (GOO_TYPE_CANVAS_POLYLINE_MODEL, NULL);
- pmodel = (GooCanvasPolylineModel*) model;
-
- polyline_data = &pmodel->polyline_data;
- polyline_data->close_path = FALSE;
- polyline_data->num_points = 2;
- polyline_data->coords = g_slice_alloc (4 * sizeof (gdouble));
- polyline_data->coords[0] = x1;
- polyline_data->coords[1] = y1;
- polyline_data->coords[2] = x2;
- polyline_data->coords[3] = y2;
-
- va_start (var_args, y2);
- first_property = va_arg (var_args, char*);
- if (first_property)
- g_object_set_valist ((GObject*) model, first_property, var_args);
- va_end (var_args);
-
- if (parent)
- {
- goo_canvas_item_model_add_child (parent, model, -1);
- g_object_unref (model);
- }
-
- return model;
-}
-
-
-static void
-goo_canvas_polyline_model_finalize (GObject *object)
-{
- GooCanvasPolylineModel *pmodel = (GooCanvasPolylineModel*) object;
-
- g_slice_free1 (pmodel->polyline_data.num_points * 2 * sizeof (gdouble),
- pmodel->polyline_data.coords);
- g_slice_free (GooCanvasPolylineArrowData, pmodel->polyline_data.arrow_data);
-
- G_OBJECT_CLASS (goo_canvas_polyline_model_parent_class)->finalize (object);
-}
-
-
-static void
-goo_canvas_polyline_model_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- GooCanvasPolylineModel *pmodel = (GooCanvasPolylineModel*) object;
+ g_object_class_install_property (gobject_class, PROP_POINTS,
+ g_param_spec_boxed ("points",
+ _("Points"),
+ _("The array of points"),
+ GOO_TYPE_CANVAS_POINTS,
+ G_PARAM_READWRITE));
- goo_canvas_polyline_get_common_property (object, &pmodel->polyline_data,
- prop_id, value, pspec);
-}
+ g_object_class_install_property (gobject_class, PROP_CLOSE_PATH,
+ g_param_spec_boolean ("close-path",
+ _("Close Path"),
+ _("If the last point should be connected to the first"),
+ FALSE,
+ G_PARAM_READWRITE));
+ g_object_class_install_property (gobject_class, PROP_START_ARROW,
+ g_param_spec_boolean ("start-arrow",
+ _("Start Arrow"),
+ _("If an arrow should be displayed at the start of the polyline"),
+ FALSE,
+ G_PARAM_READWRITE));
-static void
-goo_canvas_polyline_model_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- GooCanvasPolylineModel *pmodel = (GooCanvasPolylineModel*) object;
+ g_object_class_install_property (gobject_class, PROP_END_ARROW,
+ g_param_spec_boolean ("end-arrow",
+ _("End Arrow"),
+ _("If an arrow should be displayed at the end of the polyline"),
+ FALSE,
+ G_PARAM_READWRITE));
- goo_canvas_polyline_set_common_property (object, &pmodel->polyline_data,
- prop_id, value, pspec);
- g_signal_emit_by_name (pmodel, "changed", TRUE);
-}
+ g_object_class_install_property (gobject_class, PROP_ARROW_LENGTH,
+ g_param_spec_double ("arrow-length",
+ _("Arrow Length"),
+ _("The length of the arrows, as a multiple of the line width"),
+ 0.0, G_MAXDOUBLE, 5.0,
+ G_PARAM_READWRITE));
+ g_object_class_install_property (gobject_class, PROP_ARROW_WIDTH,
+ g_param_spec_double ("arrow-width",
+ _("Arrow Width"),
+ _("The width of the arrows, as a multiple of the line width"),
+ 0.0, G_MAXDOUBLE, 4.0,
+ G_PARAM_READWRITE));
-static GooCanvasItem*
-goo_canvas_polyline_model_create_item (GooCanvasItemModel *model,
- GooCanvas *canvas)
-{
- GooCanvasItem *item;
+ g_object_class_install_property (gobject_class, PROP_ARROW_TIP_LENGTH,
+ g_param_spec_double ("arrow-tip-length",
+ _("Arrow Tip Length"),
+ _("The length of the arrow tip, as a multiple of the line width"),
+ 0.0, G_MAXDOUBLE, 4.0,
+ G_PARAM_READWRITE));
- item = g_object_new (GOO_TYPE_CANVAS_POLYLINE, NULL);
- goo_canvas_item_set_model (item, model);
+ g_object_class_install_property (gobject_class, PROP_X,
+ g_param_spec_double ("x",
+ "X",
+ _("The x coordinate of the left-most point of the polyline"),
+ -G_MAXDOUBLE,
+ G_MAXDOUBLE, 0.0,
+ G_PARAM_READWRITE));
- return item;
-}
+ g_object_class_install_property (gobject_class, PROP_Y,
+ g_param_spec_double ("y",
+ "Y",
+ _("The y coordinate of the top-most point of the polyline"),
+ -G_MAXDOUBLE,
+ G_MAXDOUBLE, 0.0,
+ G_PARAM_READWRITE));
+ g_object_class_install_property (gobject_class, PROP_WIDTH,
+ g_param_spec_double ("width",
+ _("Width"),
+ _("The width of the polyline"),
+ 0.0, G_MAXDOUBLE, 0.0,
+ G_PARAM_READWRITE));
-static void
-item_model_interface_init (GooCanvasItemModelIface *iface)
-{
- iface->create_item = goo_canvas_polyline_model_create_item;
+ g_object_class_install_property (gobject_class, PROP_HEIGHT,
+ g_param_spec_double ("height",
+ _("Height"),
+ _("The height of the polyline"),
+ 0.0, G_MAXDOUBLE, 0.0,
+ G_PARAM_READWRITE));
}
diff --git a/src/goocanvaspolyline.h b/src/goocanvaspolyline.h
index 96212bd..a038432 100644
--- a/src/goocanvaspolyline.h
+++ b/src/goocanvaspolyline.h
@@ -51,22 +51,6 @@ struct _GooCanvasPolylineArrowData
};
-/* This is the data used by both model and view classes. */
-typedef struct _GooCanvasPolylineData GooCanvasPolylineData;
-struct _GooCanvasPolylineData
-{
- gdouble *coords;
-
- GooCanvasPolylineArrowData *arrow_data;
-
- guint num_points : 16;
- guint close_path : 1;
- guint start_arrow : 1;
- guint end_arrow : 1;
- guint reconfigure_arrows : 1; /* Not used any more. */
-};
-
-
#define GOO_TYPE_CANVAS_POLYLINE (goo_canvas_polyline_get_type ())
#define GOO_CANVAS_POLYLINE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GOO_TYPE_CANVAS_POLYLINE, GooCanvasPolyline))
#define GOO_CANVAS_POLYLINE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GOO_TYPE_CANVAS_POLYLINE, GooCanvasPolylineClass))
@@ -87,7 +71,14 @@ struct _GooCanvasPolyline
{
GooCanvasItemSimple parent;
- GooCanvasPolylineData *polyline_data;
+ gdouble *coords;
+
+ GooCanvasPolylineArrowData *arrow_data;
+
+ guint num_points : 16;
+ guint close_path : 1;
+ guint start_arrow : 1;
+ guint end_arrow : 1;
};
struct _GooCanvasPolylineClass
@@ -120,57 +111,6 @@ GooCanvasItem* goo_canvas_polyline_new_line (GooCanvasItem *pare
-#define GOO_TYPE_CANVAS_POLYLINE_MODEL (goo_canvas_polyline_model_get_type ())
-#define GOO_CANVAS_POLYLINE_MODEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GOO_TYPE_CANVAS_POLYLINE_MODEL, GooCanvasPolylineModel))
-#define GOO_CANVAS_POLYLINE_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GOO_TYPE_CANVAS_POLYLINE_MODEL, GooCanvasPolylineModelClass))
-#define GOO_IS_CANVAS_POLYLINE_MODEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GOO_TYPE_CANVAS_POLYLINE_MODEL))
-#define GOO_IS_CANVAS_POLYLINE_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GOO_TYPE_CANVAS_POLYLINE_MODEL))
-#define GOO_CANVAS_POLYLINE_MODEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GOO_TYPE_CANVAS_POLYLINE_MODEL, GooCanvasPolylineModelClass))
-
-
-typedef struct _GooCanvasPolylineModel GooCanvasPolylineModel;
-typedef struct _GooCanvasPolylineModelClass GooCanvasPolylineModelClass;
-
-/**
- * GooCanvasPolylineModel
- *
- * The #GooCanvasPolylineModel-struct struct contains private data only.
- */
-struct _GooCanvasPolylineModel
-{
- GooCanvasItemModelSimple parent_object;
-
- GooCanvasPolylineData polyline_data;
-};
-
-struct _GooCanvasPolylineModelClass
-{
- GooCanvasItemModelSimpleClass parent_class;
-
- /*< private >*/
-
- /* Padding for future expansion */
- void (*_goo_canvas_reserved1) (void);
- void (*_goo_canvas_reserved2) (void);
- void (*_goo_canvas_reserved3) (void);
- void (*_goo_canvas_reserved4) (void);
-};
-
-
-GType goo_canvas_polyline_model_get_type (void) G_GNUC_CONST;
-
-GooCanvasItemModel* goo_canvas_polyline_model_new (GooCanvasItemModel *parent,
- gboolean close_path,
- gint num_points,
- ...);
-
-GooCanvasItemModel* goo_canvas_polyline_model_new_line (GooCanvasItemModel *parent,
- gdouble x1,
- gdouble y1,
- gdouble x2,
- gdouble y2,
- ...);
-
G_END_DECLS
#endif /* __GOO_CANVAS_POLYLINE_H__ */
diff --git a/src/goocanvasrect.c b/src/goocanvasrect.c
index 0af1021..8257574 100644
--- a/src/goocanvasrect.c
+++ b/src/goocanvasrect.c
@@ -44,67 +44,13 @@ enum {
};
-static void canvas_item_interface_init (GooCanvasItemIface *iface);
-
-G_DEFINE_TYPE_WITH_CODE (GooCanvasRect, goo_canvas_rect,
- GOO_TYPE_CANVAS_ITEM_SIMPLE,
- G_IMPLEMENT_INTERFACE (GOO_TYPE_CANVAS_ITEM,
- canvas_item_interface_init))
-
-
-static void
-goo_canvas_rect_install_common_properties (GObjectClass *gobject_class)
-{
- g_object_class_install_property (gobject_class, PROP_X,
- g_param_spec_double ("x",
- "X",
- _("The x coordinate of the rectangle"),
- -G_MAXDOUBLE,
- G_MAXDOUBLE, 0.0,
- G_PARAM_READWRITE));
-
- g_object_class_install_property (gobject_class, PROP_Y,
- g_param_spec_double ("y",
- "Y",
- _("The y coordinate of the rectangle"),
- -G_MAXDOUBLE,
- G_MAXDOUBLE, 0.0,
- G_PARAM_READWRITE));
-
- g_object_class_install_property (gobject_class, PROP_WIDTH,
- g_param_spec_double ("width",
- _("Width"),
- _("The width of the rectangle"),
- 0.0, G_MAXDOUBLE, 0.0,
- G_PARAM_READWRITE));
-
- g_object_class_install_property (gobject_class, PROP_HEIGHT,
- g_param_spec_double ("height",
- _("Height"),
- _("The height of the rectangle"),
- 0.0, G_MAXDOUBLE, 0.0,
- G_PARAM_READWRITE));
-
- g_object_class_install_property (gobject_class, PROP_RADIUS_X,
- g_param_spec_double ("radius_x",
- _("Radius X"),
- _("The horizontal radius to use for rounded corners"),
- 0.0, G_MAXDOUBLE, 0.0,
- G_PARAM_READWRITE));
-
- g_object_class_install_property (gobject_class, PROP_RADIUS_Y,
- g_param_spec_double ("radius_y",
- _("Radius Y"),
- _("The vertical radius to use for rounded corners"),
- 0.0, G_MAXDOUBLE, 0.0,
- G_PARAM_READWRITE));
-}
+G_DEFINE_TYPE (GooCanvasRect, goo_canvas_rect, GOO_TYPE_CANVAS_ITEM_SIMPLE)
static void
goo_canvas_rect_init (GooCanvasRect *rect)
{
- rect->rect_data = g_slice_new0 (GooCanvasRectData);
+
}
@@ -146,20 +92,18 @@ goo_canvas_rect_new (GooCanvasItem *parent,
{
GooCanvasItem *item;
GooCanvasRect *rect;
- GooCanvasRectData *rect_data;
const char *first_property;
va_list var_args;
item = g_object_new (GOO_TYPE_CANVAS_RECT, NULL);
rect = (GooCanvasRect*) item;
- rect_data = rect->rect_data;
- rect_data->x = x;
- rect_data->y = y;
- rect_data->width = width;
- rect_data->height = height;
- rect_data->radius_x = 0;
- rect_data->radius_y = 0;
+ rect->x = x;
+ rect->y = y;
+ rect->width = width;
+ rect->height = height;
+ rect->radius_x = 0;
+ rect->radius_y = 0;
va_start (var_args, height);
first_property = va_arg (var_args, char*);
@@ -178,47 +122,32 @@ goo_canvas_rect_new (GooCanvasItem *parent,
static void
-goo_canvas_rect_finalize (GObject *object)
+goo_canvas_rect_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
{
- GooCanvasItemSimple *simple = (GooCanvasItemSimple*) object;
GooCanvasRect *rect = (GooCanvasRect*) object;
- /* Free our data if we didn't have a model. (If we had a model it would
- have been reset in dispose() and simple_data will be NULL.) */
- if (simple->simple_data)
- g_slice_free (GooCanvasRectData, rect->rect_data);
- rect->rect_data = NULL;
-
- G_OBJECT_CLASS (goo_canvas_rect_parent_class)->finalize (object);
-}
-
-
-static void
-goo_canvas_rect_get_common_property (GObject *object,
- GooCanvasRectData *rect_data,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
switch (prop_id)
{
case PROP_X:
- g_value_set_double (value, rect_data->x);
+ g_value_set_double (value, rect->x);
break;
case PROP_Y:
- g_value_set_double (value, rect_data->y);
+ g_value_set_double (value, rect->y);
break;
case PROP_WIDTH:
- g_value_set_double (value, rect_data->width);
+ g_value_set_double (value, rect->width);
break;
case PROP_HEIGHT:
- g_value_set_double (value, rect_data->height);
+ g_value_set_double (value, rect->height);
break;
case PROP_RADIUS_X:
- g_value_set_double (value, rect_data->radius_x);
+ g_value_set_double (value, rect->radius_x);
break;
case PROP_RADIUS_Y:
- g_value_set_double (value, rect_data->radius_y);
+ g_value_set_double (value, rect->radius_y);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -228,69 +157,39 @@ goo_canvas_rect_get_common_property (GObject *object,
static void
-goo_canvas_rect_get_property (GObject *object,
+goo_canvas_rect_set_property (GObject *object,
guint prop_id,
- GValue *value,
+ const GValue *value,
GParamSpec *pspec)
{
+ GooCanvasItemSimple *simple = (GooCanvasItemSimple*) object;
GooCanvasRect *rect = (GooCanvasRect*) object;
- goo_canvas_rect_get_common_property (object, rect->rect_data, prop_id,
- value, pspec);
-}
-
-
-static void
-goo_canvas_rect_set_common_property (GObject *object,
- GooCanvasRectData *rect_data,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
switch (prop_id)
{
case PROP_X:
- rect_data->x = g_value_get_double (value);
+ rect->x = g_value_get_double (value);
break;
case PROP_Y:
- rect_data->y = g_value_get_double (value);
+ rect->y = g_value_get_double (value);
break;
case PROP_WIDTH:
- rect_data->width = g_value_get_double (value);
+ rect->width = g_value_get_double (value);
break;
case PROP_HEIGHT:
- rect_data->height = g_value_get_double (value);
+ rect->height = g_value_get_double (value);
break;
case PROP_RADIUS_X:
- rect_data->radius_x = g_value_get_double (value);
+ rect->radius_x = g_value_get_double (value);
break;
case PROP_RADIUS_Y:
- rect_data->radius_y = g_value_get_double (value);
+ rect->radius_y = g_value_get_double (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
-}
-
-
-static void
-goo_canvas_rect_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- GooCanvasItemSimple *simple = (GooCanvasItemSimple*) object;
- GooCanvasRect *rect = (GooCanvasRect*) object;
- if (simple->model)
- {
- g_warning ("Can't set property of a canvas item with a model - set the model property instead");
- return;
- }
-
- goo_canvas_rect_set_common_property (object, rect->rect_data, prop_id,
- value, pspec);
goo_canvas_item_simple_changed (simple, TRUE);
}
@@ -300,54 +199,50 @@ goo_canvas_rect_create_path (GooCanvasItemSimple *simple,
cairo_t *cr)
{
GooCanvasRect *rect = (GooCanvasRect*) simple;
- GooCanvasRectData *rect_data = rect->rect_data;
cairo_new_path (cr);
/* Check if we need to draw rounded corners. */
- if (rect_data->radius_x > 0 && rect_data->radius_y > 0)
+ if (rect->radius_x > 0 && rect->radius_y > 0)
{
/* The radii can't be more than half the size of the rect. */
- double rx = MIN (rect_data->radius_x, rect_data->width / 2);
- double ry = MIN (rect_data->radius_y, rect_data->height / 2);
+ double rx = MIN (rect->radius_x, rect->width / 2);
+ double ry = MIN (rect->radius_y, rect->height / 2);
/* Draw the top-right arc. */
cairo_save (cr);
- cairo_translate (cr, rect_data->x + rect_data->width - rx,
- rect_data->y + ry);
+ cairo_translate (cr, rect->x + rect->width - rx, rect->y + ry);
cairo_scale (cr, rx, ry);
cairo_arc (cr, 0.0, 0.0, 1.0, 1.5 * M_PI, 2.0 * M_PI);
cairo_restore (cr);
/* Draw the line down the right side. */
- cairo_line_to (cr, rect_data->x + rect_data->width,
- rect_data->y + rect_data->height - ry);
+ cairo_line_to (cr, rect->x + rect->width, rect->y + rect->height - ry);
/* Draw the bottom-right arc. */
cairo_save (cr);
- cairo_translate (cr, rect_data->x + rect_data->width - rx,
- rect_data->y + rect_data->height - ry);
+ cairo_translate (cr, rect->x + rect->width - rx,
+ rect->y + rect->height - ry);
cairo_scale (cr, rx, ry);
cairo_arc (cr, 0.0, 0.0, 1.0, 0.0, 0.5 * M_PI);
cairo_restore (cr);
/* Draw the line left across the bottom. */
- cairo_line_to (cr, rect_data->x + rx, rect_data->y + rect_data->height);
+ cairo_line_to (cr, rect->x + rx, rect->y + rect->height);
/* Draw the bottom-left arc. */
cairo_save (cr);
- cairo_translate (cr, rect_data->x + rx,
- rect_data->y + rect_data->height - ry);
+ cairo_translate (cr, rect->x + rx, rect->y + rect->height - ry);
cairo_scale (cr, rx, ry);
cairo_arc (cr, 0.0, 0.0, 1.0, 0.5 * M_PI, M_PI);
cairo_restore (cr);
/* Draw the line up the left side. */
- cairo_line_to (cr, rect_data->x, rect_data->y + ry);
+ cairo_line_to (cr, rect->x, rect->y + ry);
/* Draw the top-left arc. */
cairo_save (cr);
- cairo_translate (cr, rect_data->x + rx, rect_data->y + ry);
+ cairo_translate (cr, rect->x + rx, rect->y + ry);
cairo_scale (cr, rx, ry);
cairo_arc (cr, 0.0, 0.0, 1.0, M_PI, 1.5 * M_PI);
cairo_restore (cr);
@@ -358,8 +253,7 @@ goo_canvas_rect_create_path (GooCanvasItemSimple *simple,
else
{
/* Draw the plain rectangle. */
- cairo_rectangle (cr, rect_data->x, rect_data->y,
- rect_data->width, rect_data->height);
+ cairo_rectangle (cr, rect->x, rect->y, rect->width, rect->height);
}
}
@@ -369,44 +263,16 @@ goo_canvas_rect_update (GooCanvasItemSimple *simple,
cairo_t *cr)
{
GooCanvasRect *rect = (GooCanvasRect*) simple;
- GooCanvasRectData *rect_data = rect->rect_data;
gdouble half_line_width;
/* We can quickly compute the bounds as being just the rectangle's size
plus half the line width around each edge. */
half_line_width = goo_canvas_item_simple_get_line_width (simple) / 2;
- simple->bounds.x1 = rect_data->x - half_line_width;
- simple->bounds.y1 = rect_data->y - half_line_width;
- simple->bounds.x2 = rect_data->x + rect_data->width + half_line_width;
- simple->bounds.y2 = rect_data->y + rect_data->height + half_line_width;
-}
-
-
-static void
-goo_canvas_rect_set_model (GooCanvasItem *item,
- GooCanvasItemModel *model)
-{
- GooCanvasItemSimple *simple = (GooCanvasItemSimple*) item;
- GooCanvasRect *rect = (GooCanvasRect*) item;
- GooCanvasRectModel *rmodel = (GooCanvasRectModel*) model;
-
- /* If our rect_data was allocated, free it. */
- if (!simple->model)
- g_slice_free (GooCanvasRectData, rect->rect_data);
-
- /* Now use the new model's rect_data instead. */
- rect->rect_data = &rmodel->rect_data;
-
- /* Let the parent GooCanvasItemSimple code do the rest. */
- goo_canvas_item_simple_set_model (simple, model);
-}
-
-
-static void
-canvas_item_interface_init (GooCanvasItemIface *iface)
-{
- iface->set_model = goo_canvas_rect_set_model;
+ simple->bounds.x1 = rect->x - half_line_width;
+ simple->bounds.y1 = rect->y - half_line_width;
+ simple->bounds.x2 = rect->x + rect->width + half_line_width;
+ simple->bounds.y2 = rect->y + rect->height + half_line_width;
}
@@ -416,188 +282,53 @@ goo_canvas_rect_class_init (GooCanvasRectClass *klass)
GObjectClass *gobject_class = (GObjectClass*) klass;
GooCanvasItemSimpleClass *simple_class = (GooCanvasItemSimpleClass*) klass;
- gobject_class->finalize = goo_canvas_rect_finalize;
-
gobject_class->get_property = goo_canvas_rect_get_property;
gobject_class->set_property = goo_canvas_rect_set_property;
simple_class->simple_create_path = goo_canvas_rect_create_path;
simple_class->simple_update = goo_canvas_rect_update;
- goo_canvas_rect_install_common_properties (gobject_class);
-}
-
-
-/**
- * SECTION:goocanvasrectmodel
- * @Title: GooCanvasRectModel
- * @Short_Description: a model for rectangle items.
- *
- * GooCanvasRectModel represents a model for rectangle items.
- *
- * It is a subclass of #GooCanvasItemModelSimple and so inherits all of the
- * style properties such as "stroke-color", "fill-color" and "line-width".
- *
- * It also implements the #GooCanvasItemModel interface, so you can use the
- * #GooCanvasItemModel functions such as goo_canvas_item_model_raise() and
- * goo_canvas_item_model_rotate().
- *
- * To create a #GooCanvasRectModel use goo_canvas_rect_model_new().
- *
- * To get or set the properties of an existing #GooCanvasRectModel, use
- * g_object_get() and g_object_set().
- *
- * To respond to events such as mouse clicks on the rectangle you must connect
- * to the signal handlers of the corresponding #GooCanvasRect objects.
- * (See goo_canvas_get_item() and #GooCanvas::item-created.)
- */
-
-static void item_model_interface_init (GooCanvasItemModelIface *iface);
-static void goo_canvas_rect_model_get_property (GObject *object,
- guint param_id,
- GValue *value,
- GParamSpec *pspec);
-static void goo_canvas_rect_model_set_property (GObject *object,
- guint param_id,
- const GValue *value,
- GParamSpec *pspec);
-
-G_DEFINE_TYPE_WITH_CODE (GooCanvasRectModel, goo_canvas_rect_model,
- GOO_TYPE_CANVAS_ITEM_MODEL_SIMPLE,
- G_IMPLEMENT_INTERFACE (GOO_TYPE_CANVAS_ITEM_MODEL,
- item_model_interface_init))
-
-
-static void
-goo_canvas_rect_model_class_init (GooCanvasRectModelClass *klass)
-{
- GObjectClass *gobject_class = (GObjectClass*) klass;
-
- gobject_class->get_property = goo_canvas_rect_model_get_property;
- gobject_class->set_property = goo_canvas_rect_model_set_property;
-
- goo_canvas_rect_install_common_properties (gobject_class);
-}
-
-
-static void
-goo_canvas_rect_model_init (GooCanvasRectModel *rmodel)
-{
-
-}
-
-
-/**
- * goo_canvas_rect_model_new:
- * @parent: the parent model, or %NULL. If a parent is specified, it will
- * assume ownership of the item, and the item will automatically be freed when
- * it is removed from the parent. Otherwise call g_object_unref() to free it.
- * @x: the x coordinate of the left of the rectangle.
- * @y: the y coordinate of the top of the rectangle.
- * @width: the width of the rectangle.
- * @height: the height of the rectangle.
- * @...: optional pairs of property names and values, and a terminating %NULL.
- *
- * Creates a new rectangle item.
- *
- * <!--PARAMETERS-->
- *
- * Here's an example showing how to create a rectangle at (100,100) with a
- * width of 200 and a height of 100.
- *
- * <informalexample><programlisting>
- * GooCanvasItemModel *rect = goo_canvas_rect_model_new (mygroup, 100.0, 100.0, 200.0, 100.0,
- * "stroke-color", "red",
- * "line-width", 5.0,
- * "fill-color", "blue",
- * NULL);
- * </programlisting></informalexample>
- *
- * Returns: a new rectangle model.
- **/
-GooCanvasItemModel*
-goo_canvas_rect_model_new (GooCanvasItemModel *parent,
- gdouble x,
- gdouble y,
- gdouble width,
- gdouble height,
- ...)
-{
- GooCanvasItemModel *model;
- GooCanvasRectModel *rmodel;
- GooCanvasRectData *rect_data;
- const char *first_property;
- va_list var_args;
-
- model = g_object_new (GOO_TYPE_CANVAS_RECT_MODEL, NULL);
- rmodel = (GooCanvasRectModel*) model;
-
- rect_data = &rmodel->rect_data;
- rect_data->x = x;
- rect_data->y = y;
- rect_data->width = width;
- rect_data->height = height;
- rect_data->radius_x = 0;
- rect_data->radius_y = 0;
-
- va_start (var_args, height);
- first_property = va_arg (var_args, char*);
- if (first_property)
- g_object_set_valist ((GObject*) model, first_property, var_args);
- va_end (var_args);
-
- if (parent)
- {
- goo_canvas_item_model_add_child (parent, model, -1);
- g_object_unref (model);
- }
-
- return model;
-}
-
-
-static void
-goo_canvas_rect_model_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- GooCanvasRectModel *rmodel = (GooCanvasRectModel*) object;
-
- goo_canvas_rect_get_common_property (object, &rmodel->rect_data, prop_id,
- value, pspec);
-}
-
-
-static void
-goo_canvas_rect_model_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- GooCanvasRectModel *rmodel = (GooCanvasRectModel*) object;
-
- goo_canvas_rect_set_common_property (object, &rmodel->rect_data, prop_id,
- value, pspec);
- g_signal_emit_by_name (rmodel, "changed", TRUE);
-}
-
+ g_object_class_install_property (gobject_class, PROP_X,
+ g_param_spec_double ("x",
+ "X",
+ _("The x coordinate of the rectangle"),
+ -G_MAXDOUBLE,
+ G_MAXDOUBLE, 0.0,
+ G_PARAM_READWRITE));
-static GooCanvasItem*
-goo_canvas_rect_model_create_item (GooCanvasItemModel *model,
- GooCanvas *canvas)
-{
- GooCanvasItem *item;
+ g_object_class_install_property (gobject_class, PROP_Y,
+ g_param_spec_double ("y",
+ "Y",
+ _("The y coordinate of the rectangle"),
+ -G_MAXDOUBLE,
+ G_MAXDOUBLE, 0.0,
+ G_PARAM_READWRITE));
- item = g_object_new (GOO_TYPE_CANVAS_RECT, NULL);
- goo_canvas_item_set_model (item, model);
+ g_object_class_install_property (gobject_class, PROP_WIDTH,
+ g_param_spec_double ("width",
+ _("Width"),
+ _("The width of the rectangle"),
+ 0.0, G_MAXDOUBLE, 0.0,
+ G_PARAM_READWRITE));
- return item;
-}
+ g_object_class_install_property (gobject_class, PROP_HEIGHT,
+ g_param_spec_double ("height",
+ _("Height"),
+ _("The height of the rectangle"),
+ 0.0, G_MAXDOUBLE, 0.0,
+ G_PARAM_READWRITE));
+ g_object_class_install_property (gobject_class, PROP_RADIUS_X,
+ g_param_spec_double ("radius_x",
+ _("Radius X"),
+ _("The horizontal radius to use for rounded corners"),
+ 0.0, G_MAXDOUBLE, 0.0,
+ G_PARAM_READWRITE));
-static void
-item_model_interface_init (GooCanvasItemModelIface *iface)
-{
- iface->create_item = goo_canvas_rect_model_create_item;
+ g_object_class_install_property (gobject_class, PROP_RADIUS_Y,
+ g_param_spec_double ("radius_y",
+ _("Radius Y"),
+ _("The vertical radius to use for rounded corners"),
+ 0.0, G_MAXDOUBLE, 0.0,
+ G_PARAM_READWRITE));
}
diff --git a/src/goocanvasrect.h b/src/goocanvasrect.h
index 4d92928..5ba1ccf 100644
--- a/src/goocanvasrect.h
+++ b/src/goocanvasrect.h
@@ -13,14 +13,6 @@
G_BEGIN_DECLS
-/* This is the data used by both model and view classes. */
-typedef struct _GooCanvasRectData GooCanvasRectData;
-struct _GooCanvasRectData
-{
- gdouble x, y, width, height, radius_x, radius_y;
-};
-
-
#define GOO_TYPE_CANVAS_RECT (goo_canvas_rect_get_type ())
#define GOO_CANVAS_RECT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GOO_TYPE_CANVAS_RECT, GooCanvasRect))
#define GOO_CANVAS_RECT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GOO_TYPE_CANVAS_RECT, GooCanvasRectClass))
@@ -41,7 +33,7 @@ struct _GooCanvasRect
{
GooCanvasItemSimple parent;
- GooCanvasRectData *rect_data;
+ gdouble x, y, width, height, radius_x, radius_y;
};
struct _GooCanvasRectClass
@@ -69,53 +61,6 @@ GooCanvasItem* goo_canvas_rect_new (GooCanvasItem *parent,
-#define GOO_TYPE_CANVAS_RECT_MODEL (goo_canvas_rect_model_get_type ())
-#define GOO_CANVAS_RECT_MODEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GOO_TYPE_CANVAS_RECT_MODEL, GooCanvasRectModel))
-#define GOO_CANVAS_RECT_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GOO_TYPE_CANVAS_RECT_MODEL, GooCanvasRectModelClass))
-#define GOO_IS_CANVAS_RECT_MODEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GOO_TYPE_CANVAS_RECT_MODEL))
-#define GOO_IS_CANVAS_RECT_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GOO_TYPE_CANVAS_RECT_MODEL))
-#define GOO_CANVAS_RECT_MODEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GOO_TYPE_CANVAS_RECT_MODEL, GooCanvasRectModelClass))
-
-
-typedef struct _GooCanvasRectModel GooCanvasRectModel;
-typedef struct _GooCanvasRectModelClass GooCanvasRectModelClass;
-
-/**
- * GooCanvasRectModel
- *
- * The #GooCanvasRectModel-struct struct contains private data only.
- */
-struct _GooCanvasRectModel
-{
- GooCanvasItemModelSimple parent_object;
-
- GooCanvasRectData rect_data;
-};
-
-struct _GooCanvasRectModelClass
-{
- GooCanvasItemModelSimpleClass parent_class;
-
- /*< private >*/
-
- /* Padding for future expansion */
- void (*_goo_canvas_reserved1) (void);
- void (*_goo_canvas_reserved2) (void);
- void (*_goo_canvas_reserved3) (void);
- void (*_goo_canvas_reserved4) (void);
-};
-
-
-GType goo_canvas_rect_model_get_type (void) G_GNUC_CONST;
-
-GooCanvasItemModel* goo_canvas_rect_model_new (GooCanvasItemModel *parent,
- gdouble x,
- gdouble y,
- gdouble width,
- gdouble height,
- ...);
-
-
G_END_DECLS
#endif /* __GOO_CANVAS_RECT_H__ */
diff --git a/src/goocanvastable.c b/src/goocanvastable.c
index 05e5718..4137b88 100644
--- a/src/goocanvastable.c
+++ b/src/goocanvastable.c
@@ -97,7 +97,7 @@ typedef enum
} GooCanvasTableChildFlags;
-/* This is used in the GooCanvasTableData children GArray to keep the child
+/* This is used in the GooCanvasTable children GArray to keep the child
properties for each of the children. */
typedef struct _GooCanvasTableChild GooCanvasTableChild;
struct _GooCanvasTableChild
@@ -212,7 +212,7 @@ static void goo_canvas_table_set_property (GObject *object,
GParamSpec *pspec);
static void goo_canvas_table_init_layout_data (GooCanvasTable *table);
-static void goo_canvas_table_free_layout_data (GooCanvasTableData *table_data);
+static void goo_canvas_table_free_layout_data (GooCanvasTable *table);
G_DEFINE_TYPE_WITH_CODE (GooCanvasTable, goo_canvas_table,
GOO_TYPE_CANVAS_GROUP,
@@ -405,68 +405,41 @@ goo_canvas_table_class_init (GooCanvasTableClass *klass)
}
-/* This initializes the common table data. */
static void
-goo_canvas_table_init_data (GooCanvasTableData *table_data)
+goo_canvas_table_init (GooCanvasTable *table)
{
gint d;
- table_data->width = -1.0;
- table_data->height = -1.0;
+ table->width = -1.0;
+ table->height = -1.0;
for (d = 0; d < 2; d++)
{
- table_data->dimensions[d].size = 0;
- table_data->dimensions[d].default_spacing = 0.0;
- table_data->dimensions[d].spacings = NULL;
- table_data->dimensions[d].homogeneous = FALSE;
+ table->dimensions[d].size = 0;
+ table->dimensions[d].default_spacing = 0.0;
+ table->dimensions[d].spacings = NULL;
+ table->dimensions[d].homogeneous = FALSE;
}
- table_data->border_width = 0.0;
+ table->border_width = 0.0;
- table_data->children = g_array_new (0, 0, sizeof (GooCanvasTableChild));
+ table->children = g_array_new (0, 0, sizeof (GooCanvasTableChild));
- table_data->layout_data = g_slice_new (GooCanvasTableLayoutData);
- table_data->layout_data->x = 0.0;
- table_data->layout_data->y = 0.0;
+ table->layout_data = g_slice_new (GooCanvasTableLayoutData);
+ table->layout_data->x = 0.0;
+ table->layout_data->y = 0.0;
- table_data->layout_data->children = NULL;
+ table->layout_data->children = NULL;
for (d = 0; d < 2; d++)
{
- table_data->layout_data->dldata[d] = NULL;
- table_data->layout_data->prop_grid_line_width[d] = 0.0;
- table_data->layout_data->grid_line_width[d] = 0.0;
- table_data->layout_data->border_spacing[d] = 0.0;
+ table->layout_data->dldata[d] = NULL;
+ table->layout_data->prop_grid_line_width[d] = 0.0;
+ table->layout_data->grid_line_width[d] = 0.0;
+ table->layout_data->border_spacing[d] = 0.0;
}
}
-/* This frees the contents of the table data, but not the struct itself. */
-static void
-goo_canvas_table_free_data (GooCanvasTableData *table_data)
-{
- gint d;
-
- g_array_free (table_data->children, TRUE);
-
- for (d = 0; d < 2; d++)
- {
- g_free (table_data->dimensions[d].spacings);
- table_data->dimensions[d].spacings = NULL;
- }
-
- goo_canvas_table_free_layout_data (table_data);
-}
-
-
-static void
-goo_canvas_table_init (GooCanvasTable *table)
-{
- table->table_data = g_slice_new0 (GooCanvasTableData);
- goo_canvas_table_init_data (table->table_data);
-}
-
-
/**
* goo_canvas_table_new:
* @parent: the parent item, or %NULL. If a parent is specified, it will assume
@@ -547,66 +520,68 @@ goo_canvas_table_new (GooCanvasItem *parent,
static void
goo_canvas_table_finalize (GObject *object)
{
- GooCanvasItemSimple *simple = (GooCanvasItemSimple*) object;
GooCanvasTable *table = (GooCanvasTable*) object;
+ gint d;
- /* Free our data if we didn't have a model. (If we had a model it would
- have been reset in dispose() and simple_data will be NULL.) */
- if (simple->simple_data)
+ g_array_free (table->children, TRUE);
+
+ for (d = 0; d < 2; d++)
{
- goo_canvas_table_free_data (table->table_data);
- g_slice_free (GooCanvasTableData, table->table_data);
+ g_free (table->dimensions[d].spacings);
+ table->dimensions[d].spacings = NULL;
}
- table->table_data = NULL;
+
+ goo_canvas_table_free_layout_data (table);
G_OBJECT_CLASS (goo_canvas_table_parent_class)->finalize (object);
}
static void
-goo_canvas_table_get_common_property (GObject *object,
- GooCanvasTableData *table_data,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
+goo_canvas_table_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
{
+ GooCanvasTable *table = (GooCanvasTable*) object;
+
switch (prop_id)
{
case PROP_X:
- g_value_set_double (value, table_data->layout_data->x);
+ g_value_set_double (value, table->layout_data->x);
break;
case PROP_Y:
- g_value_set_double (value, table_data->layout_data->y);
+ g_value_set_double (value, table->layout_data->y);
break;
case PROP_WIDTH:
- g_value_set_double (value, table_data->width);
+ g_value_set_double (value, table->width);
break;
case PROP_HEIGHT:
- g_value_set_double (value, table_data->height);
+ g_value_set_double (value, table->height);
break;
case PROP_ROW_SPACING:
- g_value_set_double (value, table_data->dimensions[VERT].default_spacing);
+ g_value_set_double (value, table->dimensions[VERT].default_spacing);
break;
case PROP_COLUMN_SPACING:
- g_value_set_double (value, table_data->dimensions[HORZ].default_spacing);
+ g_value_set_double (value, table->dimensions[HORZ].default_spacing);
break;
case PROP_HOMOGENEOUS_ROWS:
- g_value_set_boolean (value, table_data->dimensions[VERT].homogeneous);
+ g_value_set_boolean (value, table->dimensions[VERT].homogeneous);
break;
case PROP_HOMOGENEOUS_COLUMNS:
- g_value_set_boolean (value, table_data->dimensions[HORZ].homogeneous);
+ g_value_set_boolean (value, table->dimensions[HORZ].homogeneous);
break;
case PROP_X_BORDER_SPACING:
- g_value_set_double (value, table_data->layout_data->border_spacing[HORZ]);
+ g_value_set_double (value, table->layout_data->border_spacing[HORZ]);
break;
case PROP_Y_BORDER_SPACING:
- g_value_set_double (value, table_data->layout_data->border_spacing[VERT]);
+ g_value_set_double (value, table->layout_data->border_spacing[VERT]);
break;
case PROP_HORZ_GRID_LINE_WIDTH:
- g_value_set_double (value, table_data->layout_data->prop_grid_line_width[HORZ]);
+ g_value_set_double (value, table->layout_data->prop_grid_line_width[HORZ]);
break;
case PROP_VERT_GRID_LINE_WIDTH:
- g_value_set_double (value, table_data->layout_data->prop_grid_line_width[VERT]);
+ g_value_set_double (value, table->layout_data->prop_grid_line_width[VERT]);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -616,140 +591,104 @@ goo_canvas_table_get_common_property (GObject *object,
static void
-goo_canvas_table_get_property (GObject *object,
+goo_canvas_table_set_property (GObject *object,
guint prop_id,
- GValue *value,
+ const GValue *value,
GParamSpec *pspec)
{
+ GooCanvasItemSimple *simple = (GooCanvasItemSimple*) object;
GooCanvasTable *table = (GooCanvasTable*) object;
- goo_canvas_table_get_common_property (object, table->table_data,
- prop_id, value, pspec);
-}
-
-
-static gboolean
-goo_canvas_table_set_common_property (GObject *object,
- GooCanvasTableData *table_data,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- gboolean recompute_bounds = TRUE;
-
switch (prop_id)
{
case PROP_X:
- table_data->layout_data->x = g_value_get_double (value);
+ table->layout_data->x = g_value_get_double (value);
break;
case PROP_Y:
- table_data->layout_data->y = g_value_get_double (value);
+ table->layout_data->y = g_value_get_double (value);
break;
case PROP_WIDTH:
- table_data->width = g_value_get_double (value);
+ table->width = g_value_get_double (value);
break;
case PROP_HEIGHT:
- table_data->height = g_value_get_double (value);
+ table->height = g_value_get_double (value);
break;
case PROP_ROW_SPACING:
- table_data->dimensions[VERT].default_spacing = g_value_get_double (value);
+ table->dimensions[VERT].default_spacing = g_value_get_double (value);
break;
case PROP_COLUMN_SPACING:
- table_data->dimensions[HORZ].default_spacing = g_value_get_double (value);
+ table->dimensions[HORZ].default_spacing = g_value_get_double (value);
break;
case PROP_HOMOGENEOUS_ROWS:
- table_data->dimensions[VERT].homogeneous = g_value_get_boolean (value);
+ table->dimensions[VERT].homogeneous = g_value_get_boolean (value);
break;
case PROP_HOMOGENEOUS_COLUMNS:
- table_data->dimensions[HORZ].homogeneous = g_value_get_boolean (value);
+ table->dimensions[HORZ].homogeneous = g_value_get_boolean (value);
break;
case PROP_X_BORDER_SPACING:
- table_data->layout_data->border_spacing[HORZ] = g_value_get_double (value);
+ table->layout_data->border_spacing[HORZ] = g_value_get_double (value);
break;
case PROP_Y_BORDER_SPACING:
- table_data->layout_data->border_spacing[VERT] = g_value_get_double (value);
+ table->layout_data->border_spacing[VERT] = g_value_get_double (value);
break;
case PROP_HORZ_GRID_LINE_WIDTH:
- table_data->layout_data->prop_grid_line_width[HORZ] = g_value_get_double (value);
+ table->layout_data->prop_grid_line_width[HORZ] = g_value_get_double (value);
break;
case PROP_VERT_GRID_LINE_WIDTH:
- table_data->layout_data->prop_grid_line_width[VERT] = g_value_get_double (value);
+ table->layout_data->prop_grid_line_width[VERT] = g_value_get_double (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
- return recompute_bounds;
-}
-
-
-static void
-goo_canvas_table_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- GooCanvasItemSimple *simple = (GooCanvasItemSimple*) object;
- GooCanvasTable *table = (GooCanvasTable*) object;
- 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;
- }
-
- recompute_bounds = goo_canvas_table_set_common_property (object,
- table->table_data,
- prop_id, value,
- pspec);
- goo_canvas_item_simple_changed (simple, recompute_bounds);
+ goo_canvas_item_simple_changed (simple, TRUE);
}
static void
-goo_canvas_table_update_dimensions (GooCanvasTableData *table_data,
+goo_canvas_table_update_dimensions (GooCanvasTable *table,
GooCanvasTableChild *table_child)
{
GooCanvasTableLayoutData *layout_data;
gint d, size[2], i;
- layout_data = table_data->layout_data;
+ layout_data = table->layout_data;
size[0] = table_child->start[0] + table_child->size[0];
size[1] = table_child->start[1] + table_child->size[1];
for (d = 0; d < 2; d++)
{
- if (size[d] > table_data->dimensions[d].size)
+ if (size[d] > table->dimensions[d].size)
{
/* Resize the spacings array and the layout data array. */
- table_data->dimensions[d].spacings = g_realloc (table_data->dimensions[d].spacings, size[d] * sizeof (gdouble));
+ table->dimensions[d].spacings = g_realloc (table->dimensions[d].spacings, size[d] * sizeof (gdouble));
layout_data->dldata[d] = g_renew (GooCanvasTableDimensionLayoutData, layout_data->dldata[d], size[d]);
/* Initialize new spacings to -1.0 so the default is used, and
set the new grid_line_visibility arrays to NULL. */
- for (i = table_data->dimensions[d].size; i < size[d]; i++)
+ for (i = table->dimensions[d].size; i < size[d]; i++)
{
- table_data->dimensions[d].spacings[i] = -1.0;
+ table->dimensions[d].spacings[i] = -1.0;
layout_data->dldata[d][i].grid_line_visibility = NULL;
}
}
}
- table_data->dimensions[0].size = MAX (size[0], table_data->dimensions[0].size);
- table_data->dimensions[1].size = MAX (size[1], table_data->dimensions[1].size);
+ table->dimensions[0].size = MAX (size[0], table->dimensions[0].size);
+ table->dimensions[1].size = MAX (size[1], table->dimensions[1].size);
}
+
/* Sets or unsets grid line visibility for a given child */
static void
-goo_canvas_update_grid_line_visibility (GooCanvasTableData *table_data)
+goo_canvas_update_grid_line_visibility (GooCanvasTable *table)
{
GooCanvasTableLayoutData *layout_data;
GooCanvasTableChild *table_child;
guint32 grid_line_size;
gint d, d2, child_num, i, j;
- layout_data = table_data->layout_data;
+ layout_data = table->layout_data;
for (d = 0; d < 2; d++)
{
/* This is the opposite dimension. */
@@ -760,11 +699,11 @@ goo_canvas_update_grid_line_visibility (GooCanvasTableData *table_data)
we store the grid lines (right to) a particular column for each row.
Therefore we need one bit for each row. This is also why this depends
on dimensions[1-d] instead of dimensions[d]. */
- grid_line_size = ((table_data->dimensions[d2].size + 31) / 32);
+ grid_line_size = ((table->dimensions[d2].size + 31) / 32);
/* Allocate or reallocate the grid_line_visibility arrays and initialize
all grid lines to visible (by setting to the arrays to all 0xFF). */
- for (i = 0; i + 1 < table_data->dimensions[d].size; i++)
+ for (i = 0; i + 1 < table->dimensions[d].size; i++)
{
layout_data->dldata[d][i].grid_line_visibility
= g_realloc (layout_data->dldata[d][i].grid_line_visibility,
@@ -774,9 +713,9 @@ goo_canvas_update_grid_line_visibility (GooCanvasTableData *table_data)
}
/* Remove lines for each child spanning multiple rows/colmuns */
- for (child_num = 0; child_num < table_data->children->len; child_num++)
+ for (child_num = 0; child_num < table->children->len; child_num++)
{
- table_child = &g_array_index (table_data->children,
+ table_child = &g_array_index (table->children,
GooCanvasTableChild, child_num);
/* Foreach cell the child is spanning */
@@ -797,7 +736,7 @@ goo_canvas_update_grid_line_visibility (GooCanvasTableData *table_data)
}
static void
-goo_canvas_table_add_child_internal (GooCanvasTableData *table_data,
+goo_canvas_table_add_child_internal (GooCanvasTable *table,
gint position)
{
GooCanvasTableChild table_child;
@@ -818,10 +757,10 @@ goo_canvas_table_add_child_internal (GooCanvasTableData *table_data,
}
if (position < 0)
- position = table_data->children->len;
- g_array_insert_val (table_data->children, position, table_child);
+ position = table->children->len;
+ g_array_insert_val (table->children, position, table_child);
- goo_canvas_table_update_dimensions (table_data, &table_child);
+ goo_canvas_table_update_dimensions (table, &table_child);
}
@@ -830,11 +769,9 @@ goo_canvas_table_add_child (GooCanvasItem *item,
GooCanvasItem *child,
gint position)
{
- GooCanvasItemSimple *simple = (GooCanvasItemSimple*) item;
GooCanvasTable *table = (GooCanvasTable*) item;
- if (!simple->model)
- goo_canvas_table_add_child_internal (table->table_data, position);
+ goo_canvas_table_add_child_internal (table, position);
/* Let the parent GooCanvasGroup code do the rest. */
goo_canvas_table_parent_iface->add_child (item, child, position);
@@ -842,14 +779,14 @@ goo_canvas_table_add_child (GooCanvasItem *item,
static void
-goo_canvas_table_move_child_internal (GooCanvasTableData *table_data,
+goo_canvas_table_move_child_internal (GooCanvasTable *table,
gint old_position,
gint new_position)
{
GooCanvasTableChild *table_child, tmp_child;
/* Copy the child temporarily. */
- table_child = &g_array_index (table_data->children, GooCanvasTableChild,
+ table_child = &g_array_index (table->children, GooCanvasTableChild,
old_position);
tmp_child = *table_child;
@@ -858,22 +795,22 @@ goo_canvas_table_move_child_internal (GooCanvasTableData *table_data,
{
/* Move the items down one place. */
g_memmove (table_child,
- &g_array_index (table_data->children, GooCanvasTableChild,
+ &g_array_index (table->children, GooCanvasTableChild,
old_position + 1),
sizeof (GooCanvasTableChild) * (new_position - old_position));
}
else
{
/* Move the items up one place. */
- g_memmove (&g_array_index (table_data->children, GooCanvasTableChild,
+ g_memmove (&g_array_index (table->children, GooCanvasTableChild,
new_position + 1),
- &g_array_index (table_data->children, GooCanvasTableChild,
+ &g_array_index (table->children, GooCanvasTableChild,
new_position),
sizeof (GooCanvasTableChild) * (old_position - new_position));
}
/* Copy the child into its new position. */
- table_child = &g_array_index (table_data->children, GooCanvasTableChild,
+ table_child = &g_array_index (table->children, GooCanvasTableChild,
new_position);
*table_child = tmp_child;
}
@@ -884,12 +821,10 @@ goo_canvas_table_move_child (GooCanvasItem *item,
gint old_position,
gint new_position)
{
- GooCanvasItemSimple *simple = (GooCanvasItemSimple*) item;
GooCanvasTable *table = (GooCanvasTable*) item;
- if (!simple->model)
- goo_canvas_table_move_child_internal (table->table_data, old_position,
- new_position);
+ goo_canvas_table_move_child_internal (table, old_position,
+ new_position);
/* Let the parent GooCanvasGroup code do the rest. */
goo_canvas_table_parent_iface->move_child (item, old_position, new_position);
@@ -900,14 +835,12 @@ static void
goo_canvas_table_remove_child (GooCanvasItem *item,
gint child_num)
{
- GooCanvasItemSimple *simple = (GooCanvasItemSimple*) item;
GooCanvasGroup *group = (GooCanvasGroup*) item;
GooCanvasTable *table = (GooCanvasTable*) item;
g_return_if_fail (child_num < group->items->len);
- if (!simple->model)
- g_array_remove_index (table->table_data->children, child_num);
+ g_array_remove_index (table->children, child_num);
/* Let the parent GooCanvasGroup code do the rest. */
goo_canvas_table_parent_iface->remove_child (item, child_num);
@@ -995,7 +928,7 @@ goo_canvas_table_get_child_property (GooCanvasItem *item,
{
if (group->items->pdata[child_num] == child)
{
- table_child = &g_array_index (table->table_data->children,
+ table_child = &g_array_index (table->children,
GooCanvasTableChild, child_num);
goo_canvas_table_get_common_child_property ((GObject*) table,
table_child,
@@ -1009,7 +942,7 @@ goo_canvas_table_get_child_property (GooCanvasItem *item,
static void
goo_canvas_table_set_common_child_property (GObject *object,
- GooCanvasTableData *table_data,
+ GooCanvasTable *table,
GooCanvasTableChild *table_child,
guint property_id,
const GValue *value,
@@ -1092,7 +1025,7 @@ goo_canvas_table_set_common_child_property (GObject *object,
break;
}
- goo_canvas_table_update_dimensions (table_data, table_child);
+ goo_canvas_table_update_dimensions (table, table_child);
}
@@ -1113,10 +1046,10 @@ goo_canvas_table_set_child_property (GooCanvasItem *item,
{
if (group->items->pdata[child_num] == child)
{
- table_child = &g_array_index (table->table_data->children,
+ table_child = &g_array_index (table->children,
GooCanvasTableChild, child_num);
goo_canvas_table_set_common_child_property ((GObject*) table,
- table->table_data,
+ table,
table_child,
property_id, value,
pspec);
@@ -1128,49 +1061,26 @@ goo_canvas_table_set_child_property (GooCanvasItem *item,
}
-static void
-goo_canvas_table_set_model (GooCanvasItem *item,
- GooCanvasItemModel *model)
-{
- GooCanvasItemSimple *simple = (GooCanvasItemSimple*) item;
- GooCanvasTable *table = (GooCanvasTable*) item;
- GooCanvasTableModel *tmodel = (GooCanvasTableModel*) model;
-
- /* If our table_data was allocated, free it. */
- if (!simple->model)
- {
- goo_canvas_table_free_data (table->table_data);
- g_slice_free (GooCanvasTableData, table->table_data);
- }
-
- /* Now use the new model's table_data instead. */
- table->table_data = &tmodel->table_data;
-
- /* Let the parent GooCanvasGroup code do the rest. */
- goo_canvas_table_parent_iface->set_model (item, model);
-}
-
-
/*
* Size requisition/allocation code.
*/
static void
-goo_canvas_table_free_layout_data (GooCanvasTableData *table_data)
+goo_canvas_table_free_layout_data (GooCanvasTable *table)
{
gint i;
- if (table_data->layout_data)
+ if (table->layout_data)
{
- for (i = 0; i < table_data->dimensions[VERT].size; i++)
- g_free (table_data->layout_data->dldata[VERT][i].grid_line_visibility);
- for (i = 0; i < table_data->dimensions[HORZ].size; i++)
- g_free (table_data->layout_data->dldata[HORZ][i].grid_line_visibility);
- g_free (table_data->layout_data->dldata[HORZ]);
- g_free (table_data->layout_data->dldata[VERT]);
- g_free (table_data->layout_data->children);
- g_slice_free (GooCanvasTableLayoutData, table_data->layout_data);
- table_data->layout_data = NULL;
+ for (i = 0; i < table->dimensions[VERT].size; i++)
+ g_free (table->layout_data->dldata[VERT][i].grid_line_visibility);
+ for (i = 0; i < table->dimensions[HORZ].size; i++)
+ g_free (table->layout_data->dldata[HORZ][i].grid_line_visibility);
+ g_free (table->layout_data->dldata[HORZ]);
+ g_free (table->layout_data->dldata[VERT]);
+ g_free (table->layout_data->children);
+ g_slice_free (GooCanvasTableLayoutData, table->layout_data);
+ table->layout_data = NULL;
}
}
@@ -1180,14 +1090,13 @@ static void
goo_canvas_table_init_layout_data (GooCanvasTable *table)
{
GooCanvasItemSimple *simple = (GooCanvasItemSimple*) table;
- GooCanvasTableData *table_data = table->table_data;
GooCanvasTableDimension *dimension;
- GooCanvasTableLayoutData *layout_data = table_data->layout_data;
+ GooCanvasTableLayoutData *layout_data = table->layout_data;
GooCanvasTableDimensionLayoutData *dldata;
gint d, i;
layout_data->children = g_new (GooCanvasTableChildLayoutData,
- table_data->children->len);
+ table->children->len);
layout_data->last_width = -1;
/* If we are not yet added to a canvas, integer layout is irrelevant anyway.
@@ -1197,7 +1106,7 @@ goo_canvas_table_init_layout_data (GooCanvasTable *table)
layout_data->integer_layout = simple->canvas->integer_layout;
else
layout_data->integer_layout = FALSE;
- layout_data->border_width = table_data->border_width;
+ layout_data->border_width = table->border_width;
if (layout_data->integer_layout)
layout_data->border_width = floor (layout_data->border_width + 0.5);
@@ -1211,7 +1120,7 @@ goo_canvas_table_init_layout_data (GooCanvasTable *table)
for (d = 0; d < 2; d++)
{
- dimension = &table_data->dimensions[d];
+ dimension = &table->dimensions[d];
/* Already allocated in goo_canvas_table_update_dimensions() */
/*layout_data->dldata[d] = g_renew (GooCanvasTableDimensionLayoutData,
@@ -1243,7 +1152,7 @@ goo_canvas_table_init_layout_data (GooCanvasTable *table)
}
/* Update grid line visibility */
- goo_canvas_update_grid_line_visibility (table_data);
+ goo_canvas_update_grid_line_visibility (table);
}
@@ -1257,8 +1166,7 @@ goo_canvas_table_size_request_init (GooCanvasTable *table,
cairo_t *cr)
{
GooCanvasGroup *group = (GooCanvasGroup*) table;
- GooCanvasTableData *table_data = table->table_data;
- GooCanvasTableLayoutData *layout_data = table_data->layout_data;
+ GooCanvasTableLayoutData *layout_data = table->layout_data;
GooCanvasTableDimension *dimension;
GooCanvasTableDimensionLayoutData *dldata;
GooCanvasTableChild *child;
@@ -1268,9 +1176,9 @@ goo_canvas_table_size_request_init (GooCanvasTable *table,
gint i, j, d, start, end;
guint8 flags;
- for (i = 0; i < table_data->children->len; i++)
+ for (i = 0; i < table->children->len; i++)
{
- child = &g_array_index (table_data->children, GooCanvasTableChild, i);
+ child = &g_array_index (table->children, GooCanvasTableChild, i);
child_item = group->items->pdata[i];
/* Children will return FALSE if they don't need space allocated. */
@@ -1327,9 +1235,9 @@ goo_canvas_table_size_request_init (GooCanvasTable *table,
}
/* Now handle children that span more than one row or column. */
- for (i = 0; i < table_data->children->len; i++)
+ for (i = 0; i < table->children->len; i++)
{
- child = &g_array_index (table_data->children, GooCanvasTableChild, i);
+ child = &g_array_index (table->children, GooCanvasTableChild, i);
if (layout_data->children[i].requested_size[HORZ] < 0.0)
continue;
@@ -1378,7 +1286,7 @@ goo_canvas_table_size_request_init (GooCanvasTable *table,
changed after this point. */
for (d = 0; d < 2; d++)
{
- dimension = &table_data->dimensions[d];
+ dimension = &table->dimensions[d];
dldata = layout_data->dldata[d];
for (i = 0; i < dimension->size; i++)
@@ -1407,9 +1315,8 @@ static void
goo_canvas_table_size_request_pass1 (GooCanvasTable *table,
gint d)
{
- GooCanvasTableData *table_data = table->table_data;
- GooCanvasTableDimension *dimension = &table_data->dimensions[d];
- GooCanvasTableLayoutData *layout_data = table_data->layout_data;
+ GooCanvasTableDimension *dimension = &table->dimensions[d];
+ GooCanvasTableLayoutData *layout_data = table->layout_data;
GooCanvasTableDimensionLayoutData *dldata = layout_data->dldata[d];
GooCanvasTableChild *child;
gdouble requested_size;
@@ -1418,9 +1325,9 @@ goo_canvas_table_size_request_pass1 (GooCanvasTable *table,
for (i = 0; i < dimension->size; i++)
dldata[i].requisition = 0.0;
- for (i = 0; i < table_data->children->len; i++)
+ for (i = 0; i < table->children->len; i++)
{
- child = &g_array_index (table_data->children, GooCanvasTableChild, i);
+ child = &g_array_index (table->children, GooCanvasTableChild, i);
requested_size = layout_data->children[i].requested_size[d];
@@ -1445,20 +1352,19 @@ static void
goo_canvas_table_size_request_pass2 (GooCanvasTable *table,
gint d)
{
- GooCanvasTableData *table_data = table->table_data;
- GooCanvasTableLayoutData *layout_data = table_data->layout_data;
+ GooCanvasTableLayoutData *layout_data = table->layout_data;
GooCanvasTableDimensionLayoutData *dldata = layout_data->dldata[d];
gdouble max_size = 0.0;
gint i;
- if (table_data->dimensions[d].homogeneous)
+ if (table->dimensions[d].homogeneous)
{
/* Calculate the maximum row or column size. */
- for (i = 0; i < table_data->dimensions[d].size; i++)
+ for (i = 0; i < table->dimensions[d].size; i++)
max_size = MAX (max_size, dldata[i].requisition);
/* Use the maximum size for all rows or columns. */
- for (i = 0; i < table_data->dimensions[d].size; i++)
+ for (i = 0; i < table->dimensions[d].size; i++)
dldata[i].requisition = max_size;
}
}
@@ -1471,15 +1377,14 @@ static void
goo_canvas_table_size_request_pass3 (GooCanvasTable *table,
gint d)
{
- GooCanvasTableData *table_data = table->table_data;
- GooCanvasTableLayoutData *layout_data = table_data->layout_data;
+ GooCanvasTableLayoutData *layout_data = table->layout_data;
GooCanvasTableDimensionLayoutData *dldata;
GooCanvasTableChild *child;
gint i, j;
- for (i = 0; i < table_data->children->len; i++)
+ for (i = 0; i < table->children->len; i++)
{
- child = &g_array_index (table_data->children, GooCanvasTableChild, i);
+ child = &g_array_index (table->children, GooCanvasTableChild, i);
if (layout_data->children[i].requested_size[HORZ] <= 0.0)
continue;
@@ -1559,9 +1464,8 @@ static void
goo_canvas_table_size_allocate_init (GooCanvasTable *table,
gint d)
{
- GooCanvasTableData *table_data = table->table_data;
- GooCanvasTableLayoutData *layout_data = table_data->layout_data;
- GooCanvasTableDimension *dimension = &table_data->dimensions[d];
+ GooCanvasTableLayoutData *layout_data = table->layout_data;
+ GooCanvasTableDimension *dimension = &table->dimensions[d];
GooCanvasTableDimensionLayoutData *dldata = layout_data->dldata[d];
gint i;
@@ -1576,8 +1480,7 @@ static void
goo_canvas_table_size_allocate_pass1 (GooCanvasTable *table,
gint d)
{
- GooCanvasTableData *table_data = table->table_data;
- GooCanvasTableLayoutData *layout_data = table_data->layout_data;
+ GooCanvasTableLayoutData *layout_data = table->layout_data;
GooCanvasTableDimension *dimension;
GooCanvasTableDimensionLayoutData *dldata;
gdouble total_size, size_to_allocate, natural_size, extra, old_extra;
@@ -1587,7 +1490,7 @@ goo_canvas_table_size_allocate_pass1 (GooCanvasTable *table,
* then we have to expand any expandable rows and columns
* to fill in the extra space.
*/
- dimension = &table_data->dimensions[d];
+ dimension = &table->dimensions[d];
dldata = layout_data->dldata[d];
natural_size = 0;
@@ -1626,7 +1529,7 @@ goo_canvas_table_size_allocate_pass1 (GooCanvasTable *table,
the children expand, or if there are no children, or if we were
allocated less space than we requested and any children shrink.
If so, we divide up all the allocated space. */
- if (nexpand || table_data->children->len == 0
+ if (nexpand || table->children->len == 0
|| (natural_size > total_size && nshrink))
{
size_to_allocate = total_size;
@@ -1726,14 +1629,13 @@ static void
goo_canvas_table_size_allocate_pass2 (GooCanvasTable *table,
gint d)
{
- GooCanvasTableData *table_data = table->table_data;
- GooCanvasTableLayoutData *layout_data = table_data->layout_data;
+ GooCanvasTableLayoutData *layout_data = table->layout_data;
GooCanvasTableDimension *dimension;
GooCanvasTableDimensionLayoutData *dldata;
gdouble pos;
gint i;
- dimension = &table_data->dimensions[d];
+ dimension = &table->dimensions[d];
dldata = layout_data->dldata[d];
pos = layout_data->border_width + layout_data->border_spacing[d] + layout_data->grid_line_width[1-d];
@@ -1762,8 +1664,7 @@ goo_canvas_table_size_allocate_pass3 (GooCanvasTable *table,
{
GooCanvasItemSimple *simple = (GooCanvasItemSimple*) table;
GooCanvasGroup *group = (GooCanvasGroup*) table;
- GooCanvasTableData *table_data = table->table_data;
- GooCanvasTableLayoutData *layout_data = table_data->layout_data;
+ GooCanvasTableLayoutData *layout_data = table->layout_data;
GooCanvasTableDimensionLayoutData *rows = layout_data->dldata[VERT];
GooCanvasTableDimensionLayoutData *columns = layout_data->dldata[HORZ];
GooCanvasTableChild *child;
@@ -1779,9 +1680,9 @@ goo_canvas_table_size_allocate_pass3 (GooCanvasTable *table,
if (simple->canvas)
direction = gtk_widget_get_direction (GTK_WIDGET (simple->canvas));
- for (i = 0; i < table_data->children->len; i++)
+ for (i = 0; i < table->children->len; i++)
{
- child = &g_array_index (table_data->children, GooCanvasTableChild, i);
+ child = &g_array_index (table->children, GooCanvasTableChild, i);
child_item = group->items->pdata[i];
child_data = &layout_data->children[i];
@@ -1862,8 +1763,7 @@ goo_canvas_table_update_requested_heights (GooCanvasItem *item,
{
GooCanvasGroup *group = (GooCanvasGroup*) item;
GooCanvasTable *table = (GooCanvasTable*) item;
- GooCanvasTableData *table_data = table->table_data;
- GooCanvasTableLayoutData *layout_data = table_data->layout_data;
+ GooCanvasTableLayoutData *layout_data = table->layout_data;
GooCanvasTableDimensionLayoutData *rows = layout_data->dldata[VERT];
GooCanvasTableDimensionLayoutData *columns = layout_data->dldata[HORZ];
GooCanvasTableChild *child;
@@ -1884,9 +1784,9 @@ goo_canvas_table_update_requested_heights (GooCanvasItem *item,
goo_canvas_table_size_allocate_pass2 (table, HORZ);
/* Now check if any child changes height based on their allocated width. */
- for (i = 0; i < table_data->children->len; i++)
+ for (i = 0; i < table->children->len; i++)
{
- child = &g_array_index (table_data->children, GooCanvasTableChild, i);
+ child = &g_array_index (table->children, GooCanvasTableChild, i);
child_item = group->items->pdata[i];
child_data = &layout_data->children[i];
@@ -1918,7 +1818,7 @@ goo_canvas_table_update_requested_heights (GooCanvasItem *item,
goo_canvas_table_size_request_pass3 (table, VERT);
goo_canvas_table_size_request_pass2 (table, VERT);
- end = table_data->dimensions[VERT].size - 1;
+ end = table->dimensions[VERT].size - 1;
for (row = 0; row <= end; row++)
{
height += rows[row].requisition;
@@ -1938,16 +1838,14 @@ goo_canvas_table_get_requested_area (GooCanvasItem *item,
GooCanvasBounds *requested_area)
{
GooCanvasItemSimple *simple = (GooCanvasItemSimple*) item;
- GooCanvasItemSimpleData *simple_data = simple->simple_data;
GooCanvasTable *table = (GooCanvasTable*) item;
- GooCanvasTableData *table_data = table->table_data;
- GooCanvasTableLayoutData *layout_data = table_data->layout_data;
+ GooCanvasTableLayoutData *layout_data = table->layout_data;
GooCanvasTableDimensionLayoutData *rows, *columns;
gdouble width = 0.0, height = 0.0;
gint row, column, end;
/* Request a redraw of the existing bounds */
- goo_canvas_request_item_redraw (simple->canvas, &simple->bounds, simple_data->is_static);
+ goo_canvas_request_item_redraw (simple->canvas, &simple->bounds, simple->is_static);
/* We reset the bounds to 0, just in case we are hidden or aren't allocated
any area. */
@@ -1958,12 +1856,12 @@ goo_canvas_table_get_requested_area (GooCanvasItem *item,
goo_canvas_item_simple_check_style (simple);
- if (simple_data->visibility == GOO_CANVAS_ITEM_HIDDEN)
+ if (simple->visibility == GOO_CANVAS_ITEM_HIDDEN)
return FALSE;
cairo_save (cr);
- if (simple_data->transform)
- cairo_transform (cr, simple_data->transform);
+ if (simple->transform)
+ cairo_transform (cr, simple->transform);
cairo_translate (cr, layout_data->x, layout_data->y);
@@ -1981,7 +1879,7 @@ goo_canvas_table_get_requested_area (GooCanvasItem *item,
rows = layout_data->dldata[VERT];
columns = layout_data->dldata[HORZ];
- end = table_data->dimensions[HORZ].size - 1;
+ end = table->dimensions[HORZ].size - 1;
for (column = 0; column <= end; column++)
{
width += columns[column].requisition;
@@ -1994,8 +1892,8 @@ goo_canvas_table_get_requested_area (GooCanvasItem *item,
layout_data->natural_size[HORZ] = width;
/* If the width has been set, that overrides the calculations. */
- if (table_data->width > 0.0)
- width = table_data->width;
+ if (table->width > 0.0)
+ width = table->width;
layout_data->requested_size[HORZ] = width;
layout_data->allocated_size[HORZ] = width;
@@ -2008,7 +1906,7 @@ goo_canvas_table_get_requested_area (GooCanvasItem *item,
goo_canvas_table_size_request_pass3 (table, VERT);
goo_canvas_table_size_request_pass2 (table, VERT);
- end = table_data->dimensions[VERT].size - 1;
+ end = table->dimensions[VERT].size - 1;
for (row = 0; row <= end; row++)
{
height += rows[row].requisition;
@@ -2021,8 +1919,8 @@ goo_canvas_table_get_requested_area (GooCanvasItem *item,
layout_data->natural_size[VERT] = height;
/* If the height has been set, that overrides the calculations. */
- if (table_data->height > 0.0)
- height = table_data->height;
+ if (table->height > 0.0)
+ height = table->height;
layout_data->requested_size[VERT] = height;
@@ -2046,28 +1944,26 @@ goo_canvas_table_get_requested_height (GooCanvasItem *item,
gdouble width)
{
GooCanvasItemSimple *simple = (GooCanvasItemSimple*) item;
- GooCanvasItemSimpleData *simple_data = simple->simple_data;
GooCanvasTable *table = (GooCanvasTable*) item;
- GooCanvasTableData *table_data = table->table_data;
- GooCanvasTableLayoutData *layout_data = table_data->layout_data;
+ GooCanvasTableLayoutData *layout_data = table->layout_data;
gdouble allocated_width = width, height;
/* If we have a transformation besides a simple scale & translation, just
return -1 as we can't adjust the height in that case. */
- if (simple_data->transform && (simple_data->transform->xy != 0.0
- || simple_data->transform->yx != 0.0))
+ if (simple->transform && (simple->transform->xy != 0.0
+ || simple->transform->yx != 0.0))
return -1;
cairo_save (cr);
- if (simple_data->transform)
- cairo_transform (cr, simple_data->transform);
+ if (simple->transform)
+ cairo_transform (cr, simple->transform);
cairo_translate (cr, layout_data->x, layout_data->y);
/* Convert the width from the parent's coordinate space. Note that we only
need to support a simple scale operation here. */
- if (simple_data->transform)
- allocated_width /= simple_data->transform->xx;
+ if (simple->transform)
+ allocated_width /= simple->transform->xx;
layout_data->allocated_size[HORZ] = allocated_width;
if (layout_data->integer_layout)
@@ -2080,8 +1976,8 @@ goo_canvas_table_get_requested_height (GooCanvasItem *item,
/* Convert to the parent's coordinate space. As above, we only need to
support a simple scale operation here. */
height = layout_data->natural_size[VERT];
- if (simple_data->transform)
- height *= simple_data->transform->yy;
+ if (simple->transform)
+ height *= simple->transform->yy;
/* Return the new requested height of the table. */
return height;
@@ -2097,10 +1993,8 @@ goo_canvas_table_allocate_area (GooCanvasItem *item,
gdouble y_offset)
{
GooCanvasItemSimple *simple = (GooCanvasItemSimple*) item;
- GooCanvasItemSimpleData *simple_data = simple->simple_data;
GooCanvasTable *table = (GooCanvasTable*) item;
- GooCanvasTableData *table_data = table->table_data;
- GooCanvasTableLayoutData *layout_data = table_data->layout_data;
+ GooCanvasTableLayoutData *layout_data = table->layout_data;
gdouble requested_width, requested_height, allocated_width, allocated_height;
gdouble width_proportion, height_proportion, min_proportion;
@@ -2115,8 +2009,8 @@ goo_canvas_table_allocate_area (GooCanvasItem *item,
/* If the table is rotated we have to scale it to make sure it fits in the
allocated area. */
- if (simple_data->transform && (simple_data->transform->xy != 0.0
- || simple_data->transform->yx != 0.0))
+ if (simple->transform && (simple->transform->xy != 0.0
+ || simple->transform->yx != 0.0))
{
/* Calculate the minimum proportion, which we'll use to scale our
original width & height requests. */
@@ -2145,15 +2039,15 @@ goo_canvas_table_allocate_area (GooCanvasItem *item,
cairo_save (cr);
cairo_translate (cr, -(allocated_area->x1 - requested_area->x1),
-(allocated_area->y1 - requested_area->y1));
- if (simple_data->transform)
- cairo_transform (cr, simple_data->transform);
+ if (simple->transform)
+ cairo_transform (cr, simple->transform);
cairo_translate (cr, layout_data->x, layout_data->y);
goo_canvas_table_update_requested_heights (item, cr);
cairo_restore (cr);
cairo_save (cr);
- if (simple_data->transform)
- cairo_transform (cr, simple_data->transform);
+ if (simple->transform)
+ cairo_transform (cr, simple->transform);
cairo_translate (cr, layout_data->x, layout_data->y);
/* Calculate the table's bounds. */
@@ -2175,7 +2069,7 @@ goo_canvas_table_allocate_area (GooCanvasItem *item,
cairo_restore (cr);
- goo_canvas_request_item_redraw (simple->canvas, &simple->bounds, simple_data->is_static);
+ goo_canvas_request_item_redraw (simple->canvas, &simple->bounds, simple->is_static);
}
@@ -2214,17 +2108,15 @@ goo_canvas_table_paint (GooCanvasItem *item,
gdouble scale)
{
GooCanvasItemSimple *simple = (GooCanvasItemSimple*) item;
- GooCanvasItemSimpleData *simple_data = simple->simple_data;
- GooCanvasStyle *style = simple_data->style;
+ GooCanvasStyle *style = simple->style;
GooCanvasGroup *group = (GooCanvasGroup*) item;
GooCanvasTable *table = (GooCanvasTable*) item;
- GooCanvasTableData *table_data = table->table_data;
- GooCanvasTableLayoutData *layout_data = table_data->layout_data;
+ GooCanvasTableLayoutData *layout_data = table->layout_data;
GooCanvasTableDimensionLayoutData *rows = layout_data->dldata[VERT];
GooCanvasTableDimensionLayoutData *columns = layout_data->dldata[HORZ];
gdouble vert_grid_line_width = layout_data->grid_line_width[VERT];
gdouble horz_grid_line_width = layout_data->grid_line_width[HORZ];
- GArray *children = table_data->children;
+ GArray *children = table->children;
GooCanvasTableChild *table_child;
GooCanvasItem *child;
gboolean check_clip = FALSE, clip;
@@ -2241,22 +2133,22 @@ goo_canvas_table_paint (GooCanvasItem *item,
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
- && simple->canvas->scale < simple_data->visibility_threshold))
+ if (simple->visibility <= GOO_CANVAS_ITEM_INVISIBLE
+ || (simple->visibility == GOO_CANVAS_ITEM_VISIBLE_ABOVE_THRESHOLD
+ && simple->canvas->scale < simple->visibility_threshold))
return;
/* Paint all the items in the group. */
cairo_save (cr);
- if (simple_data->transform)
- cairo_transform (cr, simple_data->transform);
+ if (simple->transform)
+ cairo_transform (cr, simple->transform);
cairo_translate (cr, layout_data->x, layout_data->y);
/* Clip with the table's clip path, if it is set. */
- if (simple_data->clip_path_commands)
+ if (simple->clip_path_commands)
{
- goo_canvas_create_path (simple_data->clip_path_commands, cr);
- cairo_set_fill_rule (cr, simple_data->clip_fill_rule);
+ goo_canvas_create_path (simple->clip_path_commands, cr);
+ cairo_set_fill_rule (cr, simple->clip_fill_rule);
cairo_clip (cr);
}
@@ -2322,9 +2214,9 @@ goo_canvas_table_paint (GooCanvasItem *item,
/* Inner lines. Make sure we don't do overlapping drawing operations,
so we could easily draw alpha transparent borders */
- for (i = 0; i + 1 < table_data->dimensions[VERT].size; i++)
+ for (i = 0; i + 1 < table->dimensions[VERT].size; i++)
{
- for (j = 0; j < table_data->dimensions[HORZ].size; j++)
+ for (j = 0; j < table->dimensions[HORZ].size; j++)
{
cur_grid_line_visibility = GOO_CANVAS_TABLE_IS_GRID_LINE_VISIBLE(layout_data->dldata[VERT], i, j);
if (cur_grid_line_visibility)
@@ -2347,7 +2239,7 @@ goo_canvas_table_paint (GooCanvasItem *item,
if (simple->canvas->integer_layout)
half_spacing_after = ceil (half_spacing_after);
- if (j == table_data->dimensions[HORZ].size - 1)
+ if (j == table->dimensions[HORZ].size - 1)
line_end = frame_width - layout_data->border_width - vert_grid_line_width;
else
line_end = columns[j + 1].start - half_spacing_after;
@@ -2382,9 +2274,9 @@ goo_canvas_table_paint (GooCanvasItem *item,
so we could easily draw alpha transparent borders. We need to
take additionally care that we don't cross already drawn
horizontal lines. */
- for (i = 0; i + 1 < table_data->dimensions[HORZ].size; i++)
+ for (i = 0; i + 1 < table->dimensions[HORZ].size; i++)
{
- for (j = 0; j < table_data->dimensions[VERT].size; j++)
+ for (j = 0; j < table->dimensions[VERT].size; j++)
{
cur_grid_line_visibility = GOO_CANVAS_TABLE_IS_GRID_LINE_VISIBLE(layout_data->dldata[HORZ], i, j);
if (cur_grid_line_visibility)
@@ -2415,7 +2307,7 @@ goo_canvas_table_paint (GooCanvasItem *item,
half_spacing_after = ceil (half_spacing_after);
}
- if (j == table_data->dimensions[VERT].size - 1)
+ if (j == table->dimensions[VERT].size - 1)
line_end = frame_height - layout_data->border_width - horz_grid_line_width;
else
/* Don't draw bottom part if already drawn by horizontal grid line */
@@ -2516,14 +2408,12 @@ goo_canvas_table_get_items_at (GooCanvasItem *item,
GList *found_items)
{
GooCanvasItemSimple *simple = (GooCanvasItemSimple*) item;
- GooCanvasItemSimpleData *simple_data = simple->simple_data;
GooCanvasGroup *group = (GooCanvasGroup*) item;
GooCanvasTable *table = (GooCanvasTable*) item;
- GooCanvasTableData *table_data = table->table_data;
- GooCanvasTableLayoutData *layout_data = table_data->layout_data;
+ GooCanvasTableLayoutData *layout_data = table->layout_data;
GooCanvasTableDimensionLayoutData *rows = layout_data->dldata[VERT];
GooCanvasTableDimensionLayoutData *columns = layout_data->dldata[HORZ];
- GArray *children = table_data->children;
+ GArray *children = table->children;
GooCanvasTableChild *table_child;
GooCanvasItem *child;
gboolean visible = parent_visible, check_clip = FALSE;
@@ -2539,30 +2429,30 @@ goo_canvas_table_get_items_at (GooCanvasItem *item,
|| simple->bounds.y1 > y || simple->bounds.y2 < y)
return found_items;
- if (simple_data->visibility <= GOO_CANVAS_ITEM_INVISIBLE
- || (simple_data->visibility == GOO_CANVAS_ITEM_VISIBLE_ABOVE_THRESHOLD
- && simple->canvas->scale < simple_data->visibility_threshold))
+ if (simple->visibility <= GOO_CANVAS_ITEM_INVISIBLE
+ || (simple->visibility == GOO_CANVAS_ITEM_VISIBLE_ABOVE_THRESHOLD
+ && simple->canvas->scale < simple->visibility_threshold))
visible = FALSE;
/* Check if the group should receive events. */
if (is_pointer_event
- && (simple_data->pointer_events == GOO_CANVAS_EVENTS_NONE
- || ((simple_data->pointer_events & GOO_CANVAS_EVENTS_VISIBLE_MASK)
+ && (simple->pointer_events == GOO_CANVAS_EVENTS_NONE
+ || ((simple->pointer_events & GOO_CANVAS_EVENTS_VISIBLE_MASK)
&& !visible)))
return found_items;
cairo_save (cr);
- if (simple_data->transform)
- cairo_transform (cr, simple_data->transform);
+ if (simple->transform)
+ cairo_transform (cr, simple->transform);
cairo_translate (cr, layout_data->x, layout_data->y);
cairo_device_to_user (cr, &user_x, &user_y);
/* If the table has a clip path, check if the point is inside it. */
- if (simple_data->clip_path_commands)
+ if (simple->clip_path_commands)
{
- goo_canvas_create_path (simple_data->clip_path_commands, cr);
- cairo_set_fill_rule (cr, simple_data->clip_fill_rule);
+ goo_canvas_create_path (simple->clip_path_commands, cr);
+ cairo_set_fill_rule (cr, simple->clip_fill_rule);
if (!cairo_in_fill (cr, user_x, user_y))
{
cairo_restore (cr);
@@ -2640,10 +2530,9 @@ goo_canvas_table_get_transform_for_child (GooCanvasItem *item,
gboolean has_transform = FALSE;
gint child_num;
-
- if (simple->simple_data->transform)
+ if (simple->transform)
{
- *transform = *simple->simple_data->transform;
+ *transform = *simple->transform;
has_transform = TRUE;
}
else
@@ -2655,7 +2544,7 @@ goo_canvas_table_get_transform_for_child (GooCanvasItem *item,
{
if (group->items->pdata[child_num] == child)
{
- table_child = &g_array_index (table->table_data->children,
+ table_child = &g_array_index (table->children,
GooCanvasTableChild, child_num);
cairo_matrix_translate (transform, table_child->position[HORZ],
table_child->position[VERT]);
@@ -2684,330 +2573,4 @@ item_interface_init (GooCanvasItemIface *iface)
iface->allocate_area = goo_canvas_table_allocate_area;
iface->paint = goo_canvas_table_paint;
iface->get_items_at = goo_canvas_table_get_items_at;
-
- iface->set_model = goo_canvas_table_set_model;
-}
-
-
-
-/**
- * SECTION:goocanvastablemodel
- * @Title: GooCanvasTableModel
- * @Short_Description: a model for a table container to layout items.
- *
- * #GooCanvasTableModel is a model for a table container used to lay out other
- * canvas items. It is used in a similar way to how the GtkTable widget is used
- * to lay out GTK+ widgets.
- *
- * Item models are added to the table using the normal methods, then
- * goo_canvas_item_model_set_child_properties() is used to specify how each
- * child item is to be positioned within the table (i.e. which row and column
- * it is in, how much padding it should have and whether it should expand or
- * shrink).
- *
- * #GooCanvasTableModel is a subclass of #GooCanvasItemModelSimple and so
- * inherits all of the style properties such as "stroke-color", "fill-color"
- * and "line-width". Setting a style property on a #GooCanvasTableModel will
- * affect all children of the #GooCanvasTableModel (unless the children
- * override the property setting).
- *
- * #GooCanvasTableModel implements the #GooCanvasItemModel interface, so you
- * can use the #GooCanvasItemModel functions such as
- * goo_canvas_item_model_raise() and goo_canvas_item_rotate(), and the
- * properties such as "visibility" and "pointer-events".
- *
- * To create a #GooCanvasTableModel use goo_canvas_table_model_new().
- *
- * To get or set the properties of an existing #GooCanvasTableModel, use
- * g_object_get() and g_object_set().
- */
-
-static GooCanvasItemModelIface *goo_canvas_table_model_parent_iface;
-
-static void item_model_interface_init (GooCanvasItemModelIface *iface);
-static void goo_canvas_table_model_finalize (GObject *object);
-static void goo_canvas_table_model_get_property (GObject *object,
- guint param_id,
- GValue *value,
- GParamSpec *pspec);
-static void goo_canvas_table_model_set_property (GObject *object,
- guint param_id,
- const GValue *value,
- GParamSpec *pspec);
-
-G_DEFINE_TYPE_WITH_CODE (GooCanvasTableModel, goo_canvas_table_model,
- GOO_TYPE_CANVAS_GROUP_MODEL,
- G_IMPLEMENT_INTERFACE (GOO_TYPE_CANVAS_ITEM_MODEL,
- item_model_interface_init))
-
-
-static void
-goo_canvas_table_model_class_init (GooCanvasTableModelClass *klass)
-{
- GObjectClass *gobject_class = (GObjectClass*) klass;
-
- goo_canvas_table_model_parent_iface = g_type_interface_peek (goo_canvas_table_model_parent_class, GOO_TYPE_CANVAS_ITEM_MODEL);
-
- gobject_class->finalize = goo_canvas_table_model_finalize;
-
- gobject_class->get_property = goo_canvas_table_model_get_property;
- gobject_class->set_property = goo_canvas_table_model_set_property;
-
- goo_canvas_table_install_common_properties (gobject_class, goo_canvas_item_model_class_install_child_property);
-}
-
-
-static void
-goo_canvas_table_model_init (GooCanvasTableModel *tmodel)
-{
- goo_canvas_table_init_data (&tmodel->table_data);
-}
-
-
-/**
- * goo_canvas_table_model_new:
- * @parent: the parent model, or %NULL. If a parent is specified, it will
- * assume ownership of the item, and the item will automatically be freed when
- * it is removed from the parent. Otherwise call g_object_unref() to free it.
- * @...: optional pairs of property names and values, and a terminating %NULL.
- *
- * Creates a new table model.
- *
- * <!--PARAMETERS-->
- *
- * Here's an example showing how to create a table with a square, a circle and
- * a triangle in it:
- *
- * <informalexample><programlisting>
- * GooCanvasItemModel *table, *square, *circle, *triangle;
- *
- * table = goo_canvas_table_model_new (root,
- * "row-spacing", 4.0,
- * "column-spacing", 4.0,
- * NULL);
- * goo_canvas_item_model_translate (table, 400, 200);
- *
- * square = goo_canvas_rect_model_new (table, 0.0, 0.0, 50.0, 50.0,
- * "fill-color", "red",
- * NULL);
- * goo_canvas_item_model_set_child_properties (table, square,
- * "row", 0,
- * "column", 0,
- * NULL);
- *
- * circle = goo_canvas_ellipse_model_new (table, 0.0, 0.0, 25.0, 25.0,
- * "fill-color", "blue",
- * NULL);
- * goo_canvas_item_model_set_child_properties (table, circle,
- * "row", 0,
- * "column", 1,
- * NULL);
- *
- * triangle = goo_canvas_polyline_model_new (table, TRUE, 3,
- * 25.0, 0.0, 0.0, 50.0, 50.0, 50.0,
- * "fill-color", "yellow",
- * NULL);
- * goo_canvas_item_model_set_child_properties (table, triangle,
- * "row", 0,
- * "column", 2,
- * NULL);
- * </programlisting></informalexample>
- *
- * Returns: a new table model.
- **/
-GooCanvasItemModel*
-goo_canvas_table_model_new (GooCanvasItemModel *parent,
- ...)
-{
- GooCanvasItemModel *model;
- va_list var_args;
- const char *first_property;
-
- model = g_object_new (GOO_TYPE_CANVAS_TABLE_MODEL, NULL);
-
- va_start (var_args, parent);
- first_property = va_arg (var_args, char*);
- if (first_property)
- g_object_set_valist (G_OBJECT (model), first_property, var_args);
- va_end (var_args);
-
- if (parent)
- {
- goo_canvas_item_model_add_child (parent, model, -1);
- g_object_unref (model);
- }
-
- return model;
-}
-
-
-static void
-goo_canvas_table_model_finalize (GObject *object)
-{
- GooCanvasTableModel *tmodel = (GooCanvasTableModel*) object;
-
- goo_canvas_table_free_data (&tmodel->table_data);
-
- G_OBJECT_CLASS (goo_canvas_table_model_parent_class)->finalize (object);
-}
-
-
-static void
-goo_canvas_table_model_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- GooCanvasTableModel *emodel = (GooCanvasTableModel*) object;
-
- goo_canvas_table_get_common_property (object, &emodel->table_data,
- prop_id, value, pspec);
-}
-
-
-static void
-goo_canvas_table_model_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- GooCanvasTableModel *emodel = (GooCanvasTableModel*) object;
- gboolean recompute_bounds;
-
- recompute_bounds = goo_canvas_table_set_common_property (object,
- &emodel->table_data,
- prop_id, value,
- pspec);
- g_signal_emit_by_name (emodel, "changed", recompute_bounds);
-}
-
-
-static void
-goo_canvas_table_model_add_child (GooCanvasItemModel *model,
- GooCanvasItemModel *child,
- gint position)
-{
- GooCanvasTableModel *tmodel = (GooCanvasTableModel*) model;
-
- goo_canvas_table_add_child_internal (&tmodel->table_data, position);
-
- /* Let the parent GooCanvasGroupModel code do the rest. */
- goo_canvas_table_model_parent_iface->add_child (model, child, position);
-}
-
-
-static void
-goo_canvas_table_model_move_child (GooCanvasItemModel *model,
- gint old_position,
- gint new_position)
-{
- GooCanvasTableModel *tmodel = (GooCanvasTableModel*) model;
-
- goo_canvas_table_move_child_internal (&tmodel->table_data, old_position,
- new_position);
-
- /* Let the parent GooCanvasGroupModel code do the rest. */
- goo_canvas_table_model_parent_iface->move_child (model, old_position,
- new_position);
-}
-
-
-static void
-goo_canvas_table_model_remove_child (GooCanvasItemModel *model,
- gint child_num)
-{
- GooCanvasTableModel *tmodel = (GooCanvasTableModel*) model;
-
- g_array_remove_index (tmodel->table_data.children, child_num);
-
- /* Let the parent GooCanvasGroupModel code do the rest. */
- goo_canvas_table_model_parent_iface->remove_child (model, child_num);
-}
-
-
-static void
-goo_canvas_table_model_get_child_property (GooCanvasItemModel *model,
- GooCanvasItemModel *child,
- guint property_id,
- GValue *value,
- GParamSpec *pspec)
-{
- GooCanvasGroupModel *gmodel = (GooCanvasGroupModel*) model;
- GooCanvasTableModel *tmodel = (GooCanvasTableModel*) model;
- GooCanvasTableChild *table_child;
- gint child_num;
-
- for (child_num = 0; child_num < gmodel->children->len; child_num++)
- {
- if (gmodel->children->pdata[child_num] == child)
- {
- table_child = &g_array_index (tmodel->table_data.children,
- GooCanvasTableChild, child_num);
- goo_canvas_table_get_common_child_property ((GObject*) tmodel,
- table_child,
- property_id, value,
- pspec);
- break;
- }
- }
-}
-
-
-static void
-goo_canvas_table_model_set_child_property (GooCanvasItemModel *model,
- GooCanvasItemModel *child,
- guint property_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- GooCanvasGroupModel *gmodel = (GooCanvasGroupModel*) model;
- GooCanvasTableModel *tmodel = (GooCanvasTableModel*) model;
- GooCanvasTableChild *table_child;
- gint child_num;
-
- for (child_num = 0; child_num < gmodel->children->len; child_num++)
- {
- if (gmodel->children->pdata[child_num] == child)
- {
- table_child = &g_array_index (tmodel->table_data.children,
- GooCanvasTableChild, child_num);
- goo_canvas_table_set_common_child_property ((GObject*) tmodel,
- &tmodel->table_data,
- table_child,
- property_id, value,
- pspec);
- break;
- }
- }
-
- g_signal_emit_by_name (tmodel, "changed", TRUE);
-}
-
-
-static GooCanvasItem*
-goo_canvas_table_model_create_item (GooCanvasItemModel *model,
- GooCanvas *canvas)
-{
- GooCanvasItem *item;
-
- item = goo_canvas_table_new (NULL, NULL);
- /* Note that we set the canvas before the model, since we may need the
- canvas to create any child items. */
- goo_canvas_item_set_canvas (item, canvas);
- goo_canvas_item_set_model (item, model);
-
- return item;
-}
-
-
-static void
-item_model_interface_init (GooCanvasItemModelIface *iface)
-{
- iface->add_child = goo_canvas_table_model_add_child;
- iface->move_child = goo_canvas_table_model_move_child;
- iface->remove_child = goo_canvas_table_model_remove_child;
- iface->get_child_property = goo_canvas_table_model_get_child_property;
- iface->set_child_property = goo_canvas_table_model_set_child_property;
-
- iface->create_item = goo_canvas_table_model_create_item;
}
diff --git a/src/goocanvastable.h b/src/goocanvastable.h
index e204657..e33eeab 100644
--- a/src/goocanvastable.h
+++ b/src/goocanvastable.h
@@ -28,26 +28,6 @@ struct _GooCanvasTableDimension
};
-/* This is the data used by both model and view classes. */
-typedef struct _GooCanvasTableData GooCanvasTableData;
-typedef struct _GooCanvasTableLayoutData GooCanvasTableLayoutData;
-struct _GooCanvasTableData
-{
- /* The explicitly set width or height, or -1. */
- gdouble width, height;
-
- /* One for rows & one for columns. */
- GooCanvasTableDimension dimensions[2];
-
- gdouble border_width;
-
- /* An array of GooCanvasTableChild. */
- GArray *children;
-
- GooCanvasTableLayoutData *layout_data;
-};
-
-
#define GOO_TYPE_CANVAS_TABLE (goo_canvas_table_get_type ())
#define GOO_CANVAS_TABLE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GOO_TYPE_CANVAS_TABLE, GooCanvasTable))
#define GOO_CANVAS_TABLE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GOO_TYPE_CANVAS_TABLE, GooCanvasTableClass))
@@ -59,6 +39,8 @@ struct _GooCanvasTableData
typedef struct _GooCanvasTable GooCanvasTable;
typedef struct _GooCanvasTableClass GooCanvasTableClass;
+typedef struct _GooCanvasTableLayoutData GooCanvasTableLayoutData;
+
/**
* GooCanvasTable
*
@@ -68,7 +50,18 @@ struct _GooCanvasTable
{
GooCanvasGroup parent;
- GooCanvasTableData *table_data;
+ /* The explicitly set width or height, or -1. */
+ gdouble width, height;
+
+ /* One for rows & one for columns. */
+ GooCanvasTableDimension dimensions[2];
+
+ gdouble border_width;
+
+ /* An array of GooCanvasTableChild. */
+ GArray *children;
+
+ GooCanvasTableLayoutData *layout_data;
};
struct _GooCanvasTableClass
@@ -92,48 +85,6 @@ GooCanvasItem* goo_canvas_table_new (GooCanvasItem *parent,
-#define GOO_TYPE_CANVAS_TABLE_MODEL (goo_canvas_table_model_get_type ())
-#define GOO_CANVAS_TABLE_MODEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GOO_TYPE_CANVAS_TABLE_MODEL, GooCanvasTableModel))
-#define GOO_CANVAS_TABLE_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GOO_TYPE_CANVAS_TABLE_MODEL, GooCanvasTableModelClass))
-#define GOO_IS_CANVAS_TABLE_MODEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GOO_TYPE_CANVAS_TABLE_MODEL))
-#define GOO_IS_CANVAS_TABLE_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GOO_TYPE_CANVAS_TABLE_MODEL))
-#define GOO_CANVAS_TABLE_MODEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GOO_TYPE_CANVAS_TABLE_MODEL, GooCanvasTableModelClass))
-
-
-typedef struct _GooCanvasTableModel GooCanvasTableModel;
-typedef struct _GooCanvasTableModelClass GooCanvasTableModelClass;
-
-/**
- * GooCanvasTableModel
- *
- * The #GooCanvasTableModel-struct struct contains private data only.
- */
-struct _GooCanvasTableModel
-{
- GooCanvasGroupModel parent_object;
-
- GooCanvasTableData table_data;
-};
-
-struct _GooCanvasTableModelClass
-{
- GooCanvasGroupModelClass parent_class;
-
- /*< private >*/
-
- /* Padding for future expansion */
- void (*_goo_canvas_reserved1) (void);
- void (*_goo_canvas_reserved2) (void);
- void (*_goo_canvas_reserved3) (void);
- void (*_goo_canvas_reserved4) (void);
-};
-
-
-GType goo_canvas_table_model_get_type (void) G_GNUC_CONST;
-GooCanvasItemModel* goo_canvas_table_model_new (GooCanvasItemModel *parent,
- ...);
-
-
G_END_DECLS
#endif /* __GOO_CANVAS_TABLE_H__ */
diff --git a/src/goocanvastext.c b/src/goocanvastext.c
index 10508fe..d3c98d1 100644
--- a/src/goocanvastext.c
+++ b/src/goocanvastext.c
@@ -34,15 +34,6 @@
#include "goocanvastext.h"
#include "goocanvas.h"
-typedef struct _GooCanvasTextPrivate GooCanvasTextPrivate;
-struct _GooCanvasTextPrivate {
- gdouble height;
-};
-
-#define GOO_CANVAS_TEXT_GET_PRIVATE(text) \
- (G_TYPE_INSTANCE_GET_PRIVATE ((text), GOO_TYPE_CANVAS_TEXT, GooCanvasTextPrivate))
-#define GOO_CANVAS_TEXT_MODEL_GET_PRIVATE(text) \
- (G_TYPE_INSTANCE_GET_PRIVATE ((text), GOO_TYPE_CANVAS_TEXT_MODEL, GooCanvasTextPrivate))
enum {
PROP_0,
@@ -59,9 +50,9 @@ enum {
PROP_WRAP
};
+
static PangoLayout*
-goo_canvas_text_create_layout (GooCanvasItemSimpleData *simple_data,
- GooCanvasTextData *text_data,
+goo_canvas_text_create_layout (GooCanvasText *text,
gdouble layout_width,
cairo_t *cr,
GooCanvasBounds *bounds,
@@ -70,14 +61,7 @@ goo_canvas_text_create_layout (GooCanvasItemSimpleData *simple_data,
static void goo_canvas_text_finalize (GObject *object);
static void canvas_item_interface_init (GooCanvasItemIface *iface);
-static void goo_canvas_text_get_property (GObject *object,
- guint param_id,
- GValue *value,
- GParamSpec *pspec);
-static void goo_canvas_text_set_property (GObject *object,
- guint param_id,
- const GValue *value,
- GParamSpec *pspec);
+
G_DEFINE_TYPE_WITH_CODE (GooCanvasText, goo_canvas_text,
GOO_TYPE_CANVAS_ITEM_SIMPLE,
@@ -86,105 +70,14 @@ G_DEFINE_TYPE_WITH_CODE (GooCanvasText, goo_canvas_text,
static void
-goo_canvas_text_install_common_properties (GObjectClass *gobject_class)
-{
- /* Text */
- g_object_class_install_property (gobject_class, PROP_TEXT,
- g_param_spec_string ("text",
- _("Text"),
- _("The text to display"),
- NULL,
- G_PARAM_READWRITE));
-
- g_object_class_install_property (gobject_class, PROP_USE_MARKUP,
- g_param_spec_boolean ("use-markup",
- _("Use Markup"),
- _("Whether to parse PangoMarkup in the text, to support different styles"),
- FALSE,
- G_PARAM_READWRITE));
-
- g_object_class_install_property (gobject_class, PROP_ELLIPSIZE,
- g_param_spec_enum ("ellipsize",
- _("Ellipsize"),
- _("The preferred place to ellipsize the string, if the label does not have enough room to display the entire string"),
- PANGO_TYPE_ELLIPSIZE_MODE,
- PANGO_ELLIPSIZE_NONE,
- G_PARAM_READWRITE));
-
- g_object_class_install_property (gobject_class, PROP_WRAP,
- g_param_spec_enum ("wrap",
- _("Wrap"),
- _("The preferred method of wrapping the string if a width has been set"),
- PANGO_TYPE_WRAP_MODE,
- PANGO_WRAP_WORD,
- G_PARAM_READWRITE));
-
- /* Position */
- g_object_class_install_property (gobject_class, PROP_X,
- g_param_spec_double ("x",
- "X",
- _("The x coordinate of the text"),
- -G_MAXDOUBLE,
- G_MAXDOUBLE, 0.0,
- G_PARAM_READWRITE));
-
- g_object_class_install_property (gobject_class, PROP_Y,
- g_param_spec_double ("y",
- "Y",
- _("The y coordinate of the text"),
- -G_MAXDOUBLE,
- G_MAXDOUBLE, 0.0,
- G_PARAM_READWRITE));
-
- g_object_class_install_property (gobject_class, PROP_WIDTH,
- g_param_spec_double ("width",
- _("Width"),
- _("The width to use to layout the text, or -1 to let the text use as much horizontal space as needed"),
- -G_MAXDOUBLE,
- G_MAXDOUBLE, -1.0,
- G_PARAM_READWRITE));
-
- g_object_class_install_property (gobject_class, PROP_HEIGHT,
- g_param_spec_double ("height",
- _("Height"),
- _("The height to use to layout the text, or -1 to let the text use as much vertical space as needed"),
- -G_MAXDOUBLE,
- G_MAXDOUBLE, -1.0,
- G_PARAM_READWRITE));
-
-
- g_object_class_install_property (gobject_class, PROP_ANCHOR,
- g_param_spec_enum ("anchor",
- _("Anchor"),
- _("How to position the text relative to the given x and y coordinates"),
- GTK_TYPE_ANCHOR_TYPE,
- GTK_ANCHOR_NW,
- G_PARAM_READWRITE));
-
- g_object_class_install_property (gobject_class, PROP_ALIGN,
- g_param_spec_enum ("alignment",
- _("Alignment"),
- _("How to align the text"),
- PANGO_TYPE_ALIGNMENT,
- PANGO_ALIGN_LEFT,
- G_PARAM_READWRITE));
-}
-
-
-static void
goo_canvas_text_init (GooCanvasText *text)
{
- GooCanvasTextPrivate *priv = GOO_CANVAS_TEXT_GET_PRIVATE (text);
-
- text->text_data = g_slice_new0 (GooCanvasTextData);
- text->text_data->width = -1.0;
- text->text_data->anchor = GTK_ANCHOR_NW;
- text->text_data->ellipsize = PANGO_ELLIPSIZE_NONE;
- text->text_data->wrap = PANGO_WRAP_WORD;
-
+ text->width = -1.0;
+ text->height = -1.0;
text->layout_width = -1.0;
-
- priv->height = -1.0;
+ text->anchor = GTK_ANCHOR_NW;
+ text->ellipsize = PANGO_ELLIPSIZE_NONE;
+ text->wrap = PANGO_WRAP_WORD;
}
@@ -230,19 +123,17 @@ goo_canvas_text_new (GooCanvasItem *parent,
{
GooCanvasItem *item;
GooCanvasText *text;
- GooCanvasTextData *text_data;
const char *first_property;
va_list var_args;
item = g_object_new (GOO_TYPE_CANVAS_TEXT, NULL);
text = (GooCanvasText*) item;
- text_data = text->text_data;
- text_data->text = g_strdup (string);
- text_data->x = x;
- text_data->y = y;
- text_data->width = width;
- text_data->anchor = anchor;
+ text->text = g_strdup (string);
+ text->x = x;
+ text->y = y;
+ text->width = width;
+ text->anchor = anchor;
va_start (var_args, anchor);
first_property = va_arg (var_args, char*);
@@ -263,74 +154,54 @@ goo_canvas_text_new (GooCanvasItem *parent,
static void
goo_canvas_text_finalize (GObject *object)
{
- GooCanvasItemSimple *simple = (GooCanvasItemSimple*) object;
GooCanvasText *text = (GooCanvasText*) object;
- /* Free our data if we didn't have a model. (If we had a model it would
- have been reset in dispose() and simple_data will be NULL.) */
- if (simple->simple_data)
- {
- g_free (text->text_data->text);
- g_slice_free (GooCanvasTextData, text->text_data);
- }
- text->text_data = NULL;
+ g_free (text->text);
+ text->text = NULL;
G_OBJECT_CLASS (goo_canvas_text_parent_class)->finalize (object);
}
-/* Gets the private data to use, from the model or from the item itself. */
-static GooCanvasTextPrivate*
-goo_canvas_text_get_private (GooCanvasText *text)
-{
- GooCanvasItemSimple *simple = (GooCanvasItemSimple*) text;
-
- if (simple->model)
- return GOO_CANVAS_TEXT_MODEL_GET_PRIVATE (simple->model);
- else
- return GOO_CANVAS_TEXT_GET_PRIVATE (text);
-}
-
-
static void
-goo_canvas_text_get_common_property (GObject *object,
- GooCanvasTextData *text_data,
- GooCanvasTextPrivate *priv,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
+goo_canvas_text_get_property (GObject *object,
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
{
+ GooCanvasText *text = (GooCanvasText*) object;
+
switch (prop_id)
{
case PROP_X:
- g_value_set_double (value, text_data->x);
+ g_value_set_double (value, text->x);
break;
case PROP_Y:
- g_value_set_double (value, text_data->y);
+ g_value_set_double (value, text->y);
break;
case PROP_WIDTH:
- g_value_set_double (value, text_data->width);
+ g_value_set_double (value, text->width);
break;
case PROP_HEIGHT:
- g_value_set_double (value, priv->height);
+ g_value_set_double (value, text->height);
break;
case PROP_TEXT:
- g_value_set_string (value, text_data->text);
+ g_value_set_string (value, text->text);
break;
case PROP_USE_MARKUP:
- g_value_set_boolean (value, text_data->use_markup);
+ g_value_set_boolean (value, text->use_markup);
break;
case PROP_ELLIPSIZE:
- g_value_set_enum (value, text_data->ellipsize);
+ g_value_set_enum (value, text->ellipsize);
break;
case PROP_WRAP:
- g_value_set_enum (value, text_data->wrap);
+ g_value_set_enum (value, text->wrap);
break;
case PROP_ANCHOR:
- g_value_set_enum (value, text_data->anchor);
+ g_value_set_enum (value, text->anchor);
break;
case PROP_ALIGN:
- g_value_set_enum (value, text_data->alignment);
+ g_value_set_enum (value, text->alignment);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -340,99 +211,66 @@ goo_canvas_text_get_common_property (GObject *object,
static void
-goo_canvas_text_get_property (GObject *object,
+goo_canvas_text_set_property (GObject *object,
guint prop_id,
- GValue *value,
+ const GValue *value,
GParamSpec *pspec)
{
+ GooCanvasItemSimple *simple = (GooCanvasItemSimple*) object;
GooCanvasText *text = (GooCanvasText*) object;
- GooCanvasTextPrivate *priv = goo_canvas_text_get_private (text);
-
- goo_canvas_text_get_common_property (object, text->text_data, priv,
- prop_id, value, pspec);
-}
-
-static void
-goo_canvas_text_set_common_property (GObject *object,
- GooCanvasTextData *text_data,
- GooCanvasTextPrivate *priv,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
switch (prop_id)
{
case PROP_X:
- text_data->x = g_value_get_double (value);
+ text->x = g_value_get_double (value);
break;
case PROP_Y:
- text_data->y = g_value_get_double (value);
+ text->y = g_value_get_double (value);
break;
case PROP_WIDTH:
- text_data->width = g_value_get_double (value);
+ text->width = g_value_get_double (value);
break;
case PROP_HEIGHT:
- priv->height = g_value_get_double (value);
+ text->height = g_value_get_double (value);
break;
case PROP_TEXT:
- g_free (text_data->text);
- text_data->text = g_value_dup_string (value);
+ g_free (text->text);
+ text->text = g_value_dup_string (value);
break;
case PROP_USE_MARKUP:
- text_data->use_markup = g_value_get_boolean (value);
+ text->use_markup = g_value_get_boolean (value);
break;
case PROP_ELLIPSIZE:
- text_data->ellipsize = g_value_get_enum (value);
+ text->ellipsize = g_value_get_enum (value);
break;
case PROP_WRAP:
- text_data->wrap = g_value_get_enum (value);
+ text->wrap = g_value_get_enum (value);
break;
case PROP_ANCHOR:
- text_data->anchor = g_value_get_enum (value);
+ text->anchor = g_value_get_enum (value);
break;
case PROP_ALIGN:
- text_data->alignment = g_value_get_enum (value);
+ text->alignment = g_value_get_enum (value);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
}
-}
-
-static void
-goo_canvas_text_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- GooCanvasItemSimple *simple = (GooCanvasItemSimple*) object;
- GooCanvasText *text = (GooCanvasText*) object;
- GooCanvasTextPrivate *priv = goo_canvas_text_get_private (text);
-
- if (simple->model)
- {
- g_warning ("Can't set property of a canvas item with a model - set the model property instead");
- return;
- }
-
- goo_canvas_text_set_common_property (object, text->text_data, priv, prop_id,
- value, pspec);
goo_canvas_item_simple_changed (simple, TRUE);
}
static PangoLayout*
-goo_canvas_text_create_layout (GooCanvasItemSimpleData *simple_data,
- GooCanvasTextData *text_data,
+goo_canvas_text_create_layout (GooCanvasText *text,
gdouble layout_width,
cairo_t *cr,
GooCanvasBounds *bounds,
gdouble *origin_x_return,
gdouble *origin_y_return)
{
- GooCanvasStyle *style = simple_data->style;
+ GooCanvasItemSimple *simple = (GooCanvasItemSimple*) text;
+ GooCanvasStyle *style = simple->style;
GValue *svalue;
PangoLayout *layout;
PangoContext *context;
@@ -443,7 +281,7 @@ goo_canvas_text_create_layout (GooCanvasItemSimpleData *simple_data,
cairo_font_options_t *font_options;
cairo_hint_metrics_t hint_metrics = CAIRO_HINT_METRICS_OFF;
- string = text_data->text ? text_data->text : "";
+ string = text->text ? text->text : "";
layout = pango_cairo_create_layout (cr);
context = pango_layout_get_context (layout);
@@ -451,7 +289,7 @@ goo_canvas_text_create_layout (GooCanvasItemSimpleData *simple_data,
if (layout_width > 0)
pango_layout_set_width (layout, (double) layout_width * PANGO_SCALE);
- if (text_data->use_markup)
+ if (text->use_markup)
pango_layout_set_markup (layout, string, -1);
else
pango_layout_set_text (layout, string, -1);
@@ -471,12 +309,12 @@ goo_canvas_text_create_layout (GooCanvasItemSimpleData *simple_data,
pango_cairo_context_set_font_options (context, font_options);
cairo_font_options_destroy (font_options);
- if (text_data->alignment != PANGO_ALIGN_LEFT)
- pango_layout_set_alignment (layout, text_data->alignment);
+ if (text->alignment != PANGO_ALIGN_LEFT)
+ pango_layout_set_alignment (layout, text->alignment);
- pango_layout_set_ellipsize (layout, text_data->ellipsize);
+ pango_layout_set_ellipsize (layout, text->ellipsize);
- pango_layout_set_wrap (layout, text_data->wrap);
+ pango_layout_set_wrap (layout, text->wrap);
if (bounds)
{
@@ -488,17 +326,17 @@ goo_canvas_text_create_layout (GooCanvasItemSimpleData *simple_data,
/* If the text width has been set, that width is used to do the alignment
positioning. Otherwise the actual width is used. */
- if (text_data->width > 0)
- align_width = text_data->width;
+ if (text->width > 0)
+ align_width = text->width;
else
align_width = logical_width;
/* Now calculate the origin of the text, i.e. where we will tell Pango
to draw it. */
- origin_x = text_data->x;
- origin_y = text_data->y;
+ origin_x = text->x;
+ origin_y = text->y;
- switch (text_data->anchor)
+ switch (text->anchor)
{
case GTK_ANCHOR_N:
case GTK_ANCHOR_CENTER:
@@ -514,7 +352,7 @@ goo_canvas_text_create_layout (GooCanvasItemSimpleData *simple_data,
break;
}
- switch (text_data->anchor)
+ switch (text->anchor)
{
case GTK_ANCHOR_W:
case GTK_ANCHOR_CENTER:
@@ -540,13 +378,13 @@ goo_canvas_text_create_layout (GooCanvasItemSimpleData *simple_data,
bounds->x1 = origin_x;
bounds->y1 = origin_y;
- if (text_data->width > 0)
+ if (text->width > 0)
{
/* If the text width has been set, and the alignment isn't
PANGO_ALIGN_LEFT, we need to adjust for the difference between
the actual width of the text and the width that was used for
alignment. */
- switch (text_data->alignment)
+ switch (text->alignment)
{
case PANGO_ALIGN_CENTER:
bounds->x1 += (align_width - logical_width) / 2.0;
@@ -593,23 +431,21 @@ goo_canvas_text_update (GooCanvasItemSimple *simple,
cairo_t *cr)
{
GooCanvasText *text = (GooCanvasText*) simple;
- GooCanvasTextPrivate *priv = goo_canvas_text_get_private (text);
PangoLayout *layout;
/* Initialize the layout width to the text item's specified width property.
It may get changed later in get_requested_height() according to the
layout container and settings. */
- text->layout_width = text->text_data->width;
+ text->layout_width = text->width;
/* Compute the new bounds. */
- layout = goo_canvas_text_create_layout (simple->simple_data, text->text_data,
- text->layout_width, cr,
+ layout = goo_canvas_text_create_layout (text, text->layout_width, cr,
&simple->bounds, NULL, NULL);
g_object_unref (layout);
/* If the height is set, use that. */
- if (priv->height > 0.0)
- simple->bounds.y2 = simple->bounds.y1 + priv->height;
+ if (text->height > 0.0)
+ simple->bounds.y2 = simple->bounds.y1 + text->height;
}
@@ -635,9 +471,7 @@ goo_canvas_text_is_item_at (GooCanvasItemSimple *simple,
cairo_t *cr,
gboolean is_pointer_event)
{
- GooCanvasItemSimpleData *simple_data = simple->simple_data;
GooCanvasText *text = (GooCanvasText*) simple;
- GooCanvasTextPrivate *priv = goo_canvas_text_get_private (text);
PangoLayout *layout;
GooCanvasBounds bounds;
PangoLayoutIter *iter;
@@ -648,20 +482,19 @@ goo_canvas_text_is_item_at (GooCanvasItemSimple *simple,
gboolean in_item = FALSE;
/* If there is no text just return. */
- if (!text->text_data->text || !text->text_data->text[0])
+ if (!text->text || !text->text[0])
return FALSE;
if (is_pointer_event
- && simple_data->pointer_events & GOO_CANVAS_EVENTS_PAINTED_MASK
- && goo_canvas_text_is_unpainted (simple_data->style))
+ && simple->pointer_events & GOO_CANVAS_EVENTS_PAINTED_MASK
+ && goo_canvas_text_is_unpainted (simple->style))
return FALSE;
/* Check if the point is outside the clipped height. */
- if (priv->height > 0.0 && y > priv->height)
+ if (text->height > 0.0 && y > text->height)
return FALSE;
- layout = goo_canvas_text_create_layout (simple_data, text->text_data,
- text->layout_width, cr, &bounds,
+ layout = goo_canvas_text_create_layout (text, text->layout_width, cr, &bounds,
&origin_x, &origin_y);
/* Convert the coordinates into Pango units. */
@@ -712,28 +545,26 @@ goo_canvas_text_paint (GooCanvasItemSimple *simple,
const GooCanvasBounds *bounds)
{
GooCanvasText *text = (GooCanvasText*) simple;
- GooCanvasTextPrivate *priv = goo_canvas_text_get_private (text);
PangoLayout *layout;
GooCanvasBounds layout_bounds;
gdouble origin_x, origin_y;
/* If there is no text just return. */
- if (!text->text_data->text || !text->text_data->text[0])
+ if (!text->text || !text->text[0])
return;
- goo_canvas_style_set_fill_options (simple->simple_data->style, cr);
+ goo_canvas_style_set_fill_options (simple->style, cr);
cairo_new_path (cr);
- layout = goo_canvas_text_create_layout (simple->simple_data, text->text_data,
- text->layout_width, cr,
+ layout = goo_canvas_text_create_layout (text, text->layout_width, cr,
&layout_bounds,
&origin_x, &origin_y);
cairo_save (cr);
- if (priv->height > 0.0)
+ if (text->height > 0.0)
{
cairo_rectangle (cr, origin_x, origin_y,
- text->layout_width, priv->height);
+ text->layout_width, text->height);
cairo_clip (cr);
}
cairo_move_to (cr, origin_x, origin_y);
@@ -750,34 +581,31 @@ goo_canvas_text_get_requested_height (GooCanvasItem *item,
gdouble width)
{
GooCanvasItemSimple *simple = (GooCanvasItemSimple*) item;
- GooCanvasItemSimpleData *simple_data = simple->simple_data;
GooCanvasText *text = (GooCanvasText*) item;
- GooCanvasTextPrivate *priv = goo_canvas_text_get_private (text);
PangoLayout *layout;
gdouble height;
/* If we have a transformation besides a simple scale & translation, just
return -1 as we can't adjust the height in that case. */
- if (simple_data->clip_path_commands
- || (simple_data->transform && (simple_data->transform->xy != 0.0
- || simple_data->transform->yx != 0.0)))
+ if (simple->clip_path_commands
+ || (simple->transform && (simple->transform->xy != 0.0
+ || simple->transform->yx != 0.0)))
return -1;
cairo_save (cr);
- if (simple_data->transform)
- cairo_transform (cr, simple_data->transform);
+ if (simple->transform)
+ cairo_transform (cr, simple->transform);
/* Convert the width from the parent's coordinate space. Note that we only
need to support a simple scale operation here. */
text->layout_width = width;
- if (simple_data->transform)
- text->layout_width /= simple_data->transform->xx;
+ if (simple->transform)
+ text->layout_width /= simple->transform->xx;
- if (priv->height < 0.0)
+ if (text->height < 0.0)
{
/* Create layout with given width. */
- layout = goo_canvas_text_create_layout (simple_data, text->text_data,
- text->layout_width, cr,
+ layout = goo_canvas_text_create_layout (text, text->layout_width, cr,
&simple->bounds, NULL, NULL);
g_object_unref (layout);
@@ -785,13 +613,13 @@ goo_canvas_text_get_requested_height (GooCanvasItem *item,
}
else
{
- height = priv->height;
+ height = text->height;
}
/* Convert to the parent's coordinate space. As above, we only need to
support a simple scale operation here. */
- if (simple_data->transform)
- height *= simple_data->transform->yy;
+ if (simple->transform)
+ height *= simple->transform->yy;
/* Convert the item's bounds to device space. */
goo_canvas_item_simple_user_bounds_to_device (simple, cr, &simple->bounds);
@@ -828,8 +656,7 @@ goo_canvas_text_get_natural_extents (GooCanvasText *text,
goo_canvas_item_ensure_updated (item);
cr = goo_canvas_create_cairo_context (simple->canvas);
- layout = goo_canvas_text_create_layout (simple->simple_data, text->text_data,
- text->text_data->width, cr, NULL,
+ layout = goo_canvas_text_create_layout (text, text->width, cr, NULL,
NULL, NULL);
pango_layout_get_extents (layout, ink_rect, logical_rect);
g_object_unref (layout);
@@ -838,30 +665,9 @@ goo_canvas_text_get_natural_extents (GooCanvasText *text,
static void
-goo_canvas_text_set_model (GooCanvasItem *item,
- GooCanvasItemModel *model)
-{
- GooCanvasItemSimple *simple = (GooCanvasItemSimple*) item;
- GooCanvasText *text = (GooCanvasText*) item;
- GooCanvasTextModel *tmodel = (GooCanvasTextModel*) model;
-
- /* If our text_data was allocated, free it. */
- if (!simple->model)
- g_slice_free (GooCanvasTextData, text->text_data);
-
- /* Now use the new model's text_data instead. */
- text->text_data = &tmodel->text_data;
-
- /* Let the parent GooCanvasItemSimple code do the rest. */
- goo_canvas_item_simple_set_model (simple, model);
-}
-
-
-static void
canvas_item_interface_init (GooCanvasItemIface *iface)
{
iface->get_requested_height = goo_canvas_text_get_requested_height;
- iface->set_model = goo_canvas_text_set_model;
}
@@ -871,8 +677,6 @@ goo_canvas_text_class_init (GooCanvasTextClass *klass)
GObjectClass *gobject_class = (GObjectClass*) klass;
GooCanvasItemSimpleClass *simple_class = (GooCanvasItemSimpleClass*) klass;
- g_type_class_add_private (gobject_class, sizeof (GooCanvasTextPrivate));
-
gobject_class->finalize = goo_canvas_text_finalize;
gobject_class->get_property = goo_canvas_text_get_property;
@@ -882,209 +686,84 @@ goo_canvas_text_class_init (GooCanvasTextClass *klass)
simple_class->simple_paint = goo_canvas_text_paint;
simple_class->simple_is_item_at = goo_canvas_text_is_item_at;
- goo_canvas_text_install_common_properties (gobject_class);
-}
-
-
-
-/**
- * SECTION:goocanvastextmodel
- * @Title: GooCanvasTextModel
- * @Short_Description: a model for text items.
- *
- * GooCanvasTextModel represents a model for text items.
- *
- * It is a subclass of #GooCanvasItemModelSimple and so inherits all of the
- * style properties such as "fill-color".
- *
- * It also implements the #GooCanvasItemModel interface, so you can use the
- * #GooCanvasItemModel functions such as goo_canvas_item_model_raise() and
- * goo_canvas_item_model_rotate().
- *
- * To create a #GooCanvasTextModel use goo_canvas_text_model_new().
- *
- * To get or set the properties of an existing #GooCanvasTextModel, use
- * g_object_get() and g_object_set().
- *
- * To respond to events such as mouse clicks on the text item you must connect
- * to the signal handlers of the corresponding #GooCanvasText objects.
- * (See goo_canvas_get_item() and #GooCanvas::item-created.)
- */
-
-static void item_model_interface_init (GooCanvasItemModelIface *iface);
-static void goo_canvas_text_model_finalize (GObject *object);
-static void goo_canvas_text_model_get_property (GObject *object,
- guint param_id,
- GValue *value,
- GParamSpec *pspec);
-static void goo_canvas_text_model_set_property (GObject *object,
- guint param_id,
- const GValue *value,
- GParamSpec *pspec);
-
-G_DEFINE_TYPE_WITH_CODE (GooCanvasTextModel, goo_canvas_text_model,
- GOO_TYPE_CANVAS_ITEM_MODEL_SIMPLE,
- G_IMPLEMENT_INTERFACE (GOO_TYPE_CANVAS_ITEM_MODEL,
- item_model_interface_init))
-
-
-static void
-goo_canvas_text_model_class_init (GooCanvasTextModelClass *klass)
-{
- GObjectClass *gobject_class = (GObjectClass*) klass;
-
- g_type_class_add_private (gobject_class, sizeof (GooCanvasTextPrivate));
-
- gobject_class->finalize = goo_canvas_text_model_finalize;
-
- gobject_class->get_property = goo_canvas_text_model_get_property;
- gobject_class->set_property = goo_canvas_text_model_set_property;
-
- goo_canvas_text_install_common_properties (gobject_class);
-}
-
-
-static void
-goo_canvas_text_model_init (GooCanvasTextModel *tmodel)
-{
- GooCanvasTextPrivate *priv = GOO_CANVAS_TEXT_MODEL_GET_PRIVATE (tmodel);
-
- tmodel->text_data.width = -1.0;
- tmodel->text_data.anchor = GTK_ANCHOR_NW;
- tmodel->text_data.ellipsize = PANGO_ELLIPSIZE_NONE;
- tmodel->text_data.wrap = PANGO_WRAP_WORD;
-
- priv->height = -1.0;
-}
-
-
-/**
- * goo_canvas_text_model_new:
- * @parent: the parent model, or %NULL. If a parent is specified, it will
- * assume ownership of the item, and the item will automatically be freed when
- * it is removed from the parent. Otherwise call g_object_unref() to free it.
- * @string: the text to display.
- * @x: the x coordinate of the text.
- * @y: the y coordinate of the text.
- * @width: the width of the text item, or -1 for unlimited width.
- * @anchor: the position of the text relative to the given @x and @y
- * coordinates. For example an anchor of %GDK_ANCHOR_NW will result in the
- * top-left of the text being placed at the given @x and @y coordinates.
- * An anchor of %GDK_ANCHOR_CENTER will result in the center of the text being
- * placed at the @x and @y coordinates.
- * @...: optional pairs of property names and values, and a terminating %NULL.
- *
- * Creates a new text model.
- *
- * <!--PARAMETERS-->
- *
- * Here's an example showing how to create a text item with the bottom right
- * of the text box placed at (500,500):
- *
- * <informalexample><programlisting>
- * GooCanvasItemModel *text = goo_canvas_text_model_new (mygroup, "Hello World", 500.0, 500.0, 200.0, GTK_ANCHOR_SE,
- * "fill-color", "blue",
- * NULL);
- * </programlisting></informalexample>
- *
- * Returns: a new text model.
- **/
-GooCanvasItemModel*
-goo_canvas_text_model_new (GooCanvasItemModel *parent,
- const char *string,
- gdouble x,
- gdouble y,
- gdouble width,
- GtkAnchorType anchor,
- ...)
-{
- GooCanvasItemModel *model;
- GooCanvasTextModel *tmodel;
- GooCanvasTextData *text_data;
- const char *first_property;
- va_list var_args;
-
- model = g_object_new (GOO_TYPE_CANVAS_TEXT_MODEL, NULL);
- tmodel = (GooCanvasTextModel*) model;
-
- text_data = &tmodel->text_data;
- text_data->text = g_strdup (string);
- text_data->x = x;
- text_data->y = y;
- text_data->width = width;
- text_data->anchor = anchor;
-
- va_start (var_args, anchor);
- first_property = va_arg (var_args, char*);
- if (first_property)
- g_object_set_valist ((GObject*) model, first_property, var_args);
- va_end (var_args);
-
- if (parent)
- {
- goo_canvas_item_model_add_child (parent, model, -1);
- g_object_unref (model);
- }
-
- return model;
-}
-
-
-static void
-goo_canvas_text_model_finalize (GObject *object)
-{
- GooCanvasTextModel *tmodel = (GooCanvasTextModel*) object;
-
- g_free (tmodel->text_data.text);
-
- G_OBJECT_CLASS (goo_canvas_text_model_parent_class)->finalize (object);
-}
-
-
-static void
-goo_canvas_text_model_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- GooCanvasTextModel *tmodel = (GooCanvasTextModel*) object;
- GooCanvasTextPrivate *priv = GOO_CANVAS_TEXT_MODEL_GET_PRIVATE (tmodel);
+ /* Text */
+ g_object_class_install_property (gobject_class, PROP_TEXT,
+ g_param_spec_string ("text",
+ _("Text"),
+ _("The text to display"),
+ NULL,
+ G_PARAM_READWRITE));
- goo_canvas_text_get_common_property (object, &tmodel->text_data, priv,
- prop_id, value, pspec);
-}
+ g_object_class_install_property (gobject_class, PROP_USE_MARKUP,
+ g_param_spec_boolean ("use-markup",
+ _("Use Markup"),
+ _("Whether to parse PangoMarkup in the text, to support different styles"),
+ FALSE,
+ G_PARAM_READWRITE));
+ g_object_class_install_property (gobject_class, PROP_ELLIPSIZE,
+ g_param_spec_enum ("ellipsize",
+ _("Ellipsize"),
+ _("The preferred place to ellipsize the string, if the label does not have enough room to display the entire string"),
+ PANGO_TYPE_ELLIPSIZE_MODE,
+ PANGO_ELLIPSIZE_NONE,
+ G_PARAM_READWRITE));
-static void
-goo_canvas_text_model_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- GooCanvasTextModel *tmodel = (GooCanvasTextModel*) object;
- GooCanvasTextPrivate *priv = GOO_CANVAS_TEXT_MODEL_GET_PRIVATE (tmodel);
+ g_object_class_install_property (gobject_class, PROP_WRAP,
+ g_param_spec_enum ("wrap",
+ _("Wrap"),
+ _("The preferred method of wrapping the string if a width has been set"),
+ PANGO_TYPE_WRAP_MODE,
+ PANGO_WRAP_WORD,
+ G_PARAM_READWRITE));
- goo_canvas_text_set_common_property (object, &tmodel->text_data, priv,
- prop_id, value, pspec);
- g_signal_emit_by_name (tmodel, "changed", TRUE);
-}
+ /* Position */
+ g_object_class_install_property (gobject_class, PROP_X,
+ g_param_spec_double ("x",
+ "X",
+ _("The x coordinate of the text"),
+ -G_MAXDOUBLE,
+ G_MAXDOUBLE, 0.0,
+ G_PARAM_READWRITE));
+ g_object_class_install_property (gobject_class, PROP_Y,
+ g_param_spec_double ("y",
+ "Y",
+ _("The y coordinate of the text"),
+ -G_MAXDOUBLE,
+ G_MAXDOUBLE, 0.0,
+ G_PARAM_READWRITE));
-static GooCanvasItem*
-goo_canvas_text_model_create_item (GooCanvasItemModel *model,
- GooCanvas *canvas)
-{
- GooCanvasItem *item;
+ g_object_class_install_property (gobject_class, PROP_WIDTH,
+ g_param_spec_double ("width",
+ _("Width"),
+ _("The width to use to layout the text, or -1 to let the text use as much horizontal space as needed"),
+ -G_MAXDOUBLE,
+ G_MAXDOUBLE, -1.0,
+ G_PARAM_READWRITE));
- item = g_object_new (GOO_TYPE_CANVAS_TEXT, NULL);
- goo_canvas_item_set_model (item, model);
+ g_object_class_install_property (gobject_class, PROP_HEIGHT,
+ g_param_spec_double ("height",
+ _("Height"),
+ _("The height to use to layout the text, or -1 to let the text use as much vertical space as needed"),
+ -G_MAXDOUBLE,
+ G_MAXDOUBLE, -1.0,
+ G_PARAM_READWRITE));
- return item;
-}
+ g_object_class_install_property (gobject_class, PROP_ANCHOR,
+ g_param_spec_enum ("anchor",
+ _("Anchor"),
+ _("How to position the text relative to the given x and y coordinates"),
+ GTK_TYPE_ANCHOR_TYPE,
+ GTK_ANCHOR_NW,
+ G_PARAM_READWRITE));
-static void
-item_model_interface_init (GooCanvasItemModelIface *iface)
-{
- iface->create_item = goo_canvas_text_model_create_item;
+ g_object_class_install_property (gobject_class, PROP_ALIGN,
+ g_param_spec_enum ("alignment",
+ _("Alignment"),
+ _("How to align the text"),
+ PANGO_TYPE_ALIGNMENT,
+ PANGO_ALIGN_LEFT,
+ G_PARAM_READWRITE));
}
diff --git a/src/goocanvastext.h b/src/goocanvastext.h
index 7d0ecbd..5e0824b 100644
--- a/src/goocanvastext.h
+++ b/src/goocanvastext.h
@@ -13,20 +13,6 @@
G_BEGIN_DECLS
-/* This is the data used by both model and view classes. */
-typedef struct _GooCanvasTextData GooCanvasTextData;
-struct _GooCanvasTextData
-{
- gchar *text;
- gdouble x, y, width;
- guint use_markup : 1;
- guint anchor : 5; /* GtkAnchorType */
- guint alignment : 3; /* PangoAlignment */
- guint ellipsize : 3; /* PangoEllipsizeMode */
- guint wrap : 3; /* PangoWrapMode */
-};
-
-
#define GOO_TYPE_CANVAS_TEXT (goo_canvas_text_get_type ())
#define GOO_CANVAS_TEXT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GOO_TYPE_CANVAS_TEXT, GooCanvasText))
#define GOO_CANVAS_TEXT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GOO_TYPE_CANVAS_TEXT, GooCanvasTextClass))
@@ -47,8 +33,15 @@ struct _GooCanvasText
{
GooCanvasItemSimple parent;
- GooCanvasTextData *text_data;
+ gchar *text;
+ gdouble x, y, width, height;
gdouble layout_width;
+
+ guint use_markup : 1;
+ guint anchor : 5; /* GtkAnchorType */
+ guint alignment : 3; /* PangoAlignment */
+ guint ellipsize : 3; /* PangoEllipsizeMode */
+ guint wrap : 3; /* PangoWrapMode */
};
struct _GooCanvasTextClass
@@ -80,54 +73,6 @@ void goo_canvas_text_get_natural_extents (GooCanvasText *text,
PangoRectangle *logical_rect);
-#define GOO_TYPE_CANVAS_TEXT_MODEL (goo_canvas_text_model_get_type ())
-#define GOO_CANVAS_TEXT_MODEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GOO_TYPE_CANVAS_TEXT_MODEL, GooCanvasTextModel))
-#define GOO_CANVAS_TEXT_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GOO_TYPE_CANVAS_TEXT_MODEL, GooCanvasTextModelClass))
-#define GOO_IS_CANVAS_TEXT_MODEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GOO_TYPE_CANVAS_TEXT_MODEL))
-#define GOO_IS_CANVAS_TEXT_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GOO_TYPE_CANVAS_TEXT_MODEL))
-#define GOO_CANVAS_TEXT_MODEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GOO_TYPE_CANVAS_TEXT_MODEL, GooCanvasTextModelClass))
-
-
-typedef struct _GooCanvasTextModel GooCanvasTextModel;
-typedef struct _GooCanvasTextModelClass GooCanvasTextModelClass;
-
-/**
- * GooCanvasTextModel
- *
- * The #GooCanvasTextModel-struct struct contains private data only.
- */
-struct _GooCanvasTextModel
-{
- GooCanvasItemModelSimple parent_object;
-
- GooCanvasTextData text_data;
-};
-
-struct _GooCanvasTextModelClass
-{
- GooCanvasItemModelSimpleClass parent_class;
-
- /*< private >*/
-
- /* Padding for future expansion */
- void (*_goo_canvas_reserved1) (void);
- void (*_goo_canvas_reserved2) (void);
- void (*_goo_canvas_reserved3) (void);
- void (*_goo_canvas_reserved4) (void);
-};
-
-
-GType goo_canvas_text_model_get_type (void) G_GNUC_CONST;
-
-GooCanvasItemModel* goo_canvas_text_model_new (GooCanvasItemModel *parent,
- const char *string,
- gdouble x,
- gdouble y,
- gdouble width,
- GtkAnchorType anchor,
- ...);
-
-
G_END_DECLS
#endif /* __GOO_CANVAS_TEXT_H__ */
diff --git a/src/goocanvasutils.c b/src/goocanvasutils.c
index ca07559..bc658ed 100644
--- a/src/goocanvasutils.c
+++ b/src/goocanvasutils.c
@@ -483,10 +483,6 @@ goo_canvas_query_child_properties (gpointer class,
return goo_canvas_item_class_list_child_properties (class,
n_properties);
- if (g_type_interface_peek (class, GOO_TYPE_CANVAS_ITEM_MODEL))
- return goo_canvas_item_model_class_list_child_properties (class,
- n_properties);
-
return NULL;
}
diff --git a/src/goocanvaswidget.c b/src/goocanvaswidget.c
index 70adfc0..397a6cf 100644
--- a/src/goocanvaswidget.c
+++ b/src/goocanvaswidget.c
@@ -28,9 +28,6 @@
* It doesn't support rendering of widgets to a given cairo_t, which
* means you can't output the widget to a pdf or postscript file.
* </para></listitem><listitem><para>
- * It doesn't have a model/view variant like the other standard items,
- * so it can only be used in a simple canvas without a model.
- * </para></listitem><listitem><para>
* It can't be made a static item.
* </para></listitem></itemizedlist>
*/
@@ -246,7 +243,7 @@ goo_canvas_widget_set_widget (GooCanvasWidget *witem,
g_object_ref (witem->widget);
g_object_set_data (G_OBJECT (witem->widget), "goo-canvas-item", witem);
- if (simple->simple_data->visibility <= GOO_CANVAS_ITEM_INVISIBLE)
+ if (simple->visibility <= GOO_CANVAS_ITEM_INVISIBLE)
gtk_widget_hide (widget);
else
gtk_widget_show (widget);
@@ -308,7 +305,7 @@ goo_canvas_widget_get_property (GObject *object,
g_value_set_enum (value, witem->anchor);
break;
case PROP_VISIBILITY:
- g_value_set_enum (value, simple->simple_data->visibility);
+ g_value_set_enum (value, simple->visibility);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@@ -347,8 +344,8 @@ goo_canvas_widget_set_property (GObject *object,
witem->anchor = g_value_get_enum (value);
break;
case PROP_VISIBILITY:
- simple->simple_data->visibility = g_value_get_enum (value);
- if (simple->simple_data->visibility <= GOO_CANVAS_ITEM_INVISIBLE)
+ simple->visibility = g_value_get_enum (value);
+ if (simple->visibility <= GOO_CANVAS_ITEM_INVISIBLE)
gtk_widget_hide (witem->widget);
else
gtk_widget_show (witem->widget);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]