Freeciv-3.3: /fast/freeciv/nightly/main/client/gui-sdl2/widget_edit.c Source File

Freeciv-3.3

Loading...
Searching...
No Matches
widget_edit.c
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 2006 - The Freeciv Project
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
6 any later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12***********************************************************************/
13
14#ifdef HAVE_CONFIG_H
15#include <fc_config.h>
16#endif
17
18/* SDL2 */
19#ifdef SDL2_PLAIN_INCLUDE
20#include <SDL.h>
21#else /* SDL2_PLAIN_INCLUDE */
22#include <SDL2/SDL.h>
23#endif /* SDL2_PLAIN_INCLUDE */
24
25/* gui-sdl2 */
26#include "colors.h"
27#include "graphics.h"
28#include "gui_id.h"
29#include "gui_tilespec.h"
30#include "mapview.h"
31#include "themespec.h"
32#include "utf8string.h"
33#include "widget.h"
34#include "widget_p.h"
35
36 struct utf8_char {
37 struct utf8_char *next;
38 struct utf8_char *prev;
39 int bytes;
40 char chr[7];
41 SDL_Surface *tsurf;
42};
43
44 struct text_edit {
45 struct utf8_char *begin_text_chain;
46 struct utf8_char *end_text_chain;
47 struct utf8_char *input_chain;
48 SDL_Surface *bg;
49 struct widget *pwidget;
50 int chain_len;
51 int start_x;
52 int true_length;
53 int input_chain_x;
54};
55
56static size_t chainlen(const struct utf8_char *chain);
57static void del_chain(struct utf8_char *chain);
58static struct utf8_char *text2chain(const char *text_in);
59static char *chain2text(const struct utf8_char *in_chain, size_t len, size_t *size);
60
61 static int (*baseclass_redraw)(struct widget *pwidget);
62
63/**********************************************************************/
66 static int redraw_edit_chain(struct text_edit *edt)
67{
68 struct utf8_char *input_chain_tmp;
69 SDL_Rect dest, dest_copy = {0, 0, 0, 0};
70 int start_mod_x;
71 int ret;
72
73 dest_copy.x = edt->pwidget->size.x;
74 dest_copy.y = edt->pwidget->size.y;
75
76 ret = (*baseclass_redraw)(edt->pwidget);
77 if (ret != 0) {
78 return ret;
79 }
80
81 /* blit theme */
82 dest = dest_copy;
83
84 alphablit(edt->bg, NULL, edt->pwidget->dst->surface, &dest, 255);
85
86 /* set start parameters */
87 input_chain_tmp = edt->begin_text_chain;
88 start_mod_x = 0;
89
90 dest_copy.y += (edt->bg->h - input_chain_tmp->tsurf->h) / 2;
91 dest_copy.x += edt->start_x;
92
93 /* draw loop */
94 while (input_chain_tmp) {
95 dest_copy.x += start_mod_x;
96 /* check if we draw inside of edit rect */
97 if (dest_copy.x > edt->pwidget->size.x + edt->bg->w - 4) {
98 break;
99 }
100
101 if (dest_copy.x > edt->pwidget->size.x) {
102 dest = dest_copy;
103 alphablit(input_chain_tmp->tsurf, NULL, edt->pwidget->dst->surface, &dest,
104 255);
105 }
106
107 start_mod_x = input_chain_tmp->tsurf->w;
108
109 /* draw cursor */
110 if (input_chain_tmp == edt->input_chain) {
111 dest = dest_copy;
112
113 create_line(edt->pwidget->dst->surface,
114 dest.x - 1, dest.y + (edt->bg->h / 8),
115 dest.x - 1, dest.y + edt->bg->h - (edt->bg->h / 4),
116 get_theme_color(COLOR_THEME_EDITFIELD_CARET));
117 /* save active element position */
118 edt->input_chain_x = dest_copy.x;
119 }
120
121 input_chain_tmp = input_chain_tmp->next;
122 } /* while - draw loop */
123
124 widget_flush(edt->pwidget);
125
126 return 0;
127}
128
129/**********************************************************************/
142 static int redraw_edit(struct widget *edit_widget)
143{
144 if (get_wstate(edit_widget) == FC_WS_PRESSED) {
145 return redraw_edit_chain((struct text_edit *)edit_widget->data.ptr);
146 } else {
147 int ret;
148 SDL_Rect rdest = {edit_widget->size.x, edit_widget->size.y, 0, 0};
149 SDL_Surface *pedit = NULL;
150 SDL_Surface *text;
151
152 ret = (*baseclass_redraw)(edit_widget);
153 if (ret != 0) {
154 return ret;
155 }
156
157 if (edit_widget->string_utf8->text != NULL
158 && get_wflags(edit_widget) & WF_PASSWD_EDIT) {
159 char *backup = edit_widget->string_utf8->text;
160 size_t len = strlen(backup) + 1;
161 char *cbuf = fc_calloc(1, len);
162
163 memset(cbuf, '*', len - 1);
164 cbuf[len - 1] = '\0';
165 edit_widget->string_utf8->text = cbuf;
166 text = create_text_surf_from_utf8(edit_widget->string_utf8);
167 FC_FREE(cbuf);
168 edit_widget->string_utf8->text = backup;
169 } else {
170 text = create_text_surf_from_utf8(edit_widget->string_utf8);
171 }
172
173 pedit = create_bcgnd_surf(edit_widget->theme, get_wstate(edit_widget),
174 edit_widget->size.w, edit_widget->size.h);
175
176 if (!pedit) {
177 return -1;
178 }
179
180 /* blit theme */
181 alphablit(pedit, NULL, edit_widget->dst->surface, &rdest, 255);
182
183 /* set position and blit text */
184 if (text) {
185 rdest.y += (pedit->h - text->h) / 2;
186 /* blit centred text to botton */
187 if (edit_widget->string_utf8->style & SF_CENTER) {
188 rdest.x += (pedit->w - text->w) / 2;
189 } else {
190 if (edit_widget->string_utf8->style & SF_CENTER_RIGHT) {
191 rdest.x += pedit->w - text->w - adj_size(5);
192 } else {
193 rdest.x += adj_size(5); /* center left */
194 }
195 }
196
197 alphablit(text, NULL, edit_widget->dst->surface, &rdest, 255);
198 }
199 /* text */
200 ret = pedit->h;
201
202 /* Free memory */
203 FREESURFACE(text);
204 FREESURFACE(pedit);
205
206 return ret;
207 }
208
209 return 0;
210}
211
212/**********************************************************************/
217 static size_t chainlen(const struct utf8_char *chain)
218{
219 size_t length = 0;
220
221 if (chain) {
222 while (TRUE) {
223 length++;
224 if (chain->next == NULL) {
225 break;
226 }
227 chain = chain->next;
228 }
229 }
230
231 return length;
232}
233
234/**********************************************************************/
237 static void del_chain(struct utf8_char *chain)
238{
239 int i, len = 0;
240
241 if (!chain) {
242 return;
243 }
244
245 len = chainlen(chain);
246
247 if (len > 1) {
248 chain = chain->next;
249 for (i = 0; i < len - 1; i++) {
250 FREESURFACE(chain->prev->tsurf);
251 FC_FREE(chain->prev);
252 chain = chain->next;
253 }
254 }
255
256 FC_FREE(chain);
257}
258
259/**********************************************************************/
263 static struct utf8_char *text2chain(const char *text_in)
264{
265 int i, len;
266 struct utf8_char *out_chain = NULL;
267 struct utf8_char *chr_tmp = NULL;
268 int j;
269
270 if (text_in == NULL) {
271 return NULL;
272 }
273
274 len = strlen(text_in);
275
276 if (len == 0) {
277 return NULL;
278 }
279
280 out_chain = fc_calloc(1, sizeof(struct utf8_char));
281 out_chain->chr[0] = text_in[0];
282 for (j = 1; (text_in[j] & (128 + 64)) == 128; j++) {
283 out_chain->chr[j] = text_in[j];
284 }
285 out_chain->bytes = j;
286 chr_tmp = out_chain;
287
288 for (i = 1; i < len; i += j) {
289 chr_tmp->next = fc_calloc(1, sizeof(struct utf8_char));
290 chr_tmp->next->chr[0] = text_in[i];
291 for (j = 1; (text_in[i + j] & (128 + 64)) == 128; j++) {
292 chr_tmp->next->chr[j] = text_in[i + j];
293 }
294 chr_tmp->next->bytes = j;
295 chr_tmp->next->prev = chr_tmp;
296 chr_tmp = chr_tmp->next;
297 }
298
299 return out_chain;
300}
301
302/**********************************************************************/
306 static char *chain2text(const struct utf8_char *in_chain, size_t len,
307 size_t *size)
308{
309 int i;
310 char *out_text = NULL;
311 int oi = 0;
312 int total_size = 0;
313
314 if (!(len && in_chain)) {
315 return out_text;
316 }
317
318 out_text = fc_calloc(8, len + 1);
319 for (i = 0; i < len; i++) {
320 int j;
321
322 for (j = 0; j < in_chain->bytes && i < len; j++) {
323 out_text[oi++] = in_chain->chr[j];
324 }
325
326 total_size += in_chain->bytes;
327 in_chain = in_chain->next;
328 }
329
330 *size = total_size;
331
332 return out_text;
333}
334
335/* =================================================== */
336
337/**********************************************************************/
350 struct widget *create_edit(SDL_Surface *background, struct gui_layer *pdest,
351 utf8_str *pstr, int length, Uint32 flags)
352{
353 SDL_Rect buf = {0, 0, 0, 0};
354 struct widget *pedit = widget_new();
355
356 pedit->theme = current_theme->edit;
357 pedit->theme2 = background; /* FIXME: make somewhere use of it */
358 pedit->string_utf8 = pstr;
359 set_wflag(pedit, (WF_FREE_STRING | WF_FREE_GFX | flags));
360 set_wstate(pedit, FC_WS_DISABLED);
361 set_wtype(pedit, WT_EDIT);
362 pedit->mod = KMOD_NONE;
363
364 baseclass_redraw = pedit->redraw;
365 pedit->redraw = redraw_edit;
366
367 if (pstr != NULL) {
368 pedit->string_utf8->style |= SF_CENTER;
369 utf8_str_size(pstr, &buf);
370 buf.h += adj_size(4);
371 }
372
373 length = MAX(length, buf.w + adj_size(10));
374
375 correct_size_bcgnd_surf(current_theme->edit, &length, &buf.h);
376
377 pedit->size.w = length;
378 pedit->size.h = buf.h;
379
380 if (pdest) {
381 pedit->dst = pdest;
382 } else {
383 pedit->dst = add_gui_layer(pedit->size.w, pedit->size.h);
384 }
385
386 return pedit;
387}
388
389/**********************************************************************/
392 int draw_edit(struct widget *pedit, Sint16 start_x, Sint16 start_y)
393{
394 pedit->size.x = start_x;
395 pedit->size.y = start_y;
396
397 if (get_wflags(pedit) & WF_RESTORE_BACKGROUND) {
398 refresh_widget_background(pedit);
399 }
400
401 return redraw_edit(pedit);
402}
403
404/**********************************************************************/
423 static Uint16 edit_key_down(SDL_Keysym key, void *data)
424{
425 struct text_edit *edt = (struct text_edit *)data;
426 struct utf8_char *input_chain_tmp;
427 bool redraw = FALSE;
428
429 /* find which key is pressed */
430 switch (key.sym) {
431 case SDLK_ESCAPE:
432 /* exit from loop without changes */
433 return ED_ESC;
434 case SDLK_RETURN:
435 case SDLK_KP_ENTER:
436 /* exit from loop */
437 return ED_RETURN;
438 /*
439 case SDLK_KP6:
440 if (key.mod & KMOD_NUM) {
441 goto INPUT;
442 }
443 */
444 case SDLK_RIGHT:
445 {
446 /* move cursor right */
447 if (edt->input_chain->next) {
448 if (edt->input_chain_x >= (edt->pwidget->size.x + edt->bg->w - adj_size(10))) {
449 edt->start_x -= edt->input_chain->tsurf->w -
450 (edt->pwidget->size.x + edt->bg->w - adj_size(5) - edt->input_chain_x);
451 }
452
453 edt->input_chain = edt->input_chain->next;
454 redraw = TRUE;
455 }
456 }
457 break;
458 /*
459 case SDLK_KP4:
460 if (key.mod & KMOD_NUM) {
461 goto INPUT;
462 }
463 */
464 case SDLK_LEFT:
465 {
466 /* move cursor left */
467 if (edt->input_chain->prev) {
468 edt->input_chain = edt->input_chain->prev;
469 if ((edt->input_chain_x <=
470 (edt->pwidget->size.x + adj_size(9))) && (edt->start_x != adj_size(5))) {
471 if (edt->input_chain_x != (edt->pwidget->size.x + adj_size(5))) {
472 edt->start_x += (edt->pwidget->size.x - edt->input_chain_x + adj_size(5));
473 }
474
475 edt->start_x += (edt->input_chain->tsurf->w);
476 }
477 redraw = TRUE;
478 }
479 }
480 break;
481 /*
482 case SDLK_KP7:
483 if (key.mod & KMOD_NUM) {
484 goto INPUT;
485 }
486 */
487 case SDLK_HOME:
488 {
489 /* move cursor to begin of chain (and edit field) */
490 edt->input_chain = edt->begin_text_chain;
491 redraw = TRUE;
492 edt->start_x = adj_size(5);
493 }
494 break;
495 /*
496 case SDLK_KP1:
497 if (key.mod & KMOD_NUM) {
498 goto INPUT;
499 }
500 */
501 case SDLK_END:
502 {
503 /* move cursor to end of chain (and edit field) */
504 edt->input_chain = edt->end_text_chain;
505 redraw = TRUE;
506
507 if (edt->pwidget->size.w - edt->true_length < 0) {
508 edt->start_x = edt->pwidget->size.w - edt->true_length - adj_size(5);
509 }
510 }
511 break;
512 case SDLK_BACKSPACE:
513 {
514 /* del element of chain (and move cursor left) */
515 if (edt->input_chain->prev) {
516 if ((edt->input_chain_x <=
517 (edt->pwidget->size.x + adj_size(9))) && (edt->start_x != adj_size(5))) {
518 if (edt->input_chain_x != (edt->pwidget->size.x + adj_size(5))) {
519 edt->start_x += (edt->pwidget->size.x - edt->input_chain_x + adj_size(5));
520 }
521 edt->start_x += (edt->input_chain->prev->tsurf->w);
522 }
523
524 if (edt->input_chain->prev->prev) {
525 edt->input_chain->prev->prev->next = edt->input_chain;
526 input_chain_tmp = edt->input_chain->prev->prev;
527 edt->true_length -= edt->input_chain->prev->tsurf->w;
528 FREESURFACE(edt->input_chain->prev->tsurf);
529 FC_FREE(edt->input_chain->prev);
530 edt->input_chain->prev = input_chain_tmp;
531 } else {
532 edt->true_length -= edt->input_chain->prev->tsurf->w;
533 FREESURFACE(edt->input_chain->prev->tsurf);
534 FC_FREE(edt->input_chain->prev);
535 edt->begin_text_chain = edt->input_chain;
536 }
537
538 edt->chain_len--;
539 redraw = TRUE;
540 }
541 }
542 break;
543 /*
544 case SDLK_KP_PERIOD:
545 if (key.mod & KMOD_NUM) {
546 goto INPUT;
547 }
548 */
549 case SDLK_DELETE:
550 {
551 /* del element of chain */
552 if (edt->input_chain->next && edt->input_chain->prev) {
553 edt->input_chain->prev->next = edt->input_chain->next;
554 edt->input_chain->next->prev = edt->input_chain->prev;
555 input_chain_tmp = edt->input_chain->next;
556 edt->true_length -= edt->input_chain->tsurf->w;
557 FREESURFACE(edt->input_chain->tsurf);
558 FC_FREE(edt->input_chain);
559 edt->input_chain = input_chain_tmp;
560 edt->chain_len--;
561 redraw = TRUE;
562 }
563
564 if (edt->input_chain->next && !edt->input_chain->prev) {
565 edt->input_chain = edt->input_chain->next;
566 edt->true_length -= edt->input_chain->prev->tsurf->w;
567 FREESURFACE(edt->input_chain->prev->tsurf);
568 FC_FREE(edt->input_chain->prev);
569 edt->begin_text_chain = edt->input_chain;
570 edt->chain_len--;
571 redraw = TRUE;
572 }
573 }
574 break;
575 default:
576 break;
577 } /* key pressed switch */
578
579 if (redraw) {
580 redraw_edit_chain(edt);
581 }
582
583 return ID_ERROR;
584}
585
586/**********************************************************************/
589 static Uint16 edit_textinput(char *text, void *data)
590{
591 struct text_edit *edt = (struct text_edit *)data;
592 struct utf8_char *input_chain_tmp;
593 int i;
594
595 for (i = 0; text[i] != '\0';) {
596 int charlen = 1;
597 unsigned char leading = text[i++];
598 int sum = 128 + 64;
599 int addition = 32;
600
601 /* add new element of chain (and move cursor right) */
602 if (edt->input_chain != edt->begin_text_chain) {
603 input_chain_tmp = edt->input_chain->prev;
604 edt->input_chain->prev = fc_calloc(1, sizeof(struct utf8_char));
605 edt->input_chain->prev->next = edt->input_chain;
606 edt->input_chain->prev->prev = input_chain_tmp;
607 input_chain_tmp->next = edt->input_chain->prev;
608 } else {
609 edt->input_chain->prev = fc_calloc(1, sizeof(struct utf8_char));
610 edt->input_chain->prev->next = edt->input_chain;
611 edt->begin_text_chain = edt->input_chain->prev;
612 }
613
614 edt->input_chain->prev->chr[0] = leading;
615 /* UTF-8 multibyte handling */
616 while (leading >= sum) {
617 edt->input_chain->prev->chr[charlen++] = text[i++];
618 sum += addition;
619 addition /= 2;
620 }
621 edt->input_chain->prev->chr[charlen] = '\0';
622 edt->input_chain->prev->bytes = charlen;
623
624 if (get_wflags(edt->pwidget) & WF_PASSWD_EDIT) {
625 char passwd_chr[2] = {'*', '\0'};
626
627 edt->input_chain->prev->tsurf =
628 TTF_RenderUTF8_Blended(edt->pwidget->string_utf8->font,
629 passwd_chr,
630 edt->pwidget->string_utf8->fgcol);
631 } else {
632 edt->input_chain->prev->tsurf =
633 TTF_RenderUTF8_Blended(edt->pwidget->string_utf8->font,
634 edt->input_chain->prev->chr,
635 edt->pwidget->string_utf8->fgcol);
636 }
637 edt->true_length += edt->input_chain->prev->tsurf->w;
638
639 if (edt->input_chain_x >= edt->pwidget->size.x + edt->bg->w - adj_size(10)) {
640 if (edt->input_chain == edt->end_text_chain) {
641 edt->start_x = edt->bg->w - adj_size(5) - edt->true_length;
642 } else {
643 edt->start_x -= edt->input_chain->prev->tsurf->w -
644 (edt->pwidget->size.x + edt->bg->w - adj_size(5) - edt->input_chain_x);
645 }
646 }
647
648 edt->chain_len++;
649 }
650
651 redraw_edit_chain(edt);
652
653 return ID_ERROR;
654}
655
656/**********************************************************************/
659 static Uint16 edit_mouse_button_down(SDL_MouseButtonEvent *button_event,
660 void *data)
661{
662 struct text_edit *edt = (struct text_edit *)data;
663
664 if (button_event->button == SDL_BUTTON_LEFT) {
665 if (!(button_event->x >= edt->pwidget->size.x
666 && button_event->x < edt->pwidget->size.x + edt->bg->w
667 && button_event->y >= edt->pwidget->size.y
668 && button_event->y < edt->pwidget->size.y + edt->bg->h)) {
669 /* exit from loop */
670 return (Uint16)ED_MOUSE;
671 }
672 }
673
674 return (Uint16)ID_ERROR;
675}
676
677/**********************************************************************/
681 enum edit_return_codes edit_field(struct widget *edit_widget)
682{
683 struct text_edit edt;
684 struct utf8_char ___last;
685 struct utf8_char *input_chain_tmp = NULL;
686 enum edit_return_codes ret;
687 void *backup = edit_widget->data.ptr;
688
689 edt.pwidget = edit_widget;
690 edt.chain_len = 0;
691 edt.true_length = 0;
692 edt.start_x = adj_size(5);
693 edt.input_chain_x = 0;
694
695 edit_widget->data.ptr = (void *)&edt;
696
697#if 0
698 SDL_EnableUNICODE(1);
699 SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY, SDL_DEFAULT_REPEAT_INTERVAL);
700#endif /* 0 */
701
702 edt.bg = create_bcgnd_surf(edit_widget->theme, FC_WS_PRESSED,
703 edit_widget->size.w, edit_widget->size.h);
704
705 /* Creating Chain */
706 edt.begin_text_chain = text2chain(edit_widget->string_utf8->text);
707
708 /* Creating Empty (Last) pice of Chain */
709 edt.input_chain = &___last;
710 edt.end_text_chain = edt.input_chain;
711 edt.end_text_chain->chr[0] = 32; /* spacebar */
712 edt.end_text_chain->chr[1] = 0; /* spacebar */
713 edt.end_text_chain->next = NULL;
714 edt.end_text_chain->prev = NULL;
715
716 /* set font style (if any ) */
717 if (!((edit_widget->string_utf8->style & 0x0F) & TTF_STYLE_NORMAL)) {
718 TTF_SetFontStyle(edit_widget->string_utf8->font,
719 (edit_widget->string_utf8->style & 0x0F));
720 }
721
722 edt.end_text_chain->tsurf =
723 TTF_RenderUTF8_Blended(edit_widget->string_utf8->font,
724 edt.end_text_chain->chr,
725 edit_widget->string_utf8->fgcol);
726
727 /* create surface for each font in chain and find chain length */
728 if (edt.begin_text_chain) {
729 input_chain_tmp = edt.begin_text_chain;
730
731 while (TRUE) {
732 edt.chain_len++;
733
734 if (get_wflags(edit_widget) & WF_PASSWD_EDIT) {
735 const char passwd_chr[2] = {'*', '\0'};
736
737 input_chain_tmp->tsurf =
738 TTF_RenderUTF8_Blended(edit_widget->string_utf8->font,
739 passwd_chr,
740 edit_widget->string_utf8->fgcol);
741 } else {
742 input_chain_tmp->tsurf =
743 TTF_RenderUTF8_Blended(edit_widget->string_utf8->font,
744 input_chain_tmp->chr,
745 edit_widget->string_utf8->fgcol);
746 }
747
748 edt.true_length += input_chain_tmp->tsurf->w;
749
750 if (input_chain_tmp->next == NULL) {
751 break;
752 }
753
754 input_chain_tmp = input_chain_tmp->next;
755 }
756 /* set terminator of list */
757 input_chain_tmp->next = edt.input_chain;
758 edt.input_chain->prev = input_chain_tmp;
759 input_chain_tmp = NULL;
760 } else {
761 edt.begin_text_chain = edt.input_chain;
762 }
763
764 redraw_edit_chain(&edt);
765
766 set_wstate(edit_widget, FC_WS_PRESSED);
767 {
768 /* Local loop */
769 Uint16 rety = gui_event_loop((void *)&edt, NULL,
770 edit_key_down, NULL, edit_textinput, NULL, NULL, NULL,
771 edit_mouse_button_down, NULL, NULL);
772
773 if (edt.begin_text_chain == edt.end_text_chain) {
774 edt.begin_text_chain = NULL;
775 }
776
777 if (rety == MAX_ID) {
778 ret = ED_FORCE_EXIT;
779 } else {
780 ret = (enum edit_return_codes) rety;
781
782 /* This is here because we have no knowledge that edit_widget exist
783 or nor in force exit mode from gui loop */
784
785 /* Reset font settings */
786 if (!((edit_widget->string_utf8->style & 0x0F) & TTF_STYLE_NORMAL)) {
787 TTF_SetFontStyle(edit_widget->string_utf8->font, TTF_STYLE_NORMAL);
788 }
789
790 if (ret != ED_ESC) {
791 size_t len = 0;
792
793 FC_FREE(edit_widget->string_utf8->text);
794 edit_widget->string_utf8->text =
795 chain2text(edt.begin_text_chain, edt.chain_len, &len);
796 edit_widget->string_utf8->n_alloc = len + 1;
797 }
798
799 edit_widget->data.ptr = backup;
800 set_wstate(edit_widget, FC_WS_NORMAL);
801 }
802 }
803
804 FREESURFACE(edt.end_text_chain->tsurf);
805
806 del_chain(edt.begin_text_chain);
807
808 FREESURFACE(edt.bg);
809
810 /* Disable repeat key */
811
812#if 0
813 SDL_EnableKeyRepeat(0, SDL_DEFAULT_REPEAT_INTERVAL);
814
815 /* Disable Unicode */
816 SDL_EnableUNICODE(0);
817#endif /* 0 */
818
819 return ret;
820}
incite_cost
char * incite_cost
Definition comments.c:74
current_theme
QString current_theme
Definition fc_client.cpp:64
get_theme_color
SDL_Color * get_theme_color(enum theme_color themecolor)
Definition colors.c:47
create_line
void create_line(SDL_Surface *dest, Sint16 x0, Sint16 y0, Sint16 x1, Sint16 y1, SDL_Color *pcolor)
Definition graphics.c:1381
alphablit
int alphablit(SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect, unsigned char alpha_mod)
Definition graphics.c:199
add_gui_layer
struct gui_layer * add_gui_layer(int width, int height)
Definition graphics.c:112
FREESURFACE
#define FREESURFACE(ptr)
Definition graphics.h:322
ID_ERROR
@ ID_ERROR
Definition gui_id.h:26
gui_event_loop
Uint16 gui_event_loop(void *data, void(*loop_action)(void *data), Uint16(*key_down_handler)(SDL_Keysym key, void *data), Uint16(*key_up_handler)(SDL_Keysym key, void *data), Uint16(*textinput_handler)(char *text, void *data), Uint16(*finger_down_handler)(SDL_TouchFingerEvent *touch_event, void *data), Uint16(*finger_up_handler)(SDL_TouchFingerEvent *touch_event, void *data), Uint16(*finger_motion_handler)(SDL_TouchFingerEvent *touch_event, void *data), Uint16(*mouse_button_down_handler)(SDL_MouseButtonEvent *button_event, void *data), Uint16(*mouse_button_up_handler)(SDL_MouseButtonEvent *button_event, void *data), Uint16(*mouse_motion_handler)(SDL_MouseMotionEvent *motion_event, void *data))
Definition gui_main.c:602
adj_size
#define adj_size(size)
Definition gui_main.h:141
utf8_str_size
void utf8_str_size(utf8_str *pstr, SDL_Rect *fill)
Definition gui_string.c:106
create_text_surf_from_utf8
SDL_Surface * create_text_surf_from_utf8(utf8_str *pstr)
Definition gui_string.c:425
SF_CENTER
#define SF_CENTER
Definition gui_string.h:40
SF_CENTER_RIGHT
#define SF_CENTER_RIGHT
Definition gui_string.h:41
COLOR_THEME_EDITFIELD_CARET
@ COLOR_THEME_EDITFIELD_CARET
Definition themecolors.h:32
correct_size_bcgnd_surf
void correct_size_bcgnd_surf(SDL_Surface *ptheme, int *width, int *height)
Definition widget.c:63
refresh_widget_background
void refresh_widget_background(struct widget *pwidget)
Definition widget.c:1151
create_bcgnd_surf
SDL_Surface * create_bcgnd_surf(SDL_Surface *ptheme, enum widget_state state, Uint16 width, Uint16 height)
Definition widget.c:78
MAX_ID
#define MAX_ID
Definition widget.h:38
FC_WS_DISABLED
@ FC_WS_DISABLED
Definition widget.h:99
FC_WS_NORMAL
@ FC_WS_NORMAL
Definition widget.h:96
FC_WS_PRESSED
@ FC_WS_PRESSED
Definition widget.h:98
widget_flush
static void widget_flush(struct widget *pwidget)
Definition widget.h:291
get_wflags
enum widget_flag get_wflags(const struct widget *pwidget)
Definition widget_core.c:86
set_wstate
void set_wstate(struct widget *pwidget, enum widget_state state)
Definition widget_core.c:36
get_wstate
enum widget_state get_wstate(const struct widget *pwidget)
Definition widget_core.c:70
WF_FREE_GFX
@ WF_FREE_GFX
Definition widget.h:70
WF_PASSWD_EDIT
@ WF_PASSWD_EDIT
Definition widget.h:90
WF_FREE_STRING
@ WF_FREE_STRING
Definition widget.h:76
WF_RESTORE_BACKGROUND
@ WF_RESTORE_BACKGROUND
Definition widget.h:85
set_wtype
void set_wtype(struct widget *pwidget, enum widget_type type)
Definition widget_core.c:45
set_wflag
void set_wflag(struct widget *pwidget, enum widget_flag flag)
Definition widget_core.c:54
WT_EDIT
@ WT_EDIT
Definition widget.h:48
widget_new
struct widget * widget_new(void)
Definition widget_core.c:252
text2chain
static struct utf8_char * text2chain(const char *text_in)
Definition widget_edit.c:263
redraw_edit_chain
static int redraw_edit_chain(struct text_edit *edt)
Definition widget_edit.c:66
chain2text
static char * chain2text(const struct utf8_char *in_chain, size_t len, size_t *size)
Definition widget_edit.c:306
chainlen
static size_t chainlen(const struct utf8_char *chain)
Definition widget_edit.c:217
create_edit
struct widget * create_edit(SDL_Surface *background, struct gui_layer *pdest, utf8_str *pstr, int length, Uint32 flags)
Definition widget_edit.c:350
edit_field
enum edit_return_codes edit_field(struct widget *edit_widget)
Definition widget_edit.c:681
edit_mouse_button_down
static Uint16 edit_mouse_button_down(SDL_MouseButtonEvent *button_event, void *data)
Definition widget_edit.c:659
baseclass_redraw
static int(* baseclass_redraw)(struct widget *pwidget)
Definition widget_edit.c:61
edit_textinput
static Uint16 edit_textinput(char *text, void *data)
Definition widget_edit.c:589
del_chain
static void del_chain(struct utf8_char *chain)
Definition widget_edit.c:237
redraw_edit
static int redraw_edit(struct widget *edit_widget)
Definition widget_edit.c:142
edit_key_down
static Uint16 edit_key_down(SDL_Keysym key, void *data)
Definition widget_edit.c:423
draw_edit
int draw_edit(struct widget *pedit, Sint16 start_x, Sint16 start_y)
Definition widget_edit.c:392
edit_return_codes
edit_return_codes
Definition widget_edit.h:17
ED_FORCE_EXIT
@ ED_FORCE_EXIT
Definition widget_edit.h:21
ED_ESC
@ ED_ESC
Definition widget_edit.h:19
ED_RETURN
@ ED_RETURN
Definition widget_edit.h:18
ED_MOUSE
@ ED_MOUSE
Definition widget_edit.h:20
gui_id.h
gui_tilespec.h
themespec.h
utf8string.h
widget.h
widget_p.h
colors.h
graphics.h
mapview.h
fc_calloc
#define fc_calloc(n, esz)
Definition mem.h:38
FC_FREE
#define FC_FREE(ptr)
Definition mem.h:41
len
int len
Definition packhand.c:127
MAX
#define MAX(x, y)
Definition shared.h:54
size
size_t size
Definition specvec.h:72
gui_layer
Definition graphics.h:227
text_edit
Definition widget_edit.c:44
text_edit::start_x
int start_x
Definition widget_edit.c:51
text_edit::pwidget
struct widget * pwidget
Definition widget_edit.c:49
text_edit::true_length
int true_length
Definition widget_edit.c:52
text_edit::input_chain_x
int input_chain_x
Definition widget_edit.c:53
text_edit::begin_text_chain
struct utf8_char * begin_text_chain
Definition widget_edit.c:45
text_edit::end_text_chain
struct utf8_char * end_text_chain
Definition widget_edit.c:46
text_edit::bg
SDL_Surface * bg
Definition widget_edit.c:48
text_edit::input_chain
struct utf8_char * input_chain
Definition widget_edit.c:47
text_edit::chain_len
int chain_len
Definition widget_edit.c:50
utf8_char
Definition widget_edit.c:36
utf8_char::next
struct utf8_char * next
Definition widget_edit.c:37
utf8_char::prev
struct utf8_char * prev
Definition widget_edit.c:38
utf8_char::bytes
int bytes
Definition widget_edit.c:39
utf8_char::tsurf
SDL_Surface * tsurf
Definition widget_edit.c:41
utf8_char::chr
char chr[7]
Definition widget_edit.c:40
utf8_str
Definition gui_string.h:52
utf8_str::style
Uint8 style
Definition gui_string.h:53
widget
Definition widget.h:112
widget::key
SDL_Keycode key
Definition widget.h:153
widget::theme
SDL_Surface * theme
Definition widget.h:118
widget::theme2
SDL_Surface * theme2
Definition widget.h:119
widget::redraw
int(* redraw)(struct widget *pwidget)
Definition widget.h:163
widget::dst
struct gui_layer * dst
Definition widget.h:116
widget::mod
Uint16 mod
Definition widget.h:154
widget::string_utf8
utf8_str * string_utf8
Definition widget.h:121
widget::size
SDL_Rect size
Definition widget.h:145
widget::data
union widget::@217 data
TRUE
#define TRUE
Definition support.h:46
FALSE
#define FALSE
Definition support.h:47