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_STATE_INFO pConInfo
)
36 FillRect(drawItem
->hDC
, &drawItem
->rcItem
, GetSysColorBrush(COLOR_BACKGROUND
));
38 // FIXME: Use: SM_CXSIZE, SM_CYSIZE, SM_CXVSCROLL, SM_CYHSCROLL, SM_CXMIN, SM_CYMIN, SM_CXFRAME, SM_CYFRAME
39 /* Use it for scaling */
40 sizex
= drawItem
->rcItem
.right
- drawItem
->rcItem
.left
;
41 sizey
= drawItem
->rcItem
.bottom
- drawItem
->rcItem
.top
;
43 if ( pConInfo
->WindowPosition
.x
== MAXDWORD
&&
44 pConInfo
->WindowPosition
.y
== MAXDWORD
)
52 // Calculate pos correctly when console centered
53 startx
= pConInfo
->WindowPosition
.x
;
54 starty
= pConInfo
->WindowPosition
.y
;
58 // Stretch console when bold fonts are selected
59 endx
= startx
+ pConInfo
->WindowSize
.X
; // drawItem->rcItem.right - startx + 15;
60 endy
= starty
+ pConInfo
->WindowSize
.Y
; // starty + sizey / 3;
62 /* Draw console size */
63 SetRect(&cRect
, startx
, starty
, endx
, endy
);
64 FillRect(drawItem
->hDC
, &cRect
, GetSysColorBrush(COLOR_WINDOWFRAME
));
66 /* Draw console border */
67 SetRect(&fRect
, startx
+ 1, starty
+ 1, cRect
.right
- 1, cRect
.bottom
- 1);
68 FrameRect(drawItem
->hDC
, &fRect
, GetSysColorBrush(COLOR_ACTIVEBORDER
));
71 SetRect(&fRect
, startx
+ 3, starty
+ 3, startx
+ 5, starty
+ 5);
72 FillRect(drawItem
->hDC
, &fRect
, GetSysColorBrush(COLOR_ACTIVEBORDER
));
74 /* Draw window title */
75 SetRect(&fRect
, startx
+ 7, starty
+ 3, cRect
.right
- 9, starty
+ 5);
76 FillRect(drawItem
->hDC
, &fRect
, GetSysColorBrush(COLOR_ACTIVECAPTION
));
78 /* Draw first right box */
79 SetRect(&fRect
, fRect
.right
+ 1, starty
+ 3, fRect
.right
+ 3, starty
+ 5);
80 FillRect(drawItem
->hDC
, &fRect
, GetSysColorBrush(COLOR_ACTIVEBORDER
));
82 /* Draw second right box */
83 SetRect(&fRect
, fRect
.right
+ 1, starty
+ 3, fRect
.right
+ 3, starty
+ 5);
84 FillRect(drawItem
->hDC
, &fRect
, GetSysColorBrush(COLOR_ACTIVEBORDER
));
87 SetRect(&fRect
, cRect
.right
- 5, fRect
.bottom
+ 1, cRect
.right
- 3, cRect
.bottom
- 3);
88 FillRect(drawItem
->hDC
, &fRect
, GetSysColorBrush(COLOR_SCROLLBAR
));
90 /* Draw console background */
91 hBrush
= CreateSolidBrush(pConInfo
->ColorTable
[BkgdAttribFromAttrib(pConInfo
->ScreenAttributes
)]);
92 SetRect(&fRect
, startx
+ 3, starty
+ 6, cRect
.right
- 6, cRect
.bottom
- 3);
93 FillRect(drawItem
->hDC
, &fRect
, hBrush
);
94 DeleteObject((HGDIOBJ
)hBrush
);
98 PaintText(LPDRAWITEMSTRUCT drawItem
,
99 PCONSOLE_STATE_INFO pConInfo
,
102 USHORT CurrentAttrib
;
103 COLORREF pbkColor
, ptColor
;
104 COLORREF nbkColor
, ntColor
;
108 COORD FontSize
= pConInfo
->FontSize
;
110 if (TextMode
== Screen
)
111 CurrentAttrib
= pConInfo
->ScreenAttributes
;
112 else if (TextMode
== Popup
)
113 CurrentAttrib
= pConInfo
->PopupAttributes
;
117 nbkColor
= pConInfo
->ColorTable
[BkgdAttribFromAttrib(CurrentAttrib
)];
118 ntColor
= pConInfo
->ColorTable
[TextAttribFromAttrib(CurrentAttrib
)];
120 hBrush
= CreateSolidBrush(nbkColor
);
121 if (!hBrush
) return FALSE
;
123 FontSize
.Y
= FontSize
.Y
> 0 ? -MulDiv(FontSize
.Y
, GetDeviceCaps(drawItem
->hDC
, LOGPIXELSY
), 72)
126 Font
= CreateFontW(FontSize
.Y
,
130 pConInfo
->FontWeight
,
138 FIXED_PITCH
| pConInfo
->FontFamily
,
142 DPRINT1("PaintText: CreateFont failed\n");
143 DeleteObject(hBrush
);
147 OldFont
= SelectObject(drawItem
->hDC
, Font
);
151 DeleteObject(hBrush
);
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 UNREFERENCED_PARAMETER(hwndDlg
);
178 UNREFERENCED_PARAMETER(wParam
);
184 /* Multi-monitor support */
185 LONG xVirtScr
, yVirtScr
; // Coordinates of the top-left virtual screen
186 LONG cxVirtScr
, cyVirtScr
; // Width and Height of the virtual screen
187 LONG cxFrame
, cyFrame
; // Thickness of the window frame
189 /* Multi-monitor support */
190 xVirtScr
= GetSystemMetrics(SM_XVIRTUALSCREEN
);
191 yVirtScr
= GetSystemMetrics(SM_YVIRTUALSCREEN
);
192 cxVirtScr
= GetSystemMetrics(SM_CXVIRTUALSCREEN
);
193 cyVirtScr
= GetSystemMetrics(SM_CYVIRTUALSCREEN
);
194 cxFrame
= GetSystemMetrics(SM_CXFRAME
);
195 cyFrame
= GetSystemMetrics(SM_CYFRAME
);
197 SendDlgItemMessageW(hwndDlg
, IDC_UPDOWN_SCREEN_BUFFER_HEIGHT
, UDM_SETRANGE
, 0, (LPARAM
)MAKELONG(9999, 1));
198 SendDlgItemMessageW(hwndDlg
, IDC_UPDOWN_SCREEN_BUFFER_WIDTH
, UDM_SETRANGE
, 0, (LPARAM
)MAKELONG(9999, 1));
199 SendDlgItemMessageW(hwndDlg
, IDC_UPDOWN_WINDOW_SIZE_HEIGHT
, UDM_SETRANGE
, 0, (LPARAM
)MAKELONG(9999, 1));
200 SendDlgItemMessageW(hwndDlg
, IDC_UPDOWN_WINDOW_SIZE_WIDTH
, UDM_SETRANGE
, 0, (LPARAM
)MAKELONG(9999, 1));
202 SetDlgItemInt(hwndDlg
, IDC_EDIT_SCREEN_BUFFER_HEIGHT
, ConInfo
->ScreenBufferSize
.Y
, FALSE
);
203 SetDlgItemInt(hwndDlg
, IDC_EDIT_SCREEN_BUFFER_WIDTH
, ConInfo
->ScreenBufferSize
.X
, FALSE
);
204 SetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_SIZE_HEIGHT
, ConInfo
->WindowSize
.Y
, FALSE
);
205 SetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_SIZE_WIDTH
, ConInfo
->WindowSize
.X
, FALSE
);
207 SendDlgItemMessageW(hwndDlg
, IDC_UPDOWN_WINDOW_POS_LEFT
, UDM_SETRANGE
, 0,
208 (LPARAM
)MAKELONG(xVirtScr
+ cxVirtScr
- cxFrame
, xVirtScr
- cxFrame
));
209 SendDlgItemMessageW(hwndDlg
, IDC_UPDOWN_WINDOW_POS_TOP
, UDM_SETRANGE
, 0,
210 (LPARAM
)MAKELONG(yVirtScr
+ cyVirtScr
- cyFrame
, yVirtScr
- cyFrame
));
212 SetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_POS_LEFT
, ConInfo
->WindowPosition
.x
, TRUE
);
213 SetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_POS_TOP
, ConInfo
->WindowPosition
.y
, TRUE
);
215 if (ConInfo
->AutoPosition
)
217 EnableDlgItem(hwndDlg
, IDC_EDIT_WINDOW_POS_LEFT
, FALSE
);
218 EnableDlgItem(hwndDlg
, IDC_EDIT_WINDOW_POS_TOP
, FALSE
);
219 EnableDlgItem(hwndDlg
, IDC_UPDOWN_WINDOW_POS_LEFT
, FALSE
);
220 EnableDlgItem(hwndDlg
, IDC_UPDOWN_WINDOW_POS_TOP
, FALSE
);
222 CheckDlgButton(hwndDlg
, IDC_CHECK_SYSTEM_POS_WINDOW
,
223 ConInfo
->AutoPosition
? BST_CHECKED
: BST_UNCHECKED
);
230 PaintConsole((LPDRAWITEMSTRUCT
)lParam
, ConInfo
);
236 LPNMUPDOWN lpnmud
= (LPNMUPDOWN
)lParam
;
237 LPPSHNOTIFY lppsn
= (LPPSHNOTIFY
)lParam
;
239 if (lppsn
->hdr
.code
== UDN_DELTAPOS
)
241 DWORD wheight
, wwidth
;
242 DWORD sheight
, swidth
;
245 if (lppsn
->hdr
.idFrom
== IDC_UPDOWN_WINDOW_SIZE_WIDTH
)
247 wwidth
= lpnmud
->iPos
+ lpnmud
->iDelta
;
251 wwidth
= GetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_SIZE_WIDTH
, NULL
, FALSE
);
254 if (lppsn
->hdr
.idFrom
== IDC_UPDOWN_WINDOW_SIZE_HEIGHT
)
256 wheight
= lpnmud
->iPos
+ lpnmud
->iDelta
;
260 wheight
= GetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_SIZE_HEIGHT
, NULL
, FALSE
);
263 if (lppsn
->hdr
.idFrom
== IDC_UPDOWN_SCREEN_BUFFER_WIDTH
)
265 swidth
= lpnmud
->iPos
+ lpnmud
->iDelta
;
269 swidth
= GetDlgItemInt(hwndDlg
, IDC_EDIT_SCREEN_BUFFER_WIDTH
, NULL
, FALSE
);
272 if (lppsn
->hdr
.idFrom
== IDC_UPDOWN_SCREEN_BUFFER_HEIGHT
)
274 sheight
= lpnmud
->iPos
+ lpnmud
->iDelta
;
278 sheight
= GetDlgItemInt(hwndDlg
, IDC_EDIT_SCREEN_BUFFER_HEIGHT
, NULL
, FALSE
);
281 if (lppsn
->hdr
.idFrom
== IDC_UPDOWN_WINDOW_POS_LEFT
)
283 left
= lpnmud
->iPos
+ lpnmud
->iDelta
;
287 left
= GetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_POS_LEFT
, NULL
, TRUE
);
290 if (lppsn
->hdr
.idFrom
== IDC_UPDOWN_WINDOW_POS_TOP
)
292 top
= lpnmud
->iPos
+ lpnmud
->iDelta
;
296 top
= GetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_POS_TOP
, NULL
, TRUE
);
299 if (lppsn
->hdr
.idFrom
== IDC_UPDOWN_WINDOW_SIZE_WIDTH
|| lppsn
->hdr
.idFrom
== IDC_UPDOWN_WINDOW_SIZE_HEIGHT
)
301 /* Automatically adjust screen buffer size when window size enlarges */
302 if (wwidth
>= swidth
)
304 SetDlgItemInt(hwndDlg
, IDC_EDIT_SCREEN_BUFFER_WIDTH
, wwidth
, TRUE
);
307 if (wheight
>= sheight
)
309 SetDlgItemInt(hwndDlg
, IDC_EDIT_SCREEN_BUFFER_HEIGHT
, wheight
, TRUE
);
314 /* Be sure that the (new) screen buffer sizes are in the correct range */
315 swidth
= min(max(swidth
, 1), 0xFFFF);
316 sheight
= min(max(sheight
, 1), 0xFFFF);
318 if (lppsn
->hdr
.idFrom
== IDC_UPDOWN_SCREEN_BUFFER_WIDTH
|| lppsn
->hdr
.idFrom
== IDC_UPDOWN_SCREEN_BUFFER_HEIGHT
)
320 /* Automatically adjust window size when screen buffer decreases */
323 SetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_SIZE_WIDTH
, swidth
, TRUE
);
326 if (wheight
> sheight
)
328 SetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_SIZE_HEIGHT
, sheight
, TRUE
);
333 ConInfo
->ScreenBufferSize
.X
= (SHORT
)swidth
;
334 ConInfo
->ScreenBufferSize
.Y
= (SHORT
)sheight
;
335 ConInfo
->WindowSize
.X
= (SHORT
)wwidth
;
336 ConInfo
->WindowSize
.Y
= (SHORT
)wheight
;
337 ConInfo
->WindowPosition
.x
= left
;
338 ConInfo
->WindowPosition
.y
= top
;
339 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
346 switch (LOWORD(wParam
))
348 case IDC_EDIT_SCREEN_BUFFER_WIDTH
:
350 if (HIWORD(wParam
) == EN_KILLFOCUS
)
352 DWORD swidth
, wwidth
;
354 swidth
= GetDlgItemInt(hwndDlg
, IDC_EDIT_SCREEN_BUFFER_WIDTH
, NULL
, FALSE
);
355 wwidth
= GetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_SIZE_WIDTH
, NULL
, FALSE
);
357 /* Be sure that the (new) screen buffer width is in the correct range */
358 swidth
= min(max(swidth
, 1), 0xFFFF);
360 /* Automatically adjust window size when screen buffer decreases */
364 SetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_SIZE_WIDTH
, wwidth
, TRUE
);
367 ConInfo
->ScreenBufferSize
.X
= (SHORT
)swidth
;
368 ConInfo
->WindowSize
.X
= (SHORT
)wwidth
;
369 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
374 case IDC_EDIT_WINDOW_SIZE_WIDTH
:
376 if (HIWORD(wParam
) == EN_KILLFOCUS
)
378 DWORD swidth
, wwidth
;
380 swidth
= GetDlgItemInt(hwndDlg
, IDC_EDIT_SCREEN_BUFFER_WIDTH
, NULL
, FALSE
);
381 wwidth
= GetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_SIZE_WIDTH
, NULL
, FALSE
);
383 /* Automatically adjust screen buffer size when window size enlarges */
384 if (wwidth
>= swidth
)
388 /* Be sure that the (new) screen buffer width is in the correct range */
389 swidth
= min(max(swidth
, 1), 0xFFFF);
391 SetDlgItemInt(hwndDlg
, IDC_EDIT_SCREEN_BUFFER_WIDTH
, swidth
, TRUE
);
394 ConInfo
->ScreenBufferSize
.X
= (SHORT
)swidth
;
395 ConInfo
->WindowSize
.X
= (SHORT
)wwidth
;
396 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
401 case IDC_EDIT_SCREEN_BUFFER_HEIGHT
:
403 if (HIWORD(wParam
) == EN_KILLFOCUS
)
405 DWORD sheight
, wheight
;
407 sheight
= GetDlgItemInt(hwndDlg
, IDC_EDIT_SCREEN_BUFFER_HEIGHT
, NULL
, FALSE
);
408 wheight
= GetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_SIZE_HEIGHT
, NULL
, FALSE
);
410 /* Be sure that the (new) screen buffer width is in the correct range */
411 sheight
= min(max(sheight
, 1), 0xFFFF);
413 /* Automatically adjust window size when screen buffer decreases */
414 if (wheight
> sheight
)
417 SetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_SIZE_HEIGHT
, wheight
, TRUE
);
420 ConInfo
->ScreenBufferSize
.Y
= (SHORT
)sheight
;
421 ConInfo
->WindowSize
.Y
= (SHORT
)wheight
;
422 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
427 case IDC_EDIT_WINDOW_SIZE_HEIGHT
:
429 if (HIWORD(wParam
) == EN_KILLFOCUS
)
431 DWORD sheight
, wheight
;
433 sheight
= GetDlgItemInt(hwndDlg
, IDC_EDIT_SCREEN_BUFFER_HEIGHT
, NULL
, FALSE
);
434 wheight
= GetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_SIZE_HEIGHT
, NULL
, FALSE
);
436 /* Automatically adjust screen buffer size when window size enlarges */
437 if (wheight
>= sheight
)
441 /* Be sure that the (new) screen buffer width is in the correct range */
442 sheight
= min(max(sheight
, 1), 0xFFFF);
444 SetDlgItemInt(hwndDlg
, IDC_EDIT_SCREEN_BUFFER_HEIGHT
, sheight
, TRUE
);
447 ConInfo
->ScreenBufferSize
.Y
= (SHORT
)sheight
;
448 ConInfo
->WindowSize
.Y
= (SHORT
)wheight
;
449 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
454 case IDC_EDIT_WINDOW_POS_LEFT
:
455 case IDC_EDIT_WINDOW_POS_TOP
:
457 if (HIWORD(wParam
) == EN_KILLFOCUS
)
461 left
= GetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_POS_LEFT
, NULL
, TRUE
);
462 top
= GetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_POS_TOP
, NULL
, TRUE
);
464 ConInfo
->WindowPosition
.x
= left
;
465 ConInfo
->WindowPosition
.y
= top
;
466 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
471 case IDC_CHECK_SYSTEM_POS_WINDOW
:
473 LONG res
= SendMessage((HWND
)lParam
, BM_GETCHECK
, 0, 0);
474 if (res
== BST_CHECKED
)
478 left
= GetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_POS_LEFT
, NULL
, TRUE
);
479 top
= GetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_POS_TOP
, NULL
, TRUE
);
481 ConInfo
->AutoPosition
= FALSE
;
482 ConInfo
->WindowPosition
.x
= left
;
483 ConInfo
->WindowPosition
.y
= top
;
484 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
486 SendMessage((HWND
)lParam
, BM_SETCHECK
, (WPARAM
)BST_UNCHECKED
, 0);
487 EnableDlgItem(hwndDlg
, IDC_EDIT_WINDOW_POS_LEFT
, TRUE
);
488 EnableDlgItem(hwndDlg
, IDC_EDIT_WINDOW_POS_TOP
, TRUE
);
489 EnableDlgItem(hwndDlg
, IDC_UPDOWN_WINDOW_POS_LEFT
, TRUE
);
490 EnableDlgItem(hwndDlg
, IDC_UPDOWN_WINDOW_POS_TOP
, TRUE
);
492 else if (res
== BST_UNCHECKED
)
494 ConInfo
->AutoPosition
= TRUE
;
495 // Do not touch ConInfo->WindowPosition !!
496 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
498 SendMessage((HWND
)lParam
, BM_SETCHECK
, (WPARAM
)BST_CHECKED
, 0);
499 EnableDlgItem(hwndDlg
, IDC_EDIT_WINDOW_POS_LEFT
, FALSE
);
500 EnableDlgItem(hwndDlg
, IDC_EDIT_WINDOW_POS_TOP
, FALSE
);
501 EnableDlgItem(hwndDlg
, IDC_UPDOWN_WINDOW_POS_LEFT
, FALSE
);
502 EnableDlgItem(hwndDlg
, IDC_UPDOWN_WINDOW_POS_TOP
, FALSE
);