- merge audio headers
[reactos.git] / dll / cpl / console / layout.c
1 /*
2 * PROJECT: ReactOS Console Configuration DLL
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: dll/win32/console/layout.c
5 * PURPOSE: displays layout dialog
6 * PROGRAMMERS: Johannes Anderwald (johannes.anderwald@student.tugraz.at)
7 */
8
9 #include "console.h"
10
11
12
13 void PaintConsole(LPDRAWITEMSTRUCT drawItem, PConsoleInfo pConInfo)
14 {
15 HBRUSH hBrush;
16 RECT cRect, fRect;
17 DWORD startx, starty;
18 DWORD endx, endy;
19 DWORD sizex, sizey;
20
21 FillRect(drawItem->hDC, &drawItem->rcItem, GetSysColorBrush(COLOR_BACKGROUND));
22
23 sizex = drawItem->rcItem.right - drawItem->rcItem.left;
24 sizey = drawItem->rcItem.bottom - drawItem->rcItem.top;
25
26 if (pConInfo->WindowPosition == UINT_MAX)
27 {
28 startx = sizex / 3;
29 starty = sizey / 3;
30 }
31 else
32 {
33 //TODO
34 // calculate pos correctly when console centered
35 startx = sizex / 3;
36 starty = sizey / 3;
37 }
38
39 //TODO
40 // strech console when bold fonts are selected
41 endx = drawItem->rcItem.right - startx + 15;
42 endy = starty + sizey / 3;
43
44 /* draw console size */
45 SetRect(&cRect, startx, starty, endx, endy);
46 FillRect(drawItem->hDC, &cRect, GetSysColorBrush(COLOR_WINDOWFRAME));
47
48 /* draw console border */
49 SetRect(&fRect, startx + 1, starty + 1, cRect.right - 1, cRect.bottom - 1);
50 FrameRect(drawItem->hDC, &fRect, GetSysColorBrush(COLOR_ACTIVEBORDER));
51
52 /* draw left box */
53 SetRect(&fRect, startx + 3, starty + 3, startx + 5, starty + 5);
54 FillRect(drawItem->hDC, &fRect, GetSysColorBrush(COLOR_ACTIVEBORDER));
55
56 /* draw window title */
57 SetRect(&fRect, startx + 7, starty + 3, cRect.right - 9, starty + 5);
58 FillRect(drawItem->hDC, &fRect, GetSysColorBrush(COLOR_ACTIVECAPTION));
59
60 /* draw first right box */
61 SetRect(&fRect, fRect.right + 1, starty + 3, fRect.right + 3, starty + 5);
62 FillRect(drawItem->hDC, &fRect, GetSysColorBrush(COLOR_ACTIVEBORDER));
63
64 /* draw second right box */
65 SetRect(&fRect, fRect.right + 1, starty + 3, fRect.right + 3, starty + 5);
66 FillRect(drawItem->hDC, &fRect, GetSysColorBrush(COLOR_ACTIVEBORDER));
67
68 /* draw scrollbar */
69 SetRect(&fRect, cRect.right - 5, fRect.bottom + 1, cRect.right - 3, cRect.bottom - 3);
70 FillRect(drawItem->hDC, &fRect, GetSysColorBrush(COLOR_SCROLLBAR));
71
72 /* draw console background */
73 hBrush = CreateSolidBrush(pConInfo->ScreenBackground);
74 SetRect(&fRect, startx + 3, starty + 6, cRect.right - 6, cRect.bottom - 3);
75 FillRect(drawItem->hDC, &fRect, hBrush);
76 DeleteObject((HGDIOBJ)hBrush);
77 }
78
79 void PaintText(LPDRAWITEMSTRUCT drawItem, PConsoleInfo pConInfo)
80 {
81 COLORREF pbkColor, ptColor;
82 COLORREF nbkColor, ntColor;
83 HBRUSH hBrush = NULL;
84 TCHAR szText[1024];
85
86 ZeroMemory(szText, sizeof(szText));
87 LoadString(hApplet, IDS_SCREEN_TEXT, szText, sizeof(szText) / sizeof(TCHAR));
88
89 if (drawItem->CtlID == IDC_STATIC_SCREEN_COLOR)
90 {
91 nbkColor = pConInfo->ScreenBackground;
92 hBrush = CreateSolidBrush(nbkColor);
93 ntColor = pConInfo->ScreenText;
94 }
95 else if (drawItem->CtlID == IDC_STATIC_POPUP_COLOR)
96 {
97 nbkColor = pConInfo->PopupBackground;
98 hBrush = CreateSolidBrush(nbkColor);
99 ntColor = pConInfo->PopupText;
100 }
101
102 if (!hBrush)
103 {
104 return;
105 }
106
107 FillRect(drawItem->hDC, &drawItem->rcItem, hBrush);
108 if (ntColor == nbkColor)
109 {
110 /* text has same color -> invisible */
111 return;
112 }
113
114 ptColor = SetTextColor(drawItem->hDC, ntColor);
115 pbkColor = SetBkColor(drawItem->hDC, nbkColor);
116 DrawText(drawItem->hDC, szText, _tcslen(szText), &drawItem->rcItem, 0);
117 SetTextColor(drawItem->hDC, ptColor);
118 SetBkColor(drawItem->hDC, pbkColor);
119 DeleteObject((HGDIOBJ)hBrush);
120 }
121
122
123
124 INT_PTR
125 CALLBACK
126 LayoutProc(
127 HWND hwndDlg,
128 UINT uMsg,
129 WPARAM wParam,
130 LPARAM lParam
131 )
132 {
133 LPNMUPDOWN lpnmud;
134 LPPSHNOTIFY lppsn;
135 PConsoleInfo pConInfo = (PConsoleInfo)GetWindowLongPtr(hwndDlg, DWLP_USER);
136
137 UNREFERENCED_PARAMETER(hwndDlg);
138 UNREFERENCED_PARAMETER(wParam);
139
140 switch(uMsg)
141 {
142 case WM_INITDIALOG:
143 {
144 DWORD xres, yres;
145 HDC hDC;
146 pConInfo = (PConsoleInfo) ((LPPROPSHEETPAGE)lParam)->lParam;
147 SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)pConInfo);
148 SetDlgItemInt(hwndDlg, IDC_EDIT_SCREEN_BUFFER_HEIGHT, HIWORD(pConInfo->ScreenBuffer), FALSE);
149 SetDlgItemInt(hwndDlg, IDC_EDIT_SCREEN_BUFFER_WIDTH, LOWORD(pConInfo->ScreenBuffer), FALSE);
150 SetDlgItemInt(hwndDlg, IDC_EDIT_WINDOW_SIZE_HEIGHT, HIWORD(pConInfo->WindowSize), FALSE);
151 SetDlgItemInt(hwndDlg, IDC_EDIT_WINDOW_SIZE_WIDTH, LOWORD(pConInfo->WindowSize), FALSE);
152 SendMessage(GetDlgItem(hwndDlg, IDC_UPDOWN_SCREEN_BUFFER_HEIGHT), UDM_SETRANGE, 0, (LPARAM)MAKELONG(9999, 1));
153 SendMessage(GetDlgItem(hwndDlg, IDC_UPDOWN_SCREEN_BUFFER_WIDTH), UDM_SETRANGE, 0, (LPARAM)MAKELONG(9999, 1));
154 SendMessage(GetDlgItem(hwndDlg, IDC_UPDOWN_WINDOW_SIZE_HEIGHT), UDM_SETRANGE, 0, (LPARAM)MAKELONG(9999, 1));
155 SendMessage(GetDlgItem(hwndDlg, IDC_UPDOWN_WINDOW_SIZE_WIDTH), UDM_SETRANGE, 0, (LPARAM)MAKELONG(9999, 1));
156
157 hDC = GetDC(NULL);
158 xres = GetDeviceCaps(hDC, HORZRES);
159 yres = GetDeviceCaps(hDC, VERTRES);
160 SendMessage(GetDlgItem(hwndDlg, IDC_UPDOWN_WINDOW_POS_LEFT), UDM_SETRANGE, 0, (LPARAM)MAKELONG(xres, 0));
161 SendMessage(GetDlgItem(hwndDlg, IDC_UPDOWN_WINDOW_POS_TOP), UDM_SETRANGE, 0, (LPARAM)MAKELONG(yres, 0));
162
163 if (pConInfo->WindowPosition != MAXDWORD)
164 {
165 SetDlgItemInt(hwndDlg, IDC_EDIT_WINDOW_POS_LEFT, LOWORD(pConInfo->WindowPosition), FALSE);
166 SetDlgItemInt(hwndDlg, IDC_EDIT_WINDOW_POS_TOP, HIWORD(pConInfo->WindowPosition), FALSE);
167 }
168 else
169 {
170 //FIXME calculate window pos from xres, yres
171 SetDlgItemInt(hwndDlg, IDC_EDIT_WINDOW_POS_LEFT, 88, FALSE);
172 SetDlgItemInt(hwndDlg, IDC_EDIT_WINDOW_POS_TOP, 88, FALSE);
173 EnableWindow(GetDlgItem(hwndDlg, IDC_EDIT_WINDOW_POS_LEFT), FALSE);
174 EnableWindow(GetDlgItem(hwndDlg, IDC_EDIT_WINDOW_POS_TOP), FALSE);
175 EnableWindow(GetDlgItem(hwndDlg, IDC_UPDOWN_WINDOW_POS_LEFT), FALSE);
176 EnableWindow(GetDlgItem(hwndDlg, IDC_UPDOWN_WINDOW_POS_TOP), FALSE);
177 SendMessage(GetDlgItem(hwndDlg, IDC_CHECK_SYSTEM_POS_WINDOW), BM_SETCHECK, (WPARAM)BST_CHECKED, 0);
178 }
179
180 return TRUE;
181 }
182 case WM_DRAWITEM:
183 {
184 PaintConsole((LPDRAWITEMSTRUCT)lParam, pConInfo);
185 return TRUE;
186 }
187 case WM_NOTIFY:
188 {
189 lpnmud = (LPNMUPDOWN) lParam;
190 lppsn = (LPPSHNOTIFY) lParam;
191
192 if (lppsn->hdr.code == UDN_DELTAPOS)
193 {
194 DWORD wheight, wwidth;
195 DWORD sheight, swidth;
196 DWORD left, top;
197
198 if (lppsn->hdr.idFrom == IDC_UPDOWN_WINDOW_SIZE_WIDTH)
199 {
200 wwidth = lpnmud->iPos + lpnmud->iDelta;
201 }
202 else
203 {
204 wwidth = GetDlgItemInt(hwndDlg, IDC_EDIT_WINDOW_SIZE_WIDTH, NULL, FALSE);
205 }
206
207 if (lppsn->hdr.idFrom == IDC_UPDOWN_WINDOW_SIZE_HEIGHT)
208 {
209 wheight = lpnmud->iPos + lpnmud->iDelta;
210 }
211 else
212 {
213 wheight = GetDlgItemInt(hwndDlg, IDC_EDIT_WINDOW_SIZE_HEIGHT, NULL, FALSE);
214 }
215
216 if (lppsn->hdr.idFrom == IDC_UPDOWN_SCREEN_BUFFER_WIDTH)
217 {
218 swidth = lpnmud->iPos + lpnmud->iDelta;
219 }
220 else
221 {
222 swidth = GetDlgItemInt(hwndDlg, IDC_EDIT_SCREEN_BUFFER_WIDTH, NULL, FALSE);
223 }
224
225 if (lppsn->hdr.idFrom == IDC_UPDOWN_SCREEN_BUFFER_HEIGHT)
226 {
227 sheight = lpnmud->iPos + lpnmud->iDelta;
228 }
229 else
230 {
231 sheight = GetDlgItemInt(hwndDlg, IDC_EDIT_SCREEN_BUFFER_HEIGHT, NULL, FALSE);
232 }
233
234 if (lppsn->hdr.idFrom == IDC_UPDOWN_WINDOW_POS_LEFT)
235 {
236 left = lpnmud->iPos + lpnmud->iDelta;
237 }
238 else
239 {
240 left = GetDlgItemInt(hwndDlg, IDC_EDIT_WINDOW_POS_LEFT, NULL, FALSE);
241 }
242
243 if (lppsn->hdr.idFrom == IDC_UPDOWN_WINDOW_POS_TOP)
244 {
245 top = lpnmud->iPos + lpnmud->iDelta;
246 }
247 else
248 {
249 top = GetDlgItemInt(hwndDlg, IDC_EDIT_WINDOW_POS_TOP, NULL, FALSE);
250 }
251
252 if (lppsn->hdr.idFrom == IDC_UPDOWN_WINDOW_SIZE_WIDTH || lppsn->hdr.idFrom == IDC_UPDOWN_WINDOW_SIZE_HEIGHT)
253 {
254 /* automatically adjust screen buffer size when window size enlarges */
255 if (wwidth >= swidth)
256 {
257 SetDlgItemInt(hwndDlg, IDC_EDIT_SCREEN_BUFFER_WIDTH, wwidth, TRUE);
258 swidth = wwidth;
259 }
260
261 if (wheight >= sheight)
262 {
263 SetDlgItemInt(hwndDlg, IDC_EDIT_SCREEN_BUFFER_HEIGHT, wheight, TRUE);
264 sheight = wheight;
265 }
266 }
267 swidth = max(swidth, 1);
268 sheight = max(sheight, 1);
269
270 if (lppsn->hdr.idFrom == IDC_UPDOWN_SCREEN_BUFFER_WIDTH || lppsn->hdr.idFrom == IDC_UPDOWN_SCREEN_BUFFER_HEIGHT)
271 {
272 /* automatically adjust window size when screen buffer decreases */
273 if (wwidth > swidth)
274 {
275 SetDlgItemInt(hwndDlg, IDC_EDIT_WINDOW_SIZE_WIDTH, swidth, TRUE);
276 wwidth = swidth;
277 }
278
279 if (wheight > sheight)
280 {
281 SetDlgItemInt(hwndDlg, IDC_EDIT_WINDOW_SIZE_HEIGHT, sheight, TRUE);
282 wheight = sheight;
283 }
284 }
285
286 pConInfo->ScreenBuffer = MAKELONG(swidth, sheight);
287 pConInfo->WindowSize = MAKELONG(wwidth, wheight);
288 pConInfo->WindowPosition = MAKELONG(left, top);
289 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
290 }
291 break;
292 }
293 case WM_COMMAND:
294 {
295 switch(LOWORD(wParam))
296 {
297 case IDC_EDIT_SCREEN_BUFFER_WIDTH:
298 case IDC_EDIT_SCREEN_BUFFER_HEIGHT:
299 case IDC_EDIT_WINDOW_SIZE_WIDTH:
300 case IDC_UPDOWN_WINDOW_SIZE_HEIGHT:
301 case IDC_EDIT_WINDOW_POS_LEFT:
302 case IDC_EDIT_WINDOW_POS_TOP:
303 {
304 if (HIWORD(wParam) == EN_KILLFOCUS)
305 {
306 DWORD wheight, wwidth;
307 DWORD sheight, swidth;
308 DWORD left, top;
309
310 wwidth = GetDlgItemInt(hwndDlg, IDC_EDIT_WINDOW_SIZE_WIDTH, NULL, FALSE);
311 wheight = GetDlgItemInt(hwndDlg, IDC_EDIT_WINDOW_SIZE_HEIGHT, NULL, FALSE);
312 swidth = GetDlgItemInt(hwndDlg, IDC_EDIT_SCREEN_BUFFER_WIDTH, NULL, FALSE);
313 sheight = GetDlgItemInt(hwndDlg, IDC_EDIT_SCREEN_BUFFER_HEIGHT, NULL, FALSE);
314 left = GetDlgItemInt(hwndDlg, IDC_EDIT_WINDOW_POS_LEFT, NULL, FALSE);
315 top = GetDlgItemInt(hwndDlg, IDC_EDIT_WINDOW_POS_TOP, NULL, FALSE);
316
317 swidth = max(swidth, 1);
318 sheight = max(sheight, 1);
319
320 /* automatically adjust window size when screen buffer decreases */
321 if (wwidth > swidth)
322 {
323 SetDlgItemInt(hwndDlg, IDC_EDIT_WINDOW_SIZE_WIDTH, swidth, TRUE);
324 wwidth = swidth;
325 }
326
327 if (wheight > sheight)
328 {
329 SetDlgItemInt(hwndDlg, IDC_EDIT_WINDOW_SIZE_HEIGHT, sheight, TRUE);
330 wheight = sheight;
331 }
332
333
334 pConInfo->ScreenBuffer = MAKELONG(swidth, sheight);
335 pConInfo->WindowSize = MAKELONG(wwidth, wheight);
336 pConInfo->WindowPosition = MAKELONG(left, top);
337
338 PropSheet_Changed(GetParent(hwndDlg), hwndDlg);
339 }
340 break;
341 }
342
343 case IDC_CHECK_SYSTEM_POS_WINDOW:
344 {
345 LONG res = SendMessage((HWND)lParam, BM_GETCHECK, 0, 0);
346 if (res == BST_CHECKED)
347 {
348 ULONG left, top;
349
350 left = GetDlgItemInt(hwndDlg, IDC_EDIT_WINDOW_POS_LEFT, NULL, FALSE);
351 top = GetDlgItemInt(hwndDlg, IDC_EDIT_WINDOW_POS_TOP, NULL, FALSE);
352 pConInfo->WindowPosition = MAKELONG(left, top);
353 SendMessage((HWND)lParam, BM_SETCHECK, (WPARAM)BST_UNCHECKED, 0);
354 EnableWindow(GetDlgItem(hwndDlg, IDC_EDIT_WINDOW_POS_LEFT), TRUE);
355 EnableWindow(GetDlgItem(hwndDlg, IDC_EDIT_WINDOW_POS_TOP), TRUE);
356 EnableWindow(GetDlgItem(hwndDlg, IDC_UPDOWN_WINDOW_POS_LEFT), TRUE);
357 EnableWindow(GetDlgItem(hwndDlg, IDC_UPDOWN_WINDOW_POS_TOP), TRUE);
358 }
359 else if (res == BST_UNCHECKED)
360 {
361 pConInfo->WindowPosition = UINT_MAX;
362 SendMessage((HWND)lParam, BM_SETCHECK, (WPARAM)BST_CHECKED, 0);
363 EnableWindow(GetDlgItem(hwndDlg, IDC_EDIT_WINDOW_POS_LEFT), FALSE);
364 EnableWindow(GetDlgItem(hwndDlg, IDC_EDIT_WINDOW_POS_TOP), FALSE);
365 EnableWindow(GetDlgItem(hwndDlg, IDC_UPDOWN_WINDOW_POS_LEFT), FALSE);
366 EnableWindow(GetDlgItem(hwndDlg, IDC_UPDOWN_WINDOW_POS_TOP), FALSE);
367 }
368 }
369 }
370 }
371 default:
372 break;
373 }
374
375 return FALSE;
376 }