4 * Copyright 1995 Bernd Schmidt
11 #include "wine/winbase16.h"
12 #include "wine/winuser16.h"
16 #include "debugtools.h"
18 DEFAULT_DEBUG_CHANNEL(dialog
);
20 #define MSGBOX_IDICON 1088
21 #define MSGBOX_IDTEXT 100
23 static HFONT
MSGBOX_OnInit(HWND hwnd
, LPMSGBOXPARAMSA lpmb
)
25 static HFONT hFont
= 0, hPrevFont
= 0;
30 int bspace
, bw
, bh
, theight
, tleft
, wwidth
, wheight
, bpos
;
31 int borheight
, borwidth
, iheight
, ileft
, iwidth
, twidth
, tiheight
;
35 if (TWEAK_WineLook
>= WIN95_LOOK
) {
36 NONCLIENTMETRICSA nclm
;
37 nclm
.cbSize
= sizeof(NONCLIENTMETRICSA
);
38 SystemParametersInfoA (SPI_GETNONCLIENTMETRICS
, 0, &nclm
, 0);
39 hFont
= CreateFontIndirectA (&nclm
.lfMessageFont
);
42 SendDlgItemMessageA (hwnd
, i
, WM_SETFONT
, (WPARAM
)hFont
, 0);
44 SendDlgItemMessageA (hwnd
, MSGBOX_IDTEXT
, WM_SETFONT
, (WPARAM
)hFont
, 0);
46 if (HIWORD(lpmb
->lpszCaption
)) {
47 SetWindowTextA(hwnd
, lpmb
->lpszCaption
);
49 if (LoadStringA(lpmb
->hInstance
, LOWORD(lpmb
->lpszCaption
), buf
, sizeof(buf
)))
50 SetWindowTextA(hwnd
, buf
);
52 if (HIWORD(lpmb
->lpszText
)) {
53 lpszText
= lpmb
->lpszText
;
56 if (!LoadStringA(lpmb
->hInstance
, LOWORD(lpmb
->lpszText
), buf
, sizeof(buf
)))
57 *buf
= 0; /* FIXME ?? */
59 SetWindowTextA(GetDlgItem(hwnd
, MSGBOX_IDTEXT
), lpszText
);
61 /* Hide not selected buttons */
62 switch(lpmb
->dwStyle
& MB_TYPEMASK
) {
64 ShowWindow(GetDlgItem(hwnd
, IDCANCEL
), SW_HIDE
);
67 ShowWindow(GetDlgItem(hwnd
, IDABORT
), SW_HIDE
);
68 ShowWindow(GetDlgItem(hwnd
, IDRETRY
), SW_HIDE
);
69 ShowWindow(GetDlgItem(hwnd
, IDIGNORE
), SW_HIDE
);
70 ShowWindow(GetDlgItem(hwnd
, IDYES
), SW_HIDE
);
71 ShowWindow(GetDlgItem(hwnd
, IDNO
), SW_HIDE
);
73 case MB_ABORTRETRYIGNORE
:
74 ShowWindow(GetDlgItem(hwnd
, IDOK
), SW_HIDE
);
75 ShowWindow(GetDlgItem(hwnd
, IDCANCEL
), SW_HIDE
);
76 ShowWindow(GetDlgItem(hwnd
, IDYES
), SW_HIDE
);
77 ShowWindow(GetDlgItem(hwnd
, IDNO
), SW_HIDE
);
80 ShowWindow(GetDlgItem(hwnd
, IDCANCEL
), SW_HIDE
);
83 ShowWindow(GetDlgItem(hwnd
, IDOK
), SW_HIDE
);
84 ShowWindow(GetDlgItem(hwnd
, IDABORT
), SW_HIDE
);
85 ShowWindow(GetDlgItem(hwnd
, IDRETRY
), SW_HIDE
);
86 ShowWindow(GetDlgItem(hwnd
, IDIGNORE
), SW_HIDE
);
89 ShowWindow(GetDlgItem(hwnd
, IDOK
), SW_HIDE
);
90 ShowWindow(GetDlgItem(hwnd
, IDABORT
), SW_HIDE
);
91 ShowWindow(GetDlgItem(hwnd
, IDIGNORE
), SW_HIDE
);
92 ShowWindow(GetDlgItem(hwnd
, IDYES
), SW_HIDE
);
93 ShowWindow(GetDlgItem(hwnd
, IDNO
), SW_HIDE
);
97 switch(lpmb
->dwStyle
& MB_ICONMASK
) {
98 case MB_ICONEXCLAMATION
:
99 SendDlgItemMessageA(hwnd
, stc1
, STM_SETICON
, LoadIconA(0, IDI_EXCLAMATIONA
), 0);
101 case MB_ICONQUESTION
:
102 SendDlgItemMessageA(hwnd
, stc1
, STM_SETICON
, LoadIconA(0, IDI_QUESTIONA
), 0);
104 case MB_ICONASTERISK
:
105 SendDlgItemMessageA(hwnd
, stc1
, STM_SETICON
, LoadIconA(0, IDI_ASTERISKA
), 0);
108 SendDlgItemMessageA(hwnd
, stc1
, STM_SETICON
, LoadIconA(0, IDI_HANDA
), 0);
111 /* By default, Windows 95/98/NT do not associate an icon to message boxes.
112 * So wine should do the same.
117 /* Position everything */
118 GetWindowRect(hwnd
, &rect
);
119 borheight
= rect
.bottom
- rect
.top
;
120 borwidth
= rect
.right
- rect
.left
;
121 GetClientRect(hwnd
, &rect
);
122 borheight
-= rect
.bottom
- rect
.top
;
123 borwidth
-= rect
.right
- rect
.left
;
125 /* Get the icon height */
126 GetWindowRect(GetDlgItem(hwnd
, MSGBOX_IDICON
), &rect
);
127 MapWindowPoints(0, hwnd
, (LPPOINT
)&rect
, 2);
128 iheight
= rect
.bottom
- rect
.top
;
130 iwidth
= rect
.right
- ileft
;
134 hPrevFont
= SelectObject(hdc
, hFont
);
136 /* Get the number of visible buttons and their size */
137 bh
= bw
= 1; /* Minimum button sizes */
138 for (buttons
= 0, i
= 1; i
< 8; i
++)
140 hItem
= GetDlgItem(hwnd
, i
);
141 if (GetWindowLongA(hItem
, GWL_STYLE
) & WS_VISIBLE
)
143 char buttonText
[1024];
146 if (GetWindowTextA(hItem
, buttonText
, sizeof buttonText
))
148 DrawTextA( hdc
, buttonText
, -1, &rect
, DT_LEFT
| DT_EXPANDTABS
| DT_CALCRECT
);
149 h
= rect
.bottom
- rect
.top
;
150 w
= rect
.right
- rect
.left
;
156 bw
= max(bw
, bh
* 2);
157 /* Button white space */
160 bspace
= bw
/3; /* Space between buttons */
162 /* Get the text size */
163 GetClientRect(GetDlgItem(hwnd
, MSGBOX_IDTEXT
), &rect
);
164 rect
.top
= rect
.left
= rect
.bottom
= 0;
165 DrawTextA( hdc
, lpszText
, -1, &rect
,
166 DT_LEFT
| DT_EXPANDTABS
| DT_WORDBREAK
| DT_CALCRECT
);
167 /* Min text width corresponds to space for the buttons */
168 tleft
= 2 * ileft
+ iwidth
;
169 twidth
= max((bw
+ bspace
) * buttons
+ bspace
- tleft
, rect
.right
);
170 theight
= rect
.bottom
;
173 SelectObject(hdc
, hPrevFont
);
174 ReleaseDC(hItem
, hdc
);
176 tiheight
= 16 + max(iheight
, theight
);
177 wwidth
= tleft
+ twidth
+ ileft
+ borwidth
;
178 wheight
= 8 + tiheight
+ bh
+ borheight
;
180 /* Resize the window */
181 SetWindowPos(hwnd
, 0, 0, 0, wwidth
, wheight
,
182 SWP_NOMOVE
| SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_NOREDRAW
);
184 /* Position the icon */
185 SetWindowPos(GetDlgItem(hwnd
, MSGBOX_IDICON
), 0, ileft
, (tiheight
- iheight
) / 2, 0, 0,
186 SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_NOREDRAW
);
188 /* Position the text */
189 SetWindowPos(GetDlgItem(hwnd
, MSGBOX_IDTEXT
), 0, tleft
, (tiheight
- theight
) / 2, twidth
, theight
,
190 SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_NOREDRAW
);
192 /* Position the buttons */
193 bpos
= (wwidth
- (bw
+ bspace
) * buttons
+ bspace
) / 2;
194 for (buttons
= i
= 0; i
< 7; i
++) {
195 /* some arithmetic to get the right order for YesNoCancel windows */
196 hItem
= GetDlgItem(hwnd
, (i
+ 5) % 7 + 1);
197 if (GetWindowLongA(hItem
, GWL_STYLE
) & WS_VISIBLE
) {
198 if (buttons
++ == ((lpmb
->dwStyle
& MB_DEFMASK
) >> 8)) {
200 SendMessageA( hItem
, BM_SETSTYLE
, BS_DEFPUSHBUTTON
, TRUE
);
202 SetWindowPos(hItem
, 0, bpos
, tiheight
, bw
, bh
,
203 SWP_NOZORDER
|SWP_NOACTIVATE
|SWP_NOREDRAW
);
211 /**************************************************************************
214 * Dialog procedure for message boxes.
216 static LRESULT CALLBACK
MSGBOX_DlgProc( HWND hwnd
, UINT message
,
217 WPARAM wParam
, LPARAM lParam
)
222 hFont
= MSGBOX_OnInit(hwnd
, (LPMSGBOXPARAMSA
)lParam
);
235 EndDialog(hwnd
, wParam
);
242 /* Ok. Ignore all the other messages */
243 TRACE("Message number %i is being ignored.\n", message
);
250 /**************************************************************************
251 * MessageBox (USER.1)
253 INT16 WINAPI
MessageBox16( HWND16 hwnd
, LPCSTR text
, LPCSTR title
, UINT16 type
)
255 WARN("Messagebox\n");
256 return MessageBoxA( hwnd
, text
, title
, type
);
260 /**************************************************************************
261 * MessageBoxA (USER32.@)
264 * The WARN is here to help debug erroneous MessageBoxes
265 * Use: -debugmsg warn+dialog,+relay
267 INT WINAPI
MessageBoxA(HWND hWnd
, LPCSTR text
, LPCSTR title
, UINT type
)
273 WARN("Messagebox\n");
275 if(!(hRes
= FindResourceA(GetModuleHandleA("USER32"), "MSGBOX", RT_DIALOGA
)))
277 if(!(template = (LPVOID
)LoadResource(GetModuleHandleA("USER32"), hRes
)))
280 if (!text
) text
="<WINE-NULL>";
283 mbox
.lpszCaption
= title
;
284 mbox
.lpszText
= text
;
286 return DialogBoxIndirectParamA( GetWindowLongA(hWnd
,GWL_HINSTANCE
), template,
287 hWnd
, (DLGPROC
)MSGBOX_DlgProc
, (LPARAM
)&mbox
);
291 /**************************************************************************
292 * MessageBoxW (USER32.@)
294 INT WINAPI
MessageBoxW( HWND hwnd
, LPCWSTR text
, LPCWSTR title
,
297 LPSTR titleA
= HEAP_strdupWtoA( GetProcessHeap(), 0, title
);
298 LPSTR textA
= HEAP_strdupWtoA( GetProcessHeap(), 0, text
);
301 WARN("Messagebox\n");
303 ret
= MessageBoxA( hwnd
, textA
, titleA
, type
);
304 HeapFree( GetProcessHeap(), 0, titleA
);
305 HeapFree( GetProcessHeap(), 0, textA
);
310 /**************************************************************************
311 * MessageBoxExA (USER32.@)
313 INT WINAPI
MessageBoxExA( HWND hWnd
, LPCSTR text
, LPCSTR title
,
314 UINT type
, WORD langid
)
316 WARN("Messagebox\n");
317 /* ignore language id for now */
318 return MessageBoxA(hWnd
,text
,title
,type
);
321 /**************************************************************************
322 * MessageBoxExW (USER32.@)
324 INT WINAPI
MessageBoxExW( HWND hWnd
, LPCWSTR text
, LPCWSTR title
,
325 UINT type
, WORD langid
)
327 WARN("Messagebox\n");
328 /* ignore language id for now */
329 return MessageBoxW(hWnd
,text
,title
,type
);
332 /**************************************************************************
333 * MessageBoxIndirect (USER.827)
335 INT16 WINAPI
MessageBoxIndirect16( LPMSGBOXPARAMS16 msgbox
)
339 MSGBOXPARAMSA msgbox32
;
341 WARN("Messagebox\n");
343 if(!(hRes
= FindResourceA(GetModuleHandleA("USER32"), "MSGBOX", RT_DIALOGA
)))
345 if(!(template = (LPVOID
)LoadResource(GetModuleHandleA("USER32"), hRes
)))
348 msgbox32
.cbSize
= msgbox
->cbSize
;
349 msgbox32
.hwndOwner
= msgbox
->hwndOwner
;
350 msgbox32
.hInstance
= msgbox
->hInstance
;
351 msgbox32
.lpszText
= MapSL(msgbox
->lpszText
);
352 msgbox32
.lpszCaption
= MapSL(msgbox
->lpszCaption
);
353 msgbox32
.dwStyle
= msgbox
->dwStyle
;
354 msgbox32
.lpszIcon
= MapSL(msgbox
->lpszIcon
);
355 msgbox32
.dwContextHelpId
= msgbox
->dwContextHelpId
;
356 msgbox32
.lpfnMsgBoxCallback
= msgbox
->lpfnMsgBoxCallback
;
357 msgbox32
.dwLanguageId
= msgbox
->dwLanguageId
;
359 return DialogBoxIndirectParamA( msgbox32
.hInstance
, template,
360 msgbox32
.hwndOwner
, (DLGPROC
)MSGBOX_DlgProc
,
364 /**************************************************************************
365 * MessageBoxIndirectA (USER32.@)
367 INT WINAPI
MessageBoxIndirectA( LPMSGBOXPARAMSA msgbox
)
372 WARN("Messagebox\n");
374 if(!(hRes
= FindResourceA(GetModuleHandleA("USER32"), "MSGBOX", RT_DIALOGA
)))
376 if(!(template = (LPVOID
)LoadResource(GetModuleHandleA("USER32"), hRes
)))
379 return DialogBoxIndirectParamA( msgbox
->hInstance
, template,
380 msgbox
->hwndOwner
, (DLGPROC
)MSGBOX_DlgProc
,
384 /**************************************************************************
385 * MessageBoxIndirectW (USER32.@)
387 INT WINAPI
MessageBoxIndirectW( LPMSGBOXPARAMSW msgbox
)
389 MSGBOXPARAMSA msgboxa
;
390 memcpy(&msgboxa
,msgbox
,sizeof(msgboxa
));
391 msgboxa
.lpszCaption
= HEAP_strdupWtoA( GetProcessHeap(), 0, msgbox
->lpszCaption
);
392 msgboxa
.lpszText
= HEAP_strdupWtoA( GetProcessHeap(), 0, msgbox
->lpszText
);
393 msgboxa
.lpszIcon
= HEAP_strdupWtoA( GetProcessHeap(), 0, msgbox
->lpszIcon
);
394 return MessageBoxIndirectA(&msgboxa
);