diff options
Diffstat (limited to 'apps')
-rw-r--r-- | apps/recorder/keyboard.c | 581 |
1 files changed, 295 insertions, 286 deletions
diff --git a/apps/recorder/keyboard.c b/apps/recorder/keyboard.c index 5bfb1024b3..856a1482e3 100644 --- a/apps/recorder/keyboard.c +++ b/apps/recorder/keyboard.c | |||
@@ -20,7 +20,6 @@ | |||
20 | ****************************************************************************/ | 20 | ****************************************************************************/ |
21 | #include "kernel.h" | 21 | #include "kernel.h" |
22 | #include "system.h" | 22 | #include "system.h" |
23 | #include "version.h" | ||
24 | #include <string.h> | 23 | #include <string.h> |
25 | #include "font.h" | 24 | #include "font.h" |
26 | #include "screens.h" | 25 | #include "screens.h" |
@@ -39,7 +38,6 @@ | |||
39 | #include "viewport.h" | 38 | #include "viewport.h" |
40 | #include "file.h" | 39 | #include "file.h" |
41 | #include "splash.h" | 40 | #include "splash.h" |
42 | #include "appevents.h" | ||
43 | 41 | ||
44 | #ifndef O_BINARY | 42 | #ifndef O_BINARY |
45 | #define O_BINARY 0 | 43 | #define O_BINARY 0 |
@@ -94,17 +92,17 @@ | |||
94 | 92 | ||
95 | struct keyboard_parameters | 93 | struct keyboard_parameters |
96 | { | 94 | { |
97 | const unsigned char* default_kbd; | ||
98 | int DEFAULT_LINES; | ||
99 | unsigned short kbd_buf[KBD_BUF_SIZE]; | 95 | unsigned short kbd_buf[KBD_BUF_SIZE]; |
96 | int default_lines; | ||
100 | int nchars; | 97 | int nchars; |
101 | int font_w; | 98 | int font_w; |
102 | int font_h; | 99 | int font_h; |
103 | int text_w; | 100 | int text_w; |
104 | struct font* font; | ||
105 | int curfont; | 101 | int curfont; |
106 | int main_y; | 102 | int main_y; |
103 | #ifdef HAVE_MORSE_INPUT | ||
107 | int old_main_y; | 104 | int old_main_y; |
105 | #endif | ||
108 | int max_chars; | 106 | int max_chars; |
109 | int max_chars_text; | 107 | int max_chars_text; |
110 | int lines; | 108 | int lines; |
@@ -118,8 +116,23 @@ struct keyboard_parameters | |||
118 | #ifdef KBD_MODES | 116 | #ifdef KBD_MODES |
119 | bool line_edit; | 117 | bool line_edit; |
120 | #endif | 118 | #endif |
119 | }; | ||
120 | |||
121 | struct edit_state | ||
122 | { | ||
123 | char* text; | ||
124 | int buflen; | ||
125 | int len_utf8; | ||
126 | int editpos; /* Edit position on all screens */ | ||
127 | bool cur_blink; /* Cursor on/off flag */ | ||
121 | bool hangul; | 128 | bool hangul; |
122 | unsigned short hlead, hvowel, htail; | 129 | unsigned short hlead, hvowel, htail; |
130 | #ifdef HAVE_MORSE_INPUT | ||
131 | bool morse_mode; | ||
132 | bool morse_reading; | ||
133 | unsigned char morse_code; | ||
134 | int morse_tick; | ||
135 | #endif | ||
123 | }; | 136 | }; |
124 | 137 | ||
125 | static struct keyboard_parameters kbd_param[NB_SCREENS]; | 138 | static struct keyboard_parameters kbd_param[NB_SCREENS]; |
@@ -147,8 +160,10 @@ int load_kbd(unsigned char* filename) | |||
147 | 160 | ||
148 | FOR_NB_SCREENS(l) | 161 | FOR_NB_SCREENS(l) |
149 | { | 162 | { |
163 | /* initialize parameters */ | ||
150 | struct keyboard_parameters *pm = &kbd_param[l]; | 164 | struct keyboard_parameters *pm = &kbd_param[l]; |
151 | pm->x = pm->y = pm->page = 0; | 165 | pm->x = pm->y = pm->page = 0; |
166 | pm->default_lines = 0; | ||
152 | } | 167 | } |
153 | 168 | ||
154 | if (filename == NULL) | 169 | if (filename == NULL) |
@@ -185,11 +200,12 @@ int load_kbd(unsigned char* filename) | |||
185 | } | 200 | } |
186 | 201 | ||
187 | utf8decode(buf, &ch); | 202 | utf8decode(buf, &ch); |
188 | FOR_NB_SCREENS(l) | 203 | if (ch != 0xFEFF && ch != '\r') /* skip BOM & carriage returns */ |
189 | kbd_param[l].kbd_buf[i] = ch; | 204 | { |
190 | 205 | FOR_NB_SCREENS(l) | |
191 | if (ch != 0xFEFF && ch != '\r') /*skip BOM & carriage returns */ | 206 | kbd_param[l].kbd_buf[i] = ch; |
192 | i++; | 207 | i++; |
208 | } | ||
193 | } | 209 | } |
194 | 210 | ||
195 | close(fd); | 211 | close(fd); |
@@ -211,7 +227,7 @@ static void kbd_spellchar(unsigned short c) | |||
211 | unsigned char* utf8 = utf8encode(c, tmp); | 227 | unsigned char* utf8 = utf8encode(c, tmp); |
212 | *utf8 = 0; | 228 | *utf8 = 0; |
213 | 229 | ||
214 | if(c == ' ') | 230 | if (c == ' ') |
215 | talk_id(VOICE_BLANK, false); | 231 | talk_id(VOICE_BLANK, false); |
216 | else | 232 | else |
217 | talk_spell(tmp, false); | 233 | talk_spell(tmp, false); |
@@ -221,43 +237,42 @@ static void kbd_spellchar(unsigned short c) | |||
221 | #ifdef KBD_MODES | 237 | #ifdef KBD_MODES |
222 | static void say_edit(void) | 238 | static void say_edit(void) |
223 | { | 239 | { |
224 | if(global_settings.talk_menu) | 240 | if (global_settings.talk_menu) |
225 | talk_id(VOICE_EDIT, false); | 241 | talk_id(VOICE_EDIT, false); |
226 | } | 242 | } |
227 | #endif | 243 | #endif |
228 | 244 | ||
229 | static void kbd_inschar(unsigned char* text, int buflen, | 245 | static void kbd_inschar(struct edit_state *state, unsigned short ch) |
230 | int* editpos, unsigned short ch) | ||
231 | { | 246 | { |
232 | int i, j, len; | 247 | int i, j, len; |
233 | unsigned char tmp[4]; | 248 | unsigned char tmp[4]; |
234 | unsigned char* utf8; | 249 | unsigned char* utf8; |
235 | 250 | ||
236 | len = strlen(text); | 251 | len = strlen(state->text); |
237 | utf8 = utf8encode(ch, tmp); | 252 | utf8 = utf8encode(ch, tmp); |
238 | j = (long)utf8 - (long)tmp; | 253 | j = (long)utf8 - (long)tmp; |
239 | 254 | ||
240 | if (len + j < buflen) | 255 | if (len + j < state->buflen) |
241 | { | 256 | { |
242 | i = utf8seek(text, *editpos); | 257 | i = utf8seek(state->text, state->editpos); |
243 | utf8 = text + i; | 258 | utf8 = state->text + i; |
244 | memmove(utf8 + j, utf8, len - i + 1); | 259 | memmove(utf8 + j, utf8, len - i + 1); |
245 | memcpy(utf8, tmp, j); | 260 | memcpy(utf8, tmp, j); |
246 | (*editpos)++; | 261 | state->editpos++; |
247 | } | 262 | } |
248 | } | 263 | } |
249 | 264 | ||
250 | static void kbd_delchar(unsigned char* text, int* editpos) | 265 | static void kbd_delchar(struct edit_state *state) |
251 | { | 266 | { |
252 | int i, j, len; | 267 | int i, j, len; |
253 | unsigned char* utf8; | 268 | unsigned char* utf8; |
254 | 269 | ||
255 | if (*editpos > 0) | 270 | if (state->editpos > 0) |
256 | { | 271 | { |
257 | (*editpos)--; | 272 | state->editpos--; |
258 | len = strlen(text); | 273 | len = strlen(state->text); |
259 | i = utf8seek(text, *editpos); | 274 | i = utf8seek(state->text, state->editpos); |
260 | utf8 = text + i; | 275 | utf8 = state->text + i; |
261 | j = utf8seek(utf8, 1); | 276 | j = utf8seek(utf8, 1); |
262 | memmove(utf8, utf8 + j, len - i - j + 1); | 277 | memmove(utf8, utf8 + j, len - i - j + 1); |
263 | } | 278 | } |
@@ -279,137 +294,152 @@ int kbd_input(char* text, int buflen) | |||
279 | #else | 294 | #else |
280 | struct keyboard_parameters * const param = kbd_param; | 295 | struct keyboard_parameters * const param = kbd_param; |
281 | #endif | 296 | #endif |
297 | struct edit_state state; | ||
282 | int l; /* screen loop variable */ | 298 | int l; /* screen loop variable */ |
283 | int editpos; /* Edit position on all screens */ | ||
284 | unsigned short ch; | 299 | unsigned short ch; |
285 | unsigned char *utf8; | ||
286 | bool cur_blink = true; /* Cursor on/off flag */ | ||
287 | int ret = 0; /* assume success */ | 300 | int ret = 0; /* assume success */ |
288 | #ifdef HAVE_MORSE_INPUT | ||
289 | bool morse_mode = global_settings.morse_input; | ||
290 | bool morse_reading = false; | ||
291 | unsigned char morse_code = 0; | ||
292 | int morse_tick = 0; | ||
293 | #endif | ||
294 | FOR_NB_SCREENS(l) | 301 | FOR_NB_SCREENS(l) |
295 | { | 302 | { |
296 | struct keyboard_parameters *pm = ¶m[l]; | ||
297 | viewportmanager_theme_enable(l, false, NULL); | 303 | viewportmanager_theme_enable(l, false, NULL); |
298 | #if LCD_WIDTH >= 160 && LCD_HEIGHT >= 96 | ||
299 | struct screen *sc = &screens[l]; | ||
300 | |||
301 | if (sc->getwidth() >= 160 && sc->getheight() >= 96) | ||
302 | { | ||
303 | pm->default_kbd = | ||
304 | "ABCDEFG abcdefg !?\" @#$%+'\n" | ||
305 | "HIJKLMN hijklmn 789 &_()-`\n" | ||
306 | "OPQRSTU opqrstu 456 §|{}/<\n" | ||
307 | "VWXYZ., vwxyz.,0123 ~=[]*>\n" | ||
308 | "ÀÁÂÃÄÅÆ ÌÍÎÏ ÈÉÊË ¢£¤¥¦§©®\n" | ||
309 | "àáâãäåæ ìíîï èéêë «»°ºª¹²³\n" | ||
310 | "ÓÒÔÕÖØ ÇÐÞÝß ÙÚÛÜ ¯±×÷¡¿µ·\n" | ||
311 | "òóôõöø çðþýÿ ùúûü ¼½¾¬¶¨:;"; | ||
312 | |||
313 | pm->DEFAULT_LINES = 8; | ||
314 | } | ||
315 | else | ||
316 | #endif /* LCD_WIDTH >= 160 && LCD_HEIGHT >= 96 */ | ||
317 | { | ||
318 | pm->default_kbd = | ||
319 | "ABCDEFG !?\" @#$%+'\n" | ||
320 | "HIJKLMN 789 &_()-`\n" | ||
321 | "OPQRSTU 456 §|{}/<\n" | ||
322 | "VWXYZ.,0123 ~=[]*>\n" | ||
323 | |||
324 | "abcdefg ¢£¤¥¦§©®¬\n" | ||
325 | "hijklmn «»°ºª¹²³¶\n" | ||
326 | "opqrstu ¯±×÷¡¿µ·¨\n" | ||
327 | "vwxyz., :;¼½¾ \n" | ||
328 | |||
329 | "ÀÁÂÃÄÅÆ ÌÍÎÏ ÈÉÊË\n" | ||
330 | "àáâãäåæ ìíîï èéêë\n" | ||
331 | "ÓÒÔÕÖØ ÇÐÞÝß ÙÚÛÜ\n" | ||
332 | "òóôõöø çðþýÿ ùúûü"; | ||
333 | |||
334 | pm->DEFAULT_LINES = 4; | ||
335 | } | ||
336 | } | 304 | } |
337 | 305 | ||
338 | char outline[256]; | 306 | char outline[8]; |
339 | #ifdef HAVE_BUTTONBAR | 307 | #ifdef HAVE_BUTTONBAR |
340 | struct gui_buttonbar buttonbar; | 308 | struct gui_buttonbar buttonbar; |
341 | bool buttonbar_config = global_settings.buttonbar; | 309 | bool buttonbar_config = global_settings.buttonbar; |
342 | 310 | ||
343 | global_settings.buttonbar = true; | 311 | global_settings.buttonbar = true; |
344 | gui_buttonbar_init(&buttonbar); | 312 | gui_buttonbar_init(&buttonbar); |
313 | gui_buttonbar_set_display(&buttonbar, &screens[SCREEN_MAIN]); | ||
314 | #endif | ||
345 | 315 | ||
346 | FOR_NB_SCREENS(l) | 316 | /* initialize state */ |
347 | gui_buttonbar_set_display(&buttonbar, &screens[l]); | 317 | state.text = text; |
318 | state.buflen = buflen; | ||
319 | state.cur_blink = true; | ||
320 | #ifdef HAVE_MORSE_INPUT | ||
321 | state.morse_mode = global_settings.morse_input; | ||
322 | state.morse_reading = false; | ||
348 | #endif | 323 | #endif |
324 | state.hangul = false; | ||
349 | 325 | ||
350 | FOR_NB_SCREENS(l) | 326 | if (!kbd_loaded) |
351 | { | 327 | { |
352 | struct keyboard_parameters *pm = ¶m[l]; | 328 | /* Copy default keyboard to buffer */ |
353 | 329 | FOR_NB_SCREENS(l) | |
354 | if ( !kbd_loaded ) | ||
355 | { | 330 | { |
356 | /* Copy default keyboard to buffer */ | 331 | struct keyboard_parameters *pm = ¶m[l]; |
357 | const unsigned char *p = pm->default_kbd; | 332 | const unsigned char *p; |
358 | int i = 0; | 333 | int i = 0; |
359 | 334 | ||
360 | pm->curfont = FONT_SYSFIXED; | 335 | /* initialize parameters */ |
336 | pm->x = pm->y = pm->page = 0; | ||
337 | |||
338 | #if LCD_WIDTH >= 160 && LCD_HEIGHT >= 96 | ||
339 | struct screen *sc = &screens[l]; | ||
361 | 340 | ||
362 | while (*p != 0) | 341 | if (sc->getwidth() >= 160 && sc->getheight() >= 96) |
342 | { | ||
343 | p = "ABCDEFG abcdefg !?\" @#$%+'\n" | ||
344 | "HIJKLMN hijklmn 789 &_()-`\n" | ||
345 | "OPQRSTU opqrstu 456 §|{}/<\n" | ||
346 | "VWXYZ., vwxyz.,0123 ~=[]*>\n" | ||
347 | "ÀÁÂÃÄÅÆ ÌÍÎÏ ÈÉÊË ¢£¤¥¦§©®\n" | ||
348 | "àáâãäåæ ìíîï èéêë «»°ºª¹²³\n" | ||
349 | "ÓÒÔÕÖØ ÇÐÞÝß ÙÚÛÜ ¯±×÷¡¿µ·\n" | ||
350 | "òóôõöø çðþýÿ ùúûü ¼½¾¬¶¨:;"; | ||
351 | |||
352 | pm->default_lines = 8; | ||
353 | } | ||
354 | else | ||
355 | #endif /* LCD_WIDTH >= 160 && LCD_HEIGHT >= 96 */ | ||
356 | { | ||
357 | p = "ABCDEFG !?\" @#$%+'\n" | ||
358 | "HIJKLMN 789 &_()-`\n" | ||
359 | "OPQRSTU 456 §|{}/<\n" | ||
360 | "VWXYZ.,0123 ~=[]*>\n" | ||
361 | |||
362 | "abcdefg ¢£¤¥¦§©®¬\n" | ||
363 | "hijklmn «»°ºª¹²³¶\n" | ||
364 | "opqrstu ¯±×÷¡¿µ·¨\n" | ||
365 | "vwxyz., :;¼½¾ \n" | ||
366 | |||
367 | "ÀÁÂÃÄÅÆ ÌÍÎÏ ÈÉÊË\n" | ||
368 | "àáâãäåæ ìíîï èéêë\n" | ||
369 | "ÓÒÔÕÖØ ÇÐÞÝß ÙÚÛÜ\n" | ||
370 | "òóôõöø çðþýÿ ùúûü"; | ||
371 | |||
372 | pm->default_lines = 4; | ||
373 | } | ||
374 | |||
375 | while (*p) | ||
363 | p = utf8decode(p, &pm->kbd_buf[i++]); | 376 | p = utf8decode(p, &pm->kbd_buf[i++]); |
364 | 377 | ||
365 | pm->nchars = i; | 378 | pm->nchars = i; |
366 | } | 379 | } |
367 | else | 380 | kbd_loaded = true; |
368 | { | ||
369 | pm->curfont = FONT_UI; | ||
370 | } | ||
371 | } | 381 | } |
372 | 382 | ||
373 | FOR_NB_SCREENS(l) | 383 | FOR_NB_SCREENS(l) |
374 | { | 384 | { |
375 | struct keyboard_parameters *pm = ¶m[l]; | 385 | struct keyboard_parameters *pm = ¶m[l]; |
376 | struct screen *sc = &screens[l]; | 386 | struct screen *sc = &screens[l]; |
387 | struct font* font; | ||
388 | const unsigned char *p; | ||
389 | int icon_w, sc_w; | ||
377 | int i, w; | 390 | int i, w; |
378 | 391 | ||
379 | pm->font = font_get(pm->curfont); | 392 | pm->curfont = pm->default_lines ? FONT_SYSFIXED : FONT_UI; |
380 | pm->font_h = pm->font->height; | 393 | font = font_get(pm->curfont); |
394 | pm->font_h = font->height; | ||
381 | 395 | ||
382 | /* check if FONT_UI fits the screen */ | 396 | /* check if FONT_UI fits the screen */ |
383 | if (2*pm->font_h + 3 + BUTTONBAR_HEIGHT > sc->getheight()) | 397 | if (2*pm->font_h + 3 + BUTTONBAR_HEIGHT > sc->getheight()) |
384 | { | 398 | { |
385 | pm->font = font_get(FONT_SYSFIXED); | ||
386 | pm->font_h = pm->font->height; | ||
387 | pm->curfont = FONT_SYSFIXED; | 399 | pm->curfont = FONT_SYSFIXED; |
400 | font = font_get(FONT_SYSFIXED); | ||
401 | pm->font_h = font->height; | ||
388 | } | 402 | } |
389 | 403 | ||
390 | /* find max width of keyboard glyphs. | 404 | /* find max width of keyboard glyphs. |
391 | * since we're going to be adding spaces, | 405 | * since we're going to be adding spaces, |
392 | * max width is at least their width */ | 406 | * max width is at least their width */ |
393 | pm->font_w = font_get_width(pm->font, ' '); | 407 | pm->font_w = font_get_width(font, ' '); |
394 | for (i = 0; i < pm->nchars; i++) | 408 | for (i = 0; i < pm->nchars; i++) |
395 | { | 409 | { |
396 | if (pm->kbd_buf[i] != '\n') | 410 | if (pm->kbd_buf[i] != '\n') |
397 | { | 411 | { |
398 | w = font_get_width(pm->font, pm->kbd_buf[i]); | 412 | w = font_get_width(font, pm->kbd_buf[i]); |
399 | if (w > pm->font_w) | 413 | if (pm->font_w < w) |
400 | pm->font_w = w; | 414 | pm->font_w = w; |
401 | } | 415 | } |
402 | } | 416 | } |
417 | |||
418 | /* Find max width for text string */ | ||
419 | pm->text_w = pm->font_w; | ||
420 | p = state.text; | ||
421 | while (*p) | ||
422 | { | ||
423 | p = utf8decode(p, &ch); | ||
424 | w = font_get_width(font, ch); | ||
425 | if (pm->text_w < w) | ||
426 | pm->text_w = w; | ||
427 | } | ||
428 | |||
429 | /* calculate how many characters to put in a row. */ | ||
430 | icon_w = get_icon_width(l); | ||
431 | sc_w = sc->getwidth(); | ||
432 | pm->max_chars = sc_w / pm->font_w; | ||
433 | pm->max_chars_text = (sc_w - icon_w * 2 - 2) / pm->text_w; | ||
434 | if (pm->max_chars_text < 3 && icon_w > pm->text_w) | ||
435 | pm->max_chars_text = sc_w / pm->text_w - 2; | ||
403 | } | 436 | } |
404 | 437 | ||
405 | FOR_NB_SCREENS(l) | 438 | FOR_NB_SCREENS(l) |
406 | { | 439 | { |
407 | struct keyboard_parameters *pm = ¶m[l]; | 440 | struct keyboard_parameters *pm = ¶m[l]; |
408 | struct screen *sc = &screens[l]; | ||
409 | int i = 0; | 441 | int i = 0; |
410 | 442 | ||
411 | pm->max_chars = sc->getwidth() / pm->font_w; | ||
412 | |||
413 | /* Pad lines with spaces */ | 443 | /* Pad lines with spaces */ |
414 | while (i < pm->nchars) | 444 | while (i < pm->nchars) |
415 | { | 445 | { |
@@ -455,36 +485,18 @@ int kbd_input(char* text, int buflen) | |||
455 | } | 485 | } |
456 | } | 486 | } |
457 | 487 | ||
458 | /* Find max width for text string */ | 488 | /* calculate pm->pages and pm->lines */ |
459 | FOR_NB_SCREENS(l) | 489 | FOR_NB_SCREENS(l) |
460 | { | 490 | { |
461 | struct keyboard_parameters *pm = ¶m[l]; | 491 | struct keyboard_parameters *pm = ¶m[l]; |
462 | struct screen *sc = &screens[l]; | 492 | struct screen *sc = &screens[l]; |
463 | int icon_w, sc_w, sc_h; | 493 | int sc_h, total_lines; |
464 | |||
465 | pm->text_w = pm->font_w; | ||
466 | |||
467 | utf8 = text; | ||
468 | while (*utf8) | ||
469 | { | ||
470 | int w; | ||
471 | utf8 = (unsigned char*)utf8decode(utf8, &ch); | ||
472 | w = font_get_width(pm->font, ch); | ||
473 | if (w > pm->text_w) | ||
474 | pm->text_w = w; | ||
475 | } | ||
476 | 494 | ||
477 | icon_w = get_icon_width(l); | ||
478 | sc_w = sc->getwidth(); | ||
479 | sc_h = sc->getheight(); | 495 | sc_h = sc->getheight(); |
480 | pm->max_chars_text = (sc_w - icon_w * 2 - 2) / pm->text_w; | ||
481 | if(pm->max_chars_text < 3 && icon_w > pm->text_w) | ||
482 | pm->max_chars_text = sc_w / pm->text_w - 2; | ||
483 | |||
484 | pm->lines = (sc_h - BUTTONBAR_HEIGHT) / pm->font_h - 1; | 496 | pm->lines = (sc_h - BUTTONBAR_HEIGHT) / pm->font_h - 1; |
485 | 497 | ||
486 | if (!kbd_loaded && pm->lines > pm->DEFAULT_LINES) | 498 | if (pm->default_lines && pm->lines > pm->default_lines) |
487 | pm->lines = pm->DEFAULT_LINES; | 499 | pm->lines = pm->default_lines; |
488 | 500 | ||
489 | pm->keyboard_margin = sc_h - BUTTONBAR_HEIGHT | 501 | pm->keyboard_margin = sc_h - BUTTONBAR_HEIGHT |
490 | - (pm->lines+1)*pm->font_h; | 502 | - (pm->lines+1)*pm->font_h; |
@@ -498,27 +510,29 @@ int kbd_input(char* text, int buflen) | |||
498 | if (pm->keyboard_margin > DEFAULT_MARGIN) | 510 | if (pm->keyboard_margin > DEFAULT_MARGIN) |
499 | pm->keyboard_margin = DEFAULT_MARGIN; | 511 | pm->keyboard_margin = DEFAULT_MARGIN; |
500 | 512 | ||
501 | pm->pages = (pm->nchars + (pm->lines*pm->max_chars-1)) | 513 | total_lines = (pm->nchars + pm->max_chars - 1) / pm->max_chars; |
502 | / (pm->lines*pm->max_chars); | 514 | pm->pages = (total_lines + pm->lines - 1) / pm->lines; |
503 | 515 | pm->lines = (total_lines + pm->pages - 1) / pm->pages; | |
504 | if (pm->pages == 1) | ||
505 | pm->lines = (pm->nchars + pm->max_chars - 1) / pm->max_chars; | ||
506 | 516 | ||
507 | pm->main_y = pm->font_h*pm->lines + pm->keyboard_margin; | 517 | pm->main_y = pm->font_h*pm->lines + pm->keyboard_margin; |
508 | pm->keyboard_margin -= pm->keyboard_margin/2; | 518 | pm->keyboard_margin -= pm->keyboard_margin/2; |
509 | 519 | ||
510 | #ifdef HAVE_MORSE_INPUT | 520 | #ifdef HAVE_MORSE_INPUT |
511 | pm->old_main_y = pm->main_y; | 521 | pm->old_main_y = sc_h - pm->font_h - BUTTONBAR_HEIGHT; |
512 | if (morse_mode) | 522 | if (state.morse_mode) |
513 | pm->main_y = sc_h - pm->font_h - BUTTONBAR_HEIGHT; | 523 | { |
524 | int y = pm->main_y; | ||
525 | pm->main_y = pm->old_main_y; | ||
526 | pm->old_main_y = y; | ||
527 | } | ||
514 | #endif | 528 | #endif |
515 | } | 529 | } |
516 | 530 | ||
517 | /* Initial edit position is after last character */ | 531 | /* Initial edit position is after last character */ |
518 | editpos = utf8length(text); | 532 | state.editpos = utf8length(state.text); |
519 | 533 | ||
520 | if (global_settings.talk_menu) /* voice UI? */ | 534 | if (global_settings.talk_menu) /* voice UI? */ |
521 | talk_spell(text, true); /* spell initial text */ | 535 | talk_spell(state.text, true); /* spell initial text */ |
522 | 536 | ||
523 | while (!done) | 537 | while (!done) |
524 | { | 538 | { |
@@ -534,21 +548,23 @@ int kbd_input(char* text, int buflen) | |||
534 | struct keyboard_parameters *pm; | 548 | struct keyboard_parameters *pm; |
535 | struct screen *sc; | 549 | struct screen *sc; |
536 | 550 | ||
537 | int len_utf8 = utf8length(text); | 551 | state.len_utf8 = utf8length(state.text); |
538 | 552 | ||
539 | FOR_NB_SCREENS(l) | 553 | FOR_NB_SCREENS(l) |
540 | screens[l].clear_display(); | 554 | screens[l].clear_display(); |
541 | 555 | ||
542 | #ifdef HAVE_MORSE_INPUT | 556 | FOR_NB_SCREENS(l) |
543 | if (morse_mode) | ||
544 | { | 557 | { |
545 | FOR_NB_SCREENS(l) | 558 | #ifdef HAVE_MORSE_INPUT |
559 | if (state.morse_mode) | ||
546 | { | 560 | { |
547 | /* declare scoped pointers inside screen loops - hide the | 561 | /* declare scoped pointers inside screen loops - hide the |
548 | declarations from previous block level */ | 562 | declarations from previous block level */ |
549 | const int w = 6; /* sysfixed font width */ | 563 | const int w = 6, h = 8; /* sysfixed font width, height */ |
564 | struct keyboard_parameters *pm = ¶m[l]; | ||
550 | struct screen *sc = &screens[l]; | 565 | struct screen *sc = &screens[l]; |
551 | int i, x, y; | 566 | int i, x, y; |
567 | int sc_w = sc->getwidth(), sc_h = pm->main_y - pm->keyboard_margin - 1; | ||
552 | 568 | ||
553 | /* Draw morse code screen with sysfont */ | 569 | /* Draw morse code screen with sysfont */ |
554 | sc->setfont(FONT_SYSFIXED); | 570 | sc->setfont(FONT_SYSFIXED); |
@@ -559,39 +575,40 @@ int kbd_input(char* text, int buflen) | |||
559 | /* Draw morse code table with code descriptions. */ | 575 | /* Draw morse code table with code descriptions. */ |
560 | for (i = 0; morse_alphabets[i] != '\0'; i++) | 576 | for (i = 0; morse_alphabets[i] != '\0'; i++) |
561 | { | 577 | { |
562 | int morse_len; | 578 | int morse_code, j; |
563 | int j; | ||
564 | 579 | ||
565 | outline[0] = morse_alphabets[i]; | 580 | outline[0] = morse_alphabets[i]; |
566 | sc->putsxy(x, y, outline); | 581 | sc->putsxy(x, y, outline); |
567 | 582 | ||
568 | for (j = 0; (morse_codes[i] >> j) > 0x01; j++) ; | 583 | morse_code = morse_codes[i]; |
569 | morse_len = j; | 584 | for (j = 0; morse_code > 0x01; morse_code >>= 1) |
585 | j++; | ||
570 | 586 | ||
571 | x += w + 3; | 587 | x += w + 3 + j*4; |
572 | for (j = 0; j < morse_len; j++) | 588 | morse_code = morse_codes[i]; |
589 | for (; morse_code > 0x01; morse_code >>= 1) | ||
573 | { | 590 | { |
574 | if ((morse_codes[i] >> (morse_len-j-1)) & 0x01) | 591 | x -= 4; |
575 | sc->fillrect(x + j*4, y + 2, 3, 4); | 592 | if (morse_code & 0x01) |
593 | sc->fillrect(x, y + 2, 3, 4); | ||
576 | else | 594 | else |
577 | sc->fillrect(x + j*4, y + 3, 1, 2); | 595 | sc->fillrect(x, y + 3, 1, 2); |
578 | } | 596 | } |
579 | 597 | ||
580 | x += w*5 - 3; | 598 | x += w*5 - 3; |
581 | if (x + w*6 >= sc->getwidth()) | 599 | if (x + w*6 >= sc_w) |
582 | { | 600 | { |
583 | x = 0; | 601 | x = 0; |
584 | y += 8; /* sysfixed font height */ | 602 | y += h; |
603 | if (y + h >= sc_h) | ||
604 | break; | ||
585 | } | 605 | } |
586 | } | 606 | } |
587 | } | 607 | } |
588 | } | 608 | else |
589 | else | ||
590 | #endif /* HAVE_MORSE_INPUT */ | 609 | #endif /* HAVE_MORSE_INPUT */ |
591 | { | ||
592 | /* draw page */ | ||
593 | FOR_NB_SCREENS(l) | ||
594 | { | 610 | { |
611 | /* draw page */ | ||
595 | struct keyboard_parameters *pm = ¶m[l]; | 612 | struct keyboard_parameters *pm = ¶m[l]; |
596 | struct screen *sc = &screens[l]; | 613 | struct screen *sc = &screens[l]; |
597 | int i, j, k; | 614 | int i, j, k; |
@@ -600,9 +617,10 @@ int kbd_input(char* text, int buflen) | |||
600 | 617 | ||
601 | k = pm->page*pm->max_chars*pm->lines; | 618 | k = pm->page*pm->max_chars*pm->lines; |
602 | 619 | ||
603 | for (i = j = 0; j < pm->lines && k < pm->nchars; k++) | 620 | for (i = j = 0; k < pm->nchars; k++) |
604 | { | 621 | { |
605 | int w; | 622 | int w; |
623 | unsigned char *utf8; | ||
606 | utf8 = utf8encode(pm->kbd_buf[k], outline); | 624 | utf8 = utf8encode(pm->kbd_buf[k], outline); |
607 | *utf8 = 0; | 625 | *utf8 = 0; |
608 | 626 | ||
@@ -613,9 +631,21 @@ int kbd_input(char* text, int buflen) | |||
613 | if (++i >= pm->max_chars) | 631 | if (++i >= pm->max_chars) |
614 | { | 632 | { |
615 | i = 0; | 633 | i = 0; |
616 | j++; | 634 | if (++j >= pm->lines) |
635 | break; | ||
617 | } | 636 | } |
618 | } | 637 | } |
638 | |||
639 | #ifdef KBD_MODES | ||
640 | if (!pm->line_edit) | ||
641 | #endif | ||
642 | { | ||
643 | /* highlight the key that has focus */ | ||
644 | sc->set_drawmode(DRMODE_COMPLEMENT); | ||
645 | sc->fillrect(pm->font_w*pm->x, pm->font_h*pm->y, | ||
646 | pm->font_w, pm->font_h); | ||
647 | sc->set_drawmode(DRMODE_SOLID); | ||
648 | } | ||
619 | } | 649 | } |
620 | } | 650 | } |
621 | 651 | ||
@@ -623,42 +653,36 @@ int kbd_input(char* text, int buflen) | |||
623 | { | 653 | { |
624 | struct keyboard_parameters *pm = ¶m[l]; | 654 | struct keyboard_parameters *pm = ¶m[l]; |
625 | struct screen *sc = &screens[l]; | 655 | struct screen *sc = &screens[l]; |
656 | unsigned char *utf8; | ||
626 | int i = 0, j = 0, icon_w; | 657 | int i = 0, j = 0, icon_w; |
627 | int text_w = pm->text_w; | 658 | int text_w = pm->text_w; |
628 | int sc_w = sc->getwidth(); | 659 | int sc_w = sc->getwidth(); |
660 | int y = pm->main_y - pm->keyboard_margin, w; | ||
629 | int text_margin = (sc_w - text_w * pm->max_chars_text) / 2; | 661 | int text_margin = (sc_w - text_w * pm->max_chars_text) / 2; |
630 | 662 | ||
631 | /* Clear text area one pixel above separator line so any overdraw | 663 | /* Clear text area one pixel above separator line so any overdraw |
632 | doesn't collide */ | 664 | doesn't collide */ |
633 | sc->set_drawmode(DRMODE_SOLID | DRMODE_INVERSEVID); | 665 | screen_clear_area(sc, 0, y - 1, sc_w, pm->font_h + 4); |
634 | sc->fillrect(0, pm->main_y - pm->keyboard_margin - 1, | ||
635 | sc_w, pm->font_h + 4); | ||
636 | sc->set_drawmode(DRMODE_SOLID); | ||
637 | 666 | ||
638 | sc->hline(0, sc_w - 1, pm->main_y - pm->keyboard_margin); | 667 | sc->hline(0, sc_w - 1, y); |
639 | 668 | ||
640 | /* write out the text */ | 669 | /* write out the text */ |
641 | sc->setfont(pm->curfont); | 670 | sc->setfont(pm->curfont); |
642 | 671 | ||
643 | pm->curpos = MIN(editpos, pm->max_chars_text | 672 | pm->curpos = MIN(state.editpos, pm->max_chars_text |
644 | - MIN(len_utf8 - editpos, 2)); | 673 | - MIN(state.len_utf8 - state.editpos, 2)); |
645 | pm->leftpos = editpos - pm->curpos; | 674 | pm->leftpos = state.editpos - pm->curpos; |
646 | utf8 = text + utf8seek(text, pm->leftpos); | 675 | utf8 = state.text + utf8seek(state.text, pm->leftpos); |
647 | 676 | ||
648 | while (*utf8 && i < pm->max_chars_text) | 677 | while (*utf8 && i < pm->max_chars_text) |
649 | { | 678 | { |
650 | outline[j++] = *utf8++; | 679 | j = utf8seek(utf8, 1); |
651 | 680 | strlcpy(outline, utf8, j+1); | |
652 | if ((*utf8 & MASK) != COMP) | 681 | sc->getstringsize(outline, &w, NULL); |
653 | { | 682 | sc->putsxy(text_margin + i*text_w + (text_w-w)/2, |
654 | int w; | 683 | pm->main_y, outline); |
655 | outline[j] = 0; | 684 | utf8 += j; |
656 | j = 0; | 685 | i++; |
657 | sc->getstringsize(outline, &w, NULL); | ||
658 | sc->putsxy(text_margin + i*text_w + (text_w-w)/2, | ||
659 | pm->main_y, outline); | ||
660 | i++; | ||
661 | } | ||
662 | } | 686 | } |
663 | 687 | ||
664 | icon_w = get_icon_width(l); | 688 | icon_w = get_icon_width(l); |
@@ -673,13 +697,12 @@ int kbd_input(char* text, int buflen) | |||
673 | } | 697 | } |
674 | else | 698 | else |
675 | { | 699 | { |
676 | int w; | ||
677 | sc->getstringsize("<", &w, NULL); | 700 | sc->getstringsize("<", &w, NULL); |
678 | sc->putsxy(text_margin - w, pm->main_y, "<"); | 701 | sc->putsxy(text_margin - w, pm->main_y, "<"); |
679 | } | 702 | } |
680 | } | 703 | } |
681 | 704 | ||
682 | if (len_utf8 - pm->leftpos > pm->max_chars_text) | 705 | if (state.len_utf8 - pm->leftpos > pm->max_chars_text) |
683 | { | 706 | { |
684 | /* Draw nicer bitmap arrow if room, else settle for ">". */ | 707 | /* Draw nicer bitmap arrow if room, else settle for ">". */ |
685 | if (text_margin >= icon_w) | 708 | if (text_margin >= icon_w) |
@@ -697,14 +720,23 @@ int kbd_input(char* text, int buflen) | |||
697 | /* cursor */ | 720 | /* cursor */ |
698 | i = text_margin + pm->curpos * text_w; | 721 | i = text_margin + pm->curpos * text_w; |
699 | 722 | ||
700 | if (cur_blink) | 723 | if (state.cur_blink) |
701 | sc->vline(i, pm->main_y, pm->main_y + pm->font_h - 1); | 724 | sc->vline(i, pm->main_y, pm->main_y + pm->font_h - 1); |
702 | 725 | ||
703 | if (pm->hangul) /* draw underbar */ | 726 | if (state.hangul) /* draw underbar */ |
704 | sc->hline(i - text_w, i, pm->main_y + pm->font_h - 1); | 727 | sc->hline(i - text_w, i, pm->main_y + pm->font_h - 1); |
728 | |||
729 | #ifdef KBD_MODES | ||
730 | if (pm->line_edit) | ||
731 | { | ||
732 | sc->set_drawmode(DRMODE_COMPLEMENT); | ||
733 | sc->fillrect(0, y + 2, sc_w, pm->font_h + 2); | ||
734 | sc->set_drawmode(DRMODE_SOLID); | ||
735 | } | ||
736 | #endif | ||
705 | } | 737 | } |
706 | 738 | ||
707 | cur_blink = !cur_blink; | 739 | state.cur_blink = !state.cur_blink; |
708 | 740 | ||
709 | #ifdef HAVE_BUTTONBAR | 741 | #ifdef HAVE_BUTTONBAR |
710 | /* draw the button bar */ | 742 | /* draw the button bar */ |
@@ -713,31 +745,11 @@ int kbd_input(char* text, int buflen) | |||
713 | #endif | 745 | #endif |
714 | 746 | ||
715 | FOR_NB_SCREENS(l) | 747 | FOR_NB_SCREENS(l) |
716 | { | ||
717 | struct keyboard_parameters *pm = ¶m[l]; | ||
718 | struct screen *sc = &screens[l]; | ||
719 | |||
720 | sc->set_drawmode(DRMODE_COMPLEMENT); | ||
721 | #ifdef KBD_MODES | ||
722 | if (pm->line_edit) | ||
723 | sc->fillrect(0, pm->main_y - pm->keyboard_margin + 2, | ||
724 | sc->getwidth(), pm->font_h + 2); | ||
725 | else /* highlight the key that has focus */ | ||
726 | #endif | ||
727 | #ifdef HAVE_MORSE_INPUT | ||
728 | if(!morse_mode) | ||
729 | #endif | ||
730 | sc->fillrect(pm->font_w*pm->x, pm->font_h*pm->y, | ||
731 | pm->font_w, pm->font_h); | ||
732 | sc->set_drawmode(DRMODE_SOLID); | ||
733 | } | ||
734 | |||
735 | FOR_NB_SCREENS(l) | ||
736 | screens[l].update(); | 748 | screens[l].update(); |
737 | 749 | ||
738 | button = get_action( | 750 | button = get_action( |
739 | #ifdef HAVE_MORSE_INPUT | 751 | #ifdef HAVE_MORSE_INPUT |
740 | morse_mode? CONTEXT_MORSE_INPUT: | 752 | state.morse_mode? CONTEXT_MORSE_INPUT: |
741 | #endif | 753 | #endif |
742 | CONTEXT_KEYBOARD, HZ/2); | 754 | CONTEXT_KEYBOARD, HZ/2); |
743 | #if NB_SCREENS > 1 | 755 | #if NB_SCREENS > 1 |
@@ -750,11 +762,11 @@ int kbd_input(char* text, int buflen) | |||
750 | /* Remap some buttons to allow to move | 762 | /* Remap some buttons to allow to move |
751 | * cursor in line edit mode and morse mode. */ | 763 | * cursor in line edit mode and morse mode. */ |
752 | #if defined(KBD_MODES) && defined(HAVE_MORSE_INPUT) | 764 | #if defined(KBD_MODES) && defined(HAVE_MORSE_INPUT) |
753 | if (pm->line_edit || morse_mode) | 765 | if (pm->line_edit || state.morse_mode) |
754 | #elif defined(KBD_MODES) | 766 | #elif defined(KBD_MODES) |
755 | if (pm->line_edit) | 767 | if (pm->line_edit) |
756 | #else /* defined(HAVE_MORSE_INPUT) */ | 768 | #else /* defined(HAVE_MORSE_INPUT) */ |
757 | if (morse_mode) | 769 | if (state.morse_mode) |
758 | #endif | 770 | #endif |
759 | { | 771 | { |
760 | if (button == ACTION_KBD_LEFT) | 772 | if (button == ACTION_KBD_LEFT) |
@@ -784,7 +796,7 @@ int kbd_input(char* text, int buflen) | |||
784 | 796 | ||
785 | case ACTION_KBD_PAGE_FLIP: | 797 | case ACTION_KBD_PAGE_FLIP: |
786 | #ifdef HAVE_MORSE_INPUT | 798 | #ifdef HAVE_MORSE_INPUT |
787 | if (morse_mode) | 799 | if (state.morse_mode) |
788 | break; | 800 | break; |
789 | #endif | 801 | #endif |
790 | if (++pm->page >= pm->pages) | 802 | if (++pm->page >= pm->pages) |
@@ -796,17 +808,14 @@ int kbd_input(char* text, int buflen) | |||
796 | 808 | ||
797 | #if defined(HAVE_MORSE_INPUT) && defined(KBD_TOGGLE_INPUT) | 809 | #if defined(HAVE_MORSE_INPUT) && defined(KBD_TOGGLE_INPUT) |
798 | case ACTION_KBD_MORSE_INPUT: | 810 | case ACTION_KBD_MORSE_INPUT: |
799 | morse_mode = !morse_mode; | 811 | state.morse_mode = !state.morse_mode; |
800 | 812 | ||
801 | FOR_NB_SCREENS(l) | 813 | FOR_NB_SCREENS(l) |
802 | { | 814 | { |
803 | struct keyboard_parameters *pm = ¶m[l]; | 815 | struct keyboard_parameters *pm = ¶m[l]; |
804 | struct screen *sc = &screens[l]; | 816 | int y = pm->main_y; |
805 | 817 | pm->main_y = pm->old_main_y; | |
806 | if (morse_mode) | 818 | pm->old_main_y = y; |
807 | pm->main_y = sc->getheight() - pm->font_h - BUTTONBAR_HEIGHT; | ||
808 | else | ||
809 | pm->main_y = pm->old_main_y; | ||
810 | } | 819 | } |
811 | /* FIXME: We should talk something like Morse mode.. */ | 820 | /* FIXME: We should talk something like Morse mode.. */ |
812 | break; | 821 | break; |
@@ -844,11 +853,11 @@ int kbd_input(char* text, int buflen) | |||
844 | 853 | ||
845 | case ACTION_KBD_DOWN: | 854 | case ACTION_KBD_DOWN: |
846 | #ifdef HAVE_MORSE_INPUT | 855 | #ifdef HAVE_MORSE_INPUT |
847 | if (morse_mode) | 856 | if (state.morse_mode) |
848 | { | 857 | { |
849 | #ifdef KBD_MODES | 858 | #ifdef KBD_MODES |
850 | pm->line_edit = !pm->line_edit; | 859 | pm->line_edit = !pm->line_edit; |
851 | if(pm->line_edit) | 860 | if (pm->line_edit) |
852 | say_edit(); | 861 | say_edit(); |
853 | #endif | 862 | #endif |
854 | break; | 863 | break; |
@@ -880,11 +889,11 @@ int kbd_input(char* text, int buflen) | |||
880 | 889 | ||
881 | case ACTION_KBD_UP: | 890 | case ACTION_KBD_UP: |
882 | #ifdef HAVE_MORSE_INPUT | 891 | #ifdef HAVE_MORSE_INPUT |
883 | if (morse_mode) | 892 | if (state.morse_mode) |
884 | { | 893 | { |
885 | #ifdef KBD_MODES | 894 | #ifdef KBD_MODES |
886 | pm->line_edit = !pm->line_edit; | 895 | pm->line_edit = !pm->line_edit; |
887 | if(pm->line_edit) | 896 | if (pm->line_edit) |
888 | say_edit(); | 897 | say_edit(); |
889 | #endif | 898 | #endif |
890 | break; | 899 | break; |
@@ -916,25 +925,25 @@ int kbd_input(char* text, int buflen) | |||
916 | 925 | ||
917 | #ifdef HAVE_MORSE_INPUT | 926 | #ifdef HAVE_MORSE_INPUT |
918 | case ACTION_KBD_MORSE_SELECT: | 927 | case ACTION_KBD_MORSE_SELECT: |
919 | if (morse_mode && morse_reading) | 928 | if (state.morse_mode && state.morse_reading) |
920 | { | 929 | { |
921 | morse_code <<= 1; | 930 | state.morse_code <<= 1; |
922 | if ((current_tick - morse_tick) > HZ/5) | 931 | if ((current_tick - state.morse_tick) > HZ/5) |
923 | morse_code |= 0x01; | 932 | state.morse_code |= 0x01; |
924 | } | 933 | } |
925 | break; | 934 | break; |
926 | #endif /* HAVE_MORSE_INPUT */ | 935 | #endif /* HAVE_MORSE_INPUT */ |
927 | 936 | ||
928 | case ACTION_KBD_SELECT: | 937 | case ACTION_KBD_SELECT: |
929 | #ifdef HAVE_MORSE_INPUT | 938 | #ifdef HAVE_MORSE_INPUT |
930 | if (morse_mode) | 939 | if (state.morse_mode) |
931 | { | 940 | { |
932 | morse_tick = current_tick; | 941 | state.morse_tick = current_tick; |
933 | 942 | ||
934 | if (!morse_reading) | 943 | if (!state.morse_reading) |
935 | { | 944 | { |
936 | morse_reading = true; | 945 | state.morse_reading = true; |
937 | morse_code = 1; | 946 | state.morse_code = 1; |
938 | } | 947 | } |
939 | } | 948 | } |
940 | else | 949 | else |
@@ -949,103 +958,104 @@ int kbd_input(char* text, int buflen) | |||
949 | { | 958 | { |
950 | unsigned short tmp; | 959 | unsigned short tmp; |
951 | 960 | ||
952 | if (!pm->hangul) | 961 | if (!state.hangul) |
953 | { | 962 | { |
954 | pm->hlead = pm->hvowel = pm->htail = 0; | 963 | state.hlead = state.hvowel = state.htail = 0; |
955 | pm->hangul = true; | 964 | state.hangul = true; |
956 | } | 965 | } |
957 | 966 | ||
958 | if (!pm->hvowel) | 967 | if (!state.hvowel) |
959 | { | 968 | { |
960 | pm->hvowel = ch; | 969 | state.hvowel = ch; |
961 | } | 970 | } |
962 | else if (!pm->htail) | 971 | else if (!state.htail) |
963 | { | 972 | { |
964 | pm->htail = ch; | 973 | state.htail = ch; |
965 | } | 974 | } |
966 | else | 975 | else |
967 | { /* previous hangul complete */ | 976 | { |
977 | /* previous hangul complete */ | ||
968 | /* check whether tail is actually lead of next char */ | 978 | /* check whether tail is actually lead of next char */ |
969 | tmp = hangul_join(pm->htail, ch, 0); | 979 | tmp = hangul_join(state.htail, ch, 0); |
970 | 980 | ||
971 | if (tmp != 0xfffd) | 981 | if (tmp != 0xfffd) |
972 | { | 982 | { |
973 | tmp = hangul_join(pm->hlead, pm->hvowel, 0); | 983 | tmp = hangul_join(state.hlead, state.hvowel, 0); |
974 | kbd_delchar(text, &editpos); | 984 | kbd_delchar(&state); |
975 | kbd_inschar(text, buflen, &editpos, tmp); | 985 | kbd_inschar(&state, tmp); |
976 | /* insert dummy char */ | 986 | /* insert dummy char */ |
977 | kbd_inschar(text, buflen, &editpos, ' '); | 987 | kbd_inschar(&state, ' '); |
978 | pm->hlead = pm->htail; | 988 | state.hlead = state.htail; |
979 | pm->hvowel = ch; | 989 | state.hvowel = ch; |
980 | pm->htail = 0; | 990 | state.htail = 0; |
981 | } | 991 | } |
982 | else | 992 | else |
983 | { | 993 | { |
984 | pm->hvowel = pm->htail = 0; | 994 | state.hvowel = state.htail = 0; |
985 | pm->hlead = ch; | 995 | state.hlead = ch; |
986 | } | 996 | } |
987 | } | 997 | } |
988 | 998 | ||
989 | /* combine into hangul */ | 999 | /* combine into hangul */ |
990 | tmp = hangul_join(pm->hlead, pm->hvowel, pm->htail); | 1000 | tmp = hangul_join(state.hlead, state.hvowel, state.htail); |
991 | 1001 | ||
992 | if (tmp != 0xfffd) | 1002 | if (tmp != 0xfffd) |
993 | { | 1003 | { |
994 | kbd_delchar(text, &editpos); | 1004 | kbd_delchar(&state); |
995 | ch = tmp; | 1005 | ch = tmp; |
996 | } | 1006 | } |
997 | else | 1007 | else |
998 | { | 1008 | { |
999 | pm->hvowel = pm->htail = 0; | 1009 | state.hvowel = state.htail = 0; |
1000 | pm->hlead = ch; | 1010 | state.hlead = ch; |
1001 | } | 1011 | } |
1002 | } | 1012 | } |
1003 | else | 1013 | else |
1004 | { | 1014 | { |
1005 | pm->hangul = false; | 1015 | state.hangul = false; |
1006 | } | 1016 | } |
1007 | 1017 | ||
1008 | /* insert char */ | 1018 | /* insert char */ |
1009 | kbd_inschar(text, buflen, &editpos, ch); | 1019 | kbd_inschar(&state, ch); |
1010 | 1020 | ||
1011 | if (global_settings.talk_menu) /* voice UI? */ | 1021 | if (global_settings.talk_menu) /* voice UI? */ |
1012 | talk_spell(text, false); /* speak revised text */ | 1022 | talk_spell(state.text, false); /* speak revised text */ |
1013 | } | 1023 | } |
1014 | break; | 1024 | break; |
1015 | 1025 | ||
1016 | case ACTION_KBD_BACKSPACE: | 1026 | case ACTION_KBD_BACKSPACE: |
1017 | if (pm->hangul) | 1027 | if (state.hangul) |
1018 | { | 1028 | { |
1019 | if (pm->htail) | 1029 | if (state.htail) |
1020 | pm->htail = 0; | 1030 | state.htail = 0; |
1021 | else if (pm->hvowel) | 1031 | else if (state.hvowel) |
1022 | pm->hvowel = 0; | 1032 | state.hvowel = 0; |
1023 | else | 1033 | else |
1024 | pm->hangul = false; | 1034 | state.hangul = false; |
1025 | } | 1035 | } |
1026 | 1036 | ||
1027 | kbd_delchar(text, &editpos); | 1037 | kbd_delchar(&state); |
1028 | 1038 | ||
1029 | if (pm->hangul) | 1039 | if (state.hangul) |
1030 | { | 1040 | { |
1031 | if (pm->hvowel) | 1041 | if (state.hvowel) |
1032 | ch = hangul_join(pm->hlead, pm->hvowel, pm->htail); | 1042 | ch = hangul_join(state.hlead, state.hvowel, state.htail); |
1033 | else | 1043 | else |
1034 | ch = pm->hlead; | 1044 | ch = state.hlead; |
1035 | kbd_inschar(text, buflen, &editpos, ch); | 1045 | kbd_inschar(&state, ch); |
1036 | } | 1046 | } |
1037 | 1047 | ||
1038 | if (global_settings.talk_menu) /* voice UI? */ | 1048 | if (global_settings.talk_menu) /* voice UI? */ |
1039 | talk_spell(text, false); /* speak revised text */ | 1049 | talk_spell(state.text, false); /* speak revised text */ |
1040 | break; | 1050 | break; |
1041 | 1051 | ||
1042 | case ACTION_KBD_CURSOR_RIGHT: | 1052 | case ACTION_KBD_CURSOR_RIGHT: |
1043 | pm->hangul = false; | 1053 | state.hangul = false; |
1044 | 1054 | ||
1045 | if (editpos < len_utf8) | 1055 | if (state.editpos < state.len_utf8) |
1046 | { | 1056 | { |
1047 | int c = utf8seek(text, ++editpos); | 1057 | int c = utf8seek(state.text, ++state.editpos); |
1048 | kbd_spellchar(text[c]); | 1058 | kbd_spellchar(state.text[c]); |
1049 | } | 1059 | } |
1050 | #if CONFIG_CODEC == SWCODEC | 1060 | #if CONFIG_CODEC == SWCODEC |
1051 | else if (global_settings.talk_menu) | 1061 | else if (global_settings.talk_menu) |
@@ -1054,12 +1064,12 @@ int kbd_input(char* text, int buflen) | |||
1054 | break; | 1064 | break; |
1055 | 1065 | ||
1056 | case ACTION_KBD_CURSOR_LEFT: | 1066 | case ACTION_KBD_CURSOR_LEFT: |
1057 | pm->hangul = false; | 1067 | state.hangul = false; |
1058 | 1068 | ||
1059 | if (editpos > 0) | 1069 | if (state.editpos > 0) |
1060 | { | 1070 | { |
1061 | int c = utf8seek(text, --editpos); | 1071 | int c = utf8seek(state.text, --state.editpos); |
1062 | kbd_spellchar(text[c]); | 1072 | kbd_spellchar(state.text[c]); |
1063 | } | 1073 | } |
1064 | #if CONFIG_CODEC == SWCODEC | 1074 | #if CONFIG_CODEC == SWCODEC |
1065 | else if (global_settings.talk_menu) | 1075 | else if (global_settings.talk_menu) |
@@ -1067,17 +1077,17 @@ int kbd_input(char* text, int buflen) | |||
1067 | #endif | 1077 | #endif |
1068 | break; | 1078 | break; |
1069 | 1079 | ||
1070 | case BUTTON_NONE: | 1080 | case ACTION_NONE: |
1071 | #ifdef HAVE_MORSE_INPUT | 1081 | #ifdef HAVE_MORSE_INPUT |
1072 | if (morse_reading) | 1082 | if (state.morse_reading) |
1073 | { | 1083 | { |
1074 | int j; | 1084 | int j; |
1075 | logf("Morse: 0x%02x", morse_code); | 1085 | logf("Morse: 0x%02x", state.morse_code); |
1076 | morse_reading = false; | 1086 | state.morse_reading = false; |
1077 | 1087 | ||
1078 | for (j = 0; morse_alphabets[j] != '\0'; j++) | 1088 | for (j = 0; morse_alphabets[j] != '\0'; j++) |
1079 | { | 1089 | { |
1080 | if (morse_codes[j] == morse_code) | 1090 | if (morse_codes[j] == state.morse_code) |
1081 | break ; | 1091 | break ; |
1082 | } | 1092 | } |
1083 | 1093 | ||
@@ -1088,12 +1098,11 @@ int kbd_input(char* text, int buflen) | |||
1088 | } | 1098 | } |
1089 | 1099 | ||
1090 | /* turn off hangul input */ | 1100 | /* turn off hangul input */ |
1091 | FOR_NB_SCREENS(l) | 1101 | state.hangul = false; |
1092 | param[l].hangul = false; | 1102 | kbd_inschar(&state, morse_alphabets[j]); |
1093 | kbd_inschar(text, buflen, &editpos, morse_alphabets[j]); | ||
1094 | 1103 | ||
1095 | if (global_settings.talk_menu) /* voice UI? */ | 1104 | if (global_settings.talk_menu) /* voice UI? */ |
1096 | talk_spell(text, false); /* speak revised text */ | 1105 | talk_spell(state.text, false); /* speak revised text */ |
1097 | } | 1106 | } |
1098 | #endif /* HAVE_MORSE_INPUT */ | 1107 | #endif /* HAVE_MORSE_INPUT */ |
1099 | break; | 1108 | break; |
@@ -1108,9 +1117,9 @@ int kbd_input(char* text, int buflen) | |||
1108 | 1117 | ||
1109 | } /* end switch */ | 1118 | } /* end switch */ |
1110 | 1119 | ||
1111 | if (button != BUTTON_NONE) | 1120 | if (button != ACTION_NONE) |
1112 | { | 1121 | { |
1113 | cur_blink = true; | 1122 | state.cur_blink = true; |
1114 | } | 1123 | } |
1115 | } | 1124 | } |
1116 | 1125 | ||
@@ -1122,9 +1131,9 @@ int kbd_input(char* text, int buflen) | |||
1122 | splash(HZ/2, ID2P(LANG_CANCEL)); | 1131 | splash(HZ/2, ID2P(LANG_CANCEL)); |
1123 | 1132 | ||
1124 | #if defined(HAVE_MORSE_INPUT) && defined(KBD_TOGGLE_INPUT) | 1133 | #if defined(HAVE_MORSE_INPUT) && defined(KBD_TOGGLE_INPUT) |
1125 | if(global_settings.morse_input != morse_mode) | 1134 | if (global_settings.morse_input != state.morse_mode) |
1126 | { | 1135 | { |
1127 | global_settings.morse_input = morse_mode; | 1136 | global_settings.morse_input = state.morse_mode; |
1128 | settings_save(); | 1137 | settings_save(); |
1129 | } | 1138 | } |
1130 | #endif /* HAVE_MORSE_INPUT && KBD_TOGGLE_INPUT */ | 1139 | #endif /* HAVE_MORSE_INPUT && KBD_TOGGLE_INPUT */ |
@@ -1133,6 +1142,6 @@ int kbd_input(char* text, int buflen) | |||
1133 | { | 1142 | { |
1134 | screens[l].setfont(FONT_UI); | 1143 | screens[l].setfont(FONT_UI); |
1135 | viewportmanager_theme_undo(l, false); | 1144 | viewportmanager_theme_undo(l, false); |
1136 | } | 1145 | } |
1137 | return ret; | 1146 | return ret; |
1138 | } | 1147 | } |