- Update icons
[reactos.git] / reactos / dll / cpl / console / colors.c
1 /* $Id: colors.c 29690 2007-10-19 23:21:45Z dreimer $
2 *
3 * PROJECT: ReactOS Console Configuration DLL
4 * LICENSE: GPL - See COPYING in the top level directory
5 * FILE: dll/win32/console/colors.c
6 * PURPOSE: displays colors dialog
7 * PROGRAMMERS: Johannes Anderwald (johannes.anderwald@student.tugraz.at)
8 */
9
10 #include "console.h"
11
12 static
13 BOOL
14 PaintStaticControls(HWND hwndDlg, PConsoleInfo pConInfo, LPDRAWITEMSTRUCT drawItem)
15 {
16 HBRUSH hBrush;
17 DWORD index;
18
19 index = drawItem->CtlID - IDC_STATIC_COLOR1;
20 hBrush = CreateSolidBrush(pConInfo->Colors[index]);
21 if (!hBrush)
22 {
23 return FALSE;
24 }
25
26 FillRect(drawItem->hDC, &drawItem->rcItem, hBrush);
27 DeleteObject((HGDIOBJ)hBrush);
28 if (pConInfo->ActiveStaticControl == index)
29 {
30 DrawFocusRect(drawItem->hDC, &drawItem->rcItem);
31 }
32 return TRUE;
33 }
34
35 INT_PTR
36 CALLBACK
37 ColorsProc(
38 HWND hwndDlg,
39 UINT uMsg,
40 WPARAM wParam,
41 LPARAM lParam
42 )
43 {
44 PConsoleInfo pConInfo;
45 LPNMUPDOWN lpnmud;
46 LPPSHNOTIFY lppsn;
47 LPDRAWITEMSTRUCT drawItem;
48 DWORD red = -1;
49 DWORD green = -1;
50 DWORD blue = -1;
51
52 pConInfo = (PConsoleInfo) GetWindowLongPtr(hwndDlg, DWLP_USER);
53
54 switch(uMsg)
55 {
56 case WM_INITDIALOG:
57 {
58 pConInfo = (PConsoleInfo) ((LPPROPSHEETPAGE)lParam)->lParam;
59 SetWindowLongPtr(hwndDlg, DWLP_USER, (LONG_PTR)pConInfo);
60 SendMessage(GetDlgItem(hwndDlg, IDC_RADIO_SCREEN_BACKGROUND), BM_SETCHECK, BST_CHECKED, 0);
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));
64 SetDlgItemInt(hwndDlg, IDC_EDIT_COLOR_RED, GetRValue(pConInfo->ScreenBackground), FALSE);
65 SetDlgItemInt(hwndDlg, IDC_EDIT_COLOR_GREEN, GetGValue(pConInfo->ScreenBackground), FALSE);
66 SetDlgItemInt(hwndDlg, IDC_EDIT_COLOR_BLUE, GetBValue(pConInfo->ScreenBackground), FALSE);
67 CheckRadioButton(hwndDlg, IDC_RADIO_SCREEN_TEXT, IDC_RADIO_POPUP_BACKGROUND, IDC_RADIO_SCREEN_BACKGROUND);
68 return TRUE;
69 }
70 case WM_DRAWITEM:
71 {
72 drawItem = (LPDRAWITEMSTRUCT)lParam;
73 if (drawItem->CtlID >= IDC_STATIC_COLOR1 && drawItem->CtlID <= IDC_STATIC_COLOR16)
74 {
75 return PaintStaticControls(hwndDlg, pConInfo, drawItem);
76 }
77 else if (drawItem->CtlID == IDC_STATIC_SCREEN_COLOR || drawItem->CtlID == IDC_STATIC_POPUP_COLOR)
78 {
79 PaintText(drawItem, pConInfo);
80 return TRUE;
81 }
82 }
83 case WM_NOTIFY:
84 {
85 lpnmud = (LPNMUPDOWN) lParam;
86 lppsn = (LPPSHNOTIFY) lParam;
87
88 if (lppsn->hdr.code == PSN_APPLY)
89 {
90 if (!pConInfo->AppliedConfig)
91 {
92 ApplyConsoleInfo(hwndDlg, pConInfo);
93 }
94 else
95 {
96 /* options have already been applied */
97 SetWindowLong(hwndDlg, DWL_MSGRESULT, PSNRET_NOERROR);
98 return TRUE;
99 }
100 return TRUE;
101 }
102
103 if (lpnmud->hdr.idFrom == IDC_UPDOWN_COLOR_RED)
104 {
105 red = lpnmud->iPos;
106 }
107 else if (lpnmud->hdr.idFrom == IDC_UPDOWN_COLOR_GREEN)
108 {
109 green = lpnmud->iPos;
110 }
111 else if (lpnmud->hdr.idFrom == IDC_UPDOWN_COLOR_BLUE)
112 {
113 blue = lpnmud->iPos;
114 }
115 else
116 {
117 break;
118 }
119
120 if (red == -1)
121 {
122 red = SendMessage(GetDlgItem(hwndDlg, IDC_UPDOWN_COLOR_RED), UDM_GETPOS, 0, 0);
123 if (HIWORD(red))
124 {
125 //TODO: handle error
126 break;
127 }
128 red = LOBYTE(red);
129 }
130
131 if (green == -1)
132 {
133 green = SendMessage(GetDlgItem(hwndDlg, IDC_UPDOWN_COLOR_GREEN), UDM_GETPOS, 0, 0);
134 if (HIWORD(green))
135 {
136 //TODO: handle error
137 break;
138 }
139 green = LOBYTE(green);
140 }
141
142 if (blue == -1)
143 {
144 blue = SendMessage(GetDlgItem(hwndDlg, IDC_UPDOWN_COLOR_BLUE), UDM_GETPOS, 0, 0);
145 if (HIWORD(blue))
146 {
147 //TODO: handle error
148 break;
149 }
150 blue = LOBYTE(blue);
151 }
152 pConInfo->Colors[pConInfo->ActiveStaticControl] = RGB(red, green, blue);
153 InvalidateRect(GetDlgItem(hwndDlg, IDC_STATIC_COLOR1 + pConInfo->ActiveStaticControl), NULL, TRUE);
154 InvalidateRect(GetDlgItem(hwndDlg, IDC_STATIC_SCREEN_COLOR), NULL, TRUE);
155 InvalidateRect(GetDlgItem(hwndDlg, IDC_STATIC_POPUP_COLOR), NULL, TRUE);
156 break;
157 }
158 case WM_COMMAND:
159 {
160 switch(LOWORD(wParam))
161 {
162 case IDC_RADIO_SCREEN_TEXT:
163 {
164 SetDlgItemInt(hwndDlg, IDC_EDIT_COLOR_RED, GetRValue(pConInfo->ScreenText), FALSE);
165 SetDlgItemInt(hwndDlg, IDC_EDIT_COLOR_GREEN, GetGValue(pConInfo->ScreenText), FALSE);
166 SetDlgItemInt(hwndDlg, IDC_EDIT_COLOR_BLUE, GetBValue(pConInfo->ScreenText), FALSE);
167 InvalidateRect(GetDlgItem(hwndDlg, IDC_STATIC_SCREEN_COLOR), NULL, TRUE);
168 InvalidateRect(GetDlgItem(hwndDlg, IDC_STATIC_POPUP_COLOR), NULL, TRUE);
169 break;
170 }
171 case IDC_RADIO_SCREEN_BACKGROUND:
172 {
173 SetDlgItemInt(hwndDlg, IDC_EDIT_COLOR_RED, GetRValue(pConInfo->ScreenBackground), FALSE);
174 SetDlgItemInt(hwndDlg, IDC_EDIT_COLOR_GREEN, GetGValue(pConInfo->ScreenBackground), FALSE);
175 SetDlgItemInt(hwndDlg, IDC_EDIT_COLOR_BLUE, GetBValue(pConInfo->ScreenBackground), FALSE);
176 InvalidateRect(GetDlgItem(hwndDlg, IDC_STATIC_SCREEN_COLOR), NULL, TRUE);
177 InvalidateRect(GetDlgItem(hwndDlg, IDC_STATIC_POPUP_COLOR), NULL, TRUE);
178 break;
179 }
180 case IDC_RADIO_POPUP_TEXT:
181 {
182 SetDlgItemInt(hwndDlg, IDC_EDIT_COLOR_RED, GetRValue(pConInfo->PopupText), FALSE);
183 SetDlgItemInt(hwndDlg, IDC_EDIT_COLOR_GREEN, GetGValue(pConInfo->PopupText), FALSE);
184 SetDlgItemInt(hwndDlg, IDC_EDIT_COLOR_BLUE, GetBValue(pConInfo->PopupText), FALSE);
185 InvalidateRect(GetDlgItem(hwndDlg, IDC_STATIC_SCREEN_COLOR), NULL, TRUE);
186 InvalidateRect(GetDlgItem(hwndDlg, IDC_STATIC_POPUP_COLOR), NULL, TRUE);
187 break;
188 }
189 case IDC_RADIO_POPUP_BACKGROUND:
190 {
191 SetDlgItemInt(hwndDlg, IDC_EDIT_COLOR_RED, GetRValue(pConInfo->PopupBackground), FALSE);
192 SetDlgItemInt(hwndDlg, IDC_EDIT_COLOR_GREEN, GetGValue(pConInfo->PopupBackground), FALSE);
193 SetDlgItemInt(hwndDlg, IDC_EDIT_COLOR_BLUE, GetBValue(pConInfo->PopupBackground), FALSE);
194 InvalidateRect(GetDlgItem(hwndDlg, IDC_STATIC_SCREEN_COLOR), NULL, TRUE);
195 InvalidateRect(GetDlgItem(hwndDlg, IDC_STATIC_POPUP_COLOR), NULL, TRUE);
196 break;
197 }
198 }
199 if (HIWORD(wParam) == STN_CLICKED && LOWORD(wParam) >= IDC_STATIC_COLOR1 && LOWORD(wParam) <= IDC_STATIC_COLOR16)
200 {
201 DWORD index = LOWORD(wParam) - IDC_STATIC_COLOR1;
202
203 if (index == pConInfo->ActiveStaticControl)
204 {
205 /* same static control was re-clicked */
206 break;
207 }
208
209 SetDlgItemInt(hwndDlg, IDC_EDIT_COLOR_RED, GetRValue(pConInfo->Colors[index]), FALSE);
210 SetDlgItemInt(hwndDlg, IDC_EDIT_COLOR_GREEN, GetGValue(pConInfo->Colors[index]), FALSE);
211 SetDlgItemInt(hwndDlg, IDC_EDIT_COLOR_BLUE, GetBValue(pConInfo->Colors[index]), FALSE);
212
213 /* update global struct */
214 if (IsDlgButtonChecked(hwndDlg, IDC_RADIO_SCREEN_TEXT))
215 {
216 pConInfo->ScreenText = pConInfo->Colors[index];
217 }
218 else if (IsDlgButtonChecked(hwndDlg, IDC_RADIO_SCREEN_BACKGROUND))
219 {
220 pConInfo->ScreenBackground = pConInfo->Colors[index];
221 }
222 else if (IsDlgButtonChecked(hwndDlg, IDC_RADIO_POPUP_TEXT))
223 {
224 pConInfo->PopupText = pConInfo->Colors[index];
225 }
226 else if (IsDlgButtonChecked(hwndDlg, IDC_RADIO_POPUP_BACKGROUND))
227 {
228 pConInfo->PopupBackground = pConInfo->Colors[index];
229 }
230 InvalidateRect(GetDlgItem(hwndDlg, IDC_STATIC_COLOR1 + pConInfo->ActiveStaticControl), NULL, TRUE);
231 InvalidateRect(GetDlgItem(hwndDlg, IDC_STATIC_COLOR1 + index), NULL, TRUE);
232 InvalidateRect(GetDlgItem(hwndDlg, IDC_STATIC_SCREEN_COLOR), NULL, TRUE);
233 InvalidateRect(GetDlgItem(hwndDlg, IDC_STATIC_POPUP_COLOR), NULL, TRUE);
234 pConInfo->ActiveStaticControl = index;
235 break;
236 }
237 }
238
239
240 default:
241 break;
242 }
243
244 return FALSE;
245 }