Got rid of THREAD_InitDone.
[wine.git] / windows / msgbox.c
blob21a9207819a162496b909b146c3be3b3b0aafde2
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 "ldt.h"
12 #include "debug.h"
13 #include "debugstr.h"
14 #include "tweak.h"
16 DEFAULT_DEBUG_CHANNEL(dialog)
18 /**************************************************************************
19 * MSGBOX_DlgProc
21 * Dialog procedure for message boxes.
23 static LRESULT CALLBACK MSGBOX_DlgProc( HWND hwnd, UINT message,
24 WPARAM wParam, LPARAM lParam )
26 static HFONT hFont = 0;
27 LPMSGBOXPARAMSA lpmb;
29 RECT rect, textrect;
30 HWND hItem;
31 HDC hdc;
32 LRESULT lRet;
33 int i, buttons, bwidth, bheight, theight, wwidth, bpos;
34 int borheight, iheight, tiheight;
36 switch(message) {
37 case WM_INITDIALOG:
38 lpmb = (LPMSGBOXPARAMSA)lParam;
39 if (TWEAK_WineLook >= WIN95_LOOK) {
40 NONCLIENTMETRICSA nclm;
41 INT i;
42 nclm.cbSize = sizeof(NONCLIENTMETRICSA);
43 SystemParametersInfoA (SPI_GETNONCLIENTMETRICS, 0, &nclm, 0);
44 hFont = CreateFontIndirectA (&nclm.lfMessageFont);
45 /* set button font */
46 for (i=1; i < 8; i++)
47 SendDlgItemMessageA (hwnd, i, WM_SETFONT, (WPARAM)hFont, 0);
48 /* set text font */
49 SendDlgItemMessageA (hwnd, 100, WM_SETFONT, (WPARAM)hFont, 0);
51 if (lpmb->lpszCaption) SetWindowTextA(hwnd, lpmb->lpszCaption);
52 SetWindowTextA(GetDlgItem(hwnd, 100), lpmb->lpszText);
53 /* Hide not selected buttons */
54 switch(lpmb->dwStyle & MB_TYPEMASK) {
55 case MB_OK:
56 ShowWindow(GetDlgItem(hwnd, 2), SW_HIDE);
57 /* fall through */
58 case MB_OKCANCEL:
59 ShowWindow(GetDlgItem(hwnd, 3), SW_HIDE);
60 ShowWindow(GetDlgItem(hwnd, 4), SW_HIDE);
61 ShowWindow(GetDlgItem(hwnd, 5), SW_HIDE);
62 ShowWindow(GetDlgItem(hwnd, 6), SW_HIDE);
63 ShowWindow(GetDlgItem(hwnd, 7), SW_HIDE);
64 break;
65 case MB_ABORTRETRYIGNORE:
66 ShowWindow(GetDlgItem(hwnd, 1), SW_HIDE);
67 ShowWindow(GetDlgItem(hwnd, 2), SW_HIDE);
68 ShowWindow(GetDlgItem(hwnd, 6), SW_HIDE);
69 ShowWindow(GetDlgItem(hwnd, 7), SW_HIDE);
70 break;
71 case MB_YESNO:
72 ShowWindow(GetDlgItem(hwnd, 2), SW_HIDE);
73 /* fall through */
74 case MB_YESNOCANCEL:
75 ShowWindow(GetDlgItem(hwnd, 1), SW_HIDE);
76 ShowWindow(GetDlgItem(hwnd, 3), SW_HIDE);
77 ShowWindow(GetDlgItem(hwnd, 4), SW_HIDE);
78 ShowWindow(GetDlgItem(hwnd, 5), SW_HIDE);
79 break;
81 /* Set the icon */
82 switch(lpmb->dwStyle & MB_ICONMASK) {
83 case MB_ICONEXCLAMATION:
84 SendDlgItemMessage16(hwnd, stc1, STM_SETICON16,
85 (WPARAM16)LoadIcon16(0, IDI_EXCLAMATION16), 0);
86 break;
87 case MB_ICONQUESTION:
88 SendDlgItemMessage16(hwnd, stc1, STM_SETICON16,
89 (WPARAM16)LoadIcon16(0, IDI_QUESTION16), 0);
90 break;
91 case MB_ICONASTERISK:
92 SendDlgItemMessage16(hwnd, stc1, STM_SETICON16,
93 (WPARAM16)LoadIcon16(0, IDI_ASTERISK16), 0);
94 break;
95 case MB_ICONHAND:
96 default:
97 SendDlgItemMessage16(hwnd, stc1, STM_SETICON16,
98 (WPARAM16)LoadIcon16(0, IDI_HAND16), 0);
99 break;
102 /* Position everything */
103 GetWindowRect(hwnd, &rect);
104 borheight = rect.bottom - rect.top;
105 wwidth = rect.right - rect.left;
106 GetClientRect(hwnd, &rect);
107 borheight -= rect.bottom - rect.top;
109 /* Get the icon height */
110 GetWindowRect(GetDlgItem(hwnd, 1088), &rect);
111 iheight = rect.bottom - rect.top;
113 /* Get the number of visible buttons and their width */
114 GetWindowRect(GetDlgItem(hwnd, 2), &rect);
115 bheight = rect.bottom - rect.top;
116 bwidth = rect.left;
117 GetWindowRect(GetDlgItem(hwnd, 1), &rect);
118 bwidth -= rect.left;
119 for (buttons = 0, i = 1; i < 8; i++)
121 hItem = GetDlgItem(hwnd, i);
122 if (GetWindowLongA(hItem, GWL_STYLE) & WS_VISIBLE) buttons++;
125 /* Get the text size */
126 hItem = GetDlgItem(hwnd, 100);
127 GetWindowRect(hItem, &textrect);
128 MapWindowPoints(0, hwnd, (LPPOINT)&textrect, 2);
130 GetClientRect(hItem, &rect);
131 hdc = GetDC(hItem);
132 lRet = DrawTextA( hdc, lpmb->lpszText, -1, &rect,
133 DT_LEFT | DT_EXPANDTABS | DT_WORDBREAK | DT_CALCRECT);
134 theight = rect.bottom - rect.top;
135 tiheight = 16 + MAX(iheight, theight);
136 ReleaseDC(hItem, hdc);
138 /* Position the text */
139 SetWindowPos(hItem, 0, textrect.left, (tiheight - theight) / 2,
140 rect.right - rect.left, theight,
141 SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOREDRAW);
143 /* Position the icon */
144 hItem = GetDlgItem(hwnd, 1088);
145 GetWindowRect(hItem, &rect);
146 MapWindowPoints(0, hwnd, (LPPOINT)&rect, 2);
147 SetWindowPos(hItem, 0, rect.left, (tiheight - iheight) / 2, 0, 0,
148 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOREDRAW);
150 /* Resize the window */
151 SetWindowPos(hwnd, 0, 0, 0, wwidth, 8 + tiheight + bheight + borheight,
152 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOREDRAW);
154 /* Position the buttons */
155 bpos = (wwidth - bwidth * buttons) / 2;
156 GetWindowRect(GetDlgItem(hwnd, 1), &rect);
157 for (buttons = i = 0; i < 7; i++) {
158 /* some arithmetic to get the right order for YesNoCancel windows */
159 hItem = GetDlgItem(hwnd, (i + 5) % 7 + 1);
160 if (GetWindowLongA(hItem, GWL_STYLE) & WS_VISIBLE) {
161 if (buttons++ == ((lpmb->dwStyle & MB_DEFMASK) >> 8)) {
162 SetFocus(hItem);
163 SendMessageA( hItem, BM_SETSTYLE, BS_DEFPUSHBUTTON, TRUE );
165 SetWindowPos(hItem, 0, bpos, tiheight, 0, 0,
166 SWP_NOSIZE|SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOREDRAW);
167 bpos += bwidth;
170 return 0;
171 break;
173 case WM_COMMAND:
174 switch (wParam)
176 case IDOK:
177 case IDCANCEL:
178 case IDABORT:
179 case IDRETRY:
180 case IDIGNORE:
181 case IDYES:
182 case IDNO:
183 if ((TWEAK_WineLook > WIN31_LOOK) && hFont)
184 DeleteObject (hFont);
185 EndDialog(hwnd, wParam);
186 break;
189 default:
190 /* Ok. Ignore all the other messages */
191 TRACE (dialog, "Message number %i is being ignored.\n", message);
192 break;
194 return 0;
198 /**************************************************************************
199 * MessageBox16 (USER.1)
201 INT16 WINAPI MessageBox16( HWND16 hwnd, LPCSTR text, LPCSTR title, UINT16 type)
203 WARN(dialog,"Messagebox\n");
204 return MessageBoxA( hwnd, text, title, type );
208 /**************************************************************************
209 * MessageBox32A (USER32.391)
211 * NOTES
212 * The WARN is here to help debug erroneous MessageBoxes
213 * Use: -debugmsg warn+dialog,+relay
215 INT WINAPI MessageBoxA(HWND hWnd, LPCSTR text, LPCSTR title, UINT type)
217 LPVOID template;
218 HRSRC hRes;
219 MSGBOXPARAMSA mbox;
221 WARN(dialog,"Messagebox\n");
223 if(!(hRes = FindResourceA(GetModuleHandleA("USER32"), "MSGBOX", RT_DIALOGA)))
224 return 0;
225 if(!(template = (LPVOID)LoadResource(GetModuleHandleA("USER32"), hRes)))
226 return 0;
228 if (!text) text="<WINE-NULL>";
229 if (!title)
230 title="Error";
231 mbox.lpszCaption = title;
232 mbox.lpszText = text;
233 mbox.dwStyle = type;
234 return DialogBoxIndirectParamA( GetWindowLongA(hWnd,GWL_HINSTANCE), template,
235 hWnd, (DLGPROC)MSGBOX_DlgProc, (LPARAM)&mbox );
239 /**************************************************************************
240 * MessageBox32W (USER32.396)
242 INT WINAPI MessageBoxW( HWND hwnd, LPCWSTR text, LPCWSTR title,
243 UINT type )
245 LPSTR titleA = HEAP_strdupWtoA( GetProcessHeap(), 0, title );
246 LPSTR textA = HEAP_strdupWtoA( GetProcessHeap(), 0, text );
247 INT ret;
249 WARN(dialog,"Messagebox\n");
251 ret = MessageBoxA( hwnd, textA, titleA, type );
252 HeapFree( GetProcessHeap(), 0, titleA );
253 HeapFree( GetProcessHeap(), 0, textA );
254 return ret;
258 /**************************************************************************
259 * MessageBoxEx32A (USER32.392)
261 INT WINAPI MessageBoxExA( HWND hWnd, LPCSTR text, LPCSTR title,
262 UINT type, WORD langid )
264 WARN(dialog,"Messagebox\n");
265 /* ignore language id for now */
266 return MessageBoxA(hWnd,text,title,type);
269 /**************************************************************************
270 * MessageBoxEx32W (USER32.393)
272 INT WINAPI MessageBoxExW( HWND hWnd, LPCWSTR text, LPCWSTR title,
273 UINT type, WORD langid )
275 WARN(dialog,"Messagebox\n");
276 /* ignore language id for now */
277 return MessageBoxW(hWnd,text,title,type);
280 /**************************************************************************
281 * MessageBoxIndirect16 (USER.827)
283 INT16 WINAPI MessageBoxIndirect16( LPMSGBOXPARAMS16 msgbox )
285 LPVOID template;
286 HRSRC hRes;
287 MSGBOXPARAMSA msgbox32;
289 WARN(dialog,"Messagebox\n");
291 if(!(hRes = FindResourceA(GetModuleHandleA("USER32"), "MSGBOX", RT_DIALOGA)))
292 return 0;
293 if(!(template = (LPVOID)LoadResource(GetModuleHandleA("USER32"), hRes)))
294 return 0;
296 msgbox32.cbSize = msgbox->cbSize;
297 msgbox32.hwndOwner = msgbox->hwndOwner;
298 msgbox32.hInstance = msgbox->hInstance;
299 msgbox32.lpszText = PTR_SEG_TO_LIN(msgbox->lpszText);
300 msgbox32.lpszCaption = PTR_SEG_TO_LIN(msgbox->lpszCaption);
301 msgbox32.dwStyle = msgbox->dwStyle;
302 msgbox32.lpszIcon = PTR_SEG_TO_LIN(msgbox->lpszIcon);
303 msgbox32.dwContextHelpId = msgbox->dwContextHelpId;
304 msgbox32.lpfnMsgBoxCallback = msgbox->lpfnMsgBoxCallback;
305 msgbox32.dwLanguageId = msgbox->dwLanguageId;
307 return DialogBoxIndirectParamA( msgbox32.hInstance, template,
308 msgbox32.hwndOwner, (DLGPROC)MSGBOX_DlgProc,
309 (LPARAM)&msgbox32 );
312 /**************************************************************************
313 * MessageBoxIndirect32A (USER32.394)
315 INT WINAPI MessageBoxIndirectA( LPMSGBOXPARAMSA msgbox )
317 LPVOID template;
318 HRSRC hRes;
320 WARN(dialog,"Messagebox\n");
322 if(!(hRes = FindResourceA(GetModuleHandleA("USER32"), "MSGBOX", RT_DIALOGA)))
323 return 0;
324 if(!(template = (LPVOID)LoadResource(GetModuleHandleA("USER32"), hRes)))
325 return 0;
327 return DialogBoxIndirectParamA( msgbox->hInstance, template,
328 msgbox->hwndOwner, (DLGPROC)MSGBOX_DlgProc,
329 (LPARAM)msgbox );
332 /**************************************************************************
333 * MessageBoxIndirect32W (USER32.395)
335 INT WINAPI MessageBoxIndirectW( LPMSGBOXPARAMSW msgbox )
337 MSGBOXPARAMSA msgboxa;
338 WARN(dialog,"Messagebox\n");
340 memcpy(&msgboxa,msgbox,sizeof(msgboxa));
341 if (msgbox->lpszCaption)
342 lstrcpyWtoA((LPSTR)msgboxa.lpszCaption,msgbox->lpszCaption);
343 if (msgbox->lpszText)
344 lstrcpyWtoA((LPSTR)msgboxa.lpszText,msgbox->lpszText);
346 return MessageBoxIndirectA(&msgboxa);
350 /**************************************************************************
351 * FatalAppExit16 (KERNEL.137)
353 void WINAPI FatalAppExit16( UINT16 action, LPCSTR str )
355 WARN(dialog,"AppExit\n");
356 FatalAppExitA( action, str );
360 /**************************************************************************
361 * FatalAppExit32A (KERNEL32.108)
363 void WINAPI FatalAppExitA( UINT action, LPCSTR str )
365 WARN(dialog,"AppExit\n");
366 MessageBoxA( 0, str, NULL, MB_SYSTEMMODAL | MB_OK );
367 ExitProcess(0);
371 /**************************************************************************
372 * FatalAppExit32W (KERNEL32.109)
374 void WINAPI FatalAppExitW( UINT action, LPCWSTR str )
376 WARN(dialog,"AppExit\n");
377 MessageBoxW( 0, str, NULL, MB_SYSTEMMODAL | MB_OK );
378 ExitProcess(0);