Prepare release and bump version numbers to 2.17.0.2
[TortoiseGit.git] / src / TortoiseMerge / LineDiffBar.cpp
blob87b5aea0230739dc3d486e8e6a1f64319f6d61ba
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.
20 #include "stdafx.h"
21 #include "TortoiseMerge.h"
22 #include "MainFrm.h"
23 #include "LocatorBar.h"
24 #include "LeftView.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()
36 if (m_pCacheBitmap)
38 m_pCacheBitmap->DeleteObject();
39 delete m_pCacheBitmap;
40 m_pCacheBitmap = nullptr;
44 BEGIN_MESSAGE_MAP(CLineDiffBar, CPaneDialog)
45 ON_WM_PAINT()
46 ON_WM_SIZE()
47 ON_WM_ERASEBKGND()
48 END_MESSAGE_MAP()
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();
57 CRect rect;
58 GetWindowRect(rect);
59 CSize size = rect.Size();
60 size.cy = 2 * m_nLineHeight;
61 SetMinSize(size);
62 SetWindowPos(nullptr, 0, 0, size.cx, 2 * m_nLineHeight, SWP_NOMOVE);
63 RecalcLayout();
64 if (m_pMainFrm)
65 m_pMainFrm->RecalcLayout();
68 void CLineDiffBar::ShowLines(int nLineIndex)
70 m_nLineIndex = nLineIndex;
71 Invalidate();
74 void CLineDiffBar::OnPaint()
76 CPaintDC dc(this); // device context for painting
77 CRect rect;
78 GetClientRect(rect);
79 int height = rect.Height();
80 int width = rect.Width();
82 CDC cacheDC;
83 VERIFY(cacheDC.CreateCompatibleDC(&dc));
84 cacheDC.FillSolidRect(&rect, ::GetSysColor(COLOR_WINDOW));
85 if (!m_pCacheBitmap)
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);
95 if (m_pMainFrm!=0)
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);
131 cacheDC.DeleteDC();
134 void CLineDiffBar::OnSize(UINT nType, int cx, int cy)
136 CPaneDialog::OnSize(nType, cx, cy);
138 if (m_pCacheBitmap)
140 m_pCacheBitmap->DeleteObject();
141 delete m_pCacheBitmap;
142 m_pCacheBitmap = nullptr;
144 SetWindowPos(nullptr, 0, 0, cx, 2 * m_nLineHeight, SWP_NOMOVE);
145 Invalidate();
148 BOOL CLineDiffBar::OnEraseBkgnd(CDC* /*pDC*/)
150 return TRUE;