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
)
221 WARN(dialog
,"Messagebox\n");
222 if (!text
) text
="<WINE-NULL>";
225 mbox
.lpszCaption
= title
;
226 mbox
.lpszText
= text
;
228 return DialogBoxIndirectParamA( WIN_GetWindowInstance(hWnd
),
229 SYSRES_GetResPtr( SYSRES_DIALOG_MSGBOX
),
230 hWnd
, (DLGPROC
)MSGBOX_DlgProc
, (LPARAM
)&mbox
);
234 /**************************************************************************
235 * MessageBox32W (USER32.396)
237 INT WINAPI
MessageBoxW( HWND hwnd
, LPCWSTR text
, LPCWSTR title
,
240 LPSTR titleA
= HEAP_strdupWtoA( GetProcessHeap(), 0, title
);
241 LPSTR textA
= HEAP_strdupWtoA( GetProcessHeap(), 0, text
);
244 WARN(dialog
,"Messagebox\n");
246 ret
= MessageBoxA( hwnd
, textA
, titleA
, type
);
247 HeapFree( GetProcessHeap(), 0, titleA
);
248 HeapFree( GetProcessHeap(), 0, textA
);
253 /**************************************************************************
254 * MessageBoxEx32A (USER32.392)
256 INT WINAPI
MessageBoxExA( HWND hWnd
, LPCSTR text
, LPCSTR title
,
257 UINT type
, WORD langid
)
259 WARN(dialog
,"Messagebox\n");
260 /* ignore language id for now */
261 return MessageBoxA(hWnd
,text
,title
,type
);
264 /**************************************************************************
265 * MessageBoxEx32W (USER32.393)
267 INT WINAPI
MessageBoxExW( HWND hWnd
, LPCWSTR text
, LPCWSTR title
,
268 UINT type
, WORD langid
)
270 WARN(dialog
,"Messagebox\n");
271 /* ignore language id for now */
272 return MessageBoxW(hWnd
,text
,title
,type
);
275 /**************************************************************************
276 * MessageBoxIndirect16 (USER.827)
278 INT16 WINAPI
MessageBoxIndirect16( LPMSGBOXPARAMS16 msgbox
)
280 MSGBOXPARAMSA msgbox32
;
281 WARN(dialog
,"Messagebox\n");
283 msgbox32
.cbSize
= msgbox
->cbSize
;
284 msgbox32
.hwndOwner
= msgbox
->hwndOwner
;
285 msgbox32
.hInstance
= msgbox
->hInstance
;
286 msgbox32
.lpszText
= PTR_SEG_TO_LIN(msgbox
->lpszText
);
287 msgbox32
.lpszCaption
= PTR_SEG_TO_LIN(msgbox
->lpszCaption
);
288 msgbox32
.dwStyle
= msgbox
->dwStyle
;
289 msgbox32
.lpszIcon
= PTR_SEG_TO_LIN(msgbox
->lpszIcon
);
290 msgbox32
.dwContextHelpId
= msgbox
->dwContextHelpId
;
291 msgbox32
.lpfnMsgBoxCallback
= msgbox
->lpfnMsgBoxCallback
;
292 msgbox32
.dwLanguageId
= msgbox
->dwLanguageId
;
294 return DialogBoxIndirectParamA( msgbox32
.hInstance
,
295 SYSRES_GetResPtr( SYSRES_DIALOG_MSGBOX
),
296 msgbox32
.hwndOwner
, (DLGPROC
)MSGBOX_DlgProc
,
300 /**************************************************************************
301 * MessageBoxIndirect32A (USER32.394)
303 INT WINAPI
MessageBoxIndirectA( LPMSGBOXPARAMSA msgbox
)
305 WARN(dialog
,"Messagebox\n");
306 return DialogBoxIndirectParamA( msgbox
->hInstance
,
307 SYSRES_GetResPtr( SYSRES_DIALOG_MSGBOX
),
308 msgbox
->hwndOwner
, (DLGPROC
)MSGBOX_DlgProc
,
312 /**************************************************************************
313 * MessageBoxIndirect32W (USER32.395)
315 INT WINAPI
MessageBoxIndirectW( LPMSGBOXPARAMSW msgbox
)
317 MSGBOXPARAMSA msgboxa
;
318 WARN(dialog
,"Messagebox\n");
320 memcpy(&msgboxa
,msgbox
,sizeof(msgboxa
));
321 if (msgbox
->lpszCaption
)
322 lstrcpyWtoA((LPSTR
)msgboxa
.lpszCaption
,msgbox
->lpszCaption
);
323 if (msgbox
->lpszText
)
324 lstrcpyWtoA((LPSTR
)msgboxa
.lpszText
,msgbox
->lpszText
);
326 return MessageBoxIndirectA(&msgboxa
);
330 /**************************************************************************
331 * FatalAppExit16 (KERNEL.137)
333 void WINAPI
FatalAppExit16( UINT16 action
, LPCSTR str
)
335 WARN(dialog
,"AppExit\n");
336 FatalAppExitA( action
, str
);
340 /**************************************************************************
341 * FatalAppExit32A (KERNEL32.108)
343 void WINAPI
FatalAppExitA( UINT action
, LPCSTR str
)
345 WARN(dialog
,"AppExit\n");
346 MessageBoxA( 0, str
, NULL
, MB_SYSTEMMODAL
| MB_OK
);
351 /**************************************************************************
352 * FatalAppExit32W (KERNEL32.109)
354 void WINAPI
FatalAppExitW( UINT action
, LPCWSTR str
)
356 WARN(dialog
,"AppExit\n");
357 MessageBoxW( 0, str
, NULL
, MB_SYSTEMMODAL
| MB_OK
);