4 * Copyright 1995 Bernd Schmidt
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 #include "wine/winbase16.h"
26 #include "wine/winuser16.h"
30 #include "wine/debug.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(dialog
);
34 #define MSGBOX_IDICON 1088
35 #define MSGBOX_IDTEXT 100
37 static HFONT
MSGBOX_OnInit(HWND hwnd
, LPMSGBOXPARAMSA lpmb
)
39 static HFONT hFont
= 0, hPrevFont
= 0;
44 int bspace
, bw
, bh
, theight
, tleft
, wwidth
, wheight
, bpos
;
45 int borheight
, borwidth
, iheight
, ileft
, iwidth
, twidth
, tiheight
;
49 if (TWEAK_WineLook
>= WIN95_LOOK
) {
50 NONCLIENTMETRICSA nclm
;
51 nclm
.cbSize
= sizeof(NONCLIENTMETRICSA
);
52 SystemParametersInfoA (SPI_GETNONCLIENTMETRICS
, 0, &nclm
, 0);
53 hFont
= CreateFontIndirectA (&nclm
.lfMessageFont
);
56 SendDlgItemMessageA (hwnd
, i
, WM_SETFONT
, (WPARAM
)hFont
, 0);
58 SendDlgItemMessageA (hwnd
, MSGBOX_IDTEXT
, WM_SETFONT
, (WPARAM
)hFont
, 0);
60 if (HIWORD(lpmb
->lpszCaption
)) {
61 SetWindowTextA(hwnd
, lpmb
->lpszCaption
);
63 if (LoadStringA(lpmb
->hInstance
, LOWORD(lpmb
->lpszCaption
), buf
, sizeof(buf
)))
64 SetWindowTextA(hwnd
, buf
);
66 if (HIWORD(lpmb
->lpszText
)) {
67 lpszText
= lpmb
->lpszText
;
70 if (!LoadStringA(lpmb
->hInstance
, LOWORD(lpmb
->lpszText
), buf
, sizeof(buf
)))
71 *buf
= 0; /* FIXME ?? */
73 SetWindowTextA(GetDlgItem(hwnd
, MSGBOX_IDTEXT
), lpszText
);
75 /* Hide not selected buttons */
76 switch(lpmb
->dwStyle
& MB_TYPEMASK
) {
78 ShowWindow(GetDlgItem(hwnd
, IDCANCEL
), SW_HIDE
);
81 ShowWindow(GetDlgItem(hwnd
, IDABORT
), SW_HIDE
);
82 ShowWindow(GetDlgItem(hwnd
, IDRETRY
), SW_HIDE
);
83 ShowWindow(GetDlgItem(hwnd
, IDIGNORE
), SW_HIDE
);
84 ShowWindow(GetDlgItem(hwnd
, IDYES
), SW_HIDE
);
85 ShowWindow(GetDlgItem(hwnd
, IDNO
), SW_HIDE
);
87 case MB_ABORTRETRYIGNORE
:
88 ShowWindow(GetDlgItem(hwnd
, IDOK
), SW_HIDE
);
89 ShowWindow(GetDlgItem(hwnd
, IDCANCEL
), SW_HIDE
);
90 ShowWindow(GetDlgItem(hwnd
, IDYES
), SW_HIDE
);
91 ShowWindow(GetDlgItem(hwnd
, IDNO
), SW_HIDE
);
94 ShowWindow(GetDlgItem(hwnd
, IDCANCEL
), SW_HIDE
);
97 ShowWindow(GetDlgItem(hwnd
, IDOK
), SW_HIDE
);
98 ShowWindow(GetDlgItem(hwnd
, IDABORT
), SW_HIDE
);
99 ShowWindow(GetDlgItem(hwnd
, IDRETRY
), SW_HIDE
);
100 ShowWindow(GetDlgItem(hwnd
, IDIGNORE
), SW_HIDE
);
103 ShowWindow(GetDlgItem(hwnd
, IDOK
), SW_HIDE
);
104 ShowWindow(GetDlgItem(hwnd
, IDABORT
), SW_HIDE
);
105 ShowWindow(GetDlgItem(hwnd
, IDIGNORE
), SW_HIDE
);
106 ShowWindow(GetDlgItem(hwnd
, IDYES
), SW_HIDE
);
107 ShowWindow(GetDlgItem(hwnd
, IDNO
), SW_HIDE
);
111 switch(lpmb
->dwStyle
& MB_ICONMASK
) {
112 case MB_ICONEXCLAMATION
:
113 SendDlgItemMessageA(hwnd
, stc1
, STM_SETICON
, LoadIconA(0, IDI_EXCLAMATIONA
), 0);
115 case MB_ICONQUESTION
:
116 SendDlgItemMessageA(hwnd
, stc1
, STM_SETICON
, LoadIconA(0, IDI_QUESTIONA
), 0);
118 case MB_ICONASTERISK
:
119 SendDlgItemMessageA(hwnd
, stc1
, STM_SETICON
, LoadIconA(0, IDI_ASTERISKA
), 0);
122 SendDlgItemMessageA(hwnd
, stc1
, STM_SETICON
, LoadIconA(0, IDI_HANDA
), 0);
125 /* By default, Windows 95/98/NT do not associate an icon to message boxes.
126 * So wine should do the same.
131 /* Position everything */
132 GetWindowRect(hwnd
, &rect
);
133 borheight
= rect
.bottom
- rect
.top
;
134 borwidth
= rect
.right
- rect
.left
;
135 GetClientRect(hwnd
, &rect
);
136 borheight
-= rect
.bottom
- rect
.top
;
137 borwidth
-= rect
.right
- rect
.left
;
139 /* Get the icon height */
140 GetWindowRect(GetDlgItem(hwnd
, MSGBOX_IDICON
), &rect
);
141 MapWindowPoints(0, hwnd
, (LPPOINT
)&rect
, 2);
142 iheight
= rect
.bottom
- rect
.top
;
144 iwidth
= rect
.right
- ileft
;
148 hPrevFont
= SelectObject(hdc
, hFont
);
150 /* Get the number of visible buttons and their size */
151 bh
= bw
= 1; /* Minimum button sizes */
152 for (buttons
= 0, i
= 1; i
< 8; i
++)
154 hItem
= GetDlgItem(hwnd
, i
);
155 if (GetWindowLongA(hItem
, GWL_STYLE
) & WS_VISIBLE
)
157 char buttonText
[1024];
160 if (GetWindowTextA(hItem
, buttonText
, sizeof buttonText
))
162 DrawTextA( hdc
, buttonText
, -1, &rect
, DT_LEFT
| DT_EXPANDTABS
| DT_CALCRECT
);
163 h
= rect
.bottom
- rect
.top
;
164 w
= rect
.right
- rect
.left
;
170 bw
= max(bw
, bh
* 2);
171 /* Button white space */
174 bspace
= bw
/3; /* Space between buttons */
176 /* Get the text size */
177 GetClientRect(GetDlgItem(hwnd
, MSGBOX_IDTEXT
), &rect
);
178 rect
.top
= rect
.left
= rect
.bottom
= 0;
179 DrawTextA( hdc
, lpszText
, -1, &rect
,
180 DT_LEFT
| DT_EXPANDTABS
| DT_WORDBREAK
| DT_CALCRECT
);
181 /* Min text width corresponds to space for the buttons */
182 tleft
= 2 * ileft
+ iwidth
;
183 twidth
= max((bw
+ bspace
) * buttons
+ bspace
- tleft
, rect
.right
);
184 theight
= rect
.bottom
;
187 SelectObject(hdc
, hPrevFont
);
188 ReleaseDC(hItem
, hdc
);
190 tiheight
= 16 + max(iheight
, theight
);
191 wwidth
= tleft
+ twidth
+ ileft
+ borwidth
;
192 wheight
= 8 + tiheight
+ bh
+ borheight
;
194 /* Resize the window */
195 SetWindowPos(hwnd
, 0, 0, 0, wwidth
, wheight
,
196 SWP_NOMOVE
| SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_NOREDRAW
);
198 /* Position the icon */
199 SetWindowPos(GetDlgItem(hwnd
, MSGBOX_IDICON
), 0, ileft
, (tiheight
- iheight
) / 2, 0, 0,
200 SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_NOREDRAW
);
202 /* Position the text */
203 SetWindowPos(GetDlgItem(hwnd
, MSGBOX_IDTEXT
), 0, tleft
, (tiheight
- theight
) / 2, twidth
, theight
,
204 SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_NOREDRAW
);
206 /* Position the buttons */
207 bpos
= (wwidth
- (bw
+ bspace
) * buttons
+ bspace
) / 2;
208 for (buttons
= i
= 0; i
< 7; i
++) {
209 /* some arithmetic to get the right order for YesNoCancel windows */
210 hItem
= GetDlgItem(hwnd
, (i
+ 5) % 7 + 1);
211 if (GetWindowLongA(hItem
, GWL_STYLE
) & WS_VISIBLE
) {
212 if (buttons
++ == ((lpmb
->dwStyle
& MB_DEFMASK
) >> 8)) {
214 SendMessageA( hItem
, BM_SETSTYLE
, BS_DEFPUSHBUTTON
, TRUE
);
216 SetWindowPos(hItem
, 0, bpos
, tiheight
, bw
, bh
,
217 SWP_NOZORDER
|SWP_NOACTIVATE
|SWP_NOREDRAW
);
222 /* handle modal MessageBoxes */
223 if (lpmb
->dwStyle
& (MB_TASKMODAL
|MB_SYSTEMMODAL
))
225 FIXME("%s modal msgbox ! Not modal yet.\n",
226 lpmb
->dwStyle
& MB_TASKMODAL
? "task" : "system");
227 /* Probably do EnumTaskWindows etc. here for TASKMODAL
228 * and work your way up to the top - I'm lazy (HWND_TOP) */
229 SetWindowPos(hwnd
, HWND_TOP
, 0, 0, 0, 0,
230 SWP_NOSIZE
| SWP_NOMOVE
);
231 if (lpmb
->dwStyle
& MB_TASKMODAL
)
232 /* at least MB_TASKMODAL seems to imply a ShowWindow */
233 ShowWindow(hwnd
, SW_SHOW
);
235 if (lpmb
->dwStyle
& MB_APPLMODAL
)
236 FIXME("app modal msgbox ! Not modal yet.\n");
242 /**************************************************************************
245 * Dialog procedure for message boxes.
247 static LRESULT CALLBACK
MSGBOX_DlgProc( HWND hwnd
, UINT message
,
248 WPARAM wParam
, LPARAM lParam
)
253 hFont
= MSGBOX_OnInit(hwnd
, (LPMSGBOXPARAMSA
)lParam
);
266 EndDialog(hwnd
, wParam
);
273 /* Ok. Ignore all the other messages */
274 TRACE("Message number 0x%04x is being ignored.\n", message
);
281 /**************************************************************************
282 * MessageBoxA (USER32.@)
285 * The WARN is here to help debug erroneous MessageBoxes
286 * Use: -debugmsg warn+dialog,+relay
288 INT WINAPI
MessageBoxA(HWND hWnd
, LPCSTR text
, LPCSTR title
, UINT type
)
294 WARN("Messagebox\n");
296 if(!(hRes
= FindResourceA(GetModuleHandleA("USER32"), "MSGBOX", RT_DIALOGA
)))
298 if(!(template = (LPVOID
)LoadResource(GetModuleHandleA("USER32"), hRes
)))
301 if (!text
) text
="<WINE-NULL>";
304 mbox
.lpszCaption
= title
;
305 mbox
.lpszText
= text
;
307 return DialogBoxIndirectParamA( GetWindowLongA(hWnd
,GWL_HINSTANCE
), template,
308 hWnd
, (DLGPROC
)MSGBOX_DlgProc
, (LPARAM
)&mbox
);
312 /**************************************************************************
313 * MessageBoxW (USER32.@)
315 INT WINAPI
MessageBoxW( HWND hwnd
, LPCWSTR text
, LPCWSTR title
,
318 LPSTR titleA
= HEAP_strdupWtoA( GetProcessHeap(), 0, title
);
319 LPSTR textA
= HEAP_strdupWtoA( GetProcessHeap(), 0, text
);
322 WARN("Messagebox\n");
324 ret
= MessageBoxA( hwnd
, textA
, titleA
, type
);
325 HeapFree( GetProcessHeap(), 0, titleA
);
326 HeapFree( GetProcessHeap(), 0, textA
);
331 /**************************************************************************
332 * MessageBoxExA (USER32.@)
334 INT WINAPI
MessageBoxExA( HWND hWnd
, LPCSTR text
, LPCSTR title
,
335 UINT type
, WORD langid
)
337 WARN("Messagebox\n");
338 /* ignore language id for now */
339 return MessageBoxA(hWnd
,text
,title
,type
);
342 /**************************************************************************
343 * MessageBoxExW (USER32.@)
345 INT WINAPI
MessageBoxExW( HWND hWnd
, LPCWSTR text
, LPCWSTR title
,
346 UINT type
, WORD langid
)
348 WARN("Messagebox\n");
349 /* ignore language id for now */
350 return MessageBoxW(hWnd
,text
,title
,type
);
353 /**************************************************************************
354 * MessageBoxIndirectA (USER32.@)
356 INT WINAPI
MessageBoxIndirectA( LPMSGBOXPARAMSA msgbox
)
361 WARN("Messagebox\n");
363 if(!(hRes
= FindResourceA(GetModuleHandleA("USER32"), "MSGBOX", RT_DIALOGA
)))
365 if(!(template = (LPVOID
)LoadResource(GetModuleHandleA("USER32"), hRes
)))
368 return DialogBoxIndirectParamA( msgbox
->hInstance
, template,
369 msgbox
->hwndOwner
, (DLGPROC
)MSGBOX_DlgProc
,
373 /**************************************************************************
374 * MessageBoxIndirectW (USER32.@)
376 INT WINAPI
MessageBoxIndirectW( LPMSGBOXPARAMSW msgbox
)
378 MSGBOXPARAMSA msgboxa
;
379 memcpy(&msgboxa
,msgbox
,sizeof(msgboxa
));
380 msgboxa
.lpszCaption
= HEAP_strdupWtoA( GetProcessHeap(), 0, msgbox
->lpszCaption
);
381 msgboxa
.lpszText
= HEAP_strdupWtoA( GetProcessHeap(), 0, msgbox
->lpszText
);
382 msgboxa
.lpszIcon
= HEAP_strdupWtoA( GetProcessHeap(), 0, msgbox
->lpszIcon
);
383 return MessageBoxIndirectA(&msgboxa
);