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);
208 /* handle modal MessageBoxes */
209 if (lpmb->dwStyle & (MB_TASKMODAL|MB_SYSTEMMODAL))
211 FIXME("%s modal msgbox ! Not modal yet.\n",
212 lpmb->dwStyle & MB_TASKMODAL ? "task" : "system");
213 /* Probably do EnumTaskWindows etc. here for TASKMODAL
214 * and work your way up to the top - I'm lazy (HWND_TOP) */
215 SetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0,
216 SWP_NOSIZE | SWP_NOMOVE);
217 if (lpmb->dwStyle & MB_TASKMODAL)
218 /* at least MB_TASKMODAL seems to imply a ShowWindow */
219 ShowWindow(hwnd, SW_SHOW);
221 if (lpmb->dwStyle & MB_APPLMODAL)
222 FIXME("app modal msgbox ! Not modal yet.\n");
228 /**************************************************************************
231 * Dialog procedure for message boxes.
233 static LRESULT CALLBACK MSGBOX_DlgProc( HWND hwnd, UINT message,
234 WPARAM wParam, LPARAM lParam )
239 hFont = MSGBOX_OnInit(hwnd, (LPMSGBOXPARAMSA)lParam);
252 EndDialog(hwnd, wParam);
259 /* Ok. Ignore all the other messages */
260 TRACE("Message number 0x%04x is being ignored.\n", message);
267 /**************************************************************************
268 * MessageBoxA (USER32.@)
271 * The WARN is here to help debug erroneous MessageBoxes
272 * Use: -debugmsg warn+dialog,+relay
274 INT WINAPI MessageBoxA(HWND hWnd, LPCSTR text, LPCSTR title, UINT type)
280 WARN("Messagebox\n");
282 if(!(hRes = FindResourceA(GetModuleHandleA("USER32"), "MSGBOX", RT_DIALOGA)))
284 if(!(template = (LPVOID)LoadResource(GetModuleHandleA("USER32"), hRes)))
287 if (!text) text="<WINE-NULL>";
290 mbox.lpszCaption = title;
291 mbox.lpszText = text;
293 return DialogBoxIndirectParamA( GetWindowLongA(hWnd,GWL_HINSTANCE), template,
294 hWnd, (DLGPROC)MSGBOX_DlgProc, (LPARAM)&mbox );
298 /**************************************************************************
299 * MessageBoxW (USER32.@)
301 INT WINAPI MessageBoxW( HWND hwnd, LPCWSTR text, LPCWSTR title,
304 LPSTR titleA = HEAP_strdupWtoA( GetProcessHeap(), 0, title );
305 LPSTR textA = HEAP_strdupWtoA( GetProcessHeap(), 0, text );
308 WARN("Messagebox\n");
310 ret = MessageBoxA( hwnd, textA, titleA, type );
311 HeapFree( GetProcessHeap(), 0, titleA );
312 HeapFree( GetProcessHeap(), 0, textA );
317 /**************************************************************************
318 * MessageBoxExA (USER32.@)
320 INT WINAPI MessageBoxExA( HWND hWnd, LPCSTR text, LPCSTR title,
321 UINT type, WORD langid )
323 WARN("Messagebox\n");
324 /* ignore language id for now */
325 return MessageBoxA(hWnd,text,title,type);
328 /**************************************************************************
329 * MessageBoxExW (USER32.@)
331 INT WINAPI MessageBoxExW( HWND hWnd, LPCWSTR text, LPCWSTR title,
332 UINT type, WORD langid )
334 WARN("Messagebox\n");
335 /* ignore language id for now */
336 return MessageBoxW(hWnd,text,title,type);
339 /**************************************************************************
340 * MessageBoxIndirectA (USER32.@)
342 INT WINAPI MessageBoxIndirectA( LPMSGBOXPARAMSA msgbox )
347 WARN("Messagebox\n");
349 if(!(hRes = FindResourceA(GetModuleHandleA("USER32"), "MSGBOX", RT_DIALOGA)))
351 if(!(template = (LPVOID)LoadResource(GetModuleHandleA("USER32"), hRes)))
354 return DialogBoxIndirectParamA( msgbox->hInstance, template,
355 msgbox->hwndOwner, (DLGPROC)MSGBOX_DlgProc,
359 /**************************************************************************
360 * MessageBoxIndirectW (USER32.@)
362 INT WINAPI MessageBoxIndirectW( LPMSGBOXPARAMSW msgbox )
364 MSGBOXPARAMSA msgboxa;
365 memcpy(&msgboxa,msgbox,sizeof(msgboxa));
366 msgboxa.lpszCaption = HEAP_strdupWtoA( GetProcessHeap(), 0, msgbox->lpszCaption );
367 msgboxa.lpszText = HEAP_strdupWtoA( GetProcessHeap(), 0, msgbox->lpszText );
368 msgboxa.lpszIcon = HEAP_strdupWtoA( GetProcessHeap(), 0, msgbox->lpszIcon );
369 return MessageBoxIndirectA(&msgboxa);