1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
19 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
20 * file for a list of people on the GTK+ Team. See the ChangeLog
21 * files for a list of changes. These files are distributed with
22 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
32 #include "gtkprivate.h"
35 #if !defined G_OS_WIN32 && !(defined GDK_WINDOWING_QUARTZ && defined QUARTZ_RELOCATION)
38 _gtk_get_datadir (void)
44 _gtk_get_libdir (void)
50 _gtk_get_sysconfdir (void)
52 return GTK_SYSCONFDIR;
56 _gtk_get_localedir (void)
62 _gtk_get_data_prefix (void)
64 return GTK_DATA_PREFIX;
71 * Return the Unix-style locale string for the language currently in
72 * effect. On Unix systems, this is the return value from
73 * <literal>setlocale(LC_CTYPE, NULL)</literal>, and the user can
74 * affect this through the environment variables LC_ALL, LC_CTYPE or
75 * LANG (checked in that order). The locale strings typically is in
76 * the form lang_COUNTRY, where lang is an ISO-639 language code, and
77 * COUNTRY is an ISO-3166 country code. For instance, sv_FI for
78 * Swedish as written in Finland or pt_BR for Portuguese as written in
81 * On Windows, the C library doesn't use any such environment
82 * variables, and setting them won't affect the behaviour of functions
83 * like ctime(). The user sets the locale through the Regional Options
84 * in the Control Panel. The C library (in the setlocale() function)
85 * does not use country and language codes, but country and language
86 * names spelled out in English.
87 * However, this function does check the above environment
88 * variables, and does return a Unix-style locale string based on
89 * either said environment variables or the thread's current locale.
91 * Return value: a dynamically allocated string, free with g_free().
95 _gtk_get_lc_ctype (void)
98 /* Somebody might try to set the locale for this process using the
99 * LANG or LC_ environment variables. The Microsoft C library
100 * doesn't know anything about them. You set the locale in the
101 * Control Panel. Setting these env vars won't have any affect on
102 * locale-dependent C library functions like ctime(). But just for
103 * kicks, do obey LC_ALL, LC_CTYPE and LANG in GTK. (This also makes
104 * it easier to test GTK and Pango in various default languages, you
105 * don't have to clickety-click in the Control Panel, you can simply
106 * start the program with LC_ALL=something on the command line.)
110 p = getenv ("LC_ALL");
114 p = getenv ("LC_CTYPE");
122 return g_win32_getlocale ();
124 return g_strdup (setlocale (LC_CTYPE, NULL));
129 _gtk_boolean_handled_accumulator (GSignalInvocationHint *ihint,
131 const GValue *handler_return,
134 gboolean continue_emission;
135 gboolean signal_handled;
137 signal_handled = g_value_get_boolean (handler_return);
138 g_value_set_boolean (return_accu, signal_handled);
139 continue_emission = !signal_handled;
141 return continue_emission;
145 _gtk_single_string_accumulator (GSignalInvocationHint *ihint,
147 const GValue *handler_return,
150 gboolean continue_emission;
153 str = g_value_get_string (handler_return);
154 g_value_set_string (return_accu, str);
155 continue_emission = str == NULL;
157 return continue_emission;
161 _gtk_replace_virtual_modifiers (GdkKeymap *keymap,
162 GdkModifierType modifiers)
164 GdkModifierType result = 0;
167 g_return_val_if_fail (GDK_IS_KEYMAP (keymap), 0);
169 for (i = 0; i < 8; i++) /* SHIFT...MOD5 */
171 GdkModifierType real = 1 << i;
173 if (modifiers & real)
175 GdkModifierType virtual = real;
177 gdk_keymap_add_virtual_modifiers (keymap, &virtual);
182 result |= virtual & ~real;
190 _gtk_get_primary_accel_mod (void)
192 static GdkModifierType primary = 0;
196 GdkDisplay *display = gdk_display_get_default ();
198 primary = gdk_keymap_get_modifier_mask (gdk_keymap_get_for_display (display),
199 GDK_MODIFIER_INTENT_PRIMARY_ACCELERATOR);
200 primary = _gtk_replace_virtual_modifiers (gdk_keymap_get_for_display (display),
208 _gtk_translate_keyboard_accel_state (GdkKeymap *keymap,
209 guint hardware_keycode,
210 GdkModifierType state,
211 GdkModifierType accel_mask,
214 gint *effective_group,
216 GdkModifierType *consumed_modifiers)
218 GdkModifierType shift_group_mask;
219 gboolean group_mask_disabled = FALSE;
222 /* if the group-toggling modifier is part of the accel mod mask, and
223 * it is active, disable it for matching
225 shift_group_mask = gdk_keymap_get_modifier_mask (keymap,
226 GDK_MODIFIER_INTENT_SHIFT_GROUP);
227 if (accel_mask & state & shift_group_mask)
229 state &= ~shift_group_mask;
231 group_mask_disabled = TRUE;
234 retval = gdk_keymap_translate_keyboard_state (keymap,
235 hardware_keycode, state, group,
237 effective_group, level,
240 /* add back the group mask, we want to match against the modifier,
241 * but not against the keyval from its group
243 if (group_mask_disabled)
246 *effective_group = 1;
248 if (consumed_modifiers)
249 *consumed_modifiers &= ~shift_group_mask;