1 /* gtkeditkey.c - key defs for gtk
3 Copyright (C) 1996, 1997 the Free Software Foundation
5 Authors: 1996, 1997 Paul Sheer
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program 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
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
23 #include "editcmddef.h"
24 #include <gdk/gdkkeysyms.h>
26 int mod_type_key (guint x
);
28 int (*user_defined_key_function
) (unsigned int state
, unsigned int keycode
, KeySym keysym
) = 0;
30 int option_interpret_numlock
= 0;
32 void edit_set_user_key_function (int (*user_def_key_func
) (unsigned int, unsigned int, KeySym
))
34 user_defined_key_function
= user_def_key_func
;
37 int edit_translate_key (unsigned int x_keycode
, long x_key
, int x_state
, int *cmd
, int *ch
)
40 int char_for_insertion
= -1;
42 static long key_map
[128] =
43 {GDK_BackSpace
, CK_BackSpace
, GDK_Delete
, CK_Delete
, GDK_Return
, CK_Enter
, GDK_Page_Up
, CK_Page_Up
,
44 GDK_Page_Down
, CK_Page_Down
, GDK_Left
, CK_Left
, GDK_Right
, CK_Right
, GDK_Up
, CK_Up
, GDK_Down
, CK_Down
,
45 GDK_Home
, CK_Home
, GDK_End
, CK_End
, GDK_Tab
, CK_Tab
, GDK_Undo
, CK_Undo
, GDK_Insert
, CK_Toggle_Insert
,
46 GDK_F3
, CK_Mark
, GDK_F5
, CK_Copy
, GDK_F6
, CK_Move
, GDK_F8
, CK_Remove
, GDK_F2
, CK_Save
, GDK_F12
, CK_Save_As
,
47 GDK_F10
, CK_Exit
, GDK_Escape
, CK_Cancel
, GDK_F9
, CK_Menu
,
48 GDK_F4
, CK_Replace
, GDK_F4
, CK_Replace_Again
, GDK_F17
, CK_Find_Again
, GDK_F7
, CK_Find
, GDK_F15
, CK_Insert_File
, 0, 0};
50 static long key_pad_map
[10] =
51 {GDK_Insert
, GDK_End
, GDK_Down
, GDK_Page_Down
, GDK_Left
,
52 GDK_Down
, GDK_Right
, GDK_Home
, GDK_Up
, GDK_Page_Up
};
55 #define DEFAULT_NUM_LOCK 1
57 static int num_lock
= DEFAULT_NUM_LOCK
;
59 static int compose
= 0;
60 static int decimal
= 0;
66 if (mod_type_key (x_key
)) {
71 c
= get_international_character (x_key
);
75 get_international_character (0);
79 char_for_insertion
= c
;
85 if (option_international_characters
) {
86 if (x_key
>= ' ' && x_key
<= '~') {
89 extern int compose_key_pressed
;
91 if (compose_key_pressed
) {
93 c
= (x_key
>= 'A' && x_key
<= 'Z') ? x_key
- 'A' + 'a' : x_key
;
94 c
= get_international_character ((x_state
& ShiftMask
) ?
95 ((c
>= 'a' && c
<= 'z') ? c
+ 'A' - 'a' : c
)
103 char_for_insertion
= c
;
109 if (x_key
<= 0 || mod_type_key (x_key
))
114 if (strchr ("0123456789abcdefh", x_key
)) {
119 char_for_insertion
= hex
;
129 decimal
+= (x_key
- '0') * ((int) ("d\n\001")[raw
- 1]);
131 hex
+= (strcspn ("0123456789abcdef", u
) << (4 * (2 - raw
)));
133 char_for_insertion
= decimal
;
146 if (x_key
== GDK_Return
)
147 char_for_insertion
= '\n';
149 char_for_insertion
= x_key
;
151 if (x_state
& ControlMask
)
152 char_for_insertion
&= 31;
153 if (x_state
& (MyAltMask
))
154 char_for_insertion
|= 128;
158 if (user_defined_key_function
)
159 if ((h
= (*(user_defined_key_function
)) (x_state
, x_keycode
, x_key
))) {
164 if ((x_state
& MyAltMask
)) {
165 switch ((int) x_key
) {
168 command
= CK_Delete_Word_Left
;
172 command
= CK_Delete_Word_Right
;
180 command
= CK_Selection_History
;
184 command
= CK_Scroll_Up
;
188 command
= CK_Scroll_Down
;
192 command
= CK_Delete_To_Line_End
;
195 command
= CK_Delete_To_Line_Begin
;
203 command
= CK_Save_And_Quit
;
207 command
= CK_Paragraph_Format
;
211 if ((x_state
& MyAltMask
) && (x_state
& ShiftMask
)) {
212 switch ((int) x_key
) {
215 command
= CK_Scroll_Up_Highlight
;
219 command
= CK_Scroll_Down_Highlight
;
223 if (!(x_state
& MyAltMask
)) {
225 if ((x_key
== GDK_a
|| x_key
== GDK_A
) && (x_state
& ControlMask
)) {
227 command
= CK_Macro (CKeySymMod (CRawkeyQuery (0, 0, 0, " Execute Macro ", " Press macro hotkey: ")));
228 if (command
== CK_Macro (0))
233 if (x_key
== GDK_Num_Lock
&& option_interpret_numlock
) {
234 num_lock
= 1 - num_lock
;
237 switch ((int) x_key
) {
247 case GDK_KP_Page_Down
:
248 x_key
= GDK_Page_Down
;
274 case GDK_KP_Subtract
:
279 /* first translate the key-pad */
281 if (x_key
>= GDK_R1
&& x_key
<= GDK_R9
) {
282 x_key
= key_pad_map
[x_key
- GDK_R1
+ 1];
283 } else if (x_key
>= GDK_KP_0
&& x_key
<= GDK_KP_9
) {
284 x_key
= key_pad_map
[x_key
- GDK_KP_0
];
285 } else if (x_key
== GDK_KP_Decimal
) {
289 if (x_key
>= GDK_KP_0
&& x_key
<= GDK_KP_9
) {
290 x_key
+= GDK_0
- GDK_KP_0
;
292 if (x_key
== GDK_KP_Decimal
) {
297 if ((x_state
& ShiftMask
) && (x_state
& ControlMask
)) {
298 switch ((int) x_key
) {
300 command
= CK_Beginning_Of_Text_Highlight
;
303 command
= CK_End_Of_Text_Highlight
;
306 command
= CK_Word_Left_Highlight
;
309 command
= CK_Word_Right_Highlight
;
312 command
= CK_Paragraph_Up_Highlight
;
315 command
= CK_Paragraph_Down_Highlight
;
318 command
= CK_Begin_Page_Highlight
;
321 command
= CK_End_Page_Highlight
;
325 if ((x_state
& ShiftMask
) && !(x_state
& ControlMask
)) {
326 switch ((int) x_key
) {
328 command
= CK_Page_Up_Highlight
;
331 command
= CK_Page_Down_Highlight
;
334 command
= CK_Left_Highlight
;
337 command
= CK_Right_Highlight
;
340 command
= CK_Up_Highlight
;
343 command
= CK_Down_Highlight
;
346 command
= CK_Home_Highlight
;
349 command
= CK_End_Highlight
;
360 /* this parallel F12, F19, F15, and F17 for some systems */
362 command
= CK_Save_As
;
365 command
= CK_Insert_File
;
368 command
= CK_Find_Again
;
371 command
= CK_Replace_Again
;
374 command
= CK_Run_Another
;
378 /* things that need a control key */
379 if (x_state
& ControlMask
) {
380 switch ((int) x_key
) {
382 command
= CK_Man_Page
;
390 command
= CK_Beginning_Of_Text
;
393 command
= CK_End_Of_Text
;
396 command
= CK_Paragraph_Up
;
399 command
= CK_Paragraph_Down
;
402 command
= CK_Word_Left
;
405 command
= CK_Word_Right
;
408 command
= CK_Begin_Page
;
411 command
= CK_End_Page
;
433 command
= CK_Save_Block
;
437 command
= CK_Insert_File
;
444 command
= CK_Delete_Line
;
450 command
= CK_Save_Desktop
;
453 command
= CK_New_Window
;
459 command
= CK_Check_Save_And_Quit
;
463 command
= CK_Complete
;
466 command
= CK_Column_Mark
;
470 /* an ordinary ascii character or international character */
471 if (!(x_state
& MyAltMask
)) {
472 if (!(x_state
& ControlMask
)) {
473 if ((x_key
>= GDK_space
&& x_key
<= GDK_asciitilde
) || ((x_key
>= 160 && x_key
< 256) && option_international_characters
)) {
474 char_for_insertion
= x_key
;
478 if (!(x_state
& ShiftMask
)) {
480 while (key_map
[i
] != x_key
&& key_map
[i
])
482 command
= key_map
[i
+ 1];
492 *ch
= char_for_insertion
;
494 if ((command
== -1 || command
== 0) && char_for_insertion
== -1) /* unchanged, key has no function here */