OSDN Git Service

Improve plugin system (#797) (6)
[winmerge-jp/winmerge-jp.git] / Src / MergeEditView.h
1 /////////////////////////////////////////////////////////////////////////////
2 //    WinMerge:  an interactive diff/merge utility
3 //    Copyright (C) 1997  Dean P. Grimm
4 //    SPDX-License-Identifier: GPL-2.0-or-later
5 /////////////////////////////////////////////////////////////////////////////
6 /** 
7  * @file  MergeEditView.h
8  *
9  * @brief Declaration file for CMergeEditView
10  *
11  */
12 #pragma once
13
14 /** 
15  * @brief Non-diff lines shown above diff when scrolling to it
16  */
17 const UINT CONTEXT_LINES_ABOVE = 5;
18
19 /** 
20  * @brief Non-diff lines shown below diff when scrolling to it
21  */
22 const UINT CONTEXT_LINES_BELOW = 3;
23
24
25 #define FLAG_RESCAN_WAITS_FOR_IDLE   1
26
27
28 /////////////////////////////////////////////////////////////////////////////
29 // CMergeEditView view
30 #include "edtlib.h"
31 #include "GhostTextView.h"
32 #include "OptionsDiffColors.h"
33 #include <map>
34 #include <vector>
35
36 class IMergeEditStatus;
37 class CLocationView;
38 class CMergeDoc;
39 struct DIFFRANGE;
40
41 /**
42 This class is the base class for WinMerge editor panels.
43 It hooks the painting of ghost lines (GetLineColors), the shared
44 scrollbar (OnUpdateSibling...).
45 It offers the UI interface commands to work with diffs 
46
47 @todo
48 If we keep GetLineColors here, we should clear DIFF flag here
49 and not in CGhostTextBuffer (when insertText/deleteText). 
50 Small problem... This class doesn't derives from CGhostTextBuffer... 
51 We could define a new class which derives from CGhostTextBuffer to clear the DIFF flag.
52 and calls a virtual function for additional things to do on the flag.
53 Maybe in the future...
54 */
55 class CMergeEditView : public CGhostTextView
56 {
57 protected:
58         CMergeEditView();           // protected constructor used by dynamic creation
59         DECLARE_DYNCREATE(CMergeEditView)
60         CCrystalParser m_xParser; /**< Syntax parser used for syntax highlighting. */
61
62 // Attributes
63 public:
64         /**
65          * Index of pane this view is attached to.
66          * This indicates the pane number the view is attached to. If we swap panes
67          * then these indexes are changed.
68          */
69         int m_nThisPane;
70         int m_nThisGroup;
71         bool m_bDetailView;
72         IMergeEditStatus * m_piMergeEditStatus; /**< interface to status bar */
73
74 protected:
75         /// first line of diff (first displayable line)
76         int m_lineBegin;
77         /// last line of diff (last displayable line)
78         int m_lineEnd; 
79
80 private:
81         /** 
82         This flag is set when we receive an OnTimer command, and we want 
83         to wait for theApp::OnIdle before processing it 
84         */
85         unsigned fTimerWaitingForIdle;
86         COLORSETTINGS m_cachedColors; /**< Cached color settings */
87
88         /// active prediffer ID : helper to check the radio button
89         int m_CurrentPredifferID;
90
91         bool m_bCurrentLineIsDiff; /**< `true` if cursor is in diff line */
92
93         bool m_bChangedSchemeManually;  /**< `true` if the syntax highlighting scheme is changed manually */
94
95 // Attributes
96 public:
97         void CopyProperties (CCrystalTextView* pSource) override;
98
99 // Operations
100 public:
101         void RefreshOptions();
102         bool IsReadOnly(int pane) const;
103         void ShowDiff(bool bScroll, bool bSelectText);
104         virtual void OnEditOperation(int nAction, LPCTSTR pszText, size_t cchText) override;
105         bool IsLineInCurrentDiff(int nLine) const;
106         void SelectNone();
107         void SelectDiff(int nDiff, bool bScroll = true, bool bSelectText = true);
108         void DeselectDiffIfCursorNotInCurrentDiff();
109         virtual CCrystalTextBuffer *LocateTextBuffer ();
110         const CCrystalTextBuffer *LocateTextBuffer () const { return const_cast<CMergeEditView *>(this)->LocateTextBuffer(); };
111         void GetFullySelectedDiffs(int & firstDiff, int & lastDiff);
112         void GetFullySelectedDiffs(int & firstDiff, int & lastDiff, int & firstWordDiff,  int & lastWordDiff, const CPoint *pptStart = nullptr, const CPoint *ppEnd = nullptr);
113         void GetSelectedDiffs(int & firstDiff, int & lastDiff);
114         std::map<int, std::vector<int>> GetColumnSelectedWordDiffIndice();
115         CString GetSelectedText();
116         std::pair<int, int> GetSelectedLineAndCharacterCount();
117         CString GetLineText(int idx);
118         CMergeDoc* GetDocument();
119         const CMergeDoc *GetDocument() const { return const_cast<CMergeEditView *>(this)->GetDocument(); }
120         void UpdateResources();
121         bool IsModified() { return (LocateTextBuffer()->IsModified()); }
122         void PrimeListWithFile();
123         void SetStatusInterface(IMergeEditStatus * piMergeEditStatus);
124         void SelectArea(const CPoint & ptStart, const CPoint & ptEnd) { SetSelection(ptStart, ptEnd); } // make public
125         using CGhostTextView::GetSelection;
126         virtual void UpdateSiblingScrollPos (bool bHorz) override;
127     virtual std::vector<CrystalLineParser::TEXTBLOCK> GetMarkerTextBlocks(int nLineIndex) const;
128         virtual std::vector<CrystalLineParser::TEXTBLOCK> GetAdditionalTextBlocks (int nLineIndex) override;
129         virtual COLORREF GetColor(int nColorIndex) const override;
130         virtual void GetLineColors (int nLineIndex, COLORREF & crBkgnd,
131                         COLORREF & crText, bool & bDrawWhitespace) override;
132         virtual void GetLineColors2 (int nLineIndex, DWORD ignoreFlags
133                 , COLORREF & crBkgnd, COLORREF & crText, bool & bDrawWhitespace);
134         void WMGoto() { OnWMGoto(); };
135         void GotoLine(UINT nLine, bool bRealLine, int pane, bool bMoveAnchor = true);
136         int GetTopLine() const { return m_nTopLine; }
137         using CCrystalTextView::GetScreenLines;
138         int GetTopSubLine() const { return m_nTopSubLine; }
139         using CCrystalTextView::GetSubLines;
140         using CCrystalTextView::GetSubLineCount;
141         using CCrystalTextView::GetSubLineIndex;
142         using CCrystalTextView::GetLineBySubLine;
143         virtual int GetEmptySubLines( int nLineIndex ) override;
144         virtual void InvalidateSubLineIndexCache( int nLineIndex ) override;
145         void RepaintLocationPane();
146         void SetPredifferByMenu(UINT nID);
147         void DocumentsLoaded();
148         void UpdateLocationViewPosition(int nTopLine = -1, int nBottomLine = -1);
149         virtual void RecalcPageLayouts(CDC * pdc, CPrintInfo * pInfo) override;
150         virtual void GetPrintHeaderText(int nPageNum, CString & text) override;
151         virtual void PrintHeader(CDC * pdc, int nPageNum) override;
152         virtual void PrintFooter(CDC * pdc, int nPageNum) override;
153         virtual void SetWordWrapping( bool bWordWrap ) override;
154         void UpdateStatusbar();
155         CMergeEditView *GetGroupView(int nPane) const;
156
157         virtual void OnDisplayDiff(int nDiff=0);
158
159         // to customize the mergeview menu
160         HMENU createPrediffersSubmenu(HMENU hMenu);
161
162         bool IsInitialized() const;
163         bool IsCursorInDiff() const;
164         bool IsDiffVisible(int nDiff);
165         void ZoomText(short amount);
166         virtual bool QueryEditable() override;
167         virtual void EnsureVisible(CPoint pt) override;
168         virtual void EnsureVisible(CPoint ptStart, CPoint ptEnd) override;
169         bool EnsureInDiff(CPoint& pt);
170         void SetSelection(const CPoint& ptStart, const CPoint& ptEnd, bool bUpdateView = true) override;
171         void ScrollToSubLine(int nNewTopLine, bool bNoSmoothScroll = false, bool bTrackScrollBar = true) override;
172         void SetActivePane();
173
174         // Overrides
175         // ClassWizard generated virtual function overrides
176         //{{AFX_VIRTUAL(CMergeEditView)
177         public:
178         virtual void OnInitialUpdate();
179         protected:
180         virtual void OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView);
181         virtual void OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint);
182         virtual BOOL PreTranslateMessage(MSG* pMsg);
183         virtual void OnBeginPrinting (CDC * pDC, CPrintInfo * pInfo);
184         virtual void OnEndPrinting (CDC * pDC, CPrintInfo * pInfo);
185         virtual void OnPrint(CDC* pDC, CPrintInfo* pInfo);
186         //}}AFX_VIRTUAL
187
188 // Implementation
189 protected:
190         virtual ~CMergeEditView();
191         virtual void OnUpdateSibling (CCrystalTextView * pUpdateSource, bool bHorz) override;
192         virtual void OnUpdateCaret() override;
193         bool MergeModeKeyDown(MSG* pMsg);
194         bool IsDiffVisible(const DIFFRANGE& diff, int nLinesBelow = 0);
195         void OnNext3wayDiff(int type);
196         void OnUpdateNext3wayDiff(CCmdUI* pCmdUI, int type);
197         void OnPrev3wayDiff(int type);
198         void OnUpdatePrev3wayDiff(CCmdUI* pCmdUI, int type);
199         void OnDropFiles(const std::vector<String>& files);
200
201         // Generated message map functions
202 protected:
203         //{{AFX_MSG(CMergeEditView)
204         afx_msg void OnCurdiff();
205         afx_msg void OnUpdateCurdiff(CCmdUI* pCmdUI);
206         afx_msg void OnEditCopy();
207         afx_msg void OnUpdateEditCopy(CCmdUI* pCmdUI);
208         afx_msg void OnEditCut();
209         afx_msg void OnUpdateEditCut(CCmdUI* pCmdUI);
210         afx_msg void OnEditPaste();
211         afx_msg void OnUpdateEditPaste(CCmdUI* pCmdUI);
212         afx_msg void OnEditUndo();
213         afx_msg void OnFirstdiff();
214         afx_msg void OnUpdateFirstdiff(CCmdUI* pCmdUI);
215         afx_msg void OnLastdiff();
216         afx_msg void OnUpdateLastdiff(CCmdUI* pCmdUI);
217         afx_msg void OnNextdiff();
218         afx_msg void OnUpdateNextdiff(CCmdUI* pCmdUI);
219         afx_msg void OnPrevdiff();
220         afx_msg void OnUpdatePrevdiff(CCmdUI* pCmdUI);
221         afx_msg void OnNextConflict();
222         afx_msg void OnUpdateNextConflict(CCmdUI* pCmdUI);
223         afx_msg void OnPrevConflict();
224         afx_msg void OnUpdatePrevConflict(CCmdUI* pCmdUI);
225         afx_msg void OnNextdiffLM();
226         afx_msg void OnUpdateNextdiffLM(CCmdUI* pCmdUI);
227         afx_msg void OnPrevdiffLM();
228         afx_msg void OnUpdatePrevdiffLM(CCmdUI* pCmdUI);
229         afx_msg void OnNextdiffLR();
230         afx_msg void OnUpdateNextdiffLR(CCmdUI* pCmdUI);
231         afx_msg void OnPrevdiffLR();
232         afx_msg void OnUpdatePrevdiffLR(CCmdUI* pCmdUI);
233         afx_msg void OnNextdiffMR();
234         afx_msg void OnUpdateNextdiffMR(CCmdUI* pCmdUI);
235         afx_msg void OnPrevdiffMR();
236         afx_msg void OnUpdatePrevdiffMR(CCmdUI* pCmdUI);
237         afx_msg void OnNextdiffLO();
238         afx_msg void OnUpdateNextdiffLO(CCmdUI* pCmdUI);
239         afx_msg void OnPrevdiffLO();
240         afx_msg void OnUpdatePrevdiffLO(CCmdUI* pCmdUI);
241         afx_msg void OnNextdiffMO();
242         afx_msg void OnUpdateNextdiffMO(CCmdUI* pCmdUI);
243         afx_msg void OnPrevdiffMO();
244         afx_msg void OnUpdatePrevdiffMO(CCmdUI* pCmdUI);
245         afx_msg void OnNextdiffRO();
246         afx_msg void OnUpdateNextdiffRO(CCmdUI* pCmdUI);
247         afx_msg void OnPrevdiffRO();
248         afx_msg void OnUpdatePrevdiffRO(CCmdUI* pCmdUI);
249         afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
250         afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
251         afx_msg void OnRButtonDown(UINT nFlags, CPoint point);
252         afx_msg void OnAllLeft();
253         afx_msg void OnUpdateAllLeft(CCmdUI* pCmdUI);
254         afx_msg void OnAllRight();
255         afx_msg void OnUpdateAllRight(CCmdUI* pCmdUI);
256         afx_msg void OnAutoMerge();
257         afx_msg void OnUpdateAutoMerge(CCmdUI* pCmdUI);
258         afx_msg void OnX2Y(int srcPane, int dstPane, bool selectedLineOnly = false);
259         afx_msg void OnUpdateX2Y(int dstPane, CCmdUI* pCmdUI);
260         afx_msg void OnL2r();
261         afx_msg void OnUpdateL2r(CCmdUI* pCmdUI);
262         afx_msg void OnLinesL2r();
263         afx_msg void OnUpdateLinesL2r(CCmdUI* pCmdUI);
264         afx_msg void OnR2l();
265         afx_msg void OnUpdateR2l(CCmdUI* pCmdUI);
266         afx_msg void OnLinesR2l();
267         afx_msg void OnUpdateLinesR2l(CCmdUI* pCmdUI);
268         afx_msg void OnCopyFromLeft();
269         afx_msg void OnUpdateCopyFromLeft(CCmdUI* pCmdUI);
270         afx_msg void OnCopyLinesFromLeft();
271         afx_msg void OnUpdateCopyLinesFromLeft(CCmdUI* pCmdUI);
272         afx_msg void OnCopyFromRight();
273         afx_msg void OnUpdateCopyFromRight(CCmdUI* pCmdUI);
274         afx_msg void OnCopyLinesFromRight();
275         afx_msg void OnUpdateCopyLinesFromRight(CCmdUI* pCmdUI);
276         afx_msg void OnAddSyncPoint();
277         afx_msg void OnClearSyncPoints();
278         afx_msg void OnUpdateClearSyncPoints(CCmdUI* pCmdUI);
279         afx_msg void OnUpdateEditUndo(CCmdUI* pCmdUI);
280         afx_msg void OnEditRedo();
281         afx_msg void OnUpdateEditRedo(CCmdUI* pCmdUI);
282         afx_msg void OnTimer(UINT_PTR nIDEvent);
283         afx_msg void OnUpdateFileSaveLeft(CCmdUI* pCmdUI);
284         afx_msg void OnUpdateFileSaveMiddle(CCmdUI* pCmdUI);
285         afx_msg void OnUpdateFileSaveRight(CCmdUI* pCmdUI);
286         afx_msg void OnRefresh();
287         afx_msg void OnUpdateFileSave(CCmdUI* pCmdUI);
288         template<bool reversed>
289         afx_msg void OnSelectLineDiff();
290         afx_msg void OnUpdateSelectLineDiff(CCmdUI* pCmdUI);
291         afx_msg void OnAddToSubstitutionFilters();
292         afx_msg void OnUpdateAddToSubstitutionFilters(CCmdUI* pCmdUI);
293         afx_msg void OnContextMenu(CWnd* pWnd, CPoint point);
294         afx_msg void OnUpdateEditReplace(CCmdUI* pCmdUI);
295         afx_msg void OnLeftReadOnly();
296         afx_msg void OnUpdateLeftReadOnly(CCmdUI* pCmdUI);
297         afx_msg void OnMiddleReadOnly();
298         afx_msg void OnUpdateMiddleReadOnly(CCmdUI* pCmdUI);
299         afx_msg void OnRightReadOnly();
300         afx_msg void OnUpdateRightReadOnly(CCmdUI* pCmdUI);
301         afx_msg void OnUpdateStatusRO(CCmdUI* pCmdUI);
302         afx_msg void OnConvertEolTo(UINT nID );
303         afx_msg void OnUpdateConvertEolTo(CCmdUI* pCmdUI);
304         afx_msg void OnUpdateStatusEOL(CCmdUI* pCmdUI);
305         afx_msg void OnL2RNext();
306         afx_msg void OnUpdateL2RNext(CCmdUI* pCmdUI);
307         afx_msg void OnR2LNext();
308         afx_msg void OnUpdateR2LNext(CCmdUI* pCmdUI);
309         afx_msg void OnChangePane();
310         afx_msg void OnWMGoto();
311         afx_msg void OnGotoMovedLineLM();
312         afx_msg void OnUpdateGotoMovedLineLM(CCmdUI* pCmdUI);
313         afx_msg void OnGotoMovedLineMR();
314         afx_msg void OnUpdateGotoMovedLineMR(CCmdUI* pCmdUI);
315         afx_msg void OnShellMenu();
316         afx_msg void OnUpdateShellMenu(CCmdUI* pCmdUI);
317         afx_msg void OnScripts(UINT nID );
318         afx_msg void OnUpdatePrediffer(CCmdUI* pCmdUI);
319         afx_msg void OnNoPrediffer();
320         afx_msg void OnPrediffer(UINT nID );
321         afx_msg void OnHScroll (UINT nSBCode, UINT nPos, CScrollBar * pScrollBar);
322         afx_msg void OnVScroll (UINT nSBCode, UINT nPos, CScrollBar * pScrollBar);
323         afx_msg void OnEditCopyLineNumbers();
324         afx_msg void OnUpdateEditCopyLinenumbers(CCmdUI* pCmdUI);
325         afx_msg void OnViewLineDiffs();
326         afx_msg void OnUpdateViewLineDiffs(CCmdUI* pCmdUI);
327         afx_msg void OnViewLineNumbers();
328         afx_msg void OnUpdateViewLineNumbers(CCmdUI* pCmdUI);
329         afx_msg void OnViewWordWrap();
330         afx_msg void OnUpdateViewWordWrap(CCmdUI* pCmdUI);
331         afx_msg void OnViewWhitespace();
332         afx_msg void OnUpdateViewWhitespace(CCmdUI* pCmdUI);
333         afx_msg void OnViewEOL();
334         afx_msg void OnUpdateViewEOL(CCmdUI* pCmdUI);
335         afx_msg void OnOpenFile();
336         afx_msg void OnOpenFileWith();
337         afx_msg void OnOpenFileWithEditor();
338         afx_msg void OnOpenParentFolder();
339         afx_msg void OnViewSwapPanes12();
340         afx_msg void OnViewSwapPanes23();
341         afx_msg void OnViewSwapPanes13();
342         afx_msg void OnSize(UINT nType, int cx, int cy);
343         afx_msg void OnHelp();
344         afx_msg void OnViewMargin();
345         afx_msg void OnUpdateViewMargin(CCmdUI* pCmdUI);
346         afx_msg void OnUpdateViewChangeScheme(CCmdUI *pCmdUI);
347         afx_msg void OnChangeScheme(UINT nID);
348         afx_msg void OnUpdateChangeScheme(CCmdUI* pCmdUI);
349         afx_msg BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt);
350         afx_msg void OnMouseHWheel(UINT nFlags, short zDelta, CPoint pt);
351         afx_msg void OnViewZoomIn();
352         afx_msg void OnViewZoomOut();
353         afx_msg void OnViewZoomNormal();
354         afx_msg void OnWindowSplit();
355         afx_msg void OnUpdateWindowSplit(CCmdUI* pCmdUI);
356         afx_msg void OnStatusBarDblClick(NMHDR* pNMHDR, LRESULT* pResult);
357
358         //}}AFX_MSG
359         DECLARE_MESSAGE_MAP()
360 };
361
362 #ifndef _DEBUG  // debug version in DiffView.cpp
363 inline CMergeDoc* CMergeEditView::GetDocument()
364    { return reinterpret_cast<CMergeDoc*>(m_pDocument); }
365 #endif
366
367 /**
368  * @brief Check if cursor is inside difference.
369  * @return true if cursor is inside difference.
370  */
371 inline bool CMergeEditView::IsCursorInDiff() const
372 {
373         return m_bCurrentLineIsDiff;
374 }
375