OSDN Git Service

Update TranslationsStatus.*
[winmerge-jp/winmerge-jp.git] / Src / PropMarkerColors.cpp
1 /** 
2  * @file  PropMarkerColors.cpp
3  *
4  * @brief Implementation of PropMarkerColors propertysheet
5  */
6
7 #include "stdafx.h"
8 #include "PropMarkerColors.h"
9 #include "SyntaxColors.h"
10 #include "OptionsCustomColors.h"
11 #include "OptionsDef.h"
12 #include "OptionsMgr.h"
13 #include "OptionsPanel.h"
14
15 #ifdef _DEBUG
16 #define new DEBUG_NEW
17 #endif
18
19 /** 
20  * @brief Default constructor.
21  */
22 PropMarkerColors::PropMarkerColors(COptionsMgr *optionsMgr, SyntaxColors *pColors)
23  : OptionsPanel(optionsMgr, PropMarkerColors::IDD)
24 , m_pTempColors(pColors)
25 , m_cCustColors()
26 {
27 }
28
29 void PropMarkerColors::DoDataExchange(CDataExchange* pDX)
30 {
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]);
37         //}}AFX_DATA_MAP
38 }
39
40
41 BEGIN_MESSAGE_MAP(PropMarkerColors, OptionsPanel)
42         //{{AFX_MSG_MAP(PropMarkerColors)
43         ON_COMMAND_RANGE(IDC_MARKER0_BKGD_COLOR, IDC_MARKER3_BKGD_COLOR, OnMarkerColors)
44         //}}AFX_MSG_MAP
45 END_MESSAGE_MAP()
46
47 /** 
48  * @brief Reads options values from storage to UI.
49  * (Property sheet calls this before displaying all property pages)
50  */
51 void PropMarkerColors::ReadOptions()
52 {
53         SerializeColorsToFromScreen(LOAD_COLORS);
54 }
55
56 /** 
57  * @brief Writes options values from UI to storage.
58  * (Property sheet calls this after displaying all property pages)
59  */
60 void PropMarkerColors::WriteOptions()
61 {
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)
66
67         // Also, CPropSyntaxColors writes m_pTempColors out, so we don't have to
68         // We share m_pTempColors with CPropSyntaxColors
69 }
70
71 /** 
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.
75  */
76 void PropMarkerColors::BrowseColorAndSave(CColorButton & colorButton, int colorIndex)
77 {
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();
82         
83         if (dialog.DoModal() == IDOK)
84         {
85                 currentColor = dialog.GetColor();
86                 colorButton.SetColor(currentColor);
87                 m_pTempColors->SetColor(colorIndex, currentColor);
88         }
89         Options::CustomColors::Save(GetOptionsMgr(), m_cCustColors.data());
90 }
91
92 /** 
93  * @brief User wants to change whitespace color
94  */
95 void PropMarkerColors::OnMarkerColors(UINT nID) 
96 {
97         BrowseColorAndSave(m_btnMarkerColors[nID - IDC_MARKER0_BKGD_COLOR], COLORINDEX_MARKERBKGND0 + nID - IDC_MARKER0_BKGD_COLOR);
98 }
99
100 /**
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)
106  */
107 void PropMarkerColors::SerializeColorsToFromScreen(OPERATION op)
108 {
109         if (op == SET_DEFAULTS)
110                 m_pTempColors->SetDefaults();
111
112         for (int i = 0; i < 4; ++i)
113                 SerializeColorToFromScreen(op, m_btnMarkerColors[i], COLORINDEX_MARKERBKGND0 + i);
114 }
115
116 /**
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)
122  */
123 void PropMarkerColors::SerializeColorToFromScreen(OPERATION op, CColorButton & btn, int colorIndex)
124 {
125         switch (op)
126         {
127         case SET_DEFAULTS:
128         case LOAD_COLORS:
129                 btn.SetColor(m_pTempColors->GetColor(colorIndex));
130                 break;
131         }
132 }