Author: hbelusca
Date: Mon May 8 17:19:07 2017
New Revision: 74502
URL:
http://svn.reactos.org/svn/reactos?rev=74502&view=rev
Log:
[CONSOLE.CPL]: Simplify the color selection code by factorizing common parts.
Modified:
trunk/reactos/dll/cpl/console/colors.c
Modified: trunk/reactos/dll/cpl/console/colors.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/dll/cpl/console/colors.c?r…
==============================================================================
--- trunk/reactos/dll/cpl/console/colors.c [iso-8859-1] (original)
+++ trunk/reactos/dll/cpl/console/colors.c [iso-8859-1] Mon May 8 17:19:07 2017
@@ -133,12 +133,34 @@
/* NOTE: both BN_CLICKED and STN_CLICKED == 0 */
if (HIWORD(wParam) == BN_CLICKED || HIWORD(wParam) == STN_CLICKED)
{
- switch (LOWORD(wParam))
- {
- case IDC_RADIO_SCREEN_TEXT:
- {
- /* Get the color of the screen foreground */
- colorIndex = TextAttribFromAttrib(ConInfo->ScreenAttributes);
+ if (LOWORD(wParam) == IDC_RADIO_SCREEN_TEXT ||
+ LOWORD(wParam) == IDC_RADIO_SCREEN_BACKGROUND ||
+ LOWORD(wParam) == IDC_RADIO_POPUP_TEXT ||
+ LOWORD(wParam) == IDC_RADIO_POPUP_BACKGROUND)
+ {
+ switch (LOWORD(wParam))
+ {
+ case IDC_RADIO_SCREEN_TEXT:
+ /* Get the colour of the screen foreground */
+ colorIndex = TextAttribFromAttrib(ConInfo->ScreenAttributes);
+ break;
+
+ case IDC_RADIO_SCREEN_BACKGROUND:
+ /* Get the colour of the screen background */
+ colorIndex = BkgdAttribFromAttrib(ConInfo->ScreenAttributes);
+ break;
+
+ case IDC_RADIO_POPUP_TEXT:
+ /* Get the colour of the popup foreground */
+ colorIndex = TextAttribFromAttrib(ConInfo->PopupAttributes);
+ break;
+
+ case IDC_RADIO_POPUP_BACKGROUND:
+ /* Get the colour of the popup background */
+ colorIndex = BkgdAttribFromAttrib(ConInfo->PopupAttributes);
+ break;
+ }
+
color = ConInfo->ColorTable[colorIndex];
/* Set the values of the colour indicators */
@@ -149,15 +171,17 @@
InvalidateRect(GetDlgItem(hDlg, IDC_STATIC_COLOR1 +
ActiveStaticControl), NULL, TRUE);
ActiveStaticControl = colorIndex;
InvalidateRect(GetDlgItem(hDlg, IDC_STATIC_COLOR1 +
ActiveStaticControl), NULL, TRUE);
- InvalidateRect(GetDlgItem(hDlg, IDC_STATIC_SCREEN_COLOR), NULL,
TRUE);
- InvalidateRect(GetDlgItem(hDlg, IDC_STATIC_POPUP_COLOR) , NULL,
TRUE);
- break;
- }
-
- case IDC_RADIO_SCREEN_BACKGROUND:
- {
- /* Get the color of the screen background */
- colorIndex = BkgdAttribFromAttrib(ConInfo->ScreenAttributes);
+ break;
+ }
+ else
+ if (IDC_STATIC_COLOR1 <= LOWORD(wParam) && LOWORD(wParam)
<= IDC_STATIC_COLOR16)
+ {
+ colorIndex = LOWORD(wParam) - IDC_STATIC_COLOR1;
+
+ /* If the same static control was re-clicked, don't take it into
account */
+ if (colorIndex == ActiveStaticControl)
+ break;
+
color = ConInfo->ColorTable[colorIndex];
/* Set the values of the colour indicators */
@@ -165,67 +189,6 @@
SetDlgItemInt(hDlg, IDC_EDIT_COLOR_GREEN, GetGValue(color), FALSE);
SetDlgItemInt(hDlg, IDC_EDIT_COLOR_BLUE , GetBValue(color), FALSE);
- InvalidateRect(GetDlgItem(hDlg, IDC_STATIC_COLOR1 +
ActiveStaticControl), NULL, TRUE);
- ActiveStaticControl = colorIndex;
- InvalidateRect(GetDlgItem(hDlg, IDC_STATIC_COLOR1 +
ActiveStaticControl), NULL, TRUE);
- InvalidateRect(GetDlgItem(hDlg, IDC_STATIC_SCREEN_COLOR), NULL,
TRUE);
- InvalidateRect(GetDlgItem(hDlg, IDC_STATIC_POPUP_COLOR) , NULL,
TRUE);
- break;
- }
-
- case IDC_RADIO_POPUP_TEXT:
- {
- /* Get the color of the popup foreground */
- colorIndex = TextAttribFromAttrib(ConInfo->PopupAttributes);
- color = ConInfo->ColorTable[colorIndex];
-
- /* Set the values of the colour indicators */
- SetDlgItemInt(hDlg, IDC_EDIT_COLOR_RED , GetRValue(color), FALSE);
- SetDlgItemInt(hDlg, IDC_EDIT_COLOR_GREEN, GetGValue(color), FALSE);
- SetDlgItemInt(hDlg, IDC_EDIT_COLOR_BLUE , GetBValue(color), FALSE);
-
- InvalidateRect(GetDlgItem(hDlg, IDC_STATIC_COLOR1 +
ActiveStaticControl), NULL, TRUE);
- ActiveStaticControl = colorIndex;
- InvalidateRect(GetDlgItem(hDlg, IDC_STATIC_COLOR1 +
ActiveStaticControl), NULL, TRUE);
- InvalidateRect(GetDlgItem(hDlg, IDC_STATIC_SCREEN_COLOR), NULL,
TRUE);
- InvalidateRect(GetDlgItem(hDlg, IDC_STATIC_POPUP_COLOR) , NULL,
TRUE);
- break;
- }
-
- case IDC_RADIO_POPUP_BACKGROUND:
- {
- /* Get the color of the popup background */
- colorIndex = BkgdAttribFromAttrib(ConInfo->PopupAttributes);
- color = ConInfo->ColorTable[colorIndex];
-
- /* Set the values of the colour indicators */
- SetDlgItemInt(hDlg, IDC_EDIT_COLOR_RED , GetRValue(color), FALSE);
- SetDlgItemInt(hDlg, IDC_EDIT_COLOR_GREEN, GetGValue(color), FALSE);
- SetDlgItemInt(hDlg, IDC_EDIT_COLOR_BLUE , GetBValue(color), FALSE);
-
- InvalidateRect(GetDlgItem(hDlg, IDC_STATIC_COLOR1 +
ActiveStaticControl), NULL, TRUE);
- ActiveStaticControl = colorIndex;
- InvalidateRect(GetDlgItem(hDlg, IDC_STATIC_COLOR1 +
ActiveStaticControl), NULL, TRUE);
- InvalidateRect(GetDlgItem(hDlg, IDC_STATIC_SCREEN_COLOR), NULL,
TRUE);
- InvalidateRect(GetDlgItem(hDlg, IDC_STATIC_POPUP_COLOR) , NULL,
TRUE);
- break;
- }
- }
-
- if (IDC_STATIC_COLOR1 <= LOWORD(wParam) && LOWORD(wParam)
<= IDC_STATIC_COLOR16)
- {
- colorIndex = LOWORD(wParam) - IDC_STATIC_COLOR1;
-
- /* If the same static control was re-clicked, don't take it into
account */
- if (colorIndex == ActiveStaticControl)
- break;
-
- color = ConInfo->ColorTable[colorIndex];
-
- SetDlgItemInt(hDlg, IDC_EDIT_COLOR_RED , GetRValue(color), FALSE);
- SetDlgItemInt(hDlg, IDC_EDIT_COLOR_GREEN, GetGValue(color), FALSE);
- SetDlgItemInt(hDlg, IDC_EDIT_COLOR_BLUE , GetBValue(color), FALSE);
-
if (IsDlgButtonChecked(hDlg, IDC_RADIO_SCREEN_TEXT))
{
ConInfo->ScreenAttributes = MakeAttrib(colorIndex,
BkgdAttribFromAttrib(ConInfo->ScreenAttributes));
@@ -255,20 +218,37 @@
}
else if (HIWORD(wParam) == EN_KILLFOCUS)
{
- switch (LOWORD(wParam))
- {
- case IDC_EDIT_COLOR_RED:
- {
- DWORD red;
-
- /* Get the current color */
+ if (LOWORD(wParam) == IDC_EDIT_COLOR_RED ||
+ LOWORD(wParam) == IDC_EDIT_COLOR_GREEN ||
+ LOWORD(wParam) == IDC_EDIT_COLOR_BLUE)
+ {
+ DWORD value;
+
+ /* Get the current colour */
colorIndex = ActiveStaticControl;
color = ConInfo->ColorTable[colorIndex];
- red = GetDlgItemInt(hDlg, IDC_EDIT_COLOR_RED, NULL, FALSE);
- red = min(max(red, 0), 255);
-
- color = RGB(red, GetGValue(color), GetBValue(color));
+ /* Modify the colour component */
+ switch (LOWORD(wParam))
+ {
+ case IDC_EDIT_COLOR_RED:
+ value = GetDlgItemInt(hDlg, IDC_EDIT_COLOR_RED, NULL, FALSE);
+ value = min(max(value, 0), 255);
+ color = RGB(value, GetGValue(color), GetBValue(color));
+ break;
+
+ case IDC_EDIT_COLOR_GREEN:
+ value = GetDlgItemInt(hDlg, IDC_EDIT_COLOR_GREEN, NULL, FALSE);
+ value = min(max(value, 0), 255);
+ color = RGB(GetRValue(color), value, GetBValue(color));
+ break;
+
+ case IDC_EDIT_COLOR_BLUE:
+ value = GetDlgItemInt(hDlg, IDC_EDIT_COLOR_BLUE, NULL, FALSE);
+ value = min(max(value, 0), 255);
+ color = RGB(GetRValue(color), GetGValue(color), value);
+ break;
+ }
ConInfo->ColorTable[colorIndex] = color;
InvalidateRect(GetDlgItem(hDlg, IDC_STATIC_COLOR1 + colorIndex),
NULL, TRUE);
@@ -278,51 +258,6 @@
PropSheet_Changed(GetParent(hDlg), hDlg);
break;
}
-
- case IDC_EDIT_COLOR_GREEN:
- {
- DWORD green;
-
- /* Get the current color */
- colorIndex = ActiveStaticControl;
- color = ConInfo->ColorTable[colorIndex];
-
- green = GetDlgItemInt(hDlg, IDC_EDIT_COLOR_GREEN, NULL, FALSE);
- green = min(max(green, 0), 255);
-
- color = RGB(GetRValue(color), green, GetBValue(color));
-
- ConInfo->ColorTable[colorIndex] = color;
- InvalidateRect(GetDlgItem(hDlg, IDC_STATIC_COLOR1 + colorIndex),
NULL, TRUE);
- InvalidateRect(GetDlgItem(hDlg, IDC_STATIC_SCREEN_COLOR), NULL,
TRUE);
- InvalidateRect(GetDlgItem(hDlg, IDC_STATIC_POPUP_COLOR) , NULL,
TRUE);
-
- PropSheet_Changed(GetParent(hDlg), hDlg);
- break;
- }
-
- case IDC_EDIT_COLOR_BLUE:
- {
- DWORD blue;
-
- /* Get the current color */
- colorIndex = ActiveStaticControl;
- color = ConInfo->ColorTable[colorIndex];
-
- blue = GetDlgItemInt(hDlg, IDC_EDIT_COLOR_BLUE, NULL, FALSE);
- blue = min(max(blue, 0), 255);
-
- color = RGB(GetRValue(color), GetGValue(color), blue);
-
- ConInfo->ColorTable[colorIndex] = color;
- InvalidateRect(GetDlgItem(hDlg, IDC_STATIC_COLOR1 + colorIndex),
NULL, TRUE);
- InvalidateRect(GetDlgItem(hDlg, IDC_STATIC_SCREEN_COLOR), NULL,
TRUE);
- InvalidateRect(GetDlgItem(hDlg, IDC_STATIC_POPUP_COLOR) , NULL,
TRUE);
-
- PropSheet_Changed(GetParent(hDlg), hDlg);
- break;
- }
- }
}
break;