blob: c8215fdc6a7d7a7724af9f1d4747cc84c7f64eee [file] [log] [blame]
Alexandre Julliard2787be81995-05-22 18:23:01 +00001/*
2 * Message boxes
3 *
4 * Copyright 1995 Bernd Schmidt
5 *
6 */
7
8#include "windows.h"
9#include "dlgs.h"
Alexandre Julliardc981d0b1996-03-31 16:40:13 +000010#include "module.h"
Alexandre Julliardaf0bae51995-10-03 17:06:08 +000011#include "win.h"
Alexandre Julliardd7d4fdf1995-12-26 15:05:24 +000012#include "resource.h"
Alexandre Julliard2787be81995-05-22 18:23:01 +000013#include "task.h"
14
15typedef struct {
Alexandre Julliard7e56f681996-01-31 19:02:28 +000016 LPCSTR title;
17 LPCSTR text;
Alexandre Julliard2787be81995-05-22 18:23:01 +000018 WORD type;
19} MSGBOX, *LPMSGBOX;
20
Alexandre Julliardaf0bae51995-10-03 17:06:08 +000021LRESULT SystemMessageBoxProc(HWND hwnd,UINT message,WPARAM wParam,LPARAM lParam)
Alexandre Julliard2787be81995-05-22 18:23:01 +000022{
23 LPMSGBOX lpmb;
24 RECT rect, textrect;
25 HWND hItem;
26 HDC hdc;
27 LONG lRet;
28 int i, buttons, bwidth, bheight, theight, wwidth, bpos;
29 int borheight, iheight, tiheight;
30
31 switch(message) {
32 case WM_INITDIALOG:
33 lpmb = (LPMSGBOX)lParam;
34 if (lpmb->title != NULL) {
35 SetWindowText(hwnd, lpmb->title);
36 }
37 SetWindowText(GetDlgItem(hwnd, 100), lpmb->text);
38 /* Hide not selected buttons */
39 switch(lpmb->type & MB_TYPEMASK) {
40 case MB_OK:
41 ShowWindow(GetDlgItem(hwnd, 2), SW_HIDE);
42 /* fall through */
43 case MB_OKCANCEL:
44 ShowWindow(GetDlgItem(hwnd, 3), SW_HIDE);
45 ShowWindow(GetDlgItem(hwnd, 4), SW_HIDE);
46 ShowWindow(GetDlgItem(hwnd, 5), SW_HIDE);
47 ShowWindow(GetDlgItem(hwnd, 6), SW_HIDE);
48 ShowWindow(GetDlgItem(hwnd, 7), SW_HIDE);
49 break;
50 case MB_ABORTRETRYIGNORE:
51 ShowWindow(GetDlgItem(hwnd, 1), SW_HIDE);
52 ShowWindow(GetDlgItem(hwnd, 2), SW_HIDE);
53 ShowWindow(GetDlgItem(hwnd, 6), SW_HIDE);
54 ShowWindow(GetDlgItem(hwnd, 7), SW_HIDE);
55 break;
56 case MB_YESNO:
57 ShowWindow(GetDlgItem(hwnd, 2), SW_HIDE);
58 /* fall through */
59 case MB_YESNOCANCEL:
60 ShowWindow(GetDlgItem(hwnd, 1), SW_HIDE);
61 ShowWindow(GetDlgItem(hwnd, 3), SW_HIDE);
62 ShowWindow(GetDlgItem(hwnd, 4), SW_HIDE);
63 ShowWindow(GetDlgItem(hwnd, 5), SW_HIDE);
64 break;
65 }
66 /* Set the icon */
67 switch(lpmb->type & MB_ICONMASK) {
68 case MB_ICONEXCLAMATION:
Alexandre Julliardaf0bae51995-10-03 17:06:08 +000069 SendDlgItemMessage(hwnd, stc1, STM_SETICON,
70 (WPARAM)LoadIcon(0, IDI_EXCLAMATION), 0);
Alexandre Julliard2787be81995-05-22 18:23:01 +000071 break;
72 case MB_ICONQUESTION:
Alexandre Julliardaf0bae51995-10-03 17:06:08 +000073 SendDlgItemMessage(hwnd, stc1, STM_SETICON,
74 (WPARAM)LoadIcon(0, IDI_QUESTION), 0);
Alexandre Julliard2787be81995-05-22 18:23:01 +000075 break;
76 case MB_ICONASTERISK:
Alexandre Julliardaf0bae51995-10-03 17:06:08 +000077 SendDlgItemMessage(hwnd, stc1, STM_SETICON,
78 (WPARAM)LoadIcon(0, IDI_ASTERISK), 0);
Alexandre Julliard2787be81995-05-22 18:23:01 +000079 break;
80 case MB_ICONHAND:
Alexandre Julliardbd34d4f1995-06-20 19:08:12 +000081 default:
Alexandre Julliardaf0bae51995-10-03 17:06:08 +000082 SendDlgItemMessage(hwnd, stc1, STM_SETICON,
83 (WPARAM)LoadIcon(0, IDI_HAND), 0);
Alexandre Julliard2787be81995-05-22 18:23:01 +000084 break;
85 }
86
87 /* Position everything */
88 GetWindowRect(hwnd, &rect);
89 borheight = rect.bottom - rect.top;
90 wwidth = rect.right - rect.left;
91 GetClientRect(hwnd, &rect);
92 borheight -= rect.bottom - rect.top;
93
94 /* Get the icon height */
95 GetWindowRect(GetDlgItem(hwnd, 1088), &rect);
96 iheight = rect.bottom - rect.top;
97
98 /* Get the number of visible buttons and their width */
99 GetWindowRect(GetDlgItem(hwnd, 2), &rect);
100 bheight = rect.bottom - rect.top;
101 bwidth = rect.left;
102 GetWindowRect(GetDlgItem(hwnd, 1), &rect);
103 bwidth -= rect.left;
104 for (buttons = 0, i = 1; i < 8; i++) {
105 hItem = GetDlgItem(hwnd, i);
106 if (GetWindowLong(hItem, GWL_STYLE) & WS_VISIBLE) {
107 buttons++;
108 }
109 }
110
111 /* Get the text size */
112 hItem = GetDlgItem(hwnd, 100);
113 GetWindowRect(hItem, &textrect);
114 MapWindowPoints(0, hwnd, (LPPOINT)&textrect, 2);
115
116 GetClientRect(hItem, &rect);
117 hdc = GetDC(hItem);
118 lRet = DrawText(hdc, lpmb->text, -1, &rect,
119 DT_LEFT | DT_EXPANDTABS | DT_WORDBREAK | DT_CALCRECT);
120 theight = rect.bottom - rect.top;
Alexandre Julliard902da691995-11-05 14:39:02 +0000121 tiheight = 16 + MAX(iheight, theight);
Alexandre Julliard2787be81995-05-22 18:23:01 +0000122 ReleaseDC(hItem, hdc);
123
124 /* Position the text */
125 SetWindowPos(hItem, 0, textrect.left, (tiheight - theight) / 2,
126 rect.right - rect.left, theight,
127 SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOREDRAW);
128
129 /* Position the icon */
130 hItem = GetDlgItem(hwnd, 1088);
131 GetWindowRect(hItem, &rect);
132 MapWindowPoints(0, hwnd, (LPPOINT)&rect, 2);
133 SetWindowPos(hItem, 0, rect.left, (tiheight - iheight) / 2, 0, 0,
134 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOREDRAW);
135
136 /* Resize the window */
137 SetWindowPos(hwnd, 0, 0, 0, wwidth, 8 + tiheight + bheight + borheight,
138 SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOREDRAW);
139
140 /* Position the buttons */
141 bpos = (wwidth - bwidth * buttons) / 2;
142 GetWindowRect(GetDlgItem(hwnd, 1), &rect);
143 for (buttons = i = 0; i < 7; i++) {
144 /* some arithmetic to get the right order for YesNoCancel windows */
145 hItem = GetDlgItem(hwnd, (i + 5) % 7 + 1);
146 if (GetWindowLong(hItem, GWL_STYLE) & WS_VISIBLE) {
147 if (buttons++ == ((lpmb->type & MB_DEFMASK) >> 8)) {
148 SetFocus(hItem);
149 SendMessage(hItem, BM_SETSTYLE, BS_DEFPUSHBUTTON, TRUE);
150 }
151 SetWindowPos(hItem, 0, bpos, tiheight, 0, 0,
152 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOREDRAW);
153 bpos += bwidth;
154 }
155 }
156 return 0;
157 break;
158
159 case WM_COMMAND:
160 switch (wParam) {
161 case IDOK:
162 case IDCANCEL:
163 case IDABORT:
164 case IDRETRY:
165 case IDIGNORE:
166 case IDYES:
167 case IDNO:
168 EndDialog(hwnd, wParam);
169 break;
170 }
171 break;
172 }
173 return 0;
174}
175
176/**************************************************************************
177 * MessageBox [USER.1]
178 */
179
Alexandre Julliard7e56f681996-01-31 19:02:28 +0000180int MessageBox(HWND hWnd, LPCSTR text, LPCSTR title, WORD type)
Alexandre Julliard2787be81995-05-22 18:23:01 +0000181{
Alexandre Julliardff8331e1995-09-18 11:19:54 +0000182 HANDLE handle;
183 MSGBOX mbox;
184 int ret;
185 DWORD WineProc,Win16Proc,Win32Proc;
Alexandre Julliard2787be81995-05-22 18:23:01 +0000186
Alexandre Julliardff8331e1995-09-18 11:19:54 +0000187 mbox.title = title;
188 mbox.text = text;
189 mbox.type = type;
190
Alexandre Julliardd7d4fdf1995-12-26 15:05:24 +0000191 handle = SYSRES_LoadResource( SYSRES_DIALOG_MSGBOX );
Alexandre Julliardff8331e1995-09-18 11:19:54 +0000192 if (!handle) return 0;
Alexandre Julliardaf0bae51995-10-03 17:06:08 +0000193 ret = DialogBoxIndirectParam( WIN_GetWindowInstance(hWnd),
Alexandre Julliardff8331e1995-09-18 11:19:54 +0000194 handle, hWnd,
Alexandre Julliardc981d0b1996-03-31 16:40:13 +0000195 MODULE_GetWndProcEntry16("SystemMessageBoxProc"),
Alexandre Julliardff8331e1995-09-18 11:19:54 +0000196 (LONG)&mbox );
Alexandre Julliardd7d4fdf1995-12-26 15:05:24 +0000197 SYSRES_FreeResource( handle );
Alexandre Julliardff8331e1995-09-18 11:19:54 +0000198 return ret;
Alexandre Julliard2787be81995-05-22 18:23:01 +0000199}
200
201/**************************************************************************
202 * FatalAppExit [USER.137]
203 */
204
Alexandre Julliard7e56f681996-01-31 19:02:28 +0000205void FatalAppExit(UINT fuAction, LPCSTR str)
Alexandre Julliard2787be81995-05-22 18:23:01 +0000206{
207 MessageBox(0, str, NULL, MB_SYSTEMMODAL | MB_OK);
208 TASK_KillCurrentTask(0);
209}