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