4 * Copyright 1995 Bernd Schmidt
7 #include "wine/winuser16.h"
18 /**************************************************************************
21 * Dialog procedure for message boxes.
23 static LRESULT CALLBACK
MSGBOX_DlgProc( HWND32 hwnd
, UINT32 message
,
24 WPARAM32 wParam
, LPARAM lParam
)
26 static HFONT32 hFont
= 0;
27 LPMSGBOXPARAMS32A lpmb
;
29 RECT32 rect
, textrect
;
33 int i
, buttons
, bwidth
, bheight
, theight
, wwidth
, bpos
;
34 int borheight
, iheight
, tiheight
;
38 lpmb
= (LPMSGBOXPARAMS32A
)lParam
;
39 if (TWEAK_WineLook
>= WIN95_LOOK
) {
40 NONCLIENTMETRICS32A nclm
;
42 nclm
.cbSize
= sizeof(NONCLIENTMETRICS32A
);
43 SystemParametersInfo32A (SPI_GETNONCLIENTMETRICS
, 0, &nclm
, 0);
44 hFont
= CreateFontIndirect32A (&nclm
.lfMessageFont
);
47 SendDlgItemMessage32A (hwnd
, i
, WM_SETFONT
, (WPARAM32
)hFont
, 0);
49 SendDlgItemMessage32A (hwnd
, 100, WM_SETFONT
, (WPARAM32
)hFont
, 0);
51 if (lpmb
->lpszCaption
) SetWindowText32A(hwnd
, lpmb
->lpszCaption
);
52 SetWindowText32A(GetDlgItem32(hwnd
, 100), lpmb
->lpszText
);
53 /* Hide not selected buttons */
54 switch(lpmb
->dwStyle
& MB_TYPEMASK
) {
56 ShowWindow32(GetDlgItem32(hwnd
, 2), SW_HIDE
);
59 ShowWindow32(GetDlgItem32(hwnd
, 3), SW_HIDE
);
60 ShowWindow32(GetDlgItem32(hwnd
, 4), SW_HIDE
);
61 ShowWindow32(GetDlgItem32(hwnd
, 5), SW_HIDE
);
62 ShowWindow32(GetDlgItem32(hwnd
, 6), SW_HIDE
);
63 ShowWindow32(GetDlgItem32(hwnd
, 7), SW_HIDE
);
65 case MB_ABORTRETRYIGNORE
:
66 ShowWindow32(GetDlgItem32(hwnd
, 1), SW_HIDE
);
67 ShowWindow32(GetDlgItem32(hwnd
, 2), SW_HIDE
);
68 ShowWindow32(GetDlgItem32(hwnd
, 6), SW_HIDE
);
69 ShowWindow32(GetDlgItem32(hwnd
, 7), SW_HIDE
);
72 ShowWindow32(GetDlgItem32(hwnd
, 2), SW_HIDE
);
75 ShowWindow32(GetDlgItem32(hwnd
, 1), SW_HIDE
);
76 ShowWindow32(GetDlgItem32(hwnd
, 3), SW_HIDE
);
77 ShowWindow32(GetDlgItem32(hwnd
, 4), SW_HIDE
);
78 ShowWindow32(GetDlgItem32(hwnd
, 5), SW_HIDE
);
82 switch(lpmb
->dwStyle
& MB_ICONMASK
) {
83 case MB_ICONEXCLAMATION
:
84 SendDlgItemMessage16(hwnd
, stc1
, STM_SETICON16
,
85 (WPARAM16
)LoadIcon16(0, IDI_EXCLAMATION16
), 0);
88 SendDlgItemMessage16(hwnd
, stc1
, STM_SETICON16
,
89 (WPARAM16
)LoadIcon16(0, IDI_QUESTION16
), 0);
92 SendDlgItemMessage16(hwnd
, stc1
, STM_SETICON16
,
93 (WPARAM16
)LoadIcon16(0, IDI_ASTERISK16
), 0);
97 SendDlgItemMessage16(hwnd
, stc1
, STM_SETICON16
,
98 (WPARAM16
)LoadIcon16(0, IDI_HAND16
), 0);
102 /* Position everything */
103 GetWindowRect32(hwnd
, &rect
);
104 borheight
= rect
.bottom
- rect
.top
;
105 wwidth
= rect
.right
- rect
.left
;
106 GetClientRect32(hwnd
, &rect
);
107 borheight
-= rect
.bottom
- rect
.top
;
109 /* Get the icon height */
110 GetWindowRect32(GetDlgItem32(hwnd
, 1088), &rect
);
111 iheight
= rect
.bottom
- rect
.top
;
113 /* Get the number of visible buttons and their width */
114 GetWindowRect32(GetDlgItem32(hwnd
, 2), &rect
);
115 bheight
= rect
.bottom
- rect
.top
;
117 GetWindowRect32(GetDlgItem32(hwnd
, 1), &rect
);
119 for (buttons
= 0, i
= 1; i
< 8; i
++)
121 hItem
= GetDlgItem32(hwnd
, i
);
122 if (GetWindowLong32A(hItem
, GWL_STYLE
) & WS_VISIBLE
) buttons
++;
125 /* Get the text size */
126 hItem
= GetDlgItem32(hwnd
, 100);
127 GetWindowRect32(hItem
, &textrect
);
128 MapWindowPoints32(0, hwnd
, (LPPOINT32
)&textrect
, 2);
130 GetClientRect32(hItem
, &rect
);
131 hdc
= GetDC32(hItem
);
132 lRet
= DrawText32A( hdc
, lpmb
->lpszText
, -1, &rect
,
133 DT_LEFT
| DT_EXPANDTABS
| DT_WORDBREAK
| DT_CALCRECT
);
134 theight
= rect
.bottom
- rect
.top
;
135 tiheight
= 16 + MAX(iheight
, theight
);
136 ReleaseDC32(hItem
, hdc
);
138 /* Position the text */
139 SetWindowPos32(hItem
, 0, textrect
.left
, (tiheight
- theight
) / 2,
140 rect
.right
- rect
.left
, theight
,
141 SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_NOREDRAW
);
143 /* Position the icon */
144 hItem
= GetDlgItem32(hwnd
, 1088);
145 GetWindowRect32(hItem
, &rect
);
146 MapWindowPoints32(0, hwnd
, (LPPOINT32
)&rect
, 2);
147 SetWindowPos32(hItem
, 0, rect
.left
, (tiheight
- iheight
) / 2, 0, 0,
148 SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_NOREDRAW
);
150 /* Resize the window */
151 SetWindowPos32(hwnd
, 0, 0, 0, wwidth
, 8 + tiheight
+ bheight
+ borheight
,
152 SWP_NOMOVE
| SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_NOREDRAW
);
154 /* Position the buttons */
155 bpos
= (wwidth
- bwidth
* buttons
) / 2;
156 GetWindowRect32(GetDlgItem32(hwnd
, 1), &rect
);
157 for (buttons
= i
= 0; i
< 7; i
++) {
158 /* some arithmetic to get the right order for YesNoCancel windows */
159 hItem
= GetDlgItem32(hwnd
, (i
+ 5) % 7 + 1);
160 if (GetWindowLong32A(hItem
, GWL_STYLE
) & WS_VISIBLE
) {
161 if (buttons
++ == ((lpmb
->dwStyle
& MB_DEFMASK
) >> 8)) {
163 SendMessage32A( hItem
, BM_SETSTYLE32
, BS_DEFPUSHBUTTON
, TRUE
);
165 SetWindowPos32(hItem
, 0, bpos
, tiheight
, 0, 0,
166 SWP_NOSIZE
|SWP_NOZORDER
|SWP_NOACTIVATE
|SWP_NOREDRAW
);
183 if ((TWEAK_WineLook
> WIN31_LOOK
) && hFont
)
184 DeleteObject32 (hFont
);
185 EndDialog32(hwnd
, wParam
);
190 /* Ok. Ignore all the other messages */
191 TRACE (dialog
, "Message number %i is being ignored.\n", message
);
198 /**************************************************************************
199 * MessageBox16 (USER.1)
201 INT16 WINAPI
MessageBox16( HWND16 hwnd
, LPCSTR text
, LPCSTR title
, UINT16 type
)
203 WARN(dialog
,"Messagebox\n");
204 return MessageBox32A( hwnd
, text
, title
, type
);
208 /**************************************************************************
209 * MessageBox32A (USER32.391)
212 * The WARN is here to help debug erroneous MessageBoxes
213 * Use: -debugmsg warn+dialog,+relay
215 INT32 WINAPI
MessageBox32A(HWND32 hWnd
, LPCSTR text
, LPCSTR title
, UINT32 type
)
217 MSGBOXPARAMS32A mbox
;
218 WARN(dialog
,"Messagebox\n");
219 if (!text
) text
="<WINE-NULL>";
222 mbox
.lpszCaption
= title
;
223 mbox
.lpszText
= text
;
225 return DialogBoxIndirectParam32A( WIN_GetWindowInstance(hWnd
),
226 SYSRES_GetResPtr( SYSRES_DIALOG_MSGBOX
),
227 hWnd
, MSGBOX_DlgProc
, (LPARAM
)&mbox
);
231 /**************************************************************************
232 * MessageBox32W (USER32.396)
234 INT32 WINAPI
MessageBox32W( HWND32 hwnd
, LPCWSTR text
, LPCWSTR title
,
237 LPSTR titleA
= HEAP_strdupWtoA( GetProcessHeap(), 0, title
);
238 LPSTR textA
= HEAP_strdupWtoA( GetProcessHeap(), 0, text
);
241 WARN(dialog
,"Messagebox\n");
243 ret
= MessageBox32A( hwnd
, textA
, titleA
, type
);
244 HeapFree( GetProcessHeap(), 0, titleA
);
245 HeapFree( GetProcessHeap(), 0, textA
);
250 /**************************************************************************
251 * MessageBoxEx32A (USER32.392)
253 INT32 WINAPI
MessageBoxEx32A( HWND32 hWnd
, LPCSTR text
, LPCSTR title
,
254 UINT32 type
, WORD langid
)
256 WARN(dialog
,"Messagebox\n");
257 /* ignore language id for now */
258 return MessageBox32A(hWnd
,text
,title
,type
);
261 /**************************************************************************
262 * MessageBoxEx32W (USER32.393)
264 INT32 WINAPI
MessageBoxEx32W( HWND32 hWnd
, LPCWSTR text
, LPCWSTR title
,
265 UINT32 type
, WORD langid
)
267 WARN(dialog
,"Messagebox\n");
268 /* ignore language id for now */
269 return MessageBox32W(hWnd
,text
,title
,type
);
272 /**************************************************************************
273 * MessageBoxIndirect16 (USER.827)
275 INT16 WINAPI
MessageBoxIndirect16( LPMSGBOXPARAMS16 msgbox
)
277 MSGBOXPARAMS32A msgbox32
;
278 WARN(dialog
,"Messagebox\n");
280 msgbox32
.cbSize
= msgbox
->cbSize
;
281 msgbox32
.hwndOwner
= msgbox
->hwndOwner
;
282 msgbox32
.hInstance
= msgbox
->hInstance
;
283 msgbox32
.lpszText
= PTR_SEG_TO_LIN(msgbox
->lpszText
);
284 msgbox32
.lpszCaption
= PTR_SEG_TO_LIN(msgbox
->lpszCaption
);
285 msgbox32
.dwStyle
= msgbox
->dwStyle
;
286 msgbox32
.lpszIcon
= PTR_SEG_TO_LIN(msgbox
->lpszIcon
);
287 msgbox32
.dwContextHelpId
= msgbox
->dwContextHelpId
;
288 msgbox32
.lpfnMsgBoxCallback
= msgbox
->lpfnMsgBoxCallback
;
289 msgbox32
.dwLanguageId
= msgbox
->dwLanguageId
;
291 return DialogBoxIndirectParam32A( msgbox32
.hInstance
,
292 SYSRES_GetResPtr( SYSRES_DIALOG_MSGBOX
),
293 msgbox32
.hwndOwner
, MSGBOX_DlgProc
,
297 /**************************************************************************
298 * MessageBoxIndirect32A (USER32.394)
300 INT32 WINAPI
MessageBoxIndirect32A( LPMSGBOXPARAMS32A msgbox
)
302 WARN(dialog
,"Messagebox\n");
303 return DialogBoxIndirectParam32A( msgbox
->hInstance
,
304 SYSRES_GetResPtr( SYSRES_DIALOG_MSGBOX
),
305 msgbox
->hwndOwner
, MSGBOX_DlgProc
,
309 /**************************************************************************
310 * MessageBoxIndirect32W (USER32.395)
312 INT32 WINAPI
MessageBoxIndirect32W( LPMSGBOXPARAMS32W msgbox
)
314 MSGBOXPARAMS32A msgboxa
;
315 WARN(dialog
,"Messagebox\n");
317 memcpy(&msgboxa
,msgbox
,sizeof(msgboxa
));
318 if (msgbox
->lpszCaption
)
319 lstrcpyWtoA((LPSTR
)msgboxa
.lpszCaption
,msgbox
->lpszCaption
);
320 if (msgbox
->lpszText
)
321 lstrcpyWtoA((LPSTR
)msgboxa
.lpszText
,msgbox
->lpszText
);
323 return MessageBoxIndirect32A(&msgboxa
);
327 /**************************************************************************
328 * FatalAppExit16 (KERNEL.137)
330 void WINAPI
FatalAppExit16( UINT16 action
, LPCSTR str
)
332 WARN(dialog
,"AppExit\n");
333 FatalAppExit32A( action
, str
);
337 /**************************************************************************
338 * FatalAppExit32A (KERNEL32.108)
340 void WINAPI
FatalAppExit32A( UINT32 action
, LPCSTR str
)
342 WARN(dialog
,"AppExit\n");
343 MessageBox32A( 0, str
, NULL
, MB_SYSTEMMODAL
| MB_OK
);
348 /**************************************************************************
349 * FatalAppExit32W (KERNEL32.109)
351 void WINAPI
FatalAppExit32W( UINT32 action
, LPCWSTR str
)
353 WARN(dialog
,"AppExit\n");
354 MessageBox32W( 0, str
, NULL
, MB_SYSTEMMODAL
| MB_OK
);