1 #include "goocanvas-perl.h"
2 
3 MODULE = Goo::Canvas::Item		PACKAGE = Goo::Canvas::Item   PREFIX = goo_canvas_item_
4 
5 GooCanvas*
6 goo_canvas_item_get_canvas(item)
7     GooCanvasItem *item
8 
9 void
10 goo_canvas_item_set_canvas(item, canvas)
11     GooCanvasItem *item
12     GooCanvas *canvas
13 
14 GooCanvasItem*
15 goo_canvas_item_get_parent(item)
16     GooCanvasItem *item
17 
18 void
19 goo_canvas_item_set_parent(item, parent)
20     GooCanvasItem *item
21     GooCanvasItem *parent
22 
23 GooCanvasItemModel*
24 goo_canvas_item_get_model(item)
25     GooCanvasItem *item
26 
27 void
28 goo_canvas_item_set_model(item, model)
29     GooCanvasItem *item
30     GooCanvasItemModel *model
31 
32 gboolean
33 goo_canvas_item_is_container(item)
34     GooCanvasItem *item
35 
36 gint
37 goo_canvas_item_get_n_children(item)
38     GooCanvasItem *item
39 
40 GooCanvasItem*
41 goo_canvas_item_get_child(item, child_num)
42     GooCanvasItem *item
43     gint child_num
44 
45 gint
46 goo_canvas_item_find_child(item, child)
47     GooCanvasItem *item
48     GooCanvasItem *child
49 
50 void
51 goo_canvas_item_add_child(item, child, position)
52     GooCanvasItem *item
53     GooCanvasItem *child
54     gint position
55 
56 void
57 goo_canvas_item_move_child(item, old_position, new_position)
58     GooCanvasItem *item
59     gint old_position
60     gint new_position
61 
62 void
63 goo_canvas_item_remove_child(item, child_num)
64     GooCanvasItem *item
65     gint child_num
66 
67 gboolean
68 goo_canvas_item_get_transform_for_child(item, child, transform)
69     GooCanvasItem *item
70     GooCanvasItem *child
71     cairo_matrix_t *transform
72 
73 void
74 goo_canvas_item_raise(item, ...)
75     GooCanvasItem *item
76    CODE:
77     if ( items == 1 )
78         goo_canvas_item_raise(item, NULL);
79     else
80         goo_canvas_item_raise(item, SvGooCanvasItem (ST(1)));
81 
82 void
83 goo_canvas_item_lower(item, ...)
84     GooCanvasItem *item
85    CODE:
86     if ( items == 1 )
87        goo_canvas_item_lower(item, NULL);
88     else
89        goo_canvas_item_lower(item, SvGooCanvasItem (ST(1)));
90 
91 void
92 goo_canvas_item_get_transform(item)
93     GooCanvasItem *item
94    PREINIT:
95     gboolean ret;
96     cairo_matrix_t *transform;
97    PPCODE:
98     ret = goo_canvas_item_get_transform(item, transform);
99     if ( ret ) {
100         ST(0) = newSVCairoMatrix (transform);
101         sv_2mortal(ST(0));
102     }
103     else {
104         XSRETURN_UNDEF;
105     }
106 
107 void
108 goo_canvas_item_set_transform(item, matrix)
109     GooCanvasItem *item
110     cairo_matrix_t *matrix
111 
112 void
113 goo_canvas_item_set_simple_transform(item, x, y, scale, rotation)
114     GooCanvasItem *item
115     gdouble x
116     gdouble y
117     gdouble scale
118     gdouble rotation
119 
120 void
121 goo_canvas_item_translate(item, tx, ty)
122     GooCanvasItem *item
123     gdouble tx
124     gdouble ty
125 
126 void
127 goo_canvas_item_scale(item, sx, sy)
128     GooCanvasItem *item
129     gdouble sx
130     gdouble sy
131 
132 void
133 goo_canvas_item_rotate(item, degrees, cx, cy)
134     GooCanvasItem *item
135     gdouble degrees
136     gdouble cx
137     gdouble cy
138 
139 void
140 goo_canvas_item_skew_x(item, degrees, cx, cy)
141     GooCanvasItem *item
142     gdouble degrees
143     gdouble cx
144     gdouble cy
145 
146 void
147 goo_canvas_item_skew_y(item, degrees, cx, cy)
148     GooCanvasItem *item
149     gdouble degrees
150     gdouble cx
151     gdouble cy
152 
153 GooCanvasStyle*
154 goo_canvas_item_get_style(item)
155     GooCanvasItem *item
156 
157 void
158 goo_canvas_item_set_style(item, style)
159     GooCanvasItem *item
160     GooCanvasStyle *style
161 
162 void
163 goo_canvas_item_animate(item, x, y, scale, degrees, absolute, duration, step_time, type)
164     GooCanvasItem *item
165     gdouble x
166     gdouble y
167     gdouble scale
168     gdouble degrees
169     gboolean absolute
170     gint duration
171     gint step_time
172     GooCanvasAnimateType type
173 
174 void
175 goo_canvas_item_stop_animation(item)
176     GooCanvasItem *item
177 
178 void
179 goo_canvas_item_request_update(item)
180     GooCanvasItem *item
181 
182 void
183 goo_canvas_item_ensure_updated(item)
184     GooCanvasItem *item
185 
186 GooCanvasBounds *
187 goo_canvas_item_update(item, entire_tree, cr)
188     GooCanvasItem *item
189     gboolean entire_tree
190     cairo_t *cr
191    CODE:
192     Newx(RETVAL, 1, GooCanvasBounds);
193     goo_canvas_item_update(item, entire_tree, cr, RETVAL);
194    OUTPUT:
195     RETVAL
196 
197 GooCanvasBounds *
198 goo_canvas_item_get_requested_area(item, cr)
199     GooCanvasItem *item
200     cairo_t *cr
201    PREINIT:
202     gboolean ret;
203    CODE:
204     Newx(RETVAL, 1, GooCanvasBounds);
205     ret = goo_canvas_item_get_requested_area(item, cr, RETVAL);
206     if ( !ret ) {
207         Safefree(RETVAL);
208         RETVAL = NULL;
209     }
210    OUTPUT:
211     RETVAL
212 
213 void
214 goo_canvas_item_allocate_area(item, cr, requested_area, allocated_area, x_offset, y_offset)
215     GooCanvasItem *item
216     cairo_t *cr
217     GooCanvasBounds *requested_area
218     GooCanvasBounds *allocated_area
219     gdouble x_offset
220     gdouble y_offset
221 
222 GooCanvasBounds*
223 goo_canvas_item_get_bounds(item)
224     GooCanvasItem *item
225    CODE:
226     Newx(RETVAL, 1, GooCanvasBounds);
227     goo_canvas_item_get_bounds(item, RETVAL);
228    OUTPUT:
229     RETVAL
230 
231 AV*
goo_canvas_item_get_items_at(item,x,y,cr,is_pointer_event,parent_is_visible)232 goo_canvas_item_get_items_at(item, x, y, cr, is_pointer_event, parent_is_visible)
233     GooCanvasItem *item
234     gdouble x
235     gdouble y
236     cairo_t *cr
237     gboolean is_pointer_event
238     gboolean parent_is_visible
239   PREINIT:
240     GList *list, *i;
241   CODE:
242     list = goo_canvas_item_get_items_at(item, x, y, cr, is_pointer_event, parent_is_visible, NULL);
243     RETVAL = newAV();
244     for ( i = list; i != NULL; i = i->next ) {
245         av_push(RETVAL, newSVGooCanvasItem((GooCanvasItem*)i->data));
246     }
247     sv_2mortal((SV*)RETVAL);
248   OUTPUT:
249     RETVAL
250   CLEANUP:
251     g_list_free (list);
252 
253 gboolean
254 goo_canvas_item_is_visible(item)
255     GooCanvasItem *item
256 
257 void
258 goo_canvas_item_paint(item, cr, bounds, scale)
259     GooCanvasItem *item
260     cairo_t *cr
261     GooCanvasBounds *bounds
262     gdouble scale
263 
264 void
265 goo_canvas_item_set_child_properties(item, child, ...)
266     GooCanvasItem *item
267     GooCanvasItem *child
268    PREINIT:
269     GParamSpec *pspec;
270     GValue value = {0,};
271     int i;
272    CODE:
273     if ( 0 != items % 2 )
274         croak ("set_child_properties: expects name => value pairs"
275                "(odd number of arguments detected)");
276     for ( i = 2; i < items; i+= 2 ) {
277         char* name = SvPV_nolen(ST(i));
278         SV *newval = ST(i+1);
279         pspec = goo_canvas_item_class_find_child_property(
280             (GObjectClass*)g_type_class_peek(G_OBJECT_TYPE (G_OBJECT(item))),  name);
281         if ( !pspec ) {
282             const char* classname =
283                 gperl_object_package_from_type(G_OBJECT_TYPE (G_OBJECT(item)));
284             if ( !classname )
285                 classname = G_OBJECT_TYPE_NAME(G_OBJECT(item));
286             croak("type %s does not support property '%s'",
287                   classname, name);
288         }
289         g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (pspec));
290         gperl_value_from_sv (&value, newval);
291         if ( G_IS_PARAM_SPEC_BOOLEAN(pspec) ) {
292             goo_canvas_item_set_child_properties(item, child, name, g_value_get_boolean(&value), NULL);
293         } else if ( G_IS_PARAM_SPEC_CHAR(pspec) ) {
294             goo_canvas_item_set_child_properties(item, child, name, g_value_get_char(&value), NULL);
295         } else if ( G_IS_PARAM_SPEC_UCHAR(pspec) ) {
296             goo_canvas_item_set_child_properties(item, child, name, g_value_get_uchar(&value), NULL);
297         } else if ( G_IS_PARAM_SPEC_INT(pspec) ) {
298             goo_canvas_item_set_child_properties(item, child, name, g_value_get_int(&value), NULL);
299         } else if ( G_IS_PARAM_SPEC_UINT(pspec) ) {
300             goo_canvas_item_set_child_properties(item, child, name, g_value_get_uint(&value), NULL);
301         } else if ( G_IS_PARAM_SPEC_LONG(pspec) ) {
302             goo_canvas_item_set_child_properties(item, child, name, g_value_get_long(&value), NULL);
303         } else if ( G_IS_PARAM_SPEC_ULONG(pspec) ) {
304             goo_canvas_item_set_child_properties(item, child, name, g_value_get_ulong(&value), NULL);
305         } else if ( G_IS_PARAM_SPEC_INT64(pspec) ) {
306             goo_canvas_item_set_child_properties(item, child, name, g_value_get_int64(&value), NULL);
307         } else if ( G_IS_PARAM_SPEC_UINT64(pspec) ) {
308             goo_canvas_item_set_child_properties(item, child, name, g_value_get_uint64(&value), NULL);
309         } else if ( G_IS_PARAM_SPEC_FLOAT(pspec) ) {
310             goo_canvas_item_set_child_properties(item, child, name, g_value_get_float(&value), NULL);
311         } else if ( G_IS_PARAM_SPEC_DOUBLE(pspec) ) {
312             goo_canvas_item_set_child_properties(item, child, name, g_value_get_double(&value), NULL);
313         } else if ( G_IS_PARAM_SPEC_ENUM(pspec) ) {
314             goo_canvas_item_set_child_properties(item, child, name, g_value_get_enum(&value), NULL);
315         } else if ( G_IS_PARAM_SPEC_FLAGS(pspec) ) {
316             goo_canvas_item_set_child_properties(item, child, name, g_value_get_flags(&value), NULL);
317         } else if ( G_IS_PARAM_SPEC_STRING(pspec) ) {
318             goo_canvas_item_set_child_properties(item, child, name, g_value_get_string(&value), NULL);
319         } else if ( G_IS_PARAM_SPEC_PARAM(pspec) ) {
320             goo_canvas_item_set_child_properties(item, child, name, g_value_get_param(&value), NULL);
321         } else if ( G_IS_PARAM_SPEC_BOXED(pspec) ) {
322             goo_canvas_item_set_child_properties(item, child, name, g_value_get_boxed(&value), NULL);
323         } else if ( G_IS_PARAM_SPEC_POINTER(pspec) ) {
324             goo_canvas_item_set_child_properties(item, child, name, g_value_get_pointer(&value), NULL);
325         } else if ( G_IS_PARAM_SPEC_OBJECT(pspec) ) {
326             goo_canvas_item_set_child_properties(item, child, name, g_value_get_object(&value), NULL);
327         } else if ( G_IS_PARAM_SPEC_UNICHAR(pspec) ) {
328             goo_canvas_item_set_child_properties(item, child, name, g_value_get_uint(&value), NULL);
329         } else if ( G_IS_PARAM_SPEC_VALUE_ARRAY(pspec) ) {
330             goo_canvas_item_set_child_properties(item, child, name, g_value_get_boxed(&value), NULL);
331         } else if ( G_IS_PARAM_SPEC_GTYPE(pspec) ) {
332             goo_canvas_item_set_child_properties(item, child, name, g_value_get_gtype(&value), NULL);
333         }
334         g_value_unset (&value);
335     }
336 
337 =for apidoc
338 Not like the original C function, which call as
339 goo_canvas_item_get_child_properties(item, child, key1, &val1, key2,
340 &val2, ..., NULL). This function call as
341 $item->get_child_properties($child, $key1, $key2, ...) and return a list
342 ($key1, $val1, $key2, $val2, ...) instead. So you can call like
343 %pair = $item->get_child_properties($child, $key1, $key2) and use $pair{$key1} and $pair{$key2} to access the value for the property.
344 =cut
345 void
346 goo_canvas_item_get_child_properties(item, child, ...)
347     GooCanvasItem *item
348     GooCanvasItem *child
349    PREINIT:
350     GParamSpec *pspec;
351     GValue value = {0,};
352     int i;
353    PPCODE:
354     for ( i = 2; i < items; i++ ) {
355         char* name = SvPV_nolen(ST(i));
356         SV* pval;
357         pspec = goo_canvas_item_class_find_child_property(
358             (GObjectClass*)g_type_class_peek(G_OBJECT_TYPE (G_OBJECT(item))),  name);
359         if ( !pspec ) {
360             const char* classname =
361                 gperl_object_package_from_type(G_OBJECT_TYPE (G_OBJECT(item)));
362             if ( !classname )
363                 classname = G_OBJECT_TYPE_NAME(G_OBJECT(item));
364             croak("type %s does not support property '%s'",
365                   classname, name);
366         }
367         g_value_init (&value, G_PARAM_SPEC_VALUE_TYPE (pspec));
368         if ( G_IS_PARAM_SPEC_BOOLEAN(pspec) ) {
369            gboolean val;
370            goo_canvas_item_get_child_properties(item, child, name, &val, NULL);
371            g_value_set_boolean(&value, val);
372         } else if ( G_IS_PARAM_SPEC_CHAR(pspec) ) {
373            gchar val;
374            goo_canvas_item_get_child_properties(item, child, name, &val, NULL);
375            g_value_set_char(&value, val);
376         } else if ( G_IS_PARAM_SPEC_UCHAR(pspec) ) {
377            guchar val;
378            goo_canvas_item_get_child_properties(item, child, name, &val, NULL);
379            g_value_set_uchar(&value, val);
380         } else if ( G_IS_PARAM_SPEC_INT(pspec) ) {
381            gint val;
382            goo_canvas_item_get_child_properties(item, child, name, &val, NULL);
383            g_value_set_int(&value, val);
384         } else if ( G_IS_PARAM_SPEC_UINT(pspec) ) {
385            guint val;
386            goo_canvas_item_get_child_properties(item, child, name, &val, NULL);
387            g_value_set_uint(&value, val);
388         } else if ( G_IS_PARAM_SPEC_LONG(pspec) ) {
389            glong val;
390            goo_canvas_item_get_child_properties(item, child, name, &val, NULL);
391            g_value_set_long(&value, val);
392         } else if ( G_IS_PARAM_SPEC_ULONG(pspec) ) {
393            gulong val;
394            goo_canvas_item_get_child_properties(item, child, name, &val, NULL);
395            g_value_set_ulong(&value, val);
396         } else if ( G_IS_PARAM_SPEC_INT64(pspec) ) {
397            gint64 val;
398            goo_canvas_item_get_child_properties(item, child, name, &val, NULL);
399            g_value_set_int64(&value, val);
400         } else if ( G_IS_PARAM_SPEC_UINT64(pspec) ) {
401            guint64 val;
402            goo_canvas_item_get_child_properties(item, child, name, &val, NULL);
403            g_value_set_uint64(&value, val);
404         } else if ( G_IS_PARAM_SPEC_FLOAT(pspec) ) {
405            gfloat val;
406            goo_canvas_item_get_child_properties(item, child, name, &val, NULL);
407            g_value_set_float(&value, val);
408         } else if ( G_IS_PARAM_SPEC_DOUBLE(pspec) ) {
409            gdouble val;
410            goo_canvas_item_get_child_properties(item, child, name, &val, NULL);
411            g_value_set_double(&value, val);
412         } else if ( G_IS_PARAM_SPEC_ENUM(pspec) ) {
413            gint val;
414            goo_canvas_item_get_child_properties(item, child, name, &val, NULL);
415            g_value_set_enum(&value, val);
416         } else if ( G_IS_PARAM_SPEC_FLAGS(pspec) ) {
417            guint val;
418            goo_canvas_item_get_child_properties(item, child, name, &val, NULL);
419            g_value_set_flags(&value, val);
420         } else if ( G_IS_PARAM_SPEC_STRING(pspec) ) {
421            gchar* val;
422            goo_canvas_item_get_child_properties(item, child, name, &val, NULL);
423            g_value_set_string(&value, val);
424         } else if ( G_IS_PARAM_SPEC_PARAM(pspec) ) {
425            GParamSpec* val;
426            goo_canvas_item_get_child_properties(item, child, name, &val, NULL);
427            g_value_set_param(&value, val);
428         } else if ( G_IS_PARAM_SPEC_BOXED(pspec) ) {
429            gpointer val;
430            goo_canvas_item_get_child_properties(item, child, name, &val, NULL);
431            g_value_set_boxed(&value, val);
432         } else if ( G_IS_PARAM_SPEC_POINTER(pspec) ) {
433            gpointer val;
434            goo_canvas_item_get_child_properties(item, child, name, &val, NULL);
435            g_value_set_pointer(&value, val);
436         } else if ( G_IS_PARAM_SPEC_OBJECT(pspec) ) {
437            gpointer val;
438            goo_canvas_item_get_child_properties(item, child, name, &val, NULL);
439            g_value_set_object(&value, val);
440         } else if ( G_IS_PARAM_SPEC_UNICHAR(pspec) ) {
441            guint val;
442            goo_canvas_item_get_child_properties(item, child, name, &val, NULL);
443            g_value_set_uint(&value, val);
444         } else if ( G_IS_PARAM_SPEC_VALUE_ARRAY(pspec) ) {
445            gpointer val;
446            goo_canvas_item_get_child_properties(item, child, name, &val, NULL);
447            g_value_set_boxed(&value, val);
448         } else if ( G_IS_PARAM_SPEC_GTYPE(pspec) ) {
449            GType val;
450            goo_canvas_item_get_child_properties(item, child, name, &val, NULL);
451            g_value_set_gtype(&value, val);
452         }
453         pval = gperl_sv_from_value(&value);
454         g_value_unset (&value);
455         mXPUSHp(name, strlen(name));
456         XPUSHs(pval);
457     }
458