--- a/src/osk_gui.cpp Mon May 19 14:14:33 2008 +0000
+++ b/src/osk_gui.cpp Mon May 19 15:13:58 2008 +0000
@@ -42,6 +42,7 @@
static byte _keystate = KEYS_NONE;
struct OskWindow : public Window {
+ StringID caption; ///< the caption for this window.
QueryString *qs; ///< text-input
int text_btn; ///< widget number of parent's text field
int ok_btn; ///< widget number of parent's ok button (=0 when ok shouldn't be passed on)
@@ -54,7 +55,7 @@
this->parent = parent;
assert(parent != NULL);
- if (parent->widget[button].data != 0) parent->caption = parent->widget[button].data;
+ this->caption = (parent->widget[button].data != STR_NULL) ? parent->widget[button].data : parent->caption;
this->qs = parent;
this->text_btn = button;
@@ -96,8 +97,8 @@
this->ChangeOskDiabledState(shift);
- SetDParam(0, this->qs->caption);
- DrawWindowWidgets(this);
+ SetDParam(0, this->caption);
+ this->DrawWidgets();
for (uint i = 0; i < OSK_KEYBOARD_ENTRIES; i++) {
DrawCharCentered(_keyboard[shift][i],
@@ -129,6 +130,8 @@
return;
}
+ bool delete_this = false;
+
switch (widget) {
case OSK_WIDGET_BACKSPACE:
if (DeleteTextBufferChar(&this->qs->text, WKC_BACKSPACE)) this->InvalidateWidget(OSK_WIDGET_TEXT);
@@ -169,25 +172,29 @@
/* pass information by simulating a button press on parent window */
if (this->ok_btn != 0) {
this->parent->OnClick(pt, this->ok_btn);
+ /* Window gets deleted when the parent window removes itself. */
+ return;
}
}
- delete this;
+ delete_this = true;
break;
case OSK_WIDGET_CANCEL:
if (this->cancel_btn != 0) { // pass a cancel event to the parent window
this->parent->OnClick(pt, this->cancel_btn);
/* Window gets deleted when the parent window removes itself. */
+ return;
} else { // or reset to original string
strcpy(qs->text.buf, this->orig_str_buf);
UpdateTextBufferSize(&qs->text);
MoveTextBufferPos(&qs->text, WKC_END);
- delete this;
+ delete_this = true;
}
break;
}
/* make sure that the parent window's textbox also gets updated */
if (this->parent != NULL) this->parent->InvalidateWidget(this->text_btn);
+ if (delete_this) delete this;
}
virtual void OnMouseLoop()
@@ -276,12 +283,11 @@
{ WIDGETS_END},
};
-WindowDesc _osk_desc = {
+static const WindowDesc _osk_desc = {
WDP_CENTER, WDP_CENTER, 256, 140, 256, 140,
WC_OSK, WC_NONE,
WDF_STD_TOOLTIPS | WDF_STD_BTN | WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS,
_osk_widgets,
- NULL
};
/**
@@ -339,7 +345,7 @@
}
/**
- * Show the osk associated with a given textbox
+ * Show the on-screen keyboard (osk) associated with a given textbox
* @param parent pointer to the Window where this keyboard originated from
* @param q querystr_d pointer to the query string of the parent, which is
* shared for both windows