4 * Copyright 1995 Bernd Schmidt
8 #include "wine/winuser16.h"
19 DEFAULT_DEBUG_CHANNEL(dialog
)
21 /**************************************************************************
24 * Dialog procedure for message boxes.
26 static LRESULT CALLBACK
MSGBOX_DlgProc( HWND hwnd
, UINT message
,
27 WPARAM wParam
, LPARAM lParam
)
29 static HFONT hFont
= 0;
36 int i
, buttons
, bwidth
, bheight
, theight
, wwidth
, bpos
;
37 int borheight
, iheight
, tiheight
;
41 lpmb
= (LPMSGBOXPARAMSA
)lParam
;
42 if (TWEAK_WineLook
>= WIN95_LOOK
) {
43 NONCLIENTMETRICSA nclm
;
45 nclm
.cbSize
= sizeof(NONCLIENTMETRICSA
);
46 SystemParametersInfoA (SPI_GETNONCLIENTMETRICS
, 0, &nclm
, 0);
47 hFont
= CreateFontIndirectA (&nclm
.lfMessageFont
);
50 SendDlgItemMessageA (hwnd
, i
, WM_SETFONT
, (WPARAM
)hFont
, 0);
52 SendDlgItemMessageA (hwnd
, 100, WM_SETFONT
, (WPARAM
)hFont
, 0);
54 if (lpmb
->lpszCaption
) SetWindowTextA(hwnd
, lpmb
->lpszCaption
);
55 SetWindowTextA(GetDlgItem(hwnd
, 100), lpmb
->lpszText
);
56 /* Hide not selected buttons */
57 switch(lpmb
->dwStyle
& MB_TYPEMASK
) {
59 ShowWindow(GetDlgItem(hwnd
, 2), SW_HIDE
);
62 ShowWindow(GetDlgItem(hwnd
, 3), SW_HIDE
);
63 ShowWindow(GetDlgItem(hwnd
, 4), SW_HIDE
);
64 ShowWindow(GetDlgItem(hwnd
, 5), SW_HIDE
);
65 ShowWindow(GetDlgItem(hwnd
, 6), SW_HIDE
);
66 ShowWindow(GetDlgItem(hwnd
, 7), SW_HIDE
);
68 case MB_ABORTRETRYIGNORE
:
69 ShowWindow(GetDlgItem(hwnd
, 1), SW_HIDE
);
70 ShowWindow(GetDlgItem(hwnd
, 2), SW_HIDE
);
71 ShowWindow(GetDlgItem(hwnd
, 6), SW_HIDE
);
72 ShowWindow(GetDlgItem(hwnd
, 7), SW_HIDE
);
75 ShowWindow(GetDlgItem(hwnd
, 2), SW_HIDE
);
78 ShowWindow(GetDlgItem(hwnd
, 1), SW_HIDE
);
79 ShowWindow(GetDlgItem(hwnd
, 3), SW_HIDE
);
80 ShowWindow(GetDlgItem(hwnd
, 4), SW_HIDE
);
81 ShowWindow(GetDlgItem(hwnd
, 5), SW_HIDE
);
85 switch(lpmb
->dwStyle
& MB_ICONMASK
) {
86 case MB_ICONEXCLAMATION
:
87 SendDlgItemMessage16(hwnd
, stc1
, STM_SETICON16
,
88 (WPARAM16
)LoadIcon16(0, IDI_EXCLAMATION16
), 0);
91 SendDlgItemMessage16(hwnd
, stc1
, STM_SETICON16
,
92 (WPARAM16
)LoadIcon16(0, IDI_QUESTION16
), 0);
95 SendDlgItemMessage16(hwnd
, stc1
, STM_SETICON16
,
96 (WPARAM16
)LoadIcon16(0, IDI_ASTERISK16
), 0);
100 SendDlgItemMessage16(hwnd
, stc1
, STM_SETICON16
,
101 (WPARAM16
)LoadIcon16(0, IDI_HAND16
), 0);
105 /* Position everything */
106 GetWindowRect(hwnd
, &rect
);
107 borheight
= rect
.bottom
- rect
.top
;
108 wwidth
= rect
.right
- rect
.left
;
109 GetClientRect(hwnd
, &rect
);
110 borheight
-= rect
.bottom
- rect
.top
;
112 /* Get the icon height */
113 GetWindowRect(GetDlgItem(hwnd
, 1088), &rect
);
114 iheight
= rect
.bottom
- rect
.top
;
116 /* Get the number of visible buttons and their width */
117 GetWindowRect(GetDlgItem(hwnd
, 2), &rect
);
118 bheight
= rect
.bottom
- rect
.top
;
120 GetWindowRect(GetDlgItem(hwnd
, 1), &rect
);
122 for (buttons
= 0, i
= 1; i
< 8; i
++)
124 hItem
= GetDlgItem(hwnd
, i
);
125 if (GetWindowLongA(hItem
, GWL_STYLE
) & WS_VISIBLE
) buttons
++;
128 /* Get the text size */
129 hItem
= GetDlgItem(hwnd
, 100);
130 GetWindowRect(hItem
, &textrect
);
131 MapWindowPoints(0, hwnd
, (LPPOINT
)&textrect
, 2);
133 GetClientRect(hItem
, &rect
);
135 lRet
= DrawTextA( hdc
, lpmb
->lpszText
, -1, &rect
,
136 DT_LEFT
| DT_EXPANDTABS
| DT_WORDBREAK
| DT_CALCRECT
);
137 theight
= rect
.bottom
- rect
.top
;
138 tiheight
= 16 + MAX(iheight
, theight
);
139 ReleaseDC(hItem
, hdc
);
141 /* Position the text */
142 SetWindowPos(hItem
, 0, textrect
.left
, (tiheight
- theight
) / 2,
143 rect
.right
- rect
.left
, theight
,
144 SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_NOREDRAW
);
146 /* Position the icon */
147 hItem
= GetDlgItem(hwnd
, 1088);
148 GetWindowRect(hItem
, &rect
);
149 MapWindowPoints(0, hwnd
, (LPPOINT
)&rect
, 2);
150 SetWindowPos(hItem
, 0, rect
.left
, (tiheight
- iheight
) / 2, 0, 0,
151 SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_NOREDRAW
);
153 /* Resize the window */
154 SetWindowPos(hwnd
, 0, 0, 0, wwidth
, 8 + tiheight
+ bheight
+ borheight
,
155 SWP_NOMOVE
| SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_NOREDRAW
);
157 /* Position the buttons */
158 bpos
= (wwidth
- bwidth
* buttons
) / 2;
159 GetWindowRect(GetDlgItem(hwnd
, 1), &rect
);
160 for (buttons
= i
= 0; i
< 7; i
++) {
161 /* some arithmetic to get the right order for YesNoCancel windows */
162 hItem
= GetDlgItem(hwnd
, (i
+ 5) % 7 + 1);
163 if (GetWindowLongA(hItem
, GWL_STYLE
) & WS_VISIBLE
) {
164 if (buttons
++ == ((lpmb
->dwStyle
& MB_DEFMASK
) >> 8)) {
166 SendMessageA( hItem
, BM_SETSTYLE
, BS_DEFPUSHBUTTON
, TRUE
);
168 SetWindowPos(hItem
, 0, bpos
, tiheight
, 0, 0,
169 SWP_NOSIZE
|SWP_NOZORDER
|SWP_NOACTIVATE
|SWP_NOREDRAW
);
186 if ((TWEAK_WineLook
> WIN31_LOOK
) && hFont
)
187 DeleteObject (hFont
);
188 EndDialog(hwnd
, wParam
);
193 /* Ok. Ignore all the other messages */
194 TRACE (dialog
, "Message number %i is being ignored.\n", message
);
201 /**************************************************************************
202 * MessageBox16 (USER.1)
204 INT16 WINAPI
MessageBox16( HWND16 hwnd
, LPCSTR text
, LPCSTR title
, UINT16 type
)
206 WARN(dialog
,"Messagebox\n");
207 return MessageBoxA( hwnd
, text
, title
, type
);
211 /**************************************************************************
212 * MessageBox32A (USER32.391)
215 * The WARN is here to help debug erroneous MessageBoxes
216 * Use: -debugmsg warn+dialog,+relay
218 INT WINAPI
MessageBoxA(HWND hWnd
, LPCSTR text
, LPCSTR title
, UINT type
)
224 WARN(dialog
,"Messagebox\n");
226 if(!(hRes
= FindResourceA(GetModuleHandleA("USER32"), "MSGBOX", RT_DIALOGA
)))
228 if(!(template = (LPVOID
)LoadResource(GetModuleHandleA("USER32"), hRes
)))
231 if (!text
) text
="<WINE-NULL>";
234 mbox
.lpszCaption
= title
;
235 mbox
.lpszText
= text
;
237 return DialogBoxIndirectParamA( WIN_GetWindowInstance(hWnd
), template,
238 hWnd
, (DLGPROC
)MSGBOX_DlgProc
, (LPARAM
)&mbox
);
242 /**************************************************************************
243 * MessageBox32W (USER32.396)
245 INT WINAPI
MessageBoxW( HWND hwnd
, LPCWSTR text
, LPCWSTR title
,
248 LPSTR titleA
= HEAP_strdupWtoA( GetProcessHeap(), 0, title
);
249 LPSTR textA
= HEAP_strdupWtoA( GetProcessHeap(), 0, text
);
252 WARN(dialog
,"Messagebox\n");
254 ret
= MessageBoxA( hwnd
, textA
, titleA
, type
);
255 HeapFree( GetProcessHeap(), 0, titleA
);
256 HeapFree( GetProcessHeap(), 0, textA
);
261 /**************************************************************************
262 * MessageBoxEx32A (USER32.392)
264 INT WINAPI
MessageBoxExA( HWND hWnd
, LPCSTR text
, LPCSTR title
,
265 UINT type
, WORD langid
)
267 WARN(dialog
,"Messagebox\n");
268 /* ignore language id for now */
269 return MessageBoxA(hWnd
,text
,title
,type
);
272 /**************************************************************************
273 * MessageBoxEx32W (USER32.393)
275 INT WINAPI
MessageBoxExW( HWND hWnd
, LPCWSTR text
, LPCWSTR title
,
276 UINT type
, WORD langid
)
278 WARN(dialog
,"Messagebox\n");
279 /* ignore language id for now */
280 return MessageBoxW(hWnd
,text
,title
,type
);
283 /**************************************************************************
284 * MessageBoxIndirect16 (USER.827)
286 INT16 WINAPI
MessageBoxIndirect16( LPMSGBOXPARAMS16 msgbox
)
290 MSGBOXPARAMSA msgbox32
;
292 WARN(dialog
,"Messagebox\n");
294 if(!(hRes
= FindResourceA(GetModuleHandleA("USER32"), "MSGBOX", RT_DIALOGA
)))
296 if(!(template = (LPVOID
)LoadResource(GetModuleHandleA("USER32"), hRes
)))
299 msgbox32
.cbSize
= msgbox
->cbSize
;
300 msgbox32
.hwndOwner
= msgbox
->hwndOwner
;
301 msgbox32
.hInstance
= msgbox
->hInstance
;
302 msgbox32
.lpszText
= PTR_SEG_TO_LIN(msgbox
->lpszText
);
303 msgbox32
.lpszCaption
= PTR_SEG_TO_LIN(msgbox
->lpszCaption
);
304 msgbox32
.dwStyle
= msgbox
->dwStyle
;
305 msgbox32
.lpszIcon
= PTR_SEG_TO_LIN(msgbox
->lpszIcon
);
306 msgbox32
.dwContextHelpId
= msgbox
->dwContextHelpId
;
307 msgbox32
.lpfnMsgBoxCallback
= msgbox
->lpfnMsgBoxCallback
;
308 msgbox32
.dwLanguageId
= msgbox
->dwLanguageId
;
310 return DialogBoxIndirectParamA( msgbox32
.hInstance
, template,
311 msgbox32
.hwndOwner
, (DLGPROC
)MSGBOX_DlgProc
,
315 /**************************************************************************
316 * MessageBoxIndirect32A (USER32.394)
318 INT WINAPI
MessageBoxIndirectA( LPMSGBOXPARAMSA msgbox
)
323 WARN(dialog
,"Messagebox\n");
325 if(!(hRes
= FindResourceA(GetModuleHandleA("USER32"), "MSGBOX", RT_DIALOGA
)))
327 if(!(template = (LPVOID
)LoadResource(GetModuleHandleA("USER32"), hRes
)))
330 return DialogBoxIndirectParamA( msgbox
->hInstance
, template,
331 msgbox
->hwndOwner
, (DLGPROC
)MSGBOX_DlgProc
,
335 /**************************************************************************
336 * MessageBoxIndirect32W (USER32.395)
338 INT WINAPI
MessageBoxIndirectW( LPMSGBOXPARAMSW msgbox
)
340 MSGBOXPARAMSA msgboxa
;
341 WARN(dialog
,"Messagebox\n");
343 memcpy(&msgboxa
,msgbox
,sizeof(msgboxa
));
344 if (msgbox
->lpszCaption
)
345 lstrcpyWtoA((LPSTR
)msgboxa
.lpszCaption
,msgbox
->lpszCaption
);
346 if (msgbox
->lpszText
)
347 lstrcpyWtoA((LPSTR
)msgboxa
.lpszText
,msgbox
->lpszText
);
349 return MessageBoxIndirectA(&msgboxa
);
353 /**************************************************************************
354 * FatalAppExit16 (KERNEL.137)
356 void WINAPI
FatalAppExit16( UINT16 action
, LPCSTR str
)
358 WARN(dialog
,"AppExit\n");
359 FatalAppExitA( action
, str
);
363 /**************************************************************************
364 * FatalAppExit32A (KERNEL32.108)
366 void WINAPI
FatalAppExitA( UINT action
, LPCSTR str
)
368 WARN(dialog
,"AppExit\n");
369 MessageBoxA( 0, str
, NULL
, MB_SYSTEMMODAL
| MB_OK
);
374 /**************************************************************************
375 * FatalAppExit32W (KERNEL32.109)
377 void WINAPI
FatalAppExitW( UINT action
, LPCWSTR str
)
379 WARN(dialog
,"AppExit\n");
380 MessageBoxW( 0, str
, NULL
, MB_SYSTEMMODAL
| MB_OK
);