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"
20 * @brief Default constructor.
22 PropTextColors::PropTextColors(COptionsMgr *optionsMgr, SyntaxColors *pColors)
23 : OptionsPanel(optionsMgr, PropTextColors::IDD)
24 , m_bCustomColors(false)
25 , m_pTempColors(pColors)
30 void PropTextColors::DoDataExchange(CDataExchange* pDX)
32 CDialog::DoDataExchange(pDX);
33 //{{AFX_DATA_MAP(PropTextColors)
34 DDX_Check(pDX, IDC_DEFAULT_STANDARD_COLORS, m_bCustomColors);
35 DDX_Control(pDX, IDC_WHITESPACE_BKGD_COLOR, m_btnWhitespaceBackground);
36 DDX_Control(pDX, IDC_REGULAR_BKGD_COLOR, m_btnRegularBackground);
37 DDX_Control(pDX, IDC_REGULAR_TEXT_COLOR, m_btnRegularText);
38 DDX_Control(pDX, IDC_SELECTION_BKGD_COLOR, m_btnSelectionBackground);
39 DDX_Control(pDX, IDC_SELECTION_TEXT_COLOR, m_btnSelectionText);
40 DDX_Control(pDX, IDC_MARGIN_BKGD_COLOR, m_btnMarginBackground);
42 EnableColorButtons(m_bCustomColors);
46 BEGIN_MESSAGE_MAP(PropTextColors, OptionsPanel)
47 //{{AFX_MSG_MAP(PropTextColors)
48 ON_BN_CLICKED(IDC_DEFAULT_STANDARD_COLORS, OnDefaultsStandardColors)
49 ON_BN_CLICKED(IDC_WHITESPACE_BKGD_COLOR, OnWhitespaceBackgroundColor)
50 ON_BN_CLICKED(IDC_REGULAR_BKGD_COLOR, OnRegularBackgroundColor)
51 ON_BN_CLICKED(IDC_REGULAR_TEXT_COLOR, OnRegularTextColor)
52 ON_BN_CLICKED(IDC_SELECTION_BKGD_COLOR, OnSelectionBackgroundColor)
53 ON_BN_CLICKED(IDC_SELECTION_TEXT_COLOR, OnSelectionTextColor)
54 ON_BN_CLICKED(IDC_MARGIN_BKGD_COLOR, OnMarginBackgroundColor)
59 * @brief Reads options values from storage to UI.
60 * (Property sheet calls this before displaying all property pages)
62 void PropTextColors::ReadOptions()
64 m_bCustomColors = GetOptionsMgr()->GetBool(OPT_CLR_DEFAULT_TEXT_COLORING) ? false : true;
65 SerializeColorsToFromScreen(LOAD_COLORS);
69 * @brief Writes options values from UI to storage.
70 * (Property sheet calls this after displaying all property pages)
72 void PropTextColors::WriteOptions()
74 GetOptionsMgr()->SaveOption(OPT_CLR_DEFAULT_TEXT_COLORING, !m_bCustomColors);
75 // User can only change colors via BrowseColorAndSave,
76 // which writes to m_pTempColors
77 // so user's latest choices are in m_pTempColors
78 // (we don't have to read them from screen)
80 // Also, CPropSyntaxColors writes m_pTempColors out, so we don't have to
81 // We share m_pTempColors with CPropSyntaxColors
85 * @brief Let user browse common color dialog, and select a color
86 * @param [in] colorButton Button for which to change color.
87 * @param [in] colorIndex Index to color table.
89 void PropTextColors::BrowseColorAndSave(CColorButton & colorButton, int colorIndex)
91 // Ignore user if colors are slaved to system
92 if (IsDlgButtonChecked(IDC_DEFAULT_STANDARD_COLORS) == BST_UNCHECKED)
95 COLORREF currentColor = m_pTempColors->GetColor(colorIndex);
96 CColorDialog dialog(currentColor);
97 Options::CustomColors::Load(GetOptionsMgr(), m_cCustColors.data());
98 dialog.m_cc.lpCustColors = m_cCustColors.data();
100 if (dialog.DoModal() == IDOK)
102 currentColor = dialog.GetColor();
103 colorButton.SetColor(currentColor);
104 m_pTempColors->SetColor(colorIndex, currentColor);
106 Options::CustomColors::Save(GetOptionsMgr(), m_cCustColors.data());
110 * @brief User wants to change whitespace color
112 void PropTextColors::OnWhitespaceBackgroundColor()
114 BrowseColorAndSave(m_btnWhitespaceBackground, COLORINDEX_WHITESPACE);
118 * @brief User wants to change regular background color
120 void PropTextColors::OnRegularBackgroundColor()
122 BrowseColorAndSave(m_btnRegularBackground, COLORINDEX_BKGND);
126 * @brief User wants to change regular text color
128 void PropTextColors::OnRegularTextColor()
130 BrowseColorAndSave(m_btnRegularText, COLORINDEX_NORMALTEXT);
134 * @brief User wants to change regular selection background color
136 void PropTextColors::OnSelectionBackgroundColor()
138 BrowseColorAndSave(m_btnSelectionBackground, COLORINDEX_SELBKGND);
142 * @brief User wants to change regular selection text color
144 void PropTextColors::OnSelectionTextColor()
146 BrowseColorAndSave(m_btnSelectionText, COLORINDEX_SELTEXT);
150 * @brief User wants to change margin background color
152 void PropTextColors::OnMarginBackgroundColor()
154 BrowseColorAndSave(m_btnMarginBackground, COLORINDEX_SELMARGIN);
158 * @brief Load all colors, Save all colors, or set all colors to default
159 * @param [in] op Operation to do, one of
160 * - SET_DEFAULTS : Sets colors to defaults
161 * - LOAD_COLORS : Loads colors from registry
162 * (No save operation because BrowseColorAndSave saves immediately when user chooses)
164 void PropTextColors::SerializeColorsToFromScreen(OPERATION op)
166 if (op == SET_DEFAULTS)
167 m_pTempColors->SetDefaults();
169 SerializeColorToFromScreen(op, m_btnWhitespaceBackground, COLORINDEX_WHITESPACE);
171 SerializeColorToFromScreen(op, m_btnRegularBackground, COLORINDEX_BKGND);
172 SerializeColorToFromScreen(op, m_btnRegularText, COLORINDEX_NORMALTEXT);
174 SerializeColorToFromScreen(op, m_btnSelectionBackground, COLORINDEX_SELBKGND);
175 SerializeColorToFromScreen(op, m_btnSelectionText, COLORINDEX_SELTEXT);
177 SerializeColorToFromScreen(op, m_btnMarginBackground, COLORINDEX_SELMARGIN);
181 * @brief Load color to button, Save color from button, or set button color to default
182 * @param [in] op Operation to do, one of
183 * - SET_DEFAULTS : Sets colors to defaults
184 * - LOAD_COLORS : Loads colors from registry
185 * (No save operation because BrowseColorAndSave saves immediately when user chooses)
187 void PropTextColors::SerializeColorToFromScreen(OPERATION op, CColorButton & btn, int colorIndex)
193 btn.SetColor(m_pTempColors->GetColor(colorIndex));
199 * @brief Set colors to track standard (theme) colors
201 void PropTextColors::OnDefaultsStandardColors()
203 // Reset all text colors to default every time user checks defaults button
204 SerializeColorsToFromScreen(SET_DEFAULTS);
210 * @brief Enable / disable color controls on dialog.
211 * @param [in] bEnable If `true` color controls are enabled.
213 void PropTextColors::EnableColorButtons(bool bEnable)
215 EnableDlgItem(IDC_WHITESPACE_COLOR_LABEL, bEnable);
216 EnableDlgItem(IDC_TEXT_COLOR_LABEL, bEnable);
217 EnableDlgItem(IDC_SELECTION_COLOR_LABEL, bEnable);
218 EnableDlgItem(IDC_MARGIN_COLOR_LABEL, bEnable);
219 EnableDlgItem(IDC_BACKGROUND_COLUMN_LABEL, bEnable);
220 EnableDlgItem(IDC_TEXT_COLUMN_LABEL, bEnable);