2 * @file PropMarkerColors.cpp
4 * @brief Implementation of PropMarkerColors propertysheet
8 #include "PropMarkerColors.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 PropMarkerColors::PropMarkerColors(COptionsMgr *optionsMgr, SyntaxColors *pColors)
23 : OptionsPanel(optionsMgr, PropMarkerColors::IDD)
24 , m_pTempColors(pColors)
29 void PropMarkerColors::DoDataExchange(CDataExchange* pDX)
31 CDialog::DoDataExchange(pDX);
32 //{{AFX_DATA_MAP(PropMarkerColors)
33 DDX_Control(pDX, IDC_MARKER0_BKGD_COLOR, m_btnMarkerColors[0]);
34 DDX_Control(pDX, IDC_MARKER1_BKGD_COLOR, m_btnMarkerColors[1]);
35 DDX_Control(pDX, IDC_MARKER2_BKGD_COLOR, m_btnMarkerColors[2]);
36 DDX_Control(pDX, IDC_MARKER3_BKGD_COLOR, m_btnMarkerColors[3]);
41 BEGIN_MESSAGE_MAP(PropMarkerColors, OptionsPanel)
42 //{{AFX_MSG_MAP(PropMarkerColors)
43 ON_COMMAND_RANGE(IDC_MARKER0_BKGD_COLOR, IDC_MARKER3_BKGD_COLOR, OnMarkerColors)
48 * @brief Reads options values from storage to UI.
49 * (Property sheet calls this before displaying all property pages)
51 void PropMarkerColors::ReadOptions()
53 SerializeColorsToFromScreen(LOAD_COLORS);
57 * @brief Writes options values from UI to storage.
58 * (Property sheet calls this after displaying all property pages)
60 void PropMarkerColors::WriteOptions()
62 // User can only change colors via BrowseColorAndSave,
63 // which writes to m_pTempColors
64 // so user's latest choices are in m_pTempColors
65 // (we don't have to read them from screen)
67 // Also, CPropSyntaxColors writes m_pTempColors out, so we don't have to
68 // We share m_pTempColors with CPropSyntaxColors
72 * @brief Let user browse common color dialog, and select a color
73 * @param [in] colorButton Button for which to change color.
74 * @param [in] colorIndex Index to color table.
76 void PropMarkerColors::BrowseColorAndSave(CColorButton & colorButton, int colorIndex)
78 COLORREF currentColor = m_pTempColors->GetColor(colorIndex);
79 CColorDialog dialog(currentColor);
80 Options::CustomColors::Load(GetOptionsMgr(), m_cCustColors.data());
81 dialog.m_cc.lpCustColors = m_cCustColors.data();
83 if (dialog.DoModal() == IDOK)
85 currentColor = dialog.GetColor();
86 colorButton.SetColor(currentColor);
87 m_pTempColors->SetColor(colorIndex, currentColor);
89 Options::CustomColors::Save(GetOptionsMgr(), m_cCustColors.data());
93 * @brief User wants to change whitespace color
95 void PropMarkerColors::OnMarkerColors(UINT nID)
97 BrowseColorAndSave(m_btnMarkerColors[nID - IDC_MARKER0_BKGD_COLOR], COLORINDEX_MARKERBKGND0 + nID - IDC_MARKER0_BKGD_COLOR);
101 * @brief Load all colors, Save all colors, or set all colors to default
102 * @param [in] op Operation to do, one of
103 * - SET_DEFAULTS : Sets colors to defaults
104 * - LOAD_COLORS : Loads colors from registry
105 * (No save operation because BrowseColorAndSave saves immediately when user chooses)
107 void PropMarkerColors::SerializeColorsToFromScreen(OPERATION op)
109 if (op == SET_DEFAULTS)
110 m_pTempColors->SetDefaults();
112 for (int i = 0; i < 4; ++i)
113 SerializeColorToFromScreen(op, m_btnMarkerColors[i], COLORINDEX_MARKERBKGND0 + i);
117 * @brief Load color to button, Save color from button, or set button color to default
118 * @param [in] op Operation to do, one of
119 * - SET_DEFAULTS : Sets colors to defaults
120 * - LOAD_COLORS : Loads colors from registry
121 * (No save operation because BrowseColorAndSave saves immediately when user chooses)
123 void PropMarkerColors::SerializeColorToFromScreen(OPERATION op, CColorButton & btn, int colorIndex)
129 btn.SetColor(m_pTempColors->GetColor(colorIndex));