gobject2gtk.c 7.25 KB
Newer Older
1
2
/* Written by Erik Walthinsen 06-2001 */
/* Modified by Jamie Gennis 06-2001 */
Steve Baker Baker's avatar
Steve Baker Baker committed
3
#include <string.h>
4
#include <stdio.h>
5
#include "gstlog.h"
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
#include "gobject2gtk.h"



// GObject dummy implementation
static void
g_object_set_arg(GtkObject *object, GtkArg *arg, guint id)
{
  ((GObjectClass *)object->klass)->set_property((GObject *)object,id,arg,NULL);
}

static void
g_object_get_arg(GtkObject *object, GtkArg *arg, guint id)
{
  ((GObjectClass *)object->klass)->get_property((GObject *)object,id,arg,NULL);
}

static void
g_object_base_class_init (GObjectClass *klass)
{
  GtkObjectClass *gtkobject_class;

  gtkobject_class = (GtkObjectClass*) klass;
 
  gtkobject_class->set_arg = g_object_set_arg;
  gtkobject_class->get_arg = g_object_get_arg;
}

34
35
36
37
38
39
40
41
42
43
44
void
g2g_object_run_dispose (GObject *object)
{
  g_return_if_fail (G_IS_OBJECT (object));
  g_return_if_fail (object->ref_count > 0);

  g_object_ref (object);
  G_OBJECT_GET_CLASS (object)->dispose (object);
  g_object_unref (object);
}

45
GType
46
g2g_object_get_type (void)
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
{
  static GType object_type = 0;

  if (!object_type) {
    static const GtkTypeInfo object_info = {
      "GObject",
      sizeof(GObject),
      sizeof(GObjectClass),
      (GtkClassInitFunc)NULL,
      (GtkObjectInitFunc)NULL,
      (GtkArgSetFunc)NULL,
      (GtkArgGetFunc)NULL,
      (GtkClassInitFunc)g_object_base_class_init,
    };
    object_type = gtk_type_unique(gtk_object_get_type(),&object_info);
  }
  return object_type;
} 




guint
70
g2g_type_register_static (GtkType parent_type, gchar *type_name,
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
                        const GTypeInfo *info, guint flags)
{
  GtkTypeInfo gtkinfo = {
    type_name,
    info->instance_size,
    info->class_size,
    info->class_init,
    info->instance_init,
    NULL,
    NULL,
    info->base_init,
  };
  return gtk_type_unique(parent_type,&gtkinfo);
}


gpointer
88
g2g_object_new(GtkType type,gpointer blah_varargs_stuff) {
89
90
91
92
93
  return gtk_type_new(type);
}


void
94
g2g_object_class_install_property(GObjectClass *oclass,guint property_id,GParamSpec *pspec)
95
96
97
98
99
100
101
102
103
104
{
  gchar *arg_fullname;
 
  arg_fullname = g_strdup_printf("%s::%s",gtk_type_name(oclass->type),pspec->name);
  //fprintf(stderr,"installing arg \"%s\" into class \"%s\"\n",arg_fullname,"");
  gtk_object_add_arg_type(arg_fullname,pspec->value_type,pspec->flags,property_id);
  g_free(pspec);
}

GParamSpec *
105
g2g_object_class_find_property(GObjectClass *class, const gchar *name)
106
107
108
{
  GtkArgInfo *info;
  GParamSpec *spec;
109

110
111
  //fprintf(stderr,"class name is %s\n",gtk_type_name(class->type));

112
  gtk_object_arg_get_info(class->type,name,&info);
113
114
115
  spec = g_new0(GParamSpec,1);

  if (info) {
116
    spec->name = (gchar *) name;
117
118
119
120
121
122
123
124
125
126
    spec->value_type = info->type;
    spec->flags = info->arg_flags;
  } else {
    spec->value_type = GTK_TYPE_NONE;
  }

  return spec;
}

GParamSpec **
127
g2g_object_class_list_properties(GObjectClass *oclass,guint *n_properties) {
128
129
130
131
132
133
134
135
  GType type = G_OBJECT_CLASS_TYPE (oclass);
  guint32 *flags;
  GtkArg *args;
  gint num_args;
  GParamSpec **params;
  int i;

  args = gtk_object_query_args (type, &flags, &num_args);
136
  // FIXME: args and flags need to be freed. 
137
138
139
140
141
142
143
144
145

  params = g_new0(GParamSpec *,num_args);
  for (i=0;i<num_args;i++) {
    params[i] = g_new0(GParamSpec,1);
    params[i]->name = args[i].name;
    params[i]->value_type = args[i].type;
    params[i]->flags = flags[i];
  }

146
147
  *n_properties = num_args;

148
149
150
151
  return params;
}

GParamSpec *
152
g2g_param_spec_boolean(gchar *name,gchar *nick,gchar *blurb,gboolean def,gint flags) {
153
154
155
156
157
158
159
160
161
162
  GParamSpec *spec = g_new(GParamSpec,1);

  spec->name = name;
  spec->value_type = GTK_TYPE_BOOL;
  spec->flags = flags;

  return spec;
}

GParamSpec *
163
g2g_param_spec_enum(gchar *name,gchar *nick,gchar *blurb,GtkType e,guint def,gint flags) {
164
165
166
167
168
169
170
171
172
173
  GParamSpec *spec = g_new(GParamSpec,1);

  spec->name = name;
  spec->value_type = e;
  spec->flags = flags;

  return spec;
}

GParamSpec *
174
g2g_param_spec_int(gchar *name,gchar *nick,gchar *blurb,gint min,gint max,gint def,gint flags) {
175
176
177
178
179
180
181
182
183
184
  GParamSpec *spec = g_new(GParamSpec,1);

  spec->name = name;
  spec->value_type = GTK_TYPE_INT;
  spec->flags = flags;

  return spec;
}

GParamSpec *
185
g2g_param_spec_uint(gchar *name,gchar *nick,gchar *blurb,guint min,guint max,guint def,gint flags) {
186
187
188
189
190
191
192
193
194
195
  GParamSpec *spec = g_new(GParamSpec,1);

  spec->name = name;
  spec->value_type = GTK_TYPE_UINT;
  spec->flags = flags;

  return spec;
}

GParamSpec *
196
g2g_param_spec_long(gchar *name,gchar *nick,gchar *blurb,glong min,glong max,glong def,gint flags) {
197
198
199
200
201
202
203
204
205
206
  GParamSpec *spec = g_new(GParamSpec,1);

  spec->name = name;
  spec->value_type = GTK_TYPE_LONG;
  spec->flags = flags;

  return spec;
}

GParamSpec *
207
g2g_param_spec_ulong(gchar *name,gchar *nick,gchar *blurb,gulong min,gulong max,gulong def,gint flags) {
208
209
210
211
212
213
214
215
216
217
  GParamSpec *spec = g_new(GParamSpec,1);

  spec->name = name;
  spec->value_type = GTK_TYPE_ULONG;
  spec->flags = flags;

  return spec;
}

GParamSpec *
218
g2g_param_spec_float(gchar *name,gchar *nick,gchar *blurb,float min,float max,float def,gint flags) {
219
220
221
222
223
224
225
226
227
228
  GParamSpec *spec = g_new(GParamSpec,1);

  spec->name = name;
  spec->value_type = GTK_TYPE_FLOAT;
  spec->flags = flags;

  return spec;
}

GParamSpec *
229
g2g_param_spec_double(gchar *name,gchar *nick,gchar *blurb,double min,double max,double def,gint flags) {
230
231
232
233
234
235
236
237
238
239
  GParamSpec *spec = g_new(GParamSpec,1);

  spec->name = name;
  spec->value_type = GTK_TYPE_DOUBLE;
  spec->flags = flags;

  return spec;
}

GParamSpec *
240
g2g_param_spec_pointer(gchar *name,gchar *nick,gchar *blurb,gint flags) {
241
242
243
244
245
246
247
248
249
250
  GParamSpec *spec = g_new(GParamSpec,1);

  spec->name = name;
  spec->value_type = GTK_TYPE_POINTER;
  spec->flags = flags;

  return spec;
}

GParamSpec *
251
g2g_param_spec_string(gchar *name,gchar *nick,gchar *blurb,gchar *def,gint flags) {
252
253
254
255
256
257
258
259
260
261
262
263
  GParamSpec *spec = g_new(GParamSpec,1);

  spec->name = name;
  spec->value_type = GTK_TYPE_STRING;
  spec->flags = flags;

  return spec;
}



guint
264
g2g_signal_new (const gchar       *name,
265
266
267
268
269
270
271
272
273
		GtkType            object_type,
		GtkSignalRunType   signal_flags,
		guint              function_offset,
		gpointer           accumulator,  // GSignalAccumulator
		gpointer           accu_data,
		GtkSignalMarshaller  marshaller,
		GType              return_val,
		guint              nparams,
		...)
274
275
276
277
278
279
{
  GtkType *params;
  guint i;
  va_list args;
  guint signal_id;

280
281
282
  if (strcmp (name, "destroy") == 0)
    name = "g2gdestroy";

283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
#define MAX_SIGNAL_PARAMS		(31)		// from gtksignal.c
  g_return_val_if_fail (nparams < MAX_SIGNAL_PARAMS, 0);
     
  if (nparams > 0) 
    {
      params = g_new (GtkType, nparams);

      va_start (args, nparams);
                   
      for (i = 0; i < nparams; i++)
        params[i] = va_arg (args, GtkType);
  
      va_end (args);
    }           
  else
    params = NULL;
 
  signal_id = gtk_signal_newv (name,
                               signal_flags,
                               object_type,
                               function_offset,
                               marshaller,
                               return_val,
                               nparams,
                               params);
          
  g_free (params);

  // now register it.
  gtk_object_class_add_signals(gtk_type_class(object_type), &signal_id, 1);
    
  return signal_id;
}
316
317
318
319
320
321
322
323

gint* g_signal_list_ids (GType type, guint *n_ids)
{
  GtkObjectClass *class;

  class = gtk_type_class (type);

  *n_ids = class->nsignals;
324

325
326
327
  return class->signals;
}