Commit | Line | Data |
---|---|---|
2787be87 AJ |
1 | /* |
2 | * Message boxes | |
3 | * | |
4 | * Copyright 1995 Bernd Schmidt | |
2787be87 AJ |
5 | */ |
6 | ||
ee517e86 | 7 | #include <string.h> |
ca1bc866 | 8 | #include "wine/winuser16.h" |
2787be87 | 9 | #include "dlgs.h" |
7ebe1a41 | 10 | #include "heap.h" |
d7c565f5 | 11 | #include "ldt.h" |
54c2711f AJ |
12 | #include "debug.h" |
13 | #include "debugstr.h" | |
d30dfd24 | 14 | #include "tweak.h" |
2787be87 | 15 | |
b4b9fae6 PS |
16 | DEFAULT_DEBUG_CHANNEL(dialog) |
17 | ||
9ea19e54 AJ |
18 | /************************************************************************** |
19 | * MSGBOX_DlgProc | |
20 | * | |
21 | * Dialog procedure for message boxes. | |
22 | */ | |
a3960292 AJ |
23 | static LRESULT CALLBACK MSGBOX_DlgProc( HWND hwnd, UINT message, |
24 | WPARAM wParam, LPARAM lParam ) | |
2787be87 | 25 | { |
a3960292 AJ |
26 | static HFONT hFont = 0; |
27 | LPMSGBOXPARAMSA lpmb; | |
44ed71f5 | 28 | |
a3960292 AJ |
29 | RECT rect, textrect; |
30 | HWND hItem; | |
31 | HDC hdc; | |
9ea19e54 | 32 | LRESULT lRet; |
2787be87 AJ |
33 | int i, buttons, bwidth, bheight, theight, wwidth, bpos; |
34 | int borheight, iheight, tiheight; | |
35 | ||
36 | switch(message) { | |
37 | case WM_INITDIALOG: | |
a3960292 | 38 | lpmb = (LPMSGBOXPARAMSA)lParam; |
d30dfd24 | 39 | if (TWEAK_WineLook >= WIN95_LOOK) { |
a3960292 AJ |
40 | NONCLIENTMETRICSA nclm; |
41 | INT i; | |
42 | nclm.cbSize = sizeof(NONCLIENTMETRICSA); | |
43 | SystemParametersInfoA (SPI_GETNONCLIENTMETRICS, 0, &nclm, 0); | |
44 | hFont = CreateFontIndirectA (&nclm.lfMessageFont); | |
d30dfd24 AJ |
45 | /* set button font */ |
46 | for (i=1; i < 8; i++) | |
a3960292 | 47 | SendDlgItemMessageA (hwnd, i, WM_SETFONT, (WPARAM)hFont, 0); |
d30dfd24 | 48 | /* set text font */ |
a3960292 | 49 | SendDlgItemMessageA (hwnd, 100, WM_SETFONT, (WPARAM)hFont, 0); |
d30dfd24 | 50 | } |
a3960292 AJ |
51 | if (lpmb->lpszCaption) SetWindowTextA(hwnd, lpmb->lpszCaption); |
52 | SetWindowTextA(GetDlgItem(hwnd, 100), lpmb->lpszText); | |
2787be87 | 53 | /* Hide not selected buttons */ |
44ed71f5 | 54 | switch(lpmb->dwStyle & MB_TYPEMASK) { |
2787be87 | 55 | case MB_OK: |
a3960292 | 56 | ShowWindow(GetDlgItem(hwnd, 2), SW_HIDE); |
2787be87 AJ |
57 | /* fall through */ |
58 | case MB_OKCANCEL: | |
a3960292 AJ |
59 | ShowWindow(GetDlgItem(hwnd, 3), SW_HIDE); |
60 | ShowWindow(GetDlgItem(hwnd, 4), SW_HIDE); | |
61 | ShowWindow(GetDlgItem(hwnd, 5), SW_HIDE); | |
62 | ShowWindow(GetDlgItem(hwnd, 6), SW_HIDE); | |
63 | ShowWindow(GetDlgItem(hwnd, 7), SW_HIDE); | |
2787be87 AJ |
64 | break; |
65 | case MB_ABORTRETRYIGNORE: | |
a3960292 AJ |
66 | ShowWindow(GetDlgItem(hwnd, 1), SW_HIDE); |
67 | ShowWindow(GetDlgItem(hwnd, 2), SW_HIDE); | |
68 | ShowWindow(GetDlgItem(hwnd, 6), SW_HIDE); | |
69 | ShowWindow(GetDlgItem(hwnd, 7), SW_HIDE); | |
2787be87 AJ |
70 | break; |
71 | case MB_YESNO: | |
a3960292 | 72 | ShowWindow(GetDlgItem(hwnd, 2), SW_HIDE); |
2787be87 AJ |
73 | /* fall through */ |
74 | case MB_YESNOCANCEL: | |
a3960292 AJ |
75 | ShowWindow(GetDlgItem(hwnd, 1), SW_HIDE); |
76 | ShowWindow(GetDlgItem(hwnd, 3), SW_HIDE); | |
77 | ShowWindow(GetDlgItem(hwnd, 4), SW_HIDE); | |
78 | ShowWindow(GetDlgItem(hwnd, 5), SW_HIDE); | |
2787be87 AJ |
79 | break; |
80 | } | |
81 | /* Set the icon */ | |
44ed71f5 | 82 | switch(lpmb->dwStyle & MB_ICONMASK) { |
2787be87 | 83 | case MB_ICONEXCLAMATION: |
491502b9 | 84 | SendDlgItemMessage16(hwnd, stc1, STM_SETICON16, |
c7c217b3 | 85 | (WPARAM16)LoadIcon16(0, IDI_EXCLAMATION16), 0); |
2787be87 AJ |
86 | break; |
87 | case MB_ICONQUESTION: | |
491502b9 | 88 | SendDlgItemMessage16(hwnd, stc1, STM_SETICON16, |
c7c217b3 | 89 | (WPARAM16)LoadIcon16(0, IDI_QUESTION16), 0); |
2787be87 AJ |
90 | break; |
91 | case MB_ICONASTERISK: | |
491502b9 | 92 | SendDlgItemMessage16(hwnd, stc1, STM_SETICON16, |
c7c217b3 | 93 | (WPARAM16)LoadIcon16(0, IDI_ASTERISK16), 0); |
2787be87 AJ |
94 | break; |
95 | case MB_ICONHAND: | |
bd34d4ff | 96 | default: |
491502b9 | 97 | SendDlgItemMessage16(hwnd, stc1, STM_SETICON16, |
c7c217b3 | 98 | (WPARAM16)LoadIcon16(0, IDI_HAND16), 0); |
2787be87 AJ |
99 | break; |
100 | } | |
101 | ||
102 | /* Position everything */ | |
a3960292 | 103 | GetWindowRect(hwnd, &rect); |
2787be87 AJ |
104 | borheight = rect.bottom - rect.top; |
105 | wwidth = rect.right - rect.left; | |
a3960292 | 106 | GetClientRect(hwnd, &rect); |
2787be87 AJ |
107 | borheight -= rect.bottom - rect.top; |
108 | ||
109 | /* Get the icon height */ | |
a3960292 | 110 | GetWindowRect(GetDlgItem(hwnd, 1088), &rect); |
2787be87 AJ |
111 | iheight = rect.bottom - rect.top; |
112 | ||
113 | /* Get the number of visible buttons and their width */ | |
a3960292 | 114 | GetWindowRect(GetDlgItem(hwnd, 2), &rect); |
2787be87 AJ |
115 | bheight = rect.bottom - rect.top; |
116 | bwidth = rect.left; | |
a3960292 | 117 | GetWindowRect(GetDlgItem(hwnd, 1), &rect); |
2787be87 | 118 | bwidth -= rect.left; |
1e9ac798 AJ |
119 | for (buttons = 0, i = 1; i < 8; i++) |
120 | { | |
a3960292 AJ |
121 | hItem = GetDlgItem(hwnd, i); |
122 | if (GetWindowLongA(hItem, GWL_STYLE) & WS_VISIBLE) buttons++; | |
2787be87 AJ |
123 | } |
124 | ||
125 | /* Get the text size */ | |
a3960292 AJ |
126 | hItem = GetDlgItem(hwnd, 100); |
127 | GetWindowRect(hItem, &textrect); | |
128 | MapWindowPoints(0, hwnd, (LPPOINT)&textrect, 2); | |
2787be87 | 129 | |
a3960292 AJ |
130 | GetClientRect(hItem, &rect); |
131 | hdc = GetDC(hItem); | |
132 | lRet = DrawTextA( hdc, lpmb->lpszText, -1, &rect, | |
9ea19e54 | 133 | DT_LEFT | DT_EXPANDTABS | DT_WORDBREAK | DT_CALCRECT); |
2787be87 | 134 | theight = rect.bottom - rect.top; |
902da699 | 135 | tiheight = 16 + MAX(iheight, theight); |
a3960292 | 136 | ReleaseDC(hItem, hdc); |
2787be87 AJ |
137 | |
138 | /* Position the text */ | |
a3960292 | 139 | SetWindowPos(hItem, 0, textrect.left, (tiheight - theight) / 2, |
01d6346a AJ |
140 | rect.right - rect.left, theight, |
141 | SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOREDRAW); | |
2787be87 AJ |
142 | |
143 | /* Position the icon */ | |
a3960292 AJ |
144 | hItem = GetDlgItem(hwnd, 1088); |
145 | GetWindowRect(hItem, &rect); | |
146 | MapWindowPoints(0, hwnd, (LPPOINT)&rect, 2); | |
147 | SetWindowPos(hItem, 0, rect.left, (tiheight - iheight) / 2, 0, 0, | |
01d6346a | 148 | SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOREDRAW); |
2787be87 AJ |
149 | |
150 | /* Resize the window */ | |
a3960292 | 151 | SetWindowPos(hwnd, 0, 0, 0, wwidth, 8 + tiheight + bheight + borheight, |
01d6346a | 152 | SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOREDRAW); |
2787be87 AJ |
153 | |
154 | /* Position the buttons */ | |
155 | bpos = (wwidth - bwidth * buttons) / 2; | |
a3960292 | 156 | GetWindowRect(GetDlgItem(hwnd, 1), &rect); |
2787be87 AJ |
157 | for (buttons = i = 0; i < 7; i++) { |
158 | /* some arithmetic to get the right order for YesNoCancel windows */ | |
a3960292 AJ |
159 | hItem = GetDlgItem(hwnd, (i + 5) % 7 + 1); |
160 | if (GetWindowLongA(hItem, GWL_STYLE) & WS_VISIBLE) { | |
44ed71f5 | 161 | if (buttons++ == ((lpmb->dwStyle & MB_DEFMASK) >> 8)) { |
a3960292 AJ |
162 | SetFocus(hItem); |
163 | SendMessageA( hItem, BM_SETSTYLE, BS_DEFPUSHBUTTON, TRUE ); | |
2787be87 | 164 | } |
a3960292 | 165 | SetWindowPos(hItem, 0, bpos, tiheight, 0, 0, |
01d6346a | 166 | SWP_NOSIZE|SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOREDRAW); |
2787be87 AJ |
167 | bpos += bwidth; |
168 | } | |
169 | } | |
170 | return 0; | |
171 | break; | |
172 | ||
173 | case WM_COMMAND: | |
9ea19e54 AJ |
174 | switch (wParam) |
175 | { | |
2787be87 AJ |
176 | case IDOK: |
177 | case IDCANCEL: | |
178 | case IDABORT: | |
179 | case IDRETRY: | |
180 | case IDIGNORE: | |
181 | case IDYES: | |
182 | case IDNO: | |
d30dfd24 | 183 | if ((TWEAK_WineLook > WIN31_LOOK) && hFont) |
a3960292 AJ |
184 | DeleteObject (hFont); |
185 | EndDialog(hwnd, wParam); | |
2787be87 AJ |
186 | break; |
187 | } | |
d30dfd24 | 188 | |
54c2711f AJ |
189 | default: |
190 | /* Ok. Ignore all the other messages */ | |
191 | TRACE (dialog, "Message number %i is being ignored.\n", message); | |
2787be87 AJ |
192 | break; |
193 | } | |
194 | return 0; | |
195 | } | |
196 | ||
9ea19e54 | 197 | |
2787be87 | 198 | /************************************************************************** |
b1bac320 | 199 | * MessageBox16 (USER.1) |
2787be87 | 200 | */ |
670cdc45 | 201 | INT16 WINAPI MessageBox16( HWND16 hwnd, LPCSTR text, LPCSTR title, UINT16 type) |
b1bac320 | 202 | { |
767e6f6f | 203 | WARN(dialog,"Messagebox\n"); |
a3960292 | 204 | return MessageBoxA( hwnd, text, title, type ); |
b1bac320 | 205 | } |
2787be87 | 206 | |
9ea19e54 | 207 | |
b1bac320 | 208 | /************************************************************************** |
c7c217b3 | 209 | * MessageBox32A (USER32.391) |
d30dfd24 AJ |
210 | * |
211 | * NOTES | |
212 | * The WARN is here to help debug erroneous MessageBoxes | |
213 | * Use: -debugmsg warn+dialog,+relay | |
b1bac320 | 214 | */ |
a3960292 | 215 | INT WINAPI MessageBoxA(HWND hWnd, LPCSTR text, LPCSTR title, UINT type) |
2787be87 | 216 | { |
d1895a77 BS |
217 | LPVOID template; |
218 | HRSRC hRes; | |
a3960292 | 219 | MSGBOXPARAMSA mbox; |
d1895a77 | 220 | |
767e6f6f | 221 | WARN(dialog,"Messagebox\n"); |
d1895a77 BS |
222 | |
223 | if(!(hRes = FindResourceA(GetModuleHandleA("USER32"), "MSGBOX", RT_DIALOGA))) | |
224 | return 0; | |
225 | if(!(template = (LPVOID)LoadResource(GetModuleHandleA("USER32"), hRes))) | |
226 | return 0; | |
227 | ||
349a9531 | 228 | if (!text) text="<WINE-NULL>"; |
54c2711f AJ |
229 | if (!title) |
230 | title="Error"; | |
44ed71f5 AJ |
231 | mbox.lpszCaption = title; |
232 | mbox.lpszText = text; | |
233 | mbox.dwStyle = type; | |
d7c565f5 | 234 | return DialogBoxIndirectParamA( GetWindowLongA(hWnd,GWL_HINSTANCE), template, |
a3960292 | 235 | hWnd, (DLGPROC)MSGBOX_DlgProc, (LPARAM)&mbox ); |
2787be87 AJ |
236 | } |
237 | ||
9ea19e54 | 238 | |
b1bac320 | 239 | /************************************************************************** |
c7c217b3 | 240 | * MessageBox32W (USER32.396) |
b1bac320 | 241 | */ |
a3960292 AJ |
242 | INT WINAPI MessageBoxW( HWND hwnd, LPCWSTR text, LPCWSTR title, |
243 | UINT type ) | |
b1bac320 | 244 | { |
9ea19e54 AJ |
245 | LPSTR titleA = HEAP_strdupWtoA( GetProcessHeap(), 0, title ); |
246 | LPSTR textA = HEAP_strdupWtoA( GetProcessHeap(), 0, text ); | |
a3960292 | 247 | INT ret; |
767e6f6f AJ |
248 | |
249 | WARN(dialog,"Messagebox\n"); | |
250 | ||
a3960292 | 251 | ret = MessageBoxA( hwnd, textA, titleA, type ); |
9ea19e54 AJ |
252 | HeapFree( GetProcessHeap(), 0, titleA ); |
253 | HeapFree( GetProcessHeap(), 0, textA ); | |
254 | return ret; | |
255 | } | |
b1bac320 | 256 | |
b1bac320 | 257 | |
349a9531 | 258 | /************************************************************************** |
c7c217b3 | 259 | * MessageBoxEx32A (USER32.392) |
349a9531 | 260 | */ |
a3960292 AJ |
261 | INT WINAPI MessageBoxExA( HWND hWnd, LPCSTR text, LPCSTR title, |
262 | UINT type, WORD langid ) | |
670cdc45 | 263 | { |
767e6f6f | 264 | WARN(dialog,"Messagebox\n"); |
349a9531 | 265 | /* ignore language id for now */ |
a3960292 | 266 | return MessageBoxA(hWnd,text,title,type); |
349a9531 AJ |
267 | } |
268 | ||
269 | /************************************************************************** | |
c7c217b3 | 270 | * MessageBoxEx32W (USER32.393) |
349a9531 | 271 | */ |
a3960292 AJ |
272 | INT WINAPI MessageBoxExW( HWND hWnd, LPCWSTR text, LPCWSTR title, |
273 | UINT type, WORD langid ) | |
349a9531 | 274 | { |
767e6f6f | 275 | WARN(dialog,"Messagebox\n"); |
349a9531 | 276 | /* ignore language id for now */ |
a3960292 | 277 | return MessageBoxW(hWnd,text,title,type); |
349a9531 AJ |
278 | } |
279 | ||
c7c217b3 AJ |
280 | /************************************************************************** |
281 | * MessageBoxIndirect16 (USER.827) | |
282 | */ | |
283 | INT16 WINAPI MessageBoxIndirect16( LPMSGBOXPARAMS16 msgbox ) | |
284 | { | |
d1895a77 BS |
285 | LPVOID template; |
286 | HRSRC hRes; | |
a3960292 | 287 | MSGBOXPARAMSA msgbox32; |
d1895a77 | 288 | |
767e6f6f | 289 | WARN(dialog,"Messagebox\n"); |
c7c217b3 | 290 | |
d1895a77 BS |
291 | if(!(hRes = FindResourceA(GetModuleHandleA("USER32"), "MSGBOX", RT_DIALOGA))) |
292 | return 0; | |
293 | if(!(template = (LPVOID)LoadResource(GetModuleHandleA("USER32"), hRes))) | |
294 | return 0; | |
295 | ||
c7c217b3 AJ |
296 | msgbox32.cbSize = msgbox->cbSize; |
297 | msgbox32.hwndOwner = msgbox->hwndOwner; | |
298 | msgbox32.hInstance = msgbox->hInstance; | |
299 | msgbox32.lpszText = PTR_SEG_TO_LIN(msgbox->lpszText); | |
300 | msgbox32.lpszCaption = PTR_SEG_TO_LIN(msgbox->lpszCaption); | |
301 | msgbox32.dwStyle = msgbox->dwStyle; | |
302 | msgbox32.lpszIcon = PTR_SEG_TO_LIN(msgbox->lpszIcon); | |
303 | msgbox32.dwContextHelpId = msgbox->dwContextHelpId; | |
304 | msgbox32.lpfnMsgBoxCallback = msgbox->lpfnMsgBoxCallback; | |
305 | msgbox32.dwLanguageId = msgbox->dwLanguageId; | |
306 | ||
d1895a77 | 307 | return DialogBoxIndirectParamA( msgbox32.hInstance, template, |
a3960292 | 308 | msgbox32.hwndOwner, (DLGPROC)MSGBOX_DlgProc, |
c7c217b3 AJ |
309 | (LPARAM)&msgbox32 ); |
310 | } | |
311 | ||
44ed71f5 AJ |
312 | /************************************************************************** |
313 | * MessageBoxIndirect32A (USER32.394) | |
314 | */ | |
a3960292 | 315 | INT WINAPI MessageBoxIndirectA( LPMSGBOXPARAMSA msgbox ) |
44ed71f5 | 316 | { |
d1895a77 BS |
317 | LPVOID template; |
318 | HRSRC hRes; | |
319 | ||
767e6f6f | 320 | WARN(dialog,"Messagebox\n"); |
d1895a77 BS |
321 | |
322 | if(!(hRes = FindResourceA(GetModuleHandleA("USER32"), "MSGBOX", RT_DIALOGA))) | |
323 | return 0; | |
324 | if(!(template = (LPVOID)LoadResource(GetModuleHandleA("USER32"), hRes))) | |
325 | return 0; | |
326 | ||
327 | return DialogBoxIndirectParamA( msgbox->hInstance, template, | |
a3960292 | 328 | msgbox->hwndOwner, (DLGPROC)MSGBOX_DlgProc, |
44ed71f5 AJ |
329 | (LPARAM)msgbox ); |
330 | } | |
331 | ||
332 | /************************************************************************** | |
333 | * MessageBoxIndirect32W (USER32.395) | |
334 | */ | |
a3960292 | 335 | INT WINAPI MessageBoxIndirectW( LPMSGBOXPARAMSW msgbox ) |
44ed71f5 | 336 | { |
a3960292 | 337 | MSGBOXPARAMSA msgboxa; |
767e6f6f | 338 | WARN(dialog,"Messagebox\n"); |
44ed71f5 AJ |
339 | |
340 | memcpy(&msgboxa,msgbox,sizeof(msgboxa)); | |
767e6f6f | 341 | if (msgbox->lpszCaption) |
7a6228d1 | 342 | lstrcpyWtoA((LPSTR)msgboxa.lpszCaption,msgbox->lpszCaption); |
767e6f6f | 343 | if (msgbox->lpszText) |
7a6228d1 | 344 | lstrcpyWtoA((LPSTR)msgboxa.lpszText,msgbox->lpszText); |
44ed71f5 | 345 | |
a3960292 | 346 | return MessageBoxIndirectA(&msgboxa); |
44ed71f5 AJ |
347 | } |
348 | ||
349a9531 | 349 | |
9ea19e54 AJ |
350 | /************************************************************************** |
351 | * FatalAppExit16 (KERNEL.137) | |
352 | */ | |
670cdc45 | 353 | void WINAPI FatalAppExit16( UINT16 action, LPCSTR str ) |
9ea19e54 | 354 | { |
767e6f6f | 355 | WARN(dialog,"AppExit\n"); |
a3960292 | 356 | FatalAppExitA( action, str ); |
b1bac320 AJ |
357 | } |
358 | ||
9ea19e54 | 359 | |
2787be87 | 360 | /************************************************************************** |
9ea19e54 | 361 | * FatalAppExit32A (KERNEL32.108) |
2787be87 | 362 | */ |
a3960292 | 363 | void WINAPI FatalAppExitA( UINT action, LPCSTR str ) |
9ea19e54 | 364 | { |
767e6f6f | 365 | WARN(dialog,"AppExit\n"); |
a3960292 | 366 | MessageBoxA( 0, str, NULL, MB_SYSTEMMODAL | MB_OK ); |
85ed45e3 | 367 | ExitProcess(0); |
9ea19e54 | 368 | } |
2787be87 | 369 | |
9ea19e54 AJ |
370 | |
371 | /************************************************************************** | |
372 | * FatalAppExit32W (KERNEL32.109) | |
373 | */ | |
a3960292 | 374 | void WINAPI FatalAppExitW( UINT action, LPCWSTR str ) |
2787be87 | 375 | { |
767e6f6f | 376 | WARN(dialog,"AppExit\n"); |
a3960292 | 377 | MessageBoxW( 0, str, NULL, MB_SYSTEMMODAL | MB_OK ); |
85ed45e3 | 378 | ExitProcess(0); |
2787be87 | 379 | } |
349a9531 AJ |
380 | |
381 |