[ACPPAGE] Make use of the PCH.
[reactos.git] / dll / cpl / console / colors.c
1 /*
2 * PROJECT: ReactOS Console Configuration DLL
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: dll/cpl/console/colors.c
5 * PURPOSE: Colors dialog
6 * PROGRAMMERS: Johannes Anderwald (johannes.anderwald@reactos.org)
7 * Hermes Belusca-Maito (hermes.belusca@sfr.fr)
8 */
9
10 #include "console.h"
11
12 #define NDEBUG
13 #include <debug.h>
14
15 static DWORD ActiveStaticControl = 0;
16
17 static VOID
18 PaintStaticControls(
19 IN LPDRAWITEMSTRUCT drawItem,
20 IN PCONSOLE_STATE_INFO pConInfo)
21 {
22 HBRUSH hBrush;
23 DWORD index;
24
25 index = min(drawItem->CtlID - IDC_STATIC_COLOR1,
26 ARRAYSIZE(pConInfo->ColorTable) - 1);
27
28 hBrush = CreateSolidBrush(pConInfo->ColorTable[index]);
29 if (!hBrush) return;
30
31 FillRect(drawItem->hDC, &drawItem->rcItem, hBrush);
32 DeleteObject(hBrush);
33
34 if (ActiveStaticControl == index)
35 DrawFocusRect(drawItem->hDC, &drawItem->rcItem);
36 }
37
38 INT_PTR CALLBACK
39 ColorsProc(HWND hDlg,
40 UINT uMsg,
41 WPARAM wParam,
42 LPARAM lParam)
43 {
44 DWORD colorIndex;
45 COLORREF color;
46
47 switch (uMsg)
48 {
49 case WM_INITDIALOG:
50 {
51 /* Set the valid range of the colour indicators */
52 SendDlgItemMessageW(hDlg, IDC_UPDOWN_COLOR_RED , UDM_SETRANGE, 0, (LPARAM)MAKELONG(255, 0));
53 SendDlgItemMessageW(hDlg, IDC_UPDOWN_COLOR_GREEN, UDM_SETRANGE, 0, (LPARAM)MAKELONG(255, 0));
54 SendDlgItemMessageW(hDlg, IDC_UPDOWN_COLOR_BLUE , UDM_SETRANGE, 0, (LPARAM)MAKELONG(255, 0));
55
56 /* Select by default the screen background option */
57 CheckRadioButton(hDlg, IDC_RADIO_SCREEN_TEXT, IDC_RADIO_POPUP_BACKGROUND, IDC_RADIO_SCREEN_BACKGROUND);
58 SendMessageW(hDlg, WM_COMMAND, IDC_RADIO_SCREEN_BACKGROUND, 0);
59
60 return TRUE;
61 }
62
63 case WM_DRAWITEM:
64 {
65 LPDRAWITEMSTRUCT drawItem = (LPDRAWITEMSTRUCT)lParam;
66
67 if (IDC_STATIC_COLOR1 <= drawItem->CtlID && drawItem->CtlID <= IDC_STATIC_COLOR16)
68 PaintStaticControls(drawItem, ConInfo);
69 else if (drawItem->CtlID == IDC_STATIC_SCREEN_COLOR)
70 PaintText(drawItem, ConInfo, Screen);
71 else if (drawItem->CtlID == IDC_STATIC_POPUP_COLOR)
72 PaintText(drawItem, ConInfo, Popup);
73
74 return TRUE;
75 }
76
77 case WM_NOTIFY:
78 {
79 switch (((LPNMHDR)lParam)->code)
80 {
81 case PSN_APPLY:
82 {
83 ApplyConsoleInfo(hDlg);
84 return TRUE;
85 }
86
87 case UDN_DELTAPOS:
88 {
89 LPNMUPDOWN lpnmud = (LPNMUPDOWN)lParam;
90
91 /* Get the current color */
92 colorIndex = ActiveStaticControl;
93 color = ConInfo->ColorTable[colorIndex];
94
95 if (lpnmud->hdr.idFrom == IDC_UPDOWN_COLOR_RED)
96 {
97 lpnmud->iPos = min(max(lpnmud->iPos + lpnmud->iDelta, 0), 255);
98 color = RGB(lpnmud->iPos, GetGValue(color), GetBValue(color));
99 }
100 else if (lpnmud->hdr.idFrom == IDC_UPDOWN_COLOR_GREEN)
101 {
102 lpnmud->iPos = min(max(lpnmud->iPos + lpnmud->iDelta, 0), 255);
103 color = RGB(GetRValue(color), lpnmud->iPos, GetBValue(color));
104 }
105 else if (lpnmud->hdr.idFrom == IDC_UPDOWN_COLOR_BLUE)
106 {
107 lpnmud->iPos = min(max(lpnmud->iPos + lpnmud->iDelta, 0), 255);
108 color = RGB(GetRValue(color), GetGValue(color), lpnmud->iPos);
109 }
110 else
111 {
112 break;
113 }
114
115 ConInfo->ColorTable[colorIndex] = color;
116 InvalidateRect(GetDlgItem(hDlg, IDC_STATIC_COLOR1 + colorIndex), NULL, TRUE);
117 InvalidateRect(GetDlgItem(hDlg, IDC_STATIC_SCREEN_COLOR), NULL, TRUE);
118 InvalidateRect(GetDlgItem(hDlg, IDC_STATIC_POPUP_COLOR) , NULL, TRUE);
119
120 PropSheet_Changed(GetParent(hDlg), hDlg);
121 break;
122 }
123 }
124
125 break;
126 }
127
128 case WM_COMMAND:
129 {
130 /* NOTE: both BN_CLICKED and STN_CLICKED == 0 */
131 if (HIWORD(wParam) == BN_CLICKED || HIWORD(wParam) == STN_CLICKED)
132 {
133 if (LOWORD(wParam) == IDC_RADIO_SCREEN_TEXT ||
134 LOWORD(wParam) == IDC_RADIO_SCREEN_BACKGROUND ||
135 LOWORD(wParam) == IDC_RADIO_POPUP_TEXT ||
136 LOWORD(wParam) == IDC_RADIO_POPUP_BACKGROUND)
137 {
138 switch (LOWORD(wParam))
139 {
140 case IDC_RADIO_SCREEN_TEXT:
141 /* Get the colour of the screen foreground */
142 colorIndex = TextAttribFromAttrib(ConInfo->ScreenAttributes);
143 break;
144
145 case IDC_RADIO_SCREEN_BACKGROUND:
146 /* Get the colour of the screen background */
147 colorIndex = BkgdAttribFromAttrib(ConInfo->ScreenAttributes);
148 break;
149
150 case IDC_RADIO_POPUP_TEXT:
151 /* Get the colour of the popup foreground */
152 colorIndex = TextAttribFromAttrib(ConInfo->PopupAttributes);
153 break;
154
155 case IDC_RADIO_POPUP_BACKGROUND:
156 /* Get the colour of the popup background */
157 colorIndex = BkgdAttribFromAttrib(ConInfo->PopupAttributes);
158 break;
159 }
160
161 color = ConInfo->ColorTable[colorIndex];
162
163 /* Set the values of the colour indicators */
164 SetDlgItemInt(hDlg, IDC_EDIT_COLOR_RED , GetRValue(color), FALSE);
165 SetDlgItemInt(hDlg, IDC_EDIT_COLOR_GREEN, GetGValue(color), FALSE);
166 SetDlgItemInt(hDlg, IDC_EDIT_COLOR_BLUE , GetBValue(color), FALSE);
167
168 InvalidateRect(GetDlgItem(hDlg, IDC_STATIC_COLOR1 + ActiveStaticControl), NULL, TRUE);
169 ActiveStaticControl = colorIndex;
170 InvalidateRect(GetDlgItem(hDlg, IDC_STATIC_COLOR1 + ActiveStaticControl), NULL, TRUE);
171 break;
172 }
173 else
174 if (IDC_STATIC_COLOR1 <= LOWORD(wParam) && LOWORD(wParam) <= IDC_STATIC_COLOR16)
175 {
176 colorIndex = LOWORD(wParam) - IDC_STATIC_COLOR1;
177
178 /* If the same static control was re-clicked, don't take it into account */
179 if (colorIndex == ActiveStaticControl)
180 break;
181
182 color = ConInfo->ColorTable[colorIndex];
183
184 /* Set the values of the colour indicators */
185 SetDlgItemInt(hDlg, IDC_EDIT_COLOR_RED , GetRValue(color), FALSE);
186 SetDlgItemInt(hDlg, IDC_EDIT_COLOR_GREEN, GetGValue(color), FALSE);
187 SetDlgItemInt(hDlg, IDC_EDIT_COLOR_BLUE , GetBValue(color), FALSE);
188
189 if (IsDlgButtonChecked(hDlg, IDC_RADIO_SCREEN_TEXT))
190 {
191 ConInfo->ScreenAttributes = MakeAttrib(colorIndex, BkgdAttribFromAttrib(ConInfo->ScreenAttributes));
192 }
193 else if (IsDlgButtonChecked(hDlg, IDC_RADIO_SCREEN_BACKGROUND))
194 {
195 ConInfo->ScreenAttributes = MakeAttrib(TextAttribFromAttrib(ConInfo->ScreenAttributes), colorIndex);
196 }
197 else if (IsDlgButtonChecked(hDlg, IDC_RADIO_POPUP_TEXT))
198 {
199 ConInfo->PopupAttributes = MakeAttrib(colorIndex, BkgdAttribFromAttrib(ConInfo->PopupAttributes));
200 }
201 else if (IsDlgButtonChecked(hDlg, IDC_RADIO_POPUP_BACKGROUND))
202 {
203 ConInfo->PopupAttributes = MakeAttrib(TextAttribFromAttrib(ConInfo->PopupAttributes), colorIndex);
204 }
205
206 InvalidateRect(GetDlgItem(hDlg, IDC_STATIC_COLOR1 + ActiveStaticControl), NULL, TRUE);
207 ActiveStaticControl = colorIndex;
208 InvalidateRect(GetDlgItem(hDlg, IDC_STATIC_COLOR1 + ActiveStaticControl), NULL, TRUE);
209 InvalidateRect(GetDlgItem(hDlg, IDC_STATIC_SCREEN_COLOR), NULL, TRUE);
210 InvalidateRect(GetDlgItem(hDlg, IDC_STATIC_POPUP_COLOR) , NULL, TRUE);
211
212 PropSheet_Changed(GetParent(hDlg), hDlg);
213 break;
214 }
215 }
216 else if (HIWORD(wParam) == EN_KILLFOCUS)
217 {
218 if (LOWORD(wParam) == IDC_EDIT_COLOR_RED ||
219 LOWORD(wParam) == IDC_EDIT_COLOR_GREEN ||
220 LOWORD(wParam) == IDC_EDIT_COLOR_BLUE)
221 {
222 DWORD value;
223
224 /* Get the current colour */
225 colorIndex = ActiveStaticControl;
226 color = ConInfo->ColorTable[colorIndex];
227
228 /* Modify the colour component */
229 switch (LOWORD(wParam))
230 {
231 case IDC_EDIT_COLOR_RED:
232 value = GetDlgItemInt(hDlg, IDC_EDIT_COLOR_RED, NULL, FALSE);
233 value = min(max(value, 0), 255);
234 color = RGB(value, GetGValue(color), GetBValue(color));
235 break;
236
237 case IDC_EDIT_COLOR_GREEN:
238 value = GetDlgItemInt(hDlg, IDC_EDIT_COLOR_GREEN, NULL, FALSE);
239 value = min(max(value, 0), 255);
240 color = RGB(GetRValue(color), value, GetBValue(color));
241 break;
242
243 case IDC_EDIT_COLOR_BLUE:
244 value = GetDlgItemInt(hDlg, IDC_EDIT_COLOR_BLUE, NULL, FALSE);
245 value = min(max(value, 0), 255);
246 color = RGB(GetRValue(color), GetGValue(color), value);
247 break;
248 }
249
250 ConInfo->ColorTable[colorIndex] = color;
251 InvalidateRect(GetDlgItem(hDlg, IDC_STATIC_COLOR1 + colorIndex), NULL, TRUE);
252 InvalidateRect(GetDlgItem(hDlg, IDC_STATIC_SCREEN_COLOR), NULL, TRUE);
253 InvalidateRect(GetDlgItem(hDlg, IDC_STATIC_POPUP_COLOR) , NULL, TRUE);
254
255 PropSheet_Changed(GetParent(hDlg), hDlg);
256 break;
257 }
258 }
259
260 break;
261 }
262
263 default:
264 break;
265 }
266
267 return FALSE;
268 }