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> 03-03-13 5:00a\n") \
17 _T("SYSTEM32 <DIR> 03-03-13 5:00a\n") \
18 _T("readme txt 1739 03-03-13 5:00a\n") \
19 _T("explorer exe 3329536 03-03-13 5:00a\n") \
20 _T("vgafonts cab 18736 03-03-13 5:00a\n") \
21 _T("setuplog txt 313 03-03-13 5:00a\n") \
22 _T("win ini 7005 03-03-13 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
= (COORD
){swidth
, sheight
};
296 pConInfo
->ci
.ConsoleSize
= (COORD
){wwidth
, wheight
};
297 GuiInfo
->WindowOrigin
= (POINT
){left
, top
};
298 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
304 switch (LOWORD(wParam
))
306 case IDC_EDIT_SCREEN_BUFFER_WIDTH
:
307 case IDC_EDIT_SCREEN_BUFFER_HEIGHT
:
308 case IDC_EDIT_WINDOW_SIZE_WIDTH
:
309 case IDC_UPDOWN_WINDOW_SIZE_HEIGHT
:
310 case IDC_EDIT_WINDOW_POS_LEFT
:
311 case IDC_EDIT_WINDOW_POS_TOP
:
313 if (HIWORD(wParam
) == EN_KILLFOCUS
)
315 DWORD wheight
, wwidth
;
316 DWORD sheight
, swidth
;
319 wwidth
= GetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_SIZE_WIDTH
, NULL
, FALSE
);
320 wheight
= GetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_SIZE_HEIGHT
, NULL
, FALSE
);
321 swidth
= GetDlgItemInt(hwndDlg
, IDC_EDIT_SCREEN_BUFFER_WIDTH
, NULL
, FALSE
);
322 sheight
= GetDlgItemInt(hwndDlg
, IDC_EDIT_SCREEN_BUFFER_HEIGHT
, NULL
, FALSE
);
323 left
= GetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_POS_LEFT
, NULL
, FALSE
);
324 top
= GetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_POS_TOP
, NULL
, FALSE
);
326 swidth
= max(swidth
, 1);
327 sheight
= max(sheight
, 1);
329 /* Automatically adjust window size when screen buffer decreases */
332 SetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_SIZE_WIDTH
, swidth
, TRUE
);
336 if (wheight
> sheight
)
338 SetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_SIZE_HEIGHT
, sheight
, TRUE
);
342 pConInfo
->ci
.ScreenBufferSize
= (COORD
){swidth
, sheight
};
343 pConInfo
->ci
.ConsoleSize
= (COORD
){wwidth
, wheight
};
344 GuiInfo
->WindowOrigin
= (POINT
){left
, top
};
345 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
350 case IDC_CHECK_SYSTEM_POS_WINDOW
:
352 LONG res
= SendMessage((HWND
)lParam
, BM_GETCHECK
, 0, 0);
353 if (res
== BST_CHECKED
)
357 left
= GetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_POS_LEFT
, NULL
, FALSE
);
358 top
= GetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_POS_TOP
, NULL
, FALSE
);
359 GuiInfo
->WindowOrigin
= (POINT
){left
, top
};
360 SendMessage((HWND
)lParam
, BM_SETCHECK
, (WPARAM
)BST_UNCHECKED
, 0);
361 EnableWindow(GetDlgItem(hwndDlg
, IDC_EDIT_WINDOW_POS_LEFT
), TRUE
);
362 EnableWindow(GetDlgItem(hwndDlg
, IDC_EDIT_WINDOW_POS_TOP
), TRUE
);
363 EnableWindow(GetDlgItem(hwndDlg
, IDC_UPDOWN_WINDOW_POS_LEFT
), TRUE
);
364 EnableWindow(GetDlgItem(hwndDlg
, IDC_UPDOWN_WINDOW_POS_TOP
), TRUE
);
366 else if (res
== BST_UNCHECKED
)
368 GuiInfo
->WindowOrigin
= (POINT
){UINT_MAX
, UINT_MAX
};
369 SendMessage((HWND
)lParam
, BM_SETCHECK
, (WPARAM
)BST_CHECKED
, 0);
370 EnableWindow(GetDlgItem(hwndDlg
, IDC_EDIT_WINDOW_POS_LEFT
), FALSE
);
371 EnableWindow(GetDlgItem(hwndDlg
, IDC_EDIT_WINDOW_POS_TOP
), FALSE
);
372 EnableWindow(GetDlgItem(hwndDlg
, IDC_UPDOWN_WINDOW_POS_LEFT
), FALSE
);
373 EnableWindow(GetDlgItem(hwndDlg
, IDC_UPDOWN_WINDOW_POS_TOP
), FALSE
);