File: | ctk/ctkbindings.c |
Warning: | line 824, column 3 Value stored to 'entry' is never read |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | /* CTK - The GIMP Toolkit |
2 | * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald |
3 | * |
4 | * CtkBindingSet: Keybinding manager for GObjects. |
5 | * Copyright (C) 1998 Tim Janik |
6 | * |
7 | * This library is free software; you can redistribute it and/or |
8 | * modify it under the terms of the GNU Lesser General Public |
9 | * License as published by the Free Software Foundation; either |
10 | * version 2 of the License, or (at your option) any later version. |
11 | * |
12 | * This library 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 GNU |
15 | * Lesser General Public License for more details. |
16 | * |
17 | * You should have received a copy of the GNU Lesser General Public |
18 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. |
19 | */ |
20 | |
21 | /* |
22 | * Modified by the CTK+ Team and others 1997-2000. See the AUTHORS |
23 | * file for a list of people on the CTK+ Team. See the ChangeLog |
24 | * files for a list of changes. These files are distributed with |
25 | * CTK+ at ftp://ftp.ctk.org/pub/ctk/. |
26 | */ |
27 | |
28 | #include "config.h" |
29 | #include <string.h> |
30 | #include <stdarg.h> |
31 | |
32 | #include "ctkbindingsprivate.h" |
33 | #include "ctkkeyhash.h" |
34 | #include "ctkstylecontext.h" |
35 | #include "ctkwidget.h" |
36 | #include "ctkintl.h" |
37 | |
38 | /** |
39 | * SECTION:ctkbindings |
40 | * @Title: Bindings |
41 | * @Short_description: Key bindings for individual widgets |
42 | * @See_also: Keyboard Accelerators, Mnemonics, #CtkCssProvider |
43 | * |
44 | * #CtkBindingSet provides a mechanism for configuring CTK+ key bindings |
45 | * through CSS files. This eases key binding adjustments for application |
46 | * developers as well as users and provides CTK+ users or administrators |
47 | * with high key binding configurability which requires no application |
48 | * or toolkit side changes. |
49 | * |
50 | * In order for bindings to work in a custom widget implementation, the |
51 | * widget’s #CtkWidget:can-focus and #CtkWidget:has-focus properties |
52 | * must both be true. For example, by calling ctk_widget_set_can_focus() |
53 | * in the widget’s initialisation function; and by calling |
54 | * ctk_widget_grab_focus() when the widget is clicked. |
55 | * |
56 | * # Installing a key binding |
57 | * |
58 | * A CSS file binding consists of a “binding-set” definition and a match |
59 | * statement to apply the binding set to specific widget types. Details |
60 | * on the matching mechanism are described under |
61 | * [Selectors][ctkcssprovider-selectors] |
62 | * in the #CtkCssProvider documentation. Inside the binding set |
63 | * definition, key combinations are bound to one or more specific |
64 | * signal emissions on the target widget. Key combinations are strings |
65 | * consisting of an optional #CdkModifierType name and |
66 | * [key names][cdk3-Keyboard-Handling] |
67 | * such as those defined in `cdk/cdkkeysyms.h` |
68 | * or returned from cdk_keyval_name(), they have to be parsable by |
69 | * ctk_accelerator_parse(). Specifications of signal emissions consist |
70 | * of a string identifying the signal name, and a list of signal specific |
71 | * arguments in parenthesis. |
72 | * |
73 | * For example for binding Control and the left or right cursor keys |
74 | * of a #CtkEntry widget to the #CtkEntry::move-cursor signal (so |
75 | * movement occurs in 3-character steps), the following binding can be |
76 | * used: |
77 | * |
78 | * |[ <!-- language="CSS" --> |
79 | * @binding-set MoveCursor3 |
80 | * { |
81 | * bind "<Control>Right" { "move-cursor" (visual-positions, 3, 0) }; |
82 | * bind "<Control>Left" { "move-cursor" (visual-positions, -3, 0) }; |
83 | * } |
84 | * |
85 | * entry |
86 | * { |
87 | * -ctk-key-bindings: MoveCursor3; |
88 | * } |
89 | * ]| |
90 | * |
91 | * # Unbinding existing key bindings |
92 | * |
93 | * CTK+ already defines a number of useful bindings for the widgets |
94 | * it provides. Because custom bindings set up in CSS files take |
95 | * precedence over the default bindings shipped with CTK+, overriding |
96 | * existing bindings as demonstrated in |
97 | * [Installing a key binding][ctk-bindings-install] |
98 | * works as expected. The same mechanism can not be used to “unbind” |
99 | * existing bindings, however. |
100 | * |
101 | * |[ <!-- language="CSS" --> |
102 | * @binding-set MoveCursor3 |
103 | * { |
104 | * bind "<Control>Right" { }; |
105 | * bind "<Control>Left" { }; |
106 | * } |
107 | * |
108 | * entry |
109 | * { |
110 | * -ctk-key-bindings: MoveCursor3; |
111 | * } |
112 | * ]| |
113 | * |
114 | * The above example will not have the desired effect of causing |
115 | * “<Control>Right” and “<Control>Left” key presses to be ignored by CTK+. |
116 | * Instead, it just causes any existing bindings from the bindings set |
117 | * “MoveCursor3” to be deleted, so when “<Control>Right” or |
118 | * “<Control>Left” are pressed, no binding for these keys is found in |
119 | * binding set “MoveCursor3”. CTK+ will thus continue to search for |
120 | * matching key bindings, and will eventually lookup and find the default |
121 | * CTK+ bindings for entries which implement word movement. To keep CTK+ |
122 | * from activating its default bindings, the “unbind” keyword can be used |
123 | * like this: |
124 | * |
125 | * |[ <!-- language="CSS" --> |
126 | * @binding-set MoveCursor3 |
127 | * { |
128 | * unbind "<Control>Right"; |
129 | * unbind "<Control>Left"; |
130 | * } |
131 | * |
132 | * entry |
133 | * { |
134 | * -ctk-key-bindings: MoveCursor3; |
135 | * } |
136 | * ]| |
137 | * |
138 | * Now, CTK+ will find a match when looking up “<Control>Right” and |
139 | * “<Control>Left” key presses before it resorts to its default bindings, |
140 | * and the match instructs it to abort (“unbind”) the search, so the key |
141 | * presses are not consumed by this widget. As usual, further processing |
142 | * of the key presses, e.g. by an entry’s parent widget, is now possible. |
143 | */ |
144 | |
145 | /* --- defines --- */ |
146 | #define BINDING_MOD_MASK()(ctk_accelerator_get_default_mod_mask () | CDK_RELEASE_MASK) (ctk_accelerator_get_default_mod_mask () | CDK_RELEASE_MASK) |
147 | |
148 | |
149 | #define CTK_TYPE_IDENTIFIER(ctk_identifier_get_type ()) (ctk_identifier_get_type ()) |
150 | _CDK_EXTERN__attribute__((visibility("default"))) extern |
151 | GType ctk_identifier_get_type (void) G_GNUC_CONST__attribute__ ((__const__)); |
152 | |
153 | |
154 | /* --- structures --- */ |
155 | typedef enum { |
156 | CTK_BINDING_TOKEN_BIND, |
157 | CTK_BINDING_TOKEN_UNBIND |
158 | } CtkBindingTokens; |
159 | |
160 | /* --- variables --- */ |
161 | static GHashTable *binding_entry_hash_table = NULL((void*)0); |
162 | static GSList *binding_key_hashes = NULL((void*)0); |
163 | static GSList *binding_set_list = NULL((void*)0); |
164 | static const gchar key_class_binding_set[] = "ctk-class-binding-set"; |
165 | static GQuark key_id_class_binding_set = 0; |
166 | |
167 | |
168 | /* --- functions --- */ |
169 | GType |
170 | ctk_identifier_get_type (void) |
171 | { |
172 | static GType our_type = 0; |
173 | |
174 | if (our_type == 0) |
175 | { |
176 | GTypeInfo tinfo = { 0, }; |
177 | our_type = g_type_register_static (G_TYPE_STRING((GType) ((16) << (2))), I_("CtkIdentifier")g_intern_static_string ("CtkIdentifier"), &tinfo, 0); |
178 | } |
179 | |
180 | return our_type; |
181 | } |
182 | |
183 | static CtkBindingSignal* |
184 | binding_signal_new (const gchar *signal_name, |
185 | guint n_args) |
186 | { |
187 | CtkBindingSignal *signal; |
188 | |
189 | signal = (CtkBindingSignal *) g_slice_alloc0 (sizeof (CtkBindingSignal) + n_args * sizeof (CtkBindingArg)); |
190 | signal->next = NULL((void*)0); |
191 | signal->signal_name = (gchar *)g_intern_string (signal_name); |
192 | signal->n_args = n_args; |
193 | signal->args = (CtkBindingArg *)(signal + 1); |
194 | |
195 | return signal; |
196 | } |
197 | |
198 | static void |
199 | binding_signal_free (CtkBindingSignal *sig) |
200 | { |
201 | guint i; |
202 | |
203 | for (i = 0; i < sig->n_args; i++) |
204 | { |
205 | if (G_TYPE_FUNDAMENTAL (sig->args[i].arg_type)(g_type_fundamental (sig->args[i].arg_type)) == G_TYPE_STRING((GType) ((16) << (2)))) |
206 | g_free (sig->args[i].d.string_data); |
207 | } |
208 | g_slice_free1 (sizeof (CtkBindingSignal) + sig->n_args * sizeof (CtkBindingArg), sig); |
209 | } |
210 | |
211 | static guint |
212 | binding_entry_hash (gconstpointer key) |
213 | { |
214 | register const CtkBindingEntry *e = key; |
215 | register guint h; |
216 | |
217 | h = e->keyval; |
218 | h ^= e->modifiers; |
219 | |
220 | return h; |
221 | } |
222 | |
223 | static gint |
224 | binding_entries_compare (gconstpointer a, |
225 | gconstpointer b) |
226 | { |
227 | register const CtkBindingEntry *ea = a; |
228 | register const CtkBindingEntry *eb = b; |
229 | |
230 | return (ea->keyval == eb->keyval && ea->modifiers == eb->modifiers); |
231 | } |
232 | |
233 | static void |
234 | binding_key_hash_insert_entry (CtkKeyHash *key_hash, |
235 | CtkBindingEntry *entry) |
236 | { |
237 | guint keyval = entry->keyval; |
238 | |
239 | /* We store lowercased accelerators. To deal with this, if <Shift> |
240 | * was specified, uppercase. |
241 | */ |
242 | if (entry->modifiers & CDK_SHIFT_MASK) |
243 | { |
244 | if (keyval == CDK_KEY_Tab0xff09) |
245 | keyval = CDK_KEY_ISO_Left_Tab0xfe20; |
246 | else |
247 | keyval = cdk_keyval_to_upper (keyval); |
248 | } |
249 | |
250 | _ctk_key_hash_add_entry (key_hash, keyval, entry->modifiers & ~CDK_RELEASE_MASK, entry); |
251 | } |
252 | |
253 | static void |
254 | binding_key_hash_destroy (gpointer data) |
255 | { |
256 | CtkKeyHash *key_hash = data; |
257 | |
258 | binding_key_hashes = g_slist_remove (binding_key_hashes, key_hash); |
259 | _ctk_key_hash_free (key_hash); |
260 | } |
261 | |
262 | static void |
263 | insert_entries_into_key_hash (gpointer key G_GNUC_UNUSED__attribute__ ((__unused__)), |
264 | gpointer value, |
265 | gpointer data) |
266 | { |
267 | CtkKeyHash *key_hash = data; |
268 | CtkBindingEntry *entry = value; |
269 | |
270 | for (; entry; entry = entry->hash_next) |
271 | binding_key_hash_insert_entry (key_hash, entry); |
272 | } |
273 | |
274 | static CtkKeyHash * |
275 | binding_key_hash_for_keymap (CdkKeymap *keymap) |
276 | { |
277 | static GQuark key_hash_quark = 0; |
278 | CtkKeyHash *key_hash; |
279 | |
280 | if (!key_hash_quark) |
281 | key_hash_quark = g_quark_from_static_string ("ctk-binding-key-hash"); |
282 | |
283 | key_hash = g_object_get_qdata (G_OBJECT (keymap)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((keymap)), (((GType) ((20) << (2)))))))), key_hash_quark); |
284 | |
285 | if (!key_hash) |
286 | { |
287 | key_hash = _ctk_key_hash_new (keymap, NULL((void*)0)); |
288 | g_object_set_qdata_full (G_OBJECT (keymap)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((keymap)), (((GType) ((20) << (2)))))))), key_hash_quark, key_hash, binding_key_hash_destroy); |
289 | |
290 | if (binding_entry_hash_table) |
291 | g_hash_table_foreach (binding_entry_hash_table, |
292 | insert_entries_into_key_hash, |
293 | key_hash); |
294 | |
295 | binding_key_hashes = g_slist_prepend (binding_key_hashes, key_hash); |
296 | } |
297 | |
298 | return key_hash; |
299 | } |
300 | |
301 | |
302 | static CtkBindingEntry* |
303 | binding_entry_new (CtkBindingSet *binding_set, |
304 | guint keyval, |
305 | CdkModifierType modifiers) |
306 | { |
307 | GSList *tmp_list; |
308 | CtkBindingEntry *entry; |
309 | |
310 | if (!binding_entry_hash_table) |
311 | binding_entry_hash_table = g_hash_table_new (binding_entry_hash, binding_entries_compare); |
312 | |
313 | entry = g_new (CtkBindingEntry, 1)((CtkBindingEntry *) g_malloc_n ((1), sizeof (CtkBindingEntry ))); |
314 | entry->keyval = keyval; |
315 | entry->modifiers = modifiers; |
316 | entry->binding_set = binding_set, |
317 | entry->destroyed = FALSE(0); |
318 | entry->in_emission = FALSE(0); |
319 | entry->marks_unbound = FALSE(0); |
320 | entry->signals = NULL((void*)0); |
321 | |
322 | entry->set_next = binding_set->entries; |
323 | binding_set->entries = entry; |
324 | |
325 | entry->hash_next = g_hash_table_lookup (binding_entry_hash_table, entry); |
326 | if (entry->hash_next) |
327 | g_hash_table_remove (binding_entry_hash_table, entry->hash_next); |
328 | g_hash_table_insert (binding_entry_hash_table, entry, entry); |
329 | |
330 | for (tmp_list = binding_key_hashes; tmp_list; tmp_list = tmp_list->next) |
331 | { |
332 | CtkKeyHash *key_hash = tmp_list->data; |
333 | binding_key_hash_insert_entry (key_hash, entry); |
334 | } |
335 | |
336 | return entry; |
337 | } |
338 | |
339 | static void |
340 | binding_entry_free (CtkBindingEntry *entry) |
341 | { |
342 | CtkBindingSignal *sig; |
343 | |
344 | g_assert (entry->set_next == NULL &&do { if (entry->set_next == ((void*)0) && entry-> hash_next == ((void*)0) && entry->in_emission == ( 0) && entry->destroyed == (!(0))) ; else g_assertion_message_expr ("Ctk", "ctkbindings.c", 347, ((const char*) (__func__)), "entry->set_next == NULL && entry->hash_next == NULL && entry->in_emission == FALSE && entry->destroyed == TRUE" ); } while (0) |
345 | entry->hash_next == NULL &&do { if (entry->set_next == ((void*)0) && entry-> hash_next == ((void*)0) && entry->in_emission == ( 0) && entry->destroyed == (!(0))) ; else g_assertion_message_expr ("Ctk", "ctkbindings.c", 347, ((const char*) (__func__)), "entry->set_next == NULL && entry->hash_next == NULL && entry->in_emission == FALSE && entry->destroyed == TRUE" ); } while (0) |
346 | entry->in_emission == FALSE &&do { if (entry->set_next == ((void*)0) && entry-> hash_next == ((void*)0) && entry->in_emission == ( 0) && entry->destroyed == (!(0))) ; else g_assertion_message_expr ("Ctk", "ctkbindings.c", 347, ((const char*) (__func__)), "entry->set_next == NULL && entry->hash_next == NULL && entry->in_emission == FALSE && entry->destroyed == TRUE" ); } while (0) |
347 | entry->destroyed == TRUE)do { if (entry->set_next == ((void*)0) && entry-> hash_next == ((void*)0) && entry->in_emission == ( 0) && entry->destroyed == (!(0))) ; else g_assertion_message_expr ("Ctk", "ctkbindings.c", 347, ((const char*) (__func__)), "entry->set_next == NULL && entry->hash_next == NULL && entry->in_emission == FALSE && entry->destroyed == TRUE" ); } while (0); |
348 | |
349 | entry->destroyed = FALSE(0); |
350 | |
351 | sig = entry->signals; |
352 | while (sig) |
353 | { |
354 | CtkBindingSignal *prev; |
355 | |
356 | prev = sig; |
357 | sig = prev->next; |
358 | binding_signal_free (prev); |
359 | } |
360 | g_free (entry); |
361 | } |
362 | |
363 | static void |
364 | binding_entry_destroy (CtkBindingEntry *entry) |
365 | { |
366 | CtkBindingEntry *o_entry; |
367 | register CtkBindingEntry *tmp; |
368 | CtkBindingEntry *begin; |
369 | register CtkBindingEntry *last; |
370 | GSList *tmp_list; |
371 | |
372 | /* unlink from binding set |
373 | */ |
374 | last = NULL((void*)0); |
375 | tmp = entry->binding_set->entries; |
376 | while (tmp) |
377 | { |
378 | if (tmp == entry) |
379 | { |
380 | if (last) |
381 | last->set_next = entry->set_next; |
382 | else |
383 | entry->binding_set->entries = entry->set_next; |
384 | break; |
385 | } |
386 | last = tmp; |
387 | tmp = last->set_next; |
388 | } |
389 | entry->set_next = NULL((void*)0); |
390 | |
391 | o_entry = g_hash_table_lookup (binding_entry_hash_table, entry); |
392 | begin = o_entry; |
393 | last = NULL((void*)0); |
394 | tmp = begin; |
395 | while (tmp) |
396 | { |
397 | if (tmp == entry) |
398 | { |
399 | if (last) |
400 | last->hash_next = entry->hash_next; |
401 | else |
402 | begin = entry->hash_next; |
403 | break; |
404 | } |
405 | last = tmp; |
406 | tmp = last->hash_next; |
407 | } |
408 | entry->hash_next = NULL((void*)0); |
409 | |
410 | if (!begin) |
411 | g_hash_table_remove (binding_entry_hash_table, entry); |
412 | else if (begin != o_entry) |
413 | { |
414 | g_hash_table_remove (binding_entry_hash_table, entry); |
415 | g_hash_table_insert (binding_entry_hash_table, begin, begin); |
416 | } |
417 | |
418 | for (tmp_list = binding_key_hashes; tmp_list; tmp_list = tmp_list->next) |
419 | { |
420 | CtkKeyHash *key_hash = tmp_list->data; |
421 | _ctk_key_hash_remove_entry (key_hash, entry); |
422 | } |
423 | |
424 | entry->destroyed = TRUE(!(0)); |
425 | |
426 | if (!entry->in_emission) |
427 | binding_entry_free (entry); |
428 | } |
429 | |
430 | static CtkBindingEntry* |
431 | binding_ht_lookup_entry (CtkBindingSet *set, |
432 | guint keyval, |
433 | CdkModifierType modifiers) |
434 | { |
435 | CtkBindingEntry lookup_entry = { 0 }; |
436 | CtkBindingEntry *entry; |
437 | |
438 | if (!binding_entry_hash_table) |
439 | return NULL((void*)0); |
440 | |
441 | lookup_entry.keyval = keyval; |
442 | lookup_entry.modifiers = modifiers; |
443 | |
444 | entry = g_hash_table_lookup (binding_entry_hash_table, &lookup_entry); |
445 | for (; entry; entry = entry->hash_next) |
446 | if (entry->binding_set == set) |
447 | return entry; |
448 | |
449 | return NULL((void*)0); |
450 | } |
451 | |
452 | static gboolean |
453 | binding_compose_params (GObject *object, |
454 | CtkBindingArg *args, |
455 | GSignalQuery *query, |
456 | GValue **params_p) |
457 | { |
458 | GValue *params; |
459 | const GType *types; |
460 | guint i; |
461 | gboolean valid; |
462 | |
463 | params = g_new0 (GValue, query->n_params + 1)((GValue *) g_malloc0_n ((query->n_params + 1), sizeof (GValue ))); |
464 | *params_p = params; |
465 | |
466 | /* The instance we emit on is the first object in the array |
467 | */ |
468 | g_value_init (params, G_TYPE_OBJECT((GType) ((20) << (2)))); |
469 | g_value_set_object (params, G_OBJECT (object)((((GObject*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((object)), (((GType) ((20) << (2))))))))); |
470 | params++; |
471 | |
472 | types = query->param_types; |
473 | valid = TRUE(!(0)); |
474 | for (i = 1; i < query->n_params + 1 && valid; i++) |
475 | { |
476 | GValue tmp_value = G_VALUE_INIT{ 0, { { 0 } } }; |
477 | |
478 | g_value_init (params, *types); |
479 | |
480 | switch (G_TYPE_FUNDAMENTAL (args->arg_type)(g_type_fundamental (args->arg_type))) |
481 | { |
482 | case G_TYPE_DOUBLE((GType) ((15) << (2))): |
483 | g_value_init (&tmp_value, G_TYPE_DOUBLE((GType) ((15) << (2)))); |
484 | g_value_set_double (&tmp_value, args->d.double_data); |
485 | break; |
486 | case G_TYPE_LONG((GType) ((8) << (2))): |
487 | g_value_init (&tmp_value, G_TYPE_LONG((GType) ((8) << (2)))); |
488 | g_value_set_long (&tmp_value, args->d.long_data); |
489 | break; |
490 | case G_TYPE_STRING((GType) ((16) << (2))): |
491 | /* ctk_rc_parse_flags/enum() has fancier parsing for this; we can't call |
492 | * that since we don't have a GParamSpec, so just do something simple |
493 | */ |
494 | if (G_TYPE_FUNDAMENTAL (*types)(g_type_fundamental (*types)) == G_TYPE_ENUM((GType) ((12) << (2)))) |
495 | { |
496 | GEnumClass *class = G_ENUM_CLASS (g_type_class_ref (*types))((((GEnumClass*) (void *) g_type_check_class_cast ((GTypeClass *) ((g_type_class_ref (*types))), (((GType) ((12) << (2 )))))))); |
497 | |
498 | valid = FALSE(0); |
499 | |
500 | if (args->arg_type == CTK_TYPE_IDENTIFIER(ctk_identifier_get_type ())) |
501 | { |
502 | GEnumValue *enum_value = NULL((void*)0); |
503 | enum_value = g_enum_get_value_by_name (class, args->d.string_data); |
504 | if (!enum_value) |
505 | enum_value = g_enum_get_value_by_nick (class, args->d.string_data); |
506 | if (enum_value) |
507 | { |
508 | g_value_init (&tmp_value, *types); |
509 | g_value_set_enum (&tmp_value, enum_value->value); |
510 | valid = TRUE(!(0)); |
511 | } |
512 | } |
513 | |
514 | g_type_class_unref (class); |
515 | } |
516 | /* This is just a hack for compatibility with CTK+-1.2 where a string |
517 | * could be used for a single flag value / without the support for multiple |
518 | * values in ctk_rc_parse_flags(), this isn't very useful. |
519 | */ |
520 | else if (G_TYPE_FUNDAMENTAL (*types)(g_type_fundamental (*types)) == G_TYPE_FLAGS((GType) ((13) << (2)))) |
521 | { |
522 | GFlagsClass *class = G_FLAGS_CLASS (g_type_class_ref (*types))((((GFlagsClass*) (void *) g_type_check_class_cast ((GTypeClass *) ((g_type_class_ref (*types))), (((GType) ((13) << (2 )))))))); |
523 | |
524 | valid = FALSE(0); |
525 | |
526 | if (args->arg_type == CTK_TYPE_IDENTIFIER(ctk_identifier_get_type ())) |
527 | { |
528 | GFlagsValue *flags_value = NULL((void*)0); |
529 | flags_value = g_flags_get_value_by_name (class, args->d.string_data); |
530 | if (!flags_value) |
531 | flags_value = g_flags_get_value_by_nick (class, args->d.string_data); |
532 | if (flags_value) |
533 | { |
534 | g_value_init (&tmp_value, *types); |
535 | g_value_set_flags (&tmp_value, flags_value->value); |
536 | valid = TRUE(!(0)); |
537 | } |
538 | } |
539 | |
540 | g_type_class_unref (class); |
541 | } |
542 | else |
543 | { |
544 | g_value_init (&tmp_value, G_TYPE_STRING((GType) ((16) << (2)))); |
545 | g_value_set_static_string (&tmp_value, args->d.string_data); |
546 | } |
547 | break; |
548 | default: |
549 | valid = FALSE(0); |
550 | break; |
551 | } |
552 | |
553 | if (valid) |
554 | { |
555 | if (!g_value_transform (&tmp_value, params)) |
556 | valid = FALSE(0); |
557 | |
558 | g_value_unset (&tmp_value); |
559 | } |
560 | |
561 | types++; |
562 | params++; |
563 | args++; |
564 | } |
565 | |
566 | if (!valid) |
567 | { |
568 | guint j; |
569 | |
570 | for (j = 0; j < i; j++) |
571 | g_value_unset (&(*params_p)[j]); |
572 | |
573 | g_free (*params_p); |
574 | *params_p = NULL((void*)0); |
575 | } |
576 | |
577 | return valid; |
578 | } |
579 | |
580 | static gboolean |
581 | ctk_binding_entry_activate (CtkBindingEntry *entry, |
582 | GObject *object) |
583 | { |
584 | CtkBindingSignal *sig; |
585 | gboolean old_emission; |
586 | gboolean handled = FALSE(0); |
587 | gint i; |
588 | |
589 | old_emission = entry->in_emission; |
590 | entry->in_emission = TRUE(!(0)); |
591 | |
592 | g_object_ref (object)((__typeof__ (object)) (g_object_ref) (object)); |
593 | |
594 | for (sig = entry->signals; sig; sig = sig->next) |
595 | { |
596 | GSignalQuery query; |
597 | guint signal_id; |
598 | GValue *params = NULL((void*)0); |
599 | GValue return_val = G_VALUE_INIT{ 0, { { 0 } } }; |
600 | gchar *accelerator = NULL((void*)0); |
601 | |
602 | signal_id = g_signal_lookup (sig->signal_name, G_OBJECT_TYPE (object)(((((GTypeClass*) (((GTypeInstance*) (object))->g_class))-> g_type)))); |
603 | if (!signal_id) |
604 | { |
605 | accelerator = ctk_accelerator_name (entry->keyval, entry->modifiers); |
606 | g_warning ("ctk_binding_entry_activate(): binding \"%s::%s\": " |
607 | "could not find signal \"%s\" in the '%s' class ancestry", |
608 | entry->binding_set->set_name, |
609 | accelerator, |
610 | sig->signal_name, |
611 | g_type_name (G_OBJECT_TYPE (object)(((((GTypeClass*) (((GTypeInstance*) (object))->g_class))-> g_type))))); |
612 | g_free (accelerator); |
613 | continue; |
614 | } |
615 | |
616 | g_signal_query (signal_id, &query); |
617 | if (query.n_params != sig->n_args || |
618 | (query.return_type != G_TYPE_NONE((GType) ((1) << (2))) && query.return_type != G_TYPE_BOOLEAN((GType) ((5) << (2)))) || |
619 | !binding_compose_params (object, sig->args, &query, ¶ms)) |
620 | { |
621 | accelerator = ctk_accelerator_name (entry->keyval, entry->modifiers); |
622 | g_warning ("ctk_binding_entry_activate(): binding \"%s::%s\": " |
623 | "signature mismatch for signal \"%s\" in the '%s' class ancestry", |
624 | entry->binding_set->set_name, |
625 | accelerator, |
626 | sig->signal_name, |
627 | g_type_name (G_OBJECT_TYPE (object)(((((GTypeClass*) (((GTypeInstance*) (object))->g_class))-> g_type))))); |
628 | } |
629 | else if (!(query.signal_flags & G_SIGNAL_ACTION)) |
630 | { |
631 | accelerator = ctk_accelerator_name (entry->keyval, entry->modifiers); |
632 | g_warning ("ctk_binding_entry_activate(): binding \"%s::%s\": " |
633 | "signal \"%s\" in the '%s' class ancestry cannot be used for action emissions", |
634 | entry->binding_set->set_name, |
635 | accelerator, |
636 | sig->signal_name, |
637 | g_type_name (G_OBJECT_TYPE (object)(((((GTypeClass*) (((GTypeInstance*) (object))->g_class))-> g_type))))); |
638 | } |
639 | g_free (accelerator); |
640 | if (accelerator) |
641 | continue; |
642 | |
643 | if (query.return_type == G_TYPE_BOOLEAN((GType) ((5) << (2)))) |
644 | g_value_init (&return_val, G_TYPE_BOOLEAN((GType) ((5) << (2)))); |
645 | |
646 | g_signal_emitv (params, signal_id, 0, &return_val); |
647 | |
648 | if (query.return_type == G_TYPE_BOOLEAN((GType) ((5) << (2)))) |
649 | { |
650 | if (g_value_get_boolean (&return_val)) |
651 | handled = TRUE(!(0)); |
652 | g_value_unset (&return_val); |
653 | } |
654 | else |
655 | handled = TRUE(!(0)); |
656 | |
657 | if (params != NULL((void*)0)) |
658 | { |
659 | for (i = 0; i < query.n_params + 1; i++) |
660 | g_value_unset (¶ms[i]); |
661 | |
662 | g_free (params); |
663 | } |
664 | |
665 | if (entry->destroyed) |
666 | break; |
667 | } |
668 | |
669 | g_object_unref (object); |
670 | |
671 | entry->in_emission = old_emission; |
672 | if (entry->destroyed && !entry->in_emission) |
673 | binding_entry_free (entry); |
674 | |
675 | return handled; |
676 | } |
677 | |
678 | /** |
679 | * ctk_binding_set_new: (skip) |
680 | * @set_name: unique name of this binding set |
681 | * |
682 | * CTK+ maintains a global list of binding sets. Each binding set has |
683 | * a unique name which needs to be specified upon creation. |
684 | * |
685 | * Returns: (transfer none): new binding set |
686 | */ |
687 | CtkBindingSet* |
688 | ctk_binding_set_new (const gchar *set_name) |
689 | { |
690 | CtkBindingSet *binding_set; |
691 | |
692 | g_return_val_if_fail (set_name != NULL, NULL)do { if ((set_name != ((void*)0))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "set_name != NULL"); return (((void*)0)); } } while (0); |
693 | |
694 | binding_set = g_new (CtkBindingSet, 1)((CtkBindingSet *) g_malloc_n ((1), sizeof (CtkBindingSet))); |
695 | binding_set->set_name = (gchar *) g_intern_string (set_name); |
696 | binding_set->widget_path_pspecs = NULL((void*)0); |
697 | binding_set->widget_class_pspecs = NULL((void*)0); |
698 | binding_set->class_branch_pspecs = NULL((void*)0); |
699 | binding_set->entries = NULL((void*)0); |
700 | binding_set->current = NULL((void*)0); |
701 | binding_set->parsed = FALSE(0); |
702 | |
703 | binding_set_list = g_slist_prepend (binding_set_list, binding_set); |
704 | |
705 | return binding_set; |
706 | } |
707 | |
708 | /** |
709 | * ctk_binding_set_by_class: (skip) |
710 | * @object_class: a valid #GObject class |
711 | * |
712 | * This function returns the binding set named after the type name of |
713 | * the passed in class structure. New binding sets are created on |
714 | * demand by this function. |
715 | * |
716 | * Returns: (transfer none): the binding set corresponding to |
717 | * @object_class |
718 | */ |
719 | CtkBindingSet* |
720 | ctk_binding_set_by_class (gpointer object_class) |
721 | { |
722 | GObjectClass *class = object_class; |
723 | CtkBindingSet* binding_set; |
724 | |
725 | g_return_val_if_fail (G_IS_OBJECT_CLASS (class), NULL)do { if (((((__extension__ ({ GTypeClass *__class = (GTypeClass *) ((class)); GType __t = (((GType) ((20) << (2)))); gboolean __r; if (!__class) __r = (0); else if (__class->g_type == __t) __r = (!(0)); else __r = g_type_check_class_is_a (__class , __t); __r; })))))) { } else { g_return_if_fail_warning ("Ctk" , ((const char*) (__func__)), "G_IS_OBJECT_CLASS (class)"); return (((void*)0)); } } while (0); |
726 | |
727 | if (!key_id_class_binding_set) |
728 | key_id_class_binding_set = g_quark_from_static_string (key_class_binding_set); |
729 | |
730 | binding_set = g_dataset_id_get_data (class, key_id_class_binding_set); |
731 | |
732 | if (binding_set) |
733 | return binding_set; |
734 | |
735 | binding_set = ctk_binding_set_new (g_type_name (G_OBJECT_CLASS_TYPE (class)((((GTypeClass*) (class))->g_type)))); |
736 | g_dataset_id_set_data (class, key_id_class_binding_set, binding_set)g_dataset_id_set_data_full ((class), (key_id_class_binding_set ), (binding_set), ((void*)0)); |
737 | |
738 | return binding_set; |
739 | } |
740 | |
741 | static CtkBindingSet* |
742 | ctk_binding_set_find_interned (const gchar *set_name) |
743 | { |
744 | GSList *slist; |
745 | |
746 | for (slist = binding_set_list; slist; slist = slist->next) |
747 | { |
748 | CtkBindingSet *binding_set; |
749 | |
750 | binding_set = slist->data; |
751 | if (binding_set->set_name == set_name) |
752 | return binding_set; |
753 | } |
754 | |
755 | return NULL((void*)0); |
756 | } |
757 | |
758 | /** |
759 | * ctk_binding_set_find: |
760 | * @set_name: unique binding set name |
761 | * |
762 | * Find a binding set by its globally unique name. |
763 | * |
764 | * The @set_name can either be a name used for ctk_binding_set_new() |
765 | * or the type name of a class used in ctk_binding_set_by_class(). |
766 | * |
767 | * Returns: (nullable) (transfer none): %NULL or the specified binding set |
768 | */ |
769 | CtkBindingSet* |
770 | ctk_binding_set_find (const gchar *set_name) |
771 | { |
772 | g_return_val_if_fail (set_name != NULL, NULL)do { if ((set_name != ((void*)0))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "set_name != NULL"); return (((void*)0)); } } while (0); |
773 | |
774 | return ctk_binding_set_find_interned (g_intern_string (set_name)); |
775 | } |
776 | |
777 | /** |
778 | * ctk_binding_set_activate: |
779 | * @binding_set: a #CtkBindingSet set to activate |
780 | * @keyval: key value of the binding |
781 | * @modifiers: key modifier of the binding |
782 | * @object: object to activate when binding found |
783 | * |
784 | * Find a key binding matching @keyval and @modifiers within |
785 | * @binding_set and activate the binding on @object. |
786 | * |
787 | * Returns: %TRUE if a binding was found and activated |
788 | */ |
789 | gboolean |
790 | ctk_binding_set_activate (CtkBindingSet *binding_set, |
791 | guint keyval, |
792 | CdkModifierType modifiers, |
793 | GObject *object) |
794 | { |
795 | CtkBindingEntry *entry; |
796 | |
797 | g_return_val_if_fail (binding_set != NULL, FALSE)do { if ((binding_set != ((void*)0))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "binding_set != NULL"); return ((0)); } } while (0); |
798 | g_return_val_if_fail (G_IS_OBJECT (object), FALSE)do { if (((((g_type_check_instance_is_fundamentally_a ((GTypeInstance *) ((object)), (((GType) ((20) << (2)))))))))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__) ), "G_IS_OBJECT (object)"); return ((0)); } } while (0); |
799 | |
800 | keyval = cdk_keyval_to_lower (keyval); |
801 | modifiers = modifiers & BINDING_MOD_MASK ()(ctk_accelerator_get_default_mod_mask () | CDK_RELEASE_MASK); |
802 | |
803 | entry = binding_ht_lookup_entry (binding_set, keyval, modifiers); |
804 | if (entry) |
805 | return ctk_binding_entry_activate (entry, object); |
806 | |
807 | return FALSE(0); |
808 | } |
809 | |
810 | static void |
811 | ctk_binding_entry_clear_internal (CtkBindingSet *binding_set, |
812 | guint keyval, |
813 | CdkModifierType modifiers) |
814 | { |
815 | CtkBindingEntry *entry; |
816 | |
817 | keyval = cdk_keyval_to_lower (keyval); |
818 | modifiers = modifiers & BINDING_MOD_MASK ()(ctk_accelerator_get_default_mod_mask () | CDK_RELEASE_MASK); |
819 | |
820 | entry = binding_ht_lookup_entry (binding_set, keyval, modifiers); |
821 | if (entry) |
822 | binding_entry_destroy (entry); |
823 | |
824 | entry = binding_entry_new (binding_set, keyval, modifiers); |
Value stored to 'entry' is never read | |
825 | } |
826 | |
827 | /** |
828 | * ctk_binding_entry_skip: |
829 | * @binding_set: a #CtkBindingSet to skip an entry of |
830 | * @keyval: key value of binding to skip |
831 | * @modifiers: key modifier of binding to skip |
832 | * |
833 | * Install a binding on @binding_set which causes key lookups |
834 | * to be aborted, to prevent bindings from lower priority sets |
835 | * to be activated. |
836 | * |
837 | * Since: 2.12 |
838 | */ |
839 | void |
840 | ctk_binding_entry_skip (CtkBindingSet *binding_set, |
841 | guint keyval, |
842 | CdkModifierType modifiers) |
843 | { |
844 | CtkBindingEntry *entry; |
845 | |
846 | g_return_if_fail (binding_set != NULL)do { if ((binding_set != ((void*)0))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "binding_set != NULL"); return ; } } while (0); |
847 | |
848 | keyval = cdk_keyval_to_lower (keyval); |
849 | modifiers = modifiers & BINDING_MOD_MASK ()(ctk_accelerator_get_default_mod_mask () | CDK_RELEASE_MASK); |
850 | |
851 | entry = binding_ht_lookup_entry (binding_set, keyval, modifiers); |
852 | if (entry) |
853 | binding_entry_destroy (entry); |
854 | |
855 | entry = binding_entry_new (binding_set, keyval, modifiers); |
856 | entry->marks_unbound = TRUE(!(0)); |
857 | } |
858 | |
859 | /** |
860 | * ctk_binding_entry_remove: |
861 | * @binding_set: a #CtkBindingSet to remove an entry of |
862 | * @keyval: key value of binding to remove |
863 | * @modifiers: key modifier of binding to remove |
864 | * |
865 | * Remove a binding previously installed via |
866 | * ctk_binding_entry_add_signal() on @binding_set. |
867 | */ |
868 | void |
869 | ctk_binding_entry_remove (CtkBindingSet *binding_set, |
870 | guint keyval, |
871 | CdkModifierType modifiers) |
872 | { |
873 | CtkBindingEntry *entry; |
874 | |
875 | g_return_if_fail (binding_set != NULL)do { if ((binding_set != ((void*)0))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "binding_set != NULL"); return ; } } while (0); |
876 | |
877 | keyval = cdk_keyval_to_lower (keyval); |
878 | modifiers = modifiers & BINDING_MOD_MASK ()(ctk_accelerator_get_default_mod_mask () | CDK_RELEASE_MASK); |
879 | |
880 | entry = binding_ht_lookup_entry (binding_set, keyval, modifiers); |
881 | if (entry) |
882 | binding_entry_destroy (entry); |
883 | } |
884 | |
885 | /** |
886 | * ctk_binding_entry_add_signall: |
887 | * @binding_set: a #CtkBindingSet to add a signal to |
888 | * @keyval: key value |
889 | * @modifiers: key modifier |
890 | * @signal_name: signal name to be bound |
891 | * @binding_args: (transfer none) (element-type CtkBindingArg): |
892 | * list of #CtkBindingArg signal arguments |
893 | * |
894 | * Override or install a new key binding for @keyval with @modifiers on |
895 | * @binding_set. |
896 | */ |
897 | void |
898 | ctk_binding_entry_add_signall (CtkBindingSet *binding_set, |
899 | guint keyval, |
900 | CdkModifierType modifiers, |
901 | const gchar *signal_name, |
902 | GSList *binding_args) |
903 | { |
904 | _ctk_binding_entry_add_signall (binding_set, |
905 | keyval, modifiers, |
906 | signal_name, binding_args); |
907 | } |
908 | |
909 | void |
910 | _ctk_binding_entry_add_signall (CtkBindingSet *binding_set, |
911 | guint keyval, |
912 | CdkModifierType modifiers, |
913 | const gchar *signal_name, |
914 | GSList *binding_args) |
915 | { |
916 | CtkBindingEntry *entry; |
917 | CtkBindingSignal *signal, **signal_p; |
918 | GSList *slist; |
919 | guint n = 0; |
920 | CtkBindingArg *arg; |
921 | |
922 | g_return_if_fail (binding_set != NULL)do { if ((binding_set != ((void*)0))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "binding_set != NULL"); return ; } } while (0); |
923 | g_return_if_fail (signal_name != NULL)do { if ((signal_name != ((void*)0))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "signal_name != NULL"); return ; } } while (0); |
924 | |
925 | keyval = cdk_keyval_to_lower (keyval); |
926 | modifiers = modifiers & BINDING_MOD_MASK ()(ctk_accelerator_get_default_mod_mask () | CDK_RELEASE_MASK); |
927 | |
928 | signal = binding_signal_new (signal_name, g_slist_length (binding_args)); |
929 | |
930 | arg = signal->args; |
931 | for (slist = binding_args; slist; slist = slist->next) |
932 | { |
933 | CtkBindingArg *tmp_arg; |
934 | |
935 | tmp_arg = slist->data; |
936 | if (!tmp_arg) |
937 | { |
938 | g_warning ("ctk_binding_entry_add_signall(): arg[%u] is 'NULL'", n); |
939 | binding_signal_free (signal); |
940 | return; |
941 | } |
942 | switch (G_TYPE_FUNDAMENTAL (tmp_arg->arg_type)(g_type_fundamental (tmp_arg->arg_type))) |
943 | { |
944 | case G_TYPE_LONG((GType) ((8) << (2))): |
945 | arg->arg_type = G_TYPE_LONG((GType) ((8) << (2))); |
946 | arg->d.long_data = tmp_arg->d.long_data; |
947 | break; |
948 | case G_TYPE_DOUBLE((GType) ((15) << (2))): |
949 | arg->arg_type = G_TYPE_DOUBLE((GType) ((15) << (2))); |
950 | arg->d.double_data = tmp_arg->d.double_data; |
951 | break; |
952 | case G_TYPE_STRING((GType) ((16) << (2))): |
953 | if (tmp_arg->arg_type != CTK_TYPE_IDENTIFIER(ctk_identifier_get_type ())) |
954 | arg->arg_type = G_TYPE_STRING((GType) ((16) << (2))); |
955 | else |
956 | arg->arg_type = CTK_TYPE_IDENTIFIER(ctk_identifier_get_type ()); |
957 | arg->d.string_data = g_strdup (tmp_arg->d.string_data)g_strdup_inline (tmp_arg->d.string_data); |
958 | if (!arg->d.string_data) |
959 | { |
960 | g_warning ("ctk_binding_entry_add_signall(): value of 'string' arg[%u] is 'NULL'", n); |
961 | binding_signal_free (signal); |
962 | return; |
963 | } |
964 | break; |
965 | default: |
966 | g_warning ("ctk_binding_entry_add_signall(): unsupported type '%s' for arg[%u]", |
967 | g_type_name (arg->arg_type), n); |
968 | binding_signal_free (signal); |
969 | return; |
970 | } |
971 | arg++; |
972 | n++; |
973 | } |
974 | |
975 | entry = binding_ht_lookup_entry (binding_set, keyval, modifiers); |
976 | if (!entry) |
977 | { |
978 | ctk_binding_entry_clear_internal (binding_set, keyval, modifiers); |
979 | entry = binding_ht_lookup_entry (binding_set, keyval, modifiers); |
980 | } |
981 | signal_p = &entry->signals; |
982 | while (*signal_p) |
983 | signal_p = &(*signal_p)->next; |
984 | *signal_p = signal; |
985 | } |
986 | |
987 | /** |
988 | * ctk_binding_entry_add_signal: |
989 | * @binding_set: a #CtkBindingSet to install an entry for |
990 | * @keyval: key value of binding to install |
991 | * @modifiers: key modifier of binding to install |
992 | * @signal_name: signal to execute upon activation |
993 | * @n_args: number of arguments to @signal_name |
994 | * @...: arguments to @signal_name |
995 | * |
996 | * Override or install a new key binding for @keyval with @modifiers on |
997 | * @binding_set. When the binding is activated, @signal_name will be |
998 | * emitted on the target widget, with @n_args @Varargs used as |
999 | * arguments. |
1000 | * |
1001 | * Each argument to the signal must be passed as a pair of varargs: the |
1002 | * #GType of the argument, followed by the argument value (which must |
1003 | * be of the given type). There must be @n_args pairs in total. |
1004 | * |
1005 | * ## Adding a Key Binding |
1006 | * |
1007 | * |[<!-- language="C" --> |
1008 | * CtkBindingSet *binding_set; |
1009 | * CdkModifierType modmask = CDK_CONTROL_MASK; |
1010 | * int count = 1; |
1011 | * ctk_binding_entry_add_signal (binding_set, |
1012 | * CDK_KEY_space, |
1013 | * modmask, |
1014 | * "move-cursor", 2, |
1015 | * CTK_TYPE_MOVEMENT_STEP, CTK_MOVEMENT_PAGES, |
1016 | * G_TYPE_INT, count, |
1017 | * G_TYPE_BOOLEAN, FALSE); |
1018 | * ]| |
1019 | */ |
1020 | void |
1021 | ctk_binding_entry_add_signal (CtkBindingSet *binding_set, |
1022 | guint keyval, |
1023 | CdkModifierType modifiers, |
1024 | const gchar *signal_name, |
1025 | guint n_args, |
1026 | ...) |
1027 | { |
1028 | GSList *slist, *free_slist; |
1029 | va_list args; |
1030 | guint i; |
1031 | |
1032 | g_return_if_fail (binding_set != NULL)do { if ((binding_set != ((void*)0))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "binding_set != NULL"); return ; } } while (0); |
1033 | g_return_if_fail (signal_name != NULL)do { if ((signal_name != ((void*)0))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "signal_name != NULL"); return ; } } while (0); |
1034 | |
1035 | va_start (args, n_args)__builtin_va_start(args, n_args); |
1036 | slist = NULL((void*)0); |
1037 | for (i = 0; i < n_args; i++) |
1038 | { |
1039 | CtkBindingArg *arg; |
1040 | |
1041 | arg = g_slice_new0 (CtkBindingArg)((CtkBindingArg*) g_slice_alloc0 (sizeof (CtkBindingArg))); |
1042 | slist = g_slist_prepend (slist, arg); |
1043 | |
1044 | arg->arg_type = va_arg (args, GType)__builtin_va_arg(args, GType); |
1045 | switch (G_TYPE_FUNDAMENTAL (arg->arg_type)(g_type_fundamental (arg->arg_type))) |
1046 | { |
1047 | case G_TYPE_CHAR((GType) ((3) << (2))): |
1048 | case G_TYPE_UCHAR((GType) ((4) << (2))): |
1049 | case G_TYPE_INT((GType) ((6) << (2))): |
1050 | case G_TYPE_UINT((GType) ((7) << (2))): |
1051 | case G_TYPE_BOOLEAN((GType) ((5) << (2))): |
1052 | case G_TYPE_ENUM((GType) ((12) << (2))): |
1053 | case G_TYPE_FLAGS((GType) ((13) << (2))): |
1054 | arg->arg_type = G_TYPE_LONG((GType) ((8) << (2))); |
1055 | arg->d.long_data = va_arg (args, gint)__builtin_va_arg(args, gint); |
1056 | break; |
1057 | case G_TYPE_LONG((GType) ((8) << (2))): |
1058 | case G_TYPE_ULONG((GType) ((9) << (2))): |
1059 | arg->arg_type = G_TYPE_LONG((GType) ((8) << (2))); |
1060 | arg->d.long_data = va_arg (args, glong)__builtin_va_arg(args, glong); |
1061 | break; |
1062 | case G_TYPE_FLOAT((GType) ((14) << (2))): |
1063 | case G_TYPE_DOUBLE((GType) ((15) << (2))): |
1064 | arg->arg_type = G_TYPE_DOUBLE((GType) ((15) << (2))); |
1065 | arg->d.double_data = va_arg (args, gdouble)__builtin_va_arg(args, gdouble); |
1066 | break; |
1067 | case G_TYPE_STRING((GType) ((16) << (2))): |
1068 | if (arg->arg_type != CTK_TYPE_IDENTIFIER(ctk_identifier_get_type ())) |
1069 | arg->arg_type = G_TYPE_STRING((GType) ((16) << (2))); |
1070 | arg->d.string_data = va_arg (args, gchar*)__builtin_va_arg(args, gchar*); |
1071 | if (!arg->d.string_data) |
1072 | { |
1073 | g_warning ("ctk_binding_entry_add_signal(): type '%s' arg[%u] is 'NULL'", |
1074 | g_type_name (arg->arg_type), |
1075 | i); |
1076 | i += n_args + 1; |
1077 | } |
1078 | break; |
1079 | default: |
1080 | g_warning ("ctk_binding_entry_add_signal(): unsupported type '%s' for arg[%u]", |
1081 | g_type_name (arg->arg_type), i); |
1082 | i += n_args + 1; |
1083 | break; |
1084 | } |
1085 | } |
1086 | va_end (args)__builtin_va_end(args); |
1087 | |
1088 | if (i == n_args || i == 0) |
1089 | { |
1090 | slist = g_slist_reverse (slist); |
1091 | _ctk_binding_entry_add_signall (binding_set, keyval, modifiers, signal_name, slist); |
1092 | } |
1093 | |
1094 | free_slist = slist; |
1095 | while (slist) |
1096 | { |
1097 | g_slice_free (CtkBindingArg, slist->data)do { if (1) g_slice_free1 (sizeof (CtkBindingArg), (slist-> data)); else (void) ((CtkBindingArg*) 0 == (slist->data)); } while (0); |
1098 | slist = slist->next; |
1099 | } |
1100 | g_slist_free (free_slist); |
1101 | } |
1102 | |
1103 | static guint |
1104 | ctk_binding_parse_signal (GScanner *scanner, |
1105 | CtkBindingSet *binding_set, |
1106 | guint keyval, |
1107 | CdkModifierType modifiers) |
1108 | { |
1109 | gchar *signal; |
1110 | guint expected_token = 0; |
1111 | GSList *args; |
1112 | GSList *slist; |
1113 | gboolean done; |
1114 | gboolean negate; |
1115 | gboolean need_arg; |
1116 | gboolean seen_comma; |
1117 | |
1118 | g_return_val_if_fail (scanner != NULL, G_TOKEN_ERROR)do { if ((scanner != ((void*)0))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "scanner != NULL"); return (G_TOKEN_ERROR); } } while (0); |
1119 | |
1120 | g_scanner_get_next_token (scanner); |
1121 | |
1122 | if (scanner->token != G_TOKEN_STRING) |
1123 | return G_TOKEN_STRING; |
1124 | |
1125 | g_scanner_peek_next_token (scanner); |
1126 | |
1127 | if (scanner->next_token != '(') |
1128 | { |
1129 | g_scanner_get_next_token (scanner); |
1130 | return '('; |
1131 | } |
1132 | |
1133 | signal = g_strdup (scanner->value.v_string)g_strdup_inline (scanner->value.v_string); |
1134 | g_scanner_get_next_token (scanner); |
1135 | |
1136 | negate = FALSE(0); |
1137 | args = NULL((void*)0); |
1138 | done = FALSE(0); |
1139 | need_arg = TRUE(!(0)); |
1140 | seen_comma = FALSE(0); |
1141 | scanner->config->scan_symbols = FALSE(0); |
1142 | |
1143 | do |
1144 | { |
1145 | CtkBindingArg *arg; |
1146 | |
1147 | if (need_arg) |
1148 | expected_token = G_TOKEN_INT; |
1149 | else |
1150 | expected_token = ')'; |
1151 | |
1152 | g_scanner_get_next_token (scanner); |
1153 | |
1154 | switch ((guint) scanner->token) |
1155 | { |
1156 | case G_TOKEN_FLOAT: |
1157 | if (need_arg) |
1158 | { |
1159 | need_arg = FALSE(0); |
1160 | arg = g_new (CtkBindingArg, 1)((CtkBindingArg *) g_malloc_n ((1), sizeof (CtkBindingArg))); |
1161 | arg->arg_type = G_TYPE_DOUBLE((GType) ((15) << (2))); |
1162 | arg->d.double_data = scanner->value.v_float; |
1163 | |
1164 | if (negate) |
1165 | { |
1166 | arg->d.double_data = - arg->d.double_data; |
1167 | negate = FALSE(0); |
1168 | } |
1169 | args = g_slist_prepend (args, arg); |
1170 | } |
1171 | else |
1172 | done = TRUE(!(0)); |
1173 | |
1174 | break; |
1175 | case G_TOKEN_INT: |
1176 | if (need_arg) |
1177 | { |
1178 | need_arg = FALSE(0); |
1179 | arg = g_new (CtkBindingArg, 1)((CtkBindingArg *) g_malloc_n ((1), sizeof (CtkBindingArg))); |
1180 | arg->arg_type = G_TYPE_LONG((GType) ((8) << (2))); |
1181 | arg->d.long_data = scanner->value.v_int; |
1182 | |
1183 | if (negate) |
1184 | { |
1185 | arg->d.long_data = - arg->d.long_data; |
1186 | negate = FALSE(0); |
1187 | } |
1188 | args = g_slist_prepend (args, arg); |
1189 | } |
1190 | else |
1191 | done = TRUE(!(0)); |
1192 | break; |
1193 | case G_TOKEN_STRING: |
1194 | if (need_arg && !negate) |
1195 | { |
1196 | need_arg = FALSE(0); |
1197 | arg = g_new (CtkBindingArg, 1)((CtkBindingArg *) g_malloc_n ((1), sizeof (CtkBindingArg))); |
1198 | arg->arg_type = G_TYPE_STRING((GType) ((16) << (2))); |
1199 | arg->d.string_data = g_strdup (scanner->value.v_string)g_strdup_inline (scanner->value.v_string); |
1200 | args = g_slist_prepend (args, arg); |
1201 | } |
1202 | else |
1203 | done = TRUE(!(0)); |
1204 | |
1205 | break; |
1206 | case G_TOKEN_IDENTIFIER: |
1207 | if (need_arg && !negate) |
1208 | { |
1209 | need_arg = FALSE(0); |
1210 | arg = g_new (CtkBindingArg, 1)((CtkBindingArg *) g_malloc_n ((1), sizeof (CtkBindingArg))); |
1211 | arg->arg_type = CTK_TYPE_IDENTIFIER(ctk_identifier_get_type ()); |
1212 | arg->d.string_data = g_strdup (scanner->value.v_identifier)g_strdup_inline (scanner->value.v_identifier); |
1213 | args = g_slist_prepend (args, arg); |
1214 | } |
1215 | else |
1216 | done = TRUE(!(0)); |
1217 | |
1218 | break; |
1219 | case '-': |
1220 | if (!need_arg) |
1221 | done = TRUE(!(0)); |
1222 | else if (negate) |
1223 | { |
1224 | expected_token = G_TOKEN_INT; |
1225 | done = TRUE(!(0)); |
1226 | } |
1227 | else |
1228 | negate = TRUE(!(0)); |
1229 | |
1230 | break; |
1231 | case ',': |
1232 | seen_comma = TRUE(!(0)); |
1233 | if (need_arg) |
1234 | done = TRUE(!(0)); |
1235 | else |
1236 | need_arg = TRUE(!(0)); |
1237 | |
1238 | break; |
1239 | case ')': |
1240 | if (!(need_arg && seen_comma) && !negate) |
1241 | { |
1242 | args = g_slist_reverse (args); |
1243 | _ctk_binding_entry_add_signall (binding_set, |
1244 | keyval, |
1245 | modifiers, |
1246 | signal, |
1247 | args); |
1248 | expected_token = G_TOKEN_NONE; |
1249 | } |
1250 | |
1251 | done = TRUE(!(0)); |
1252 | break; |
1253 | default: |
1254 | done = TRUE(!(0)); |
1255 | break; |
1256 | } |
1257 | } |
1258 | while (!done); |
1259 | |
1260 | scanner->config->scan_symbols = TRUE(!(0)); |
1261 | |
1262 | for (slist = args; slist; slist = slist->next) |
1263 | { |
1264 | CtkBindingArg *arg; |
1265 | |
1266 | arg = slist->data; |
1267 | |
1268 | if (G_TYPE_FUNDAMENTAL (arg->arg_type)(g_type_fundamental (arg->arg_type)) == G_TYPE_STRING((GType) ((16) << (2)))) |
1269 | g_free (arg->d.string_data); |
1270 | g_free (arg); |
1271 | } |
1272 | |
1273 | g_slist_free (args); |
1274 | g_free (signal); |
1275 | |
1276 | return expected_token; |
1277 | } |
1278 | |
1279 | static inline guint |
1280 | ctk_binding_parse_bind (GScanner *scanner, |
1281 | CtkBindingSet *binding_set) |
1282 | { |
1283 | guint keyval = 0; |
1284 | CdkModifierType modifiers = 0; |
1285 | gboolean unbind = FALSE(0); |
1286 | |
1287 | g_return_val_if_fail (scanner != NULL, G_TOKEN_ERROR)do { if ((scanner != ((void*)0))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "scanner != NULL"); return (G_TOKEN_ERROR); } } while (0); |
1288 | |
1289 | g_scanner_get_next_token (scanner); |
1290 | |
1291 | if (scanner->token != G_TOKEN_SYMBOL) |
1292 | return G_TOKEN_SYMBOL; |
1293 | |
1294 | if (scanner->value.v_symbol != GUINT_TO_POINTER (CTK_BINDING_TOKEN_BIND)((gpointer) (gulong) (CTK_BINDING_TOKEN_BIND)) && |
1295 | scanner->value.v_symbol != GUINT_TO_POINTER (CTK_BINDING_TOKEN_UNBIND)((gpointer) (gulong) (CTK_BINDING_TOKEN_UNBIND))) |
1296 | return G_TOKEN_SYMBOL; |
1297 | |
1298 | unbind = (scanner->value.v_symbol == GUINT_TO_POINTER (CTK_BINDING_TOKEN_UNBIND)((gpointer) (gulong) (CTK_BINDING_TOKEN_UNBIND))); |
1299 | g_scanner_get_next_token (scanner); |
1300 | |
1301 | if (scanner->token != (guint) G_TOKEN_STRING) |
1302 | return G_TOKEN_STRING; |
1303 | |
1304 | ctk_accelerator_parse (scanner->value.v_string, &keyval, &modifiers); |
1305 | modifiers &= BINDING_MOD_MASK ()(ctk_accelerator_get_default_mod_mask () | CDK_RELEASE_MASK); |
1306 | |
1307 | if (keyval == 0) |
1308 | return G_TOKEN_STRING; |
1309 | |
1310 | if (unbind) |
1311 | { |
1312 | ctk_binding_entry_skip (binding_set, keyval, modifiers); |
1313 | return G_TOKEN_NONE; |
1314 | } |
1315 | |
1316 | g_scanner_get_next_token (scanner); |
1317 | |
1318 | if (scanner->token != '{') |
1319 | return '{'; |
1320 | |
1321 | ctk_binding_entry_clear_internal (binding_set, keyval, modifiers); |
1322 | g_scanner_peek_next_token (scanner); |
1323 | |
1324 | while (scanner->next_token != '}') |
1325 | { |
1326 | guint expected_token; |
1327 | |
1328 | switch (scanner->next_token) |
1329 | { |
1330 | case G_TOKEN_STRING: |
1331 | expected_token = ctk_binding_parse_signal (scanner, |
1332 | binding_set, |
1333 | keyval, |
1334 | modifiers); |
1335 | if (expected_token != G_TOKEN_NONE) |
1336 | return expected_token; |
1337 | break; |
1338 | default: |
1339 | g_scanner_get_next_token (scanner); |
1340 | return '}'; |
1341 | } |
1342 | |
1343 | g_scanner_peek_next_token (scanner); |
1344 | } |
1345 | |
1346 | g_scanner_get_next_token (scanner); |
1347 | |
1348 | return G_TOKEN_NONE; |
1349 | } |
1350 | |
1351 | static GScanner * |
1352 | create_signal_scanner (void) |
1353 | { |
1354 | GScanner *scanner; |
1355 | |
1356 | scanner = g_scanner_new (NULL((void*)0)); |
1357 | scanner->config->cset_identifier_nth = G_CSET_a_2_z"abcdefghijklmnopqrstuvwxyz" G_CSET_A_2_Z"ABCDEFGHIJKLMNOPQRSTUVWXYZ" G_CSET_DIGITS"0123456789" "-_"; |
1358 | |
1359 | g_scanner_scope_add_symbol (scanner, 0, "bind", GUINT_TO_POINTER (CTK_BINDING_TOKEN_BIND)((gpointer) (gulong) (CTK_BINDING_TOKEN_BIND))); |
1360 | g_scanner_scope_add_symbol (scanner, 0, "unbind", GUINT_TO_POINTER (CTK_BINDING_TOKEN_UNBIND)((gpointer) (gulong) (CTK_BINDING_TOKEN_UNBIND))); |
1361 | |
1362 | g_scanner_set_scope (scanner, 0); |
1363 | |
1364 | return scanner; |
1365 | } |
1366 | |
1367 | /** |
1368 | * ctk_binding_entry_add_signal_from_string: |
1369 | * @binding_set: a #CtkBindingSet |
1370 | * @signal_desc: a signal description |
1371 | * |
1372 | * Parses a signal description from @signal_desc and incorporates |
1373 | * it into @binding_set. |
1374 | * |
1375 | * Signal descriptions may either bind a key combination to |
1376 | * one or more signals: |
1377 | * |[ |
1378 | * bind "key" { |
1379 | * "signalname" (param, ...) |
1380 | * ... |
1381 | * } |
1382 | * ]| |
1383 | * |
1384 | * Or they may also unbind a key combination: |
1385 | * |[ |
1386 | * unbind "key" |
1387 | * ]| |
1388 | * |
1389 | * Key combinations must be in a format that can be parsed by |
1390 | * ctk_accelerator_parse(). |
1391 | * |
1392 | * Returns: %G_TOKEN_NONE if the signal was successfully parsed and added, |
1393 | * the expected token otherwise |
1394 | * |
1395 | * Since: 3.0 |
1396 | */ |
1397 | GTokenType |
1398 | ctk_binding_entry_add_signal_from_string (CtkBindingSet *binding_set, |
1399 | const gchar *signal_desc) |
1400 | { |
1401 | static GScanner *scanner = NULL((void*)0); |
1402 | GTokenType ret; |
1403 | |
1404 | g_return_val_if_fail (binding_set != NULL, G_TOKEN_NONE)do { if ((binding_set != ((void*)0))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "binding_set != NULL"); return (G_TOKEN_NONE); } } while (0); |
1405 | g_return_val_if_fail (signal_desc != NULL, G_TOKEN_NONE)do { if ((signal_desc != ((void*)0))) { } else { g_return_if_fail_warning ("Ctk", ((const char*) (__func__)), "signal_desc != NULL"); return (G_TOKEN_NONE); } } while (0); |
1406 | |
1407 | if (G_UNLIKELY (!scanner)(!scanner)) |
1408 | scanner = create_signal_scanner (); |
1409 | |
1410 | g_scanner_input_text (scanner, signal_desc, |
1411 | (guint) strlen (signal_desc)); |
1412 | |
1413 | ret = ctk_binding_parse_bind (scanner, binding_set); |
1414 | |
1415 | /* Reset for next use */ |
1416 | g_scanner_set_scope (scanner, 0); |
1417 | |
1418 | return ret; |
1419 | } |
1420 | |
1421 | static gint |
1422 | find_entry_with_binding (CtkBindingEntry *entry, |
1423 | CtkBindingSet *binding_set) |
1424 | { |
1425 | return (entry->binding_set == binding_set) ? 0 : 1; |
1426 | } |
1427 | |
1428 | static gboolean |
1429 | binding_activate (CtkBindingSet *binding_set, |
1430 | GSList *entries, |
1431 | GObject *object, |
1432 | gboolean is_release, |
1433 | gboolean *unbound) |
1434 | { |
1435 | CtkBindingEntry *entry; |
1436 | GSList *elem; |
1437 | |
1438 | elem = g_slist_find_custom (entries, binding_set, |
1439 | (GCompareFunc) find_entry_with_binding); |
1440 | |
1441 | if (!elem) |
1442 | return FALSE(0); |
1443 | |
1444 | entry = elem->data; |
1445 | |
1446 | if (is_release != ((entry->modifiers & CDK_RELEASE_MASK) != 0)) |
1447 | return FALSE(0); |
1448 | |
1449 | if (entry->marks_unbound) |
1450 | { |
1451 | *unbound = TRUE(!(0)); |
1452 | return FALSE(0); |
1453 | } |
1454 | |
1455 | if (ctk_binding_entry_activate (entry, object)) |
1456 | return TRUE(!(0)); |
1457 | |
1458 | return FALSE(0); |
1459 | } |
1460 | |
1461 | static gboolean |
1462 | ctk_bindings_activate_list (GObject *object, |
1463 | GSList *entries, |
1464 | gboolean is_release) |
1465 | { |
1466 | CtkStyleContext *context; |
1467 | CtkBindingSet *binding_set; |
1468 | gboolean handled = FALSE(0); |
1469 | gboolean unbound = FALSE(0); |
1470 | GPtrArray *array; |
1471 | |
1472 | if (!entries) |
1473 | return FALSE(0); |
1474 | |
1475 | context = ctk_widget_get_style_context (CTK_WIDGET (object)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((object)), ((ctk_widget_get_type ()))))))); |
1476 | |
1477 | ctk_style_context_get (context, ctk_style_context_get_state (context), |
1478 | "-ctk-key-bindings", &array, |
1479 | NULL((void*)0)); |
1480 | if (array) |
1481 | { |
1482 | gint i; |
1483 | |
1484 | for (i = 0; i < array->len; i++) |
1485 | { |
1486 | binding_set = g_ptr_array_index (array, i)((array)->pdata)[i]; |
1487 | handled = binding_activate (binding_set, entries, |
1488 | object, is_release, |
1489 | &unbound); |
1490 | if (handled || unbound) |
1491 | break; |
1492 | } |
1493 | |
1494 | g_ptr_array_unref (array); |
1495 | |
1496 | if (unbound) |
1497 | return FALSE(0); |
1498 | } |
1499 | |
1500 | if (!handled) |
1501 | { |
1502 | GType class_type; |
1503 | |
1504 | class_type = G_TYPE_FROM_INSTANCE (object)((((GTypeClass*) (((GTypeInstance*) (object))->g_class))-> g_type)); |
1505 | |
1506 | while (class_type && !handled) |
1507 | { |
1508 | binding_set = ctk_binding_set_find_interned (g_type_name (class_type)); |
1509 | class_type = g_type_parent (class_type); |
1510 | |
1511 | if (!binding_set) |
1512 | continue; |
1513 | |
1514 | handled = binding_activate (binding_set, entries, |
1515 | object, is_release, |
1516 | &unbound); |
1517 | if (unbound) |
1518 | break; |
1519 | } |
1520 | |
1521 | if (unbound) |
1522 | return FALSE(0); |
1523 | } |
1524 | |
1525 | return handled; |
1526 | } |
1527 | |
1528 | /** |
1529 | * ctk_bindings_activate: |
1530 | * @object: object to activate when binding found |
1531 | * @keyval: key value of the binding |
1532 | * @modifiers: key modifier of the binding |
1533 | * |
1534 | * Find a key binding matching @keyval and @modifiers and activate the |
1535 | * binding on @object. |
1536 | * |
1537 | * Returns: %TRUE if a binding was found and activated |
1538 | */ |
1539 | gboolean |
1540 | ctk_bindings_activate (GObject *object, |
1541 | guint keyval, |
1542 | CdkModifierType modifiers) |
1543 | { |
1544 | GSList *entries = NULL((void*)0); |
1545 | CdkDisplay *display; |
1546 | CtkKeyHash *key_hash; |
1547 | gboolean handled = FALSE(0); |
1548 | gboolean is_release; |
1549 | |
1550 | if (!CTK_IS_WIDGET (object)(((__extension__ ({ GTypeInstance *__inst = (GTypeInstance*) ( (object)); GType __t = ((ctk_widget_get_type ())); gboolean __r ; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; }))))) |
1551 | return FALSE(0); |
1552 | |
1553 | is_release = (modifiers & CDK_RELEASE_MASK) != 0; |
1554 | modifiers = modifiers & BINDING_MOD_MASK ()(ctk_accelerator_get_default_mod_mask () | CDK_RELEASE_MASK) & ~CDK_RELEASE_MASK; |
1555 | |
1556 | display = ctk_widget_get_display (CTK_WIDGET (object)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((object)), ((ctk_widget_get_type ()))))))); |
1557 | key_hash = binding_key_hash_for_keymap (cdk_keymap_get_for_display (display)); |
1558 | |
1559 | entries = _ctk_key_hash_lookup_keyval (key_hash, keyval, modifiers); |
1560 | |
1561 | handled = ctk_bindings_activate_list (object, entries, is_release); |
1562 | |
1563 | g_slist_free (entries); |
1564 | |
1565 | return handled; |
1566 | } |
1567 | |
1568 | /** |
1569 | * ctk_bindings_activate_event: |
1570 | * @object: a #GObject (generally must be a widget) |
1571 | * @event: a #CdkEventKey |
1572 | * |
1573 | * Looks up key bindings for @object to find one matching |
1574 | * @event, and if one was found, activate it. |
1575 | * |
1576 | * Returns: %TRUE if a matching key binding was found |
1577 | * |
1578 | * Since: 2.4 |
1579 | */ |
1580 | gboolean |
1581 | ctk_bindings_activate_event (GObject *object, |
1582 | CdkEventKey *event) |
1583 | { |
1584 | GSList *entries = NULL((void*)0); |
1585 | CdkDisplay *display; |
1586 | CtkKeyHash *key_hash; |
1587 | gboolean handled = FALSE(0); |
1588 | |
1589 | if (!CTK_IS_WIDGET (object)(((__extension__ ({ GTypeInstance *__inst = (GTypeInstance*) ( (object)); GType __t = ((ctk_widget_get_type ())); gboolean __r ; if (!__inst) __r = (0); else if (__inst->g_class && __inst->g_class->g_type == __t) __r = (!(0)); else __r = g_type_check_instance_is_a (__inst, __t); __r; }))))) |
1590 | return FALSE(0); |
1591 | |
1592 | display = ctk_widget_get_display (CTK_WIDGET (object)((((CtkWidget*) (void *) g_type_check_instance_cast ((GTypeInstance *) ((object)), ((ctk_widget_get_type ()))))))); |
1593 | key_hash = binding_key_hash_for_keymap (cdk_keymap_get_for_display (display)); |
1594 | |
1595 | entries = _ctk_key_hash_lookup (key_hash, |
1596 | event->hardware_keycode, |
1597 | event->state, |
1598 | BINDING_MOD_MASK ()(ctk_accelerator_get_default_mod_mask () | CDK_RELEASE_MASK) & ~CDK_RELEASE_MASK, |
1599 | event->group); |
1600 | |
1601 | handled = ctk_bindings_activate_list (object, entries, |
1602 | event->type == CDK_KEY_RELEASE); |
1603 | |
1604 | g_slist_free (entries); |
1605 | |
1606 | return handled; |
1607 | } |