Added a test for MUIA_Listview_SelectChange.
[AROS.git] / workbench / tools / KeyShow / keyboardgroup_class.c
blob2ded9b3baa2995c0c627cf5f16faba68e713df35
1 /*
2 Copyright © 2012, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <proto/muimaster.h>
7 #include <proto/intuition.h>
8 #include <proto/keymap.h>
9 #include <proto/utility.h>
10 #include <proto/alib.h>
12 //#define DEBUG 1
13 #include <aros/debug.h>
15 #include <libraries/mui.h>
16 #include <devices/rawkeycodes.h>
17 #include <zune/customclasses.h>
19 #include <stdio.h>
21 #include "keyboardgroup_class.h"
22 #include "locale.h"
24 #define KEY(n) Child, keybtn[n]
26 #define KBUFSIZE (12)
28 // On classic keyboard in top left corner of num pad
29 #define RAWKEY_KP_LBRACKET 0x5A
30 #define RAWKEY_KP_RBRACKET 0x5B
32 struct Key
34 TEXT alone[KBUFSIZE];
35 TEXT shift[KBUFSIZE];
36 TEXT alt[KBUFSIZE];
37 TEXT ctrl[KBUFSIZE];
38 TEXT shift_alt[KBUFSIZE];
39 TEXT ctrl_alt[KBUFSIZE];
40 TEXT ctrl_shift[KBUFSIZE];
41 BOOL immutable;
44 // copied from rom/keymap/defaultkeymap.c
45 static const BYTE keymapstr_table[8][8] =
47 {0, 0, 0, 0, 0, 0, 0, 0}, /* KCF_NOQUAL == 0 */
48 {0, 1, 0, 1, 0, 1, 0, 1}, /* KCF_SHIFT == 1 */
49 {0, 0, 1, 1, 0, 0, 1, 1}, /* KCF_ALT == 2 */
50 {0, 1, 2, 3, 0, 1, 2, 3}, /* KCF_SHIFT|KCF_ALT == 3 */
51 {0, 0, 0, 0, 1, 1, 1, 1}, /* KCF_CONTROL == 4 */
52 {0, 1, 0, 1, 2, 3, 2, 3}, /* KCF_SHIFT|KCF_CONTROL == 5 */
53 {0, 0, 1, 1, 2, 2, 3, 3}, /* KCF_ALT|KCF_CONTROL == 6 */
54 {0, 1, 2, 3, 4, 5, 6, 7} /* KCF_SHIFT|KCF_ALT|KCF_CONTROL == KC__VANILLA == 7 */
57 // TODO: is this order always the same?
58 static const BYTE deadkey_table[] = " ´`^~\"°";
61 struct KeyboardGroup_DATA
63 struct Key *key;
64 Object *keybutton[128]; // 64-127 are high keys
65 struct Hook change_qualifier_hook;
69 static void set_immutable_key(struct Key *key, ULONG idx, CONST_STRPTR content)
71 strlcpy(key[idx].alone, content, KBUFSIZE);
72 key[idx].immutable = TRUE;
76 static void parse_normal_key(struct Key *key, UBYTE type, IPTR value)
78 switch (type)
80 case KC_NOQUAL:
81 (*key).alone[0] = value & 0xff;
82 break;
83 case KCF_SHIFT:
84 (*key).alone[0] = value & 0xff;
85 (*key).shift[0] = (value >> 8) & 0xff;
86 break;
87 case KCF_ALT:
88 (*key).alone[0] = value & 0xff;
89 (*key).alt[0] = (value >> 8) & 0xff;
90 break;
91 case KCF_CONTROL:
92 (*key).alone[0] = value & 0xff;
93 (*key).ctrl[0] = (value >> 8) & 0xff;
94 break;
95 case KCF_ALT + KCF_SHIFT:
96 (*key).alone[0] = value & 0xff;
97 (*key).shift[0] = (value >> 8) & 0xff;
98 (*key).alt[0] = (value >> 16) & 0xff;
99 (*key).shift_alt[0] = (value >> 24) & 0xff;
100 break;
101 case KCF_CONTROL + KCF_ALT:
102 (*key).alone[0] = value & 0xff;
103 (*key).alt[0] = (value >> 8) & 0xff;
104 (*key).ctrl[0] = (value >> 16) & 0xff;
105 (*key).ctrl_alt[0] = (value >> 24) & 0xff;
106 break;
107 case KCF_CONTROL + KCF_SHIFT:
108 (*key).alone[0] = value & 0xff;
109 (*key).shift[0] = (value >> 8) & 0xff;
110 (*key).ctrl[0] = (value >> 16) & 0xff;
111 (*key).ctrl_shift[0]= (value >> 24) & 0xff;
112 break;
113 case KC_VANILLA:
114 (*key).alone[0] = value & 0xff;
115 (*key).shift[0] = (value >> 8) & 0xff;
116 (*key).alt[0] = (value >> 16) & 0xff;
117 (*key).shift_alt[0] = (value >> 24) & 0xff;
118 (*key).ctrl[0] = '^';
119 (*key).ctrl[1] = value & 0xff;
120 break;
125 static UBYTE set_string_key(UBYTE type, IPTR value, BYTE qual)
127 D(bug("[KeyShow] set_string_key type %u value %u\n", type, value));
129 BYTE idx;
131 D(bug("[KeyShow] getting idx at [%d][%d]\n", type, qual));
132 idx = keymapstr_table[type][qual];
134 if (idx != -1)
136 UBYTE *str_descrs = (UBYTE *)value;
137 UBYTE len, offset;
139 /* Since each string descriptor uses two bytes we multiply by 2 */
140 idx *= 2;
142 /* Get string info from string descriptor table */
143 len = str_descrs[idx];
144 offset = str_descrs[idx + 1];
146 D(bug("[KeyShow] len=%d, offset=%d\n", len, offset));
148 /* Return char only if len is 1 */
149 if (len == 1 && str_descrs[offset] > 31)
151 D(bug("[KeyShow] retval %d", str_descrs[offset]));
152 return str_descrs[offset];
154 } /* if (idx != -1) */
156 return 0;
160 static void parse_string_key(struct Key *key, UBYTE type, IPTR value)
162 D(bug("[KeyShow] parse_string_key type %u value %u\n", type, value));
164 switch (type)
166 case KC_NOQUAL:
167 (*key).alone[0] = set_string_key(type, value, KC_NOQUAL);
168 break;
169 case KCF_SHIFT:
170 (*key).alone[0] = set_string_key(type, value, KC_NOQUAL);
171 (*key).shift[0] = set_string_key(type, value, KCF_SHIFT);
172 break;
173 case KCF_ALT:
174 (*key).alone[0] = set_string_key(type, value, KC_NOQUAL);
175 (*key).alt[0] = set_string_key(type, value, KCF_ALT);
176 break;
177 case KCF_CONTROL:
178 (*key).alone[0] = set_string_key(type, value, KC_NOQUAL);
179 (*key).ctrl[0] = set_string_key(type, value, KCF_CONTROL);
180 break;
181 case KCF_ALT + KCF_SHIFT:
182 (*key).alone[0] = set_string_key(type, value, KC_NOQUAL);
183 (*key).shift[0] = set_string_key(type, value, KCF_SHIFT);
184 (*key).alt[0] = set_string_key(type, value, KCF_ALT);
185 (*key).shift_alt[0] = set_string_key(type, value, KCF_ALT + KCF_SHIFT);
186 break;
187 case KCF_CONTROL + KCF_ALT:
188 (*key).alone[0] = set_string_key(type, value, KC_NOQUAL);
189 (*key).alt[0] = set_string_key(type, value, KCF_ALT);
190 (*key).ctrl[0] = set_string_key(type, value, KCF_CONTROL);
191 (*key).ctrl_alt[0] = set_string_key(type, value, KCF_CONTROL + KCF_ALT);
192 break;
193 case KCF_CONTROL + KCF_SHIFT:
194 (*key).alone[0] = set_string_key(type, value, KC_NOQUAL);
195 (*key).shift[0] = set_string_key(type, value, KCF_SHIFT);
196 (*key).ctrl[0] = set_string_key(type, value, KCF_CONTROL);
197 (*key).ctrl_shift[0]= set_string_key(type, value, KCF_CONTROL + KCF_SHIFT);
198 break;
199 case KC_VANILLA:
200 (*key).alone[0] = set_string_key(type, value, KC_NOQUAL);
201 (*key).shift[0] = set_string_key(type, value, KCF_SHIFT);
202 (*key).alt[0] = set_string_key(type, value, KCF_ALT);
203 (*key).shift_alt[0] = set_string_key(type, value, KCF_ALT + KCF_SHIFT);
204 (*key).ctrl[0] = set_string_key(type, value, KCF_CONTROL);
205 (*key).ctrl_alt[0] = set_string_key(type, value, KCF_CONTROL + KCF_ALT);
206 (*key).ctrl_shift[0]= set_string_key(type, value, KCF_CONTROL + KCF_SHIFT);
207 break;
212 static void set_dead_key(STRPTR buffer, UBYTE type, IPTR value, BYTE qual)
214 D(bug("[KeyShow] set_dead_key type %u value %u\n", type, value));
216 BYTE idx;
217 UBYTE result;
219 /* Use keymap_str table to get idx to right key descriptor */
220 idx = keymapstr_table[type & KC_VANILLA][qual];
221 if (idx != -1)
223 UBYTE *dead_descr = (UBYTE *)value;
225 switch (dead_descr[idx * 2])
227 case DPF_DEAD:
228 // dead key
229 D(bug("[KeyShow] set_dead_key DPF_DEAD\n"));
230 UBYTE deadidx = dead_descr[idx * 2 + 1];
231 if (deadidx < 8)
233 result = deadkey_table[deadidx];
234 if (result > 31)
236 // render char. with pen number 5
237 snprintf(buffer, KBUFSIZE - 1, "\0335%c", result);
240 break;
242 case DPF_MOD:
243 // deadable key
244 D(bug("[KeyShow] set_dead_key DPF_MOD\n"));
245 result = dead_descr[dead_descr[idx * 2 + 1]];
246 if (result > 31)
248 // render char. in bold
249 snprintf(buffer, KBUFSIZE - 1, "\033b%c", result);
251 break;
253 case 0:
254 D(bug("[KeyShow] set_dead_key DPF 0\n"));
255 result = dead_descr[idx * 2 + 1];
256 if (result > 31)
258 buffer[0] = result;
260 break;
267 static void parse_dead_key(struct Key *key, UBYTE type, IPTR value)
269 D(bug("[KeyShow] parse_dead_key key %p type %u value %u\n", key, type, value));
271 switch (type)
273 case KC_NOQUAL:
274 set_dead_key((*key).alone, type, value, KC_NOQUAL);
275 break;
276 case KCF_SHIFT:
277 set_dead_key((*key).alone, type, value, KC_NOQUAL);
278 set_dead_key((*key).shift, type, value, KCF_SHIFT);
279 break;
280 case KCF_ALT:
281 set_dead_key((*key).alone, type, value, KC_NOQUAL);
282 set_dead_key((*key).alt, type, value, KCF_ALT);
283 break;
284 case KCF_CONTROL:
285 set_dead_key((*key).alone, type, value, KC_NOQUAL);
286 set_dead_key((*key).ctrl, type, value, KCF_CONTROL);
287 break;
288 case KCF_ALT + KCF_SHIFT:
289 set_dead_key((*key).alone, type, value, KC_NOQUAL);
290 set_dead_key((*key).shift, type, value, KCF_SHIFT);
291 set_dead_key((*key).alt, type, value, KCF_ALT);
292 set_dead_key((*key).shift_alt, type, value, KCF_ALT + KCF_SHIFT);
293 break;
294 case KCF_CONTROL + KCF_ALT:
295 set_dead_key((*key).alone, type, value, KC_NOQUAL);
296 set_dead_key((*key).alt, type, value, KCF_ALT);
297 set_dead_key((*key).ctrl, type, value, KCF_CONTROL);
298 set_dead_key((*key).ctrl_alt, type, value, KCF_CONTROL + KCF_ALT);
299 break;
300 case KCF_CONTROL + KCF_SHIFT:
301 set_dead_key((*key).alone, type, value, KC_NOQUAL);
302 set_dead_key((*key).shift, type, value, KCF_SHIFT);
303 set_dead_key((*key).ctrl, type, value, KCF_CONTROL);
304 set_dead_key((*key).ctrl_shift, type, value, KCF_CONTROL + KCF_SHIFT);
305 break;
306 case KC_VANILLA:
307 set_dead_key((*key).alone, type, value, KC_NOQUAL);
308 set_dead_key((*key).shift, type, value, KCF_SHIFT);
309 set_dead_key((*key).alt, type, value, KCF_ALT);
310 set_dead_key((*key).shift_alt, type, value, KCF_ALT + KCF_SHIFT);
311 set_dead_key((*key).ctrl, type, value, KCF_CONTROL);
312 set_dead_key((*key).ctrl_alt, type, value, KCF_CONTROL + KCF_ALT);
313 set_dead_key((*key).ctrl_shift, type, value, KCF_CONTROL + KCF_SHIFT);
314 break;
319 static struct Key *read_keymap(void)
321 struct Key *key = AllocVec(sizeof(struct Key) * 128, MEMF_CLEAR);
322 if (key)
324 struct KeyMap *km = AskKeyMapDefault();
325 LONG i;
326 IPTR value;
327 UBYTE type;
328 for (i = 0; i < 128; i++)
330 if (i < 64)
332 type = km->km_LoKeyMapTypes[i];
333 value = km->km_LoKeyMap[i];
335 else
337 type = km->km_HiKeyMapTypes[i-64];
338 value = km->km_HiKeyMap[i-64];
341 if (type & KCF_STRING)
343 parse_string_key(&key[i], type & KC_VANILLA, value);
345 else if (type & KCF_DEAD)
347 parse_dead_key(&key[i], type & KC_VANILLA, value);
349 else
351 parse_normal_key(&key[i], type, value);
354 // Qualifier keys
355 set_immutable_key(key, RAWKEY_LSHIFT, _(MSG_KEY_SHIFT));
356 set_immutable_key(key, RAWKEY_RSHIFT, _(MSG_KEY_SHIFT));
357 set_immutable_key(key, RAWKEY_LCONTROL, _(MSG_KEY_CTRL));
358 set_immutable_key(key, RAWKEY_LALT, _(MSG_KEY_ALT));
359 set_immutable_key(key, RAWKEY_RALT, _(MSG_KEY_ALT));
361 // Special keys
362 set_immutable_key(key, RAWKEY_UP, "\033I[6:11]");
363 set_immutable_key(key, RAWKEY_DOWN, "\033I[6:12]");
364 set_immutable_key(key, RAWKEY_RIGHT, "\033I[6:14]");
365 set_immutable_key(key, RAWKEY_LEFT, "\033I[6:13]");
368 set_immutable_key(key, RAWKEY_CAPSLOCK, _(MSG_KEY_LOCK));
369 set_immutable_key(key, RAWKEY_BACKSPACE, _(MSG_KEY_BACKSP));
370 set_immutable_key(key, RAWKEY_TAB, _(MSG_KEY_TAB));
371 set_immutable_key(key, RAWKEY_RETURN, _(MSG_KEY_RETURN));
372 set_immutable_key(key, RAWKEY_ESCAPE, _(MSG_KEY_ESC));
374 set_immutable_key(key, RAWKEY_HELP, _(MSG_KEY_HELP));
375 set_immutable_key(key, RAWKEY_F1, "F1");
376 set_immutable_key(key, RAWKEY_F2, "F2");
377 set_immutable_key(key, RAWKEY_F3, "F3");
378 set_immutable_key(key, RAWKEY_F4, "F4");
379 set_immutable_key(key, RAWKEY_F5, "F5");
380 set_immutable_key(key, RAWKEY_F6, "F6");
381 set_immutable_key(key, RAWKEY_F7, "F7");
382 set_immutable_key(key, RAWKEY_F8, "F8");
383 set_immutable_key(key, RAWKEY_F9, "F9");
384 set_immutable_key(key, RAWKEY_F10, "F10");
385 set_immutable_key(key, RAWKEY_F11, "F11");
386 set_immutable_key(key, RAWKEY_F12, "F12");
387 set_immutable_key(key, RAWKEY_LAMIGA, _(MSG_KEY_A));
388 set_immutable_key(key, RAWKEY_RAMIGA, _(MSG_KEY_A));
390 set_immutable_key(key, RAWKEY_INSERT, _(MSG_KEY_INSERT));
391 set_immutable_key(key, RAWKEY_HOME, _(MSG_KEY_HOME));
392 set_immutable_key(key, RAWKEY_PAGEUP, _(MSG_KEY_PAGEUP));
393 set_immutable_key(key, RAWKEY_DELETE, _(MSG_KEY_DELETE));
394 set_immutable_key(key, RAWKEY_END, _(MSG_KEY_END));
395 set_immutable_key(key, RAWKEY_PAGEDOWN, _(MSG_KEY_PAGEDOWN));
397 set_immutable_key(key, RAWKEY_PRTSCREEN, _(MSG_KEY_PRTSCREEN));
398 set_immutable_key(key, RAWKEY_SCRLOCK, _(MSG_KEY_SCRLOCK));
399 set_immutable_key(key, RAWKEY_PAUSE, _(MSG_KEY_PAUSE));
401 set_immutable_key(key, RAWKEY_KP_ENTER, _(MSG_KEY_NUM_ENTER));
402 set_immutable_key(key, 127, _(MSG_KEY_CTRL)); // Pseudo right Ctrl
404 return key;
407 AROS_UFH3S(void, change_qualifier_func,
408 AROS_UFHA(struct Hook *, h, A0),
409 AROS_UFHA(Object *, obj, A2),
410 AROS_UFHA(ULONG *, msg, A1))
412 AROS_USERFUNC_INIT
414 struct KeyboardGroup_DATA *data = h->h_Data;
416 ULONG i;
417 ULONG selectedkey = msg[0];
418 BOOL keydown = msg[1];
420 BOOL shift = XGET(data->keybutton[96], MUIA_Selected) | XGET(data->keybutton[97], MUIA_Selected);
421 BOOL alt = XGET(data->keybutton[100], MUIA_Selected) | XGET(data->keybutton[101], MUIA_Selected);
422 BOOL ctrl = XGET(data->keybutton[99], MUIA_Selected) | XGET(data->keybutton[127], MUIA_Selected);
424 D(bug("[keyshow/change_qualifier_func] old: shift %d alt %d ctrl %d key %d trigger %d\n", shift, alt, ctrl, selectedkey, keydown));
426 if (keydown)
428 if ((selectedkey == RAWKEY_LSHIFT) || (selectedkey == RAWKEY_RSHIFT))
429 shift = TRUE;
430 else if ((selectedkey == RAWKEY_LALT) || (selectedkey == RAWKEY_RALT))
431 alt = TRUE;
432 else if ((selectedkey == RAWKEY_LCONTROL) || (selectedkey == 127))
433 ctrl = TRUE;
435 else
437 if ((selectedkey == RAWKEY_LSHIFT) || (selectedkey == RAWKEY_RSHIFT))
438 shift = FALSE;
439 else if ((selectedkey == RAWKEY_LALT) || (selectedkey == RAWKEY_RALT))
440 alt = FALSE;
441 else if ((selectedkey == RAWKEY_LCONTROL) || (selectedkey == 127))
442 ctrl = FALSE;
445 NNSET(data->keybutton[RAWKEY_LSHIFT], MUIA_Selected, shift);
446 NNSET(data->keybutton[RAWKEY_RSHIFT], MUIA_Selected, shift);
447 NNSET(data->keybutton[RAWKEY_LALT], MUIA_Selected, alt);
448 NNSET(data->keybutton[RAWKEY_RALT], MUIA_Selected, alt);
449 NNSET(data->keybutton[RAWKEY_LCONTROL], MUIA_Selected, ctrl);
450 NNSET(data->keybutton[127], MUIA_Selected, ctrl);
452 D(bug("[keyshow/change_qualifier_func] new: shift %d alt %d ctrl %d key %d trigger %d\n", shift, alt, ctrl, selectedkey, keydown));
454 if (shift && !alt && !ctrl)
456 for (i = 0; i < 128; i++)
458 if (!data->key[i].immutable)
459 SET(data->keybutton[i], MUIA_Text_Contents, data->key[i].shift);
462 else if (!shift && alt && !ctrl)
464 for (i = 0; i < 128; i++)
466 if (!data->key[i].immutable)
467 SET(data->keybutton[i], MUIA_Text_Contents, data->key[i].alt);
470 else if (!shift && !alt && ctrl)
472 for (i = 0; i < 128; i++)
474 if (!data->key[i].immutable)
475 SET(data->keybutton[i], MUIA_Text_Contents, data->key[i].ctrl);
478 else if (shift && alt && !ctrl)
480 for (i = 0; i < 128; i++)
482 if (!data->key[i].immutable)
483 SET(data->keybutton[i], MUIA_Text_Contents, data->key[i].shift_alt);
486 else if (!shift && alt && ctrl)
488 for (i = 0; i < 128; i++)
490 if (!data->key[i].immutable)
491 SET(data->keybutton[i], MUIA_Text_Contents, data->key[i].ctrl_alt);
494 else if (shift && !alt && ctrl)
496 for (i = 0; i < 128; i++)
498 if (!data->key[i].immutable)
499 SET(data->keybutton[i], MUIA_Text_Contents, data->key[i].ctrl_shift);
502 else
504 for (i = 0; i < 128; i++)
506 if (!data->key[i].immutable)
507 SET(data->keybutton[i], MUIA_Text_Contents, data->key[i].alone);
511 AROS_USERFUNC_EXIT
515 Object *KeyboardGroup__OM_NEW(Class *CLASS, Object *self, struct opSet *message)
517 LONG i;
518 Object *keybtn[128];
519 struct Key *key = read_keymap();
520 ULONG kbtype = MUIV_KeyboardGroup_Type_Amiga;
522 struct TagItem *tstate = message->ops_AttrList;
523 struct TagItem *tag = NULL;
525 while ((tag = NextTagItem(&tstate)) != NULL)
527 switch (tag->ti_Tag)
529 case MUIA_KeyboardGroup_Type:
530 kbtype = tag->ti_Data;
531 break;
535 for (i = 0; i < 128; i++)
537 if ((i < 96 || i > 101 || i == RAWKEY_CAPSLOCK) && i != 127)
539 keybtn[i] = MUI_NewObject(MUIC_Text,
540 ButtonFrame,
541 MUIA_Font, MUIV_Font_Tiny,
542 MUIA_Text_Contents, key[i].alone,
543 MUIA_Text_PreParse, "\33c",
544 TAG_DONE);
546 else
548 // Qualifier keys
549 keybtn[i] = MUI_NewObject(MUIC_Text,
550 ButtonFrame,
551 MUIA_Font, MUIV_Font_Tiny,
552 MUIA_Text_Contents, key[i].alone,
553 MUIA_Text_PreParse, "\33c",
554 MUIA_InputMode , MUIV_InputMode_Toggle,
555 MUIA_Background , MUII_ButtonBack,
556 TAG_DONE);
560 if (kbtype == MUIV_KeyboardGroup_Type_PC105)
562 self = (Object *) DoSuperNewTags
564 CLASS, self, NULL,
565 MUIA_Group_Horiz, TRUE,
566 Child, VGroup,
567 GroupFrame,
568 Child, HGroup,
569 //MUIA_Group_SameSize, TRUE,
570 KEY(RAWKEY_ESCAPE), KEY(RAWKEY_F1), KEY(RAWKEY_F2), KEY(RAWKEY_F3), KEY(RAWKEY_F4), KEY(RAWKEY_F5),
571 KEY(RAWKEY_F6), KEY(RAWKEY_F7), KEY(RAWKEY_F8), KEY(RAWKEY_F9), KEY(RAWKEY_F10), KEY(RAWKEY_F11), KEY(RAWKEY_F12),
572 End,
573 Child, VSpace(5),
574 Child, HGroup,
575 Child, HGroup,
576 MUIA_Group_SameSize, TRUE,
577 KEY(0), KEY(1), KEY(2), KEY(3), KEY(4), KEY(5), KEY(6), KEY(7), KEY(8), KEY(9), KEY(10), KEY(11), KEY(12), KEY(13),
578 End,
579 KEY(RAWKEY_BACKSPACE),
580 End,
581 Child, HGroup,
582 KEY(RAWKEY_TAB),
583 Child, HGroup,
584 MUIA_Group_SameSize, TRUE,
585 KEY(16), KEY(17), KEY(18), KEY(19), KEY(20), KEY(21), KEY(22), KEY(23), KEY(24), KEY(25), KEY(26), KEY(27),
586 End,
587 KEY(RAWKEY_RETURN),
588 End,
589 Child, HGroup,
590 KEY(RAWKEY_CAPSLOCK),
591 Child, HGroup,
592 MUIA_Group_SameSize, TRUE,
593 KEY(32), KEY(33), KEY(34), KEY(35), KEY(36), KEY(37), KEY(38), KEY(39), KEY(40), KEY(41), KEY(42), KEY(43),
594 End,
595 Child, HVSpace,
596 End,
597 Child, HGroup,
598 KEY(RAWKEY_LSHIFT),
599 Child, HGroup,
600 MUIA_Group_SameSize, TRUE,
601 KEY(48), KEY(49), KEY(50), KEY(51), KEY(52), KEY(53), KEY(54), KEY(55), KEY(56), KEY(57), KEY(58),
602 End,
603 KEY(RAWKEY_RSHIFT),
604 End,
605 Child, HGroup,
606 Child, HGroup,
607 MUIA_Group_SameSize, TRUE,
608 KEY(RAWKEY_LCONTROL), KEY(RAWKEY_LAMIGA), KEY(RAWKEY_LALT),
609 End,
610 KEY(RAWKEY_SPACE),
611 Child, HGroup,
612 MUIA_Group_SameSize, TRUE,
613 KEY(RAWKEY_RALT), KEY(RAWKEY_RAMIGA), KEY(RAWKEY_HELP), KEY(127),
614 End,
615 End,
616 End,
617 Child, VGroup,
618 Child, HGroup,
619 GroupFrame,
620 //MUIA_Group_SameSize, TRUE,
621 KEY(RAWKEY_PRTSCREEN), KEY(RAWKEY_SCRLOCK), KEY(RAWKEY_PAUSE),
622 End,
623 Child, ColGroup(3),
624 GroupFrame,
625 //MUIA_Group_SameSize, TRUE,
626 KEY(RAWKEY_INSERT), KEY(RAWKEY_HOME), KEY(RAWKEY_PAGEUP),
627 KEY(RAWKEY_DELETE), KEY(RAWKEY_END), KEY(RAWKEY_PAGEDOWN),
628 End,
629 Child, HVSpace,
630 Child, ColGroup(3),
631 GroupFrame,
632 MUIA_Group_SameSize, TRUE,
633 Child, HVSpace,
634 KEY(RAWKEY_UP),
635 Child, HVSpace,
636 KEY(RAWKEY_LEFT), KEY(RAWKEY_DOWN), KEY(RAWKEY_RIGHT),
637 End,
638 End,
639 Child, VGroup,
640 Child, HVSpace,
641 Child, ColGroup(4),
642 GroupFrame,
643 MUIA_Group_SameSize, TRUE,
644 // rawkey codes refer to a matrix position and can
645 // differ from their real meaning
646 KEY(RAWKEY_KP_LBRACKET), KEY(RAWKEY_KP_RBRACKET), KEY(RAWKEY_KP_DIVIDE), KEY(RAWKEY_KP_MULTIPLY),
647 KEY(RAWKEY_KP_7), KEY(RAWKEY_KP_8), KEY(RAWKEY_KP_9), KEY(RAWKEY_KP_PLUS),
648 KEY(RAWKEY_KP_4), KEY(RAWKEY_KP_5), KEY(RAWKEY_KP_6), Child, HVSpace,
649 KEY(RAWKEY_KP_1), KEY(RAWKEY_KP_2), KEY(RAWKEY_KP_3), KEY(RAWKEY_KP_ENTER),
650 KEY(RAWKEY_KP_0), Child, HVSpace, KEY(RAWKEY_KP_DECIMAL), Child, HVSpace,
651 End,
652 End,
653 TAG_MORE, (IPTR)message->ops_AttrList
656 else if (kbtype == MUIV_KeyboardGroup_Type_PC104)
658 self = (Object *) DoSuperNewTags
660 CLASS, self, NULL,
661 MUIA_Group_Horiz, TRUE,
662 Child, VGroup,
663 GroupFrame,
664 Child, HGroup,
665 //MUIA_Group_SameSize, TRUE,
666 KEY(RAWKEY_ESCAPE), KEY(RAWKEY_F1), KEY(RAWKEY_F2), KEY(RAWKEY_F3), KEY(RAWKEY_F4), KEY(RAWKEY_F5),
667 KEY(RAWKEY_F6), KEY(RAWKEY_F7), KEY(RAWKEY_F8), KEY(RAWKEY_F9), KEY(RAWKEY_F10), KEY(RAWKEY_F11), KEY(RAWKEY_F12),
668 End,
669 Child, VSpace(5),
670 Child, HGroup,
671 Child, HGroup,
672 MUIA_Group_SameSize, TRUE,
673 KEY(0), KEY(1), KEY(2), KEY(3), KEY(4), KEY(5), KEY(6), KEY(7), KEY(8), KEY(9), KEY(10), KEY(11), KEY(12),
674 End,
675 KEY(RAWKEY_BACKSPACE),
676 End,
677 Child, HGroup,
678 KEY(RAWKEY_TAB),
679 Child, HGroup,
680 MUIA_Group_SameSize, TRUE,
681 KEY(16), KEY(17), KEY(18), KEY(19), KEY(20), KEY(21), KEY(22), KEY(23), KEY(24), KEY(25), KEY(26), KEY(27),
682 End,
683 KEY(13), // FIXME: is this correct?
684 End,
685 Child, HGroup,
686 KEY(RAWKEY_CAPSLOCK),
687 Child, HGroup,
688 MUIA_Group_SameSize, TRUE,
689 KEY(32), KEY(33), KEY(34), KEY(35), KEY(36), KEY(37), KEY(38), KEY(39), KEY(40), KEY(41), KEY(42),
690 End,
691 KEY(RAWKEY_RETURN),
692 End,
693 Child, HGroup,
694 KEY(RAWKEY_LSHIFT),
695 Child, HGroup,
696 MUIA_Group_SameSize, TRUE,
697 KEY(49), KEY(50), KEY(51), KEY(52), KEY(53), KEY(54), KEY(55), KEY(56), KEY(57), KEY(58),
698 End,
699 KEY(RAWKEY_RSHIFT),
700 End,
701 Child, HGroup,
702 Child, HGroup,
703 MUIA_Group_SameSize, TRUE,
704 KEY(RAWKEY_LCONTROL), KEY(RAWKEY_LAMIGA), KEY(RAWKEY_LALT),
705 End,
706 KEY(RAWKEY_SPACE),
707 Child, HGroup,
708 MUIA_Group_SameSize, TRUE,
709 KEY(RAWKEY_RALT), KEY(RAWKEY_RAMIGA), KEY(RAWKEY_HELP), KEY(127),
710 End,
711 End,
712 End,
713 Child, VGroup,
714 Child, HGroup,
715 GroupFrame,
716 //MUIA_Group_SameSize, TRUE,
717 KEY(RAWKEY_PRTSCREEN), KEY(RAWKEY_SCRLOCK), KEY(RAWKEY_PAUSE),
718 End,
719 Child, ColGroup(3),
720 GroupFrame,
721 //MUIA_Group_SameSize, TRUE,
722 KEY(RAWKEY_INSERT), KEY(RAWKEY_HOME), KEY(RAWKEY_PAGEUP),
723 KEY(RAWKEY_DELETE), KEY(RAWKEY_END), KEY(RAWKEY_PAGEDOWN),
724 End,
725 Child, HVSpace,
726 Child, ColGroup(3),
727 GroupFrame,
728 MUIA_Group_SameSize, TRUE,
729 Child, HVSpace,
730 KEY(RAWKEY_UP),
731 Child, HVSpace,
732 KEY(RAWKEY_LEFT), KEY(RAWKEY_DOWN), KEY(RAWKEY_RIGHT),
733 End,
734 End,
735 Child, VGroup,
736 Child, HVSpace,
737 Child, ColGroup(4),
738 GroupFrame,
739 MUIA_Group_SameSize, TRUE,
740 // rawkey codes refer to a matrix position and can
741 // differ from their real meaning
742 KEY(RAWKEY_KP_LBRACKET), KEY(RAWKEY_KP_RBRACKET), KEY(RAWKEY_KP_DIVIDE), KEY(RAWKEY_KP_MULTIPLY),
743 KEY(RAWKEY_KP_7), KEY(RAWKEY_KP_8), KEY(RAWKEY_KP_9), KEY(RAWKEY_KP_PLUS),
744 KEY(RAWKEY_KP_4), KEY(RAWKEY_KP_5), KEY(RAWKEY_KP_6), Child, HVSpace,
745 KEY(RAWKEY_KP_1), KEY(RAWKEY_KP_2), KEY(RAWKEY_KP_3), KEY(RAWKEY_KP_ENTER),
746 KEY(RAWKEY_KP_0), Child, HVSpace, KEY(RAWKEY_KP_DECIMAL), Child, HVSpace,
747 End,
748 End,
749 TAG_MORE, (IPTR)message->ops_AttrList
752 else
754 self = (Object *) DoSuperNewTags
756 CLASS, self, NULL,
757 MUIA_Group_Horiz, TRUE,
758 Child, VGroup,
759 GroupFrame,
760 Child, HGroup,
761 //MUIA_Group_SameSize, TRUE,
762 KEY(RAWKEY_ESCAPE), KEY(RAWKEY_F1), KEY(RAWKEY_F2), KEY(RAWKEY_F3), KEY(RAWKEY_F4), KEY(RAWKEY_F5),
763 KEY(RAWKEY_F6), KEY(RAWKEY_F7), KEY(RAWKEY_F8), KEY(RAWKEY_F9), KEY(RAWKEY_F10),
764 End,
765 Child, VSpace(5),
766 Child, HGroup,
767 Child, HGroup,
768 MUIA_Group_SameSize, TRUE,
769 KEY(0), KEY(1), KEY(2), KEY(3), KEY(4), KEY(5), KEY(6), KEY(7), KEY(8), KEY(9), KEY(10), KEY(11), KEY(12), KEY(13),
770 End,
771 KEY(RAWKEY_BACKSPACE),
772 End,
773 Child, HGroup,
774 KEY(RAWKEY_TAB),
775 Child, HGroup,
776 MUIA_Group_SameSize, TRUE,
777 KEY(16), KEY(17), KEY(18), KEY(19), KEY(20), KEY(21), KEY(22), KEY(23), KEY(24), KEY(25), KEY(26), KEY(27),
778 End,
779 KEY(RAWKEY_RETURN),
780 End,
781 Child, HGroup,
782 KEY(RAWKEY_LCONTROL),
783 KEY(RAWKEY_CAPSLOCK),
784 Child, HGroup,
785 MUIA_Group_SameSize, TRUE,
786 KEY(32), KEY(33), KEY(34), KEY(35), KEY(36), KEY(37), KEY(38), KEY(39), KEY(40), KEY(41), KEY(42), KEY(43),
787 End,
788 Child, HVSpace,
789 End,
790 Child, HGroup,
791 KEY(RAWKEY_LSHIFT),
792 Child, HGroup,
793 MUIA_Group_SameSize, TRUE,
794 KEY(48), KEY(49), KEY(50), KEY(51), KEY(52), KEY(53), KEY(54), KEY(55), KEY(56), KEY(57), KEY(58),
795 End,
796 KEY(RAWKEY_RSHIFT),
797 End,
798 Child, HGroup,
799 Child, HGroup,
800 MUIA_Group_SameSize, TRUE,
801 KEY(RAWKEY_LALT), KEY(RAWKEY_LAMIGA),
802 End,
803 KEY(RAWKEY_SPACE),
804 Child, HGroup,
805 MUIA_Group_SameSize, TRUE,
806 KEY(RAWKEY_RAMIGA), KEY(RAWKEY_RALT),
807 End,
808 End,
809 End,
810 Child, VGroup,
811 Child, HGroup,
812 GroupFrame,
813 //MUIA_Group_SameSize, TRUE,
814 KEY(RAWKEY_DELETE), KEY(RAWKEY_HELP),
815 End,
816 Child, HVSpace,
817 Child, ColGroup(3),
818 GroupFrame,
819 MUIA_Group_SameSize, TRUE,
820 Child, HVSpace,
821 KEY(RAWKEY_UP),
822 Child, HVSpace,
823 KEY(RAWKEY_LEFT), KEY(RAWKEY_DOWN), KEY(RAWKEY_RIGHT),
824 End,
825 End,
826 Child, VGroup,
827 Child, HVSpace,
828 Child, ColGroup(4),
829 GroupFrame,
830 MUIA_Group_SameSize, TRUE,
831 KEY(RAWKEY_KP_LBRACKET), KEY(RAWKEY_KP_RBRACKET), KEY(RAWKEY_KP_DIVIDE), KEY(RAWKEY_KP_MULTIPLY),
832 KEY(RAWKEY_KP_7), KEY(RAWKEY_KP_8), KEY(RAWKEY_KP_9), KEY(RAWKEY_KP_MINUS),
833 KEY(RAWKEY_KP_4), KEY(RAWKEY_KP_5), KEY(RAWKEY_KP_6), KEY(RAWKEY_KP_PLUS),
834 KEY(RAWKEY_KP_1), KEY(RAWKEY_KP_2), KEY(RAWKEY_KP_3), KEY(RAWKEY_KP_ENTER),
835 KEY(RAWKEY_KP_0), Child, HVSpace, KEY(RAWKEY_KP_DECIMAL), Child, HVSpace,
836 End,
837 End,
838 TAG_MORE, (IPTR)message->ops_AttrList
842 if (self)
844 struct KeyboardGroup_DATA *data = INST_DATA(CLASS, self);
846 data->key = key;
847 for (i = 0; i < 128; i++)
849 data->keybutton[i] = keybtn[i];
852 data->change_qualifier_hook.h_Entry = (HOOKFUNC)change_qualifier_func;
853 data->change_qualifier_hook.h_Data = data;
855 // add notifications to the qualifier keys
856 for (i = 96; i < 104; i++)
858 DoMethod
860 data->keybutton[i], MUIM_Notify, MUIA_Selected, MUIV_EveryTime,
861 self, 4, MUIM_CallHook, &data->change_qualifier_hook, i, MUIV_TriggerValue
864 DoMethod
866 data->keybutton[127], MUIM_Notify, MUIA_Selected, MUIV_EveryTime,
867 self, 4, MUIM_CallHook, &data->change_qualifier_hook, 127, MUIV_TriggerValue
870 return self;
874 IPTR KeyboardGroup__OM_DISPOSE(Class *CLASS, Object *self, Msg message)
876 struct KeyboardGroup_DATA *data = INST_DATA(CLASS, self);
878 FreeVec(data->key);
880 return DoSuperMethodA(CLASS, self, message);
884 IPTR KeyboardGroup__MUIM_Setup(Class *CLASS, Object *obj, struct MUIP_HandleInput *msg)
886 if (!DoSuperMethodA(CLASS, obj, msg))
887 return FALSE;
889 MUI_RequestIDCMP(obj, IDCMP_RAWKEY);
891 return TRUE;
895 IPTR KeyboardGroup__MUIM_Cleanup(Class *CLASS, Object *obj, struct MUIP_HandleInput *msg)
897 MUI_RejectIDCMP(obj,IDCMP_MOUSEBUTTONS|IDCMP_RAWKEY);
898 return DoSuperMethodA(CLASS, obj, msg);
902 IPTR KeyboardGroup__MUIM_HandleInput(Class *CLASS, Object *obj, struct MUIP_HandleInput *msg)
904 struct KeyboardGroup_DATA *data = INST_DATA(CLASS, obj);
906 if (msg->imsg)
908 switch (msg->imsg->Class)
910 case IDCMP_RAWKEY:
912 D(bug("[KeyShow/HandleInput] Rawkey %d\n", msg->imsg->Code));
913 if (msg->imsg->Code > 95 && msg->imsg->Code < 102 && msg->imsg->Code != RAWKEY_CAPSLOCK) // Qualifier key
915 Object *btn = data->keybutton[msg->imsg->Code];
916 if (btn)
918 SET(btn, MUIA_Selected, XGET(btn, MUIA_Selected) ? FALSE : TRUE);
919 //MUI_Redraw(obj, MADF_DRAWUPDATE);
923 break;
927 return 0;
930 ZUNE_CUSTOMCLASS_5
932 KeyboardGroup, NULL, MUIC_Group, NULL,
933 OM_NEW, struct opSet *,
934 OM_DISPOSE, Msg,
935 MUIM_Setup, struct MUIP_HandleInput *,
936 MUIM_Cleanup, struct MUIP_HandleInput *,
937 MUIM_HandleInput, struct MUIP_HandleInput *