src/video/haiku/SDL_bmessagebox.cc
author EXL <exlmotodev@gmail.com>
Mon, 11 Nov 2019 16:44:40 -0500
changeset 13230 57ed423da32a
child 13238 007002587d5d
permissions -rw-r--r--
haiku: Implement message box for Haiku

Add implementation for functions:

SDL_ShowSimpleMessageBox()
SDL_ShowMessageBox()

Add simple customization support also.
Fix build for x86_gcc2.

Partially fixes Bugzilla #4442.
exlmotodev@13230
     1
/*
exlmotodev@13230
     2
  Simple DirectMedia Layer
exlmotodev@13230
     3
  Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
exlmotodev@13230
     4
  Copyright (C) 2018 EXL <exlmotodev@gmail.com>
exlmotodev@13230
     5
exlmotodev@13230
     6
  This software is provided 'as-is', without any express or implied
exlmotodev@13230
     7
  warranty.  In no event will the authors be held liable for any damages
exlmotodev@13230
     8
  arising from the use of this software.
exlmotodev@13230
     9
exlmotodev@13230
    10
  Permission is granted to anyone to use this software for any purpose,
exlmotodev@13230
    11
  including commercial applications, and to alter it and redistribute it
exlmotodev@13230
    12
  freely, subject to the following restrictions:
exlmotodev@13230
    13
exlmotodev@13230
    14
  1. The origin of this software must not be misrepresented; you must not
exlmotodev@13230
    15
     claim that you wrote the original software. If you use this software
exlmotodev@13230
    16
     in a product, an acknowledgment in the product documentation would be
exlmotodev@13230
    17
     appreciated but is not required.
exlmotodev@13230
    18
  2. Altered source versions must be plainly marked as such, and must not be
exlmotodev@13230
    19
     misrepresented as being the original software.
exlmotodev@13230
    20
  3. This notice may not be removed or altered from any source distribution.
exlmotodev@13230
    21
*/
exlmotodev@13230
    22
exlmotodev@13230
    23
#include "../../SDL_internal.h"
exlmotodev@13230
    24
exlmotodev@13230
    25
#if SDL_VIDEO_DRIVER_HAIKU
exlmotodev@13230
    26
exlmotodev@13230
    27
#include "SDL_messagebox.h"
exlmotodev@13230
    28
exlmotodev@13230
    29
/* For application signature. */
exlmotodev@13230
    30
#include "../../main/haiku/SDL_BeApp.h"
exlmotodev@13230
    31
exlmotodev@13230
    32
#include <Alert.h>
exlmotodev@13230
    33
#include <Application.h>
exlmotodev@13230
    34
#include <Button.h>
exlmotodev@13230
    35
#include <Font.h>
exlmotodev@13230
    36
#include <Layout.h>
exlmotodev@13230
    37
#include <String.h>
exlmotodev@13230
    38
#include <TextView.h>
exlmotodev@13230
    39
#include <View.h>
exlmotodev@13230
    40
#include <Window.h>
exlmotodev@13230
    41
exlmotodev@13230
    42
#include <InterfaceDefs.h>
exlmotodev@13230
    43
#include <SupportDefs.h>
exlmotodev@13230
    44
#include <GraphicsDefs.h>
exlmotodev@13230
    45
exlmotodev@13230
    46
#include <new>
exlmotodev@13230
    47
#include <vector>
exlmotodev@13230
    48
#include <algorithm>
exlmotodev@13230
    49
exlmotodev@13230
    50
enum
exlmotodev@13230
    51
{
exlmotodev@13230
    52
	G_CLOSE_BUTTON_ID   = -1,
exlmotodev@13230
    53
	G_DEFAULT_BUTTON_ID = 0,
exlmotodev@13230
    54
	G_MAX_STRING_LENGTH_BYTES = 120
exlmotodev@13230
    55
};
exlmotodev@13230
    56
exlmotodev@13230
    57
class BE_SDL_MessageBox : public BAlert
exlmotodev@13230
    58
{
exlmotodev@13230
    59
	float fComputedMessageBoxWidth;
exlmotodev@13230
    60
exlmotodev@13230
    61
	BTextView *fMessageBoxTextView;
exlmotodev@13230
    62
exlmotodev@13230
    63
	int fCloseButton;
exlmotodev@13230
    64
	int fDefaultButton;
exlmotodev@13230
    65
exlmotodev@13230
    66
	bool fCustomColorScheme;
exlmotodev@13230
    67
	bool fThereIsLongLine;
exlmotodev@13230
    68
	rgb_color fTextColor;
exlmotodev@13230
    69
exlmotodev@13230
    70
	const char *fTitle;
exlmotodev@13230
    71
	const char *BE_SDL_DefTitle;
exlmotodev@13230
    72
	const char *BE_SDL_DefMessage;
exlmotodev@13230
    73
	const char *BE_SDL_DefButton;
exlmotodev@13230
    74
exlmotodev@13230
    75
	std::vector<const SDL_MessageBoxButtonData *> fButtons;
exlmotodev@13230
    76
exlmotodev@13230
    77
	static bool
exlmotodev@13230
    78
	SortButtonsPredicate(const SDL_MessageBoxButtonData *aButtonLeft,
exlmotodev@13230
    79
	                                 const SDL_MessageBoxButtonData *aButtonRight)
exlmotodev@13230
    80
	{
exlmotodev@13230
    81
		return aButtonLeft->buttonid < aButtonRight->buttonid;
exlmotodev@13230
    82
	}
exlmotodev@13230
    83
exlmotodev@13230
    84
	alert_type
exlmotodev@13230
    85
	ConvertMessageBoxType(const SDL_MessageBoxFlags aWindowType) const
exlmotodev@13230
    86
	{
exlmotodev@13230
    87
		switch (aWindowType)
exlmotodev@13230
    88
		{
exlmotodev@13230
    89
			default:
exlmotodev@13230
    90
			case SDL_MESSAGEBOX_WARNING:
exlmotodev@13230
    91
			{
exlmotodev@13230
    92
				return B_WARNING_ALERT;
exlmotodev@13230
    93
			}
exlmotodev@13230
    94
			case SDL_MESSAGEBOX_ERROR:
exlmotodev@13230
    95
			{
exlmotodev@13230
    96
				return B_STOP_ALERT;
exlmotodev@13230
    97
			}
exlmotodev@13230
    98
			case SDL_MESSAGEBOX_INFORMATION:
exlmotodev@13230
    99
			{
exlmotodev@13230
   100
				return B_INFO_ALERT;
exlmotodev@13230
   101
			}
exlmotodev@13230
   102
		}
exlmotodev@13230
   103
	}
exlmotodev@13230
   104
exlmotodev@13230
   105
	rgb_color
exlmotodev@13230
   106
	ConvertColorType(const SDL_MessageBoxColor *aColor) const
exlmotodev@13230
   107
	{
exlmotodev@13230
   108
		rgb_color color = { aColor->r, aColor->g, aColor->b, color.alpha = 255 };
exlmotodev@13230
   109
		return color;
exlmotodev@13230
   110
	}
exlmotodev@13230
   111
exlmotodev@13230
   112
	int32
exlmotodev@13230
   113
	GetLeftPanelWidth(void) const
exlmotodev@13230
   114
	{
exlmotodev@13230
   115
		// See file "haiku/src/kits/interface/Alert.cpp" for this magic numbers.
exlmotodev@13230
   116
		//    IconStripeWidth = 30 * Scale
exlmotodev@13230
   117
		//    IconSize = 32 * Scale
exlmotodev@13230
   118
		//    Scale = max_c(1, ((int32)be_plain_font->Size() + 15) / 16)
exlmotodev@13230
   119
		//    RealWidth = (IconStripeWidth * Scale) + (IconSize * Scale)
exlmotodev@13230
   120
exlmotodev@13230
   121
		int32 scale = max_c(1, ((int32)be_plain_font->Size() + 15) / 16);
exlmotodev@13230
   122
		return (30 * scale) + (32 * scale);
exlmotodev@13230
   123
	}
exlmotodev@13230
   124
exlmotodev@13230
   125
	void
exlmotodev@13230
   126
	UpdateTextViewWidth(void)
exlmotodev@13230
   127
	{
exlmotodev@13230
   128
		fComputedMessageBoxWidth = fMessageBoxTextView->PreferredSize().Width() + GetLeftPanelWidth();
exlmotodev@13230
   129
	}
exlmotodev@13230
   130
exlmotodev@13230
   131
	void
exlmotodev@13230
   132
	ParseSdlMessageBoxData(const SDL_MessageBoxData *aMessageBoxData)
exlmotodev@13230
   133
	{
exlmotodev@13230
   134
		if (aMessageBoxData == NULL)
exlmotodev@13230
   135
		{
exlmotodev@13230
   136
			SetTitle(BE_SDL_DefTitle);
exlmotodev@13230
   137
			SetMessageText(BE_SDL_DefMessage);
exlmotodev@13230
   138
			AddButton(BE_SDL_DefButton);
exlmotodev@13230
   139
			return;
exlmotodev@13230
   140
		}
exlmotodev@13230
   141
exlmotodev@13230
   142
		if (aMessageBoxData->numbuttons <= 0)
exlmotodev@13230
   143
		{
exlmotodev@13230
   144
			AddButton(BE_SDL_DefButton);
exlmotodev@13230
   145
		}
exlmotodev@13230
   146
		else
exlmotodev@13230
   147
		{
exlmotodev@13230
   148
			AddSdlButtons(aMessageBoxData->buttons, aMessageBoxData->numbuttons);
exlmotodev@13230
   149
		}
exlmotodev@13230
   150
exlmotodev@13230
   151
		if (aMessageBoxData->colorScheme != NULL)
exlmotodev@13230
   152
		{
exlmotodev@13230
   153
			fCustomColorScheme = true;
exlmotodev@13230
   154
			ApplyAndParseColorScheme(aMessageBoxData->colorScheme);
exlmotodev@13230
   155
		}
exlmotodev@13230
   156
exlmotodev@13230
   157
		(aMessageBoxData->title != NULL) ?
exlmotodev@13230
   158
			SetTitle(aMessageBoxData->title) : SetTitle(BE_SDL_DefTitle);
exlmotodev@13230
   159
		(aMessageBoxData->message != NULL) ?
exlmotodev@13230
   160
			SetMessageText(aMessageBoxData->message) : SetMessageText(BE_SDL_DefMessage);
exlmotodev@13230
   161
exlmotodev@13230
   162
		SetType(ConvertMessageBoxType(static_cast<SDL_MessageBoxFlags>(aMessageBoxData->flags)));
exlmotodev@13230
   163
	}
exlmotodev@13230
   164
exlmotodev@13230
   165
	void
exlmotodev@13230
   166
	ApplyAndParseColorScheme(const SDL_MessageBoxColorScheme *aColorScheme)
exlmotodev@13230
   167
	{
exlmotodev@13230
   168
		SetBackgroundColor(&aColorScheme->colors[SDL_MESSAGEBOX_COLOR_BACKGROUND]);
exlmotodev@13230
   169
		fTextColor = ConvertColorType(&aColorScheme->colors[SDL_MESSAGEBOX_COLOR_TEXT]);
exlmotodev@13230
   170
		SetButtonColors(&aColorScheme->colors[SDL_MESSAGEBOX_COLOR_BUTTON_BORDER],
exlmotodev@13230
   171
		                &aColorScheme->colors[SDL_MESSAGEBOX_COLOR_BUTTON_BACKGROUND],
exlmotodev@13230
   172
		                &aColorScheme->colors[SDL_MESSAGEBOX_COLOR_TEXT],
exlmotodev@13230
   173
		                &aColorScheme->colors[SDL_MESSAGEBOX_COLOR_BUTTON_SELECTED]);
exlmotodev@13230
   174
	}
exlmotodev@13230
   175
exlmotodev@13230
   176
	void
exlmotodev@13230
   177
	SetButtonColors(const SDL_MessageBoxColor *aBorderColor,
exlmotodev@13230
   178
	                const SDL_MessageBoxColor *aBackgroundColor,
exlmotodev@13230
   179
	                const SDL_MessageBoxColor *aTextColor,
exlmotodev@13230
   180
	                const SDL_MessageBoxColor *aSelectedColor)
exlmotodev@13230
   181
	{
exlmotodev@13230
   182
		if (fCustomColorScheme)
exlmotodev@13230
   183
		{
exlmotodev@13230
   184
			int32 countButtons = CountButtons();
exlmotodev@13230
   185
			for (int i = 0; i < countButtons; ++i)
exlmotodev@13230
   186
			{
exlmotodev@13230
   187
				ButtonAt(i)->SetViewColor(ConvertColorType(aBorderColor));
exlmotodev@13230
   188
				ButtonAt(i)->SetLowColor(ConvertColorType(aBackgroundColor));
exlmotodev@13230
   189
exlmotodev@13230
   190
				// This doesn't work. See this why:
exlmotodev@13230
   191
				// https://github.com/haiku/haiku/commit/de9c53f8f5008c7b3b0af75d944a628e17f6dffe
exlmotodev@13230
   192
				// Let it remain.
exlmotodev@13230
   193
				ButtonAt(i)->SetHighColor(ConvertColorType(aTextColor));
exlmotodev@13230
   194
			}
exlmotodev@13230
   195
		}
exlmotodev@13230
   196
		// TODO: Not Implemented.
exlmotodev@13230
   197
		// Is it even necessary?!
exlmotodev@13230
   198
		(void)aSelectedColor;
exlmotodev@13230
   199
	}
exlmotodev@13230
   200
exlmotodev@13230
   201
	void
exlmotodev@13230
   202
	SetBackgroundColor(const SDL_MessageBoxColor *aColor)
exlmotodev@13230
   203
	{
exlmotodev@13230
   204
		rgb_color background = ConvertColorType(aColor);
exlmotodev@13230
   205
exlmotodev@13230
   206
		GetLayout()->View()->SetViewColor(background);
exlmotodev@13230
   207
		// See file "haiku/src/kits/interface/Alert.cpp", the "TAlertView" is the internal name of the left panel.
exlmotodev@13230
   208
		FindView("TAlertView")->SetViewColor(background);
exlmotodev@13230
   209
		fMessageBoxTextView->SetViewColor(background);
exlmotodev@13230
   210
	}
exlmotodev@13230
   211
exlmotodev@13230
   212
	bool
exlmotodev@13230
   213
	CheckLongLines(const char *aMessage)
exlmotodev@13230
   214
	{
exlmotodev@13230
   215
		int final = 0;
exlmotodev@13230
   216
exlmotodev@13230
   217
		// This UTF-8 friendly.
exlmotodev@13230
   218
		BString message = aMessage;
exlmotodev@13230
   219
		int32 length = message.CountChars();
exlmotodev@13230
   220
exlmotodev@13230
   221
		for (int i = 0, c = 0; i < length; ++i)
exlmotodev@13230
   222
		{
exlmotodev@13230
   223
			c++;
exlmotodev@13230
   224
			if (*(message.CharAt(i)) == '\n')
exlmotodev@13230
   225
			{
exlmotodev@13230
   226
				c = 0;
exlmotodev@13230
   227
			}
exlmotodev@13230
   228
			if (c > final)
exlmotodev@13230
   229
			{
exlmotodev@13230
   230
				final = c;
exlmotodev@13230
   231
			}
exlmotodev@13230
   232
		}
exlmotodev@13230
   233
exlmotodev@13230
   234
		return (final > G_MAX_STRING_LENGTH_BYTES);
exlmotodev@13230
   235
	}
exlmotodev@13230
   236
exlmotodev@13230
   237
	void
exlmotodev@13230
   238
	SetMessageText(const char *aMessage)
exlmotodev@13230
   239
	{
exlmotodev@13230
   240
		fThereIsLongLine = CheckLongLines(aMessage);
exlmotodev@13230
   241
		if (fThereIsLongLine)
exlmotodev@13230
   242
		{
exlmotodev@13230
   243
			fMessageBoxTextView->SetWordWrap(true);
exlmotodev@13230
   244
		}
exlmotodev@13230
   245
exlmotodev@13230
   246
		rgb_color textColor = ui_color(B_PANEL_TEXT_COLOR);
exlmotodev@13230
   247
		if (fCustomColorScheme)
exlmotodev@13230
   248
		{
exlmotodev@13230
   249
			textColor = fTextColor;
exlmotodev@13230
   250
		}
exlmotodev@13230
   251
exlmotodev@13230
   252
		/*
exlmotodev@13230
   253
		if (fNoTitledWindow)
exlmotodev@13230
   254
		{
exlmotodev@13230
   255
			fMessageBoxTextView->SetFontAndColor(be_bold_font);
exlmotodev@13230
   256
			fMessageBoxTextView->Insert(fTitle);
exlmotodev@13230
   257
			fMessageBoxTextView->Insert("\n\n");
exlmotodev@13230
   258
			fMessageBoxTextView->SetFontAndColor(be_plain_font);
exlmotodev@13230
   259
		}
exlmotodev@13230
   260
		*/
exlmotodev@13230
   261
exlmotodev@13230
   262
		fMessageBoxTextView->SetFontAndColor(be_plain_font, B_FONT_ALL, &textColor);
exlmotodev@13230
   263
		fMessageBoxTextView->Insert(aMessage);
exlmotodev@13230
   264
exlmotodev@13230
   265
		// Be sure to call update width method.
exlmotodev@13230
   266
		UpdateTextViewWidth();
exlmotodev@13230
   267
	}
exlmotodev@13230
   268
exlmotodev@13230
   269
	void
exlmotodev@13230
   270
	AddSdlButtons(const SDL_MessageBoxButtonData *aButtons, int aNumButtons)
exlmotodev@13230
   271
	{
exlmotodev@13230
   272
		for (int i = 0; i < aNumButtons; ++i)
exlmotodev@13230
   273
		{
exlmotodev@13230
   274
			fButtons.push_back(&aButtons[i]);
exlmotodev@13230
   275
		}
exlmotodev@13230
   276
exlmotodev@13230
   277
		std::sort(fButtons.begin(), fButtons.end(), &BE_SDL_MessageBox::SortButtonsPredicate);
exlmotodev@13230
   278
exlmotodev@13230
   279
		size_t countButtons = fButtons.size();
exlmotodev@13230
   280
		for (size_t i = 0; i < countButtons; ++i)
exlmotodev@13230
   281
		{
exlmotodev@13230
   282
			switch (fButtons[i]->flags)
exlmotodev@13230
   283
			{
exlmotodev@13230
   284
				case SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT:
exlmotodev@13230
   285
				{
exlmotodev@13230
   286
					fCloseButton = static_cast<int>(i);
exlmotodev@13230
   287
					break;
exlmotodev@13230
   288
				}
exlmotodev@13230
   289
				case SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT:
exlmotodev@13230
   290
				{
exlmotodev@13230
   291
					fDefaultButton = static_cast<int>(i);
exlmotodev@13230
   292
					break;
exlmotodev@13230
   293
				}
exlmotodev@13230
   294
				default:
exlmotodev@13230
   295
				{
exlmotodev@13230
   296
					break;
exlmotodev@13230
   297
				}
exlmotodev@13230
   298
			}
exlmotodev@13230
   299
			AddButton(fButtons[i]->text);
exlmotodev@13230
   300
		}
exlmotodev@13230
   301
exlmotodev@13230
   302
		SetDefaultButton(ButtonAt(fDefaultButton));
exlmotodev@13230
   303
	}
exlmotodev@13230
   304
exlmotodev@13230
   305
public:
exlmotodev@13230
   306
	explicit
exlmotodev@13230
   307
	BE_SDL_MessageBox(const SDL_MessageBoxData *aMessageBoxData)
exlmotodev@13230
   308
		: BAlert(NULL, NULL, NULL, NULL, NULL, B_WIDTH_FROM_LABEL, B_WARNING_ALERT),
exlmotodev@13230
   309
		  fComputedMessageBoxWidth(0.0f),
exlmotodev@13230
   310
		  fCloseButton(G_CLOSE_BUTTON_ID), fDefaultButton(G_DEFAULT_BUTTON_ID),
exlmotodev@13230
   311
		  fCustomColorScheme(false), fThereIsLongLine(false),
exlmotodev@13230
   312
		  BE_SDL_DefTitle("SDL2 MessageBox"),
exlmotodev@13230
   313
		  BE_SDL_DefMessage("Some information has been lost."),
exlmotodev@13230
   314
		  BE_SDL_DefButton("OK")
exlmotodev@13230
   315
	{
exlmotodev@13230
   316
		// MessageBox settings.
exlmotodev@13230
   317
		// We need a title to display it.
exlmotodev@13230
   318
		SetLook(B_TITLED_WINDOW_LOOK);
exlmotodev@13230
   319
		SetFlags(Flags() | B_CLOSE_ON_ESCAPE);
exlmotodev@13230
   320
exlmotodev@13230
   321
		// MessageBox TextView settings.
exlmotodev@13230
   322
		fMessageBoxTextView = TextView();
exlmotodev@13230
   323
		fMessageBoxTextView->SetWordWrap(false);
exlmotodev@13230
   324
		fMessageBoxTextView->SetStylable(true);
exlmotodev@13230
   325
exlmotodev@13230
   326
		ParseSdlMessageBoxData(aMessageBoxData);
exlmotodev@13230
   327
	}
exlmotodev@13230
   328
exlmotodev@13230
   329
	int
exlmotodev@13230
   330
	GetCloseButtonId(void) const
exlmotodev@13230
   331
	{
exlmotodev@13230
   332
		return fCloseButton;
exlmotodev@13230
   333
	}
exlmotodev@13230
   334
exlmotodev@13230
   335
	virtual
exlmotodev@13230
   336
	~BE_SDL_MessageBox(void)
exlmotodev@13230
   337
	{
exlmotodev@13230
   338
		fButtons.clear();
exlmotodev@13230
   339
	}
exlmotodev@13230
   340
exlmotodev@13230
   341
protected:
exlmotodev@13230
   342
	virtual void
exlmotodev@13230
   343
	FrameResized(float aNewWidth, float aNewHeight)
exlmotodev@13230
   344
	{
exlmotodev@13230
   345
		if (fComputedMessageBoxWidth > aNewWidth)
exlmotodev@13230
   346
		{
exlmotodev@13230
   347
			ResizeTo(fComputedMessageBoxWidth, aNewHeight);
exlmotodev@13230
   348
		}
exlmotodev@13230
   349
		else
exlmotodev@13230
   350
		{
exlmotodev@13230
   351
			BAlert::FrameResized(aNewWidth, aNewHeight);
exlmotodev@13230
   352
		}
exlmotodev@13230
   353
	}
exlmotodev@13230
   354
exlmotodev@13230
   355
	virtual void
exlmotodev@13230
   356
	SetTitle(const char* aTitle)
exlmotodev@13230
   357
	{
exlmotodev@13230
   358
		fTitle = aTitle;
exlmotodev@13230
   359
		BAlert::SetTitle(aTitle);
exlmotodev@13230
   360
	}
exlmotodev@13230
   361
};
exlmotodev@13230
   362
exlmotodev@13230
   363
#ifdef __cplusplus
exlmotodev@13230
   364
extern "C" {
exlmotodev@13230
   365
#endif
exlmotodev@13230
   366
exlmotodev@13230
   367
int
exlmotodev@13230
   368
BE_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid)
exlmotodev@13230
   369
{
exlmotodev@13230
   370
	// Initialize button by closed or error value first.
exlmotodev@13230
   371
	*buttonid = G_CLOSE_BUTTON_ID;
exlmotodev@13230
   372
exlmotodev@13230
   373
	// We need to check "be_app" pointer to "NULL". The "messageboxdata->window" pointer isn't appropriate here
exlmotodev@13230
   374
	// because it is possible to create a MessageBox from another thread. This fixes the following errors:
exlmotodev@13230
   375
	// "You need a valid BApplication object before interacting with the app_server."
exlmotodev@13230
   376
	// "2 BApplication objects were created. Only one is allowed."
exlmotodev@13230
   377
	BApplication *application = NULL;
exlmotodev@13230
   378
	if (be_app == NULL)
exlmotodev@13230
   379
	{
exlmotodev@13230
   380
		application = new(std::nothrow) BApplication(signature);
exlmotodev@13230
   381
		if (application == NULL)
exlmotodev@13230
   382
		{
exlmotodev@13230
   383
			return SDL_SetError("Cannot create the BApplication object. Lack of memory?");
exlmotodev@13230
   384
		}
exlmotodev@13230
   385
	}
exlmotodev@13230
   386
exlmotodev@13230
   387
	BE_SDL_MessageBox *SDL_MessageBox = new(std::nothrow) BE_SDL_MessageBox(messageboxdata);
exlmotodev@13230
   388
	if (SDL_MessageBox == NULL)
exlmotodev@13230
   389
	{
exlmotodev@13230
   390
		return SDL_SetError("Cannot create the BE_SDL_MessageBox (BAlert inheritor) object. Lack of memory?");
exlmotodev@13230
   391
	}
exlmotodev@13230
   392
	const int closeButton = SDL_MessageBox->GetCloseButtonId();
exlmotodev@13230
   393
	int pushedButton = SDL_MessageBox->Go();
exlmotodev@13230
   394
exlmotodev@13230
   395
	// The close button is equivalent to pressing Escape.
exlmotodev@13230
   396
	if (closeButton != G_CLOSE_BUTTON_ID && pushedButton == G_CLOSE_BUTTON_ID)
exlmotodev@13230
   397
	{
exlmotodev@13230
   398
		pushedButton = closeButton;
exlmotodev@13230
   399
	}
exlmotodev@13230
   400
exlmotodev@13230
   401
	// It's deleted by itself after the "Go()" method was executed.
exlmotodev@13230
   402
	/*
exlmotodev@13230
   403
	if (messageBox != NULL)
exlmotodev@13230
   404
	{
exlmotodev@13230
   405
		delete messageBox;
exlmotodev@13230
   406
	}
exlmotodev@13230
   407
	*/
exlmotodev@13230
   408
	if (application != NULL)
exlmotodev@13230
   409
	{
exlmotodev@13230
   410
		delete application;
exlmotodev@13230
   411
	}
exlmotodev@13230
   412
exlmotodev@13230
   413
	// Initialize button by real pushed value then.
exlmotodev@13230
   414
	*buttonid = pushedButton;
exlmotodev@13230
   415
exlmotodev@13230
   416
	return 0;
exlmotodev@13230
   417
}
exlmotodev@13230
   418
exlmotodev@13230
   419
#ifdef __cplusplus
exlmotodev@13230
   420
}
exlmotodev@13230
   421
#endif
exlmotodev@13230
   422
exlmotodev@13230
   423
#endif /* SDL_VIDEO_DRIVER_HAIKU */
exlmotodev@13230
   424
exlmotodev@13230
   425
/* vi: set ts=4 sw=4 expandtab: */