1 // TortoiseMerge - a Diff/Patch program
\r
3 // Copyright (C) 2003-2009 - TortoiseSVN
\r
5 // This program is free software; you can redistribute it and/or
\r
6 // modify it under the terms of the GNU General Public License
\r
7 // as published by the Free Software Foundation; either version 2
\r
8 // of the License, or (at your option) any later version.
\r
10 // This program is distributed in the hope that it will be useful,
\r
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 // GNU General Public License for more details.
\r
15 // You should have received a copy of the GNU General Public License
\r
16 // along with this program; if not, write to the Free Software Foundation,
\r
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
\r
21 #include "registry.h"
\r
22 #include "TortoiseMerge.h"
\r
23 #include "MainFrm.h"
\r
24 #include "BaseView.h"
\r
25 #include "DiffColors.h"
\r
26 #include "StringUtils.h"
\r
31 #define new DEBUG_NEW
\r
34 #define MARGINWIDTH 20
\r
35 #define HEADERHEIGHT 10
\r
39 #define INLINEADDED_COLOR RGB(255, 255, 150)
\r
40 #define INLINEREMOVED_COLOR RGB(200, 100, 100)
\r
41 #define MODIFIED_COLOR RGB(220, 220, 255)
\r
43 #define IDT_SCROLLTIMER 101
\r
45 CBaseView * CBaseView::m_pwndLeft = NULL;
\r
46 CBaseView * CBaseView::m_pwndRight = NULL;
\r
47 CBaseView * CBaseView::m_pwndBottom = NULL;
\r
48 CLocatorBar * CBaseView::m_pwndLocator = NULL;
\r
49 CLineDiffBar * CBaseView::m_pwndLineDiffBar = NULL;
\r
50 CMFCStatusBar * CBaseView::m_pwndStatusBar = NULL;
\r
51 CMainFrame * CBaseView::m_pMainFrame = NULL;
\r
53 IMPLEMENT_DYNCREATE(CBaseView, CView)
\r
55 CBaseView::CBaseView()
\r
57 m_pCacheBitmap = NULL;
\r
59 m_pOtherViewData = NULL;
\r
62 m_nScreenChars = -1;
\r
63 m_nMaxLineLength = -1;
\r
64 m_nScreenLines = -1;
\r
69 m_bMouseWithin = FALSE;
\r
70 m_bIsHidden = FALSE;
\r
71 lineendings = EOL_AUTOLINE;
\r
72 m_bCaretHidden = true;
\r
75 m_nCaretGoalPos = 0;
\r
76 m_ptSelectionStartPos = m_ptCaretPos;
\r
77 m_ptSelectionEndPos = m_ptCaretPos;
\r
78 m_ptSelectionOrigin = m_ptCaretPos;
\r
80 m_bShowSelection = true;
\r
81 texttype = CFileTextLines::AUTOTYPE;
\r
82 m_bViewWhitespace = CRegDWORD(_T("Software\\TortoiseMerge\\ViewWhitespaces"), 1);
\r
83 m_bViewLinenumbers = CRegDWORD(_T("Software\\TortoiseMerge\\ViewLinenumbers"), 1);
\r
84 m_bShowInlineDiff = CRegDWORD(_T("Software\\TortoiseMerge\\DisplayBinDiff"), TRUE);
\r
85 m_InlineAddedBk = CRegDWORD(_T("Software\\TortoiseMerge\\InlineAdded"), INLINEADDED_COLOR);
\r
86 m_InlineRemovedBk = CRegDWORD(_T("Software\\TortoiseMerge\\InlineRemoved"), INLINEREMOVED_COLOR);
\r
87 m_ModifiedBk = CRegDWORD(_T("Software\\TortoiseMerge\\Colors\\ColorModifiedB"), MODIFIED_COLOR);
\r
88 m_WhiteSpaceFg = CRegDWORD(_T("Software\\TortoiseMerge\\Colors\\Whitespace"), GetSysColor(COLOR_GRAYTEXT));
\r
89 m_sWordSeparators = CRegString(_T("Software\\TortoiseMerge\\WordSeparators"), _T("[]();.,{}!@#$%^&*-+=|/\\<>'`~"));;
\r
90 m_bIconLFs = CRegDWORD(_T("Software\\TortoiseMerge\\IconLFs"), 0);
\r
91 m_nSelBlockStart = -1;
\r
92 m_nSelBlockEnd = -1;
\r
93 m_bModified = FALSE;
\r
94 m_bOtherDiffChecked = false;
\r
95 m_bInlineWordDiff = true;
\r
96 m_nTabSize = (int)(DWORD)CRegDWORD(_T("Software\\TortoiseMerge\\TabSize"), 4);
\r
97 for (int i=0; i<MAXFONTS; i++)
\r
99 m_apFonts[i] = NULL;
\r
101 m_hConflictedIcon = (HICON)::LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_CONFLICTEDLINE),
\r
102 IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
\r
103 m_hConflictedIgnoredIcon = (HICON)::LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_CONFLICTEDIGNOREDLINE),
\r
104 IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
\r
105 m_hRemovedIcon = (HICON)::LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_REMOVEDLINE),
\r
106 IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
\r
107 m_hAddedIcon = (HICON)::LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_ADDEDLINE),
\r
108 IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
\r
109 m_hWhitespaceBlockIcon = (HICON)::LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_WHITESPACELINE),
\r
110 IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
\r
111 m_hEqualIcon = (HICON)::LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_EQUALLINE),
\r
112 IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
\r
113 m_hLineEndingCR = (HICON)::LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_LINEENDINGCR),
\r
114 IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
\r
115 m_hLineEndingCRLF = (HICON)::LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_LINEENDINGCRLF),
\r
116 IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
\r
117 m_hLineEndingLF = (HICON)::LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_LINEENDINGLF),
\r
118 IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
\r
119 m_hEditedIcon = (HICON)::LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDI_LINEEDITED),
\r
120 IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR);
\r
121 for (int i=0; i<1024; ++i)
\r
122 m_sConflictedText += _T("??");
\r
123 m_sNoLineNr.LoadString(IDS_EMPTYLINETT);
\r
127 CBaseView::~CBaseView()
\r
129 if (m_pCacheBitmap)
\r
131 m_pCacheBitmap->DeleteObject();
\r
132 delete m_pCacheBitmap;
\r
134 for (int i=0; i<MAXFONTS; i++)
\r
136 if (m_apFonts[i] != NULL)
\r
138 m_apFonts[i]->DeleteObject();
\r
139 delete m_apFonts[i];
\r
141 m_apFonts[i] = NULL;
\r
143 DestroyIcon(m_hAddedIcon);
\r
144 DestroyIcon(m_hRemovedIcon);
\r
145 DestroyIcon(m_hConflictedIcon);
\r
146 DestroyIcon(m_hConflictedIgnoredIcon);
\r
147 DestroyIcon(m_hWhitespaceBlockIcon);
\r
148 DestroyIcon(m_hEqualIcon);
\r
149 DestroyIcon(m_hLineEndingCR);
\r
150 DestroyIcon(m_hLineEndingCRLF);
\r
151 DestroyIcon(m_hLineEndingLF);
\r
152 DestroyIcon(m_hEditedIcon);
\r
155 BEGIN_MESSAGE_MAP(CBaseView, CView)
\r
166 ON_WM_CONTEXTMENU()
\r
167 ON_COMMAND(ID_NAVIGATE_NEXTDIFFERENCE, OnMergeNextdifference)
\r
168 ON_COMMAND(ID_NAVIGATE_PREVIOUSDIFFERENCE, OnMergePreviousdifference)
\r
169 ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTW, 0, 0xFFFF, OnToolTipNotify)
\r
170 ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTA, 0, 0xFFFF, OnToolTipNotify)
\r
172 ON_WM_LBUTTONDOWN()
\r
173 ON_COMMAND(ID_EDIT_COPY, OnEditCopy)
\r
175 ON_COMMAND(ID_NAVIGATE_PREVIOUSCONFLICT, OnMergePreviousconflict)
\r
176 ON_COMMAND(ID_NAVIGATE_NEXTCONFLICT, OnMergeNextconflict)
\r
178 ON_COMMAND(ID_CARET_DOWN, &CBaseView::OnCaretDown)
\r
179 ON_COMMAND(ID_CARET_LEFT, &CBaseView::OnCaretLeft)
\r
180 ON_COMMAND(ID_CARET_RIGHT, &CBaseView::OnCaretRight)
\r
181 ON_COMMAND(ID_CARET_UP, &CBaseView::OnCaretUp)
\r
182 ON_COMMAND(ID_CARET_WORDLEFT, &CBaseView::OnCaretWordleft)
\r
183 ON_COMMAND(ID_CARET_WORDRIGHT, &CBaseView::OnCaretWordright)
\r
184 ON_COMMAND(ID_EDIT_CUT, &CBaseView::OnEditCut)
\r
185 ON_COMMAND(ID_EDIT_PASTE, &CBaseView::OnEditPaste)
\r
191 void CBaseView::DocumentUpdated()
\r
193 if (m_pCacheBitmap != NULL)
\r
195 m_pCacheBitmap->DeleteObject();
\r
196 delete m_pCacheBitmap;
\r
197 m_pCacheBitmap = NULL;
\r
199 m_nLineHeight = -1;
\r
201 m_nScreenChars = -1;
\r
202 m_nMaxLineLength = -1;
\r
203 m_nScreenLines = -1;
\r
205 m_bModified = FALSE;
\r
206 m_bOtherDiffChecked = false;
\r
210 m_nTabSize = (int)(DWORD)CRegDWORD(_T("Software\\TortoiseMerge\\TabSize"), 4);
\r
211 m_bViewLinenumbers = CRegDWORD(_T("Software\\TortoiseMerge\\ViewLinenumbers"), 1);
\r
212 m_bShowInlineDiff = CRegDWORD(_T("Software\\TortoiseMerge\\DisplayBinDiff"), TRUE);
\r
213 m_InlineAddedBk = CRegDWORD(_T("Software\\TortoiseMerge\\InlineAdded"), INLINEADDED_COLOR);
\r
214 m_InlineRemovedBk = CRegDWORD(_T("Software\\TortoiseMerge\\InlineRemoved"), INLINEREMOVED_COLOR);
\r
215 m_ModifiedBk = CRegDWORD(_T("Software\\TortoiseMerge\\Colors\\ColorModifiedB"), MODIFIED_COLOR);
\r
216 m_WhiteSpaceFg = CRegDWORD(_T("Software\\TortoiseMerge\\Colors\\Whitespace"), GetSysColor(COLOR_GRAYTEXT));
\r
217 m_bIconLFs = CRegDWORD(_T("Software\\TortoiseMerge\\IconLFs"), 0);
\r
218 for (int i=0; i<MAXFONTS; i++)
\r
220 if (m_apFonts[i] != NULL)
\r
222 m_apFonts[i]->DeleteObject();
\r
223 delete m_apFonts[i];
\r
225 m_apFonts[i] = NULL;
\r
227 m_nSelBlockStart = -1;
\r
228 m_nSelBlockEnd = -1;
\r
229 RecalcVertScrollBar();
\r
230 RecalcHorzScrollBar();
\r
235 void CBaseView::UpdateStatusBar()
\r
237 int nRemovedLines = 0;
\r
238 int nAddedLines = 0;
\r
239 int nConflictedLines = 0;
\r
243 for (int i=0; i<m_pViewData->GetCount(); i++)
\r
245 DiffStates state = m_pViewData->GetState(i);
\r
248 case DIFFSTATE_ADDED:
\r
249 case DIFFSTATE_IDENTICALADDED:
\r
250 case DIFFSTATE_THEIRSADDED:
\r
251 case DIFFSTATE_YOURSADDED:
\r
252 case DIFFSTATE_CONFLICTADDED:
\r
255 case DIFFSTATE_IDENTICALREMOVED:
\r
256 case DIFFSTATE_REMOVED:
\r
257 case DIFFSTATE_THEIRSREMOVED:
\r
258 case DIFFSTATE_YOURSREMOVED:
\r
261 case DIFFSTATE_CONFLICTED:
\r
262 case DIFFSTATE_CONFLICTED_IGNORED:
\r
263 nConflictedLines++;
\r
274 case CFileTextLines::ASCII:
\r
275 sBarText = _T("ASCII ");
\r
277 case CFileTextLines::BINARY:
\r
278 sBarText = _T("BINARY ");
\r
280 case CFileTextLines::UNICODE_LE:
\r
281 sBarText = _T("UTF-16LE ");
\r
283 case CFileTextLines::UTF8:
\r
284 sBarText = _T("UTF8 ");
\r
286 case CFileTextLines::UTF8BOM:
\r
287 sBarText = _T("UTF8 BOM ");
\r
291 switch(lineendings)
\r
294 sBarText += _T("LF ");
\r
297 sBarText += _T("CRLF ");
\r
300 sBarText += _T("LFCR ");
\r
303 sBarText += _T("CR ");
\r
307 if (sBarText.IsEmpty())
\r
308 sBarText += _T(" / ");
\r
312 sTemp.Format(IDS_STATUSBAR_REMOVEDLINES, nRemovedLines);
\r
313 if (!sBarText.IsEmpty())
\r
314 sBarText += _T(" / ");
\r
319 sTemp.Format(IDS_STATUSBAR_ADDEDLINES, nAddedLines);
\r
320 if (!sBarText.IsEmpty())
\r
321 sBarText += _T(" / ");
\r
324 if (nConflictedLines)
\r
326 sTemp.Format(IDS_STATUSBAR_CONFLICTEDLINES, nConflictedLines);
\r
327 if (!sBarText.IsEmpty())
\r
328 sBarText += _T(" / ");
\r
331 if (m_pwndStatusBar)
\r
336 int nIndex = m_pwndStatusBar->CommandToIndex(m_nStatusBarID);
\r
337 if (m_nStatusBarID == ID_INDICATOR_BOTTOMVIEW)
\r
339 sBarText.Format(IDS_STATUSBAR_CONFLICTS, nConflictedLines);
\r
341 if (m_nStatusBarID == ID_INDICATOR_LEFTVIEW)
\r
343 sTemp.LoadString(IDS_STATUSBAR_LEFTVIEW);
\r
344 sBarText = sTemp+sBarText;
\r
346 if (m_nStatusBarID == ID_INDICATOR_RIGHTVIEW)
\r
348 sTemp.LoadString(IDS_STATUSBAR_RIGHTVIEW);
\r
349 sBarText = sTemp+sBarText;
\r
351 m_pwndStatusBar->GetPaneInfo(nIndex, nID, nStyle, cxWidth);
\r
352 //calculate the width of the text
\r
353 CDC * pDC = m_pwndStatusBar->GetDC();
\r
356 CSize size = pDC->GetTextExtent(sBarText);
\r
357 m_pwndStatusBar->SetPaneInfo(nIndex, nID, nStyle, size.cx+2);
\r
360 m_pwndStatusBar->SetPaneText(nIndex, sBarText);
\r
364 BOOL CBaseView::PreCreateWindow(CREATESTRUCT& cs)
\r
366 if (!CView::PreCreateWindow(cs))
\r
369 cs.dwExStyle |= WS_EX_CLIENTEDGE;
\r
370 cs.style &= ~WS_BORDER;
\r
371 cs.lpszClass = AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW|CS_DBLCLKS,
\r
372 ::LoadCursor(NULL, IDC_ARROW), reinterpret_cast<HBRUSH>(COLOR_WINDOW+1), NULL);
\r
374 CWnd *pParentWnd = CWnd::FromHandlePermanent(cs.hwndParent);
\r
375 if (pParentWnd == NULL || ! pParentWnd->IsKindOf(RUNTIME_CLASS(CSplitterWnd)))
\r
377 // View must always create its own scrollbars,
\r
378 // if only it's not used within splitter
\r
379 cs.style |= (WS_HSCROLL | WS_VSCROLL);
\r
381 cs.lpszClass = AfxRegisterWndClass(CS_DBLCLKS);
\r
385 CFont* CBaseView::GetFont(BOOL bItalic /*= FALSE*/, BOOL bBold /*= FALSE*/, BOOL bStrikeOut /*= FALSE*/)
\r
394 if (m_apFonts[nIndex] == NULL)
\r
396 m_apFonts[nIndex] = new CFont;
\r
397 m_lfBaseFont.lfCharSet = DEFAULT_CHARSET;
\r
398 m_lfBaseFont.lfWeight = bBold ? FW_BOLD : FW_NORMAL;
\r
399 m_lfBaseFont.lfItalic = (BYTE) bItalic;
\r
400 m_lfBaseFont.lfStrikeOut = (BYTE) bStrikeOut;
\r
402 m_lfBaseFont.lfStrikeOut = (BYTE)(DWORD)CRegDWORD(_T("Software\\TortoiseMerge\\StrikeOut"), TRUE);
\r
403 CDC * pDC = GetDC();
\r
406 m_lfBaseFont.lfHeight = -MulDiv((DWORD)CRegDWORD(_T("Software\\TortoiseMerge\\LogFontSize"), 10), GetDeviceCaps(pDC->m_hDC, LOGPIXELSY), 72);
\r
409 _tcsncpy_s(m_lfBaseFont.lfFaceName, 32, (LPCTSTR)(CString)CRegString(_T("Software\\TortoiseMerge\\LogFontName"), _T("Courier New")), 32);
\r
410 if (!m_apFonts[nIndex]->CreateFontIndirect(&m_lfBaseFont))
\r
412 delete m_apFonts[nIndex];
\r
413 m_apFonts[nIndex] = NULL;
\r
414 return CView::GetFont();
\r
417 return m_apFonts[nIndex];
\r
420 void CBaseView::CalcLineCharDim()
\r
422 CDC *pDC = GetDC();
\r
423 CFont *pOldFont = pDC->SelectObject(GetFont());
\r
424 CSize szCharExt = pDC->GetTextExtent(_T("X"));
\r
425 m_nLineHeight = szCharExt.cy;
\r
426 if (m_nLineHeight <= 0)
\r
427 m_nLineHeight = -1;
\r
428 m_nCharWidth = szCharExt.cx;
\r
429 if (m_nCharWidth <= 0)
\r
431 pDC->SelectObject(pOldFont);
\r
435 int CBaseView::GetScreenChars()
\r
437 if (m_nScreenChars == -1)
\r
440 GetClientRect(&rect);
\r
441 m_nScreenChars = (rect.Width() - GetMarginWidth()) / GetCharWidth();
\r
443 return m_nScreenChars;
\r
446 int CBaseView::GetAllMinScreenChars() const
\r
449 if (IsLeftViewGood())
\r
450 nChars = m_pwndLeft->GetScreenChars();
\r
451 if (IsRightViewGood())
\r
452 nChars = (nChars < m_pwndRight->GetScreenChars() ? nChars : m_pwndRight->GetScreenChars());
\r
453 if (IsBottomViewGood())
\r
454 nChars = (nChars < m_pwndBottom->GetScreenChars() ? nChars : m_pwndBottom->GetScreenChars());
\r
458 int CBaseView::GetAllMaxLineLength() const
\r
461 if (IsLeftViewGood())
\r
462 nLength = m_pwndLeft->GetMaxLineLength();
\r
463 if (IsRightViewGood())
\r
464 nLength = (nLength > m_pwndRight->GetMaxLineLength() ? nLength : m_pwndRight->GetMaxLineLength());
\r
465 if (IsBottomViewGood())
\r
466 nLength = (nLength > m_pwndBottom->GetMaxLineLength() ? nLength : m_pwndBottom->GetMaxLineLength());
\r
470 int CBaseView::GetLineHeight()
\r
472 if (m_nLineHeight == -1)
\r
474 if (m_nLineHeight <= 0)
\r
476 return m_nLineHeight;
\r
479 int CBaseView::GetCharWidth()
\r
481 if (m_nCharWidth == -1)
\r
483 if (m_nCharWidth <= 0)
\r
485 return m_nCharWidth;
\r
488 int CBaseView::GetMaxLineLength()
\r
490 if (m_nMaxLineLength == -1)
\r
492 m_nMaxLineLength = 0;
\r
493 int nLineCount = GetLineCount();
\r
494 for (int i=0; i<nLineCount; i++)
\r
496 int nActualLength = GetLineActualLength(i);
\r
497 if (m_nMaxLineLength < nActualLength)
\r
498 m_nMaxLineLength = nActualLength;
\r
501 return m_nMaxLineLength;
\r
504 int CBaseView::GetLineActualLength(int index) const
\r
506 if (m_pViewData == NULL)
\r
509 return CalculateActualOffset(index, GetLineLength(index));
\r
512 int CBaseView::GetLineLength(int index) const
\r
514 if (m_pViewData == NULL)
\r
516 if (m_pViewData->GetCount() == 0)
\r
518 int nLineLength = m_pViewData->GetLine(index).GetLength();
\r
519 ASSERT(nLineLength >= 0);
\r
520 return nLineLength;
\r
523 int CBaseView::GetLineCount() const
\r
525 if (m_pViewData == NULL)
\r
527 int nLineCount = m_pViewData->GetCount();
\r
528 ASSERT(nLineCount >= 0);
\r
532 LPCTSTR CBaseView::GetLineChars(int index) const
\r
534 if (m_pViewData == NULL)
\r
536 if (m_pViewData->GetCount() == 0)
\r
538 return m_pViewData->GetLine(index);
\r
541 void CBaseView::CheckOtherView()
\r
543 if (m_bOtherDiffChecked)
\r
545 // find out what the 'other' file is
\r
546 m_pOtherViewData = NULL;
\r
547 if (this == m_pwndLeft && IsRightViewGood())
\r
548 m_pOtherViewData = m_pwndRight->m_pViewData;
\r
550 if (this == m_pwndRight && IsLeftViewGood())
\r
551 m_pOtherViewData = m_pwndLeft->m_pViewData;
\r
553 m_bOtherDiffChecked = true;
\r
556 CString CBaseView::GetWhitespaceBlock(CViewData *viewData, int nLineIndex)
\r
558 enum { MAX_WHITESPACEBLOCK_SIZE = 8 };
\r
561 DiffStates origstate = viewData->GetState(nLineIndex);
\r
563 // Go back and forward at most MAX_WHITESPACEBLOCK_SIZE lines to see where this block ends
\r
564 int nStartBlock = nLineIndex;
\r
565 int nEndBlock = nLineIndex;
\r
566 while ((nStartBlock > 0) && (nStartBlock > (nLineIndex - MAX_WHITESPACEBLOCK_SIZE)))
\r
568 DiffStates state = viewData->GetState(nStartBlock - 1);
\r
569 if ((origstate == DIFFSTATE_EMPTY) && (state != DIFFSTATE_NORMAL))
\r
571 if ((origstate == state) || (state == DIFFSTATE_EMPTY))
\r
576 while ((nEndBlock < (viewData->GetCount() - 1)) && (nEndBlock < (nLineIndex + MAX_WHITESPACEBLOCK_SIZE)))
\r
578 DiffStates state = viewData->GetState(nEndBlock + 1);
\r
579 if ((origstate == DIFFSTATE_EMPTY) && (state != DIFFSTATE_NORMAL))
\r
581 if ((origstate == state) || (state == DIFFSTATE_EMPTY))
\r
588 for (int i = nStartBlock; i <= nEndBlock; ++i)
\r
589 block += viewData->GetLine(i);
\r
593 bool CBaseView::IsBlockWhitespaceOnly(int nLineIndex, bool& bIdentical)
\r
595 enum { MAX_WHITESPACEBLOCK_SIZE = 8 };
\r
597 if (!m_pOtherViewData)
\r
600 (m_pViewData->GetState(nLineIndex) == DIFFSTATE_NORMAL) &&
\r
601 (m_pOtherViewData->GetLine(nLineIndex) == m_pViewData->GetLine(nLineIndex))
\r
605 CString mine = GetWhitespaceBlock(m_pViewData, nLineIndex);
\r
606 CString other = GetWhitespaceBlock(m_pOtherViewData, min(nLineIndex, m_pOtherViewData->GetCount() - 1));
\r
607 bIdentical = mine == other;
\r
609 mine.Replace(_T(" "), _T(""));
\r
610 mine.Replace(_T("\t"), _T(""));
\r
611 mine.Replace(_T("\r"), _T(""));
\r
612 mine.Replace(_T("\n"), _T(""));
\r
613 other.Replace(_T(" "), _T(""));
\r
614 other.Replace(_T("\t"), _T(""));
\r
615 other.Replace(_T("\r"), _T(""));
\r
616 other.Replace(_T("\n"), _T(""));
\r
618 return (mine == other) && (!mine.IsEmpty());
\r
621 int CBaseView::GetLineNumber(int index) const
\r
623 if (m_pViewData == NULL)
\r
625 if (m_pViewData->GetLineNumber(index)==DIFF_EMPTYLINENUMBER)
\r
627 return m_pViewData->GetLineNumber(index);
\r
630 int CBaseView::GetScreenLines()
\r
632 if (m_nScreenLines == -1)
\r
635 sbi.cbSize = sizeof(sbi);
\r
636 GetScrollBarInfo(OBJID_HSCROLL, &sbi);
\r
637 int scrollBarHeight = sbi.rcScrollBar.bottom - sbi.rcScrollBar.top;
\r
640 GetClientRect(&rect);
\r
641 m_nScreenLines = (rect.Height() - HEADERHEIGHT - scrollBarHeight) / GetLineHeight();
\r
643 return m_nScreenLines;
\r
646 int CBaseView::GetAllMinScreenLines() const
\r
649 if (IsLeftViewGood())
\r
650 nLines = m_pwndLeft->GetScreenLines();
\r
651 if (IsRightViewGood())
\r
652 nLines = (nLines < m_pwndRight->GetScreenLines() ? nLines : m_pwndRight->GetScreenLines());
\r
653 if (IsBottomViewGood())
\r
654 nLines = (nLines < m_pwndBottom->GetScreenLines() ? nLines : m_pwndBottom->GetScreenLines());
\r
658 int CBaseView::GetAllLineCount() const
\r
661 if (IsLeftViewGood())
\r
662 nLines = m_pwndLeft->GetLineCount();
\r
663 if (IsRightViewGood())
\r
664 nLines = (nLines > m_pwndRight->GetLineCount() ? nLines : m_pwndRight->GetLineCount());
\r
665 if (IsBottomViewGood())
\r
666 nLines = (nLines > m_pwndBottom->GetLineCount() ? nLines : m_pwndBottom->GetLineCount());
\r
670 void CBaseView::RecalcAllVertScrollBars(BOOL bPositionOnly /*= FALSE*/)
\r
672 if (IsLeftViewGood())
\r
673 m_pwndLeft->RecalcVertScrollBar(bPositionOnly);
\r
674 if (IsRightViewGood())
\r
675 m_pwndRight->RecalcVertScrollBar(bPositionOnly);
\r
676 if (IsBottomViewGood())
\r
677 m_pwndBottom->RecalcVertScrollBar(bPositionOnly);
\r
680 void CBaseView::RecalcVertScrollBar(BOOL bPositionOnly /*= FALSE*/)
\r
683 si.cbSize = sizeof(si);
\r
686 si.fMask = SIF_POS;
\r
687 si.nPos = m_nTopLine;
\r
691 EnableScrollBarCtrl(SB_VERT, TRUE);
\r
692 if (GetAllMinScreenLines() >= GetAllLineCount() && m_nTopLine > 0)
\r
697 si.fMask = SIF_DISABLENOSCROLL | SIF_PAGE | SIF_POS | SIF_RANGE;
\r
699 si.nMax = GetAllLineCount();
\r
700 si.nPage = GetAllMinScreenLines();
\r
701 si.nPos = m_nTopLine;
\r
703 VERIFY(SetScrollInfo(SB_VERT, &si));
\r
706 void CBaseView::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
\r
708 CView::OnVScroll(nSBCode, nPos, pScrollBar);
\r
710 m_pwndLeft->OnDoVScroll(nSBCode, nPos, pScrollBar, this);
\r
712 m_pwndRight->OnDoVScroll(nSBCode, nPos, pScrollBar, this);
\r
714 m_pwndBottom->OnDoVScroll(nSBCode, nPos, pScrollBar, this);
\r
716 m_pwndLocator->Invalidate();
\r
719 void CBaseView::OnDoVScroll(UINT nSBCode, UINT /*nPos*/, CScrollBar* /*pScrollBar*/, CBaseView * master)
\r
721 // Note we cannot use nPos because of its 16-bit nature
\r
723 si.cbSize = sizeof(si);
\r
724 si.fMask = SIF_ALL;
\r
725 VERIFY(master->GetScrollInfo(SB_VERT, &si));
\r
727 int nPageLines = GetScreenLines();
\r
728 int nLineCount = GetLineCount();
\r
734 static LONG textwidth = 0;
\r
735 static CString sFormat(MAKEINTRESOURCE(IDS_VIEWSCROLLTIPTEXT));
\r
742 nNewTopLine = nLineCount - nPageLines + 1;
\r
745 nNewTopLine = m_nTopLine - 1;
\r
748 nNewTopLine = m_nTopLine + 1;
\r
751 nNewTopLine = m_nTopLine - si.nPage + 1;
\r
754 nNewTopLine = m_nTopLine + si.nPage - 1;
\r
756 case SB_THUMBPOSITION:
\r
757 m_ScrollTool.Clear();
\r
758 nNewTopLine = si.nTrackPos;
\r
761 case SB_THUMBTRACK:
\r
762 nNewTopLine = si.nTrackPos;
\r
763 if (GetFocus() == this)
\r
765 GetClientRect(&thumbrect);
\r
766 ClientToScreen(&thumbrect);
\r
767 thumbpoint.x = thumbrect.right;
\r
768 thumbpoint.y = thumbrect.top + ((thumbrect.bottom-thumbrect.top)*si.nTrackPos)/(si.nMax-si.nMin);
\r
769 m_ScrollTool.Init(&thumbpoint);
\r
770 if (textwidth == 0)
\r
772 CString sTemp = sFormat;
\r
773 sTemp.Format(sFormat, m_nDigits, 10*m_nDigits-1);
\r
774 textwidth = m_ScrollTool.GetTextWidth(sTemp);
\r
776 thumbpoint.x -= textwidth;
\r
777 int line = GetLineNumber(nNewTopLine);
\r
779 m_ScrollTool.SetText(&thumbpoint, sFormat, m_nDigits, GetLineNumber(nNewTopLine)+1);
\r
781 m_ScrollTool.SetText(&thumbpoint, m_sNoLineNr);
\r
788 if (nNewTopLine < 0)
\r
790 if (nNewTopLine >= nLineCount)
\r
791 nNewTopLine = nLineCount - 1;
\r
792 ScrollToLine(nNewTopLine);
\r
795 void CBaseView::RecalcAllHorzScrollBars(BOOL bPositionOnly /*= FALSE*/)
\r
797 if (IsLeftViewGood())
\r
798 m_pwndLeft->RecalcHorzScrollBar(bPositionOnly);
\r
799 if (IsRightViewGood())
\r
800 m_pwndRight->RecalcHorzScrollBar(bPositionOnly);
\r
801 if (IsBottomViewGood())
\r
802 m_pwndBottom->RecalcHorzScrollBar(bPositionOnly);
\r
805 void CBaseView::RecalcHorzScrollBar(BOOL bPositionOnly /*= FALSE*/)
\r
808 si.cbSize = sizeof(si);
\r
811 si.fMask = SIF_POS;
\r
812 si.nPos = m_nOffsetChar;
\r
816 EnableScrollBarCtrl(SB_HORZ, TRUE);
\r
817 if (GetAllMinScreenChars() >= GetAllMaxLineLength() && m_nOffsetChar > 0)
\r
822 si.fMask = SIF_DISABLENOSCROLL | SIF_PAGE | SIF_POS | SIF_RANGE;
\r
824 si.nMax = GetAllMaxLineLength() + GetMarginWidth()/GetCharWidth();
\r
825 si.nPage = GetAllMinScreenChars();
\r
826 si.nPos = m_nOffsetChar;
\r
828 VERIFY(SetScrollInfo(SB_HORZ, &si));
\r
831 void CBaseView::OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar)
\r
833 CView::OnHScroll(nSBCode, nPos, pScrollBar);
\r
835 m_pwndLeft->OnDoHScroll(nSBCode, nPos, pScrollBar, this);
\r
837 m_pwndRight->OnDoHScroll(nSBCode, nPos, pScrollBar, this);
\r
839 m_pwndBottom->OnDoHScroll(nSBCode, nPos, pScrollBar, this);
\r
841 m_pwndLocator->Invalidate();
\r
844 void CBaseView::OnDoHScroll(UINT nSBCode, UINT /*nPos*/, CScrollBar* /*pScrollBar*/, CBaseView * master)
\r
847 si.cbSize = sizeof(si);
\r
848 si.fMask = SIF_ALL;
\r
849 VERIFY(master->GetScrollInfo(SB_HORZ, &si));
\r
851 int nPageChars = GetScreenChars();
\r
852 int nMaxLineLength = GetMaxLineLength();
\r
861 nNewOffset = nMaxLineLength - nPageChars + 1;
\r
864 nNewOffset = m_nOffsetChar - 1;
\r
867 nNewOffset = m_nOffsetChar + 1;
\r
870 nNewOffset = m_nOffsetChar - si.nPage + 1;
\r
873 nNewOffset = m_nOffsetChar + si.nPage - 1;
\r
875 case SB_THUMBPOSITION:
\r
876 case SB_THUMBTRACK:
\r
877 nNewOffset = si.nTrackPos;
\r
883 if (nNewOffset >= nMaxLineLength)
\r
884 nNewOffset = nMaxLineLength - 1;
\r
885 if (nNewOffset < 0)
\r
887 ScrollToChar(nNewOffset, TRUE);
\r
890 void CBaseView::ScrollToChar(int nNewOffsetChar, BOOL bTrackScrollBar /*= TRUE*/)
\r
892 if (m_nOffsetChar != nNewOffsetChar)
\r
894 int nScrollChars = m_nOffsetChar - nNewOffsetChar;
\r
895 m_nOffsetChar = nNewOffsetChar;
\r
897 GetClientRect(&rcScroll);
\r
898 rcScroll.left += GetMarginWidth();
\r
899 rcScroll.top += GetLineHeight()+HEADERHEIGHT;
\r
900 ScrollWindow(nScrollChars * GetCharWidth(), 0, &rcScroll, &rcScroll);
\r
901 // update the view header
\r
904 rcScroll.bottom = GetLineHeight()+HEADERHEIGHT;
\r
905 InvalidateRect(&rcScroll, FALSE);
\r
907 if (bTrackScrollBar)
\r
908 RecalcHorzScrollBar(TRUE);
\r
913 void CBaseView::ScrollSide(int delta)
\r
915 int nNewOffset = m_nOffsetChar;
\r
916 nNewOffset += delta;
\r
917 int nMaxLineLength = GetMaxLineLength();
\r
918 if (nNewOffset >= nMaxLineLength)
\r
919 nNewOffset = nMaxLineLength - 1;
\r
920 if (nNewOffset < 0)
\r
922 ScrollToChar(nNewOffset, TRUE);
\r
923 if (m_pwndLineDiffBar)
\r
924 m_pwndLineDiffBar->Invalidate();
\r
928 void CBaseView::ScrollToLine(int nNewTopLine, BOOL bTrackScrollBar /*= TRUE*/)
\r
930 if (m_nTopLine != nNewTopLine)
\r
932 if (nNewTopLine < 0)
\r
934 int nScrollLines = m_nTopLine - nNewTopLine;
\r
935 m_nTopLine = nNewTopLine;
\r
937 GetClientRect(&rcScroll);
\r
938 rcScroll.top += GetLineHeight()+HEADERHEIGHT;
\r
939 ScrollWindow(0, nScrollLines * GetLineHeight(), &rcScroll, &rcScroll);
\r
941 if (bTrackScrollBar)
\r
942 RecalcVertScrollBar(TRUE);
\r
948 void CBaseView::DrawMargin(CDC *pdc, const CRect &rect, int nLineIndex)
\r
950 pdc->FillSolidRect(rect, ::GetSysColor(COLOR_SCROLLBAR));
\r
952 if ((nLineIndex >= 0)&&(m_pViewData)&&(m_pViewData->GetCount()))
\r
954 DiffStates state = m_pViewData->GetState(nLineIndex);
\r
958 case DIFFSTATE_ADDED:
\r
959 case DIFFSTATE_THEIRSADDED:
\r
960 case DIFFSTATE_YOURSADDED:
\r
961 case DIFFSTATE_IDENTICALADDED:
\r
962 case DIFFSTATE_CONFLICTADDED:
\r
963 icon = m_hAddedIcon;
\r
965 case DIFFSTATE_REMOVED:
\r
966 case DIFFSTATE_THEIRSREMOVED:
\r
967 case DIFFSTATE_YOURSREMOVED:
\r
968 case DIFFSTATE_IDENTICALREMOVED:
\r
969 icon = m_hRemovedIcon;
\r
971 case DIFFSTATE_CONFLICTED:
\r
972 icon = m_hConflictedIcon;
\r
974 case DIFFSTATE_CONFLICTED_IGNORED:
\r
975 icon = m_hConflictedIgnoredIcon;
\r
977 case DIFFSTATE_EDITED:
\r
978 icon = m_hEditedIcon;
\r
983 bool bIdentical = false;
\r
984 if ((state != DIFFSTATE_EDITED)&&(IsBlockWhitespaceOnly(nLineIndex, bIdentical)))
\r
987 icon = m_hEqualIcon;
\r
989 icon = m_hWhitespaceBlockIcon;
\r
994 ::DrawIconEx(pdc->m_hDC, rect.left + 2, rect.top + (rect.Height()-16)/2, icon, 16, 16, NULL, NULL, DI_NORMAL);
\r
996 if ((m_bViewLinenumbers)&&(m_nDigits))
\r
998 int nLineNumber = GetLineNumber(nLineIndex);
\r
999 if (nLineNumber >= 0)
\r
1001 CString sLinenumberFormat;
\r
1002 CString sLinenumber;
\r
1003 sLinenumberFormat.Format(_T("%%%dd"), m_nDigits);
\r
1004 sLinenumber.Format(sLinenumberFormat, nLineNumber+1);
\r
1005 pdc->SetBkColor(::GetSysColor(COLOR_SCROLLBAR));
\r
1006 pdc->SetTextColor(::GetSysColor(COLOR_WINDOWTEXT));
\r
1008 pdc->SelectObject(GetFont());
\r
1009 pdc->ExtTextOut(rect.left + 18, rect.top, ETO_CLIPPED, &rect, sLinenumber, NULL);
\r
1015 int CBaseView::GetMarginWidth()
\r
1017 if ((m_bViewLinenumbers)&&(m_pViewData)&&(m_pViewData->GetCount()))
\r
1019 int nWidth = GetCharWidth();
\r
1020 if (m_nDigits <= 0)
\r
1022 int nLength = (int)m_pViewData->GetCount();
\r
1023 // find out how many digits are needed to show the highest line number
\r
1025 while (nLength / 10)
\r
1030 m_nDigits = nDigits;
\r
1032 return (MARGINWIDTH + (m_nDigits * nWidth) + 2);
\r
1034 return MARGINWIDTH;
\r
1037 void CBaseView::DrawHeader(CDC *pdc, const CRect &rect)
\r
1039 CRect textrect(rect.left, rect.top, rect.Width(), GetLineHeight()+HEADERHEIGHT);
\r
1040 COLORREF crBk, crFg;
\r
1041 CDiffColors::GetInstance().GetColors(DIFFSTATE_NORMAL, crBk, crFg);
\r
1042 crBk = ::GetSysColor(COLOR_SCROLLBAR);
\r
1043 if (IsBottomViewGood())
\r
1045 pdc->SetBkColor(crBk);
\r
1050 if (this == m_pwndRight)
\r
1052 CDiffColors::GetInstance().GetColors(DIFFSTATE_ADDED, crBk, crFg);
\r
1053 pdc->SetBkColor(crBk);
\r
1057 CDiffColors::GetInstance().GetColors(DIFFSTATE_REMOVED, crBk, crFg);
\r
1058 pdc->SetBkColor(crBk);
\r
1061 pdc->FillSolidRect(textrect, crBk);
\r
1063 pdc->SetTextColor(crFg);
\r
1065 pdc->SelectObject(GetFont(FALSE, TRUE, FALSE));
\r
1068 if (m_sWindowName.Left(2).Compare(_T("* "))!=0)
\r
1069 m_sWindowName = _T("* ") + m_sWindowName;
\r
1073 if (m_sWindowName.Left(2).Compare(_T("* "))==0)
\r
1074 m_sWindowName = m_sWindowName.Mid(2);
\r
1076 CString sViewTitle = m_sWindowName;
\r
1077 int nStringLength = (GetCharWidth()*m_sWindowName.GetLength());
\r
1078 if (nStringLength > rect.Width())
\r
1080 int offset = min(m_nOffsetChar, (nStringLength-rect.Width())/GetCharWidth()+1);
\r
1082 sViewTitle = m_sWindowName.Mid(offset);
\r
1084 pdc->ExtTextOut(max(rect.left + (rect.Width()-nStringLength)/2, 1),
\r
1085 rect.top+(HEADERHEIGHT/2), ETO_CLIPPED, textrect, sViewTitle, NULL);
\r
1086 if (this->GetFocus() == this)
\r
1087 pdc->DrawEdge(textrect, EDGE_BUMP, BF_RECT);
\r
1089 pdc->DrawEdge(textrect, EDGE_ETCHED, BF_RECT);
\r
1092 void CBaseView::OnDraw(CDC * pDC)
\r
1095 GetClientRect(rcClient);
\r
1097 int nLineCount = GetLineCount();
\r
1098 int nLineHeight = GetLineHeight();
\r
1101 VERIFY(cacheDC.CreateCompatibleDC(pDC));
\r
1102 if (m_pCacheBitmap == NULL)
\r
1104 m_pCacheBitmap = new CBitmap;
\r
1105 VERIFY(m_pCacheBitmap->CreateCompatibleBitmap(pDC, rcClient.Width(), nLineHeight));
\r
1107 CBitmap *pOldBitmap = cacheDC.SelectObject(m_pCacheBitmap);
\r
1109 DrawHeader(pDC, rcClient);
\r
1112 rcLine = rcClient;
\r
1113 rcLine.top += nLineHeight+HEADERHEIGHT;
\r
1114 rcLine.bottom = rcLine.top + nLineHeight;
\r
1115 CRect rcCacheMargin(0, 0, GetMarginWidth(), nLineHeight);
\r
1116 CRect rcCacheLine(GetMarginWidth(), 0, rcLine.Width(), nLineHeight);
\r
1118 int nCurrentLine = m_nTopLine;
\r
1119 while (rcLine.top < rcClient.bottom)
\r
1121 if (nCurrentLine < nLineCount)
\r
1123 DrawMargin(&cacheDC, rcCacheMargin, nCurrentLine);
\r
1124 DrawSingleLine(&cacheDC, rcCacheLine, nCurrentLine);
\r
1128 DrawMargin(&cacheDC, rcCacheMargin, -1);
\r
1129 DrawSingleLine(&cacheDC, rcCacheLine, -1);
\r
1132 VERIFY(pDC->BitBlt(rcLine.left, rcLine.top, rcLine.Width(), rcLine.Height(), &cacheDC, 0, 0, SRCCOPY));
\r
1135 rcLine.OffsetRect(0, nLineHeight);
\r
1138 cacheDC.SelectObject(pOldBitmap);
\r
1139 cacheDC.DeleteDC();
\r
1142 BOOL CBaseView::IsLineRemoved(int nLineIndex)
\r
1144 DiffStates state = DIFFSTATE_UNKNOWN;
\r
1146 state = m_pViewData->GetState(nLineIndex);
\r
1150 case DIFFSTATE_REMOVED:
\r
1151 case DIFFSTATE_THEIRSREMOVED:
\r
1152 case DIFFSTATE_YOURSREMOVED:
\r
1153 case DIFFSTATE_IDENTICALREMOVED:
\r
1163 bool CBaseView::IsLineConflicted(int nLineIndex)
\r
1165 DiffStates state = DIFFSTATE_UNKNOWN;
\r
1167 state = m_pViewData->GetState(nLineIndex);
\r
1171 case DIFFSTATE_CONFLICTED:
\r
1172 case DIFFSTATE_CONFLICTED_IGNORED:
\r
1173 case DIFFSTATE_CONFLICTEMPTY:
\r
1174 case DIFFSTATE_CONFLICTADDED:
\r
1184 COLORREF CBaseView::IntenseColor(long scale, COLORREF col)
\r
1186 // if the color is already dark (gray scale below 127),
\r
1187 // then lighten the color by 'scale', otherwise darken it
\r
1188 int Gray = (((int)GetRValue(col)) + GetGValue(col) + GetBValue(col))/3;
\r
1191 long red = MulDiv(GetRValue(col),(255-scale),255);
\r
1192 long green = MulDiv(GetGValue(col),(255-scale),255);
\r
1193 long blue = MulDiv(GetBValue(col),(255-scale),255);
\r
1195 return RGB(red, green, blue);
\r
1197 long R = MulDiv(255-GetRValue(col),scale,255)+GetRValue(col);
\r
1198 long G = MulDiv(255-GetGValue(col),scale,255)+GetGValue(col);
\r
1199 long B = MulDiv(255-GetBValue(col),scale,255)+GetBValue(col);
\r
1201 return RGB(R, G, B);
\r
1204 COLORREF CBaseView::InlineDiffColor(int nLineIndex)
\r
1206 return IsLineRemoved(nLineIndex) ? m_InlineRemovedBk : m_InlineAddedBk;
\r
1209 void CBaseView::DrawLineEnding(CDC *pDC, const CRect &rc, int nLineIndex, const CPoint& origin)
\r
1211 if (!(m_bViewWhitespace && m_pViewData && (nLineIndex >= 0) && (nLineIndex < m_pViewData->GetCount())))
\r
1214 EOL ending = m_pViewData->GetLineEnding(nLineIndex);
\r
1217 HICON hEndingIcon = NULL;
\r
1220 case EOL_CR: hEndingIcon = m_hLineEndingCR; break;
\r
1221 case EOL_CRLF: hEndingIcon = m_hLineEndingCRLF; break;
\r
1222 case EOL_LF: hEndingIcon = m_hLineEndingLF; break;
\r
1225 if (origin.x < (rc.left-GetCharWidth()))
\r
1227 // If EOL style has changed, color end-of-line markers as inline differences.
\r
1229 m_bShowInlineDiff && m_pOtherViewData &&
\r
1230 (nLineIndex < m_pOtherViewData->GetCount()) &&
\r
1231 (ending != EOL_NOENDING) &&
\r
1232 (ending != m_pOtherViewData->GetLineEnding(nLineIndex) &&
\r
1233 (m_pOtherViewData->GetLineEnding(nLineIndex) != EOL_NOENDING))
\r
1236 pDC->FillSolidRect(origin.x, origin.y, rc.Height(), rc.Height(), InlineDiffColor(nLineIndex));
\r
1239 DrawIconEx(pDC->GetSafeHdc(), origin.x, origin.y, hEndingIcon, rc.Height(), rc.Height(), NULL, NULL, DI_NORMAL);
\r
1243 CPen pen(PS_SOLID, 0, m_WhiteSpaceFg);
\r
1244 CPen * oldpen = pDC->SelectObject(&pen);
\r
1245 int yMiddle = origin.y + rc.Height()/2;
\r
1246 int xMiddle = origin.x+GetCharWidth()/2;
\r
1250 // arrow from right to left
\r
1251 pDC->MoveTo(origin.x+GetCharWidth(), yMiddle);
\r
1252 pDC->LineTo(origin.x, yMiddle);
\r
1253 pDC->LineTo(origin.x+4, yMiddle+4);
\r
1254 pDC->MoveTo(origin.x, yMiddle);
\r
1255 pDC->LineTo(origin.x+4, yMiddle-4);
\r
1258 // arrow from top to middle+2, then left
\r
1259 pDC->MoveTo(origin.x+GetCharWidth(), rc.top);
\r
1260 pDC->LineTo(origin.x+GetCharWidth(), yMiddle);
\r
1261 pDC->LineTo(origin.x, yMiddle);
\r
1262 pDC->LineTo(origin.x+4, yMiddle+4);
\r
1263 pDC->MoveTo(origin.x, yMiddle);
\r
1264 pDC->LineTo(origin.x+4, yMiddle-4);
\r
1267 // arrow from top to bottom
\r
1268 pDC->MoveTo(xMiddle, rc.top);
\r
1269 pDC->LineTo(xMiddle, rc.bottom-1);
\r
1270 pDC->LineTo(xMiddle+4, rc.bottom-5);
\r
1271 pDC->MoveTo(xMiddle, rc.bottom-1);
\r
1272 pDC->LineTo(xMiddle-4, rc.bottom-5);
\r
1275 pDC->SelectObject(oldpen);
\r
1279 void CBaseView::DrawBlockLine(CDC *pDC, const CRect &rc, int nLineIndex)
\r
1281 const int THICKNESS = 2;
\r
1282 COLORREF rectcol = GetSysColor(m_bFocused ? COLOR_WINDOWTEXT : COLOR_GRAYTEXT);
\r
1283 if ((nLineIndex == m_nSelBlockStart) && m_bShowSelection)
\r
1285 pDC->FillSolidRect(rc.left, rc.top, rc.Width(), THICKNESS, rectcol);
\r
1287 if ((nLineIndex == m_nSelBlockEnd) && m_bShowSelection)
\r
1289 pDC->FillSolidRect(rc.left, rc.bottom - THICKNESS, rc.Width(), THICKNESS, rectcol);
\r
1293 void CBaseView::DrawText(
\r
1294 CDC * pDC, const CRect &rc, LPCTSTR text, int textlength, int nLineIndex, POINT coords, bool bModified, bool bInlineDiff)
\r
1296 ASSERT(m_pViewData && (nLineIndex < m_pViewData->GetCount()));
\r
1297 DiffStates diffState = m_pViewData->GetState(nLineIndex);
\r
1299 // first suppose the whole line is selected
\r
1300 int selectedStart = 0, selectedEnd = textlength;
\r
1302 if ((m_ptSelectionStartPos.y > nLineIndex) || (m_ptSelectionEndPos.y < nLineIndex)
\r
1303 || ! m_bShowSelection)
\r
1305 // this line has no selected text
\r
1306 selectedStart = textlength;
\r
1308 else if ((m_ptSelectionStartPos.y == nLineIndex) || (m_ptSelectionEndPos.y == nLineIndex))
\r
1310 // the line is partially selected
\r
1311 int xoffs = m_nOffsetChar + (coords.x - GetMarginWidth()) / GetCharWidth();
\r
1312 if (m_ptSelectionStartPos.y == nLineIndex)
\r
1314 // the first line of selection
\r
1315 int nSelectionStartOffset = CalculateActualOffset(m_ptSelectionStartPos.y, m_ptSelectionStartPos.x);
\r
1316 selectedStart = max(min(nSelectionStartOffset - xoffs, textlength), 0);
\r
1319 if (m_ptSelectionEndPos.y == nLineIndex)
\r
1321 // the last line of selection
\r
1322 int nSelectionEndOffset = CalculateActualOffset(m_ptSelectionEndPos.y, m_ptSelectionEndPos.x);
\r
1323 selectedEnd = max(min(nSelectionEndOffset - xoffs, textlength), 0);
\r
1327 COLORREF crBkgnd, crText;
\r
1328 CDiffColors::GetInstance().GetColors(diffState, crBkgnd, crText);
\r
1329 if (bModified || (diffState == DIFFSTATE_EDITED))
\r
1330 crBkgnd = m_ModifiedBk;
\r
1332 crBkgnd = InlineDiffColor(nLineIndex);
\r
1334 pDC->SetBkColor(crBkgnd);
\r
1335 pDC->SetTextColor(crText);
\r
1336 if (selectedStart>=0)
\r
1337 VERIFY(pDC->ExtTextOut(coords.x, coords.y, ETO_CLIPPED, &rc, text, selectedStart, NULL));
\r
1339 long intenseColorScale = m_bFocused ? 70 : 30;
\r
1340 pDC->SetBkColor(IntenseColor(intenseColorScale, crBkgnd));
\r
1341 pDC->SetTextColor(IntenseColor(intenseColorScale, crText));
\r
1342 VERIFY(pDC->ExtTextOut(
\r
1343 coords.x + selectedStart * GetCharWidth(), coords.y, ETO_CLIPPED, &rc,
\r
1344 text + selectedStart, selectedEnd - selectedStart, NULL));
\r
1346 pDC->SetBkColor(crBkgnd);
\r
1347 pDC->SetTextColor(crText);
\r
1348 if (textlength - selectedEnd >= 0)
\r
1349 VERIFY(pDC->ExtTextOut(
\r
1350 coords.x + selectedEnd * GetCharWidth(), coords.y, ETO_CLIPPED, &rc,
\r
1351 text + selectedEnd, textlength - selectedEnd, NULL));
\r
1354 bool CBaseView::DrawInlineDiff(CDC *pDC, const CRect &rc, int nLineIndex, const CString &line, CPoint &origin)
\r
1356 if (!m_bShowInlineDiff || line.IsEmpty())
\r
1358 if ((m_pwndBottom != NULL) && !(m_pwndBottom->IsHidden()))
\r
1361 LPCTSTR pszDiffChars = NULL;
\r
1362 int nDiffLength = 0;
\r
1363 if (m_pOtherViewData)
\r
1365 int index = min(nLineIndex, m_pOtherViewData->GetCount() - 1);
\r
1366 pszDiffChars = m_pOtherViewData->GetLine(index);
\r
1367 nDiffLength = m_pOtherViewData->GetLine(index).GetLength();
\r
1370 if (!pszDiffChars || !*pszDiffChars)
\r
1374 ExpandChars(pszDiffChars, 0, nDiffLength, diffline);
\r
1375 svn_diff_t * diff = NULL;
\r
1376 m_svnlinediff.Diff(&diff, line, line.GetLength(), diffline, diffline.GetLength(), m_bInlineWordDiff);
\r
1377 if (!diff || !SVNLineDiff::ShowInlineDiff(diff))
\r
1380 int lineoffset = 0;
\r
1381 std::deque<int> removedPositions;
\r
1384 apr_off_t len = diff->original_length;
\r
1387 for (int i = 0; i < len; ++i)
\r
1389 s += m_svnlinediff.m_line1tokens[lineoffset].c_str();
\r
1392 bool isModified = diff->type == svn_diff__type_diff_modified;
\r
1393 DrawText(pDC, rc, (LPCTSTR)s, s.GetLength(), nLineIndex, origin, true, isModified);
\r
1394 origin.x += pDC->GetTextExtent(s).cx;
\r
1396 if (isModified && (len < diff->modified_length))
\r
1397 removedPositions.push_back(origin.x - 1);
\r
1399 diff = diff->next;
\r
1401 // Draw vertical bars at removed chunks' positions.
\r
1402 for (std::deque<int>::iterator it = removedPositions.begin(); it != removedPositions.end(); ++it)
\r
1403 pDC->FillSolidRect(*it, rc.top, 1, rc.Height(), m_InlineRemovedBk);
\r
1407 void CBaseView::DrawSingleLine(CDC *pDC, const CRect &rc, int nLineIndex)
\r
1409 if (nLineIndex >= GetLineCount())
\r
1411 ASSERT(nLineIndex >= -1);
\r
1413 if ((nLineIndex == -1) || !m_pViewData)
\r
1415 // Draw line beyond the text
\r
1416 COLORREF crBkgnd, crText;
\r
1417 CDiffColors::GetInstance().GetColors(DIFFSTATE_UNKNOWN, crBkgnd, crText);
\r
1418 pDC->FillSolidRect(rc, crBkgnd);
\r
1422 DiffStates diffState = m_pViewData->GetState(nLineIndex);
\r
1423 COLORREF crBkgnd, crText;
\r
1424 CDiffColors::GetInstance().GetColors(diffState, crBkgnd, crText);
\r
1426 if (diffState == DIFFSTATE_CONFLICTED)
\r
1428 // conflicted lines are shown without 'text' on them
\r
1430 pDC->FillSolidRect(rc, crBkgnd);
\r
1431 // now draw some faint text patterns
\r
1432 pDC->SetTextColor(IntenseColor(130, crBkgnd));
\r
1433 pDC->DrawText(m_sConflictedText, rect, DT_LEFT|DT_NOPREFIX|DT_SINGLELINE);
\r
1434 DrawBlockLine(pDC, rc, nLineIndex);
\r
1438 CPoint origin(rc.left - m_nOffsetChar * GetCharWidth(), rc.top);
\r
1439 int nLength = GetLineLength(nLineIndex);
\r
1442 // Draw the empty line
\r
1443 pDC->FillSolidRect(rc, crBkgnd);
\r
1444 DrawBlockLine(pDC, rc, nLineIndex);
\r
1445 DrawLineEnding(pDC, rc, nLineIndex, origin);
\r
1448 LPCTSTR pszChars = GetLineChars(nLineIndex);
\r
1449 if (pszChars == NULL)
\r
1456 pDC->SelectObject(GetFont(FALSE, FALSE, IsLineRemoved(nLineIndex)));
\r
1458 ExpandChars(pszChars, 0, nLength, line);
\r
1460 int nWidth = rc.right - origin.x;
\r
1461 int savedx = origin.x;
\r
1462 bool bInlineDiffDrawn =
\r
1463 nWidth > 0 && diffState != DIFFSTATE_NORMAL &&
\r
1464 DrawInlineDiff(pDC, rc, nLineIndex, line, origin);
\r
1466 if (!bInlineDiffDrawn)
\r
1468 int nCount = min(line.GetLength(), nWidth / GetCharWidth() + 1);
\r
1469 DrawText(pDC, rc, line, nCount, nLineIndex, origin, false, false);
\r
1472 origin.x = savedx + pDC->GetTextExtent(line).cx;
\r
1474 // draw white space after the end of line
\r
1476 if (origin.x > frect.left)
\r
1477 frect.left = origin.x;
\r
1478 if (bInlineDiffDrawn)
\r
1479 CDiffColors::GetInstance().GetColors(DIFFSTATE_UNKNOWN, crBkgnd, crText);
\r
1480 if (frect.right > frect.left)
\r
1481 pDC->FillSolidRect(frect, crBkgnd);
\r
1482 // draw the whitespace chars
\r
1483 if (m_bViewWhitespace)
\r
1486 int y = rc.top + (rc.bottom-rc.top)/2;
\r
1488 int nActualOffset = 0;
\r
1489 while ((nActualOffset < m_nOffsetChar) && (*pszChars))
\r
1491 if (*pszChars == _T('\t'))
\r
1492 nActualOffset += (GetTabSize() - nActualOffset % GetTabSize());
\r
1497 if (nActualOffset > m_nOffsetChar)
\r
1500 CPen pen(PS_SOLID, 0, m_WhiteSpaceFg);
\r
1501 CPen pen2(PS_SOLID, 2, m_WhiteSpaceFg);
\r
1504 switch (*pszChars)
\r
1509 CPen * oldPen = pDC->SelectObject(&pen);
\r
1510 int nSpaces = GetTabSize() - (m_nOffsetChar + xpos) % GetTabSize();
\r
1511 pDC->MoveTo(xpos * GetCharWidth() + rc.left, y);
\r
1512 pDC->LineTo((xpos + nSpaces) * GetCharWidth() + rc.left-2, y);
\r
1513 pDC->LineTo((xpos + nSpaces) * GetCharWidth() + rc.left-6, y-4);
\r
1514 pDC->MoveTo((xpos + nSpaces) * GetCharWidth() + rc.left-2, y);
\r
1515 pDC->LineTo((xpos + nSpaces) * GetCharWidth() + rc.left-6, y+4);
\r
1517 pDC->SelectObject(oldPen);
\r
1522 // draw a small dot
\r
1523 CPen * oldPen = pDC->SelectObject(&pen2);
\r
1524 pDC->MoveTo(xpos * GetCharWidth() + rc.left + GetCharWidth()/2-1, y);
\r
1525 pDC->LineTo(xpos * GetCharWidth() + rc.left + GetCharWidth()/2+1, y);
\r
1527 pDC->SelectObject(oldPen);
\r
1537 DrawBlockLine(pDC, rc, nLineIndex);
\r
1538 DrawLineEnding(pDC, rc, nLineIndex, origin);
\r
1541 void CBaseView::ExpandChars(LPCTSTR pszChars, int nOffset, int nCount, CString &line)
\r
1549 int nTabSize = GetTabSize();
\r
1551 int nActualOffset = 0;
\r
1552 for (int i=0; i<nOffset; i++)
\r
1554 if (pszChars[i] == _T('\t'))
\r
1555 nActualOffset += (nTabSize - nActualOffset % nTabSize);
\r
1560 pszChars += nOffset;
\r
1561 int nLength = nCount;
\r
1563 int nTabCount = 0;
\r
1564 for (int i=0; i<nLength; i++)
\r
1566 if (pszChars[i] == _T('\t'))
\r
1570 LPTSTR pszBuf = line.GetBuffer(nLength + nTabCount * (nTabSize - 1) + 1);
\r
1572 if (nTabCount > 0 || m_bViewWhitespace)
\r
1574 for (int i=0; i<nLength; i++)
\r
1576 if (pszChars[i] == _T('\t'))
\r
1578 int nSpaces = nTabSize - (nActualOffset + nCurPos) % nTabSize;
\r
1579 while (nSpaces > 0)
\r
1581 pszBuf[nCurPos ++] = _T(' ');
\r
1587 pszBuf[nCurPos] = pszChars[i];
\r
1594 memcpy(pszBuf, pszChars, sizeof(TCHAR) * nLength);
\r
1595 nCurPos = nLength;
\r
1597 pszBuf[nCurPos] = 0;
\r
1598 line.ReleaseBuffer();
\r
1601 void CBaseView::ScrollAllToLine(int nNewTopLine, BOOL bTrackScrollBar)
\r
1603 if ((m_pwndLeft)&&(m_pwndRight))
\r
1605 m_pwndLeft->ScrollToLine(nNewTopLine, bTrackScrollBar);
\r
1606 m_pwndRight->ScrollToLine(nNewTopLine, bTrackScrollBar);
\r
1611 m_pwndLeft->ScrollToLine(nNewTopLine, bTrackScrollBar);
\r
1613 m_pwndRight->ScrollToLine(nNewTopLine, bTrackScrollBar);
\r
1616 m_pwndBottom->ScrollToLine(nNewTopLine, bTrackScrollBar);
\r
1617 if (m_pwndLocator)
\r
1618 m_pwndLocator->Invalidate();
\r
1621 void CBaseView::GoToLine(int nNewLine, BOOL bAll)
\r
1623 //almost the same as ScrollAllToLine, but try to put the line in the
\r
1624 //middle of the view, not on top
\r
1625 int nNewTopLine = nNewLine - GetScreenLines()/2;
\r
1626 if (nNewTopLine < 0)
\r
1630 if (nNewTopLine >= m_pViewData->GetCount())
\r
1631 nNewTopLine = m_pViewData->GetCount()-1;
\r
1633 ScrollAllToLine(nNewTopLine);
\r
1635 ScrollToLine(nNewTopLine);
\r
1639 BOOL CBaseView::OnEraseBkgnd(CDC* /*pDC*/)
\r
1644 int CBaseView::OnCreate(LPCREATESTRUCT lpCreateStruct)
\r
1646 if (CView::OnCreate(lpCreateStruct) == -1)
\r
1649 memset(&m_lfBaseFont, 0, sizeof(m_lfBaseFont));
\r
1650 //lstrcpy(m_lfBaseFont.lfFaceName, _T("Courier New"));
\r
1651 //lstrcpy(m_lfBaseFont.lfFaceName, _T("FixedSys"));
\r
1652 m_lfBaseFont.lfHeight = 0;
\r
1653 m_lfBaseFont.lfWeight = FW_NORMAL;
\r
1654 m_lfBaseFont.lfItalic = FALSE;
\r
1655 m_lfBaseFont.lfCharSet = DEFAULT_CHARSET;
\r
1656 m_lfBaseFont.lfOutPrecision = OUT_DEFAULT_PRECIS;
\r
1657 m_lfBaseFont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
\r
1658 m_lfBaseFont.lfQuality = DEFAULT_QUALITY;
\r
1659 m_lfBaseFont.lfPitchAndFamily = DEFAULT_PITCH;
\r
1664 void CBaseView::OnDestroy()
\r
1666 CView::OnDestroy();
\r
1667 for (int i=0; i<MAXFONTS; i++)
\r
1669 if (m_apFonts[i] != NULL)
\r
1671 m_apFonts[i]->DeleteObject();
\r
1672 delete m_apFonts[i];
\r
1673 m_apFonts[i] = NULL;
\r
1676 if (m_pCacheBitmap != NULL)
\r
1678 delete m_pCacheBitmap;
\r
1679 m_pCacheBitmap = NULL;
\r
1683 void CBaseView::OnSize(UINT nType, int cx, int cy)
\r
1685 if (m_pCacheBitmap != NULL)
\r
1687 m_pCacheBitmap->DeleteObject();
\r
1688 delete m_pCacheBitmap;
\r
1689 m_pCacheBitmap = NULL;
\r
1691 // make sure the view header is redrawn
\r
1693 GetClientRect(&rcScroll);
\r
1694 rcScroll.bottom = GetLineHeight()+HEADERHEIGHT;
\r
1695 InvalidateRect(&rcScroll, FALSE);
\r
1697 m_nScreenLines = -1;
\r
1698 m_nScreenChars = -1;
\r
1699 RecalcVertScrollBar();
\r
1700 RecalcHorzScrollBar();
\r
1701 CView::OnSize(nType, cx, cy);
\r
1704 BOOL CBaseView::OnMouseWheel(UINT nFlags, short zDelta, CPoint pt)
\r
1707 m_pwndLeft->OnDoMouseWheel(nFlags, zDelta, pt);
\r
1709 m_pwndRight->OnDoMouseWheel(nFlags, zDelta, pt);
\r
1711 m_pwndBottom->OnDoMouseWheel(nFlags, zDelta, pt);
\r
1712 if (m_pwndLocator)
\r
1713 m_pwndLocator->Invalidate();
\r
1714 return CView::OnMouseWheel(nFlags, zDelta, pt);
\r
1717 void CBaseView::OnDoMouseWheel(UINT /*nFlags*/, short zDelta, CPoint /*pt*/)
\r
1719 if (GetKeyState(VK_CONTROL)&0x8000)
\r
1721 // Ctrl-Wheel scrolls sideways
\r
1722 ScrollSide(-zDelta/30);
\r
1726 int nLineCount = GetLineCount();
\r
1727 int nTopLine = m_nTopLine;
\r
1728 nTopLine -= (zDelta/30);
\r
1731 if (nTopLine >= nLineCount)
\r
1732 nTopLine = nLineCount - 1;
\r
1733 ScrollToLine(nTopLine, TRUE);
\r
1737 BOOL CBaseView::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
\r
1739 if (nHitTest == HTCLIENT)
\r
1741 ::SetCursor(::LoadCursor(NULL, MAKEINTRESOURCE(IDC_ARROW))); // Set To Arrow Cursor
\r
1744 return CView::OnSetCursor(pWnd, nHitTest, message);
\r
1747 void CBaseView::OnKillFocus(CWnd* pNewWnd)
\r
1749 CView::OnKillFocus(pNewWnd);
\r
1750 m_bFocused = FALSE;
\r
1755 void CBaseView::OnSetFocus(CWnd* pOldWnd)
\r
1757 CView::OnSetFocus(pOldWnd);
\r
1758 m_bFocused = TRUE;
\r
1763 int CBaseView::GetLineFromPoint(CPoint point)
\r
1765 ScreenToClient(&point);
\r
1766 return (((point.y - HEADERHEIGHT) / GetLineHeight()) + m_nTopLine);
\r
1769 bool CBaseView::OnContextMenu(CPoint /*point*/, int /*nLine*/, DiffStates /*state*/)
\r
1774 void CBaseView::OnContextMenu(CWnd* /*pWnd*/, CPoint point)
\r
1776 int nLine = GetLineFromPoint(point);
\r
1780 if (m_nSelBlockEnd >= GetLineCount())
\r
1781 m_nSelBlockEnd = GetLineCount()-1;
\r
1782 if ((nLine <= m_pViewData->GetCount())&&(nLine > m_nTopLine))
\r
1784 int nIndex = nLine - 1;
\r
1785 DiffStates state = m_pViewData->GetState(nIndex);
\r
1786 if ((state != DIFFSTATE_NORMAL) && (state != DIFFSTATE_UNKNOWN))
\r
1788 // if there's nothing selected, or if the selection is outside the window then
\r
1789 // select the diff block under the cursor.
\r
1790 if (((m_nSelBlockStart<0)&&(m_nSelBlockEnd<0))||
\r
1791 ((m_nSelBlockEnd < m_nTopLine)||(m_nSelBlockStart > m_nTopLine+m_nScreenLines)))
\r
1793 while (nIndex >= 0)
\r
1800 if (state != m_pViewData->GetState(--nIndex))
\r
1803 m_nSelBlockStart = nIndex+1;
\r
1804 while (nIndex < (m_pViewData->GetCount()-1))
\r
1806 if (state != m_pViewData->GetState(++nIndex))
\r
1809 if ((nIndex == (m_pViewData->GetCount()-1))&&(state == m_pViewData->GetState(nIndex)))
\r
1810 m_nSelBlockEnd = nIndex;
\r
1812 m_nSelBlockEnd = nIndex-1;
\r
1813 SetupSelection(m_nSelBlockStart, m_nSelBlockEnd);
\r
1814 m_ptCaretPos.x = 0;
\r
1815 m_ptCaretPos.y = nLine - 1;
\r
1819 if (((state == DIFFSTATE_NORMAL)||(state == DIFFSTATE_UNKNOWN)) &&
\r
1820 (m_nSelBlockStart >= 0)&&(m_nSelBlockEnd >= 0))
\r
1822 // find a more 'relevant' state in the selection
\r
1823 for (int i=m_nSelBlockStart; i<=m_nSelBlockEnd; ++i)
\r
1825 state = m_pViewData->GetState(i);
\r
1826 if ((state != DIFFSTATE_NORMAL) && (state != DIFFSTATE_UNKNOWN))
\r
1830 bool bKeepSelection = OnContextMenu(point, nLine, state);
\r
1831 if (! bKeepSelection)
\r
1837 void CBaseView::RefreshViews()
\r
1841 m_pwndLeft->UpdateStatusBar();
\r
1842 m_pwndLeft->Invalidate();
\r
1846 m_pwndRight->UpdateStatusBar();
\r
1847 m_pwndRight->Invalidate();
\r
1851 m_pwndBottom->UpdateStatusBar();
\r
1852 m_pwndBottom->Invalidate();
\r
1854 if (m_pwndLocator)
\r
1855 m_pwndLocator->Invalidate();
\r
1858 void CBaseView::GoToFirstDifference()
\r
1860 m_ptCaretPos.y = 0;
\r
1861 SelectNextBlock(1, false, false);
\r
1864 void CBaseView::HiglightLines(int start, int end /* = -1 */)
\r
1867 m_nSelBlockStart = start;
\r
1870 m_nSelBlockEnd = end;
\r
1871 m_ptCaretPos.x = 0;
\r
1872 m_ptCaretPos.y = start;
\r
1877 void CBaseView::SetupSelection(int start, int end)
\r
1879 if (IsBottomViewGood())
\r
1881 m_pwndBottom->m_nSelBlockStart = start;
\r
1882 m_pwndBottom->m_nSelBlockEnd = end;
\r
1883 m_pwndBottom->Invalidate();
\r
1885 if (IsLeftViewGood())
\r
1887 m_pwndLeft->m_nSelBlockStart = start;
\r
1888 m_pwndLeft->m_nSelBlockEnd = end;
\r
1889 m_pwndLeft->Invalidate();
\r
1891 if (IsRightViewGood())
\r
1893 m_pwndRight->m_nSelBlockStart = start;
\r
1894 m_pwndRight->m_nSelBlockEnd = end;
\r
1895 m_pwndRight->Invalidate();
\r
1899 void CBaseView::OnMergePreviousconflict()
\r
1901 SelectNextBlock(-1, true);
\r
1904 void CBaseView::OnMergeNextconflict()
\r
1906 SelectNextBlock(1, true);
\r
1909 void CBaseView::OnMergeNextdifference()
\r
1911 SelectNextBlock(1, false);
\r
1914 void CBaseView::OnMergePreviousdifference()
\r
1916 SelectNextBlock(-1, false);
\r
1919 void CBaseView::SelectNextBlock(int nDirection, bool bConflict, bool bSkipEndOfCurrentBlock /* = true */)
\r
1921 if (! m_pViewData)
\r
1924 if (m_pViewData->GetCount() == 0)
\r
1927 int nCenterPos = m_ptCaretPos.y;
\r
1929 if (nDirection > 0)
\r
1930 nLimit = m_pViewData->GetCount() - 1;
\r
1932 if (nCenterPos >= m_pViewData->GetCount())
\r
1933 nCenterPos = m_pViewData->GetCount()-1;
\r
1935 if (bSkipEndOfCurrentBlock)
\r
1937 // Find end of current block
\r
1938 DiffStates state = m_pViewData->GetState(nCenterPos);
\r
1939 while ((nCenterPos != nLimit) &&
\r
1940 (m_pViewData->GetState(nCenterPos)==state))
\r
1941 nCenterPos += nDirection;
\r
1944 // Find next diff/conflict block
\r
1945 while (nCenterPos != nLimit)
\r
1947 DiffStates linestate = m_pViewData->GetState(nCenterPos);
\r
1949 (linestate != DIFFSTATE_NORMAL) &&
\r
1950 (linestate != DIFFSTATE_UNKNOWN))
\r
1953 ((linestate == DIFFSTATE_CONFLICTADDED) ||
\r
1954 (linestate == DIFFSTATE_CONFLICTED_IGNORED) ||
\r
1955 (linestate == DIFFSTATE_CONFLICTED) ||
\r
1956 (linestate == DIFFSTATE_CONFLICTEMPTY)))
\r
1959 nCenterPos += nDirection;
\r
1962 // Find end of new block
\r
1963 DiffStates state = m_pViewData->GetState(nCenterPos);
\r
1964 int nBlockEnd = nCenterPos;
\r
1965 while ((nBlockEnd != nLimit) &&
\r
1966 (state == m_pViewData->GetState(nBlockEnd + nDirection)))
\r
1967 nBlockEnd += nDirection;
\r
1969 int nTopPos = nCenterPos - (GetScreenLines()/2);
\r
1973 m_ptCaretPos.x = 0;
\r
1974 m_ptCaretPos.y = nCenterPos;
\r
1976 if (nDirection > 0)
\r
1977 SetupSelection(nCenterPos, nBlockEnd);
\r
1979 SetupSelection(nBlockEnd, nCenterPos);
\r
1981 ScrollAllToLine(nTopPos, FALSE);
\r
1982 RecalcAllVertScrollBars(TRUE);
\r
1983 m_nCaretGoalPos = 0;
\r
1985 ShowDiffLines(nCenterPos);
\r
1988 BOOL CBaseView::OnToolTipNotify(UINT /*id*/, NMHDR *pNMHDR, LRESULT *pResult)
\r
1990 // need to handle both ANSI and UNICODE versions of the message
\r
1991 TOOLTIPTEXTA* pTTTA = (TOOLTIPTEXTA*)pNMHDR;
\r
1992 TOOLTIPTEXTW* pTTTW = (TOOLTIPTEXTW*)pNMHDR;
\r
1993 CString strTipText;
\r
1994 UINT nID = (UINT)pNMHDR->idFrom;
\r
1995 if (pNMHDR->code == TTN_NEEDTEXTA && (pTTTA->uFlags & TTF_IDISHWND) ||
\r
1996 pNMHDR->code == TTN_NEEDTEXTW && (pTTTW->uFlags & TTF_IDISHWND))
\r
1998 // idFrom is actually the HWND of the tool
\r
1999 nID = ::GetDlgCtrlID((HWND)nID);
\r
2002 if (pNMHDR->idFrom == (UINT)m_hWnd)
\r
2004 if (m_sWindowName.Left(2).Compare(_T("* "))==0)
\r
2006 strTipText = m_sWindowName.Mid(2) + _T("\r\n") + m_sFullFilePath;
\r
2010 strTipText = m_sWindowName + _T("\r\n") + m_sFullFilePath;
\r
2017 if (strTipText.IsEmpty())
\r
2020 if (pNMHDR->code == TTN_NEEDTEXTA)
\r
2022 pTTTA->lpszText = m_szTip;
\r
2023 WideCharToMultiByte(CP_ACP, 0, strTipText, -1, m_szTip, strTipText.GetLength()+1, 0, 0);
\r
2027 lstrcpyn(m_wszTip, strTipText, strTipText.GetLength()+1);
\r
2028 pTTTW->lpszText = m_wszTip;
\r
2031 return TRUE; // message was handled
\r
2035 INT_PTR CBaseView::OnToolHitTest(CPoint point, TOOLINFO* pTI) const
\r
2038 GetClientRect(rcClient);
\r
2039 CRect textrect(rcClient.left, rcClient.top, rcClient.Width(), m_nLineHeight+HEADERHEIGHT);
\r
2040 if (textrect.PtInRect(point))
\r
2042 // inside the header part of the view (showing the filename)
\r
2043 pTI->hwnd = this->m_hWnd;
\r
2044 this->GetClientRect(&pTI->rect);
\r
2045 pTI->uFlags |= TTF_ALWAYSTIP | TTF_IDISHWND;
\r
2046 pTI->uId = (UINT)m_hWnd;
\r
2047 pTI->lpszText = LPSTR_TEXTCALLBACK;
\r
2049 // we want multi line tooltips
\r
2050 CToolTipCtrl* pToolTip = AfxGetModuleThreadState()->m_pToolTip;
\r
2051 if (pToolTip->GetSafeHwnd() != NULL)
\r
2053 pToolTip->SetMaxTipWidth(INT_MAX);
\r
2061 void CBaseView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
\r
2063 bool bControl = !!(GetKeyState(VK_CONTROL)&0x8000);
\r
2064 bool bShift = !!(GetKeyState(VK_SHIFT)&0x8000);
\r
2069 m_ptCaretPos.y -= GetScreenLines();
\r
2070 m_ptCaretPos.y = max(m_ptCaretPos.y, 0);
\r
2071 m_ptCaretPos.x = CalculateCharIndex(m_ptCaretPos.y, m_nCaretGoalPos);
\r
2073 AdjustSelection();
\r
2077 EnsureCaretVisible();
\r
2078 ShowDiffLines(m_ptCaretPos.y);
\r
2083 m_ptCaretPos.y += GetScreenLines();
\r
2084 if (m_ptCaretPos.y >= GetLineCount())
\r
2085 m_ptCaretPos.y = GetLineCount()-1;
\r
2086 m_ptCaretPos.x = CalculateCharIndex(m_ptCaretPos.y, m_nCaretGoalPos);
\r
2088 AdjustSelection();
\r
2092 EnsureCaretVisible();
\r
2093 ShowDiffLines(m_ptCaretPos.y);
\r
2100 ScrollAllToLine(0);
\r
2101 m_ptCaretPos.x = 0;
\r
2102 m_ptCaretPos.y = 0;
\r
2103 m_nCaretGoalPos = 0;
\r
2105 AdjustSelection();
\r
2112 m_ptCaretPos.x = 0;
\r
2113 m_nCaretGoalPos = 0;
\r
2115 AdjustSelection();
\r
2118 EnsureCaretVisible();
\r
2127 ScrollAllToLine(GetLineCount()-GetAllMinScreenLines());
\r
2128 m_ptCaretPos.y = GetLineCount()-1;
\r
2129 m_ptCaretPos.x = GetLineLength(m_ptCaretPos.y);
\r
2132 AdjustSelection();
\r
2139 m_ptCaretPos.x = GetLineLength(m_ptCaretPos.y);
\r
2142 AdjustSelection();
\r
2145 EnsureCaretVisible();
\r
2152 if (m_bCaretHidden)
\r
2155 if (! HasTextSelection()) {
\r
2156 if (m_ptCaretPos.y == 0 && m_ptCaretPos.x == 0)
\r
2158 m_ptSelectionEndPos = m_ptCaretPos;
\r
2160 m_ptSelectionStartPos = m_ptCaretPos;
\r
2162 RemoveSelectedText();
\r
2167 if (m_bCaretHidden)
\r
2170 if (! HasTextSelection()) {
\r
2171 if (! MoveCaretRight())
\r
2173 m_ptSelectionEndPos = m_ptCaretPos;
\r
2175 m_ptSelectionStartPos = m_ptCaretPos;
\r
2177 RemoveSelectedText();
\r
2181 CView::OnKeyDown(nChar, nRepCnt, nFlags);
\r
2184 void CBaseView::OnLButtonDown(UINT nFlags, CPoint point)
\r
2186 int nClickedLine = (((point.y - HEADERHEIGHT) / GetLineHeight()) + m_nTopLine);
\r
2187 nClickedLine--; //we need the index
\r
2188 if ((nClickedLine >= m_nTopLine)&&(nClickedLine < GetLineCount()))
\r
2190 m_ptCaretPos.y = nClickedLine;
\r
2191 m_ptCaretPos.x = CalculateCharIndex(m_ptCaretPos.y, m_nOffsetChar + (point.x - GetMarginWidth()) / GetCharWidth());
\r
2194 if (nFlags & MK_SHIFT)
\r
2195 AdjustSelection();
\r
2199 SetupSelection(m_ptCaretPos.y, m_ptCaretPos.y);
\r
2207 CView::OnLButtonDown(nFlags, point);
\r
2210 void CBaseView::OnEditCopy()
\r
2212 if ((m_ptSelectionStartPos.x == m_ptSelectionEndPos.x)&&(m_ptSelectionStartPos.y == m_ptSelectionEndPos.y))
\r
2214 // first store the selected lines in one CString
\r
2215 CString sCopyData;
\r
2216 for (int i=m_ptSelectionStartPos.y; i<=m_ptSelectionEndPos.y; i++)
\r
2218 switch (m_pViewData->GetState(i))
\r
2220 case DIFFSTATE_EMPTY:
\r
2222 case DIFFSTATE_UNKNOWN:
\r
2223 case DIFFSTATE_NORMAL:
\r
2224 case DIFFSTATE_REMOVED:
\r
2225 case DIFFSTATE_REMOVEDWHITESPACE:
\r
2226 case DIFFSTATE_ADDED:
\r
2227 case DIFFSTATE_ADDEDWHITESPACE:
\r
2228 case DIFFSTATE_WHITESPACE:
\r
2229 case DIFFSTATE_WHITESPACE_DIFF:
\r
2230 case DIFFSTATE_CONFLICTED:
\r
2231 case DIFFSTATE_CONFLICTED_IGNORED:
\r
2232 case DIFFSTATE_CONFLICTADDED:
\r
2233 case DIFFSTATE_CONFLICTEMPTY:
\r
2234 case DIFFSTATE_CONFLICTRESOLVED:
\r
2235 case DIFFSTATE_IDENTICALREMOVED:
\r
2236 case DIFFSTATE_IDENTICALADDED:
\r
2237 case DIFFSTATE_THEIRSREMOVED:
\r
2238 case DIFFSTATE_THEIRSADDED:
\r
2239 case DIFFSTATE_YOURSREMOVED:
\r
2240 case DIFFSTATE_YOURSADDED:
\r
2241 case DIFFSTATE_EDITED:
\r
2242 sCopyData += m_pViewData->GetLine(i);
\r
2243 sCopyData += _T("\r\n");
\r
2247 // remove the last \r\n
\r
2248 sCopyData = sCopyData.Left(sCopyData.GetLength()-2);
\r
2249 // remove the non-selected chars from the first line
\r
2250 sCopyData = sCopyData.Mid(m_ptSelectionStartPos.x);
\r
2251 // remove the non-selected chars from the last line
\r
2252 int lastLinePos = sCopyData.ReverseFind('\n');
\r
2254 if (lastLinePos == 0)
\r
2255 lastLinePos -= m_ptSelectionStartPos.x;
\r
2256 sCopyData = sCopyData.Left(lastLinePos+m_ptSelectionEndPos.x);
\r
2257 if (!sCopyData.IsEmpty())
\r
2259 CStringUtils::WriteAsciiStringToClipboard(sCopyData, m_hWnd);
\r
2263 void CBaseView::OnMouseMove(UINT nFlags, CPoint point)
\r
2265 if (m_pMainFrame->m_nMoveMovesToIgnore > 0) {
\r
2266 --m_pMainFrame->m_nMoveMovesToIgnore;
\r
2267 CView::OnMouseMove(nFlags, point);
\r
2271 int nMouseLine = (((point.y - HEADERHEIGHT) / GetLineHeight()) + m_nTopLine);
\r
2272 nMouseLine--; //we need the index
\r
2273 if (nMouseLine < -1)
\r
2277 ShowDiffLines(nMouseLine);
\r
2279 KillTimer(IDT_SCROLLTIMER);
\r
2280 if (nFlags & MK_LBUTTON)
\r
2282 int saveMouseLine = nMouseLine >= 0 ? nMouseLine : 0;
\r
2283 saveMouseLine = saveMouseLine < GetLineCount() ? saveMouseLine : GetLineCount() - 1;
\r
2284 int charIndex = CalculateCharIndex(saveMouseLine, m_nOffsetChar + (point.x - GetMarginWidth()) / GetCharWidth());
\r
2285 if (((m_nSelBlockStart >= 0)&&(m_nSelBlockEnd >= 0))&&
\r
2286 ((nMouseLine >= m_nTopLine)&&(nMouseLine < GetLineCount())))
\r
2288 m_ptCaretPos.y = nMouseLine;
\r
2289 m_ptCaretPos.x = charIndex;
\r
2291 AdjustSelection();
\r
2296 if (nMouseLine < m_nTopLine)
\r
2298 ScrollToLine(m_nTopLine-1, TRUE);
\r
2299 SetTimer(IDT_SCROLLTIMER, 20, NULL);
\r
2301 if (nMouseLine >= m_nTopLine + GetScreenLines())
\r
2303 ScrollToLine(m_nTopLine+1, TRUE);
\r
2304 SetTimer(IDT_SCROLLTIMER, 20, NULL);
\r
2306 if (charIndex <= m_nOffsetChar)
\r
2309 SetTimer(IDT_SCROLLTIMER, 20, NULL);
\r
2311 if (charIndex >= (GetScreenChars()+m_nOffsetChar))
\r
2314 SetTimer(IDT_SCROLLTIMER, 20, NULL);
\r
2318 if (!m_bMouseWithin)
\r
2320 m_bMouseWithin = TRUE;
\r
2321 TRACKMOUSEEVENT tme;
\r
2322 tme.cbSize = sizeof(TRACKMOUSEEVENT);
\r
2323 tme.dwFlags = TME_LEAVE;
\r
2324 tme.hwndTrack = m_hWnd;
\r
2325 _TrackMouseEvent(&tme);
\r
2328 CView::OnMouseMove(nFlags, point);
\r
2331 void CBaseView::OnMouseLeave()
\r
2333 ShowDiffLines(-1);
\r
2334 m_bMouseWithin = FALSE;
\r
2335 KillTimer(IDT_SCROLLTIMER);
\r
2336 CView::OnMouseLeave();
\r
2339 void CBaseView::OnTimer(UINT_PTR nIDEvent)
\r
2341 if (nIDEvent == IDT_SCROLLTIMER)
\r
2344 GetCursorPos(&point);
\r
2345 ScreenToClient(&point);
\r
2346 int nMouseLine = (((point.y - HEADERHEIGHT) / GetLineHeight()) + m_nTopLine);
\r
2347 nMouseLine--; //we need the index
\r
2348 if (nMouseLine < -1)
\r
2352 if (GetKeyState(VK_LBUTTON)&0x8000)
\r
2354 int saveMouseLine = nMouseLine >= 0 ? nMouseLine : 0;
\r
2355 saveMouseLine = saveMouseLine < GetLineCount() ? saveMouseLine : GetLineCount() - 1;
\r
2356 int charIndex = CalculateCharIndex(saveMouseLine, m_nOffsetChar + (point.x - GetMarginWidth()) / GetCharWidth());
\r
2357 if (nMouseLine < m_nTopLine)
\r
2359 ScrollToLine(m_nTopLine-1, TRUE);
\r
2360 SetTimer(IDT_SCROLLTIMER, 20, NULL);
\r
2362 if (nMouseLine >= m_nTopLine + GetScreenLines())
\r
2364 ScrollToLine(m_nTopLine+1, TRUE);
\r
2365 SetTimer(IDT_SCROLLTIMER, 20, NULL);
\r
2367 if (charIndex <= m_nOffsetChar)
\r
2370 SetTimer(IDT_SCROLLTIMER, 20, NULL);
\r
2372 if (charIndex >= GetScreenChars())
\r
2375 SetTimer(IDT_SCROLLTIMER, 20, NULL);
\r
2381 CView::OnTimer(nIDEvent);
\r
2384 void CBaseView::SelectLines(int nLine1, int nLine2)
\r
2388 m_nSelBlockStart = nLine1;
\r
2389 m_nSelBlockEnd = nLine2;
\r
2393 void CBaseView::ShowDiffLines(int nLine)
\r
2395 if ((nLine >= m_nTopLine)&&(nLine < GetLineCount()))
\r
2397 if ((m_pwndRight)&&(m_pwndRight->m_pViewData)&&(m_pwndLeft)&&(m_pwndLeft->m_pViewData)&&(!m_pMainFrame->m_bOneWay))
\r
2399 nLine = (nLine > m_pwndRight->m_pViewData->GetCount() ? -1 : nLine);
\r
2400 nLine = (nLine > m_pwndLeft->m_pViewData->GetCount() ? -1 : nLine);
\r
2404 if (nLine != m_nMouseLine)
\r
2406 m_nMouseLine = nLine;
\r
2407 if (nLine >= GetLineCount())
\r
2409 m_pwndLineDiffBar->ShowLines(nLine);
\r
2416 m_pwndLineDiffBar->ShowLines(nLine);
\r
2420 void CBaseView::UseTheirAndYourBlock(viewstate &rightstate, viewstate &bottomstate, viewstate &leftstate)
\r
2422 if ((m_nSelBlockStart == -1)||(m_nSelBlockEnd == -1))
\r
2424 for (int i=m_nSelBlockStart; i<=m_nSelBlockEnd; i++)
\r
2426 bottomstate.difflines[i] = m_pwndBottom->m_pViewData->GetLine(i);
\r
2427 m_pwndBottom->m_pViewData->SetLine(i, m_pwndLeft->m_pViewData->GetLine(i));
\r
2428 bottomstate.linestates[i] = m_pwndBottom->m_pViewData->GetState(i);
\r
2429 m_pwndBottom->m_pViewData->SetState(i, m_pwndLeft->m_pViewData->GetState(i));
\r
2430 m_pwndBottom->m_pViewData->SetLineEnding(i, EOL_AUTOLINE);
\r
2431 if (m_pwndBottom->IsLineConflicted(i))
\r
2433 if (m_pwndLeft->m_pViewData->GetState(i) == DIFFSTATE_CONFLICTEMPTY)
\r
2434 m_pwndBottom->m_pViewData->SetState(i, DIFFSTATE_CONFLICTRESOLVEDEMPTY);
\r
2436 m_pwndBottom->m_pViewData->SetState(i, DIFFSTATE_CONFLICTRESOLVED);
\r
2438 m_pwndLeft->m_pViewData->SetState(i, DIFFSTATE_YOURSADDED);
\r
2441 // your block is done, now insert their block
\r
2442 int index = m_nSelBlockEnd+1;
\r
2443 for (int i=m_nSelBlockStart; i<=m_nSelBlockEnd; i++)
\r
2445 bottomstate.addedlines.push_back(m_nSelBlockEnd+1);
\r
2446 m_pwndBottom->m_pViewData->InsertData(index, m_pwndRight->m_pViewData->GetData(i));
\r
2447 if (m_pwndBottom->IsLineConflicted(index))
\r
2449 if (m_pwndRight->m_pViewData->GetState(i) == DIFFSTATE_CONFLICTEMPTY)
\r
2450 m_pwndBottom->m_pViewData->SetState(index, DIFFSTATE_CONFLICTRESOLVEDEMPTY);
\r
2452 m_pwndBottom->m_pViewData->SetState(index, DIFFSTATE_CONFLICTRESOLVED);
\r
2454 m_pwndRight->m_pViewData->SetState(i, DIFFSTATE_THEIRSADDED);
\r
2457 // adjust line numbers
\r
2458 for (int i=m_nSelBlockEnd+1; i<GetLineCount(); ++i)
\r
2460 long oldline = (long)m_pwndBottom->m_pViewData->GetLineNumber(i);
\r
2462 m_pwndBottom->m_pViewData->SetLineNumber(i, oldline+(index-m_nSelBlockEnd));
\r
2465 // now insert an empty block in both yours and theirs
\r
2466 for (int emptyblocks=0; emptyblocks < m_nSelBlockEnd-m_nSelBlockStart+1; ++emptyblocks)
\r
2468 rightstate.addedlines.push_back(m_nSelBlockStart);
\r
2469 m_pwndRight->m_pViewData->InsertData(m_nSelBlockStart, _T(""), DIFFSTATE_EMPTY, -1, EOL_NOENDING);
\r
2470 m_pwndLeft->m_pViewData->InsertData(m_nSelBlockEnd+1, _T(""), DIFFSTATE_EMPTY, -1, EOL_NOENDING);
\r
2471 leftstate.addedlines.push_back(m_nSelBlockEnd+1);
\r
2473 RecalcAllVertScrollBars();
\r
2474 m_pwndBottom->SetModified();
\r
2475 m_pwndLeft->SetModified();
\r
2476 m_pwndRight->SetModified();
\r
2479 void CBaseView::UseYourAndTheirBlock(viewstate &rightstate, viewstate &bottomstate, viewstate &leftstate)
\r
2481 if ((m_nSelBlockStart == -1)||(m_nSelBlockEnd == -1))
\r
2483 for (int i=m_nSelBlockStart; i<=m_nSelBlockEnd; i++)
\r
2485 bottomstate.difflines[i] = m_pwndBottom->m_pViewData->GetLine(i);
\r
2486 m_pwndBottom->m_pViewData->SetLine(i, m_pwndRight->m_pViewData->GetLine(i));
\r
2487 bottomstate.linestates[i] = m_pwndBottom->m_pViewData->GetState(i);
\r
2488 m_pwndBottom->m_pViewData->SetState(i, m_pwndRight->m_pViewData->GetState(i));
\r
2489 rightstate.linestates[i] = m_pwndRight->m_pViewData->GetState(i);
\r
2490 m_pwndBottom->m_pViewData->SetLineEnding(i, EOL_AUTOLINE);
\r
2491 if (m_pwndBottom->IsLineConflicted(i))
\r
2493 if (m_pwndRight->m_pViewData->GetState(i) == DIFFSTATE_CONFLICTEMPTY)
\r
2494 m_pwndBottom->m_pViewData->SetState(i, DIFFSTATE_CONFLICTRESOLVEDEMPTY);
\r
2496 m_pwndBottom->m_pViewData->SetState(i, DIFFSTATE_CONFLICTRESOLVED);
\r
2498 m_pwndRight->m_pViewData->SetState(i, DIFFSTATE_YOURSADDED);
\r
2501 // your block is done, now insert their block
\r
2502 int index = m_nSelBlockEnd+1;
\r
2503 for (int i=m_nSelBlockStart; i<=m_nSelBlockEnd; i++)
\r
2505 bottomstate.addedlines.push_back(m_nSelBlockEnd+1);
\r
2506 m_pwndBottom->m_pViewData->InsertData(index, m_pwndLeft->m_pViewData->GetData(i));
\r
2507 leftstate.linestates[i] = m_pwndLeft->m_pViewData->GetState(i);
\r
2508 if (m_pwndBottom->IsLineConflicted(index))
\r
2510 if (m_pwndLeft->m_pViewData->GetState(i) == DIFFSTATE_CONFLICTEMPTY)
\r
2511 m_pwndBottom->m_pViewData->SetState(index, DIFFSTATE_CONFLICTRESOLVEDEMPTY);
\r
2513 m_pwndBottom->m_pViewData->SetState(index, DIFFSTATE_CONFLICTRESOLVED);
\r
2515 m_pwndLeft->m_pViewData->SetState(i, DIFFSTATE_THEIRSADDED);
\r
2518 // adjust line numbers
\r
2519 for (int i=m_nSelBlockEnd+1; i<m_pwndBottom->GetLineCount(); ++i)
\r
2521 long oldline = (long)m_pwndBottom->m_pViewData->GetLineNumber(i);
\r
2523 m_pwndBottom->m_pViewData->SetLineNumber(i, oldline+(index-m_nSelBlockEnd));
\r
2526 // now insert an empty block in both yours and theirs
\r
2527 for (int emptyblocks=0; emptyblocks < m_nSelBlockEnd-m_nSelBlockStart+1; ++emptyblocks)
\r
2529 leftstate.addedlines.push_back(m_nSelBlockStart);
\r
2530 m_pwndLeft->m_pViewData->InsertData(m_nSelBlockStart, _T(""), DIFFSTATE_EMPTY, -1, EOL_NOENDING);
\r
2531 m_pwndRight->m_pViewData->InsertData(m_nSelBlockEnd+1, _T(""), DIFFSTATE_EMPTY, -1, EOL_NOENDING);
\r
2532 rightstate.addedlines.push_back(m_nSelBlockEnd+1);
\r
2535 RecalcAllVertScrollBars();
\r
2536 m_pwndBottom->SetModified();
\r
2537 m_pwndLeft->SetModified();
\r
2538 m_pwndRight->SetModified();
\r
2541 void CBaseView::UseBothRightFirst(viewstate &rightstate, viewstate &leftstate)
\r
2543 if ((m_nSelBlockStart == -1)||(m_nSelBlockEnd == -1))
\r
2545 for (int i=m_nSelBlockStart; i<=m_nSelBlockEnd; i++)
\r
2547 rightstate.linestates[i] = m_pwndRight->m_pViewData->GetState(i);
\r
2548 m_pwndRight->m_pViewData->SetState(i, DIFFSTATE_YOURSADDED);
\r
2551 // your block is done, now insert their block
\r
2552 int index = m_nSelBlockEnd+1;
\r
2553 for (int i=m_nSelBlockStart; i<=m_nSelBlockEnd; i++)
\r
2555 rightstate.addedlines.push_back(m_nSelBlockEnd+1);
\r
2556 m_pwndRight->m_pViewData->InsertData(index, m_pwndLeft->m_pViewData->GetData(i));
\r
2557 m_pwndRight->m_pViewData->SetState(index++, DIFFSTATE_THEIRSADDED);
\r
2559 // adjust line numbers
\r
2561 for (int i=m_nSelBlockEnd+1; i<m_pwndRight->GetLineCount(); ++i)
\r
2563 long oldline = (long)m_pwndRight->m_pViewData->GetLineNumber(i);
\r
2565 m_pwndRight->m_pViewData->SetLineNumber(i, oldline+(index-m_nSelBlockEnd));
\r
2568 // now insert an empty block in the left view
\r
2569 for (int emptyblocks=0; emptyblocks < m_nSelBlockEnd-m_nSelBlockStart+1; ++emptyblocks)
\r
2571 leftstate.addedlines.push_back(m_nSelBlockStart);
\r
2572 m_pwndLeft->m_pViewData->InsertData(m_nSelBlockStart, _T(""), DIFFSTATE_EMPTY, -1, EOL_NOENDING);
\r
2574 RecalcAllVertScrollBars();
\r
2575 m_pwndLeft->SetModified();
\r
2576 m_pwndRight->SetModified();
\r
2579 void CBaseView::UseBothLeftFirst(viewstate &rightstate, viewstate &leftstate)
\r
2581 if ((m_nSelBlockStart == -1)||(m_nSelBlockEnd == -1))
\r
2583 // get line number from just before the block
\r
2584 long linenumber = 0;
\r
2585 if (m_nSelBlockStart > 0)
\r
2586 linenumber = m_pwndRight->m_pViewData->GetLineNumber(m_nSelBlockStart-1);
\r
2588 for (int i=m_nSelBlockStart; i<=m_nSelBlockEnd; i++)
\r
2590 rightstate.addedlines.push_back(m_nSelBlockStart);
\r
2591 m_pwndRight->m_pViewData->InsertData(i, m_pwndLeft->m_pViewData->GetLine(i), DIFFSTATE_THEIRSADDED, linenumber++, m_pwndLeft->m_pViewData->GetLineEnding(i));
\r
2593 // adjust line numbers
\r
2594 for (int i=m_nSelBlockEnd+1; i<m_pwndRight->GetLineCount(); ++i)
\r
2596 long oldline = (long)m_pwndRight->m_pViewData->GetLineNumber(i);
\r
2598 m_pwndRight->m_pViewData->SetLineNumber(i, oldline+(m_nSelBlockEnd-m_nSelBlockStart)+1);
\r
2601 // now insert an empty block in left view
\r
2602 for (int emptyblocks=0; emptyblocks < m_nSelBlockEnd-m_nSelBlockStart+1; ++emptyblocks)
\r
2604 leftstate.addedlines.push_back(m_nSelBlockEnd + 1);
\r
2605 m_pwndLeft->m_pViewData->InsertData(m_nSelBlockEnd + 1, _T(""), DIFFSTATE_EMPTY, -1, EOL_NOENDING);
\r
2607 RecalcAllVertScrollBars();
\r
2608 m_pwndLeft->SetModified();
\r
2609 m_pwndRight->SetModified();
\r
2612 void CBaseView::UpdateCaret()
\r
2614 if (m_ptCaretPos.y >= GetLineCount())
\r
2615 m_ptCaretPos.y = GetLineCount()-1;
\r
2616 if (m_ptCaretPos.y < 0)
\r
2617 m_ptCaretPos.y = 0;
\r
2618 if (m_ptCaretPos.x > GetLineLength(m_ptCaretPos.y))
\r
2619 m_ptCaretPos.x = GetLineLength(m_ptCaretPos.y);
\r
2620 if (m_ptCaretPos.x < 0)
\r
2621 m_ptCaretPos.x = 0;
\r
2623 int nCaretOffset = CalculateActualOffset(m_ptCaretPos.y, m_ptCaretPos.x);
\r
2625 if (m_bFocused && !m_bCaretHidden &&
\r
2626 m_ptCaretPos.y >= m_nTopLine &&
\r
2627 m_ptCaretPos.y < (m_nTopLine+GetScreenLines()) &&
\r
2628 nCaretOffset >= m_nOffsetChar &&
\r
2629 nCaretOffset < (m_nOffsetChar+GetScreenChars()))
\r
2631 CreateSolidCaret(2, GetLineHeight());
\r
2632 SetCaretPos(TextToClient(m_ptCaretPos));
\r
2641 void CBaseView::EnsureCaretVisible()
\r
2643 int nCaretOffset = CalculateActualOffset(m_ptCaretPos.y, m_ptCaretPos.x);
\r
2645 if (m_ptCaretPos.y < m_nTopLine)
\r
2646 ScrollAllToLine(m_ptCaretPos.y);
\r
2647 if (m_ptCaretPos.y >= (m_nTopLine+GetScreenLines()))
\r
2648 ScrollAllToLine(m_ptCaretPos.y-GetScreenLines()+1);
\r
2649 if (nCaretOffset < m_nOffsetChar)
\r
2650 ScrollToChar(nCaretOffset);
\r
2651 if (nCaretOffset > (m_nOffsetChar+GetScreenChars()-1))
\r
2652 ScrollToChar(nCaretOffset-GetScreenChars()+1);
\r
2655 int CBaseView::CalculateActualOffset(int nLineIndex, int nCharIndex) const
\r
2657 int nLength = GetLineLength(nLineIndex);
\r
2658 ASSERT(nCharIndex >= 0);
\r
2659 if (nCharIndex > nLength)
\r
2660 nCharIndex = nLength;
\r
2661 LPCTSTR pszChars = GetLineChars(nLineIndex);
\r
2663 int nTabSize = GetTabSize();
\r
2664 for (int I = 0; I < nCharIndex; I ++)
\r
2666 if (pszChars[I] == _T('\t'))
\r
2667 nOffset += (nTabSize - nOffset % nTabSize);
\r
2674 int CBaseView::CalculateCharIndex(int nLineIndex, int nActualOffset) const
\r
2676 int nLength = GetLineLength(nLineIndex);
\r
2677 LPCTSTR pszLine = GetLineChars(nLineIndex);
\r
2680 int nTabSize = GetTabSize();
\r
2681 while (nOffset < nActualOffset && nIndex < nLength)
\r
2683 if (pszLine[nIndex] == _T('\t'))
\r
2684 nOffset += (nTabSize - nOffset % nTabSize);
\r
2692 POINT CBaseView::TextToClient(const POINT& point)
\r
2695 pt.y = max(0, (point.y - m_nTopLine) * GetLineHeight());
\r
2696 pt.x = CalculateActualOffset(point.y, point.x);
\r
2698 pt.x = (pt.x - m_nOffsetChar) * GetCharWidth() + GetMarginWidth();
\r
2699 pt.y = (pt.y + GetLineHeight() + HEADERHEIGHT);
\r
2703 void CBaseView::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
\r
2705 CView::OnChar(nChar, nRepCnt, nFlags);
\r
2707 if (m_bCaretHidden)
\r
2710 if ((::GetKeyState(VK_LBUTTON) & 0x8000) != 0 ||
\r
2711 (::GetKeyState(VK_RBUTTON) & 0x8000) != 0)
\r
2714 if ((nChar > 31)||(nChar == VK_TAB))
\r
2716 RemoveSelectedText();
\r
2717 AddUndoLine(m_ptCaretPos.y);
\r
2718 CString sLine = GetLineChars(m_ptCaretPos.y);
\r
2719 sLine.Insert(m_ptCaretPos.x, (wchar_t)nChar);
\r
2720 m_pViewData->SetLine(m_ptCaretPos.y, sLine);
\r
2721 m_pViewData->SetState(m_ptCaretPos.y, DIFFSTATE_EDITED);
\r
2725 else if (nChar == VK_RETURN)
\r
2727 // insert a new, fresh and empty line below the cursor
\r
2728 RemoveSelectedText();
\r
2729 AddUndoLine(m_ptCaretPos.y, true);
\r
2730 // move the cursor to the new line
\r
2732 m_ptCaretPos.x = 0;
\r
2736 return; // Unknown control character -- ignore it.
\r
2738 EnsureCaretVisible();
\r
2740 SetModified(true);
\r
2741 Invalidate(FALSE);
\r
2744 void CBaseView::AddUndoLine(int nLine, bool bAddEmptyLine)
\r
2746 viewstate leftstate;
\r
2747 viewstate rightstate;
\r
2748 viewstate bottomstate;
\r
2749 leftstate.AddLineFormView(m_pwndLeft, nLine, bAddEmptyLine);
\r
2750 rightstate.AddLineFormView(m_pwndRight, nLine, bAddEmptyLine);
\r
2751 bottomstate.AddLineFormView(m_pwndBottom, nLine, bAddEmptyLine);
\r
2752 CUndo::GetInstance().AddState(leftstate, rightstate, bottomstate, m_ptCaretPos);
\r
2755 void CBaseView::AddEmptyLine(int nLineIndex)
\r
2757 if (m_pViewData == NULL)
\r
2759 if (!m_bCaretHidden)
\r
2761 CString sPartLine = GetLineChars(nLineIndex);
\r
2762 m_pViewData->SetLine(nLineIndex, sPartLine.Left(m_ptCaretPos.x));
\r
2763 sPartLine = sPartLine.Mid(m_ptCaretPos.x);
\r
2764 m_pViewData->InsertData(nLineIndex+1, sPartLine, DIFFSTATE_EDITED, -1, m_pViewData->GetLineEnding(nLineIndex));
\r
2767 m_pViewData->InsertData(nLineIndex+1, _T(""), DIFFSTATE_EDITED, -1, m_pViewData->GetLineEnding(nLineIndex));
\r
2768 Invalidate(FALSE);
\r
2771 void CBaseView::RemoveLine(int nLineIndex)
\r
2773 if (m_pViewData == NULL)
\r
2775 m_pViewData->RemoveData(nLineIndex);
\r
2776 if (m_ptCaretPos.y >= GetLineCount())
\r
2777 m_ptCaretPos.y = GetLineCount()-1;
\r
2778 Invalidate(FALSE);
\r
2781 void CBaseView::RemoveSelectedText()
\r
2783 if (m_pViewData == NULL)
\r
2785 if (!HasTextSelection())
\r
2788 viewstate rightstate;
\r
2789 viewstate bottomstate;
\r
2790 viewstate leftstate;
\r
2791 std::vector<LONG> linestoremove;
\r
2792 for (LONG i = m_ptSelectionStartPos.y; i <= m_ptSelectionEndPos.y; ++i)
\r
2794 if (i == m_ptSelectionStartPos.y)
\r
2796 CString sLine = GetLineChars(m_ptSelectionStartPos.y);
\r
2798 if (i == m_ptSelectionStartPos.y)
\r
2800 if ((m_pwndLeft)&&(m_pwndLeft->m_pViewData))
\r
2802 leftstate.difflines[i] = m_pwndLeft->m_pViewData->GetLine(i);
\r
2803 leftstate.linestates[i] = m_pwndLeft->m_pViewData->GetState(i);
\r
2805 if ((m_pwndRight)&&(m_pwndRight->m_pViewData))
\r
2807 rightstate.difflines[i] = m_pwndRight->m_pViewData->GetLine(i);
\r
2808 rightstate.linestates[i] = m_pwndRight->m_pViewData->GetState(i);
\r
2810 if ((m_pwndBottom)&&(m_pwndBottom->m_pViewData))
\r
2812 bottomstate.difflines[i] = m_pwndBottom->m_pViewData->GetLine(i);
\r
2813 bottomstate.linestates[i] = m_pwndBottom->m_pViewData->GetState(i);
\r
2815 newLine = sLine.Left(m_ptSelectionStartPos.x);
\r
2816 sLine = GetLineChars(m_ptSelectionEndPos.y);
\r
2817 newLine = newLine + sLine.Mid(m_ptSelectionEndPos.x);
\r
2819 m_pViewData->SetLine(i, newLine);
\r
2820 m_pViewData->SetState(i, DIFFSTATE_EDITED);
\r
2825 if ((m_pwndLeft)&&(m_pwndLeft->m_pViewData))
\r
2827 leftstate.removedlines[i] = m_pwndLeft->m_pViewData->GetData(i);
\r
2829 if ((m_pwndRight)&&(m_pwndRight->m_pViewData))
\r
2831 rightstate.removedlines[i] = m_pwndRight->m_pViewData->GetData(i);
\r
2833 if ((m_pwndBottom)&&(m_pwndBottom->m_pViewData))
\r
2835 bottomstate.removedlines[i] = m_pwndBottom->m_pViewData->GetData(i);
\r
2837 linestoremove.push_back(i);
\r
2840 CUndo::GetInstance().AddState(leftstate, rightstate, bottomstate, m_ptCaretPos);
\r
2841 // remove the lines at the end, to avoid problems with line indexes
\r
2842 if (linestoremove.size())
\r
2844 std::vector<LONG>::const_iterator it = linestoremove.begin();
\r
2845 int nLineToRemove = *it;
\r
2846 for ( ; it != linestoremove.end(); ++it)
\r
2849 m_pwndLeft->RemoveLine(nLineToRemove);
\r
2851 m_pwndRight->RemoveLine(nLineToRemove);
\r
2853 m_pwndBottom->RemoveLine(nLineToRemove);
\r
2857 m_ptCaretPos = m_ptSelectionStartPos;
\r
2861 EnsureCaretVisible();
\r
2862 Invalidate(FALSE);
\r
2865 void CBaseView::PasteText()
\r
2867 if (!OpenClipboard())
\r
2870 CString sClipboardText;
\r
2871 HGLOBAL hglb = GetClipboardData(CF_TEXT);
\r
2874 LPCSTR lpstr = (LPCSTR)GlobalLock(hglb);
\r
2875 sClipboardText = CString(lpstr);
\r
2876 GlobalUnlock(hglb);
\r
2878 hglb = GetClipboardData(CF_UNICODETEXT);
\r
2881 LPCTSTR lpstr = (LPCTSTR)GlobalLock(hglb);
\r
2882 sClipboardText = lpstr;
\r
2883 GlobalUnlock(hglb);
\r
2887 if (sClipboardText.IsEmpty())
\r
2890 sClipboardText.Replace(_T("\r\n"), _T("\r"));
\r
2891 sClipboardText.Replace('\n', '\r');
\r
2892 // We want to undo the insertion in a single step.
\r
2893 CUndo::GetInstance().BeginGrouping();
\r
2894 // use the easy way to insert text:
\r
2895 // insert char by char, using the OnChar() method
\r
2896 for (int i=0; i<sClipboardText.GetLength(); ++i)
\r
2898 OnChar(sClipboardText[i], 0, 0);
\r
2900 CUndo::GetInstance().EndGrouping();
\r
2903 void CBaseView::OnCaretDown()
\r
2906 m_ptCaretPos.y = min(m_ptCaretPos.y, GetLineCount()-1);
\r
2907 m_ptCaretPos.x = CalculateCharIndex(m_ptCaretPos.y, m_nCaretGoalPos);
\r
2908 if (GetKeyState(VK_SHIFT)&0x8000)
\r
2909 AdjustSelection();
\r
2913 EnsureCaretVisible();
\r
2914 ShowDiffLines(m_ptCaretPos.y);
\r
2917 bool CBaseView::MoveCaretLeft()
\r
2919 if (m_ptCaretPos.x == 0)
\r
2921 if (m_ptCaretPos.y > 0)
\r
2924 m_ptCaretPos.x = GetLineLength(m_ptCaretPos.y);
\r
2936 bool CBaseView::MoveCaretRight()
\r
2938 if (m_ptCaretPos.x >= GetLineLength(m_ptCaretPos.y))
\r
2940 if (m_ptCaretPos.y < (GetLineCount() - 1))
\r
2943 m_ptCaretPos.x = 0;
\r
2955 void CBaseView::UpdateGoalPos()
\r
2957 m_nCaretGoalPos = CalculateActualOffset(m_ptCaretPos.y, m_ptCaretPos.x);
\r
2960 void CBaseView::OnCaretLeft()
\r
2963 if (GetKeyState(VK_SHIFT)&0x8000)
\r
2964 AdjustSelection();
\r
2967 EnsureCaretVisible();
\r
2971 void CBaseView::OnCaretRight()
\r
2974 if (GetKeyState(VK_SHIFT)&0x8000)
\r
2975 AdjustSelection();
\r
2978 EnsureCaretVisible();
\r
2982 void CBaseView::OnCaretUp()
\r
2985 m_ptCaretPos.y = max(0, m_ptCaretPos.y);
\r
2986 m_ptCaretPos.x = CalculateCharIndex(m_ptCaretPos.y, m_nCaretGoalPos);
\r
2987 if (GetKeyState(VK_SHIFT)&0x8000)
\r
2988 AdjustSelection();
\r
2992 EnsureCaretVisible();
\r
2993 ShowDiffLines(m_ptCaretPos.y);
\r
2996 bool CBaseView::IsWordSeparator(wchar_t ch) const
\r
2998 return ch == ' ' || ch == '\t' || (m_sWordSeparators.Find(ch) >= 0);
\r
3001 bool CBaseView::IsCaretAtWordBoundary() const
\r
3003 LPCTSTR line = GetLineChars(m_ptCaretPos.y);
\r
3005 return false; // no boundary at the empty lines
\r
3006 if (m_ptCaretPos.x == 0)
\r
3007 return !IsWordSeparator(line[m_ptCaretPos.x]);
\r
3008 if (m_ptCaretPos.x >= GetLineLength(m_ptCaretPos.y))
\r
3009 return !IsWordSeparator(line[m_ptCaretPos.x - 1]);
\r
3011 IsWordSeparator(line[m_ptCaretPos.x]) !=
\r
3012 IsWordSeparator(line[m_ptCaretPos.x - 1]);
\r
3015 void CBaseView::OnCaretWordleft()
\r
3017 while (MoveCaretLeft() && !IsCaretAtWordBoundary())
\r
3020 if (GetKeyState(VK_SHIFT)&0x8000)
\r
3021 AdjustSelection();
\r
3024 EnsureCaretVisible();
\r
3028 void CBaseView::OnCaretWordright()
\r
3030 while (MoveCaretRight() && !IsCaretAtWordBoundary())
\r
3033 if (GetKeyState(VK_SHIFT)&0x8000)
\r
3034 AdjustSelection();
\r
3037 EnsureCaretVisible();
\r
3041 void CBaseView::ClearCurrentSelection()
\r
3043 m_ptSelectionStartPos = m_ptCaretPos;
\r
3044 m_ptSelectionEndPos = m_ptCaretPos;
\r
3045 m_ptSelectionOrigin = m_ptCaretPos;
\r
3046 m_nSelBlockStart = -1;
\r
3047 m_nSelBlockEnd = -1;
\r
3048 Invalidate(FALSE);
\r
3051 void CBaseView::ClearSelection()
\r
3054 m_pwndLeft->ClearCurrentSelection();
\r
3056 m_pwndRight->ClearCurrentSelection();
\r
3058 m_pwndBottom->ClearCurrentSelection();
\r
3061 void CBaseView::AdjustSelection()
\r
3063 if ((m_ptCaretPos.y < m_ptSelectionOrigin.y) ||
\r
3064 (m_ptCaretPos.y == m_ptSelectionOrigin.y && m_ptCaretPos.x <= m_ptSelectionOrigin.x))
\r
3066 m_ptSelectionStartPos = m_ptCaretPos;
\r
3067 m_ptSelectionEndPos = m_ptSelectionOrigin;
\r
3070 if ((m_ptCaretPos.y > m_ptSelectionOrigin.y) ||
\r
3071 (m_ptCaretPos.y == m_ptSelectionOrigin.y && m_ptCaretPos.x >= m_ptSelectionOrigin.x))
\r
3073 m_ptSelectionStartPos = m_ptSelectionOrigin;
\r
3074 m_ptSelectionEndPos = m_ptCaretPos;
\r
3077 SetupSelection(min(m_ptSelectionStartPos.y, m_ptSelectionEndPos.y), max(m_ptSelectionStartPos.y, m_ptSelectionEndPos.y));
\r
3079 Invalidate(FALSE);
\r
3082 void CBaseView::OnEditCut()
\r
3084 if (!m_bCaretHidden)
\r
3087 RemoveSelectedText();
\r
3091 void CBaseView::OnEditPaste()
\r
3093 if (!m_bCaretHidden)
\r