2 * @file PropSyntaxColors.cpp
4 * @brief Implementation of PropSyntaxColors propertysheet
8 #include "PropSyntaxColors.h"
9 #include "SyntaxColors.h"
10 #include "OptionsSyntaxColors.h"
11 #include "OptionsCustomColors.h"
12 #include "OptionsPanel.h"
18 static const unsigned ColorIndices[] = {
19 COLORINDEX_KEYWORD, COLORINDEX_FUNCNAME, COLORINDEX_COMMENT,
20 COLORINDEX_NUMBER, COLORINDEX_OPERATOR, COLORINDEX_STRING,
21 COLORINDEX_PREPROCESSOR, COLORINDEX_USER1, COLORINDEX_USER2
24 IMPLEMENT_DYNAMIC(PropSyntaxColors, CPropertyPage)
26 PropSyntaxColors::PropSyntaxColors(COptionsMgr *optionsMgr, SyntaxColors *pColors)
27 : OptionsPanel(optionsMgr, PropSyntaxColors::IDD)
29 m_pTempColors = pColors;
30 memset(m_cCustColors, 0, sizeof(m_cCustColors));
33 void PropSyntaxColors::DoDataExchange(CDataExchange* pDX)
35 CPropertyPage::DoDataExchange(pDX);
36 DDX_Control(pDX, IDC_SCOLOR_KEYWORDS, m_colorButtons[COLORINDEX_KEYWORD]);
37 DDX_Control(pDX, IDC_SCOLOR_FUNCTIONS, m_colorButtons[COLORINDEX_FUNCNAME]);
38 DDX_Control(pDX, IDC_SCOLOR_COMMENTS, m_colorButtons[COLORINDEX_COMMENT]);
39 DDX_Control(pDX, IDC_SCOLOR_NUMBERS, m_colorButtons[COLORINDEX_NUMBER]);
40 DDX_Control(pDX, IDC_SCOLOR_OPERATORS, m_colorButtons[COLORINDEX_OPERATOR]);
41 DDX_Control(pDX, IDC_SCOLOR_STRINGS, m_colorButtons[COLORINDEX_STRING]);
42 DDX_Control(pDX, IDC_SCOLOR_PREPROCESSOR, m_colorButtons[COLORINDEX_PREPROCESSOR]);
43 DDX_Control(pDX, IDC_SCOLOR_USER1, m_colorButtons[COLORINDEX_USER1]);
44 DDX_Control(pDX, IDC_SCOLOR_USER2, m_colorButtons[COLORINDEX_USER2]);
45 DDX_Check(pDX, IDC_SCOLOR_KEYWORDS_BOLD, m_nBolds[COLORINDEX_KEYWORD]);
46 DDX_Check(pDX, IDC_SCOLOR_FUNCTIONS_BOLD, m_nBolds[COLORINDEX_FUNCNAME]);
47 DDX_Check(pDX, IDC_SCOLOR_COMMENTS_BOLD, m_nBolds[COLORINDEX_COMMENT]);
48 DDX_Check(pDX, IDC_SCOLOR_NUMBERS_BOLD, m_nBolds[COLORINDEX_NUMBER]);
49 DDX_Check(pDX, IDC_SCOLOR_OPERATORS_BOLD, m_nBolds[COLORINDEX_OPERATOR]);
50 DDX_Check(pDX, IDC_SCOLOR_STRINGS_BOLD, m_nBolds[COLORINDEX_STRING]);
51 DDX_Check(pDX, IDC_SCOLOR_PREPROCESSOR_BOLD, m_nBolds[COLORINDEX_PREPROCESSOR]);
52 DDX_Check(pDX, IDC_SCOLOR_USER1_BOLD, m_nBolds[COLORINDEX_USER1]);
53 DDX_Check(pDX, IDC_SCOLOR_USER2_BOLD, m_nBolds[COLORINDEX_USER2]);
57 BEGIN_MESSAGE_MAP(PropSyntaxColors, CPropertyPage)
58 ON_BN_CLICKED(IDC_SCOLOR_KEYWORDS, OnBnClickedEcolor<COLORINDEX_KEYWORD>)
59 ON_BN_CLICKED(IDC_SCOLOR_FUNCTIONS, OnBnClickedEcolor<COLORINDEX_FUNCNAME>)
60 ON_BN_CLICKED(IDC_SCOLOR_COMMENTS, OnBnClickedEcolor<COLORINDEX_COMMENT>)
61 ON_BN_CLICKED(IDC_SCOLOR_NUMBERS, OnBnClickedEcolor<COLORINDEX_NUMBER>)
62 ON_BN_CLICKED(IDC_SCOLOR_OPERATORS, OnBnClickedEcolor<COLORINDEX_OPERATOR>)
63 ON_BN_CLICKED(IDC_SCOLOR_STRINGS, OnBnClickedEcolor<COLORINDEX_STRING>)
64 ON_BN_CLICKED(IDC_SCOLOR_PREPROCESSOR, OnBnClickedEcolor<COLORINDEX_PREPROCESSOR>)
65 ON_BN_CLICKED(IDC_SCOLOR_USER1, OnBnClickedEcolor<COLORINDEX_USER1>)
66 ON_BN_CLICKED(IDC_SCOLOR_USER2, OnBnClickedEcolor<COLORINDEX_USER2>)
67 ON_BN_CLICKED(IDC_SCOLORS_BDEFAULTS, OnBnClickedEcolorsBdefaults)
68 ON_BN_CLICKED(IDC_SCOLOR_KEYWORDS_BOLD, (OnBnClickedBoldButton<IDC_SCOLOR_KEYWORDS_BOLD, COLORINDEX_KEYWORD>))
69 ON_BN_CLICKED(IDC_SCOLOR_FUNCTIONS_BOLD, (OnBnClickedBoldButton<IDC_SCOLOR_FUNCTIONS_BOLD, COLORINDEX_FUNCNAME>))
70 ON_BN_CLICKED(IDC_SCOLOR_COMMENTS_BOLD, (OnBnClickedBoldButton<IDC_SCOLOR_COMMENTS_BOLD, COLORINDEX_COMMENT>))
71 ON_BN_CLICKED(IDC_SCOLOR_NUMBERS_BOLD, (OnBnClickedBoldButton<IDC_SCOLOR_NUMBERS_BOLD, COLORINDEX_NUMBER>))
72 ON_BN_CLICKED(IDC_SCOLOR_OPERATORS_BOLD, (OnBnClickedBoldButton<IDC_SCOLOR_OPERATORS_BOLD, COLORINDEX_OPERATOR>))
73 ON_BN_CLICKED(IDC_SCOLOR_STRINGS_BOLD, (OnBnClickedBoldButton<IDC_SCOLOR_STRINGS_BOLD, COLORINDEX_STRING>))
74 ON_BN_CLICKED(IDC_SCOLOR_PREPROCESSOR_BOLD, (OnBnClickedBoldButton<IDC_SCOLOR_PREPROCESSOR_BOLD, COLORINDEX_PREPROCESSOR>))
75 ON_BN_CLICKED(IDC_SCOLOR_USER1_BOLD, (OnBnClickedBoldButton<IDC_SCOLOR_USER1_BOLD, COLORINDEX_USER1>))
76 ON_BN_CLICKED(IDC_SCOLOR_USER2_BOLD, (OnBnClickedBoldButton<IDC_SCOLOR_USER2_BOLD, COLORINDEX_USER2>))
80 * @brief Reads options values from storage to UI.
81 * (Property sheet calls this before displaying all property pages)
83 void PropSyntaxColors::ReadOptions()
85 // Set colors for buttons
86 for (auto&& colorIndex : ColorIndices)
88 m_colorButtons[colorIndex].SetColor(m_pTempColors->GetColor(colorIndex));
89 m_nBolds[colorIndex] = GetCheckVal(colorIndex);
94 * @brief Writes options values from UI to storage.
95 * (Property sheet calls this after displaying all property pages)
97 void PropSyntaxColors::WriteOptions()
99 // User can only change colors via BrowseColorAndSave,
100 // which writes to m_pTempColors
101 // so user's latest choices are in m_pTempColors
102 // (we don't have to read them from screen)
103 Options::SyntaxColors::Save(GetOptionsMgr(), m_pTempColors);
107 * @brief Let user browse common color dialog, and select a color & save to registry
109 void PropSyntaxColors::BrowseColorAndSave(unsigned colorIndex)
111 COLORREF currentColor = m_pTempColors->GetColor(colorIndex);
112 CColorDialog dialog(currentColor);
113 Options::CustomColors::Load(GetOptionsMgr(), m_cCustColors);
114 dialog.m_cc.lpCustColors = m_cCustColors;
116 if (dialog.DoModal() == IDOK)
118 currentColor = dialog.GetColor();
119 m_colorButtons[colorIndex].SetColor(currentColor);
120 m_pTempColors->SetColor(colorIndex, currentColor);
122 Options::CustomColors::Save(GetOptionsMgr(), m_cCustColors);
125 template <unsigned colorIndex>
126 void PropSyntaxColors::OnBnClickedEcolor()
128 BrowseColorAndSave(colorIndex);
131 void PropSyntaxColors::OnBnClickedEcolorsBdefaults()
133 m_pTempColors->SetDefaults();
134 for (auto&& colorIndex : ColorIndices)
136 m_colorButtons[colorIndex].SetColor(m_pTempColors->GetColor(colorIndex));
137 m_nBolds[colorIndex] = GetCheckVal(colorIndex);
143 template <unsigned ctlId, unsigned colorIndex>
144 void PropSyntaxColors::OnBnClickedBoldButton()
146 m_pTempColors->SetBold(colorIndex, IsDlgButtonChecked(ctlId) == BST_CHECKED);
149 int PropSyntaxColors::GetCheckVal(UINT nColorIndex)
151 if (m_pTempColors->GetBold(nColorIndex))
154 return BST_UNCHECKED;