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: displays colors dialog
6 * PROGRAMMERS: Johannes Anderwald (johannes.anderwald@student.tugraz.at)
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
]);
30 FillRect(drawItem
->hDC
, &drawItem
->rcItem
, hBrush
);
31 DeleteObject((HGDIOBJ
)hBrush
);
32 if (pConInfo
->ActiveStaticControl
== index
)
34 DrawFocusRect(drawItem
->hDC
, &drawItem
->rcItem
);
41 ColorsProc(HWND hwndDlg
,
46 PCONSOLE_PROPS pConInfo
;
47 LPDRAWITEMSTRUCT drawItem
;
51 pConInfo
= (PCONSOLE_PROPS
)GetWindowLongPtr(hwndDlg
, DWLP_USER
);
57 pConInfo
= (PCONSOLE_PROPS
)((LPPROPSHEETPAGE
)lParam
)->lParam
;
58 SetWindowLongPtr(hwndDlg
, DWLP_USER
, (LONG_PTR
)pConInfo
);
60 /* Set the valid range of the colour indicators */
61 SendMessage(GetDlgItem(hwndDlg
, IDC_UPDOWN_COLOR_RED
), UDM_SETRANGE
, 0, (LPARAM
)MAKELONG(255, 0));
62 SendMessage(GetDlgItem(hwndDlg
, IDC_UPDOWN_COLOR_GREEN
), UDM_SETRANGE
, 0, (LPARAM
)MAKELONG(255, 0));
63 SendMessage(GetDlgItem(hwndDlg
, IDC_UPDOWN_COLOR_BLUE
), UDM_SETRANGE
, 0, (LPARAM
)MAKELONG(255, 0));
65 /* Select by default the screen background option */
66 CheckRadioButton(hwndDlg
, IDC_RADIO_SCREEN_TEXT
, IDC_RADIO_POPUP_BACKGROUND
, IDC_RADIO_SCREEN_BACKGROUND
);
67 SendMessage(hwndDlg
, WM_COMMAND
, IDC_RADIO_SCREEN_BACKGROUND
, 0);
74 drawItem
= (LPDRAWITEMSTRUCT
)lParam
;
75 if (drawItem
->CtlID
>= IDC_STATIC_COLOR1
&& drawItem
->CtlID
<= IDC_STATIC_COLOR16
)
77 return PaintStaticControls(hwndDlg
, pConInfo
, drawItem
);
79 else if (drawItem
->CtlID
== IDC_STATIC_SCREEN_COLOR
|| drawItem
->CtlID
== IDC_STATIC_POPUP_COLOR
)
81 PaintText(drawItem
, pConInfo
);
89 switch (((LPNMHDR
)lParam
)->code
)
94 if (!pConInfo
->AppliedConfig
)
96 return ApplyConsoleInfo(hwndDlg
, pConInfo
);
100 /* Options have already been applied */
101 SetWindowLongPtr(hwndDlg
, DWLP_MSGRESULT
, PSNRET_NOERROR
);
109 LPNMUPDOWN lpnmud
= (LPNMUPDOWN
)lParam
;
111 /* Get the current color */
112 colorIndex
= pConInfo
->ActiveStaticControl
;
113 color
= pConInfo
->ci
.Colors
[colorIndex
];
115 if (lpnmud
->hdr
.idFrom
== IDC_UPDOWN_COLOR_RED
)
117 if (lpnmud
->iPos
< 0) lpnmud
->iPos
= 0;
118 else if (lpnmud
->iPos
> 255) lpnmud
->iPos
= 255;
120 color
= RGB(lpnmud
->iPos
, GetGValue(color
), GetBValue(color
));
122 else if (lpnmud
->hdr
.idFrom
== IDC_UPDOWN_COLOR_GREEN
)
124 if (lpnmud
->iPos
< 0) lpnmud
->iPos
= 0;
125 else if (lpnmud
->iPos
> 255) lpnmud
->iPos
= 255;
127 color
= RGB(GetRValue(color
), lpnmud
->iPos
, GetBValue(color
));
129 else if (lpnmud
->hdr
.idFrom
== IDC_UPDOWN_COLOR_BLUE
)
131 if (lpnmud
->iPos
< 0) lpnmud
->iPos
= 0;
132 else if (lpnmud
->iPos
> 255) lpnmud
->iPos
= 255;
134 color
= RGB(GetRValue(color
), GetGValue(color
), lpnmud
->iPos
);
141 pConInfo
->ci
.Colors
[colorIndex
] = color
;
142 InvalidateRect(GetDlgItem(hwndDlg
, IDC_STATIC_COLOR1
+ colorIndex
), NULL
, TRUE
);
143 InvalidateRect(GetDlgItem(hwndDlg
, IDC_STATIC_SCREEN_COLOR
), NULL
, TRUE
);
144 InvalidateRect(GetDlgItem(hwndDlg
, IDC_STATIC_POPUP_COLOR
), NULL
, TRUE
);
146 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);
156 switch (LOWORD(wParam
))
158 case IDC_RADIO_SCREEN_TEXT
:
160 /* Get the color of the screen foreground */
161 colorIndex
= TextAttribFromAttrib(pConInfo
->ci
.ScreenAttrib
);
162 color
= pConInfo
->ci
.Colors
[colorIndex
];
164 /* Set the values of the colour indicators */
165 SetDlgItemInt(hwndDlg
, IDC_EDIT_COLOR_RED
, GetRValue(color
), FALSE
);
166 SetDlgItemInt(hwndDlg
, IDC_EDIT_COLOR_GREEN
, GetGValue(color
), FALSE
);
167 SetDlgItemInt(hwndDlg
, IDC_EDIT_COLOR_BLUE
, GetBValue(color
), FALSE
);
169 InvalidateRect(GetDlgItem(hwndDlg
, IDC_STATIC_COLOR1
+ pConInfo
->ActiveStaticControl
), NULL
, TRUE
);
170 pConInfo
->ActiveStaticControl
= colorIndex
;
171 InvalidateRect(GetDlgItem(hwndDlg
, IDC_STATIC_COLOR1
+ pConInfo
->ActiveStaticControl
), NULL
, TRUE
);
172 InvalidateRect(GetDlgItem(hwndDlg
, IDC_STATIC_SCREEN_COLOR
), NULL
, TRUE
);
173 InvalidateRect(GetDlgItem(hwndDlg
, IDC_STATIC_POPUP_COLOR
), NULL
, TRUE
);
177 case IDC_RADIO_SCREEN_BACKGROUND
:
179 /* Get the color of the screen background */
180 colorIndex
= BkgdAttribFromAttrib(pConInfo
->ci
.ScreenAttrib
);
181 color
= pConInfo
->ci
.Colors
[colorIndex
];
183 /* Set the values of the colour indicators */
184 SetDlgItemInt(hwndDlg
, IDC_EDIT_COLOR_RED
, GetRValue(color
), FALSE
);
185 SetDlgItemInt(hwndDlg
, IDC_EDIT_COLOR_GREEN
, GetGValue(color
), FALSE
);
186 SetDlgItemInt(hwndDlg
, IDC_EDIT_COLOR_BLUE
, GetBValue(color
), FALSE
);
188 InvalidateRect(GetDlgItem(hwndDlg
, IDC_STATIC_COLOR1
+ pConInfo
->ActiveStaticControl
), NULL
, TRUE
);
189 pConInfo
->ActiveStaticControl
= colorIndex
;
190 InvalidateRect(GetDlgItem(hwndDlg
, IDC_STATIC_COLOR1
+ pConInfo
->ActiveStaticControl
), NULL
, TRUE
);
191 InvalidateRect(GetDlgItem(hwndDlg
, IDC_STATIC_SCREEN_COLOR
), NULL
, TRUE
);
192 InvalidateRect(GetDlgItem(hwndDlg
, IDC_STATIC_POPUP_COLOR
), NULL
, TRUE
);
196 case IDC_RADIO_POPUP_TEXT
:
198 /* Get the color of the popup foreground */
199 colorIndex
= TextAttribFromAttrib(pConInfo
->ci
.PopupAttrib
);
200 color
= pConInfo
->ci
.Colors
[colorIndex
];
202 /* Set the values of the colour indicators */
203 SetDlgItemInt(hwndDlg
, IDC_EDIT_COLOR_RED
, GetRValue(color
), FALSE
);
204 SetDlgItemInt(hwndDlg
, IDC_EDIT_COLOR_GREEN
, GetGValue(color
), FALSE
);
205 SetDlgItemInt(hwndDlg
, IDC_EDIT_COLOR_BLUE
, GetBValue(color
), FALSE
);
207 InvalidateRect(GetDlgItem(hwndDlg
, IDC_STATIC_COLOR1
+ pConInfo
->ActiveStaticControl
), NULL
, TRUE
);
208 pConInfo
->ActiveStaticControl
= colorIndex
;
209 InvalidateRect(GetDlgItem(hwndDlg
, IDC_STATIC_COLOR1
+ pConInfo
->ActiveStaticControl
), NULL
, TRUE
);
210 InvalidateRect(GetDlgItem(hwndDlg
, IDC_STATIC_SCREEN_COLOR
), NULL
, TRUE
);
211 InvalidateRect(GetDlgItem(hwndDlg
, IDC_STATIC_POPUP_COLOR
), NULL
, TRUE
);
215 case IDC_RADIO_POPUP_BACKGROUND
:
217 /* Get the color of the popup background */
218 colorIndex
= BkgdAttribFromAttrib(pConInfo
->ci
.PopupAttrib
);
219 color
= pConInfo
->ci
.Colors
[colorIndex
];
221 /* Set the values of the colour indicators */
222 SetDlgItemInt(hwndDlg
, IDC_EDIT_COLOR_RED
, GetRValue(color
), FALSE
);
223 SetDlgItemInt(hwndDlg
, IDC_EDIT_COLOR_GREEN
, GetGValue(color
), FALSE
);
224 SetDlgItemInt(hwndDlg
, IDC_EDIT_COLOR_BLUE
, GetBValue(color
), FALSE
);
226 InvalidateRect(GetDlgItem(hwndDlg
, IDC_STATIC_COLOR1
+ pConInfo
->ActiveStaticControl
), NULL
, TRUE
);
227 pConInfo
->ActiveStaticControl
= colorIndex
;
228 InvalidateRect(GetDlgItem(hwndDlg
, IDC_STATIC_COLOR1
+ pConInfo
->ActiveStaticControl
), NULL
, TRUE
);
229 InvalidateRect(GetDlgItem(hwndDlg
, IDC_STATIC_SCREEN_COLOR
), NULL
, TRUE
);
230 InvalidateRect(GetDlgItem(hwndDlg
, IDC_STATIC_POPUP_COLOR
), NULL
, TRUE
);
235 if ( HIWORD(wParam
) == STN_CLICKED
&&
236 IDC_STATIC_COLOR1
<= LOWORD(wParam
) && LOWORD(wParam
) <= IDC_STATIC_COLOR16
)
238 colorIndex
= LOWORD(wParam
) - IDC_STATIC_COLOR1
;
240 if (colorIndex
== pConInfo
->ActiveStaticControl
)
242 /* Same static control was re-clicked */
246 color
= pConInfo
->ci
.Colors
[colorIndex
];
248 SetDlgItemInt(hwndDlg
, IDC_EDIT_COLOR_RED
, GetRValue(color
), FALSE
);
249 SetDlgItemInt(hwndDlg
, IDC_EDIT_COLOR_GREEN
, GetGValue(color
), FALSE
);
250 SetDlgItemInt(hwndDlg
, IDC_EDIT_COLOR_BLUE
, GetBValue(color
), FALSE
);
252 /* Update global struct */
253 if (IsDlgButtonChecked(hwndDlg
, IDC_RADIO_SCREEN_TEXT
))
255 pConInfo
->ci
.ScreenAttrib
= MakeAttrib(colorIndex
, BkgdAttribFromAttrib(pConInfo
->ci
.ScreenAttrib
));
257 else if (IsDlgButtonChecked(hwndDlg
, IDC_RADIO_SCREEN_BACKGROUND
))
259 pConInfo
->ci
.ScreenAttrib
= MakeAttrib(TextAttribFromAttrib(pConInfo
->ci
.ScreenAttrib
), colorIndex
);
261 else if (IsDlgButtonChecked(hwndDlg
, IDC_RADIO_POPUP_TEXT
))
263 pConInfo
->ci
.PopupAttrib
= MakeAttrib(colorIndex
, BkgdAttribFromAttrib(pConInfo
->ci
.PopupAttrib
));
265 else if (IsDlgButtonChecked(hwndDlg
, IDC_RADIO_POPUP_BACKGROUND
))
267 pConInfo
->ci
.PopupAttrib
= MakeAttrib(TextAttribFromAttrib(pConInfo
->ci
.PopupAttrib
), colorIndex
);
270 InvalidateRect(GetDlgItem(hwndDlg
, IDC_STATIC_COLOR1
+ pConInfo
->ActiveStaticControl
), NULL
, TRUE
);
271 pConInfo
->ActiveStaticControl
= colorIndex
;
272 InvalidateRect(GetDlgItem(hwndDlg
, IDC_STATIC_COLOR1
+ pConInfo
->ActiveStaticControl
), NULL
, TRUE
);
273 InvalidateRect(GetDlgItem(hwndDlg
, IDC_STATIC_SCREEN_COLOR
), NULL
, TRUE
);
274 InvalidateRect(GetDlgItem(hwndDlg
, IDC_STATIC_POPUP_COLOR
), NULL
, TRUE
);
276 PropSheet_Changed(GetParent(hwndDlg
), hwndDlg
);