Release 980329
[wine/multimedia.git] / windows / msgbox.c
blob01f45e2eadf45604609aa47f74e0e82862de4d90
1 /*
2 * Message boxes
4 * Copyright 1995 Bernd Schmidt
5 */
7 #include <stdio.h>
8 #include "windows.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"
18 /**************************************************************************
19 * MSGBOX_DlgProc
21 * Dialog procedure for message boxes.
23 static LRESULT CALLBACK MSGBOX_DlgProc( HWND32 hwnd, UINT32 message,
24 WPARAM32 wParam, LPARAM lParam )
26 LPMSGBOXPARAMS32A lpmb;
28 RECT32 rect, textrect;
29 HWND32 hItem;
30 HDC32 hdc;
31 LRESULT lRet;
32 int i, buttons, bwidth, bheight, theight, wwidth, bpos;
33 int borheight, iheight, tiheight;
35 switch(message) {
36 case WM_INITDIALOG:
37 lpmb = (LPMSGBOXPARAMS32A)lParam;
38 if (lpmb->lpszCaption) SetWindowText32A(hwnd, lpmb->lpszCaption);
39 SetWindowText32A(GetDlgItem32(hwnd, 100), lpmb->lpszText);
40 /* Hide not selected buttons */
41 switch(lpmb->dwStyle & MB_TYPEMASK) {
42 case MB_OK:
43 ShowWindow32(GetDlgItem32(hwnd, 2), SW_HIDE);
44 /* fall through */
45 case MB_OKCANCEL:
46 ShowWindow32(GetDlgItem32(hwnd, 3), SW_HIDE);
47 ShowWindow32(GetDlgItem32(hwnd, 4), SW_HIDE);
48 ShowWindow32(GetDlgItem32(hwnd, 5), SW_HIDE);
49 ShowWindow32(GetDlgItem32(hwnd, 6), SW_HIDE);
50 ShowWindow32(GetDlgItem32(hwnd, 7), SW_HIDE);
51 break;
52 case MB_ABORTRETRYIGNORE:
53 ShowWindow32(GetDlgItem32(hwnd, 1), SW_HIDE);
54 ShowWindow32(GetDlgItem32(hwnd, 2), SW_HIDE);
55 ShowWindow32(GetDlgItem32(hwnd, 6), SW_HIDE);
56 ShowWindow32(GetDlgItem32(hwnd, 7), SW_HIDE);
57 break;
58 case MB_YESNO:
59 ShowWindow32(GetDlgItem32(hwnd, 2), SW_HIDE);
60 /* fall through */
61 case MB_YESNOCANCEL:
62 ShowWindow32(GetDlgItem32(hwnd, 1), SW_HIDE);
63 ShowWindow32(GetDlgItem32(hwnd, 3), SW_HIDE);
64 ShowWindow32(GetDlgItem32(hwnd, 4), SW_HIDE);
65 ShowWindow32(GetDlgItem32(hwnd, 5), SW_HIDE);
66 break;
68 /* Set the icon */
69 switch(lpmb->dwStyle & MB_ICONMASK) {
70 case MB_ICONEXCLAMATION:
71 SendDlgItemMessage16(hwnd, stc1, STM_SETICON16,
72 (WPARAM16)LoadIcon16(0, IDI_EXCLAMATION), 0);
73 break;
74 case MB_ICONQUESTION:
75 SendDlgItemMessage16(hwnd, stc1, STM_SETICON16,
76 (WPARAM16)LoadIcon16(0, IDI_QUESTION), 0);
77 break;
78 case MB_ICONASTERISK:
79 SendDlgItemMessage16(hwnd, stc1, STM_SETICON16,
80 (WPARAM16)LoadIcon16(0, IDI_ASTERISK), 0);
81 break;
82 case MB_ICONHAND:
83 default:
84 SendDlgItemMessage16(hwnd, stc1, STM_SETICON16,
85 (WPARAM16)LoadIcon16(0, IDI_HAND), 0);
86 break;
89 /* Position everything */
90 GetWindowRect32(hwnd, &rect);
91 borheight = rect.bottom - rect.top;
92 wwidth = rect.right - rect.left;
93 GetClientRect32(hwnd, &rect);
94 borheight -= rect.bottom - rect.top;
96 /* Get the icon height */
97 GetWindowRect32(GetDlgItem32(hwnd, 1088), &rect);
98 iheight = rect.bottom - rect.top;
100 /* Get the number of visible buttons and their width */
101 GetWindowRect32(GetDlgItem32(hwnd, 2), &rect);
102 bheight = rect.bottom - rect.top;
103 bwidth = rect.left;
104 GetWindowRect32(GetDlgItem32(hwnd, 1), &rect);
105 bwidth -= rect.left;
106 for (buttons = 0, i = 1; i < 8; i++)
108 hItem = GetDlgItem32(hwnd, i);
109 if (GetWindowLong32A(hItem, GWL_STYLE) & WS_VISIBLE) buttons++;
112 /* Get the text size */
113 hItem = GetDlgItem32(hwnd, 100);
114 GetWindowRect32(hItem, &textrect);
115 MapWindowPoints32(0, hwnd, (LPPOINT32)&textrect, 2);
117 GetClientRect32(hItem, &rect);
118 hdc = GetDC32(hItem);
119 lRet = DrawText32A( hdc, lpmb->lpszText, -1, &rect,
120 DT_LEFT | DT_EXPANDTABS | DT_WORDBREAK | DT_CALCRECT);
121 theight = rect.bottom - rect.top;
122 tiheight = 16 + MAX(iheight, theight);
123 ReleaseDC32(hItem, hdc);
125 /* Position the text */
126 SetWindowPos32(hItem, 0, textrect.left, (tiheight - theight) / 2,
127 rect.right - rect.left, theight,
128 SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOREDRAW);
130 /* Position the icon */
131 hItem = GetDlgItem32(hwnd, 1088);
132 GetWindowRect32(hItem, &rect);
133 MapWindowPoints32(0, hwnd, (LPPOINT32)&rect, 2);
134 SetWindowPos32(hItem, 0, rect.left, (tiheight - iheight) / 2, 0, 0,
135 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOREDRAW);
137 /* Resize the window */
138 SetWindowPos32(hwnd, 0, 0, 0, wwidth, 8 + tiheight + bheight + borheight,
139 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOREDRAW);
141 /* Position the buttons */
142 bpos = (wwidth - bwidth * buttons) / 2;
143 GetWindowRect32(GetDlgItem32(hwnd, 1), &rect);
144 for (buttons = i = 0; i < 7; i++) {
145 /* some arithmetic to get the right order for YesNoCancel windows */
146 hItem = GetDlgItem32(hwnd, (i + 5) % 7 + 1);
147 if (GetWindowLong32A(hItem, GWL_STYLE) & WS_VISIBLE) {
148 if (buttons++ == ((lpmb->dwStyle & MB_DEFMASK) >> 8)) {
149 SetFocus32(hItem);
150 SendMessage32A( hItem, BM_SETSTYLE32, BS_DEFPUSHBUTTON, TRUE );
152 SetWindowPos32(hItem, 0, bpos, tiheight, 0, 0,
153 SWP_NOSIZE|SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOREDRAW);
154 bpos += bwidth;
157 return 0;
158 break;
160 case WM_COMMAND:
161 switch (wParam)
163 case IDOK:
164 case IDCANCEL:
165 case IDABORT:
166 case IDRETRY:
167 case IDIGNORE:
168 case IDYES:
169 case IDNO:
170 EndDialog32(hwnd, wParam);
171 break;
173 default:
174 /* Ok. Ignore all the other messages */
175 TRACE (dialog, "Message number %i is being ignored.\n", message);
176 break;
178 return 0;
182 /**************************************************************************
183 * MessageBox16 (USER.1)
185 INT16 WINAPI MessageBox16( HWND16 hwnd, LPCSTR text, LPCSTR title, UINT16 type)
187 return MessageBox32A( hwnd, text, title, type );
191 /**************************************************************************
192 * MessageBox32A (USER32.390)
194 INT32 WINAPI MessageBox32A(HWND32 hWnd, LPCSTR text, LPCSTR title, UINT32 type)
196 MSGBOXPARAMS32A mbox;
198 if (!text) text="<WINE-NULL>";
199 if (!title)
200 title="Error";
201 mbox.lpszCaption = title;
202 mbox.lpszText = text;
203 mbox.dwStyle = type;
204 return DialogBoxIndirectParam32A( WIN_GetWindowInstance(hWnd),
205 SYSRES_GetResPtr( SYSRES_DIALOG_MSGBOX ),
206 hWnd, MSGBOX_DlgProc, (LPARAM)&mbox );
210 /**************************************************************************
211 * MessageBox32W (USER32.395)
213 INT32 WINAPI MessageBox32W( HWND32 hwnd, LPCWSTR text, LPCWSTR title,
214 UINT32 type )
216 LPSTR titleA = HEAP_strdupWtoA( GetProcessHeap(), 0, title );
217 LPSTR textA = HEAP_strdupWtoA( GetProcessHeap(), 0, text );
218 INT32 ret = MessageBox32A( hwnd, textA, titleA, type );
219 HeapFree( GetProcessHeap(), 0, titleA );
220 HeapFree( GetProcessHeap(), 0, textA );
221 return ret;
225 /**************************************************************************
226 * MessageBoxEx32A (USER32.391)
228 INT32 WINAPI MessageBoxEx32A( HWND32 hWnd, LPCSTR text, LPCSTR title,
229 UINT32 type, WORD langid )
231 /* ignore language id for now */
232 return MessageBox32A(hWnd,text,title,type);
235 /**************************************************************************
236 * MessageBoxEx32W (USER32.392)
238 INT32 WINAPI MessageBoxEx32W( HWND32 hWnd, LPCWSTR text, LPCWSTR title,
239 UINT32 type, WORD langid )
241 /* ignore language id for now */
242 return MessageBox32W(hWnd,text,title,type);
245 /**************************************************************************
246 * MessageBoxIndirect32A (USER32.394)
248 INT32 WINAPI MessageBoxIndirect32A( LPMSGBOXPARAMS32A msgbox )
250 return DialogBoxIndirectParam32A( msgbox->hInstance,
251 SYSRES_GetResPtr( SYSRES_DIALOG_MSGBOX ),
252 msgbox->hwndOwner, MSGBOX_DlgProc,
253 (LPARAM)msgbox );
256 /**************************************************************************
257 * MessageBoxIndirect32W (USER32.395)
259 INT32 WINAPI MessageBoxIndirect32W( LPMSGBOXPARAMS32W msgbox )
261 MSGBOXPARAMS32A msgboxa;
263 memcpy(&msgboxa,msgbox,sizeof(msgboxa));
264 if (msgbox->lpszCaption) lstrcpyWtoA(msgboxa.lpszCaption,msgbox->lpszCaption);
265 if (msgbox->lpszText) lstrcpyWtoA(msgboxa.lpszText,msgbox->lpszText);
267 return MessageBoxIndirect32A(&msgboxa);
271 /**************************************************************************
272 * FatalAppExit16 (KERNEL.137)
274 void WINAPI FatalAppExit16( UINT16 action, LPCSTR str )
276 FatalAppExit32A( action, str );
280 /**************************************************************************
281 * FatalAppExit32A (KERNEL32.108)
283 void WINAPI FatalAppExit32A( UINT32 action, LPCSTR str )
285 MessageBox32A( 0, str, NULL, MB_SYSTEMMODAL | MB_OK );
286 TASK_KillCurrentTask(0);
290 /**************************************************************************
291 * FatalAppExit32W (KERNEL32.109)
293 void WINAPI FatalAppExit32W( UINT32 action, LPCWSTR str )
295 MessageBox32W( 0, str, NULL, MB_SYSTEMMODAL | MB_OK );
296 TASK_KillCurrentTask(0);