1 // TortoiseGitMerge - a Diff/Patch program
3 // Copyright (C) 2023 - TortoiseGit
4 // Copyright (C) 2006-2008, 2010 - TortoiseSVN
6 // This program is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public License
8 // as published by the Free Software Foundation; either version 2
9 // of the License, or (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software Foundation,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 #include "TortoiseMerge.h"
23 #include "LocatorBar.h"
25 #include "RightView.h"
26 #include "BottomView.h"
28 IMPLEMENT_DYNAMIC(CLineDiffBar
, CPaneDialog
)
29 CLineDiffBar::CLineDiffBar() : CPaneDialog()
31 m_bExclusiveRow
= TRUE
;
34 CLineDiffBar::~CLineDiffBar()
38 m_pCacheBitmap
->DeleteObject();
39 delete m_pCacheBitmap
;
40 m_pCacheBitmap
= nullptr;
44 BEGIN_MESSAGE_MAP(CLineDiffBar
, CPaneDialog
)
50 void CLineDiffBar::DocumentUpdated()
52 //resize according to the font size
53 if ((m_pMainFrm
)&&(m_pMainFrm
->m_pwndLeftView
))
55 m_nLineHeight
= m_pMainFrm
->m_pwndLeftView
->GetLineHeight();
59 CSize size
= rect
.Size();
60 size
.cy
= 2 * m_nLineHeight
;
62 SetWindowPos(nullptr, 0, 0, size
.cx
, 2 * m_nLineHeight
, SWP_NOMOVE
);
65 m_pMainFrm
->RecalcLayout();
68 void CLineDiffBar::ShowLines(int nLineIndex
)
70 m_nLineIndex
= nLineIndex
;
74 void CLineDiffBar::OnPaint()
76 CPaintDC
dc(this); // device context for painting
79 int height
= rect
.Height();
80 int width
= rect
.Width();
83 VERIFY(cacheDC
.CreateCompatibleDC(&dc
));
84 cacheDC
.FillSolidRect(&rect
, ::GetSysColor(COLOR_WINDOW
));
87 m_pCacheBitmap
= new CBitmap
;
88 VERIFY(m_pCacheBitmap
->CreateCompatibleBitmap(&dc
, width
, height
));
90 CBitmap
*pOldBitmap
= cacheDC
.SelectObject(m_pCacheBitmap
);
92 CRect upperrect
= CRect(rect
.left
, rect
.top
, rect
.right
, rect
.bottom
/2);
93 CRect lowerrect
= CRect(rect
.left
, rect
.bottom
/2, rect
.right
, rect
.bottom
);
97 CLeftView
* leftView
= m_pMainFrm
->m_pwndLeftView
;
98 CRightView
* rightView
= m_pMainFrm
->m_pwndRightView
;
99 if (CBaseView::IsViewGood(leftView
)&&CBaseView::IsViewGood(rightView
))
101 BOOL bViewWhiteSpace
= leftView
->m_bViewWhitespace
;
102 BOOL bInlineDiffs
= leftView
->m_bShowInlineDiff
;
104 leftView
->m_bViewWhitespace
= TRUE
;
105 leftView
->m_bShowInlineDiff
= TRUE
;
106 leftView
->m_bWhitespaceInlineDiffs
= true;
107 leftView
->m_bShowSelection
= false;
108 rightView
->m_bViewWhitespace
= TRUE
;
109 rightView
->m_bShowInlineDiff
= TRUE
;
110 rightView
->m_bWhitespaceInlineDiffs
= true;
111 rightView
->m_bShowSelection
= false;
113 // Use left and right view to display lines next to each other
114 leftView
->DrawSingleLine(&cacheDC
, &upperrect
, m_nLineIndex
);
115 rightView
->DrawSingleLine(&cacheDC
, &lowerrect
, m_nLineIndex
);
117 leftView
->m_bViewWhitespace
= bViewWhiteSpace
;
118 leftView
->m_bShowInlineDiff
= bInlineDiffs
;
119 leftView
->m_bWhitespaceInlineDiffs
= false;
120 leftView
->m_bShowSelection
= true;
121 rightView
->m_bViewWhitespace
= bViewWhiteSpace
;
122 rightView
->m_bShowInlineDiff
= bInlineDiffs
;
123 rightView
->m_bWhitespaceInlineDiffs
= false;
124 rightView
->m_bShowSelection
= true;
128 VERIFY(dc
.BitBlt(rect
.left
, rect
.top
, width
, height
, &cacheDC
, 0, 0, SRCCOPY
));
130 cacheDC
.SelectObject(pOldBitmap
);
134 void CLineDiffBar::OnSize(UINT nType
, int cx
, int cy
)
136 CPaneDialog::OnSize(nType
, cx
, cy
);
140 m_pCacheBitmap
->DeleteObject();
141 delete m_pCacheBitmap
;
142 m_pCacheBitmap
= nullptr;
144 SetWindowPos(nullptr, 0, 0, cx
, 2 * m_nLineHeight
, SWP_NOMOVE
);
148 BOOL
CLineDiffBar::OnEraseBkgnd(CDC
* /*pDC*/)