1 // TortoiseGitMerge - a Diff/Patch program
3 // Copyright (C) 2006-2008, 2012-2014 - TortoiseSVN
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include "TortoiseMerge.h"
21 #include "SetColorPage.h"
22 #include "DiffColors.h"
25 // CSetColorPage dialog
27 IMPLEMENT_DYNAMIC(CSetColorPage
, CPropertyPage
)
28 CSetColorPage::CSetColorPage()
29 : CPropertyPage(CSetColorPage::IDD
)
30 , m_bReloadNeeded(FALSE
)
31 , m_regInlineAdded(_T("Software\\TortoiseGitMerge\\InlineAdded"), INLINEADDED_COLOR
)
32 , m_regInlineRemoved(_T("Software\\TortoiseGitMerge\\InlineRemoved"), INLINEREMOVED_COLOR
)
33 , m_regModifiedBackground(_T("Software\\TortoiseGitMerge\\Colors\\ColorModifiedB"), MODIFIED_COLOR
)
38 CSetColorPage::~CSetColorPage()
43 void CSetColorPage::SaveData()
48 COLORREF cFg
= ::GetSysColor(COLOR_WINDOWTEXT
);
50 COLORREF cBk
= m_cBkNormal
.GetColor();
52 cBk
= m_cBkNormal
.GetAutomaticColor();
53 CDiffColors::GetInstance().SetColors(DIFFSTATE_NORMAL
, cBk
, cFg
);
54 CDiffColors::GetInstance().SetColors(DIFFSTATE_UNKNOWN
, cBk
, cFg
);
56 cBk
= m_cBkRemoved
.GetColor();
58 cBk
= m_cBkRemoved
.GetAutomaticColor();
59 CDiffColors::GetInstance().SetColors(DIFFSTATE_REMOVED
, cBk
, cFg
);
60 CDiffColors::GetInstance().SetColors(DIFFSTATE_IDENTICALREMOVED
, cBk
, cFg
);
61 CDiffColors::GetInstance().SetColors(DIFFSTATE_THEIRSREMOVED
, cBk
, cFg
);
62 CDiffColors::GetInstance().SetColors(DIFFSTATE_YOURSREMOVED
, cBk
, cFg
);
64 cBk
= m_cBkAdded
.GetColor();
66 cBk
= m_cBkAdded
.GetAutomaticColor();
67 CDiffColors::GetInstance().SetColors(DIFFSTATE_ADDED
, cBk
, cFg
);
68 CDiffColors::GetInstance().SetColors(DIFFSTATE_IDENTICALADDED
, cBk
, cFg
);
69 CDiffColors::GetInstance().SetColors(DIFFSTATE_THEIRSADDED
, cBk
, cFg
);
70 CDiffColors::GetInstance().SetColors(DIFFSTATE_YOURSADDED
, cBk
, cFg
);
72 if ((DWORD
)m_regInlineAdded
!= (DWORD
)m_cBkInlineAdded
.GetColor())
73 m_bReloadNeeded
= true;
74 m_regInlineAdded
= (m_cBkInlineAdded
.GetColor() == -1 ? m_cBkInlineAdded
.GetAutomaticColor() : m_cBkInlineAdded
.GetColor());
75 if ((DWORD
)m_regInlineRemoved
!= (DWORD
)m_cBkInlineRemoved
.GetColor())
76 m_bReloadNeeded
= true;
77 m_regInlineRemoved
= (m_cBkInlineRemoved
.GetColor() == -1 ? m_cBkInlineRemoved
.GetAutomaticColor() : m_cBkInlineRemoved
.GetColor());
78 if ((DWORD
)m_regModifiedBackground
!= (DWORD
)m_cBkModified
.GetColor())
79 m_bReloadNeeded
= true;
80 m_regModifiedBackground
= (m_cBkModified
.GetColor() == -1 ? m_cBkModified
.GetAutomaticColor() : m_cBkModified
.GetColor());
81 CDiffColors::GetInstance().SetColors(DIFFSTATE_EDITED
, (DWORD
)m_regModifiedBackground
, cFg
);
83 cBk
= m_cBkEmpty
.GetColor();
85 cBk
= m_cBkEmpty
.GetAutomaticColor();
86 CDiffColors::GetInstance().SetColors(DIFFSTATE_EMPTY
, cBk
, cFg
);
88 COLORREF adjustedcolor
= cBk
;
89 cBk
= m_cBkConflict
.GetColor();
91 cBk
= m_cBkConflict
.GetAutomaticColor();
92 CDiffColors::GetInstance().SetColors(DIFFSTATE_CONFLICTED
, cBk
, cFg
);
93 CDiffColors::GetInstance().SetColors(DIFFSTATE_CONFLICTED_IGNORED
, cBk
, cFg
);
94 CDiffColors::GetInstance().SetColors(DIFFSTATE_CONFLICTADDED
, cBk
, cFg
);
95 CDiffColors::GetInstance().SetColors(DIFFSTATE_CONFLICTEMPTY
, adjustedcolor
, cFg
);
97 cBk
= m_cBkConflictResolved
.GetColor();
99 cBk
= m_cBkConflictResolved
.GetAutomaticColor();
100 CDiffColors::GetInstance().SetColors(DIFFSTATE_CONFLICTRESOLVED
, cBk
, cFg
);
103 cFg
= m_cFgWhitespaces
.GetColor();
105 cFg
= m_cFgWhitespaces
.GetAutomaticColor();
106 CRegDWORD
regWhitespaceColor(_T("Software\\TortoiseGitMerge\\Colors\\Whitespace"), GetSysColor(COLOR_GRAYTEXT
));
107 regWhitespaceColor
= cFg
;
110 void CSetColorPage::DoDataExchange(CDataExchange
* pDX
)
112 CPropertyPage::DoDataExchange(pDX
);
113 DDX_Control(pDX
, IDC_BKNORMAL
, m_cBkNormal
);
114 DDX_Control(pDX
, IDC_BKREMOVED
, m_cBkRemoved
);
115 DDX_Control(pDX
, IDC_BKADDED
, m_cBkAdded
);
116 DDX_Control(pDX
, IDC_BKWHITESPACES
, m_cBkInlineAdded
);
117 DDX_Control(pDX
, IDC_BKWHITESPACEDIFF
, m_cBkInlineRemoved
);
118 DDX_Control(pDX
, IDC_BKMODIFIED
, m_cBkModified
);
119 DDX_Control(pDX
, IDC_BKEMPTY
, m_cBkEmpty
);
120 DDX_Control(pDX
, IDC_BKCONFLICTED
, m_cBkConflict
);
121 DDX_Control(pDX
, IDC_BKCONFLICTRESOLVED
, m_cBkConflictResolved
);
122 DDX_Control(pDX
, IDC_FGWHITESPACES
, m_cFgWhitespaces
);
126 BEGIN_MESSAGE_MAP(CSetColorPage
, CPropertyPage
)
127 ON_BN_CLICKED(IDC_BKNORMAL
, &CSetColorPage::OnBnClickedColor
)
128 ON_BN_CLICKED(IDC_BKREMOVED
, &CSetColorPage::OnBnClickedColor
)
129 ON_BN_CLICKED(IDC_BKADDED
, &CSetColorPage::OnBnClickedColor
)
130 ON_BN_CLICKED(IDC_BKWHITESPACES
, &CSetColorPage::OnBnClickedColor
)
131 ON_BN_CLICKED(IDC_BKWHITESPACEDIFF
, &CSetColorPage::OnBnClickedColor
)
132 ON_BN_CLICKED(IDC_BKMODIFIED
, &CSetColorPage::OnBnClickedColor
)
133 ON_BN_CLICKED(IDC_BKEMPTY
, &CSetColorPage::OnBnClickedColor
)
134 ON_BN_CLICKED(IDC_BKCONFLICTED
, &CSetColorPage::OnBnClickedColor
)
135 ON_BN_CLICKED(IDC_BKCONFLICTRESOLVED
, &CSetColorPage::OnBnClickedColor
)
136 ON_BN_CLICKED(IDC_FGWHITESPACES
, &CSetColorPage::OnBnClickedColor
)
137 ON_BN_CLICKED(IDC_RESTORE
, &CSetColorPage::OnBnClickedRestore
)
141 // CSetColorPage message handlers
143 BOOL
CSetColorPage::OnInitDialog()
145 CPropertyPage::OnInitDialog();
150 CString sDefaultText
, sCustomText
;
151 sDefaultText
.LoadString(IDS_COLOURPICKER_DEFAULTTEXT
);
152 sCustomText
.LoadString(IDS_COLOURPICKER_CUSTOMTEXT
);
154 CDiffColors::GetInstance().GetColors(DIFFSTATE_NORMAL
, cBk
, cFg
);
155 m_cBkNormal
.SetColor(cBk
);
156 m_cBkNormal
.EnableAutomaticButton(sDefaultText
, DIFFSTATE_NORMAL_DEFAULT_BG
);
157 m_cBkNormal
.EnableOtherButton(sCustomText
);
159 CDiffColors::GetInstance().GetColors(DIFFSTATE_REMOVED
, cBk
, cFg
);
160 m_cBkRemoved
.SetColor(cBk
);
161 m_cBkRemoved
.EnableAutomaticButton(sDefaultText
, DIFFSTATE_REMOVED_DEFAULT_BG
);
162 m_cBkRemoved
.EnableOtherButton(sCustomText
);
164 CDiffColors::GetInstance().GetColors(DIFFSTATE_ADDED
, cBk
, cFg
);
165 m_cBkAdded
.SetColor(cBk
);
166 m_cBkAdded
.EnableAutomaticButton(sDefaultText
, DIFFSTATE_ADDED_DEFAULT_BG
);
167 m_cBkAdded
.EnableOtherButton(sCustomText
);
169 m_cBkInlineAdded
.SetColor((DWORD
)m_regInlineAdded
);
170 m_cBkInlineAdded
.EnableAutomaticButton(sDefaultText
, INLINEADDED_COLOR
);
171 m_cBkInlineAdded
.EnableOtherButton(sCustomText
);
173 m_cBkInlineRemoved
.SetColor((DWORD
)m_regInlineRemoved
);
174 m_cBkInlineRemoved
.EnableAutomaticButton(sDefaultText
, INLINEREMOVED_COLOR
);
175 m_cBkInlineRemoved
.EnableOtherButton(sCustomText
);
177 m_cBkModified
.SetColor((DWORD
)m_regModifiedBackground
);
178 m_cBkModified
.EnableAutomaticButton(sDefaultText
, MODIFIED_COLOR
);
179 m_cBkModified
.EnableOtherButton(sCustomText
);
181 CDiffColors::GetInstance().GetColors(DIFFSTATE_EMPTY
, cBk
, cFg
);
182 m_cBkEmpty
.SetColor(cBk
);
183 m_cBkEmpty
.EnableAutomaticButton(sDefaultText
, DIFFSTATE_EMPTY_DEFAULT_BG
);
184 m_cBkEmpty
.EnableOtherButton(sCustomText
);
186 CDiffColors::GetInstance().GetColors(DIFFSTATE_CONFLICTED
, cBk
, cFg
);
187 m_cBkConflict
.SetColor(cBk
);
188 m_cBkConflict
.EnableAutomaticButton(sDefaultText
, DIFFSTATE_CONFLICTED_DEFAULT_BG
);
189 m_cBkConflict
.EnableOtherButton(sCustomText
);
191 CDiffColors::GetInstance().GetColors(DIFFSTATE_CONFLICTRESOLVED
, cBk
, cFg
);
192 m_cBkConflictResolved
.SetColor(cBk
);
193 m_cBkConflictResolved
.EnableAutomaticButton(sDefaultText
, DIFFSTATE_CONFLICTRESOLVED_DEFAULT_BG
);
194 m_cBkConflictResolved
.EnableOtherButton(sCustomText
);
197 CRegDWORD
regWhitespaceColor(_T("Software\\TortoiseGitMerge\\Colors\\Whitespace"), GetSysColor(COLOR_GRAYTEXT
));
198 m_cFgWhitespaces
.SetColor((COLORREF
)(DWORD
)regWhitespaceColor
);
199 m_cFgWhitespaces
.EnableAutomaticButton(sDefaultText
, GetSysColor(COLOR_GRAYTEXT
));
200 m_cFgWhitespaces
.EnableOtherButton(sCustomText
);
205 return TRUE
; // return TRUE unless you set the focus to a control
206 // EXCEPTION: OCX Property Pages should return FALSE
209 BOOL
CSetColorPage::OnApply()
214 return CPropertyPage::OnApply();
217 void CSetColorPage::OnBnClickedColor()
222 void CSetColorPage::OnBnClickedRestore()
224 m_cBkNormal
.SetColor(DIFFSTATE_NORMAL_DEFAULT_BG
);
225 m_cBkRemoved
.SetColor(DIFFSTATE_REMOVED_DEFAULT_BG
);
226 m_cBkAdded
.SetColor(DIFFSTATE_ADDED_DEFAULT_BG
);
227 m_cBkInlineAdded
.SetColor(INLINEADDED_COLOR
);
228 m_cBkInlineRemoved
.SetColor(INLINEREMOVED_COLOR
);
229 m_cBkModified
.SetColor(MODIFIED_COLOR
);
230 m_cBkEmpty
.SetColor(DIFFSTATE_EMPTY_DEFAULT_BG
);
231 m_cBkConflict
.SetColor(DIFFSTATE_CONFLICTED_DEFAULT_BG
);
232 m_cBkConflictResolved
.SetColor(DIFFSTATE_CONFLICTRESOLVED_DEFAULT_BG
);
233 m_cFgWhitespaces
.SetColor(GetSysColor(COLOR_GRAYTEXT
));