|
|
|
|
@ -1,4 +1,4 @@
|
|
|
|
|
/* $Id: gui_entry.c,v 1.14 2013/03/24 00:38:50 steffen Exp $ */
|
|
|
|
|
/* $Id: gui_entry.c,v 1.15 2013/04/21 23:02:23 steffen Exp $ */
|
|
|
|
|
/***************************************************************************
|
|
|
|
|
* gui_entry.c
|
|
|
|
|
*
|
|
|
|
|
@ -40,6 +40,9 @@ void gui_entry_draw (GUIItem *item) {
|
|
|
|
|
if (item) entry = (GUIEntry *) item->data;
|
|
|
|
|
else return;
|
|
|
|
|
|
|
|
|
|
// d_printf ("gui_entry curpos:%d len:%d", entry->curpos, strlen(entry->text));
|
|
|
|
|
// d_print_data (entry->text, strlen (entry->text)+1);
|
|
|
|
|
|
|
|
|
|
ls.width = 1.0;
|
|
|
|
|
if (currentwin->focus == (void*) item)
|
|
|
|
|
ls.c = ls.borderc = color[COLOR_white][3];
|
|
|
|
|
@ -59,6 +62,7 @@ void gui_entry_draw (GUIItem *item) {
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
strncpy (text2, entry->text, entry->curpos);
|
|
|
|
|
text2[entry->curpos] = '\0';
|
|
|
|
|
snprintf (text1, GUI_TEXTLEN, "%s|%s", text2, entry->text+entry->curpos);
|
|
|
|
|
}
|
|
|
|
|
gfx_draw_text (currentwin->screen, item->x+2, item->y, text1, &color[COLOR_white][3]);
|
|
|
|
|
@ -69,12 +73,14 @@ void gui_entry_draw (GUIItem *item) {
|
|
|
|
|
* event handling
|
|
|
|
|
*/
|
|
|
|
|
int gui_entry_event (GUIItem *item, GUIEvent *event) {
|
|
|
|
|
char text1[GUI_TEXTLEN];
|
|
|
|
|
char text[GUI_TEXTLEN];
|
|
|
|
|
char text2[GUI_TEXTLEN];
|
|
|
|
|
GUIEntry *entry = NULL;
|
|
|
|
|
|
|
|
|
|
if (item) entry = (GUIEntry *) item->data;
|
|
|
|
|
|
|
|
|
|
// d_printf ("gui_entry curpos:%d keyval:%lx", entry->curpos, event->keyval);
|
|
|
|
|
|
|
|
|
|
if (event->event == EGUI_MOUSEPRESSED) {
|
|
|
|
|
gui_set_focus (item);
|
|
|
|
|
gui_softkeyb_show (TRUE);
|
|
|
|
|
@ -82,12 +88,18 @@ int gui_entry_event (GUIItem *item, GUIEvent *event) {
|
|
|
|
|
|
|
|
|
|
else if (event->event == EGUI_KEYCHAR) {
|
|
|
|
|
if (event->keyval == 0x08) { // backspace
|
|
|
|
|
if (entry->curpos > 0) {
|
|
|
|
|
memset (text1, 0x0, GUI_TEXTLEN);
|
|
|
|
|
memset (text2, 0x0, GUI_TEXTLEN);
|
|
|
|
|
strncpy (text1, entry->text, entry->curpos-1);
|
|
|
|
|
snprintf (text2, GUI_TEXTLEN, "%s%s", text1, entry->text+entry->curpos);
|
|
|
|
|
strncpy (entry->text, text2, GUI_TEXTLEN);
|
|
|
|
|
d_printf ("gui_entry:backspace");
|
|
|
|
|
if (entry->curpos > 0 && entry->curpos < strlen (entry->text)) {
|
|
|
|
|
memset (text, 0x0, GUI_TEXTLEN);
|
|
|
|
|
strncpy (text, entry->text, entry->curpos-1);
|
|
|
|
|
text[entry->curpos] = '\0';
|
|
|
|
|
snprintf (entry->text, GUI_TEXTLEN, "%s%s", text, entry->text+entry->curpos);
|
|
|
|
|
entry->curpos--;
|
|
|
|
|
}
|
|
|
|
|
else if (entry->curpos >= strlen (entry->text)) {
|
|
|
|
|
memset (text, 0x0, GUI_TEXTLEN);
|
|
|
|
|
strncpy (text, entry->text, entry->curpos-1);
|
|
|
|
|
strncpy (entry->text, text, GUI_TEXTLEN);
|
|
|
|
|
entry->curpos--;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
@ -99,23 +111,38 @@ int gui_entry_event (GUIItem *item, GUIEvent *event) {
|
|
|
|
|
gui_close ();
|
|
|
|
|
}
|
|
|
|
|
else if (event->keyval == 0x0d) { // enter
|
|
|
|
|
d_printf ("gui_entry:enter");
|
|
|
|
|
if (entry->callback_enter) entry->callback_enter ();
|
|
|
|
|
}
|
|
|
|
|
else if (event->keyval == 0x51) { // left
|
|
|
|
|
d_printf ("gui_entry:curpos--");
|
|
|
|
|
entry->curpos--;
|
|
|
|
|
}
|
|
|
|
|
else if (event->keyval == 0x53) { // right
|
|
|
|
|
d_printf ("gui_entry:curpos++");
|
|
|
|
|
entry->curpos++;
|
|
|
|
|
}
|
|
|
|
|
else if (event->keyval != 0) {
|
|
|
|
|
d_printf ("gui_entry:new text");
|
|
|
|
|
if (entry->curpos == strlen (entry->text)) {
|
|
|
|
|
strncpy (text, entry->text, GUI_TEXTLEN );
|
|
|
|
|
snprintf (entry->text, GUI_TEXTLEN, "%s%c", text, event->keyval);
|
|
|
|
|
entry->curpos++;
|
|
|
|
|
}
|
|
|
|
|
else if ((event->keyval & 0x00) == 0xff00) {
|
|
|
|
|
// ignore all the rest
|
|
|
|
|
else if (entry->curpos == 0) {
|
|
|
|
|
strncpy (text, entry->text, GUI_TEXTLEN );
|
|
|
|
|
snprintf (entry->text, GUI_TEXTLEN, "%c%s", event->keyval, text);
|
|
|
|
|
entry->curpos++;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
strncpy (text1, entry->text, GUI_TEXTLEN );
|
|
|
|
|
snprintf (entry->text, GUI_TEXTLEN, "%s%c", text1, event->keyval);
|
|
|
|
|
strncpy (text, entry->text, entry->curpos);
|
|
|
|
|
text[entry->curpos] = '\0';
|
|
|
|
|
snprintf (text2, GUI_TEXTLEN, "%s%c%s", text, event->keyval, entry->text+entry->curpos);
|
|
|
|
|
strncpy (entry->text, text2, GUI_TEXTLEN);
|
|
|
|
|
entry->curpos++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
currentwin->screen_changed = 1;
|
|
|
|
|
draw ();
|
|
|
|
|
return 1;
|
|
|
|
|
|