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/
21 ***************************************************************************/
25 #include <devices/inputevent.h>
26 #include <libraries/mui.h>
27 #include <proto/intuition.h>
28 #include <proto/keymap.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
);
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
;
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",
78 ULONG qualifier
= msg
->imsg
->Qualifier
;
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
));
96 buffer
[strlen(buffer
)-1] = '\0';
100 UWORD code
= msg
->imsg
->Code
;
102 if(code
>= RAWKEY_F11
&& code
<= RAWKEY_F10
)
104 static const char *key_name
[] =
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
));
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;
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;
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;
150 strlcat(buffer
, "help", sizeof(buffer
));
154 strlcat(buffer
, "nm_wheel_up", sizeof(buffer
));
158 strlcat(buffer
, "nm_wheel_down", sizeof(buffer
));
162 strlcat(buffer
, "nm_wheel_left", sizeof(buffer
));
166 strlcat(buffer
, "nm_wheel_right", sizeof(buffer
));
169 case NM_BUTTON_FOURTH
:
170 strlcat(buffer
, "nm_wheel_button", sizeof(buffer
));
175 const char *append
= NULL
;
176 unsigned char key
[2];
178 key
[0] = ConvertKey(msg
->imsg
);
189 append
= "backspace";
197 append
= isFlagSet(qualifier
, IEQUALIFIER_NUMERICPAD
) ? "enter" : "return";
213 append
= (char *)key
;
218 strlcat(buffer
, append
, sizeof(buffer
));
228 if(isFlagSet(data
->Flags
, FLG_Backspace
))
231 clearFlag(data
->Flags
, FLG_Backspace
);
235 setFlag(data
->Flags
, FLG_Backspace
);
240 clearFlag(data
->Flags
, FLG_Backspace
);
242 SetAttrs(obj
, MUIA_String_Contents
, buffer
, TAG_DONE
);
244 result
= MUI_EventHandlerRC_Eat
;