2 * @file PropTextColors.cpp
4 * @brief Implementation of PropTextColors propertysheet
8 #include "PropTextColors.h"
9 #include "SyntaxColors.h"
10 #include "OptionsCustomColors.h"
11 #include "OptionsDef.h"
12 #include "OptionsMgr.h"
13 #include "OptionsPanel.h"
19 /** @brief Section name for settings in registry. */
20 static const TCHAR Section[] = _T("Custom Colors");
23 * @brief Default constructor.
25 PropTextColors::PropTextColors(COptionsMgr *optionsMgr, SyntaxColors *pColors)
26 : OptionsPanel(optionsMgr, PropTextColors::IDD)
27 , m_bCustomColors(false)
28 , m_pTempColors(pColors)
33 void PropTextColors::DoDataExchange(CDataExchange* pDX)
35 CDialog::DoDataExchange(pDX);
36 //{{AFX_DATA_MAP(PropTextColors)
37 DDX_Check(pDX, IDC_DEFAULT_STANDARD_COLORS, m_bCustomColors);
38 DDX_Control(pDX, IDC_WHITESPACE_BKGD_COLOR, m_btnWhitespaceBackground);
39 DDX_Control(pDX, IDC_REGULAR_BKGD_COLOR, m_btnRegularBackground);
40 DDX_Control(pDX, IDC_REGULAR_TEXT_COLOR, m_btnRegularText);
41 DDX_Control(pDX, IDC_SELECTION_BKGD_COLOR, m_btnSelectionBackground);
42 DDX_Control(pDX, IDC_SELECTION_TEXT_COLOR, m_btnSelectionText);
43 DDX_Control(pDX, IDC_MARGIN_BKGD_COLOR, m_btnMarginBackground);
45 EnableColorButtons(m_bCustomColors);
49 BEGIN_MESSAGE_MAP(PropTextColors, OptionsPanel)
50 //{{AFX_MSG_MAP(PropTextColors)
51 ON_BN_CLICKED(IDC_DEFAULT_STANDARD_COLORS, OnDefaultsStandardColors)
52 ON_BN_CLICKED(IDC_WHITESPACE_BKGD_COLOR, OnWhitespaceBackgroundColor)
53 ON_BN_CLICKED(IDC_REGULAR_BKGD_COLOR, OnRegularBackgroundColor)
54 ON_BN_CLICKED(IDC_REGULAR_TEXT_COLOR, OnRegularTextColor)
55 ON_BN_CLICKED(IDC_SELECTION_BKGD_COLOR, OnSelectionBackgroundColor)
56 ON_BN_CLICKED(IDC_SELECTION_TEXT_COLOR, OnSelectionTextColor)
57 ON_BN_CLICKED(IDC_MARGIN_BKGD_COLOR, OnMarginBackgroundColor)
62 * @brief Reads options values from storage to UI.
63 * (Property sheet calls this before displaying all property pages)
65 void PropTextColors::ReadOptions()
67 m_bCustomColors = GetOptionsMgr()->GetBool(OPT_CLR_DEFAULT_TEXT_COLORING) ? false : true;
68 SerializeColorsToFromScreen(LOAD_COLORS);
72 * @brief Writes options values from UI to storage.
73 * (Property sheet calls this after displaying all property pages)
75 void PropTextColors::WriteOptions()
77 GetOptionsMgr()->SaveOption(OPT_CLR_DEFAULT_TEXT_COLORING, !m_bCustomColors);
78 // User can only change colors via BrowseColorAndSave,
79 // which writes to m_pTempColors
80 // so user's latest choices are in m_pTempColors
81 // (we don't have to read them from screen)
83 // Also, CPropSyntaxColors writes m_pTempColors out, so we don't have to
84 // We share m_pTempColors with CPropSyntaxColors
88 * @brief Let user browse common color dialog, and select a color
89 * @param [in] colorButton Button for which to change color.
90 * @param [in] colorIndex Index to color table.
92 void PropTextColors::BrowseColorAndSave(CColorButton & colorButton, int colorIndex)
94 // Ignore user if colors are slaved to system
95 if (IsDlgButtonChecked(IDC_DEFAULT_STANDARD_COLORS) == BST_UNCHECKED)
98 COLORREF currentColor = m_pTempColors->GetColor(colorIndex);
99 CColorDialog dialog(currentColor);
100 Options::CustomColors::Load(GetOptionsMgr(), m_cCustColors.data());
101 dialog.m_cc.lpCustColors = m_cCustColors.data();
103 if (dialog.DoModal() == IDOK)
105 currentColor = dialog.GetColor();
106 colorButton.SetColor(currentColor);
107 m_pTempColors->SetColor(colorIndex, currentColor);
109 Options::CustomColors::Save(GetOptionsMgr(), m_cCustColors.data());
113 * @brief User wants to change whitespace color
115 void PropTextColors::OnWhitespaceBackgroundColor()
117 BrowseColorAndSave(m_btnWhitespaceBackground, COLORINDEX_WHITESPACE);
121 * @brief User wants to change regular background color
123 void PropTextColors::OnRegularBackgroundColor()
125 BrowseColorAndSave(m_btnRegularBackground, COLORINDEX_BKGND);
129 * @brief User wants to change regular text color
131 void PropTextColors::OnRegularTextColor()
133 BrowseColorAndSave(m_btnRegularText, COLORINDEX_NORMALTEXT);
137 * @brief User wants to change regular selection background color
139 void PropTextColors::OnSelectionBackgroundColor()
141 BrowseColorAndSave(m_btnSelectionBackground, COLORINDEX_SELBKGND);
145 * @brief User wants to change regular selection text color
147 void PropTextColors::OnSelectionTextColor()
149 BrowseColorAndSave(m_btnSelectionText, COLORINDEX_SELTEXT);
153 * @brief User wants to change margin background color
155 void PropTextColors::OnMarginBackgroundColor()
157 BrowseColorAndSave(m_btnMarginBackground, COLORINDEX_SELMARGIN);
161 * @brief Load all colors, Save all colors, or set all colors to default
162 * @param [in] op Operation to do, one of
163 * - SET_DEFAULTS : Sets colors to defaults
164 * - LOAD_COLORS : Loads colors from registry
165 * (No save operation because BrowseColorAndSave saves immediately when user chooses)
167 void PropTextColors::SerializeColorsToFromScreen(OPERATION op)
169 if (op == SET_DEFAULTS)
170 m_pTempColors->SetDefaults();
172 SerializeColorToFromScreen(op, m_btnWhitespaceBackground, COLORINDEX_WHITESPACE);
174 SerializeColorToFromScreen(op, m_btnRegularBackground, COLORINDEX_BKGND);
175 SerializeColorToFromScreen(op, m_btnRegularText, COLORINDEX_NORMALTEXT);
177 SerializeColorToFromScreen(op, m_btnSelectionBackground, COLORINDEX_SELBKGND);
178 SerializeColorToFromScreen(op, m_btnSelectionText, COLORINDEX_SELTEXT);
180 SerializeColorToFromScreen(op, m_btnMarginBackground, COLORINDEX_SELMARGIN);
184 * @brief Load color to button, Save color from button, or set button color to default
185 * @param [in] op Operation to do, one of
186 * - SET_DEFAULTS : Sets colors to defaults
187 * - LOAD_COLORS : Loads colors from registry
188 * (No save operation because BrowseColorAndSave saves immediately when user chooses)
190 void PropTextColors::SerializeColorToFromScreen(OPERATION op, CColorButton & btn, int colorIndex)
196 btn.SetColor(m_pTempColors->GetColor(colorIndex));
202 * @brief Set colors to track standard (theme) colors
204 void PropTextColors::OnDefaultsStandardColors()
206 // Reset all text colors to default every time user checks defaults button
207 SerializeColorsToFromScreen(SET_DEFAULTS);
213 * @brief Enable / disable color controls on dialog.
214 * @param [in] bEnable If `true` color controls are enabled.
216 void PropTextColors::EnableColorButtons(bool bEnable)
218 EnableDlgItem(IDC_WHITESPACE_COLOR_LABEL, bEnable);
219 EnableDlgItem(IDC_TEXT_COLOR_LABEL, bEnable);
220 EnableDlgItem(IDC_SELECTION_COLOR_LABEL, bEnable);
221 EnableDlgItem(IDC_MARGIN_COLOR_LABEL, bEnable);
222 EnableDlgItem(IDC_BACKGROUND_COLUMN_LABEL, bEnable);
223 EnableDlgItem(IDC_TEXT_COLUMN_LABEL, bEnable);