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)
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 ***********************************************************************/
15 #include <fc_config.h>
19 #ifdef SDL2_PLAIN_INCLUDE
21 #else /* SDL2_PLAIN_INCLUDE */
23 #endif /* SDL2_PLAIN_INCLUDE */
28 #include "gui_iconv.h"
30 #include "gui_tilespec.h"
32 #include "themespec.h"
33 #include "unistring.h"
34 #include "utf8string.h"
39 struct Utf8Char
*next
;
40 struct Utf8Char
*prev
;
47 struct Utf8Char
*pBeginTextChain
;
48 struct Utf8Char
*pEndTextChain
;
49 struct Utf8Char
*pInputChain
;
51 struct widget
*pWidget
;
58 static size_t chainlen(const struct Utf8Char
*pChain
);
59 static void del_chain(struct Utf8Char
*pChain
);
60 static struct Utf8Char
*text2chain(const char *text_in
);
61 static char *chain2text(const struct Utf8Char
*pInChain
, size_t len
, size_t *size
);
63 static int (*baseclass_redraw
)(struct widget
*pwidget
);
65 /**************************************************************************
66 Draw the text being edited.
67 **************************************************************************/
68 static int redraw_edit_chain(struct EDIT
*pEdt
)
70 struct Utf8Char
*pInputChain_TMP
;
71 SDL_Rect Dest
, Dest_Copy
= {0, 0, 0, 0};
75 Dest_Copy
.x
= pEdt
->pWidget
->size
.x
;
76 Dest_Copy
.y
= pEdt
->pWidget
->size
.y
;
78 ret
= (*baseclass_redraw
)(pEdt
->pWidget
);
86 alphablit(pEdt
->pBg
, NULL
, pEdt
->pWidget
->dst
->surface
, &Dest
, 255);
88 /* set start parameters */
89 pInputChain_TMP
= pEdt
->pBeginTextChain
;
92 Dest_Copy
.y
+= (pEdt
->pBg
->h
- pInputChain_TMP
->pTsurf
->h
) / 2;
93 Dest_Copy
.x
+= pEdt
->Start_X
;
96 while (pInputChain_TMP
) {
97 Dest_Copy
.x
+= iStart_Mod_X
;
98 /* chech if we draw inside of edit rect */
99 if (Dest_Copy
.x
> pEdt
->pWidget
->size
.x
+ pEdt
->pBg
->w
- 4) {
103 if (Dest_Copy
.x
> pEdt
->pWidget
->size
.x
) {
105 alphablit(pInputChain_TMP
->pTsurf
, NULL
, pEdt
->pWidget
->dst
->surface
, &Dest
,
109 iStart_Mod_X
= pInputChain_TMP
->pTsurf
->w
;
112 if (pInputChain_TMP
== pEdt
->pInputChain
) {
115 create_line(pEdt
->pWidget
->dst
->surface
,
116 Dest
.x
- 1, Dest
.y
+ (pEdt
->pBg
->h
/ 8),
117 Dest
.x
- 1, Dest
.y
+ pEdt
->pBg
->h
- (pEdt
->pBg
->h
/ 4),
118 get_theme_color(COLOR_THEME_EDITFIELD_CARET
));
119 /* save active element position */
120 pEdt
->InputChain_X
= Dest_Copy
.x
;
123 pInputChain_TMP
= pInputChain_TMP
->next
;
124 } /* while - draw loop */
126 widget_flush(pEdt
->pWidget
);
131 /**************************************************************************
132 Create Edit Field surface ( with Text) and blit them to Main.screen,
133 on position 'pEdit_Widget->size.x , pEdit_Widget->size.y'
135 Graphic is taken from 'pEdit_Widget->theme'
136 Text is taken from 'pEdit_Widget->string_utf8'
138 if flag 'FW_DRAW_THEME_TRANSPARENT' is set theme will be blit
139 transparent ( Alpha = 128 )
141 function return Hight of created surfaces or (-1) if theme surface can't
143 **************************************************************************/
144 static int redraw_edit(struct widget
*pEdit_Widget
)
148 if (get_wstate(pEdit_Widget
) == FC_WS_PRESSED
) {
149 return redraw_edit_chain((struct EDIT
*)pEdit_Widget
->data
.ptr
);
152 SDL_Rect rDest
= {pEdit_Widget
->size
.x
, pEdit_Widget
->size
.y
, 0, 0};
153 SDL_Surface
*pEdit
= NULL
;
156 ret
= (*baseclass_redraw
)(pEdit_Widget
);
161 if (pEdit_Widget
->string_utf8
->text
!= NULL
162 && get_wflags(pEdit_Widget
) & WF_PASSWD_EDIT
) {
163 char *backup
= pEdit_Widget
->string_utf8
->text
;
164 size_t len
= strlen(backup
) + 1;
165 char *cbuf
= fc_calloc(1, len
);
167 memset(cbuf
, '*', len
- 1);
168 cbuf
[len
- 1] = '\0';
169 pEdit_Widget
->string_utf8
->text
= cbuf
;
170 pText
= create_text_surf_from_utf8(pEdit_Widget
->string_utf8
);
172 pEdit_Widget
->string_utf8
->text
= backup
;
174 pText
= create_text_surf_from_utf8(pEdit_Widget
->string_utf8
);
177 pEdit
= create_bcgnd_surf(pEdit_Widget
->theme
, get_wstate(pEdit_Widget
),
178 pEdit_Widget
->size
.w
, pEdit_Widget
->size
.h
);
185 alphablit(pEdit
, NULL
, pEdit_Widget
->dst
->surface
, &rDest
, 255);
187 /* set position and blit text */
189 rDest
.y
+= (pEdit
->h
- pText
->h
) / 2;
190 /* blit centred text to botton */
191 if (pEdit_Widget
->string_utf8
->style
& SF_CENTER
) {
192 rDest
.x
+= (pEdit
->w
- pText
->w
) / 2;
194 if (pEdit_Widget
->string_utf8
->style
& SF_CENTER_RIGHT
) {
195 rDest
.x
+= pEdit
->w
- pText
->w
- adj_size(5);
197 rDest
.x
+= adj_size(5); /* center left */
201 alphablit(pText
, NULL
, pEdit_Widget
->dst
->surface
, &rDest
, 255);
216 /**************************************************************************
217 Return length of Utf8Char chain.
218 WARRNING: if struct Utf8Char has 1 member and Utf8Char->chr == 0 then
219 this function return 1 ( not 0 like in strlen )
220 **************************************************************************/
221 static size_t chainlen(const struct Utf8Char
*pChain
)
228 if (pChain
->next
== NULL
) {
231 pChain
= pChain
->next
;
238 /**************************************************************************
239 Delete Utf8Char structure.
240 **************************************************************************/
241 static void del_chain(struct Utf8Char
*pChain
)
249 len
= chainlen(pChain
);
252 pChain
= pChain
->next
;
253 for (i
= 0; i
< len
- 1; i
++) {
254 FREESURFACE(pChain
->prev
->pTsurf
);
255 FC_FREE(pChain
->prev
);
256 pChain
= pChain
->next
;
263 /**************************************************************************
264 Convert utf8 string to Utf8Char structure.
265 Memory alocation -> after all use need call del_chain(...) !
266 **************************************************************************/
267 static struct Utf8Char
*text2chain(const char *text_in
)
270 struct Utf8Char
*out_chain
= NULL
;
271 struct Utf8Char
*chr_tmp
= NULL
;
274 if (text_in
== NULL
) {
278 len
= strlen(text_in
);
284 out_chain
= fc_calloc(1, sizeof(struct Utf8Char
));
285 out_chain
->chr
[0] = text_in
[0];
286 for (j
= 1; (text_in
[j
] & (128 + 64)) == 128; j
++) {
287 out_chain
->chr
[j
] = text_in
[j
];
289 out_chain
->bytes
= j
;
292 for (i
= 1; i
< len
; i
+= j
) {
293 chr_tmp
->next
= fc_calloc(1, sizeof(struct Utf8Char
));
294 chr_tmp
->next
->chr
[0] = text_in
[i
];
295 for (j
= 1; (text_in
[i
+ j
] & (128 + 64)) == 128; j
++) {
296 chr_tmp
->next
->chr
[j
] = text_in
[i
+ j
];
298 chr_tmp
->next
->bytes
= j
;
299 chr_tmp
->next
->prev
= chr_tmp
;
300 chr_tmp
= chr_tmp
->next
;
306 /**************************************************************************
307 Convert Utf8Char structure to chars
308 WARNING: Do not free Utf8Char structure but allocates new char array.
309 **************************************************************************/
310 static char *chain2text(const struct Utf8Char
*pInChain
, size_t len
,
314 char *pOutText
= NULL
;
318 if (!(len
&& pInChain
)) {
322 pOutText
= fc_calloc(8, len
+ 1);
323 for (i
= 0; i
< len
; i
++) {
326 for (j
= 0; j
< pInChain
->bytes
&& i
< len
; j
++) {
327 pOutText
[oi
++] = pInChain
->chr
[j
];
330 total_size
+= pInChain
->bytes
;
331 pInChain
= pInChain
->next
;
339 /* =================================================== */
341 /**************************************************************************
342 Create ( malloc ) Edit Widget structure.
344 Edit Theme graphic is taken from current_theme->Edit surface;
345 Text is taken from 'pstr'.
347 'length' parameter determinate width of Edit rect.
349 This function determinate future size of Edit ( width, height ) and
350 save this in: pWidget->size rectangle ( SDL_Rect )
352 function return pointer to allocated Edit Widget.
353 **************************************************************************/
354 struct widget
*create_edit(SDL_Surface
*pBackground
, struct gui_layer
*pDest
,
355 utf8_str
*pstr
, int length
, Uint32 flags
)
357 SDL_Rect buf
= {0, 0, 0, 0};
358 struct widget
*pEdit
= widget_new();
360 pEdit
->theme
= current_theme
->Edit
;
361 pEdit
->theme2
= pBackground
; /* FIXME: make somewhere use of it */
362 pEdit
->string_utf8
= pstr
;
363 set_wflag(pEdit
, (WF_FREE_STRING
| WF_FREE_GFX
| flags
));
364 set_wstate(pEdit
, FC_WS_DISABLED
);
365 set_wtype(pEdit
, WT_EDIT
);
366 pEdit
->mod
= KMOD_NONE
;
368 baseclass_redraw
= pEdit
->redraw
;
369 pEdit
->redraw
= redraw_edit
;
372 pEdit
->string_utf8
->style
|= SF_CENTER
;
373 utf8_str_size(pstr
, &buf
);
374 buf
.h
+= adj_size(4);
377 length
= MAX(length
, buf
.w
+ adj_size(10));
379 correct_size_bcgnd_surf(current_theme
->Edit
, &length
, &buf
.h
);
381 pEdit
->size
.w
= length
;
382 pEdit
->size
.h
= buf
.h
;
387 pEdit
->dst
= add_gui_layer(pEdit
->size
.w
, pEdit
->size
.h
);
393 /**************************************************************************
394 set new x, y position and redraw edit.
395 **************************************************************************/
396 int draw_edit(struct widget
*pEdit
, Sint16 start_x
, Sint16 start_y
)
398 pEdit
->size
.x
= start_x
;
399 pEdit
->size
.y
= start_y
;
401 if (get_wflags(pEdit
) & WF_RESTORE_BACKGROUND
) {
402 refresh_widget_background(pEdit
);
405 return redraw_edit(pEdit
);
408 /**************************************************************************
409 This functions are pure madness :)
410 Create Edit Field surface ( with Text) and blit them to Main.screen,
411 on position 'pEdit_Widget->size.x , pEdit_Widget->size.y'
413 Main role of this functions are been text input to GUI.
414 This code allow you to add, del unichar from unistring.
416 Graphic is taken from 'pEdit_Widget->theme'
417 OldText is taken from 'pEdit_Widget->string_utf8'
419 NewText is returned to 'pEdit_Widget->string_utf8' ( after free OldText )
421 if flag 'FW_DRAW_THEME_TRANSPARENT' is set theme will be blit
422 transparent ( Alpha = 128 )
424 NOTE: This functions can return NULL in 'pEdit_Widget->string_utf8->text' but
425 never free 'pEdit_Widget->string_utf8' struct.
426 **************************************************************************/
427 static Uint16
edit_key_down(SDL_Keysym key
, void *pData
)
429 struct EDIT
*pEdt
= (struct EDIT
*)pData
;
430 struct Utf8Char
*pInputChain_TMP
;
433 /* find which key is pressed */
436 /* exit from loop without changes */
444 if (key.mod & KMOD_NUM) {
450 /* move cursor right */
451 if (pEdt
->pInputChain
->next
) {
452 if (pEdt
->InputChain_X
>= (pEdt
->pWidget
->size
.x
+ pEdt
->pBg
->w
- adj_size(10))) {
453 pEdt
->Start_X
-= pEdt
->pInputChain
->pTsurf
->w
-
454 (pEdt
->pWidget
->size
.x
+ pEdt
->pBg
->w
- adj_size(5) - pEdt
->InputChain_X
);
457 pEdt
->pInputChain
= pEdt
->pInputChain
->next
;
464 if (key.mod & KMOD_NUM) {
470 /* move cursor left */
471 if (pEdt
->pInputChain
->prev
) {
472 pEdt
->pInputChain
= pEdt
->pInputChain
->prev
;
473 if ((pEdt
->InputChain_X
<=
474 (pEdt
->pWidget
->size
.x
+ adj_size(9))) && (pEdt
->Start_X
!= adj_size(5))) {
475 if (pEdt
->InputChain_X
!= (pEdt
->pWidget
->size
.x
+ adj_size(5))) {
476 pEdt
->Start_X
+= (pEdt
->pWidget
->size
.x
- pEdt
->InputChain_X
+ adj_size(5));
479 pEdt
->Start_X
+= (pEdt
->pInputChain
->pTsurf
->w
);
487 if (key.mod & KMOD_NUM) {
493 /* move cursor to begin of chain (and edit field) */
494 pEdt
->pInputChain
= pEdt
->pBeginTextChain
;
496 pEdt
->Start_X
= adj_size(5);
501 if (key.mod & KMOD_NUM) {
507 /* move cursor to end of chain (and edit field) */
508 pEdt
->pInputChain
= pEdt
->pEndTextChain
;
511 if (pEdt
->pWidget
->size
.w
- pEdt
->Truelength
< 0) {
512 pEdt
->Start_X
= pEdt
->pWidget
->size
.w
- pEdt
->Truelength
- adj_size(5);
518 /* del element of chain (and move cursor left) */
519 if (pEdt
->pInputChain
->prev
) {
520 if ((pEdt
->InputChain_X
<=
521 (pEdt
->pWidget
->size
.x
+ adj_size(9))) && (pEdt
->Start_X
!= adj_size(5))) {
522 if (pEdt
->InputChain_X
!= (pEdt
->pWidget
->size
.x
+ adj_size(5))) {
523 pEdt
->Start_X
+= (pEdt
->pWidget
->size
.x
- pEdt
->InputChain_X
+ adj_size(5));
525 pEdt
->Start_X
+= (pEdt
->pInputChain
->prev
->pTsurf
->w
);
528 if (pEdt
->pInputChain
->prev
->prev
) {
529 pEdt
->pInputChain
->prev
->prev
->next
= pEdt
->pInputChain
;
530 pInputChain_TMP
= pEdt
->pInputChain
->prev
->prev
;
531 pEdt
->Truelength
-= pEdt
->pInputChain
->prev
->pTsurf
->w
;
532 FREESURFACE(pEdt
->pInputChain
->prev
->pTsurf
);
533 FC_FREE(pEdt
->pInputChain
->prev
);
534 pEdt
->pInputChain
->prev
= pInputChain_TMP
;
536 pEdt
->Truelength
-= pEdt
->pInputChain
->prev
->pTsurf
->w
;
537 FREESURFACE(pEdt
->pInputChain
->prev
->pTsurf
);
538 FC_FREE(pEdt
->pInputChain
->prev
);
539 pEdt
->pBeginTextChain
= pEdt
->pInputChain
;
549 if (key.mod & KMOD_NUM) {
555 /* del element of chain */
556 if (pEdt
->pInputChain
->next
&& pEdt
->pInputChain
->prev
) {
557 pEdt
->pInputChain
->prev
->next
= pEdt
->pInputChain
->next
;
558 pEdt
->pInputChain
->next
->prev
= pEdt
->pInputChain
->prev
;
559 pInputChain_TMP
= pEdt
->pInputChain
->next
;
560 pEdt
->Truelength
-= pEdt
->pInputChain
->pTsurf
->w
;
561 FREESURFACE(pEdt
->pInputChain
->pTsurf
);
562 FC_FREE(pEdt
->pInputChain
);
563 pEdt
->pInputChain
= pInputChain_TMP
;
568 if (pEdt
->pInputChain
->next
&& !pEdt
->pInputChain
->prev
) {
569 pEdt
->pInputChain
= pEdt
->pInputChain
->next
;
570 pEdt
->Truelength
-= pEdt
->pInputChain
->prev
->pTsurf
->w
;
571 FREESURFACE(pEdt
->pInputChain
->prev
->pTsurf
);
572 FC_FREE(pEdt
->pInputChain
->prev
);
573 pEdt
->pBeginTextChain
= pEdt
->pInputChain
;
581 } /* key pressed switch */
584 redraw_edit_chain(pEdt
);
590 /**************************************************************************
591 Handle textinput strings coming to the edit widget
592 **************************************************************************/
593 static Uint16
edit_textinput(char *text
, void *pData
)
595 struct EDIT
*pEdt
= (struct EDIT
*)pData
;
596 struct Utf8Char
*pInputChain_TMP
;
599 for (i
= 0; text
[i
] != '\0';) {
601 unsigned char leading
= text
[i
++];
605 /* add new element of chain (and move cursor right) */
606 if (pEdt
->pInputChain
!= pEdt
->pBeginTextChain
) {
607 pInputChain_TMP
= pEdt
->pInputChain
->prev
;
608 pEdt
->pInputChain
->prev
= fc_calloc(1, sizeof(struct Utf8Char
));
609 pEdt
->pInputChain
->prev
->next
= pEdt
->pInputChain
;
610 pEdt
->pInputChain
->prev
->prev
= pInputChain_TMP
;
611 pInputChain_TMP
->next
= pEdt
->pInputChain
->prev
;
613 pEdt
->pInputChain
->prev
= fc_calloc(1, sizeof(struct Utf8Char
));
614 pEdt
->pInputChain
->prev
->next
= pEdt
->pInputChain
;
615 pEdt
->pBeginTextChain
= pEdt
->pInputChain
->prev
;
618 pEdt
->pInputChain
->prev
->chr
[0] = leading
;
619 /* UTF-8 multibyte handling */
620 while (leading
>= sum
) {
621 pEdt
->pInputChain
->prev
->chr
[charlen
++] = text
[i
++];
625 pEdt
->pInputChain
->prev
->chr
[charlen
] = '\0';
626 pEdt
->pInputChain
->prev
->bytes
= charlen
;
628 if (get_wflags(pEdt
->pWidget
) & WF_PASSWD_EDIT
) {
629 char passwd_chr
[2] = {'*', '\0'};
631 pEdt
->pInputChain
->prev
->pTsurf
=
632 TTF_RenderUTF8_Blended(pEdt
->pWidget
->string_utf8
->font
,
634 pEdt
->pWidget
->string_utf8
->fgcol
);
636 pEdt
->pInputChain
->prev
->pTsurf
=
637 TTF_RenderUTF8_Blended(pEdt
->pWidget
->string_utf8
->font
,
638 pEdt
->pInputChain
->prev
->chr
,
639 pEdt
->pWidget
->string_utf8
->fgcol
);
641 pEdt
->Truelength
+= pEdt
->pInputChain
->prev
->pTsurf
->w
;
643 if (pEdt
->InputChain_X
>= pEdt
->pWidget
->size
.x
+ pEdt
->pBg
->w
- adj_size(10)) {
644 if (pEdt
->pInputChain
== pEdt
->pEndTextChain
) {
645 pEdt
->Start_X
= pEdt
->pBg
->w
- adj_size(5) - pEdt
->Truelength
;
647 pEdt
->Start_X
-= pEdt
->pInputChain
->prev
->pTsurf
->w
-
648 (pEdt
->pWidget
->size
.x
+ pEdt
->pBg
->w
- adj_size(5) - pEdt
->InputChain_X
);
655 redraw_edit_chain(pEdt
);
660 /**************************************************************************
661 Handle mouse down events on edit widget.
662 **************************************************************************/
663 static Uint16
edit_mouse_button_down(SDL_MouseButtonEvent
*pButtonEvent
,
666 struct EDIT
*pEdt
= (struct EDIT
*)pData
;
668 if (pButtonEvent
->button
== SDL_BUTTON_LEFT
) {
669 if (!(pButtonEvent
->x
>= pEdt
->pWidget
->size
.x
670 && pButtonEvent
->x
< pEdt
->pWidget
->size
.x
+ pEdt
->pBg
->w
671 && pButtonEvent
->y
>= pEdt
->pWidget
->size
.y
672 && pButtonEvent
->y
< pEdt
->pWidget
->size
.y
+ pEdt
->pBg
->h
)) {
674 return (Uint16
)ED_MOUSE
;
678 return (Uint16
)ID_ERROR
;
681 /**************************************************************************
682 Handle active edit. Returns what should happen to the edit
684 **************************************************************************/
685 enum Edit_Return_Codes
edit_field(struct widget
*pEdit_Widget
)
688 struct Utf8Char ___last
;
689 struct Utf8Char
*pInputChain_TMP
= NULL
;
690 enum Edit_Return_Codes ret
;
691 void *backup
= pEdit_Widget
->data
.ptr
;
693 pEdt
.pWidget
= pEdit_Widget
;
696 pEdt
.Start_X
= adj_size(5);
697 pEdt
.InputChain_X
= 0;
699 pEdit_Widget
->data
.ptr
= (void *)&pEdt
;
702 SDL_EnableUNICODE(1);
703 SDL_EnableKeyRepeat(SDL_DEFAULT_REPEAT_DELAY
, SDL_DEFAULT_REPEAT_INTERVAL
);
706 pEdt
.pBg
= create_bcgnd_surf(pEdit_Widget
->theme
, 2,
707 pEdit_Widget
->size
.w
, pEdit_Widget
->size
.h
);
710 pEdt
.pBeginTextChain
= text2chain(pEdit_Widget
->string_utf8
->text
);
712 /* Creating Empty (Last) pice of Chain */
713 pEdt
.pInputChain
= &___last
;
714 pEdt
.pEndTextChain
= pEdt
.pInputChain
;
715 pEdt
.pEndTextChain
->chr
[0] = 32; /* spacebar */
716 pEdt
.pEndTextChain
->chr
[1] = 0; /* spacebar */
717 pEdt
.pEndTextChain
->next
= NULL
;
718 pEdt
.pEndTextChain
->prev
= NULL
;
720 /* set font style (if any ) */
721 if (!((pEdit_Widget
->string_utf8
->style
& 0x0F) & TTF_STYLE_NORMAL
)) {
722 TTF_SetFontStyle(pEdit_Widget
->string_utf8
->font
,
723 (pEdit_Widget
->string_utf8
->style
& 0x0F));
726 pEdt
.pEndTextChain
->pTsurf
=
727 TTF_RenderUTF8_Blended(pEdit_Widget
->string_utf8
->font
,
728 pEdt
.pEndTextChain
->chr
,
729 pEdit_Widget
->string_utf8
->fgcol
);
731 /* create surface for each font in chain and find chain length */
732 if (pEdt
.pBeginTextChain
) {
733 pInputChain_TMP
= pEdt
.pBeginTextChain
;
738 if (get_wflags(pEdit_Widget
) & WF_PASSWD_EDIT
) {
739 const char passwd_chr
[2] = {'*', '\0'};
741 pInputChain_TMP
->pTsurf
=
742 TTF_RenderUTF8_Blended(pEdit_Widget
->string_utf8
->font
,
744 pEdit_Widget
->string_utf8
->fgcol
);
746 pInputChain_TMP
->pTsurf
=
747 TTF_RenderUTF8_Blended(pEdit_Widget
->string_utf8
->font
,
748 pInputChain_TMP
->chr
,
749 pEdit_Widget
->string_utf8
->fgcol
);
752 pEdt
.Truelength
+= pInputChain_TMP
->pTsurf
->w
;
754 if (pInputChain_TMP
->next
== NULL
) {
758 pInputChain_TMP
= pInputChain_TMP
->next
;
760 /* set terminator of list */
761 pInputChain_TMP
->next
= pEdt
.pInputChain
;
762 pEdt
.pInputChain
->prev
= pInputChain_TMP
;
763 pInputChain_TMP
= NULL
;
765 pEdt
.pBeginTextChain
= pEdt
.pInputChain
;
768 redraw_edit_chain(&pEdt
);
770 set_wstate(pEdit_Widget
, FC_WS_PRESSED
);
773 Uint16 rety
= gui_event_loop((void *)&pEdt
, NULL
,
774 edit_key_down
, NULL
, edit_textinput
,
775 edit_mouse_button_down
, NULL
, NULL
);
777 if (pEdt
.pBeginTextChain
== pEdt
.pEndTextChain
) {
778 pEdt
.pBeginTextChain
= NULL
;
781 if (rety
== MAX_ID
) {
784 ret
= (enum Edit_Return_Codes
) rety
;
786 /* this is here because we have no knowledge that pEdit_Widget exist
787 or nor in force exit mode from gui loop */
789 /* reset font settings */
790 if (!((pEdit_Widget
->string_utf8
->style
& 0x0F) & TTF_STYLE_NORMAL
)) {
791 TTF_SetFontStyle(pEdit_Widget
->string_utf8
->font
, TTF_STYLE_NORMAL
);
797 FC_FREE(pEdit_Widget
->string_utf8
->text
);
798 pEdit_Widget
->string_utf8
->text
=
799 chain2text(pEdt
.pBeginTextChain
, pEdt
.ChainLen
, &len
);
800 pEdit_Widget
->string_utf8
->n_alloc
= len
+ 1;
803 pEdit_Widget
->data
.ptr
= backup
;
804 set_wstate(pEdit_Widget
, FC_WS_NORMAL
);
808 FREESURFACE(pEdt
.pEndTextChain
->pTsurf
);
810 del_chain(pEdt
.pBeginTextChain
);
812 FREESURFACE(pEdt
.pBg
);
814 /* disable repeat key */
817 SDL_EnableKeyRepeat(0, SDL_DEFAULT_REPEAT_INTERVAL
);
819 /* disable Unicode */
820 SDL_EnableUNICODE(0);