1
// TortoiseGitMerge - a Diff/Patch program
3 // Copyright (C) 2003-2016 - TortoiseSVN
4 // Copyright (C) 2011-2012 Sven Strickroth <email@cs-ware.de>
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.
23 #include "TortoiseMerge.h"
26 #include "DiffColors.h"
27 #include "StringUtils.h"
29 #include "GotoLineDlg.h"
30 #include "EncodingDlg.h"
31 #include "EditorConfigWrapper.h"
34 // We use three different kind of lines here:
35 // 1. The real lines of the original files.
36 // These are shown in the view margin and are not used elsewhere, they're only for user information.
38 // The lines actually shown on screen. All methods use screen lines as parameters/outputs if not explicitly specified otherwise.
40 // These are the lines of the diff data. If unmodified sections are collapsed, not all of those lines are shown.
42 // Basically view lines are the line data, while screen lines are shown lines.
49 #define MARGINWIDTH 20
50 #define HEADERHEIGHT 10
52 #define IDT_SCROLLTIMER 101
54 CBaseView
* CBaseView::m_pwndLeft
= NULL
;
55 CBaseView
* CBaseView::m_pwndRight
= NULL
;
56 CBaseView
* CBaseView::m_pwndBottom
= NULL
;
57 CLocatorBar
* CBaseView::m_pwndLocator
= NULL
;
58 CLineDiffBar
* CBaseView::m_pwndLineDiffBar
= NULL
;
59 CMFCStatusBar
* CBaseView::m_pwndStatusBar
= NULL
;
60 CMFCRibbonStatusBar
* CBaseView::m_pwndRibbonStatusBar
= NULL
;
61 CMainFrame
* CBaseView::m_pMainFrame
= NULL
;
62 CBaseView::Screen2View
CBaseView::m_Screen2View
;
63 const UINT
CBaseView::m_FindDialogMessage
= RegisterWindowMessage(FINDMSGSTRING
);
65 allviewstate
CBaseView::m_AllState
;
67 IMPLEMENT_DYNCREATE(CBaseView
, CView
)
69 CBaseView::CBaseView()
70 : m_pCacheBitmap(NULL
)
72 , m_pOtherViewData(NULL
)
77 , m_nLastScreenChars(-1)
78 , m_nMaxLineLength(-1)
84 , m_mouseInMargin(false)
86 , m_lineendings(EOL_AUTOLINE
)
88 , m_bReadonlyIsChangable(false)
91 , m_nSelViewBlockStart(-1)
92 , m_nSelViewBlockEnd(-1)
94 , m_bShowSelection(true)
95 , m_texttype(CFileTextLines::AUTOTYPE
)
97 , m_bOtherDiffChecked(false)
98 , m_bInlineWordDiff(true)
99 , m_bWhitespaceInlineDiffs(false)
101 , m_pFindDialog(NULL
)
103 , m_bMatchCase(false)
104 , m_bLimitToDiff(true)
105 , m_bWholeWord(false)
107 , m_pWorkingFile(NULL
)
108 , m_bInsertMode(true)
109 , m_bEditorConfigEnabled(false)
110 , m_bEditorConfigLoaded(2) // 2 = not evaluated
112 m_ptCaretViewPos
.x
= 0;
113 m_ptCaretViewPos
.y
= 0;
114 m_ptSelectionViewPosStart
= m_ptCaretViewPos
;
115 m_ptSelectionViewPosEnd
= m_ptSelectionViewPosStart
;
116 m_ptSelectionViewPosOrigin
= m_ptSelectionViewPosEnd
;
117 m_bViewWhitespace
= CRegDWORD(_T("Software\\TortoiseGitMerge\\ViewWhitespaces"), 1);
118 m_bViewLinenumbers
= CRegDWORD(_T("Software\\TortoiseGitMerge\\ViewLinenumbers"), 1);
119 m_bShowInlineDiff
= CRegDWORD(_T("Software\\TortoiseGitMerge\\DisplayBinDiff"), TRUE
);
120 m_nInlineDiffMaxLineLength
= CRegDWORD(_T("Software\\TortoiseGitMerge\\InlineDiffMaxLineLength"), 3000);
121 m_InlineAddedBk
= CRegDWORD(_T("Software\\TortoiseGitMerge\\InlineAdded"), INLINEADDED_COLOR
);
122 m_InlineRemovedBk
= CRegDWORD(_T("Software\\TortoiseGitMerge\\InlineRemoved"), INLINEREMOVED_COLOR
);
123 m_ModifiedBk
= CRegDWORD(_T("Software\\TortoiseGitMerge\\Colors\\ColorModifiedB"), MODIFIED_COLOR
);
124 m_WhiteSpaceFg
= CRegDWORD(_T("Software\\TortoiseGitMerge\\Colors\\Whitespace"), GetSysColor(COLOR_GRAYTEXT
));
125 m_sWordSeparators
= CRegString(_T("Software\\TortoiseGitMerge\\WordSeparators"), _T("[]();:.,{}!@#$%^&*-+=|/\\<>'`~\"?"));
126 m_bIconLFs
= CRegDWORD(_T("Software\\TortoiseGitMerge\\IconLFs"), 0);
127 m_nTabSize
= (int)(DWORD
)CRegDWORD(_T("Software\\TortoiseGitMerge\\TabSize"), 4);
128 m_nTabMode
= (int)(DWORD
)CRegDWORD(_T("Software\\TortoiseGitMerge\\TabMode"), TABMODE_NONE
);
129 m_bEditorConfigEnabled
= !!(DWORD
)CRegDWORD(_T("Software\\TortoiseGitMerge\\EnableEditorConfig"), FALSE
);
130 std::fill_n(m_apFonts
, fontsCount
, (CFont
*)NULL
);
131 m_hConflictedIcon
= LoadIcon(IDI_CONFLICTEDLINE
);
132 m_hConflictedIgnoredIcon
= LoadIcon(IDI_CONFLICTEDIGNOREDLINE
);
133 m_hRemovedIcon
= LoadIcon(IDI_REMOVEDLINE
);
134 m_hAddedIcon
= LoadIcon(IDI_ADDEDLINE
);
135 m_hWhitespaceBlockIcon
= LoadIcon(IDI_WHITESPACELINE
);
136 m_hEqualIcon
= LoadIcon(IDI_EQUALLINE
);
137 m_hLineEndingCR
= LoadIcon(IDI_LINEENDINGCR
);
138 m_hLineEndingCRLF
= LoadIcon(IDI_LINEENDINGCRLF
);
139 m_hLineEndingLF
= LoadIcon(IDI_LINEENDINGLF
);
140 m_hEditedIcon
= LoadIcon(IDI_LINEEDITED
);
141 m_hMovedIcon
= LoadIcon(IDI_MOVEDLINE
);
142 m_hMarkedIcon
= LoadIcon(IDI_LINEMARKED
);
143 m_margincursor
= (HCURSOR
)LoadImage(AfxGetResourceHandle(), MAKEINTRESOURCE(IDC_MARGINCURSOR
), IMAGE_CURSOR
, 0, 0, LR_DEFAULTSIZE
);
145 for (int i
=0; i
<1024; ++i
)
146 m_sConflictedText
+= _T("??");
147 m_sNoLineNr
.LoadString(IDS_EMPTYLINETT
);
151 SecureZeroMemory(&m_lfBaseFont
, sizeof(m_lfBaseFont
));
154 m_Eols
[EOL_LF
] = L
"\n"; // x0a
155 m_Eols
[EOL_CR
] = L
"\r"; // x0d
156 m_Eols
[EOL_CRLF
] = L
"\r\n"; // x0d x0a
157 m_Eols
[EOL_LFCR
] = L
"\n\r";
158 m_Eols
[EOL_VT
] = L
"\v"; // x0b
159 m_Eols
[EOL_FF
] = L
"\f"; // x0c
160 m_Eols
[EOL_NEL
] = L
"\x85";
161 m_Eols
[EOL_LS
] = L
"\x2028";
162 m_Eols
[EOL_PS
] = L
"\x2029";
163 m_Eols
[EOL_AUTOLINE
] = m_Eols
[m_lineendings
==EOL_AUTOLINE
166 m_SaveParams
.m_LineEndings
= EOL::EOL_AUTOLINE
;
167 m_SaveParams
.m_UnicodeType
= CFileTextLines::AUTOTYPE
;
170 CBaseView::~CBaseView()
174 DestroyIcon(m_hAddedIcon
);
175 DestroyIcon(m_hRemovedIcon
);
176 DestroyIcon(m_hConflictedIcon
);
177 DestroyIcon(m_hConflictedIgnoredIcon
);
178 DestroyIcon(m_hWhitespaceBlockIcon
);
179 DestroyIcon(m_hEqualIcon
);
180 DestroyIcon(m_hLineEndingCR
);
181 DestroyIcon(m_hLineEndingCRLF
);
182 DestroyIcon(m_hLineEndingLF
);
183 DestroyIcon(m_hEditedIcon
);
184 DestroyIcon(m_hMovedIcon
);
185 DestroyIcon(m_hMarkedIcon
);
186 DestroyCursor(m_margincursor
);
189 BEGIN_MESSAGE_MAP(CBaseView
, CView
)
202 ON_COMMAND(ID_NAVIGATE_NEXTDIFFERENCE
, OnMergeNextdifference
)
203 ON_COMMAND(ID_NAVIGATE_PREVIOUSDIFFERENCE
, OnMergePreviousdifference
)
204 ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTW
, 0, 0xFFFF, OnToolTipNotify
)
205 ON_NOTIFY_EX_RANGE(TTN_NEEDTEXTA
, 0, 0xFFFF, OnToolTipNotify
)
208 ON_COMMAND(ID_EDIT_COPY
, OnEditCopy
)
210 ON_COMMAND(ID_NAVIGATE_PREVIOUSCONFLICT
, OnMergePreviousconflict
)
211 ON_COMMAND(ID_NAVIGATE_NEXTCONFLICT
, OnMergeNextconflict
)
213 ON_COMMAND(ID_CARET_DOWN
, &CBaseView::OnCaretDown
)
214 ON_COMMAND(ID_CARET_LEFT
, &CBaseView::OnCaretLeft
)
215 ON_COMMAND(ID_CARET_RIGHT
, &CBaseView::OnCaretRight
)
216 ON_COMMAND(ID_CARET_UP
, &CBaseView::OnCaretUp
)
217 ON_COMMAND(ID_CARET_WORDLEFT
, &CBaseView::OnCaretWordleft
)
218 ON_COMMAND(ID_CARET_WORDRIGHT
, &CBaseView::OnCaretWordright
)
219 ON_COMMAND(ID_EDIT_CUT
, &CBaseView::OnEditCut
)
220 ON_COMMAND(ID_EDIT_PASTE
, &CBaseView::OnEditPaste
)
222 ON_WM_LBUTTONDBLCLK()
223 ON_COMMAND(ID_NAVIGATE_NEXTINLINEDIFF
, &CBaseView::OnNavigateNextinlinediff
)
224 ON_COMMAND(ID_NAVIGATE_PREVINLINEDIFF
, &CBaseView::OnNavigatePrevinlinediff
)
225 ON_COMMAND(ID_EDIT_SELECTALL
, &CBaseView::OnEditSelectall
)
226 ON_COMMAND(ID_EDIT_FIND
, OnEditFind
)
227 ON_REGISTERED_MESSAGE(m_FindDialogMessage
, OnFindDialogMessage
)
228 ON_COMMAND(ID_EDIT_FINDNEXT
, OnEditFindnext
)
229 ON_COMMAND(ID_EDIT_FINDPREV
, OnEditFindprev
)
230 ON_COMMAND(ID_EDIT_FINDNEXTSTART
, OnEditFindnextStart
)
231 ON_COMMAND(ID_EDIT_FINDPREVSTART
, OnEditFindprevStart
)
232 ON_COMMAND(ID_EDIT_GOTOLINE
, &CBaseView::OnEditGotoline
)
237 void CBaseView::DocumentUpdated()
243 m_nLastScreenChars
= -1;
244 m_nMaxLineLength
= -1;
248 m_bOtherDiffChecked
= false;
251 m_nTabSize
= (int)(DWORD
)CRegDWORD(_T("Software\\TortoiseGitMerge\\TabSize"), 4);
252 m_nTabMode
= (int)(DWORD
)CRegDWORD(_T("Software\\TortoiseGitMerge\\TabMode"), TABMODE_NONE
);
253 m_bViewLinenumbers
= CRegDWORD(_T("Software\\TortoiseGitMerge\\ViewLinenumbers"), 1);
254 m_InlineAddedBk
= CRegDWORD(_T("Software\\TortoiseGitMerge\\InlineAdded"), INLINEADDED_COLOR
);
255 m_InlineRemovedBk
= CRegDWORD(_T("Software\\TortoiseGitMerge\\InlineRemoved"), INLINEREMOVED_COLOR
);
256 m_ModifiedBk
= CRegDWORD(_T("Software\\TortoiseGitMerge\\Colors\\ColorModifiedB"), MODIFIED_COLOR
);
257 m_WhiteSpaceFg
= CRegDWORD(_T("Software\\TortoiseGitMerge\\Colors\\Whitespace"), GetSysColor(COLOR_GRAYTEXT
));
258 m_bIconLFs
= CRegDWORD(_T("Software\\TortoiseGitMerge\\IconLFs"), 0);
259 m_nInlineDiffMaxLineLength
= CRegDWORD(_T("Software\\TortoiseGitMerge\\InlineDiffMaxLineLength"), 3000);
260 m_Eols
[EOL_AUTOLINE
] = m_Eols
[m_lineendings
==EOL_AUTOLINE
263 SetEditorConfigEnabled(m_bEditorConfigEnabled
);
265 ClearCurrentSelection();
270 void CBaseView::SetEditorConfigEnabled(bool bEditorConfigEnabled
)
272 m_bEditorConfigEnabled
= bEditorConfigEnabled
;
273 m_nTabSize
= (int)(DWORD
)CRegDWORD(_T("Software\\TortoiseGitMerge\\TabSize"), 4);
274 m_nTabMode
= (int)(DWORD
)CRegDWORD(_T("Software\\TortoiseGitMerge\\TabMode"), TABMODE_NONE
);
275 if (m_bEditorConfigEnabled
)
277 m_bEditorConfigLoaded
= FALSE
; // no editorconfig entries loaded
278 CEditorConfigWrapper ec
;
279 if (ec
.Load(m_sReflectedName
.IsEmpty() ? m_sFullFilePath
: m_sReflectedName
))
281 m_bEditorConfigLoaded
= TRUE
;
282 if (ec
.m_nTabWidth
!= nullptr)
283 m_nTabSize
= ec
.m_nTabWidth
;
284 if (ec
.m_bIndentStyle
!= nullptr)
285 m_nTabMode
= (m_nTabMode
& ~TABMODE_USESPACES
) | (ec
.m_bIndentStyle
? TABMODE_USESPACES
: TABMODE_NONE
);
290 static CString
GetTabModeString(int nTabMode
, int nTabSize
, bool bEditorConfig
)
293 if (nTabMode
& TABMODE_USESPACES
)
297 text
.AppendFormat(L
" %d", nTabSize
);
298 if (nTabMode
& TABMODE_SMARTINDENT
)
305 void CBaseView::UpdateStatusBar()
307 int nRemovedLines
= 0;
309 int nConflictedLines
= 0;
313 for (int i
=0; i
<m_pViewData
->GetCount(); i
++)
315 DiffStates state
= m_pViewData
->GetState(i
);
318 case DIFFSTATE_ADDED
:
319 case DIFFSTATE_IDENTICALADDED
:
320 case DIFFSTATE_THEIRSADDED
:
321 case DIFFSTATE_YOURSADDED
:
322 case DIFFSTATE_CONFLICTADDED
:
325 case DIFFSTATE_IDENTICALREMOVED
:
326 case DIFFSTATE_REMOVED
:
327 case DIFFSTATE_THEIRSREMOVED
:
328 case DIFFSTATE_YOURSREMOVED
:
331 case DIFFSTATE_CONFLICTED
:
332 case DIFFSTATE_CONFLICTED_IGNORED
:
344 sBarText
+= CFileTextLines::GetEncodingName(m_texttype
);
345 sBarText
+= sBarText
.IsEmpty() ? L
"" : L
" ";
346 sBarText
+= GetEolName(m_lineendings
);
347 sBarText
+= sBarText
.IsEmpty() ? L
"" : L
" ";
349 if (sBarText
.IsEmpty())
350 sBarText
+= _T(" / ");
355 sTemp
.Format(IDS_STATUSBAR_REMOVEDLINES
, nRemovedLines
);
356 if (!sBarText
.IsEmpty())
357 sBarText
+= _T(" / ");
362 sTemp
.Format(IDS_STATUSBAR_ADDEDLINES
, nAddedLines
);
363 if (!sBarText
.IsEmpty())
364 sBarText
+= _T(" / ");
367 if (nConflictedLines
)
369 sTemp
.Format(IDS_STATUSBAR_CONFLICTEDLINES
, nConflictedLines
);
370 if (!sBarText
.IsEmpty())
371 sBarText
+= _T(" / ");
374 if (m_pwndStatusBar
|| m_pwndRibbonStatusBar
)
381 if (m_nStatusBarID
== ID_INDICATOR_BOTTOMVIEW
)
383 sBarText
.Format(IDS_STATUSBAR_CONFLICTS
, nConflictedLines
);
385 if (m_nStatusBarID
== ID_INDICATOR_LEFTVIEW
)
387 sTemp
.LoadString(IDS_STATUSBAR_LEFTVIEW
);
388 sBarText
= sTemp
+sBarText
;
390 if (m_nStatusBarID
== ID_INDICATOR_RIGHTVIEW
)
392 sTemp
.LoadString(IDS_STATUSBAR_RIGHTVIEW
);
393 sBarText
= sTemp
+sBarText
;
395 int nIndex
= m_pwndStatusBar
->CommandToIndex(m_nStatusBarID
);
396 m_pwndStatusBar
->GetPaneInfo(nIndex
, nID
, nStyle
, cxWidth
);
397 //calculate the width of the text
398 CDC
* pDC
= m_pwndStatusBar
->GetDC();
401 CSize size
= pDC
->GetTextExtent(sBarText
);
402 m_pwndStatusBar
->SetPaneInfo(nIndex
, nID
, nStyle
, size
.cx
+2);
405 m_pwndStatusBar
->SetPaneText(nIndex
, sBarText
);
407 else if (m_pwndRibbonStatusBar
)
409 if (!IsViewGood(m_pwndBottom
))
410 m_pwndRibbonStatusBar
->RemoveElement(ID_INDICATOR_BOTTOMVIEW
);
411 if ((m_nStatusBarID
== ID_INDICATOR_BOTTOMVIEW
) && (IsViewGood(this)))
413 m_pwndRibbonStatusBar
->RemoveElement(ID_INDICATOR_BOTTOMVIEW
);
414 auto apBtnGroupBottom
= std::make_unique
<CMFCRibbonButtonsGroup
>();
415 apBtnGroupBottom
->SetID(ID_INDICATOR_BOTTOMVIEW
);
416 apBtnGroupBottom
->AddButton(new CMFCRibbonStatusBarPane(ID_SEPARATOR
, CString(MAKEINTRESOURCE(IDS_STATUSBAR_BOTTOMVIEW
)), TRUE
));
417 CMFCRibbonButton
* pButton
= new CMFCRibbonButton(ID_INDICATOR_BOTTOMVIEWCOMBOENCODING
, L
"");
418 m_pMainFrame
->FillEncodingButton(pButton
, ID_INDICATOR_BOTTOMENCODINGSTART
);
419 apBtnGroupBottom
->AddButton(pButton
);
420 pButton
= new CMFCRibbonButton(ID_INDICATOR_BOTTOMVIEWCOMBOEOL
, L
"");
421 m_pMainFrame
->FillEOLButton(pButton
, ID_INDICATOR_BOTTOMEOLSTART
);
422 apBtnGroupBottom
->AddButton(pButton
);
423 pButton
= new CMFCRibbonButton(ID_INDICATOR_BOTTOMVIEWCOMBOTABMODE
, L
"");
424 m_pMainFrame
->FillEOLButton(pButton
, ID_INDICATOR_BOTTOMTABMODESTART
);
425 apBtnGroupBottom
->AddButton(pButton
);
426 apBtnGroupBottom
->AddButton(new CMFCRibbonStatusBarPane(ID_INDICATOR_BOTTOMVIEW
, L
"", TRUE
));
427 m_pwndRibbonStatusBar
->AddExtendedElement(apBtnGroupBottom
.release(), L
"");
430 CMFCRibbonButtonsGroup
* pGroup
= DYNAMIC_DOWNCAST(CMFCRibbonButtonsGroup
, m_pwndRibbonStatusBar
->FindByID(m_nStatusBarID
));
433 CMFCRibbonStatusBarPane
* pPane
= DYNAMIC_DOWNCAST(CMFCRibbonStatusBarPane
, pGroup
->GetButton(4));
436 pPane
->SetText(sBarText
);
438 CMFCRibbonButton
* pButton
= DYNAMIC_DOWNCAST(CMFCRibbonButton
, pGroup
->GetButton(1));
441 pButton
->SetText(CFileTextLines::GetEncodingName(m_texttype
));
442 pButton
->SetDescription(CFileTextLines::GetEncodingName(m_texttype
));
444 pButton
= DYNAMIC_DOWNCAST(CMFCRibbonButton
, pGroup
->GetButton(2));
447 pButton
->SetText(GetEolName(m_lineendings
));
448 pButton
->SetDescription(GetEolName(m_lineendings
));
450 pButton
= DYNAMIC_DOWNCAST(CMFCRibbonButton
, pGroup
->GetButton(3));
453 pButton
->SetText(GetTabModeString(m_nTabMode
, m_nTabSize
, m_bEditorConfigEnabled
&& m_bEditorConfigLoaded
));
454 pButton
->SetDescription(GetTabModeString(m_nTabMode
, m_nTabSize
, m_bEditorConfigEnabled
&& m_bEditorConfigLoaded
));
457 m_pwndRibbonStatusBar
->RecalcLayout();
458 m_pwndRibbonStatusBar
->Invalidate();
463 BOOL
CBaseView::PreCreateWindow(CREATESTRUCT
& cs
)
465 if (!CView::PreCreateWindow(cs
))
468 cs
.dwExStyle
|= WS_EX_CLIENTEDGE
;
469 cs
.style
&= ~WS_BORDER
;
470 cs
.lpszClass
= AfxRegisterWndClass(CS_HREDRAW
|CS_VREDRAW
|CS_DBLCLKS
,
471 ::LoadCursor(NULL
, IDC_ARROW
), reinterpret_cast<HBRUSH
>(COLOR_WINDOW
+1), NULL
);
473 CWnd
*pParentWnd
= CWnd::FromHandlePermanent(cs
.hwndParent
);
474 if (pParentWnd
== NULL
|| ! pParentWnd
->IsKindOf(RUNTIME_CLASS(CSplitterWnd
)))
476 // View must always create its own scrollbars,
477 // if only it's not used within splitter
478 cs
.style
|= (WS_HSCROLL
| WS_VSCROLL
);
480 cs
.lpszClass
= AfxRegisterWndClass(CS_DBLCLKS
);
484 CFont
* CBaseView::GetFont(BOOL bItalic
/*= FALSE*/, BOOL bBold
/*= FALSE*/)
491 if (m_apFonts
[nIndex
] == NULL
)
493 m_apFonts
[nIndex
] = new CFont
;
494 m_lfBaseFont
.lfCharSet
= DEFAULT_CHARSET
;
495 m_lfBaseFont
.lfWeight
= bBold
? FW_BOLD
: FW_NORMAL
;
496 m_lfBaseFont
.lfItalic
= (BYTE
) bItalic
;
500 m_lfBaseFont
.lfHeight
= -MulDiv((DWORD
)CRegDWORD(_T("Software\\TortoiseGitMerge\\LogFontSize"), 10), GetDeviceCaps(pDC
->m_hDC
, LOGPIXELSY
), 72);
503 _tcsncpy_s(m_lfBaseFont
.lfFaceName
, (LPCTSTR
)(CString
)CRegString(_T("Software\\TortoiseGitMerge\\LogFontName"), _T("Courier New")), _countof(m_lfBaseFont
.lfFaceName
) - 1);
504 if (!m_apFonts
[nIndex
]->CreateFontIndirect(&m_lfBaseFont
))
506 delete m_apFonts
[nIndex
];
507 m_apFonts
[nIndex
] = NULL
;
508 return CView::GetFont();
511 return m_apFonts
[nIndex
];
514 void CBaseView::CalcLineCharDim()
519 CFont
*pOldFont
= pDC
->SelectObject(GetFont());
520 const CSize szCharExt
= pDC
->GetTextExtent(_T("X"));
521 pDC
->SelectObject(pOldFont
);
524 m_nLineHeight
= szCharExt
.cy
;
525 if (m_nLineHeight
<= 0)
527 m_nCharWidth
= szCharExt
.cx
;
528 if (m_nCharWidth
<= 0)
532 int CBaseView::GetScreenChars()
534 if (m_nScreenChars
== -1)
537 GetClientRect(&rect
);
538 m_nScreenChars
= (rect
.Width() - GetMarginWidth() - GetSystemMetrics(SM_CXVSCROLL
)) / GetCharWidth();
539 if (m_nScreenChars
< 0)
542 return m_nScreenChars
;
545 int CBaseView::GetAllMinScreenChars() const
547 int nChars
= INT_MAX
;
548 if (IsLeftViewGood())
549 nChars
= std::min
<int>(nChars
, m_pwndLeft
->GetScreenChars());
550 if (IsRightViewGood())
551 nChars
= std::min
<int>(nChars
, m_pwndRight
->GetScreenChars());
552 if (IsBottomViewGood())
553 nChars
= std::min
<int>(nChars
, m_pwndBottom
->GetScreenChars());
554 return (nChars
==INT_MAX
) ? 0 : nChars
;
557 int CBaseView::GetAllMaxLineLength() const
560 if (IsLeftViewGood())
561 nLength
= std::max
<int>(nLength
, m_pwndLeft
->GetMaxLineLength());
562 if (IsRightViewGood())
563 nLength
= std::max
<int>(nLength
, m_pwndRight
->GetMaxLineLength());
564 if (IsBottomViewGood())
565 nLength
= std::max
<int>(nLength
, m_pwndBottom
->GetMaxLineLength());
569 int CBaseView::GetLineHeight()
571 if (m_nLineHeight
== -1)
573 if (m_nLineHeight
<= 0)
575 return m_nLineHeight
;
578 int CBaseView::GetCharWidth()
580 if (m_nCharWidth
== -1)
582 if (m_nCharWidth
<= 0)
587 int CBaseView::GetMaxLineLength()
589 if (m_nMaxLineLength
== -1)
591 m_nMaxLineLength
= 0;
592 int nLineCount
= GetLineCount();
594 return GetLineLengthWithTabsConverted(0);
595 for (int i
=0; i
<nLineCount
; i
++)
597 int nActualLength
= GetLineLengthWithTabsConverted(i
);
598 if (m_nMaxLineLength
< nActualLength
)
599 m_nMaxLineLength
= nActualLength
;
602 return m_nMaxLineLength
;
605 int CBaseView::GetLineLengthWithTabsConverted(int index
)
607 if (m_pViewData
== NULL
)
609 if (m_pViewData
->GetCount() == 0)
611 if ((int)m_Screen2View
.size() <= index
)
614 if (m_pMainFrame
->m_bWrapLines
)
615 sLine
= GetLineChars(index
);
618 int viewLine
= GetViewLineForScreen(index
);
619 sLine
= m_pViewData
->GetLine(viewLine
);
622 wchar_t* pChar
= (LPWSTR
)(LPCWSTR
)sLine
;
623 auto nLineLength
= sLine
.GetLength();
624 for (int i
= 0; i
< nLineLength
; ++i
)
630 // GetTabSize() - 1 because the tabs are already counted
631 nLineLength
= nLineLength
+ (tabCount
* (GetTabSize() - 1));
632 ASSERT(nLineLength
>= 0);
636 int CBaseView::GetLineLength(int index
)
638 if (m_pViewData
== NULL
)
640 if (m_pViewData
->GetCount() == 0)
642 if ((int)m_Screen2View
.size() <= index
)
644 int viewLine
= GetViewLineForScreen(index
);
645 if (m_pMainFrame
->m_bWrapLines
)
647 int nLineLength
= GetLineChars(index
).GetLength();
648 ASSERT(nLineLength
>= 0);
651 int nLineLength
= m_pViewData
->GetLine(viewLine
).GetLength();
652 ASSERT(nLineLength
>= 0);
656 int CBaseView::GetViewLineLength(int nViewLine
) const
658 if (m_pViewData
== NULL
)
660 if (m_pViewData
->GetCount() <= nViewLine
)
662 int nLineLength
= m_pViewData
->GetLine(nViewLine
).GetLength();
663 ASSERT(nLineLength
>= 0);
667 int CBaseView::GetLineCount() const
669 if (m_pViewData
== NULL
)
671 int nLineCount
= (int)m_Screen2View
.size();
672 ASSERT(nLineCount
>= 0);
676 int CBaseView::GetSubLineOffset(int index
)
678 return m_Screen2View
.GetSubLineOffset(index
);
681 CString
CBaseView::GetViewLineChars(int nViewLine
) const
683 if (m_pViewData
== NULL
)
685 if (m_pViewData
->GetCount() <= nViewLine
)
687 return m_pViewData
->GetLine(nViewLine
);
690 CString
CBaseView::GetLineChars(int index
)
692 if (m_pViewData
== NULL
)
694 if (m_pViewData
->GetCount() == 0)
696 if ((int)m_Screen2View
.size() <= index
)
698 int viewLine
= GetViewLineForScreen(index
);
699 if (m_pMainFrame
->m_bWrapLines
)
701 int subLine
= GetSubLineOffset(index
);
704 if (subLine
< CountMultiLines(viewLine
))
706 return m_ScreenedViewLine
[viewLine
].SubLines
[subLine
];
711 return m_pViewData
->GetLine(viewLine
);
714 void CBaseView::CheckOtherView()
716 if (m_bOtherDiffChecked
)
718 // find out what the 'other' file is
719 m_pOtherViewData
= NULL
;
721 if (this == m_pwndLeft
&& IsRightViewGood())
723 m_pOtherViewData
= m_pwndRight
->m_pViewData
;
724 m_pOtherView
= m_pwndRight
;
727 if (this == m_pwndRight
&& IsLeftViewGood())
729 m_pOtherViewData
= m_pwndLeft
->m_pViewData
;
730 m_pOtherView
= m_pwndLeft
;
733 m_bOtherDiffChecked
= true;
737 void CBaseView::GetWhitespaceBlock(CViewData
*viewData
, int nLineIndex
, int & nStartBlock
, int & nEndBlock
)
739 enum { MAX_WHITESPACEBLOCK_SIZE
= 8 };
742 DiffStates origstate
= viewData
->GetState(nLineIndex
);
744 // Go back and forward at most MAX_WHITESPACEBLOCK_SIZE lines to see where this block ends
745 nStartBlock
= nLineIndex
;
746 nEndBlock
= nLineIndex
;
747 while ((nStartBlock
> 0) && (nStartBlock
> (nLineIndex
- MAX_WHITESPACEBLOCK_SIZE
)))
749 DiffStates state
= viewData
->GetState(nStartBlock
- 1);
750 if ((origstate
== DIFFSTATE_EMPTY
) && (state
!= DIFFSTATE_NORMAL
))
752 if ((origstate
== state
) || (state
== DIFFSTATE_EMPTY
))
757 while ((nEndBlock
< (viewData
->GetCount() - 1)) && (nEndBlock
< (nLineIndex
+ MAX_WHITESPACEBLOCK_SIZE
)))
759 DiffStates state
= viewData
->GetState(nEndBlock
+ 1);
760 if ((origstate
== DIFFSTATE_EMPTY
) && (state
!= DIFFSTATE_NORMAL
))
762 if ((origstate
== state
) || (state
== DIFFSTATE_EMPTY
))
769 CString
CBaseView::GetWhitespaceString(CViewData
*viewData
, int nStartBlock
, int nEndBlock
)
771 enum { MAX_WHITESPACEBLOCK_SIZE
= 8 };
774 for (int i
= nStartBlock
; i
<= nEndBlock
; ++i
)
775 len
+= viewData
->GetLine(i
).GetLength()+2;
778 // do not check for whitespace blocks if the line is too long, because
779 // reserving a lot of memory here takes too much time (performance hog)
780 if (len
> MAX_WHITESPACEBLOCK_SIZE
*256)
782 block
.Preallocate(len
+1);
783 for (int i
= nStartBlock
; i
<= nEndBlock
; ++i
)
785 block
+= viewData
->GetLine(i
);
786 block
+= m_Eols
[viewData
->GetLineEnding(i
)];
791 bool CBaseView::IsBlockWhitespaceOnly(int nLineIndex
, bool& bIdentical
, int& blockstart
, int& blockend
)
793 if (m_pViewData
== NULL
)
797 if (!m_pOtherViewData
)
799 int viewLine
= GetViewLineForScreen(nLineIndex
);
801 (m_pViewData
->GetState(viewLine
) == DIFFSTATE_NORMAL
) &&
802 (m_pOtherViewData
->GetLine(viewLine
) == m_pViewData
->GetLine(viewLine
))
808 // first check whether the line itself only has whitespace changes
809 CString mine
= m_pViewData
->GetLine(viewLine
);
810 CString other
= m_pOtherViewData
->GetLine(min(viewLine
, m_pOtherViewData
->GetCount() - 1));
811 if (mine
.IsEmpty() && other
.IsEmpty())
822 FilterWhitespaces(mine
, other
);
826 int nStartBlock2
, nEndBlock2
;
827 GetWhitespaceBlock(m_pViewData
, viewLine
, blockstart
, blockend
);
828 GetWhitespaceBlock(m_pOtherViewData
, min(viewLine
, m_pOtherViewData
->GetCount() - 1), nStartBlock2
, nEndBlock2
);
829 mine
= GetWhitespaceString(m_pViewData
, blockstart
, blockend
);
834 other
= GetWhitespaceString(m_pOtherViewData
, nStartBlock2
, nEndBlock2
);
835 bIdentical
= mine
== other
;
836 FilterWhitespaces(mine
, other
);
839 return (!mine
.IsEmpty()) && (mine
== other
);
842 bool CBaseView::IsViewLineHidden(int nViewLine
)
844 return IsViewLineHidden(m_pViewData
, nViewLine
);
847 bool CBaseView::IsViewLineHidden(CViewData
* pViewData
, int nViewLine
)
849 return m_pMainFrame
->m_bCollapsed
&& (pViewData
->GetHideState(nViewLine
)!=HIDESTATE_SHOWN
);
852 int CBaseView::GetLineNumber(int index
) const
854 if (m_pViewData
== NULL
)
856 int viewLine
= GetViewLineForScreen(index
);
857 if (m_pViewData
->GetLineNumber(viewLine
)==DIFF_EMPTYLINENUMBER
)
859 return m_pViewData
->GetLineNumber(viewLine
);
862 int CBaseView::GetScreenLines()
864 if (m_nScreenLines
== -1)
867 GetClientRect(&rect
);
868 SCROLLBARINFO sbi
= { sizeof(sbi
) };
869 if (GetScrollBarInfo(OBJID_HSCROLL
, &sbi
))
871 // only use the scroll bar size if the info is correct and the scrollbar is visible
872 // if anything isn't proper, assume the scrollbar has a size of zero
873 // and calculate the screen lines without it.
874 if (!(sbi
.rgstate
[0] & STATE_SYSTEM_INVISIBLE
) && !(sbi
.rgstate
[0] & STATE_SYSTEM_UNAVAILABLE
))
876 int scrollBarHeight
= sbi
.rcScrollBar
.bottom
- sbi
.rcScrollBar
.top
;
877 m_nScreenLines
= (rect
.Height() - HEADERHEIGHT
- scrollBarHeight
) / GetLineHeight();
878 if (m_nScreenLines
< 0)
880 return m_nScreenLines
;
883 // if the scroll bar is not visible, unavailable or there was an error,
884 // assume the scroll bar height is zero and return the screen lines here.
885 // Of course, that means the cache (using the member variable) won't work
886 // and we fetch the scroll bar info every time. But in this case the overhead is necessary.
887 return (rect
.Height() - HEADERHEIGHT
) / GetLineHeight();
889 return m_nScreenLines
;
892 int CBaseView::GetAllMinScreenLines() const
894 int nLines
= INT_MAX
;
895 if (IsLeftViewGood())
896 nLines
= m_pwndLeft
->GetScreenLines();
897 if (IsRightViewGood())
898 nLines
= std::min
<int>(nLines
, m_pwndRight
->GetScreenLines());
899 if (IsBottomViewGood())
900 nLines
= std::min
<int>(nLines
, m_pwndBottom
->GetScreenLines());
901 return (nLines
== INT_MAX
) || (nLines
< 0) ? 0 : nLines
;
904 int CBaseView::GetAllLineCount() const
907 if (IsLeftViewGood())
908 nLines
= m_pwndLeft
->GetLineCount();
909 if (IsRightViewGood())
910 nLines
= std::max
<int>(nLines
, m_pwndRight
->GetLineCount());
911 if (IsBottomViewGood())
912 nLines
= std::max
<int>(nLines
, m_pwndBottom
->GetLineCount());
916 void CBaseView::RecalcAllVertScrollBars(BOOL bPositionOnly
/*= FALSE*/)
918 if (IsLeftViewGood())
919 m_pwndLeft
->RecalcVertScrollBar(bPositionOnly
);
920 if (IsRightViewGood())
921 m_pwndRight
->RecalcVertScrollBar(bPositionOnly
);
922 if (IsBottomViewGood())
923 m_pwndBottom
->RecalcVertScrollBar(bPositionOnly
);
926 void CBaseView::RecalcVertScrollBar(BOOL bPositionOnly
/*= FALSE*/)
929 si
.cbSize
= sizeof(si
);
933 si
.nPos
= m_nTopLine
;
937 EnableScrollBarCtrl(SB_VERT
, TRUE
);
938 if (GetAllMinScreenLines() >= GetAllLineCount() && m_nTopLine
> 0)
943 si
.fMask
= SIF_DISABLENOSCROLL
| SIF_PAGE
| SIF_POS
| SIF_RANGE
;
945 si
.nMax
= GetAllLineCount();
946 si
.nPage
= GetAllMinScreenLines();
947 si
.nPos
= m_nTopLine
;
949 VERIFY(SetScrollInfo(SB_VERT
, &si
));
952 void CBaseView::OnVScroll(UINT nSBCode
, UINT nPos
, CScrollBar
* pScrollBar
)
954 CView::OnVScroll(nSBCode
, nPos
, pScrollBar
);
956 m_pwndLeft
->OnDoVScroll(nSBCode
, nPos
, pScrollBar
, this);
958 m_pwndRight
->OnDoVScroll(nSBCode
, nPos
, pScrollBar
, this);
960 m_pwndBottom
->OnDoVScroll(nSBCode
, nPos
, pScrollBar
, this);
962 m_pwndLocator
->Invalidate();
965 void CBaseView::OnDoVScroll(UINT nSBCode
, UINT
/*nPos*/, CScrollBar
* /*pScrollBar*/, CBaseView
* master
)
967 // Note we cannot use nPos because of its 16-bit nature
969 si
.cbSize
= sizeof(si
);
971 VERIFY(master
->GetScrollInfo(SB_VERT
, &si
));
973 int nPageLines
= GetScreenLines();
974 int nLineCount
= GetLineCount();
978 static LONG textwidth
= 0;
979 static CString
sFormat(MAKEINTRESOURCE(IDS_VIEWSCROLLTIPTEXT
));
986 nNewTopLine
= nLineCount
- nPageLines
+ 1;
989 nNewTopLine
= m_nTopLine
- 1;
992 nNewTopLine
= m_nTopLine
+ 1;
995 nNewTopLine
= m_nTopLine
- si
.nPage
+ 1;
998 nNewTopLine
= m_nTopLine
+ si
.nPage
- 1;
1000 case SB_THUMBPOSITION
:
1001 m_ScrollTool
.Clear();
1002 nNewTopLine
= si
.nTrackPos
;
1006 nNewTopLine
= si
.nTrackPos
;
1007 if (GetFocus() == this)
1010 GetClientRect(&thumbrect
);
1011 ClientToScreen(&thumbrect
);
1014 thumbpoint
.x
= thumbrect
.right
;
1015 thumbpoint
.y
= thumbrect
.top
+ ((thumbrect
.bottom
-thumbrect
.top
)*si
.nTrackPos
)/(si
.nMax
-si
.nMin
);
1016 m_ScrollTool
.Init(&thumbpoint
);
1019 CString sTemp
= sFormat
;
1020 sTemp
.Format(sFormat
, m_nDigits
, 10*m_nDigits
-1);
1021 textwidth
= m_ScrollTool
.GetTextWidth(sTemp
);
1023 thumbpoint
.x
-= textwidth
;
1024 int line
= GetLineNumber(nNewTopLine
);
1026 m_ScrollTool
.SetText(&thumbpoint
, sFormat
, m_nDigits
, GetLineNumber(nNewTopLine
)+1);
1028 m_ScrollTool
.SetText(&thumbpoint
, m_sNoLineNr
);
1035 if (nNewTopLine
< 0)
1037 if (nNewTopLine
>= nLineCount
)
1038 nNewTopLine
= nLineCount
- 1;
1039 ScrollToLine(nNewTopLine
);
1042 void CBaseView::RecalcAllHorzScrollBars(BOOL bPositionOnly
/*= FALSE*/)
1044 if (IsLeftViewGood())
1045 m_pwndLeft
->RecalcHorzScrollBar(bPositionOnly
);
1046 if (IsRightViewGood())
1047 m_pwndRight
->RecalcHorzScrollBar(bPositionOnly
);
1048 if (IsBottomViewGood())
1049 m_pwndBottom
->RecalcHorzScrollBar(bPositionOnly
);
1052 void CBaseView::RecalcHorzScrollBar(BOOL bPositionOnly
/*= FALSE*/)
1055 si
.cbSize
= sizeof(si
);
1059 si
.nPos
= m_nOffsetChar
;
1063 EnableScrollBarCtrl(SB_HORZ
, !m_pMainFrame
->m_bWrapLines
);
1064 if (!m_pMainFrame
->m_bWrapLines
)
1066 int minScreenChars
= GetAllMinScreenChars();
1067 int maxLineLength
= GetAllMaxLineLength();
1068 if (minScreenChars
>= maxLineLength
&& m_nOffsetChar
> 0)
1073 si
.fMask
= SIF_DISABLENOSCROLL
| SIF_PAGE
| SIF_POS
| SIF_RANGE
;
1075 si
.nMax
= m_pMainFrame
->m_bWrapLines
? minScreenChars
: maxLineLength
;
1076 si
.nMax
+= GetMarginWidth()/GetCharWidth();
1077 si
.nPage
= GetScreenChars();
1078 si
.nPos
= m_nOffsetChar
;
1081 VERIFY(SetScrollInfo(SB_HORZ
, &si
));
1084 void CBaseView::OnHScroll(UINT nSBCode
, UINT nPos
, CScrollBar
* pScrollBar
)
1086 CView::OnHScroll(nSBCode
, nPos
, pScrollBar
);
1088 m_pwndLeft
->OnDoHScroll(nSBCode
, nPos
, pScrollBar
, this);
1090 m_pwndRight
->OnDoHScroll(nSBCode
, nPos
, pScrollBar
, this);
1092 m_pwndBottom
->OnDoHScroll(nSBCode
, nPos
, pScrollBar
, this);
1094 m_pwndLocator
->Invalidate();
1097 void CBaseView::OnDoHScroll(UINT nSBCode
, UINT
/*nPos*/, CScrollBar
* /*pScrollBar*/, CBaseView
* master
)
1100 si
.cbSize
= sizeof(si
);
1102 VERIFY(master
->GetScrollInfo(SB_HORZ
, &si
));
1104 int nPageChars
= GetScreenChars();
1105 int nMaxLineLength
= GetMaxLineLength();
1114 nNewOffset
= nMaxLineLength
- nPageChars
+ 1;
1117 nNewOffset
= m_nOffsetChar
- 1;
1120 nNewOffset
= m_nOffsetChar
+ 1;
1123 nNewOffset
= m_nOffsetChar
- si
.nPage
+ 1;
1126 nNewOffset
= m_nOffsetChar
+ si
.nPage
- 1;
1128 case SB_THUMBPOSITION
:
1130 nNewOffset
= si
.nTrackPos
;
1136 if (nNewOffset
>= nMaxLineLength
)
1137 nNewOffset
= nMaxLineLength
- 1;
1140 ScrollToChar(nNewOffset
, TRUE
);
1143 void CBaseView::ScrollToChar(int nNewOffsetChar
, BOOL bTrackScrollBar
/*= TRUE*/)
1145 if (m_nOffsetChar
!= nNewOffsetChar
)
1147 int nScrollChars
= m_nOffsetChar
- nNewOffsetChar
;
1148 m_nOffsetChar
= nNewOffsetChar
;
1150 GetClientRect(&rcScroll
);
1151 rcScroll
.left
+= GetMarginWidth();
1152 rcScroll
.top
+= GetLineHeight()+HEADERHEIGHT
;
1153 ScrollWindow(nScrollChars
* GetCharWidth(), 0, &rcScroll
, &rcScroll
);
1154 // update the view header
1157 rcScroll
.bottom
= GetLineHeight()+HEADERHEIGHT
;
1158 InvalidateRect(&rcScroll
, FALSE
);
1160 if (bTrackScrollBar
)
1161 RecalcHorzScrollBar(TRUE
);
1163 if (m_pwndLineDiffBar
)
1164 m_pwndLineDiffBar
->Invalidate();
1168 void CBaseView::ScrollAllToChar(int nNewOffsetChar
, BOOL bTrackScrollBar
/* = TRUE */)
1171 m_pwndLeft
->ScrollToChar(nNewOffsetChar
, bTrackScrollBar
);
1173 m_pwndRight
->ScrollToChar(nNewOffsetChar
, bTrackScrollBar
);
1175 m_pwndBottom
->ScrollToChar(nNewOffsetChar
, bTrackScrollBar
);
1178 void CBaseView::ScrollAllSide(int delta
)
1180 int nNewOffset
= m_nOffsetChar
;
1181 nNewOffset
+= delta
;
1182 int nMaxLineLength
= GetMaxLineLength();
1183 if (nNewOffset
>= nMaxLineLength
)
1184 nNewOffset
= nMaxLineLength
- 1;
1187 ScrollAllToChar(nNewOffset
, TRUE
);
1188 if (m_pwndLineDiffBar
)
1189 m_pwndLineDiffBar
->Invalidate();
1193 void CBaseView::ScrollSide(int delta
)
1195 int nNewOffset
= m_nOffsetChar
;
1196 nNewOffset
+= delta
;
1197 int nMaxLineLength
= GetMaxLineLength();
1198 if (nNewOffset
>= nMaxLineLength
)
1199 nNewOffset
= nMaxLineLength
- 1;
1202 ScrollToChar(nNewOffset
, TRUE
);
1203 if (m_pwndLineDiffBar
)
1204 m_pwndLineDiffBar
->Invalidate();
1208 void CBaseView::ScrollVertical(short zDelta
)
1210 const int nLineCount
= GetLineCount();
1211 int nTopLine
= m_nTopLine
;
1212 nTopLine
-= (zDelta
/30);
1215 if (nTopLine
>= nLineCount
)
1216 nTopLine
= nLineCount
- 1;
1217 ScrollToLine(nTopLine
, TRUE
);
1220 void CBaseView::ScrollToLine(int nNewTopLine
, BOOL bTrackScrollBar
/*= TRUE*/)
1222 if (m_nTopLine
!= nNewTopLine
)
1224 if (nNewTopLine
< 0)
1227 int nScrollLines
= m_nTopLine
- nNewTopLine
;
1229 m_nTopLine
= nNewTopLine
;
1231 GetClientRect(&rcScroll
);
1232 rcScroll
.top
+= GetLineHeight()+HEADERHEIGHT
;
1233 ScrollWindow(0, nScrollLines
* GetLineHeight(), &rcScroll
, &rcScroll
);
1235 if (bTrackScrollBar
)
1236 RecalcVertScrollBar(TRUE
);
1242 void CBaseView::DrawMargin(CDC
*pdc
, const CRect
&rect
, int nLineIndex
)
1244 pdc
->FillSolidRect(rect
, ::GetSysColor(COLOR_SCROLLBAR
));
1246 if ((nLineIndex
>= 0)&&(m_pViewData
)&&(m_pViewData
->GetCount()))
1248 int nViewLine
= GetViewLineForScreen(nLineIndex
);
1250 ASSERT(nViewLine
<(int)m_ScreenedViewLine
.size());
1251 TScreenedViewLine::EIcon eIcon
= m_ScreenedViewLine
[nViewLine
].eIcon
;
1252 if (eIcon
==TScreenedViewLine::ICN_UNKNOWN
)
1254 DiffStates state
= m_pViewData
->GetState(nViewLine
);
1257 case DIFFSTATE_ADDED
:
1258 case DIFFSTATE_THEIRSADDED
:
1259 case DIFFSTATE_YOURSADDED
:
1260 case DIFFSTATE_IDENTICALADDED
:
1261 case DIFFSTATE_CONFLICTADDED
:
1262 eIcon
= TScreenedViewLine::ICN_ADD
;
1264 case DIFFSTATE_REMOVED
:
1265 case DIFFSTATE_THEIRSREMOVED
:
1266 case DIFFSTATE_YOURSREMOVED
:
1267 case DIFFSTATE_IDENTICALREMOVED
:
1268 eIcon
= TScreenedViewLine::ICN_REMOVED
;
1270 case DIFFSTATE_CONFLICTED
:
1271 eIcon
= TScreenedViewLine::ICN_CONFLICT
;
1273 case DIFFSTATE_CONFLICTED_IGNORED
:
1274 eIcon
= TScreenedViewLine::ICN_CONFLICTIGNORED
;
1276 case DIFFSTATE_EDITED
:
1277 eIcon
= TScreenedViewLine::ICN_EDIT
;
1282 bool bIdentical
= false;
1283 int blockstart
= -1;
1285 if ((state
!= DIFFSTATE_EDITED
)&&(IsBlockWhitespaceOnly(nLineIndex
, bIdentical
, blockstart
, blockend
)))
1288 eIcon
= TScreenedViewLine::ICN_SAME
;
1290 eIcon
= TScreenedViewLine::ICN_WHITESPACEDIFF
;
1291 if (((blockstart
>= 0) && (blockend
>= 0)) && (blockstart
< blockend
))
1293 if (nViewLine
> blockstart
)
1294 Invalidate(); // redraw the upper icons since they're now changing
1295 while (blockstart
<= blockend
)
1296 m_ScreenedViewLine
[blockstart
++].eIcon
= eIcon
;
1299 if (m_pViewData
->GetMovedIndex(nViewLine
) >= 0)
1300 eIcon
= TScreenedViewLine::ICN_MOVED
;
1301 if (m_pViewData
->GetMarked(nViewLine
))
1302 eIcon
= TScreenedViewLine::ICN_MARKED
;
1303 m_ScreenedViewLine
[nViewLine
].eIcon
= eIcon
;
1307 case TScreenedViewLine::ICN_UNKNOWN
:
1308 case TScreenedViewLine::ICN_NONE
:
1310 case TScreenedViewLine::ICN_SAME
:
1311 icon
= m_hEqualIcon
;
1313 case TScreenedViewLine::ICN_EDIT
:
1314 icon
= m_hEditedIcon
;
1316 case TScreenedViewLine::ICN_WHITESPACEDIFF
:
1317 icon
= m_hWhitespaceBlockIcon
;
1319 case TScreenedViewLine::ICN_ADD
:
1320 icon
= m_hAddedIcon
;
1322 case TScreenedViewLine::ICN_CONFLICT
:
1323 icon
= m_hConflictedIcon
;
1325 case TScreenedViewLine::ICN_CONFLICTIGNORED
:
1326 icon
= m_hConflictedIgnoredIcon
;
1328 case TScreenedViewLine::ICN_REMOVED
:
1329 icon
= m_hRemovedIcon
;
1331 case TScreenedViewLine::ICN_MOVED
:
1332 icon
= m_hMovedIcon
;
1334 case TScreenedViewLine::ICN_MARKED
:
1335 icon
= m_hMarkedIcon
;
1342 ::DrawIconEx(pdc
->m_hDC
, rect
.left
+ 2, rect
.top
+ (rect
.Height()-16)/2, icon
, 16, 16, NULL
, NULL
, DI_NORMAL
);
1344 if ((m_bViewLinenumbers
)&&(m_nDigits
))
1346 int nSubLine
= GetSubLineOffset(nLineIndex
);
1347 bool bIsFirstSubline
= (nSubLine
== 0) || (nSubLine
== -1);
1348 CString sLinenumber
;
1349 if (bIsFirstSubline
)
1351 CString sLinenumberFormat
;
1352 int nLineNumber
= GetLineNumber(nLineIndex
);
1353 if (IsViewLineHidden(GetViewLineForScreen(nLineIndex
)))
1355 // TODO: do not show if there is no number hidden
1356 // TODO: show number if there is only one
1357 sLinenumberFormat
.Format(_T("%%%ds"), m_nDigits
);
1358 sLinenumber
.Format(sLinenumberFormat
, (m_nDigits
>1) ? _T("↕⁞") : _T("⁞")); // alternative …
1360 else if (nLineNumber
>= 0)
1362 sLinenumberFormat
.Format(_T("%%%dd"), m_nDigits
);
1363 sLinenumber
.Format(sLinenumberFormat
, nLineNumber
+1);
1365 else if (m_pMainFrame
->m_bWrapLines
)
1367 sLinenumberFormat
.Format(_T("%%%ds"), m_nDigits
);
1368 sLinenumber
.Format(sLinenumberFormat
, _T("·"));
1370 if (!sLinenumber
.IsEmpty())
1372 pdc
->SetBkColor(::GetSysColor(COLOR_SCROLLBAR
));
1373 pdc
->SetTextColor(::GetSysColor(COLOR_WINDOWTEXT
));
1375 pdc
->SelectObject(GetFont());
1376 pdc
->ExtTextOut(rect
.left
+ 18, rect
.top
, ETO_CLIPPED
, &rect
, sLinenumber
, NULL
);
1383 int CBaseView::GetMarginWidth()
1385 if ((m_bViewLinenumbers
)&&(m_pViewData
)&&(m_pViewData
->GetCount()))
1389 int nLength
= (int)m_pViewData
->GetCount();
1390 // find out how many digits are needed to show the highest line number
1392 sMax
.Format(_T("%d"), nLength
);
1393 m_nDigits
= sMax
.GetLength();
1395 int nWidth
= GetCharWidth();
1396 return (MARGINWIDTH
+ (m_nDigits
* nWidth
) + 2);
1401 void CBaseView::DrawHeader(CDC
*pdc
, const CRect
&rect
)
1403 CRect
textrect(rect
.left
, rect
.top
, rect
.Width(), GetLineHeight()+HEADERHEIGHT
);
1404 COLORREF crBk
, crFg
;
1405 if (IsBottomViewGood())
1407 CDiffColors::GetInstance().GetColors(DIFFSTATE_NORMAL
, crBk
, crFg
);
1408 crBk
= ::GetSysColor(COLOR_SCROLLBAR
);
1412 DiffStates state
= DIFFSTATE_REMOVED
;
1413 if (this == m_pwndRight
)
1415 state
= DIFFSTATE_ADDED
;
1417 CDiffColors::GetInstance().GetColors(state
, crBk
, crFg
);
1419 pdc
->SetBkColor(crBk
);
1420 pdc
->FillSolidRect(textrect
, crBk
);
1422 pdc
->SetTextColor(crFg
);
1424 pdc
->SelectObject(GetFont(FALSE
, TRUE
));
1429 sViewTitle
= _T("* ") + m_sWindowName
;
1433 sViewTitle
= m_sWindowName
;
1435 int nStringLength
= (GetCharWidth()*m_sWindowName
.GetLength());
1436 if (nStringLength
> rect
.Width())
1438 int offset
= std::min
<int>(m_nOffsetChar
, (nStringLength
-rect
.Width())/GetCharWidth()+1);
1439 sViewTitle
= m_sWindowName
.Mid(offset
);
1441 pdc
->ExtTextOut(std::max
<int>(rect
.left
+ (rect
.Width()-nStringLength
)/2, 1),
1442 rect
.top
+(HEADERHEIGHT
/2), ETO_CLIPPED
, textrect
, sViewTitle
, NULL
);
1443 if (this->GetFocus() == this)
1444 pdc
->DrawEdge(textrect
, EDGE_BUMP
, BF_RECT
);
1446 pdc
->DrawEdge(textrect
, EDGE_ETCHED
, BF_RECT
);
1449 void CBaseView::OnDraw(CDC
* pDC
)
1452 GetClientRect(rcClient
);
1454 int nLineCount
= GetLineCount();
1455 int nLineHeight
= GetLineHeight();
1458 VERIFY(cacheDC
.CreateCompatibleDC(pDC
));
1459 if (m_pCacheBitmap
== NULL
)
1461 m_pCacheBitmap
= new CBitmap
;
1462 VERIFY(m_pCacheBitmap
->CreateCompatibleBitmap(pDC
, rcClient
.Width(), nLineHeight
));
1464 CBitmap
*pOldBitmap
= cacheDC
.SelectObject(m_pCacheBitmap
);
1466 DrawHeader(pDC
, rcClient
);
1470 rcLine
.top
+= nLineHeight
+HEADERHEIGHT
;
1471 rcLine
.bottom
= rcLine
.top
+ nLineHeight
;
1472 CRect
rcCacheMargin(0, 0, GetMarginWidth(), nLineHeight
);
1473 CRect
rcCacheLine(GetMarginWidth(), 0, rcLine
.Width(), nLineHeight
);
1475 int nCurrentLine
= m_nTopLine
;
1476 bool bBeyondFileLineCached
= false;
1477 while (rcLine
.top
< rcClient
.bottom
)
1479 if (nCurrentLine
< nLineCount
)
1481 DrawMargin(&cacheDC
, rcCacheMargin
, nCurrentLine
);
1482 DrawSingleLine(&cacheDC
, rcCacheLine
, nCurrentLine
);
1483 bBeyondFileLineCached
= false;
1485 else if (!bBeyondFileLineCached
)
1487 DrawMargin(&cacheDC
, rcCacheMargin
, -1);
1488 DrawSingleLine(&cacheDC
, rcCacheLine
, -1);
1489 bBeyondFileLineCached
= true;
1492 VERIFY(pDC
->BitBlt(rcLine
.left
, rcLine
.top
, rcLine
.Width(), rcLine
.Height(), &cacheDC
, 0, 0, SRCCOPY
));
1495 rcLine
.OffsetRect(0, nLineHeight
);
1498 cacheDC
.SelectObject(pOldBitmap
);
1502 bool CBaseView::IsStateConflicted(DiffStates state
)
1506 case DIFFSTATE_CONFLICTED
:
1507 case DIFFSTATE_CONFLICTED_IGNORED
:
1508 case DIFFSTATE_CONFLICTEMPTY
:
1509 case DIFFSTATE_CONFLICTADDED
:
1515 bool CBaseView::IsStateEmpty(DiffStates state
)
1519 case DIFFSTATE_CONFLICTEMPTY
:
1520 case DIFFSTATE_UNKNOWN
:
1521 case DIFFSTATE_EMPTY
:
1527 bool CBaseView::IsStateRemoved(DiffStates state
)
1531 case DIFFSTATE_REMOVED
:
1532 case DIFFSTATE_THEIRSREMOVED
:
1533 case DIFFSTATE_YOURSREMOVED
:
1534 case DIFFSTATE_IDENTICALREMOVED
:
1540 DiffStates
CBaseView::ResolveState(DiffStates state
)
1542 if (IsStateConflicted(state
))
1544 if (state
== DIFFSTATE_CONFLICTEMPTY
)
1545 return DIFFSTATE_CONFLICTRESOLVEDEMPTY
;
1547 return DIFFSTATE_CONFLICTRESOLVED
;
1553 bool CBaseView::IsLineEmpty(int nLineIndex
)
1555 if (m_pViewData
== 0)
1557 int nViewLine
= GetViewLineForScreen(nLineIndex
);
1558 return IsViewLineEmpty(nViewLine
);
1561 bool CBaseView::IsViewLineEmpty(int nViewLine
)
1563 if (m_pViewData
== 0)
1565 const DiffStates state
= m_pViewData
->GetState(nViewLine
);
1566 return IsStateEmpty(state
);
1569 bool CBaseView::IsLineRemoved(int nLineIndex
)
1571 if (m_pViewData
== 0)
1573 int nViewLine
= GetViewLineForScreen(nLineIndex
);
1574 return IsViewLineRemoved(nViewLine
);
1577 bool CBaseView::IsViewLineRemoved(int nViewLine
)
1579 if (m_pViewData
== 0)
1581 const DiffStates state
= m_pViewData
->GetState(nViewLine
);
1582 return IsStateRemoved(state
);
1585 bool CBaseView::IsViewLineConflicted(int nLineIndex
)
1587 if (m_pViewData
== 0)
1589 const DiffStates state
= m_pViewData
->GetState(nLineIndex
);
1590 return IsStateConflicted(state
);
1593 COLORREF
CBaseView::InlineDiffColor(int nLineIndex
)
1595 return IsLineRemoved(nLineIndex
) ? m_InlineRemovedBk
: m_InlineAddedBk
;
1598 COLORREF
CBaseView::InlineViewLineDiffColor(int nViewLine
)
1600 return IsViewLineRemoved(nViewLine
) ? m_InlineRemovedBk
: m_InlineAddedBk
;
1603 void CBaseView::DrawLineEnding(CDC
*pDC
, const CRect
&rc
, int nLineIndex
, const CPoint
& origin
)
1605 if (origin
.x
< (rc
.left
- GetCharWidth() +1))
1607 if (!(m_bViewWhitespace
&& m_pViewData
&& (nLineIndex
>= 0) && (nLineIndex
< GetLineCount())))
1609 int viewLine
= GetViewLineForScreen(nLineIndex
);
1610 EOL ending
= m_pViewData
->GetLineEnding(viewLine
);
1613 HICON hEndingIcon
= NULL
;
1616 case EOL_CR
: hEndingIcon
= m_hLineEndingCR
; break;
1617 case EOL_CRLF
: hEndingIcon
= m_hLineEndingCRLF
; break;
1618 case EOL_LF
: hEndingIcon
= m_hLineEndingLF
; break;
1621 // If EOL style has changed, color end-of-line markers as inline differences.
1623 m_bShowInlineDiff
&& m_pOtherViewData
&&
1624 (viewLine
< m_pOtherViewData
->GetCount()) &&
1625 (ending
!= EOL_NOENDING
) &&
1626 (ending
!= m_pOtherViewData
->GetLineEnding(viewLine
) &&
1627 (m_pOtherViewData
->GetLineEnding(viewLine
) != EOL_NOENDING
))
1630 pDC
->FillSolidRect(origin
.x
, origin
.y
, rc
.Height(), rc
.Height(), InlineDiffColor(nLineIndex
));
1633 DrawIconEx(pDC
->GetSafeHdc(), origin
.x
, origin
.y
, hEndingIcon
, rc
.Height(), rc
.Height(), NULL
, NULL
, DI_NORMAL
);
1637 CPen
pen(PS_SOLID
, 0, m_WhiteSpaceFg
);
1638 CPen
* oldpen
= pDC
->SelectObject(&pen
);
1639 int yMiddle
= origin
.y
+ rc
.Height()/2;
1640 int xMiddle
= origin
.x
+GetCharWidth()/2;
1641 bool bMultiline
= false;
1642 if (((int)m_Screen2View
.size() > nLineIndex
+1) && (GetViewLineForScreen(nLineIndex
+1) == viewLine
))
1644 if (GetLineLength(nLineIndex
+1))
1648 pDC
->MoveTo(origin
.x
, yMiddle
-2);
1649 pDC
->LineTo(origin
.x
+GetCharWidth()-1, yMiddle
-2);
1650 pDC
->LineTo(origin
.x
+GetCharWidth()-1, yMiddle
+2);
1651 pDC
->LineTo(origin
.x
, yMiddle
+2);
1653 else if (GetLineLength(nLineIndex
) == 0)
1656 else if ((nLineIndex
> 0) && (GetViewLineForScreen(nLineIndex
-1) == viewLine
) && (GetLineLength(nLineIndex
) == 0))
1665 // arrow from top to middle+2, then left
1666 pDC
->MoveTo(origin
.x
+GetCharWidth()-1, rc
.top
+1);
1667 pDC
->LineTo(origin
.x
+GetCharWidth()-1, yMiddle
);
1669 // arrow from right to left
1670 pDC
->MoveTo(origin
.x
+GetCharWidth()-1, yMiddle
);
1671 pDC
->LineTo(origin
.x
, yMiddle
);
1672 pDC
->LineTo(origin
.x
+4, yMiddle
+4);
1673 pDC
->MoveTo(origin
.x
, yMiddle
);
1674 pDC
->LineTo(origin
.x
+4, yMiddle
-4);
1677 // from right-upper to left then down
1678 pDC
->MoveTo(origin
.x
+GetCharWidth()-1, yMiddle
-2);
1679 pDC
->LineTo(xMiddle
, yMiddle
-2);
1680 pDC
->LineTo(xMiddle
, rc
.bottom
-1);
1681 pDC
->LineTo(xMiddle
+4, rc
.bottom
-5);
1682 pDC
->MoveTo(xMiddle
, rc
.bottom
-1);
1683 pDC
->LineTo(xMiddle
-4, rc
.bottom
-5);
1686 // arrow from top to bottom
1687 pDC
->MoveTo(xMiddle
, rc
.top
);
1688 pDC
->LineTo(xMiddle
, rc
.bottom
-1);
1689 pDC
->LineTo(xMiddle
+4, rc
.bottom
-5);
1690 pDC
->MoveTo(xMiddle
, rc
.bottom
-1);
1691 pDC
->LineTo(xMiddle
-4, rc
.bottom
-5);
1693 case EOL_FF
: // Form Feed, U+000C
1694 case EOL_NEL
: // Next Line, U+0085
1695 case EOL_LS
: // Line Separator, U+2028
1696 case EOL_PS
: // Paragraph Separator, U+2029
1697 // draw a horizontal line at the bottom of this line
1698 pDC
->FillSolidRect(rc
.left
, rc
.bottom
-1, rc
.right
, rc
.bottom
, GetSysColor(COLOR_WINDOWTEXT
));
1699 pDC
->MoveTo(origin
.x
+GetCharWidth()-1, rc
.bottom
-GetCharWidth()-2);
1700 pDC
->LineTo(origin
.x
, rc
.bottom
-2);
1701 pDC
->LineTo(origin
.x
+5, rc
.bottom
-2);
1702 pDC
->MoveTo(origin
.x
, rc
.bottom
-2);
1703 pDC
->LineTo(origin
.x
+1, rc
.bottom
-6);
1705 default: // other EOLs
1706 // arrow from top right to bottom left
1707 pDC
->MoveTo(origin
.x
+GetCharWidth()-1, rc
.bottom
-GetCharWidth());
1708 pDC
->LineTo(origin
.x
, rc
.bottom
-1);
1709 pDC
->LineTo(origin
.x
+5, rc
.bottom
-2);
1710 pDC
->MoveTo(origin
.x
, rc
.bottom
-1);
1711 pDC
->LineTo(origin
.x
+1, rc
.bottom
-6);
1717 pDC
->SelectObject(oldpen
);
1721 void CBaseView::DrawBlockLine(CDC
*pDC
, const CRect
&rc
, int nLineIndex
)
1723 if (!m_bShowSelection
)
1728 if (!GetViewSelection(nSelBlockStart
, nSelBlockEnd
))
1731 const int THICKNESS
= 2;
1732 COLORREF rectcol
= GetSysColor(m_bFocused
? COLOR_WINDOWTEXT
: COLOR_GRAYTEXT
);
1734 int nViewLineIndex
= GetViewLineForScreen(nLineIndex
);
1735 int nSubLine
= GetSubLineOffset(nLineIndex
);
1736 bool bFirstLineOfViewLine
= (nSubLine
==0 || nSubLine
==-1);
1737 if ((nViewLineIndex
== nSelBlockStart
) && bFirstLineOfViewLine
)
1739 pDC
->FillSolidRect(rc
.left
, rc
.top
, rc
.Width(), THICKNESS
, rectcol
);
1742 bool bLastLineOfViewLine
= (nLineIndex
+1 == m_Screen2View
.size()) || (GetViewLineForScreen(nLineIndex
) != GetViewLineForScreen(nLineIndex
+1));
1743 if ((nViewLineIndex
== nSelBlockEnd
) && bLastLineOfViewLine
)
1745 pDC
->FillSolidRect(rc
.left
, rc
.bottom
- THICKNESS
, rc
.Width(), THICKNESS
, rectcol
);
1749 void CBaseView::DrawTextLine(
1750 CDC
* pDC
, const CRect
&rc
, int nLineIndex
, POINT
& coords
)
1752 ASSERT(nLineIndex
< GetLineCount());
1753 int nViewLine
= GetViewLineForScreen(nLineIndex
);
1754 ASSERT(m_pViewData
&& (nViewLine
< m_pViewData
->GetCount()));
1756 LineColors lineCols
= GetLineColors(nViewLine
);
1758 CString sViewLine
= GetViewLineChars(nViewLine
);
1760 if (m_bShowSelection
&& HasTextSelection())
1762 // has this line selection ?
1763 if ((m_ptSelectionViewPosStart
.y
<= nViewLine
) && (nViewLine
<= m_ptSelectionViewPosEnd
.y
))
1765 int nViewLineLength
= sViewLine
.GetLength();
1767 // first suppose the whole line is selected
1768 int selectedStart
= 0;
1769 int selectedEnd
= nViewLineLength
;
1771 // the view line is partially selected
1772 if (m_ptSelectionViewPosStart
.y
== nViewLine
)
1774 selectedStart
= m_ptSelectionViewPosStart
.x
;
1777 if (m_ptSelectionViewPosEnd
.y
== nViewLine
)
1779 selectedEnd
= m_ptSelectionViewPosEnd
.x
;
1781 // apply selection coloring
1782 // First enforce start and end point
1783 lineCols
.SplitBlock(selectedStart
);
1784 lineCols
.SplitBlock(selectedEnd
);
1785 // change color of affected parts
1786 long intenseColorScale
= m_bFocused
? 70 : 30;
1787 std::map
<int, linecolors_t
>::iterator it
= lineCols
.lower_bound(selectedStart
);
1788 for ( ; it
!= lineCols
.end() && it
->first
< selectedEnd
; ++it
)
1790 COLORREF crBk
= CAppUtils::IntenseColor(intenseColorScale
, it
->second
.background
);
1791 if (it
->second
.shot
== it
->second
.background
)
1793 it
->second
.shot
= crBk
;
1795 it
->second
.background
= crBk
;
1796 it
->second
.text
= CAppUtils::IntenseColor(intenseColorScale
, it
->second
.text
);
1801 // TODO: remove duplicate from selection and mark
1802 if (!m_sMarkedWord
.IsEmpty())
1804 int nMarkLength
= m_sMarkedWord
.GetLength();
1805 //int nViewLineLength = sViewLine.GetLength();
1806 const TCHAR
* text
= sViewLine
;
1807 const TCHAR
* findText
= text
;
1808 while ((findText
= _tcsstr(findText
, (LPCTSTR
)m_sMarkedWord
))!=0)
1810 int nMarkStart
= static_cast<int>(findText
- text
);
1811 int nMarkEnd
= nMarkStart
+ nMarkLength
;
1812 findText
+= nMarkLength
;
1813 ECharGroup eLeft
= GetCharGroup(sViewLine
, nMarkStart
- 1);
1814 ECharGroup eStart
= GetCharGroup(sViewLine
, nMarkStart
);
1815 if (eLeft
== eStart
)
1817 ECharGroup eRight
= GetCharGroup(sViewLine
, nMarkEnd
);
1818 ECharGroup eEnd
= GetCharGroup(sViewLine
, nMarkEnd
- 1);
1822 // First enforce start and end point
1823 lineCols
.SplitBlock(nMarkStart
);
1824 lineCols
.SplitBlock(nMarkEnd
);
1825 // change color of affected parts
1826 const long int nIntenseColorScale
= 200;
1827 std::map
<int, linecolors_t
>::iterator it
= lineCols
.lower_bound(nMarkStart
);
1828 for ( ; it
!= lineCols
.end() && it
->first
< nMarkEnd
; ++it
)
1830 COLORREF crBk
= CAppUtils::IntenseColor(nIntenseColorScale
, it
->second
.background
);
1831 if (it
->second
.shot
== it
->second
.background
)
1833 it
->second
.shot
= crBk
;
1835 it
->second
.background
= crBk
;
1836 it
->second
.text
= CAppUtils::IntenseColor(nIntenseColorScale
, it
->second
.text
);
1840 if (!m_sFindText
.IsEmpty())
1844 int nStringPos
= nMarkStart
;
1845 CString searchLine
= sViewLine
;
1847 searchLine
.MakeLower();
1848 while (StringFound(searchLine
, SearchNext
, nMarkStart
, nMarkEnd
)!=0)
1850 // First enforce start and end point
1851 lineCols
.SplitBlock(nMarkStart
+nStringPos
);
1852 lineCols
.SplitBlock(nMarkEnd
+nStringPos
);
1853 // change color of affected parts
1854 const long int nIntenseColorScale
= 30;
1855 std::map
<int, linecolors_t
>::iterator it
= lineCols
.lower_bound(nMarkStart
+nStringPos
);
1856 for ( ; it
!= lineCols
.end() && it
->first
< nMarkEnd
; ++it
)
1858 COLORREF crBk
= CAppUtils::IntenseColor(nIntenseColorScale
, it
->second
.background
);
1859 if (it
->second
.shot
== it
->second
.background
)
1861 it
->second
.shot
= crBk
;
1863 it
->second
.background
= crBk
;
1864 it
->second
.text
= CAppUtils::IntenseColor(nIntenseColorScale
, it
->second
.text
);
1866 searchLine
= searchLine
.Mid(nMarkEnd
);
1867 nStringPos
= nMarkEnd
;
1873 // @ this point we may cache data for next line which may be same in wrapped mode
1875 int nTextOffset
= 0;
1876 int nSubline
= GetSubLineOffset(nLineIndex
);
1877 for (int n
=0; n
<nSubline
; n
++)
1879 CString sLine
= m_ScreenedViewLine
[nViewLine
].SubLines
[n
];
1880 nTextOffset
+= sLine
.GetLength();
1883 CString sLine
= GetLineChars(nLineIndex
);
1884 int nLineLength
= sLine
.GetLength();
1885 CString sLineExp
= ExpandChars(sLine
);
1886 LPCTSTR textExp
= sLineExp
;
1887 //int nLineLengthExp = sLineExp.GetLength();
1889 int nLeft
= coords
.x
;
1890 for (std::map
<int, linecolors_t
>::const_iterator itStart
= lineCols
.begin(); itStart
!= lineCols
.end(); ++itStart
)
1892 std::map
<int, linecolors_t
>::const_iterator itEnd
= itStart
;
1894 int nStart
= std::max
<int>(0, itStart
->first
- nTextOffset
);
1895 int nEnd
= nLineLength
;
1896 if (itEnd
!= lineCols
.end())
1898 nEnd
= std::min
<int>(nEnd
, itEnd
->first
- nTextOffset
);
1900 int nBlockLength
= nEnd
- nStart
;
1901 if (nBlockLength
> 0 && nEnd
>=0)
1903 pDC
->SetBkColor(itStart
->second
.background
);
1904 pDC
->SetTextColor(itStart
->second
.text
);
1905 int nEndExp
= CountExpandedChars(sLine
, nEnd
);
1906 int nTextLength
= nEndExp
- nStartExp
;
1907 LPCTSTR p_zBlockText
= textExp
+ nStartExp
;
1909 GetTextExtentPoint32(pDC
->GetSafeHdc(), p_zBlockText
, nTextLength
, &Size
); // falls time-2-tme
1910 int nRight
= nLeft
+ Size
.cx
;
1911 if ((nRight
> rc
.left
) && (nLeft
< rc
.right
))
1913 // note: ExtTextOut has a limit for the length of the string. That limit is supposed
1914 // to be 8192, but that's not really true: I found that the limit (at least on my machine and a few others)
1915 // is 4094 (4095 doesn't work anymore).
1916 // So we limit the length here to that 4094 chars.
1917 // In case we're scrolled to the right, there's no need to draw the string
1918 // from way outside our window, so we also offset the drawing to the start of the window.
1919 // This reduces the string length as well.
1921 int leftcoord
= nLeft
;
1924 int fit
= nTextLength
;
1925 auto posBuffer
= std::make_unique
<int[]>(fit
);
1926 GetTextExtentExPoint(pDC
->GetSafeHdc(), p_zBlockText
, nTextLength
, INT_MAX
, &fit
, posBuffer
.get(), &Size
);
1927 int lower
= 0, upper
= fit
- 1;
1930 int middle
= (upper
+ lower
+ 1) / 2;
1931 int width
= posBuffer
.get()[middle
];
1932 if (rc
.left
- nLeft
< width
)
1936 } while (lower
< upper
);
1939 nTextLength
-= offset
;
1940 leftcoord
+= lower
> 0 ? posBuffer
.get()[lower
- 1] : 0;
1943 pDC
->ExtTextOut(leftcoord
, coords
.y
, ETO_CLIPPED
, &rc
, p_zBlockText
+offset
, min(nTextLength
, 4094), NULL
);
1944 if ((itStart
->second
.shot
!= itStart
->second
.background
) && (itStart
->first
== nStart
+ nTextOffset
))
1946 pDC
->FillSolidRect(nLeft
-1, rc
.top
, 1, rc
.Height(), itStart
->second
.shot
);
1951 nStartExp
= nEndExp
;
1956 void CBaseView::DrawSingleLine(CDC
*pDC
, const CRect
&rc
, int nLineIndex
)
1958 if (nLineIndex
>= GetLineCount())
1960 ASSERT(nLineIndex
>= -1);
1962 if ((nLineIndex
== -1) || !m_pViewData
)
1964 // Draw line beyond the text
1965 COLORREF crBkgnd
, crText
;
1966 CDiffColors::GetInstance().GetColors(DIFFSTATE_UNKNOWN
, crBkgnd
, crText
);
1967 pDC
->FillSolidRect(rc
, crBkgnd
);
1971 int viewLine
= GetViewLineForScreen(nLineIndex
);
1972 if (m_pMainFrame
->m_bCollapsed
)
1974 if (m_pViewData
->GetHideState(viewLine
) == HIDESTATE_MARKER
)
1976 COLORREF crBkgnd
, crText
;
1977 CDiffColors::GetInstance().GetColors(DIFFSTATE_UNKNOWN
, crBkgnd
, crText
);
1978 pDC
->FillSolidRect(rc
, crBkgnd
);
1980 const int THICKNESS
= 2;
1981 COLORREF rectcol
= GetSysColor(COLOR_WINDOWTEXT
);
1982 pDC
->FillSolidRect(rc
.left
, rc
.top
+ (rc
.Height()/2), rc
.Width(), THICKNESS
, rectcol
);
1983 pDC
->SetTextColor(GetSysColor(COLOR_GRAYTEXT
));
1984 pDC
->SetBkColor(crBkgnd
);
1986 pDC
->DrawText(_T("{...}"), &rect
, DT_NOPREFIX
|DT_SINGLELINE
|DT_CENTER
);
1991 DiffStates diffState
= m_pViewData
->GetState(viewLine
);
1992 COLORREF crBkgnd
, crText
;
1993 CDiffColors::GetInstance().GetColors(diffState
, crBkgnd
, crText
);
1995 if (diffState
== DIFFSTATE_CONFLICTED
)
1997 // conflicted lines are shown without 'text' on them
1999 pDC
->FillSolidRect(rc
, crBkgnd
);
2000 // now draw some faint text patterns
2001 pDC
->SetTextColor(CAppUtils::IntenseColor(130, crBkgnd
));
2002 pDC
->DrawText(m_sConflictedText
, rect
, DT_LEFT
|DT_NOPREFIX
|DT_SINGLELINE
);
2003 DrawBlockLine(pDC
, rc
, nLineIndex
);
2007 CPoint
origin(rc
.left
- m_nOffsetChar
* GetCharWidth(), rc
.top
);
2008 CString sLine
= GetLineChars(nLineIndex
);
2009 if (sLine
.IsEmpty())
2011 pDC
->FillSolidRect(rc
, crBkgnd
);
2012 DrawBlockLine(pDC
, rc
, nLineIndex
);
2013 DrawLineEnding(pDC
, rc
, nLineIndex
, origin
);
2021 pDC
->SelectObject(GetFont(FALSE
, FALSE
));
2023 DrawTextLine(pDC
, rc
, nLineIndex
, origin
);
2025 // draw white space after the end of line
2027 if (origin
.x
> frect
.left
)
2028 frect
.left
= origin
.x
;
2029 if (frect
.right
> frect
.left
)
2030 pDC
->FillSolidRect(frect
, crBkgnd
);
2032 // draw the whitespace chars
2033 LPCTSTR pszChars
= (LPCWSTR
)sLine
;
2034 if (m_bViewWhitespace
)
2038 LPCTSTR pLastSpace
= pszChars
;
2039 int y
= rc
.top
+ (rc
.bottom
-rc
.top
)/2;
2040 xpos
-= m_nOffsetChar
* GetCharWidth();
2042 CPen
pen(PS_SOLID
, 0, m_WhiteSpaceFg
);
2043 CPen
pen2(PS_SOLID
, 2, m_WhiteSpaceFg
);
2050 xpos
+= pDC
->GetTextExtent(pLastSpace
, (int)(pszChars
- pLastSpace
)).cx
;
2051 pLastSpace
= pszChars
+ 1;
2053 int nSpaces
= GetTabSize() - nChars
% GetTabSize();
2054 if (xpos
+ nSpaces
* GetCharWidth() > 0)
2056 int xposreal
= max(xpos
, 0);
2057 if ((xposreal
> 0) || (nSpaces
> 0))
2059 CPen
* oldPen
= pDC
->SelectObject(&pen
);
2060 pDC
->MoveTo(xposreal
+ rc
.left
, y
);
2061 pDC
->LineTo((xpos
+ nSpaces
* GetCharWidth()) + rc
.left
- 2, y
);
2062 pDC
->LineTo((xpos
+ nSpaces
* GetCharWidth()) + rc
.left
- 6, y
- 4);
2063 pDC
->MoveTo((xpos
+ nSpaces
* GetCharWidth()) + rc
.left
- 2, y
);
2064 pDC
->LineTo((xpos
+ nSpaces
* GetCharWidth()) + rc
.left
- 6, y
+ 4);
2065 pDC
->SelectObject(oldPen
);
2068 xpos
+= nSpaces
* GetCharWidth();
2074 xpos
+= pDC
->GetTextExtent(pLastSpace
, (int)(pszChars
- pLastSpace
)).cx
;
2075 pLastSpace
= pszChars
+ 1;
2079 CPen
* oldPen
= pDC
->SelectObject(&pen2
);
2080 pDC
->MoveTo(xpos
+ rc
.left
+ GetCharWidth()/2-1, y
);
2081 pDC
->LineTo(xpos
+ rc
.left
+ GetCharWidth()/2+1, y
);
2082 pDC
->SelectObject(oldPen
);
2084 xpos
+= GetCharWidth();
2095 DrawBlockLine(pDC
, rc
, nLineIndex
);
2096 if (origin
.x
>= rc
.left
)
2097 DrawLineEnding(pDC
, rc
, nLineIndex
, origin
);
2100 void CBaseView::ExpandChars(const CString
&sLine
, int nOffset
, int nCount
, CString
&line
)
2108 int nTabSize
= GetTabSize();
2110 int nActualOffset
= CountExpandedChars(sLine
, nOffset
);
2112 LPCTSTR pszChars
= (LPCWSTR
)sLine
;
2113 pszChars
+= nOffset
;
2114 int nLength
= nCount
;
2117 for (int i
=0; i
<nLength
; i
++)
2119 if (pszChars
[i
] == _T('\t'))
2123 LPTSTR pszBuf
= line
.GetBuffer(nLength
+ nTabCount
* (nTabSize
- 1) + 1);
2125 if (nTabCount
> 0 || m_bViewWhitespace
)
2127 for (int i
=0; i
<nLength
; i
++)
2129 if (pszChars
[i
] == _T('\t'))
2131 int nSpaces
= nTabSize
- (nActualOffset
+ nCurPos
) % nTabSize
;
2134 pszBuf
[nCurPos
++] = _T(' ');
2140 pszBuf
[nCurPos
] = pszChars
[i
];
2147 memcpy(pszBuf
, pszChars
, sizeof(TCHAR
) * nLength
);
2150 pszBuf
[nCurPos
] = 0;
2151 line
.ReleaseBuffer();
2154 CString
CBaseView::ExpandChars(const CString
&sLine
, int nOffset
)
2157 int nLength
= sLine
.GetLength();
2158 ExpandChars(sLine
, nOffset
, nLength
, sRet
);
2162 int CBaseView::CountExpandedChars(const CString
&sLine
, int nLength
)
2164 int nTabSize
= GetTabSize();
2166 int nActualOffset
= 0;
2167 for (int i
=0; i
<nLength
; i
++)
2169 if (sLine
[i
] == _T('\t'))
2170 nActualOffset
+= (nTabSize
- nActualOffset
% nTabSize
);
2174 return nActualOffset
;
2177 void CBaseView::ScrollAllToLine(int nNewTopLine
, BOOL bTrackScrollBar
)
2180 m_pwndLeft
->ScrollToLine(nNewTopLine
, bTrackScrollBar
);
2182 m_pwndRight
->ScrollToLine(nNewTopLine
, bTrackScrollBar
);
2184 m_pwndBottom
->ScrollToLine(nNewTopLine
, bTrackScrollBar
);
2186 m_pwndLocator
->Invalidate();
2189 void CBaseView::GoToLine(int nNewLine
, BOOL bAll
)
2191 //almost the same as ScrollAllToLine, but try to put the line in the
2192 //middle of the view, not on top
2193 int nNewTopLine
= nNewLine
- GetScreenLines()/2;
2194 if (nNewTopLine
< 0)
2196 if (nNewTopLine
>= (int)m_Screen2View
.size())
2197 nNewTopLine
= (int)m_Screen2View
.size()-1;
2199 ScrollAllToLine(nNewTopLine
);
2201 ScrollToLine(nNewTopLine
);
2204 BOOL
CBaseView::OnEraseBkgnd(CDC
* /*pDC*/)
2209 int CBaseView::OnCreate(LPCREATESTRUCT lpCreateStruct
)
2211 if (CView::OnCreate(lpCreateStruct
) == -1)
2214 SecureZeroMemory(&m_lfBaseFont
, sizeof(m_lfBaseFont
));
2215 //lstrcpy(m_lfBaseFont.lfFaceName, _T("Courier New"));
2216 //lstrcpy(m_lfBaseFont.lfFaceName, _T("FixedSys"));
2217 m_lfBaseFont
.lfHeight
= 0;
2218 m_lfBaseFont
.lfWeight
= FW_NORMAL
;
2219 m_lfBaseFont
.lfItalic
= FALSE
;
2220 m_lfBaseFont
.lfCharSet
= DEFAULT_CHARSET
;
2221 m_lfBaseFont
.lfOutPrecision
= OUT_DEFAULT_PRECIS
;
2222 m_lfBaseFont
.lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
2223 m_lfBaseFont
.lfQuality
= DEFAULT_QUALITY
;
2224 m_lfBaseFont
.lfPitchAndFamily
= DEFAULT_PITCH
;
2229 void CBaseView::OnDestroy()
2231 if ((m_pFindDialog
)&&(!m_pFindDialog
->IsTerminating()))
2233 m_pFindDialog
->SendMessage(WM_CLOSE
);
2241 void CBaseView::OnSize(UINT nType
, int cx
, int cy
)
2243 CView::OnSize(nType
, cx
, cy
);
2246 m_nScreenLines
= -1;
2247 m_nScreenChars
= -1;
2248 if (m_nLastScreenChars
!= GetScreenChars())
2250 BuildAllScreen2ViewVector();
2251 m_nLastScreenChars
= m_nScreenChars
;
2252 if (m_pMainFrame
&& m_pMainFrame
->m_bWrapLines
)
2254 // if we're in wrap mode, the line wrapping most likely changed
2255 // and that means we have to redraw the whole window, not just the
2261 // make sure the view header is redrawn
2263 GetClientRect(&rcScroll
);
2264 rcScroll
.bottom
= GetLineHeight()+HEADERHEIGHT
;
2265 InvalidateRect(&rcScroll
, FALSE
);
2270 // make sure the view header is redrawn
2272 GetClientRect(&rcScroll
);
2273 rcScroll
.bottom
= GetLineHeight()+HEADERHEIGHT
;
2274 InvalidateRect(&rcScroll
, FALSE
);
2277 RecalcVertScrollBar();
2278 RecalcHorzScrollBar();
2283 BOOL
CBaseView::OnMouseWheel(UINT nFlags
, short zDelta
, CPoint pt
)
2286 m_pwndLeft
->OnDoMouseWheel(nFlags
, zDelta
, pt
);
2288 m_pwndRight
->OnDoMouseWheel(nFlags
, zDelta
, pt
);
2290 m_pwndBottom
->OnDoMouseWheel(nFlags
, zDelta
, pt
);
2292 m_pwndLocator
->Invalidate();
2293 return CView::OnMouseWheel(nFlags
, zDelta
, pt
);
2296 void CBaseView::OnMouseHWheel(UINT nFlags
, short zDelta
, CPoint pt
)
2299 m_pwndLeft
->OnDoMouseHWheel(nFlags
, zDelta
, pt
);
2301 m_pwndRight
->OnDoMouseHWheel(nFlags
, zDelta
, pt
);
2303 m_pwndBottom
->OnDoMouseHWheel(nFlags
, zDelta
, pt
);
2305 m_pwndLocator
->Invalidate();
2308 void CBaseView::OnDoMouseWheel(UINT
/*nFlags*/, short zDelta
, CPoint
/*pt*/)
2310 bool bControl
= !!(GetKeyState(VK_CONTROL
)&0x8000);
2311 bool bShift
= !!(GetKeyState(VK_SHIFT
)&0x8000);
2313 if (bControl
|| bShift
)
2315 if (m_pMainFrame
->m_bWrapLines
)
2317 // Ctrl-Wheel scrolls sideways
2318 ScrollSide(-zDelta
/30);
2322 ScrollVertical(zDelta
);
2326 void CBaseView::OnDoMouseHWheel(UINT
/*nFlags*/, short zDelta
, CPoint
/*pt*/)
2328 bool bControl
= !!(GetKeyState(VK_CONTROL
)&0x8000);
2329 bool bShift
= !!(GetKeyState(VK_SHIFT
)&0x8000);
2331 if (bControl
|| bShift
)
2333 ScrollVertical(zDelta
);
2337 if (m_pMainFrame
->m_bWrapLines
)
2339 // Ctrl-Wheel scrolls sideways
2340 ScrollSide(-zDelta
/30);
2344 BOOL
CBaseView::OnSetCursor(CWnd
* pWnd
, UINT nHitTest
, UINT message
)
2346 if (nHitTest
== HTCLIENT
)
2348 if ((m_pViewData
)&&(m_pMainFrame
->m_bCollapsed
))
2350 if (m_nMouseLine
< (int)m_Screen2View
.size())
2352 if (m_nMouseLine
>= 0)
2354 int viewLine
= GetViewLineForScreen(m_nMouseLine
);
2355 if (viewLine
< m_pViewData
->GetCount())
2357 if (m_pViewData
->GetHideState(viewLine
) == HIDESTATE_MARKER
)
2359 ::SetCursor(::LoadCursor(NULL
, IDC_HAND
));
2366 if (m_mouseInMargin
)
2368 ::SetCursor(m_margincursor
);
2371 if (m_nMouseLine
>= 0)
2373 ::SetCursor(::LoadCursor(NULL
, IDC_IBEAM
)); // Set To Edit Cursor
2377 ::SetCursor(::LoadCursor(NULL
, IDC_ARROW
)); // Set To Arrow Cursor
2380 return CView::OnSetCursor(pWnd
, nHitTest
, message
);
2383 void CBaseView::OnKillFocus(CWnd
* pNewWnd
)
2385 CView::OnKillFocus(pNewWnd
);
2391 void CBaseView::OnSetFocus(CWnd
* pOldWnd
)
2393 CView::OnSetFocus(pOldWnd
);
2399 int CBaseView::GetLineFromPoint(CPoint point
)
2401 ScreenToClient(&point
);
2402 return (((point
.y
- HEADERHEIGHT
) / GetLineHeight()) + m_nTopLine
);
2405 void CBaseView::OnContextMenu(CPoint point
, DiffStates state
)
2407 if (!this->IsWindowVisible())
2411 if (!popup
.CreatePopupMenu())
2414 AddContextItems(popup
, state
);
2418 int nEncodingCommandBase
= POPUPCOMMAND__LAST
;
2419 int nEolCommandBase
= nEncodingCommandBase
+_countof(uctArray
);
2423 TWhitecharsProperties oWhites
= GetWhitecharsProperties();
2424 temp
.LoadString(IDS_EDIT_TAB2SPACE
);
2425 popup
.AppendMenu(MF_STRING
| (oWhites
.HasTabsToConvert
? MF_ENABLED
: (MF_DISABLED
|MF_GRAYED
)), POPUPCOMMAND_TABTOSPACES
, temp
);
2426 temp
.LoadString(IDS_EDIT_SPACE2TAB
);
2427 popup
.AppendMenu(MF_STRING
| (oWhites
.HasSpacesToConvert
? MF_ENABLED
: (MF_DISABLED
|MF_GRAYED
)), POPUPCOMMAND_SPACESTOTABS
, temp
);
2428 temp
.LoadString(IDS_EDIT_TRIM
);
2429 popup
.AppendMenu(MF_STRING
| (oWhites
.HasTrailWhiteChars
? MF_ENABLED
: (MF_DISABLED
|MF_GRAYED
)), POPUPCOMMAND_REMOVETRAILWHITES
, temp
);
2432 if (!popupEols
.CreatePopupMenu())
2435 EOL eEolType
= GetLineEndings(oWhites
.HasMixedEols
);
2436 for (int i
= 1; i
< _countof(eolArray
); i
++)
2438 temp
= GetEolName(eolArray
[i
]);
2439 bool bChecked
= (eEolType
== eolArray
[i
]);
2440 popupEols
.AppendMenu(MF_STRING
| MF_ENABLED
| (bChecked
? MF_CHECKED
: 0), nEolCommandBase
+i
, temp
);
2443 temp
.LoadString(IDS_VIEWCONTEXTMENU_EOL
);
2444 popup
.AppendMenuW(MF_POPUP
| MF_ENABLED
, (UINT_PTR
)popupEols
.GetSafeHmenu(), temp
);
2446 // add encoding submenu
2447 if (!popupUnicode
.CreatePopupMenu())
2449 for (int i
= 0; i
< _countof(uctArray
); i
++)
2451 temp
= CFileTextLines::GetEncodingName(uctArray
[i
]);
2452 bool bChecked
= (m_texttype
== uctArray
[i
]);
2453 popupUnicode
.AppendMenu(MF_STRING
| MF_ENABLED
| (bChecked
? MF_CHECKED
: 0), nEncodingCommandBase
+i
, temp
);
2455 temp
.LoadString(IDS_VIEWCONTEXTMENU_ENCODING
);
2456 popup
.AppendMenuW(MF_POPUP
| MF_ENABLED
, (UINT_PTR
)popupUnicode
.GetSafeHmenu(), temp
);
2460 CompensateForKeyboard(point
);
2462 int cmd
= popup
.TrackPopupMenu(TPM_RETURNCMD
| TPM_LEFTALIGN
| TPM_NONOTIFY
| TPM_RIGHTBUTTON
, point
.x
, point
.y
, this);
2464 if ((cmd
>=nEncodingCommandBase
) && (cmd
<nEncodingCommandBase
+(int)_countof(uctArray
)))
2466 SetTextType(uctArray
[cmd
-nEncodingCommandBase
]);
2468 if ((cmd
>=nEolCommandBase
) && (cmd
<nEolCommandBase
+(int)_countof(eolArray
)))
2470 ReplaceLineEndings(eolArray
[cmd
-nEolCommandBase
]);
2475 // 2-pane view commands; target is right view
2476 case POPUPCOMMAND_USELEFTBLOCK
:
2477 m_pwndRight
->UseLeftBlock();
2479 case POPUPCOMMAND_USELEFTFILE
:
2480 m_pwndRight
->UseLeftFile();
2482 case POPUPCOMMAND_USEBOTHLEFTFIRST
:
2483 m_pwndRight
->UseBothLeftFirst();
2485 case POPUPCOMMAND_USEBOTHRIGHTFIRST
:
2486 m_pwndRight
->UseBothRightFirst();
2488 case POPUPCOMMAND_MARKBLOCK
:
2489 m_pwndRight
->MarkBlock(true);
2491 case POPUPCOMMAND_UNMARKBLOCK
:
2492 m_pwndRight
->MarkBlock(false);
2494 case POPUPCOMMAND_LEAVEONLYMARKEDBLOCKS
:
2495 m_pwndRight
->LeaveOnlyMarkedBlocks();
2497 // 2-pane view multiedit commands; target is left view
2498 case POPUPCOMMAND_PREPENDFROMRIGHT
:
2499 if (!m_pwndLeft
->IsReadonly())
2500 m_pwndLeft
->UseBothRightFirst();
2502 case POPUPCOMMAND_REPLACEBYRIGHT
:
2503 if (!m_pwndLeft
->IsReadonly())
2504 m_pwndLeft
->UseRightBlock();
2506 case POPUPCOMMAND_APPENDFROMRIGHT
:
2507 if (!m_pwndLeft
->IsReadonly())
2508 m_pwndLeft
->UseBothLeftFirst();
2510 case POPUPCOMMAND_USERIGHTFILE
:
2511 m_pwndLeft
->UseRightFile();
2513 // 3-pane view commands; target is bottom view
2514 case POPUPCOMMAND_USEYOURANDTHEIRBLOCK
:
2515 m_pwndBottom
->UseBothRightFirst();
2517 case POPUPCOMMAND_USETHEIRANDYOURBLOCK
:
2518 m_pwndBottom
->UseBothLeftFirst();
2520 case POPUPCOMMAND_USEYOURBLOCK
:
2521 m_pwndBottom
->UseRightBlock();
2523 case POPUPCOMMAND_USEYOURFILE
:
2524 m_pwndBottom
->UseRightFile();
2526 case POPUPCOMMAND_USETHEIRBLOCK
:
2527 m_pwndBottom
->UseLeftBlock();
2529 case POPUPCOMMAND_USETHEIRFILE
:
2530 m_pwndBottom
->UseLeftFile();
2532 // copy, cut and paste commands
2542 // white chars manipulations
2543 case POPUPCOMMAND_TABTOSPACES
:
2544 ConvertTabToSpaces();
2546 case POPUPCOMMAND_SPACESTOTABS
:
2549 case POPUPCOMMAND_REMOVETRAILWHITES
:
2550 RemoveTrailWhiteChars();
2555 SaveUndoStep(); // all except copy, cut paste save undo step, but this should not be harmful as step is empty already and thus not saved
2559 void CBaseView::OnContextMenu(CWnd
* /*pWnd*/, CPoint point
)
2564 int nViewBlockStart
= -1;
2565 int nViewBlockEnd
= -1;
2566 GetViewSelection(nViewBlockStart
, nViewBlockEnd
);
2567 if ((point
.x
>= 0) && (point
.y
>= 0))
2569 int nLine
= GetLineFromPoint(point
)-1;
2570 if ((nLine
>= 0) && (nLine
< m_Screen2View
.size()))
2572 int nViewLine
= GetViewLineForScreen(nLine
);
2573 if (((nViewLine
< nViewBlockStart
) || (nViewBlockEnd
< nViewLine
)))
2575 ClearSelection(); // Clear text-copy selection
2577 nViewBlockStart
= nViewLine
;
2578 nViewBlockEnd
= nViewLine
;
2579 DiffStates state
= m_pViewData
->GetState(nViewLine
);
2580 while (nViewBlockStart
> 0)
2582 const DiffStates lineState
= m_pViewData
->GetState(nViewBlockStart
-1);
2583 if (!LinesInOneChange(-1, state
, lineState
))
2588 while (nViewBlockEnd
< (m_pViewData
->GetCount()-1))
2590 const DiffStates lineState
= m_pViewData
->GetState(nViewBlockEnd
+1);
2591 if (!LinesInOneChange(1, state
, lineState
))
2596 SetupAllViewSelection(nViewBlockStart
, nViewBlockEnd
);
2597 UpdateCaretPosition(point
);
2602 // FixSelection(); fix selection range
2603 /*if (m_nSelBlockEnd >= m_pViewData->GetCount())
2604 m_nSelBlockEnd = m_pViewData->GetCount()-1;//*/
2606 DiffStates state
= DIFFSTATE_UNKNOWN
;
2607 if (GetViewSelection(nViewBlockStart
, nViewBlockEnd
))
2609 // find a more 'relevant' state in the selection
2610 for (int i
=nViewBlockStart
; i
<=nViewBlockEnd
; ++i
)
2612 state
= m_pViewData
->GetState(i
);
2613 if ((state
!= DIFFSTATE_NORMAL
) && (state
!= DIFFSTATE_UNKNOWN
))
2617 OnContextMenu(point
, state
);
2620 void CBaseView::RefreshViews()
2624 m_pwndLeft
->UpdateStatusBar();
2625 m_pwndLeft
->Invalidate();
2629 m_pwndRight
->UpdateStatusBar();
2630 m_pwndRight
->Invalidate();
2634 m_pwndBottom
->UpdateStatusBar();
2635 m_pwndBottom
->Invalidate();
2638 m_pwndLocator
->Invalidate();
2641 void CBaseView::GoToFirstDifference()
2643 SetCaretToFirstViewLine();
2644 SelectNextBlock(1, false, false);
2647 void CBaseView::GoToFirstConflict()
2649 SetCaretToFirstViewLine();
2650 SelectNextBlock(1, true, false);
2653 void CBaseView::HighlightLines(int nStart
, int nEnd
/* = -1 */)
2656 SetupAllSelection(nStart
, max(nStart
, nEnd
));
2658 UpdateCaretPosition(SetupPoint(0, nStart
));
2662 void CBaseView::HighlightViewLines(int nStart
, int nEnd
/* = -1 */)
2665 SetupAllViewSelection(nStart
, max(nStart
, nEnd
));
2667 UpdateCaretViewPosition(SetupPoint(0, nStart
));
2671 void CBaseView::SetupAllViewSelection(int start
, int end
)
2673 SetupViewSelection(m_pwndBottom
, start
, end
);
2674 SetupViewSelection(m_pwndLeft
, start
, end
);
2675 SetupViewSelection(m_pwndRight
, start
, end
);
2678 void CBaseView::SetupAllSelection(int start
, int end
)
2680 SetupAllViewSelection(GetViewLineForScreen(start
), GetViewLineForScreen(end
));
2683 //void CBaseView::SetupSelection(CBaseView* view, int start, int end) { }
2685 void CBaseView::SetupSelection(int start
, int end
)
2687 SetupViewSelection(GetViewLineForScreen(start
), GetViewLineForScreen(end
));
2690 void CBaseView::SetupViewSelection(CBaseView
* view
, int start
, int end
)
2692 if (!IsViewGood(view
))
2694 view
->SetupViewSelection(start
, end
);
2697 void CBaseView::SetupViewSelection(int start
, int end
)
2699 // clear text selection before setting line selection ?
2700 m_nSelViewBlockStart
= start
;
2701 m_nSelViewBlockEnd
= end
;
2706 void CBaseView::OnMergePreviousconflict()
2708 SelectNextBlock(-1, true);
2711 void CBaseView::OnMergeNextconflict()
2713 SelectNextBlock(1, true);
2716 void CBaseView::OnMergeNextdifference()
2718 SelectNextBlock(1, false);
2721 void CBaseView::OnMergePreviousdifference()
2723 SelectNextBlock(-1, false);
2726 bool CBaseView::HasNextConflict()
2728 return SelectNextBlock(1, true, true, true);
2731 bool CBaseView::HasPrevConflict()
2733 return SelectNextBlock(-1, true, true, true);
2736 bool CBaseView::HasNextDiff()
2738 return SelectNextBlock(1, false, true, true);
2741 bool CBaseView::HasPrevDiff()
2743 return SelectNextBlock(-1, false, true, true);
2746 bool CBaseView::LinesInOneChange(int direction
,
2747 DiffStates initialLineState
, DiffStates currentLineState
)
2749 // Checks whether all the adjacent lines starting from the initial line
2750 // and up to the current line form the single change
2752 // First of all, if the two lines have identical states, they surely
2753 // belong to one change.
2754 if (initialLineState
== currentLineState
)
2757 // Either we move down and initial line state is "added" or "removed" and
2758 // current line state is "empty"...
2761 if (currentLineState
== DIFFSTATE_EMPTY
)
2763 if (initialLineState
== DIFFSTATE_ADDED
|| initialLineState
== DIFFSTATE_REMOVED
)
2766 if (initialLineState
== DIFFSTATE_CONFLICTADDED
&& currentLineState
== DIFFSTATE_CONFLICTEMPTY
)
2769 // ...or we move up and initial line state is "empty" and current line
2770 // state is "added" or "removed".
2773 if (initialLineState
== DIFFSTATE_EMPTY
)
2775 if (currentLineState
== DIFFSTATE_ADDED
|| currentLineState
== DIFFSTATE_REMOVED
)
2778 if (initialLineState
== DIFFSTATE_CONFLICTEMPTY
&& currentLineState
== DIFFSTATE_CONFLICTADDED
)
2784 bool CBaseView::SelectNextBlock(int nDirection
, bool bConflict
, bool bSkipEndOfCurrentBlock
/* = true */, bool dryrun
/* = false */)
2789 const int linesCount
= (int)m_Screen2View
.size();
2793 int nCenterPos
= GetCaretPosition().y
;
2796 nLimit
= linesCount
;
2798 if (nCenterPos
>= linesCount
)
2799 nCenterPos
= linesCount
-1;
2801 if (bSkipEndOfCurrentBlock
)
2803 // Find end of current block
2804 const DiffStates state
= m_pViewData
->GetState(GetViewLineForScreen(nCenterPos
));
2805 while (nCenterPos
!= nLimit
)
2807 const DiffStates lineState
= m_pViewData
->GetState(GetViewLineForScreen(nCenterPos
));
2808 if (!LinesInOneChange(nDirection
, state
, lineState
))
2810 nCenterPos
+= nDirection
;
2814 // Find next diff/conflict block
2815 while (nCenterPos
!= nLimit
)
2817 DiffStates linestate
= m_pViewData
->GetState(GetViewLineForScreen(nCenterPos
));
2819 (linestate
!= DIFFSTATE_NORMAL
) &&
2820 (linestate
!= DIFFSTATE_UNKNOWN
))
2825 ((linestate
== DIFFSTATE_CONFLICTADDED
) ||
2826 (linestate
== DIFFSTATE_CONFLICTED_IGNORED
) ||
2827 (linestate
== DIFFSTATE_CONFLICTED
) ||
2828 (linestate
== DIFFSTATE_CONFLICTEMPTY
)))
2833 nCenterPos
+= nDirection
;
2835 if (nCenterPos
== nLimit
)
2838 return (nCenterPos
!= nLimit
);
2840 // Find end of new block
2841 DiffStates state
= m_pViewData
->GetState(GetViewLineForScreen(nCenterPos
));
2842 int nBlockEnd
= nCenterPos
;
2843 const int maxAllowedLine
= nLimit
-nDirection
;
2844 while (nBlockEnd
!= maxAllowedLine
)
2846 const int lineIndex
= nBlockEnd
+ nDirection
;
2847 if (lineIndex
>= linesCount
)
2849 DiffStates lineState
= m_pViewData
->GetState(GetViewLineForScreen(lineIndex
));
2850 if (!LinesInOneChange(nDirection
, state
, lineState
))
2852 nBlockEnd
+= nDirection
;
2855 int nTopPos
= nCenterPos
- (GetScreenLines()/2);
2859 POINT ptCaretPos
= {0, nCenterPos
};
2860 SetCaretPosition(ptCaretPos
);
2863 SetupAllSelection(nCenterPos
, nBlockEnd
);
2865 SetupAllSelection(nBlockEnd
, nCenterPos
);
2867 ScrollAllToLine(nTopPos
, FALSE
);
2868 RecalcAllVertScrollBars(TRUE
);
2869 SetCaretToLineStart();
2870 EnsureCaretVisible();
2871 OnNavigateNextinlinediff();
2873 UpdateViewsCaretPosition();
2875 ShowDiffLines(nCenterPos
);
2879 BOOL
CBaseView::OnToolTipNotify(UINT
/*id*/, NMHDR
*pNMHDR
, LRESULT
*pResult
)
2881 if (pNMHDR
->idFrom
!= (UINT_PTR
)m_hWnd
)
2885 strTipText
= m_sWindowName
+ _T("\r\n") + m_sFullFilePath
;
2887 DWORD pos
= GetMessagePos();
2888 CPoint
point(GET_X_LPARAM(pos
), GET_Y_LPARAM(pos
));
2889 ScreenToClient(&point
);
2890 const int nLine
= GetButtonEventLineIndex(point
);
2894 int nViewLine
= GetViewLineForScreen(nLine
);
2895 if((m_pViewData
)&&(nViewLine
< m_pViewData
->GetCount()))
2897 auto movedIndex
= m_pViewData
->GetMovedIndex(nViewLine
);
2898 if (movedIndex
>= 0)
2900 if (m_pViewData
->IsMovedFrom(nViewLine
))
2902 strTipText
.Format(IDS_MOVED_TO_TT
, movedIndex
+1);
2906 strTipText
.Format(IDS_MOVED_FROM_TT
, movedIndex
+1);
2914 if (strTipText
.IsEmpty())
2917 // need to handle both ANSI and UNICODE versions of the message
2918 if (pNMHDR
->code
== TTN_NEEDTEXTA
)
2920 TOOLTIPTEXTA
* pTTTA
= (TOOLTIPTEXTA
*)pNMHDR
;
2921 pTTTA
->lpszText
= m_szTip
;
2922 WideCharToMultiByte(CP_ACP
, 0, strTipText
, -1, m_szTip
, strTipText
.GetLength()+1, 0, 0);
2926 TOOLTIPTEXTW
* pTTTW
= (TOOLTIPTEXTW
*)pNMHDR
;
2927 lstrcpyn(m_wszTip
, strTipText
, min(strTipText
.GetLength() + 1, _countof(m_wszTip
) - 1));
2928 pTTTW
->lpszText
= m_wszTip
;
2931 return TRUE
; // message was handled
2934 INT_PTR
CBaseView::OnToolHitTest(CPoint point
, TOOLINFO
* pTI
) const
2937 GetClientRect(rcClient
);
2938 CRect
textrect(rcClient
.left
, rcClient
.top
, rcClient
.Width(), m_nLineHeight
+HEADERHEIGHT
);
2939 int marginwidth
= MARGINWIDTH
;
2940 if ((m_bViewLinenumbers
)&&(m_pViewData
)&&(m_pViewData
->GetCount())&&(m_nDigits
> 0))
2942 marginwidth
= (MARGINWIDTH
+ (m_nDigits
* m_nCharWidth
) + 2);
2944 CRect
borderrect(rcClient
.left
, rcClient
.top
+m_nLineHeight
+HEADERHEIGHT
, marginwidth
, rcClient
.bottom
);
2946 if (textrect
.PtInRect(point
) || borderrect
.PtInRect(point
))
2948 // inside the header part of the view (showing the filename)
2949 pTI
->hwnd
= this->m_hWnd
;
2950 this->GetClientRect(&pTI
->rect
);
2951 pTI
->uFlags
|= TTF_ALWAYSTIP
| TTF_IDISHWND
;
2952 pTI
->uId
= (UINT_PTR
)m_hWnd
;
2953 pTI
->lpszText
= LPSTR_TEXTCALLBACK
;
2955 // we want multi line tooltips
2956 CToolTipCtrl
* pToolTip
= AfxGetModuleThreadState()->m_pToolTip
;
2957 if (pToolTip
->GetSafeHwnd() != NULL
)
2959 pToolTip
->SetMaxTipWidth(INT_MAX
);
2962 return (textrect
.PtInRect(point
) ? 1 : 2);
2968 void CBaseView::OnKeyDown(UINT nChar
, UINT nRepCnt
, UINT nFlags
)
2970 bool bControl
= !!(GetKeyState(VK_CONTROL
)&0x8000);
2971 bool bShift
= !!(GetKeyState(VK_SHIFT
)&0x8000);
2978 if (this==m_pwndLeft
)
2980 if (IsViewGood(m_pwndRight
))
2982 m_pwndRight
->SetFocus();
2984 else if (IsViewGood(m_pwndBottom
))
2986 m_pwndBottom
->SetFocus();
2989 else if (this==m_pwndRight
)
2991 if (IsViewGood(m_pwndBottom
))
2993 m_pwndBottom
->SetFocus();
2995 else if (IsViewGood(m_pwndLeft
))
2997 m_pwndLeft
->SetFocus();
3000 else if (this==m_pwndBottom
)
3002 if (IsViewGood(m_pwndLeft
))
3004 m_pwndLeft
->SetFocus();
3006 else if (IsViewGood(m_pwndRight
))
3008 m_pwndRight
->SetFocus();
3015 POINT ptCaretPos
= GetCaretPosition();
3016 ptCaretPos
.y
-= GetScreenLines();
3017 ptCaretPos
.y
= max(ptCaretPos
.y
, 0);
3018 ptCaretPos
.x
= CalculateCharIndex(ptCaretPos
.y
, m_nCaretGoalPos
);
3019 SetCaretPosition(ptCaretPos
);
3020 OnCaretMove(MOVELEFT
, bShift
);
3021 ShowDiffLines(ptCaretPos
.y
);
3026 POINT ptCaretPos
= GetCaretPosition();
3027 ptCaretPos
.y
+= GetScreenLines();
3028 if (ptCaretPos
.y
>= GetLineCount())
3029 ptCaretPos
.y
= GetLineCount()-1;
3030 ptCaretPos
.x
= CalculateCharIndex(ptCaretPos
.y
, m_nCaretGoalPos
);
3031 SetCaretPosition(ptCaretPos
);
3032 OnCaretMove(MOVERIGHT
, bShift
);
3033 ShowDiffLines(ptCaretPos
.y
);
3041 SetCaretToViewStart();
3042 m_nCaretGoalPos
= 0;
3044 AdjustSelection(MOVELEFT
);
3051 POINT ptCaretPos
= GetCaretPosition();
3052 CString sLine
= GetLineChars(ptCaretPos
.y
);
3054 while (pos
< sLine
.GetLength())
3056 if (sLine
[pos
] != ' ' && sLine
[pos
] != '\t')
3060 if (ptCaretPos
.x
== pos
)
3062 SetCaretToLineStart();
3063 m_nCaretGoalPos
= 0;
3064 OnCaretMove(MOVERIGHT
, bShift
);
3070 SetCaretAndGoalPosition(ptCaretPos
);
3071 OnCaretMove(MOVELEFT
, bShift
);
3080 ScrollAllToLine(GetLineCount()-GetAllMinScreenLines());
3082 ptCaretPos
.y
= GetLineCount()-1;
3083 ptCaretPos
.x
= GetLineLength(ptCaretPos
.y
);
3084 SetCaretAndGoalPosition(ptCaretPos
);
3086 AdjustSelection(MOVERIGHT
);
3092 POINT ptCaretPos
= GetCaretPosition();
3093 ptCaretPos
.x
= GetLineLength(ptCaretPos
.y
);
3094 if ((GetSubLineOffset(ptCaretPos
.y
) != -1) && (GetSubLineOffset(ptCaretPos
.y
) != CountMultiLines(GetViewLineForScreen(ptCaretPos
.y
))-1)) // not last screen line of view line
3098 SetCaretAndGoalPosition(ptCaretPos
);
3099 OnCaretMove(MOVERIGHT
, bShift
);
3106 if (! HasTextSelection())
3108 POINT ptCaretPos
= GetCaretPosition();
3109 if (ptCaretPos
.y
== 0 && ptCaretPos
.x
== 0)
3111 m_ptSelectionViewPosEnd
= GetCaretViewPosition();
3113 MoveCaretWordLeft();
3116 while (MoveCaretLeft() && IsViewLineEmpty(GetCaretViewPosition().y
))
3120 m_ptSelectionViewPosStart
= GetCaretViewPosition();
3122 RemoveSelectedText();
3128 if (! HasTextSelection())
3132 m_ptSelectionViewPosStart
= GetCaretViewPosition();
3133 MoveCaretWordRight();
3134 m_ptSelectionViewPosEnd
= GetCaretViewPosition();
3138 if (! MoveCaretRight())
3140 m_ptSelectionViewPosEnd
= GetCaretViewPosition();
3142 m_ptSelectionViewPosStart
= GetCaretViewPosition();
3145 RemoveSelectedText();
3149 m_bInsertMode
= !m_bInsertMode
;
3153 CView::OnKeyDown(nChar
, nRepCnt
, nFlags
);
3156 void CBaseView::OnLButtonDown(UINT nFlags
, CPoint point
)
3158 const int nClickedLine
= GetButtonEventLineIndex(point
);
3159 if ((nClickedLine
>= m_nTopLine
)&&(nClickedLine
< GetLineCount()))
3162 ptCaretPos
.y
= nClickedLine
;
3163 int xpos2
= CalcColFromPoint(point
.x
, nClickedLine
);
3164 ptCaretPos
.x
= CalculateCharIndex(ptCaretPos
.y
, xpos2
);
3165 SetCaretAndGoalPosition(ptCaretPos
);
3167 if (nFlags
& MK_SHIFT
)
3168 AdjustSelection(MOVERIGHT
);
3172 SetupAllSelection(ptCaretPos
.y
, ptCaretPos
.y
);
3173 if (point
.x
< GetMarginWidth())
3175 // select the whole line
3176 m_ptSelectionViewPosStart
= m_ptSelectionViewPosEnd
= GetCaretViewPosition();
3177 m_ptSelectionViewPosEnd
.x
= GetViewLineLength(m_ptSelectionViewPosEnd
.y
);
3181 UpdateViewsCaretPosition();
3185 CView::OnLButtonDown(nFlags
, point
);
3188 CBaseView::ECharGroup
CBaseView::GetCharGroup(wchar_t zChar
) const
3190 if (zChar
== ' ' || zChar
== '\t' )
3192 return CHG_WHITESPACE
;
3198 if (m_sWordSeparators
.Find(zChar
) >= 0)
3200 return CHG_WORDSEPARATOR
;
3202 return CHG_WORDLETTER
;
3205 void CBaseView::OnLButtonDblClk(UINT nFlags
, CPoint point
)
3207 if (m_pViewData
== 0) {
3208 CView::OnLButtonDblClk(nFlags
, point
);
3212 const int nClickedLine
= GetButtonEventLineIndex(point
);
3213 if ( nClickedLine
< 0)
3215 int nViewLine
= GetViewLineForScreen(nClickedLine
);
3216 if (point
.x
< GetMarginWidth()) // only if double clicked on the margin
3218 if((nViewLine
< m_pViewData
->GetCount())) // a double click on moved line scrolls to corresponding line
3220 if (m_pViewData
->GetMovedIndex(nViewLine
)>=0)
3222 int movedindex
= m_pViewData
->GetMovedIndex(nViewLine
);
3223 int screenLine
= FindViewLineNumber(movedindex
);
3224 int nTop
= screenLine
- GetScreenLines()/2;
3227 ScrollAllToLine(nTop
);
3228 // find and select the whole moved block
3229 int startSel
= movedindex
;
3230 int endSel
= movedindex
;
3231 while ((startSel
> 0) && (m_pOtherViewData
->GetMovedIndex(startSel
) >= 0))
3234 while ((endSel
< GetLineCount()) && (m_pOtherViewData
->GetMovedIndex(endSel
) >= 0))
3237 m_pOtherView
->SetupSelection(startSel
, endSel
);
3238 return CView::OnLButtonDblClk(nFlags
, point
);
3242 if ((m_pMainFrame
->m_bCollapsed
)&&(m_pViewData
->GetHideState(nViewLine
) == HIDESTATE_MARKER
))
3244 // a double click on a marker expands the hidden text
3246 while ((i
< m_pViewData
->GetCount())&&(m_pViewData
->GetHideState(i
) != HIDESTATE_SHOWN
))
3248 if ((m_pwndLeft
)&&(m_pwndLeft
->m_pViewData
))
3249 m_pwndLeft
->m_pViewData
->SetLineHideState(i
, HIDESTATE_SHOWN
);
3250 if ((m_pwndRight
)&&(m_pwndRight
->m_pViewData
))
3251 m_pwndRight
->m_pViewData
->SetLineHideState(i
, HIDESTATE_SHOWN
);
3252 if ((m_pwndBottom
)&&(m_pwndBottom
->m_pViewData
))
3253 m_pwndBottom
->m_pViewData
->SetLineHideState(i
, HIDESTATE_SHOWN
);
3256 BuildAllScreen2ViewVector();
3258 m_pwndLeft
->Invalidate();
3260 m_pwndRight
->Invalidate();
3262 m_pwndBottom
->Invalidate();
3267 ptCaretPos
.y
= nClickedLine
;
3268 ptCaretPos
.x
= CalculateCharIndex(ptCaretPos
.y
, m_nOffsetChar
+ (point
.x
- GetMarginWidth()) / GetCharWidth());
3269 SetCaretPosition(ptCaretPos
);
3272 POINT ptViewCarret
= GetCaretViewPosition();
3273 nViewLine
= ptViewCarret
.y
;
3274 if (nViewLine
>= GetViewCount())
3276 const CString
&sLine
= GetViewLine(nViewLine
);
3277 int nLineLength
= sLine
.GetLength();
3278 int nBasePos
= ptViewCarret
.x
;
3279 // get target char group
3280 ECharGroup eLeft
= CHG_UNKNOWN
;
3283 eLeft
= GetCharGroup(sLine
[nBasePos
-1]);
3285 ECharGroup eRight
= CHG_UNKNOWN
;
3286 if (nBasePos
< nLineLength
)
3288 eRight
= GetCharGroup(sLine
[nBasePos
]);
3290 ECharGroup eTarget
= max(eRight
, eLeft
);
3292 int nLeft
= nBasePos
;
3293 while (nLeft
> 0 && GetCharGroup(sLine
[nLeft
-1]) == eTarget
)
3298 int nRight
= nBasePos
;
3299 while (nRight
< nLineLength
&& GetCharGroup(sLine
[nRight
]) == eTarget
)
3304 m_ptSelectionViewPosStart
.x
= nLeft
;
3305 m_ptSelectionViewPosStart
.y
= nViewLine
;
3306 m_ptSelectionViewPosEnd
.x
= nRight
;
3307 m_ptSelectionViewPosEnd
.y
= nViewLine
;
3308 m_ptSelectionViewPosOrigin
= m_ptSelectionViewPosStart
;
3309 SetupAllViewSelection(nViewLine
, nViewLine
);
3311 ptCaretPos
= ConvertViewPosToScreen(m_ptSelectionViewPosEnd
);
3312 UpdateViewsCaretPosition();
3316 m_sPreviousMarkedWord
= m_sMarkedWord
; // store marked word to recall in case of triple click
3317 int nMarkWidth
= max(nRight
- nLeft
, 0);
3318 m_sMarkedWord
= sLine
.Mid(m_ptSelectionViewPosStart
.x
, nMarkWidth
).Trim();
3319 if (m_sMarkedWord
.Compare(m_sPreviousMarkedWord
) == 0)
3321 m_sMarkedWord
.Empty();
3325 m_pwndLeft
->SetMarkedWord(m_sMarkedWord
);
3327 m_pwndRight
->SetMarkedWord(m_sMarkedWord
);
3329 m_pwndBottom
->SetMarkedWord(m_sMarkedWord
);
3333 m_pwndLocator
->Invalidate();
3336 CView::OnLButtonDblClk(nFlags
, point
);
3339 void CBaseView::OnLButtonTrippleClick( UINT
/*nFlags*/, CPoint point
)
3341 const int nClickedLine
= GetButtonEventLineIndex(point
);
3342 if (((point
.y
- HEADERHEIGHT
) / GetLineHeight()) <= 0)
3344 if (!m_sConvertedFilePath
.IsEmpty() && (GetKeyState(VK_CONTROL
)&0x8000))
3346 PCIDLIST_ABSOLUTE __unaligned pidl
= ILCreateFromPath((LPCTSTR
)m_sConvertedFilePath
);
3349 SHOpenFolderAndSelectItems(pidl
,0,0,0);
3350 CoTaskMemFree((LPVOID
)pidl
);
3356 ptCaretPos
.y
= nClickedLine
;
3357 ptCaretPos
.x
= CalculateCharIndex(ptCaretPos
.y
, m_nOffsetChar
+ (point
.x
- GetMarginWidth()) / GetCharWidth());
3358 SetCaretAndGoalPosition(ptCaretPos
);
3359 m_sMarkedWord
= m_sPreviousMarkedWord
; // recall previous Marked word
3361 m_pwndLeft
->SetMarkedWord(m_sMarkedWord
);
3363 m_pwndRight
->SetMarkedWord(m_sMarkedWord
);
3365 m_pwndBottom
->SetMarkedWord(m_sMarkedWord
);
3367 m_ptSelectionViewPosStart
.x
= 0;
3368 m_ptSelectionViewPosStart
.y
= nClickedLine
;
3369 m_ptSelectionViewPosEnd
.x
= GetLineLength(nClickedLine
);
3370 m_ptSelectionViewPosEnd
.y
= nClickedLine
;
3371 SetupSelection(m_ptSelectionViewPosStart
.y
, m_ptSelectionViewPosEnd
.y
);
3372 UpdateViewsCaretPosition();
3375 m_pwndLocator
->Invalidate();
3378 void CBaseView::OnEditCopy()
3380 CString sCopyData
= GetSelectedText();
3382 if (!sCopyData
.IsEmpty())
3384 CStringUtils::WriteAsciiStringToClipboard(sCopyData
, m_hWnd
);
3388 void CBaseView::OnMouseMove(UINT nFlags
, CPoint point
)
3390 if (m_pMainFrame
->m_nMoveMovesToIgnore
> 0)
3392 --m_pMainFrame
->m_nMoveMovesToIgnore
;
3393 CView::OnMouseMove(nFlags
, point
);
3396 int nMouseLine
= GetButtonEventLineIndex(point
);
3397 if (nMouseLine
< -1)
3399 m_mouseInMargin
= point
.x
< GetMarginWidth();
3401 ShowDiffLines(nMouseLine
);
3403 KillTimer(IDT_SCROLLTIMER
);
3404 if (nFlags
& MK_LBUTTON
)
3406 int saveMouseLine
= nMouseLine
>= 0 ? nMouseLine
: 0;
3407 saveMouseLine
= saveMouseLine
< GetLineCount() ? saveMouseLine
: GetLineCount() - 1;
3408 if (saveMouseLine
< 0)
3410 int col
= CalcColFromPoint(point
.x
, saveMouseLine
);
3411 int charIndex
= CalculateCharIndex(saveMouseLine
, col
);
3412 if (HasSelection() &&
3413 ((nMouseLine
>= m_nTopLine
)&&(nMouseLine
< GetLineCount())))
3415 POINT ptCaretPos
= {charIndex
, nMouseLine
};
3416 SetCaretAndGoalPosition(ptCaretPos
);
3417 AdjustSelection(MOVERIGHT
);
3421 if (nMouseLine
< m_nTopLine
)
3423 ScrollAllToLine(m_nTopLine
-1, TRUE
);
3424 SetTimer(IDT_SCROLLTIMER
, 20, NULL
);
3426 if (nMouseLine
>= m_nTopLine
+ GetScreenLines() - 2)
3428 ScrollAllToLine(m_nTopLine
+1, TRUE
);
3429 SetTimer(IDT_SCROLLTIMER
, 20, NULL
);
3431 if (!m_pMainFrame
->m_bWrapLines
&& ((m_nOffsetChar
+ (point
.x
- GetMarginWidth()) / GetCharWidth()) <= m_nOffsetChar
))
3434 SetTimer(IDT_SCROLLTIMER
, 20, NULL
);
3436 if (!m_pMainFrame
->m_bWrapLines
&& (charIndex
>= (GetScreenChars()+m_nOffsetChar
-4)))
3439 SetTimer(IDT_SCROLLTIMER
, 20, NULL
);
3445 CView::OnMouseMove(nFlags
, point
);
3448 void CBaseView::OnLButtonUp(UINT nFlags
, CPoint point
)
3452 KillTimer(IDT_SCROLLTIMER
);
3454 __super::OnLButtonUp(nFlags
, point
);
3457 void CBaseView::OnTimer(UINT_PTR nIDEvent
)
3459 if (nIDEvent
== IDT_SCROLLTIMER
)
3462 GetCursorPos(&point
);
3463 ScreenToClient(&point
);
3464 int nMouseLine
= GetButtonEventLineIndex(point
);
3465 if (nMouseLine
< -1)
3469 if (GetKeyState(VK_LBUTTON
)&0x8000)
3471 int saveMouseLine
= nMouseLine
>= 0 ? nMouseLine
: 0;
3472 saveMouseLine
= saveMouseLine
< GetLineCount() ? saveMouseLine
: GetLineCount() - 1;
3473 int charIndex
= CalculateCharIndex(saveMouseLine
, m_nOffsetChar
+ (point
.x
- GetMarginWidth()) / GetCharWidth());
3474 if (nMouseLine
< m_nTopLine
)
3476 ScrollAllToLine(m_nTopLine
-1, TRUE
);
3477 SetTimer(IDT_SCROLLTIMER
, 20, NULL
);
3479 if (nMouseLine
>= m_nTopLine
+ GetScreenLines() - 2)
3481 ScrollAllToLine(m_nTopLine
+1, TRUE
);
3482 SetTimer(IDT_SCROLLTIMER
, 20, NULL
);
3484 if (!m_pMainFrame
->m_bWrapLines
&& ((m_nOffsetChar
+ (point
.x
- GetMarginWidth()) / GetCharWidth()) <= m_nOffsetChar
))
3487 SetTimer(IDT_SCROLLTIMER
, 20, NULL
);
3489 if (!m_pMainFrame
->m_bWrapLines
&& (charIndex
>= (GetScreenChars()+m_nOffsetChar
-4)))
3492 SetTimer(IDT_SCROLLTIMER
, 20, NULL
);
3498 CView::OnTimer(nIDEvent
);
3501 void CBaseView::ShowDiffLines(int nLine
)
3503 if ((nLine
< m_nTopLine
)||(nLine
>= GetLineCount()))
3505 m_pwndLineDiffBar
->ShowLines(nLine
);
3507 m_nMouseLine
= nLine
;
3511 if ((!m_pwndRight
)||(!m_pwndLeft
))
3513 if(m_pMainFrame
->m_bOneWay
)
3516 nLine
= (nLine
> (int)m_pwndRight
->m_Screen2View
.size() ? -1 : nLine
);
3517 nLine
= (nLine
> (int)m_pwndLeft
->m_Screen2View
.size() ? -1 : nLine
);
3522 if (nLine
!= m_nMouseLine
)
3524 if (nLine
>= GetLineCount())
3526 m_nMouseLine
= nLine
;
3527 m_pwndLineDiffBar
->ShowLines(nLine
);
3529 m_pMainFrame
->m_nMoveMovesToIgnore
= MOVESTOIGNORE
;
3532 const viewdata
& CBaseView::GetEmptyLineData()
3534 static const viewdata
emptyLine(_T(""), DIFFSTATE_EMPTY
, -1, EOL_NOENDING
, HIDESTATE_SHOWN
);
3538 void CBaseView::InsertViewEmptyLines(int nFirstView
, int nCount
)
3540 for (int i
= 0; i
< nCount
; i
++)
3542 InsertViewData(nFirstView
, GetEmptyLineData());
3547 void CBaseView::UpdateCaret()
3549 POINT ptCaretPos
= GetCaretPosition();
3550 ptCaretPos
.y
= std::max
<int>(std::min
<int>(ptCaretPos
.y
, GetLineCount()-1), 0);
3551 ptCaretPos
.x
= std::max
<int>(std::min
<int>(ptCaretPos
.x
, GetLineLength(ptCaretPos
.y
)), 0);
3552 SetCaretPosition(ptCaretPos
);
3554 int nCaretOffset
= CalculateActualOffset(ptCaretPos
);
3557 ptCaretPos
.y
>= m_nTopLine
&&
3558 ptCaretPos
.y
< (m_nTopLine
+GetScreenLines()) &&
3559 nCaretOffset
>= m_nOffsetChar
&&
3560 nCaretOffset
< (m_nOffsetChar
+GetScreenChars()))
3562 POINT pt1
= TextToClient(ptCaretPos
);
3564 CreateSolidCaret(2, GetLineHeight());
3567 POINT pt
= { ptCaretPos
.x
+ 1, ptCaretPos
.y
};
3568 POINT pt2
= TextToClient(pt
);
3569 int width
= max(GetCharWidth(), pt2
.x
- pt1
.x
);
3570 CreateSolidCaret(width
, GetLineHeight());
3581 POINT
CBaseView::ConvertScreenPosToView(const POINT
& pt
)
3586 int nSubLine
= GetSubLineOffset(pt
.y
);
3589 for (int nScreenLine
= pt
.y
-1; nScreenLine
>= pt
.y
-nSubLine
; nScreenLine
--)
3591 ptViewPos
.x
+= GetLineChars(nScreenLine
).GetLength();
3595 ptViewPos
.y
= GetViewLineForScreen(pt
.y
);
3599 POINT
CBaseView::ConvertViewPosToScreen(const POINT
& pt
)
3602 int nViewLineLenLeft
= GetViewLineLength(pt
.y
);
3603 ptPos
.x
= min(nViewLineLenLeft
, pt
.x
);
3604 ptPos
.y
= FindScreenLineForViewLine(pt
.y
);
3605 if (GetViewLineForScreen(ptPos
.y
) != pt
.y
)
3609 else if (GetSubLineOffset(ptPos
.y
) >= 0) // sublined
3611 int nSubLineLength
= GetLineChars(ptPos
.y
).GetLength();
3612 while (nSubLineLength
< ptPos
.x
)
3614 ptPos
.x
-= nSubLineLength
;
3615 nViewLineLenLeft
-= nSubLineLength
;
3617 nSubLineLength
= GetLineChars(ptPos
.y
).GetLength();
3619 // last pos of non last sub-line go to start of next screen line
3620 // Note: while this works correctly, it's not what a user might expect:
3621 // cursor-right when the caret is before the last char of a wrapped line
3622 // now moves the caret to the next line. But users expect the caret to
3623 // move to the right of the last char instead, and with another cursor-right
3624 // keystroke to move the caret to the next line.
3625 // Basically, this would require to handle two caret positions for the same
3626 // logical position in the line string (one on the last position of the first line,
3627 // one on the first position of the new line. For non-wrapped lines this works
3628 // because there's an 'invisible' newline char at the end of the first line.
3629 if (nSubLineLength
== ptPos
.x
&& nViewLineLenLeft
> nSubLineLength
)
3640 void CBaseView::EnsureCaretVisible()
3642 POINT ptCaretPos
= GetCaretPosition();
3643 int nCaretOffset
= CalculateActualOffset(ptCaretPos
);
3645 if (ptCaretPos
.y
< m_nTopLine
)
3646 ScrollAllToLine(ptCaretPos
.y
);
3647 int screnLines
= GetScreenLines();
3650 if (ptCaretPos
.y
>= (m_nTopLine
+screnLines
)-1)
3651 ScrollAllToLine(ptCaretPos
.y
-screnLines
+2);
3652 if (nCaretOffset
< m_nOffsetChar
)
3653 ScrollAllToChar(nCaretOffset
);
3654 if (nCaretOffset
> (m_nOffsetChar
+GetScreenChars()-1))
3655 ScrollAllToChar(nCaretOffset
-GetScreenChars()+1);
3659 int CBaseView::CalculateActualOffset(const POINT
& point
)
3661 int nLineIndex
= point
.y
;
3662 int nCharIndex
= point
.x
;
3663 ASSERT(nCharIndex
>= 0);
3664 CString sLine
= GetLineChars(nLineIndex
);
3665 int nLineLength
= sLine
.GetLength();
3666 return CountExpandedChars(sLine
, min(nCharIndex
, nLineLength
));
3669 int CBaseView::CalculateCharIndex(int nLineIndex
, int nActualOffset
)
3671 int nLength
= GetLineLength(nLineIndex
);
3672 int nSubLine
= GetSubLineOffset(nLineIndex
);
3675 int nViewLine
= GetViewLineForScreen(nLineIndex
);
3676 if ((nViewLine
>=0)&&(nViewLine
< (int)m_ScreenedViewLine
.size()))
3678 int nMultilineCount
= CountMultiLines(nViewLine
);
3679 if ((nMultilineCount
>0) && (nSubLine
<nMultilineCount
-1))
3685 CString Line
= GetLineChars(nLineIndex
);
3688 int nTabSize
= GetTabSize();
3689 while (nOffset
< nActualOffset
&& nIndex
< nLength
)
3691 if (Line
.GetAt(nIndex
) == _T('\t'))
3692 nOffset
+= (nTabSize
- nOffset
% nTabSize
);
3701 * @param xpos X coordinate in CBaseView
3702 * @param lineIndex logical line index (e.g. wrap/collapse)
3704 int CBaseView::CalcColFromPoint(int xpos
, int lineIndex
)
3710 CString text
= ExpandChars(GetLineChars(lineIndex
), 0);
3711 int fit
= text
.GetLength();
3712 auto posBuffer
= std::make_unique
<int[]>(fit
);
3713 pDC
->SelectObject(GetFont()); // is this right font ?
3715 GetTextExtentExPoint(pDC
->GetSafeHdc(), text
, fit
, INT_MAX
, &fit
, posBuffer
.get(), &size
);
3717 int lower
= -1, upper
= fit
- 1;
3718 int xcheck
= xpos
- GetMarginWidth() + m_nOffsetChar
* GetCharWidth();
3721 int middle
= (upper
+ lower
+ 1) / 2;
3722 int width
= posBuffer
.get()[middle
];
3727 } while (lower
< upper
);
3730 if (lower
< fit
- 1)
3732 int charWidth
= posBuffer
.get()[lower
] - (lower
> 0 ? posBuffer
.get()[lower
- 1] : 0);
3733 if (posBuffer
.get()[lower
] - xcheck
<= charWidth
/ 2)
3739 xpos2
= (xpos
- GetMarginWidth()) / GetCharWidth() + m_nOffsetChar
;
3740 if ((xpos
% GetCharWidth()) >= (GetCharWidth()/2))
3746 POINT
CBaseView::TextToClient(const POINT
& point
)
3749 int nOffsetScreenLine
= max(0, (point
.y
- m_nTopLine
));
3750 pt
.y
= nOffsetScreenLine
* GetLineHeight();
3751 pt
.x
= CalculateActualOffset(point
);
3753 int nLeft
= GetMarginWidth() - m_nOffsetChar
* GetCharWidth();
3754 CDC
* pDC
= GetDC();
3757 pDC
->SelectObject(GetFont()); // is this right font ?
3758 int nScreenLine
= nOffsetScreenLine
+ m_nTopLine
;
3759 CString sLine
= GetLineChars(nScreenLine
);
3760 ExpandChars(sLine
, 0, std::min
<int>(pt
.x
, sLine
.GetLength()), sLine
);
3761 nLeft
+= pDC
->GetTextExtent(sLine
, pt
.x
).cx
;
3764 nLeft
+= pt
.x
* GetCharWidth();
3768 pt
.y
= (pt
.y
+ GetLineHeight() + HEADERHEIGHT
);
3772 void CBaseView::OnChar(UINT nChar
, UINT nRepCnt
, UINT nFlags
)
3774 CView::OnChar(nChar
, nRepCnt
, nFlags
);
3776 bool bShift
= !!(GetKeyState(VK_SHIFT
)&0x8000);
3777 bool bSkipSelectionClear
= false;
3782 if ((::GetKeyState(VK_LBUTTON
) & 0x8000) != 0 ||
3783 (::GetKeyState(VK_RBUTTON
) & 0x8000) != 0)
3788 if (!m_pViewData
) // no data - nothing to do
3791 if (nChar
== VK_F16
)
3793 // generated by a ctrl+backspace - ignore.
3795 else if (nChar
==VK_TAB
&& HasTextLineSelection())
3797 // change indentation for selected lines
3800 RemoveIndentationForSelectedBlock();
3804 AddIndentationForSelectedBlock();
3806 bSkipSelectionClear
= true;
3808 else if ((nChar
> 31)||(nChar
== VK_TAB
))
3811 RemoveSelectedText();
3812 POINT ptCaretViewPos
= GetCaretViewPosition();
3813 int nViewLine
= ptCaretViewPos
.y
;
3814 if ((nViewLine
==0)&&(GetViewCount()==0))
3815 OnChar(VK_RETURN
, 0, 0);
3817 viewdata lineData
= GetViewData(nViewLine
);
3818 if (nChar
== VK_TAB
)
3820 int indentChars
= GetIndentCharsForLine(ptCaretViewPos
.x
, nViewLine
);
3821 if (indentChars
> 0)
3823 lineData
.sLine
.Insert(ptCaretViewPos
.x
, CString(_T(' '), indentChars
));
3824 charCount
= indentChars
;
3827 lineData
.sLine
.Insert(ptCaretViewPos
.x
, _T('\t'));
3832 lineData
.sLine
.Insert(ptCaretViewPos
.x
, (wchar_t)nChar
);
3835 if (lineData
.sLine
.GetLength() > ptCaretViewPos
.x
)
3836 lineData
.sLine
.SetAt(ptCaretViewPos
.x
, (wchar_t)nChar
);
3838 lineData
.sLine
.Insert(ptCaretViewPos
.x
, (wchar_t)nChar
);
3841 if (IsStateEmpty(lineData
.state
))
3843 // if not last line set EOL
3844 for (int nCheckViewLine
= nViewLine
+1; nCheckViewLine
< GetViewCount(); nCheckViewLine
++)
3846 if (!IsViewLineEmpty(nCheckViewLine
))
3848 lineData
.ending
= m_lineendings
;
3852 // make sure previous (non empty) line have EOL set
3853 for (int nCheckViewLine
= nViewLine
-1; nCheckViewLine
> 0; nCheckViewLine
--)
3855 if (!IsViewLineEmpty(nCheckViewLine
))
3857 if (GetViewLineEnding(nCheckViewLine
) == EOL_NOENDING
)
3859 SetViewLineEnding(nCheckViewLine
, m_lineendings
);
3865 lineData
.state
= DIFFSTATE_EDITED
;
3866 bool bNeedRenumber
= false;
3867 if (lineData
.linenumber
== -1)
3869 lineData
.linenumber
= 0;
3870 bNeedRenumber
= true;
3872 SetViewData(nViewLine
, lineData
);
3875 BuildAllScreen2ViewVector(nViewLine
);
3878 UpdateViewLineNumbers();
3880 for (int i
= 0; i
< charCount
; ++i
)
3884 else if (nChar
== 10)
3886 int nViewLine
= GetViewLineForScreen(GetCaretPosition().y
);
3887 EOL eol
= m_pViewData
->GetLineEnding(nViewLine
);
3888 EOL newEOL
= EOL_CRLF
;
3901 if (eol
==EOL_NOENDING
|| eol
==newEOL
)
3902 // don't allow to change enter on empty line, or last text line (lines with EOL_NOENDING)
3903 // to add EOL on newly edited empty line hit enter
3904 // don't store into UNDO if no change happened
3905 // and don't mark file as modified
3907 AddUndoViewLine(nViewLine
);
3908 m_pViewData
->SetLineEnding(nViewLine
, newEOL
);
3909 m_pViewData
->SetState(nViewLine
, DIFFSTATE_EDITED
);
3912 else if (nChar
== VK_RETURN
)
3914 // insert a new, fresh and empty line below the cursor
3915 RemoveSelectedText();
3917 CUndo::GetInstance().BeginGrouping();
3919 POINT ptCaretViewPos
= GetCaretViewPosition();
3920 int nViewLine
= ptCaretViewPos
.y
;
3921 int nLeft
= ptCaretViewPos
.x
;
3922 CString sLine
= GetViewLineChars(nViewLine
);
3923 CString sLineLeft
= sLine
.Left(nLeft
);
3924 CString sLineRight
= sLine
.Right(sLine
.GetLength() - nLeft
);
3925 EOL eOriginalEnding
= EOL_AUTOLINE
;
3926 if (m_pViewData
->GetCount() > nViewLine
)
3927 eOriginalEnding
= GetViewLineEnding(nViewLine
);
3929 if (!sLineRight
.IsEmpty() || (eOriginalEnding
!=m_lineendings
))
3931 viewdata
newFirstLine(sLineLeft
, DIFFSTATE_EDITED
, 1, m_lineendings
, HIDESTATE_SHOWN
);
3932 SetViewData(nViewLine
, newFirstLine
);
3935 int nInsertLine
= (m_pViewData
->GetCount()==0) ? 0 : nViewLine
+ 1;
3936 viewdata
newLastLine(sLineRight
, DIFFSTATE_EDITED
, 1, eOriginalEnding
, HIDESTATE_SHOWN
);
3937 InsertViewData(nInsertLine
, newLastLine
);
3941 // adds new line everywhere except me
3942 if (IsViewGood(m_pwndLeft
) && m_pwndLeft
!=this)
3944 m_pwndLeft
->InsertViewEmptyLines(nInsertLine
, 1);
3946 if (IsViewGood(m_pwndRight
) && m_pwndRight
!=this)
3948 m_pwndRight
->InsertViewEmptyLines(nInsertLine
, 1);
3950 if (IsViewGood(m_pwndBottom
) && m_pwndBottom
!=this)
3952 m_pwndBottom
->InsertViewEmptyLines(nInsertLine
, 1);
3956 UpdateViewLineNumbers();
3958 CUndo::GetInstance().EndGrouping();
3960 BuildAllScreen2ViewVector();
3961 // move the cursor to the new line
3962 ptCaretViewPos
= SetupPoint(0, nViewLine
+1);
3963 SetCaretAndGoalViewPosition(ptCaretViewPos
);
3966 return; // Unknown control character -- ignore it.
3967 if (!bSkipSelectionClear
)
3969 EnsureCaretVisible();
3974 void CBaseView::AddUndoViewLine(int nViewLine
, bool bAddEmptyLine
)
3977 m_AllState
.left
.AddViewLineFromView(m_pwndLeft
, nViewLine
, bAddEmptyLine
);
3978 m_AllState
.right
.AddViewLineFromView(m_pwndRight
, nViewLine
, bAddEmptyLine
);
3979 m_AllState
.bottom
.AddViewLineFromView(m_pwndBottom
, nViewLine
, bAddEmptyLine
);
3982 RecalcAllVertScrollBars();
3986 void CBaseView::AddEmptyViewLine(int nViewLineIndex
)
3988 if (m_pViewData
== NULL
)
3990 int viewLine
= nViewLineIndex
;
3991 EOL ending
= m_pViewData
->GetLineEnding(viewLine
);
3992 if (ending
== EOL_NOENDING
)
3994 ending
= m_lineendings
;
3996 viewdata
newLine(_T(""), DIFFSTATE_EDITED
, -1, ending
, HIDESTATE_SHOWN
);
3997 if (IsTarget()) // TODO: once more wievs will writable this is not correct anymore
3999 CString sPartLine
= GetViewLineChars(nViewLineIndex
);
4000 int nPosx
= GetCaretPosition().x
; // should be view pos ?
4001 m_pViewData
->SetLine(viewLine
, sPartLine
.Left(nPosx
));
4002 sPartLine
= sPartLine
.Mid(nPosx
);
4003 newLine
.sLine
= sPartLine
;
4005 m_pViewData
->InsertData(viewLine
+1, newLine
);
4006 BuildAllScreen2ViewVector();
4009 void CBaseView::RemoveSelectedText()
4011 if (m_pViewData
== NULL
)
4013 if (!HasTextSelection())
4016 // fix selection if starts or ends on empty line
4017 SetCaretViewPosition(m_ptSelectionViewPosEnd
);
4018 while (IsViewLineEmpty(GetCaretViewPosition().y
) && MoveCaretRight())
4021 m_ptSelectionViewPosEnd
= GetCaretViewPosition();
4022 SetCaretViewPosition(m_ptSelectionViewPosStart
);
4023 while (IsViewLineEmpty(GetCaretViewPosition().y
) && MoveCaretRight())
4026 m_ptSelectionViewPosStart
= GetCaretViewPosition();
4027 if (!HasTextSelection())
4033 // We want to undo the insertion in a single step.
4035 CUndo::GetInstance().BeginGrouping();
4037 // combine first and last line
4038 viewdata oFirstLine
= GetViewData(m_ptSelectionViewPosStart
.y
);
4039 viewdata oLastLine
= GetViewData(m_ptSelectionViewPosEnd
.y
);
4040 oFirstLine
.sLine
= oFirstLine
.sLine
.Left(m_ptSelectionViewPosStart
.x
) + oLastLine
.sLine
.Mid(m_ptSelectionViewPosEnd
.x
);
4041 oFirstLine
.ending
= oLastLine
.ending
;
4042 oFirstLine
.state
= DIFFSTATE_EDITED
;
4043 SetViewData(m_ptSelectionViewPosStart
.y
, oFirstLine
);
4045 // clean up middle lines if any
4046 if (m_ptSelectionViewPosStart
.y
!= m_ptSelectionViewPosEnd
.y
)
4048 viewdata oEmptyLine
= GetEmptyLineData();
4049 for (int nViewLine
= m_ptSelectionViewPosStart
.y
+1; nViewLine
<= m_ptSelectionViewPosEnd
.y
; nViewLine
++)
4051 SetViewData(nViewLine
, oEmptyLine
);
4055 if (CleanEmptyLines())
4057 BuildAllScreen2ViewVector(); // schedule full rebuild
4060 UpdateViewLineNumbers();
4063 SetModified(); //TODO set modified only if real data was changed
4065 CUndo::GetInstance().EndGrouping();
4067 BuildAllScreen2ViewVector(m_ptSelectionViewPosStart
.y
, m_ptSelectionViewPosEnd
.y
);
4068 SetCaretViewPosition(m_ptSelectionViewPosStart
);
4072 EnsureCaretVisible();
4076 void CBaseView::PasteText()
4078 if (!OpenClipboard())
4081 CString sClipboardText
;
4082 HGLOBAL hglb
= GetClipboardData(CF_TEXT
);
4085 LPCSTR lpstr
= (LPCSTR
)GlobalLock(hglb
);
4086 sClipboardText
= CString(lpstr
);
4089 hglb
= GetClipboardData(CF_UNICODETEXT
);
4092 LPCTSTR lpstr
= (LPCTSTR
)GlobalLock(hglb
);
4093 sClipboardText
= lpstr
;
4098 if (sClipboardText
.IsEmpty())
4101 sClipboardText
.Replace(_T("\r\n"), _T("\r"));
4102 sClipboardText
.Replace('\n', '\r');
4104 InsertText(sClipboardText
);
4107 void CBaseView::OnCaretDown()
4109 POINT ptCaretPos
= GetCaretPosition();
4110 int nLine
= ptCaretPos
.y
;
4111 int nNextLine
= nLine
+ 1;
4112 if (nNextLine
>= GetLineCount()) // already at last line
4117 POINT ptCaretViewPos
= GetCaretViewPosition();
4118 int nViewLine
= ptCaretViewPos
.y
;
4119 int nNextViewLine
= GetViewLineForScreen(nNextLine
);
4120 if (!((nNextViewLine
== nViewLine
) && (GetSubLineOffset(nNextLine
)<CountMultiLines(nNextViewLine
)))) // not on same view line
4122 // find next suitable screen line
4123 while ((nNextViewLine
== nViewLine
) || IsViewLineHidden(nNextViewLine
))
4126 if (nNextLine
>= GetLineCount())
4130 nNextViewLine
= GetViewLineForScreen(nNextLine
);
4133 ptCaretPos
.y
= nNextLine
;
4134 ptCaretPos
.x
= CalculateCharIndex(ptCaretPos
.y
, m_nCaretGoalPos
);
4135 SetCaretPosition(ptCaretPos
);
4136 OnCaretMove(MOVELEFT
);
4137 ShowDiffLines(ptCaretPos
.y
);
4140 bool CBaseView::MoveCaretLeft()
4142 POINT ptCaretViewPos
= GetCaretViewPosition();
4144 //int nViewLine = ptCaretViewPos.y;
4145 if (ptCaretViewPos
.x
== 0)
4147 int nPrevLine
= GetCaretPosition().y
;
4155 nPrevViewLine
= GetViewLineForScreen(nPrevLine
);
4156 } while ((GetSubLineOffset(nPrevLine
) >= CountMultiLines(nPrevViewLine
)) || IsViewLineHidden(nPrevViewLine
));
4157 ptCaretViewPos
= ConvertScreenPosToView(SetupPoint(GetLineLength(nPrevLine
), nPrevLine
));
4158 ShowDiffLines(nPrevLine
);
4163 SetCaretAndGoalViewPosition(ptCaretViewPos
);
4167 bool CBaseView::MoveCaretRight()
4169 POINT ptCaretViewPos
= GetCaretViewPosition();
4171 int nViewLine
= ptCaretViewPos
.y
;
4172 int nViewLineLen
= GetViewLineLength(nViewLine
);
4173 if (ptCaretViewPos
.x
>= nViewLineLen
)
4175 int nNextLine
= GetCaretPosition().y
;
4179 if (nNextLine
>= GetLineCount())
4183 nNextViewLine
= GetViewLineForScreen(nNextLine
);
4184 } while (nNextViewLine
== nViewLine
|| IsViewLineHidden(nNextViewLine
));
4185 ptCaretViewPos
.y
= nNextViewLine
;
4186 ptCaretViewPos
.x
= 0;
4187 ShowDiffLines(nNextLine
);
4192 SetCaretAndGoalViewPosition(ptCaretViewPos
);
4196 void CBaseView::UpdateGoalPos()
4198 m_nCaretGoalPos
= CalculateActualOffset(GetCaretPosition());
4201 void CBaseView::OnCaretLeft()
4204 OnCaretMove(MOVELEFT
);
4207 void CBaseView::OnCaretRight()
4210 OnCaretMove(MOVERIGHT
);
4213 void CBaseView::OnCaretUp()
4215 POINT ptCaretPos
= GetCaretPosition();
4216 int nLine
= ptCaretPos
.y
;
4217 if (nLine
<= 0) // already at first line
4221 int nPrevLine
= nLine
- 1;
4223 POINT ptCaretViewPos
= GetCaretViewPosition();
4224 int nViewLine
= ptCaretViewPos
.y
;
4225 int nPrevViewLine
= GetViewLineForScreen(nPrevLine
);
4226 if (nPrevViewLine
!= nViewLine
) // not on same view line
4228 // find previous suitable screen line
4229 while ((GetSubLineOffset(nPrevLine
) >= CountMultiLines(nPrevViewLine
)) || IsViewLineHidden(nPrevViewLine
))
4236 nPrevViewLine
= GetViewLineForScreen(nPrevLine
);
4239 ptCaretPos
.y
= nPrevLine
;
4240 ptCaretPos
.x
= CalculateCharIndex(ptCaretPos
.y
, m_nCaretGoalPos
);
4241 SetCaretPosition(ptCaretPos
);
4242 OnCaretMove(MOVELEFT
);
4243 ShowDiffLines(ptCaretPos
.y
);
4246 bool CBaseView::IsWordSeparator(const wchar_t ch
) const
4248 switch (GetCharGroup(ch
))
4251 case CHG_WHITESPACE
:
4252 case CHG_WORDSEPARATOR
:
4258 bool CBaseView::IsCaretAtWordBoundary()
4260 POINT ptViewCaret
= GetCaretViewPosition();
4261 CString line
= GetViewLineChars(ptViewCaret
.y
);
4263 return false; // no boundary at the empty lines
4264 if (ptViewCaret
.x
== 0)
4265 return !IsWordSeparator(line
.GetAt(ptViewCaret
.x
));
4266 if (ptViewCaret
.x
>= GetViewLineLength(ptViewCaret
.y
))
4267 return !IsWordSeparator(line
.GetAt(ptViewCaret
.x
- 1));
4269 IsWordSeparator(line
.GetAt(ptViewCaret
.x
)) !=
4270 IsWordSeparator(line
.GetAt(ptViewCaret
.x
- 1));
4273 void CBaseView::UpdateViewsCaretPosition()
4275 POINT ptCaretPos
= GetCaretPosition();
4276 if (m_pwndBottom
&& m_pwndBottom
!=this)
4277 m_pwndBottom
->UpdateCaretPosition(ptCaretPos
);
4278 if (m_pwndLeft
&& m_pwndLeft
!=this)
4279 m_pwndLeft
->UpdateCaretPosition(ptCaretPos
);
4280 if (m_pwndRight
&& m_pwndRight
!=this)
4281 m_pwndRight
->UpdateCaretPosition(ptCaretPos
);
4284 void CBaseView::OnCaretWordleft()
4286 MoveCaretWordLeft();
4287 OnCaretMove(MOVELEFT
);
4290 void CBaseView::OnCaretWordright()
4292 MoveCaretWordRight();
4293 OnCaretMove(MOVERIGHT
);
4296 void CBaseView::MoveCaretWordLeft()
4298 while (MoveCaretLeft() && !IsCaretAtWordBoundary())
4303 void CBaseView::MoveCaretWordRight()
4305 while (MoveCaretRight() && !IsCaretAtWordBoundary())
4310 void CBaseView::ClearCurrentSelection()
4312 m_ptSelectionViewPosStart
= GetCaretViewPosition();
4313 m_ptSelectionViewPosEnd
= m_ptSelectionViewPosStart
;
4314 m_ptSelectionViewPosOrigin
= m_ptSelectionViewPosStart
;
4315 m_nSelViewBlockStart
= -1;
4316 m_nSelViewBlockEnd
= -1;
4320 void CBaseView::ClearSelection()
4323 m_pwndLeft
->ClearCurrentSelection();
4325 m_pwndRight
->ClearCurrentSelection();
4327 m_pwndBottom
->ClearCurrentSelection();
4330 void CBaseView::AdjustSelection(bool bMoveLeft
)
4332 POINT ptCaretViewPos
= GetCaretViewPosition();
4333 if (ArePointsSame(m_ptSelectionViewPosOrigin
, SetupPoint(-1, -1)))
4335 // select all have been used recently update origin
4336 m_ptSelectionViewPosOrigin
= bMoveLeft
? m_ptSelectionViewPosEnd
: m_ptSelectionViewPosStart
;
4338 if ((ptCaretViewPos
.y
< m_ptSelectionViewPosOrigin
.y
) ||
4339 (ptCaretViewPos
.y
== m_ptSelectionViewPosOrigin
.y
&& ptCaretViewPos
.x
<= m_ptSelectionViewPosOrigin
.x
))
4341 m_ptSelectionViewPosStart
= ptCaretViewPos
;
4342 m_ptSelectionViewPosEnd
= m_ptSelectionViewPosOrigin
;
4346 m_ptSelectionViewPosStart
= m_ptSelectionViewPosOrigin
;
4347 m_ptSelectionViewPosEnd
= ptCaretViewPos
;
4350 SetupAllViewSelection(m_ptSelectionViewPosStart
.y
, m_ptSelectionViewPosEnd
.y
);
4355 void CBaseView::OnEditCut()
4360 RemoveSelectedText();
4364 void CBaseView::OnEditPaste()
4368 CUndo::GetInstance().BeginGrouping();
4369 RemoveSelectedText();
4371 CUndo::GetInstance().EndGrouping();
4375 void CBaseView::DeleteFonts()
4377 for (int i
=0; i
<fontsCount
; i
++)
4379 if (m_apFonts
[i
] != NULL
)
4381 m_apFonts
[i
]->DeleteObject();
4382 delete m_apFonts
[i
];
4383 m_apFonts
[i
] = NULL
;
4388 void CBaseView::OnCaretMove(bool bMoveLeft
)
4390 bool bShift
= !!(GetKeyState(VK_SHIFT
)&0x8000);
4391 OnCaretMove(bMoveLeft
, bShift
);
4394 void CBaseView::OnCaretMove(bool bMoveLeft
, bool isShiftPressed
)
4397 AdjustSelection(bMoveLeft
);
4400 EnsureCaretVisible();
4404 void CBaseView::AddContextItems(CIconMenu
& popup
, DiffStates
/*state*/)
4406 AddCutCopyAndPaste(popup
);
4409 void CBaseView::AddCutCopyAndPaste(CIconMenu
& popup
)
4411 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
4413 temp
.LoadString(IDS_EDIT_COPY
);
4414 popup
.AppendMenu(MF_STRING
| (HasTextSelection() ? MF_ENABLED
: MF_DISABLED
|MF_GRAYED
), ID_EDIT_COPY
, temp
);
4417 temp
.LoadString(IDS_EDIT_CUT
);
4418 popup
.AppendMenu(MF_STRING
| (HasTextSelection() ? MF_ENABLED
: MF_DISABLED
|MF_GRAYED
), ID_EDIT_CUT
, temp
);
4419 temp
.LoadString(IDS_EDIT_PASTE
);
4420 popup
.AppendMenu(MF_STRING
| (CAppUtils::HasClipboardFormat(CF_UNICODETEXT
)||CAppUtils::HasClipboardFormat(CF_TEXT
) ? MF_ENABLED
: MF_DISABLED
|MF_GRAYED
), ID_EDIT_PASTE
, temp
);
4421 popup
.AppendMenu(MF_SEPARATOR
, NULL
);
4425 void CBaseView::CompensateForKeyboard(CPoint
& point
)
4427 // if the context menu is invoked through the keyboard, we have to use
4428 // a calculated position on where to anchor the menu on
4429 if (ArePointsSame(point
, SetupPoint(-1, -1)))
4432 GetWindowRect(&rect
);
4433 point
= rect
.CenterPoint();
4437 HICON
CBaseView::LoadIcon(WORD iconId
)
4439 HANDLE icon
= ::LoadImage( AfxGetResourceHandle(), MAKEINTRESOURCE(iconId
),
4440 IMAGE_ICON
, 16, 16, LR_DEFAULTCOLOR
);
4444 void CBaseView::ReleaseBitmap()
4446 if (m_pCacheBitmap
!= NULL
)
4448 m_pCacheBitmap
->DeleteObject();
4449 delete m_pCacheBitmap
;
4450 m_pCacheBitmap
= NULL
;
4454 void CBaseView::BuildMarkedWordArray()
4456 int lineCount
= GetLineCount();
4457 m_arMarkedWordLines
.clear();
4458 m_arMarkedWordLines
.reserve(lineCount
);
4459 bool bDoit
= !m_sMarkedWord
.IsEmpty();
4460 for (int i
= 0; i
< lineCount
; ++i
)
4464 CString line
= GetLineChars(i
);
4466 if (!line
.IsEmpty())
4469 int nMarkStart
= -1;
4470 while ((nMarkStart
= line
.Find(m_sMarkedWord
, ++nMarkStart
)) >= 0)
4472 int nMarkEnd
= nMarkStart
+ m_sMarkedWord
.GetLength();
4473 ECharGroup eLeft
= GetCharGroup(line
, nMarkStart
- 1);
4474 ECharGroup eStart
= GetCharGroup(line
, nMarkStart
);
4475 if (eLeft
!= eStart
)
4477 ECharGroup eRight
= GetCharGroup(line
, nMarkEnd
);
4478 ECharGroup eEnd
= GetCharGroup(line
, nMarkEnd
- 1);
4486 m_arMarkedWordLines
.push_back(found
);
4489 m_arMarkedWordLines
.push_back(0);
4492 m_arMarkedWordLines
.push_back(0);
4496 void CBaseView::BuildFindStringArray()
4498 int lineCount
= GetLineCount();
4499 m_arFindStringLines
.clear();
4500 m_arFindStringLines
.reserve(lineCount
);
4501 bool bDoit
= !m_sFindText
.IsEmpty();
4504 for (int i
= 0; i
< lineCount
; ++i
)
4508 CString line
= GetLineChars(i
);
4510 if (!line
.IsEmpty())
4512 switch (m_pViewData
->GetState(GetViewLineForScreen(i
)))
4514 case DIFFSTATE_EMPTY
:
4515 m_arFindStringLines
.push_back(0);
4517 case DIFFSTATE_UNKNOWN
:
4518 case DIFFSTATE_NORMAL
:
4521 m_arFindStringLines
.push_back(0);
4524 case DIFFSTATE_REMOVED
:
4525 case DIFFSTATE_REMOVEDWHITESPACE
:
4526 case DIFFSTATE_ADDED
:
4527 case DIFFSTATE_ADDEDWHITESPACE
:
4528 case DIFFSTATE_WHITESPACE
:
4529 case DIFFSTATE_WHITESPACE_DIFF
:
4530 case DIFFSTATE_CONFLICTED
:
4531 case DIFFSTATE_CONFLICTED_IGNORED
:
4532 case DIFFSTATE_CONFLICTADDED
:
4533 case DIFFSTATE_CONFLICTEMPTY
:
4534 case DIFFSTATE_CONFLICTRESOLVED
:
4535 case DIFFSTATE_IDENTICALREMOVED
:
4536 case DIFFSTATE_IDENTICALADDED
:
4537 case DIFFSTATE_THEIRSREMOVED
:
4538 case DIFFSTATE_THEIRSADDED
:
4539 case DIFFSTATE_YOURSREMOVED
:
4540 case DIFFSTATE_YOURSADDED
:
4541 case DIFFSTATE_EDITED
:
4544 line
= line
.MakeLower();
4548 while (StringFound(line
, SearchNext
, s
, e
))
4554 m_arFindStringLines
.push_back(match
);
4558 m_arFindStringLines
.push_back(0);
4562 m_arFindStringLines
.push_back(0);
4565 m_arFindStringLines
.push_back(0);
4570 bool CBaseView::GetInlineDiffPositions(int nViewLine
, std::vector
<inlineDiffPos
>& positions
)
4572 if (!m_bShowInlineDiff
)
4574 if ((m_pwndBottom
!= NULL
) && !(m_pwndBottom
->IsHidden()))
4577 if (m_pViewData
== nullptr || m_pViewData
->GetCount() <= nViewLine
)
4579 const CString
&sLine
= m_pViewData
->GetLine(nViewLine
);
4580 if (sLine
.IsEmpty())
4584 if (!m_pOtherViewData
)
4587 const CString
&sDiffLine
= m_pOtherViewData
->GetLine(nViewLine
);
4588 if (sDiffLine
.IsEmpty())
4591 svn_diff_t
* diff
= NULL
;
4592 auto pLine1
= (this == m_pwndLeft
) ? &sLine
: &sDiffLine
;
4593 auto pLine2
= (this == m_pwndLeft
) ? &sDiffLine
: &sLine
;
4594 m_svnlinediff
.Diff(&diff
, *pLine1
, pLine1
->GetLength(), *pLine2
, pLine2
->GetLength(), m_bInlineWordDiff
);
4595 if (!diff
|| !SVNLineDiff::ShowInlineDiff(diff
))
4598 size_t lineoffset
= 0;
4599 size_t position
= 0;
4602 if (this == m_pwndRight
)
4604 apr_off_t nTmp
= diff
->modified_length
;
4605 diff
->modified_length
= diff
->original_length
;
4606 diff
->original_length
= nTmp
;
4608 nTmp
= diff
->modified_start
;
4609 diff
->modified_start
= diff
->original_start
;
4610 diff
->original_start
= nTmp
;
4612 apr_off_t len
= diff
->original_length
;
4613 size_t oldpos
= position
;
4615 for (apr_off_t i
= 0; i
< len
; ++i
)
4617 position
+= (this == m_pwndRight
) ? m_svnlinediff
.m_line2tokens
[lineoffset
].size() : m_svnlinediff
.m_line1tokens
[lineoffset
].size();
4621 if (diff
->type
== svn_diff__type_diff_modified
)
4626 positions
.push_back(p
);
4632 return !positions
.empty();
4635 void CBaseView::OnNavigateNextinlinediff()
4638 if (GetNextInlineDiff(nX
))
4640 POINT ptCaretViewPos
= GetCaretViewPosition();
4641 ptCaretViewPos
.x
= nX
;
4642 SetCaretAndGoalViewPosition(ptCaretViewPos
);
4643 m_ptSelectionViewPosOrigin
= ptCaretViewPos
;
4644 EnsureCaretVisible();
4648 void CBaseView::OnNavigatePrevinlinediff()
4651 if (GetPrevInlineDiff(nX
))
4653 POINT ptCaretViewPos
= GetCaretViewPosition();
4654 ptCaretViewPos
.x
= nX
;
4655 SetCaretAndGoalViewPosition(ptCaretViewPos
);
4656 m_ptSelectionViewPosOrigin
= ptCaretViewPos
;
4657 EnsureCaretVisible();
4661 bool CBaseView::HasNextInlineDiff()
4664 return GetNextInlineDiff(nPos
);
4667 bool CBaseView::GetNextInlineDiff(int & nPos
)
4669 POINT ptCaretViewPos
= GetCaretViewPosition();
4670 std::vector
<inlineDiffPos
> positions
;
4671 if (GetInlineDiffPositions(ptCaretViewPos
.y
, positions
))
4673 for (auto it
= positions
.cbegin(); it
!= positions
.cend(); ++it
)
4675 if (it
->start
> ptCaretViewPos
.x
)
4677 nPos
= (LONG
)it
->start
;
4680 if (it
->end
> ptCaretViewPos
.x
)
4682 nPos
= (LONG
)it
->end
;
4690 bool CBaseView::HasPrevInlineDiff()
4693 return GetPrevInlineDiff(nPos
);
4696 bool CBaseView::GetPrevInlineDiff(int & nPos
)
4698 POINT ptCaretViewPos
= GetCaretViewPosition();
4699 std::vector
<inlineDiffPos
> positions
;
4700 if (GetInlineDiffPositions(ptCaretViewPos
.y
, positions
))
4702 for (auto it
= positions
.crbegin(); it
!= positions
.crend(); ++it
)
4704 if ( it
->end
< ptCaretViewPos
.x
)
4706 nPos
= (LONG
)it
->end
;
4709 if ( it
->start
< ptCaretViewPos
.x
)
4711 nPos
= (LONG
)it
->start
;
4719 CBaseView
* CBaseView::GetFirstGoodView()
4721 if (IsViewGood(m_pwndLeft
))
4723 if (IsViewGood(m_pwndRight
))
4725 if (IsViewGood(m_pwndBottom
))
4726 return m_pwndBottom
;
4730 void CBaseView::BuildAllScreen2ViewVector()
4732 CBaseView
* p_pwndView
= GetFirstGoodView();
4735 m_Screen2View
.ScheduleFullRebuild(p_pwndView
->m_pViewData
);
4739 void CBaseView::BuildAllScreen2ViewVector(int nViewLine
)
4741 BuildAllScreen2ViewVector(nViewLine
, nViewLine
);
4744 void CBaseView::BuildAllScreen2ViewVector(int nFirstViewLine
, int nLastViewLine
)
4746 CBaseView
* p_pwndView
= GetFirstGoodView();
4749 m_Screen2View
.ScheduleRangeRebuild(p_pwndView
->m_pViewData
, nFirstViewLine
, nLastViewLine
);
4753 void CBaseView::UpdateViewLineNumbers()
4755 int nLineNumber
= 0;
4756 int nViewLineCount
= GetViewCount();
4757 for (int nViewLine
= 0; nViewLine
< nViewLineCount
; nViewLine
++)
4759 int oldLine
= (int)GetViewLineNumber(nViewLine
);
4761 SetViewLineNumber(nViewLine
, nLineNumber
++);
4766 int CBaseView::CleanEmptyLines()
4768 int nRemovedCount
= 0;
4769 int nViewLineCount
= GetViewCount();
4770 bool bCheckLeft
= IsViewGood(m_pwndLeft
);
4771 bool bCheckRight
= IsViewGood(m_pwndRight
);
4772 bool bCheckBottom
= IsViewGood(m_pwndBottom
);
4773 for (int nViewLine
= 0; nViewLine
< nViewLineCount
; )
4775 bool bAllEmpty
= true;
4776 bAllEmpty
&= !bCheckLeft
|| IsStateEmpty(m_pwndLeft
->GetViewState(nViewLine
));
4777 bAllEmpty
&= !bCheckRight
|| IsStateEmpty(m_pwndRight
->GetViewState(nViewLine
));
4778 bAllEmpty
&= !bCheckBottom
|| IsStateEmpty(m_pwndBottom
->GetViewState(nViewLine
));
4783 m_pwndLeft
->RemoveViewData(nViewLine
);
4787 m_pwndRight
->RemoveViewData(nViewLine
);
4791 m_pwndBottom
->RemoveViewData(nViewLine
);
4793 if (CUndo::GetInstance().IsGrouping()) // if use group undo -> ensure back adding goes in right (reversed) order
4803 return nRemovedCount
;
4806 int CBaseView::FindScreenLineForViewLine( int viewLine
)
4808 return m_Screen2View
.FindScreenLineForViewLine(viewLine
);
4811 int CBaseView::CountMultiLines( int nViewLine
)
4813 if (m_ScreenedViewLine
.empty())
4814 return 0; // in case the view is completely empty
4816 ASSERT(nViewLine
< (int)m_ScreenedViewLine
.size());
4818 if (m_ScreenedViewLine
[nViewLine
].bSublinesSet
)
4820 return (int)m_ScreenedViewLine
[nViewLine
].SubLines
.size();
4823 CString multiline
= CStringUtils::WordWrap(m_pViewData
->GetLine(nViewLine
), GetScreenChars()-1, false, true, GetTabSize()); // GetMultiLine(nLine);
4825 TScreenedViewLine oScreenedLine
;
4829 while ((pos
= multiline
.Find('\n', pos
)) >= 0)
4831 oScreenedLine
.SubLines
.push_back(multiline
.Mid(prevpos
, pos
-prevpos
)); // WordWrap could return vector/list of lines instead of string
4835 oScreenedLine
.SubLines
.push_back(multiline
.Mid(prevpos
));
4836 oScreenedLine
.bSublinesSet
= true;
4837 m_ScreenedViewLine
[nViewLine
] = oScreenedLine
;
4839 return CountMultiLines(nViewLine
);
4842 /// prepare inline diff cache
4843 LineColors
& CBaseView::GetLineColors(int nViewLine
)
4845 ASSERT(nViewLine
< (int)m_ScreenedViewLine
.size());
4847 if (m_bWhitespaceInlineDiffs
)
4849 if (m_ScreenedViewLine
[nViewLine
].bLineColorsSetWhiteSpace
)
4850 return m_ScreenedViewLine
[nViewLine
].lineColorsWhiteSpace
;
4854 if (m_ScreenedViewLine
[nViewLine
].bLineColorsSet
)
4855 return m_ScreenedViewLine
[nViewLine
].lineColors
;
4858 LineColors oLineColors
;
4859 // set main line color
4860 COLORREF crBkgnd
, crText
;
4861 DiffStates diffState
= m_pViewData
->GetState(nViewLine
);
4862 CDiffColors::GetInstance().GetColors(diffState
, crBkgnd
, crText
);
4863 oLineColors
.SetColor(0, crText
, crBkgnd
);
4866 if (!m_bShowInlineDiff
)
4869 if ((diffState
== DIFFSTATE_NORMAL
)&&(!m_bWhitespaceInlineDiffs
))
4872 CString sLine
= GetViewLineChars(nViewLine
);
4873 if (sLine
.IsEmpty())
4878 CString sDiffLine
= m_pOtherView
->GetViewLineChars(nViewLine
);
4879 if (sDiffLine
.IsEmpty())
4882 svn_diff_t
* diff
= NULL
;
4883 if (sLine
.GetLength() > (int)m_nInlineDiffMaxLineLength
)
4885 auto pLine1
= (this == m_pwndLeft
) ? &sLine
: &sDiffLine
;
4886 auto pLine2
= (this == m_pwndLeft
) ? &sDiffLine
: &sLine
;
4887 m_svnlinediff
.Diff(&diff
, *pLine1
, pLine1
->GetLength(), *pLine2
, pLine2
->GetLength(), m_bInlineWordDiff
);
4888 if (!diff
|| !SVNLineDiff::ShowInlineDiff(diff
) || !diff
->next
)
4892 int nTextStartOffset
= 0;
4893 std::map
<int, COLORREF
> removedPositions
;
4896 if (this == m_pwndRight
)
4898 apr_off_t nTmp
= diff
->modified_length
;
4899 diff
->modified_length
= diff
->original_length
;
4900 diff
->original_length
= nTmp
;
4902 nTmp
= diff
->modified_start
;
4903 diff
->modified_start
= diff
->original_start
;
4904 diff
->original_start
= nTmp
;
4906 apr_off_t len
= diff
->original_length
;
4908 size_t nTextLength
= 0;
4909 for (int i
= 0; i
< len
; ++i
)
4911 nTextLength
+= (this == m_pwndRight
) ? m_svnlinediff
.m_line2tokens
[lineoffset
].size() : m_svnlinediff
.m_line1tokens
[lineoffset
].size();
4914 bool bInlineDiff
= (diff
->type
== svn_diff__type_diff_modified
);
4916 CDiffColors::GetInstance().GetColors(diffState
, crBkgnd
, crText
);
4917 if ((m_bShowInlineDiff
)&&(bInlineDiff
))
4919 crBkgnd
= InlineViewLineDiffColor(nViewLine
);
4923 crBkgnd
= m_ModifiedBk
;
4926 if (len
< diff
->modified_length
)
4928 removedPositions
[nTextStartOffset
] = m_InlineRemovedBk
;
4930 oLineColors
.SetColor(nTextStartOffset
, crText
, crBkgnd
);
4932 nTextStartOffset
+= (int)nTextLength
;
4935 for (std::map
<int, COLORREF
>::const_iterator it
= removedPositions
.begin(); it
!= removedPositions
.end(); ++it
)
4937 oLineColors
.AddShotColor(it
->first
, it
->second
);
4939 } while (false); // error catch
4941 if (!m_bWhitespaceInlineDiffs
)
4943 m_ScreenedViewLine
[nViewLine
].lineColors
= oLineColors
;
4944 m_ScreenedViewLine
[nViewLine
].bLineColorsSet
= true;
4948 m_ScreenedViewLine
[nViewLine
].lineColorsWhiteSpace
= oLineColors
;
4949 m_ScreenedViewLine
[nViewLine
].bLineColorsSetWhiteSpace
= true;
4952 return GetLineColors(nViewLine
);
4955 void CBaseView::OnEditSelectall()
4957 if (m_pViewData
== nullptr)
4959 int nLastViewLine
= m_pViewData
->GetCount()-1;
4960 if (nLastViewLine
< 0)
4962 SetupAllViewSelection(0, nLastViewLine
);
4964 CString sLine
= GetViewLineChars(nLastViewLine
);
4965 m_ptSelectionViewPosStart
= SetupPoint(0, 0);
4966 m_ptSelectionViewPosEnd
= SetupPoint(sLine
.GetLength(), nLastViewLine
);
4967 m_ptSelectionViewPosOrigin
= SetupPoint(-1, -1);
4972 void CBaseView::FilterWhitespaces(CString
& first
, CString
& second
)
4974 FilterWhitespaces(first
);
4975 FilterWhitespaces(second
);
4978 void CBaseView::FilterWhitespaces(CString
& line
)
4986 int CBaseView::GetButtonEventLineIndex(const POINT
& point
)
4988 const int nLineFromTop
= (point
.y
- HEADERHEIGHT
) / GetLineHeight();
4989 int nEventLine
= nLineFromTop
+ m_nTopLine
;
4990 nEventLine
--; //we need the index
4995 BOOL
CBaseView::PreTranslateMessage(MSG
* pMsg
)
4997 if (RelayTrippleClick(pMsg
))
4999 return CView::PreTranslateMessage(pMsg
);
5003 void CBaseView::ResetUndoStep()
5008 void CBaseView::SaveUndoStep()
5010 if (!m_AllState
.IsEmpty())
5012 CUndo::GetInstance().AddState(m_AllState
, GetCaretViewPosition());
5017 void CBaseView::InsertViewData( int index
, const CString
& sLine
, DiffStates state
, int linenumber
, EOL ending
, HIDESTATE hide
, int movedline
)
5019 m_pState
->addedlines
.push_back(index
);
5020 m_pViewData
->InsertData(index
, sLine
, state
, linenumber
, ending
, hide
, movedline
);
5023 void CBaseView::InsertViewData( int index
, const viewdata
& data
)
5025 m_pState
->addedlines
.push_back(index
);
5026 m_pViewData
->InsertData(index
, data
);
5029 void CBaseView::RemoveViewData( int index
)
5031 m_pState
->removedlines
[index
] = m_pViewData
->GetData(index
);
5032 m_pViewData
->RemoveData(index
);
5035 void CBaseView::SetViewData( int index
, const viewdata
& data
)
5037 m_pState
->replacedlines
[index
] = m_pViewData
->GetData(index
);
5038 m_pViewData
->SetData(index
, data
);
5041 void CBaseView::SetViewState( int index
, DiffStates state
)
5043 m_pState
->linestates
[index
] = m_pViewData
->GetState(index
);
5044 m_pViewData
->SetState(index
, state
);
5047 void CBaseView::SetViewLine( int index
, const CString
& sLine
)
5049 m_pState
->difflines
[index
] = m_pViewData
->GetLine(index
);
5050 m_pViewData
->SetLine(index
, sLine
);
5053 void CBaseView::SetViewLineNumber( int index
, int linenumber
)
5055 int oldLineNumber
= m_pViewData
->GetLineNumber(index
);
5056 if (oldLineNumber
!= linenumber
) {
5057 m_pState
->linelines
[index
] = oldLineNumber
;
5058 m_pViewData
->SetLineNumber(index
, linenumber
);
5062 void CBaseView::SetViewLineEnding( int index
, EOL ending
)
5064 m_pState
->linesEOL
[index
] = m_pViewData
->GetLineEnding(index
);
5065 m_pViewData
->SetLineEnding(index
, ending
);
5068 void CBaseView::SetViewMarked( int index
, bool marked
)
5070 m_pState
->markedlines
[index
] = m_pViewData
->GetMarked(index
);
5071 m_pViewData
->SetMarked(index
, marked
);
5075 BOOL
CBaseView::GetViewSelection( int& start
, int& end
) const
5079 start
= m_nSelViewBlockStart
;
5080 end
= m_nSelViewBlockEnd
;
5086 int CBaseView::Screen2View::GetViewLineForScreen( int screenLine
)
5088 RebuildIfNecessary();
5089 if ((size() <= screenLine
) || (screenLine
< 0))
5091 return m_Screen2View
[screenLine
].nViewLine
;
5094 int CBaseView::Screen2View::size()
5096 RebuildIfNecessary();
5097 return (int)m_Screen2View
.size();
5100 int CBaseView::Screen2View::GetSubLineOffset( int screenLine
)
5102 RebuildIfNecessary();
5103 if (size() <= screenLine
)
5105 return m_Screen2View
[screenLine
].nViewSubLine
;
5108 CBaseView::TScreenLineInfo
CBaseView::Screen2View::GetScreenLineInfo( int screenLine
)
5110 RebuildIfNecessary();
5111 return m_Screen2View
[screenLine
];
5115 doing partial rebuild, whole screen2view vector is built, but uses ScreenedViewLine cache to do it faster
5117 void CBaseView::Screen2View::RebuildIfNecessary()
5120 return; // rebuild not necessary
5122 FixScreenedCacheSize(m_pwndLeft
);
5123 FixScreenedCacheSize(m_pwndRight
);
5124 FixScreenedCacheSize(m_pwndBottom
);
5127 for (auto it
= m_RebuildRanges
.cbegin(); it
!= m_RebuildRanges
.cend(); ++it
)
5129 ResetScreenedViewLineCache(m_pwndLeft
, *it
);
5130 ResetScreenedViewLineCache(m_pwndRight
, *it
);
5131 ResetScreenedViewLineCache(m_pwndBottom
, *it
);
5136 ResetScreenedViewLineCache(m_pwndLeft
);
5137 ResetScreenedViewLineCache(m_pwndRight
);
5138 ResetScreenedViewLineCache(m_pwndBottom
);
5140 m_RebuildRanges
.clear();
5143 size_t OldSize
= m_Screen2View
.size();
5144 m_Screen2View
.clear();
5145 m_Screen2View
.reserve(OldSize
); // guess same size
5146 for (int i
= 0; i
< m_pViewData
->GetCount(); ++i
)
5148 if (m_pMainFrame
->m_bCollapsed
)
5150 while ((i
< m_pViewData
->GetCount())&&(m_pViewData
->GetHideState(i
) == HIDESTATE_HIDDEN
))
5152 if (!(i
< m_pViewData
->GetCount()))
5155 TScreenLineInfo oLineInfo
;
5156 oLineInfo
.nViewLine
= i
;
5157 oLineInfo
.nViewSubLine
= -1; // no wrap
5158 if (m_pMainFrame
->m_bWrapLines
&& !IsViewLineHidden(m_pViewData
, i
))
5161 if (IsLeftViewGood())
5162 nMaxLines
= std::max
<int>(nMaxLines
, m_pwndLeft
->CountMultiLines(i
));
5163 if (IsRightViewGood())
5164 nMaxLines
= std::max
<int>(nMaxLines
, m_pwndRight
->CountMultiLines(i
));
5165 if (IsBottomViewGood())
5166 nMaxLines
= std::max
<int>(nMaxLines
, m_pwndBottom
->CountMultiLines(i
));
5167 for (int l
= 0; l
< (nMaxLines
-1); ++l
)
5169 oLineInfo
.nViewSubLine
++;
5170 m_Screen2View
.push_back(oLineInfo
);
5172 oLineInfo
.nViewSubLine
++;
5174 m_Screen2View
.push_back(oLineInfo
);
5178 if (IsLeftViewGood())
5179 m_pwndLeft
->BuildMarkedWordArray();
5180 if (IsRightViewGood())
5181 m_pwndRight
->BuildMarkedWordArray();
5182 if (IsBottomViewGood())
5183 m_pwndBottom
->BuildMarkedWordArray();
5185 RecalcAllVertScrollBars();
5186 RecalcAllHorzScrollBars();
5189 int CBaseView::Screen2View::FindScreenLineForViewLine( int viewLine
)
5191 RebuildIfNecessary();
5193 int nScreenLineCount
= (int)m_Screen2View
.size();
5196 if (nScreenLineCount
>16)
5198 // for enough long data search for last screen
5199 // with viewline less than one we are looking for
5200 // use approximate method (based on) binary search using asymmetric start point
5201 // in form 2**n (determined as MSB of length) to go around division and rounding;
5202 // this effectively looks for bit values from MSB to LSB
5205 //GetMostSignificantBitValue
5206 // note _BitScanReverse(&nTestBit, nScreenLineCount); can be used instead
5207 nTestBit
= nScreenLineCount
;
5208 nTestBit
|= nTestBit
>>1;
5209 nTestBit
|= nTestBit
>>2;
5210 nTestBit
|= nTestBit
>>4;
5211 nTestBit
|= nTestBit
>>8;
5212 nTestBit
|= nTestBit
>>16;
5213 nTestBit
^= (nTestBit
>>1);
5217 int nTestPos
= nPos
| nTestBit
;
5218 if (nTestPos
< nScreenLineCount
&& m_Screen2View
[nTestPos
].nViewLine
< viewLine
)
5225 while (nPos
< nScreenLineCount
&& m_Screen2View
[nPos
].nViewLine
< viewLine
)
5233 void CBaseView::Screen2View::ScheduleFullRebuild(CViewData
* pViewData
) {
5236 m_pViewData
= pViewData
;
5239 void CBaseView::Screen2View::ScheduleRangeRebuild(CViewData
* pViewData
, int nFirstViewLine
, int nLastViewLine
)
5244 m_pViewData
= pViewData
;
5246 TRebuildRange Range
;
5247 Range
.FirstViewLine
=nFirstViewLine
;
5248 Range
.LastViewLine
=nLastViewLine
;
5249 m_RebuildRanges
.push_back(Range
);
5252 bool CBaseView::Screen2View::FixScreenedCacheSize(CBaseView
* pwndView
)
5254 if (!IsViewGood(pwndView
))
5258 const int nOldSize
= (int)pwndView
->m_ScreenedViewLine
.size();
5259 const int nViewCount
= std::max
<int>(pwndView
->GetViewCount(), 0);
5260 if (nOldSize
== nViewCount
)
5264 pwndView
->m_ScreenedViewLine
.resize(nViewCount
);
5268 bool CBaseView::Screen2View::ResetScreenedViewLineCache(CBaseView
* pwndView
) const
5270 if (!IsViewGood(pwndView
))
5274 TRebuildRange Range
={0, pwndView
->GetViewCount()-1};
5275 ResetScreenedViewLineCache(pwndView
, Range
);
5279 bool CBaseView::Screen2View::ResetScreenedViewLineCache(CBaseView
* pwndView
, const TRebuildRange
& Range
) const
5281 if (!IsViewGood(pwndView
))
5285 if (Range
.LastViewLine
== -1)
5289 ASSERT(Range
.FirstViewLine
>= 0);
5290 ASSERT(Range
.LastViewLine
< pwndView
->GetViewCount());
5291 for (int i
= Range
.FirstViewLine
; i
<= Range
.LastViewLine
; i
++)
5293 pwndView
->m_ScreenedViewLine
[i
].Clear();
5298 void CBaseView::WrapChanged()
5300 m_nMaxLineLength
= -1;
5304 void CBaseView::OnEditFind()
5310 if (this == m_pwndLeft
)
5312 if (this == m_pwndRight
)
5314 if (this == m_pwndBottom
)
5317 m_pFindDialog
= new CFindDlg(this);
5318 m_pFindDialog
->Create(this, id
);
5320 m_pFindDialog
->SetFindString(HasTextSelection() ? GetSelectedText() : L
"");
5321 m_pFindDialog
->SetReadonly(m_bReadonly
);
5324 LRESULT
CBaseView::OnFindDialogMessage(WPARAM wParam
, LPARAM
/*lParam*/)
5326 ASSERT(m_pFindDialog
!= NULL
);
5328 if (m_pFindDialog
->IsTerminating())
5330 // invalidate the handle identifying the dialog box.
5331 m_pFindDialog
= NULL
;
5335 if(m_pFindDialog
->FindNext())
5337 //read data from dialog
5338 m_sFindText
= m_pFindDialog
->GetFindString();
5339 m_bMatchCase
= (m_pFindDialog
->MatchCase() == TRUE
);
5340 m_bLimitToDiff
= m_pFindDialog
->LimitToDiffs();
5341 m_bWholeWord
= m_pFindDialog
->WholeWord();
5344 m_sFindText
= m_sFindText
.MakeLower();
5346 BuildFindStringArray();
5347 if ((CFindDlg::FindType
)wParam
== CFindDlg::FindType::Find
)
5349 if (m_pFindDialog
->SearchUp())
5354 else if ((CFindDlg::FindType
)wParam
== CFindDlg::FindType::Count
)
5357 for (size_t i
= 0; i
< m_arFindStringLines
.size(); ++i
)
5358 count
+= m_arFindStringLines
[i
];
5360 format
.LoadString(IDS_FIND_COUNT
);
5362 matches
.Format(format
, count
);
5363 m_pFindDialog
->SetStatusText(matches
);
5365 else if ((CFindDlg::FindType
)wParam
== CFindDlg::FindType::Replace
)
5369 bool bFound
= false;
5370 if (m_pFindDialog
->SearchUp())
5371 bFound
= Search(SearchPrevious
, true, true, false);
5373 bFound
= Search(SearchNext
, true, true, false);
5376 CString sReplaceText
= m_pFindDialog
->GetReplaceString();
5377 CUndo::GetInstance().BeginGrouping();
5378 RemoveSelectedText();
5379 InsertText(sReplaceText
);
5380 CUndo::GetInstance().EndGrouping();
5384 else if ((CFindDlg::FindType
)wParam
== CFindDlg::FindType::ReplaceAll
)
5388 bool bFound
= false;
5389 int replaceCount
= 0;
5390 POINT lastPoint
= m_ptSelectionViewPosStart
;
5391 m_ptSelectionViewPosStart
.x
= m_ptSelectionViewPosStart
.y
= 0;
5392 CUndo::GetInstance().BeginGrouping();
5395 bFound
= Search(SearchNext
, true, false, true);
5398 CString sReplaceText
= m_pFindDialog
->GetReplaceString();
5399 RemoveSelectedText();
5400 InsertText(sReplaceText
);
5404 CUndo::GetInstance().EndGrouping();
5405 if (replaceCount
== 0)
5406 m_ptSelectionViewPosStart
= lastPoint
;
5408 message
.Format(IDS_FIND_REPLACED
, replaceCount
);
5410 m_pFindDialog
->SetStatusText(message
, RGB(0, 0, 0));
5418 void CBaseView::OnEditFindnextStart()
5420 if (m_pViewData
== nullptr)
5422 if (HasTextSelection())
5424 m_sFindText
= GetSelectedText();
5425 m_bMatchCase
= false;
5426 m_bLimitToDiff
= false;
5427 m_bWholeWord
= false;
5428 m_sFindText
= m_sFindText
.MakeLower();
5430 BuildFindStringArray();
5435 m_sFindText
.Empty();
5436 BuildFindStringArray();
5440 void CBaseView::OnEditFindprevStart()
5442 if (m_pViewData
== nullptr)
5444 if (HasTextSelection())
5446 m_sFindText
= GetSelectedText();
5447 m_bMatchCase
= false;
5448 m_bLimitToDiff
= false;
5449 m_bWholeWord
= false;
5450 m_sFindText
= m_sFindText
.MakeLower();
5452 BuildFindStringArray();
5457 m_sFindText
.Empty();
5458 BuildFindStringArray();
5462 bool CBaseView::StringFound(const CString
& str
, SearchDirection srchDir
, int& start
, int& end
) const
5464 if (srchDir
== SearchPrevious
)
5467 int laststart2
= -1;
5470 laststart2
= laststart
;
5471 laststart
= str
.Find(m_sFindText
, laststart
+ 1);
5472 } while (laststart
>= 0 && laststart
< start
);
5476 start
= str
.Find(m_sFindText
, start
);
5477 end
= start
+ m_sFindText
.GetLength();
5478 bool bStringFound
= (start
>= 0);
5479 if (bStringFound
&& m_bWholeWord
)
5482 bStringFound
= IsWordSeparator(str
.Mid(start
-1,1).GetAt(0));
5486 if (str
.GetLength() > end
)
5487 bStringFound
= IsWordSeparator(str
.Mid(end
, 1).GetAt(0));
5490 return bStringFound
;
5493 void CBaseView::OnEditFindprev()
5495 Search(SearchPrevious
, false, true, false);
5498 void CBaseView::OnEditFindnext()
5500 Search(SearchNext
, false, true, false);
5503 bool CBaseView::Search(SearchDirection srchDir
, bool useStart
, bool flashIfNotFound
, bool stopEof
)
5505 if (m_sFindText
.IsEmpty())
5510 POINT start
= useStart
? m_ptSelectionViewPosStart
: m_ptSelectionViewPosEnd
;
5512 end
.y
= m_pViewData
->GetCount()-1;
5516 if (srchDir
==SearchNext
)
5517 end
.x
= GetViewLineLength(end
.y
);
5520 end
.x
= m_ptSelectionViewPosStart
.x
;
5524 if (!HasTextSelection())
5526 start
.y
= m_ptCaretViewPos
.y
;
5527 if (srchDir
==SearchNext
)
5528 start
.x
= m_ptCaretViewPos
.x
;
5532 end
.x
= m_ptCaretViewPos
.x
;
5535 CString sSelectedText
;
5537 for (int nViewLine
=start
.y
; ;srchDir
==SearchNext
? nViewLine
++ : nViewLine
--)
5543 nViewLine
= m_pViewData
->GetCount()-1;
5544 startline
= start
.y
;
5545 if (flashIfNotFound
)
5548 m_pFindDialog
->SetStatusText(CString(MAKEINTRESOURCE(IDS_FIND_TOPREACHED
)), RGB(63, 127, 47));
5549 m_pMainFrame
->FlashWindowEx(FLASHW_ALL
, 2, 100);
5552 if (nViewLine
> end
.y
)
5557 startline
= start
.y
;
5558 if (flashIfNotFound
)
5561 m_pFindDialog
->SetStatusText(CString(MAKEINTRESOURCE(IDS_FIND_BOTTOMREACHED
)), RGB(63, 127, 47));
5562 m_pMainFrame
->FlashWindowEx(FLASHW_ALL
, 2, 100);
5565 switch (m_pViewData
->GetState(nViewLine
))
5567 case DIFFSTATE_EMPTY
:
5569 case DIFFSTATE_UNKNOWN
:
5570 case DIFFSTATE_NORMAL
:
5573 case DIFFSTATE_REMOVED
:
5574 case DIFFSTATE_REMOVEDWHITESPACE
:
5575 case DIFFSTATE_ADDED
:
5576 case DIFFSTATE_ADDEDWHITESPACE
:
5577 case DIFFSTATE_WHITESPACE
:
5578 case DIFFSTATE_WHITESPACE_DIFF
:
5579 case DIFFSTATE_CONFLICTED
:
5580 case DIFFSTATE_CONFLICTED_IGNORED
:
5581 case DIFFSTATE_CONFLICTADDED
:
5582 case DIFFSTATE_CONFLICTEMPTY
:
5583 case DIFFSTATE_CONFLICTRESOLVED
:
5584 case DIFFSTATE_IDENTICALREMOVED
:
5585 case DIFFSTATE_IDENTICALADDED
:
5586 case DIFFSTATE_THEIRSREMOVED
:
5587 case DIFFSTATE_THEIRSADDED
:
5588 case DIFFSTATE_YOURSREMOVED
:
5589 case DIFFSTATE_YOURSADDED
:
5590 case DIFFSTATE_EDITED
:
5592 sSelectedText
= GetViewLineChars(nViewLine
);
5593 if (nViewLine
== start
.y
&& startline
< 0)
5594 sSelectedText
= srchDir
== SearchNext
? sSelectedText
.Mid(start
.x
) : sSelectedText
.Left(end
.x
);
5596 sSelectedText
= sSelectedText
.MakeLower();
5597 int startfound
= srchDir
== SearchNext
? 0 : sSelectedText
.GetLength();
5599 if (StringFound(sSelectedText
, srchDir
, startfound
, endfound
))
5601 HighlightViewLines(nViewLine
, nViewLine
);
5602 m_ptSelectionViewPosStart
.x
= startfound
;
5603 m_ptSelectionViewPosEnd
.x
= endfound
;
5604 if (nViewLine
== start
.y
&& startline
< 0)
5606 m_ptSelectionViewPosStart
.x
+= start
.x
;
5607 m_ptSelectionViewPosEnd
.x
+= start
.x
;
5609 m_ptSelectionViewPosEnd
.x
= m_ptSelectionViewPosStart
.x
+ m_sFindText
.GetLength();
5610 m_ptSelectionViewPosStart
.y
= nViewLine
;
5611 m_ptSelectionViewPosEnd
.y
= nViewLine
;
5612 m_ptCaretViewPos
= m_ptSelectionViewPosStart
;
5613 UpdateViewsCaretPosition();
5614 EnsureCaretVisible();
5624 if (nViewLine
== startline
)
5626 if (flashIfNotFound
)
5629 message
.Format(IDS_FIND_NOTFOUND
, m_sFindText
);
5631 m_pFindDialog
->SetStatusText(message
, RGB(255, 0, 0));
5632 ::MessageBeep(0xFFFFFFFF);
5633 m_pMainFrame
->FlashWindowEx(FLASHW_ALL
, 3, 100);
5639 m_pMainFrame
->m_nMoveMovesToIgnore
= MOVESTOIGNORE
;
5643 CString
CBaseView::GetSelectedText() const
5645 CString sSelectedText
;
5646 POINT start
= m_ptSelectionViewPosStart
;
5647 POINT end
= m_ptSelectionViewPosEnd
;
5648 if (!HasTextSelection())
5650 if (!HasSelection())
5651 return sSelectedText
;
5652 start
.y
= m_nSelViewBlockStart
;
5654 end
.y
= m_nSelViewBlockEnd
;
5655 end
.x
= GetViewLineLength(m_nSelViewBlockEnd
);
5657 if (m_pViewData
== nullptr)
5658 return sSelectedText
;
5659 // first store the selected lines in one CString
5660 for (int nViewLine
=start
.y
; nViewLine
<=end
.y
; nViewLine
++)
5662 switch (m_pViewData
->GetState(nViewLine
))
5664 case DIFFSTATE_EMPTY
:
5666 case DIFFSTATE_UNKNOWN
:
5667 case DIFFSTATE_NORMAL
:
5668 case DIFFSTATE_REMOVED
:
5669 case DIFFSTATE_REMOVEDWHITESPACE
:
5670 case DIFFSTATE_ADDED
:
5671 case DIFFSTATE_ADDEDWHITESPACE
:
5672 case DIFFSTATE_WHITESPACE
:
5673 case DIFFSTATE_WHITESPACE_DIFF
:
5674 case DIFFSTATE_CONFLICTED
:
5675 case DIFFSTATE_CONFLICTED_IGNORED
:
5676 case DIFFSTATE_CONFLICTADDED
:
5677 case DIFFSTATE_CONFLICTEMPTY
:
5678 case DIFFSTATE_CONFLICTRESOLVED
:
5679 case DIFFSTATE_IDENTICALREMOVED
:
5680 case DIFFSTATE_IDENTICALADDED
:
5681 case DIFFSTATE_THEIRSREMOVED
:
5682 case DIFFSTATE_THEIRSADDED
:
5683 case DIFFSTATE_YOURSREMOVED
:
5684 case DIFFSTATE_YOURSADDED
:
5685 case DIFFSTATE_EDITED
:
5686 sSelectedText
+= GetViewLineChars(nViewLine
);
5687 sSelectedText
+= _T("\r\n");
5691 // remove the non-selected chars from the first line, last line and last \r\n
5692 int nLeftCut
= start
.x
;
5693 int nRightCut
= GetViewLineChars(end
.y
).GetLength() - end
.x
+ 2;
5694 sSelectedText
= sSelectedText
.Mid(nLeftCut
, sSelectedText
.GetLength()-nLeftCut
-nRightCut
);
5695 return sSelectedText
;
5698 void CBaseView::CheckModifications(bool& hasMods
, bool& hasConflicts
, bool& hasWhitespaceMods
)
5701 hasConflicts
= false;
5702 hasWhitespaceMods
= false;
5706 for (int i
=0; i
<m_pViewData
->GetCount(); i
++)
5708 DiffStates state
= m_pViewData
->GetState(i
);
5711 case DIFFSTATE_ADDED
:
5712 case DIFFSTATE_IDENTICALADDED
:
5713 case DIFFSTATE_THEIRSADDED
:
5714 case DIFFSTATE_YOURSADDED
:
5715 case DIFFSTATE_CONFLICTADDED
:
5716 case DIFFSTATE_IDENTICALREMOVED
:
5717 case DIFFSTATE_REMOVED
:
5718 case DIFFSTATE_THEIRSREMOVED
:
5719 case DIFFSTATE_YOURSREMOVED
:
5720 case DIFFSTATE_EMPTY
:
5723 case DIFFSTATE_CONFLICTED
:
5724 case DIFFSTATE_CONFLICTED_IGNORED
:
5725 hasConflicts
= true;
5727 case DIFFSTATE_REMOVEDWHITESPACE
:
5728 case DIFFSTATE_ADDEDWHITESPACE
:
5729 case DIFFSTATE_WHITESPACE
:
5730 case DIFFSTATE_WHITESPACE_DIFF
:
5731 hasWhitespaceMods
= true;
5738 void CBaseView::OnEditGotoline()
5740 if (m_pViewData
== NULL
)
5742 // find the last and first line number
5743 int nViewLineCount
= m_pViewData
->GetCount();
5745 int nLastLineNumber
= DIFF_EMPTYLINENUMBER
;
5746 for (int nViewLine
=nViewLineCount
-1; nViewLine
>=0; --nViewLine
)
5748 nLastLineNumber
= m_pViewData
->GetLineNumber(nViewLine
);
5749 if (nLastLineNumber
!=DIFF_EMPTYLINENUMBER
)
5754 if (nLastLineNumber
==DIFF_EMPTYLINENUMBER
|| nLastLineNumber
==0) // not numbered line foud or last one is first
5759 int nFirstLineNumber
=1; // first is always 1
5762 sText
.Format(IDS_GOTOLINE
, nFirstLineNumber
, nLastLineNumber
);
5764 CGotoLineDlg
dlg(this);
5765 dlg
.SetLabel(sText
);
5766 dlg
.SetLimits(nFirstLineNumber
, nLastLineNumber
);
5767 if (dlg
.DoModal() == IDOK
)
5769 for (int nViewLine
= 0; nViewLine
< nViewLineCount
; ++nViewLine
)
5771 if ((m_pViewData
->GetLineNumber(nViewLine
)+1) == dlg
.GetLineNumber())
5773 HighlightViewLines(nViewLine
, nViewLine
);
5780 void CBaseView::OnToggleReadonly()
5782 if (IsReadonlyChangable()) {
5783 SetWritable(IsReadonly());
5787 int CBaseView::SaveFile(int nFlags
)
5790 if (m_pViewData
!=NULL
&& m_pWorkingFile
!=NULL
)
5792 CFileTextLines file
;
5793 m_SaveParams
.m_LineEndings
= m_lineendings
;
5794 m_SaveParams
.m_UnicodeType
= m_texttype
;
5795 file
.SetSaveParams(m_SaveParams
);
5797 for (int i
=0; i
<m_pViewData
->GetCount(); i
++)
5799 //only copy non-removed lines
5800 DiffStates state
= m_pViewData
->GetState(i
);
5803 case DIFFSTATE_CONFLICTED
:
5804 case DIFFSTATE_CONFLICTED_IGNORED
:
5811 } while((last
<m_pViewData
->GetCount()) && ((m_pViewData
->GetState(last
)==DIFFSTATE_CONFLICTED
)||(m_pViewData
->GetState(last
)==DIFFSTATE_CONFLICTED_IGNORED
)));
5812 file
.Add(_T("<<<<<<< .mine"), EOL_NOENDING
);
5813 for (int j
=first
; j
<last
; j
++)
5815 file
.Add(m_pwndRight
->m_pViewData
->GetLine(j
), m_pwndRight
->m_pViewData
->GetLineEnding(j
));
5817 file
.Add(_T("======="), EOL_NOENDING
);
5818 for (int j
=first
; j
<last
; j
++)
5820 file
.Add(m_pwndLeft
->m_pViewData
->GetLine(j
), m_pwndLeft
->m_pViewData
->GetLineEnding(j
));
5822 file
.Add(_T(">>>>>>> .theirs"), EOL_NOENDING
);
5826 case DIFFSTATE_EMPTY
:
5828 case DIFFSTATE_CONFLICTEMPTY
:
5829 case DIFFSTATE_IDENTICALREMOVED
:
5830 case DIFFSTATE_REMOVED
:
5831 case DIFFSTATE_THEIRSREMOVED
:
5832 case DIFFSTATE_YOURSREMOVED
:
5833 case DIFFSTATE_CONFLICTRESOLVEDEMPTY
:
5834 if ((nFlags
&SAVE_REMOVEDLINES
) == 0)
5836 // do not save removed lines
5840 file
.Add(m_pViewData
->GetLine(i
), m_pViewData
->GetLineEnding(i
));
5844 CString filename
= m_pWorkingFile
->GetFilename();
5845 if (m_pWorkingFile
->IsReadonly())
5846 if (!CCommonAppUtils::FileOpenSave(filename
, NULL
, IDS_SAVEASTITLE
, IDS_COMMONFILEFILTER
, false, m_hWnd
))
5848 if (!file
.Save(filename
))
5850 ::MessageBox(m_hWnd
, file
.GetErrorString(), _T("TortoiseGitMerge"), MB_ICONERROR
);
5853 m_pWorkingFile
->SetFileName(filename
);
5854 m_pWorkingFile
->StoreFileAttributes();
5855 // m_dlgFilePatches.SetFileStatusAsPatched(sFilePath);
5857 CUndo::GetInstance().MarkAsOriginalState(
5859 this == m_pwndRight
,
5860 this == m_pwndBottom
);
5861 if (file
.GetCount() == 1 && file
.GetAt(0).IsEmpty() && file
.GetLineEnding(0) == EOL_NOENDING
)
5863 return file
.GetCount();
5869 int CBaseView::SaveFileTo(CString sFileName
, int nFlags
)
5873 m_pWorkingFile
->SetFileName(sFileName
);
5874 return SaveFile(nFlags
);
5880 EOL
CBaseView::GetLineEndings()
5882 return GetLineEndings(GetWhitecharsProperties().HasMixedEols
);
5885 EOL
CBaseView::GetLineEndings(bool bHasMixedEols
)
5889 return EOL_AUTOLINE
; // mixed eols - hack value
5891 if (m_lineendings
== EOL_AUTOLINE
)
5895 return m_lineendings
;
5898 void CBaseView::ReplaceLineEndings(EOL eEol
)
5900 if (eEol
== EOL_AUTOLINE
)
5905 m_lineendings
= eEol
;
5906 // replace all set EOLs
5907 // TODO store line endings and lineendings in undo
5908 //CUndo::BeginGrouping();
5909 for (int i
= 0; i
< GetViewCount(); ++i
)
5915 EOL eLineEol
= GetViewLineEnding(i
);
5916 if (eLineEol
== EOL_AUTOLINE
|| eLineEol
== EOL_NOENDING
|| eLineEol
== m_lineendings
)
5920 SetViewLineEnding(i
, eEol
);
5922 //CUndo::EndGrouping();
5923 //CUndo::saveundostep;
5928 void CBaseView::SetLineEndingStyle(EOL eEol
)
5930 m_lineendings
= eEol
;
5933 void CBaseView::SetTextType(CFileTextLines::UnicodeType eTextType
)
5935 if (m_texttype
== eTextType
)
5939 m_texttype
= eTextType
;
5944 void CBaseView::AskUserForNewLineEndingsAndTextType(int nTextId
)
5947 return; // nothing to be changed in read-only view
5949 dlg
.view
.LoadString(nTextId
);
5950 dlg
.texttype
= m_texttype
;
5951 dlg
.lineendings
= GetLineEndings();
5952 if (dlg
.DoModal() != IDOK
)
5954 SetTextType(dlg
.texttype
);
5955 ReplaceLineEndings(dlg
.lineendings
);
5959 Replaces lines from source view to this
5961 void CBaseView::UseViewBlock(CBaseView
* pwndView
, int nFirstViewLine
, int nLastViewLine
, std::function
<bool(int)> fnSkip
)
5963 if (!IsViewGood(pwndView
))
5967 CUndo::GetInstance().BeginGrouping();
5969 for (int viewLine
= nFirstViewLine
; viewLine
<= nLastViewLine
; viewLine
++)
5971 bool skip
= fnSkip(viewLine
);
5974 if (GetViewMarked(viewLine
))
5975 SetViewMarked(viewLine
, false);
5978 viewdata line
= pwndView
->GetViewData(viewLine
);
5979 if (line
.ending
!= EOL_NOENDING
)
5980 line
.ending
= m_lineendings
;
5983 case DIFFSTATE_CONFLICTEMPTY
:
5984 case DIFFSTATE_UNKNOWN
:
5985 line
.state
= DIFFSTATE_EMPTY
;
5986 case DIFFSTATE_EMPTY
:
5988 case DIFFSTATE_ADDED
:
5989 case DIFFSTATE_CONFLICTADDED
:
5990 case DIFFSTATE_CONFLICTED
:
5991 case DIFFSTATE_CONFLICTED_IGNORED
:
5992 case DIFFSTATE_IDENTICALADDED
:
5993 case DIFFSTATE_THEIRSADDED
:
5994 case DIFFSTATE_YOURSADDED
:
5995 case DIFFSTATE_IDENTICALREMOVED
:
5996 case DIFFSTATE_REMOVED
:
5997 case DIFFSTATE_THEIRSREMOVED
:
5998 case DIFFSTATE_YOURSREMOVED
:
5999 pwndView
->SetViewState(viewLine
, DIFFSTATE_NORMAL
);
6000 line
.state
= DIFFSTATE_NORMAL
;
6001 case DIFFSTATE_NORMAL
:
6006 bool marked
= GetViewMarked(viewLine
);
6007 SetViewData(viewLine
, line
);
6009 SetViewMarked(viewLine
, false);
6010 if ((m_texttype
== UnicodeType::ASCII
) && (pwndView
->GetTextType() != UnicodeType::ASCII
))
6012 // if this view is in ASCII and the other is not, we have to make sure that
6013 // the text we copy from the other view can actually be saved in ASCII encoding.
6014 // if not, we have to change this views encoding to the same encoding as the other view
6015 BOOL useDefault
= FALSE
;
6016 WideCharToMultiByte(CP_ACP
, WC_NO_BEST_FIT_CHARS
, line
.sLine
, -1, NULL
, 0, 0, &useDefault
);
6017 if (useDefault
) // a default char is required, so the char can not be saved as ASCII
6018 SetTextType(pwndView
->GetTextType());
6021 // normal lines is mostly same but may differ in EOL so any copied line change view state to modified
6022 // TODO: check if copied line is same as original one set modified only when differ
6026 int nRemovedLines
= CleanEmptyLines();
6029 // make sure all non empty line have EOL set but last
6030 // wrong can be last copied line(have eol, but no line under),
6031 // or old last line (line before copied block missing eol, but have line under)
6032 // we'll check all lines to be sure
6033 int nLine
= GetViewCount();
6034 // check last line have no EOL set
6037 if (!IsViewLineEmpty(nLine
))
6039 if (GetViewLineEnding(nLine
) != EOL_NOENDING
)
6041 // we added non last line into empty block on the end (or should we remove eol from this one ?)
6042 // so next line is empty
6043 ASSERT(IsViewLineEmpty(nLine
+1));
6044 // and we can turn it to normal empty line
6045 SetViewData(nLine
+1, viewdata(CString(), DIFFSTATE_ADDED
, 1, EOL_NOENDING
, HIDESTATE_SHOWN
));
6050 // check all (nonlast) line have EOL set
6053 if (!IsViewLineEmpty(nLine
))
6055 if (GetViewLineEnding(nLine
) == EOL_NOENDING
)
6057 SetViewLineEnding(nLine
, m_lineendings
);
6058 // in theory there should be only one line needing fix, but most of time we get over all anyway
6064 UpdateViewLineNumbers();
6067 CUndo::GetInstance().EndGrouping();
6069 if (nRemovedLines
!=0)
6071 // some lines are gone update selection
6073 SetupAllViewSelection(nFirstViewLine
, nLastViewLine
- nRemovedLines
);
6075 BuildAllScreen2ViewVector();
6076 pwndView
->Invalidate();
6080 void CBaseView::MarkBlock(bool marked
, int nFirstViewLine
, int nLastViewLine
)
6084 CUndo::GetInstance().BeginGrouping();
6086 for (int viewLine
= nFirstViewLine
; viewLine
<= nLastViewLine
; viewLine
++)
6087 SetViewMarked(viewLine
, marked
);
6091 CUndo::GetInstance().EndGrouping();
6093 BuildAllScreen2ViewVector();
6098 void CBaseView::LeaveOnlyMarkedBlocks(CBaseView
*pwndView
)
6100 auto fn
= [this](int viewLine
) -> bool { return GetViewMarked(viewLine
) || GetViewState(viewLine
) == DIFFSTATE_EDITED
; };
6101 UseViewBlock(pwndView
, 0, GetViewCount() - 1, fn
);
6104 void CBaseView::UseViewFileOfMarked(CBaseView
*pwndView
)
6106 auto fn
= [this](int viewLine
) -> bool { return !GetViewMarked(viewLine
) || GetViewState(viewLine
) == DIFFSTATE_EDITED
; };
6107 UseViewBlock(pwndView
, 0, GetViewCount() - 1, fn
);
6110 void CBaseView::UseViewFileExceptEdited(CBaseView
*pwndView
)
6112 auto fn
= [this](int viewLine
) -> bool { return GetViewState(viewLine
) == DIFFSTATE_EDITED
; };
6113 UseViewBlock(pwndView
, 0, GetViewCount() - 1, fn
);
6116 int CBaseView::GetIndentCharsForLine(int x
, int y
)
6118 const int maxGuessLine
= 100;
6120 CString line
= GetViewLine(y
);
6121 if (m_nTabMode
& TABMODE_SMARTINDENT
)
6123 // detect left char and right char
6124 TCHAR lc
= x
> 0 ? line
[x
- 1] : '\0';
6125 TCHAR rc
= x
< line
.GetLength() ? line
[x
] : '\0';
6126 if (lc
== ' ' && rc
!= '\t' || rc
== ' ' && lc
!= '\t')
6128 if (lc
== '\t' && rc
!= ' ' || rc
== '\t' && lc
!= ' ')
6130 if (lc
== ' ' && rc
== '\t' || rc
== ' ' && lc
== '\t')
6131 nTabMode
= m_nTabMode
& TABMODE_USESPACES
;
6133 // detect lines nearby
6134 for (int i
= y
- 1, j
= y
+ 1; nTabMode
== -1; --i
, ++j
)
6136 bool above
= i
> 0 && i
>= y
- maxGuessLine
;
6137 bool below
= j
< GetViewCount() && j
<= y
+ maxGuessLine
;
6138 if (!(above
|| below
))
6140 TCHAR ac
= above
? GetViewLine(i
)[0] : '\0';
6141 TCHAR bc
= below
? GetViewLine(j
)[0] : '\0';
6142 if (ac
== ' ' && bc
!= '\t' || bc
== ' ' && ac
!= '\t')
6144 else if (ac
== '\t' && bc
!= ' ' || bc
== '\t' && ac
!= ' ')
6146 else if (ac
== ' ' && bc
== '\t' || bc
== ' ' && ac
== '\t')
6147 nTabMode
= m_nTabMode
& TABMODE_USESPACES
;
6151 nTabMode
= m_nTabMode
& TABMODE_USESPACES
;
6156 x
= CountExpandedChars(line
, x
);
6157 return (m_nTabSize
- (x
% m_nTabSize
));
6164 void CBaseView::AddIndentationForSelectedBlock()
6166 bool bModified
= false;
6167 for (int nViewLine
= m_ptSelectionViewPosStart
.y
; nViewLine
<= m_ptSelectionViewPosEnd
.y
; nViewLine
++)
6169 // skip the line if no character is selected in the last selected line
6170 if (nViewLine
== m_ptSelectionViewPosEnd
.y
&& m_ptSelectionViewPosEnd
.x
== 0)
6175 if (IsLineEmpty(nViewLine
))
6179 const CString
&sLine
= GetViewLine(nViewLine
);
6180 CString sTemp
= sLine
;
6181 if (sTemp
.Trim().IsEmpty())
6183 // skip empty and whitechar only lines
6186 // add tab to line start (alternatively m_nTabSize spaces can be used)
6188 int indentChars
= GetIndentCharsForLine(0, nViewLine
);
6189 tabStr
= indentChars
> 0 ? CString(_T(' '), indentChars
) : _T("\t");
6190 SetViewLine(nViewLine
, tabStr
+ sLine
);
6197 BuildAllScreen2ViewVector();
6201 void CBaseView::RemoveIndentationForSelectedBlock()
6203 bool bModified
= false;
6204 for (int nViewLine
= m_ptSelectionViewPosStart
.y
; nViewLine
<= m_ptSelectionViewPosEnd
.y
; nViewLine
++)
6206 // skip the line if no character is selected in the last selected line
6207 if (nViewLine
== m_ptSelectionViewPosEnd
.y
&& m_ptSelectionViewPosEnd
.x
== 0)
6212 if (IsLineEmpty(nViewLine
))
6216 CString sLine
= GetViewLine(nViewLine
);
6217 // remove up to n spaces from line start
6218 // and one tab (if less then n spaces was removed)
6220 while (nPos
<m_nTabSize
)
6222 switch (sLine
[nPos
])
6234 sLine
.Delete(0, nPos
);
6235 SetViewLine(nViewLine
, sLine
);
6243 BuildAllScreen2ViewVector();
6248 there are two possible versions
6249 - convert tabs to spaces only in front of text (implemented)
6250 - convert all tabs to spaces
6252 void CBaseView::ConvertTabToSpaces()
6254 bool bModified
= false;
6255 for (int nViewLine
= 0; nViewLine
< GetViewCount(); nViewLine
++)
6257 if (IsLineEmpty(nViewLine
))
6261 const CString
&sLine
= GetViewLine(nViewLine
);
6262 bool bTabToConvertFound
= false;
6265 while (nPosIn
<sLine
.GetLength())
6267 switch (sLine
[nPosIn
])
6275 bTabToConvertFound
= true;
6276 nPosOut
= (nPosOut
+m_nTabSize
) - nPosOut
%m_nTabSize
;
6281 if (bTabToConvertFound
)
6283 CString sLineNew
= sLine
;
6284 sLineNew
.Delete(0, nPosIn
);
6285 sLineNew
= CString(' ', nPosOut
) + sLineNew
;
6286 SetViewLine(nViewLine
, sLineNew
);
6294 BuildAllScreen2ViewVector();
6299 there are two possible version
6300 - convert spaces to tabs only in front of text (implemented)
6301 - convert all spaces to tabs
6303 void CBaseView::Tabularize()
6305 bool bModified
= false;
6306 for (int nViewLine
= 0; nViewLine
< GetViewCount(); nViewLine
++)
6308 if (IsLineEmpty(nViewLine
))
6312 const CString
&sLine
= GetViewLine(nViewLine
);
6314 int nTabCount
= 0; // total tabs to be used
6315 int nSpaceCount
= 0; // number of spaces in tab size run
6317 while (nPos
<sLine
.GetLength())
6319 switch (sLine
[nPos
++])
6323 if (++nSpaceCount
< m_nTabSize
)
6337 CString sLineNew
= sLine
;
6338 sLineNew
.Delete(0, nDel
);
6339 sLineNew
= CString('\t', nTabCount
) + sLineNew
;
6340 if (sLine
!=sLineNew
)
6342 SetViewLine(nViewLine
, sLineNew
);
6351 BuildAllScreen2ViewVector();
6355 void CBaseView::RemoveTrailWhiteChars()
6357 bool bModified
= false;
6358 for (int nViewLine
= 0; nViewLine
< GetViewCount(); nViewLine
++)
6360 if (IsLineEmpty(nViewLine
))
6364 const CString
&sLine
= GetViewLine(nViewLine
);
6365 CString sLineNew
= sLine
;
6366 sLineNew
.TrimRight();
6367 if (sLine
.GetLength()!=sLineNew
.GetLength())
6369 SetViewLine(nViewLine
, sLineNew
);
6377 BuildAllScreen2ViewVector();
6381 CBaseView::TWhitecharsProperties
CBaseView::GetWhitecharsProperties()
6383 if (GetViewCount()>10000)
6385 // 10k lines is enough to check
6386 TWhitecharsProperties oRet
= {true, true, true, true};
6389 TWhitecharsProperties oRet
= {};
6390 for (int nViewLine
= 0; nViewLine
< GetViewCount(); nViewLine
++)
6392 if (IsLineEmpty(nViewLine
))
6396 const CString
&sLine
= GetViewLine(nViewLine
);
6397 if (sLine
.IsEmpty())
6401 // check leading whites for convertible tabs and spaces
6403 int nSpaceCount
= 0; // number of spaces in tab size run
6404 while (nPos
<sLine
.GetLength() && (!oRet
.HasSpacesToConvert
|| !oRet
.HasTabsToConvert
))
6406 switch (sLine
[nPos
++])
6409 if (++nSpaceCount
>= m_nTabSize
)
6411 oRet
.HasSpacesToConvert
= true;
6415 oRet
.HasTabsToConvert
= true;
6418 oRet
.HasSpacesToConvert
= true;
6425 // check trailing whites for removable chars
6426 switch (sLine
[sLine
.GetLength()-1])
6430 oRet
.HasTrailWhiteChars
= true;
6434 EOL eLineEol
= GetViewLineEnding(nViewLine
);
6435 if (!oRet
.HasMixedEols
&& (eLineEol
!= m_lineendings
) && (eLineEol
!= EOL_AUTOLINE
) && (eLineEol
!= EOL_NOENDING
))
6437 oRet
.HasMixedEols
= true;
6443 void CBaseView::InsertText(const CString
& sText
)
6447 POINT ptCaretViewPos
= GetCaretViewPosition();
6448 int nLeft
= ptCaretViewPos
.x
;
6449 int nViewLine
= ptCaretViewPos
.y
;
6451 if ((nViewLine
== 0) && (GetViewCount() == 0))
6452 OnChar(VK_RETURN
, 0, 0);
6454 std::vector
<CString
> lines
;
6457 while ((nEolPos
= sText
.Find('\r', nEolPos
)) >= 0)
6459 CString sLine
= sText
.Mid(nStart
, nEolPos
- nStart
);
6460 lines
.push_back(sLine
);
6464 CString sLine
= sText
.Mid(nStart
);
6465 lines
.push_back(sLine
);
6467 int nLinesToPaste
= (int)lines
.size();
6468 if (nLinesToPaste
> 1)
6472 // We want to undo the multiline insertion in a single step.
6473 CUndo::GetInstance().BeginGrouping();
6475 sLine
= GetViewLineChars(nViewLine
);
6476 CString sLineLeft
= sLine
.Left(nLeft
);
6477 CString sLineRight
= sLine
.Right(sLine
.GetLength() - nLeft
);
6478 EOL eOriginalEnding
= GetViewLineEnding(nViewLine
);
6479 viewdata
newLine(L
"", DIFFSTATE_EDITED
, 1, m_lineendings
, HIDESTATE_SHOWN
);
6480 if (!lines
[0].IsEmpty() || !sLineRight
.IsEmpty() || (eOriginalEnding
!= m_lineendings
))
6482 newLine
.sLine
= sLineLeft
+ lines
[0];
6483 SetViewData(nViewLine
, newLine
);
6486 int nInsertLine
= nViewLine
;
6487 for (int i
= 1; i
< nLinesToPaste
- 1; i
++)
6489 newLine
.sLine
= lines
[i
];
6490 InsertViewData(++nInsertLine
, newLine
);
6492 newLine
.sLine
= lines
[nLinesToPaste
- 1] + sLineRight
;
6493 newLine
.ending
= eOriginalEnding
;
6494 InsertViewData(++nInsertLine
, newLine
);
6499 // adds new lines everywhere except me
6500 if (IsViewGood(m_pwndLeft
) && m_pwndLeft
!= this)
6502 m_pwndLeft
->InsertViewEmptyLines(nViewLine
+ 1, nLinesToPaste
- 1);
6504 if (IsViewGood(m_pwndRight
) && m_pwndRight
!= this)
6506 m_pwndRight
->InsertViewEmptyLines(nViewLine
+ 1, nLinesToPaste
- 1);
6508 if (IsViewGood(m_pwndBottom
) && m_pwndBottom
!= this)
6510 m_pwndBottom
->InsertViewEmptyLines(nViewLine
+ 1, nLinesToPaste
- 1);
6514 UpdateViewLineNumbers();
6515 CUndo::GetInstance().EndGrouping();
6517 ptCaretViewPos
= SetupPoint(lines
[nLinesToPaste
- 1].GetLength(), nInsertLine
);
6521 // single line text - just insert it
6522 sLine
= GetViewLineChars(nViewLine
);
6523 sLine
.Insert(nLeft
, sText
);
6524 ptCaretViewPos
= SetupPoint(nLeft
+ sText
.GetLength(), nViewLine
);
6525 SetViewLine(nViewLine
, sLine
);
6526 SetViewState(nViewLine
, DIFFSTATE_EDITED
);
6532 BuildAllScreen2ViewVector();
6533 UpdateCaretViewPosition(ptCaretViewPos
);