File: GtkBuilder.xs

package info (click to toggle)
libgtk2-perl 2:1.2499-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 4,668 kB
  • ctags: 594
  • sloc: perl: 22,100; ansic: 122; makefile: 17
file content (240 lines) | stat: -rw-r--r-- 7,268 bytes parent folder | download | duplicates (3)
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
/*
 * Copyright (c) 2007, 2012 by the gtk2-perl team (see the file AUTHORS)
 *
 * Licensed under the LGPL, see LICENSE file for more information.
 *
 * $Id$
 */

#include "gtk2perl.h"

/* This doesn't belong here.  But currently, this is the only place a GType for
 * GConnectFlags is needed, so adding extra API to Glib doesn't seem justified.
 */
static GType
gtk2perl_connect_flags_get_type (void)
{
	static GType etype = 0;
	if (etype == 0) {
		static const GFlagsValue values[] = {
			{ G_CONNECT_AFTER, "G_CONNECT_AFTER", "after" },
			{ G_CONNECT_SWAPPED, "G_CONNECT_SWAPPED", "swapped" },
			{ 0, NULL, NULL }
		};
		/* This is actually a race condition, but I don't think it
		 * matters too much in this case. */
		etype = g_type_from_name ("GConnectFlags");
		if (etype == 0) {
			etype = g_flags_register_static ("GConnectFlags", values);
		}
	}
	return etype;
}

static GPerlCallback *
gtk2perl_builder_connect_func_create (SV *func, SV *data)
{
	GType param_types[] = {
		GTK_TYPE_BUILDER,
		G_TYPE_OBJECT,
		G_TYPE_STRING,
		G_TYPE_STRING,
		G_TYPE_OBJECT,
		gtk2perl_connect_flags_get_type ()
	};
	return gperl_callback_new (func, data,
	                           G_N_ELEMENTS (param_types),
	                           param_types,
	                           G_TYPE_NONE);
}

static void
gtk2perl_builder_connect_func (GtkBuilder    *builder,
			       GObject       *object,
			       const gchar   *signal_name,
			       const gchar   *handler_name,
			       GObject       *connect_object,
			       GConnectFlags  flags,
			       gpointer       user_data)
{
	gperl_callback_invoke ((GPerlCallback *) user_data,
			       NULL,
	                       builder,
			       object,
			       signal_name,
			       handler_name,
			       connect_object,
			       flags);
}

MODULE = Gtk2::Builder	PACKAGE = Gtk2::Builder	PREFIX = gtk_builder_

BOOT:
	if (!gperl_type_from_package ("Glib::ConnectFlags")) {
		gperl_register_fundamental (gtk2perl_connect_flags_get_type (),
	                                    "Glib::ConnectFlags");
	}
	gperl_register_error_domain (GTK_BUILDER_ERROR,
				     GTK_TYPE_BUILDER_ERROR,
				     "Gtk2::Builder::Error");

GtkBuilder_noinc * gtk_builder_new (class)
    C_ARGS:
	/* void */

# guint gtk_builder_add_from_file (GtkBuilder *builder, const gchar *filename, GError **error);
=for apidoc __gerror__
=cut
guint gtk_builder_add_from_file (GtkBuilder *builder, GPerlFilename filename)
    PREINIT:
	GError *error = NULL;
    CODE:
	RETVAL = gtk_builder_add_from_file (builder, filename, &error);
	if (error)
		gperl_croak_gerror (NULL, error);
    OUTPUT:
	RETVAL

# guint gtk_builder_add_from_string (GtkBuilder *builder, const gchar *buffer, gsize length, GError **error);
=for apidoc __gerror__
=cut
guint gtk_builder_add_from_string (GtkBuilder *builder, const gchar *buffer)
    PREINIT:
	gsize length;
	GError *error = NULL;
    CODE:
	length = sv_len (ST (1));
	RETVAL = gtk_builder_add_from_string (builder, buffer, length, &error);
	if (error)
		gperl_croak_gerror (NULL, error);
    OUTPUT:
	RETVAL

GObject * gtk_builder_get_object (GtkBuilder *builder, const gchar *name);

# GSList * gtk_builder_get_objects (GtkBuilder *builder);
void
gtk_builder_get_objects (GtkBuilder *builder)
    PREINIT:
	GSList *list, *i;
    PPCODE:
	list = gtk_builder_get_objects (builder);
	for (i = list; i != NULL; i = i->next) {
		XPUSHs (sv_2mortal (newSVGObject (i->data)));
	}
	g_slist_free (list);

#if 0 /* evil hack to convince Glib::GenPod to output docs for connect_signals */

# connect_signals is implemented in Gtk2.pm
=for apidoc Gtk2::Builder::connect_signals
=for signature $builder->connect_signals ($user_data)
=for signature $builder->connect_signals ($user_data, $package)
=for signature $builder->connect_signals ($user_data, %handlers)
=for arg ... (__hide__)

There are four ways to let Gtk2::Builder do the signal connecting work for you:

=over

=item C<< $builder->connect_signals ($user_data) >>

When invoked like this, Gtk2::Builder will connect signals to functions in the
calling package.  The callback names are specified in the UI description.

=item C<< $builder->connect_signals ($user_data, $package) >>

When invoked like this, Gtk2::Builder will connect signals to functions in the
package I<$package>.

=item C<< $builder->connect_signals ($user_data, $object) >>

When invoked like this, Gtk2::Builder will connect signals to method calls
against the object $object.

=item C<< $builder->connect_signals ($user_data, %handlers) >>

When invoked like this, I<%handlers> is used as a mapping from handler names to
code references.

=back

=cut
void gtk_builder_connect_signals (GtkBuilder *builder, ...);

#endif /* evil hack */

# void gtk_builder_connect_signals_full (GtkBuilder *builder, GtkBuilderConnectFunc func, gpointer user_data);
void gtk_builder_connect_signals_full (GtkBuilder *builder, SV *func, SV *user_data=NULL);
    PREINIT:
	GPerlCallback *callback;
    CODE:
	callback = gtk2perl_builder_connect_func_create (func, user_data);
    	gtk_builder_connect_signals_full (
		builder,
		gtk2perl_builder_connect_func,
		callback);
	gperl_callback_destroy (callback);

void gtk_builder_set_translation_domain (GtkBuilder *builder, const gchar_ornull *domain);

const gchar_ornull * gtk_builder_get_translation_domain (GtkBuilder *builder);

# Are these needed?
# GType gtk_builder_get_type_from_name (GtkBuilder *builder, const char *type_name);
# gboolean gtk_builder_value_from_string (GParamSpec *pspec, const gchar *string, GValue *value);
# gboolean gtk_builder_value_from_string_type (GType type, const gchar *string, GValue *value);

#if GTK_CHECK_VERSION (2, 14, 0)

=for apidoc __hide__
=cut
# guint gtk_builder_add_objects_from_file (GtkBuilder *builder, const gchar *filename, gchar **object_ids, GError **error);
guint
gtk_builder_add_objects_from_file (GtkBuilder *builder, const gchar *filename, gchar *first_object_id, ...)
    PREINIT:
	gchar **object_ids = NULL;
	GError *error = NULL;
	int i;
    CODE:
#define FIRST_ITEM 2
	object_ids = g_new0 (gchar *, items - FIRST_ITEM + 1); /* NULL-terminate */
	object_ids[0] = first_object_id;
	for (i = FIRST_ITEM + 1; i < items; i++) {
		object_ids[i - FIRST_ITEM] = SvGChar (ST (i));
	}
	RETVAL = gtk_builder_add_objects_from_file (
	       	   builder, filename, object_ids, &error);
	if (!RETVAL) {
		gperl_croak_gerror (NULL, error);
	}
	g_free (object_ids);
#undef FIRST_ITEM
    OUTPUT:
	RETVAL

# guint gtk_builder_add_objects_from_string (GtkBuilder *builder, const gchar *buffer, gsize length, gchar **object_ids, GError **error);
guint
gtk_builder_add_objects_from_string (GtkBuilder *builder, const gchar *buffer, gchar *first_object_id, ...)
    PREINIT:
	gchar **object_ids = NULL;
	GError *error = NULL;
	int i;
    CODE:
#define FIRST_ITEM 2
	object_ids = g_new0 (gchar *, items - FIRST_ITEM + 1); /* NULL-terminate */
	object_ids[0] = first_object_id;
	for (i = FIRST_ITEM + 1; i < items; i++) {
		object_ids[i - FIRST_ITEM] = SvGChar (ST (i));
	}
	RETVAL = gtk_builder_add_objects_from_string (
	       	   builder, buffer, sv_len (ST (1)), object_ids, &error);
	if (!RETVAL) {
		gperl_croak_gerror (NULL, error);
	}
	g_free (object_ids);
#undef FIRST_ITEM
    OUTPUT:
	RETVAL

#endif