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: Layout dialog
6 * PROGRAMMERS: Johannes Anderwald (johannes.anderwald@reactos.org)
7 * Hermes Belusca-Maito (hermes.belusca@sfr.fr)
15 const WCHAR szPreviewText
[] =
16 L
"C:\\ReactOS> dir \n" \
17 L
"SYSTEM <DIR> 13-04-15 5:00a\n" \
18 L
"SYSTEM32 <DIR> 13-04-15 5:00a\n" \
19 L
"readme txt 1739 13-04-15 5:00a\n" \
20 L
"explorer exe 3329536 13-04-15 5:00a\n" \
21 L
"vgafonts cab 18736 13-04-15 5:00a\n" \
22 L
"setuplog txt 313 13-04-15 5:00a\n" \
23 L
"win ini 7005 13-04-15 5:00a\n" ;
27 PaintConsole(LPDRAWITEMSTRUCT drawItem
,
28 PCONSOLE_PROPS pConInfo
)
30 PGUI_CONSOLE_INFO GuiInfo
= pConInfo
->TerminalInfo
.TermInfo
;
37 FillRect(drawItem
->hDC
, &drawItem
->rcItem
, GetSysColorBrush(COLOR_BACKGROUND
));
39 // FIXME: Use: SM_CXSIZE, SM_CYSIZE, SM_CXVSCROLL, SM_CYHSCROLL, SM_CXMIN, SM_CYMIN, SM_CXFRAME, SM_CYFRAME
40 /* Use it for scaling */
41 sizex
= drawItem
->rcItem
.right
- drawItem
->rcItem
.left
;
42 sizey
= drawItem
->rcItem
.bottom
- drawItem
->rcItem
.top
;
44 if ( GuiInfo
->WindowOrigin
.x
== MAXDWORD
&&
45 GuiInfo
->WindowOrigin
.y
== MAXDWORD
)
53 // Calculate pos correctly when console centered
54 startx
= GuiInfo
->WindowOrigin
.x
;
55 starty
= GuiInfo
->WindowOrigin
.y
;
59 // Stretch console when bold fonts are selected
60 endx
= startx
+ pConInfo
->ci
.ConsoleSize
.X
; // drawItem->rcItem.right - startx + 15;
61 endy
= starty
+ pConInfo
->ci
.ConsoleSize
.Y
; // starty + sizey / 3;
63 /* Draw console size */
64 SetRect(&cRect
, startx
, starty
, endx
, endy
);
65 FillRect(drawItem
->hDC
, &cRect
, GetSysColorBrush(COLOR_WINDOWFRAME
));
67 /* Draw console border */
68 SetRect(&fRect
, startx
+ 1, starty
+ 1, cRect
.right
- 1, cRect
.bottom
- 1);
69 FrameRect(drawItem
->hDC
, &fRect
, GetSysColorBrush(COLOR_ACTIVEBORDER
));
72 SetRect(&fRect
, startx
+ 3, starty
+ 3, startx
+ 5, starty
+ 5);
73 FillRect(drawItem
->hDC
, &fRect
, GetSysColorBrush(COLOR_ACTIVEBORDER
));
75 /* Draw window title */
76 SetRect(&fRect
, startx
+ 7, starty
+ 3, cRect
.right
- 9, starty
+ 5);
77 FillRect(drawItem
->hDC
, &fRect
, GetSysColorBrush(COLOR_ACTIVECAPTION
));
79 /* Draw first right box */
80 SetRect(&fRect
, fRect
.right
+ 1, starty
+ 3, fRect
.right
+ 3, starty
+ 5);
81 FillRect(drawItem
->hDC
, &fRect
, GetSysColorBrush(COLOR_ACTIVEBORDER
));
83 /* Draw second right box */
84 SetRect(&fRect
, fRect
.right
+ 1, starty
+ 3, fRect
.right
+ 3, starty
+ 5);
85 FillRect(drawItem
->hDC
, &fRect
, GetSysColorBrush(COLOR_ACTIVEBORDER
));
88 SetRect(&fRect
, cRect
.right
- 5, fRect
.bottom
+ 1, cRect
.right
- 3, cRect
.bottom
- 3);
89 FillRect(drawItem
->hDC
, &fRect
, GetSysColorBrush(COLOR_SCROLLBAR
));
91 /* Draw console background */
92 hBrush
= CreateSolidBrush(pConInfo
->ci
.Colors
[BkgdAttribFromAttrib(pConInfo
->ci
.ScreenAttrib
)]);
93 SetRect(&fRect
, startx
+ 3, starty
+ 6, cRect
.right
- 6, cRect
.bottom
- 3);
94 FillRect(drawItem
->hDC
, &fRect
, hBrush
);
95 DeleteObject((HGDIOBJ
)hBrush
);
99 PaintText(LPDRAWITEMSTRUCT drawItem
,
100 PCONSOLE_PROPS pConInfo
,
103 PGUI_CONSOLE_INFO GuiInfo
= pConInfo
->TerminalInfo
.TermInfo
;
104 USHORT CurrentAttrib
;
105 COLORREF pbkColor
, ptColor
;
106 COLORREF nbkColor
, ntColor
;
110 COORD FontSize
= GuiInfo
->FontSize
;
112 if (TextMode
== Screen
)
113 CurrentAttrib
= pConInfo
->ci
.ScreenAttrib
;
114 else if (TextMode
== Popup
)
115 CurrentAttrib
= pConInfo
->ci
.PopupAttrib
;
119 nbkColor
= pConInfo
->ci
.Colors
[BkgdAttribFromAttrib(CurrentAttrib
)];
120 ntColor
= pConInfo
->ci
.Colors
[TextAttribFromAttrib(CurrentAttrib
)];
122 hBrush
= CreateSolidBrush(nbkColor
);
123 if (!hBrush
) return FALSE
;
125 FontSize
.Y
= FontSize
.Y
> 0 ? -MulDiv(FontSize
.Y
, GetDeviceCaps(drawItem
->hDC
, LOGPIXELSY
), 72)
128 Font
= CreateFontW(FontSize
.Y
,
140 FIXED_PITCH
| GuiInfo
->FontFamily
,
144 DPRINT1("PaintText: CreateFont failed\n");
148 OldFont
= SelectObject(drawItem
->hDC
, Font
);
155 FillRect(drawItem
->hDC
, &drawItem
->rcItem
, hBrush
);
157 ptColor
= SetTextColor(drawItem
->hDC
, ntColor
);
158 pbkColor
= SetBkColor(drawItem
->hDC
, nbkColor
);
159 DrawTextW(drawItem
->hDC
, szPreviewText
, wcslen(szPreviewText
), &drawItem
->rcItem
, 0);
160 SetTextColor(drawItem
->hDC
, ptColor
);
161 SetBkColor(drawItem
->hDC
, pbkColor
);
162 DeleteObject(hBrush
);
164 SelectObject(drawItem
->hDC
, OldFont
);
172 LayoutProc(HWND hwndDlg
,
177 PCONSOLE_PROPS pConInfo
= (PCONSOLE_PROPS
)GetWindowLongPtr(hwndDlg
, DWLP_USER
);
178 PGUI_CONSOLE_INFO GuiInfo
= (pConInfo
? pConInfo
->TerminalInfo
.TermInfo
: NULL
);
180 UNREFERENCED_PARAMETER(hwndDlg
);
181 UNREFERENCED_PARAMETER(wParam
);
187 /* Multi-monitor support */
188 LONG xVirtScr
, yVirtScr
; // Coordinates of the top-left virtual screen
189 LONG cxVirtScr
, cyVirtScr
; // Width and Height of the virtual screen
190 LONG cxFrame
, cyFrame
; // Thickness of the window frame
192 pConInfo
= (PCONSOLE_PROPS
)((LPPROPSHEETPAGE
)lParam
)->lParam
;
193 GuiInfo
= pConInfo
->TerminalInfo
.TermInfo
;
194 SetWindowLongPtr(hwndDlg
, DWLP_USER
, (LONG_PTR
)pConInfo
);
196 /* Multi-monitor support */
197 xVirtScr
= GetSystemMetrics(SM_XVIRTUALSCREEN
);
198 yVirtScr
= GetSystemMetrics(SM_YVIRTUALSCREEN
);
199 cxVirtScr
= GetSystemMetrics(SM_CXVIRTUALSCREEN
);
200 cyVirtScr
= GetSystemMetrics(SM_CYVIRTUALSCREEN
);
201 cxFrame
= GetSystemMetrics(SM_CXFRAME
);
202 cyFrame
= GetSystemMetrics(SM_CYFRAME
);
204 SendDlgItemMessageW(hwndDlg
, IDC_UPDOWN_SCREEN_BUFFER_HEIGHT
, UDM_SETRANGE
, 0, (LPARAM
)MAKELONG(9999, 1));
205 SendDlgItemMessageW(hwndDlg
, IDC_UPDOWN_SCREEN_BUFFER_WIDTH
, UDM_SETRANGE
, 0, (LPARAM
)MAKELONG(9999, 1));
206 SendDlgItemMessageW(hwndDlg
, IDC_UPDOWN_WINDOW_SIZE_HEIGHT
, UDM_SETRANGE
, 0, (LPARAM
)MAKELONG(9999, 1));
207 SendDlgItemMessageW(hwndDlg
, IDC_UPDOWN_WINDOW_SIZE_WIDTH
, UDM_SETRANGE
, 0, (LPARAM
)MAKELONG(9999, 1));
209 SetDlgItemInt(hwndDlg
, IDC_EDIT_SCREEN_BUFFER_HEIGHT
, pConInfo
->ci
.ScreenBufferSize
.Y
, FALSE
);
210 SetDlgItemInt(hwndDlg
, IDC_EDIT_SCREEN_BUFFER_WIDTH
, pConInfo
->ci
.ScreenBufferSize
.X
, FALSE
);
211 SetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_SIZE_HEIGHT
, pConInfo
->ci
.ConsoleSize
.Y
, FALSE
);
212 SetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_SIZE_WIDTH
, pConInfo
->ci
.ConsoleSize
.X
, FALSE
);
214 SendDlgItemMessageW(hwndDlg
, IDC_UPDOWN_WINDOW_POS_LEFT
, UDM_SETRANGE
, 0,
215 (LPARAM
)MAKELONG(xVirtScr
+ cxVirtScr
- cxFrame
, xVirtScr
- cxFrame
));
216 SendDlgItemMessageW(hwndDlg
, IDC_UPDOWN_WINDOW_POS_TOP
, UDM_SETRANGE
, 0,
217 (LPARAM
)MAKELONG(yVirtScr
+ cyVirtScr
- cyFrame
, yVirtScr
- cyFrame
));
219 SetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_POS_LEFT
, GuiInfo
->WindowOrigin
.x
, TRUE
);
220 SetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_POS_TOP
, GuiInfo
->WindowOrigin
.y
, TRUE
);
222 if (GuiInfo
->AutoPosition
)
224 EnableDlgItem(hwndDlg
, IDC_EDIT_WINDOW_POS_LEFT
, FALSE
);
225 EnableDlgItem(hwndDlg
, IDC_EDIT_WINDOW_POS_TOP
, FALSE
);
226 EnableDlgItem(hwndDlg
, IDC_UPDOWN_WINDOW_POS_LEFT
, FALSE
);
227 EnableDlgItem(hwndDlg
, IDC_UPDOWN_WINDOW_POS_TOP
, FALSE
);
229 CheckDlgButton(hwndDlg
, IDC_CHECK_SYSTEM_POS_WINDOW
,
230 GuiInfo
->AutoPosition
? BST_CHECKED
: BST_UNCHECKED
);
237 PaintConsole((LPDRAWITEMSTRUCT
)lParam
, pConInfo
);
243 LPNMUPDOWN lpnmud
= (LPNMUPDOWN
)lParam
;
244 LPPSHNOTIFY lppsn
= (LPPSHNOTIFY
)lParam
;
246 if (lppsn
->hdr
.code
== UDN_DELTAPOS
)
248 DWORD wheight
, wwidth
;
249 DWORD sheight
, swidth
;
252 if (lppsn
->hdr
.idFrom
== IDC_UPDOWN_WINDOW_SIZE_WIDTH
)
254 wwidth
= lpnmud
->iPos
+ lpnmud
->iDelta
;
258 wwidth
= GetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_SIZE_WIDTH
, NULL
, FALSE
);
261 if (lppsn
->hdr
.idFrom
== IDC_UPDOWN_WINDOW_SIZE_HEIGHT
)
263 wheight
= lpnmud
->iPos
+ lpnmud
->iDelta
;
267 wheight
= GetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_SIZE_HEIGHT
, NULL
, FALSE
);
270 if (lppsn
->hdr
.idFrom
== IDC_UPDOWN_SCREEN_BUFFER_WIDTH
)
272 swidth
= lpnmud
->iPos
+ lpnmud
->iDelta
;
276 swidth
= GetDlgItemInt(hwndDlg
, IDC_EDIT_SCREEN_BUFFER_WIDTH
, NULL
, FALSE
);
279 if (lppsn
->hdr
.idFrom
== IDC_UPDOWN_SCREEN_BUFFER_HEIGHT
)
281 sheight
= lpnmud
->iPos
+ lpnmud
->iDelta
;
285 sheight
= GetDlgItemInt(hwndDlg
, IDC_EDIT_SCREEN_BUFFER_HEIGHT
, NULL
, FALSE
);
288 if (lppsn
->hdr
.idFrom
== IDC_UPDOWN_WINDOW_POS_LEFT
)
290 left
= lpnmud
->iPos
+ lpnmud
->iDelta
;
294 left
= GetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_POS_LEFT
, NULL
, TRUE
);
297 if (lppsn
->hdr
.idFrom
== IDC_UPDOWN_WINDOW_POS_TOP
)
299 top
= lpnmud
->iPos
+ lpnmud
->iDelta
;
303 top
= GetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_POS_TOP
, NULL
, TRUE
);
306 if (lppsn
->hdr
.idFrom
== IDC_UPDOWN_WINDOW_SIZE_WIDTH
|| lppsn
->hdr
.idFrom
== IDC_UPDOWN_WINDOW_SIZE_HEIGHT
)
308 /* Automatically adjust screen buffer size when window size enlarges */
309 if (wwidth
>= swidth
)
311 SetDlgItemInt(hwndDlg
, IDC_EDIT_SCREEN_BUFFER_WIDTH
, wwidth
, TRUE
);
314 if (wheight
>= sheight
)
316 SetDlgItemInt(hwndDlg
, IDC_EDIT_SCREEN_BUFFER_HEIGHT
, wheight
, TRUE
);
321 /* Be sure that the (new) screen buffer sizes are in the correct range */
322 swidth
= min(max(swidth
, 1), 0xFFFF);
323 sheight
= min(max(sheight
, 1), 0xFFFF);
325 if (lppsn
->hdr
.idFrom
== IDC_UPDOWN_SCREEN_BUFFER_WIDTH
|| lppsn
->hdr
.idFrom
== IDC_UPDOWN_SCREEN_BUFFER_HEIGHT
)
327 /* Automatically adjust window size when screen buffer decreases */
330 SetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_SIZE_WIDTH
, swidth
, TRUE
);
333 if (wheight
> sheight
)
335 SetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_SIZE_HEIGHT
, sheight
, TRUE
);
340 pConInfo
->ci
.ScreenBufferSize
.X
= (SHORT
)swidth
;
341 pConInfo
->ci
.ScreenBufferSize
.Y
= (SHORT
)sheight
;
342 pConInfo
->ci
.ConsoleSize
.X
= (SHORT
)wwidth
;
343 pConInfo
->ci
.ConsoleSize
.Y
= (SHORT
)wheight
;
344 GuiInfo
->WindowOrigin
.x
= left
;
345 GuiInfo
->WindowOrigin
.y
= top
;
346 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
353 switch (LOWORD(wParam
))
355 case IDC_EDIT_SCREEN_BUFFER_WIDTH
:
357 if (HIWORD(wParam
) == EN_KILLFOCUS
)
359 DWORD swidth
, wwidth
;
361 swidth
= GetDlgItemInt(hwndDlg
, IDC_EDIT_SCREEN_BUFFER_WIDTH
, NULL
, FALSE
);
362 wwidth
= GetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_SIZE_WIDTH
, NULL
, FALSE
);
364 /* Be sure that the (new) screen buffer width is in the correct range */
365 swidth
= min(max(swidth
, 1), 0xFFFF);
367 /* Automatically adjust window size when screen buffer decreases */
371 SetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_SIZE_WIDTH
, wwidth
, TRUE
);
374 pConInfo
->ci
.ScreenBufferSize
.X
= (SHORT
)swidth
;
375 pConInfo
->ci
.ConsoleSize
.X
= (SHORT
)wwidth
;
376 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
381 case IDC_EDIT_WINDOW_SIZE_WIDTH
:
383 if (HIWORD(wParam
) == EN_KILLFOCUS
)
385 DWORD swidth
, wwidth
;
387 swidth
= GetDlgItemInt(hwndDlg
, IDC_EDIT_SCREEN_BUFFER_WIDTH
, NULL
, FALSE
);
388 wwidth
= GetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_SIZE_WIDTH
, NULL
, FALSE
);
390 /* Automatically adjust screen buffer size when window size enlarges */
391 if (wwidth
>= swidth
)
395 /* Be sure that the (new) screen buffer width is in the correct range */
396 swidth
= min(max(swidth
, 1), 0xFFFF);
398 SetDlgItemInt(hwndDlg
, IDC_EDIT_SCREEN_BUFFER_WIDTH
, swidth
, TRUE
);
401 pConInfo
->ci
.ScreenBufferSize
.X
= (SHORT
)swidth
;
402 pConInfo
->ci
.ConsoleSize
.X
= (SHORT
)wwidth
;
403 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
408 case IDC_EDIT_SCREEN_BUFFER_HEIGHT
:
410 if (HIWORD(wParam
) == EN_KILLFOCUS
)
412 DWORD sheight
, wheight
;
414 sheight
= GetDlgItemInt(hwndDlg
, IDC_EDIT_SCREEN_BUFFER_HEIGHT
, NULL
, FALSE
);
415 wheight
= GetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_SIZE_HEIGHT
, NULL
, FALSE
);
417 /* Be sure that the (new) screen buffer width is in the correct range */
418 sheight
= min(max(sheight
, 1), 0xFFFF);
420 /* Automatically adjust window size when screen buffer decreases */
421 if (wheight
> sheight
)
424 SetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_SIZE_HEIGHT
, wheight
, TRUE
);
427 pConInfo
->ci
.ScreenBufferSize
.Y
= (SHORT
)sheight
;
428 pConInfo
->ci
.ConsoleSize
.Y
= (SHORT
)wheight
;
429 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
434 case IDC_EDIT_WINDOW_SIZE_HEIGHT
:
436 if (HIWORD(wParam
) == EN_KILLFOCUS
)
438 DWORD sheight
, wheight
;
440 sheight
= GetDlgItemInt(hwndDlg
, IDC_EDIT_SCREEN_BUFFER_HEIGHT
, NULL
, FALSE
);
441 wheight
= GetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_SIZE_HEIGHT
, NULL
, FALSE
);
443 /* Automatically adjust screen buffer size when window size enlarges */
444 if (wheight
>= sheight
)
448 /* Be sure that the (new) screen buffer width is in the correct range */
449 sheight
= min(max(sheight
, 1), 0xFFFF);
451 SetDlgItemInt(hwndDlg
, IDC_EDIT_SCREEN_BUFFER_HEIGHT
, sheight
, TRUE
);
454 pConInfo
->ci
.ScreenBufferSize
.Y
= (SHORT
)sheight
;
455 pConInfo
->ci
.ConsoleSize
.Y
= (SHORT
)wheight
;
456 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
461 case IDC_EDIT_WINDOW_POS_LEFT
:
462 case IDC_EDIT_WINDOW_POS_TOP
:
464 if (HIWORD(wParam
) == EN_KILLFOCUS
)
468 left
= GetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_POS_LEFT
, NULL
, TRUE
);
469 top
= GetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_POS_TOP
, NULL
, TRUE
);
471 GuiInfo
->WindowOrigin
.x
= left
;
472 GuiInfo
->WindowOrigin
.y
= top
;
473 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
478 case IDC_CHECK_SYSTEM_POS_WINDOW
:
480 LONG res
= SendMessage((HWND
)lParam
, BM_GETCHECK
, 0, 0);
481 if (res
== BST_CHECKED
)
485 left
= GetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_POS_LEFT
, NULL
, TRUE
);
486 top
= GetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_POS_TOP
, NULL
, TRUE
);
488 GuiInfo
->AutoPosition
= FALSE
;
489 GuiInfo
->WindowOrigin
.x
= left
;
490 GuiInfo
->WindowOrigin
.y
= top
;
491 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
493 SendMessage((HWND
)lParam
, BM_SETCHECK
, (WPARAM
)BST_UNCHECKED
, 0);
494 EnableDlgItem(hwndDlg
, IDC_EDIT_WINDOW_POS_LEFT
, TRUE
);
495 EnableDlgItem(hwndDlg
, IDC_EDIT_WINDOW_POS_TOP
, TRUE
);
496 EnableDlgItem(hwndDlg
, IDC_UPDOWN_WINDOW_POS_LEFT
, TRUE
);
497 EnableDlgItem(hwndDlg
, IDC_UPDOWN_WINDOW_POS_TOP
, TRUE
);
499 else if (res
== BST_UNCHECKED
)
501 GuiInfo
->AutoPosition
= TRUE
;
502 // Do not touch GuiInfo->WindowOrigin !!
503 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
505 SendMessage((HWND
)lParam
, BM_SETCHECK
, (WPARAM
)BST_CHECKED
, 0);
506 EnableDlgItem(hwndDlg
, IDC_EDIT_WINDOW_POS_LEFT
, FALSE
);
507 EnableDlgItem(hwndDlg
, IDC_EDIT_WINDOW_POS_TOP
, FALSE
);
508 EnableDlgItem(hwndDlg
, IDC_UPDOWN_WINDOW_POS_LEFT
, FALSE
);
509 EnableDlgItem(hwndDlg
, IDC_UPDOWN_WINDOW_POS_TOP
, FALSE
);