blob: a2cb5bea708b8955d5bc7c43b8705b30abcc293b [file] [log] [blame]
Alexandre Julliard2787be81995-05-22 18:23:01 +00001/*
2 * Message boxes
3 *
4 * Copyright 1995 Bernd Schmidt
Alexandre Julliard2787be81995-05-22 18:23:01 +00005 */
6
Alexandre Julliardb1bac321996-12-15 19:45:59 +00007#include <stdio.h>
Alexandre Julliard2787be81995-05-22 18:23:01 +00008#include "windows.h"
9#include "dlgs.h"
Alexandre Julliard7ebe1a41996-12-22 18:27:48 +000010#include "heap.h"
Alexandre Julliardc981d0b1996-03-31 16:40:13 +000011#include "module.h"
Alexandre Julliardaf0bae51995-10-03 17:06:08 +000012#include "win.h"
Alexandre Julliardd7d4fdf1995-12-26 15:05:24 +000013#include "resource.h"
Alexandre Julliard2787be81995-05-22 18:23:01 +000014#include "task.h"
15
Alexandre Julliard9ea19e51997-01-01 17:29:55 +000016typedef struct
17{
18 LPCSTR title;
19 LPCSTR text;
20 UINT32 type;
Alexandre Julliard2787be81995-05-22 18:23:01 +000021} MSGBOX, *LPMSGBOX;
22
Alexandre Julliard9ea19e51997-01-01 17:29:55 +000023
24/**************************************************************************
25 * MSGBOX_DlgProc
26 *
27 * Dialog procedure for message boxes.
28 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +000029static LRESULT CALLBACK MSGBOX_DlgProc( HWND32 hwnd, UINT32 message,
30 WPARAM32 wParam, LPARAM lParam )
Alexandre Julliard2787be81995-05-22 18:23:01 +000031{
32 LPMSGBOX lpmb;
Alexandre Julliard9ea19e51997-01-01 17:29:55 +000033 RECT32 rect, textrect;
34 HWND32 hItem;
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +000035 HDC32 hdc;
Alexandre Julliard9ea19e51997-01-01 17:29:55 +000036 LRESULT lRet;
Alexandre Julliard2787be81995-05-22 18:23:01 +000037 int i, buttons, bwidth, bheight, theight, wwidth, bpos;
38 int borheight, iheight, tiheight;
39
40 switch(message) {
41 case WM_INITDIALOG:
42 lpmb = (LPMSGBOX)lParam;
Alexandre Julliard2d93d001996-05-21 15:01:41 +000043 if (lpmb->title) SetWindowText32A(hwnd, lpmb->title);
Alexandre Julliard01d63461997-01-20 19:43:45 +000044 SetWindowText32A(GetDlgItem32(hwnd, 100), lpmb->text);
Alexandre Julliard2787be81995-05-22 18:23:01 +000045 /* Hide not selected buttons */
46 switch(lpmb->type & MB_TYPEMASK) {
47 case MB_OK:
Alexandre Julliard01d63461997-01-20 19:43:45 +000048 ShowWindow32(GetDlgItem32(hwnd, 2), SW_HIDE);
Alexandre Julliard2787be81995-05-22 18:23:01 +000049 /* fall through */
50 case MB_OKCANCEL:
Alexandre Julliard01d63461997-01-20 19:43:45 +000051 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);
Alexandre Julliard2787be81995-05-22 18:23:01 +000056 break;
57 case MB_ABORTRETRYIGNORE:
Alexandre Julliard01d63461997-01-20 19:43:45 +000058 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);
Alexandre Julliard2787be81995-05-22 18:23:01 +000062 break;
63 case MB_YESNO:
Alexandre Julliard01d63461997-01-20 19:43:45 +000064 ShowWindow32(GetDlgItem32(hwnd, 2), SW_HIDE);
Alexandre Julliard2787be81995-05-22 18:23:01 +000065 /* fall through */
66 case MB_YESNOCANCEL:
Alexandre Julliard01d63461997-01-20 19:43:45 +000067 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);
Alexandre Julliard2787be81995-05-22 18:23:01 +000071 break;
72 }
73 /* Set the icon */
74 switch(lpmb->type & MB_ICONMASK) {
75 case MB_ICONEXCLAMATION:
Alexandre Julliard2d93d001996-05-21 15:01:41 +000076 SendDlgItemMessage16(hwnd, stc1, STM_SETICON,
Alexandre Julliard530ee841996-10-23 16:59:13 +000077 (WPARAM16)LoadIcon16(0, IDI_EXCLAMATION), 0);
Alexandre Julliard2787be81995-05-22 18:23:01 +000078 break;
79 case MB_ICONQUESTION:
Alexandre Julliard2d93d001996-05-21 15:01:41 +000080 SendDlgItemMessage16(hwnd, stc1, STM_SETICON,
Alexandre Julliard530ee841996-10-23 16:59:13 +000081 (WPARAM16)LoadIcon16(0, IDI_QUESTION), 0);
Alexandre Julliard2787be81995-05-22 18:23:01 +000082 break;
83 case MB_ICONASTERISK:
Alexandre Julliard2d93d001996-05-21 15:01:41 +000084 SendDlgItemMessage16(hwnd, stc1, STM_SETICON,
Alexandre Julliard530ee841996-10-23 16:59:13 +000085 (WPARAM16)LoadIcon16(0, IDI_ASTERISK), 0);
Alexandre Julliard2787be81995-05-22 18:23:01 +000086 break;
87 case MB_ICONHAND:
Alexandre Julliardbd34d4f1995-06-20 19:08:12 +000088 default:
Alexandre Julliard2d93d001996-05-21 15:01:41 +000089 SendDlgItemMessage16(hwnd, stc1, STM_SETICON,
Alexandre Julliard530ee841996-10-23 16:59:13 +000090 (WPARAM16)LoadIcon16(0, IDI_HAND), 0);
Alexandre Julliard2787be81995-05-22 18:23:01 +000091 break;
92 }
93
94 /* Position everything */
Alexandre Julliard9ea19e51997-01-01 17:29:55 +000095 GetWindowRect32(hwnd, &rect);
Alexandre Julliard2787be81995-05-22 18:23:01 +000096 borheight = rect.bottom - rect.top;
97 wwidth = rect.right - rect.left;
Alexandre Julliard9ea19e51997-01-01 17:29:55 +000098 GetClientRect32(hwnd, &rect);
Alexandre Julliard2787be81995-05-22 18:23:01 +000099 borheight -= rect.bottom - rect.top;
100
101 /* Get the icon height */
Alexandre Julliard01d63461997-01-20 19:43:45 +0000102 GetWindowRect32(GetDlgItem32(hwnd, 1088), &rect);
Alexandre Julliard2787be81995-05-22 18:23:01 +0000103 iheight = rect.bottom - rect.top;
104
105 /* Get the number of visible buttons and their width */
Alexandre Julliard01d63461997-01-20 19:43:45 +0000106 GetWindowRect32(GetDlgItem32(hwnd, 2), &rect);
Alexandre Julliard2787be81995-05-22 18:23:01 +0000107 bheight = rect.bottom - rect.top;
108 bwidth = rect.left;
Alexandre Julliard01d63461997-01-20 19:43:45 +0000109 GetWindowRect32(GetDlgItem32(hwnd, 1), &rect);
Alexandre Julliard2787be81995-05-22 18:23:01 +0000110 bwidth -= rect.left;
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000111 for (buttons = 0, i = 1; i < 8; i++)
112 {
Alexandre Julliard01d63461997-01-20 19:43:45 +0000113 hItem = GetDlgItem32(hwnd, i);
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000114 if (GetWindowLong32A(hItem, GWL_STYLE) & WS_VISIBLE) buttons++;
Alexandre Julliard2787be81995-05-22 18:23:01 +0000115 }
116
117 /* Get the text size */
Alexandre Julliard01d63461997-01-20 19:43:45 +0000118 hItem = GetDlgItem32(hwnd, 100);
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000119 GetWindowRect32(hItem, &textrect);
120 MapWindowPoints32(0, hwnd, (LPPOINT32)&textrect, 2);
Alexandre Julliard2787be81995-05-22 18:23:01 +0000121
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000122 GetClientRect32(hItem, &rect);
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000123 hdc = GetDC32(hItem);
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000124 lRet = DrawText32A( hdc, lpmb->text, -1, &rect,
125 DT_LEFT | DT_EXPANDTABS | DT_WORDBREAK | DT_CALCRECT);
Alexandre Julliard2787be81995-05-22 18:23:01 +0000126 theight = rect.bottom - rect.top;
Alexandre Julliard902da691995-11-05 14:39:02 +0000127 tiheight = 16 + MAX(iheight, theight);
Alexandre Julliard2c69f6d1996-09-28 18:11:01 +0000128 ReleaseDC32(hItem, hdc);
Alexandre Julliard2787be81995-05-22 18:23:01 +0000129
130 /* Position the text */
Alexandre Julliard01d63461997-01-20 19:43:45 +0000131 SetWindowPos32(hItem, 0, textrect.left, (tiheight - theight) / 2,
132 rect.right - rect.left, theight,
133 SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOREDRAW);
Alexandre Julliard2787be81995-05-22 18:23:01 +0000134
135 /* Position the icon */
Alexandre Julliard01d63461997-01-20 19:43:45 +0000136 hItem = GetDlgItem32(hwnd, 1088);
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000137 GetWindowRect32(hItem, &rect);
138 MapWindowPoints32(0, hwnd, (LPPOINT32)&rect, 2);
Alexandre Julliard01d63461997-01-20 19:43:45 +0000139 SetWindowPos32(hItem, 0, rect.left, (tiheight - iheight) / 2, 0, 0,
140 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOREDRAW);
Alexandre Julliard2787be81995-05-22 18:23:01 +0000141
142 /* Resize the window */
Alexandre Julliard01d63461997-01-20 19:43:45 +0000143 SetWindowPos32(hwnd, 0, 0, 0, wwidth, 8 + tiheight + bheight + borheight,
144 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOREDRAW);
Alexandre Julliard2787be81995-05-22 18:23:01 +0000145
146 /* Position the buttons */
147 bpos = (wwidth - bwidth * buttons) / 2;
Alexandre Julliard01d63461997-01-20 19:43:45 +0000148 GetWindowRect32(GetDlgItem32(hwnd, 1), &rect);
Alexandre Julliard2787be81995-05-22 18:23:01 +0000149 for (buttons = i = 0; i < 7; i++) {
150 /* some arithmetic to get the right order for YesNoCancel windows */
Alexandre Julliard01d63461997-01-20 19:43:45 +0000151 hItem = GetDlgItem32(hwnd, (i + 5) % 7 + 1);
Alexandre Julliard1e9ac791996-06-06 18:38:27 +0000152 if (GetWindowLong32A(hItem, GWL_STYLE) & WS_VISIBLE) {
Alexandre Julliard2787be81995-05-22 18:23:01 +0000153 if (buttons++ == ((lpmb->type & MB_DEFMASK) >> 8)) {
Alexandre Julliard8bbf8181996-09-13 16:50:47 +0000154 SetFocus32(hItem);
Alexandre Julliard2d93d001996-05-21 15:01:41 +0000155 SendMessage32A( hItem, BM_SETSTYLE32, BS_DEFPUSHBUTTON, TRUE );
Alexandre Julliard2787be81995-05-22 18:23:01 +0000156 }
Alexandre Julliard01d63461997-01-20 19:43:45 +0000157 SetWindowPos32(hItem, 0, bpos, tiheight, 0, 0,
158 SWP_NOSIZE|SWP_NOZORDER|SWP_NOACTIVATE|SWP_NOREDRAW);
Alexandre Julliard2787be81995-05-22 18:23:01 +0000159 bpos += bwidth;
160 }
161 }
162 return 0;
163 break;
164
165 case WM_COMMAND:
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000166 switch (wParam)
167 {
Alexandre Julliard2787be81995-05-22 18:23:01 +0000168 case IDOK:
169 case IDCANCEL:
170 case IDABORT:
171 case IDRETRY:
172 case IDIGNORE:
173 case IDYES:
174 case IDNO:
Alexandre Julliardf0cbfa01997-02-15 14:29:56 +0000175 EndDialog32(hwnd, wParam);
Alexandre Julliard2787be81995-05-22 18:23:01 +0000176 break;
177 }
178 break;
179 }
180 return 0;
181}
182
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000183
Alexandre Julliard2787be81995-05-22 18:23:01 +0000184/**************************************************************************
Alexandre Julliardb1bac321996-12-15 19:45:59 +0000185 * MessageBox16 (USER.1)
Alexandre Julliard2787be81995-05-22 18:23:01 +0000186 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000187INT16 WINAPI MessageBox16( HWND16 hwnd, LPCSTR text, LPCSTR title, UINT16 type)
Alexandre Julliardb1bac321996-12-15 19:45:59 +0000188{
189 return MessageBox32A( hwnd, text, title, type );
190}
Alexandre Julliard2787be81995-05-22 18:23:01 +0000191
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000192
Alexandre Julliardb1bac321996-12-15 19:45:59 +0000193/**************************************************************************
194 * MessageBox32A (USER32.390)
195 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000196INT32 WINAPI MessageBox32A(HWND32 hWnd, LPCSTR text, LPCSTR title, UINT32 type)
Alexandre Julliard2787be81995-05-22 18:23:01 +0000197{
Alexandre Julliardff8331e1995-09-18 11:19:54 +0000198 MSGBOX mbox;
Alexandre Julliard349a9531997-02-02 19:01:52 +0000199
200 if (!text) text="<WINE-NULL>";
201 if (!title) title="<WINE-NULL>";
Alexandre Julliardff8331e1995-09-18 11:19:54 +0000202 mbox.title = title;
203 mbox.text = text;
204 mbox.type = type;
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000205 return DialogBoxIndirectParam32A( WIN_GetWindowInstance(hWnd),
206 SYSRES_GetResPtr( SYSRES_DIALOG_MSGBOX ),
207 hWnd, MSGBOX_DlgProc, (LPARAM)&mbox );
Alexandre Julliard2787be81995-05-22 18:23:01 +0000208}
209
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000210
Alexandre Julliard2787be81995-05-22 18:23:01 +0000211/**************************************************************************
Alexandre Julliardb1bac321996-12-15 19:45:59 +0000212 * MessageBox32W (USER32.395)
213 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000214INT32 WINAPI MessageBox32W( HWND32 hwnd, LPCWSTR text, LPCWSTR title,
215 UINT32 type )
Alexandre Julliardb1bac321996-12-15 19:45:59 +0000216{
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000217 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 );
Alexandre Julliardb1bac321996-12-15 19:45:59 +0000222 return ret;
223}
224
Alexandre Julliard2787be81995-05-22 18:23:01 +0000225
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000226/**************************************************************************
Alexandre Julliard349a9531997-02-02 19:01:52 +0000227 * MessageBoxEx32A (USER32.391)
228 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000229INT32 WINAPI MessageBoxEx32A( HWND32 hWnd, LPCSTR text, LPCSTR title,
230 UINT32 type, WORD langid )
231{
Alexandre Julliard349a9531997-02-02 19:01:52 +0000232 /* ignore language id for now */
233 return MessageBox32A(hWnd,text,title,type);
234}
235
236/**************************************************************************
237 * MessageBoxEx32W (USER32.392)
238 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000239INT32 WINAPI MessageBoxEx32W( HWND32 hWnd, LPCWSTR text, LPCWSTR title,
240 UINT32 type, WORD langid )
Alexandre Julliard349a9531997-02-02 19:01:52 +0000241{
242 /* ignore language id for now */
243 return MessageBox32W(hWnd,text,title,type);
244}
245
246
247/**************************************************************************
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000248 * FatalAppExit16 (KERNEL.137)
249 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000250void WINAPI FatalAppExit16( UINT16 action, LPCSTR str )
Alexandre Julliard2787be81995-05-22 18:23:01 +0000251{
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000252 FatalAppExit32A( action, str );
253}
254
255
256/**************************************************************************
257 * FatalAppExit32A (KERNEL32.108)
258 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000259void WINAPI FatalAppExit32A( UINT32 action, LPCSTR str )
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000260{
261 MessageBox32A( 0, str, NULL, MB_SYSTEMMODAL | MB_OK );
262 TASK_KillCurrentTask(0);
263}
264
265
266/**************************************************************************
267 * FatalAppExit32W (KERNEL32.109)
268 */
Alexandre Julliard670cdc41997-08-24 16:00:30 +0000269void WINAPI FatalAppExit32W( UINT32 action, LPCWSTR str )
Alexandre Julliard9ea19e51997-01-01 17:29:55 +0000270{
271 MessageBox32W( 0, str, NULL, MB_SYSTEMMODAL | MB_OK );
272 TASK_KillCurrentTask(0);
Alexandre Julliard2787be81995-05-22 18:23:01 +0000273}
Alexandre Julliard349a9531997-02-02 19:01:52 +0000274
275