Fix checkout failure when running clone with libgit2 without specifying local branch...
[TortoiseGit.git] / src / TortoiseMerge / LineDiffBar.cpp
blob4880305ec4433a1f719bee53ee15a367408fc007
1 // TortoiseGitMerge - a Diff/Patch program
3 // Copyright (C) 2006-2008, 2010 - 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.
19 #include "stdafx.h"
20 #include "TortoiseMerge.h"
21 #include "MainFrm.h"
22 #include "LocatorBar.h"
23 #include "LeftView.h"
24 #include "RightView.h"
25 #include "BottomView.h"
27 IMPLEMENT_DYNAMIC(CLineDiffBar, CPaneDialog)
28 CLineDiffBar::CLineDiffBar() : CPaneDialog()
30 m_pMainFrm = NULL;
31 m_pCacheBitmap = NULL;
32 m_nLineIndex = -1;
33 m_nLineHeight = 0;
34 m_bExclusiveRow = TRUE;
37 CLineDiffBar::~CLineDiffBar()
39 if (m_pCacheBitmap)
41 m_pCacheBitmap->DeleteObject();
42 delete m_pCacheBitmap;
43 m_pCacheBitmap = NULL;
47 BEGIN_MESSAGE_MAP(CLineDiffBar, CPaneDialog)
48 ON_WM_PAINT()
49 ON_WM_SIZE()
50 ON_WM_ERASEBKGND()
51 END_MESSAGE_MAP()
53 void CLineDiffBar::DocumentUpdated()
55 //resize according to the font size
56 if ((m_pMainFrm)&&(m_pMainFrm->m_pwndLeftView))
58 m_nLineHeight = m_pMainFrm->m_pwndLeftView->GetLineHeight();
60 CRect rect;
61 GetWindowRect(rect);
62 CSize size = rect.Size();
63 size.cy = 2 * m_nLineHeight;
64 SetMinSize(size);
65 SetWindowPos(NULL, 0, 0, size.cx, 2*m_nLineHeight, SWP_NOMOVE);
66 RecalcLayout();
67 if (m_pMainFrm)
68 m_pMainFrm->RecalcLayout();
71 void CLineDiffBar::ShowLines(int nLineIndex)
73 m_nLineIndex = nLineIndex;
74 Invalidate();
77 void CLineDiffBar::OnPaint()
79 CPaintDC dc(this); // device context for painting
80 CRect rect;
81 GetClientRect(rect);
82 int height = rect.Height();
83 int width = rect.Width();
85 CDC cacheDC;
86 VERIFY(cacheDC.CreateCompatibleDC(&dc));
87 cacheDC.FillSolidRect(&rect, ::GetSysColor(COLOR_WINDOW));
88 if (m_pCacheBitmap == NULL)
90 m_pCacheBitmap = new CBitmap;
91 VERIFY(m_pCacheBitmap->CreateCompatibleBitmap(&dc, width, height));
93 CBitmap *pOldBitmap = cacheDC.SelectObject(m_pCacheBitmap);
95 CRect upperrect = CRect(rect.left, rect.top, rect.right, rect.bottom/2);
96 CRect lowerrect = CRect(rect.left, rect.bottom/2, rect.right, rect.bottom);
98 if (m_pMainFrm!=0)
100 CLeftView* leftView = m_pMainFrm->m_pwndLeftView;
101 CRightView* rightView = m_pMainFrm->m_pwndRightView;
102 if (CBaseView::IsViewGood(leftView)&&CBaseView::IsViewGood(rightView))
104 BOOL bViewWhiteSpace = leftView->m_bViewWhitespace;
105 BOOL bInlineDiffs = leftView->m_bShowInlineDiff;
107 leftView->m_bViewWhitespace = TRUE;
108 leftView->m_bShowInlineDiff = TRUE;
109 leftView->m_bWhitespaceInlineDiffs = true;
110 leftView->m_bShowSelection = false;
111 rightView->m_bViewWhitespace = TRUE;
112 rightView->m_bShowInlineDiff = TRUE;
113 rightView->m_bWhitespaceInlineDiffs = true;
114 rightView->m_bShowSelection = false;
116 // Use left and right view to display lines next to each other
117 leftView->DrawSingleLine(&cacheDC, &upperrect, m_nLineIndex);
118 rightView->DrawSingleLine(&cacheDC, &lowerrect, m_nLineIndex);
120 leftView->m_bViewWhitespace = bViewWhiteSpace;
121 leftView->m_bShowInlineDiff = bInlineDiffs;
122 leftView->m_bWhitespaceInlineDiffs = false;
123 leftView->m_bShowSelection = true;
124 rightView->m_bViewWhitespace = bViewWhiteSpace;
125 rightView->m_bShowInlineDiff = bInlineDiffs;
126 rightView->m_bWhitespaceInlineDiffs = false;
127 rightView->m_bShowSelection = true;
131 VERIFY(dc.BitBlt(rect.left, rect.top, width, height, &cacheDC, 0, 0, SRCCOPY));
133 cacheDC.SelectObject(pOldBitmap);
134 cacheDC.DeleteDC();
137 void CLineDiffBar::OnSize(UINT nType, int cx, int cy)
139 CPaneDialog::OnSize(nType, cx, cy);
141 if (m_pCacheBitmap != NULL)
143 m_pCacheBitmap->DeleteObject();
144 delete m_pCacheBitmap;
145 m_pCacheBitmap = NULL;
147 SetWindowPos(NULL, 0, 0, cx, 2*m_nLineHeight, SWP_NOMOVE);
148 Invalidate();
151 BOOL CLineDiffBar::OnEraseBkgnd(CDC* /*pDC*/)
153 return TRUE;