2 * PROJECT: ReactOS Console Configuration DLL
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: dll/win32/console/colors.c
5 * PURPOSE: Colors dialog
6 * PROGRAMMERS: Johannes Anderwald (johannes.anderwald@reactos.org)
15 PaintStaticControls(HWND hwndDlg
,
16 PCONSOLE_PROPS pConInfo
,
17 LPDRAWITEMSTRUCT drawItem
)
22 index
= min(drawItem
->CtlID
- IDC_STATIC_COLOR1
,
23 sizeof(pConInfo
->ci
.Colors
) / sizeof(pConInfo
->ci
.Colors
[0]) - 1);
24 hBrush
= CreateSolidBrush(pConInfo
->ci
.Colors
[index
]);
25 if (!hBrush
) return FALSE
;
27 FillRect(drawItem
->hDC
, &drawItem
->rcItem
, hBrush
);
28 DeleteObject((HGDIOBJ
)hBrush
);
29 if (pConInfo
->ActiveStaticControl
== index
)
31 DrawFocusRect(drawItem
->hDC
, &drawItem
->rcItem
);
38 ColorsProc(HWND hwndDlg
,
43 PCONSOLE_PROPS pConInfo
;
47 pConInfo
= (PCONSOLE_PROPS
)GetWindowLongPtr(hwndDlg
, DWLP_USER
);
53 pConInfo
= (PCONSOLE_PROPS
)((LPPROPSHEETPAGE
)lParam
)->lParam
;
54 SetWindowLongPtr(hwndDlg
, DWLP_USER
, (LONG_PTR
)pConInfo
);
56 /* Set the valid range of the colour indicators */
57 SendDlgItemMessageW(hwndDlg
, IDC_UPDOWN_COLOR_RED
, UDM_SETRANGE
, 0, (LPARAM
)MAKELONG(255, 0));
58 SendDlgItemMessageW(hwndDlg
, IDC_UPDOWN_COLOR_GREEN
, UDM_SETRANGE
, 0, (LPARAM
)MAKELONG(255, 0));
59 SendDlgItemMessageW(hwndDlg
, IDC_UPDOWN_COLOR_BLUE
, UDM_SETRANGE
, 0, (LPARAM
)MAKELONG(255, 0));
61 /* Select by default the screen background option */
62 CheckRadioButton(hwndDlg
, IDC_RADIO_SCREEN_TEXT
, IDC_RADIO_POPUP_BACKGROUND
, IDC_RADIO_SCREEN_BACKGROUND
);
63 SendMessage(hwndDlg
, WM_COMMAND
, IDC_RADIO_SCREEN_BACKGROUND
, 0);
70 LPDRAWITEMSTRUCT drawItem
= (LPDRAWITEMSTRUCT
)lParam
;
72 if (drawItem
->CtlID
>= IDC_STATIC_COLOR1
&& drawItem
->CtlID
<= IDC_STATIC_COLOR16
)
73 return PaintStaticControls(hwndDlg
, pConInfo
, drawItem
);
74 else if (drawItem
->CtlID
== IDC_STATIC_SCREEN_COLOR
)
75 return PaintText(drawItem
, pConInfo
, Screen
);
76 else if (drawItem
->CtlID
== IDC_STATIC_POPUP_COLOR
)
77 return PaintText(drawItem
, pConInfo
, Popup
);
84 switch (((LPNMHDR
)lParam
)->code
)
88 if (!pConInfo
->AppliedConfig
)
90 return ApplyConsoleInfo(hwndDlg
, pConInfo
);
94 /* Options have already been applied */
95 SetWindowLongPtr(hwndDlg
, DWLP_MSGRESULT
, PSNRET_NOERROR
);
103 LPNMUPDOWN lpnmud
= (LPNMUPDOWN
)lParam
;
105 /* Get the current color */
106 colorIndex
= pConInfo
->ActiveStaticControl
;
107 color
= pConInfo
->ci
.Colors
[colorIndex
];
109 if (lpnmud
->hdr
.idFrom
== IDC_UPDOWN_COLOR_RED
)
111 lpnmud
->iPos
= min(max(lpnmud
->iPos
+ lpnmud
->iDelta
, 0), 255);
112 color
= RGB(lpnmud
->iPos
, GetGValue(color
), GetBValue(color
));
114 else if (lpnmud
->hdr
.idFrom
== IDC_UPDOWN_COLOR_GREEN
)
116 lpnmud
->iPos
= min(max(lpnmud
->iPos
+ lpnmud
->iDelta
, 0), 255);
117 color
= RGB(GetRValue(color
), lpnmud
->iPos
, GetBValue(color
));
119 else if (lpnmud
->hdr
.idFrom
== IDC_UPDOWN_COLOR_BLUE
)
121 lpnmud
->iPos
= min(max(lpnmud
->iPos
+ lpnmud
->iDelta
, 0), 255);
122 color
= RGB(GetRValue(color
), GetGValue(color
), lpnmud
->iPos
);
129 pConInfo
->ci
.Colors
[colorIndex
] = color
;
130 InvalidateRect(GetDlgItem(hwndDlg
, IDC_STATIC_COLOR1
+ colorIndex
), NULL
, TRUE
);
131 InvalidateRect(GetDlgItem(hwndDlg
, IDC_STATIC_SCREEN_COLOR
), NULL
, TRUE
);
132 InvalidateRect(GetDlgItem(hwndDlg
, IDC_STATIC_POPUP_COLOR
) , NULL
, TRUE
);
134 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
144 switch (LOWORD(wParam
))
146 case IDC_RADIO_SCREEN_TEXT
:
148 /* Get the color of the screen foreground */
149 colorIndex
= TextAttribFromAttrib(pConInfo
->ci
.ScreenAttrib
);
150 color
= pConInfo
->ci
.Colors
[colorIndex
];
152 /* Set the values of the colour indicators */
153 SetDlgItemInt(hwndDlg
, IDC_EDIT_COLOR_RED
, GetRValue(color
), FALSE
);
154 SetDlgItemInt(hwndDlg
, IDC_EDIT_COLOR_GREEN
, GetGValue(color
), FALSE
);
155 SetDlgItemInt(hwndDlg
, IDC_EDIT_COLOR_BLUE
, GetBValue(color
), FALSE
);
157 InvalidateRect(GetDlgItem(hwndDlg
, IDC_STATIC_COLOR1
+ pConInfo
->ActiveStaticControl
), NULL
, TRUE
);
158 pConInfo
->ActiveStaticControl
= colorIndex
;
159 InvalidateRect(GetDlgItem(hwndDlg
, IDC_STATIC_COLOR1
+ pConInfo
->ActiveStaticControl
), NULL
, TRUE
);
160 InvalidateRect(GetDlgItem(hwndDlg
, IDC_STATIC_SCREEN_COLOR
), NULL
, TRUE
);
161 InvalidateRect(GetDlgItem(hwndDlg
, IDC_STATIC_POPUP_COLOR
) , NULL
, TRUE
);
165 case IDC_RADIO_SCREEN_BACKGROUND
:
167 /* Get the color of the screen background */
168 colorIndex
= BkgdAttribFromAttrib(pConInfo
->ci
.ScreenAttrib
);
169 color
= pConInfo
->ci
.Colors
[colorIndex
];
171 /* Set the values of the colour indicators */
172 SetDlgItemInt(hwndDlg
, IDC_EDIT_COLOR_RED
, GetRValue(color
), FALSE
);
173 SetDlgItemInt(hwndDlg
, IDC_EDIT_COLOR_GREEN
, GetGValue(color
), FALSE
);
174 SetDlgItemInt(hwndDlg
, IDC_EDIT_COLOR_BLUE
, GetBValue(color
), FALSE
);
176 InvalidateRect(GetDlgItem(hwndDlg
, IDC_STATIC_COLOR1
+ pConInfo
->ActiveStaticControl
), NULL
, TRUE
);
177 pConInfo
->ActiveStaticControl
= colorIndex
;
178 InvalidateRect(GetDlgItem(hwndDlg
, IDC_STATIC_COLOR1
+ pConInfo
->ActiveStaticControl
), NULL
, TRUE
);
179 InvalidateRect(GetDlgItem(hwndDlg
, IDC_STATIC_SCREEN_COLOR
), NULL
, TRUE
);
180 InvalidateRect(GetDlgItem(hwndDlg
, IDC_STATIC_POPUP_COLOR
) , NULL
, TRUE
);
184 case IDC_RADIO_POPUP_TEXT
:
186 /* Get the color of the popup foreground */
187 colorIndex
= TextAttribFromAttrib(pConInfo
->ci
.PopupAttrib
);
188 color
= pConInfo
->ci
.Colors
[colorIndex
];
190 /* Set the values of the colour indicators */
191 SetDlgItemInt(hwndDlg
, IDC_EDIT_COLOR_RED
, GetRValue(color
), FALSE
);
192 SetDlgItemInt(hwndDlg
, IDC_EDIT_COLOR_GREEN
, GetGValue(color
), FALSE
);
193 SetDlgItemInt(hwndDlg
, IDC_EDIT_COLOR_BLUE
, GetBValue(color
), FALSE
);
195 InvalidateRect(GetDlgItem(hwndDlg
, IDC_STATIC_COLOR1
+ pConInfo
->ActiveStaticControl
), NULL
, TRUE
);
196 pConInfo
->ActiveStaticControl
= colorIndex
;
197 InvalidateRect(GetDlgItem(hwndDlg
, IDC_STATIC_COLOR1
+ pConInfo
->ActiveStaticControl
), NULL
, TRUE
);
198 InvalidateRect(GetDlgItem(hwndDlg
, IDC_STATIC_SCREEN_COLOR
), NULL
, TRUE
);
199 InvalidateRect(GetDlgItem(hwndDlg
, IDC_STATIC_POPUP_COLOR
) , NULL
, TRUE
);
203 case IDC_RADIO_POPUP_BACKGROUND
:
205 /* Get the color of the popup background */
206 colorIndex
= BkgdAttribFromAttrib(pConInfo
->ci
.PopupAttrib
);
207 color
= pConInfo
->ci
.Colors
[colorIndex
];
209 /* Set the values of the colour indicators */
210 SetDlgItemInt(hwndDlg
, IDC_EDIT_COLOR_RED
, GetRValue(color
), FALSE
);
211 SetDlgItemInt(hwndDlg
, IDC_EDIT_COLOR_GREEN
, GetGValue(color
), FALSE
);
212 SetDlgItemInt(hwndDlg
, IDC_EDIT_COLOR_BLUE
, GetBValue(color
), FALSE
);
214 InvalidateRect(GetDlgItem(hwndDlg
, IDC_STATIC_COLOR1
+ pConInfo
->ActiveStaticControl
), NULL
, TRUE
);
215 pConInfo
->ActiveStaticControl
= colorIndex
;
216 InvalidateRect(GetDlgItem(hwndDlg
, IDC_STATIC_COLOR1
+ pConInfo
->ActiveStaticControl
), NULL
, TRUE
);
217 InvalidateRect(GetDlgItem(hwndDlg
, IDC_STATIC_SCREEN_COLOR
), NULL
, TRUE
);
218 InvalidateRect(GetDlgItem(hwndDlg
, IDC_STATIC_POPUP_COLOR
) , NULL
, TRUE
);
222 case IDC_EDIT_COLOR_RED
:
224 if (HIWORD(wParam
) == EN_KILLFOCUS
)
228 /* Get the current color */
229 colorIndex
= pConInfo
->ActiveStaticControl
;
230 color
= pConInfo
->ci
.Colors
[colorIndex
];
232 red
= GetDlgItemInt(hwndDlg
, IDC_EDIT_COLOR_RED
, NULL
, FALSE
);
233 red
= min(max(red
, 0), 255);
235 color
= RGB(red
, GetGValue(color
), GetBValue(color
));
237 pConInfo
->ci
.Colors
[colorIndex
] = color
;
238 InvalidateRect(GetDlgItem(hwndDlg
, IDC_STATIC_COLOR1
+ colorIndex
), NULL
, TRUE
);
239 InvalidateRect(GetDlgItem(hwndDlg
, IDC_STATIC_SCREEN_COLOR
), NULL
, TRUE
);
240 InvalidateRect(GetDlgItem(hwndDlg
, IDC_STATIC_POPUP_COLOR
) , NULL
, TRUE
);
242 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
247 case IDC_EDIT_COLOR_GREEN
:
249 if (HIWORD(wParam
) == EN_KILLFOCUS
)
253 /* Get the current color */
254 colorIndex
= pConInfo
->ActiveStaticControl
;
255 color
= pConInfo
->ci
.Colors
[colorIndex
];
257 green
= GetDlgItemInt(hwndDlg
, IDC_EDIT_COLOR_GREEN
, NULL
, FALSE
);
258 green
= min(max(green
, 0), 255);
260 color
= RGB(GetRValue(color
), green
, GetBValue(color
));
262 pConInfo
->ci
.Colors
[colorIndex
] = color
;
263 InvalidateRect(GetDlgItem(hwndDlg
, IDC_STATIC_COLOR1
+ colorIndex
), NULL
, TRUE
);
264 InvalidateRect(GetDlgItem(hwndDlg
, IDC_STATIC_SCREEN_COLOR
), NULL
, TRUE
);
265 InvalidateRect(GetDlgItem(hwndDlg
, IDC_STATIC_POPUP_COLOR
) , NULL
, TRUE
);
267 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
272 case IDC_EDIT_COLOR_BLUE
:
274 if (HIWORD(wParam
) == EN_KILLFOCUS
)
278 /* Get the current color */
279 colorIndex
= pConInfo
->ActiveStaticControl
;
280 color
= pConInfo
->ci
.Colors
[colorIndex
];
282 blue
= GetDlgItemInt(hwndDlg
, IDC_EDIT_COLOR_BLUE
, NULL
, FALSE
);
283 blue
= min(max(blue
, 0), 255);
285 color
= RGB(GetRValue(color
), GetGValue(color
), blue
);
287 pConInfo
->ci
.Colors
[colorIndex
] = color
;
288 InvalidateRect(GetDlgItem(hwndDlg
, IDC_STATIC_COLOR1
+ colorIndex
), NULL
, TRUE
);
289 InvalidateRect(GetDlgItem(hwndDlg
, IDC_STATIC_SCREEN_COLOR
), NULL
, TRUE
);
290 InvalidateRect(GetDlgItem(hwndDlg
, IDC_STATIC_POPUP_COLOR
) , NULL
, TRUE
);
292 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
299 if ( HIWORD(wParam
) == STN_CLICKED
&&
300 IDC_STATIC_COLOR1
<= LOWORD(wParam
) && LOWORD(wParam
) <= IDC_STATIC_COLOR16
)
302 colorIndex
= LOWORD(wParam
) - IDC_STATIC_COLOR1
;
304 if (colorIndex
== pConInfo
->ActiveStaticControl
)
306 /* Same static control was re-clicked */
310 color
= pConInfo
->ci
.Colors
[colorIndex
];
312 SetDlgItemInt(hwndDlg
, IDC_EDIT_COLOR_RED
, GetRValue(color
), FALSE
);
313 SetDlgItemInt(hwndDlg
, IDC_EDIT_COLOR_GREEN
, GetGValue(color
), FALSE
);
314 SetDlgItemInt(hwndDlg
, IDC_EDIT_COLOR_BLUE
, GetBValue(color
), FALSE
);
316 /* Update global struct */
317 if (IsDlgButtonChecked(hwndDlg
, IDC_RADIO_SCREEN_TEXT
))
319 pConInfo
->ci
.ScreenAttrib
= MakeAttrib(colorIndex
, BkgdAttribFromAttrib(pConInfo
->ci
.ScreenAttrib
));
321 else if (IsDlgButtonChecked(hwndDlg
, IDC_RADIO_SCREEN_BACKGROUND
))
323 pConInfo
->ci
.ScreenAttrib
= MakeAttrib(TextAttribFromAttrib(pConInfo
->ci
.ScreenAttrib
), colorIndex
);
325 else if (IsDlgButtonChecked(hwndDlg
, IDC_RADIO_POPUP_TEXT
))
327 pConInfo
->ci
.PopupAttrib
= MakeAttrib(colorIndex
, BkgdAttribFromAttrib(pConInfo
->ci
.PopupAttrib
));
329 else if (IsDlgButtonChecked(hwndDlg
, IDC_RADIO_POPUP_BACKGROUND
))
331 pConInfo
->ci
.PopupAttrib
= MakeAttrib(TextAttribFromAttrib(pConInfo
->ci
.PopupAttrib
), colorIndex
);
334 InvalidateRect(GetDlgItem(hwndDlg
, IDC_STATIC_COLOR1
+ pConInfo
->ActiveStaticControl
), NULL
, TRUE
);
335 pConInfo
->ActiveStaticControl
= colorIndex
;
336 InvalidateRect(GetDlgItem(hwndDlg
, IDC_STATIC_COLOR1
+ pConInfo
->ActiveStaticControl
), NULL
, TRUE
);
337 InvalidateRect(GetDlgItem(hwndDlg
, IDC_STATIC_SCREEN_COLOR
), NULL
, TRUE
);
338 InvalidateRect(GetDlgItem(hwndDlg
, IDC_STATIC_POPUP_COLOR
) , NULL
, TRUE
);
340 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);