| 1 | /* $Id: msgbox.c,v 1.1 2000-01-12 12:41:20 sandervl Exp $ */ | 
|---|
| 2 | /* | 
|---|
| 3 | * Message boxes (based on Wine code) | 
|---|
| 4 | * | 
|---|
| 5 | * Copyright 1995 Bernd Schmidt | 
|---|
| 6 | * | 
|---|
| 7 | * | 
|---|
| 8 | */ | 
|---|
| 9 | #include <win\winbase.h> | 
|---|
| 10 | #include <win\winuser.h> | 
|---|
| 11 | #include <string.h> | 
|---|
| 12 | #include <dlgs.h> | 
|---|
| 13 | #include <misc.h> | 
|---|
| 14 | #include <heapstring.h> | 
|---|
| 15 |  | 
|---|
| 16 | #define MSGBOX_IDICON 1088 | 
|---|
| 17 | #define MSGBOX_IDTEXT 100 | 
|---|
| 18 |  | 
|---|
| 19 | static HFONT MSGBOX_OnInit(HWND hwnd, LPMSGBOXPARAMSA lpmb) | 
|---|
| 20 | { | 
|---|
| 21 | static HFONT hFont = 0, hPrevFont = 0; | 
|---|
| 22 | RECT rect; | 
|---|
| 23 | HWND hItem; | 
|---|
| 24 | HDC hdc; | 
|---|
| 25 | int i, buttons; | 
|---|
| 26 | int bspace, bw, bh, theight, tleft, wwidth, wheight, bpos; | 
|---|
| 27 | int borheight, borwidth, iheight, ileft, iwidth, twidth, tiheight; | 
|---|
| 28 | LPCSTR lpszText; | 
|---|
| 29 | char buf[256]; | 
|---|
| 30 |  | 
|---|
| 31 | ////    if (TWEAK_WineLook >= WIN95_LOOK) { | 
|---|
| 32 | NONCLIENTMETRICSA nclm; | 
|---|
| 33 | ////    INT i; | 
|---|
| 34 | nclm.cbSize = sizeof(NONCLIENTMETRICSA); | 
|---|
| 35 | SystemParametersInfoA (SPI_GETNONCLIENTMETRICS, 0, &nclm, 0); | 
|---|
| 36 | hFont = CreateFontIndirectA (&nclm.lfMessageFont); | 
|---|
| 37 | /* set button font */ | 
|---|
| 38 | for (i=1; i < 8; i++) | 
|---|
| 39 | SendDlgItemMessageA (hwnd, i, WM_SETFONT, (WPARAM)hFont, 0); | 
|---|
| 40 | /* set text font */ | 
|---|
| 41 | SendDlgItemMessageA (hwnd, MSGBOX_IDTEXT, WM_SETFONT, (WPARAM)hFont, 0); | 
|---|
| 42 | ////    } | 
|---|
| 43 | if (HIWORD(lpmb->lpszCaption)) { | 
|---|
| 44 | SetWindowTextA(hwnd, lpmb->lpszCaption); | 
|---|
| 45 | } else { | 
|---|
| 46 | if (LoadStringA(lpmb->hInstance, LOWORD(lpmb->lpszCaption), buf, sizeof(buf))) | 
|---|
| 47 | SetWindowTextA(hwnd, buf); | 
|---|
| 48 | } | 
|---|
| 49 | if (HIWORD(lpmb->lpszText)) { | 
|---|
| 50 | lpszText = lpmb->lpszText; | 
|---|
| 51 | } else { | 
|---|
| 52 | lpszText = buf; | 
|---|
| 53 | if (!LoadStringA(lpmb->hInstance, LOWORD(lpmb->lpszText), buf, sizeof(buf))) | 
|---|
| 54 | *buf = 0;     /* FIXME ?? */ | 
|---|
| 55 | } | 
|---|
| 56 | SetWindowTextA(GetDlgItem(hwnd, MSGBOX_IDTEXT), lpszText); | 
|---|
| 57 |  | 
|---|
| 58 | /* Hide not selected buttons */ | 
|---|
| 59 | switch(lpmb->dwStyle & MB_TYPEMASK) { | 
|---|
| 60 | case MB_OK: | 
|---|
| 61 | ShowWindow(GetDlgItem(hwnd, IDCANCEL), SW_HIDE); | 
|---|
| 62 | /* fall through */ | 
|---|
| 63 | case MB_OKCANCEL: | 
|---|
| 64 | ShowWindow(GetDlgItem(hwnd, IDABORT), SW_HIDE); | 
|---|
| 65 | ShowWindow(GetDlgItem(hwnd, IDRETRY), SW_HIDE); | 
|---|
| 66 | ShowWindow(GetDlgItem(hwnd, IDIGNORE), SW_HIDE); | 
|---|
| 67 | ShowWindow(GetDlgItem(hwnd, IDYES), SW_HIDE); | 
|---|
| 68 | ShowWindow(GetDlgItem(hwnd, IDNO), SW_HIDE); | 
|---|
| 69 | break; | 
|---|
| 70 | case MB_ABORTRETRYIGNORE: | 
|---|
| 71 | ShowWindow(GetDlgItem(hwnd, IDOK), SW_HIDE); | 
|---|
| 72 | ShowWindow(GetDlgItem(hwnd, IDCANCEL), SW_HIDE); | 
|---|
| 73 | ShowWindow(GetDlgItem(hwnd, IDYES), SW_HIDE); | 
|---|
| 74 | ShowWindow(GetDlgItem(hwnd, IDNO), SW_HIDE); | 
|---|
| 75 | break; | 
|---|
| 76 | case MB_YESNO: | 
|---|
| 77 | ShowWindow(GetDlgItem(hwnd, IDCANCEL), SW_HIDE); | 
|---|
| 78 | /* fall through */ | 
|---|
| 79 | case MB_YESNOCANCEL: | 
|---|
| 80 | ShowWindow(GetDlgItem(hwnd, IDOK), SW_HIDE); | 
|---|
| 81 | ShowWindow(GetDlgItem(hwnd, IDABORT), SW_HIDE); | 
|---|
| 82 | ShowWindow(GetDlgItem(hwnd, IDRETRY), SW_HIDE); | 
|---|
| 83 | ShowWindow(GetDlgItem(hwnd, IDIGNORE), SW_HIDE); | 
|---|
| 84 | break; | 
|---|
| 85 | case MB_RETRYCANCEL: | 
|---|
| 86 | ShowWindow(GetDlgItem(hwnd, IDOK), SW_HIDE); | 
|---|
| 87 | ShowWindow(GetDlgItem(hwnd, IDABORT), SW_HIDE); | 
|---|
| 88 | ShowWindow(GetDlgItem(hwnd, IDIGNORE), SW_HIDE); | 
|---|
| 89 | ShowWindow(GetDlgItem(hwnd, IDYES), SW_HIDE); | 
|---|
| 90 | ShowWindow(GetDlgItem(hwnd, IDNO), SW_HIDE); | 
|---|
| 91 | break; | 
|---|
| 92 | } | 
|---|
| 93 | /* Set the icon */ | 
|---|
| 94 | switch(lpmb->dwStyle & MB_ICONMASK) { | 
|---|
| 95 | case MB_ICONEXCLAMATION: | 
|---|
| 96 | SendDlgItemMessageA(hwnd, stc1, STM_SETICON, | 
|---|
| 97 | (WPARAM)LoadIconA(0, IDI_EXCLAMATIONA), 0); | 
|---|
| 98 | break; | 
|---|
| 99 | case MB_ICONQUESTION: | 
|---|
| 100 | SendDlgItemMessageA(hwnd, stc1, STM_SETICON, | 
|---|
| 101 | (WPARAM)LoadIconA(0, IDI_QUESTIONA), 0); | 
|---|
| 102 | break; | 
|---|
| 103 | case MB_ICONASTERISK: | 
|---|
| 104 | SendDlgItemMessageA(hwnd, stc1, STM_SETICON, | 
|---|
| 105 | (WPARAM)LoadIconA(0, IDI_ASTERISKA), 0); | 
|---|
| 106 | break; | 
|---|
| 107 | case MB_ICONHAND: | 
|---|
| 108 | default: | 
|---|
| 109 | SendDlgItemMessageA(hwnd, stc1, STM_SETICON, | 
|---|
| 110 | (WPARAM)LoadIconA(0, IDI_HANDA), 0); | 
|---|
| 111 | break; | 
|---|
| 112 | } | 
|---|
| 113 |  | 
|---|
| 114 | /* Position everything */ | 
|---|
| 115 | GetWindowRect(hwnd, &rect); | 
|---|
| 116 | borheight = rect.bottom - rect.top; | 
|---|
| 117 | borwidth  = rect.right - rect.left; | 
|---|
| 118 | GetClientRect(hwnd, &rect); | 
|---|
| 119 | borheight -= rect.bottom - rect.top; | 
|---|
| 120 | borwidth  -= rect.right - rect.left; | 
|---|
| 121 |  | 
|---|
| 122 | /* Get the icon height */ | 
|---|
| 123 | GetWindowRect(GetDlgItem(hwnd, MSGBOX_IDICON), &rect); | 
|---|
| 124 | MapWindowPoints(0, hwnd, (LPPOINT)&rect, 2); | 
|---|
| 125 | iheight = rect.bottom - rect.top; | 
|---|
| 126 | ileft = rect.left; | 
|---|
| 127 | iwidth = rect.right - ileft; | 
|---|
| 128 |  | 
|---|
| 129 | hdc = GetDC(hwnd); | 
|---|
| 130 | if (hFont) | 
|---|
| 131 | hPrevFont = SelectObject(hdc, hFont); | 
|---|
| 132 |  | 
|---|
| 133 | /* Get the number of visible buttons and their size */ | 
|---|
| 134 | bh = bw = 1; /* Minimum button sizes */ | 
|---|
| 135 | for (buttons = 0, i = 1; i < 8; i++) | 
|---|
| 136 | { | 
|---|
| 137 | hItem = GetDlgItem(hwnd, i); | 
|---|
| 138 | if (GetWindowLongA(hItem, GWL_STYLE) & WS_VISIBLE) | 
|---|
| 139 | { | 
|---|
| 140 | char buttonText[1024]; | 
|---|
| 141 | int w, h; | 
|---|
| 142 | buttons++; | 
|---|
| 143 | if (GetWindowTextA(hItem, buttonText, sizeof buttonText)) | 
|---|
| 144 | { | 
|---|
| 145 | DrawTextA( hdc, buttonText, -1, &rect, DT_LEFT | DT_EXPANDTABS | DT_CALCRECT); | 
|---|
| 146 | h = rect.bottom - rect.top; | 
|---|
| 147 | w = rect.right - rect.left; | 
|---|
| 148 | if (h > bh) bh = h; | 
|---|
| 149 | if (w > bw)  bw = w ; | 
|---|
| 150 | } | 
|---|
| 151 | } | 
|---|
| 152 | } | 
|---|
| 153 | bw = MAX(bw, bh * 2); | 
|---|
| 154 | /* Button white space */ | 
|---|
| 155 | bh = bh * 2; | 
|---|
| 156 | bw = bw * 2; | 
|---|
| 157 | bspace = bw/3; /* Space between buttons */ | 
|---|
| 158 |  | 
|---|
| 159 | /* Get the text size */ | 
|---|
| 160 | GetClientRect(GetDlgItem(hwnd, MSGBOX_IDTEXT), &rect); | 
|---|
| 161 | rect.top = rect.left = rect.bottom = 0; | 
|---|
| 162 | DrawTextA( hdc, lpszText, -1, &rect, | 
|---|
| 163 | DT_LEFT | DT_EXPANDTABS | DT_WORDBREAK | DT_CALCRECT); | 
|---|
| 164 | /* Min text width corresponds to space for the buttons */ | 
|---|
| 165 | tleft = 2 * ileft + iwidth; | 
|---|
| 166 | twidth = MAX((bw + bspace) * buttons + bspace - tleft, rect.right); | 
|---|
| 167 | theight = rect.bottom; | 
|---|
| 168 |  | 
|---|
| 169 | if (hFont) | 
|---|
| 170 | SelectObject(hdc, hPrevFont); | 
|---|
| 171 | ReleaseDC(hItem, hdc); | 
|---|
| 172 |  | 
|---|
| 173 | tiheight = 16 + MAX(iheight, theight); | 
|---|
| 174 | wwidth  = tleft + twidth + ileft + borwidth; | 
|---|
| 175 | wheight = 8 + tiheight + bh + borheight; | 
|---|
| 176 |  | 
|---|
| 177 | /* Resize the window */ | 
|---|
| 178 | SetWindowPos(hwnd, 0, 0, 0, wwidth, wheight, | 
|---|
| 179 | SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOREDRAW); | 
|---|
| 180 |  | 
|---|
| 181 | /* Position the icon */ | 
|---|
| 182 | SetWindowPos(GetDlgItem(hwnd, MSGBOX_IDICON), 0, ileft, (tiheight - iheight) / 2, 0, 0, | 
|---|
| 183 | SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOREDRAW); | 
|---|
| 184 |  | 
|---|
| 185 | /* Position the text */ | 
|---|
| 186 | SetWindowPos(GetDlgItem(hwnd, MSGBOX_IDTEXT), 0, tleft, (tiheight - theight) / 2, twidth, theight, | 
|---|
| 187 | SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOREDRAW); | 
|---|
| 188 |  | 
|---|
| 189 | /* Position the buttons */ | 
|---|
| 190 | bpos = (wwidth - (bw + bspace) * buttons + bspace) / 2; | 
|---|
| 191 | for (buttons = i = 0; i < 7; i++) { | 
|---|
| 192 | /* some arithmetic to get the right order for YesNoCancel windows */ | 
|---|
| 193 | hItem = GetDlgItem(hwnd, (i + 5) % 7 + 1); | 
|---|
| 194 | if (GetWindowLongA(hItem, GWL_STYLE) & WS_VISIBLE) { | 
|---|
| 195 | if (buttons++ == ((lpmb->dwStyle & MB_DEFMASK) >> 8)) { | 
|---|
| 196 | SetFocus(hItem); | 
|---|
| 197 | SendMessageA( hItem, BM_SETSTYLE, BS_DEFPUSHBUTTON, TRUE ); | 
|---|
| 198 | } | 
|---|
| 199 | SetWindowPos(hItem, 0, bpos, tiheight, bw, bh, | 
|---|
| 200 | SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOREDRAW); | 
|---|
| 201 | bpos += bw + bspace; | 
|---|
| 202 | } | 
|---|
| 203 | } | 
|---|
| 204 | return hFont; | 
|---|
| 205 | } | 
|---|
| 206 |  | 
|---|
| 207 |  | 
|---|
| 208 | /************************************************************************** | 
|---|
| 209 | *           MSGBOX_DlgProc | 
|---|
| 210 | * | 
|---|
| 211 | * Dialog procedure for message boxes. | 
|---|
| 212 | */ | 
|---|
| 213 | static LRESULT CALLBACK MSGBOX_DlgProc( HWND hwnd, UINT message, | 
|---|
| 214 | WPARAM wParam, LPARAM lParam ) | 
|---|
| 215 | { | 
|---|
| 216 | static HFONT hFont; | 
|---|
| 217 | switch(message) { | 
|---|
| 218 | case WM_INITDIALOG: | 
|---|
| 219 | hFont = MSGBOX_OnInit(hwnd, (LPMSGBOXPARAMSA)lParam); | 
|---|
| 220 | return 0; | 
|---|
| 221 |  | 
|---|
| 222 | case WM_COMMAND: | 
|---|
| 223 | switch (wParam) | 
|---|
| 224 | { | 
|---|
| 225 | case IDOK: | 
|---|
| 226 | case IDCANCEL: | 
|---|
| 227 | case IDABORT: | 
|---|
| 228 | case IDRETRY: | 
|---|
| 229 | case IDIGNORE: | 
|---|
| 230 | case IDYES: | 
|---|
| 231 | case IDNO: | 
|---|
| 232 | EndDialog(hwnd, wParam); | 
|---|
| 233 | if (hFont) | 
|---|
| 234 | DeleteObject(hFont); | 
|---|
| 235 | break; | 
|---|
| 236 | } | 
|---|
| 237 |  | 
|---|
| 238 | default: | 
|---|
| 239 | /* Ok. Ignore all the other messages */ | 
|---|
| 240 | //TRACE("Message number %i is being ignored.\n", message); | 
|---|
| 241 | break; | 
|---|
| 242 | } | 
|---|
| 243 | return 0; | 
|---|
| 244 | } | 
|---|
| 245 |  | 
|---|
| 246 | /************************************************************************** | 
|---|
| 247 | *           MessageBox32A   (USER32.391) | 
|---|
| 248 | * | 
|---|
| 249 | * NOTES | 
|---|
| 250 | *   The WARN is here to help debug erroneous MessageBoxes | 
|---|
| 251 | *   Use: -debugmsg warn+dialog,+relay | 
|---|
| 252 | */ | 
|---|
| 253 | INT WINAPI MessageBoxA(HWND hWnd, LPCSTR text, LPCSTR title, UINT type) | 
|---|
| 254 | { | 
|---|
| 255 | LPVOID lpTemplate; | 
|---|
| 256 | HRSRC hRes; | 
|---|
| 257 | MSGBOXPARAMSA mbox; | 
|---|
| 258 |  | 
|---|
| 259 | dprintf(("MessageBoxA %x %s %s %x", hWnd, text, title, type)); | 
|---|
| 260 |  | 
|---|
| 261 | if(!(hRes = FindResourceA(GetModuleHandleA("USER32"), "MSGBOX", RT_DIALOGA))) | 
|---|
| 262 | return 0; | 
|---|
| 263 | if(!(lpTemplate = (LPVOID)LoadResource(GetModuleHandleA("USER32"), hRes))) | 
|---|
| 264 | return 0; | 
|---|
| 265 |  | 
|---|
| 266 | if (!text) text="<ODIN-NULL>"; | 
|---|
| 267 | if (!title) | 
|---|
| 268 | title="Error"; | 
|---|
| 269 | mbox.lpszCaption = title; | 
|---|
| 270 | mbox.lpszText  = text; | 
|---|
| 271 | mbox.dwStyle  = type; | 
|---|
| 272 | return DialogBoxIndirectParamA( GetWindowLongA(hWnd,GWL_HINSTANCE), lpTemplate, | 
|---|
| 273 | hWnd, (DLGPROC)MSGBOX_DlgProc, (LPARAM)&mbox ); | 
|---|
| 274 | } | 
|---|
| 275 |  | 
|---|
| 276 |  | 
|---|
| 277 | /************************************************************************** | 
|---|
| 278 | *           MessageBox32W   (USER32.396) | 
|---|
| 279 | */ | 
|---|
| 280 | INT WINAPI MessageBoxW( HWND hwnd, LPCWSTR text, LPCWSTR title, | 
|---|
| 281 | UINT type ) | 
|---|
| 282 | { | 
|---|
| 283 | LPSTR titleA = HEAP_strdupWtoA( GetProcessHeap(), 0, title ); | 
|---|
| 284 | LPSTR textA  = HEAP_strdupWtoA( GetProcessHeap(), 0, text ); | 
|---|
| 285 | INT ret; | 
|---|
| 286 |  | 
|---|
| 287 | ret = MessageBoxA( hwnd, textA, titleA, type ); | 
|---|
| 288 | HeapFree( GetProcessHeap(), 0, titleA ); | 
|---|
| 289 | HeapFree( GetProcessHeap(), 0, textA ); | 
|---|
| 290 | return ret; | 
|---|
| 291 | } | 
|---|
| 292 |  | 
|---|
| 293 |  | 
|---|
| 294 | /************************************************************************** | 
|---|
| 295 | *           MessageBoxEx32A   (USER32.392) | 
|---|
| 296 | */ | 
|---|
| 297 | INT WINAPI MessageBoxExA( HWND hWnd, LPCSTR text, LPCSTR title, | 
|---|
| 298 | UINT type, WORD langid ) | 
|---|
| 299 | { | 
|---|
| 300 | /* ignore language id for now */ | 
|---|
| 301 | return MessageBoxA(hWnd,text,title,type); | 
|---|
| 302 | } | 
|---|
| 303 |  | 
|---|
| 304 | /************************************************************************** | 
|---|
| 305 | *           MessageBoxEx32W   (USER32.393) | 
|---|
| 306 | */ | 
|---|
| 307 | INT WINAPI MessageBoxExW( HWND hWnd, LPCWSTR text, LPCWSTR title, | 
|---|
| 308 | UINT type, WORD langid ) | 
|---|
| 309 | { | 
|---|
| 310 | /* ignore language id for now */ | 
|---|
| 311 | return MessageBoxW(hWnd,text,title,type); | 
|---|
| 312 | } | 
|---|
| 313 |  | 
|---|
| 314 |  | 
|---|
| 315 | /************************************************************************** | 
|---|
| 316 | *           MessageBoxIndirect32A   (USER32.394) | 
|---|
| 317 | */ | 
|---|
| 318 | INT WINAPI MessageBoxIndirectA( LPMSGBOXPARAMSA msgbox ) | 
|---|
| 319 | { | 
|---|
| 320 | LPVOID lpTemplate; | 
|---|
| 321 | HRSRC hRes; | 
|---|
| 322 |  | 
|---|
| 323 | dprintf(("MessageBoxIndirectA %x", msgbox)); | 
|---|
| 324 |  | 
|---|
| 325 | if(!(hRes = FindResourceA(GetModuleHandleA("USER32"), "MSGBOX", RT_DIALOGA))) | 
|---|
| 326 | return 0; | 
|---|
| 327 | if(!(lpTemplate = (LPVOID)LoadResource(GetModuleHandleA("USER32"), hRes))) | 
|---|
| 328 | return 0; | 
|---|
| 329 |  | 
|---|
| 330 | return DialogBoxIndirectParamA( msgbox->hInstance, lpTemplate, | 
|---|
| 331 | msgbox->hwndOwner, (DLGPROC)MSGBOX_DlgProc, | 
|---|
| 332 | (LPARAM)msgbox ); | 
|---|
| 333 | } | 
|---|
| 334 |  | 
|---|
| 335 | /************************************************************************** | 
|---|
| 336 | *           MessageBoxIndirect32W   (USER32.395) | 
|---|
| 337 | */ | 
|---|
| 338 | INT WINAPI MessageBoxIndirectW( LPMSGBOXPARAMSW msgbox ) | 
|---|
| 339 | { | 
|---|
| 340 | MSGBOXPARAMSA       msgboxa; | 
|---|
| 341 |  | 
|---|
| 342 | memcpy(&msgboxa,msgbox,sizeof(msgboxa)); | 
|---|
| 343 | if (msgbox->lpszCaption) | 
|---|
| 344 | lstrcpyWtoA((LPSTR)msgboxa.lpszCaption,msgbox->lpszCaption); | 
|---|
| 345 | if (msgbox->lpszText) | 
|---|
| 346 | lstrcpyWtoA((LPSTR)msgboxa.lpszText,msgbox->lpszText); | 
|---|
| 347 |  | 
|---|
| 348 | return MessageBoxIndirectA(&msgboxa); | 
|---|
| 349 | } | 
|---|
| 350 |  | 
|---|
| 351 | /***************************************************************************** | 
|---|
| 352 | * Name      : BOOL WIN32API SysErrorBox | 
|---|
| 353 | * Purpose   : Unknown | 
|---|
| 354 | * Parameters: Unknown | 
|---|
| 355 | * Variables : | 
|---|
| 356 | * Result    : | 
|---|
| 357 | * Remark    : HARDERR like ? | 
|---|
| 358 | * Status    : UNTESTED UNKNOWN STUB | 
|---|
| 359 | * | 
|---|
| 360 | * Author    : Patrick Haller [Wed, 1998/06/16 11:55] | 
|---|
| 361 | *****************************************************************************/ | 
|---|
| 362 |  | 
|---|
| 363 | BOOL WIN32API SysErrorBox(DWORD x1, | 
|---|
| 364 | DWORD x2, | 
|---|
| 365 | DWORD x3) | 
|---|
| 366 | { | 
|---|
| 367 | dprintf(("USER32: SysErrorBox(%08xh,%08xh,%08xh) not implemented.\n", | 
|---|
| 368 | x1, | 
|---|
| 369 | x2, | 
|---|
| 370 | x3)); | 
|---|
| 371 |  | 
|---|
| 372 | return (FALSE); /* default */ | 
|---|
| 373 | } | 
|---|