1 /***************************************************************************
3 TextEditor.mcc - Textediting MUI Custom Class
4 Copyright (C) 1997-2000 Allan Odgaard
5 Copyright (C) 2005-2014 TextEditor.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 TextEditor class Support Site: http://www.sf.net/projects/texteditor-mcc
21 ***************************************************************************/
26 #include <clib/alib_protos.h>
27 #include <devices/inputevent.h>
29 #include <dos/dostags.h>
30 #include <dos/rdargs.h>
31 #include <exec/memory.h>
32 #include <libraries/mui.h>
33 #include <mui/HotkeyString_mcc.h>
34 #include <proto/dos.h>
35 #include <proto/exec.h>
36 #include <proto/intuition.h>
37 #include <proto/keymap.h>
38 #include <proto/muimaster.h>
83 #if defined(__amigaos4__)
85 #elif defined(__MORPHOS__)
109 void ConvertKeyString(STRPTR keystring
, UWORD action
, struct KeyAction
*storage
)
111 IPTR args
[key_count
];
112 struct RDArgs
*ra_result
;
113 struct RDArgs
*myrdargs
;
115 static const char * const ratemplate
=
116 "LSHIFT/S,RSHIFT/S,CAPSLOCK/S,CONTROL=CTRL/S,LALT/S,RALT/S,LAMIGA=LCOMMAND/S,RAMIGA=RCOMMAND/S,NUMPAD=NUMERICPAD/S,SHIFT/S,ALT/S,AMIGA=COMMAND/S,"
117 "f1/S,f2/S,f3/S,f4/S,f5/S,f6/S,f7/S,f8/S,f9/S,f10/S,f11/S,f12/S,"
119 "up/S,down/S,right/S,left/S,"
120 "home/S,end/S,page_up=pageup/S,page_down=pagedown/S,insert/S,printscreen=prtscr/S,pause=break/S,numlock/S,"
121 #if defined(__amigaos4__)
123 #elif defined(__MORPHOS__)
124 "scrolllock=scrlock/S,"
126 "media_stop/S,media_play/S,media_prev/S,media_next/S,media_rewind/S,media_forward/S,"
127 "nm_wheel_up/S,nm_wheel_down/S,nm_wheel_left/S,nm_wheel_right/S,nm_wheel_button/S,"
128 "escape=esc/S,tab/S,return=enter/S,space/S,backspace=bs/S,delete=del/S,key/F";
130 storage
->vanilla
= FALSE
;
132 storage
->qualifier
= 0;
133 storage
->action
= action
;
136 memset(args
, 0, sizeof(args
));
138 if((myrdargs
= AllocDosObject(DOS_RDARGS
, NULL
)) != NULL
)
140 ULONG length
= strlen(keystring
);
143 if((buffer
= AllocVecShared(length
+ 2, MEMF_ANY
)) != NULL
)
145 strlcpy(buffer
, keystring
, length
+ 1);
146 buffer
[length
] = '\n';
147 buffer
[length
+1] = '\0';
148 myrdargs
->RDA_Source
.CS_Buffer
= buffer
;
149 myrdargs
->RDA_Source
.CS_Length
= length
+1;
150 myrdargs
->RDA_Source
.CS_CurChr
= 0;
151 myrdargs
->RDA_Flags
|= RDAF_NOPROMPT
;
153 if((ra_result
= ReadArgs(ratemplate
, (APTR
)args
, myrdargs
)) != NULL
)
155 // Scan for 12 qualifier keys
157 storage
->qualifier
|= IEQUALIFIER_LSHIFT
;
159 storage
->qualifier
|= IEQUALIFIER_RSHIFT
;
160 if(args
[key_capslock
])
161 storage
->qualifier
|= IEQUALIFIER_CAPSLOCK
;
162 if(args
[key_control
])
163 storage
->qualifier
|= IEQUALIFIER_CONTROL
;
165 storage
->qualifier
|= IEQUALIFIER_LALT
;
167 storage
->qualifier
|= IEQUALIFIER_RALT
;
169 storage
->qualifier
|= IEQUALIFIER_LCOMMAND
;
171 storage
->qualifier
|= IEQUALIFIER_RCOMMAND
;
173 storage
->qualifier
|= IEQUALIFIER_NUMERICPAD
;
175 storage
->qualifier
|= IEQUALIFIER_SHIFT
;
177 storage
->qualifier
|= IEQUALIFIER_ALT
;
179 storage
->qualifier
|= IEQUALIFIER_COMMAND
;
181 // Scan for the 10 standard F-keys (f1-f10)
183 storage
->key
= RAWKEY_F1
;
185 storage
->key
= RAWKEY_F2
;
187 storage
->key
= RAWKEY_F3
;
189 storage
->key
= RAWKEY_F4
;
191 storage
->key
= RAWKEY_F5
;
193 storage
->key
= RAWKEY_F6
;
195 storage
->key
= RAWKEY_F7
;
197 storage
->key
= RAWKEY_F8
;
199 storage
->key
= RAWKEY_F9
;
201 storage
->key
= RAWKEY_F10
;
203 // Scan for the 2 extended f-keys (f11,f12)
205 storage
->key
= RAWKEY_F11
;
207 storage
->key
= RAWKEY_F12
;
211 storage
->key
= RAWKEY_HELP
;
213 // Scan for cursor-keys
215 storage
->key
= RAWKEY_CRSRUP
;
217 storage
->key
= RAWKEY_CRSRDOWN
;
219 storage
->key
= RAWKEY_CRSRRIGHT
;
221 storage
->key
= RAWKEY_CRSRLEFT
;
223 // scan for the other extended (non-standard) keys
225 storage
->key
= RAWKEY_HOME
;
227 storage
->key
= RAWKEY_END
;
228 if(args
[key_page_up
])
229 storage
->key
= RAWKEY_PAGEUP
;
230 if(args
[key_page_down
])
231 storage
->key
= RAWKEY_PAGEDOWN
;
233 storage
->key
= RAWKEY_INSERT
;
235 storage
->key
= RAWKEY_PRINTSCR
;
237 storage
->key
= RAWKEY_BREAK
;
238 if(args
[key_numlock
])
239 storage
->key
= RAWKEY_NUMLOCK
;
241 // some keys are mutual excluse on some platforms
242 #if defined(__amigso4__)
244 storage
->key
= RAWKEY_MENU
;
245 #elif defined(__MORPHOS__)
246 if(args
[key_scrlock
])
247 storage
->key
= RAWKEY_SCRLOCK
;
250 // lets address the media/CDTV keys as well
251 #if defined(__amigaos4__)
252 if(args
[key_mm_stop
])
253 storage
->key
= RAWKEY_MEDIA_STOP
;
254 if(args
[key_mm_play
])
255 storage
->key
= RAWKEY_MEDIA_PLAY_PAUSE
;
256 if(args
[key_mm_prev
])
257 storage
->key
= RAWKEY_MEDIA_PREV_TRACK
;
258 if(args
[key_mm_next
])
259 storage
->key
= RAWKEY_MEDIA_NEXT_TRACK
;
260 if(args
[key_mm_rewind
])
261 storage
->key
= RAWKEY_MEDIA_SHUFFLE
;
262 if(args
[key_mm_forward
])
263 storage
->key
= RAWKEY_MEDIA_REPEAT
;
265 if(args
[key_mm_stop
])
266 storage
->key
= RAWKEY_AUD_STOP
;
267 if(args
[key_mm_play
])
268 storage
->key
= RAWKEY_AUD_PLAY_PAUSE
;
269 if(args
[key_mm_prev
])
270 storage
->key
= RAWKEY_AUD_PREV_TRACK
;
271 if(args
[key_mm_next
])
272 storage
->key
= RAWKEY_AUD_NEXT_TRACK
;
273 if(args
[key_mm_rewind
])
274 storage
->key
= RAWKEY_AUD_SHUFFLE
;
275 if(args
[key_mm_forward
])
276 storage
->key
= RAWKEY_AUD_REPEAT
;
279 // take respect of the NEWMOUSE RAWKEY based wheel events as well
280 if(args
[key_wheel_up
])
281 storage
->key
= NM_WHEEL_UP
;
282 if(args
[key_wheel_down
])
283 storage
->key
= NM_WHEEL_DOWN
;
284 if(args
[key_wheel_left
])
285 storage
->key
= NM_WHEEL_LEFT
;
286 if(args
[key_wheel_right
])
287 storage
->key
= NM_WHEEL_RIGHT
;
288 if(args
[key_wheel_button
])
289 storage
->key
= NM_BUTTON_FOURTH
;
291 if(storage
->key
== 0)
293 storage
->vanilla
= TRUE
;
295 storage
->key
= 0x1b; /* Esc */
297 storage
->key
= 0x09; /* Tab */
299 storage
->key
= 0x0d; /* CR */
301 storage
->key
= 0x20; /* Space */
302 if(args
[key_backspace
])
303 storage
->key
= 0x08; /* Backspace */
305 storage
->key
= 0x7f; /* Delete */
307 if(storage
->key
== 0 && args
[key_key
])
309 STRPTR str
= (STRPTR
)args
[key_key
];
311 storage
->key
= str
[0];
318 FreeDosObject(DOS_RDARGS
, myrdargs
);
322 void KeyToString(STRPTR buffer
, ULONG buffer_len
, struct KeyAction
*ka
)
326 // lets first put the qualifiers in our buffer string
327 if(ka
->qualifier
& IEQUALIFIER_LSHIFT
)
328 strlcat(buffer
, "lshift ", buffer_len
);
329 if(ka
->qualifier
& IEQUALIFIER_RSHIFT
)
330 strlcat(buffer
, "rshift ", buffer_len
);
331 if(ka
->qualifier
& IEQUALIFIER_CAPSLOCK
)
332 strlcat(buffer
, "capslock ", buffer_len
);
333 if(ka
->qualifier
& IEQUALIFIER_CONTROL
)
334 strlcat(buffer
, "control ", buffer_len
);
335 if(ka
->qualifier
& IEQUALIFIER_LALT
)
336 strlcat(buffer
, "lalt ", buffer_len
);
337 if(ka
->qualifier
& IEQUALIFIER_RALT
)
338 strlcat(buffer
, "ralt ", buffer_len
);
339 if(ka
->qualifier
& IEQUALIFIER_LCOMMAND
)
340 strlcat(buffer
, "lcommand ", buffer_len
);
341 if(ka
->qualifier
& IEQUALIFIER_RCOMMAND
)
342 strlcat(buffer
, "rcommand ", buffer_len
);
343 if(ka
->qualifier
& IEQUALIFIER_NUMERICPAD
)
344 strlcat(buffer
, "numpad ", buffer_len
);
345 if(ka
->qualifier
& IEQUALIFIER_SHIFT
)
346 strlcat(buffer
, "shift ", buffer_len
);
347 if(ka
->qualifier
& IEQUALIFIER_ALT
)
348 strlcat(buffer
, "alt ", buffer_len
);
349 if(ka
->qualifier
& IEQUALIFIER_COMMAND
)
350 strlcat(buffer
, "command ", buffer_len
);
352 // then we check wheter this are vanilla key codes or RAWKEY codes
357 case 0x08: strlcat(buffer
, "backspace", buffer_len
); break;
358 case 0x09: strlcat(buffer
, "tab", buffer_len
); break;
359 case 0x0d: strlcat(buffer
, ((ka
->qualifier
& IEQUALIFIER_NUMERICPAD
) ? "enter" : "return"), buffer_len
); break;
360 case 0x1b: strlcat(buffer
, "esc", buffer_len
); break;
361 case 0x29: strlcat(buffer
, "space", buffer_len
); break;
362 case 0x7f: strlcat(buffer
, "del", buffer_len
); break;
366 char *p
= &buffer
[strlen(buffer
)];
377 case RAWKEY_CRSRUP
: strlcat(buffer
, "up", buffer_len
); break;
378 case RAWKEY_CRSRDOWN
: strlcat(buffer
, "down", buffer_len
); break;
379 case RAWKEY_CRSRRIGHT
: strlcat(buffer
, "right", buffer_len
); break;
380 case RAWKEY_CRSRLEFT
: strlcat(buffer
, "left", buffer_len
); break;
381 case RAWKEY_F1
: strlcat(buffer
, "f1", buffer_len
); break;
382 case RAWKEY_F2
: strlcat(buffer
, "f2", buffer_len
); break;
383 case RAWKEY_F3
: strlcat(buffer
, "f3", buffer_len
); break;
384 case RAWKEY_F4
: strlcat(buffer
, "f4", buffer_len
); break;
385 case RAWKEY_F5
: strlcat(buffer
, "f5", buffer_len
); break;
386 case RAWKEY_F6
: strlcat(buffer
, "f6", buffer_len
); break;
387 case RAWKEY_F7
: strlcat(buffer
, "f7", buffer_len
); break;
388 case RAWKEY_F8
: strlcat(buffer
, "f8", buffer_len
); break;
389 case RAWKEY_F9
: strlcat(buffer
, "f9", buffer_len
); break;
390 case RAWKEY_F10
: strlcat(buffer
, "f10", buffer_len
); break;
391 case RAWKEY_F11
: strlcat(buffer
, "f11", buffer_len
); break;
392 case RAWKEY_F12
: strlcat(buffer
, "f12", buffer_len
); break;
393 case RAWKEY_HELP
: strlcat(buffer
, "help", buffer_len
); break;
394 case RAWKEY_HOME
: strlcat(buffer
, "home", buffer_len
); break;
395 case RAWKEY_END
: strlcat(buffer
, "end", buffer_len
); break;
396 case RAWKEY_PAGEUP
: strlcat(buffer
, "page_up", buffer_len
); break;
397 case RAWKEY_PAGEDOWN
: strlcat(buffer
, "page_down", buffer_len
); break;
398 case RAWKEY_INSERT
: strlcat(buffer
, "insert", buffer_len
); break;
399 case RAWKEY_PRINTSCR
: strlcat(buffer
, "printscreen", buffer_len
); break;
400 case RAWKEY_BREAK
: strlcat(buffer
, "pause", buffer_len
); break;
401 case RAWKEY_NUMLOCK
: strlcat(buffer
, "numlock", buffer_len
); break;
403 #if defined(__amigaos4__)
404 case RAWKEY_MENU
: strlcat(buffer
, "menu", buffer_len
); break;
405 #elif defined(__MORPHOS__)
406 case RAWKEY_SCRLOCK
: strlcat(buffer
, "scrolllock", buffer_len
); break;
409 #if defined(__amigaos4__)
410 case RAWKEY_MEDIA_STOP
: strlcat(buffer
, "media_stop", buffer_len
); break;
411 case RAWKEY_MEDIA_PLAY_PAUSE
: strlcat(buffer
, "media_play", buffer_len
); break;
412 case RAWKEY_MEDIA_PREV_TRACK
: strlcat(buffer
, "media_prev", buffer_len
); break;
413 case RAWKEY_MEDIA_NEXT_TRACK
: strlcat(buffer
, "media_next", buffer_len
); break;
414 case RAWKEY_MEDIA_SHUFFLE
: strlcat(buffer
, "media_rewind", buffer_len
); break;
415 case RAWKEY_MEDIA_REPEAT
: strlcat(buffer
, "media_forward", buffer_len
); break;
417 case RAWKEY_AUD_STOP
: strlcat(buffer
, "media_stop", buffer_len
); break;
418 case RAWKEY_AUD_PLAY_PAUSE
: strlcat(buffer
, "media_play", buffer_len
); break;
419 case RAWKEY_AUD_PREV_TRACK
: strlcat(buffer
, "media_prev", buffer_len
); break;
420 case RAWKEY_AUD_NEXT_TRACK
: strlcat(buffer
, "media_next", buffer_len
); break;
421 case RAWKEY_AUD_SHUFFLE
: strlcat(buffer
, "media_rewind", buffer_len
); break;
422 case RAWKEY_AUD_REPEAT
: strlcat(buffer
, "media_forward", buffer_len
); break;
425 case NM_WHEEL_UP
: strlcat(buffer
, "nm_wheel_up", buffer_len
); break;
426 case NM_WHEEL_DOWN
: strlcat(buffer
, "nm_wheel_down", buffer_len
); break;
427 case NM_WHEEL_LEFT
: strlcat(buffer
, "nm_wheel_left", buffer_len
); break;
428 case NM_WHEEL_RIGHT
: strlcat(buffer
, "nm_wheel_right", buffer_len
); break;
429 case NM_BUTTON_FOURTH
: strlcat(buffer
, "nm_wheel_button", buffer_len
); break;
432 strlcat(buffer
, "???", buffer_len
);
438 void ImportKeys(struct InstData_MCP
*data
, void *config
)
441 struct te_key
*userkeys
;
445 if(config
!= NULL
&& (cfg_data
= (void *)DoMethod(config
, MUIM_Dataspace_Find
, MUICFG_TextEditor_Keybindings
)))
448 userkeys
= (struct te_key
*)default_keybindings
;
450 DoMethod(data
->keybindings
, MUIM_List_Clear
);
452 set(data
->keybindings
, MUIA_List_Quiet
, TRUE
);
454 while((WORD
)userkeys
->code
!= -1)
456 DoMethod(data
->keybindings
, MUIM_List_InsertSingle
, userkeys
, MUIV_List_Insert_Bottom
);
461 set(data
->keybindings
, MUIA_List_Quiet
, FALSE
);
466 void ExportKeys(struct InstData_MCP
*data
, void *config
)
469 struct te_key
*entry
;
470 struct te_key
*entries
;
472 c
= xget(data
->keybindings
, MUIA_List_Entries
);
473 size
= (c
+1) * sizeof(struct te_key
);
475 if((entries
= (struct te_key
*)AllocVecShared(size
, MEMF_ANY
)))
477 struct te_key
*buffer
= entries
+c
;
482 DoMethod(data
->keybindings
, MUIM_List_GetEntry
, c
, &entry
);
484 buffer
->code
= entry
->code
;
485 buffer
->qual
= entry
->qual
;
486 buffer
->act
= entry
->act
;
488 DoMethod(config
, MUIM_Dataspace_Add
, entries
, size
, MUICFG_TextEditor_Keybindings
);