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