Fixed issue #1507: Submodule Diff Dialog should show dirty state only on working...
[TortoiseGit.git] / src / TortoiseMerge / LineDiffBar.cpp
blobd3b06d37d7cf910eb4ea00597fd03efe26ec0198
1 // TortoiseMerge - a Diff/Patch program
3 // Copyright (C) 2006-2008 - 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)&&(m_pMainFrm->m_pwndLeftView)&&(m_pMainFrm->m_pwndRightView))
100 if ((m_pMainFrm->m_pwndLeftView->IsWindowVisible())&&(m_pMainFrm->m_pwndRightView->IsWindowVisible()))
102 BOOL bViewWhiteSpace = m_pMainFrm->m_pwndLeftView->m_bViewWhitespace;
103 BOOL bInlineDiffs = m_pMainFrm->m_pwndLeftView->m_bShowInlineDiff;
105 m_pMainFrm->m_pwndLeftView->m_bViewWhitespace = TRUE;
106 m_pMainFrm->m_pwndLeftView->m_bShowInlineDiff = TRUE;
107 m_pMainFrm->m_pwndLeftView->m_bShowSelection = false;
108 m_pMainFrm->m_pwndRightView->m_bViewWhitespace = TRUE;
109 m_pMainFrm->m_pwndRightView->m_bShowInlineDiff = TRUE;
110 m_pMainFrm->m_pwndRightView->m_bShowSelection = false;
112 // Use left and right view to display lines next to each other
113 m_pMainFrm->m_pwndLeftView->DrawSingleLine(&cacheDC, &upperrect, m_nLineIndex);
114 m_pMainFrm->m_pwndRightView->DrawSingleLine(&cacheDC, &lowerrect, m_nLineIndex);
116 m_pMainFrm->m_pwndLeftView->m_bViewWhitespace = bViewWhiteSpace;
117 m_pMainFrm->m_pwndLeftView->m_bShowInlineDiff = bInlineDiffs;
118 m_pMainFrm->m_pwndLeftView->m_bShowSelection = true;
119 m_pMainFrm->m_pwndRightView->m_bViewWhitespace = bViewWhiteSpace;
120 m_pMainFrm->m_pwndRightView->m_bShowInlineDiff = bInlineDiffs;
121 m_pMainFrm->m_pwndRightView->m_bShowSelection = true;
125 VERIFY(dc.BitBlt(rect.left, rect.top, width, height, &cacheDC, 0, 0, SRCCOPY));
127 cacheDC.SelectObject(pOldBitmap);
128 cacheDC.DeleteDC();
131 void CLineDiffBar::OnSize(UINT nType, int cx, int cy)
133 CPaneDialog::OnSize(nType, cx, cy);
135 if (m_pCacheBitmap != NULL)
137 m_pCacheBitmap->DeleteObject();
138 delete m_pCacheBitmap;
139 m_pCacheBitmap = NULL;
141 SetWindowPos(NULL, 0, 0, cx, 2*m_nLineHeight, SWP_NOMOVE);
142 Invalidate();
145 BOOL CLineDiffBar::OnEraseBkgnd(CDC* /*pDC*/)
147 return TRUE;