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, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
21 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
22 * file for a list of people on the GTK+ Team. See the ChangeLog
23 * files for a list of changes. These files are distributed with
24 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
34 #include "gtkprivate.h"
37 #if !defined G_OS_WIN32 && !(defined GDK_WINDOWING_QUARTZ && defined QUARTZ_RELOCATION)
40 _gtk_get_datadir (void)
46 _gtk_get_libdir (void)
52 _gtk_get_sysconfdir (void)
54 return GTK_SYSCONFDIR;
58 _gtk_get_localedir (void)
64 _gtk_get_data_prefix (void)
66 return GTK_DATA_PREFIX;
73 * Return the Unix-style locale string for the language currently in
74 * effect. On Unix systems, this is the return value from
75 * <literal>setlocale(LC_CTYPE, NULL)</literal>, and the user can
76 * affect this through the environment variables LC_ALL, LC_CTYPE or
77 * LANG (checked in that order). The locale strings typically is in
78 * the form lang_COUNTRY, where lang is an ISO-639 language code, and
79 * COUNTRY is an ISO-3166 country code. For instance, sv_FI for
80 * Swedish as written in Finland or pt_BR for Portuguese as written in
83 * On Windows, the C library doesn't use any such environment
84 * variables, and setting them won't affect the behaviour of functions
85 * like ctime(). The user sets the locale through the Regional Options
86 * in the Control Panel. The C library (in the setlocale() function)
87 * does not use country and language codes, but country and language
88 * names spelled out in English.
89 * However, this function does check the above environment
90 * variables, and does return a Unix-style locale string based on
91 * either said environment variables or the thread's current locale.
93 * Return value: a dynamically allocated string, free with g_free().
97 _gtk_get_lc_ctype (void)
100 /* Somebody might try to set the locale for this process using the
101 * LANG or LC_ environment variables. The Microsoft C library
102 * doesn't know anything about them. You set the locale in the
103 * Control Panel. Setting these env vars won't have any affect on
104 * locale-dependent C library functions like ctime(). But just for
105 * kicks, do obey LC_ALL, LC_CTYPE and LANG in GTK. (This also makes
106 * it easier to test GTK and Pango in various default languages, you
107 * don't have to clickety-click in the Control Panel, you can simply
108 * start the program with LC_ALL=something on the command line.)
112 p = getenv ("LC_ALL");
116 p = getenv ("LC_CTYPE");
124 return g_win32_getlocale ();
126 return g_strdup (setlocale (LC_CTYPE, NULL));
131 _gtk_boolean_handled_accumulator (GSignalInvocationHint *ihint,
133 const GValue *handler_return,
136 gboolean continue_emission;
137 gboolean signal_handled;
139 signal_handled = g_value_get_boolean (handler_return);
140 g_value_set_boolean (return_accu, signal_handled);
141 continue_emission = !signal_handled;
143 return continue_emission;
147 _gtk_single_string_accumulator (GSignalInvocationHint *ihint,
149 const GValue *handler_return,
152 gboolean continue_emission;
155 str = g_value_get_string (handler_return);
156 g_value_set_string (return_accu, str);
157 continue_emission = str == NULL;
159 return continue_emission;
163 _gtk_replace_virtual_modifiers (GdkKeymap *keymap,
164 GdkModifierType modifiers)
166 GdkModifierType result = 0;
169 g_return_val_if_fail (GDK_IS_KEYMAP (keymap), 0);
171 for (i = 0; i < 8; i++) /* SHIFT...MOD5 */
173 GdkModifierType real = 1 << i;
175 if (modifiers & real)
177 GdkModifierType virtual = real;
179 gdk_keymap_add_virtual_modifiers (keymap, &virtual);
184 result |= virtual & ~real;
192 _gtk_get_primary_accel_mod (void)
194 static GdkModifierType primary = 0;
198 GdkDisplay *display = gdk_display_get_default ();
200 primary = gdk_keymap_get_modifier_mask (gdk_keymap_get_for_display (display),
201 GDK_MODIFIER_INTENT_PRIMARY_ACCELERATOR);
202 primary = _gtk_replace_virtual_modifiers (gdk_keymap_get_for_display (display),
210 _gtk_translate_keyboard_accel_state (GdkKeymap *keymap,
211 guint hardware_keycode,
212 GdkModifierType state,
213 GdkModifierType accel_mask,
216 gint *effective_group,
218 GdkModifierType *consumed_modifiers)
220 GdkModifierType shift_group_mask;
221 gboolean group_mask_disabled = FALSE;
224 /* if the group-toggling modifier is part of the accel mod mask, and
225 * it is active, disable it for matching
227 shift_group_mask = gdk_keymap_get_modifier_mask (keymap,
228 GDK_MODIFIER_INTENT_SHIFT_GROUP);
229 if (accel_mask & state & shift_group_mask)
231 state &= ~shift_group_mask;
233 group_mask_disabled = TRUE;
236 retval = gdk_keymap_translate_keyboard_state (keymap,
237 hardware_keycode, state, group,
239 effective_group, level,
242 /* add back the group mask, we want to match against the modifier,
243 * but not against the keyval from its group
245 if (group_mask_disabled)
248 *effective_group = 1;
250 if (consumed_modifiers)
251 *consumed_modifiers &= ~shift_group_mask;