summaryrefslogtreecommitdiff
path: root/src/ui/inputwidget.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ui/inputwidget.c')
-rw-r--r--src/ui/inputwidget.c46
1 files changed, 28 insertions, 18 deletions
diff --git a/src/ui/inputwidget.c b/src/ui/inputwidget.c
index dd8fa744..4b5cd623 100644
--- a/src/ui/inputwidget.c
+++ b/src/ui/inputwidget.c
@@ -107,6 +107,24 @@ static void showCursor_InputWidget_(iInputWidget *d) {
107 d->cursorVis = 2; 107 d->cursorVis = 2;
108} 108}
109 109
110static void invalidateBuffered_InputWidget_(iInputWidget *d) {
111 if (d->buffered) {
112 delete_TextBuf(d->buffered);
113 d->buffered = NULL;
114 }
115}
116
117static void updateMetrics_InputWidget_(iInputWidget *d) {
118 iWidget *w = as_Widget(d);
119 /* Caller must arrange the width, but the height is fixed. */
120 w->rect.size.y = lineHeight_Text(default_FontId) + 2 * gap_UI;
121#if defined (iPlatformAppleMobile)
122 w->rect.size.y += 2 * gap_UI;
123#endif
124 invalidateBuffered_InputWidget_(d);
125 arrange_Widget(w);
126}
127
110void init_InputWidget(iInputWidget *d, size_t maxLen) { 128void init_InputWidget(iInputWidget *d, size_t maxLen) {
111 iWidget *w = &d->widget; 129 iWidget *w = &d->widget;
112 init_Widget(w); 130 init_Widget(w);
@@ -115,24 +133,20 @@ void init_InputWidget(iInputWidget *d, size_t maxLen) {
115 init_Array(&d->oldText, sizeof(iChar)); 133 init_Array(&d->oldText, sizeof(iChar));
116 init_String(&d->hint); 134 init_String(&d->hint);
117 init_Array(&d->undoStack, sizeof(iInputUndo)); 135 init_Array(&d->undoStack, sizeof(iInputUndo));
118 d->font = uiInput_FontId | alwaysVariableFlag_FontId; 136 d->font = uiInput_FontId | alwaysVariableFlag_FontId;
119 d->leftPadding = 0; 137 d->leftPadding = 0;
120 d->rightPadding = 0; 138 d->rightPadding = 0;
121 d->cursor = 0; 139 d->cursor = 0;
122 d->lastCursor = 0; 140 d->lastCursor = 0;
123 d->inFlags = eatEscape_InputWidgetFlag; 141 d->inFlags = eatEscape_InputWidgetFlag;
124 iZap(d->mark); 142 iZap(d->mark);
125 setMaxLen_InputWidget(d, maxLen); 143 setMaxLen_InputWidget(d, maxLen);
126 /* Caller must arrange the width, but the height is fixed. */
127 w->rect.size.y = lineHeight_Text(default_FontId) + 2 * gap_UI;
128#if defined (iPlatformAppleMobile)
129 w->rect.size.y += 2 * gap_UI;
130#endif
131 setFlags_Widget(w, fixedHeight_WidgetFlag, iTrue); 144 setFlags_Widget(w, fixedHeight_WidgetFlag, iTrue);
132 init_Click(&d->click, d, SDL_BUTTON_LEFT); 145 init_Click(&d->click, d, SDL_BUTTON_LEFT);
133 d->timer = 0; 146 d->timer = 0;
134 d->cursorVis = 0; 147 d->cursorVis = 0;
135 d->buffered = NULL; 148 d->buffered = NULL;
149 updateMetrics_InputWidget_(d);
136} 150}
137 151
138void deinit_InputWidget(iInputWidget *d) { 152void deinit_InputWidget(iInputWidget *d) {
@@ -226,13 +240,6 @@ static iString *visText_InputWidget_(const iInputWidget *d) {
226 return text; 240 return text;
227} 241}
228 242
229static void invalidateBuffered_InputWidget_(iInputWidget *d) {
230 if (d->buffered) {
231 delete_TextBuf(d->buffered);
232 d->buffered = NULL;
233 }
234}
235
236static void updateBuffered_InputWidget_(iInputWidget *d) { 243static void updateBuffered_InputWidget_(iInputWidget *d) {
237 invalidateBuffered_InputWidget_(d); 244 invalidateBuffered_InputWidget_(d);
238 iString *visText = visText_InputWidget_(d); 245 iString *visText = visText_InputWidget_(d);
@@ -600,6 +607,9 @@ static iBool processEvent_InputWidget_(iInputWidget *d, const SDL_Event *ev) {
600 } 607 }
601 return iFalse; 608 return iFalse;
602 } 609 }
610 else if (isMetricsChange_UserEvent(ev)) {
611 updateMetrics_InputWidget_(d);
612 }
603 else if (isFocused_Widget(d) && isCommand_UserEvent(ev, "copy")) { 613 else if (isFocused_Widget(d) && isCommand_UserEvent(ev, "copy")) {
604 copy_InputWidget_(d, iFalse); 614 copy_InputWidget_(d, iFalse);
605 return iTrue; 615 return iTrue;