OSDN Git Service

fix some build error
[tortoisegit/TortoiseGitJp.git] / src / TortoiseMerge / SetColorPage.cpp
1 // TortoiseMerge - a Diff/Patch program\r
2 \r
3 // Copyright (C) 2006-2008 - TortoiseSVN\r
4 \r
5 // This program is free software; you can redistribute it and/or\r
6 // modify it under the terms of the GNU General Public License\r
7 // as published by the Free Software Foundation; either version 2\r
8 // of the License, or (at your option) any later version.\r
9 \r
10 // This program is distributed in the hope that it will be useful,\r
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of\r
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
13 // GNU General Public License for more details.\r
14 \r
15 // You should have received a copy of the GNU General Public License\r
16 // along with this program; if not, write to the Free Software Foundation,\r
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\r
18 //\r
19 #include "stdafx.h"\r
20 #include "TortoiseMerge.h"\r
21 #include "SetColorPage.h"\r
22 #include "DiffColors.h"\r
23 \r
24 \r
25 // CSetColorPage dialog\r
26 #define INLINEADDED_COLOR                       RGB(255, 255, 150)\r
27 #define INLINEREMOVED_COLOR                     RGB(200, 100, 100)\r
28 #define MODIFIED_COLOR                          RGB(220, 220, 255)\r
29 \r
30 IMPLEMENT_DYNAMIC(CSetColorPage, CPropertyPage)\r
31 CSetColorPage::CSetColorPage()\r
32         : CPropertyPage(CSetColorPage::IDD)\r
33         , m_bReloadNeeded(FALSE)\r
34         , m_regInlineAdded(_T("Software\\TortoiseMerge\\InlineAdded"), INLINEADDED_COLOR)\r
35         , m_regInlineRemoved(_T("Software\\TortoiseMerge\\InlineRemoved"), INLINEREMOVED_COLOR)\r
36         , m_regModifiedBackground(_T("Software\\TortoiseMerge\\Colors\\ColorModifiedB"), MODIFIED_COLOR)\r
37 {\r
38 }\r
39 \r
40 CSetColorPage::~CSetColorPage()\r
41 {\r
42         m_bInit = FALSE;\r
43 }\r
44 \r
45 void CSetColorPage::SaveData()\r
46 {\r
47         if (m_bInit)\r
48         {\r
49                 COLORREF cBk;\r
50                 COLORREF cFg;\r
51 \r
52                 cFg = ::GetSysColor(COLOR_WINDOWTEXT);\r
53 \r
54                 cBk = m_cBkNormal.GetColor();\r
55                 if (cBk == -1)\r
56                         cBk = m_cBkNormal.GetAutomaticColor();\r
57                 CDiffColors::GetInstance().SetColors(DIFFSTATE_NORMAL, cBk, cFg);\r
58                 CDiffColors::GetInstance().SetColors(DIFFSTATE_UNKNOWN, cBk, cFg);\r
59 \r
60                 cBk = m_cBkRemoved.GetColor();\r
61                 if (cBk == -1)\r
62                         cBk = m_cBkRemoved.GetAutomaticColor();\r
63                 CDiffColors::GetInstance().SetColors(DIFFSTATE_REMOVED, cBk, cFg);\r
64                 CDiffColors::GetInstance().SetColors(DIFFSTATE_IDENTICALREMOVED, cBk, cFg);\r
65                 CDiffColors::GetInstance().SetColors(DIFFSTATE_THEIRSREMOVED, cBk, cFg);\r
66                 CDiffColors::GetInstance().SetColors(DIFFSTATE_YOURSREMOVED, cBk, cFg);\r
67 \r
68                 cBk = m_cBkAdded.GetColor();\r
69                 if (cBk == -1)\r
70                         cBk = m_cBkAdded.GetAutomaticColor();\r
71                 CDiffColors::GetInstance().SetColors(DIFFSTATE_ADDED, cBk, cFg);\r
72                 CDiffColors::GetInstance().SetColors(DIFFSTATE_IDENTICALADDED, cBk, cFg);\r
73                 CDiffColors::GetInstance().SetColors(DIFFSTATE_THEIRSADDED, cBk, cFg);\r
74                 CDiffColors::GetInstance().SetColors(DIFFSTATE_YOURSADDED, cBk, cFg);\r
75 \r
76                 if ((DWORD)m_regInlineAdded != (DWORD)m_cBkInlineAdded.GetColor())\r
77                         m_bReloadNeeded = true;\r
78                 m_regInlineAdded = (m_cBkInlineAdded.GetColor() == -1 ? m_cBkInlineAdded.GetAutomaticColor() : m_cBkInlineAdded.GetColor());\r
79                 if ((DWORD)m_regInlineRemoved != (DWORD)m_cBkInlineRemoved.GetColor())\r
80                         m_bReloadNeeded = true;\r
81                 m_regInlineRemoved = (m_cBkInlineRemoved.GetColor() == -1 ? m_cBkInlineRemoved.GetAutomaticColor() : m_cBkInlineRemoved.GetColor());\r
82                 if ((DWORD)m_regModifiedBackground != (DWORD)m_cBkModified.GetColor())\r
83                         m_bReloadNeeded = true;\r
84                 m_regModifiedBackground = (m_cBkModified.GetColor() == -1 ? m_cBkModified.GetAutomaticColor() : m_cBkModified.GetColor());\r
85 \r
86                 cBk = m_cBkEmpty.GetColor();\r
87                 if (cBk == -1)\r
88                         cBk = m_cBkEmpty.GetAutomaticColor();\r
89                 CDiffColors::GetInstance().SetColors(DIFFSTATE_EMPTY, cBk, cFg);\r
90 \r
91                 COLORREF adjustedcolor;\r
92                 cBk = m_cBkConflict.GetColor();\r
93                 if (cBk == -1)\r
94                         cBk = m_cBkConflict.GetAutomaticColor();\r
95                 CDiffColors::GetInstance().SetColors(DIFFSTATE_CONFLICTED, cBk, cFg);\r
96                 CDiffColors::GetInstance().SetColors(DIFFSTATE_CONFLICTED_IGNORED, cBk, cFg);\r
97                 CDiffColors::GetInstance().SetColors(DIFFSTATE_CONFLICTADDED, cBk, cFg);\r
98                 CDiffColors::GetInstance().SetColors(DIFFSTATE_CONFLICTEMPTY, adjustedcolor, cFg);\r
99                 \r
100                 cBk = m_cBkConflictResolved.GetColor();\r
101                 if (cBk == -1)\r
102                         cBk = m_cBkConflictResolved.GetAutomaticColor();\r
103                 CDiffColors::GetInstance().SetColors(DIFFSTATE_CONFLICTRESOLVED, cBk, cFg);\r
104 \r
105                 cFg = m_cFgWhitespaces.GetColor();\r
106                 if (cFg == -1)\r
107                         cFg = m_cFgWhitespaces.GetAutomaticColor();\r
108                 CRegDWORD regWhitespaceColor(_T("Software\\TortoiseMerge\\Colors\\Whitespace"), GetSysColor(COLOR_GRAYTEXT));\r
109                 regWhitespaceColor = cFg;\r
110         }\r
111 }\r
112 \r
113 void CSetColorPage::DoDataExchange(CDataExchange* pDX)\r
114 {\r
115         CPropertyPage::DoDataExchange(pDX);\r
116         DDX_Control(pDX, IDC_BKNORMAL, m_cBkNormal);\r
117         DDX_Control(pDX, IDC_BKREMOVED, m_cBkRemoved);\r
118         DDX_Control(pDX, IDC_BKADDED, m_cBkAdded);\r
119         DDX_Control(pDX, IDC_BKWHITESPACES, m_cBkInlineAdded);\r
120         DDX_Control(pDX, IDC_BKWHITESPACEDIFF, m_cBkInlineRemoved);\r
121         DDX_Control(pDX, IDC_BKMODIFIED, m_cBkModified);\r
122         DDX_Control(pDX, IDC_BKEMPTY, m_cBkEmpty);\r
123         DDX_Control(pDX, IDC_BKCONFLICTED, m_cBkConflict);\r
124         DDX_Control(pDX, IDC_BKCONFLICTRESOLVED, m_cBkConflictResolved);\r
125         DDX_Control(pDX, IDC_FGWHITESPACES, m_cFgWhitespaces);\r
126 }\r
127 \r
128 \r
129 BEGIN_MESSAGE_MAP(CSetColorPage, CPropertyPage)\r
130         ON_BN_CLICKED(IDC_BKNORMAL, &CSetColorPage::OnBnClickedColor)\r
131         ON_BN_CLICKED(IDC_BKREMOVED, &CSetColorPage::OnBnClickedColor)\r
132         ON_BN_CLICKED(IDC_BKADDED, &CSetColorPage::OnBnClickedColor)\r
133         ON_BN_CLICKED(IDC_BKWHITESPACES, &CSetColorPage::OnBnClickedColor)\r
134         ON_BN_CLICKED(IDC_BKWHITESPACEDIFF, &CSetColorPage::OnBnClickedColor)\r
135         ON_BN_CLICKED(IDC_BKMODIFIED, &CSetColorPage::OnBnClickedColor)\r
136         ON_BN_CLICKED(IDC_BKEMPTY, &CSetColorPage::OnBnClickedColor)\r
137         ON_BN_CLICKED(IDC_BKCONFLICTED, &CSetColorPage::OnBnClickedColor)\r
138         ON_BN_CLICKED(IDC_BKCONFLICTRESOLVED, &CSetColorPage::OnBnClickedColor)\r
139         ON_BN_CLICKED(IDC_FGWHITESPACES, &CSetColorPage::OnBnClickedColor)\r
140 END_MESSAGE_MAP()\r
141 \r
142 \r
143 // CSetColorPage message handlers\r
144 \r
145 BOOL CSetColorPage::OnInitDialog()\r
146 {\r
147         CPropertyPage::OnInitDialog();\r
148 \r
149         COLORREF cBk;\r
150         COLORREF cFg;\r
151 \r
152         CString sDefaultText, sCustomText;\r
153         sDefaultText.LoadString(IDS_COLOURPICKER_DEFAULTTEXT);\r
154         sCustomText.LoadString(IDS_COLOURPICKER_CUSTOMTEXT);\r
155 \r
156         CDiffColors::GetInstance().GetColors(DIFFSTATE_NORMAL, cBk, cFg);\r
157         m_cBkNormal.SetColor(cBk);\r
158         m_cBkNormal.EnableAutomaticButton(sDefaultText, DIFFSTATE_NORMAL_DEFAULT_BG);\r
159         m_cBkNormal.EnableOtherButton(sCustomText);\r
160 \r
161         CDiffColors::GetInstance().GetColors(DIFFSTATE_REMOVED, cBk, cFg);\r
162         m_cBkRemoved.SetColor(cBk);\r
163         m_cBkRemoved.EnableAutomaticButton(sDefaultText, DIFFSTATE_REMOVED_DEFAULT_BG);\r
164         m_cBkRemoved.EnableOtherButton(sCustomText);\r
165 \r
166         CDiffColors::GetInstance().GetColors(DIFFSTATE_ADDED, cBk, cFg);\r
167         m_cBkAdded.SetColor(cBk);\r
168         m_cBkAdded.EnableAutomaticButton(sDefaultText, DIFFSTATE_ADDED_DEFAULT_BG);\r
169         m_cBkAdded.EnableOtherButton(sCustomText);\r
170 \r
171         m_cBkInlineAdded.SetColor((DWORD)m_regInlineAdded);\r
172         m_cBkInlineAdded.EnableAutomaticButton(sDefaultText, INLINEADDED_COLOR);\r
173         m_cBkInlineAdded.EnableOtherButton(sCustomText);\r
174 \r
175         m_cBkInlineRemoved.SetColor((DWORD)m_regInlineRemoved);\r
176         m_cBkInlineRemoved.EnableAutomaticButton(sDefaultText, INLINEREMOVED_COLOR);\r
177         m_cBkInlineRemoved.EnableOtherButton(sCustomText);\r
178 \r
179         m_cBkModified.SetColor((DWORD)m_regModifiedBackground);\r
180         m_cBkModified.EnableAutomaticButton(sDefaultText, MODIFIED_COLOR);\r
181         m_cBkModified.EnableOtherButton(sCustomText);\r
182 \r
183         CDiffColors::GetInstance().GetColors(DIFFSTATE_EMPTY, cBk, cFg);\r
184         m_cBkEmpty.SetColor(cBk);\r
185         m_cBkEmpty.EnableAutomaticButton(sDefaultText, DIFFSTATE_EMPTY_DEFAULT_BG);\r
186         m_cBkEmpty.EnableOtherButton(sCustomText);\r
187 \r
188         CDiffColors::GetInstance().GetColors(DIFFSTATE_CONFLICTED, cBk, cFg);\r
189         m_cBkConflict.SetColor(cBk);\r
190         m_cBkConflict.EnableAutomaticButton(sDefaultText, DIFFSTATE_CONFLICTED_DEFAULT_BG);\r
191         m_cBkConflict.EnableOtherButton(sCustomText);\r
192 \r
193         CDiffColors::GetInstance().GetColors(DIFFSTATE_CONFLICTRESOLVED, cBk, cFg);\r
194         m_cBkConflictResolved.SetColor(cBk);\r
195         m_cBkConflictResolved.EnableAutomaticButton(sDefaultText, DIFFSTATE_CONFLICTRESOLVED_DEFAULT_BG);\r
196         m_cBkConflictResolved.EnableOtherButton(sCustomText);\r
197 \r
198 \r
199         CRegDWORD regWhitespaceColor(_T("Software\\TortoiseMerge\\Colors\\Whitespace"), GetSysColor(COLOR_GRAYTEXT));\r
200         m_cFgWhitespaces.SetColor((COLORREF)(DWORD)regWhitespaceColor);\r
201         m_cFgWhitespaces.EnableAutomaticButton(sDefaultText, GetSysColor(COLOR_GRAYTEXT));\r
202         m_cFgWhitespaces.EnableOtherButton(sCustomText);\r
203 \r
204 \r
205         m_bInit = TRUE;\r
206 \r
207         return TRUE;  // return TRUE unless you set the focus to a control\r
208         // EXCEPTION: OCX Property Pages should return FALSE\r
209 }\r
210 \r
211 BOOL CSetColorPage::OnApply()\r
212 {\r
213         UpdateData();\r
214         SaveData();\r
215         SetModified(FALSE);\r
216         return CPropertyPage::OnApply();\r
217 }\r
218 \r
219 void CSetColorPage::OnBnClickedColor()\r
220 {\r
221         SetModified();\r
222 }\r
223 \r