1 /*
2  * GooCanvas. Copyright (C) 2005 Damon Chaplin.
3  * Released under the GNU LGPL license. See COPYING for details.
4  *
5  * goocanvasitemmodel.h - interface for canvas item models.
6  */
7 #ifndef __GOO_CANVAS_ITEM_MODEL_H__
8 #define __GOO_CANVAS_ITEM_MODEL_H__
9 
10 #include <gtk/gtk.h>
11 #include "goocanvasitem.h"
12 
13 G_BEGIN_DECLS
14 
15 
16 #define GOO_TYPE_CANVAS_ITEM_MODEL            (goo_canvas_item_model_get_type ())
17 #define GOO_CANVAS_ITEM_MODEL(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GOO_TYPE_CANVAS_ITEM_MODEL, GooCanvasItemModel))
18 #define GOO_IS_CANVAS_ITEM_MODEL(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GOO_TYPE_CANVAS_ITEM_MODEL))
19 #define GOO_CANVAS_ITEM_MODEL_GET_IFACE(obj)  (G_TYPE_INSTANCE_GET_INTERFACE ((obj), GOO_TYPE_CANVAS_ITEM_MODEL, GooCanvasItemModelIface))
20 
21 
22 /**
23  * GooCanvasItemModel
24  *
25  * #GooCanvasItemModel is a typedef used for objects that implement the
26  * #GooCanvasItemModel interface.
27  *
28  * (There is no actual #GooCanvasItemModel struct, since it is only an interface.
29  * But using '#GooCanvasItemModel' is more helpful than using '#GObject'.)
30  */
31 /* The typedef is in goocanvasitem.h */
32 /*typedef struct _GooCanvasItemModel       GooCanvasItemModel;*/
33 
34 
35 /**
36  * GooCanvasItemModelIface
37  * @get_n_children: returns the number of children of the model.
38  * @get_child: returns the child at the given index.
39  * @add_child: adds a child.
40  * @move_child: moves a child up or down the stacking order.
41  * @remove_child: removes a child.
42  * @get_child_property: gets a child property of a given child model,
43  *  e.g. the "row" or "column" property of a model in a #GooCanvasTableModel.
44  * @set_child_property: sets a child property for a given child model.
45  * @get_parent: gets the model's parent.
46  * @set_parent: sets the model's parent.
47  * @create_item: creates a default canvas item to view the model.
48  * @get_transform: gets the model's transformation matrix.
49  * @set_transform: sets the model's transformation matrix.
50  * @get_style: gets the model's style.
51  * @set_style: sets the model's style.
52  * @child_added: signal emitted when a child is added.
53  * @child_moved: signal emitted when a child is moved in the stacking order.
54  * @child_removed: signal emitted when a child is removed.
55  * @changed: signal emitted when the model has changed.
56  * @child_notify: signal emitted when a child property has changed.
57  * @animation_finished: signal emitted when the model's animation has finished.
58  *
59  * #GooCanvasItemModelIFace holds the virtual methods that make up the
60  * #GooCanvasItemModel interface.
61  *
62  * Simple item models only need to implement the get_parent(), set_parent()
63  * and create_item() methods.
64  *
65  * Items that support transforms should also implement get_transform() and
66  * set_transform(). Items that support styles should implement get_style()
67  * and set_style().
68  *
69  * Container items must implement get_n_children() and get_child().
70  * Containers that support dynamic changes to their children should implement
71  * add_child(), move_child() and remove_child().
72  * Layout containers like #GooCanvasTable may implement
73  * get_child_property() and set_child_property().
74  */
75 typedef struct _GooCanvasItemModelIface  GooCanvasItemModelIface;
76 
77 struct _GooCanvasItemModelIface
78 {
79   /*< private >*/
80   GTypeInterface base_iface;
81 
82   /*< public >*/
83   /* Virtual methods that group models must implement. */
84   gint		       (* get_n_children)		(GooCanvasItemModel	*model);
85   GooCanvasItemModel*  (* get_child)			(GooCanvasItemModel	*model,
86 							 gint			 child_num);
87 
88   /* Virtual methods that group models may implement. */
89   void                 (* add_child)			(GooCanvasItemModel	*model,
90 							 GooCanvasItemModel	*child,
91 							 gint			 position);
92   void                 (* move_child)			(GooCanvasItemModel	*model,
93 							 gint			 old_position,
94 							 gint			 new_position);
95   void                 (* remove_child)			(GooCanvasItemModel	*model,
96 							 gint			 child_num);
97   void                 (* get_child_property)		(GooCanvasItemModel	*model,
98 							 GooCanvasItemModel	*child,
99 							 guint			 property_id,
100 							 GValue			*value,
101 							 GParamSpec		*pspec);
102   void                 (* set_child_property)		(GooCanvasItemModel	*item,
103 							 GooCanvasItemModel	*child,
104 							 guint			 property_id,
105 							 const GValue		*value,
106 							 GParamSpec		*pspec);
107 
108   /* Virtual methods that all item models must implement. */
109   GooCanvasItemModel*  (* get_parent)			(GooCanvasItemModel	*model);
110   void                 (* set_parent)			(GooCanvasItemModel	*model,
111 							 GooCanvasItemModel	*parent);
112 
113   GooCanvasItem*       (* create_item)			(GooCanvasItemModel	*model,
114 							 GooCanvas		*canvas);
115 
116   /* Virtual methods that all item models may implement. */
117   gboolean             (* get_transform)		(GooCanvasItemModel	*model,
118 							 cairo_matrix_t         *transform);
119   void                 (* set_transform)		(GooCanvasItemModel	*model,
120 							 const cairo_matrix_t	*transform);
121   GooCanvasStyle*      (* get_style)			(GooCanvasItemModel	*model);
122   void                 (* set_style)			(GooCanvasItemModel	*model,
123 							 GooCanvasStyle		*style);
124 
125   /* Signals. */
126   void                 (* child_added)			(GooCanvasItemModel	*model,
127 							 gint			 child_num);
128   void                 (* child_moved)			(GooCanvasItemModel	*model,
129 							 gint			 old_child_num,
130 							 gint			 new_child_num);
131   void                 (* child_removed)		(GooCanvasItemModel	*model,
132 							 gint			 child_num);
133   void                 (* changed)			(GooCanvasItemModel	*model,
134 							 gboolean		 recompute_bounds);
135   void                 (* child_notify)			(GooCanvasItemModel	*model,
136 							 GParamSpec		*pspec);
137 
138   void		       (* animation_finished)		(GooCanvasItemModel     *model,
139 							 gboolean                stopped);
140 
141   /*< private >*/
142 
143   /* Padding for future expansion */
144   void (*_goo_canvas_reserved1) (void);
145   void (*_goo_canvas_reserved2) (void);
146   void (*_goo_canvas_reserved3) (void);
147   void (*_goo_canvas_reserved4) (void);
148   void (*_goo_canvas_reserved5) (void);
149   void (*_goo_canvas_reserved6) (void);
150   void (*_goo_canvas_reserved7) (void);
151 };
152 
153 
154 GType               goo_canvas_item_model_get_type       (void) G_GNUC_CONST;
155 
156 
157 /*
158  * Group functions - these should only be called on container models.
159  */
160 gint                goo_canvas_item_model_get_n_children (GooCanvasItemModel *model);
161 GooCanvasItemModel* goo_canvas_item_model_get_child      (GooCanvasItemModel *model,
162 							  gint                child_num);
163 void                goo_canvas_item_model_add_child      (GooCanvasItemModel *model,
164 							  GooCanvasItemModel *child,
165 							  gint                position);
166 void                goo_canvas_item_model_move_child     (GooCanvasItemModel *model,
167 							  gint                old_position,
168 							  gint                new_position);
169 void                goo_canvas_item_model_remove_child   (GooCanvasItemModel *model,
170 							  gint                child_num);
171 gint                goo_canvas_item_model_find_child     (GooCanvasItemModel *model,
172 							  GooCanvasItemModel *child);
173 
174 void     goo_canvas_item_model_get_child_property	 (GooCanvasItemModel   *model,
175 							  GooCanvasItemModel   *child,
176 							  const gchar          *property_name,
177 							  GValue               *value);
178 void     goo_canvas_item_model_set_child_property	 (GooCanvasItemModel   *model,
179 							  GooCanvasItemModel   *child,
180 							  const gchar          *property_name,
181 							  const GValue         *value);
182 void     goo_canvas_item_model_get_child_properties	 (GooCanvasItemModel   *model,
183 							  GooCanvasItemModel   *child,
184 							  ...) G_GNUC_NULL_TERMINATED;
185 void     goo_canvas_item_model_set_child_properties	 (GooCanvasItemModel   *model,
186 							  GooCanvasItemModel   *child,
187 							  ...) G_GNUC_NULL_TERMINATED;
188 void     goo_canvas_item_model_get_child_properties_valist (GooCanvasItemModel   *model,
189 							    GooCanvasItemModel   *child,
190 							    va_list	         var_args);
191 void     goo_canvas_item_model_set_child_properties_valist (GooCanvasItemModel   *model,
192 							    GooCanvasItemModel   *child,
193 							    va_list	         var_args);
194 
195 
196 /*
197  * Model functions - these are safe to call on all models.
198  */
199 GooCanvasItemModel* goo_canvas_item_model_get_parent     (GooCanvasItemModel *model);
200 void                goo_canvas_item_model_set_parent	 (GooCanvasItemModel *model,
201 							  GooCanvasItemModel *parent);
202 void                goo_canvas_item_model_remove         (GooCanvasItemModel *model);
203 gboolean            goo_canvas_item_model_is_container   (GooCanvasItemModel *model);
204 
205 void                goo_canvas_item_model_raise          (GooCanvasItemModel *model,
206 							  GooCanvasItemModel *above);
207 void                goo_canvas_item_model_lower          (GooCanvasItemModel *model,
208 							  GooCanvasItemModel *below);
209 
210 gboolean            goo_canvas_item_model_get_transform  (GooCanvasItemModel *model,
211 							  cairo_matrix_t     *transform);
212 void                goo_canvas_item_model_set_transform  (GooCanvasItemModel   *model,
213 							  const cairo_matrix_t *transform);
214 gboolean	    goo_canvas_item_model_get_simple_transform (GooCanvasItemModel *model,
215 								gdouble            *x,
216 								gdouble            *y,
217 								gdouble            *scale,
218 								gdouble            *rotation);
219 void                goo_canvas_item_model_set_simple_transform (GooCanvasItemModel *model,
220 								gdouble             x,
221 								gdouble             y,
222 								gdouble             scale,
223 								gdouble             rotation);
224 
225 void                goo_canvas_item_model_translate      (GooCanvasItemModel *model,
226 							  gdouble             tx,
227 							  gdouble             ty);
228 void                goo_canvas_item_model_scale          (GooCanvasItemModel *model,
229 							  gdouble             sx,
230 							  gdouble             sy);
231 void                goo_canvas_item_model_rotate         (GooCanvasItemModel *model,
232 							  gdouble             degrees,
233 							  gdouble             cx,
234 							  gdouble             cy);
235 void                goo_canvas_item_model_skew_x         (GooCanvasItemModel *model,
236 							  gdouble             degrees,
237 							  gdouble             cx,
238 							  gdouble             cy);
239 void                goo_canvas_item_model_skew_y         (GooCanvasItemModel *model,
240 							  gdouble             degrees,
241 							  gdouble             cx,
242 							  gdouble             cy);
243 
244 GooCanvasStyle*     goo_canvas_item_model_get_style      (GooCanvasItemModel *model);
245 void                goo_canvas_item_model_set_style      (GooCanvasItemModel *model,
246 							  GooCanvasStyle  *style);
247 
248 void                goo_canvas_item_model_animate        (GooCanvasItemModel *model,
249 							  gdouble             x,
250 							  gdouble             y,
251 							  gdouble             scale,
252 							  gdouble             degrees,
253 							  gboolean            absolute,
254 							  gint                duration,
255 							  gint                step_time,
256 							  GooCanvasAnimateType type);
257 void                goo_canvas_item_model_stop_animation (GooCanvasItemModel *model);
258 
259 
260 /*
261  * Functions to support child properties when implementing new canvas items.
262  */
263 void         goo_canvas_item_model_class_install_child_property (GObjectClass *mclass,
264 								 guint	 property_id,
265 								 GParamSpec	*pspec);
266 GParamSpec*  goo_canvas_item_model_class_find_child_property	(GObjectClass	*mclass,
267 								 const gchar	*property_name);
268 GParamSpec** goo_canvas_item_model_class_list_child_properties  (GObjectClass	*mclass,
269 								 guint	*n_properties);
270 
271 
272 
273 G_END_DECLS
274 
275 #endif /* __GOO_CANVAS_ITEM_MODEL_H__ */
276