2 * PROJECT: ReactOS Console Configuration DLL
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: dll/cpl/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" ;
28 IN LPDRAWITEMSTRUCT drawItem
,
29 IN PCONSOLE_STATE_INFO pConInfo
)
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 ( pConInfo
->WindowPosition
.x
== MAXDWORD
&&
45 pConInfo
->WindowPosition
.y
== MAXDWORD
)
53 // Calculate pos correctly when console centered
54 startx
= pConInfo
->WindowPosition
.x
;
55 starty
= pConInfo
->WindowPosition
.y
;
59 // Stretch console when bold fonts are selected
60 endx
= startx
+ pConInfo
->WindowSize
.X
; // drawItem->rcItem.right - startx + 15;
61 endy
= starty
+ pConInfo
->WindowSize
.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
->ColorTable
[BkgdAttribFromAttrib(pConInfo
->ScreenAttributes
)]);
93 SetRect(&fRect
, startx
+ 3, starty
+ 6, cRect
.right
- 6, cRect
.bottom
- 3);
94 FillRect(drawItem
->hDC
, &fRect
, hBrush
);
100 IN LPDRAWITEMSTRUCT drawItem
,
101 IN PCONSOLE_STATE_INFO pConInfo
,
102 IN TEXT_TYPE TextMode
)
104 USHORT CurrentAttrib
;
105 COLORREF pbkColor
, ptColor
;
106 COLORREF nbkColor
, ntColor
;
110 COORD FontSize
= pConInfo
->FontSize
;
112 if (TextMode
== Screen
)
113 CurrentAttrib
= pConInfo
->ScreenAttributes
;
114 else if (TextMode
== Popup
)
115 CurrentAttrib
= pConInfo
->PopupAttributes
;
119 nbkColor
= pConInfo
->ColorTable
[BkgdAttribFromAttrib(CurrentAttrib
)];
120 ntColor
= pConInfo
->ColorTable
[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
,
132 pConInfo
->FontWeight
,
136 CodePageToCharSet(pConInfo
->CodePage
),
140 FIXED_PITCH
| pConInfo
->FontFamily
,
144 DPRINT1("PaintText: CreateFont failed\n");
145 DeleteObject(hBrush
);
149 OldFont
= SelectObject(drawItem
->hDC
, Font
);
153 DeleteObject(hBrush
);
157 FillRect(drawItem
->hDC
, &drawItem
->rcItem
, hBrush
);
159 ptColor
= SetTextColor(drawItem
->hDC
, ntColor
);
160 pbkColor
= SetBkColor(drawItem
->hDC
, nbkColor
);
161 DrawTextW(drawItem
->hDC
, szPreviewText
, wcslen(szPreviewText
), &drawItem
->rcItem
, 0);
162 SetTextColor(drawItem
->hDC
, ptColor
);
163 SetBkColor(drawItem
->hDC
, pbkColor
);
164 DeleteObject(hBrush
);
166 SelectObject(drawItem
->hDC
, OldFont
);
174 LayoutProc(HWND hwndDlg
,
183 /* Multi-monitor support */
184 LONG xVirtScr
, yVirtScr
; // Coordinates of the top-left virtual screen
185 LONG cxVirtScr
, cyVirtScr
; // Width and Height of the virtual screen
186 LONG cxFrame
, cyFrame
; // Thickness of the window frame
188 /* Multi-monitor support */
189 xVirtScr
= GetSystemMetrics(SM_XVIRTUALSCREEN
);
190 yVirtScr
= GetSystemMetrics(SM_YVIRTUALSCREEN
);
191 cxVirtScr
= GetSystemMetrics(SM_CXVIRTUALSCREEN
);
192 cyVirtScr
= GetSystemMetrics(SM_CYVIRTUALSCREEN
);
193 cxFrame
= GetSystemMetrics(SM_CXFRAME
);
194 cyFrame
= GetSystemMetrics(SM_CYFRAME
);
196 SendDlgItemMessageW(hwndDlg
, IDC_UPDOWN_SCREEN_BUFFER_HEIGHT
, UDM_SETRANGE
, 0, (LPARAM
)MAKELONG(9999, 1));
197 SendDlgItemMessageW(hwndDlg
, IDC_UPDOWN_SCREEN_BUFFER_WIDTH
, UDM_SETRANGE
, 0, (LPARAM
)MAKELONG(9999, 1));
198 SendDlgItemMessageW(hwndDlg
, IDC_UPDOWN_WINDOW_SIZE_HEIGHT
, UDM_SETRANGE
, 0, (LPARAM
)MAKELONG(9999, 1));
199 SendDlgItemMessageW(hwndDlg
, IDC_UPDOWN_WINDOW_SIZE_WIDTH
, UDM_SETRANGE
, 0, (LPARAM
)MAKELONG(9999, 1));
201 SetDlgItemInt(hwndDlg
, IDC_EDIT_SCREEN_BUFFER_HEIGHT
, ConInfo
->ScreenBufferSize
.Y
, FALSE
);
202 SetDlgItemInt(hwndDlg
, IDC_EDIT_SCREEN_BUFFER_WIDTH
, ConInfo
->ScreenBufferSize
.X
, FALSE
);
203 SetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_SIZE_HEIGHT
, ConInfo
->WindowSize
.Y
, FALSE
);
204 SetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_SIZE_WIDTH
, ConInfo
->WindowSize
.X
, FALSE
);
206 SendDlgItemMessageW(hwndDlg
, IDC_UPDOWN_WINDOW_POS_LEFT
, UDM_SETRANGE
, 0,
207 (LPARAM
)MAKELONG(xVirtScr
+ cxVirtScr
- cxFrame
, xVirtScr
- cxFrame
));
208 SendDlgItemMessageW(hwndDlg
, IDC_UPDOWN_WINDOW_POS_TOP
, UDM_SETRANGE
, 0,
209 (LPARAM
)MAKELONG(yVirtScr
+ cyVirtScr
- cyFrame
, yVirtScr
- cyFrame
));
211 SetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_POS_LEFT
, ConInfo
->WindowPosition
.x
, TRUE
);
212 SetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_POS_TOP
, ConInfo
->WindowPosition
.y
, TRUE
);
214 if (ConInfo
->AutoPosition
)
216 EnableDlgItem(hwndDlg
, IDC_EDIT_WINDOW_POS_LEFT
, FALSE
);
217 EnableDlgItem(hwndDlg
, IDC_EDIT_WINDOW_POS_TOP
, FALSE
);
218 EnableDlgItem(hwndDlg
, IDC_UPDOWN_WINDOW_POS_LEFT
, FALSE
);
219 EnableDlgItem(hwndDlg
, IDC_UPDOWN_WINDOW_POS_TOP
, FALSE
);
221 CheckDlgButton(hwndDlg
, IDC_CHECK_SYSTEM_POS_WINDOW
,
222 ConInfo
->AutoPosition
? BST_CHECKED
: BST_UNCHECKED
);
229 PaintConsole((LPDRAWITEMSTRUCT
)lParam
, ConInfo
);
235 LPPSHNOTIFY lppsn
= (LPPSHNOTIFY
)lParam
;
237 if (lppsn
->hdr
.code
== UDN_DELTAPOS
)
239 LPNMUPDOWN lpnmud
= (LPNMUPDOWN
)lParam
;
240 DWORD wheight
, wwidth
;
241 DWORD sheight
, swidth
;
244 if (lppsn
->hdr
.idFrom
== IDC_UPDOWN_WINDOW_SIZE_WIDTH
)
246 wwidth
= lpnmud
->iPos
+ lpnmud
->iDelta
;
250 wwidth
= GetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_SIZE_WIDTH
, NULL
, FALSE
);
253 if (lppsn
->hdr
.idFrom
== IDC_UPDOWN_WINDOW_SIZE_HEIGHT
)
255 wheight
= lpnmud
->iPos
+ lpnmud
->iDelta
;
259 wheight
= GetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_SIZE_HEIGHT
, NULL
, FALSE
);
262 if (lppsn
->hdr
.idFrom
== IDC_UPDOWN_SCREEN_BUFFER_WIDTH
)
264 swidth
= lpnmud
->iPos
+ lpnmud
->iDelta
;
268 swidth
= GetDlgItemInt(hwndDlg
, IDC_EDIT_SCREEN_BUFFER_WIDTH
, NULL
, FALSE
);
271 if (lppsn
->hdr
.idFrom
== IDC_UPDOWN_SCREEN_BUFFER_HEIGHT
)
273 sheight
= lpnmud
->iPos
+ lpnmud
->iDelta
;
277 sheight
= GetDlgItemInt(hwndDlg
, IDC_EDIT_SCREEN_BUFFER_HEIGHT
, NULL
, FALSE
);
280 if (lppsn
->hdr
.idFrom
== IDC_UPDOWN_WINDOW_POS_LEFT
)
282 left
= lpnmud
->iPos
+ lpnmud
->iDelta
;
286 left
= GetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_POS_LEFT
, NULL
, TRUE
);
289 if (lppsn
->hdr
.idFrom
== IDC_UPDOWN_WINDOW_POS_TOP
)
291 top
= lpnmud
->iPos
+ lpnmud
->iDelta
;
295 top
= GetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_POS_TOP
, NULL
, TRUE
);
298 if (lppsn
->hdr
.idFrom
== IDC_UPDOWN_WINDOW_SIZE_WIDTH
|| lppsn
->hdr
.idFrom
== IDC_UPDOWN_WINDOW_SIZE_HEIGHT
)
300 /* Automatically adjust screen buffer size when window size enlarges */
301 if (wwidth
>= swidth
)
303 SetDlgItemInt(hwndDlg
, IDC_EDIT_SCREEN_BUFFER_WIDTH
, wwidth
, TRUE
);
306 if (wheight
>= sheight
)
308 SetDlgItemInt(hwndDlg
, IDC_EDIT_SCREEN_BUFFER_HEIGHT
, wheight
, TRUE
);
313 /* Be sure that the (new) screen buffer sizes are in the correct range */
314 swidth
= min(max(swidth
, 1), 0xFFFF);
315 sheight
= min(max(sheight
, 1), 0xFFFF);
317 if (lppsn
->hdr
.idFrom
== IDC_UPDOWN_SCREEN_BUFFER_WIDTH
|| lppsn
->hdr
.idFrom
== IDC_UPDOWN_SCREEN_BUFFER_HEIGHT
)
319 /* Automatically adjust window size when screen buffer decreases */
322 SetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_SIZE_WIDTH
, swidth
, TRUE
);
325 if (wheight
> sheight
)
327 SetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_SIZE_HEIGHT
, sheight
, TRUE
);
332 ConInfo
->ScreenBufferSize
.X
= (SHORT
)swidth
;
333 ConInfo
->ScreenBufferSize
.Y
= (SHORT
)sheight
;
334 ConInfo
->WindowSize
.X
= (SHORT
)wwidth
;
335 ConInfo
->WindowSize
.Y
= (SHORT
)wheight
;
336 ConInfo
->WindowPosition
.x
= left
;
337 ConInfo
->WindowPosition
.y
= top
;
338 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
345 if (HIWORD(wParam
) == EN_KILLFOCUS
)
347 switch (LOWORD(wParam
))
349 case IDC_EDIT_SCREEN_BUFFER_WIDTH
:
351 DWORD swidth
, wwidth
;
353 swidth
= GetDlgItemInt(hwndDlg
, IDC_EDIT_SCREEN_BUFFER_WIDTH
, NULL
, FALSE
);
354 wwidth
= GetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_SIZE_WIDTH
, NULL
, FALSE
);
356 /* Be sure that the (new) screen buffer width is in the correct range */
357 swidth
= min(max(swidth
, 1), 0xFFFF);
359 /* Automatically adjust window size when screen buffer decreases */
363 SetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_SIZE_WIDTH
, wwidth
, TRUE
);
366 ConInfo
->ScreenBufferSize
.X
= (SHORT
)swidth
;
367 ConInfo
->WindowSize
.X
= (SHORT
)wwidth
;
368 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
372 case IDC_EDIT_WINDOW_SIZE_WIDTH
:
374 DWORD swidth
, wwidth
;
376 swidth
= GetDlgItemInt(hwndDlg
, IDC_EDIT_SCREEN_BUFFER_WIDTH
, NULL
, FALSE
);
377 wwidth
= GetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_SIZE_WIDTH
, NULL
, FALSE
);
379 /* Automatically adjust screen buffer size when window size enlarges */
380 if (wwidth
>= swidth
)
384 /* Be sure that the (new) screen buffer width is in the correct range */
385 swidth
= min(max(swidth
, 1), 0xFFFF);
387 SetDlgItemInt(hwndDlg
, IDC_EDIT_SCREEN_BUFFER_WIDTH
, swidth
, TRUE
);
390 ConInfo
->ScreenBufferSize
.X
= (SHORT
)swidth
;
391 ConInfo
->WindowSize
.X
= (SHORT
)wwidth
;
392 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
396 case IDC_EDIT_SCREEN_BUFFER_HEIGHT
:
398 DWORD sheight
, wheight
;
400 sheight
= GetDlgItemInt(hwndDlg
, IDC_EDIT_SCREEN_BUFFER_HEIGHT
, NULL
, FALSE
);
401 wheight
= GetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_SIZE_HEIGHT
, NULL
, FALSE
);
403 /* Be sure that the (new) screen buffer width is in the correct range */
404 sheight
= min(max(sheight
, 1), 0xFFFF);
406 /* Automatically adjust window size when screen buffer decreases */
407 if (wheight
> sheight
)
410 SetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_SIZE_HEIGHT
, wheight
, TRUE
);
413 ConInfo
->ScreenBufferSize
.Y
= (SHORT
)sheight
;
414 ConInfo
->WindowSize
.Y
= (SHORT
)wheight
;
415 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
419 case IDC_EDIT_WINDOW_SIZE_HEIGHT
:
421 DWORD sheight
, wheight
;
423 sheight
= GetDlgItemInt(hwndDlg
, IDC_EDIT_SCREEN_BUFFER_HEIGHT
, NULL
, FALSE
);
424 wheight
= GetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_SIZE_HEIGHT
, NULL
, FALSE
);
426 /* Automatically adjust screen buffer size when window size enlarges */
427 if (wheight
>= sheight
)
431 /* Be sure that the (new) screen buffer width is in the correct range */
432 sheight
= min(max(sheight
, 1), 0xFFFF);
434 SetDlgItemInt(hwndDlg
, IDC_EDIT_SCREEN_BUFFER_HEIGHT
, sheight
, TRUE
);
437 ConInfo
->ScreenBufferSize
.Y
= (SHORT
)sheight
;
438 ConInfo
->WindowSize
.Y
= (SHORT
)wheight
;
439 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
443 case IDC_EDIT_WINDOW_POS_LEFT
:
444 case IDC_EDIT_WINDOW_POS_TOP
:
446 ConInfo
->WindowPosition
.x
= GetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_POS_LEFT
, NULL
, TRUE
);
447 ConInfo
->WindowPosition
.y
= GetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_POS_TOP
, NULL
, TRUE
);
448 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
454 if (HIWORD(wParam
) == BN_CLICKED
&&
455 LOWORD(wParam
) == IDC_CHECK_SYSTEM_POS_WINDOW
)
457 if (IsDlgButtonChecked(hwndDlg
, IDC_CHECK_SYSTEM_POS_WINDOW
) == BST_CHECKED
)
459 EnableDlgItem(hwndDlg
, IDC_EDIT_WINDOW_POS_LEFT
, FALSE
);
460 EnableDlgItem(hwndDlg
, IDC_EDIT_WINDOW_POS_TOP
, FALSE
);
461 EnableDlgItem(hwndDlg
, IDC_UPDOWN_WINDOW_POS_LEFT
, FALSE
);
462 EnableDlgItem(hwndDlg
, IDC_UPDOWN_WINDOW_POS_TOP
, FALSE
);
464 ConInfo
->AutoPosition
= TRUE
;
465 // Do not touch ConInfo->WindowPosition !!
466 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
472 left
= GetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_POS_LEFT
, NULL
, TRUE
);
473 top
= GetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_POS_TOP
, NULL
, TRUE
);
475 EnableDlgItem(hwndDlg
, IDC_EDIT_WINDOW_POS_LEFT
, TRUE
);
476 EnableDlgItem(hwndDlg
, IDC_EDIT_WINDOW_POS_TOP
, TRUE
);
477 EnableDlgItem(hwndDlg
, IDC_UPDOWN_WINDOW_POS_LEFT
, TRUE
);
478 EnableDlgItem(hwndDlg
, IDC_UPDOWN_WINDOW_POS_TOP
, TRUE
);
480 ConInfo
->AutoPosition
= FALSE
;
481 ConInfo
->WindowPosition
.x
= left
;
482 ConInfo
->WindowPosition
.y
= top
;
483 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);