Release 970824
[wine/multimedia.git] / windows / msgbox.c
bloba2cb5bea708b8955d5bc7c43b8705b30abcc293b
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"
16 typedef struct
18 LPCSTR title;
19 LPCSTR text;
20 UINT32 type;
21 } MSGBOX, *LPMSGBOX;
24 /**************************************************************************
25 * MSGBOX_DlgProc
27 * Dialog procedure for message boxes.
29 static LRESULT CALLBACK MSGBOX_DlgProc( HWND32 hwnd, UINT32 message,
30 WPARAM32 wParam, LPARAM lParam )
32 LPMSGBOX lpmb;
33 RECT32 rect, textrect;
34 HWND32 hItem;
35 HDC32 hdc;
36 LRESULT lRet;
37 int i, buttons, bwidth, bheight, theight, wwidth, bpos;
38 int borheight, iheight, tiheight;
40 switch(message) {
41 case WM_INITDIALOG:
42 lpmb = (LPMSGBOX)lParam;
43 if (lpmb->title) SetWindowText32A(hwnd, lpmb->title);
44 SetWindowText32A(GetDlgItem32(hwnd, 100), lpmb->text);
45 /* Hide not selected buttons */
46 switch(lpmb->type & MB_TYPEMASK) {
47 case MB_OK:
48 ShowWindow32(GetDlgItem32(hwnd, 2), SW_HIDE);
49 /* fall through */
50 case MB_OKCANCEL:
51 ShowWindow32(GetDlgItem32(hwnd, 3), SW_HIDE);
52 ShowWindow32(GetDlgItem32(hwnd, 4), SW_HIDE);
53 ShowWindow32(GetDlgItem32(hwnd, 5), SW_HIDE);
54 ShowWindow32(GetDlgItem32(hwnd, 6), SW_HIDE);
55 ShowWindow32(GetDlgItem32(hwnd, 7), SW_HIDE);
56 break;
57 case MB_ABORTRETRYIGNORE:
58 ShowWindow32(GetDlgItem32(hwnd, 1), SW_HIDE);
59 ShowWindow32(GetDlgItem32(hwnd, 2), SW_HIDE);
60 ShowWindow32(GetDlgItem32(hwnd, 6), SW_HIDE);
61 ShowWindow32(GetDlgItem32(hwnd, 7), SW_HIDE);
62 break;
63 case MB_YESNO:
64 ShowWindow32(GetDlgItem32(hwnd, 2), SW_HIDE);
65 /* fall through */
66 case MB_YESNOCANCEL:
67 ShowWindow32(GetDlgItem32(hwnd, 1), SW_HIDE);
68 ShowWindow32(GetDlgItem32(hwnd, 3), SW_HIDE);
69 ShowWindow32(GetDlgItem32(hwnd, 4), SW_HIDE);
70 ShowWindow32(GetDlgItem32(hwnd, 5), SW_HIDE);
71 break;
73 /* Set the icon */
74 switch(lpmb->type & MB_ICONMASK) {
75 case MB_ICONEXCLAMATION:
76 SendDlgItemMessage16(hwnd, stc1, STM_SETICON,
77 (WPARAM16)LoadIcon16(0, IDI_EXCLAMATION), 0);
78 break;
79 case MB_ICONQUESTION:
80 SendDlgItemMessage16(hwnd, stc1, STM_SETICON,
81 (WPARAM16)LoadIcon16(0, IDI_QUESTION), 0);
82 break;
83 case MB_ICONASTERISK:
84 SendDlgItemMessage16(hwnd, stc1, STM_SETICON,
85 (WPARAM16)LoadIcon16(0, IDI_ASTERISK), 0);
86 break;
87 case MB_ICONHAND:
88 default:
89 SendDlgItemMessage16(hwnd, stc1, STM_SETICON,
90 (WPARAM16)LoadIcon16(0, IDI_HAND), 0);
91 break;
94 /* Position everything */
95 GetWindowRect32(hwnd, &rect);
96 borheight = rect.bottom - rect.top;
97 wwidth = rect.right - rect.left;
98 GetClientRect32(hwnd, &rect);
99 borheight -= rect.bottom - rect.top;
101 /* Get the icon height */
102 GetWindowRect32(GetDlgItem32(hwnd, 1088), &rect);
103 iheight = rect.bottom - rect.top;
105 /* Get the number of visible buttons and their width */
106 GetWindowRect32(GetDlgItem32(hwnd, 2), &rect);
107 bheight = rect.bottom - rect.top;
108 bwidth = rect.left;
109 GetWindowRect32(GetDlgItem32(hwnd, 1), &rect);
110 bwidth -= rect.left;
111 for (buttons = 0, i = 1; i < 8; i++)
113 hItem = GetDlgItem32(hwnd, i);
114 if (GetWindowLong32A(hItem, GWL_STYLE) & WS_VISIBLE) buttons++;
117 /* Get the text size */
118 hItem = GetDlgItem32(hwnd, 100);
119 GetWindowRect32(hItem, &textrect);
120 MapWindowPoints32(0, hwnd, (LPPOINT32)&textrect, 2);
122 GetClientRect32(hItem, &rect);
123 hdc = GetDC32(hItem);
124 lRet = DrawText32A( hdc, lpmb->text, -1, &rect,
125 DT_LEFT | DT_EXPANDTABS | DT_WORDBREAK | DT_CALCRECT);
126 theight = rect.bottom - rect.top;
127 tiheight = 16 + MAX(iheight, theight);
128 ReleaseDC32(hItem, hdc);
130 /* Position the text */
131 SetWindowPos32(hItem, 0, textrect.left, (tiheight - theight) / 2,
132 rect.right - rect.left, theight,
133 SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOREDRAW);
135 /* Position the icon */
136 hItem = GetDlgItem32(hwnd, 1088);
137 GetWindowRect32(hItem, &rect);
138 MapWindowPoints32(0, hwnd, (LPPOINT32)&rect, 2);
139 SetWindowPos32(hItem, 0, rect.left, (tiheight - iheight) / 2, 0, 0,
140 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOREDRAW);
142 /* Resize the window */
143 SetWindowPos32(hwnd, 0, 0, 0, wwidth, 8 + tiheight + bheight + borheight,
144 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOREDRAW);
146 /* Position the buttons */
147 bpos = (wwidth - bwidth * buttons) / 2;
148 GetWindowRect32(GetDlgItem32(hwnd, 1), &rect);
149 for (buttons = i = 0; i < 7; i++) {
150 /* some arithmetic to get the right order for YesNoCancel windows */
151 hItem = GetDlgItem32(hwnd, (i + 5) % 7 + 1);
152 if (GetWindowLong32A(hItem, GWL_STYLE) & WS_VISIBLE) {
153 if (buttons++ == ((lpmb->type & MB_DEFMASK) >> 8)) {
154 SetFocus32(hItem);
155 SendMessage32A( hItem, BM_SETSTYLE32, BS_DEFPUSHBUTTON, TRUE );
157 SetWindowPos32(hItem, 0, bpos, tiheight, 0, 0,
158 SWP_NOSIZE|SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOREDRAW);
159 bpos += bwidth;
162 return 0;
163 break;
165 case WM_COMMAND:
166 switch (wParam)
168 case IDOK:
169 case IDCANCEL:
170 case IDABORT:
171 case IDRETRY:
172 case IDIGNORE:
173 case IDYES:
174 case IDNO:
175 EndDialog32(hwnd, wParam);
176 break;
178 break;
180 return 0;
184 /**************************************************************************
185 * MessageBox16 (USER.1)
187 INT16 WINAPI MessageBox16( HWND16 hwnd, LPCSTR text, LPCSTR title, UINT16 type)
189 return MessageBox32A( hwnd, text, title, type );
193 /**************************************************************************
194 * MessageBox32A (USER32.390)
196 INT32 WINAPI MessageBox32A(HWND32 hWnd, LPCSTR text, LPCSTR title, UINT32 type)
198 MSGBOX mbox;
200 if (!text) text="<WINE-NULL>";
201 if (!title) title="<WINE-NULL>";
202 mbox.title = title;
203 mbox.text = text;
204 mbox.type = type;
205 return DialogBoxIndirectParam32A( WIN_GetWindowInstance(hWnd),
206 SYSRES_GetResPtr( SYSRES_DIALOG_MSGBOX ),
207 hWnd, MSGBOX_DlgProc, (LPARAM)&mbox );
211 /**************************************************************************
212 * MessageBox32W (USER32.395)
214 INT32 WINAPI MessageBox32W( HWND32 hwnd, LPCWSTR text, LPCWSTR title,
215 UINT32 type )
217 LPSTR titleA = HEAP_strdupWtoA( GetProcessHeap(), 0, title );
218 LPSTR textA = HEAP_strdupWtoA( GetProcessHeap(), 0, text );
219 INT32 ret = MessageBox32A( hwnd, textA, titleA, type );
220 HeapFree( GetProcessHeap(), 0, titleA );
221 HeapFree( GetProcessHeap(), 0, textA );
222 return ret;
226 /**************************************************************************
227 * MessageBoxEx32A (USER32.391)
229 INT32 WINAPI MessageBoxEx32A( HWND32 hWnd, LPCSTR text, LPCSTR title,
230 UINT32 type, WORD langid )
232 /* ignore language id for now */
233 return MessageBox32A(hWnd,text,title,type);
236 /**************************************************************************
237 * MessageBoxEx32W (USER32.392)
239 INT32 WINAPI MessageBoxEx32W( HWND32 hWnd, LPCWSTR text, LPCWSTR title,
240 UINT32 type, WORD langid )
242 /* ignore language id for now */
243 return MessageBox32W(hWnd,text,title,type);
247 /**************************************************************************
248 * FatalAppExit16 (KERNEL.137)
250 void WINAPI FatalAppExit16( UINT16 action, LPCSTR str )
252 FatalAppExit32A( action, str );
256 /**************************************************************************
257 * FatalAppExit32A (KERNEL32.108)
259 void WINAPI FatalAppExit32A( UINT32 action, LPCSTR str )
261 MessageBox32A( 0, str, NULL, MB_SYSTEMMODAL | MB_OK );
262 TASK_KillCurrentTask(0);
266 /**************************************************************************
267 * FatalAppExit32W (KERNEL32.109)
269 void WINAPI FatalAppExit32W( UINT32 action, LPCWSTR str )
271 MessageBox32W( 0, str, NULL, MB_SYSTEMMODAL | MB_OK );
272 TASK_KillCurrentTask(0);