Parse C++11 enums with type specifier
[geany-mirror.git] / src / geanyobject.c
blob28144cd6a4304a9c6241bcd4976f985ef4d32be8
1 /*
2 * geanyobject.c - this file is part of Geany, a fast and lightweight IDE
4 * Copyright 2007-2012 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
5 * Copyright 2007-2012 Nick Treleaven <nick(dot)treleaven(at)btinternet(dot)com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 /* A GObject used for connecting and emitting signals when certain events happen,
23 * e.g. opening a document.
24 * Mainly used for plugins - see the API docs.
26 * Core-only signals:
28 * signal void save_settings(GObject *obj, GKeyFile *keyfile, gpointer user_data);
29 * Emitted just before saving main keyfile settings.
31 * signal void load_settings(GObject *obj, GKeyFile *keyfile, gpointer user_data);
32 * Emitted just after loading main keyfile settings.
35 #include "geany.h"
36 #include "geanyobject.h"
38 /* extern in geany.h */
39 GObject *geany_object;
41 static guint geany_object_signals[GCB_MAX] = { 0 };
44 typedef struct _GeanyObjectPrivate GeanyObjectPrivate;
46 struct _GeanyObjectPrivate
48 /* to avoid warnings (g_type_class_add_private: assertion `private_size > 0' failed) */
49 gchar dummy;
53 G_DEFINE_TYPE(GeanyObject, geany_object, G_TYPE_OBJECT)
57 static void geany_cclosure_marshal_VOID__STRING_INT_POINTER(GClosure *closure, GValue *ret_val,
58 guint n_param_vals, const GValue *param_values, gpointer hint, gpointer mdata)
60 typedef gboolean (*GeanyMarshalFunc_VOID__STRING_INT_POINTER)
61 (gpointer data1, gconstpointer arg_1, gint arg_2, gpointer arg_3, gpointer data2);
63 register GeanyMarshalFunc_VOID__STRING_INT_POINTER callback;
64 register GCClosure* cc = (GCClosure*) closure;
65 register gpointer data1, data2;
67 g_return_if_fail(n_param_vals == 4);
69 if (G_CCLOSURE_SWAP_DATA(closure))
71 data1 = closure->data;
72 data2 = g_value_peek_pointer(param_values + 0);
74 else
76 data1 = g_value_peek_pointer(param_values + 0);
77 data2 = closure->data;
79 callback = (GeanyMarshalFunc_VOID__STRING_INT_POINTER) (mdata ? mdata : cc->callback);
80 callback(data1,
81 g_value_get_string(param_values + 1),
82 g_value_get_int(param_values + 2),
83 g_value_get_pointer(param_values + 3),
84 data2);
88 static void geany_cclosure_marshal_VOID__POINTER_POINTER(GClosure *closure, GValue *ret_val,
89 guint n_param_vals, const GValue *param_values, gpointer hint, gpointer mdata)
91 typedef gboolean (*GeanyMarshalFunc_VOID__POINTER_POINTER)
92 (gpointer data1, gconstpointer arg_1, gconstpointer arg_2, gpointer data2);
94 register GeanyMarshalFunc_VOID__POINTER_POINTER callback;
95 register GCClosure* cc = (GCClosure*) closure;
96 register gpointer data1, data2;
98 g_return_if_fail(n_param_vals == 3);
100 if (G_CCLOSURE_SWAP_DATA(closure))
102 data1 = closure->data;
103 data2 = g_value_peek_pointer(param_values + 0);
105 else
107 data1 = g_value_peek_pointer(param_values + 0);
108 data2 = closure->data;
110 callback = (GeanyMarshalFunc_VOID__POINTER_POINTER) (mdata ? mdata : cc->callback);
111 callback(data1,
112 g_value_get_pointer(param_values + 1),
113 g_value_get_pointer(param_values + 2),
114 data2);
118 static gboolean boolean_handled_accumulator(GSignalInvocationHint *ihint, GValue *return_accu,
119 const GValue *handler_return, gpointer dummy)
121 gboolean continue_emission, signal_handled;
123 signal_handled = g_value_get_boolean(handler_return);
124 g_value_set_boolean(return_accu, signal_handled);
125 continue_emission = !signal_handled;
127 return continue_emission;
131 static void geany_cclosure_marshal_BOOL__POINTER_POINTER(GClosure *closure, GValue *return_value,
132 guint n_param_values, const GValue *param_values,
133 gpointer invocation_hint G_GNUC_UNUSED, gpointer marshal_data)
135 typedef gboolean (*GeanyMarshalFunc_BOOLEAN__POINTER_POINTER)
136 (gpointer data1, gpointer arg_1, gpointer arg_2, gpointer data2);
138 register GeanyMarshalFunc_BOOLEAN__POINTER_POINTER callback;
139 register GCClosure *cc = (GCClosure*) closure;
140 register gpointer data1, data2;
141 gboolean v_return;
143 g_return_if_fail(return_value != NULL);
144 g_return_if_fail(n_param_values == 3);
146 if (G_CCLOSURE_SWAP_DATA(closure))
148 data1 = closure->data;
149 data2 = g_value_peek_pointer(param_values + 0);
151 else
153 data1 = g_value_peek_pointer(param_values + 0);
154 data2 = closure->data;
156 callback = (GeanyMarshalFunc_BOOLEAN__POINTER_POINTER)
157 (marshal_data ? marshal_data : cc->callback);
159 v_return = callback(data1,
160 g_value_get_pointer(param_values + 1),
161 g_value_get_pointer(param_values + 2),
162 data2);
164 g_value_set_boolean(return_value, v_return);
168 static void create_signals(GObjectClass *g_object_class)
170 /* Document signals */
171 geany_object_signals[GCB_DOCUMENT_NEW] = g_signal_new (
172 "document-new",
173 G_OBJECT_CLASS_TYPE (g_object_class),
174 G_SIGNAL_RUN_FIRST,
175 G_STRUCT_OFFSET (GeanyObjectClass, document_new),
176 NULL, NULL,
177 g_cclosure_marshal_VOID__POINTER,
178 G_TYPE_NONE, 1,
179 G_TYPE_POINTER);
180 geany_object_signals[GCB_DOCUMENT_OPEN] = g_signal_new (
181 "document-open",
182 G_OBJECT_CLASS_TYPE (g_object_class),
183 G_SIGNAL_RUN_FIRST,
184 G_STRUCT_OFFSET (GeanyObjectClass, document_open),
185 NULL, NULL,
186 g_cclosure_marshal_VOID__POINTER,
187 G_TYPE_NONE, 1,
188 G_TYPE_POINTER);
189 geany_object_signals[GCB_DOCUMENT_RELOAD] = g_signal_new (
190 "document-reload",
191 G_OBJECT_CLASS_TYPE (g_object_class),
192 G_SIGNAL_RUN_FIRST,
193 G_STRUCT_OFFSET (GeanyObjectClass, document_reload),
194 NULL, NULL,
195 g_cclosure_marshal_VOID__POINTER,
196 G_TYPE_NONE, 1,
197 G_TYPE_POINTER);
198 geany_object_signals[GCB_DOCUMENT_BEFORE_SAVE] = g_signal_new (
199 "document-before-save",
200 G_OBJECT_CLASS_TYPE (g_object_class),
201 G_SIGNAL_RUN_FIRST,
202 G_STRUCT_OFFSET (GeanyObjectClass, document_before_save),
203 NULL, NULL,
204 g_cclosure_marshal_VOID__POINTER,
205 G_TYPE_NONE, 1,
206 G_TYPE_POINTER);
207 geany_object_signals[GCB_DOCUMENT_SAVE] = g_signal_new (
208 "document-save",
209 G_OBJECT_CLASS_TYPE (g_object_class),
210 G_SIGNAL_RUN_FIRST,
211 G_STRUCT_OFFSET (GeanyObjectClass, document_save),
212 NULL, NULL,
213 g_cclosure_marshal_VOID__POINTER,
214 G_TYPE_NONE, 1,
215 G_TYPE_POINTER);
216 geany_object_signals[GCB_DOCUMENT_FILETYPE_SET] = g_signal_new (
217 "document-filetype-set",
218 G_OBJECT_CLASS_TYPE (g_object_class),
219 G_SIGNAL_RUN_FIRST,
220 G_STRUCT_OFFSET (GeanyObjectClass, document_filetype_set),
221 NULL, NULL,
222 geany_cclosure_marshal_VOID__POINTER_POINTER,
223 G_TYPE_NONE, 2,
224 G_TYPE_POINTER, G_TYPE_POINTER);
225 geany_object_signals[GCB_DOCUMENT_ACTIVATE] = g_signal_new (
226 "document-activate",
227 G_OBJECT_CLASS_TYPE (g_object_class),
228 G_SIGNAL_RUN_FIRST,
229 G_STRUCT_OFFSET (GeanyObjectClass, document_activate),
230 NULL, NULL,
231 g_cclosure_marshal_VOID__POINTER,
232 G_TYPE_NONE, 1,
233 G_TYPE_POINTER);
234 geany_object_signals[GCB_DOCUMENT_CLOSE] = g_signal_new (
235 "document-close",
236 G_OBJECT_CLASS_TYPE (g_object_class),
237 G_SIGNAL_RUN_FIRST,
238 G_STRUCT_OFFSET (GeanyObjectClass, document_close),
239 NULL, NULL,
240 g_cclosure_marshal_VOID__POINTER,
241 G_TYPE_NONE, 1,
242 G_TYPE_POINTER);
244 /* Project signals */
245 geany_object_signals[GCB_PROJECT_OPEN] = g_signal_new (
246 "project-open",
247 G_OBJECT_CLASS_TYPE (g_object_class),
248 G_SIGNAL_RUN_FIRST,
249 G_STRUCT_OFFSET (GeanyObjectClass, project_open),
250 NULL, NULL,
251 g_cclosure_marshal_VOID__POINTER,
252 G_TYPE_NONE, 1,
253 G_TYPE_POINTER);
254 geany_object_signals[GCB_PROJECT_SAVE] = g_signal_new (
255 "project-save",
256 G_OBJECT_CLASS_TYPE (g_object_class),
257 G_SIGNAL_RUN_FIRST,
258 G_STRUCT_OFFSET (GeanyObjectClass, project_save),
259 NULL, NULL,
260 g_cclosure_marshal_VOID__POINTER,
261 G_TYPE_NONE, 1,
262 G_TYPE_POINTER);
263 geany_object_signals[GCB_PROJECT_CLOSE] = g_signal_new (
264 "project-close",
265 G_OBJECT_CLASS_TYPE (g_object_class),
266 G_SIGNAL_RUN_FIRST,
267 G_STRUCT_OFFSET (GeanyObjectClass, project_close),
268 NULL, NULL,
269 g_cclosure_marshal_VOID__VOID,
270 G_TYPE_NONE, 0);
271 geany_object_signals[GCB_PROJECT_DIALOG_OPEN] = g_signal_new (
272 "project-dialog-open",
273 G_OBJECT_CLASS_TYPE (g_object_class),
274 G_SIGNAL_RUN_FIRST,
275 G_STRUCT_OFFSET (GeanyObjectClass, project_dialog_open),
276 NULL, NULL,
277 g_cclosure_marshal_VOID__POINTER,
278 G_TYPE_NONE, 1,
279 G_TYPE_POINTER);
280 geany_object_signals[GCB_PROJECT_DIALOG_CONFIRMED] = g_signal_new (
281 "project-dialog-confirmed",
282 G_OBJECT_CLASS_TYPE (g_object_class),
283 G_SIGNAL_RUN_FIRST,
284 G_STRUCT_OFFSET (GeanyObjectClass, project_dialog_confirmed),
285 NULL, NULL,
286 g_cclosure_marshal_VOID__POINTER,
287 G_TYPE_NONE, 1,
288 G_TYPE_POINTER);
289 geany_object_signals[GCB_PROJECT_DIALOG_CLOSE] = g_signal_new (
290 "project-dialog-close",
291 G_OBJECT_CLASS_TYPE (g_object_class),
292 G_SIGNAL_RUN_FIRST,
293 G_STRUCT_OFFSET (GeanyObjectClass, project_dialog_close),
294 NULL, NULL,
295 g_cclosure_marshal_VOID__POINTER,
296 G_TYPE_NONE, 1,
297 G_TYPE_POINTER);
299 /* Editor signals */
300 geany_object_signals[GCB_UPDATE_EDITOR_MENU] = g_signal_new (
301 "update-editor-menu",
302 G_OBJECT_CLASS_TYPE (g_object_class),
303 G_SIGNAL_RUN_FIRST,
304 G_STRUCT_OFFSET (GeanyObjectClass, update_editor_menu),
305 NULL, NULL,
306 geany_cclosure_marshal_VOID__STRING_INT_POINTER,
307 G_TYPE_NONE, 3,
308 G_TYPE_STRING, G_TYPE_INT, G_TYPE_POINTER);
309 geany_object_signals[GCB_EDITOR_NOTIFY] = g_signal_new (
310 "editor-notify",
311 G_OBJECT_CLASS_TYPE (g_object_class),
312 G_SIGNAL_RUN_LAST,
313 G_STRUCT_OFFSET (GeanyObjectClass, update_editor_menu),
314 boolean_handled_accumulator, NULL,
315 geany_cclosure_marshal_BOOL__POINTER_POINTER,
316 G_TYPE_BOOLEAN, 2,
317 G_TYPE_POINTER, G_TYPE_POINTER);
319 /* General signals */
320 geany_object_signals[GCB_GEANY_STARTUP_COMPLETE] = g_signal_new (
321 "geany-startup-complete",
322 G_OBJECT_CLASS_TYPE (g_object_class),
323 G_SIGNAL_RUN_FIRST,
324 G_STRUCT_OFFSET (GeanyObjectClass, geany_startup_complete),
325 NULL, NULL,
326 g_cclosure_marshal_VOID__VOID,
327 G_TYPE_NONE, 0);
328 geany_object_signals[GCB_BUILD_START] = g_signal_new (
329 "build-start",
330 G_OBJECT_CLASS_TYPE (g_object_class),
331 G_SIGNAL_RUN_FIRST,
332 G_STRUCT_OFFSET (GeanyObjectClass, build_start),
333 NULL, NULL,
334 g_cclosure_marshal_VOID__VOID,
335 G_TYPE_NONE, 0);
337 /* Core-only signals */
338 geany_object_signals[GCB_SAVE_SETTINGS] = g_signal_new (
339 "save-settings",
340 G_OBJECT_CLASS_TYPE (g_object_class),
341 G_SIGNAL_RUN_FIRST,
342 G_STRUCT_OFFSET (GeanyObjectClass, save_settings),
343 NULL, NULL,
344 g_cclosure_marshal_VOID__POINTER,
345 G_TYPE_NONE, 1,
346 G_TYPE_POINTER);
347 geany_object_signals[GCB_LOAD_SETTINGS] = g_signal_new (
348 "load-settings",
349 G_OBJECT_CLASS_TYPE (g_object_class),
350 G_SIGNAL_RUN_FIRST,
351 G_STRUCT_OFFSET (GeanyObjectClass, load_settings),
352 NULL, NULL,
353 g_cclosure_marshal_VOID__POINTER,
354 G_TYPE_NONE, 1,
355 G_TYPE_POINTER);
359 static void geany_object_class_init(GeanyObjectClass *klass)
361 GObjectClass *g_object_class;
362 g_object_class = G_OBJECT_CLASS(klass);
364 g_type_class_add_private(klass, sizeof(GeanyObjectPrivate));
366 create_signals(g_object_class);
370 static void geany_object_init(GeanyObject *self)
372 /* nothing to do */
376 GObject *geany_object_new(void)
378 return g_object_new(GEANY_OBJECT_TYPE, NULL);