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)
13 void PaintConsole(LPDRAWITEMSTRUCT drawItem
, PConsoleInfo pConInfo
)
21 FillRect(drawItem
->hDC
, &drawItem
->rcItem
, GetSysColorBrush(COLOR_BACKGROUND
));
23 sizex
= drawItem
->rcItem
.right
- drawItem
->rcItem
.left
;
24 sizey
= drawItem
->rcItem
.bottom
- drawItem
->rcItem
.top
;
26 if (pConInfo
->WindowPosition
== UINT_MAX
)
34 // calculate pos correctly when console centered
40 // strech console when bold fonts are selected
41 endx
= drawItem
->rcItem
.right
- startx
+ 15;
42 endy
= starty
+ sizey
/ 3;
44 /* draw console size */
45 SetRect(&cRect
, startx
, starty
, endx
, endy
);
46 FillRect(drawItem
->hDC
, &cRect
, GetSysColorBrush(COLOR_WINDOWFRAME
));
48 /* draw console border */
49 SetRect(&fRect
, startx
+ 1, starty
+ 1, cRect
.right
- 1, cRect
.bottom
- 1);
50 FrameRect(drawItem
->hDC
, &fRect
, GetSysColorBrush(COLOR_ACTIVEBORDER
));
53 SetRect(&fRect
, startx
+ 3, starty
+ 3, startx
+ 5, starty
+ 5);
54 FillRect(drawItem
->hDC
, &fRect
, GetSysColorBrush(COLOR_ACTIVEBORDER
));
56 /* draw window title */
57 SetRect(&fRect
, startx
+ 7, starty
+ 3, cRect
.right
- 9, starty
+ 5);
58 FillRect(drawItem
->hDC
, &fRect
, GetSysColorBrush(COLOR_ACTIVECAPTION
));
60 /* draw first right box */
61 SetRect(&fRect
, fRect
.right
+ 1, starty
+ 3, fRect
.right
+ 3, starty
+ 5);
62 FillRect(drawItem
->hDC
, &fRect
, GetSysColorBrush(COLOR_ACTIVEBORDER
));
64 /* draw second right box */
65 SetRect(&fRect
, fRect
.right
+ 1, starty
+ 3, fRect
.right
+ 3, starty
+ 5);
66 FillRect(drawItem
->hDC
, &fRect
, GetSysColorBrush(COLOR_ACTIVEBORDER
));
69 SetRect(&fRect
, cRect
.right
- 5, fRect
.bottom
+ 1, cRect
.right
- 3, cRect
.bottom
- 3);
70 FillRect(drawItem
->hDC
, &fRect
, GetSysColorBrush(COLOR_SCROLLBAR
));
72 /* draw console background */
73 hBrush
= CreateSolidBrush(pConInfo
->ScreenBackground
);
74 SetRect(&fRect
, startx
+ 3, starty
+ 6, cRect
.right
- 6, cRect
.bottom
- 3);
75 FillRect(drawItem
->hDC
, &fRect
, hBrush
);
76 DeleteObject((HGDIOBJ
)hBrush
);
79 void PaintText(LPDRAWITEMSTRUCT drawItem
, PConsoleInfo pConInfo
)
81 COLORREF pbkColor
, ptColor
;
82 COLORREF nbkColor
, ntColor
;
86 ZeroMemory(szText
, sizeof(szText
));
87 LoadString(hApplet
, IDS_SCREEN_TEXT
, szText
, sizeof(szText
) / sizeof(TCHAR
));
89 if (drawItem
->CtlID
== IDC_STATIC_SCREEN_COLOR
)
91 nbkColor
= pConInfo
->ScreenBackground
;
92 hBrush
= CreateSolidBrush(nbkColor
);
93 ntColor
= pConInfo
->ScreenText
;
95 else if (drawItem
->CtlID
== IDC_STATIC_POPUP_COLOR
)
97 nbkColor
= pConInfo
->PopupBackground
;
98 hBrush
= CreateSolidBrush(nbkColor
);
99 ntColor
= pConInfo
->PopupText
;
107 FillRect(drawItem
->hDC
, &drawItem
->rcItem
, hBrush
);
108 if (ntColor
== nbkColor
)
110 /* text has same color -> invisible */
114 ptColor
= SetTextColor(drawItem
->hDC
, ntColor
);
115 pbkColor
= SetBkColor(drawItem
->hDC
, nbkColor
);
116 DrawText(drawItem
->hDC
, szText
, _tcslen(szText
), &drawItem
->rcItem
, 0);
117 SetTextColor(drawItem
->hDC
, ptColor
);
118 SetBkColor(drawItem
->hDC
, pbkColor
);
119 DeleteObject((HGDIOBJ
)hBrush
);
135 PConsoleInfo pConInfo
= (PConsoleInfo
)GetWindowLongPtr(hwndDlg
, DWLP_USER
);
137 UNREFERENCED_PARAMETER(hwndDlg
);
138 UNREFERENCED_PARAMETER(wParam
);
146 pConInfo
= (PConsoleInfo
) ((LPPROPSHEETPAGE
)lParam
)->lParam
;
147 SetWindowLongPtr(hwndDlg
, DWLP_USER
, (LONG_PTR
)pConInfo
);
148 SetDlgItemInt(hwndDlg
, IDC_EDIT_SCREEN_BUFFER_HEIGHT
, HIWORD(pConInfo
->ScreenBuffer
), FALSE
);
149 SetDlgItemInt(hwndDlg
, IDC_EDIT_SCREEN_BUFFER_WIDTH
, LOWORD(pConInfo
->ScreenBuffer
), FALSE
);
150 SetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_SIZE_HEIGHT
, HIWORD(pConInfo
->WindowSize
), FALSE
);
151 SetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_SIZE_WIDTH
, LOWORD(pConInfo
->WindowSize
), FALSE
);
152 SendMessage(GetDlgItem(hwndDlg
, IDC_UPDOWN_SCREEN_BUFFER_HEIGHT
), UDM_SETRANGE
, 0, (LPARAM
)MAKELONG(9999, 1));
153 SendMessage(GetDlgItem(hwndDlg
, IDC_UPDOWN_SCREEN_BUFFER_WIDTH
), UDM_SETRANGE
, 0, (LPARAM
)MAKELONG(9999, 1));
154 SendMessage(GetDlgItem(hwndDlg
, IDC_UPDOWN_WINDOW_SIZE_HEIGHT
), UDM_SETRANGE
, 0, (LPARAM
)MAKELONG(9999, 1));
155 SendMessage(GetDlgItem(hwndDlg
, IDC_UPDOWN_WINDOW_SIZE_WIDTH
), UDM_SETRANGE
, 0, (LPARAM
)MAKELONG(9999, 1));
158 xres
= GetDeviceCaps(hDC
, HORZRES
);
159 yres
= GetDeviceCaps(hDC
, VERTRES
);
160 SendMessage(GetDlgItem(hwndDlg
, IDC_UPDOWN_WINDOW_POS_LEFT
), UDM_SETRANGE
, 0, (LPARAM
)MAKELONG(xres
, 0));
161 SendMessage(GetDlgItem(hwndDlg
, IDC_UPDOWN_WINDOW_POS_TOP
), UDM_SETRANGE
, 0, (LPARAM
)MAKELONG(yres
, 0));
163 if (pConInfo
->WindowPosition
!= MAXDWORD
)
165 SetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_POS_LEFT
, LOWORD(pConInfo
->WindowPosition
), FALSE
);
166 SetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_POS_TOP
, HIWORD(pConInfo
->WindowPosition
), FALSE
);
170 //FIXME calculate window pos from xres, yres
171 SetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_POS_LEFT
, 88, FALSE
);
172 SetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_POS_TOP
, 88, FALSE
);
173 EnableWindow(GetDlgItem(hwndDlg
, IDC_EDIT_WINDOW_POS_LEFT
), FALSE
);
174 EnableWindow(GetDlgItem(hwndDlg
, IDC_EDIT_WINDOW_POS_TOP
), FALSE
);
175 EnableWindow(GetDlgItem(hwndDlg
, IDC_UPDOWN_WINDOW_POS_LEFT
), FALSE
);
176 EnableWindow(GetDlgItem(hwndDlg
, IDC_UPDOWN_WINDOW_POS_TOP
), FALSE
);
177 SendMessage(GetDlgItem(hwndDlg
, IDC_CHECK_SYSTEM_POS_WINDOW
), BM_SETCHECK
, (WPARAM
)BST_CHECKED
, 0);
184 PaintConsole((LPDRAWITEMSTRUCT
)lParam
, pConInfo
);
189 lpnmud
= (LPNMUPDOWN
) lParam
;
190 lppsn
= (LPPSHNOTIFY
) lParam
;
192 if (lppsn
->hdr
.code
== UDN_DELTAPOS
)
194 DWORD wheight
, wwidth
;
195 DWORD sheight
, swidth
;
198 if (lppsn
->hdr
.idFrom
== IDC_UPDOWN_WINDOW_SIZE_WIDTH
)
200 wwidth
= lpnmud
->iPos
+ lpnmud
->iDelta
;
204 wwidth
= GetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_SIZE_WIDTH
, NULL
, FALSE
);
207 if (lppsn
->hdr
.idFrom
== IDC_UPDOWN_WINDOW_SIZE_HEIGHT
)
209 wheight
= lpnmud
->iPos
+ lpnmud
->iDelta
;
213 wheight
= GetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_SIZE_HEIGHT
, NULL
, FALSE
);
216 if (lppsn
->hdr
.idFrom
== IDC_UPDOWN_SCREEN_BUFFER_WIDTH
)
218 swidth
= lpnmud
->iPos
+ lpnmud
->iDelta
;
222 swidth
= GetDlgItemInt(hwndDlg
, IDC_EDIT_SCREEN_BUFFER_WIDTH
, NULL
, FALSE
);
225 if (lppsn
->hdr
.idFrom
== IDC_UPDOWN_SCREEN_BUFFER_HEIGHT
)
227 sheight
= lpnmud
->iPos
+ lpnmud
->iDelta
;
231 sheight
= GetDlgItemInt(hwndDlg
, IDC_EDIT_SCREEN_BUFFER_HEIGHT
, NULL
, FALSE
);
234 if (lppsn
->hdr
.idFrom
== IDC_UPDOWN_WINDOW_POS_LEFT
)
236 left
= lpnmud
->iPos
+ lpnmud
->iDelta
;
240 left
= GetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_POS_LEFT
, NULL
, FALSE
);
243 if (lppsn
->hdr
.idFrom
== IDC_UPDOWN_WINDOW_POS_TOP
)
245 top
= lpnmud
->iPos
+ lpnmud
->iDelta
;
249 top
= GetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_POS_TOP
, NULL
, FALSE
);
252 if (lppsn
->hdr
.idFrom
== IDC_UPDOWN_WINDOW_SIZE_WIDTH
|| lppsn
->hdr
.idFrom
== IDC_UPDOWN_WINDOW_SIZE_HEIGHT
)
254 /* automatically adjust screen buffer size when window size enlarges */
255 if (wwidth
>= swidth
)
257 SetDlgItemInt(hwndDlg
, IDC_EDIT_SCREEN_BUFFER_WIDTH
, wwidth
, TRUE
);
261 if (wheight
>= sheight
)
263 SetDlgItemInt(hwndDlg
, IDC_EDIT_SCREEN_BUFFER_HEIGHT
, wheight
, TRUE
);
267 swidth
= max(swidth
, 1);
268 sheight
= max(sheight
, 1);
270 if (lppsn
->hdr
.idFrom
== IDC_UPDOWN_SCREEN_BUFFER_WIDTH
|| lppsn
->hdr
.idFrom
== IDC_UPDOWN_SCREEN_BUFFER_HEIGHT
)
272 /* automatically adjust window size when screen buffer decreases */
275 SetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_SIZE_WIDTH
, swidth
, TRUE
);
279 if (wheight
> sheight
)
281 SetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_SIZE_HEIGHT
, sheight
, TRUE
);
286 pConInfo
->ScreenBuffer
= MAKELONG(swidth
, sheight
);
287 pConInfo
->WindowSize
= MAKELONG(wwidth
, wheight
);
288 pConInfo
->WindowPosition
= MAKELONG(left
, top
);
289 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
295 switch(LOWORD(wParam
))
297 case IDC_EDIT_SCREEN_BUFFER_WIDTH
:
298 case IDC_EDIT_SCREEN_BUFFER_HEIGHT
:
299 case IDC_EDIT_WINDOW_SIZE_WIDTH
:
300 case IDC_UPDOWN_WINDOW_SIZE_HEIGHT
:
301 case IDC_EDIT_WINDOW_POS_LEFT
:
302 case IDC_EDIT_WINDOW_POS_TOP
:
304 if (HIWORD(wParam
) == EN_KILLFOCUS
)
306 DWORD wheight
, wwidth
;
307 DWORD sheight
, swidth
;
310 wwidth
= GetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_SIZE_WIDTH
, NULL
, FALSE
);
311 wheight
= GetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_SIZE_HEIGHT
, NULL
, FALSE
);
312 swidth
= GetDlgItemInt(hwndDlg
, IDC_EDIT_SCREEN_BUFFER_WIDTH
, NULL
, FALSE
);
313 sheight
= GetDlgItemInt(hwndDlg
, IDC_EDIT_SCREEN_BUFFER_HEIGHT
, NULL
, FALSE
);
314 left
= GetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_POS_LEFT
, NULL
, FALSE
);
315 top
= GetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_POS_TOP
, NULL
, FALSE
);
317 swidth
= max(swidth
, 1);
318 sheight
= max(sheight
, 1);
320 /* automatically adjust window size when screen buffer decreases */
323 SetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_SIZE_WIDTH
, swidth
, TRUE
);
327 if (wheight
> sheight
)
329 SetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_SIZE_HEIGHT
, sheight
, TRUE
);
334 pConInfo
->ScreenBuffer
= MAKELONG(swidth
, sheight
);
335 pConInfo
->WindowSize
= MAKELONG(wwidth
, wheight
);
336 pConInfo
->WindowPosition
= MAKELONG(left
, top
);
338 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
343 case IDC_CHECK_SYSTEM_POS_WINDOW
:
345 LONG res
= SendMessage((HWND
)lParam
, BM_GETCHECK
, 0, 0);
346 if (res
== BST_CHECKED
)
350 left
= GetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_POS_LEFT
, NULL
, FALSE
);
351 top
= GetDlgItemInt(hwndDlg
, IDC_EDIT_WINDOW_POS_TOP
, NULL
, FALSE
);
352 pConInfo
->WindowPosition
= MAKELONG(left
, top
);
353 SendMessage((HWND
)lParam
, BM_SETCHECK
, (WPARAM
)BST_UNCHECKED
, 0);
354 EnableWindow(GetDlgItem(hwndDlg
, IDC_EDIT_WINDOW_POS_LEFT
), TRUE
);
355 EnableWindow(GetDlgItem(hwndDlg
, IDC_EDIT_WINDOW_POS_TOP
), TRUE
);
356 EnableWindow(GetDlgItem(hwndDlg
, IDC_UPDOWN_WINDOW_POS_LEFT
), TRUE
);
357 EnableWindow(GetDlgItem(hwndDlg
, IDC_UPDOWN_WINDOW_POS_TOP
), TRUE
);
359 else if (res
== BST_UNCHECKED
)
361 pConInfo
->WindowPosition
= UINT_MAX
;
362 SendMessage((HWND
)lParam
, BM_SETCHECK
, (WPARAM
)BST_CHECKED
, 0);
363 EnableWindow(GetDlgItem(hwndDlg
, IDC_EDIT_WINDOW_POS_LEFT
), FALSE
);
364 EnableWindow(GetDlgItem(hwndDlg
, IDC_EDIT_WINDOW_POS_TOP
), FALSE
);
365 EnableWindow(GetDlgItem(hwndDlg
, IDC_UPDOWN_WINDOW_POS_LEFT
), FALSE
);
366 EnableWindow(GetDlgItem(hwndDlg
, IDC_UPDOWN_WINDOW_POS_TOP
), FALSE
);