src/video/windows/SDL_windowsmessagebox.c
author Sam Lantinga <slouken@libsdl.org>
Thu, 17 Oct 2013 23:02:29 -0700
changeset 7828 1451063c8ecd
parent 7719 31b5f9ff36ca
child 7829 dd58730c3b4c
permissions -rw-r--r--
Fixed building using MinGW
Our SDL_windows.h needed to be included before anything else so UNICODE is defined.
slouken@6620
     1
/*
slouken@6620
     2
  Simple DirectMedia Layer
slouken@6885
     3
  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
slouken@6620
     4
slouken@6620
     5
  This software is provided 'as-is', without any express or implied
slouken@6620
     6
  warranty.  In no event will the authors be held liable for any damages
slouken@6620
     7
  arising from the use of this software.
slouken@6620
     8
slouken@6620
     9
  Permission is granted to anyone to use this software for any purpose,
slouken@6620
    10
  including commercial applications, and to alter it and redistribute it
slouken@6620
    11
  freely, subject to the following restrictions:
slouken@6620
    12
slouken@6620
    13
  1. The origin of this software must not be misrepresented; you must not
slouken@6620
    14
     claim that you wrote the original software. If you use this software
slouken@6620
    15
     in a product, an acknowledgment in the product documentation would be
slouken@6620
    16
     appreciated but is not required.
slouken@6620
    17
  2. Altered source versions must be plainly marked as such, and must not be
slouken@6620
    18
     misrepresented as being the original software.
slouken@6620
    19
  3. This notice may not be removed or altered from any source distribution.
slouken@6620
    20
*/
slouken@6620
    21
#include "SDL_config.h"
slouken@6620
    22
slouken@6620
    23
#if SDL_VIDEO_DRIVER_WINDOWS
slouken@6620
    24
slouken@7828
    25
#if defined(__WIN32__)
slouken@7828
    26
#include "../../core/windows/SDL_windows.h"
slouken@7828
    27
#endif
slouken@7828
    28
slouken@7828
    29
#include "SDL_assert.h"
slouken@6620
    30
#include "SDL_windowsvideo.h"
slouken@6620
    31
slouken@6620
    32
slouken@7030
    33
#ifndef SS_EDITCONTROL
slouken@7030
    34
#define SS_EDITCONTROL  0x2000
slouken@7030
    35
#endif
slouken@7030
    36
slouken@6620
    37
/* Display a Windows message box */
slouken@6620
    38
slouken@7028
    39
#pragma pack(push, 1)
slouken@7028
    40
slouken@6620
    41
typedef struct
slouken@6620
    42
{
slouken@7191
    43
    WORD dlgVer;
slouken@7191
    44
    WORD signature;
slouken@7191
    45
    DWORD helpID;
slouken@7191
    46
    DWORD exStyle;
slouken@7191
    47
    DWORD style;
slouken@7191
    48
    WORD cDlgItems;
slouken@7191
    49
    short x;
slouken@7191
    50
    short y;
slouken@7191
    51
    short cx;
slouken@7191
    52
    short cy;
slouken@7028
    53
} DLGTEMPLATEEX;
slouken@7028
    54
slouken@7028
    55
typedef struct
slouken@7028
    56
{
slouken@7191
    57
    DWORD helpID;
slouken@7191
    58
    DWORD exStyle;
slouken@7191
    59
    DWORD style;
slouken@7191
    60
    short x;
slouken@7191
    61
    short y;
slouken@7191
    62
    short cx;
slouken@7191
    63
    short cy;
slouken@7191
    64
    DWORD id;
slouken@7028
    65
} DLGITEMTEMPLATEEX;
slouken@7028
    66
slouken@7028
    67
#pragma pack(pop)
slouken@7028
    68
slouken@7028
    69
typedef struct
slouken@7028
    70
{
slouken@7028
    71
    DLGTEMPLATEEX* lpDialog;
slouken@6620
    72
    Uint8 *data;
slouken@6620
    73
    size_t size;
slouken@6620
    74
    size_t used;
slouken@6620
    75
} WIN_DialogData;
slouken@6620
    76
slouken@6620
    77
slouken@6620
    78
static INT_PTR MessageBoxDialogProc(HWND hDlg, UINT iMessage, WPARAM wParam, LPARAM lParam)
slouken@6620
    79
{
slouken@6620
    80
    switch ( iMessage ) {
slouken@6620
    81
    case WM_COMMAND:
slouken@6620
    82
        /* Return the ID of the button that was pushed */
slouken@7191
    83
        EndDialog(hDlg, LOWORD(wParam));
slouken@6620
    84
        return TRUE;
slouken@6620
    85
slouken@6620
    86
    default:
slouken@6620
    87
        break;
slouken@6620
    88
    }
slouken@6620
    89
    return FALSE;
slouken@6620
    90
}
slouken@6620
    91
slouken@6620
    92
static SDL_bool ExpandDialogSpace(WIN_DialogData *dialog, size_t space)
slouken@6620
    93
{
slouken@6620
    94
    size_t size = dialog->size;
slouken@6620
    95
slouken@6620
    96
    if (size == 0) {
slouken@6620
    97
        size = space;
slouken@6620
    98
    } else {
slouken@6620
    99
        while ((dialog->used + space) > size) {
slouken@6620
   100
            size *= 2;
slouken@6620
   101
        }
slouken@6620
   102
    }
slouken@6620
   103
    if (size > dialog->size) {
slouken@6620
   104
        void *data = SDL_realloc(dialog->data, size);
slouken@6620
   105
        if (!data) {
slouken@6620
   106
            SDL_OutOfMemory();
slouken@6620
   107
            return SDL_FALSE;
slouken@6620
   108
        }
slouken@6620
   109
        dialog->data = data;
slouken@6620
   110
        dialog->size = size;
slouken@7028
   111
        dialog->lpDialog = (DLGTEMPLATEEX*)dialog->data;
slouken@6620
   112
    }
slouken@6620
   113
    return SDL_TRUE;
slouken@6620
   114
}
slouken@7191
   115
slouken@6620
   116
static SDL_bool AlignDialogData(WIN_DialogData *dialog, size_t size)
slouken@6620
   117
{
slouken@6620
   118
    size_t padding = (dialog->used % size);
slouken@6620
   119
slouken@6620
   120
    if (!ExpandDialogSpace(dialog, padding)) {
slouken@6620
   121
        return SDL_FALSE;
slouken@6620
   122
    }
slouken@6620
   123
slouken@6620
   124
    dialog->used += padding;
slouken@6620
   125
slouken@6620
   126
    return SDL_TRUE;
slouken@6620
   127
}
slouken@6620
   128
slouken@6620
   129
static SDL_bool AddDialogData(WIN_DialogData *dialog, const void *data, size_t size)
slouken@6620
   130
{
slouken@6620
   131
    if (!ExpandDialogSpace(dialog, size)) {
slouken@6620
   132
        return SDL_FALSE;
slouken@6620
   133
    }
slouken@6620
   134
slouken@6620
   135
    SDL_memcpy(dialog->data+dialog->used, data, size);
slouken@6620
   136
    dialog->used += size;
slouken@6620
   137
slouken@6620
   138
    return SDL_TRUE;
slouken@6620
   139
}
slouken@6620
   140
slouken@6620
   141
static SDL_bool AddDialogString(WIN_DialogData *dialog, const char *string)
slouken@6620
   142
{
slouken@6620
   143
    WCHAR *wstring;
slouken@6620
   144
    WCHAR *p;
slouken@6620
   145
    size_t count;
slouken@6620
   146
    SDL_bool status;
slouken@6620
   147
slouken@6620
   148
    if (!string) {
slouken@6620
   149
        string = "";
slouken@6620
   150
    }
slouken@6620
   151
slouken@6620
   152
    wstring = WIN_UTF8ToString(string);
slouken@6620
   153
    if (!wstring) {
slouken@6620
   154
        return SDL_FALSE;
slouken@6620
   155
    }
slouken@6620
   156
slouken@6620
   157
    /* Find out how many characters we have, including null terminator */
slouken@6620
   158
    count = 0;
slouken@6620
   159
    for (p = wstring; *p; ++p) {
slouken@6620
   160
        ++count;
slouken@6620
   161
    }
slouken@6620
   162
    ++count;
slouken@6620
   163
slouken@6620
   164
    status = AddDialogData(dialog, wstring, count*sizeof(WCHAR));
slouken@6620
   165
    SDL_free(wstring);
slouken@6620
   166
    return status;
slouken@6620
   167
}
slouken@6620
   168
slouken@7028
   169
static int s_BaseUnitsX;
slouken@7028
   170
static int s_BaseUnitsY;
icculus@7052
   171
static void Vec2ToDLU(short *x, short *y)
slouken@7028
   172
{
slouken@7191
   173
    SDL_assert(s_BaseUnitsX != 0); /* we init in WIN_ShowMessageBox(), which is the only public function... */
slouken@7028
   174
slouken@7028
   175
    *x = MulDiv(*x, 4, s_BaseUnitsX);
slouken@7028
   176
    *y = MulDiv(*y, 8, s_BaseUnitsY);
slouken@7028
   177
}
slouken@7028
   178
slouken@7028
   179
slouken@6620
   180
static SDL_bool AddDialogControl(WIN_DialogData *dialog, WORD type, DWORD style, DWORD exStyle, int x, int y, int w, int h, int id, const char *caption)
slouken@6620
   181
{
slouken@7028
   182
    DLGITEMTEMPLATEEX item;
slouken@6620
   183
    WORD marker = 0xFFFF;
slouken@6620
   184
    WORD extraData = 0;
slouken@6620
   185
slouken@6620
   186
    SDL_zero(item);
slouken@6620
   187
    item.style = style;
slouken@7028
   188
    item.exStyle = exStyle;
slouken@6620
   189
    item.x = x;
slouken@6620
   190
    item.y = y;
slouken@6620
   191
    item.cx = w;
slouken@6620
   192
    item.cy = h;
slouken@6620
   193
    item.id = id;
slouken@6620
   194
slouken@7028
   195
    Vec2ToDLU(&item.x, &item.y);
slouken@7028
   196
    Vec2ToDLU(&item.cx, &item.cy);
slouken@7028
   197
slouken@6620
   198
    if (!AlignDialogData(dialog, sizeof(DWORD))) {
slouken@6620
   199
        return SDL_FALSE;
slouken@6620
   200
    }
slouken@6620
   201
    if (!AddDialogData(dialog, &item, sizeof(item))) {
slouken@6620
   202
        return SDL_FALSE;
slouken@6620
   203
    }
slouken@6620
   204
    if (!AddDialogData(dialog, &marker, sizeof(marker))) {
slouken@6620
   205
        return SDL_FALSE;
slouken@6620
   206
    }
slouken@6620
   207
    if (!AddDialogData(dialog, &type, sizeof(type))) {
slouken@6620
   208
        return SDL_FALSE;
slouken@6620
   209
    }
slouken@6620
   210
    if (!AddDialogString(dialog, caption)) {
slouken@6620
   211
        return SDL_FALSE;
slouken@6620
   212
    }
slouken@6620
   213
    if (!AddDialogData(dialog, &extraData, sizeof(extraData))) {
slouken@6620
   214
        return SDL_FALSE;
slouken@6620
   215
    }
slouken@7028
   216
    ++dialog->lpDialog->cDlgItems;
slouken@6620
   217
slouken@6620
   218
    return SDL_TRUE;
slouken@6620
   219
}
slouken@6620
   220
slouken@6620
   221
static SDL_bool AddDialogStatic(WIN_DialogData *dialog, int x, int y, int w, int h, const char *text)
slouken@6620
   222
{
slouken@7028
   223
    DWORD style = WS_VISIBLE | WS_CHILD | SS_LEFT | SS_NOPREFIX | SS_EDITCONTROL;
slouken@6620
   224
    return AddDialogControl(dialog, 0x0082, style, 0, x, y, w, h, -1, text);
slouken@6620
   225
}
slouken@6620
   226
slouken@6620
   227
static SDL_bool AddDialogButton(WIN_DialogData *dialog, int x, int y, int w, int h, const char *text, int id, SDL_bool isDefault)
slouken@6620
   228
{
slouken@6620
   229
    DWORD style = WS_VISIBLE | WS_CHILD;
slouken@6620
   230
    if (isDefault) {
slouken@6620
   231
        style |= BS_DEFPUSHBUTTON;
slouken@6620
   232
    } else {
slouken@6620
   233
        style |= BS_PUSHBUTTON;
slouken@6620
   234
    }
slouken@6620
   235
    return AddDialogControl(dialog, 0x0080, style, 0, x, y, w, h, id, text);
slouken@6620
   236
}
slouken@6620
   237
slouken@6620
   238
static void FreeDialogData(WIN_DialogData *dialog)
slouken@6620
   239
{
slouken@7719
   240
    SDL_free(dialog->data);
slouken@6620
   241
    SDL_free(dialog);
slouken@6620
   242
}
slouken@6620
   243
slouken@6620
   244
static WIN_DialogData *CreateDialogData(int w, int h, const char *caption)
slouken@6620
   245
{
slouken@6620
   246
    WIN_DialogData *dialog;
slouken@7028
   247
    DLGTEMPLATEEX dialogTemplate;
slouken@7028
   248
    WORD WordToPass;
slouken@6620
   249
slouken@6620
   250
    SDL_zero(dialogTemplate);
slouken@7028
   251
    dialogTemplate.dlgVer = 1;
slouken@7028
   252
    dialogTemplate.signature = 0xffff;
slouken@7028
   253
    dialogTemplate.style = (WS_CAPTION | DS_CENTER | DS_SHELLFONT);
slouken@6620
   254
    dialogTemplate.x = 0;
slouken@6620
   255
    dialogTemplate.y = 0;
slouken@6620
   256
    dialogTemplate.cx = w;
slouken@6620
   257
    dialogTemplate.cy = h;
slouken@7028
   258
    Vec2ToDLU(&dialogTemplate.cx, &dialogTemplate.cy);
slouken@6620
   259
slouken@6620
   260
    dialog = (WIN_DialogData *)SDL_calloc(1, sizeof(*dialog));
slouken@6620
   261
    if (!dialog) {
slouken@6620
   262
        return NULL;
slouken@6620
   263
    }
slouken@6620
   264
slouken@6620
   265
    if (!AddDialogData(dialog, &dialogTemplate, sizeof(dialogTemplate))) {
slouken@6620
   266
        FreeDialogData(dialog);
slouken@6620
   267
        return NULL;
slouken@6620
   268
    }
slouken@6620
   269
slouken@7191
   270
    /* No menu */
slouken@7028
   271
    WordToPass = 0;
slouken@7028
   272
    if (!AddDialogData(dialog, &WordToPass, 2)) {
slouken@6620
   273
        FreeDialogData(dialog);
slouken@6620
   274
        return NULL;
slouken@6620
   275
    }
slouken@6620
   276
slouken@7191
   277
    /* No custom class */
slouken@7028
   278
    if (!AddDialogData(dialog, &WordToPass, 2)) {
slouken@7028
   279
        FreeDialogData(dialog);
slouken@7028
   280
        return NULL;
slouken@7028
   281
    }
slouken@7028
   282
slouken@7191
   283
    /* title */
slouken@6620
   284
    if (!AddDialogString(dialog, caption)) {
slouken@6620
   285
        FreeDialogData(dialog);
slouken@6620
   286
        return NULL;
slouken@6620
   287
    }
slouken@6620
   288
slouken@7191
   289
    /* Font stuff */
slouken@7028
   290
    {
slouken@7191
   291
        /*
slouken@7191
   292
         * We want to use the system messagebox font.
slouken@7191
   293
         */
slouken@7028
   294
        BYTE ToPass;
slouken@7191
   295
slouken@7028
   296
        NONCLIENTMETRICSA NCM;
slouken@7028
   297
        NCM.cbSize = sizeof(NCM);
slouken@7028
   298
        SystemParametersInfoA(SPI_GETNONCLIENTMETRICS, 0, &NCM, 0);
slouken@7191
   299
slouken@7191
   300
        /* Font size - convert to logical font size for dialog parameter. */
slouken@7028
   301
        {
slouken@7028
   302
            HDC ScreenDC = GetDC(0);
slouken@7028
   303
            WordToPass = (WORD)(-72 * NCM.lfMessageFont.lfHeight / GetDeviceCaps(ScreenDC, LOGPIXELSY));
slouken@7028
   304
            ReleaseDC(0, ScreenDC);
slouken@7028
   305
        }
slouken@7028
   306
slouken@7028
   307
        if (!AddDialogData(dialog, &WordToPass, 2)) {
slouken@7028
   308
            FreeDialogData(dialog);
slouken@7028
   309
            return NULL;
slouken@7028
   310
        }
slouken@7028
   311
slouken@7191
   312
        /* Font weight */
slouken@7028
   313
        WordToPass = (WORD)NCM.lfMessageFont.lfWeight;
slouken@7028
   314
        if (!AddDialogData(dialog, &WordToPass, 2)) {
slouken@7028
   315
            FreeDialogData(dialog);
slouken@7028
   316
            return NULL;
slouken@7028
   317
        }
slouken@7028
   318
slouken@7191
   319
        /* italic? */
slouken@7028
   320
        ToPass = NCM.lfMessageFont.lfItalic;
slouken@7028
   321
        if (!AddDialogData(dialog, &ToPass, 1)) {
slouken@7028
   322
            FreeDialogData(dialog);
slouken@7028
   323
            return NULL;
slouken@7028
   324
        }
slouken@7028
   325
slouken@7191
   326
        /* charset? */
slouken@7028
   327
        ToPass = NCM.lfMessageFont.lfCharSet;
slouken@7028
   328
        if (!AddDialogData(dialog, &ToPass, 1)) {
slouken@7028
   329
            FreeDialogData(dialog);
slouken@7028
   330
            return NULL;
slouken@7028
   331
        }
slouken@7028
   332
slouken@7191
   333
        /* font typeface. */
slouken@7028
   334
        if (!AddDialogString(dialog, NCM.lfMessageFont.lfFaceName)) {
slouken@7028
   335
            FreeDialogData(dialog);
slouken@7028
   336
            return NULL;
slouken@7028
   337
        }
slouken@7028
   338
    }
slouken@7028
   339
slouken@6620
   340
    return dialog;
slouken@6620
   341
}
slouken@6620
   342
slouken@6620
   343
int
slouken@6620
   344
WIN_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid)
slouken@6620
   345
{
slouken@6620
   346
    WIN_DialogData *dialog;
slouken@7028
   347
    int i, x, y, which;
slouken@6620
   348
    const SDL_MessageBoxButtonData *buttons = messageboxdata->buttons;
slouken@7028
   349
    HFONT DialogFont;
slouken@7028
   350
    SIZE Size;
slouken@7028
   351
    RECT TextSize;
slouken@7028
   352
    wchar_t* wmessage;
slouken@7028
   353
    TEXTMETRIC TM;
slouken@7028
   354
slouken@7028
   355
slouken@7028
   356
    const int ButtonWidth = 88;
slouken@7028
   357
    const int ButtonHeight = 26;
slouken@7028
   358
    const int TextMargin = 16;
slouken@7028
   359
    const int ButtonMargin = 12;
slouken@6620
   360
slouken@7028
   361
slouken@7191
   362
    /* Jan 25th, 2013 - dant@fleetsa.com
slouken@7191
   363
     *
slouken@7191
   364
     *
slouken@7191
   365
     * I've tried to make this more reasonable, but I've run in to a lot
slouken@7191
   366
     * of nonsense.
slouken@7191
   367
     *
slouken@7191
   368
     * The original issue is the code was written in pixels and not
slouken@7191
   369
     * dialog units (DLUs). All DialogBox functions use DLUs, which
slouken@7191
   370
     * vary based on the selected font (yay).
slouken@7191
   371
     *
slouken@7191
   372
     * According to MSDN, the most reliable way to convert is via
slouken@7191
   373
     * MapDialogUnits, which requires an HWND, which we don't have
slouken@7191
   374
     * at time of template creation.
slouken@7191
   375
     *
slouken@7191
   376
     * We do however have:
slouken@7191
   377
     *  The system font (DLU width 8 for me)
slouken@7191
   378
     *  The font we select for the dialog (DLU width 6 for me)
slouken@7191
   379
     *
slouken@7191
   380
     * Based on experimentation, *neither* of these return the value
slouken@7191
   381
     * actually used. Stepping in to MapDialogUnits(), the conversion
slouken@7191
   382
     * is fairly clear, and uses 7 for me.
slouken@7191
   383
     *
slouken@7191
   384
     * As a result, some of this is hacky to ensure the sizing is
slouken@7191
   385
     * somewhat correct.
slouken@7191
   386
     *
slouken@7191
   387
     * Honestly, a long term solution is to use CreateWindow, not CreateDialog.
slouken@7191
   388
     *
slouken@7191
   389
slouken@7191
   390
     *
slouken@7191
   391
     * In order to get text dimensions we need to have a DC with the desired font.
slouken@7191
   392
     * I'm assuming a dialog box in SDL is rare enough we can to the create.
slouken@7191
   393
     */
slouken@7028
   394
    HDC FontDC = CreateCompatibleDC(0);
slouken@7191
   395
slouken@7028
   396
    {
slouken@7191
   397
        /* Create a duplicate of the font used in system message boxes. */
slouken@7028
   398
        LOGFONT lf;
slouken@7028
   399
        NONCLIENTMETRICS NCM;
slouken@7028
   400
        NCM.cbSize = sizeof(NCM);
slouken@7028
   401
        SystemParametersInfo(SPI_GETNONCLIENTMETRICS, 0, &NCM, 0);
slouken@7028
   402
        lf = NCM.lfMessageFont;
slouken@7028
   403
        DialogFont = CreateFontIndirect(&lf);
slouken@7028
   404
    }
slouken@7028
   405
slouken@7191
   406
    /* Select the font in to our DC */
slouken@7028
   407
    SelectObject(FontDC, DialogFont);
slouken@7028
   408
slouken@7028
   409
    {
slouken@7191
   410
        /* Get the metrics to try and figure our DLU conversion. */
slouken@7028
   411
        GetTextMetrics(FontDC, &TM);
slouken@7028
   412
        s_BaseUnitsX = TM.tmAveCharWidth + 1;
slouken@7028
   413
        s_BaseUnitsY = TM.tmHeight;
slouken@7028
   414
    }
slouken@7191
   415
slouken@7191
   416
    /* Measure the *pixel* size of the string. */
slouken@7028
   417
    wmessage = WIN_UTF8ToString(messageboxdata->message);
slouken@7028
   418
    SDL_zero(TextSize);
slouken@7028
   419
    Size.cx = DrawText(FontDC, wmessage, -1, &TextSize, DT_CALCRECT);
slouken@7028
   420
slouken@7191
   421
    /* Add some padding for hangs, etc. */
slouken@7028
   422
    TextSize.right += 2;
slouken@7028
   423
    TextSize.bottom += 2;
slouken@7028
   424
slouken@7191
   425
    /* Done with the DC, and the string */
slouken@7028
   426
    DeleteDC(FontDC);
slouken@7028
   427
    SDL_free(wmessage);
slouken@7028
   428
slouken@7191
   429
    /* Increase the size of the dialog by some border spacing around the text. */
slouken@7028
   430
    Size.cx = TextSize.right - TextSize.left;
slouken@7028
   431
    Size.cy = TextSize.bottom - TextSize.top;
slouken@7028
   432
    Size.cx += TextMargin * 2;
slouken@7028
   433
    Size.cy += TextMargin * 2;
slouken@7028
   434
slouken@7191
   435
    /* Ensure the size is wide enough for all of the buttons. */
slouken@7028
   436
    if (Size.cx < messageboxdata->numbuttons * (ButtonWidth + ButtonMargin) + ButtonMargin)
slouken@7028
   437
        Size.cx = messageboxdata->numbuttons * (ButtonWidth + ButtonMargin) + ButtonMargin;
slouken@7028
   438
slouken@7191
   439
    /* Add vertical space for the buttons and border. */
slouken@7028
   440
    Size.cy += ButtonHeight + TextMargin;
slouken@7028
   441
slouken@7028
   442
    dialog = CreateDialogData(Size.cx, Size.cy, messageboxdata->title);
slouken@6620
   443
    if (!dialog) {
slouken@6620
   444
        return -1;
slouken@6620
   445
    }
slouken@6620
   446
slouken@7028
   447
    if (!AddDialogStatic(dialog, TextMargin, TextMargin, TextSize.right - TextSize.left, TextSize.bottom - TextSize.top, messageboxdata->message)) {
slouken@6620
   448
        FreeDialogData(dialog);
slouken@6620
   449
        return -1;
slouken@6620
   450
    }
slouken@6620
   451
slouken@7191
   452
    /* Align the buttons to the right/bottom. */
slouken@7028
   453
    x = Size.cx - ButtonWidth - ButtonMargin;
slouken@7028
   454
    y = Size.cy - ButtonHeight - ButtonMargin;
slouken@6620
   455
    for (i = 0; i < messageboxdata->numbuttons; ++i) {
slouken@6620
   456
        SDL_bool isDefault;
slouken@6620
   457
slouken@6620
   458
        if (buttons[i].flags & SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT) {
slouken@6620
   459
            isDefault = SDL_TRUE;
slouken@6620
   460
        } else {
slouken@6620
   461
            isDefault = SDL_FALSE;
slouken@6620
   462
        }
slouken@7028
   463
        if (!AddDialogButton(dialog, x, y, ButtonWidth, ButtonHeight, buttons[i].text, i, isDefault)) {
slouken@6620
   464
            FreeDialogData(dialog);
slouken@6620
   465
            return -1;
slouken@6620
   466
        }
slouken@7028
   467
        x -= ButtonWidth + ButtonMargin;
slouken@6620
   468
    }
slouken@6620
   469
slouken@6620
   470
    /* FIXME: If we have a parent window, get the Instance and HWND for them */
slouken@7028
   471
    which = DialogBoxIndirect(NULL, (DLGTEMPLATE*)dialog->lpDialog, NULL, (DLGPROC)MessageBoxDialogProc);
slouken@6620
   472
    *buttonid = buttons[which].buttonid;
slouken@6620
   473
slouken@6620
   474
    FreeDialogData(dialog);
slouken@6620
   475
    return 0;
slouken@6620
   476
}
slouken@6620
   477
slouken@6620
   478
#endif /* SDL_VIDEO_DRIVER_WINDOWS */
slouken@6620
   479
slouken@6620
   480
/* vi: set ts=4 sw=4 expandtab: */