OSDN Git Service

Merge with stable
[winmerge-jp/winmerge-jp.git] / Src / MergeEditView.h
1 /////////////////////////////////////////////////////////////////////////////
2 //    WinMerge:  an interactive diff/merge utility
3 //    Copyright (C) 1997  Dean P. Grimm
4 //
5 //    This program is free software; you can redistribute it and/or modify
6 //    it under the terms of the GNU General Public License as published by
7 //    the Free Software Foundation; either version 2 of the License, or
8 //    (at your option) any later version.
9 //
10 //    This program is distributed in the hope that it will be useful,
11 //    but WITHOUT ANY WARRANTY; without even the implied warranty of
12 //    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 //    GNU General Public License for more details.
14 //
15 //    You should have received a copy of the GNU General Public License
16 //    along with this program; if not, write to the Free Software
17 //    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 //
19 /////////////////////////////////////////////////////////////////////////////
20 /** 
21  * @file  MergeEditView.h
22  *
23  * @brief Declaration file for CMergeEditView
24  *
25  */
26 // ID line follows -- this is updated by SVN
27 // $Id: MergeEditView.h 6655 2009-04-14 19:18:31Z kimmov $
28
29 #if !defined(AFX_MERGEEDITVIEW_H__0CE31CFD_4BEE_4378_ADB4_B7C9F50A9F53__INCLUDED_)
30 #define AFX_MERGEEDITVIEW_H__0CE31CFD_4BEE_4378_ADB4_B7C9F50A9F53__INCLUDED_
31
32 /** 
33  * @brief Non-diff lines shown above diff when scrolling to it
34  */
35 const UINT CONTEXT_LINES_ABOVE = 5;
36
37 /** 
38  * @brief Non-diff lines shown below diff when scrolling to it
39  */
40 const UINT CONTEXT_LINES_BELOW = 3;
41
42
43 #define FLAG_RESCAN_WAITS_FOR_IDLE   1
44
45
46 /////////////////////////////////////////////////////////////////////////////
47 // CMergeEditView view
48 #include "edtlib.h"
49 #include "GhostTextView.h"
50 #include "OptionsDiffColors.h"
51
52 class IMergeEditStatus;
53 class CLocationView;
54 class CMergeDoc;
55 struct DIFFRANGE;
56
57 /**
58 This class is the base class for WinMerge editor panels.
59 It hooks the painting of ghost lines (GetLineColors), the shared
60 scrollbar (OnUpdateSibling...).
61 It offers the UI interface commands to work with diffs 
62
63 @todo
64 If we keep GetLineColors here, we should clear DIFF flag here
65 and not in CGhostTextBuffer (when insertText/deleteText). 
66 Small problem... This class doesn't derives from CGhostTextBuffer... 
67 We could define a new class which derives from CGhostTextBuffer to clear the DIFF flag.
68 and calls a virtual function for additional things to do on the flag.
69 Maybe in the future...
70 */
71 class CMergeEditView : public CGhostTextView
72 {
73 protected:
74         CMergeEditView();           // protected constructor used by dynamic creation
75         DECLARE_DYNCREATE(CMergeEditView)
76         CCrystalParser m_xParser; /**< Syntax parser used for syntax highlighting. */
77
78 // Attributes
79 public:
80         /**
81          * Index of pane this view is attached to.
82          * This indicates the pane number the view is attached to. If we swap panes
83          * then these indexes are changed.
84          */
85         int m_nThisPane;
86         IMergeEditStatus * m_piMergeEditStatus; /**< interface to status bar */
87
88 protected:
89         /**
90          * Are automatic rescans enabled?
91          * If automatic rescans are enabled then we rescan files after edit
92          * events, unless timer suppresses rescan. We suppress rescans within
93          * certain time from previous rescan.
94          */
95         bool m_bAutomaticRescan;
96         /// first line of diff (first displayable line)
97         int m_lineBegin;
98         /// last line of diff (last displayable line)
99         int m_lineEnd; 
100
101 private:
102         /** 
103         This flag is set when we receive an OnTimer command, and we want 
104         to wait for theApp::OnIdle before processing it 
105         */
106         bool fTimerWaitingForIdle;
107         COLORSETTINGS m_cachedColors; /**< Cached color settings */
108
109         /// active prediffer ID : helper to check the radio button
110         int m_CurrentPredifferID;
111
112         bool m_bCurrentLineIsDiff; /**< TRUE if cursor is in diff line */
113         CLocationView * m_pLocationView; /**< Pointer to locationview */
114
115 // Operations
116 public:
117         void RefreshOptions();
118         bool EnableRescan(bool bEnable);
119         bool IsReadOnly(int pane) const;
120         void ShowDiff(bool bScroll, bool bSelectText);
121         virtual void OnEditOperation(int nAction, LPCTSTR pszText, int cchText);
122         void UpdateLineLengths();
123         bool IsLineInCurrentDiff(int nLine) const;
124         void SelectNone();
125         void SelectDiff(int nDiff, bool bScroll = true, bool bSelectText = true);
126         virtual CCrystalTextBuffer *LocateTextBuffer ();
127         const CCrystalTextBuffer *LocateTextBuffer () const { return const_cast<CMergeEditView *>(this)->LocateTextBuffer(); };
128         void GetFullySelectedDiffs(int & firstDiff, int & lastDiff);
129         CString GetSelectedText();
130         CString GetLineText(int idx);
131         CMergeDoc* GetDocument();
132         const CMergeDoc *GetDocument() const { return const_cast<CMergeEditView *>(this)->GetDocument(); }
133         void UpdateResources();
134         BOOL IsModified() { return (LocateTextBuffer()->IsModified()); }
135         void PrimeListWithFile();
136         void SetStatusInterface(IMergeEditStatus * piMergeEditStatus);
137         void SelectArea(const CPoint & ptStart, const CPoint & ptEnd) { SetSelection(ptStart, ptEnd); } // make public
138         void GetSelection(CPoint &ptStart, CPoint &ptEnd) { CCrystalTextView::GetSelection(ptStart, ptEnd); }
139         virtual void UpdateSiblingScrollPos (bool bHorz);
140         virtual int GetAdditionalTextBlocks (int nLineIndex, TEXTBLOCK *&pBuf);
141         virtual COLORREF GetColor(int nColorIndex);
142         virtual void GetLineColors (int nLineIndex, COLORREF & crBkgnd,
143                         COLORREF & crText, bool & bDrawWhitespace);
144         virtual void GetLineColors2 (int nLineIndex, DWORD ignoreFlags
145                 , COLORREF & crBkgnd, COLORREF & crText, bool & bDrawWhitespace);
146         void WMGoto() { OnWMGoto(); };
147         void GotoLine(UINT nLine, bool bRealLine, int pane);
148         int GetTopLine() const { return m_nTopLine; }
149         int GetScreenLines() { return CCrystalTextView::GetScreenLines(); }
150         int GetTopSubLine() const { return m_nTopSubLine; }
151         int GetSubLines(int nLineIndex) { return CCrystalTextView::GetSubLines(nLineIndex); }
152         virtual int GetSubLineCount() { return CCrystalTextView::GetSubLineCount(); }
153         virtual int GetSubLineIndex(int nLineIndex) { return CCrystalTextView::GetSubLineIndex(nLineIndex); }
154         virtual void GetLineBySubLine(int nSubLineIndex, int &nLine, int &nSubLine) {
155                 CCrystalTextView::GetLineBySubLine(nSubLineIndex, nLine, nSubLine);
156         }
157         virtual int GetEmptySubLines( int nLineIndex );
158         virtual void InvalidateSubLineIndexCache( int nLineIndex );
159         void RepaintLocationPane();
160         bool SetPredifferByName(const CString & prediffer);
161         void SetPredifferByMenu(UINT nID);
162         void DocumentsLoaded();
163         void SetLocationView(const CLocationView * pView = NULL);
164         void UpdateLocationViewPosition(int nTopLine = -1, int nBottomLine = -1);
165         virtual void RecalcPageLayouts(CDC * pdc, CPrintInfo * pInfo);
166         virtual void GetPrintHeaderText(int nPageNum, CString & text);
167         virtual void PrintHeader(CDC * pdc, int nPageNum);
168         virtual void PrintFooter(CDC * pdc, int nPageNum);
169         virtual void SetWordWrapping( bool bWordWrap );
170         void UpdateStatusbar();
171         CMergeEditView *GetGroupView(int nPane) const;
172         bool IsDetailViewPane() const;
173
174         virtual void OnDisplayDiff(int nDiff=0);
175
176         // to customize the mergeview menu
177         static HMENU createScriptsSubmenu(HMENU hMenu);
178         HMENU createPrediffersSubmenu(HMENU hMenu);
179
180         bool IsInitialized() const;
181         bool IsCursorInDiff() const;
182         bool IsDiffVisible(int nDiff);
183         void ZoomText(short amount);
184
185         // Overrides
186         // ClassWizard generated virtual function overrides
187         //{{AFX_VIRTUAL(CMergeEditView)
188         public:
189         virtual void OnInitialUpdate();
190         protected:
191         virtual void OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView);
192         virtual void OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint);
193         virtual BOOL PreTranslateMessage(MSG* pMsg);
194         virtual void OnBeginPrinting (CDC * pDC, CPrintInfo * pInfo);
195         virtual void OnEndPrinting (CDC * pDC, CPrintInfo * pInfo);
196         virtual void OnPrint(CDC* pDC, CPrintInfo* pInfo);
197         //}}AFX_VIRTUAL
198
199 // Implementation
200 protected:
201         virtual ~CMergeEditView();
202         virtual void OnUpdateSibling (CCrystalTextView * pUpdateSource, BOOL bHorz);
203         virtual void OnUpdateCaret();
204         bool MergeModeKeyDown(MSG* pMsg);
205         int FindPrediffer(LPCTSTR prediffer) const;
206         bool IsDiffVisible(const DIFFRANGE& diff, int nLinesBelow = 0);
207         void OnNext3wayDiff(int type);
208         void OnUpdateNext3wayDiff(CCmdUI* pCmdUI, int type);
209         void OnPrev3wayDiff(int type);
210         void OnUpdatePrev3wayDiff(CCmdUI* pCmdUI, int type);
211
212         // Generated message map functions
213 protected:
214         //{{AFX_MSG(CMergeEditView)
215         afx_msg void OnCurdiff();
216         afx_msg void OnUpdateCurdiff(CCmdUI* pCmdUI);
217         afx_msg void OnEditCopy();
218         afx_msg void OnUpdateEditCopy(CCmdUI* pCmdUI);
219         afx_msg void OnEditCut();
220         afx_msg void OnUpdateEditCut(CCmdUI* pCmdUI);
221         afx_msg void OnEditPaste();
222         afx_msg void OnUpdateEditPaste(CCmdUI* pCmdUI);
223         afx_msg void OnEditUndo();
224         afx_msg void OnFirstdiff();
225         afx_msg void OnUpdateFirstdiff(CCmdUI* pCmdUI);
226         afx_msg void OnLastdiff();
227         afx_msg void OnUpdateLastdiff(CCmdUI* pCmdUI);
228         afx_msg void OnNextdiff();
229         afx_msg void OnUpdateNextdiff(CCmdUI* pCmdUI);
230         afx_msg void OnPrevdiff();
231         afx_msg void OnUpdatePrevdiff(CCmdUI* pCmdUI);
232         afx_msg void OnNextConflict();
233         afx_msg void OnUpdateNextConflict(CCmdUI* pCmdUI);
234         afx_msg void OnPrevConflict();
235         afx_msg void OnUpdatePrevConflict(CCmdUI* pCmdUI);
236         afx_msg void OnNextdiffLM();
237         afx_msg void OnUpdateNextdiffLM(CCmdUI* pCmdUI);
238         afx_msg void OnPrevdiffLM();
239         afx_msg void OnUpdatePrevdiffLM(CCmdUI* pCmdUI);
240         afx_msg void OnNextdiffLR();
241         afx_msg void OnUpdateNextdiffLR(CCmdUI* pCmdUI);
242         afx_msg void OnPrevdiffLR();
243         afx_msg void OnUpdatePrevdiffLR(CCmdUI* pCmdUI);
244         afx_msg void OnNextdiffMR();
245         afx_msg void OnUpdateNextdiffMR(CCmdUI* pCmdUI);
246         afx_msg void OnPrevdiffMR();
247         afx_msg void OnUpdatePrevdiffMR(CCmdUI* pCmdUI);
248         afx_msg void OnNextdiffLO();
249         afx_msg void OnUpdateNextdiffLO(CCmdUI* pCmdUI);
250         afx_msg void OnPrevdiffLO();
251         afx_msg void OnUpdatePrevdiffLO(CCmdUI* pCmdUI);
252         afx_msg void OnNextdiffMO();
253         afx_msg void OnUpdateNextdiffMO(CCmdUI* pCmdUI);
254         afx_msg void OnPrevdiffMO();
255         afx_msg void OnUpdatePrevdiffMO(CCmdUI* pCmdUI);
256         afx_msg void OnNextdiffRO();
257         afx_msg void OnUpdateNextdiffRO(CCmdUI* pCmdUI);
258         afx_msg void OnPrevdiffRO();
259         afx_msg void OnUpdatePrevdiffRO(CCmdUI* pCmdUI);
260         afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
261         afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
262         afx_msg void OnAllLeft();
263         afx_msg void OnUpdateAllLeft(CCmdUI* pCmdUI);
264         afx_msg void OnAllRight();
265         afx_msg void OnUpdateAllRight(CCmdUI* pCmdUI);
266         afx_msg void OnAutoMerge();
267         afx_msg void OnUpdateAutoMerge(CCmdUI* pCmdUI);
268         afx_msg void OnX2Y(int srcPane, int dstPane, const String& message);
269         afx_msg void OnUpdateX2Y(int dstPane, CCmdUI* pCmdUI);
270         afx_msg void OnL2r();
271         afx_msg void OnUpdateL2r(CCmdUI* pCmdUI);
272         afx_msg void OnR2l();
273         afx_msg void OnUpdateR2l(CCmdUI* pCmdUI);
274         afx_msg void OnCopyFromLeft();
275         afx_msg void OnUpdateCopyFromLeft(CCmdUI* pCmdUI);
276         afx_msg void OnCopyFromRight();
277         afx_msg void OnUpdateCopyFromRight(CCmdUI* pCmdUI);
278         afx_msg void OnAddSyncPoint();
279         afx_msg void OnUpdateAddSyncPoint(CCmdUI* pCmdUI);
280         afx_msg void OnClearSyncPoints();
281         afx_msg void OnUpdateClearSyncPoints(CCmdUI* pCmdUI);
282         afx_msg void OnUpdateEditUndo(CCmdUI* pCmdUI);
283         afx_msg void OnEditRedo();
284         afx_msg void OnUpdateEditRedo(CCmdUI* pCmdUI);
285         afx_msg void OnTimer(UINT_PTR nIDEvent);
286         afx_msg void OnUpdateFileSaveLeft(CCmdUI* pCmdUI);
287         afx_msg void OnUpdateFileSaveMiddle(CCmdUI* pCmdUI);
288         afx_msg void OnUpdateFileSaveRight(CCmdUI* pCmdUI);
289         afx_msg void OnRefresh();
290         afx_msg void OnUpdateFileSave(CCmdUI* pCmdUI);
291         template<bool reversed>
292         afx_msg void OnSelectLineDiff();
293         afx_msg void OnUpdateSelectLineDiff(CCmdUI* pCmdUI);
294         afx_msg void OnContextMenu(CWnd* pWnd, CPoint point);
295         afx_msg void OnUpdateEditReplace(CCmdUI* pCmdUI);
296         afx_msg void OnLeftReadOnly();
297         afx_msg void OnUpdateLeftReadOnly(CCmdUI* pCmdUI);
298         afx_msg void OnMiddleReadOnly();
299         afx_msg void OnUpdateMiddleReadOnly(CCmdUI* pCmdUI);
300         afx_msg void OnRightReadOnly();
301         afx_msg void OnUpdateRightReadOnly(CCmdUI* pCmdUI);
302         afx_msg void OnUpdateStatusRO(CCmdUI* pCmdUI);
303         afx_msg void OnConvertEolTo(UINT nID );
304         afx_msg void OnUpdateConvertEolTo(CCmdUI* pCmdUI);
305         afx_msg void OnUpdateStatusEOL(CCmdUI* pCmdUI);
306         afx_msg void OnL2RNext();
307         afx_msg void OnUpdateL2RNext(CCmdUI* pCmdUI);
308         afx_msg void OnR2LNext();
309         afx_msg void OnUpdateR2LNext(CCmdUI* pCmdUI);
310         afx_msg void OnChangePane();
311         afx_msg void OnUpdateChangePane(CCmdUI* pCmdUI);
312         afx_msg void OnWMGoto();
313         afx_msg void OnUpdateWMGoto(CCmdUI* pCmdUI);
314         afx_msg void OnUpdateScripts(CCmdUI* pCmdUI);
315         afx_msg void OnScripts(UINT nID );
316         afx_msg void OnUpdateNoPrediffer(CCmdUI* pCmdUI);
317         afx_msg void OnUpdatePrediffer(CCmdUI* pCmdUI);
318         afx_msg void OnNoPrediffer();
319         afx_msg void OnPrediffer(UINT nID );
320         afx_msg void OnHScroll (UINT nSBCode, UINT nPos, CScrollBar * pScrollBar);
321         afx_msg void OnVScroll (UINT nSBCode, UINT nPos, CScrollBar * pScrollBar);
322         afx_msg void OnEditCopyLineNumbers();
323         afx_msg void OnUpdateEditCopyLinenumbers(CCmdUI* pCmdUI);
324         afx_msg void OnViewLineDiffs();
325         afx_msg void OnUpdateViewLineDiffs(CCmdUI* pCmdUI);
326         afx_msg void OnViewLineNumbers();
327         afx_msg void OnUpdateViewLineNumbers(CCmdUI* pCmdUI);
328         afx_msg void OnViewWordWrap();
329         afx_msg void OnUpdateViewWordWrap(CCmdUI* pCmdUI);
330         afx_msg void OnOpenFile();
331         afx_msg void OnOpenFileWith();
332         afx_msg void OnOpenFileWithEditor();
333         afx_msg void OnViewSwapPanes();
334         afx_msg void OnUpdateViewSwapPanes(CCmdUI* pCmdUI);
335         afx_msg void OnUpdateNoEditScripts(CCmdUI* pCmdUI);
336         afx_msg void OnSize(UINT nType, int cx, int cy);
337         afx_msg void OnHelp();
338         afx_msg void OnViewMargin();
339         afx_msg void OnUpdateViewMargin(CCmdUI* pCmdUI);
340         afx_msg void OnUpdateViewChangeScheme(CCmdUI *pCmdUI);
341         afx_msg void OnChangeScheme(UINT nID);
342         afx_msg void OnUpdateChangeScheme(CCmdUI* pCmdUI);
343         afx_msg BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt);
344         afx_msg void OnViewZoomIn();
345         afx_msg void OnViewZoomOut();
346         afx_msg void OnViewZoomNormal();
347         //}}AFX_MSG
348         DECLARE_MESSAGE_MAP()
349 };
350
351 #ifndef _DEBUG  // debug version in DiffView.cpp
352 inline CMergeDoc* CMergeEditView::GetDocument()
353    { return (CMergeDoc*)m_pDocument; }
354 #endif
355
356 /////////////////////////////////////////////////////////////////////////////
357
358 //{{AFX_INSERT_LOCATION}}
359 // Microsoft Visual C++ will insert additional declarations immediately before the previous line.
360
361 #endif // !defined(AFX_MERGEEDITVIEW_H__0CE31CFD_4BEE_4378_ADB4_B7C9F50A9F53__INCLUDED_)