4 * Copyright 1995 Bernd Schmidt
11 #include "wine/winbase16.h"
12 #include "wine/winuser16.h"
16 #include "debugtools.h"
19 DEFAULT_DEBUG_CHANNEL(dialog)
21 #define MSGBOX_IDICON 1088
22 #define MSGBOX_IDTEXT 100
24 static HFONT MSGBOX_OnInit(HWND hwnd, LPMSGBOXPARAMSA lpmb)
26 static HFONT hFont = 0, hPrevFont = 0;
31 int bspace, bw, bh, theight, tleft, wwidth, wheight, bpos;
32 int borheight, borwidth, iheight, ileft, iwidth, twidth, tiheight;
36 if (TWEAK_WineLook >= WIN95_LOOK) {
37 NONCLIENTMETRICSA nclm;
38 nclm.cbSize = sizeof(NONCLIENTMETRICSA);
39 SystemParametersInfoA (SPI_GETNONCLIENTMETRICS, 0, &nclm, 0);
40 hFont = CreateFontIndirectA (&nclm.lfMessageFont);
43 SendDlgItemMessageA (hwnd, i, WM_SETFONT, (WPARAM)hFont, 0);
45 SendDlgItemMessageA (hwnd, MSGBOX_IDTEXT, WM_SETFONT, (WPARAM)hFont, 0);
47 if (HIWORD(lpmb->lpszCaption)) {
48 SetWindowTextA(hwnd, lpmb->lpszCaption);
50 if (LoadStringA(lpmb->hInstance, LOWORD(lpmb->lpszCaption), buf, sizeof(buf)))
51 SetWindowTextA(hwnd, buf);
53 if (HIWORD(lpmb->lpszText)) {
54 lpszText = lpmb->lpszText;
57 if (!LoadStringA(lpmb->hInstance, LOWORD(lpmb->lpszText), buf, sizeof(buf)))
58 *buf = 0; /* FIXME ?? */
60 SetWindowTextA(GetDlgItem(hwnd, MSGBOX_IDTEXT), lpszText);
62 /* Hide not selected buttons */
63 switch(lpmb->dwStyle & MB_TYPEMASK) {
65 ShowWindow(GetDlgItem(hwnd, IDCANCEL), SW_HIDE);
68 ShowWindow(GetDlgItem(hwnd, IDABORT), SW_HIDE);
69 ShowWindow(GetDlgItem(hwnd, IDRETRY), SW_HIDE);
70 ShowWindow(GetDlgItem(hwnd, IDIGNORE), SW_HIDE);
71 ShowWindow(GetDlgItem(hwnd, IDYES), SW_HIDE);
72 ShowWindow(GetDlgItem(hwnd, IDNO), SW_HIDE);
74 case MB_ABORTRETRYIGNORE:
75 ShowWindow(GetDlgItem(hwnd, IDOK), SW_HIDE);
76 ShowWindow(GetDlgItem(hwnd, IDCANCEL), SW_HIDE);
77 ShowWindow(GetDlgItem(hwnd, IDYES), SW_HIDE);
78 ShowWindow(GetDlgItem(hwnd, IDNO), SW_HIDE);
81 ShowWindow(GetDlgItem(hwnd, IDCANCEL), SW_HIDE);
84 ShowWindow(GetDlgItem(hwnd, IDOK), SW_HIDE);
85 ShowWindow(GetDlgItem(hwnd, IDABORT), SW_HIDE);
86 ShowWindow(GetDlgItem(hwnd, IDRETRY), SW_HIDE);
87 ShowWindow(GetDlgItem(hwnd, IDIGNORE), SW_HIDE);
90 ShowWindow(GetDlgItem(hwnd, IDOK), SW_HIDE);
91 ShowWindow(GetDlgItem(hwnd, IDABORT), SW_HIDE);
92 ShowWindow(GetDlgItem(hwnd, IDIGNORE), SW_HIDE);
93 ShowWindow(GetDlgItem(hwnd, IDYES), SW_HIDE);
94 ShowWindow(GetDlgItem(hwnd, IDNO), SW_HIDE);
98 switch(lpmb->dwStyle & MB_ICONMASK) {
99 case MB_ICONEXCLAMATION:
100 SendDlgItemMessage16(hwnd, stc1, STM_SETICON16,
101 (WPARAM16)LoadIcon16(0, IDI_EXCLAMATION16), 0);
103 case MB_ICONQUESTION:
104 SendDlgItemMessage16(hwnd, stc1, STM_SETICON16,
105 (WPARAM16)LoadIcon16(0, IDI_QUESTION16), 0);
107 case MB_ICONASTERISK:
108 SendDlgItemMessage16(hwnd, stc1, STM_SETICON16,
109 (WPARAM16)LoadIcon16(0, IDI_ASTERISK16), 0);
112 SendDlgItemMessage16(hwnd, stc1, STM_SETICON16,
113 (WPARAM16)LoadIcon16(0, IDI_HAND16), 0);
116 /* By default, Windows 95/98/NT do not associate an icon to message boxes.
117 * So wine should do the same.
122 /* Position everything */
123 GetWindowRect(hwnd, &rect);
124 borheight = rect.bottom - rect.top;
125 borwidth = rect.right - rect.left;
126 GetClientRect(hwnd, &rect);
127 borheight -= rect.bottom - rect.top;
128 borwidth -= rect.right - rect.left;
130 /* Get the icon height */
131 GetWindowRect(GetDlgItem(hwnd, MSGBOX_IDICON), &rect);
132 MapWindowPoints(0, hwnd, (LPPOINT)&rect, 2);
133 iheight = rect.bottom - rect.top;
135 iwidth = rect.right - ileft;
139 hPrevFont = SelectObject(hdc, hFont);
141 /* Get the number of visible buttons and their size */
142 bh = bw = 1; /* Minimum button sizes */
143 for (buttons = 0, i = 1; i < 8; i++)
145 hItem = GetDlgItem(hwnd, i);
146 if (GetWindowLongA(hItem, GWL_STYLE) & WS_VISIBLE)
148 char buttonText[1024];
151 if (GetWindowTextA(hItem, buttonText, sizeof buttonText))
153 DrawTextA( hdc, buttonText, -1, &rect, DT_LEFT | DT_EXPANDTABS | DT_CALCRECT);
154 h = rect.bottom - rect.top;
155 w = rect.right - rect.left;
161 bw = max(bw, bh * 2);
162 /* Button white space */
165 bspace = bw/3; /* Space between buttons */
167 /* Get the text size */
168 GetClientRect(GetDlgItem(hwnd, MSGBOX_IDTEXT), &rect);
169 rect.top = rect.left = rect.bottom = 0;
170 DrawTextA( hdc, lpszText, -1, &rect,
171 DT_LEFT | DT_EXPANDTABS | DT_WORDBREAK | DT_CALCRECT);
172 /* Min text width corresponds to space for the buttons */
173 tleft = 2 * ileft + iwidth;
174 twidth = max((bw + bspace) * buttons + bspace - tleft, rect.right);
175 theight = rect.bottom;
178 SelectObject(hdc, hPrevFont);
179 ReleaseDC(hItem, hdc);
181 tiheight = 16 + max(iheight, theight);
182 wwidth = tleft + twidth + ileft + borwidth;
183 wheight = 8 + tiheight + bh + borheight;
185 /* Resize the window */
186 SetWindowPos(hwnd, 0, 0, 0, wwidth, wheight,
187 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOREDRAW);
189 /* Position the icon */
190 SetWindowPos(GetDlgItem(hwnd, MSGBOX_IDICON), 0, ileft, (tiheight - iheight) / 2, 0, 0,
191 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOREDRAW);
193 /* Position the text */
194 SetWindowPos(GetDlgItem(hwnd, MSGBOX_IDTEXT), 0, tleft, (tiheight - theight) / 2, twidth, theight,
195 SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOREDRAW);
197 /* Position the buttons */
198 bpos = (wwidth - (bw + bspace) * buttons + bspace) / 2;
199 for (buttons = i = 0; i < 7; i++) {
200 /* some arithmetic to get the right order for YesNoCancel windows */
201 hItem = GetDlgItem(hwnd, (i + 5) % 7 + 1);
202 if (GetWindowLongA(hItem, GWL_STYLE) & WS_VISIBLE) {
203 if (buttons++ == ((lpmb->dwStyle & MB_DEFMASK) >> 8)) {
205 SendMessageA( hItem, BM_SETSTYLE, BS_DEFPUSHBUTTON, TRUE );
207 SetWindowPos(hItem, 0, bpos, tiheight, bw, bh,
208 SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOREDRAW);
216 /**************************************************************************
219 * Dialog procedure for message boxes.
221 static LRESULT CALLBACK MSGBOX_DlgProc( HWND hwnd, UINT message,
222 WPARAM wParam, LPARAM lParam )
227 hFont = MSGBOX_OnInit(hwnd, (LPMSGBOXPARAMSA)lParam);
240 EndDialog(hwnd, wParam);
247 /* Ok. Ignore all the other messages */
248 TRACE("Message number %i is being ignored.\n", message);
255 /**************************************************************************
256 * MessageBox16 (USER.1)
258 INT16 WINAPI MessageBox16( HWND16 hwnd, LPCSTR text, LPCSTR title, UINT16 type)
260 WARN("Messagebox\n");
261 return MessageBoxA( hwnd, text, title, type );
265 /**************************************************************************
266 * MessageBoxA (USER32.391)
269 * The WARN is here to help debug erroneous MessageBoxes
270 * Use: -debugmsg warn+dialog,+relay
272 INT WINAPI MessageBoxA(HWND hWnd, LPCSTR text, LPCSTR title, UINT type)
278 WARN("Messagebox\n");
280 if(!(hRes = FindResourceA(GetModuleHandleA("USER32"), "MSGBOX", RT_DIALOGA)))
282 if(!(template = (LPVOID)LoadResource(GetModuleHandleA("USER32"), hRes)))
285 if (!text) text="<WINE-NULL>";
288 mbox.lpszCaption = title;
289 mbox.lpszText = text;
291 return DialogBoxIndirectParamA( GetWindowLongA(hWnd,GWL_HINSTANCE), template,
292 hWnd, (DLGPROC)MSGBOX_DlgProc, (LPARAM)&mbox );
296 /**************************************************************************
297 * MessageBoxW (USER32.396)
299 INT WINAPI MessageBoxW( HWND hwnd, LPCWSTR text, LPCWSTR title,
302 LPSTR titleA = HEAP_strdupWtoA( GetProcessHeap(), 0, title );
303 LPSTR textA = HEAP_strdupWtoA( GetProcessHeap(), 0, text );
306 WARN("Messagebox\n");
308 ret = MessageBoxA( hwnd, textA, titleA, type );
309 HeapFree( GetProcessHeap(), 0, titleA );
310 HeapFree( GetProcessHeap(), 0, textA );
315 /**************************************************************************
316 * MessageBoxExA (USER32.392)
318 INT WINAPI MessageBoxExA( HWND hWnd, LPCSTR text, LPCSTR title,
319 UINT type, WORD langid )
321 WARN("Messagebox\n");
322 /* ignore language id for now */
323 return MessageBoxA(hWnd,text,title,type);
326 /**************************************************************************
327 * MessageBoxExW (USER32.393)
329 INT WINAPI MessageBoxExW( HWND hWnd, LPCWSTR text, LPCWSTR title,
330 UINT type, WORD langid )
332 WARN("Messagebox\n");
333 /* ignore language id for now */
334 return MessageBoxW(hWnd,text,title,type);
337 /**************************************************************************
338 * MessageBoxIndirect16 (USER.827)
340 INT16 WINAPI MessageBoxIndirect16( LPMSGBOXPARAMS16 msgbox )
344 MSGBOXPARAMSA msgbox32;
346 WARN("Messagebox\n");
348 if(!(hRes = FindResourceA(GetModuleHandleA("USER32"), "MSGBOX", RT_DIALOGA)))
350 if(!(template = (LPVOID)LoadResource(GetModuleHandleA("USER32"), hRes)))
353 msgbox32.cbSize = msgbox->cbSize;
354 msgbox32.hwndOwner = msgbox->hwndOwner;
355 msgbox32.hInstance = msgbox->hInstance;
356 msgbox32.lpszText = PTR_SEG_TO_LIN(msgbox->lpszText);
357 msgbox32.lpszCaption = PTR_SEG_TO_LIN(msgbox->lpszCaption);
358 msgbox32.dwStyle = msgbox->dwStyle;
359 msgbox32.lpszIcon = PTR_SEG_TO_LIN(msgbox->lpszIcon);
360 msgbox32.dwContextHelpId = msgbox->dwContextHelpId;
361 msgbox32.lpfnMsgBoxCallback = msgbox->lpfnMsgBoxCallback;
362 msgbox32.dwLanguageId = msgbox->dwLanguageId;
364 return DialogBoxIndirectParamA( msgbox32.hInstance, template,
365 msgbox32.hwndOwner, (DLGPROC)MSGBOX_DlgProc,
369 /**************************************************************************
370 * MessageBoxIndirectA (USER32.394)
372 INT WINAPI MessageBoxIndirectA( LPMSGBOXPARAMSA msgbox )
377 WARN("Messagebox\n");
379 if(!(hRes = FindResourceA(GetModuleHandleA("USER32"), "MSGBOX", RT_DIALOGA)))
381 if(!(template = (LPVOID)LoadResource(GetModuleHandleA("USER32"), hRes)))
384 return DialogBoxIndirectParamA( msgbox->hInstance, template,
385 msgbox->hwndOwner, (DLGPROC)MSGBOX_DlgProc,
389 /**************************************************************************
390 * MessageBoxIndirectW (USER32.395)
392 INT WINAPI MessageBoxIndirectW( LPMSGBOXPARAMSW msgbox )
394 MSGBOXPARAMSA msgboxa;
395 WARN("Messagebox\n");
397 memcpy(&msgboxa,msgbox,sizeof(msgboxa));
398 if (msgbox->lpszCaption)
399 lstrcpyWtoA((LPSTR)msgboxa.lpszCaption,msgbox->lpszCaption);
400 if (msgbox->lpszText)
401 lstrcpyWtoA((LPSTR)msgboxa.lpszText,msgbox->lpszText);
403 return MessageBoxIndirectA(&msgboxa);