-
Notifications
You must be signed in to change notification settings - Fork 814
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PropMarkerColors.*: Forgot to add the files. github#35
- Loading branch information
Showing
2 changed files
with
230 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,163 @@ | ||
/** | ||
* @file PropMarkerColors.cpp | ||
* | ||
* @brief Implementation of PropMarkerColors propertysheet | ||
*/ | ||
|
||
#include "stdafx.h" | ||
#include "PropMarkerColors.h" | ||
#include "SyntaxColors.h" | ||
#include "OptionsCustomColors.h" | ||
#include "OptionsDef.h" | ||
#include "OptionsMgr.h" | ||
#include "OptionsPanel.h" | ||
|
||
#ifdef _DEBUG | ||
#define new DEBUG_NEW | ||
#endif | ||
|
||
/** | ||
* @brief Default constructor. | ||
*/ | ||
PropMarkerColors::PropMarkerColors(COptionsMgr *optionsMgr, SyntaxColors *pColors) | ||
: OptionsPanel(optionsMgr, PropMarkerColors::IDD) | ||
, m_bMarkerEnabled(true) | ||
, m_pTempColors(pColors) | ||
, m_cCustColors() | ||
{ | ||
} | ||
|
||
void PropMarkerColors::DoDataExchange(CDataExchange* pDX) | ||
{ | ||
CDialog::DoDataExchange(pDX); | ||
//{{AFX_DATA_MAP(PropMarkerColors) | ||
DDX_Check(pDX, IDC_MARKER_ENABLED, m_bMarkerEnabled); | ||
DDX_Control(pDX, IDC_MARKER0_BKGD_COLOR, m_btnMarkerColors[0]); | ||
DDX_Control(pDX, IDC_MARKER1_BKGD_COLOR, m_btnMarkerColors[1]); | ||
DDX_Control(pDX, IDC_MARKER2_BKGD_COLOR, m_btnMarkerColors[2]); | ||
DDX_Control(pDX, IDC_MARKER3_BKGD_COLOR, m_btnMarkerColors[3]); | ||
//}}AFX_DATA_MAP | ||
EnableColorButtons(m_bMarkerEnabled); | ||
} | ||
|
||
|
||
BEGIN_MESSAGE_MAP(PropMarkerColors, CDialog) | ||
//{{AFX_MSG_MAP(PropMarkerColors) | ||
ON_BN_CLICKED(IDC_MARKER_ENABLED, OnEnableMarker) | ||
ON_COMMAND_RANGE(IDC_MARKER0_BKGD_COLOR, IDC_MARKER3_BKGD_COLOR, OnMarkerColors) | ||
//}}AFX_MSG_MAP | ||
END_MESSAGE_MAP() | ||
|
||
/** | ||
* @brief Reads options values from storage to UI. | ||
* (Property sheet calls this before displaying all property pages) | ||
*/ | ||
void PropMarkerColors::ReadOptions() | ||
{ | ||
m_bMarkerEnabled = !!GetOptionsMgr()->GetBool(OPT_MARKER_ENABLED); | ||
SerializeColorsToFromScreen(LOAD_COLORS); | ||
} | ||
|
||
/** | ||
* @brief Writes options values from UI to storage. | ||
* (Property sheet calls this after displaying all property pages) | ||
*/ | ||
void PropMarkerColors::WriteOptions() | ||
{ | ||
GetOptionsMgr()->SaveOption(OPT_MARKER_ENABLED, m_bMarkerEnabled); | ||
// User can only change colors via BrowseColorAndSave, | ||
// which writes to m_pTempColors | ||
// so user's latest choices are in m_pTempColors | ||
// (we don't have to read them from screen) | ||
|
||
// Also, CPropSyntaxColors writes m_pTempColors out, so we don't have to | ||
// We share m_pTempColors with CPropSyntaxColors | ||
} | ||
|
||
/** | ||
* @brief Let user browse common color dialog, and select a color | ||
* @param [in] colorButton Button for which to change color. | ||
* @param [in] colorIndex Index to color table. | ||
*/ | ||
void PropMarkerColors::BrowseColorAndSave(CColorButton & colorButton, int colorIndex) | ||
{ | ||
COLORREF currentColor = m_pTempColors->GetColor(colorIndex); | ||
CColorDialog dialog(currentColor); | ||
Options::CustomColors::Load(GetOptionsMgr(), m_cCustColors.data()); | ||
dialog.m_cc.lpCustColors = m_cCustColors.data(); | ||
|
||
if (dialog.DoModal() == IDOK) | ||
{ | ||
currentColor = dialog.GetColor(); | ||
colorButton.SetColor(currentColor); | ||
m_pTempColors->SetColor(colorIndex, currentColor); | ||
} | ||
Options::CustomColors::Save(GetOptionsMgr(), m_cCustColors.data()); | ||
} | ||
|
||
/** | ||
* @brief User wants to change whitespace color | ||
*/ | ||
void PropMarkerColors::OnMarkerColors(UINT nID) | ||
{ | ||
BrowseColorAndSave(m_btnMarkerColors[nID - IDC_MARKER0_BKGD_COLOR], COLORINDEX_MARKERBKGND1 + nID - IDC_MARKER0_BKGD_COLOR); | ||
} | ||
|
||
/** | ||
* @brief Load all colors, Save all colors, or set all colors to default | ||
* @param [in] op Operation to do, one of | ||
* - SET_DEFAULTS : Sets colors to defaults | ||
* - LOAD_COLORS : Loads colors from registry | ||
* (No save operation because BrowseColorAndSave saves immediately when user chooses) | ||
*/ | ||
void PropMarkerColors::SerializeColorsToFromScreen(OPERATION op) | ||
{ | ||
if (op == SET_DEFAULTS) | ||
m_pTempColors->SetDefaults(); | ||
|
||
for (int i = 0; i < 4; ++i) | ||
SerializeColorToFromScreen(op, m_btnMarkerColors[i], COLORINDEX_MARKERBKGND1 + i); | ||
} | ||
|
||
/** | ||
* @brief Load color to button, Save color from button, or set button color to default | ||
* @param [in] op Operation to do, one of | ||
* - SET_DEFAULTS : Sets colors to defaults | ||
* - LOAD_COLORS : Loads colors from registry | ||
* (No save operation because BrowseColorAndSave saves immediately when user chooses) | ||
*/ | ||
void PropMarkerColors::SerializeColorToFromScreen(OPERATION op, CColorButton & btn, int colorIndex) | ||
{ | ||
switch (op) | ||
{ | ||
case SET_DEFAULTS: | ||
case LOAD_COLORS: | ||
btn.SetColor(m_pTempColors->GetColor(colorIndex)); | ||
break; | ||
} | ||
} | ||
|
||
/** | ||
* @brief Set colors to track standard (theme) colors | ||
*/ | ||
void PropMarkerColors::OnEnableMarker() | ||
{ | ||
UpdateData(); | ||
} | ||
|
||
/** | ||
* @brief Enable / disable color controls on dialog. | ||
* @param [in] bEnable If TRUE color controls are enabled. | ||
*/ | ||
void PropMarkerColors::EnableColorButtons(bool bEnable) | ||
{ | ||
EnableDlgItem(IDC_MARKER_COLORS_GROUP, bEnable); | ||
EnableDlgItem(IDC_MARKER0_COLOR_LABEL, bEnable); | ||
EnableDlgItem(IDC_MARKER1_COLOR_LABEL, bEnable); | ||
EnableDlgItem(IDC_MARKER2_COLOR_LABEL, bEnable); | ||
EnableDlgItem(IDC_MARKER3_COLOR_LABEL, bEnable); | ||
EnableDlgItem(IDC_MARKER0_BKGD_COLOR, bEnable); | ||
EnableDlgItem(IDC_MARKER1_BKGD_COLOR, bEnable); | ||
EnableDlgItem(IDC_MARKER2_BKGD_COLOR, bEnable); | ||
EnableDlgItem(IDC_MARKER3_BKGD_COLOR, bEnable); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/** | ||
* @file PropMarkerColors.h | ||
* | ||
* @brief Declaration file for PropMarkerColors propertyheet | ||
* | ||
*/ | ||
#pragma once | ||
|
||
#include "ColorButton.h" | ||
#include "OptionsPanel.h" | ||
#include <array> | ||
|
||
class COptionsMgr; | ||
class SyntaxColors; | ||
|
||
/** @brief Property page for colors options; used in options property sheet */ | ||
class PropMarkerColors : public OptionsPanel | ||
{ | ||
|
||
// Construction | ||
public: | ||
|
||
PropMarkerColors(COptionsMgr *optionsMgr, SyntaxColors *pColors); | ||
|
||
// Implement IOptionsPanel | ||
virtual void ReadOptions(); | ||
virtual void WriteOptions(); | ||
|
||
// Dialog Data | ||
private: | ||
|
||
SyntaxColors *m_pTempColors; | ||
std::array<COLORREF, 16> m_cCustColors; | ||
|
||
//{{AFX_DATA(PropMarkerColors) | ||
enum { IDD = IDD_PROPPAGE_COLORS_MARKER }; | ||
CColorButton m_btnMarkerColors[4]; | ||
bool m_bMarkerEnabled; | ||
//}}AFX_DATA | ||
|
||
// Overrides | ||
// ClassWizard generated virtual function overrides | ||
//{{AFX_VIRTUAL(PropMarkerColors) | ||
protected: | ||
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support | ||
//}}AFX_VIRTUAL | ||
|
||
// Implementation | ||
protected: | ||
|
||
typedef enum { SET_DEFAULTS, READ_OPTIONS, LOAD_COLORS } OPERATION; | ||
|
||
void BrowseColorAndSave(CColorButton & colorButton, int colorIndex); | ||
void SerializeColorsToFromScreen(OPERATION op); | ||
void SerializeColorToFromScreen(OPERATION op, CColorButton & btn, int colorIndex); | ||
void EnableColorButtons(bool bEnable); | ||
|
||
// Generated message map functions | ||
//{{AFX_MSG(PropMarkerColors) | ||
afx_msg void OnMarkerColors(UINT nID); | ||
afx_msg void OnEnableMarker(); | ||
//}}AFX_MSG | ||
DECLARE_MESSAGE_MAP() | ||
}; | ||
|
||
//{{AFX_INSERT_LOCATION}} | ||
// Microsoft Visual C++ will insert additional declarations immediately before the previous line. |