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
25 #include "wine/winbase16.h"
26 #include "wine/winuser16.h"
31 #include "wine/debug.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(dialog
);
35 #define MSGBOX_IDICON 1088
36 #define MSGBOX_IDTEXT 100
39 static HFONT
MSGBOX_OnInit(HWND hwnd
, LPMSGBOXPARAMSW lpmb
)
41 HFONT hFont
= 0, hPrevFont
= 0;
46 int bspace
, bw
, bh
, theight
, tleft
, wwidth
, wheight
, bpos
;
47 int borheight
, borwidth
, iheight
, ileft
, iwidth
, twidth
, tiheight
;
51 if (TWEAK_WineLook
>= WIN95_LOOK
) {
52 NONCLIENTMETRICSW nclm
;
53 nclm
.cbSize
= sizeof(nclm
);
54 SystemParametersInfoW (SPI_GETNONCLIENTMETRICS
, 0, &nclm
, 0);
55 hFont
= CreateFontIndirectW (&nclm
.lfMessageFont
);
58 SendDlgItemMessageW (hwnd
, i
, WM_SETFONT
, (WPARAM
)hFont
, 0);
60 SendDlgItemMessageW (hwnd
, MSGBOX_IDTEXT
, WM_SETFONT
, (WPARAM
)hFont
, 0);
62 if (HIWORD(lpmb
->lpszCaption
)) {
63 SetWindowTextW(hwnd
, lpmb
->lpszCaption
);
65 UINT res_id
= LOWORD(lpmb
->lpszCaption
);
68 if (LoadStringW(lpmb
->hInstance
, res_id
, buf
, 256))
69 SetWindowTextW(hwnd
, buf
);
73 if (LoadStringW(GetModuleHandleA("user32.dll"), IDS_ERROR
, buf
, 256))
74 SetWindowTextW(hwnd
, buf
);
77 if (HIWORD(lpmb
->lpszText
)) {
78 lpszText
= lpmb
->lpszText
;
81 if (!LoadStringW(lpmb
->hInstance
, LOWORD(lpmb
->lpszText
), buf
, 256))
82 *buf
= 0; /* FIXME ?? */
84 SetWindowTextW(GetDlgItem(hwnd
, MSGBOX_IDTEXT
), lpszText
);
86 /* Hide not selected buttons */
87 switch(lpmb
->dwStyle
& MB_TYPEMASK
) {
89 ShowWindow(GetDlgItem(hwnd
, IDCANCEL
), SW_HIDE
);
92 ShowWindow(GetDlgItem(hwnd
, IDABORT
), SW_HIDE
);
93 ShowWindow(GetDlgItem(hwnd
, IDRETRY
), SW_HIDE
);
94 ShowWindow(GetDlgItem(hwnd
, IDIGNORE
), SW_HIDE
);
95 ShowWindow(GetDlgItem(hwnd
, IDYES
), SW_HIDE
);
96 ShowWindow(GetDlgItem(hwnd
, IDNO
), SW_HIDE
);
98 case MB_ABORTRETRYIGNORE
:
99 ShowWindow(GetDlgItem(hwnd
, IDOK
), SW_HIDE
);
100 ShowWindow(GetDlgItem(hwnd
, IDCANCEL
), SW_HIDE
);
101 ShowWindow(GetDlgItem(hwnd
, IDYES
), SW_HIDE
);
102 ShowWindow(GetDlgItem(hwnd
, IDNO
), SW_HIDE
);
105 ShowWindow(GetDlgItem(hwnd
, IDCANCEL
), SW_HIDE
);
108 ShowWindow(GetDlgItem(hwnd
, IDOK
), SW_HIDE
);
109 ShowWindow(GetDlgItem(hwnd
, IDABORT
), SW_HIDE
);
110 ShowWindow(GetDlgItem(hwnd
, IDRETRY
), SW_HIDE
);
111 ShowWindow(GetDlgItem(hwnd
, IDIGNORE
), SW_HIDE
);
114 ShowWindow(GetDlgItem(hwnd
, IDOK
), SW_HIDE
);
115 ShowWindow(GetDlgItem(hwnd
, IDABORT
), SW_HIDE
);
116 ShowWindow(GetDlgItem(hwnd
, IDIGNORE
), SW_HIDE
);
117 ShowWindow(GetDlgItem(hwnd
, IDYES
), SW_HIDE
);
118 ShowWindow(GetDlgItem(hwnd
, IDNO
), SW_HIDE
);
122 switch(lpmb
->dwStyle
& MB_ICONMASK
) {
123 case MB_ICONEXCLAMATION
:
124 SendDlgItemMessageW(hwnd
, stc1
, STM_SETICON
,
125 (WPARAM
)LoadIconW(0, IDI_EXCLAMATIONW
), 0);
127 case MB_ICONQUESTION
:
128 SendDlgItemMessageW(hwnd
, stc1
, STM_SETICON
,
129 (WPARAM
)LoadIconW(0, IDI_QUESTIONW
), 0);
131 case MB_ICONASTERISK
:
132 SendDlgItemMessageW(hwnd
, stc1
, STM_SETICON
,
133 (WPARAM
)LoadIconW(0, IDI_ASTERISKW
), 0);
136 SendDlgItemMessageW(hwnd
, stc1
, STM_SETICON
,
137 (WPARAM
)LoadIconW(0, IDI_HANDW
), 0);
140 SendDlgItemMessageW(hwnd
, stc1
, STM_SETICON
,
141 (WPARAM
)LoadIconW(lpmb
->hInstance
, lpmb
->lpszIcon
), 0);
144 /* By default, Windows 95/98/NT do not associate an icon to message boxes.
145 * So wine should do the same.
150 /* Position everything */
151 GetWindowRect(hwnd
, &rect
);
152 borheight
= rect
.bottom
- rect
.top
;
153 borwidth
= rect
.right
- rect
.left
;
154 GetClientRect(hwnd
, &rect
);
155 borheight
-= rect
.bottom
- rect
.top
;
156 borwidth
-= rect
.right
- rect
.left
;
158 /* Get the icon height */
159 GetWindowRect(GetDlgItem(hwnd
, MSGBOX_IDICON
), &rect
);
160 MapWindowPoints(0, hwnd
, (LPPOINT
)&rect
, 2);
161 if (!(lpmb
->dwStyle
& MB_ICONMASK
))
163 rect
.bottom
= rect
.top
;
164 rect
.right
= rect
.left
;
166 iheight
= rect
.bottom
- rect
.top
;
168 iwidth
= rect
.right
- ileft
;
172 hPrevFont
= SelectObject(hdc
, hFont
);
174 /* Get the number of visible buttons and their size */
175 bh
= bw
= 1; /* Minimum button sizes */
176 for (buttons
= 0, i
= 1; i
< 8; i
++)
178 hItem
= GetDlgItem(hwnd
, i
);
179 if (GetWindowLongW(hItem
, GWL_STYLE
) & WS_VISIBLE
)
181 WCHAR buttonText
[1024];
184 if (GetWindowTextW(hItem
, buttonText
, 1024))
186 DrawTextW( hdc
, buttonText
, -1, &rect
, DT_LEFT
| DT_EXPANDTABS
| DT_CALCRECT
);
187 h
= rect
.bottom
- rect
.top
;
188 w
= rect
.right
- rect
.left
;
194 bw
= max(bw
, bh
* 2);
195 /* Button white space */
198 bspace
= bw
/3; /* Space between buttons */
200 /* Get the text size */
201 GetClientRect(GetDlgItem(hwnd
, MSGBOX_IDTEXT
), &rect
);
202 rect
.top
= rect
.left
= rect
.bottom
= 0;
203 DrawTextW( hdc
, lpszText
, -1, &rect
,
204 DT_LEFT
| DT_EXPANDTABS
| DT_WORDBREAK
| DT_CALCRECT
);
205 /* Min text width corresponds to space for the buttons */
207 if (iwidth
) tleft
+= ileft
+ iwidth
;
208 twidth
= max((bw
+ bspace
) * buttons
+ bspace
- tleft
, rect
.right
);
209 theight
= rect
.bottom
;
212 SelectObject(hdc
, hPrevFont
);
213 ReleaseDC(hItem
, hdc
);
215 tiheight
= 16 + max(iheight
, theight
);
216 wwidth
= tleft
+ twidth
+ ileft
+ borwidth
;
217 wheight
= 8 + tiheight
+ bh
+ borheight
;
219 /* Resize the window */
220 SetWindowPos(hwnd
, 0, 0, 0, wwidth
, wheight
,
221 SWP_NOMOVE
| SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_NOREDRAW
);
223 /* Position the icon */
224 SetWindowPos(GetDlgItem(hwnd
, MSGBOX_IDICON
), 0, ileft
, (tiheight
- iheight
) / 2, 0, 0,
225 SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_NOREDRAW
);
227 /* Position the text */
228 SetWindowPos(GetDlgItem(hwnd
, MSGBOX_IDTEXT
), 0, tleft
, (tiheight
- theight
) / 2, twidth
, theight
,
229 SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_NOREDRAW
);
231 /* Position the buttons */
232 bpos
= (wwidth
- (bw
+ bspace
) * buttons
+ bspace
) / 2;
233 for (buttons
= i
= 0; i
< 7; i
++) {
234 /* some arithmetic to get the right order for YesNoCancel windows */
235 hItem
= GetDlgItem(hwnd
, (i
+ 5) % 7 + 1);
236 if (GetWindowLongW(hItem
, GWL_STYLE
) & WS_VISIBLE
) {
237 if (buttons
++ == ((lpmb
->dwStyle
& MB_DEFMASK
) >> 8)) {
239 SendMessageW( hItem
, BM_SETSTYLE
, BS_DEFPUSHBUTTON
, TRUE
);
241 SetWindowPos(hItem
, 0, bpos
, tiheight
, bw
, bh
,
242 SWP_NOZORDER
|SWP_NOACTIVATE
|SWP_NOREDRAW
);
247 /* handle modal MessageBoxes */
248 if (lpmb
->dwStyle
& (MB_TASKMODAL
|MB_SYSTEMMODAL
))
250 FIXME("%s modal msgbox ! Not modal yet.\n",
251 lpmb
->dwStyle
& MB_TASKMODAL
? "task" : "system");
252 /* Probably do EnumTaskWindows etc. here for TASKMODAL
253 * and work your way up to the top - I'm lazy (HWND_TOP) */
254 SetWindowPos(hwnd
, HWND_TOP
, 0, 0, 0, 0,
255 SWP_NOSIZE
| SWP_NOMOVE
);
256 if (lpmb
->dwStyle
& MB_TASKMODAL
)
257 /* at least MB_TASKMODAL seems to imply a ShowWindow */
258 ShowWindow(hwnd
, SW_SHOW
);
260 if (lpmb
->dwStyle
& MB_APPLMODAL
)
261 FIXME("app modal msgbox ! Not modal yet.\n");
267 /**************************************************************************
270 * Dialog procedure for message boxes.
272 static INT_PTR CALLBACK
MSGBOX_DlgProc( HWND hwnd
, UINT message
,
273 WPARAM wParam
, LPARAM lParam
)
280 LPMSGBOXPARAMSW mbp
= (LPMSGBOXPARAMSW
)lParam
;
281 SetWindowContextHelpId(hwnd
, mbp
->dwContextHelpId
);
282 hFont
= MSGBOX_OnInit(hwnd
, mbp
);
283 SetPropA(hwnd
, "WINE_MSGBOX_HFONT", (HANDLE
)hFont
);
284 SetPropA(hwnd
, "WINE_MSGBOX_HELPCALLBACK", (HANDLE
)mbp
->lpfnMsgBoxCallback
);
298 hFont
= GetPropA(hwnd
, "WINE_MSGBOX_HFONT");
299 EndDialog(hwnd
, wParam
);
308 MSGBOXCALLBACK callback
= (MSGBOXCALLBACK
)GetPropA(hwnd
, "WINE_MSGBOX_HELPCALLBACK");
311 memcpy(&hi
, (void *)lParam
, sizeof(hi
));
312 hi
.dwContextId
= GetWindowContextHelpId(hwnd
);
317 SendMessageW(GetWindow(hwnd
, GW_OWNER
), WM_HELP
, 0, (LPARAM
)&hi
);
322 /* Ok. Ignore all the other messages */
323 TRACE("Message number 0x%04x is being ignored.\n", message
);
330 /**************************************************************************
331 * MessageBoxA (USER32.@)
334 * The WARN is here to help debug erroneous MessageBoxes
335 * Use: -debugmsg warn+dialog,+relay
337 INT WINAPI
MessageBoxA(HWND hWnd
, LPCSTR text
, LPCSTR title
, UINT type
)
339 return MessageBoxExA(hWnd
, text
, title
, type
, LANG_NEUTRAL
);
343 /**************************************************************************
344 * MessageBoxW (USER32.@)
346 INT WINAPI
MessageBoxW( HWND hwnd
, LPCWSTR text
, LPCWSTR title
, UINT type
)
348 return MessageBoxExW(hwnd
, text
, title
, type
, LANG_NEUTRAL
);
352 /**************************************************************************
353 * MessageBoxExA (USER32.@)
355 INT WINAPI
MessageBoxExA( HWND hWnd
, LPCSTR text
, LPCSTR title
,
356 UINT type
, WORD langid
)
358 MSGBOXPARAMSA msgbox
;
360 msgbox
.cbSize
= sizeof(msgbox
);
361 msgbox
.hwndOwner
= hWnd
;
362 msgbox
.hInstance
= 0;
363 msgbox
.lpszText
= text
;
364 msgbox
.lpszCaption
= title
;
365 msgbox
.dwStyle
= type
;
366 msgbox
.lpszIcon
= NULL
;
367 msgbox
.dwContextHelpId
= 0;
368 msgbox
.lpfnMsgBoxCallback
= NULL
;
369 msgbox
.dwLanguageId
= langid
;
371 return MessageBoxIndirectA(&msgbox
);
374 /**************************************************************************
375 * MessageBoxExW (USER32.@)
377 INT WINAPI
MessageBoxExW( HWND hWnd
, LPCWSTR text
, LPCWSTR title
,
378 UINT type
, WORD langid
)
380 MSGBOXPARAMSW msgbox
;
382 msgbox
.cbSize
= sizeof(msgbox
);
383 msgbox
.hwndOwner
= hWnd
;
384 msgbox
.hInstance
= 0;
385 msgbox
.lpszText
= text
;
386 msgbox
.lpszCaption
= title
;
387 msgbox
.dwStyle
= type
;
388 msgbox
.lpszIcon
= NULL
;
389 msgbox
.dwContextHelpId
= 0;
390 msgbox
.lpfnMsgBoxCallback
= NULL
;
391 msgbox
.dwLanguageId
= langid
;
393 return MessageBoxIndirectW(&msgbox
);
396 /**************************************************************************
397 * MessageBoxIndirectA (USER32.@)
399 INT WINAPI
MessageBoxIndirectA( LPMSGBOXPARAMSA msgbox
)
401 MSGBOXPARAMSW msgboxW
;
402 UNICODE_STRING textW
, captionW
, iconW
;
405 if (HIWORD(msgbox
->lpszText
))
406 RtlCreateUnicodeStringFromAsciiz(&textW
, msgbox
->lpszText
);
408 textW
.Buffer
= (LPWSTR
)msgbox
->lpszText
;
409 if (HIWORD(msgbox
->lpszCaption
))
410 RtlCreateUnicodeStringFromAsciiz(&captionW
, msgbox
->lpszCaption
);
412 captionW
.Buffer
= (LPWSTR
)msgbox
->lpszCaption
;
413 if (HIWORD(msgbox
->lpszIcon
))
414 RtlCreateUnicodeStringFromAsciiz(&iconW
, msgbox
->lpszIcon
);
416 iconW
.Buffer
= (LPWSTR
)msgbox
->lpszIcon
;
418 msgboxW
.cbSize
= sizeof(msgboxW
);
419 msgboxW
.hwndOwner
= msgbox
->hwndOwner
;
420 msgboxW
.hInstance
= msgbox
->hInstance
;
421 msgboxW
.lpszText
= textW
.Buffer
;
422 msgboxW
.lpszCaption
= captionW
.Buffer
;
423 msgboxW
.dwStyle
= msgbox
->dwStyle
;
424 msgboxW
.lpszIcon
= iconW
.Buffer
;
425 msgboxW
.dwContextHelpId
= msgbox
->dwContextHelpId
;
426 msgboxW
.lpfnMsgBoxCallback
= msgbox
->lpfnMsgBoxCallback
;
427 msgboxW
.dwLanguageId
= msgbox
->dwLanguageId
;
429 ret
= MessageBoxIndirectW(&msgboxW
);
431 if (HIWORD(textW
.Buffer
)) RtlFreeUnicodeString(&textW
);
432 if (HIWORD(captionW
.Buffer
)) RtlFreeUnicodeString(&captionW
);
433 if (HIWORD(iconW
.Buffer
)) RtlFreeUnicodeString(&iconW
);
437 /**************************************************************************
438 * MessageBoxIndirectW (USER32.@)
440 INT WINAPI
MessageBoxIndirectW( LPMSGBOXPARAMSW msgbox
)
445 static const WCHAR user32_res_nameW
[] = { 'u','s','e','r','3','2','.','d','l','l',0 };
446 static const WCHAR msg_box_res_nameW
[] = { 'M','S','G','B','O','X',0 };
448 hUser32
= GetModuleHandleW(user32_res_nameW
);
449 if (!(hRes
= FindResourceExW(hUser32
, RT_DIALOGW
, msg_box_res_nameW
, msgbox
->dwLanguageId
)))
451 if (!(tmplate
= (LPVOID
)LoadResource(hUser32
, hRes
)))
454 return DialogBoxIndirectParamW(msgbox
->hInstance
, tmplate
, msgbox
->hwndOwner
,
455 MSGBOX_DlgProc
, (LPARAM
)msgbox
);