1 /* Written by Erik Walthinsen 06-2001 */
2 /* Modified by Jamie Gennis 06-2001 */
6 #include "gobject2gtk.h"
9 /* list functions not in glib 1.2 */
11 g_list_delete_link (GList *list, GList *llink)
13 GList *temp = g_list_remove_link(list, llink);
19 g_slist_delete_link (GSList *list, GSList *llink)
21 GSList *temp = g_slist_remove_link(list, llink);
26 /* string helper functions not in glib 1.2 */
29 g_strcanon (gchar *string,
30 const gchar *valid_chars,
35 g_return_val_if_fail (string != NULL, NULL);
36 g_return_val_if_fail (valid_chars != NULL, NULL);
38 for (c = string; *c; c++)
40 if (!strchr (valid_chars, *c))
47 /* GObject dummy implementation */
49 g_object_set_arg(GtkObject *object, GtkArg *arg, guint id)
51 ((GObjectClass *)object->klass)->set_property((GObject *)object,id,arg,NULL);
55 g_object_get_arg(GtkObject *object, GtkArg *arg, guint id)
57 ((GObjectClass *)object->klass)->get_property((GObject *)object,id,arg,NULL);
61 g_object_base_class_init (GObjectClass *klass)
63 GtkObjectClass *gtkobject_class;
65 gtkobject_class = (GtkObjectClass*) klass;
67 gtkobject_class->set_arg = g_object_set_arg;
68 gtkobject_class->get_arg = g_object_get_arg;
72 g2g_object_run_dispose (GObject *object)
74 g_return_if_fail (G_IS_OBJECT (object));
75 g_return_if_fail (object->ref_count > 0);
77 g_object_ref (object);
78 G_OBJECT_GET_CLASS (object)->dispose (object);
79 g_object_unref (object);
83 g2g_object_get_type (void)
85 static GType object_type = 0;
88 static const GtkTypeInfo object_info = {
92 (GtkClassInitFunc)NULL,
93 (GtkObjectInitFunc)NULL,
96 (GtkClassInitFunc)g_object_base_class_init,
98 object_type = gtk_type_unique(gtk_object_get_type(),&object_info);
107 g2g_type_register_static (GtkType parent_type, gchar *type_name,
108 const GTypeInfo *info, guint flags)
110 GtkTypeInfo gtkinfo = {
120 return gtk_type_unique(parent_type,>kinfo);
125 g2g_object_new(GtkType type,gpointer blah_varargs_stuff) {
126 return gtk_type_new(type);
131 g2g_object_class_install_property(GObjectClass *oclass,guint property_id,GParamSpec *pspec)
135 arg_fullname = g_strdup_printf("%s::%s",gtk_type_name(oclass->type),pspec->name);
136 /* fprintf(stderr,"installing arg \"%s\" into class \"%s\"\n",arg_fullname,""); */
137 gtk_object_add_arg_type(arg_fullname,pspec->value_type,pspec->flags,property_id);
142 g2g_object_class_find_property(GObjectClass *class, const gchar *name)
147 /* fprintf(stderr,"class name is %s\n",gtk_type_name(class->type)); */
149 /* the return value NULL if no error */
150 if (gtk_object_arg_get_info(class->type,name,&info) != NULL) {
154 spec = g_new0(GParamSpec,1);
156 spec->name = (gchar *) name;
157 spec->value_type = info->type;
158 spec->flags = info->arg_flags;
164 g2g_object_class_list_properties(GObjectClass *oclass,guint *n_properties) {
165 GType type = G_OBJECT_CLASS_TYPE (oclass);
172 args = gtk_object_query_args (type, &flags, &num_args);
173 /* FIXME: args and flags need to be freed. */
175 params = g_new0(GParamSpec *,num_args);
176 for (i=0;i<num_args;i++) {
177 params[i] = g_new0(GParamSpec,1);
178 params[i]->name = args[i].name;
179 params[i]->value_type = args[i].type;
180 params[i]->flags = flags[i];
183 *n_properties = num_args;
189 g2g_param_spec_boolean(gchar *name,gchar *nick,gchar *blurb,gboolean def,gint flags) {
190 GParamSpec *spec = g_new(GParamSpec,1);
193 spec->value_type = GTK_TYPE_BOOL;
200 g2g_param_spec_enum(gchar *name,gchar *nick,gchar *blurb,GtkType e,guint def,gint flags) {
201 GParamSpec *spec = g_new(GParamSpec,1);
204 spec->value_type = e;
211 g2g_param_spec_int(gchar *name,gchar *nick,gchar *blurb,gint min,gint max,gint def,gint flags) {
212 GParamSpec *spec = g_new(GParamSpec,1);
215 spec->value_type = GTK_TYPE_INT;
222 g2g_param_spec_uint(gchar *name,gchar *nick,gchar *blurb,guint min,guint max,guint def,gint flags) {
223 GParamSpec *spec = g_new(GParamSpec,1);
226 spec->value_type = GTK_TYPE_UINT;
233 g2g_param_spec_long(gchar *name,gchar *nick,gchar *blurb,glong min,glong max,glong def,gint flags) {
234 GParamSpec *spec = g_new(GParamSpec,1);
237 spec->value_type = GTK_TYPE_LONG;
244 g2g_param_spec_ulong(gchar *name,gchar *nick,gchar *blurb,gulong min,gulong max,gulong def,gint flags) {
245 GParamSpec *spec = g_new(GParamSpec,1);
248 spec->value_type = GTK_TYPE_ULONG;
255 g2g_param_spec_float(gchar *name,gchar *nick,gchar *blurb,float min,float max,float def,gint flags) {
256 GParamSpec *spec = g_new(GParamSpec,1);
259 spec->value_type = GTK_TYPE_FLOAT;
266 g2g_param_spec_double(gchar *name,gchar *nick,gchar *blurb,double min,double max,double def,gint flags) {
267 GParamSpec *spec = g_new(GParamSpec,1);
270 spec->value_type = GTK_TYPE_DOUBLE;
277 g2g_param_spec_pointer(gchar *name,gchar *nick,gchar *blurb,gint flags) {
278 GParamSpec *spec = g_new(GParamSpec,1);
281 spec->value_type = GTK_TYPE_POINTER;
288 g2g_param_spec_string(gchar *name,gchar *nick,gchar *blurb,gchar *def,gint flags) {
289 GParamSpec *spec = g_new(GParamSpec,1);
292 spec->value_type = GTK_TYPE_STRING;
301 g2g_signal_new (const gchar *name,
303 GtkSignalRunType signal_flags,
304 guint function_offset,
305 gpointer accumulator, /* GSignalAccumulator */
307 GtkSignalMarshaller marshaller,
317 if (strcmp (name, "destroy") == 0)
320 #define MAX_SIGNAL_PARAMS (31) /* from gtksignal.c */
321 g_return_val_if_fail (nparams < MAX_SIGNAL_PARAMS, 0);
325 params = g_new (GtkType, nparams);
327 va_start (args, nparams);
329 for (i = 0; i < nparams; i++)
330 params[i] = va_arg (args, GtkType);
337 signal_id = gtk_signal_newv (name,
348 /* now register it. */
349 gtk_object_class_add_signals(gtk_type_class(object_type), &signal_id, 1);
354 gint* g_signal_list_ids (GType type, guint *n_ids)
356 GtkObjectClass *class;
358 class = gtk_type_class (type);
360 *n_ids = class->nsignals;
362 return class->signals;