OSDN Git Service

Use own colors settings for folder compare - Add GUI
[winmerge-jp/winmerge-jp.git] / Src / PropDirColors.cpp
1 /** 
2  * @file  PropDirColors.cpp
3  *
4  * @brief Implementation of PropDirColors propertysheet
5  */
6
7 #include "stdafx.h"
8 #include "PropDirColors.h"
9 #include "OptionsCustomColors.h"
10 #include "OptionsDef.h"
11 #include "OptionsMgr.h"
12 #include "OptionsPanel.h"
13
14 #ifdef _DEBUG
15 #define new DEBUG_NEW
16 #endif
17
18 /** 
19  * @brief Default constructor.
20  */
21 PropDirColors::PropDirColors(COptionsMgr *optionsMgr)
22  : OptionsPanel(optionsMgr, PropDirColors::IDD)
23  , m_cCustColors()
24 {
25 }
26
27 void PropDirColors::DoDataExchange(CDataExchange* pDX)
28 {
29         CDialog::DoDataExchange(pDX);
30         //{{AFX_DATA_MAP(PropDirColors)
31         DDX_Control(pDX, IDC_DIR_ITEM_DIFF_COLOR, m_cDirItemDiff);
32         DDX_Control(pDX, IDC_DIR_ITEM_DIFF_TEXT_COLOR, m_cDirItemDiffText);
33         DDX_Control(pDX, IDC_DIR_ITEM_NOTEXISTALL_COLOR, m_cDirItemNotExistAll);
34         DDX_Control(pDX, IDC_DIR_ITEM_NOTEXISTALL_TEXT_COLOR, m_cDirItemNotExistAllText);
35         DDX_Control(pDX, IDC_DIR_ITEM_FILTERED_COLOR, m_cDirItemFiltered);
36         DDX_Control(pDX, IDC_DIR_ITEM_FILTERED_TEXT_COLOR, m_cDirItemFilteredText);
37         //}}AFX_DATA_MAP
38 }
39
40
41 BEGIN_MESSAGE_MAP(PropDirColors, CDialog)
42         //{{AFX_MSG_MAP(PropDirColors)
43         ON_BN_CLICKED(IDC_DIR_ITEM_DIFF_COLOR, OnDirItemDiffColor)
44         ON_BN_CLICKED(IDC_DIR_ITEM_DIFF_TEXT_COLOR, OnDirItemDiffTextColor)
45         ON_BN_CLICKED(IDC_DIR_ITEM_NOTEXISTALL_COLOR, OnDirItemNotExistAllColor)
46         ON_BN_CLICKED(IDC_DIR_ITEM_NOTEXISTALL_TEXT_COLOR, OnDirItemNotExistAllTextColor)
47         ON_BN_CLICKED(IDC_DIR_ITEM_FILTERED_COLOR, OnDirItemFilteredColor)
48         ON_BN_CLICKED(IDC_DIR_ITEM_FILTERED_TEXT_COLOR, OnDirItemFilteredTextColor)
49         ON_BN_CLICKED(IDC_COLORDEFAULTS_BTN, OnDefaults)
50         //}}AFX_MSG_MAP
51 END_MESSAGE_MAP()
52
53 /** 
54  * @brief Reads options values from storage to UI.
55  * (Property sheet calls this before displaying all property pages)
56  */
57 void PropDirColors::ReadOptions()
58 {
59         SerializeColors(READ_OPTIONS);
60 }
61
62 /** 
63  * @brief Writes options values from UI to storage.
64  * (Property sheet calls this after displaying all property pages)
65  */
66 void PropDirColors::WriteOptions()
67 {
68         SerializeColors(WRITE_OPTIONS);
69 }
70
71 /** 
72  * @brief Let user browse common color dialog, and select a color
73  */
74 void PropDirColors::BrowseColor(CColorButton & colorButton)
75 {
76         CColorDialog dialog(colorButton.GetColor());
77         Options::CustomColors::Load(GetOptionsMgr(), m_cCustColors.data());
78         dialog.m_cc.lpCustColors = m_cCustColors.data();
79         
80         if (dialog.DoModal() == IDOK)
81                 colorButton.SetColor(dialog.GetColor());
82         Options::CustomColors::Save(GetOptionsMgr(), m_cCustColors.data());
83 }
84
85 /** 
86  * @brief User wants to change xxx color
87  */
88 void PropDirColors::OnDirItemDiffColor()
89 {
90         BrowseColor(m_cDirItemDiff);
91 }
92
93 /** 
94  * @brief User wants to change xxx color
95  */
96 void PropDirColors::OnDirItemDiffTextColor()
97 {
98         BrowseColor(m_cDirItemDiffText);
99 }
100
101 /** 
102  * @brief User wants to change xxx color
103  */
104 void PropDirColors::OnDirItemNotExistAllColor()
105 {
106         BrowseColor(m_cDirItemNotExistAll);
107 }
108
109 /** 
110  * @brief User wants to change xxx color
111  */
112 void PropDirColors::OnDirItemNotExistAllTextColor()
113 {
114         BrowseColor(m_cDirItemNotExistAllText);
115 }
116
117 /** 
118  * @brief User wants to change xxx color
119  */
120 void PropDirColors::OnDirItemFilteredColor()
121 {
122         BrowseColor(m_cDirItemFiltered);
123 }
124
125 /**
126  * @brief User wants to change xxx color
127  */
128 void PropDirColors::OnDirItemFilteredTextColor()
129 {
130         BrowseColor(m_cDirItemFilteredText);
131 }
132
133 void PropDirColors::SerializeColors(OPERATION op)
134 {
135         SerializeColor(op, m_cDirItemDiff, OPT_DIRCLR_ITEM_DIFF);
136         SerializeColor(op, m_cDirItemDiffText, OPT_DIRCLR_ITEM_DIFF_TEXT);
137
138         SerializeColor(op, m_cDirItemNotExistAll, OPT_DIRCLR_ITEM_NOT_EXIST_ALL);
139         SerializeColor(op, m_cDirItemNotExistAllText, OPT_DIRCLR_ITEM_NOT_EXIST_ALL_TEXT);
140
141         SerializeColor(op, m_cDirItemFiltered, OPT_DIRCLR_ITEM_FILTERED);
142         SerializeColor(op, m_cDirItemFilteredText, OPT_DIRCLR_ITEM_FILTERED_TEXT);
143 }
144
145 void PropDirColors::SerializeColor(OPERATION op, CColorButton & btn, const String& optionName)
146 {
147         switch (op)
148         {
149         case SET_DEFAULTS:
150                 btn.SetColor(GetOptionsMgr()->GetDefault<unsigned>(optionName));
151                 return;
152
153         case WRITE_OPTIONS:
154                 GetOptionsMgr()->SaveOption(optionName, (unsigned)btn.GetColor());
155                 return;
156
157         case READ_OPTIONS:
158                 // Set colors for buttons, do NOT invalidate
159                 btn.SetColor(GetOptionsMgr()->GetInt(optionName), false);
160                 return;
161         }
162 }
163
164 /** 
165  * @brief Resets colors to defaults
166  */
167 void PropDirColors::OnDefaults()
168 {
169         SerializeColors(SET_DEFAULTS);
170 }