Branch
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561
/*
Simple DirectMedia Layer
Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
#include "../../SDL_internal.h"
#if SDL_VIDEO_DRIVER_OS2
/* Display a OS/2 message box */
#include "SDL.h"
#include "../../core/os2/SDL_os2.h"
#include "SDL_os2video.h"
#define INCL_WIN
#include <os2.h>
#define IDD_TEXT_MESSAGE 1001
#define IDD_BITMAP 1002
#define IDD_PB_FIRST 1003
typedef struct _MSGBOXDLGDATA {
USHORT cb;
HWND hwndUnder;
} MSGBOXDLGDATA;
static VOID _wmInitDlg(HWND hwnd, MSGBOXDLGDATA *pDlgData)
{
HPS hps = WinGetPS(hwnd);
POINTL aptText[TXTBOX_COUNT];
HENUM hEnum;
HWND hWndNext;
CHAR acBuf[256];
ULONG cbBuf;
ULONG cButtons = 0;
ULONG ulButtonsCY = 0;
ULONG ulButtonsCX = 0;
RECTL rectl;
ULONG ulX;
ULONG ulIdx;
struct _BUTTON {
HWND hwnd; /* Button window handle. */
ULONG ulCX; /* Button width in dialog coordinates. */
} aButtons[32];
RECTL rectlItem;
HAB hab = WinQueryAnchorBlock(hwnd);
/* --- Align the buttons to the right/bottom. --- */
/* Collect window handles of all buttons in dialog. */
hEnum = WinBeginEnumWindows(hwnd);
while ((hWndNext = WinGetNextWindow(hEnum)) != NULLHANDLE) {
if (WinQueryClassName(hWndNext, sizeof(acBuf), acBuf) == 0) {
continue;
}
if (SDL_strcmp(acBuf, "#3") == 0) { /* Class name of button. */
if (cButtons < sizeof(aButtons) / sizeof(struct _BUTTON)) {
aButtons[cButtons].hwnd = hWndNext;
cButtons++;
}
}
}
WinEndEnumWindows(hEnum);
/* Query size of text for each button, get width of each button, total
* buttons width (ulButtonsCX) and max. height (ulButtonsCX) in _dialog
* coordinates_. */
hps = WinGetPS(hwnd);
for(ulIdx = 0; ulIdx < cButtons; ulIdx++) {
/* Query size of text in window coordinates. */
cbBuf = WinQueryWindowText(aButtons[ulIdx].hwnd, sizeof(acBuf), acBuf);
GpiQueryTextBox(hps, cbBuf, acBuf, TXTBOX_COUNT, aptText);
aptText[TXTBOX_TOPRIGHT].x -= aptText[TXTBOX_BOTTOMLEFT].x;
aptText[TXTBOX_TOPRIGHT].y -= aptText[TXTBOX_BOTTOMLEFT].y;
/* Convert text size to dialog coordinates. */
WinMapDlgPoints(hwnd, &aptText[TXTBOX_TOPRIGHT], 1, FALSE);
/* Add vertical and horizontal space for button's frame (dialog coord.). */
if (aptText[TXTBOX_TOPRIGHT].x < 30) { /* Minimal button width. */
aptText[TXTBOX_TOPRIGHT].x = 30;
} else {
aptText[TXTBOX_TOPRIGHT].x += 4;
}
aptText[TXTBOX_TOPRIGHT].y += 3;
aButtons[ulIdx].ulCX = aptText[TXTBOX_TOPRIGHT].x; /* Store button width */
ulButtonsCX += aptText[TXTBOX_TOPRIGHT].x + 2; /* Add total btn. width */
/* Get max. height for buttons. */
if (ulButtonsCY < aptText[TXTBOX_TOPRIGHT].y)
ulButtonsCY = aptText[TXTBOX_TOPRIGHT].y + 1;
}
WinReleasePS(hps);
/* Expand horizontal size of the window to fit all buttons and move window
* to the center of parent window. */
/* Convert total width of buttons to window coordinates. */
aptText[0].x = ulButtonsCX + 4;
WinMapDlgPoints(hwnd, &aptText[0], 1, TRUE);
/* Check width of the window and expand as needed. */
WinQueryWindowRect(hwnd, &rectlItem);
if (rectlItem.xRight <= aptText[0].x)
rectlItem.xRight = aptText[0].x;
/* Move window rectangle to the center of owner window. */
WinQueryWindowRect(pDlgData->hwndUnder, &rectl);
/* Left-bottom point of centered dialog on owner window. */
rectl.xLeft = (rectl.xRight - rectlItem.xRight) / 2;
rectl.yBottom = (rectl.yTop - rectlItem.yTop) / 2;
/* Map left-bottom point to desktop. */
WinMapWindowPoints(pDlgData->hwndUnder, HWND_DESKTOP, (PPOINTL)&rectl, 1);
WinOffsetRect(hab, &rectlItem, rectl.xLeft, rectl.yBottom);
/* Set new rectangle for the window. */
WinSetWindowPos(hwnd, HWND_TOP, rectlItem.xLeft, rectlItem.yBottom,
rectlItem.xRight - rectlItem.xLeft,
rectlItem.yTop - rectlItem.yBottom,
SWP_SIZE | SWP_MOVE);
/* Set buttons positions. */
/* Get horizontal position for the first button. */
WinMapDlgPoints(hwnd, (PPOINTL)&rectlItem, 2, FALSE); /* Win size to dlg coord. */
ulX = rectlItem.xRight - rectlItem.xLeft - ulButtonsCX - 2; /* First button position. */
/* Set positions and sizes for all buttons. */
for (ulIdx = 0; ulIdx < cButtons; ulIdx++) {
/* Get poisition and size for the button in dialog coordinates. */
aptText[0].x = ulX;
aptText[0].y = 2;
aptText[1].x = aButtons[ulIdx].ulCX;
aptText[1].y = ulButtonsCY;
/* Convert to window coordinates. */
WinMapDlgPoints(hwnd, aptText, 2, TRUE);
WinSetWindowPos(aButtons[ulIdx].hwnd, HWND_TOP,
aptText[0].x, aptText[0].y, aptText[1].x, aptText[1].y,
SWP_MOVE | SWP_SIZE);
/* Offset horizontal position for the next button. */
ulX += aButtons[ulIdx].ulCX + 2;
}
/* Set right bound of the text to right bound of the last button and
* bottom bound of the text just above the buttons. */
aptText[2].x = 25; /* Left bound of text in dlg coordinates. */
aptText[2].y = ulButtonsCY + 3; /* Bottom bound of the text in dlg coords. */
WinMapDlgPoints(hwnd, &aptText[2], 1, TRUE); /* Convert ^^^ to win. coords */
hWndNext = WinWindowFromID(hwnd, IDD_TEXT_MESSAGE);
WinQueryWindowRect(hWndNext, &rectlItem);
rectlItem.xLeft = aptText[2].x;
rectlItem.yBottom = aptText[2].y;
/* Right bound of the text equals right bound of the last button. */
rectlItem.xRight = aptText[0].x + aptText[1].x;
WinSetWindowPos(hWndNext, HWND_TOP, rectlItem.xLeft, rectlItem.yBottom,
rectlItem.xRight - rectlItem.xLeft,
rectlItem.yTop - rectlItem.yBottom,
SWP_MOVE | SWP_SIZE);
}
static MRESULT EXPENTRY DynDlgProc(HWND hwnd, USHORT message, MPARAM mp1, MPARAM mp2)
{
switch (message) {
case WM_INITDLG:
_wmInitDlg(hwnd, (MSGBOXDLGDATA*)mp2);
break;
case WM_COMMAND:
switch (SHORT1FROMMP(mp1)) {
case DID_OK:
WinDismissDlg(hwnd, FALSE);
break;
default:
break;
}
default:
return(WinDefDlgProc(hwnd, message, mp1, mp2));
}
return FALSE;
}
static HWND _makeDlg(const SDL_MessageBoxData *messageboxdata)
{
SDL_MessageBoxButtonData*
pSDLBtnData = (SDL_MessageBoxButtonData *)messageboxdata->buttons;
ULONG cSDLBtnData = messageboxdata->numbuttons;
PSZ pszTitle = OS2_UTF8ToSys(messageboxdata->title);
ULONG cbTitle = (pszTitle == NULL)? 1 : (SDL_strlen(pszTitle) + 1);
PSZ pszText = OS2_UTF8ToSys(messageboxdata->message);
ULONG cbText = (pszText == NULL)? 1 : (SDL_strlen(pszText) + 1);
PDLGTEMPLATE pTemplate;
ULONG cbTemplate;
ULONG ulIdx;
PCHAR pcDlgData;
PDLGTITEM pDlgItem;
PSZ pszBtnText;
ULONG cbBtnText;
HWND hwnd;
const SDL_MessageBoxColor* pSDLColors = (messageboxdata->colorScheme == NULL)?
NULL : messageboxdata->colorScheme->colors;
const SDL_MessageBoxColor* pSDLColor;
MSGBOXDLGDATA stDlgData;
/* Build a dialog tamplate in memory */
/* Size of template */
cbTemplate = sizeof(DLGTEMPLATE) + ((2 + cSDLBtnData) * sizeof(DLGTITEM)) +
sizeof(ULONG) + /* First item data - frame control data. */
cbTitle + /* First item data - frame title + ZERO. */
cbText + /* Second item data - ststic text + ZERO.*/
3; /* Third item data - system icon Id. */
/* Button items datas - text for buttons. */
for (ulIdx = 0; ulIdx < cSDLBtnData; ulIdx++) {
pszBtnText = (PSZ)pSDLBtnData[ulIdx].text;
cbTemplate += (pszBtnText == NULL)? 1 : (SDL_strlen(pszBtnText) + 1);
}
/* Presentation parameter space. */
if (pSDLColors != NULL) {
cbTemplate += 26 /* PP for frame. */ +
26 /* PP for static text. */ +
(48 * cSDLBtnData); /* PP for buttons. */
}
/* Allocate memory for the dialog template. */
pTemplate = (PDLGTEMPLATE) SDL_malloc(cbTemplate);
/* Pointer on data for dialog items in allocated memory. */
pcDlgData = &((PCHAR)pTemplate)[sizeof(DLGTEMPLATE) +
((2 + cSDLBtnData) * sizeof(DLGTITEM))];
/* Header info */
pTemplate->cbTemplate = cbTemplate; /* size of dialog template to pass to WinCreateDlg() */
pTemplate->type = 0; /* Currently always 0. */
pTemplate->codepage = 0;
pTemplate->offadlgti = 14; /* Offset to array of DLGTITEMs. */
pTemplate->fsTemplateStatus = 0; /* Reserved field? */
/* Index in array of dlg items of item to get focus, */
/* if 0 then focus goes to first control that can have focus. */
pTemplate->iItemFocus = 0;
pTemplate->coffPresParams = 0;
/* First item info - frame */
pDlgItem = pTemplate->adlgti;
pDlgItem->fsItemStatus = 0; /* Reserved? */
/* Number of dialog item child windows owned by this item. */
pDlgItem->cChildren = 2 + cSDLBtnData; /* Ststic text + buttons. */
/* Length of class name, if 0 then offClassname contains a WC_ value. */
pDlgItem->cchClassName = 0;
pDlgItem->offClassName = (USHORT)WC_FRAME;
/* Length of text. */
pDlgItem->cchText = cbTitle;
pDlgItem->offText = pcDlgData - (PCHAR)pTemplate; /* Offset to title text. */
/* Copy text for the title into the dialog template. */
if (pszTitle != NULL) {
SDL_memcpy(pcDlgData, pszTitle, cbTitle);
} else {
*pcDlgData = '\0';
}
pcDlgData += pDlgItem->cchText;
pDlgItem->flStyle = WS_GROUP | WS_VISIBLE | WS_CLIPSIBLINGS |
FS_DLGBORDER | WS_SAVEBITS;
pDlgItem->x = 100;
pDlgItem->y = 100;
pDlgItem->cx = 175;
pDlgItem->cy = 65;
pDlgItem->id = DID_OK; /* An ID value? */
if (pSDLColors == NULL)
pDlgItem->offPresParams = 0;
else {
/* Presentation parameter for the frame - dialog colors. */
pDlgItem->offPresParams = pcDlgData - (PCHAR)pTemplate;
((PPRESPARAMS)pcDlgData)->cb = 22;
pcDlgData += 4;
((PPARAM)pcDlgData)->id = PP_FOREGROUNDCOLOR;
((PPARAM)pcDlgData)->cb = 3;
((PPARAM)pcDlgData)->ab[0] = pSDLColors[SDL_MESSAGEBOX_COLOR_TEXT].b;
((PPARAM)pcDlgData)->ab[1] = pSDLColors[SDL_MESSAGEBOX_COLOR_TEXT].g;
((PPARAM)pcDlgData)->ab[2] = pSDLColors[SDL_MESSAGEBOX_COLOR_TEXT].r;
pcDlgData += 11;
((PPARAM)pcDlgData)->id = PP_BACKGROUNDCOLOR;
((PPARAM)pcDlgData)->cb = 3;
((PPARAM)pcDlgData)->ab[0] = pSDLColors[SDL_MESSAGEBOX_COLOR_BACKGROUND].b;
((PPARAM)pcDlgData)->ab[1] = pSDLColors[SDL_MESSAGEBOX_COLOR_BACKGROUND].g;
((PPARAM)pcDlgData)->ab[2] = pSDLColors[SDL_MESSAGEBOX_COLOR_BACKGROUND].r;
pcDlgData += 11;
}
/* Offset to ctl data. */
pDlgItem->offCtlData = pcDlgData - (PCHAR)pTemplate;
/* Put CtlData for the dialog in here */
*((PULONG)pcDlgData) = FCF_TITLEBAR | FCF_SYSMENU;
pcDlgData += sizeof(ULONG);
/* Second item info - static text (message). */
pDlgItem++;
pDlgItem->fsItemStatus = 0;
/* No children since its a control, it could have child control */
/* (ex. a group box). */
pDlgItem->cChildren = 0;
/* Length of class name, 0 - offClassname contains a WC_ constant. */
pDlgItem->cchClassName = 0;
pDlgItem->offClassName = (USHORT)WC_STATIC;
pDlgItem->cchText = cbText;
pDlgItem->offText = pcDlgData - (PCHAR)pTemplate; /* Offset to the text. */
/* Copy message text into the dialog template. */
if (pszText != NULL) {
SDL_memcpy(pcDlgData, pszText, cbText);
} else {
*pcDlgData = '\0';
}
pcDlgData += pDlgItem->cchText;
pDlgItem->flStyle = SS_TEXT | DT_TOP | DT_LEFT | DT_WORDBREAK | WS_VISIBLE;
/* It will be really set in _wmInitDlg(). */
pDlgItem->x = 25;
pDlgItem->y = 13;
pDlgItem->cx = 147;
pDlgItem->cy = 62; /* It will be used. */
pDlgItem->id = IDD_TEXT_MESSAGE; /* an ID value */
if (pSDLColors == NULL)
pDlgItem->offPresParams = 0;
else {
/* Presentation parameter for the static text - dialog colors. */
pDlgItem->offPresParams = pcDlgData - (PCHAR)pTemplate;
((PPRESPARAMS)pcDlgData)->cb = 22;
pcDlgData += 4;
((PPARAM)pcDlgData)->id = PP_FOREGROUNDCOLOR;
((PPARAM)pcDlgData)->cb = 3;
((PPARAM)pcDlgData)->ab[0] = pSDLColors[SDL_MESSAGEBOX_COLOR_TEXT].b;
((PPARAM)pcDlgData)->ab[1] = pSDLColors[SDL_MESSAGEBOX_COLOR_TEXT].g;
((PPARAM)pcDlgData)->ab[2] = pSDLColors[SDL_MESSAGEBOX_COLOR_TEXT].r;
pcDlgData += 11;
((PPARAM)pcDlgData)->id = PP_BACKGROUNDCOLOR;
((PPARAM)pcDlgData)->cb = 3;
((PPARAM)pcDlgData)->ab[0] = pSDLColors[SDL_MESSAGEBOX_COLOR_BACKGROUND].b;
((PPARAM)pcDlgData)->ab[1] = pSDLColors[SDL_MESSAGEBOX_COLOR_BACKGROUND].g;
((PPARAM)pcDlgData)->ab[2] = pSDLColors[SDL_MESSAGEBOX_COLOR_BACKGROUND].r;
pcDlgData += 11;
}
pDlgItem->offCtlData = 0;
/* Third item info - static bitmap. */
pDlgItem++;
pDlgItem->fsItemStatus = 0;
pDlgItem->cChildren = 0;
pDlgItem->cchClassName = 0;
pDlgItem->offClassName = (USHORT)WC_STATIC;
pDlgItem->cchText = 3; /* 0xFF, low byte of the icon Id, high byte of icon Id. */
pDlgItem->offText = pcDlgData - (PCHAR)pTemplate; /* Offset to the Id. */
/* Write system icon ID into dialog template. */
*((PBYTE)pcDlgData) = 0xFF; /* First byte is 0xFF, next 2 are system pointer Id. */
pcDlgData++;
*((PUSHORT)pcDlgData) = ((messageboxdata->flags & SDL_MESSAGEBOX_ERROR) != 0)?
SPTR_ICONERROR :
((messageboxdata->flags & SDL_MESSAGEBOX_WARNING) != 0)?
SPTR_ICONWARNING : SPTR_ICONINFORMATION;
pcDlgData += 2;
pDlgItem->flStyle = SS_SYSICON | WS_VISIBLE;
pDlgItem->x = 4;
pDlgItem->y = 45; /* It will be really set in _wmInitDlg(). */
pDlgItem->cx = 0;
pDlgItem->cy = 0;
pDlgItem->id = IDD_BITMAP;
pDlgItem->offPresParams = 0;
pDlgItem->offCtlData = 0;
/* Next items - buttons. */
for (ulIdx = 0; ulIdx < cSDLBtnData; ulIdx++) {
pDlgItem++;
pDlgItem->fsItemStatus = 0;
pDlgItem->cChildren = 0; /* No children. */
pDlgItem->cchClassName = 0; /* 0 - offClassname is WC_ constant. */
pDlgItem->offClassName = (USHORT)WC_BUTTON;
pszBtnText = OS2_UTF8ToSys(pSDLBtnData[ulIdx].text);
cbBtnText = (pszBtnText == NULL)? 1 : (SDL_strlen(pszBtnText) + 1);
pDlgItem->cchText = cbBtnText;
pDlgItem->offText = pcDlgData - (PCHAR)pTemplate; /* Offset to the text. */
/* Copy text for the button into the dialog template. */
if (pszBtnText != NULL) {
SDL_memcpy(pcDlgData, pszBtnText, cbBtnText);
} else {
*pcDlgData = '\0';
}
pcDlgData += pDlgItem->cchText;
SDL_free(pszBtnText);
pDlgItem->flStyle = BS_PUSHBUTTON | WS_TABSTOP | WS_VISIBLE;
if (pSDLBtnData[ulIdx].flags == SDL_MESSAGEBOX_BUTTON_RETURNKEY_DEFAULT) {
pDlgItem->flStyle |= BS_DEFAULT;
pTemplate->iItemFocus = ulIdx + 3; /* +3 - frame, static text and icon. */
pSDLColor = &pSDLColors[SDL_MESSAGEBOX_COLOR_BUTTON_SELECTED];
} else {
pSDLColor = &pSDLColors[SDL_MESSAGEBOX_COLOR_TEXT];
}
/* It will be really set in _wmInitDlg() */
pDlgItem->x = 10;
pDlgItem->y = 10;
pDlgItem->cx = 70;
pDlgItem->cy = 15;
pDlgItem->id = IDD_PB_FIRST + ulIdx; /* an ID value */
if (pSDLColors == NULL)
pDlgItem->offPresParams = 0;
else {
/* Presentation parameter for the button - dialog colors. */
pDlgItem->offPresParams = pcDlgData - (PCHAR)pTemplate;
((PPRESPARAMS)pcDlgData)->cb = 44;
pcDlgData += 4;
((PPARAM)pcDlgData)->id = PP_FOREGROUNDCOLOR;
((PPARAM)pcDlgData)->cb = 3;
((PPARAM)pcDlgData)->ab[0] = pSDLColor->b;
((PPARAM)pcDlgData)->ab[1] = pSDLColor->g;
((PPARAM)pcDlgData)->ab[2] = pSDLColor->r;
pcDlgData += 11;
((PPARAM)pcDlgData)->id = PP_BACKGROUNDCOLOR;
((PPARAM)pcDlgData)->cb = 3;
((PPARAM)pcDlgData)->ab[0] = pSDLColors[SDL_MESSAGEBOX_COLOR_BUTTON_BACKGROUND].b;
((PPARAM)pcDlgData)->ab[1] = pSDLColors[SDL_MESSAGEBOX_COLOR_BUTTON_BACKGROUND].g;
((PPARAM)pcDlgData)->ab[2] = pSDLColors[SDL_MESSAGEBOX_COLOR_BUTTON_BACKGROUND].r;
pcDlgData += 11;
((PPARAM)pcDlgData)->id = PP_BORDERLIGHTCOLOR;
((PPARAM)pcDlgData)->cb = 3;
((PPARAM)pcDlgData)->ab[0] = pSDLColors[SDL_MESSAGEBOX_COLOR_BUTTON_BORDER].b;
((PPARAM)pcDlgData)->ab[1] = pSDLColors[SDL_MESSAGEBOX_COLOR_BUTTON_BORDER].g;
((PPARAM)pcDlgData)->ab[2] = pSDLColors[SDL_MESSAGEBOX_COLOR_BUTTON_BORDER].r;
pcDlgData += 11;
((PPARAM)pcDlgData)->id = PP_BORDERDARKCOLOR;
((PPARAM)pcDlgData)->cb = 3;
((PPARAM)pcDlgData)->ab[0] = pSDLColors[SDL_MESSAGEBOX_COLOR_BUTTON_BORDER].b;
((PPARAM)pcDlgData)->ab[1] = pSDLColors[SDL_MESSAGEBOX_COLOR_BUTTON_BORDER].g;
((PPARAM)pcDlgData)->ab[2] = pSDLColors[SDL_MESSAGEBOX_COLOR_BUTTON_BORDER].r;
pcDlgData += 11;
}
pDlgItem->offCtlData = 0;
}
/* Check, end of templ. data: &((PCHAR)pTemplate)[cbTemplate] == pcDlgData */
/* Create the dialog from template. */
stDlgData.cb = sizeof(MSGBOXDLGDATA);
stDlgData.hwndUnder = (messageboxdata->window != NULL && messageboxdata->window->driverdata != NULL)?
((WINDATA *)messageboxdata->window->driverdata)->hwnd : HWND_DESKTOP;
hwnd = WinCreateDlg(HWND_DESKTOP, /* Parent is desktop. */
stDlgData.hwndUnder,
(PFNWP)DynDlgProc, pTemplate, &stDlgData);
SDL_free(pTemplate);
SDL_free(pszTitle);
SDL_free(pszText);
return hwnd;
}
int OS2_ShowMessageBox(const SDL_MessageBoxData *messageboxdata, int *buttonid)
{
HWND hwnd;
ULONG ulRC;
SDL_MessageBoxButtonData
*pSDLBtnData = (SDL_MessageBoxButtonData *)messageboxdata->buttons;
ULONG cSDLBtnData = messageboxdata->numbuttons;
BOOL fVideoInitialized = SDL_WasInit(SDL_INIT_VIDEO);
HAB hab;
HMQ hmq;
BOOL fSuccess = FALSE;
if (!fVideoInitialized) {
PTIB tib;
PPIB pib;
DosGetInfoBlocks(&tib, &pib);
if (pib->pib_ultype == 2 || pib->pib_ultype == 0) {
/* VIO windowable or fullscreen protect-mode session */
pib->pib_ultype = 3; /* Presentation Manager protect-mode session */
}
hab = WinInitialize(0);
if (hab == NULLHANDLE) {
debug_os2("WinInitialize() failed");
return -1;
}
hmq = WinCreateMsgQueue(hab, 0);
if (hmq == NULLHANDLE) {
debug_os2("WinCreateMsgQueue() failed");
return -1;
}
}
/* Create dynamic dialog. */
hwnd = _makeDlg(messageboxdata);
/* Show dialog and obtain button Id. */
ulRC = WinProcessDlg(hwnd);
/* Destroy dialog, */
WinDestroyWindow(hwnd);
if (ulRC == DID_CANCEL) {
/* Window closed by ESC, Alt+F4 or system menu. */
ULONG ulIdx;
for (ulIdx = 0; ulIdx < cSDLBtnData; ulIdx++, pSDLBtnData++) {
if (pSDLBtnData->flags == SDL_MESSAGEBOX_BUTTON_ESCAPEKEY_DEFAULT) {
*buttonid = pSDLBtnData->buttonid;
fSuccess = TRUE;
break;
}
}
} else {
/* Button pressed. */
ulRC -= IDD_PB_FIRST;
if (ulRC < cSDLBtnData) {
*buttonid = pSDLBtnData[ulRC].buttonid;
fSuccess = TRUE;
}
}
if (!fVideoInitialized) {
WinDestroyMsgQueue(hmq);
WinTerminate(hab);
}
return (fSuccess)? 0 : -1;
}
#endif /* SDL_VIDEO_DRIVER_OS2 */
/* vi: set ts=4 sw=4 expandtab: */