Remove unnecessary case statement braces.
[geany-mirror.git] / src / geanyobject.c
blobe62e1f9bfd4da3adc549dfa3fce97ea27c30f362
1 /*
2 * geanyobject.c - this file is part of Geany, a fast and lightweight IDE
4 * Copyright 2007-2009 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
5 * Copyright 2007-2009 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
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
20 * MA 02110-1301, USA.
22 * $Id$
25 /* A GObject used for connecting and emitting signals when certain events happen,
26 * e.g. opening a document.
27 * Mainly used for plugins - see the API docs.
29 * Core-only signals:
31 * signal void save_settings(GObject *obj, GKeyFile *keyfile, gpointer user_data);
32 * Emitted just before saving main keyfile settings.
34 * signal void load_settings(GObject *obj, GKeyFile *keyfile, gpointer user_data);
35 * Emitted just after loading main keyfile settings.
38 #include "geany.h"
39 #include "geanyobject.h"
41 /* extern in geany.h */
42 GObject *geany_object;
44 static guint geany_object_signals[GCB_MAX] = { 0 };
47 typedef struct _GeanyObjectPrivate GeanyObjectPrivate;
49 #define GEANY_OBJECT_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj),\
50 GEANY_OBJECT_TYPE, GeanyObjectPrivate))
52 struct _GeanyObjectPrivate
54 /* to avoid warnings (g_type_class_add_private: assertion `private_size > 0' failed) */
55 gchar dummy;
59 G_DEFINE_TYPE(GeanyObject, geany_object, G_TYPE_OBJECT);
63 static void geany_cclosure_marshal_VOID__STRING_INT_POINTER(GClosure *closure, GValue *ret_val,
64 guint n_param_vals, const GValue *param_values, gpointer hint, gpointer mdata)
66 typedef gboolean (*GeanyMarshalFunc_VOID__STRING_INT_POINTER)
67 (gpointer data1, gconstpointer arg_1, gint arg_2, gpointer arg_3, gpointer data2);
69 register GeanyMarshalFunc_VOID__STRING_INT_POINTER callback;
70 register GCClosure* cc = (GCClosure*) closure;
71 register gpointer data1, data2;
73 g_return_if_fail(n_param_vals == 4);
75 if (G_CCLOSURE_SWAP_DATA(closure))
77 data1 = closure->data;
78 data2 = g_value_peek_pointer(param_values + 0);
80 else
82 data1 = g_value_peek_pointer(param_values + 0);
83 data2 = closure->data;
85 callback = (GeanyMarshalFunc_VOID__STRING_INT_POINTER) (mdata ? mdata : cc->callback);
86 callback(data1,
87 g_value_get_string(param_values + 1),
88 g_value_get_int(param_values + 2),
89 g_value_get_pointer(param_values + 3),
90 data2);
94 static void geany_cclosure_marshal_VOID__POINTER_POINTER(GClosure *closure, GValue *ret_val,
95 guint n_param_vals, const GValue *param_values, gpointer hint, gpointer mdata)
97 typedef gboolean (*GeanyMarshalFunc_VOID__POINTER_POINTER)
98 (gpointer data1, gconstpointer arg_1, gconstpointer arg_2, gpointer data2);
100 register GeanyMarshalFunc_VOID__POINTER_POINTER callback;
101 register GCClosure* cc = (GCClosure*) closure;
102 register gpointer data1, data2;
104 g_return_if_fail(n_param_vals == 3);
106 if (G_CCLOSURE_SWAP_DATA(closure))
108 data1 = closure->data;
109 data2 = g_value_peek_pointer(param_values + 0);
111 else
113 data1 = g_value_peek_pointer(param_values + 0);
114 data2 = closure->data;
116 callback = (GeanyMarshalFunc_VOID__POINTER_POINTER) (mdata ? mdata : cc->callback);
117 callback(data1,
118 g_value_get_pointer(param_values + 1),
119 g_value_get_pointer(param_values + 2),
120 data2);
124 static gboolean boolean_handled_accumulator(GSignalInvocationHint *ihint, GValue *return_accu,
125 const GValue *handler_return, gpointer dummy)
127 gboolean continue_emission, signal_handled;
129 signal_handled = g_value_get_boolean(handler_return);
130 g_value_set_boolean(return_accu, signal_handled);
131 continue_emission = !signal_handled;
133 return continue_emission;
137 static void geany_cclosure_marshal_BOOL__POINTER_POINTER(GClosure *closure, GValue *return_value,
138 guint n_param_values, const GValue *param_values,
139 gpointer invocation_hint G_GNUC_UNUSED, gpointer marshal_data)
141 typedef gboolean (*GeanyMarshalFunc_BOOLEAN__POINTER_POINTER)
142 (gpointer data1, gpointer arg_1, gpointer arg_2, gpointer data2);
144 register GeanyMarshalFunc_BOOLEAN__POINTER_POINTER callback;
145 register GCClosure *cc = (GCClosure*) closure;
146 register gpointer data1, data2;
147 gboolean v_return;
149 g_return_if_fail(return_value != NULL);
150 g_return_if_fail(n_param_values == 3);
152 if (G_CCLOSURE_SWAP_DATA(closure))
154 data1 = closure->data;
155 data2 = g_value_peek_pointer(param_values + 0);
157 else
159 data1 = g_value_peek_pointer(param_values + 0);
160 data2 = closure->data;
162 callback = (GeanyMarshalFunc_BOOLEAN__POINTER_POINTER)
163 (marshal_data ? marshal_data : cc->callback);
165 v_return = callback(data1,
166 g_value_get_pointer(param_values + 1),
167 g_value_get_pointer(param_values + 2),
168 data2);
170 g_value_set_boolean(return_value, v_return);
174 static void create_signals(GObjectClass *g_object_class)
176 /* Document signals */
177 geany_object_signals[GCB_DOCUMENT_NEW] = g_signal_new (
178 "document-new",
179 G_OBJECT_CLASS_TYPE (g_object_class),
180 G_SIGNAL_RUN_FIRST,
181 G_STRUCT_OFFSET (GeanyObjectClass, document_new),
182 NULL, NULL,
183 g_cclosure_marshal_VOID__POINTER,
184 G_TYPE_NONE, 1,
185 G_TYPE_POINTER);
186 geany_object_signals[GCB_DOCUMENT_OPEN] = g_signal_new (
187 "document-open",
188 G_OBJECT_CLASS_TYPE (g_object_class),
189 G_SIGNAL_RUN_FIRST,
190 G_STRUCT_OFFSET (GeanyObjectClass, document_open),
191 NULL, NULL,
192 g_cclosure_marshal_VOID__POINTER,
193 G_TYPE_NONE, 1,
194 G_TYPE_POINTER);
195 geany_object_signals[GCB_DOCUMENT_BEFORE_SAVE] = g_signal_new (
196 "document-before-save",
197 G_OBJECT_CLASS_TYPE (g_object_class),
198 G_SIGNAL_RUN_FIRST,
199 G_STRUCT_OFFSET (GeanyObjectClass, document_before_save),
200 NULL, NULL,
201 g_cclosure_marshal_VOID__POINTER,
202 G_TYPE_NONE, 1,
203 G_TYPE_POINTER);
204 geany_object_signals[GCB_DOCUMENT_SAVE] = g_signal_new (
205 "document-save",
206 G_OBJECT_CLASS_TYPE (g_object_class),
207 G_SIGNAL_RUN_FIRST,
208 G_STRUCT_OFFSET (GeanyObjectClass, document_save),
209 NULL, NULL,
210 g_cclosure_marshal_VOID__POINTER,
211 G_TYPE_NONE, 1,
212 G_TYPE_POINTER);
213 geany_object_signals[GCB_DOCUMENT_FILETYPE_SET] = g_signal_new (
214 "document-filetype-set",
215 G_OBJECT_CLASS_TYPE (g_object_class),
216 G_SIGNAL_RUN_FIRST,
217 G_STRUCT_OFFSET (GeanyObjectClass, document_filetype_set),
218 NULL, NULL,
219 geany_cclosure_marshal_VOID__POINTER_POINTER,
220 G_TYPE_NONE, 2,
221 G_TYPE_POINTER, G_TYPE_POINTER);
222 geany_object_signals[GCB_DOCUMENT_ACTIVATE] = g_signal_new (
223 "document-activate",
224 G_OBJECT_CLASS_TYPE (g_object_class),
225 G_SIGNAL_RUN_FIRST,
226 G_STRUCT_OFFSET (GeanyObjectClass, document_activate),
227 NULL, NULL,
228 g_cclosure_marshal_VOID__POINTER,
229 G_TYPE_NONE, 1,
230 G_TYPE_POINTER);
231 geany_object_signals[GCB_DOCUMENT_CLOSE] = g_signal_new (
232 "document-close",
233 G_OBJECT_CLASS_TYPE (g_object_class),
234 G_SIGNAL_RUN_FIRST,
235 G_STRUCT_OFFSET (GeanyObjectClass, document_close),
236 NULL, NULL,
237 g_cclosure_marshal_VOID__POINTER,
238 G_TYPE_NONE, 1,
239 G_TYPE_POINTER);
241 /* Project signals */
242 geany_object_signals[GCB_PROJECT_OPEN] = g_signal_new (
243 "project-open",
244 G_OBJECT_CLASS_TYPE (g_object_class),
245 G_SIGNAL_RUN_FIRST,
246 G_STRUCT_OFFSET (GeanyObjectClass, project_open),
247 NULL, NULL,
248 g_cclosure_marshal_VOID__POINTER,
249 G_TYPE_NONE, 1,
250 G_TYPE_POINTER);
251 geany_object_signals[GCB_PROJECT_SAVE] = g_signal_new (
252 "project-save",
253 G_OBJECT_CLASS_TYPE (g_object_class),
254 G_SIGNAL_RUN_FIRST,
255 G_STRUCT_OFFSET (GeanyObjectClass, project_save),
256 NULL, NULL,
257 g_cclosure_marshal_VOID__POINTER,
258 G_TYPE_NONE, 1,
259 G_TYPE_POINTER);
260 geany_object_signals[GCB_PROJECT_CLOSE] = g_signal_new (
261 "project-close",
262 G_OBJECT_CLASS_TYPE (g_object_class),
263 G_SIGNAL_RUN_FIRST,
264 G_STRUCT_OFFSET (GeanyObjectClass, project_close),
265 NULL, NULL,
266 g_cclosure_marshal_VOID__VOID,
267 G_TYPE_NONE, 0);
269 /* Editor signals */
270 geany_object_signals[GCB_UPDATE_EDITOR_MENU] = g_signal_new (
271 "update-editor-menu",
272 G_OBJECT_CLASS_TYPE (g_object_class),
273 G_SIGNAL_RUN_FIRST,
274 G_STRUCT_OFFSET (GeanyObjectClass, update_editor_menu),
275 NULL, NULL,
276 geany_cclosure_marshal_VOID__STRING_INT_POINTER,
277 G_TYPE_NONE, 3,
278 G_TYPE_STRING, G_TYPE_INT, G_TYPE_POINTER);
279 geany_object_signals[GCB_EDITOR_NOTIFY] = g_signal_new (
280 "editor-notify",
281 G_OBJECT_CLASS_TYPE (g_object_class),
282 G_SIGNAL_RUN_LAST,
283 G_STRUCT_OFFSET (GeanyObjectClass, update_editor_menu),
284 boolean_handled_accumulator, NULL,
285 geany_cclosure_marshal_BOOL__POINTER_POINTER,
286 G_TYPE_BOOLEAN, 2,
287 G_TYPE_POINTER, G_TYPE_POINTER);
289 /* Core-only signals */
290 geany_object_signals[GCB_SAVE_SETTINGS] = g_signal_new (
291 "save-settings",
292 G_OBJECT_CLASS_TYPE (g_object_class),
293 G_SIGNAL_RUN_FIRST,
294 G_STRUCT_OFFSET (GeanyObjectClass, save_settings),
295 NULL, NULL,
296 g_cclosure_marshal_VOID__POINTER,
297 G_TYPE_NONE, 1,
298 G_TYPE_POINTER);
299 geany_object_signals[GCB_LOAD_SETTINGS] = g_signal_new (
300 "load-settings",
301 G_OBJECT_CLASS_TYPE (g_object_class),
302 G_SIGNAL_RUN_FIRST,
303 G_STRUCT_OFFSET (GeanyObjectClass, load_settings),
304 NULL, NULL,
305 g_cclosure_marshal_VOID__POINTER,
306 G_TYPE_NONE, 1,
307 G_TYPE_POINTER);
311 static void geany_object_class_init(GeanyObjectClass *klass)
313 GObjectClass *g_object_class;
314 g_object_class = G_OBJECT_CLASS(klass);
316 g_type_class_add_private(klass, sizeof(GeanyObjectPrivate));
318 create_signals(g_object_class);
322 static void geany_object_init(GeanyObject *self)
324 /* nothing to do */
328 GObject *geany_object_new(void)
330 return g_object_new(GEANY_OBJECT_TYPE, NULL);