]> Pileus Git - ~andy/gtk/blob - gdk/gdkkeys.c
Ignore the sgml directory made by gtkdoc. Use gtk_window_set_resizable
[~andy/gtk] / gdk / gdkkeys.c
1 /* GDK - The GIMP Drawing Kit
2  * Copyright (C) 2000 Red Hat, Inc.
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, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 /*
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/. 
25  */
26
27 #include "gdkkeys.h"
28 #include <config.h>
29
30 enum {
31   DIRECTION_CHANGED,
32   LAST_SIGNAL
33 };
34
35 static void gdk_keymap_init       (GdkKeymap      *keymap);
36 static void gdk_keymap_class_init (GdkKeymapClass *klass);
37
38 static gpointer parent_class = NULL;
39
40 static guint signals[LAST_SIGNAL] = { 0 };
41
42 GType
43 gdk_keymap_get_type (void)
44 {
45   static GType object_type = 0;
46
47   if (!object_type)
48     {
49       static const GTypeInfo object_info =
50       {
51         sizeof (GdkKeymapClass),
52         (GBaseInitFunc) NULL,
53         (GBaseFinalizeFunc) NULL,
54         (GClassInitFunc) gdk_keymap_class_init,
55         NULL,           /* class_finalize */
56         NULL,           /* class_data */
57         sizeof (GdkKeymap),
58         0,              /* n_preallocs */
59         (GInstanceInitFunc) gdk_keymap_init,
60       };
61       
62       object_type = g_type_register_static (G_TYPE_OBJECT,
63                                             "GdkKeymap",
64                                             &object_info, 0);
65     }
66   
67   return object_type;
68 }
69
70 static void
71 gdk_keymap_init (GdkKeymap *keymap)
72 {
73
74 }
75
76 static void
77 gdk_keymap_class_init (GdkKeymapClass *klass)
78 {
79   GObjectClass *object_class = G_OBJECT_CLASS (klass);
80
81   parent_class = g_type_class_peek_parent (klass);
82
83   signals[DIRECTION_CHANGED] =
84     g_signal_new ("direction_changed",
85                   G_OBJECT_CLASS_TYPE (object_class),
86                   G_SIGNAL_RUN_LAST,
87                   G_STRUCT_OFFSET (GdkKeymapClass, direction_changed),
88                   NULL, NULL,
89                   g_cclosure_marshal_VOID__VOID,
90                   G_TYPE_NONE,
91                   0);
92 }
93
94 /* Other key-handling stuff
95  */
96
97 #ifndef HAVE_XCONVERTCASE
98 /* compatibility function from X11R6.3, since XConvertCase is not
99  * supplied by X11R5.
100  */
101 void
102 gdk_keyval_convert_case (guint symbol,
103                          guint *lower,
104                          guint *upper)
105 {
106   guint xlower = symbol;
107   guint xupper = symbol;
108
109   switch (symbol >> 8)
110     {
111 #if     defined (GDK_A) && defined (GDK_Ooblique)
112     case 0: /* Latin 1 */
113       if ((symbol >= GDK_A) && (symbol <= GDK_Z))
114         xlower += (GDK_a - GDK_A);
115       else if ((symbol >= GDK_a) && (symbol <= GDK_z))
116         xupper -= (GDK_a - GDK_A);
117       else if ((symbol >= GDK_Agrave) && (symbol <= GDK_Odiaeresis))
118         xlower += (GDK_agrave - GDK_Agrave);
119       else if ((symbol >= GDK_agrave) && (symbol <= GDK_odiaeresis))
120         xupper -= (GDK_agrave - GDK_Agrave);
121       else if ((symbol >= GDK_Ooblique) && (symbol <= GDK_Thorn))
122         xlower += (GDK_oslash - GDK_Ooblique);
123       else if ((symbol >= GDK_oslash) && (symbol <= GDK_thorn))
124         xupper -= (GDK_oslash - GDK_Ooblique);
125       break;
126 #endif  /* LATIN1 */
127       
128 #if     defined (GDK_Aogonek) && defined (GDK_tcedilla)
129     case 1: /* Latin 2 */
130       /* Assume the KeySym is a legal value (ignore discontinuities) */
131       if (symbol == GDK_Aogonek)
132         xlower = GDK_aogonek;
133       else if (symbol >= GDK_Lstroke && symbol <= GDK_Sacute)
134         xlower += (GDK_lstroke - GDK_Lstroke);
135       else if (symbol >= GDK_Scaron && symbol <= GDK_Zacute)
136         xlower += (GDK_scaron - GDK_Scaron);
137       else if (symbol >= GDK_Zcaron && symbol <= GDK_Zabovedot)
138         xlower += (GDK_zcaron - GDK_Zcaron);
139       else if (symbol == GDK_aogonek)
140         xupper = GDK_Aogonek;
141       else if (symbol >= GDK_lstroke && symbol <= GDK_sacute)
142         xupper -= (GDK_lstroke - GDK_Lstroke);
143       else if (symbol >= GDK_scaron && symbol <= GDK_zacute)
144         xupper -= (GDK_scaron - GDK_Scaron);
145       else if (symbol >= GDK_zcaron && symbol <= GDK_zabovedot)
146         xupper -= (GDK_zcaron - GDK_Zcaron);
147       else if (symbol >= GDK_Racute && symbol <= GDK_Tcedilla)
148         xlower += (GDK_racute - GDK_Racute);
149       else if (symbol >= GDK_racute && symbol <= GDK_tcedilla)
150         xupper -= (GDK_racute - GDK_Racute);
151       break;
152 #endif  /* LATIN2 */
153       
154 #if     defined (GDK_Hstroke) && defined (GDK_Cabovedot)
155     case 2: /* Latin 3 */
156       /* Assume the KeySym is a legal value (ignore discontinuities) */
157       if (symbol >= GDK_Hstroke && symbol <= GDK_Hcircumflex)
158         xlower += (GDK_hstroke - GDK_Hstroke);
159       else if (symbol >= GDK_Gbreve && symbol <= GDK_Jcircumflex)
160         xlower += (GDK_gbreve - GDK_Gbreve);
161       else if (symbol >= GDK_hstroke && symbol <= GDK_hcircumflex)
162         xupper -= (GDK_hstroke - GDK_Hstroke);
163       else if (symbol >= GDK_gbreve && symbol <= GDK_jcircumflex)
164         xupper -= (GDK_gbreve - GDK_Gbreve);
165       else if (symbol >= GDK_Cabovedot && symbol <= GDK_Scircumflex)
166         xlower += (GDK_cabovedot - GDK_Cabovedot);
167       else if (symbol >= GDK_cabovedot && symbol <= GDK_scircumflex)
168         xupper -= (GDK_cabovedot - GDK_Cabovedot);
169       break;
170 #endif  /* LATIN3 */
171       
172 #if     defined (GDK_Rcedilla) && defined (GDK_Amacron)
173     case 3: /* Latin 4 */
174       /* Assume the KeySym is a legal value (ignore discontinuities) */
175       if (symbol >= GDK_Rcedilla && symbol <= GDK_Tslash)
176         xlower += (GDK_rcedilla - GDK_Rcedilla);
177       else if (symbol >= GDK_rcedilla && symbol <= GDK_tslash)
178         xupper -= (GDK_rcedilla - GDK_Rcedilla);
179       else if (symbol == GDK_ENG)
180         xlower = GDK_eng;
181       else if (symbol == GDK_eng)
182         xupper = GDK_ENG;
183       else if (symbol >= GDK_Amacron && symbol <= GDK_Umacron)
184         xlower += (GDK_amacron - GDK_Amacron);
185       else if (symbol >= GDK_amacron && symbol <= GDK_umacron)
186         xupper -= (GDK_amacron - GDK_Amacron);
187       break;
188 #endif  /* LATIN4 */
189       
190 #if     defined (GDK_Serbian_DJE) && defined (GDK_Cyrillic_yu)
191     case 6: /* Cyrillic */
192       /* Assume the KeySym is a legal value (ignore discontinuities) */
193       if (symbol >= GDK_Serbian_DJE && symbol <= GDK_Serbian_DZE)
194         xlower -= (GDK_Serbian_DJE - GDK_Serbian_dje);
195       else if (symbol >= GDK_Serbian_dje && symbol <= GDK_Serbian_dze)
196         xupper += (GDK_Serbian_DJE - GDK_Serbian_dje);
197       else if (symbol >= GDK_Cyrillic_YU && symbol <= GDK_Cyrillic_HARDSIGN)
198         xlower -= (GDK_Cyrillic_YU - GDK_Cyrillic_yu);
199       else if (symbol >= GDK_Cyrillic_yu && symbol <= GDK_Cyrillic_hardsign)
200         xupper += (GDK_Cyrillic_YU - GDK_Cyrillic_yu);
201       break;
202 #endif  /* CYRILLIC */
203       
204 #if     defined (GDK_Greek_ALPHAaccent) && defined (GDK_Greek_finalsmallsigma)
205     case 7: /* Greek */
206       /* Assume the KeySym is a legal value (ignore discontinuities) */
207       if (symbol >= GDK_Greek_ALPHAaccent && symbol <= GDK_Greek_OMEGAaccent)
208         xlower += (GDK_Greek_alphaaccent - GDK_Greek_ALPHAaccent);
209       else if (symbol >= GDK_Greek_alphaaccent && symbol <= GDK_Greek_omegaaccent &&
210                symbol != GDK_Greek_iotaaccentdieresis &&
211                symbol != GDK_Greek_upsilonaccentdieresis)
212         xupper -= (GDK_Greek_alphaaccent - GDK_Greek_ALPHAaccent);
213       else if (symbol >= GDK_Greek_ALPHA && symbol <= GDK_Greek_OMEGA)
214         xlower += (GDK_Greek_alpha - GDK_Greek_ALPHA);
215       else if (symbol >= GDK_Greek_alpha && symbol <= GDK_Greek_omega &&
216                symbol != GDK_Greek_finalsmallsigma)
217         xupper -= (GDK_Greek_alpha - GDK_Greek_ALPHA);
218       break;
219 #endif  /* GREEK */
220     }
221
222   if (lower)
223     *lower = xlower;
224   if (upper)
225     *upper = xupper;
226 }
227 #endif
228
229 guint
230 gdk_keyval_to_upper (guint keyval)
231 {
232   guint result;
233   
234   gdk_keyval_convert_case (keyval, NULL, &result);
235
236   return result;
237 }
238
239 guint
240 gdk_keyval_to_lower (guint keyval)
241 {
242   guint result;
243   
244   gdk_keyval_convert_case (keyval, &result, NULL);
245
246   return result;
247 }
248
249 gboolean
250 gdk_keyval_is_upper (guint keyval)
251 {
252   if (keyval)
253     {
254       guint upper_val = 0;
255       
256       gdk_keyval_convert_case (keyval, NULL, &upper_val);
257       return upper_val == keyval;
258     }
259   return FALSE;
260 }
261
262 gboolean
263 gdk_keyval_is_lower (guint keyval)
264 {
265   if (keyval)
266     {
267       guint lower_val = 0;
268       
269       gdk_keyval_convert_case (keyval, &lower_val, NULL);
270       return lower_val == keyval;
271     }
272   return FALSE;
273 }