7 #if CONFIG_KEYPAD == RECORDER_PAD
8 #define BUTTONBAR_HEIGHT 8
10 #define BUTTONBAR_HEIGHT 0
13 #define DEFAULT_MARGIN 6
14 #define KBD_BUF_SIZE 500
15 #define kbd_loaded false
16 #define statusbar_size 0
18 #if (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
19 (CONFIG_KEYPAD == IRIVER_H300_PAD)
20 #define KBD_SELECT BUTTON_SELECT
21 #define KBD_ABORT BUTTON_OFF
22 #define KBD_LEFT BUTTON_LEFT
23 #define KBD_RIGHT BUTTON_RIGHT
24 #define KBD_UP BUTTON_UP
25 #define KBD_DOWN BUTTON_DOWN
27 #elif CONFIG_KEYPAD == RECORDER_PAD
28 #define KBD_SELECT BUTTON_PLAY
29 #define KBD_ABORT BUTTON_OFF
30 #define KBD_LEFT BUTTON_LEFT
31 #define KBD_RIGHT BUTTON_RIGHT
32 #define KBD_UP BUTTON_UP
33 #define KBD_DOWN BUTTON_DOWN
35 #elif CONFIG_KEYPAD == ARCHOS_AV300_PAD
36 #define KBD_SELECT BUTTON_SELECT
37 #define KBD_ABORT BUTTON_OFF
38 #define KBD_LEFT BUTTON_LEFT
39 #define KBD_RIGHT BUTTON_RIGHT
40 #define KBD_UP BUTTON_UP
41 #define KBD_DOWN BUTTON_DOWN
43 #elif CONFIG_KEYPAD == ONDIO_PAD /* restricted Ondio keypad */
44 #define KBD_SELECT BUTTON_MENU
45 #define KBD_ABORT BUTTON_OFF
46 #define KBD_LEFT BUTTON_LEFT
47 #define KBD_RIGHT BUTTON_RIGHT
48 #define KBD_UP BUTTON_UP
49 #define KBD_DOWN BUTTON_DOWN
51 #elif (CONFIG_KEYPAD == IPOD_4G_PAD) || \
52 (CONFIG_KEYPAD == IPOD_3G_PAD) || \
53 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
55 #define KBD_SELECT BUTTON_SELECT
56 #define KBD_ABORT BUTTON_MENU
57 #define KBD_LEFT BUTTON_LEFT
58 #define KBD_RIGHT BUTTON_RIGHT
59 #define KBD_UP BUTTON_SCROLL_BACK
60 #define KBD_DOWN BUTTON_SCROLL_FWD
62 #elif CONFIG_KEYPAD == IRIVER_IFP7XX_PAD
64 /* TODO: Check keyboard mappings */
66 #define KBD_SELECT BUTTON_SELECT
67 #define KBD_ABORT BUTTON_PLAY
68 #define KBD_LEFT BUTTON_LEFT
69 #define KBD_RIGHT BUTTON_RIGHT
70 #define KBD_UP BUTTON_UP
71 #define KBD_DOWN BUTTON_DOWN
73 #elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD
75 /* TODO: Check keyboard mappings */
77 #define KBD_SELECT BUTTON_SELECT
78 #define KBD_ABORT BUTTON_REC
79 #define KBD_LEFT BUTTON_LEFT
80 #define KBD_RIGHT BUTTON_RIGHT
81 #define KBD_UP BUTTON_UP
82 #define KBD_DOWN BUTTON_DOWN
84 #elif CONFIG_KEYPAD == GIGABEAT_PAD
86 #define KBD_SELECT BUTTON_SELECT
87 #define KBD_ABORT BUTTON_POWER
88 #define KBD_LEFT BUTTON_LEFT
89 #define KBD_RIGHT BUTTON_RIGHT
90 #define KBD_UP BUTTON_UP
91 #define KBD_DOWN BUTTON_DOWN
93 #elif CONFIG_KEYPAD == GIGABEAT_S_PAD
95 #define KBD_SELECT BUTTON_SELECT
96 #define KBD_ABORT BUTTON_POWER
97 #define KBD_LEFT BUTTON_LEFT
98 #define KBD_RIGHT BUTTON_RIGHT
99 #define KBD_UP BUTTON_UP
100 #define KBD_DOWN BUTTON_DOWN
102 #elif CONFIG_KEYPAD == IRIVER_H10_PAD
104 /* TODO: Check keyboard mappings */
106 #define KBD_SELECT BUTTON_REW
107 #define KBD_ABORT BUTTON_FF
108 #define KBD_LEFT BUTTON_LEFT
109 #define KBD_RIGHT BUTTON_RIGHT
110 #define KBD_UP BUTTON_SCROLL_UP
111 #define KBD_DOWN BUTTON_SCROLL_DOWN
113 #elif (CONFIG_KEYPAD == SANSA_E200_PAD) || \
114 (CONFIG_KEYPAD == SANSA_C200_PAD) || \
115 (CONFIG_KEYPAD == SANSA_CLIP_PAD) || \
116 (CONFIG_KEYPAD == SANSA_M200_PAD) || \
117 (CONFIG_KEYPAD == SANSA_FUZE_PAD) || \
118 (CONFIG_KEYPAD == MROBE100_PAD)
120 /* TODO: Check keyboard mappings */
122 #define KBD_SELECT BUTTON_SELECT
123 #define KBD_ABORT BUTTON_POWER
124 #define KBD_LEFT BUTTON_LEFT
125 #define KBD_RIGHT BUTTON_RIGHT
126 #define KBD_UP BUTTON_UP
127 #define KBD_DOWN BUTTON_DOWN
129 #elif CONFIG_KEYPAD == IAUDIO_M3_PAD
131 #define KBD_SELECT BUTTON_RC_PLAY
132 #define KBD_ABORT BUTTON_RC_REC
133 #define KBD_LEFT BUTTON_RC_REW
134 #define KBD_RIGHT BUTTON_RC_FF
135 #define KBD_UP BUTTON_RC_VOL_UP
136 #define KBD_DOWN BUTTON_RC_VOL_DOWN
138 #elif CONFIG_KEYPAD == COWON_D2_PAD
140 #define KBD_ABORT BUTTON_POWER
142 #elif CONFIG_KEYPAD == IAUDIO67_PAD
144 #define KBD_SELECT BUTTON_MENU
145 #define KBD_ABORT BUTTON_POWER
146 #define KBD_LEFT BUTTON_LEFT
147 #define KBD_RIGHT BUTTON_RIGHT
148 #define KBD_UP BUTTON_STOP
149 #define KBD_DOWN BUTTON_PLAY
151 #elif CONFIG_KEYPAD == CREATIVEZVM_PAD
153 #define KBD_SELECT BUTTON_SELECT
154 #define KBD_ABORT BUTTON_BACK
155 #define KBD_LEFT BUTTON_LEFT
156 #define KBD_RIGHT BUTTON_RIGHT
157 #define KBD_UP BUTTON_UP
158 #define KBD_DOWN BUTTON_DOWN
160 #elif CONFIG_KEYPAD == PHILIPS_HDD1630_PAD
162 #define KBD_SELECT BUTTON_MENU
163 #define KBD_ABORT BUTTON_POWER
164 #define KBD_LEFT BUTTON_LEFT
165 #define KBD_RIGHT BUTTON_RIGHT
166 #define KBD_UP BUTTON_UP
167 #define KBD_DOWN BUTTON_DOWN
169 #elif CONFIG_KEYPAD == SAMSUNG_YH_PAD
171 #define KBD_SELECT BUTTON_PLAY
172 #define KBD_ABORT BUTTON_REW
173 #define KBD_LEFT BUTTON_LEFT
174 #define KBD_RIGHT BUTTON_RIGHT
175 #define KBD_UP BUTTON_UP
176 #define KBD_DOWN BUTTON_DOWN
178 #elif CONFIG_KEYPAD == PBELL_VIBE500_PAD
180 #define KBD_SELECT BUTTON_OK
181 #define KBD_ABORT BUTTON_CANCEL
182 #define KBD_LEFT BUTTON_PREV
183 #define KBD_RIGHT BUTTON_NEXT
184 #define KBD_UP BUTTON_UP
185 #define KBD_DOWN BUTTON_DOWN
187 #elif CONFIG_KEYPAD == MPIO_HD200_PAD
189 #define KBD_SELECT BUTTON_FUNC
190 #define KBD_ABORT BUTTON_REC
191 #define KBD_LEFT BUTTON_VOL_DOWN
192 #define KBD_RIGHT BUTTON_VOL_UP
193 #define KBD_UP BUTTON_REW
194 #define KBD_DOWN BUTTON_FF
198 #ifdef HAVE_TOUCHSCREEN
200 #define KBD_SELECT BUTTON_CENTER
203 #define KBD_ABORT BUTTON_TOPLEFT
206 #define KBD_LEFT BUTTON_MIDLEFT
209 #define KBD_RIGHT BUTTON_MIDRIGHT
212 #define KBD_UP BUTTON_TOPMIDDLE
215 #define KBD_DOWN BUTTON_BOTTOMMIDDLE
219 struct keyboard_parameters
{
220 const unsigned char* default_kbd
;
222 unsigned short kbd_buf
[KBD_BUF_SIZE
];
243 struct keyboard_parameters param
[NB_SCREENS
];
245 int zx_kbd_input(char* text
/*, int buflen*/)
250 int len_utf8
/*, c = 0*/;
252 /* int statusbar_size = global_settings.statusbar ? STATUSBAR_HEIGHT : 0;*/
253 unsigned short ch
/*, tmp, hlead = 0, hvowel = 0, htail = 0*/;
254 /*bool hangul = false;*/
256 const unsigned char *p
;
257 bool cur_blink
= true;
262 param
[l
].default_kbd
=
270 param
[l
].DEFAULT_LINES
= 7;
274 int button
, lastbutton
= 0;
277 /* Copy default keyboard to buffer */
279 param
[l
].curfont
= FONT_SYSFIXED
;
280 p
= param
[l
].default_kbd
;
282 p
= rb
->utf8decode(p
, ¶m
[l
].kbd_buf
[i
++]);
284 /* param[l].curfont = FONT_UI;*/
288 param
[l
].font
= rb
->font_get(param
[l
].curfont
);
289 param
[l
].font_h
= param
[l
].font
->height
;
291 /* check if FONT_UI fits the screen */
292 if (2*param
[l
].font_h
+3 + BUTTONBAR_HEIGHT
>
293 rb
->screens
[l
]->getheight()) {
294 param
[l
].font
= rb
->font_get(FONT_SYSFIXED
);
295 param
[l
].font_h
= param
[l
].font
->height
;
296 param
[l
].curfont
= FONT_SYSFIXED
;
299 rb
->screens
[l
]->setfont(param
[l
].curfont
);
300 /* find max width of keyboard glyphs */
301 for (i
=0; i
<param
[l
].nchars
; i
++) {
302 w
= rb
->font_get_width(param
[l
].font
, param
[l
].kbd_buf
[i
]);
303 if (w
> param
[l
].font_w
)
306 /* Since we're going to be adding spaces, make sure that we check
308 w
= rb
->font_get_width( param
[l
].font
, ' ' );
309 if( w
> param
[l
].font_w
)
315 /* Pad lines with spaces */
316 while( i
< param
[l
].nchars
)
318 if( param
[l
].kbd_buf
[i
] == '\n' )
320 k
= ( rb
->screens
[l
]->getwidth() / param
[l
].font_w
) -
321 i
% ( rb
->screens
[l
]->getwidth() / param
[l
].font_w
) - 1;
322 if( k
== ( rb
->screens
[l
]->getwidth() / param
[l
].font_w
) - 1 )
325 for( j
= i
; j
< param
[l
].nchars
; j
++ )
327 param
[l
].kbd_buf
[j
] = param
[l
].kbd_buf
[j
+1];
332 if( param
[l
].nchars
+ k
- 1 >= KBD_BUF_SIZE
)
333 { /* We don't want to overflow the buffer */
334 k
= KBD_BUF_SIZE
- param
[l
].nchars
;
336 for( j
= param
[l
].nchars
+ k
- 1; j
> i
+k
; j
-- )
338 param
[l
].kbd_buf
[j
] = param
[l
].kbd_buf
[j
-k
];
340 param
[l
].nchars
+= k
;
344 param
[l
].kbd_buf
[i
++] = ' ';
353 /* find max width for text string */
357 text_w
= param
[l
].font_w
;
359 utf8
= (unsigned char*)rb
->utf8decode(utf8
, &ch
);
360 w
= rb
->font_get_width(param
[l
].font
, ch
);
364 param
[l
].max_chars_text
= rb
->screens
[l
]->getwidth() / text_w
- 2;
366 /* calculate keyboard grid size */
367 param
[l
].max_chars
= rb
->screens
[l
]->getwidth() / param
[l
].font_w
;
369 param
[l
].lines
= param
[l
].DEFAULT_LINES
;
370 param
[l
].keyboard_margin
= DEFAULT_MARGIN
;
372 param
[l
].lines
= (rb
->screens
[l
]->lcdheight
- BUTTONBAR_HEIGHT
-
373 statusbar_size
) / param
[l
].font_h
- 1;
374 param
[l
].keyboard_margin
= rb
->screens
[l
]->lcdheight
-
375 BUTTONBAR_HEIGHT
- statusbar_size
-
376 (param
[l
].lines
+1)*param
[l
].font_h
;
377 if (param
[l
].keyboard_margin
< 3) {
379 param
[l
].keyboard_margin
+= param
[l
].font_h
;
381 if (param
[l
].keyboard_margin
> 6)
382 param
[l
].keyboard_margin
= 6;
385 param
[l
].pages
= (param
[l
].nchars
+ (param
[l
].lines
*param
[l
].max_chars
-1))
386 /(param
[l
].lines
*param
[l
].max_chars
);
387 if (param
[l
].pages
== 1 && kbd_loaded
)
388 param
[l
].lines
= (param
[l
].nchars
+ param
[l
].max_chars
- 1) / param
[l
].max_chars
;
390 param
[l
].main_y
= param
[l
].font_h
*param
[l
].lines
+ param
[l
].keyboard_margin
+ statusbar_size
;
392 param
[l
].keyboard_margin
-= param
[l
].keyboard_margin
/2;
395 editpos
= rb
->utf8length(text
);
401 len_utf8
= rb
->utf8length(text
);
403 rb
->screens
[l
]->clear_display();
409 rb
->screens
[l
]->setfont(param
[l
].curfont
);
410 k
= param
[l
].page
*param
[l
].max_chars
*param
[l
].lines
;
411 for (i
=j
=0; j
< param
[l
].lines
&& k
< param
[l
].nchars
; k
++) {
412 utf8
= rb
->utf8encode(param
[l
].kbd_buf
[k
], outline
);
414 rb
->screens
[l
]->getstringsize(outline
, &w
, NULL
);
415 rb
->screens
[l
]->putsxy(i
*param
[l
].font_w
+ (param
[l
].font_w
-w
)/2, j
*param
[l
].font_h
416 + statusbar_size
, outline
);
417 if (++i
== param
[l
].max_chars
) {
428 rb
->screens
[l
]->hline(0, rb
->screens
[l
]->getwidth() - 1,
429 param
[l
].main_y
- param
[l
].keyboard_margin
);
431 /* write out the text */
433 rb
->screens
[l
]->setfont(param
[l
].curfont
);
436 param
[l
].curpos
= MIN(editpos
, param
[l
].max_chars_text
437 - MIN(len_utf8
- editpos
, 2));
438 param
[l
].leftpos
= editpos
- param
[l
].curpos
;
439 utf8
= text
+ rb
->utf8seek(text
, param
[l
].leftpos
);
441 text_w
= param
[l
].font_w
;
442 while (*utf8
&& i
< param
[l
].max_chars_text
) {
443 outline
[j
++] = *utf8
++;
444 if ((*utf8
& MASK
) != COMP
) {
448 rb
->screens
[l
]->getstringsize(outline
, &w
, NULL
);
449 rb
->screens
[l
]->putsxy(i
*text_w
+ (text_w
-w
)/2, param
[l
].main_y
, outline
);
453 if (param
[l
].leftpos
) {
454 rb
->screens
[l
]->getstringsize("<", &w
, NULL
);
455 rb
->screens
[l
]->putsxy(text_w
- w
, param
[l
].main_y
, "<");
457 if (len_utf8
- param
[l
].leftpos
> param
[l
].max_chars_text
)
458 rb
->screens
[l
]->putsxy(rb
->screens
[l
]->width
- text_w
, param
[l
].main_y
, ">");
461 i
= (param
[l
].curpos
+ 1) * text_w
;
463 rb
->screens
[l
]->vline(i
, param
[l
].main_y
, param
[l
].main_y
+ param
[l
].font_h
-1);
465 if (hangul
) /* draw underbar */
466 rb
->screens
[l
]->hline(param
[l
].curpos
*text_w
, (param
[l
].curpos
+1)*text_w
,
467 param
[l
].main_y
+param
[l
].font_h
-1);
470 cur_blink
= !cur_blink
;
473 /* highlight the key that has focus */
476 rb
->screens
[l
]->set_drawmode(DRMODE_COMPLEMENT
);
477 rb
->screens
[l
]->fillrect(param
[l
].font_w
* param
[l
].x
,
478 statusbar_size
+ param
[l
].font_h
* param
[l
].y
,
479 param
[l
].font_w
, param
[l
].font_h
);
480 rb
->screens
[l
]->set_drawmode(DRMODE_SOLID
);
484 rb
->screens
[l
]->update();
486 button
= rb
->button_get_w_tmo(HZ
/2);
492 rb
->screens
[l
]->setfont(FONT_UI
);
498 case KBD_RIGHT
| BUTTON_REPEAT
:
502 if (++param
[l
].x
== param
[l
].max_chars
) {
504 /* no dedicated flip key - flip page on wrap */
505 if (++param
[l
].page
== param
[l
].pages
)
508 k
= (param
[l
].page
*param
[l
].lines
+ param
[l
].y
)*param
[l
].max_chars
+ param
[l
].x
;
509 /*kbd_spellchar(param[l].kbd_buf[k]);*/
514 case KBD_LEFT
| BUTTON_REPEAT
:
522 /* no dedicated flip key - flip page on wrap */
523 if (--param
[l
].page
< 0)
524 param
[l
].page
= (param
[l
].pages
-1);
525 param
[l
].x
= param
[l
].max_chars
- 1;
527 k
= (param
[l
].page
*param
[l
].lines
+
528 param
[l
].y
)*param
[l
].max_chars
+ param
[l
].x
;
529 /* kbd_spellchar(param[l].kbd_buf[k]);*/
535 case KBD_DOWN
| BUTTON_REPEAT
:
539 if (param
[l
].y
< param
[l
].lines
- 1)
546 k
= (param
[l
].page
*param
[l
].lines
+ param
[l
].y
)*
547 param
[l
].max_chars
+ param
[l
].x
;
548 /*kbd_spellchar(param[l].kbd_buf[k]);*/
554 case KBD_UP
| BUTTON_REPEAT
:
561 param
[l
].y
= param
[l
].lines
- 1;
565 k
= (param
[l
].page
*param
[l
].lines
+ param
[l
].y
)*
566 param
[l
].max_chars
+ param
[l
].x
;
567 /*kbd_spellchar(param[l].kbd_buf[k]);*/
574 if (button
== KBD_SELECT
)
577 /* inserts the selected char */
579 /* find input char */
580 k
= (param
[char_screen
].page
*param
[char_screen
].lines
+
581 param
[char_screen
].y
)*param
[char_screen
].max_chars
+
582 param
[char_screen
].x
;
583 if (k
< param
[char_screen
].nchars
)
584 ch
= param
[char_screen
].kbd_buf
[k
];
594 if(rb
->default_event_handler(button
) == SYS_USB_CONNECTED
)
596 rb
->screens
[l
]->setfont(FONT_SYSFIXED
);
600 if (button
!= BUTTON_NONE
)
607 rb
->screens
[l
]->setfont(FONT_UI
);