ReactOS  0.4.15-dev-4603-gb922b6d
colors.c
Go to the documentation of this file.
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 
16 
17 static VOID
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  FillRect(drawItem->hDC, &drawItem->rcItem, hBrush ? hBrush : GetStockObject(BLACK_BRUSH));
30  if (hBrush) DeleteObject(hBrush);
31 
33  DrawFocusRect(drawItem->hDC, &drawItem->rcItem);
34 }
35 
38  UINT uMsg,
39  WPARAM wParam,
40  LPARAM lParam)
41 {
42  DWORD colorIndex;
44 
45  switch (uMsg)
46  {
47  case WM_INITDIALOG:
48  {
49  /* Set the valid range of the colour indicators */
53 
54  /* Select by default the screen background option */
57 
58  return TRUE;
59  }
60 
61  case WM_DRAWITEM:
62  {
64 
65  if (IDC_STATIC_COLOR1 <= drawItem->CtlID && drawItem->CtlID <= IDC_STATIC_COLOR16)
66  PaintStaticControls(drawItem, ConInfo);
67  else if (drawItem->CtlID == IDC_STATIC_SCREEN_COLOR)
68  PaintText(drawItem, ConInfo, Screen);
69  else if (drawItem->CtlID == IDC_STATIC_POPUP_COLOR)
70  PaintText(drawItem, ConInfo, Popup);
71 
72  return TRUE;
73  }
74 
75  case WM_NOTIFY:
76  {
77  switch (((LPNMHDR)lParam)->code)
78  {
79  case PSN_APPLY:
80  {
81  ApplyConsoleInfo(hDlg);
82  return TRUE;
83  }
84 
85  case UDN_DELTAPOS:
86  {
87  LPNMUPDOWN lpnmud = (LPNMUPDOWN)lParam;
88 
89  /* Get the current color */
90  colorIndex = ActiveStaticControl;
91  color = ConInfo->ColorTable[colorIndex];
92 
93  if (lpnmud->hdr.idFrom == IDC_UPDOWN_COLOR_RED)
94  {
95  lpnmud->iPos = min(max(lpnmud->iPos + lpnmud->iDelta, 0), 255);
96  color = RGB(lpnmud->iPos, GetGValue(color), GetBValue(color));
97  }
98  else if (lpnmud->hdr.idFrom == IDC_UPDOWN_COLOR_GREEN)
99  {
100  lpnmud->iPos = min(max(lpnmud->iPos + lpnmud->iDelta, 0), 255);
101  color = RGB(GetRValue(color), lpnmud->iPos, GetBValue(color));
102  }
103  else if (lpnmud->hdr.idFrom == IDC_UPDOWN_COLOR_BLUE)
104  {
105  lpnmud->iPos = min(max(lpnmud->iPos + lpnmud->iDelta, 0), 255);
106  color = RGB(GetRValue(color), GetGValue(color), lpnmud->iPos);
107  }
108  else
109  {
110  break;
111  }
112 
113  ConInfo->ColorTable[colorIndex] = color;
114  InvalidateRect(GetDlgItem(hDlg, IDC_STATIC_COLOR1 + colorIndex), NULL, TRUE);
117 
118  PropSheet_Changed(GetParent(hDlg), hDlg);
119  break;
120  }
121  }
122 
123  break;
124  }
125 
126  case WM_COMMAND:
127  {
128  /* NOTE: both BN_CLICKED and STN_CLICKED == 0 */
129  if (HIWORD(wParam) == BN_CLICKED /* || HIWORD(wParam) == STN_CLICKED */)
130  {
131  WORD ctrlIndex = LOWORD(wParam);
132 
133  if (ctrlIndex == IDC_RADIO_SCREEN_TEXT ||
134  ctrlIndex == IDC_RADIO_SCREEN_BACKGROUND ||
135  ctrlIndex == IDC_RADIO_POPUP_TEXT ||
136  ctrlIndex == IDC_RADIO_POPUP_BACKGROUND)
137  {
138  switch (ctrlIndex)
139  {
141  /* Get the colour of the screen foreground */
143  break;
144 
146  /* Get the colour of the screen background */
148  break;
149 
151  /* Get the colour of the popup foreground */
153  break;
154 
156  /* Get the colour of the popup background */
158  break;
159  }
160 
161  color = ConInfo->ColorTable[colorIndex];
162 
163  /* Set the values of the colour indicators */
167 
169  ActiveStaticControl = colorIndex;
171  break;
172  }
173  else
174  if (IDC_STATIC_COLOR1 <= ctrlIndex && ctrlIndex <= IDC_STATIC_COLOR16)
175  {
176  colorIndex = ctrlIndex - 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 */
188 
190  {
192  }
194  {
196  }
198  {
200  }
202  {
204  }
205 
207  ActiveStaticControl = colorIndex;
211 
212  PropSheet_Changed(GetParent(hDlg), hDlg);
213  break;
214  }
215  }
216  else if (HIWORD(wParam) == EN_KILLFOCUS)
217  {
218  WORD ctrlIndex = LOWORD(wParam);
219 
220  if (ctrlIndex == IDC_EDIT_COLOR_RED ||
221  ctrlIndex == IDC_EDIT_COLOR_GREEN ||
222  ctrlIndex == IDC_EDIT_COLOR_BLUE)
223  {
224  DWORD value;
225 
226  /* Get the current colour */
227  colorIndex = ActiveStaticControl;
228  color = ConInfo->ColorTable[colorIndex];
229 
230  /* Modify the colour component */
231  switch (ctrlIndex)
232  {
233  case IDC_EDIT_COLOR_RED:
235  value = min(max(value, 0), 255);
237  break;
238 
241  value = min(max(value, 0), 255);
243  break;
244 
245  case IDC_EDIT_COLOR_BLUE:
247  value = min(max(value, 0), 255);
249  break;
250  }
251 
252  ConInfo->ColorTable[colorIndex] = color;
253  InvalidateRect(GetDlgItem(hDlg, IDC_STATIC_COLOR1 + colorIndex), NULL, TRUE);
256 
257  PropSheet_Changed(GetParent(hDlg), hDlg);
258  break;
259  }
260  }
261 
262  break;
263  }
264 
265  default:
266  break;
267  }
268 
269  return FALSE;
270 }
HGDIOBJ WINAPI GetStockObject(_In_ int)
#define IN
Definition: typedefs.h:39
#define IDC_RADIO_POPUP_BACKGROUND
Definition: resource.h:71
#define max(a, b)
Definition: svc.c:63
Definition: pdh_main.c:93
USHORT ScreenAttributes
Definition: settings.h:47
#define RGB(r, g, b)
Definition: precomp.h:62
NMHDR hdr
Definition: commctrl.h:2164
struct tagDRAWITEMSTRUCT * LPDRAWITEMSTRUCT
#define TRUE
Definition: types.h:120
#define IDC_UPDOWN_COLOR_RED
Definition: resource.h:73
struct _NM_UPDOWN * LPNMUPDOWN
BOOL WINAPI DrawFocusRect(_In_ HDC, _In_ LPCRECT)
#define CALLBACK
Definition: compat.h:35
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
#define GetRValue(quad)
Definition: precomp.h:64
BOOL WINAPI DeleteObject(_In_ HGDIOBJ)
UINT_PTR WPARAM
Definition: windef.h:207
#define PSN_APPLY
Definition: prsht.h:117
int32_t INT_PTR
Definition: typedefs.h:64
WPARAM wParam
Definition: combotst.c:138
#define IDC_STATIC_POPUP_COLOR
Definition: resource.h:79
#define EN_KILLFOCUS
Definition: winuser.h:2012
static VOID PaintStaticControls(IN LPDRAWITEMSTRUCT drawItem, IN PCONSOLE_STATE_INFO pConInfo)
Definition: colors.c:18
#define FALSE
Definition: types.h:117
GLuint color
Definition: glext.h:6243
#define IDC_STATIC_SCREEN_COLOR
Definition: resource.h:78
#define MakeAttrib(TextAttrib, BkgdAttrib)
Definition: settings.h:74
UINT_PTR idFrom
Definition: winuser.h:3138
COLORREF ColorTable[16]
Definition: settings.h:53
#define MAKELONG(a, b)
Definition: typedefs.h:249
#define IDC_EDIT_COLOR_RED
Definition: resource.h:72
UINT WINAPI GetDlgItemInt(_In_ HWND, _In_ int, _Out_opt_ PBOOL, _In_ BOOL)
#define IDC_EDIT_COLOR_BLUE
Definition: resource.h:76
VOID ApplyConsoleInfo(HWND hwndDlg)
Definition: console.c:88
LONG_PTR LPARAM
Definition: windef.h:208
#define GetBValue(quad)
Definition: precomp.h:66
#define IDC_EDIT_COLOR_GREEN
Definition: resource.h:74
#define IDC_RADIO_SCREEN_TEXT
Definition: resource.h:68
#define UDM_SETRANGE
Definition: commctrl.h:2141
GLuint index
Definition: glext.h:6031
#define IDC_UPDOWN_COLOR_BLUE
Definition: resource.h:77
UINT WINAPI IsDlgButtonChecked(_In_ HWND, _In_ int)
#define GetGValue(quad)
Definition: precomp.h:65
#define BkgdAttribFromAttrib(Attribute)
Definition: settings.h:73
#define BLACK_BRUSH
Definition: wingdi.h:896
HWND WINAPI GetDlgItem(_In_opt_ HWND, _In_ int)
#define PropSheet_Changed(d, w)
Definition: prsht.h:344
DWORD COLORREF
Definition: windef.h:300
BOOL WINAPI InvalidateRect(_In_opt_ HWND, _In_opt_ LPCRECT, _In_ BOOL)
unsigned short WORD
Definition: ntddk_ex.h:93
#define BN_CLICKED
Definition: winuser.h:1912
unsigned long DWORD
Definition: ntddk_ex.h:95
LRESULT WINAPI SendDlgItemMessageW(_In_ HWND, _In_ int, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
BOOL WINAPI SetDlgItemInt(_In_ HWND, _In_ int, _In_ UINT, _In_ BOOL)
#define index(s, c)
Definition: various.h:29
#define UDN_DELTAPOS
Definition: commctrl.h:2169
GLsizei const GLfloat * value
Definition: glext.h:6069
#define WM_COMMAND
Definition: winuser.h:1727
Definition: inflate.c:139
#define TextAttribFromAttrib(Attribute)
Definition: settings.h:72
Definition: console.h:35
static DWORD ActiveStaticControl
Definition: colors.c:15
#define IDC_RADIO_SCREEN_BACKGROUND
Definition: resource.h:69
int iDelta
Definition: commctrl.h:2166
HWND WINAPI GetParent(_In_ HWND)
#define IDC_STATIC_COLOR1
Definition: resource.h:81
LRESULT WINAPI SendMessageW(_In_ HWND, _In_ UINT, _In_ WPARAM, _In_ LPARAM)
#define IDC_RADIO_POPUP_TEXT
Definition: resource.h:70
PCONSOLE_STATE_INFO ConInfo
Definition: console.c:23
#define min(a, b)
Definition: monoChain.cc:55
unsigned int UINT
Definition: ndis.h:50
#define NULL
Definition: types.h:112
HBRUSH WINAPI CreateSolidBrush(_In_ COLORREF)
#define WM_DRAWITEM
Definition: winuser.h:1632
#define HIWORD(l)
Definition: typedefs.h:247
Definition: console.h:34
BOOL WINAPI CheckRadioButton(_In_ HWND, _In_ int, _In_ int, _In_ int)
USHORT PopupAttributes
Definition: settings.h:48
int WINAPI FillRect(HDC, LPCRECT, HBRUSH)
VOID PaintText(IN LPDRAWITEMSTRUCT drawItem, IN PCONSOLE_STATE_INFO pConInfo, IN TEXT_TYPE TextMode)
Definition: layout.c:471
#define WM_INITDIALOG
Definition: winuser.h:1726
LPARAM lParam
Definition: combotst.c:139
#define LOWORD(l)
Definition: pedump.c:82
#define WM_NOTIFY
Definition: richedit.h:61
INT_PTR CALLBACK ColorsProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
Definition: colors.c:37
#define IDC_STATIC_COLOR16
Definition: resource.h:96
#define IDC_UPDOWN_COLOR_GREEN
Definition: resource.h:75