grub2: bring back build of aros-side grub2 tools
[AROS.git] / workbench / classes / zune / betterstring / mcc / hotkeystring / HandleInput.c
blob321d06765cd00c6255e43d854de63ee52ee0d3b0
1 /***************************************************************************
3 BetterString.mcc - A better String gadget MUI Custom Class
4 Copyright (C) 1997-2000 Allan Odgaard
5 Copyright (C) 2005-2013 by BetterString.mcc Open Source Team
7 This library is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
12 This library 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 GNU
15 Lesser General Public License for more details.
17 BetterString class Support Site: http://www.sf.net/projects/bstring-mcc/
19 $Id$
21 ***************************************************************************/
23 #include <string.h>
25 #include <devices/inputevent.h>
26 #include <libraries/mui.h>
27 #include <proto/intuition.h>
28 #include <proto/keymap.h>
30 #include <newmouse.h>
32 #include "private.h"
34 static ULONG ConvertKey (struct IntuiMessage *imsg)
36 struct InputEvent event;
37 unsigned char code = '\0';
39 event.ie_NextEvent = NULL;
40 event.ie_Class = IECLASS_RAWKEY;
41 event.ie_SubClass = 0;
42 event.ie_Code = imsg->Code;
43 event.ie_Qualifier = 0; /* imsg->Qualifier; */
44 event.ie_EventAddress = 0; /* (APTR *) *((ULONG *)imsg->IAddress); */
46 MapRawKey(&event, (STRPTR)&code, 1, NULL);
48 return code;
51 #define BETWEEN(a, min, max) (a >= min && a <= max)
53 /* wheel mouse support */
54 #undef IECODE_KEY_CODE_LAST
55 #define IECODE_KEY_CODE_LAST 0x7e
57 IPTR HandleInput(struct IClass *cl, Object *obj, struct MUIP_HandleEvent *msg)
59 struct InstData *data = (struct InstData *)INST_DATA(cl, obj);
60 BOOL nokey = FALSE, backspace = FALSE, qual_only;
61 IPTR result;
63 qual_only = BETWEEN(msg->imsg->Code, 0x60, 0x67); // betwenn LSHIFT/RCOMMAND
65 if(qual_only || ((isFlagSet(data->Flags, FLG_Snoop) || isFlagSet(data->Flags, FLG_Active)) &&
66 msg->imsg->Class == IDCMP_RAWKEY &&
67 msg->imsg->Code <= IECODE_KEY_CODE_LAST &&
68 msg->muikey != MUIKEY_GADGET_NEXT &&
69 msg->muikey != MUIKEY_GADGET_PREV))
71 static const char *qualifier_name[] =
73 "lshift", "rshift", "capslock", "control", "lalt",
74 "ralt", "lcommand", "rcommand", "numericpad", "repeat",
75 NULL
78 ULONG qualifier = msg->imsg->Qualifier;
79 char buffer[256];
80 ULONG i;
82 buffer[0] = '\0';
84 for(i=0; qualifier_name[i]; i++)
86 if(isFlagSet(qualifier, (1U << i)))
88 strlcat(buffer, qualifier_name[i], sizeof(buffer));
89 strlcat(buffer, " ", sizeof(buffer));
93 if(qual_only)
95 if(*buffer)
96 buffer[strlen(buffer)-1] = '\0';
98 else
100 UWORD code = msg->imsg->Code;
102 if(code >= RAWKEY_F11 && code <= RAWKEY_F10)
104 static const char *key_name[] =
106 "f11",
107 "up", "down", "right", "left",
108 "f1", "f2", "f3", "f4", "f5",
109 "f6", "f7", "f8", "f9", "f10"
112 strlcat(buffer, key_name[code-RAWKEY_F11], sizeof(buffer));
114 else switch(code)
116 #if defined(__amigaos4__)
117 case RAWKEY_MENU: strlcat(buffer, "menu", sizeof(buffer)); break;
118 #elif defined(__MORPHOS__)
119 case RAWKEY_SCRLOCK: strlcat(buffer, "scrlock", sizeof(buffer)); break;
120 #endif
122 case RAWKEY_NUMLOCK: strlcat(buffer, "numlock", sizeof(buffer)); break;
123 case RAWKEY_INSERT: strlcat(buffer, "insert", sizeof(buffer)); break;
124 case RAWKEY_PAGEUP: strlcat(buffer, "page_up", sizeof(buffer)); break;
125 case RAWKEY_PAGEDOWN: strlcat(buffer, "page_down", sizeof(buffer)); break;
126 case RAWKEY_PRINTSCR: strlcat(buffer, "prtscr", sizeof(buffer)); break;
127 case RAWKEY_BREAK: strlcat(buffer, "pause", sizeof(buffer)); break;
128 case RAWKEY_F12: strlcat(buffer, "f12", sizeof(buffer)); break;
129 case RAWKEY_HOME: strlcat(buffer, "home", sizeof(buffer)); break;
130 case RAWKEY_END: strlcat(buffer, "end", sizeof(buffer)); break;
132 #if defined(__amigaos4__)
133 case RAWKEY_MEDIA_STOP: strlcat(buffer, "media_stop", sizeof(buffer)); break;
134 case RAWKEY_MEDIA_PLAY_PAUSE: strlcat(buffer, "media_play", sizeof(buffer)); break;
135 case RAWKEY_MEDIA_PREV_TRACK: strlcat(buffer, "media_prev", sizeof(buffer)); break;
136 case RAWKEY_MEDIA_NEXT_TRACK: strlcat(buffer, "media_next", sizeof(buffer)); break;
137 case RAWKEY_MEDIA_SHUFFLE: strlcat(buffer, "media_rewind", sizeof(buffer)); break;
138 case RAWKEY_MEDIA_REPEAT: strlcat(buffer, "media_forward", sizeof(buffer)); break;
139 #else
140 case RAWKEY_AUD_STOP: strlcat(buffer, "media_stop", sizeof(buffer)); break;
141 case RAWKEY_AUD_PLAY_PAUSE: strlcat(buffer, "media_play", sizeof(buffer)); break;
142 case RAWKEY_AUD_PREV_TRACK: strlcat(buffer, "media_prev", sizeof(buffer)); break;
143 case RAWKEY_AUD_NEXT_TRACK: strlcat(buffer, "media_next", sizeof(buffer)); break;
144 case RAWKEY_AUD_SHUFFLE: strlcat(buffer, "media_rewind", sizeof(buffer)); break;
145 case RAWKEY_AUD_REPEAT: strlcat(buffer, "media_forward", sizeof(buffer)); break;
146 #endif
149 case RAWKEY_HELP:
150 strlcat(buffer, "help", sizeof(buffer));
151 break;
153 case NM_WHEEL_UP:
154 strlcat(buffer, "nm_wheel_up", sizeof(buffer));
155 break;
157 case NM_WHEEL_DOWN:
158 strlcat(buffer, "nm_wheel_down", sizeof(buffer));
159 break;
161 case NM_WHEEL_LEFT:
162 strlcat(buffer, "nm_wheel_left", sizeof(buffer));
163 break;
165 case NM_WHEEL_RIGHT:
166 strlcat(buffer, "nm_wheel_right", sizeof(buffer));
167 break;
169 case NM_BUTTON_FOURTH:
170 strlcat(buffer, "nm_wheel_button", sizeof(buffer));
171 break;
173 default:
175 const char *append = NULL;
176 unsigned char key[2];
178 key[0] = ConvertKey(msg->imsg);
179 key[1] = 0;
181 switch(key[0])
183 case 0:
184 nokey = TRUE;
185 break;
187 case 8:
188 backspace = TRUE;
189 append = "backspace";
190 break;
192 case 9:
193 append = "tab";
194 break;
196 case 13:
197 append = isFlagSet(qualifier, IEQUALIFIER_NUMERICPAD) ? "enter" : "return";
198 break;
200 case 27:
201 append = "esc";
202 break;
204 case 32:
205 append = "space";
206 break;
208 case 0x7f:
209 append = "del";
210 break;
212 default:
213 append = (char *)key;
214 break;
217 if(append)
218 strlcat(buffer, append, sizeof(buffer));
220 break;
224 if(!nokey)
226 if(backspace)
228 if(isFlagSet(data->Flags, FLG_Backspace))
230 *buffer = '\0';
231 clearFlag(data->Flags, FLG_Backspace);
233 else
235 setFlag(data->Flags, FLG_Backspace);
238 else
240 clearFlag(data->Flags, FLG_Backspace);
242 SetAttrs(obj, MUIA_String_Contents, buffer, TAG_DONE);
244 result = MUI_EventHandlerRC_Eat;
246 else
247 result = 0;
249 return result;