]> Pileus Git - ~andy/gtk/blob - gtk/gtkprivate.c
stylecontext: Do invalidation on first resize container
[~andy/gtk] / gtk / gtkprivate.c
1 /* GTK - The GIMP Toolkit
2  * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
3  *
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.
8  *
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.
13  *
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/>.
16  */
17
18 /*
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/.
23  */
24
25 #include "config.h"
26
27 #include <locale.h>
28 #include <stdlib.h>
29
30 #include "gdk/gdk.h"
31
32 #include "gtkprivate.h"
33
34
35 #if !defined G_OS_WIN32 && !(defined GDK_WINDOWING_QUARTZ && defined QUARTZ_RELOCATION)
36
37 const gchar *
38 _gtk_get_datadir (void)
39 {
40   return GTK_DATADIR;
41 }
42
43 const gchar *
44 _gtk_get_libdir (void)
45 {
46   return GTK_LIBDIR;
47 }
48
49 const gchar *
50 _gtk_get_sysconfdir (void)
51 {
52   return GTK_SYSCONFDIR;
53 }
54
55 const gchar *
56 _gtk_get_localedir (void)
57 {
58   return GTK_LOCALEDIR;
59 }
60
61 const gchar *
62 _gtk_get_data_prefix (void)
63 {
64   return GTK_DATA_PREFIX;
65 }
66
67 #endif
68
69 /* _gtk_get_lc_ctype:
70  *
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
79  * Brazil.
80  *
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.
90  *
91  * Return value: a dynamically allocated string, free with g_free().
92  */
93
94 gchar *
95 _gtk_get_lc_ctype (void)
96 {
97 #ifdef G_OS_WIN32
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.)
107    */
108   gchar *p;
109
110   p = getenv ("LC_ALL");
111   if (p != NULL)
112     return g_strdup (p);
113
114   p = getenv ("LC_CTYPE");
115   if (p != NULL)
116     return g_strdup (p);
117
118   p = getenv ("LANG");
119   if (p != NULL)
120     return g_strdup (p);
121
122   return g_win32_getlocale ();
123 #else
124   return g_strdup (setlocale (LC_CTYPE, NULL));
125 #endif
126 }
127
128 gboolean
129 _gtk_boolean_handled_accumulator (GSignalInvocationHint *ihint,
130                                   GValue                *return_accu,
131                                   const GValue          *handler_return,
132                                   gpointer               dummy)
133 {
134   gboolean continue_emission;
135   gboolean signal_handled;
136
137   signal_handled = g_value_get_boolean (handler_return);
138   g_value_set_boolean (return_accu, signal_handled);
139   continue_emission = !signal_handled;
140
141   return continue_emission;
142 }
143
144 gboolean
145 _gtk_single_string_accumulator (GSignalInvocationHint *ihint,
146                                 GValue                *return_accu,
147                                 const GValue          *handler_return,
148                                 gpointer               dummy)
149 {
150   gboolean continue_emission;
151   const gchar *str;
152
153   str = g_value_get_string (handler_return);
154   g_value_set_string (return_accu, str);
155   continue_emission = str == NULL;
156
157   return continue_emission;
158 }
159
160 GdkModifierType
161 _gtk_replace_virtual_modifiers (GdkKeymap       *keymap,
162                                 GdkModifierType  modifiers)
163 {
164   GdkModifierType result = 0;
165   gint            i;
166
167   g_return_val_if_fail (GDK_IS_KEYMAP (keymap), 0);
168
169   for (i = 0; i < 8; i++) /* SHIFT...MOD5 */
170     {
171       GdkModifierType real = 1 << i;
172
173       if (modifiers & real)
174         {
175           GdkModifierType virtual = real;
176
177           gdk_keymap_add_virtual_modifiers (keymap, &virtual);
178
179           if (virtual == real)
180             result |= virtual;
181           else
182             result |= virtual & ~real;
183         }
184     }
185
186   return result;
187 }
188
189 GdkModifierType
190 _gtk_get_primary_accel_mod (void)
191 {
192   static GdkModifierType primary = 0;
193
194   if (! primary)
195     {
196       GdkDisplay *display = gdk_display_get_default ();
197
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),
201                                                 primary);
202     }
203
204   return primary;
205 }
206
207 gboolean
208 _gtk_translate_keyboard_accel_state (GdkKeymap       *keymap,
209                                      guint            hardware_keycode,
210                                      GdkModifierType  state,
211                                      GdkModifierType  accel_mask,
212                                      gint             group,
213                                      guint           *keyval,
214                                      gint            *effective_group,
215                                      gint            *level,
216                                      GdkModifierType *consumed_modifiers)
217 {
218   GdkModifierType shift_group_mask;
219   gboolean group_mask_disabled = FALSE;
220   gboolean retval;
221
222   /* if the group-toggling modifier is part of the accel mod mask, and
223    * it is active, disable it for matching
224    */
225   shift_group_mask = gdk_keymap_get_modifier_mask (keymap,
226                                                    GDK_MODIFIER_INTENT_SHIFT_GROUP);
227   if (accel_mask & state & shift_group_mask)
228     {
229       state &= ~shift_group_mask;
230       group = 0;
231       group_mask_disabled = TRUE;
232     }
233
234   retval = gdk_keymap_translate_keyboard_state (keymap,
235                                                 hardware_keycode, state, group,
236                                                 keyval,
237                                                 effective_group, level,
238                                                 consumed_modifiers);
239
240   /* add back the group mask, we want to match against the modifier,
241    * but not against the keyval from its group
242    */
243   if (group_mask_disabled)
244     {
245       if (effective_group)
246         *effective_group = 1;
247
248       if (consumed_modifiers)
249         *consumed_modifiers &= ~shift_group_mask;
250     }
251
252   return retval;
253 }