2 * @file PropTextColors.cpp
4 * @brief Implementation of PropTextColors propertysheet
6 // ID line follows -- this is updated by SVN
12 #include "PropTextColors.h"
13 #include "SyntaxColors.h"
14 #include "CustomColors.h"
15 #include "OptionsDef.h"
16 #include "OptionsMgr.h"
17 #include "OptionsPanel.h"
18 #include "DDXHelper.h"
23 static char THIS_FILE[] = __FILE__;
26 /** @brief Section name for settings in registry. */
27 static const TCHAR Section[] = _T("Custom Colors");
30 * @brief Default constructor.
32 PropTextColors::PropTextColors(COptionsMgr *optionsMgr, SyntaxColors *pColors)
33 : OptionsPanel(optionsMgr, PropTextColors::IDD)
34 , m_bCustomColors(false)
35 , m_pTempColors(pColors)
39 void PropTextColors::DoDataExchange(CDataExchange* pDX)
41 CDialog::DoDataExchange(pDX);
42 //{{AFX_DATA_MAP(PropTextColors)
43 DDX_Control(pDX, IDC_DEFAULT_STANDARD_COLORS, m_btnDefaultStandardColors);
44 DDX_Check(pDX, IDC_DEFAULT_STANDARD_COLORS, m_bCustomColors);
45 DDX_Control(pDX, IDC_WHITESPACE_BKGD_COLOR, m_btnWhitespaceBackground);
46 DDX_Control(pDX, IDC_REGULAR_BKGD_COLOR, m_btnRegularBackground);
47 DDX_Control(pDX, IDC_REGULAR_TEXT_COLOR, m_btnRegularText);
48 DDX_Control(pDX, IDC_SELECTION_BKGD_COLOR, m_btnSelectionBackground);
49 DDX_Control(pDX, IDC_SELECTION_TEXT_COLOR, m_btnSelectionText);
54 BEGIN_MESSAGE_MAP(PropTextColors, CDialog)
55 //{{AFX_MSG_MAP(PropTextColors)
56 ON_BN_CLICKED(IDC_DEFAULT_STANDARD_COLORS, OnDefaultsStandardColors)
57 ON_BN_CLICKED(IDC_WHITESPACE_BKGD_COLOR, OnWhitespaceBackgroundColor)
58 ON_BN_CLICKED(IDC_REGULAR_BKGD_COLOR, OnRegularBackgroundColor)
59 ON_BN_CLICKED(IDC_REGULAR_TEXT_COLOR, OnRegularTextColor)
60 ON_BN_CLICKED(IDC_SELECTION_BKGD_COLOR, OnSelectionBackgroundColor)
61 ON_BN_CLICKED(IDC_SELECTION_TEXT_COLOR, OnSelectionTextColor)
66 * @brief Enable/Disable controls when dialog is shown.
68 BOOL PropTextColors::OnInitDialog()
70 theApp.TranslateDialog(m_hWnd);
71 CPropertyPage::OnInitDialog();
74 EnableColorButtons(TRUE);
76 EnableColorButtons(FALSE);
78 return TRUE; // return TRUE unless you set the focus to a control
82 * @brief Reads options values from storage to UI.
83 * (Property sheet calls this before displaying all property pages)
85 void PropTextColors::ReadOptions()
87 m_bCustomColors = GetOptionsMgr()->GetBool(OPT_CLR_DEFAULT_TEXT_COLORING) ? false : true;
88 SerializeColorsToFromScreen(LOAD_COLORS);
92 * @brief Writes options values from UI to storage.
93 * (Property sheet calls this after displaying all property pages)
95 void PropTextColors::WriteOptions()
97 GetOptionsMgr()->SaveOption(OPT_CLR_DEFAULT_TEXT_COLORING, m_bCustomColors == false);
98 // User can only change colors via BrowseColorAndSave,
99 // which writes to m_pTempColors
100 // so user's latest choices are in m_pTempColors
101 // (we don't have to read them from screen)
103 // Also, CPropSyntaxColors writes m_pTempColors out, so we don't have to
104 // We share m_pTempColors with CPropSyntaxColors
108 * @brief Let user browse common color dialog, and select a color
109 * @param [in] colorButton Button for which to change color.
110 * @param [in] colorIndex Index to color table.
112 void PropTextColors::BrowseColorAndSave(CColorButton & colorButton, int colorIndex)
114 // Ignore user if colors are slaved to system
115 if (m_btnDefaultStandardColors.GetCheck() == BST_UNCHECKED)
118 COLORREF currentColor = m_pTempColors->GetColor(colorIndex);
119 CColorDialog dialog(currentColor);
120 CustomColors::Load(m_cCustColors);
121 dialog.m_cc.lpCustColors = m_cCustColors;
123 if (dialog.DoModal() == IDOK)
125 currentColor = dialog.GetColor();
126 colorButton.SetColor(currentColor);
127 m_pTempColors->SetColor(colorIndex, currentColor);
129 CustomColors::Save(m_cCustColors);
133 * @brief User wants to change whitespace color
135 void PropTextColors::OnWhitespaceBackgroundColor()
137 BrowseColorAndSave(m_btnWhitespaceBackground, COLORINDEX_WHITESPACE);
141 * @brief User wants to change regular background color
143 void PropTextColors::OnRegularBackgroundColor()
145 BrowseColorAndSave(m_btnRegularBackground, COLORINDEX_BKGND);
149 * @brief User wants to change regular text color
151 void PropTextColors::OnRegularTextColor()
153 BrowseColorAndSave(m_btnRegularText, COLORINDEX_NORMALTEXT);
157 * @brief User wants to change regular selection background color
159 void PropTextColors::OnSelectionBackgroundColor()
161 BrowseColorAndSave(m_btnSelectionBackground, COLORINDEX_SELBKGND);
165 * @brief User wants to change regular selection text color
167 void PropTextColors::OnSelectionTextColor()
169 BrowseColorAndSave(m_btnSelectionText, COLORINDEX_SELTEXT);
173 * @brief Load all colors, Save all colors, or set all colors to default
174 * @param [in] op Operation to do, one of
175 * - SET_DEFAULTS : Sets colors to defaults
176 * - LOAD_COLORS : Loads colors from registry
177 * (No save operation because BrowseColorAndSave saves immediately when user chooses)
179 void PropTextColors::SerializeColorsToFromScreen(OPERATION op)
181 if (op == SET_DEFAULTS)
182 m_pTempColors->SetDefaults();
184 SerializeColorToFromScreen(op, m_btnWhitespaceBackground, COLORINDEX_WHITESPACE);
186 SerializeColorToFromScreen(op, m_btnRegularBackground, COLORINDEX_BKGND);
187 SerializeColorToFromScreen(op, m_btnRegularText, COLORINDEX_NORMALTEXT);
189 SerializeColorToFromScreen(op, m_btnSelectionBackground, COLORINDEX_SELBKGND);
190 SerializeColorToFromScreen(op, m_btnSelectionText, COLORINDEX_SELTEXT);
194 * @brief Load color to button, Save color from button, or set button color to default
195 * @param [in] op Operation to do, one of
196 * - SET_DEFAULTS : Sets colors to defaults
197 * - LOAD_COLORS : Loads colors from registry
198 * (No save operation because BrowseColorAndSave saves immediately when user chooses)
200 void PropTextColors::SerializeColorToFromScreen(OPERATION op, CColorButton & btn, int colorIndex)
207 COLORREF color = m_pTempColors->GetColor(colorIndex);
214 COLORREF color = m_pTempColors->GetColor(colorIndex);
215 // Set colors for buttons, do NOT invalidate
216 btn.SetColor(color, FALSE);
223 * @brief Set colors to track standard (theme) colors
225 void PropTextColors::OnDefaultsStandardColors()
227 // Reset all text colors to default every time user checks defaults button
228 SerializeColorsToFromScreen(SET_DEFAULTS);
230 CButton * btn = (CButton *)GetDlgItem(IDC_DEFAULT_STANDARD_COLORS);
231 if (btn->GetCheck() == BST_UNCHECKED)
233 EnableColorButtons(FALSE);
237 EnableColorButtons(TRUE);
242 * @brief Enable / disable color controls on dialog.
243 * @param [in] bEnable If TRUE color controls are enabled.
245 void PropTextColors::EnableColorButtons(BOOL bEnable)
247 CStatic * stc = (CStatic *) GetDlgItem(IDC_CUSTOM_COLORS_GROUP);
248 stc->EnableWindow(bEnable);
249 stc = (CStatic *) GetDlgItem(IDC_WHITESPACE_COLOR_LABEL);
250 stc->EnableWindow(bEnable);
251 stc = (CStatic *) GetDlgItem(IDC_TEXT_COLOR_LABEL);
252 stc->EnableWindow(bEnable);
253 stc = (CStatic *) GetDlgItem(IDC_SELECTION_COLOR_LABEL);
254 stc->EnableWindow(bEnable);
255 stc = (CStatic *) GetDlgItem(IDC_BACKGROUND_COLUMN_LABEL);
256 stc->EnableWindow(bEnable);
257 stc = (CStatic *) GetDlgItem(IDC_TEXT_COLUMN_LABEL);
258 stc->EnableWindow(bEnable);