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 if (TextMode
== Screen
)
111 CurrentAttrib
= pConInfo
->ci
.ScreenAttrib
;
112 else if (TextMode
== Popup
)
113 CurrentAttrib
= pConInfo
->ci
.PopupAttrib
;
117 nbkColor
= pConInfo
->ci
.Colors
[BkgdAttribFromAttrib(CurrentAttrib
)];
118 ntColor
= pConInfo
->ci
.Colors
[TextAttribFromAttrib(CurrentAttrib
)];
120 hBrush
= CreateSolidBrush(nbkColor
);
121 if (!hBrush
) return FALSE
;
123 Font
= CreateFontW(GuiInfo
->FontSize
.X
,
124 0, // GuiInfo->FontSize.Y,
134 NONANTIALIASED_QUALITY
,
135 FIXED_PITCH
| GuiInfo
->FontFamily
/* FF_DONTCARE */,
139 DPRINT1("PaintText: CreateFont failed\n");
143 OldFont
= SelectObject(drawItem
->hDC
, Font
);
150 FillRect(drawItem
->hDC
, &drawItem
->rcItem
, hBrush
);
152 ptColor
= SetTextColor(drawItem
->hDC
, ntColor
);
153 pbkColor
= SetBkColor(drawItem
->hDC
, nbkColor
);
154 DrawTextW(drawItem
->hDC
, szPreviewText
, wcslen(szPreviewText
), &drawItem
->rcItem
, 0);
155 SetTextColor(drawItem
->hDC
, ptColor
);
156 SetBkColor(drawItem
->hDC
, pbkColor
);
157 DeleteObject((HGDIOBJ
)hBrush
);
159 SelectObject(drawItem
->hDC
, OldFont
);
167 LayoutProc(HWND hwndDlg
,
172 PCONSOLE_PROPS pConInfo
= (PCONSOLE_PROPS
)GetWindowLongPtr(hwndDlg
, DWLP_USER
);
173 PGUI_CONSOLE_INFO GuiInfo
= (pConInfo
? pConInfo
->TerminalInfo
.TermInfo
: NULL
);
175 UNREFERENCED_PARAMETER(hwndDlg
);
176 UNREFERENCED_PARAMETER(wParam
);
182 /* Multi-monitor support */
183 LONG xVirtScr
, yVirtScr
; // Coordinates of the top-left virtual screen
184 LONG cxVirtScr
, cyVirtScr
; // Width and Height of the virtual screen
185 LONG cxFrame
, cyFrame
; // Thickness of the window frame
187 pConInfo
= (PCONSOLE_PROPS
)((LPPROPSHEETPAGE
)lParam
)->lParam
;
188 GuiInfo
= pConInfo
->TerminalInfo
.TermInfo
;
189 SetWindowLongPtr(hwndDlg
, DWLP_USER
, (LONG_PTR
)pConInfo
);
191 /* Multi-monitor support */
192 xVirtScr
= GetSystemMetrics(SM_XVIRTUALSCREEN
);
193 yVirtScr
= GetSystemMetrics(SM_YVIRTUALSCREEN
);
194 cxVirtScr
= GetSystemMetrics(SM_CXVIRTUALSCREEN
);
195 cyVirtScr
= GetSystemMetrics(SM_CYVIRTUALSCREEN
);
196 cxFrame
= GetSystemMetrics(SM_CXFRAME
);
197 cyFrame
= GetSystemMetrics(SM_CYFRAME
);
199 SendDlgItemMessageW(hwndDlg
, IDC_UPDOWN_SCREEN_BUFFER_HEIGHT
, UDM_SETRANGE
, 0, (LPARAM
)MAKELONG(9999, 1));
200 SendDlgItemMessageW(hwndDlg
, IDC_UPDOWN_SCREEN_BUFFER_WIDTH
, UDM_SETRANGE
, 0, (LPARAM
)MAKELONG(9999, 1));
201 SendDlgItemMessageW(hwndDlg
, IDC_UPDOWN_WINDOW_SIZE_HEIGHT
, UDM_SETRANGE
, 0, (LPARAM
)MAKELONG(9999, 1));
202 SendDlgItemMessageW(hwndDlg
, IDC_UPDOWN_WINDOW_SIZE_WIDTH
, UDM_SETRANGE
, 0, (LPARAM
)MAKELONG(9999, 1));
204 SetDlgItemInt(hwndDlg
, IDC_EDIT_SCREEN_BUFFER_HEIGHT
, pConInfo
->ci
.ScreenBufferSize
.Y
, FALSE
);
205 SetDlgItemInt(hwndDlg
, IDC_EDIT_SCREEN_BUFFER_WIDTH
, pConInfo
->ci
.ScreenBufferSize
.X
, FALSE
);
206 SetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_SIZE_HEIGHT
, pConInfo
->ci
.ConsoleSize
.Y
, FALSE
);
207 SetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_SIZE_WIDTH
, pConInfo
->ci
.ConsoleSize
.X
, FALSE
);
209 SendDlgItemMessageW(hwndDlg
, IDC_UPDOWN_WINDOW_POS_LEFT
, UDM_SETRANGE
, 0,
210 (LPARAM
)MAKELONG(xVirtScr
+ cxVirtScr
- cxFrame
, xVirtScr
- cxFrame
));
211 SendDlgItemMessageW(hwndDlg
, IDC_UPDOWN_WINDOW_POS_TOP
, UDM_SETRANGE
, 0,
212 (LPARAM
)MAKELONG(yVirtScr
+ cyVirtScr
- cyFrame
, yVirtScr
- cyFrame
));
214 SetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_POS_LEFT
, GuiInfo
->WindowOrigin
.x
, TRUE
);
215 SetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_POS_TOP
, GuiInfo
->WindowOrigin
.y
, TRUE
);
217 if (GuiInfo
->AutoPosition
)
219 EnableDlgItem(hwndDlg
, IDC_EDIT_WINDOW_POS_LEFT
, FALSE
);
220 EnableDlgItem(hwndDlg
, IDC_EDIT_WINDOW_POS_TOP
, FALSE
);
221 EnableDlgItem(hwndDlg
, IDC_UPDOWN_WINDOW_POS_LEFT
, FALSE
);
222 EnableDlgItem(hwndDlg
, IDC_UPDOWN_WINDOW_POS_TOP
, FALSE
);
224 CheckDlgButton(hwndDlg
, IDC_CHECK_SYSTEM_POS_WINDOW
,
225 GuiInfo
->AutoPosition
? BST_CHECKED
: BST_UNCHECKED
);
232 PaintConsole((LPDRAWITEMSTRUCT
)lParam
, pConInfo
);
238 LPNMUPDOWN lpnmud
= (LPNMUPDOWN
)lParam
;
239 LPPSHNOTIFY lppsn
= (LPPSHNOTIFY
)lParam
;
241 if (lppsn
->hdr
.code
== UDN_DELTAPOS
)
243 DWORD wheight
, wwidth
;
244 DWORD sheight
, swidth
;
247 if (lppsn
->hdr
.idFrom
== IDC_UPDOWN_WINDOW_SIZE_WIDTH
)
249 wwidth
= lpnmud
->iPos
+ lpnmud
->iDelta
;
253 wwidth
= GetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_SIZE_WIDTH
, NULL
, FALSE
);
256 if (lppsn
->hdr
.idFrom
== IDC_UPDOWN_WINDOW_SIZE_HEIGHT
)
258 wheight
= lpnmud
->iPos
+ lpnmud
->iDelta
;
262 wheight
= GetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_SIZE_HEIGHT
, NULL
, FALSE
);
265 if (lppsn
->hdr
.idFrom
== IDC_UPDOWN_SCREEN_BUFFER_WIDTH
)
267 swidth
= lpnmud
->iPos
+ lpnmud
->iDelta
;
271 swidth
= GetDlgItemInt(hwndDlg
, IDC_EDIT_SCREEN_BUFFER_WIDTH
, NULL
, FALSE
);
274 if (lppsn
->hdr
.idFrom
== IDC_UPDOWN_SCREEN_BUFFER_HEIGHT
)
276 sheight
= lpnmud
->iPos
+ lpnmud
->iDelta
;
280 sheight
= GetDlgItemInt(hwndDlg
, IDC_EDIT_SCREEN_BUFFER_HEIGHT
, NULL
, FALSE
);
283 if (lppsn
->hdr
.idFrom
== IDC_UPDOWN_WINDOW_POS_LEFT
)
285 left
= lpnmud
->iPos
+ lpnmud
->iDelta
;
289 left
= GetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_POS_LEFT
, NULL
, TRUE
);
292 if (lppsn
->hdr
.idFrom
== IDC_UPDOWN_WINDOW_POS_TOP
)
294 top
= lpnmud
->iPos
+ lpnmud
->iDelta
;
298 top
= GetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_POS_TOP
, NULL
, TRUE
);
301 if (lppsn
->hdr
.idFrom
== IDC_UPDOWN_WINDOW_SIZE_WIDTH
|| lppsn
->hdr
.idFrom
== IDC_UPDOWN_WINDOW_SIZE_HEIGHT
)
303 /* Automatically adjust screen buffer size when window size enlarges */
304 if (wwidth
>= swidth
)
306 SetDlgItemInt(hwndDlg
, IDC_EDIT_SCREEN_BUFFER_WIDTH
, wwidth
, TRUE
);
309 if (wheight
>= sheight
)
311 SetDlgItemInt(hwndDlg
, IDC_EDIT_SCREEN_BUFFER_HEIGHT
, wheight
, TRUE
);
316 /* Be sure that the (new) screen buffer sizes are in the correct range */
317 swidth
= min(max(swidth
, 1), 0xFFFF);
318 sheight
= min(max(sheight
, 1), 0xFFFF);
320 if (lppsn
->hdr
.idFrom
== IDC_UPDOWN_SCREEN_BUFFER_WIDTH
|| lppsn
->hdr
.idFrom
== IDC_UPDOWN_SCREEN_BUFFER_HEIGHT
)
322 /* Automatically adjust window size when screen buffer decreases */
325 SetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_SIZE_WIDTH
, swidth
, TRUE
);
328 if (wheight
> sheight
)
330 SetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_SIZE_HEIGHT
, sheight
, TRUE
);
335 pConInfo
->ci
.ScreenBufferSize
.X
= (SHORT
)swidth
;
336 pConInfo
->ci
.ScreenBufferSize
.Y
= (SHORT
)sheight
;
337 pConInfo
->ci
.ConsoleSize
.X
= (SHORT
)wwidth
;
338 pConInfo
->ci
.ConsoleSize
.Y
= (SHORT
)wheight
;
339 GuiInfo
->WindowOrigin
.x
= left
;
340 GuiInfo
->WindowOrigin
.y
= top
;
341 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
348 switch (LOWORD(wParam
))
350 case IDC_EDIT_SCREEN_BUFFER_WIDTH
:
352 if (HIWORD(wParam
) == EN_KILLFOCUS
)
354 DWORD swidth
, wwidth
;
356 swidth
= GetDlgItemInt(hwndDlg
, IDC_EDIT_SCREEN_BUFFER_WIDTH
, NULL
, FALSE
);
357 wwidth
= GetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_SIZE_WIDTH
, NULL
, FALSE
);
359 /* Be sure that the (new) screen buffer width is in the correct range */
360 swidth
= min(max(swidth
, 1), 0xFFFF);
362 /* Automatically adjust window size when screen buffer decreases */
366 SetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_SIZE_WIDTH
, wwidth
, TRUE
);
369 pConInfo
->ci
.ScreenBufferSize
.X
= (SHORT
)swidth
;
370 pConInfo
->ci
.ConsoleSize
.X
= (SHORT
)wwidth
;
371 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
376 case IDC_EDIT_WINDOW_SIZE_WIDTH
:
378 if (HIWORD(wParam
) == EN_KILLFOCUS
)
380 DWORD swidth
, wwidth
;
382 swidth
= GetDlgItemInt(hwndDlg
, IDC_EDIT_SCREEN_BUFFER_WIDTH
, NULL
, FALSE
);
383 wwidth
= GetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_SIZE_WIDTH
, NULL
, FALSE
);
385 /* Automatically adjust screen buffer size when window size enlarges */
386 if (wwidth
>= swidth
)
390 /* Be sure that the (new) screen buffer width is in the correct range */
391 swidth
= min(max(swidth
, 1), 0xFFFF);
393 SetDlgItemInt(hwndDlg
, IDC_EDIT_SCREEN_BUFFER_WIDTH
, swidth
, TRUE
);
396 pConInfo
->ci
.ScreenBufferSize
.X
= (SHORT
)swidth
;
397 pConInfo
->ci
.ConsoleSize
.X
= (SHORT
)wwidth
;
398 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
403 case IDC_EDIT_SCREEN_BUFFER_HEIGHT
:
405 if (HIWORD(wParam
) == EN_KILLFOCUS
)
407 DWORD sheight
, wheight
;
409 sheight
= GetDlgItemInt(hwndDlg
, IDC_EDIT_SCREEN_BUFFER_HEIGHT
, NULL
, FALSE
);
410 wheight
= GetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_SIZE_HEIGHT
, NULL
, FALSE
);
412 /* Be sure that the (new) screen buffer width is in the correct range */
413 sheight
= min(max(sheight
, 1), 0xFFFF);
415 /* Automatically adjust window size when screen buffer decreases */
416 if (wheight
> sheight
)
419 SetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_SIZE_HEIGHT
, wheight
, TRUE
);
422 pConInfo
->ci
.ScreenBufferSize
.Y
= (SHORT
)sheight
;
423 pConInfo
->ci
.ConsoleSize
.Y
= (SHORT
)wheight
;
424 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
429 case IDC_EDIT_WINDOW_SIZE_HEIGHT
:
431 if (HIWORD(wParam
) == EN_KILLFOCUS
)
433 DWORD sheight
, wheight
;
435 sheight
= GetDlgItemInt(hwndDlg
, IDC_EDIT_SCREEN_BUFFER_HEIGHT
, NULL
, FALSE
);
436 wheight
= GetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_SIZE_HEIGHT
, NULL
, FALSE
);
438 /* Automatically adjust screen buffer size when window size enlarges */
439 if (wheight
>= sheight
)
443 /* Be sure that the (new) screen buffer width is in the correct range */
444 sheight
= min(max(sheight
, 1), 0xFFFF);
446 SetDlgItemInt(hwndDlg
, IDC_EDIT_SCREEN_BUFFER_HEIGHT
, sheight
, TRUE
);
449 pConInfo
->ci
.ScreenBufferSize
.Y
= (SHORT
)sheight
;
450 pConInfo
->ci
.ConsoleSize
.Y
= (SHORT
)wheight
;
451 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
456 case IDC_EDIT_WINDOW_POS_LEFT
:
457 case IDC_EDIT_WINDOW_POS_TOP
:
459 if (HIWORD(wParam
) == EN_KILLFOCUS
)
463 left
= GetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_POS_LEFT
, NULL
, TRUE
);
464 top
= GetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_POS_TOP
, NULL
, TRUE
);
466 GuiInfo
->WindowOrigin
.x
= left
;
467 GuiInfo
->WindowOrigin
.y
= top
;
468 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
473 case IDC_CHECK_SYSTEM_POS_WINDOW
:
475 LONG res
= SendMessage((HWND
)lParam
, BM_GETCHECK
, 0, 0);
476 if (res
== BST_CHECKED
)
480 left
= GetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_POS_LEFT
, NULL
, TRUE
);
481 top
= GetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_POS_TOP
, NULL
, TRUE
);
483 GuiInfo
->AutoPosition
= FALSE
;
484 GuiInfo
->WindowOrigin
.x
= left
;
485 GuiInfo
->WindowOrigin
.y
= top
;
486 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
488 SendMessage((HWND
)lParam
, BM_SETCHECK
, (WPARAM
)BST_UNCHECKED
, 0);
489 EnableDlgItem(hwndDlg
, IDC_EDIT_WINDOW_POS_LEFT
, TRUE
);
490 EnableDlgItem(hwndDlg
, IDC_EDIT_WINDOW_POS_TOP
, TRUE
);
491 EnableDlgItem(hwndDlg
, IDC_UPDOWN_WINDOW_POS_LEFT
, TRUE
);
492 EnableDlgItem(hwndDlg
, IDC_UPDOWN_WINDOW_POS_TOP
, TRUE
);
494 else if (res
== BST_UNCHECKED
)
496 GuiInfo
->AutoPosition
= TRUE
;
497 // Do not touch GuiInfo->WindowOrigin !!
498 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
500 SendMessage((HWND
)lParam
, BM_SETCHECK
, (WPARAM
)BST_CHECKED
, 0);
501 EnableDlgItem(hwndDlg
, IDC_EDIT_WINDOW_POS_LEFT
, FALSE
);
502 EnableDlgItem(hwndDlg
, IDC_EDIT_WINDOW_POS_TOP
, FALSE
);
503 EnableDlgItem(hwndDlg
, IDC_UPDOWN_WINDOW_POS_LEFT
, FALSE
);
504 EnableDlgItem(hwndDlg
, IDC_UPDOWN_WINDOW_POS_TOP
, FALSE
);