2 * @file PropSyntaxColors.cpp
4 * @brief Implementation of PropSyntaxColors propertysheet
6 // ID line follows -- this is updated by SVN
11 #include "SyntaxColors.h"
12 #include "SyntaxColorsUtil.h"
13 #include "PropSyntaxColors.h"
14 #include "CustomColors.h"
16 #include "OptionsPanel.h"
21 static char THIS_FILE[] = __FILE__;
24 IMPLEMENT_DYNAMIC(PropSyntaxColors, CPropertyPage)
26 PropSyntaxColors::PropSyntaxColors(COptionsMgr *optionsMgr, SyntaxColors *pColors)
27 : OptionsPanel(optionsMgr, PropSyntaxColors::IDD)
34 , m_nPreProcessorBold(0)
38 m_pTempColors = pColors;
40 // Set colors for buttons, do NOT invalidate
41 m_btnKeywordsText.SetColor(m_pTempColors->GetColor(COLORINDEX_KEYWORD), FALSE);
42 m_btnFunctionsText.SetColor(m_pTempColors->GetColor(COLORINDEX_FUNCNAME), FALSE);
43 m_btnCommentsText.SetColor(m_pTempColors->GetColor(COLORINDEX_COMMENT), FALSE);
44 m_btnNumbersText.SetColor(m_pTempColors->GetColor(COLORINDEX_NUMBER), FALSE);
45 m_btnOperatorsText.SetColor(m_pTempColors->GetColor(COLORINDEX_OPERATOR), FALSE);
46 m_btnStringsText.SetColor(m_pTempColors->GetColor(COLORINDEX_STRING), FALSE);
47 m_btnPreprocessorText.SetColor(m_pTempColors->GetColor(COLORINDEX_PREPROCESSOR), FALSE);
48 m_btnUser1Text.SetColor(m_pTempColors->GetColor(COLORINDEX_USER1), FALSE);
49 m_btnUser2Text.SetColor(m_pTempColors->GetColor(COLORINDEX_USER2), FALSE);
51 m_nKeywordsBold = GetCheckVal(COLORINDEX_KEYWORD);
52 m_nFunctionsBold = GetCheckVal(COLORINDEX_FUNCNAME);
53 m_nCommentsBold = GetCheckVal(COLORINDEX_COMMENT);
54 m_nNumbersBold = GetCheckVal(COLORINDEX_NUMBER);
55 m_nOperatorsBold = GetCheckVal(COLORINDEX_OPERATOR);
56 m_nStringsBold = GetCheckVal(COLORINDEX_STRING);
57 m_nPreProcessorBold = GetCheckVal(COLORINDEX_PREPROCESSOR);
58 m_nUser1Bold = GetCheckVal(COLORINDEX_USER1);
59 m_nUser2Bold = GetCheckVal(COLORINDEX_USER2);
62 void PropSyntaxColors::DoDataExchange(CDataExchange* pDX)
64 CPropertyPage::DoDataExchange(pDX);
65 DDX_Control(pDX, IDC_SCOLOR_KEYWORDS, m_btnKeywordsText);
66 DDX_Control(pDX, IDC_SCOLOR_FUNCTIONS, m_btnFunctionsText);
67 DDX_Control(pDX, IDC_SCOLOR_COMMENTS, m_btnCommentsText);
68 DDX_Control(pDX, IDC_SCOLOR_NUMBERS, m_btnNumbersText);
69 DDX_Control(pDX, IDC_SCOLOR_OPERATORS, m_btnOperatorsText);
70 DDX_Control(pDX, IDC_SCOLOR_STRINGS, m_btnStringsText);
71 DDX_Control(pDX, IDC_SCOLOR_PREPROCESSOR, m_btnPreprocessorText);
72 DDX_Control(pDX, IDC_SCOLOR_USER1, m_btnUser1Text);
73 DDX_Control(pDX, IDC_SCOLOR_USER2, m_btnUser2Text);
74 DDX_Control(pDX, IDC_SCOLOR_KEYWORDS_BOLD, m_btnKeywordsBold);
75 DDX_Control(pDX, IDC_SCOLOR_FUNCTIONS_BOLD, m_btnFunctionsBold);
76 DDX_Control(pDX, IDC_SCOLOR_COMMENTS_BOLD, m_btnCommentsBold);
77 DDX_Control(pDX, IDC_SCOLOR_NUMBERS_BOLD, m_btnNumbersBold);
78 DDX_Control(pDX, IDC_SCOLOR_OPERATORS_BOLD, m_btnOperatorsBold);
79 DDX_Control(pDX, IDC_SCOLOR_STRINGS_BOLD, m_btnStringsBold);
80 DDX_Control(pDX, IDC_SCOLOR_PREPROCESSOR_BOLD, m_btnPreProcessorBold);
81 DDX_Control(pDX, IDC_SCOLOR_USER1_BOLD, m_btnUser1Bold);
82 DDX_Control(pDX, IDC_SCOLOR_USER2_BOLD, m_btnUser2Bold);
83 DDX_Check(pDX, IDC_SCOLOR_KEYWORDS_BOLD, m_nKeywordsBold);
84 DDX_Check(pDX, IDC_SCOLOR_FUNCTIONS_BOLD, m_nFunctionsBold);
85 DDX_Check(pDX, IDC_SCOLOR_COMMENTS_BOLD, m_nCommentsBold);
86 DDX_Check(pDX, IDC_SCOLOR_NUMBERS_BOLD, m_nNumbersBold);
87 DDX_Check(pDX, IDC_SCOLOR_OPERATORS_BOLD, m_nOperatorsBold);
88 DDX_Check(pDX, IDC_SCOLOR_STRINGS_BOLD, m_nStringsBold);
89 DDX_Check(pDX, IDC_SCOLOR_PREPROCESSOR_BOLD, m_nPreProcessorBold);
90 DDX_Check(pDX, IDC_SCOLOR_USER1_BOLD, m_nUser1Bold);
91 DDX_Check(pDX, IDC_SCOLOR_USER2_BOLD, m_nUser2Bold);
95 BEGIN_MESSAGE_MAP(PropSyntaxColors, CPropertyPage)
96 ON_BN_CLICKED(IDC_SCOLOR_KEYWORDS, OnBnClickedEcolorKeywords)
97 ON_BN_CLICKED(IDC_SCOLOR_FUNCTIONS, OnBnClickedEcolorFunctions)
98 ON_BN_CLICKED(IDC_SCOLOR_COMMENTS, OnBnClickedEcolorComments)
99 ON_BN_CLICKED(IDC_SCOLOR_NUMBERS, OnBnClickedEcolorNumbers)
100 ON_BN_CLICKED(IDC_SCOLOR_OPERATORS, OnBnClickedEcolorOperators)
101 ON_BN_CLICKED(IDC_SCOLOR_STRINGS, OnBnClickedEcolorStrings)
102 ON_BN_CLICKED(IDC_SCOLOR_PREPROCESSOR, OnBnClickedEcolorPreprocessor)
103 ON_BN_CLICKED(IDC_SCOLOR_USER1, OnBnClickedEcolorUser1)
104 ON_BN_CLICKED(IDC_SCOLOR_USER2, OnBnClickedEcolorUser2)
105 ON_BN_CLICKED(IDC_SCOLORS_BDEFAULTS, OnBnClickedEcolorsBdefaults)
106 ON_BN_CLICKED(IDC_SCOLOR_KEYWORDS_BOLD, OnBnClickedEcolorKeywordsBold)
107 ON_BN_CLICKED(IDC_SCOLOR_FUNCTIONS_BOLD, OnBnClickedEcolorFunctionsBold)
108 ON_BN_CLICKED(IDC_SCOLOR_COMMENTS_BOLD, OnBnClickedEcolorCommentsBold)
109 ON_BN_CLICKED(IDC_SCOLOR_NUMBERS_BOLD, OnBnClickedEcolorNumbersBold)
110 ON_BN_CLICKED(IDC_SCOLOR_OPERATORS_BOLD, OnBnClickedEcolorOperatorsBold)
111 ON_BN_CLICKED(IDC_SCOLOR_STRINGS_BOLD, OnBnClickedEcolorStringsBold)
112 ON_BN_CLICKED(IDC_SCOLOR_PREPROCESSOR_BOLD, OnBnClickedEcolorPreprocessorBold)
113 ON_BN_CLICKED(IDC_SCOLOR_USER1_BOLD, OnBnClickedEcolorUser1Bold)
114 ON_BN_CLICKED(IDC_SCOLOR_USER2_BOLD, OnBnClickedEcolorUser2Bold)
118 * @brief Called before propertysheet is drawn.
120 BOOL PropSyntaxColors::OnInitDialog()
122 theApp.TranslateDialog(m_hWnd);
123 return CPropertyPage::OnInitDialog();
127 * @brief Reads options values from storage to UI.
128 * (Property sheet calls this before displaying all property pages)
130 void PropSyntaxColors::ReadOptions()
135 * @brief Writes options values from UI to storage.
136 * (Property sheet calls this after displaying all property pages)
138 void PropSyntaxColors::WriteOptions()
140 // User can only change colors via BrowseColorAndSave,
141 // which writes to m_pTempColors
142 // so user's latest choices are in m_pTempColors
143 // (we don't have to read them from screen)
144 SyntaxColors_SaveToRegistry(m_pTempColors);
148 * @brief Let user browse common color dialog, and select a color & save to registry
150 void PropSyntaxColors::BrowseColorAndSave(CColorButton & colorButton, int colorIndex)
152 COLORREF currentColor = m_pTempColors->GetColor(colorIndex);
153 CColorDialog dialog(currentColor);
154 CustomColors::Load(m_cCustColors);
155 dialog.m_cc.lpCustColors = m_cCustColors;
157 if (dialog.DoModal() == IDOK)
159 currentColor = dialog.GetColor();
160 colorButton.SetColor(currentColor);
161 m_pTempColors->SetColor(colorIndex, currentColor);
163 CustomColors::Save(m_cCustColors);
166 void PropSyntaxColors::OnBnClickedEcolorKeywords()
168 BrowseColorAndSave(m_btnKeywordsText, COLORINDEX_KEYWORD);
171 void PropSyntaxColors::OnBnClickedEcolorFunctions()
173 BrowseColorAndSave(m_btnFunctionsText, COLORINDEX_FUNCNAME);
176 void PropSyntaxColors::OnBnClickedEcolorComments()
178 BrowseColorAndSave(m_btnCommentsText, COLORINDEX_COMMENT);
181 void PropSyntaxColors::OnBnClickedEcolorNumbers()
183 BrowseColorAndSave(m_btnNumbersText, COLORINDEX_NUMBER);
186 void PropSyntaxColors::OnBnClickedEcolorOperators()
188 BrowseColorAndSave(m_btnOperatorsText, COLORINDEX_OPERATOR);
191 void PropSyntaxColors::OnBnClickedEcolorStrings()
193 BrowseColorAndSave(m_btnStringsText, COLORINDEX_STRING);
196 void PropSyntaxColors::OnBnClickedEcolorPreprocessor()
198 BrowseColorAndSave(m_btnPreprocessorText, COLORINDEX_PREPROCESSOR);
201 void PropSyntaxColors::OnBnClickedEcolorUser1()
203 BrowseColorAndSave(m_btnUser1Text, COLORINDEX_USER1);
206 void PropSyntaxColors::OnBnClickedEcolorUser2()
208 BrowseColorAndSave(m_btnUser2Text, COLORINDEX_USER2);
211 void PropSyntaxColors::OnBnClickedEcolorsBdefaults()
213 m_pTempColors->SetDefaults();
214 m_btnKeywordsText.SetColor(m_pTempColors->GetColor(COLORINDEX_KEYWORD));
215 m_btnFunctionsText.SetColor(m_pTempColors->GetColor(COLORINDEX_FUNCNAME));
216 m_btnCommentsText.SetColor(m_pTempColors->GetColor(COLORINDEX_COMMENT));
217 m_btnNumbersText.SetColor(m_pTempColors->GetColor(COLORINDEX_NUMBER));
218 m_btnOperatorsText.SetColor(m_pTempColors->GetColor(COLORINDEX_OPERATOR));
219 m_btnStringsText.SetColor(m_pTempColors->GetColor(COLORINDEX_STRING));
220 m_btnPreprocessorText.SetColor(m_pTempColors->GetColor(COLORINDEX_PREPROCESSOR));
221 m_btnUser1Text.SetColor(m_pTempColors->GetColor(COLORINDEX_USER1));
222 m_btnUser2Text.SetColor(m_pTempColors->GetColor(COLORINDEX_USER2));
224 m_nKeywordsBold = GetCheckVal(COLORINDEX_KEYWORD);
225 m_nFunctionsBold = GetCheckVal(COLORINDEX_FUNCNAME);
226 m_nCommentsBold = GetCheckVal(COLORINDEX_COMMENT);
227 m_nNumbersBold = GetCheckVal(COLORINDEX_NUMBER);
228 m_nOperatorsBold = GetCheckVal(COLORINDEX_OPERATOR);
229 m_nStringsBold = GetCheckVal(COLORINDEX_STRING);
230 m_nPreProcessorBold = GetCheckVal(COLORINDEX_PREPROCESSOR);
231 m_nUser1Bold = GetCheckVal(COLORINDEX_USER1);
232 m_nUser2Bold = GetCheckVal(COLORINDEX_USER2);
237 void PropSyntaxColors::OnBnClickedEcolorKeywordsBold()
239 UpdateBoldStatus(m_btnKeywordsBold, COLORINDEX_KEYWORD);
242 void PropSyntaxColors::OnBnClickedEcolorFunctionsBold()
244 UpdateBoldStatus(m_btnFunctionsBold, COLORINDEX_FUNCNAME);
247 void PropSyntaxColors::OnBnClickedEcolorCommentsBold()
249 UpdateBoldStatus(m_btnCommentsBold, COLORINDEX_COMMENT);
252 void PropSyntaxColors::OnBnClickedEcolorNumbersBold()
254 UpdateBoldStatus(m_btnNumbersBold, COLORINDEX_NUMBER);
257 void PropSyntaxColors::OnBnClickedEcolorOperatorsBold()
259 UpdateBoldStatus(m_btnOperatorsBold, COLORINDEX_OPERATOR);
262 void PropSyntaxColors::OnBnClickedEcolorStringsBold()
264 UpdateBoldStatus(m_btnStringsBold, COLORINDEX_STRING);
267 void PropSyntaxColors::OnBnClickedEcolorPreprocessorBold()
269 UpdateBoldStatus(m_btnPreProcessorBold, COLORINDEX_PREPROCESSOR);
272 void PropSyntaxColors::OnBnClickedEcolorUser1Bold()
274 UpdateBoldStatus(m_btnUser1Bold, COLORINDEX_USER1);
277 void PropSyntaxColors::OnBnClickedEcolorUser2Bold()
279 UpdateBoldStatus(m_btnUser2Bold, COLORINDEX_USER2);
282 int PropSyntaxColors::GetCheckVal(UINT nColorIndex)
284 if (m_pTempColors->GetBold(nColorIndex))
287 return BST_UNCHECKED;
290 void PropSyntaxColors::UpdateBoldStatus(CButton &btn, UINT colorIndex)
292 int state = btn.GetCheck();
293 if (state == BST_CHECKED)
294 m_pTempColors->SetBold(colorIndex, TRUE);
296 m_pTempColors->SetBold(colorIndex, FALSE);