File: gnome-canvas-support.c

package info (click to toggle)
rep-gtk 0.15-3
  • links: PTS
  • area: main
  • in suites: woody
  • size: 728 kB
  • ctags: 349
  • sloc: ansic: 3,577; sh: 2,430; lisp: 1,102; makefile: 159
file content (127 lines) | stat: -rw-r--r-- 3,304 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/* gnome-canvas-support.c -- helper functions for GNOME Canvas binding
   $Id: gnome-canvas-support.c,v 1.4 2000/07/23 22:52:49 john Exp $ */

#include <config.h>
#include <assert.h>
#include <gnome.h>
#include "rep-gtk.h"
#include "rep-gnome.h"
#include <string.h>

static int
list_length (repv list)
{
    repv len = Flength (list);
    return (len && rep_INTP (len)) ? rep_INT (len) : 0;
}

DEFUN ("gnome-canvas-item-new", Fgnome_canvas_item_new,
       Sgnome_canvas_item_new, (repv p_group, repv type_sym, repv scm_args),
       rep_Subr3)
{
    /* from guile-gnome/gnomeg.c */

  GnomeCanvasItem* cr_ret;
  GnomeCanvasGroup* c_group;

  int n_args;
  sgtk_object_info *info;
  GtkArg *args;

  rep_DECLARE (1, p_group, sgtk_is_a_gtkobj (gnome_canvas_group_get_type (), p_group));
  rep_DECLARE (2, type_sym, rep_SYMBOLP(type_sym));
  n_args = list_length (scm_args);
  rep_DECLARE (3, scm_args, n_args >= 0 && (n_args%2) == 0);
  n_args = n_args/2;

  info = sgtk_find_object_info (rep_STR(rep_SYM(type_sym)->name));
  rep_DECLARE (2, type_sym, info != NULL);

  c_group = (GnomeCanvasGroup*)sgtk_get_gtkobj (p_group);
  args = sgtk_build_args (info, &n_args, scm_args, Qnil,
			  (char *) &Sgnome_canvas_item_new);
  cr_ret = gnome_canvas_item_newv (c_group, info->header.type, n_args, args);
  g_free (args);

  return sgtk_wrap_gtkobj ((GtkObject*)cr_ret);
}

DEFUN ("gnome-canvas-item-set", Fgnome_canvas_item_set,
       Sgnome_canvas_item_set, (repv p_item, repv scm_args), rep_Subr2)
{
    /* from guile-gnome/gnomeg.c */

  GnomeCanvasItem* c_item;
  int n_args;
  sgtk_object_info *info;
  GtkArg *args;

  rep_DECLARE (1, p_item, sgtk_is_a_gtkobj (gnome_canvas_item_get_type (), p_item));
  n_args = list_length (scm_args);
  rep_DECLARE (2, scm_args, n_args >= 0 && (n_args%2) == 0);
  n_args = n_args/2;

  c_item = (GnomeCanvasItem*)sgtk_get_gtkobj (p_item);
  info = sgtk_find_object_info_from_type (GTK_OBJECT_TYPE(c_item));
  rep_DECLARE (1, p_item, info != NULL);
  
  args = sgtk_build_args (info, &n_args, scm_args, p_item,
			  (char *) &Sgnome_canvas_item_set);
  gnome_canvas_item_setv (c_item, n_args, args);
  g_free (args);

  return Qnil;
}

GnomeCanvasPoints *
sgtk_gnome_canvas_points_new (repv data)
{
    repv len = Flength (data);
    if (len && rep_INT (len) % 2 == 0)
    {
	int i, count = rep_INT (len);
	GnomeCanvasPoints *p = gnome_canvas_points_new (count / 2);
	if (rep_CONSP (data))
	{
	    for (i = 0; i < count; i++)
	    {
		p->coords[i] = sgtk_rep_to_double (rep_CAR (data));
		data = rep_CDR (data);
	    }
	}
	else if (rep_VECTORP (data))
	{
	    for (i = 0; i < count; i++)
		p->coords[i] = sgtk_rep_to_double (rep_VECTI (data, i));
	}
	return p;
    }
    else
	return 0;
}

repv
sgtk_gnome_canvas_points_conversion (repv arg)
{
    extern repv Fgnome_canvas_points_new (repv);

    if (rep_LISTP (arg) || rep_VECTORP (arg))
	return Fgnome_canvas_points_new (arg);
    else
	return arg;
}


/* dl hooks / init */

repv
rep_dl_init (void)
{
    repv s = rep_push_structure ("gui.gnome.canvas");
    /* ::alias:gnome-canvas gui.gnome.canvas:: */
    rep_alias_structure ("gnome-canvas");
    sgtk_gnome_init_gnome_canvas_glue ();
    rep_ADD_SUBR (Sgnome_canvas_item_new);
    rep_ADD_SUBR (Sgnome_canvas_item_set);
    return rep_pop_structure (s);
}