2 * @file PropTextColors.cpp
4 * @brief Implementation of PropTextColors propertysheet
8 #include "PropTextColors.h"
10 #include "SyntaxColors.h"
11 #include "OptionsCustomColors.h"
12 #include "OptionsDef.h"
13 #include "OptionsMgr.h"
14 #include "OptionsPanel.h"
15 #include "DDXHelper.h"
20 static char THIS_FILE[] = __FILE__;
23 /** @brief Section name for settings in registry. */
24 static const TCHAR Section[] = _T("Custom Colors");
27 * @brief Default constructor.
29 PropTextColors::PropTextColors(COptionsMgr *optionsMgr, SyntaxColors *pColors)
30 : OptionsPanel(optionsMgr, PropTextColors::IDD)
31 , m_bCustomColors(false)
32 , m_pTempColors(pColors)
34 memset(m_cCustColors, 0, sizeof(m_cCustColors));
37 void PropTextColors::DoDataExchange(CDataExchange* pDX)
39 CDialog::DoDataExchange(pDX);
40 //{{AFX_DATA_MAP(PropTextColors)
41 DDX_Control(pDX, IDC_DEFAULT_STANDARD_COLORS, m_btnDefaultStandardColors);
42 DDX_Check(pDX, IDC_DEFAULT_STANDARD_COLORS, m_bCustomColors);
43 DDX_Control(pDX, IDC_WHITESPACE_BKGD_COLOR, m_btnWhitespaceBackground);
44 DDX_Control(pDX, IDC_REGULAR_BKGD_COLOR, m_btnRegularBackground);
45 DDX_Control(pDX, IDC_REGULAR_TEXT_COLOR, m_btnRegularText);
46 DDX_Control(pDX, IDC_SELECTION_BKGD_COLOR, m_btnSelectionBackground);
47 DDX_Control(pDX, IDC_SELECTION_TEXT_COLOR, m_btnSelectionText);
52 BEGIN_MESSAGE_MAP(PropTextColors, CDialog)
53 //{{AFX_MSG_MAP(PropTextColors)
54 ON_BN_CLICKED(IDC_DEFAULT_STANDARD_COLORS, OnDefaultsStandardColors)
55 ON_BN_CLICKED(IDC_WHITESPACE_BKGD_COLOR, OnWhitespaceBackgroundColor)
56 ON_BN_CLICKED(IDC_REGULAR_BKGD_COLOR, OnRegularBackgroundColor)
57 ON_BN_CLICKED(IDC_REGULAR_TEXT_COLOR, OnRegularTextColor)
58 ON_BN_CLICKED(IDC_SELECTION_BKGD_COLOR, OnSelectionBackgroundColor)
59 ON_BN_CLICKED(IDC_SELECTION_TEXT_COLOR, OnSelectionTextColor)
64 * @brief Enable/Disable controls when dialog is shown.
66 BOOL PropTextColors::OnInitDialog()
68 theApp.TranslateDialog(m_hWnd);
69 CPropertyPage::OnInitDialog();
72 EnableColorButtons(TRUE);
74 EnableColorButtons(FALSE);
76 return TRUE; // return TRUE unless you set the focus to a control
80 * @brief Reads options values from storage to UI.
81 * (Property sheet calls this before displaying all property pages)
83 void PropTextColors::ReadOptions()
85 m_bCustomColors = GetOptionsMgr()->GetBool(OPT_CLR_DEFAULT_TEXT_COLORING) ? false : true;
86 SerializeColorsToFromScreen(LOAD_COLORS);
90 * @brief Writes options values from UI to storage.
91 * (Property sheet calls this after displaying all property pages)
93 void PropTextColors::WriteOptions()
95 GetOptionsMgr()->SaveOption(OPT_CLR_DEFAULT_TEXT_COLORING, m_bCustomColors == false);
96 // User can only change colors via BrowseColorAndSave,
97 // which writes to m_pTempColors
98 // so user's latest choices are in m_pTempColors
99 // (we don't have to read them from screen)
101 // Also, CPropSyntaxColors writes m_pTempColors out, so we don't have to
102 // We share m_pTempColors with CPropSyntaxColors
106 * @brief Let user browse common color dialog, and select a color
107 * @param [in] colorButton Button for which to change color.
108 * @param [in] colorIndex Index to color table.
110 void PropTextColors::BrowseColorAndSave(CColorButton & colorButton, int colorIndex)
112 // Ignore user if colors are slaved to system
113 if (m_btnDefaultStandardColors.GetCheck() == BST_UNCHECKED)
116 COLORREF currentColor = m_pTempColors->GetColor(colorIndex);
117 CColorDialog dialog(currentColor);
118 Options::CustomColors::Load(m_cCustColors);
119 dialog.m_cc.lpCustColors = m_cCustColors;
121 if (dialog.DoModal() == IDOK)
123 currentColor = dialog.GetColor();
124 colorButton.SetColor(currentColor);
125 m_pTempColors->SetColor(colorIndex, currentColor);
127 Options::CustomColors::Save(m_cCustColors);
131 * @brief User wants to change whitespace color
133 void PropTextColors::OnWhitespaceBackgroundColor()
135 BrowseColorAndSave(m_btnWhitespaceBackground, COLORINDEX_WHITESPACE);
139 * @brief User wants to change regular background color
141 void PropTextColors::OnRegularBackgroundColor()
143 BrowseColorAndSave(m_btnRegularBackground, COLORINDEX_BKGND);
147 * @brief User wants to change regular text color
149 void PropTextColors::OnRegularTextColor()
151 BrowseColorAndSave(m_btnRegularText, COLORINDEX_NORMALTEXT);
155 * @brief User wants to change regular selection background color
157 void PropTextColors::OnSelectionBackgroundColor()
159 BrowseColorAndSave(m_btnSelectionBackground, COLORINDEX_SELBKGND);
163 * @brief User wants to change regular selection text color
165 void PropTextColors::OnSelectionTextColor()
167 BrowseColorAndSave(m_btnSelectionText, COLORINDEX_SELTEXT);
171 * @brief Load all colors, Save all colors, or set all colors to default
172 * @param [in] op Operation to do, one of
173 * - SET_DEFAULTS : Sets colors to defaults
174 * - LOAD_COLORS : Loads colors from registry
175 * (No save operation because BrowseColorAndSave saves immediately when user chooses)
177 void PropTextColors::SerializeColorsToFromScreen(OPERATION op)
179 if (op == SET_DEFAULTS)
180 m_pTempColors->SetDefaults();
182 SerializeColorToFromScreen(op, m_btnWhitespaceBackground, COLORINDEX_WHITESPACE);
184 SerializeColorToFromScreen(op, m_btnRegularBackground, COLORINDEX_BKGND);
185 SerializeColorToFromScreen(op, m_btnRegularText, COLORINDEX_NORMALTEXT);
187 SerializeColorToFromScreen(op, m_btnSelectionBackground, COLORINDEX_SELBKGND);
188 SerializeColorToFromScreen(op, m_btnSelectionText, COLORINDEX_SELTEXT);
192 * @brief Load color to button, Save color from button, or set button color to default
193 * @param [in] op Operation to do, one of
194 * - SET_DEFAULTS : Sets colors to defaults
195 * - LOAD_COLORS : Loads colors from registry
196 * (No save operation because BrowseColorAndSave saves immediately when user chooses)
198 void PropTextColors::SerializeColorToFromScreen(OPERATION op, CColorButton & btn, int colorIndex)
205 COLORREF color = m_pTempColors->GetColor(colorIndex);
212 COLORREF color = m_pTempColors->GetColor(colorIndex);
213 // Set colors for buttons, do NOT invalidate
214 btn.SetColor(color, FALSE);
221 * @brief Set colors to track standard (theme) colors
223 void PropTextColors::OnDefaultsStandardColors()
225 // Reset all text colors to default every time user checks defaults button
226 SerializeColorsToFromScreen(SET_DEFAULTS);
228 CButton * btn = (CButton *)GetDlgItem(IDC_DEFAULT_STANDARD_COLORS);
229 if (btn->GetCheck() == BST_UNCHECKED)
231 EnableColorButtons(FALSE);
235 EnableColorButtons(TRUE);
240 * @brief Enable / disable color controls on dialog.
241 * @param [in] bEnable If TRUE color controls are enabled.
243 void PropTextColors::EnableColorButtons(BOOL bEnable)
245 CStatic * stc = (CStatic *) GetDlgItem(IDC_CUSTOM_COLORS_GROUP);
246 stc->EnableWindow(bEnable);
247 stc = (CStatic *) GetDlgItem(IDC_WHITESPACE_COLOR_LABEL);
248 stc->EnableWindow(bEnable);
249 stc = (CStatic *) GetDlgItem(IDC_TEXT_COLOR_LABEL);
250 stc->EnableWindow(bEnable);
251 stc = (CStatic *) GetDlgItem(IDC_SELECTION_COLOR_LABEL);
252 stc->EnableWindow(bEnable);
253 stc = (CStatic *) GetDlgItem(IDC_BACKGROUND_COLUMN_LABEL);
254 stc->EnableWindow(bEnable);
255 stc = (CStatic *) GetDlgItem(IDC_TEXT_COLUMN_LABEL);
256 stc->EnableWindow(bEnable);