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 SendDlgItemMessageA(hwnd, stc1, STM_SETICON, LoadIconA(0, IDI_EXCLAMATIONA), 0);
102 case MB_ICONQUESTION:
103 SendDlgItemMessageA(hwnd, stc1, STM_SETICON, LoadIconA(0, IDI_QUESTIONA), 0);
105 case MB_ICONASTERISK:
106 SendDlgItemMessageA(hwnd, stc1, STM_SETICON, LoadIconA(0, IDI_ASTERISKA), 0);
109 SendDlgItemMessageA(hwnd, stc1, STM_SETICON, LoadIconA(0, IDI_HANDA), 0);
112 /* By default, Windows 95/98/NT do not associate an icon to message boxes.
113 * So wine should do the same.
118 /* Position everything */
119 GetWindowRect(hwnd, &rect);
120 borheight = rect.bottom - rect.top;
121 borwidth = rect.right - rect.left;
122 GetClientRect(hwnd, &rect);
123 borheight -= rect.bottom - rect.top;
124 borwidth -= rect.right - rect.left;
126 /* Get the icon height */
127 GetWindowRect(GetDlgItem(hwnd, MSGBOX_IDICON), &rect);
128 MapWindowPoints(0, hwnd, (LPPOINT)&rect, 2);
129 iheight = rect.bottom - rect.top;
131 iwidth = rect.right - ileft;
135 hPrevFont = SelectObject(hdc, hFont);
137 /* Get the number of visible buttons and their size */
138 bh = bw = 1; /* Minimum button sizes */
139 for (buttons = 0, i = 1; i < 8; i++)
141 hItem = GetDlgItem(hwnd, i);
142 if (GetWindowLongA(hItem, GWL_STYLE) & WS_VISIBLE)
144 char buttonText[1024];
147 if (GetWindowTextA(hItem, buttonText, sizeof buttonText))
149 DrawTextA( hdc, buttonText, -1, &rect, DT_LEFT | DT_EXPANDTABS | DT_CALCRECT);
150 h = rect.bottom - rect.top;
151 w = rect.right - rect.left;
157 bw = max(bw, bh * 2);
158 /* Button white space */
161 bspace = bw/3; /* Space between buttons */
163 /* Get the text size */
164 GetClientRect(GetDlgItem(hwnd, MSGBOX_IDTEXT), &rect);
165 rect.top = rect.left = rect.bottom = 0;
166 DrawTextA( hdc, lpszText, -1, &rect,
167 DT_LEFT | DT_EXPANDTABS | DT_WORDBREAK | DT_CALCRECT);
168 /* Min text width corresponds to space for the buttons */
169 tleft = 2 * ileft + iwidth;
170 twidth = max((bw + bspace) * buttons + bspace - tleft, rect.right);
171 theight = rect.bottom;
174 SelectObject(hdc, hPrevFont);
175 ReleaseDC(hItem, hdc);
177 tiheight = 16 + max(iheight, theight);
178 wwidth = tleft + twidth + ileft + borwidth;
179 wheight = 8 + tiheight + bh + borheight;
181 /* Resize the window */
182 SetWindowPos(hwnd, 0, 0, 0, wwidth, wheight,
183 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOREDRAW);
185 /* Position the icon */
186 SetWindowPos(GetDlgItem(hwnd, MSGBOX_IDICON), 0, ileft, (tiheight - iheight) / 2, 0, 0,
187 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOREDRAW);
189 /* Position the text */
190 SetWindowPos(GetDlgItem(hwnd, MSGBOX_IDTEXT), 0, tleft, (tiheight - theight) / 2, twidth, theight,
191 SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOREDRAW);
193 /* Position the buttons */
194 bpos = (wwidth - (bw + bspace) * buttons + bspace) / 2;
195 for (buttons = i = 0; i < 7; i++) {
196 /* some arithmetic to get the right order for YesNoCancel windows */
197 hItem = GetDlgItem(hwnd, (i + 5) % 7 + 1);
198 if (GetWindowLongA(hItem, GWL_STYLE) & WS_VISIBLE) {
199 if (buttons++ == ((lpmb->dwStyle & MB_DEFMASK) >> 8)) {
201 SendMessageA( hItem, BM_SETSTYLE, BS_DEFPUSHBUTTON, TRUE );
203 SetWindowPos(hItem, 0, bpos, tiheight, bw, bh,
204 SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOREDRAW);
212 /**************************************************************************
215 * Dialog procedure for message boxes.
217 static LRESULT CALLBACK MSGBOX_DlgProc( HWND hwnd, UINT message,
218 WPARAM wParam, LPARAM lParam )
223 hFont = MSGBOX_OnInit(hwnd, (LPMSGBOXPARAMSA)lParam);
236 EndDialog(hwnd, wParam);
243 /* Ok. Ignore all the other messages */
244 TRACE("Message number %i is being ignored.\n", message);
251 /**************************************************************************
252 * MessageBox16 (USER.1)
254 INT16 WINAPI MessageBox16( HWND16 hwnd, LPCSTR text, LPCSTR title, UINT16 type)
256 WARN("Messagebox\n");
257 return MessageBoxA( hwnd, text, title, type );
261 /**************************************************************************
262 * MessageBoxA (USER32.391)
265 * The WARN is here to help debug erroneous MessageBoxes
266 * Use: -debugmsg warn+dialog,+relay
268 INT WINAPI MessageBoxA(HWND hWnd, LPCSTR text, LPCSTR title, UINT type)
274 WARN("Messagebox\n");
276 if(!(hRes = FindResourceA(GetModuleHandleA("USER32"), "MSGBOX", RT_DIALOGA)))
278 if(!(template = (LPVOID)LoadResource(GetModuleHandleA("USER32"), hRes)))
281 if (!text) text="<WINE-NULL>";
284 mbox.lpszCaption = title;
285 mbox.lpszText = text;
287 return DialogBoxIndirectParamA( GetWindowLongA(hWnd,GWL_HINSTANCE), template,
288 hWnd, (DLGPROC)MSGBOX_DlgProc, (LPARAM)&mbox );
292 /**************************************************************************
293 * MessageBoxW (USER32.396)
295 INT WINAPI MessageBoxW( HWND hwnd, LPCWSTR text, LPCWSTR title,
298 LPSTR titleA = HEAP_strdupWtoA( GetProcessHeap(), 0, title );
299 LPSTR textA = HEAP_strdupWtoA( GetProcessHeap(), 0, text );
302 WARN("Messagebox\n");
304 ret = MessageBoxA( hwnd, textA, titleA, type );
305 HeapFree( GetProcessHeap(), 0, titleA );
306 HeapFree( GetProcessHeap(), 0, textA );
311 /**************************************************************************
312 * MessageBoxExA (USER32.392)
314 INT WINAPI MessageBoxExA( HWND hWnd, LPCSTR text, LPCSTR title,
315 UINT type, WORD langid )
317 WARN("Messagebox\n");
318 /* ignore language id for now */
319 return MessageBoxA(hWnd,text,title,type);
322 /**************************************************************************
323 * MessageBoxExW (USER32.393)
325 INT WINAPI MessageBoxExW( HWND hWnd, LPCWSTR text, LPCWSTR title,
326 UINT type, WORD langid )
328 WARN("Messagebox\n");
329 /* ignore language id for now */
330 return MessageBoxW(hWnd,text,title,type);
333 /**************************************************************************
334 * MessageBoxIndirect16 (USER.827)
336 INT16 WINAPI MessageBoxIndirect16( LPMSGBOXPARAMS16 msgbox )
340 MSGBOXPARAMSA msgbox32;
342 WARN("Messagebox\n");
344 if(!(hRes = FindResourceA(GetModuleHandleA("USER32"), "MSGBOX", RT_DIALOGA)))
346 if(!(template = (LPVOID)LoadResource(GetModuleHandleA("USER32"), hRes)))
349 msgbox32.cbSize = msgbox->cbSize;
350 msgbox32.hwndOwner = msgbox->hwndOwner;
351 msgbox32.hInstance = msgbox->hInstance;
352 msgbox32.lpszText = PTR_SEG_TO_LIN(msgbox->lpszText);
353 msgbox32.lpszCaption = PTR_SEG_TO_LIN(msgbox->lpszCaption);
354 msgbox32.dwStyle = msgbox->dwStyle;
355 msgbox32.lpszIcon = PTR_SEG_TO_LIN(msgbox->lpszIcon);
356 msgbox32.dwContextHelpId = msgbox->dwContextHelpId;
357 msgbox32.lpfnMsgBoxCallback = msgbox->lpfnMsgBoxCallback;
358 msgbox32.dwLanguageId = msgbox->dwLanguageId;
360 return DialogBoxIndirectParamA( msgbox32.hInstance, template,
361 msgbox32.hwndOwner, (DLGPROC)MSGBOX_DlgProc,
365 /**************************************************************************
366 * MessageBoxIndirectA (USER32.394)
368 INT WINAPI MessageBoxIndirectA( LPMSGBOXPARAMSA msgbox )
373 WARN("Messagebox\n");
375 if(!(hRes = FindResourceA(GetModuleHandleA("USER32"), "MSGBOX", RT_DIALOGA)))
377 if(!(template = (LPVOID)LoadResource(GetModuleHandleA("USER32"), hRes)))
380 return DialogBoxIndirectParamA( msgbox->hInstance, template,
381 msgbox->hwndOwner, (DLGPROC)MSGBOX_DlgProc,
385 /**************************************************************************
386 * MessageBoxIndirectW (USER32.395)
388 INT WINAPI MessageBoxIndirectW( LPMSGBOXPARAMSW msgbox )
390 MSGBOXPARAMSA msgboxa;
391 memcpy(&msgboxa,msgbox,sizeof(msgboxa));
392 msgboxa.lpszCaption = HEAP_strdupWtoA( GetProcessHeap(), 0, msgbox->lpszCaption );
393 msgboxa.lpszText = HEAP_strdupWtoA( GetProcessHeap(), 0, msgbox->lpszText );
394 msgboxa.lpszIcon = HEAP_strdupWtoA( GetProcessHeap(), 0, msgbox->lpszIcon );
395 return MessageBoxIndirectA(&msgboxa);