4 * Copyright 1995 Bernd Schmidt
8 #include "wine/winuser16.h"
16 DEFAULT_DEBUG_CHANNEL(dialog
)
18 /**************************************************************************
21 * Dialog procedure for message boxes.
23 static LRESULT CALLBACK
MSGBOX_DlgProc( HWND hwnd
, UINT message
,
24 WPARAM wParam
, LPARAM lParam
)
26 static HFONT hFont
= 0;
33 int i
, buttons
, bwidth
, bheight
, theight
, wwidth
, bpos
;
34 int borheight
, iheight
, tiheight
;
38 lpmb
= (LPMSGBOXPARAMSA
)lParam
;
39 if (TWEAK_WineLook
>= WIN95_LOOK
) {
40 NONCLIENTMETRICSA nclm
;
42 nclm
.cbSize
= sizeof(NONCLIENTMETRICSA
);
43 SystemParametersInfoA (SPI_GETNONCLIENTMETRICS
, 0, &nclm
, 0);
44 hFont
= CreateFontIndirectA (&nclm
.lfMessageFont
);
47 SendDlgItemMessageA (hwnd
, i
, WM_SETFONT
, (WPARAM
)hFont
, 0);
49 SendDlgItemMessageA (hwnd
, 100, WM_SETFONT
, (WPARAM
)hFont
, 0);
51 if (lpmb
->lpszCaption
) SetWindowTextA(hwnd
, lpmb
->lpszCaption
);
52 SetWindowTextA(GetDlgItem(hwnd
, 100), lpmb
->lpszText
);
53 /* Hide not selected buttons */
54 switch(lpmb
->dwStyle
& MB_TYPEMASK
) {
56 ShowWindow(GetDlgItem(hwnd
, 2), SW_HIDE
);
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
);
65 case MB_ABORTRETRYIGNORE
:
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
);
72 ShowWindow(GetDlgItem(hwnd
, 2), SW_HIDE
);
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
);
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 GetWindowRect(hwnd
, &rect
);
104 borheight
= rect
.bottom
- rect
.top
;
105 wwidth
= rect
.right
- rect
.left
;
106 GetClientRect(hwnd
, &rect
);
107 borheight
-= rect
.bottom
- rect
.top
;
109 /* Get the icon height */
110 GetWindowRect(GetDlgItem(hwnd
, 1088), &rect
);
111 iheight
= rect
.bottom
- rect
.top
;
113 /* Get the number of visible buttons and their width */
114 GetWindowRect(GetDlgItem(hwnd
, 2), &rect
);
115 bheight
= rect
.bottom
- rect
.top
;
117 GetWindowRect(GetDlgItem(hwnd
, 1), &rect
);
119 for (buttons
= 0, i
= 1; i
< 8; i
++)
121 hItem
= GetDlgItem(hwnd
, i
);
122 if (GetWindowLongA(hItem
, GWL_STYLE
) & WS_VISIBLE
) buttons
++;
125 /* Get the text size */
126 hItem
= GetDlgItem(hwnd
, 100);
127 GetWindowRect(hItem
, &textrect
);
128 MapWindowPoints(0, hwnd
, (LPPOINT
)&textrect
, 2);
130 GetClientRect(hItem
, &rect
);
132 lRet
= DrawTextA( 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 ReleaseDC(hItem
, hdc
);
138 /* Position the text */
139 SetWindowPos(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
= 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,
148 SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_NOREDRAW
);
150 /* Resize the window */
151 SetWindowPos(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 GetWindowRect(GetDlgItem(hwnd
, 1), &rect
);
157 for (buttons
= i
= 0; i
< 7; i
++) {
158 /* some arithmetic to get the right order for YesNoCancel windows */
159 hItem
= GetDlgItem(hwnd
, (i
+ 5) % 7 + 1);
160 if (GetWindowLongA(hItem
, GWL_STYLE
) & WS_VISIBLE
) {
161 if (buttons
++ == ((lpmb
->dwStyle
& MB_DEFMASK
) >> 8)) {
163 SendMessageA( hItem
, BM_SETSTYLE
, BS_DEFPUSHBUTTON
, TRUE
);
165 SetWindowPos(hItem
, 0, bpos
, tiheight
, 0, 0,
166 SWP_NOSIZE
|SWP_NOZORDER
|SWP_NOACTIVATE
|SWP_NOREDRAW
);
183 if ((TWEAK_WineLook
> WIN31_LOOK
) && hFont
)
184 DeleteObject (hFont
);
185 EndDialog(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 MessageBoxA( 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 INT WINAPI
MessageBoxA(HWND hWnd
, LPCSTR text
, LPCSTR title
, UINT type
)
221 WARN(dialog
,"Messagebox\n");
223 if(!(hRes
= FindResourceA(GetModuleHandleA("USER32"), "MSGBOX", RT_DIALOGA
)))
225 if(!(template = (LPVOID
)LoadResource(GetModuleHandleA("USER32"), hRes
)))
228 if (!text
) text
="<WINE-NULL>";
231 mbox
.lpszCaption
= title
;
232 mbox
.lpszText
= text
;
234 return DialogBoxIndirectParamA( GetWindowLongA(hWnd
,GWL_HINSTANCE
), template,
235 hWnd
, (DLGPROC
)MSGBOX_DlgProc
, (LPARAM
)&mbox
);
239 /**************************************************************************
240 * MessageBox32W (USER32.396)
242 INT WINAPI
MessageBoxW( HWND hwnd
, LPCWSTR text
, LPCWSTR title
,
245 LPSTR titleA
= HEAP_strdupWtoA( GetProcessHeap(), 0, title
);
246 LPSTR textA
= HEAP_strdupWtoA( GetProcessHeap(), 0, text
);
249 WARN(dialog
,"Messagebox\n");
251 ret
= MessageBoxA( hwnd
, textA
, titleA
, type
);
252 HeapFree( GetProcessHeap(), 0, titleA
);
253 HeapFree( GetProcessHeap(), 0, textA
);
258 /**************************************************************************
259 * MessageBoxEx32A (USER32.392)
261 INT WINAPI
MessageBoxExA( HWND hWnd
, LPCSTR text
, LPCSTR title
,
262 UINT type
, WORD langid
)
264 WARN(dialog
,"Messagebox\n");
265 /* ignore language id for now */
266 return MessageBoxA(hWnd
,text
,title
,type
);
269 /**************************************************************************
270 * MessageBoxEx32W (USER32.393)
272 INT WINAPI
MessageBoxExW( HWND hWnd
, LPCWSTR text
, LPCWSTR title
,
273 UINT type
, WORD langid
)
275 WARN(dialog
,"Messagebox\n");
276 /* ignore language id for now */
277 return MessageBoxW(hWnd
,text
,title
,type
);
280 /**************************************************************************
281 * MessageBoxIndirect16 (USER.827)
283 INT16 WINAPI
MessageBoxIndirect16( LPMSGBOXPARAMS16 msgbox
)
287 MSGBOXPARAMSA msgbox32
;
289 WARN(dialog
,"Messagebox\n");
291 if(!(hRes
= FindResourceA(GetModuleHandleA("USER32"), "MSGBOX", RT_DIALOGA
)))
293 if(!(template = (LPVOID
)LoadResource(GetModuleHandleA("USER32"), hRes
)))
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
;
307 return DialogBoxIndirectParamA( msgbox32
.hInstance
, template,
308 msgbox32
.hwndOwner
, (DLGPROC
)MSGBOX_DlgProc
,
312 /**************************************************************************
313 * MessageBoxIndirect32A (USER32.394)
315 INT WINAPI
MessageBoxIndirectA( LPMSGBOXPARAMSA msgbox
)
320 WARN(dialog
,"Messagebox\n");
322 if(!(hRes
= FindResourceA(GetModuleHandleA("USER32"), "MSGBOX", RT_DIALOGA
)))
324 if(!(template = (LPVOID
)LoadResource(GetModuleHandleA("USER32"), hRes
)))
327 return DialogBoxIndirectParamA( msgbox
->hInstance
, template,
328 msgbox
->hwndOwner
, (DLGPROC
)MSGBOX_DlgProc
,
332 /**************************************************************************
333 * MessageBoxIndirect32W (USER32.395)
335 INT WINAPI
MessageBoxIndirectW( LPMSGBOXPARAMSW msgbox
)
337 MSGBOXPARAMSA msgboxa
;
338 WARN(dialog
,"Messagebox\n");
340 memcpy(&msgboxa
,msgbox
,sizeof(msgboxa
));
341 if (msgbox
->lpszCaption
)
342 lstrcpyWtoA((LPSTR
)msgboxa
.lpszCaption
,msgbox
->lpszCaption
);
343 if (msgbox
->lpszText
)
344 lstrcpyWtoA((LPSTR
)msgboxa
.lpszText
,msgbox
->lpszText
);
346 return MessageBoxIndirectA(&msgboxa
);
350 /**************************************************************************
351 * FatalAppExit16 (KERNEL.137)
353 void WINAPI
FatalAppExit16( UINT16 action
, LPCSTR str
)
355 WARN(dialog
,"AppExit\n");
356 FatalAppExitA( action
, str
);
360 /**************************************************************************
361 * FatalAppExit32A (KERNEL32.108)
363 void WINAPI
FatalAppExitA( UINT action
, LPCSTR str
)
365 WARN(dialog
,"AppExit\n");
366 MessageBoxA( 0, str
, NULL
, MB_SYSTEMMODAL
| MB_OK
);
371 /**************************************************************************
372 * FatalAppExit32W (KERNEL32.109)
374 void WINAPI
FatalAppExitW( UINT action
, LPCWSTR str
)
376 WARN(dialog
,"AppExit\n");
377 MessageBoxW( 0, str
, NULL
, MB_SYSTEMMODAL
| MB_OK
);