1 | /* gnome-canvas-support.c -- helper functions for GNOME Canvas binding |
---|
2 | $Id: gnome-canvas-support.c,v 1.1.1.1 2000-11-12 06:16:30 ghudson Exp $ */ |
---|
3 | |
---|
4 | #include <config.h> |
---|
5 | #include <assert.h> |
---|
6 | #include <gnome.h> |
---|
7 | #include "rep-gtk.h" |
---|
8 | #include "rep-gnome.h" |
---|
9 | #include <string.h> |
---|
10 | |
---|
11 | static int |
---|
12 | list_length (repv list) |
---|
13 | { |
---|
14 | repv len = Flength (list); |
---|
15 | return (len && rep_INTP (len)) ? rep_INT (len) : 0; |
---|
16 | } |
---|
17 | |
---|
18 | DEFUN ("gnome-canvas-item-new", Fgnome_canvas_item_new, |
---|
19 | Sgnome_canvas_item_new, (repv p_group, repv type_sym, repv scm_args), |
---|
20 | rep_Subr3) |
---|
21 | { |
---|
22 | /* from guile-gnome/gnomeg.c */ |
---|
23 | |
---|
24 | GnomeCanvasItem* cr_ret; |
---|
25 | GnomeCanvasGroup* c_group; |
---|
26 | |
---|
27 | int n_args; |
---|
28 | sgtk_object_info *info; |
---|
29 | GtkArg *args; |
---|
30 | |
---|
31 | rep_DECLARE (1, p_group, sgtk_is_a_gtkobj (gnome_canvas_group_get_type (), p_group)); |
---|
32 | rep_DECLARE (2, type_sym, rep_SYMBOLP(type_sym)); |
---|
33 | n_args = list_length (scm_args); |
---|
34 | rep_DECLARE (3, scm_args, n_args >= 0 && (n_args%2) == 0); |
---|
35 | n_args = n_args/2; |
---|
36 | |
---|
37 | info = sgtk_find_object_info (rep_STR(rep_SYM(type_sym)->name)); |
---|
38 | rep_DECLARE (2, type_sym, info != NULL); |
---|
39 | |
---|
40 | c_group = (GnomeCanvasGroup*)sgtk_get_gtkobj (p_group); |
---|
41 | args = sgtk_build_args (info, &n_args, scm_args, Qnil, |
---|
42 | (char *) &Sgnome_canvas_item_new); |
---|
43 | cr_ret = gnome_canvas_item_newv (c_group, info->header.type, n_args, args); |
---|
44 | g_free (args); |
---|
45 | |
---|
46 | return sgtk_wrap_gtkobj ((GtkObject*)cr_ret); |
---|
47 | } |
---|
48 | |
---|
49 | DEFUN ("gnome-canvas-item-set", Fgnome_canvas_item_set, |
---|
50 | Sgnome_canvas_item_set, (repv p_item, repv scm_args), rep_Subr2) |
---|
51 | { |
---|
52 | /* from guile-gnome/gnomeg.c */ |
---|
53 | |
---|
54 | GnomeCanvasItem* c_item; |
---|
55 | int n_args; |
---|
56 | sgtk_object_info *info; |
---|
57 | GtkArg *args; |
---|
58 | |
---|
59 | rep_DECLARE (1, p_item, sgtk_is_a_gtkobj (gnome_canvas_item_get_type (), p_item)); |
---|
60 | n_args = list_length (scm_args); |
---|
61 | rep_DECLARE (2, scm_args, n_args >= 0 && (n_args%2) == 0); |
---|
62 | n_args = n_args/2; |
---|
63 | |
---|
64 | c_item = (GnomeCanvasItem*)sgtk_get_gtkobj (p_item); |
---|
65 | info = sgtk_find_object_info_from_type (GTK_OBJECT_TYPE(c_item)); |
---|
66 | rep_DECLARE (1, p_item, info != NULL); |
---|
67 | |
---|
68 | args = sgtk_build_args (info, &n_args, scm_args, p_item, |
---|
69 | (char *) &Sgnome_canvas_item_set); |
---|
70 | gnome_canvas_item_setv (c_item, n_args, args); |
---|
71 | g_free (args); |
---|
72 | |
---|
73 | return Qnil; |
---|
74 | } |
---|
75 | |
---|
76 | GnomeCanvasPoints * |
---|
77 | sgtk_gnome_canvas_points_new (repv data) |
---|
78 | { |
---|
79 | repv len = Flength (data); |
---|
80 | if (len && rep_INT (len) % 2 == 0) |
---|
81 | { |
---|
82 | int i, count = rep_INT (len); |
---|
83 | GnomeCanvasPoints *p = gnome_canvas_points_new (count / 2); |
---|
84 | if (rep_CONSP (data)) |
---|
85 | { |
---|
86 | for (i = 0; i < count; i++) |
---|
87 | { |
---|
88 | p->coords[i] = sgtk_rep_to_double (rep_CAR (data)); |
---|
89 | data = rep_CDR (data); |
---|
90 | } |
---|
91 | } |
---|
92 | else if (rep_VECTORP (data)) |
---|
93 | { |
---|
94 | for (i = 0; i < count; i++) |
---|
95 | p->coords[i] = sgtk_rep_to_double (rep_VECTI (data, i)); |
---|
96 | } |
---|
97 | return p; |
---|
98 | } |
---|
99 | else |
---|
100 | return 0; |
---|
101 | } |
---|
102 | |
---|
103 | repv |
---|
104 | sgtk_gnome_canvas_points_conversion (repv arg) |
---|
105 | { |
---|
106 | extern repv Fgnome_canvas_points_new (repv); |
---|
107 | |
---|
108 | if (rep_LISTP (arg) || rep_VECTORP (arg)) |
---|
109 | return Fgnome_canvas_points_new (arg); |
---|
110 | else |
---|
111 | return arg; |
---|
112 | } |
---|
113 | |
---|
114 | |
---|
115 | /* dl hooks / init */ |
---|
116 | |
---|
117 | repv |
---|
118 | rep_dl_init (void) |
---|
119 | { |
---|
120 | repv s = rep_push_structure ("gui.gnome.canvas"); |
---|
121 | /* ::alias:gnome-canvas gui.gnome.canvas:: */ |
---|
122 | rep_alias_structure ("gnome-canvas"); |
---|
123 | sgtk_gnome_init_gnome_canvas_glue (); |
---|
124 | rep_ADD_SUBR (Sgnome_canvas_item_new); |
---|
125 | rep_ADD_SUBR (Sgnome_canvas_item_set); |
---|
126 | return rep_pop_structure (s); |
---|
127 | } |
---|