Release 970202
[wine/multimedia.git] / windows / msgbox.c
blob1ad540ded66af708f8dde6a3cec949fc7f142025
1 /*
2 * Message boxes
4 * Copyright 1995 Bernd Schmidt
5 */
7 #define NO_TRANSITION_TYPES /* This file is Win32-clean */
8 #include <stdio.h>
9 #include "windows.h"
10 #include "dlgs.h"
11 #include "heap.h"
12 #include "module.h"
13 #include "win.h"
14 #include "resource.h"
15 #include "task.h"
17 typedef struct
19 LPCSTR title;
20 LPCSTR text;
21 UINT32 type;
22 } MSGBOX, *LPMSGBOX;
25 /**************************************************************************
26 * MSGBOX_DlgProc
28 * Dialog procedure for message boxes.
30 static LRESULT MSGBOX_DlgProc( HWND32 hwnd, UINT32 message,
31 WPARAM32 wParam, LPARAM lParam )
33 LPMSGBOX lpmb;
34 RECT32 rect, textrect;
35 HWND32 hItem;
36 HDC32 hdc;
37 LRESULT lRet;
38 int i, buttons, bwidth, bheight, theight, wwidth, bpos;
39 int borheight, iheight, tiheight;
41 switch(message) {
42 case WM_INITDIALOG:
43 lpmb = (LPMSGBOX)lParam;
44 if (lpmb->title) SetWindowText32A(hwnd, lpmb->title);
45 SetWindowText32A(GetDlgItem32(hwnd, 100), lpmb->text);
46 /* Hide not selected buttons */
47 switch(lpmb->type & MB_TYPEMASK) {
48 case MB_OK:
49 ShowWindow32(GetDlgItem32(hwnd, 2), SW_HIDE);
50 /* fall through */
51 case MB_OKCANCEL:
52 ShowWindow32(GetDlgItem32(hwnd, 3), SW_HIDE);
53 ShowWindow32(GetDlgItem32(hwnd, 4), SW_HIDE);
54 ShowWindow32(GetDlgItem32(hwnd, 5), SW_HIDE);
55 ShowWindow32(GetDlgItem32(hwnd, 6), SW_HIDE);
56 ShowWindow32(GetDlgItem32(hwnd, 7), SW_HIDE);
57 break;
58 case MB_ABORTRETRYIGNORE:
59 ShowWindow32(GetDlgItem32(hwnd, 1), SW_HIDE);
60 ShowWindow32(GetDlgItem32(hwnd, 2), SW_HIDE);
61 ShowWindow32(GetDlgItem32(hwnd, 6), SW_HIDE);
62 ShowWindow32(GetDlgItem32(hwnd, 7), SW_HIDE);
63 break;
64 case MB_YESNO:
65 ShowWindow32(GetDlgItem32(hwnd, 2), SW_HIDE);
66 /* fall through */
67 case MB_YESNOCANCEL:
68 ShowWindow32(GetDlgItem32(hwnd, 1), SW_HIDE);
69 ShowWindow32(GetDlgItem32(hwnd, 3), SW_HIDE);
70 ShowWindow32(GetDlgItem32(hwnd, 4), SW_HIDE);
71 ShowWindow32(GetDlgItem32(hwnd, 5), SW_HIDE);
72 break;
74 /* Set the icon */
75 switch(lpmb->type & MB_ICONMASK) {
76 case MB_ICONEXCLAMATION:
77 SendDlgItemMessage16(hwnd, stc1, STM_SETICON,
78 (WPARAM16)LoadIcon16(0, IDI_EXCLAMATION), 0);
79 break;
80 case MB_ICONQUESTION:
81 SendDlgItemMessage16(hwnd, stc1, STM_SETICON,
82 (WPARAM16)LoadIcon16(0, IDI_QUESTION), 0);
83 break;
84 case MB_ICONASTERISK:
85 SendDlgItemMessage16(hwnd, stc1, STM_SETICON,
86 (WPARAM16)LoadIcon16(0, IDI_ASTERISK), 0);
87 break;
88 case MB_ICONHAND:
89 default:
90 SendDlgItemMessage16(hwnd, stc1, STM_SETICON,
91 (WPARAM16)LoadIcon16(0, IDI_HAND), 0);
92 break;
95 /* Position everything */
96 GetWindowRect32(hwnd, &rect);
97 borheight = rect.bottom - rect.top;
98 wwidth = rect.right - rect.left;
99 GetClientRect32(hwnd, &rect);
100 borheight -= rect.bottom - rect.top;
102 /* Get the icon height */
103 GetWindowRect32(GetDlgItem32(hwnd, 1088), &rect);
104 iheight = rect.bottom - rect.top;
106 /* Get the number of visible buttons and their width */
107 GetWindowRect32(GetDlgItem32(hwnd, 2), &rect);
108 bheight = rect.bottom - rect.top;
109 bwidth = rect.left;
110 GetWindowRect32(GetDlgItem32(hwnd, 1), &rect);
111 bwidth -= rect.left;
112 for (buttons = 0, i = 1; i < 8; i++)
114 hItem = GetDlgItem32(hwnd, i);
115 if (GetWindowLong32A(hItem, GWL_STYLE) & WS_VISIBLE) buttons++;
118 /* Get the text size */
119 hItem = GetDlgItem32(hwnd, 100);
120 GetWindowRect32(hItem, &textrect);
121 MapWindowPoints32(0, hwnd, (LPPOINT32)&textrect, 2);
123 GetClientRect32(hItem, &rect);
124 hdc = GetDC32(hItem);
125 lRet = DrawText32A( hdc, lpmb->text, -1, &rect,
126 DT_LEFT | DT_EXPANDTABS | DT_WORDBREAK | DT_CALCRECT);
127 theight = rect.bottom - rect.top;
128 tiheight = 16 + MAX(iheight, theight);
129 ReleaseDC32(hItem, hdc);
131 /* Position the text */
132 SetWindowPos32(hItem, 0, textrect.left, (tiheight - theight) / 2,
133 rect.right - rect.left, theight,
134 SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOREDRAW);
136 /* Position the icon */
137 hItem = GetDlgItem32(hwnd, 1088);
138 GetWindowRect32(hItem, &rect);
139 MapWindowPoints32(0, hwnd, (LPPOINT32)&rect, 2);
140 SetWindowPos32(hItem, 0, rect.left, (tiheight - iheight) / 2, 0, 0,
141 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOREDRAW);
143 /* Resize the window */
144 SetWindowPos32(hwnd, 0, 0, 0, wwidth, 8 + tiheight + bheight + borheight,
145 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOREDRAW);
147 /* Position the buttons */
148 bpos = (wwidth - bwidth * buttons) / 2;
149 GetWindowRect32(GetDlgItem32(hwnd, 1), &rect);
150 for (buttons = i = 0; i < 7; i++) {
151 /* some arithmetic to get the right order for YesNoCancel windows */
152 hItem = GetDlgItem32(hwnd, (i + 5) % 7 + 1);
153 if (GetWindowLong32A(hItem, GWL_STYLE) & WS_VISIBLE) {
154 if (buttons++ == ((lpmb->type & MB_DEFMASK) >> 8)) {
155 SetFocus32(hItem);
156 SendMessage32A( hItem, BM_SETSTYLE32, BS_DEFPUSHBUTTON, TRUE );
158 SetWindowPos32(hItem, 0, bpos, tiheight, 0, 0,
159 SWP_NOSIZE|SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOREDRAW);
160 bpos += bwidth;
163 return 0;
164 break;
166 case WM_COMMAND:
167 switch (wParam)
169 case IDOK:
170 case IDCANCEL:
171 case IDABORT:
172 case IDRETRY:
173 case IDIGNORE:
174 case IDYES:
175 case IDNO:
176 EndDialog(hwnd, wParam);
177 break;
179 break;
181 return 0;
185 /**************************************************************************
186 * MessageBox16 (USER.1)
188 INT16 MessageBox16( HWND16 hwnd, LPCSTR text, LPCSTR title, UINT16 type )
190 return MessageBox32A( hwnd, text, title, type );
194 /**************************************************************************
195 * MessageBox32A (USER32.390)
197 INT32 MessageBox32A( HWND32 hWnd, LPCSTR text, LPCSTR title, UINT32 type )
199 MSGBOX mbox;
201 if (!text) text="<WINE-NULL>";
202 if (!title) title="<WINE-NULL>";
203 mbox.title = title;
204 mbox.text = text;
205 mbox.type = type;
206 return DialogBoxIndirectParam32A( WIN_GetWindowInstance(hWnd),
207 SYSRES_GetResPtr( SYSRES_DIALOG_MSGBOX ),
208 hWnd, MSGBOX_DlgProc, (LPARAM)&mbox );
212 /**************************************************************************
213 * MessageBox32W (USER32.395)
215 INT32 MessageBox32W( HWND32 hwnd, LPCWSTR text, LPCWSTR title, 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
230 MessageBoxEx32A(HWND32 hWnd,LPCSTR text,LPCSTR title,UINT32 type,WORD langid) {
231 /* ignore language id for now */
232 return MessageBox32A(hWnd,text,title,type);
235 /**************************************************************************
236 * MessageBoxEx32W (USER32.392)
238 INT32
239 MessageBoxEx32W(HWND32 hWnd,LPCWSTR text,LPCWSTR title,UINT32 type,WORD langid)
241 /* ignore language id for now */
242 return MessageBox32W(hWnd,text,title,type);
246 /**************************************************************************
247 * FatalAppExit16 (KERNEL.137)
249 void FatalAppExit16( UINT16 action, LPCSTR str )
251 FatalAppExit32A( action, str );
255 /**************************************************************************
256 * FatalAppExit32A (KERNEL32.108)
258 void FatalAppExit32A( UINT32 action, LPCSTR str )
260 MessageBox32A( 0, str, NULL, MB_SYSTEMMODAL | MB_OK );
261 TASK_KillCurrentTask(0);
265 /**************************************************************************
266 * FatalAppExit32W (KERNEL32.109)
268 void FatalAppExit32W( UINT32 action, LPCWSTR str )
270 MessageBox32W( 0, str, NULL, MB_SYSTEMMODAL | MB_OK );
271 TASK_KillCurrentTask(0);