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)
14 const TCHAR szPreviewText
[] =
15 _T("C:\\ReactOS> dir \n") \
16 _T("SYSTEM <DIR> 13-04-15 5:00a\n") \
17 _T("SYSTEM32 <DIR> 13-04-15 5:00a\n") \
18 _T("readme txt 1739 13-04-15 5:00a\n") \
19 _T("explorer exe 3329536 13-04-15 5:00a\n") \
20 _T("vgafonts cab 18736 13-04-15 5:00a\n") \
21 _T("setuplog txt 313 13-04-15 5:00a\n") \
22 _T("win ini 7005 13-04-15 5:00a\n");
26 PaintConsole(LPDRAWITEMSTRUCT drawItem
,
27 PCONSOLE_PROPS pConInfo
)
29 PGUI_CONSOLE_INFO GuiInfo
= pConInfo
->TerminalInfo
.TermInfo
;
36 FillRect(drawItem
->hDC
, &drawItem
->rcItem
, GetSysColorBrush(COLOR_BACKGROUND
));
38 sizex
= drawItem
->rcItem
.right
- drawItem
->rcItem
.left
;
39 sizey
= drawItem
->rcItem
.bottom
- drawItem
->rcItem
.top
;
41 if ( GuiInfo
->WindowOrigin
.x
== MAXDWORD
&&
42 GuiInfo
->WindowOrigin
.y
== MAXDWORD
)
50 // Calculate pos correctly when console centered
56 // Strech console when bold fonts are selected
57 endx
= drawItem
->rcItem
.right
- startx
+ 15;
58 endy
= starty
+ sizey
/ 3;
60 /* Draw console size */
61 SetRect(&cRect
, startx
, starty
, endx
, endy
);
62 FillRect(drawItem
->hDC
, &cRect
, GetSysColorBrush(COLOR_WINDOWFRAME
));
64 /* Draw console border */
65 SetRect(&fRect
, startx
+ 1, starty
+ 1, cRect
.right
- 1, cRect
.bottom
- 1);
66 FrameRect(drawItem
->hDC
, &fRect
, GetSysColorBrush(COLOR_ACTIVEBORDER
));
69 SetRect(&fRect
, startx
+ 3, starty
+ 3, startx
+ 5, starty
+ 5);
70 FillRect(drawItem
->hDC
, &fRect
, GetSysColorBrush(COLOR_ACTIVEBORDER
));
72 /* Draw window title */
73 SetRect(&fRect
, startx
+ 7, starty
+ 3, cRect
.right
- 9, starty
+ 5);
74 FillRect(drawItem
->hDC
, &fRect
, GetSysColorBrush(COLOR_ACTIVECAPTION
));
76 /* Draw first right box */
77 SetRect(&fRect
, fRect
.right
+ 1, starty
+ 3, fRect
.right
+ 3, starty
+ 5);
78 FillRect(drawItem
->hDC
, &fRect
, GetSysColorBrush(COLOR_ACTIVEBORDER
));
80 /* Draw second right box */
81 SetRect(&fRect
, fRect
.right
+ 1, starty
+ 3, fRect
.right
+ 3, starty
+ 5);
82 FillRect(drawItem
->hDC
, &fRect
, GetSysColorBrush(COLOR_ACTIVEBORDER
));
85 SetRect(&fRect
, cRect
.right
- 5, fRect
.bottom
+ 1, cRect
.right
- 3, cRect
.bottom
- 3);
86 FillRect(drawItem
->hDC
, &fRect
, GetSysColorBrush(COLOR_SCROLLBAR
));
88 /* Draw console background */
89 hBrush
= CreateSolidBrush(pConInfo
->ci
.Colors
[BkgdAttribFromAttrib(pConInfo
->ci
.ScreenAttrib
)]);
90 SetRect(&fRect
, startx
+ 3, starty
+ 6, cRect
.right
- 6, cRect
.bottom
- 3);
91 FillRect(drawItem
->hDC
, &fRect
, hBrush
);
92 DeleteObject((HGDIOBJ
)hBrush
);
95 VOID
PaintText(LPDRAWITEMSTRUCT drawItem
,
96 PCONSOLE_PROPS pConInfo
)
98 COLORREF pbkColor
, ptColor
;
99 COLORREF nbkColor
, ntColor
;
100 HBRUSH hBrush
= NULL
;
102 if (drawItem
->CtlID
== IDC_STATIC_SCREEN_COLOR
)
104 nbkColor
= pConInfo
->ci
.Colors
[BkgdAttribFromAttrib(pConInfo
->ci
.ScreenAttrib
)];
105 hBrush
= CreateSolidBrush(nbkColor
);
106 ntColor
= pConInfo
->ci
.Colors
[TextAttribFromAttrib(pConInfo
->ci
.ScreenAttrib
)];
108 else if (drawItem
->CtlID
== IDC_STATIC_POPUP_COLOR
)
110 nbkColor
= pConInfo
->ci
.Colors
[BkgdAttribFromAttrib(pConInfo
->ci
.PopupAttrib
)];
111 hBrush
= CreateSolidBrush(nbkColor
);
112 ntColor
= pConInfo
->ci
.Colors
[TextAttribFromAttrib(pConInfo
->ci
.PopupAttrib
)];
120 FillRect(drawItem
->hDC
, &drawItem
->rcItem
, hBrush
);
122 ptColor
= SetTextColor(drawItem
->hDC
, ntColor
);
123 pbkColor
= SetBkColor(drawItem
->hDC
, nbkColor
);
124 DrawText(drawItem
->hDC
, szPreviewText
, _tcslen(szPreviewText
), &drawItem
->rcItem
, 0);
125 SetTextColor(drawItem
->hDC
, ptColor
);
126 SetBkColor(drawItem
->hDC
, pbkColor
);
127 DeleteObject((HGDIOBJ
)hBrush
);
132 LayoutProc(HWND hwndDlg
,
139 PCONSOLE_PROPS pConInfo
= (PCONSOLE_PROPS
)GetWindowLongPtr(hwndDlg
, DWLP_USER
);
140 PGUI_CONSOLE_INFO GuiInfo
= (pConInfo
? pConInfo
->TerminalInfo
.TermInfo
: NULL
);
142 UNREFERENCED_PARAMETER(hwndDlg
);
143 UNREFERENCED_PARAMETER(wParam
);
151 pConInfo
= (PCONSOLE_PROPS
)((LPPROPSHEETPAGE
)lParam
)->lParam
;
152 GuiInfo
= pConInfo
->TerminalInfo
.TermInfo
;
153 SetWindowLongPtr(hwndDlg
, DWLP_USER
, (LONG_PTR
)pConInfo
);
155 SendMessage(GetDlgItem(hwndDlg
, IDC_UPDOWN_SCREEN_BUFFER_HEIGHT
), UDM_SETRANGE
, 0, (LPARAM
)MAKELONG(9999, 1));
156 SendMessage(GetDlgItem(hwndDlg
, IDC_UPDOWN_SCREEN_BUFFER_WIDTH
), UDM_SETRANGE
, 0, (LPARAM
)MAKELONG(9999, 1));
157 SendMessage(GetDlgItem(hwndDlg
, IDC_UPDOWN_WINDOW_SIZE_HEIGHT
), UDM_SETRANGE
, 0, (LPARAM
)MAKELONG(9999, 1));
158 SendMessage(GetDlgItem(hwndDlg
, IDC_UPDOWN_WINDOW_SIZE_WIDTH
), UDM_SETRANGE
, 0, (LPARAM
)MAKELONG(9999, 1));
160 SetDlgItemInt(hwndDlg
, IDC_EDIT_SCREEN_BUFFER_HEIGHT
, pConInfo
->ci
.ScreenBufferSize
.Y
, FALSE
);
161 SetDlgItemInt(hwndDlg
, IDC_EDIT_SCREEN_BUFFER_WIDTH
, pConInfo
->ci
.ScreenBufferSize
.X
, FALSE
);
162 SetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_SIZE_HEIGHT
, pConInfo
->ci
.ConsoleSize
.Y
, FALSE
);
163 SetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_SIZE_WIDTH
, pConInfo
->ci
.ConsoleSize
.X
, FALSE
);
166 xres
= GetDeviceCaps(hDC
, HORZRES
);
167 yres
= GetDeviceCaps(hDC
, VERTRES
);
168 SendMessage(GetDlgItem(hwndDlg
, IDC_UPDOWN_WINDOW_POS_LEFT
), UDM_SETRANGE
, 0, (LPARAM
)MAKELONG(xres
, 0));
169 SendMessage(GetDlgItem(hwndDlg
, IDC_UPDOWN_WINDOW_POS_TOP
), UDM_SETRANGE
, 0, (LPARAM
)MAKELONG(yres
, 0));
171 if ( GuiInfo
->WindowOrigin
.x
!= MAXDWORD
&&
172 GuiInfo
->WindowOrigin
.y
!= MAXDWORD
)
174 SetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_POS_LEFT
, GuiInfo
->WindowOrigin
.x
, FALSE
);
175 SetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_POS_TOP
, GuiInfo
->WindowOrigin
.y
, FALSE
);
179 // FIXME: Calculate window pos from xres, yres
180 SetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_POS_LEFT
, 88, FALSE
);
181 SetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_POS_TOP
, 88, FALSE
);
182 EnableWindow(GetDlgItem(hwndDlg
, IDC_EDIT_WINDOW_POS_LEFT
), FALSE
);
183 EnableWindow(GetDlgItem(hwndDlg
, IDC_EDIT_WINDOW_POS_TOP
), FALSE
);
184 EnableWindow(GetDlgItem(hwndDlg
, IDC_UPDOWN_WINDOW_POS_LEFT
), FALSE
);
185 EnableWindow(GetDlgItem(hwndDlg
, IDC_UPDOWN_WINDOW_POS_TOP
), FALSE
);
186 SendMessage(GetDlgItem(hwndDlg
, IDC_CHECK_SYSTEM_POS_WINDOW
), BM_SETCHECK
, (WPARAM
)BST_CHECKED
, 0);
193 PaintConsole((LPDRAWITEMSTRUCT
)lParam
, pConInfo
);
198 lpnmud
= (LPNMUPDOWN
) lParam
;
199 lppsn
= (LPPSHNOTIFY
) lParam
;
201 if (lppsn
->hdr
.code
== UDN_DELTAPOS
)
203 DWORD wheight
, wwidth
;
204 DWORD sheight
, swidth
;
207 if (lppsn
->hdr
.idFrom
== IDC_UPDOWN_WINDOW_SIZE_WIDTH
)
209 wwidth
= lpnmud
->iPos
+ lpnmud
->iDelta
;
213 wwidth
= GetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_SIZE_WIDTH
, NULL
, FALSE
);
216 if (lppsn
->hdr
.idFrom
== IDC_UPDOWN_WINDOW_SIZE_HEIGHT
)
218 wheight
= lpnmud
->iPos
+ lpnmud
->iDelta
;
222 wheight
= GetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_SIZE_HEIGHT
, NULL
, FALSE
);
225 if (lppsn
->hdr
.idFrom
== IDC_UPDOWN_SCREEN_BUFFER_WIDTH
)
227 swidth
= lpnmud
->iPos
+ lpnmud
->iDelta
;
231 swidth
= GetDlgItemInt(hwndDlg
, IDC_EDIT_SCREEN_BUFFER_WIDTH
, NULL
, FALSE
);
234 if (lppsn
->hdr
.idFrom
== IDC_UPDOWN_SCREEN_BUFFER_HEIGHT
)
236 sheight
= lpnmud
->iPos
+ lpnmud
->iDelta
;
240 sheight
= GetDlgItemInt(hwndDlg
, IDC_EDIT_SCREEN_BUFFER_HEIGHT
, NULL
, FALSE
);
243 if (lppsn
->hdr
.idFrom
== IDC_UPDOWN_WINDOW_POS_LEFT
)
245 left
= lpnmud
->iPos
+ lpnmud
->iDelta
;
249 left
= GetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_POS_LEFT
, NULL
, FALSE
);
252 if (lppsn
->hdr
.idFrom
== IDC_UPDOWN_WINDOW_POS_TOP
)
254 top
= lpnmud
->iPos
+ lpnmud
->iDelta
;
258 top
= GetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_POS_TOP
, NULL
, FALSE
);
261 if (lppsn
->hdr
.idFrom
== IDC_UPDOWN_WINDOW_SIZE_WIDTH
|| lppsn
->hdr
.idFrom
== IDC_UPDOWN_WINDOW_SIZE_HEIGHT
)
263 /* Automatically adjust screen buffer size when window size enlarges */
264 if (wwidth
>= swidth
)
266 SetDlgItemInt(hwndDlg
, IDC_EDIT_SCREEN_BUFFER_WIDTH
, wwidth
, TRUE
);
270 if (wheight
>= sheight
)
272 SetDlgItemInt(hwndDlg
, IDC_EDIT_SCREEN_BUFFER_HEIGHT
, wheight
, TRUE
);
276 swidth
= max(swidth
, 1);
277 sheight
= max(sheight
, 1);
279 if (lppsn
->hdr
.idFrom
== IDC_UPDOWN_SCREEN_BUFFER_WIDTH
|| lppsn
->hdr
.idFrom
== IDC_UPDOWN_SCREEN_BUFFER_HEIGHT
)
281 /* Automatically adjust window size when screen buffer decreases */
284 SetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_SIZE_WIDTH
, swidth
, TRUE
);
288 if (wheight
> sheight
)
290 SetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_SIZE_HEIGHT
, sheight
, TRUE
);
295 pConInfo
->ci
.ScreenBufferSize
.X
= swidth
;
296 pConInfo
->ci
.ScreenBufferSize
.Y
= sheight
;
297 pConInfo
->ci
.ConsoleSize
.X
= wwidth
;
298 pConInfo
->ci
.ConsoleSize
.Y
= wheight
;
299 GuiInfo
->WindowOrigin
.x
= left
;
300 GuiInfo
->WindowOrigin
.y
= top
;
301 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
307 switch (LOWORD(wParam
))
309 case IDC_EDIT_SCREEN_BUFFER_WIDTH
:
310 case IDC_EDIT_SCREEN_BUFFER_HEIGHT
:
311 case IDC_EDIT_WINDOW_SIZE_WIDTH
:
312 case IDC_UPDOWN_WINDOW_SIZE_HEIGHT
:
313 case IDC_EDIT_WINDOW_POS_LEFT
:
314 case IDC_EDIT_WINDOW_POS_TOP
:
316 if (HIWORD(wParam
) == EN_KILLFOCUS
)
318 DWORD wheight
, wwidth
;
319 DWORD sheight
, swidth
;
322 wwidth
= GetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_SIZE_WIDTH
, NULL
, FALSE
);
323 wheight
= GetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_SIZE_HEIGHT
, NULL
, FALSE
);
324 swidth
= GetDlgItemInt(hwndDlg
, IDC_EDIT_SCREEN_BUFFER_WIDTH
, NULL
, FALSE
);
325 sheight
= GetDlgItemInt(hwndDlg
, IDC_EDIT_SCREEN_BUFFER_HEIGHT
, NULL
, FALSE
);
326 left
= GetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_POS_LEFT
, NULL
, FALSE
);
327 top
= GetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_POS_TOP
, NULL
, FALSE
);
329 swidth
= max(swidth
, 1);
330 sheight
= max(sheight
, 1);
332 /* Automatically adjust window size when screen buffer decreases */
335 SetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_SIZE_WIDTH
, swidth
, TRUE
);
339 if (wheight
> sheight
)
341 SetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_SIZE_HEIGHT
, sheight
, TRUE
);
345 pConInfo
->ci
.ScreenBufferSize
.X
= swidth
;
346 pConInfo
->ci
.ScreenBufferSize
.Y
= sheight
;
347 pConInfo
->ci
.ConsoleSize
.X
= wwidth
;
348 pConInfo
->ci
.ConsoleSize
.Y
= wheight
;
349 GuiInfo
->WindowOrigin
.x
= left
;
350 GuiInfo
->WindowOrigin
.y
= top
;
351 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
356 case IDC_CHECK_SYSTEM_POS_WINDOW
:
358 LONG res
= SendMessage((HWND
)lParam
, BM_GETCHECK
, 0, 0);
359 if (res
== BST_CHECKED
)
363 left
= GetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_POS_LEFT
, NULL
, FALSE
);
364 top
= GetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_POS_TOP
, NULL
, FALSE
);
365 GuiInfo
->WindowOrigin
.x
= left
;
366 GuiInfo
->WindowOrigin
.y
= top
;
367 SendMessage((HWND
)lParam
, BM_SETCHECK
, (WPARAM
)BST_UNCHECKED
, 0);
368 EnableWindow(GetDlgItem(hwndDlg
, IDC_EDIT_WINDOW_POS_LEFT
), TRUE
);
369 EnableWindow(GetDlgItem(hwndDlg
, IDC_EDIT_WINDOW_POS_TOP
), TRUE
);
370 EnableWindow(GetDlgItem(hwndDlg
, IDC_UPDOWN_WINDOW_POS_LEFT
), TRUE
);
371 EnableWindow(GetDlgItem(hwndDlg
, IDC_UPDOWN_WINDOW_POS_TOP
), TRUE
);
373 else if (res
== BST_UNCHECKED
)
375 GuiInfo
->WindowOrigin
.x
= UINT_MAX
;
376 GuiInfo
->WindowOrigin
.y
= UINT_MAX
;
377 SendMessage((HWND
)lParam
, BM_SETCHECK
, (WPARAM
)BST_CHECKED
, 0);
378 EnableWindow(GetDlgItem(hwndDlg
, IDC_EDIT_WINDOW_POS_LEFT
), FALSE
);
379 EnableWindow(GetDlgItem(hwndDlg
, IDC_EDIT_WINDOW_POS_TOP
), FALSE
);
380 EnableWindow(GetDlgItem(hwndDlg
, IDC_UPDOWN_WINDOW_POS_LEFT
), FALSE
);
381 EnableWindow(GetDlgItem(hwndDlg
, IDC_UPDOWN_WINDOW_POS_TOP
), FALSE
);