mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r13191) -Fix: segfault after confirming query subwindow in the Generate New World window
This commit is contained in:
parent
5cedf77a9a
commit
f244b6b361
|
@ -1121,11 +1121,11 @@ enum QueryWidgets {
|
||||||
* Window used for asking the user a YES/NO question.
|
* Window used for asking the user a YES/NO question.
|
||||||
*/
|
*/
|
||||||
struct QueryWindow : public Window {
|
struct QueryWindow : public Window {
|
||||||
void (*proc)(Window*, bool); ///< callback function executed on closing of popup. Window* points to parent, bool is true if 'yes' clicked, false otherwise
|
QueryCallbackProc *proc; ///< callback function executed on closing of popup. Window* points to parent, bool is true if 'yes' clicked, false otherwise
|
||||||
uint64 params[10]; ///< local copy of _decode_parameters
|
uint64 params[10]; ///< local copy of _decode_parameters
|
||||||
StringID message; ///< message shown for query window
|
StringID message; ///< message shown for query window
|
||||||
|
|
||||||
QueryWindow(const WindowDesc *desc, StringID caption, StringID message, Window *parent, void (*callback)(Window*, bool)) : Window(desc)
|
QueryWindow(const WindowDesc *desc, StringID caption, StringID message, Window *parent, QueryCallbackProc *callback) : Window(desc)
|
||||||
{
|
{
|
||||||
if (parent == NULL) parent = FindWindowById(WC_MAIN_WINDOW, 0);
|
if (parent == NULL) parent = FindWindowById(WC_MAIN_WINDOW, 0);
|
||||||
this->parent = parent;
|
this->parent = parent;
|
||||||
|
@ -1159,12 +1159,17 @@ struct QueryWindow : public Window {
|
||||||
virtual void OnClick(Point pt, int widget)
|
virtual void OnClick(Point pt, int widget)
|
||||||
{
|
{
|
||||||
switch (widget) {
|
switch (widget) {
|
||||||
case QUERY_WIDGET_YES:
|
case QUERY_WIDGET_YES: {
|
||||||
if (this->proc != NULL) {
|
/* in the Generate New World window, clicking 'Yes' causes
|
||||||
this->proc(this->parent, true);
|
* DeleteNonVitalWindows() to be called - we shouldn't be in a window then */
|
||||||
this->proc = NULL;
|
QueryCallbackProc *proc = this->proc;
|
||||||
|
Window *parent = this->parent;
|
||||||
|
delete this;
|
||||||
|
if (proc != NULL) {
|
||||||
|
proc(parent, true);
|
||||||
|
proc = NULL;
|
||||||
}
|
}
|
||||||
/* Fallthrough */
|
} break;
|
||||||
case QUERY_WIDGET_NO:
|
case QUERY_WIDGET_NO:
|
||||||
delete this;
|
delete this;
|
||||||
break;
|
break;
|
||||||
|
@ -1215,7 +1220,7 @@ static const WindowDesc _query_desc = {
|
||||||
* @param parent pointer to parent window, if this pointer is NULL the parent becomes
|
* @param parent pointer to parent window, if this pointer is NULL the parent becomes
|
||||||
* the main window WC_MAIN_WINDOW
|
* the main window WC_MAIN_WINDOW
|
||||||
* @param callback callback function pointer to set in the window descriptor*/
|
* @param callback callback function pointer to set in the window descriptor*/
|
||||||
void ShowQuery(StringID caption, StringID message, Window *parent, void (*callback)(Window*, bool))
|
void ShowQuery(StringID caption, StringID message, Window *parent, QueryCallbackProc *callback)
|
||||||
{
|
{
|
||||||
new QueryWindow(&_query_desc, caption, message, parent, callback);
|
new QueryWindow(&_query_desc, caption, message, parent, callback);
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,8 +28,10 @@ bool MoveTextBufferPos(Textbuf *tb, int navmode);
|
||||||
void InitializeTextBuffer(Textbuf *tb, const char *buf, uint16 maxlength, uint16 maxwidth);
|
void InitializeTextBuffer(Textbuf *tb, const char *buf, uint16 maxlength, uint16 maxwidth);
|
||||||
void UpdateTextBufferSize(Textbuf *tb);
|
void UpdateTextBufferSize(Textbuf *tb);
|
||||||
|
|
||||||
|
typedef void QueryCallbackProc(Window*, bool);
|
||||||
|
|
||||||
void ShowQueryString(StringID str, StringID caption, uint maxlen, uint maxwidth, Window *parent, CharSetFilter afilter);
|
void ShowQueryString(StringID str, StringID caption, uint maxlen, uint maxwidth, Window *parent, CharSetFilter afilter);
|
||||||
void ShowQuery(StringID caption, StringID message, Window *w, void (*callback)(Window*, bool));
|
void ShowQuery(StringID caption, StringID message, Window *w, QueryCallbackProc *callback);
|
||||||
|
|
||||||
/** The number of 'characters' on the on-screen keyboard. */
|
/** The number of 'characters' on the on-screen keyboard. */
|
||||||
static const uint OSK_KEYBOARD_ENTRIES = 50;
|
static const uint OSK_KEYBOARD_ENTRIES = 50;
|
||||||
|
|
Loading…
Reference in New Issue