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)
12 void PaintConsole(LPDRAWITEMSTRUCT drawItem
, PConsoleInfo pConInfo
)
20 FillRect(drawItem
->hDC
, &drawItem
->rcItem
, GetSysColorBrush(COLOR_BACKGROUND
));
22 sizex
= drawItem
->rcItem
.right
- drawItem
->rcItem
.left
;
23 sizey
= drawItem
->rcItem
.bottom
- drawItem
->rcItem
.top
;
25 if (pConInfo
->WindowPosition
== UINT_MAX
)
33 // Calculate pos correctly when console centered
39 // Strech console when bold fonts are selected
40 endx
= drawItem
->rcItem
.right
- startx
+ 15;
41 endy
= starty
+ sizey
/ 3;
43 /* Draw console size */
44 SetRect(&cRect
, startx
, starty
, endx
, endy
);
45 FillRect(drawItem
->hDC
, &cRect
, GetSysColorBrush(COLOR_WINDOWFRAME
));
47 /* Draw console border */
48 SetRect(&fRect
, startx
+ 1, starty
+ 1, cRect
.right
- 1, cRect
.bottom
- 1);
49 FrameRect(drawItem
->hDC
, &fRect
, GetSysColorBrush(COLOR_ACTIVEBORDER
));
52 SetRect(&fRect
, startx
+ 3, starty
+ 3, startx
+ 5, starty
+ 5);
53 FillRect(drawItem
->hDC
, &fRect
, GetSysColorBrush(COLOR_ACTIVEBORDER
));
55 /* Draw window title */
56 SetRect(&fRect
, startx
+ 7, starty
+ 3, cRect
.right
- 9, starty
+ 5);
57 FillRect(drawItem
->hDC
, &fRect
, GetSysColorBrush(COLOR_ACTIVECAPTION
));
59 /* Draw first right box */
60 SetRect(&fRect
, fRect
.right
+ 1, starty
+ 3, fRect
.right
+ 3, starty
+ 5);
61 FillRect(drawItem
->hDC
, &fRect
, GetSysColorBrush(COLOR_ACTIVEBORDER
));
63 /* Draw second right box */
64 SetRect(&fRect
, fRect
.right
+ 1, starty
+ 3, fRect
.right
+ 3, starty
+ 5);
65 FillRect(drawItem
->hDC
, &fRect
, GetSysColorBrush(COLOR_ACTIVEBORDER
));
68 SetRect(&fRect
, cRect
.right
- 5, fRect
.bottom
+ 1, cRect
.right
- 3, cRect
.bottom
- 3);
69 FillRect(drawItem
->hDC
, &fRect
, GetSysColorBrush(COLOR_SCROLLBAR
));
71 /* Draw console background */
72 hBrush
= CreateSolidBrush(pConInfo
->ScreenBackground
);
73 SetRect(&fRect
, startx
+ 3, starty
+ 6, cRect
.right
- 6, cRect
.bottom
- 3);
74 FillRect(drawItem
->hDC
, &fRect
, hBrush
);
75 DeleteObject((HGDIOBJ
)hBrush
);
78 void PaintText(LPDRAWITEMSTRUCT drawItem
, PConsoleInfo pConInfo
)
80 COLORREF pbkColor
, ptColor
;
81 COLORREF nbkColor
, ntColor
;
85 ZeroMemory(szText
, sizeof(szText
));
86 LoadString(hApplet
, IDS_SCREEN_TEXT
, szText
, sizeof(szText
) / sizeof(TCHAR
));
88 if (drawItem
->CtlID
== IDC_STATIC_SCREEN_COLOR
)
90 nbkColor
= pConInfo
->ScreenBackground
;
91 hBrush
= CreateSolidBrush(nbkColor
);
92 ntColor
= pConInfo
->ScreenText
;
94 else if (drawItem
->CtlID
== IDC_STATIC_POPUP_COLOR
)
96 nbkColor
= pConInfo
->PopupBackground
;
97 hBrush
= CreateSolidBrush(nbkColor
);
98 ntColor
= pConInfo
->PopupText
;
106 FillRect(drawItem
->hDC
, &drawItem
->rcItem
, hBrush
);
107 if (ntColor
== nbkColor
)
109 /* Text has same color -> invisible */
113 ptColor
= SetTextColor(drawItem
->hDC
, ntColor
);
114 pbkColor
= SetBkColor(drawItem
->hDC
, nbkColor
);
115 DrawText(drawItem
->hDC
, szText
, _tcslen(szText
), &drawItem
->rcItem
, 0);
116 SetTextColor(drawItem
->hDC
, ptColor
);
117 SetBkColor(drawItem
->hDC
, pbkColor
);
118 DeleteObject((HGDIOBJ
)hBrush
);
133 PConsoleInfo pConInfo
= (PConsoleInfo
)GetWindowLongPtr(hwndDlg
, DWLP_USER
);
135 UNREFERENCED_PARAMETER(hwndDlg
);
136 UNREFERENCED_PARAMETER(wParam
);
144 pConInfo
= (PConsoleInfo
) ((LPPROPSHEETPAGE
)lParam
)->lParam
;
145 SetWindowLongPtr(hwndDlg
, DWLP_USER
, (LONG_PTR
)pConInfo
);
146 SetDlgItemInt(hwndDlg
, IDC_EDIT_SCREEN_BUFFER_HEIGHT
, HIWORD(pConInfo
->ScreenBuffer
), FALSE
);
147 SetDlgItemInt(hwndDlg
, IDC_EDIT_SCREEN_BUFFER_WIDTH
, LOWORD(pConInfo
->ScreenBuffer
), FALSE
);
148 SetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_SIZE_HEIGHT
, HIWORD(pConInfo
->WindowSize
), FALSE
);
149 SetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_SIZE_WIDTH
, LOWORD(pConInfo
->WindowSize
), FALSE
);
150 SendMessage(GetDlgItem(hwndDlg
, IDC_UPDOWN_SCREEN_BUFFER_HEIGHT
), UDM_SETRANGE
, 0, (LPARAM
)MAKELONG(9999, 1));
151 SendMessage(GetDlgItem(hwndDlg
, IDC_UPDOWN_SCREEN_BUFFER_WIDTH
), UDM_SETRANGE
, 0, (LPARAM
)MAKELONG(9999, 1));
152 SendMessage(GetDlgItem(hwndDlg
, IDC_UPDOWN_WINDOW_SIZE_HEIGHT
), UDM_SETRANGE
, 0, (LPARAM
)MAKELONG(9999, 1));
153 SendMessage(GetDlgItem(hwndDlg
, IDC_UPDOWN_WINDOW_SIZE_WIDTH
), UDM_SETRANGE
, 0, (LPARAM
)MAKELONG(9999, 1));
156 xres
= GetDeviceCaps(hDC
, HORZRES
);
157 yres
= GetDeviceCaps(hDC
, VERTRES
);
158 SendMessage(GetDlgItem(hwndDlg
, IDC_UPDOWN_WINDOW_POS_LEFT
), UDM_SETRANGE
, 0, (LPARAM
)MAKELONG(xres
, 0));
159 SendMessage(GetDlgItem(hwndDlg
, IDC_UPDOWN_WINDOW_POS_TOP
), UDM_SETRANGE
, 0, (LPARAM
)MAKELONG(yres
, 0));
161 if (pConInfo
->WindowPosition
!= MAXDWORD
)
163 SetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_POS_LEFT
, LOWORD(pConInfo
->WindowPosition
), FALSE
);
164 SetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_POS_TOP
, HIWORD(pConInfo
->WindowPosition
), FALSE
);
168 // FIXME: Calculate window pos from xres, yres
169 SetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_POS_LEFT
, 88, FALSE
);
170 SetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_POS_TOP
, 88, FALSE
);
171 EnableWindow(GetDlgItem(hwndDlg
, IDC_EDIT_WINDOW_POS_LEFT
), FALSE
);
172 EnableWindow(GetDlgItem(hwndDlg
, IDC_EDIT_WINDOW_POS_TOP
), FALSE
);
173 EnableWindow(GetDlgItem(hwndDlg
, IDC_UPDOWN_WINDOW_POS_LEFT
), FALSE
);
174 EnableWindow(GetDlgItem(hwndDlg
, IDC_UPDOWN_WINDOW_POS_TOP
), FALSE
);
175 SendMessage(GetDlgItem(hwndDlg
, IDC_CHECK_SYSTEM_POS_WINDOW
), BM_SETCHECK
, (WPARAM
)BST_CHECKED
, 0);
182 PaintConsole((LPDRAWITEMSTRUCT
)lParam
, pConInfo
);
187 lpnmud
= (LPNMUPDOWN
) lParam
;
188 lppsn
= (LPPSHNOTIFY
) lParam
;
190 if (lppsn
->hdr
.code
== UDN_DELTAPOS
)
192 DWORD wheight
, wwidth
;
193 DWORD sheight
, swidth
;
196 if (lppsn
->hdr
.idFrom
== IDC_UPDOWN_WINDOW_SIZE_WIDTH
)
198 wwidth
= lpnmud
->iPos
+ lpnmud
->iDelta
;
202 wwidth
= GetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_SIZE_WIDTH
, NULL
, FALSE
);
205 if (lppsn
->hdr
.idFrom
== IDC_UPDOWN_WINDOW_SIZE_HEIGHT
)
207 wheight
= lpnmud
->iPos
+ lpnmud
->iDelta
;
211 wheight
= GetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_SIZE_HEIGHT
, NULL
, FALSE
);
214 if (lppsn
->hdr
.idFrom
== IDC_UPDOWN_SCREEN_BUFFER_WIDTH
)
216 swidth
= lpnmud
->iPos
+ lpnmud
->iDelta
;
220 swidth
= GetDlgItemInt(hwndDlg
, IDC_EDIT_SCREEN_BUFFER_WIDTH
, NULL
, FALSE
);
223 if (lppsn
->hdr
.idFrom
== IDC_UPDOWN_SCREEN_BUFFER_HEIGHT
)
225 sheight
= lpnmud
->iPos
+ lpnmud
->iDelta
;
229 sheight
= GetDlgItemInt(hwndDlg
, IDC_EDIT_SCREEN_BUFFER_HEIGHT
, NULL
, FALSE
);
232 if (lppsn
->hdr
.idFrom
== IDC_UPDOWN_WINDOW_POS_LEFT
)
234 left
= lpnmud
->iPos
+ lpnmud
->iDelta
;
238 left
= GetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_POS_LEFT
, NULL
, FALSE
);
241 if (lppsn
->hdr
.idFrom
== IDC_UPDOWN_WINDOW_POS_TOP
)
243 top
= lpnmud
->iPos
+ lpnmud
->iDelta
;
247 top
= GetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_POS_TOP
, NULL
, FALSE
);
250 if (lppsn
->hdr
.idFrom
== IDC_UPDOWN_WINDOW_SIZE_WIDTH
|| lppsn
->hdr
.idFrom
== IDC_UPDOWN_WINDOW_SIZE_HEIGHT
)
252 /* Automatically adjust screen buffer size when window size enlarges */
253 if (wwidth
>= swidth
)
255 SetDlgItemInt(hwndDlg
, IDC_EDIT_SCREEN_BUFFER_WIDTH
, wwidth
, TRUE
);
259 if (wheight
>= sheight
)
261 SetDlgItemInt(hwndDlg
, IDC_EDIT_SCREEN_BUFFER_HEIGHT
, wheight
, TRUE
);
265 swidth
= max(swidth
, 1);
266 sheight
= max(sheight
, 1);
268 if (lppsn
->hdr
.idFrom
== IDC_UPDOWN_SCREEN_BUFFER_WIDTH
|| lppsn
->hdr
.idFrom
== IDC_UPDOWN_SCREEN_BUFFER_HEIGHT
)
270 /* Automatically adjust window size when screen buffer decreases */
273 SetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_SIZE_WIDTH
, swidth
, TRUE
);
277 if (wheight
> sheight
)
279 SetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_SIZE_HEIGHT
, sheight
, TRUE
);
284 pConInfo
->ScreenBuffer
= MAKELONG(swidth
, sheight
);
285 pConInfo
->WindowSize
= MAKELONG(wwidth
, wheight
);
286 pConInfo
->WindowPosition
= MAKELONG(left
, top
);
287 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
293 switch(LOWORD(wParam
))
295 case IDC_EDIT_SCREEN_BUFFER_WIDTH
:
296 case IDC_EDIT_SCREEN_BUFFER_HEIGHT
:
297 case IDC_EDIT_WINDOW_SIZE_WIDTH
:
298 case IDC_UPDOWN_WINDOW_SIZE_HEIGHT
:
299 case IDC_EDIT_WINDOW_POS_LEFT
:
300 case IDC_EDIT_WINDOW_POS_TOP
:
302 if (HIWORD(wParam
) == EN_KILLFOCUS
)
304 DWORD wheight
, wwidth
;
305 DWORD sheight
, swidth
;
308 wwidth
= GetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_SIZE_WIDTH
, NULL
, FALSE
);
309 wheight
= GetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_SIZE_HEIGHT
, NULL
, FALSE
);
310 swidth
= GetDlgItemInt(hwndDlg
, IDC_EDIT_SCREEN_BUFFER_WIDTH
, NULL
, FALSE
);
311 sheight
= GetDlgItemInt(hwndDlg
, IDC_EDIT_SCREEN_BUFFER_HEIGHT
, NULL
, FALSE
);
312 left
= GetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_POS_LEFT
, NULL
, FALSE
);
313 top
= GetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_POS_TOP
, NULL
, FALSE
);
315 swidth
= max(swidth
, 1);
316 sheight
= max(sheight
, 1);
318 /* Automatically adjust window size when screen buffer decreases */
321 SetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_SIZE_WIDTH
, swidth
, TRUE
);
325 if (wheight
> sheight
)
327 SetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_SIZE_HEIGHT
, sheight
, TRUE
);
332 pConInfo
->ScreenBuffer
= MAKELONG(swidth
, sheight
);
333 pConInfo
->WindowSize
= MAKELONG(wwidth
, wheight
);
334 pConInfo
->WindowPosition
= MAKELONG(left
, top
);
336 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
341 case IDC_CHECK_SYSTEM_POS_WINDOW
:
343 LONG res
= SendMessage((HWND
)lParam
, BM_GETCHECK
, 0, 0);
344 if (res
== BST_CHECKED
)
348 left
= GetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_POS_LEFT
, NULL
, FALSE
);
349 top
= GetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_POS_TOP
, NULL
, FALSE
);
350 pConInfo
->WindowPosition
= MAKELONG(left
, top
);
351 SendMessage((HWND
)lParam
, BM_SETCHECK
, (WPARAM
)BST_UNCHECKED
, 0);
352 EnableWindow(GetDlgItem(hwndDlg
, IDC_EDIT_WINDOW_POS_LEFT
), TRUE
);
353 EnableWindow(GetDlgItem(hwndDlg
, IDC_EDIT_WINDOW_POS_TOP
), TRUE
);
354 EnableWindow(GetDlgItem(hwndDlg
, IDC_UPDOWN_WINDOW_POS_LEFT
), TRUE
);
355 EnableWindow(GetDlgItem(hwndDlg
, IDC_UPDOWN_WINDOW_POS_TOP
), TRUE
);
357 else if (res
== BST_UNCHECKED
)
359 pConInfo
->WindowPosition
= UINT_MAX
;
360 SendMessage((HWND
)lParam
, BM_SETCHECK
, (WPARAM
)BST_CHECKED
, 0);
361 EnableWindow(GetDlgItem(hwndDlg
, IDC_EDIT_WINDOW_POS_LEFT
), FALSE
);
362 EnableWindow(GetDlgItem(hwndDlg
, IDC_EDIT_WINDOW_POS_TOP
), FALSE
);
363 EnableWindow(GetDlgItem(hwndDlg
, IDC_UPDOWN_WINDOW_POS_LEFT
), FALSE
);
364 EnableWindow(GetDlgItem(hwndDlg
, IDC_UPDOWN_WINDOW_POS_TOP
), FALSE
);