Authors: Chris Morgan <cmorgan@wpi.edu>, James Abbatiello <abbejy@wpi.edu>
[wine/multimedia.git] / windows / msgbox.c
blob47b2670cf889e81054efc2f6ad83c3b8e47e20ca
1 /*
2 * Message boxes
4 * Copyright 1995 Bernd Schmidt
5 */
7 #include <string.h>
8 #include "wine/winuser16.h"
9 #include "dlgs.h"
10 #include "heap.h"
11 #include "module.h"
12 #include "win.h"
13 #include "resource.h"
14 #include "task.h"
15 #include "debug.h"
16 #include "debugstr.h"
17 #include "tweak.h"
19 DEFAULT_DEBUG_CHANNEL(dialog)
21 /**************************************************************************
22 * MSGBOX_DlgProc
24 * Dialog procedure for message boxes.
26 static LRESULT CALLBACK MSGBOX_DlgProc( HWND hwnd, UINT message,
27 WPARAM wParam, LPARAM lParam )
29 static HFONT hFont = 0;
30 LPMSGBOXPARAMSA lpmb;
32 RECT rect, textrect;
33 HWND hItem;
34 HDC hdc;
35 LRESULT lRet;
36 int i, buttons, bwidth, bheight, theight, wwidth, bpos;
37 int borheight, iheight, tiheight;
39 switch(message) {
40 case WM_INITDIALOG:
41 lpmb = (LPMSGBOXPARAMSA)lParam;
42 if (TWEAK_WineLook >= WIN95_LOOK) {
43 NONCLIENTMETRICSA nclm;
44 INT i;
45 nclm.cbSize = sizeof(NONCLIENTMETRICSA);
46 SystemParametersInfoA (SPI_GETNONCLIENTMETRICS, 0, &nclm, 0);
47 hFont = CreateFontIndirectA (&nclm.lfMessageFont);
48 /* set button font */
49 for (i=1; i < 8; i++)
50 SendDlgItemMessageA (hwnd, i, WM_SETFONT, (WPARAM)hFont, 0);
51 /* set text font */
52 SendDlgItemMessageA (hwnd, 100, WM_SETFONT, (WPARAM)hFont, 0);
54 if (lpmb->lpszCaption) SetWindowTextA(hwnd, lpmb->lpszCaption);
55 SetWindowTextA(GetDlgItem(hwnd, 100), lpmb->lpszText);
56 /* Hide not selected buttons */
57 switch(lpmb->dwStyle & MB_TYPEMASK) {
58 case MB_OK:
59 ShowWindow(GetDlgItem(hwnd, 2), SW_HIDE);
60 /* fall through */
61 case MB_OKCANCEL:
62 ShowWindow(GetDlgItem(hwnd, 3), SW_HIDE);
63 ShowWindow(GetDlgItem(hwnd, 4), SW_HIDE);
64 ShowWindow(GetDlgItem(hwnd, 5), SW_HIDE);
65 ShowWindow(GetDlgItem(hwnd, 6), SW_HIDE);
66 ShowWindow(GetDlgItem(hwnd, 7), SW_HIDE);
67 break;
68 case MB_ABORTRETRYIGNORE:
69 ShowWindow(GetDlgItem(hwnd, 1), SW_HIDE);
70 ShowWindow(GetDlgItem(hwnd, 2), SW_HIDE);
71 ShowWindow(GetDlgItem(hwnd, 6), SW_HIDE);
72 ShowWindow(GetDlgItem(hwnd, 7), SW_HIDE);
73 break;
74 case MB_YESNO:
75 ShowWindow(GetDlgItem(hwnd, 2), SW_HIDE);
76 /* fall through */
77 case MB_YESNOCANCEL:
78 ShowWindow(GetDlgItem(hwnd, 1), SW_HIDE);
79 ShowWindow(GetDlgItem(hwnd, 3), SW_HIDE);
80 ShowWindow(GetDlgItem(hwnd, 4), SW_HIDE);
81 ShowWindow(GetDlgItem(hwnd, 5), SW_HIDE);
82 break;
84 /* Set the icon */
85 switch(lpmb->dwStyle & MB_ICONMASK) {
86 case MB_ICONEXCLAMATION:
87 SendDlgItemMessage16(hwnd, stc1, STM_SETICON16,
88 (WPARAM16)LoadIcon16(0, IDI_EXCLAMATION16), 0);
89 break;
90 case MB_ICONQUESTION:
91 SendDlgItemMessage16(hwnd, stc1, STM_SETICON16,
92 (WPARAM16)LoadIcon16(0, IDI_QUESTION16), 0);
93 break;
94 case MB_ICONASTERISK:
95 SendDlgItemMessage16(hwnd, stc1, STM_SETICON16,
96 (WPARAM16)LoadIcon16(0, IDI_ASTERISK16), 0);
97 break;
98 case MB_ICONHAND:
99 default:
100 SendDlgItemMessage16(hwnd, stc1, STM_SETICON16,
101 (WPARAM16)LoadIcon16(0, IDI_HAND16), 0);
102 break;
105 /* Position everything */
106 GetWindowRect(hwnd, &rect);
107 borheight = rect.bottom - rect.top;
108 wwidth = rect.right - rect.left;
109 GetClientRect(hwnd, &rect);
110 borheight -= rect.bottom - rect.top;
112 /* Get the icon height */
113 GetWindowRect(GetDlgItem(hwnd, 1088), &rect);
114 iheight = rect.bottom - rect.top;
116 /* Get the number of visible buttons and their width */
117 GetWindowRect(GetDlgItem(hwnd, 2), &rect);
118 bheight = rect.bottom - rect.top;
119 bwidth = rect.left;
120 GetWindowRect(GetDlgItem(hwnd, 1), &rect);
121 bwidth -= rect.left;
122 for (buttons = 0, i = 1; i < 8; i++)
124 hItem = GetDlgItem(hwnd, i);
125 if (GetWindowLongA(hItem, GWL_STYLE) & WS_VISIBLE) buttons++;
128 /* Get the text size */
129 hItem = GetDlgItem(hwnd, 100);
130 GetWindowRect(hItem, &textrect);
131 MapWindowPoints(0, hwnd, (LPPOINT)&textrect, 2);
133 GetClientRect(hItem, &rect);
134 hdc = GetDC(hItem);
135 lRet = DrawTextA( hdc, lpmb->lpszText, -1, &rect,
136 DT_LEFT | DT_EXPANDTABS | DT_WORDBREAK | DT_CALCRECT);
137 theight = rect.bottom - rect.top;
138 tiheight = 16 + MAX(iheight, theight);
139 ReleaseDC(hItem, hdc);
141 /* Position the text */
142 SetWindowPos(hItem, 0, textrect.left, (tiheight - theight) / 2,
143 rect.right - rect.left, theight,
144 SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOREDRAW);
146 /* Position the icon */
147 hItem = GetDlgItem(hwnd, 1088);
148 GetWindowRect(hItem, &rect);
149 MapWindowPoints(0, hwnd, (LPPOINT)&rect, 2);
150 SetWindowPos(hItem, 0, rect.left, (tiheight - iheight) / 2, 0, 0,
151 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOREDRAW);
153 /* Resize the window */
154 SetWindowPos(hwnd, 0, 0, 0, wwidth, 8 + tiheight + bheight + borheight,
155 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOREDRAW);
157 /* Position the buttons */
158 bpos = (wwidth - bwidth * buttons) / 2;
159 GetWindowRect(GetDlgItem(hwnd, 1), &rect);
160 for (buttons = i = 0; i < 7; i++) {
161 /* some arithmetic to get the right order for YesNoCancel windows */
162 hItem = GetDlgItem(hwnd, (i + 5) % 7 + 1);
163 if (GetWindowLongA(hItem, GWL_STYLE) & WS_VISIBLE) {
164 if (buttons++ == ((lpmb->dwStyle & MB_DEFMASK) >> 8)) {
165 SetFocus(hItem);
166 SendMessageA( hItem, BM_SETSTYLE, BS_DEFPUSHBUTTON, TRUE );
168 SetWindowPos(hItem, 0, bpos, tiheight, 0, 0,
169 SWP_NOSIZE|SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOREDRAW);
170 bpos += bwidth;
173 return 0;
174 break;
176 case WM_COMMAND:
177 switch (wParam)
179 case IDOK:
180 case IDCANCEL:
181 case IDABORT:
182 case IDRETRY:
183 case IDIGNORE:
184 case IDYES:
185 case IDNO:
186 if ((TWEAK_WineLook > WIN31_LOOK) && hFont)
187 DeleteObject (hFont);
188 EndDialog(hwnd, wParam);
189 break;
192 default:
193 /* Ok. Ignore all the other messages */
194 TRACE (dialog, "Message number %i is being ignored.\n", message);
195 break;
197 return 0;
201 /**************************************************************************
202 * MessageBox16 (USER.1)
204 INT16 WINAPI MessageBox16( HWND16 hwnd, LPCSTR text, LPCSTR title, UINT16 type)
206 WARN(dialog,"Messagebox\n");
207 return MessageBoxA( hwnd, text, title, type );
211 /**************************************************************************
212 * MessageBox32A (USER32.391)
214 * NOTES
215 * The WARN is here to help debug erroneous MessageBoxes
216 * Use: -debugmsg warn+dialog,+relay
218 INT WINAPI MessageBoxA(HWND hWnd, LPCSTR text, LPCSTR title, UINT type)
220 MSGBOXPARAMSA mbox;
221 WARN(dialog,"Messagebox\n");
222 if (!text) text="<WINE-NULL>";
223 if (!title)
224 title="Error";
225 mbox.lpszCaption = title;
226 mbox.lpszText = text;
227 mbox.dwStyle = type;
228 return DialogBoxIndirectParamA( WIN_GetWindowInstance(hWnd),
229 SYSRES_GetResPtr( SYSRES_DIALOG_MSGBOX ),
230 hWnd, (DLGPROC)MSGBOX_DlgProc, (LPARAM)&mbox );
234 /**************************************************************************
235 * MessageBox32W (USER32.396)
237 INT WINAPI MessageBoxW( HWND hwnd, LPCWSTR text, LPCWSTR title,
238 UINT type )
240 LPSTR titleA = HEAP_strdupWtoA( GetProcessHeap(), 0, title );
241 LPSTR textA = HEAP_strdupWtoA( GetProcessHeap(), 0, text );
242 INT ret;
244 WARN(dialog,"Messagebox\n");
246 ret = MessageBoxA( hwnd, textA, titleA, type );
247 HeapFree( GetProcessHeap(), 0, titleA );
248 HeapFree( GetProcessHeap(), 0, textA );
249 return ret;
253 /**************************************************************************
254 * MessageBoxEx32A (USER32.392)
256 INT WINAPI MessageBoxExA( HWND hWnd, LPCSTR text, LPCSTR title,
257 UINT type, WORD langid )
259 WARN(dialog,"Messagebox\n");
260 /* ignore language id for now */
261 return MessageBoxA(hWnd,text,title,type);
264 /**************************************************************************
265 * MessageBoxEx32W (USER32.393)
267 INT WINAPI MessageBoxExW( HWND hWnd, LPCWSTR text, LPCWSTR title,
268 UINT type, WORD langid )
270 WARN(dialog,"Messagebox\n");
271 /* ignore language id for now */
272 return MessageBoxW(hWnd,text,title,type);
275 /**************************************************************************
276 * MessageBoxIndirect16 (USER.827)
278 INT16 WINAPI MessageBoxIndirect16( LPMSGBOXPARAMS16 msgbox )
280 MSGBOXPARAMSA msgbox32;
281 WARN(dialog,"Messagebox\n");
283 msgbox32.cbSize = msgbox->cbSize;
284 msgbox32.hwndOwner = msgbox->hwndOwner;
285 msgbox32.hInstance = msgbox->hInstance;
286 msgbox32.lpszText = PTR_SEG_TO_LIN(msgbox->lpszText);
287 msgbox32.lpszCaption = PTR_SEG_TO_LIN(msgbox->lpszCaption);
288 msgbox32.dwStyle = msgbox->dwStyle;
289 msgbox32.lpszIcon = PTR_SEG_TO_LIN(msgbox->lpszIcon);
290 msgbox32.dwContextHelpId = msgbox->dwContextHelpId;
291 msgbox32.lpfnMsgBoxCallback = msgbox->lpfnMsgBoxCallback;
292 msgbox32.dwLanguageId = msgbox->dwLanguageId;
294 return DialogBoxIndirectParamA( msgbox32.hInstance,
295 SYSRES_GetResPtr( SYSRES_DIALOG_MSGBOX ),
296 msgbox32.hwndOwner, (DLGPROC)MSGBOX_DlgProc,
297 (LPARAM)&msgbox32 );
300 /**************************************************************************
301 * MessageBoxIndirect32A (USER32.394)
303 INT WINAPI MessageBoxIndirectA( LPMSGBOXPARAMSA msgbox )
305 WARN(dialog,"Messagebox\n");
306 return DialogBoxIndirectParamA( msgbox->hInstance,
307 SYSRES_GetResPtr( SYSRES_DIALOG_MSGBOX ),
308 msgbox->hwndOwner, (DLGPROC)MSGBOX_DlgProc,
309 (LPARAM)msgbox );
312 /**************************************************************************
313 * MessageBoxIndirect32W (USER32.395)
315 INT WINAPI MessageBoxIndirectW( LPMSGBOXPARAMSW msgbox )
317 MSGBOXPARAMSA msgboxa;
318 WARN(dialog,"Messagebox\n");
320 memcpy(&msgboxa,msgbox,sizeof(msgboxa));
321 if (msgbox->lpszCaption)
322 lstrcpyWtoA((LPSTR)msgboxa.lpszCaption,msgbox->lpszCaption);
323 if (msgbox->lpszText)
324 lstrcpyWtoA((LPSTR)msgboxa.lpszText,msgbox->lpszText);
326 return MessageBoxIndirectA(&msgboxa);
330 /**************************************************************************
331 * FatalAppExit16 (KERNEL.137)
333 void WINAPI FatalAppExit16( UINT16 action, LPCSTR str )
335 WARN(dialog,"AppExit\n");
336 FatalAppExitA( action, str );
340 /**************************************************************************
341 * FatalAppExit32A (KERNEL32.108)
343 void WINAPI FatalAppExitA( UINT action, LPCSTR str )
345 WARN(dialog,"AppExit\n");
346 MessageBoxA( 0, str, NULL, MB_SYSTEMMODAL | MB_OK );
347 ExitProcess(0);
351 /**************************************************************************
352 * FatalAppExit32W (KERNEL32.109)
354 void WINAPI FatalAppExitW( UINT action, LPCWSTR str )
356 WARN(dialog,"AppExit\n");
357 MessageBoxW( 0, str, NULL, MB_SYSTEMMODAL | MB_OK );
358 ExitProcess(0);