4 * Copyright 1995 Bernd Schmidt
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 #include "wine/winbase16.h"
28 #include "wine/winuser16.h"
33 #include "wine/debug.h"
35 WINE_DEFAULT_DEBUG_CHANNEL(dialog
);
37 #define MSGBOX_IDICON 1088
38 #define MSGBOX_IDTEXT 100
41 static HFONT
MSGBOX_OnInit(HWND hwnd
, LPMSGBOXPARAMSW lpmb
)
43 HFONT hFont
= 0, hPrevFont
= 0;
48 int bspace
, bw
, bh
, theight
, tleft
, wwidth
, wheight
, bpos
;
49 int borheight
, borwidth
, iheight
, ileft
, iwidth
, twidth
, tiheight
;
50 NONCLIENTMETRICSW nclm
;
54 nclm
.cbSize
= sizeof(nclm
);
55 SystemParametersInfoW (SPI_GETNONCLIENTMETRICS
, 0, &nclm
, 0);
56 hFont
= CreateFontIndirectW (&nclm
.lfMessageFont
);
59 SendDlgItemMessageW (hwnd
, i
, WM_SETFONT
, (WPARAM
)hFont
, 0);
61 SendDlgItemMessageW (hwnd
, MSGBOX_IDTEXT
, WM_SETFONT
, (WPARAM
)hFont
, 0);
63 if (HIWORD(lpmb
->lpszCaption
)) {
64 SetWindowTextW(hwnd
, lpmb
->lpszCaption
);
66 UINT res_id
= LOWORD(lpmb
->lpszCaption
);
69 if (LoadStringW(lpmb
->hInstance
, res_id
, buf
, 256))
70 SetWindowTextW(hwnd
, buf
);
74 if (LoadStringW(user32_module
, IDS_ERROR
, buf
, 256))
75 SetWindowTextW(hwnd
, buf
);
78 if (HIWORD(lpmb
->lpszText
)) {
79 lpszText
= lpmb
->lpszText
;
82 if (!LoadStringW(lpmb
->hInstance
, LOWORD(lpmb
->lpszText
), buf
, 256))
83 *buf
= 0; /* FIXME ?? */
85 SetWindowTextW(GetDlgItem(hwnd
, MSGBOX_IDTEXT
), lpszText
);
87 /* Hide not selected buttons */
88 switch(lpmb
->dwStyle
& MB_TYPEMASK
) {
90 ShowWindow(GetDlgItem(hwnd
, IDCANCEL
), SW_HIDE
);
93 ShowWindow(GetDlgItem(hwnd
, IDABORT
), SW_HIDE
);
94 ShowWindow(GetDlgItem(hwnd
, IDRETRY
), SW_HIDE
);
95 ShowWindow(GetDlgItem(hwnd
, IDIGNORE
), SW_HIDE
);
96 ShowWindow(GetDlgItem(hwnd
, IDYES
), SW_HIDE
);
97 ShowWindow(GetDlgItem(hwnd
, IDNO
), SW_HIDE
);
99 case MB_ABORTRETRYIGNORE
:
100 ShowWindow(GetDlgItem(hwnd
, IDOK
), SW_HIDE
);
101 ShowWindow(GetDlgItem(hwnd
, IDCANCEL
), SW_HIDE
);
102 ShowWindow(GetDlgItem(hwnd
, IDYES
), SW_HIDE
);
103 ShowWindow(GetDlgItem(hwnd
, IDNO
), SW_HIDE
);
106 ShowWindow(GetDlgItem(hwnd
, IDCANCEL
), SW_HIDE
);
109 ShowWindow(GetDlgItem(hwnd
, IDOK
), SW_HIDE
);
110 ShowWindow(GetDlgItem(hwnd
, IDABORT
), SW_HIDE
);
111 ShowWindow(GetDlgItem(hwnd
, IDRETRY
), SW_HIDE
);
112 ShowWindow(GetDlgItem(hwnd
, IDIGNORE
), SW_HIDE
);
115 ShowWindow(GetDlgItem(hwnd
, IDOK
), SW_HIDE
);
116 ShowWindow(GetDlgItem(hwnd
, IDABORT
), SW_HIDE
);
117 ShowWindow(GetDlgItem(hwnd
, IDIGNORE
), SW_HIDE
);
118 ShowWindow(GetDlgItem(hwnd
, IDYES
), SW_HIDE
);
119 ShowWindow(GetDlgItem(hwnd
, IDNO
), SW_HIDE
);
123 switch(lpmb
->dwStyle
& MB_ICONMASK
) {
124 case MB_ICONEXCLAMATION
:
125 SendDlgItemMessageW(hwnd
, stc1
, STM_SETICON
,
126 (WPARAM
)LoadIconW(0, (LPWSTR
)IDI_EXCLAMATION
), 0);
128 case MB_ICONQUESTION
:
129 SendDlgItemMessageW(hwnd
, stc1
, STM_SETICON
,
130 (WPARAM
)LoadIconW(0, (LPWSTR
)IDI_QUESTION
), 0);
132 case MB_ICONASTERISK
:
133 SendDlgItemMessageW(hwnd
, stc1
, STM_SETICON
,
134 (WPARAM
)LoadIconW(0, (LPWSTR
)IDI_ASTERISK
), 0);
137 SendDlgItemMessageW(hwnd
, stc1
, STM_SETICON
,
138 (WPARAM
)LoadIconW(0, (LPWSTR
)IDI_HAND
), 0);
141 SendDlgItemMessageW(hwnd
, stc1
, STM_SETICON
,
142 (WPARAM
)LoadIconW(lpmb
->hInstance
, lpmb
->lpszIcon
), 0);
145 /* By default, Windows 95/98/NT do not associate an icon to message boxes.
146 * So wine should do the same.
151 /* Position everything */
152 GetWindowRect(hwnd
, &rect
);
153 borheight
= rect
.bottom
- rect
.top
;
154 borwidth
= rect
.right
- rect
.left
;
155 GetClientRect(hwnd
, &rect
);
156 borheight
-= rect
.bottom
- rect
.top
;
157 borwidth
-= rect
.right
- rect
.left
;
159 /* Get the icon height */
160 GetWindowRect(GetDlgItem(hwnd
, MSGBOX_IDICON
), &rect
);
161 MapWindowPoints(0, hwnd
, (LPPOINT
)&rect
, 2);
162 if (!(lpmb
->dwStyle
& MB_ICONMASK
))
164 rect
.bottom
= rect
.top
;
165 rect
.right
= rect
.left
;
167 iheight
= rect
.bottom
- rect
.top
;
169 iwidth
= rect
.right
- ileft
;
173 hPrevFont
= SelectObject(hdc
, hFont
);
175 /* Get the number of visible buttons and their size */
176 bh
= bw
= 1; /* Minimum button sizes */
177 for (buttons
= 0, i
= 1; i
< 8; i
++)
179 hItem
= GetDlgItem(hwnd
, i
);
180 if (GetWindowLongW(hItem
, GWL_STYLE
) & WS_VISIBLE
)
182 WCHAR buttonText
[1024];
185 if (GetWindowTextW(hItem
, buttonText
, 1024))
187 DrawTextW( hdc
, buttonText
, -1, &rect
, DT_LEFT
| DT_EXPANDTABS
| DT_CALCRECT
);
188 h
= rect
.bottom
- rect
.top
;
189 w
= rect
.right
- rect
.left
;
195 bw
= max(bw
, bh
* 2);
196 /* Button white space */
199 bspace
= bw
/3; /* Space between buttons */
201 /* Get the text size */
202 GetClientRect(GetDlgItem(hwnd
, MSGBOX_IDTEXT
), &rect
);
203 rect
.top
= rect
.left
= rect
.bottom
= 0;
204 DrawTextW( hdc
, lpszText
, -1, &rect
,
205 DT_LEFT
| DT_EXPANDTABS
| DT_WORDBREAK
| DT_CALCRECT
);
206 /* Min text width corresponds to space for the buttons */
208 if (iwidth
) tleft
+= ileft
+ iwidth
;
209 twidth
= max((bw
+ bspace
) * buttons
+ bspace
- tleft
, rect
.right
);
210 theight
= rect
.bottom
;
213 SelectObject(hdc
, hPrevFont
);
214 ReleaseDC(hItem
, hdc
);
216 tiheight
= 16 + max(iheight
, theight
);
217 wwidth
= tleft
+ twidth
+ ileft
+ borwidth
;
218 wheight
= 8 + tiheight
+ bh
+ borheight
;
220 /* Resize the window */
221 SetWindowPos(hwnd
, 0, 0, 0, wwidth
, wheight
,
222 SWP_NOMOVE
| SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_NOREDRAW
);
224 /* Position the icon */
225 SetWindowPos(GetDlgItem(hwnd
, MSGBOX_IDICON
), 0, ileft
, (tiheight
- iheight
) / 2, 0, 0,
226 SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_NOREDRAW
);
228 /* Position the text */
229 SetWindowPos(GetDlgItem(hwnd
, MSGBOX_IDTEXT
), 0, tleft
, (tiheight
- theight
) / 2, twidth
, theight
,
230 SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_NOREDRAW
);
232 /* Position the buttons */
233 bpos
= (wwidth
- (bw
+ bspace
) * buttons
+ bspace
) / 2;
234 for (buttons
= i
= 0; i
< 7; i
++) {
235 /* some arithmetic to get the right order for YesNoCancel windows */
236 hItem
= GetDlgItem(hwnd
, (i
+ 5) % 7 + 1);
237 if (GetWindowLongW(hItem
, GWL_STYLE
) & WS_VISIBLE
) {
238 if (buttons
++ == ((lpmb
->dwStyle
& MB_DEFMASK
) >> 8)) {
240 SendMessageW( hItem
, BM_SETSTYLE
, BS_DEFPUSHBUTTON
, TRUE
);
242 SetWindowPos(hItem
, 0, bpos
, tiheight
, bw
, bh
,
243 SWP_NOZORDER
|SWP_NOACTIVATE
|SWP_NOREDRAW
);
248 /* handle modal MessageBoxes */
249 if (lpmb
->dwStyle
& (MB_TASKMODAL
|MB_SYSTEMMODAL
))
251 FIXME("%s modal msgbox ! Not modal yet.\n",
252 lpmb
->dwStyle
& MB_TASKMODAL
? "task" : "system");
253 /* Probably do EnumTaskWindows etc. here for TASKMODAL
254 * and work your way up to the top - I'm lazy (HWND_TOP) */
255 SetWindowPos(hwnd
, HWND_TOP
, 0, 0, 0, 0,
256 SWP_NOSIZE
| SWP_NOMOVE
);
257 if (lpmb
->dwStyle
& MB_TASKMODAL
)
258 /* at least MB_TASKMODAL seems to imply a ShowWindow */
259 ShowWindow(hwnd
, SW_SHOW
);
261 if (lpmb
->dwStyle
& MB_APPLMODAL
)
262 FIXME("app modal msgbox ! Not modal yet.\n");
268 /**************************************************************************
271 * Dialog procedure for message boxes.
273 static INT_PTR CALLBACK
MSGBOX_DlgProc( HWND hwnd
, UINT message
,
274 WPARAM wParam
, LPARAM lParam
)
281 LPMSGBOXPARAMSW mbp
= (LPMSGBOXPARAMSW
)lParam
;
282 SetWindowContextHelpId(hwnd
, mbp
->dwContextHelpId
);
283 hFont
= MSGBOX_OnInit(hwnd
, mbp
);
284 SetPropA(hwnd
, "WINE_MSGBOX_HFONT", (HANDLE
)hFont
);
285 SetPropA(hwnd
, "WINE_MSGBOX_HELPCALLBACK", (HANDLE
)mbp
->lpfnMsgBoxCallback
);
290 switch (LOWORD(wParam
))
299 hFont
= GetPropA(hwnd
, "WINE_MSGBOX_HFONT");
300 EndDialog(hwnd
, wParam
);
309 MSGBOXCALLBACK callback
= (MSGBOXCALLBACK
)GetPropA(hwnd
, "WINE_MSGBOX_HELPCALLBACK");
312 memcpy(&hi
, (void *)lParam
, sizeof(hi
));
313 hi
.dwContextId
= GetWindowContextHelpId(hwnd
);
318 SendMessageW(GetWindow(hwnd
, GW_OWNER
), WM_HELP
, 0, (LPARAM
)&hi
);
323 /* Ok. Ignore all the other messages */
324 TRACE("Message number 0x%04x is being ignored.\n", message
);
331 /**************************************************************************
332 * MessageBoxA (USER32.@)
335 * The WARN is here to help debug erroneous MessageBoxes
336 * Use: -debugmsg warn+dialog,+relay
338 INT WINAPI
MessageBoxA(HWND hWnd
, LPCSTR text
, LPCSTR title
, UINT type
)
340 return MessageBoxExA(hWnd
, text
, title
, type
, LANG_NEUTRAL
);
344 /**************************************************************************
345 * MessageBoxW (USER32.@)
347 INT WINAPI
MessageBoxW( HWND hwnd
, LPCWSTR text
, LPCWSTR title
, UINT type
)
349 return MessageBoxExW(hwnd
, text
, title
, type
, LANG_NEUTRAL
);
353 /**************************************************************************
354 * MessageBoxExA (USER32.@)
356 INT WINAPI
MessageBoxExA( HWND hWnd
, LPCSTR text
, LPCSTR title
,
357 UINT type
, WORD langid
)
359 MSGBOXPARAMSA msgbox
;
361 msgbox
.cbSize
= sizeof(msgbox
);
362 msgbox
.hwndOwner
= hWnd
;
363 msgbox
.hInstance
= 0;
364 msgbox
.lpszText
= text
;
365 msgbox
.lpszCaption
= title
;
366 msgbox
.dwStyle
= type
;
367 msgbox
.lpszIcon
= NULL
;
368 msgbox
.dwContextHelpId
= 0;
369 msgbox
.lpfnMsgBoxCallback
= NULL
;
370 msgbox
.dwLanguageId
= langid
;
372 return MessageBoxIndirectA(&msgbox
);
375 /**************************************************************************
376 * MessageBoxExW (USER32.@)
378 INT WINAPI
MessageBoxExW( HWND hWnd
, LPCWSTR text
, LPCWSTR title
,
379 UINT type
, WORD langid
)
381 MSGBOXPARAMSW msgbox
;
383 msgbox
.cbSize
= sizeof(msgbox
);
384 msgbox
.hwndOwner
= hWnd
;
385 msgbox
.hInstance
= 0;
386 msgbox
.lpszText
= text
;
387 msgbox
.lpszCaption
= title
;
388 msgbox
.dwStyle
= type
;
389 msgbox
.lpszIcon
= NULL
;
390 msgbox
.dwContextHelpId
= 0;
391 msgbox
.lpfnMsgBoxCallback
= NULL
;
392 msgbox
.dwLanguageId
= langid
;
394 return MessageBoxIndirectW(&msgbox
);
397 /**************************************************************************
398 * MessageBoxIndirectA (USER32.@)
400 INT WINAPI
MessageBoxIndirectA( LPMSGBOXPARAMSA msgbox
)
402 MSGBOXPARAMSW msgboxW
;
403 UNICODE_STRING textW
, captionW
, iconW
;
406 if (HIWORD(msgbox
->lpszText
))
407 RtlCreateUnicodeStringFromAsciiz(&textW
, msgbox
->lpszText
);
409 textW
.Buffer
= (LPWSTR
)msgbox
->lpszText
;
410 if (HIWORD(msgbox
->lpszCaption
))
411 RtlCreateUnicodeStringFromAsciiz(&captionW
, msgbox
->lpszCaption
);
413 captionW
.Buffer
= (LPWSTR
)msgbox
->lpszCaption
;
414 if (HIWORD(msgbox
->lpszIcon
))
415 RtlCreateUnicodeStringFromAsciiz(&iconW
, msgbox
->lpszIcon
);
417 iconW
.Buffer
= (LPWSTR
)msgbox
->lpszIcon
;
419 msgboxW
.cbSize
= sizeof(msgboxW
);
420 msgboxW
.hwndOwner
= msgbox
->hwndOwner
;
421 msgboxW
.hInstance
= msgbox
->hInstance
;
422 msgboxW
.lpszText
= textW
.Buffer
;
423 msgboxW
.lpszCaption
= captionW
.Buffer
;
424 msgboxW
.dwStyle
= msgbox
->dwStyle
;
425 msgboxW
.lpszIcon
= iconW
.Buffer
;
426 msgboxW
.dwContextHelpId
= msgbox
->dwContextHelpId
;
427 msgboxW
.lpfnMsgBoxCallback
= msgbox
->lpfnMsgBoxCallback
;
428 msgboxW
.dwLanguageId
= msgbox
->dwLanguageId
;
430 ret
= MessageBoxIndirectW(&msgboxW
);
432 if (HIWORD(textW
.Buffer
)) RtlFreeUnicodeString(&textW
);
433 if (HIWORD(captionW
.Buffer
)) RtlFreeUnicodeString(&captionW
);
434 if (HIWORD(iconW
.Buffer
)) RtlFreeUnicodeString(&iconW
);
438 /**************************************************************************
439 * MessageBoxIndirectW (USER32.@)
441 INT WINAPI
MessageBoxIndirectW( LPMSGBOXPARAMSW msgbox
)
445 static const WCHAR msg_box_res_nameW
[] = { 'M','S','G','B','O','X',0 };
447 if (!(hRes
= FindResourceExW(user32_module
, (LPWSTR
)RT_DIALOG
,
448 msg_box_res_nameW
, msgbox
->dwLanguageId
)))
450 if (!(tmplate
= (LPVOID
)LoadResource(user32_module
, hRes
)))
453 return DialogBoxIndirectParamW(msgbox
->hInstance
, tmplate
, msgbox
->hwndOwner
,
454 MSGBOX_DlgProc
, (LPARAM
)msgbox
);