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 * MessageBox (USER.1)
270 INT16 WINAPI MessageBox16( HWND16 hwnd, LPCSTR text, LPCSTR title, UINT16 type)
272 WARN("Messagebox\n");
273 return MessageBoxA( hwnd, text, title, type );
277 /**************************************************************************
278 * MessageBoxA (USER32.@)
281 * The WARN is here to help debug erroneous MessageBoxes
282 * Use: -debugmsg warn+dialog,+relay
284 INT WINAPI MessageBoxA(HWND hWnd, LPCSTR text, LPCSTR title, UINT type)
290 WARN("Messagebox\n");
292 if(!(hRes = FindResourceA(GetModuleHandleA("USER32"), "MSGBOX", RT_DIALOGA)))
294 if(!(template = (LPVOID)LoadResource(GetModuleHandleA("USER32"), hRes)))
297 if (!text) text="<WINE-NULL>";
300 mbox.lpszCaption = title;
301 mbox.lpszText = text;
303 return DialogBoxIndirectParamA( GetWindowLongA(hWnd,GWL_HINSTANCE), template,
304 hWnd, (DLGPROC)MSGBOX_DlgProc, (LPARAM)&mbox );
308 /**************************************************************************
309 * MessageBoxW (USER32.@)
311 INT WINAPI MessageBoxW( HWND hwnd, LPCWSTR text, LPCWSTR title,
314 LPSTR titleA = HEAP_strdupWtoA( GetProcessHeap(), 0, title );
315 LPSTR textA = HEAP_strdupWtoA( GetProcessHeap(), 0, text );
318 WARN("Messagebox\n");
320 ret = MessageBoxA( hwnd, textA, titleA, type );
321 HeapFree( GetProcessHeap(), 0, titleA );
322 HeapFree( GetProcessHeap(), 0, textA );
327 /**************************************************************************
328 * MessageBoxExA (USER32.@)
330 INT WINAPI MessageBoxExA( HWND hWnd, LPCSTR text, LPCSTR title,
331 UINT type, WORD langid )
333 WARN("Messagebox\n");
334 /* ignore language id for now */
335 return MessageBoxA(hWnd,text,title,type);
338 /**************************************************************************
339 * MessageBoxExW (USER32.@)
341 INT WINAPI MessageBoxExW( HWND hWnd, LPCWSTR text, LPCWSTR title,
342 UINT type, WORD langid )
344 WARN("Messagebox\n");
345 /* ignore language id for now */
346 return MessageBoxW(hWnd,text,title,type);
349 /**************************************************************************
350 * MessageBoxIndirect (USER.827)
352 INT16 WINAPI MessageBoxIndirect16( LPMSGBOXPARAMS16 msgbox )
356 MSGBOXPARAMSA msgbox32;
358 WARN("Messagebox\n");
360 if(!(hRes = FindResourceA(GetModuleHandleA("USER32"), "MSGBOX", RT_DIALOGA)))
362 if(!(template = (LPVOID)LoadResource(GetModuleHandleA("USER32"), hRes)))
365 msgbox32.cbSize = msgbox->cbSize;
366 msgbox32.hwndOwner = msgbox->hwndOwner;
367 msgbox32.hInstance = msgbox->hInstance;
368 msgbox32.lpszText = MapSL(msgbox->lpszText);
369 msgbox32.lpszCaption = MapSL(msgbox->lpszCaption);
370 msgbox32.dwStyle = msgbox->dwStyle;
371 msgbox32.lpszIcon = MapSL(msgbox->lpszIcon);
372 msgbox32.dwContextHelpId = msgbox->dwContextHelpId;
373 msgbox32.lpfnMsgBoxCallback = msgbox->lpfnMsgBoxCallback;
374 msgbox32.dwLanguageId = msgbox->dwLanguageId;
376 return DialogBoxIndirectParamA( msgbox32.hInstance, template,
377 msgbox32.hwndOwner, (DLGPROC)MSGBOX_DlgProc,
381 /**************************************************************************
382 * MessageBoxIndirectA (USER32.@)
384 INT WINAPI MessageBoxIndirectA( LPMSGBOXPARAMSA msgbox )
389 WARN("Messagebox\n");
391 if(!(hRes = FindResourceA(GetModuleHandleA("USER32"), "MSGBOX", RT_DIALOGA)))
393 if(!(template = (LPVOID)LoadResource(GetModuleHandleA("USER32"), hRes)))
396 return DialogBoxIndirectParamA( msgbox->hInstance, template,
397 msgbox->hwndOwner, (DLGPROC)MSGBOX_DlgProc,
401 /**************************************************************************
402 * MessageBoxIndirectW (USER32.@)
404 INT WINAPI MessageBoxIndirectW( LPMSGBOXPARAMSW msgbox )
406 MSGBOXPARAMSA msgboxa;
407 memcpy(&msgboxa,msgbox,sizeof(msgboxa));
408 msgboxa.lpszCaption = HEAP_strdupWtoA( GetProcessHeap(), 0, msgbox->lpszCaption );
409 msgboxa.lpszText = HEAP_strdupWtoA( GetProcessHeap(), 0, msgbox->lpszText );
410 msgboxa.lpszIcon = HEAP_strdupWtoA( GetProcessHeap(), 0, msgbox->lpszIcon );
411 return MessageBoxIndirectA(&msgboxa);