1 /////////////////////////////////////////////////////////////////////////////
2 // WinMerge: an interactive diff/merge utility
3 // Copyright (C) 1997 Dean P. Grimm
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.
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 /////////////////////////////////////////////////////////////////////////////
21 * @file MergeEditView.h
23 * @brief Declaration file for CMergeEditView
26 // ID line follows -- this is updated by SVN
27 // $Id: MergeEditView.h 6655 2009-04-14 19:18:31Z kimmov $
29 #if !defined(AFX_MERGEEDITVIEW_H__0CE31CFD_4BEE_4378_ADB4_B7C9F50A9F53__INCLUDED_)
30 #define AFX_MERGEEDITVIEW_H__0CE31CFD_4BEE_4378_ADB4_B7C9F50A9F53__INCLUDED_
33 * @brief Non-diff lines shown above diff when scrolling to it
35 const UINT CONTEXT_LINES_ABOVE = 5;
38 * @brief Non-diff lines shown below diff when scrolling to it
40 const UINT CONTEXT_LINES_BELOW = 3;
43 #define FLAG_RESCAN_WAITS_FOR_IDLE 1
46 /////////////////////////////////////////////////////////////////////////////
47 // CMergeEditView view
49 #include "GhostTextView.h"
50 #include "OptionsDiffColors.h"
52 class IMergeEditStatus;
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
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...
71 class CMergeEditView : public CGhostTextView
74 CMergeEditView(); // protected constructor used by dynamic creation
75 DECLARE_DYNCREATE(CMergeEditView)
76 CCrystalParser m_xParser; /**< Syntax parser used for syntax highlighting. */
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.
86 IMergeEditStatus * m_piMergeEditStatus; /**< interface to status bar */
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.
95 bool m_bAutomaticRescan;
96 /// first line of diff (first displayable line)
98 /// last line of diff (last displayable line)
103 This flag is set when we receive an OnTimer command, and we want
104 to wait for theApp::OnIdle before processing it
106 bool fTimerWaitingForIdle;
107 COLORSETTINGS m_cachedColors; /**< Cached color settings */
109 /// active prediffer ID : helper to check the radio button
110 int m_CurrentPredifferID;
112 bool m_bCurrentLineIsDiff; /**< TRUE if cursor is in diff line */
113 CLocationView * m_pLocationView; /**< Pointer to locationview */
117 void RefreshOptions();
118 bool EnableRescan(bool bEnable);
119 bool IsReadOnly(int pane);
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);
125 void SelectDiff(int nDiff, bool bScroll = true, bool bSelectText = true);
126 virtual CCrystalTextBuffer *LocateTextBuffer ();
127 void GetFullySelectedDiffs(int & firstDiff, int & lastDiff);
128 CString GetSelectedText();
129 CString GetLineText(int idx);
130 CMergeDoc* GetDocument();
131 const CMergeDoc *GetDocument() const { return const_cast<CMergeEditView *>(this)->GetDocument(); }
132 void UpdateResources();
133 BOOL IsModified() { return (LocateTextBuffer()->IsModified()); }
134 void PrimeListWithFile();
135 void SetStatusInterface(IMergeEditStatus * piMergeEditStatus);
136 void SelectArea(const CPoint & ptStart, const CPoint & ptEnd) { SetSelection(ptStart, ptEnd); } // make public
137 void GetSelection(CPoint &ptStart, CPoint &ptEnd) { CCrystalTextView::GetSelection(ptStart, ptEnd); }
138 virtual void UpdateSiblingScrollPos (bool bHorz);
139 virtual int GetAdditionalTextBlocks (int nLineIndex, TEXTBLOCK *&pBuf);
140 virtual COLORREF GetColor(int nColorIndex);
141 virtual void GetLineColors (int nLineIndex, COLORREF & crBkgnd,
142 COLORREF & crText, bool & bDrawWhitespace);
143 virtual void GetLineColors2 (int nLineIndex, DWORD ignoreFlags
144 , COLORREF & crBkgnd, COLORREF & crText, bool & bDrawWhitespace);
145 void WMGoto() { OnWMGoto(); };
146 void GotoLine(UINT nLine, bool bRealLine, int pane);
147 int GetTopLine() { return m_nTopLine; }
148 int GetScreenLines() { return CCrystalTextView::GetScreenLines(); }
149 int GetTopSubLine() { return m_nTopSubLine; }
150 int GetSubLines(int nLineIndex) { return CCrystalTextView::GetSubLines(nLineIndex); }
151 virtual int GetSubLineCount() { return CCrystalTextView::GetSubLineCount(); }
152 virtual int GetSubLineIndex(int nLineIndex) { return CCrystalTextView::GetSubLineIndex(nLineIndex); }
153 virtual void GetLineBySubLine(int nSubLineIndex, int &nLine, int &nSubLine) {
154 CCrystalTextView::GetLineBySubLine(nSubLineIndex, nLine, nSubLine);
156 virtual int GetEmptySubLines( int nLineIndex );
157 virtual void InvalidateSubLineIndexCache( int nLineIndex );
158 void RepaintLocationPane();
159 bool SetPredifferByName(const CString & prediffer);
160 void SetPredifferByMenu(UINT nID);
161 void DocumentsLoaded();
162 void SetLocationView(const CLocationView * pView = NULL);
163 void UpdateLocationViewPosition(int nTopLine = -1, int nBottomLine = -1);
164 virtual void RecalcPageLayouts(CDC * pdc, CPrintInfo * pInfo);
165 virtual void GetPrintHeaderText(int nPageNum, CString & text);
166 virtual void PrintHeader(CDC * pdc, int nPageNum);
167 virtual void PrintFooter(CDC * pdc, int nPageNum);
168 virtual void SetWordWrapping( bool bWordWrap );
169 void UpdateStatusbar();
170 CMergeEditView *GetGroupView(int nPane) const;
171 bool IsDetailViewPane() const;
173 virtual void OnDisplayDiff(int nDiff=0);
175 // to customize the mergeview menu
176 static HMENU createScriptsSubmenu(HMENU hMenu);
177 HMENU createPrediffersSubmenu(HMENU hMenu);
179 bool IsInitialized() const;
180 bool IsCursorInDiff() const;
181 bool IsDiffVisible(int nDiff);
182 void ZoomText(short amount);
185 // ClassWizard generated virtual function overrides
186 //{{AFX_VIRTUAL(CMergeEditView)
188 virtual void OnInitialUpdate();
190 virtual void OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView);
191 virtual void OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint);
192 virtual BOOL PreTranslateMessage(MSG* pMsg);
193 virtual void OnBeginPrinting (CDC * pDC, CPrintInfo * pInfo);
194 virtual void OnEndPrinting (CDC * pDC, CPrintInfo * pInfo);
195 virtual void OnPrint(CDC* pDC, CPrintInfo* pInfo);
200 virtual ~CMergeEditView();
201 virtual void OnUpdateSibling (CCrystalTextView * pUpdateSource, BOOL bHorz);
202 virtual void OnUpdateCaret();
203 bool MergeModeKeyDown(MSG* pMsg);
204 int FindPrediffer(LPCTSTR prediffer) const;
205 bool IsDiffVisible(const DIFFRANGE& diff, int nLinesBelow = 0);
206 void OnNext3wayDiff(int type);
207 void OnUpdateNext3wayDiff(CCmdUI* pCmdUI, int type);
208 void OnPrev3wayDiff(int type);
209 void OnUpdatePrev3wayDiff(CCmdUI* pCmdUI, int type);
211 // Generated message map functions
213 //{{AFX_MSG(CMergeEditView)
214 afx_msg void OnCurdiff();
215 afx_msg void OnUpdateCurdiff(CCmdUI* pCmdUI);
216 afx_msg void OnEditCopy();
217 afx_msg void OnUpdateEditCopy(CCmdUI* pCmdUI);
218 afx_msg void OnEditCut();
219 afx_msg void OnUpdateEditCut(CCmdUI* pCmdUI);
220 afx_msg void OnEditPaste();
221 afx_msg void OnUpdateEditPaste(CCmdUI* pCmdUI);
222 afx_msg void OnEditUndo();
223 afx_msg void OnFirstdiff();
224 afx_msg void OnUpdateFirstdiff(CCmdUI* pCmdUI);
225 afx_msg void OnLastdiff();
226 afx_msg void OnUpdateLastdiff(CCmdUI* pCmdUI);
227 afx_msg void OnNextdiff();
228 afx_msg void OnUpdateNextdiff(CCmdUI* pCmdUI);
229 afx_msg void OnPrevdiff();
230 afx_msg void OnUpdatePrevdiff(CCmdUI* pCmdUI);
231 afx_msg void OnNextConflict();
232 afx_msg void OnUpdateNextConflict(CCmdUI* pCmdUI);
233 afx_msg void OnPrevConflict();
234 afx_msg void OnUpdatePrevConflict(CCmdUI* pCmdUI);
235 afx_msg void OnNextdiffLM();
236 afx_msg void OnUpdateNextdiffLM(CCmdUI* pCmdUI);
237 afx_msg void OnPrevdiffLM();
238 afx_msg void OnUpdatePrevdiffLM(CCmdUI* pCmdUI);
239 afx_msg void OnNextdiffLR();
240 afx_msg void OnUpdateNextdiffLR(CCmdUI* pCmdUI);
241 afx_msg void OnPrevdiffLR();
242 afx_msg void OnUpdatePrevdiffLR(CCmdUI* pCmdUI);
243 afx_msg void OnNextdiffMR();
244 afx_msg void OnUpdateNextdiffMR(CCmdUI* pCmdUI);
245 afx_msg void OnPrevdiffMR();
246 afx_msg void OnUpdatePrevdiffMR(CCmdUI* pCmdUI);
247 afx_msg void OnNextdiffLO();
248 afx_msg void OnUpdateNextdiffLO(CCmdUI* pCmdUI);
249 afx_msg void OnPrevdiffLO();
250 afx_msg void OnUpdatePrevdiffLO(CCmdUI* pCmdUI);
251 afx_msg void OnNextdiffMO();
252 afx_msg void OnUpdateNextdiffMO(CCmdUI* pCmdUI);
253 afx_msg void OnPrevdiffMO();
254 afx_msg void OnUpdatePrevdiffMO(CCmdUI* pCmdUI);
255 afx_msg void OnNextdiffRO();
256 afx_msg void OnUpdateNextdiffRO(CCmdUI* pCmdUI);
257 afx_msg void OnPrevdiffRO();
258 afx_msg void OnUpdatePrevdiffRO(CCmdUI* pCmdUI);
259 afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
260 afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
261 afx_msg void OnAllLeft();
262 afx_msg void OnUpdateAllLeft(CCmdUI* pCmdUI);
263 afx_msg void OnAllRight();
264 afx_msg void OnUpdateAllRight(CCmdUI* pCmdUI);
265 afx_msg void OnAutoMerge();
266 afx_msg void OnUpdateAutoMerge(CCmdUI* pCmdUI);
267 afx_msg void OnX2Y(int srcPane, int dstPane, const String& message);
268 afx_msg void OnUpdateX2Y(int dstPane, CCmdUI* pCmdUI);
269 afx_msg void OnL2r();
270 afx_msg void OnUpdateL2r(CCmdUI* pCmdUI);
271 afx_msg void OnR2l();
272 afx_msg void OnUpdateR2l(CCmdUI* pCmdUI);
273 afx_msg void OnCopyFromLeft();
274 afx_msg void OnUpdateCopyFromLeft(CCmdUI* pCmdUI);
275 afx_msg void OnCopyFromRight();
276 afx_msg void OnUpdateCopyFromRight(CCmdUI* pCmdUI);
277 afx_msg void OnAddSyncPoint();
278 afx_msg void OnUpdateAddSyncPoint(CCmdUI* pCmdUI);
279 afx_msg void OnClearSyncPoints();
280 afx_msg void OnUpdateClearSyncPoints(CCmdUI* pCmdUI);
281 afx_msg void OnUpdateEditUndo(CCmdUI* pCmdUI);
282 afx_msg void OnEditRedo();
283 afx_msg void OnUpdateEditRedo(CCmdUI* pCmdUI);
284 afx_msg void OnTimer(UINT_PTR nIDEvent);
285 afx_msg void OnUpdateFileSaveLeft(CCmdUI* pCmdUI);
286 afx_msg void OnUpdateFileSaveMiddle(CCmdUI* pCmdUI);
287 afx_msg void OnUpdateFileSaveRight(CCmdUI* pCmdUI);
288 afx_msg void OnRefresh();
289 afx_msg void OnUpdateFileSave(CCmdUI* pCmdUI);
290 template<bool reversed>
291 afx_msg void OnSelectLineDiff();
292 afx_msg void OnUpdateSelectLineDiff(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 OnUpdateChangePane(CCmdUI* pCmdUI);
311 afx_msg void OnWMGoto();
312 afx_msg void OnUpdateWMGoto(CCmdUI* pCmdUI);
313 afx_msg void OnUpdateScripts(CCmdUI* pCmdUI);
314 afx_msg void OnScripts(UINT nID );
315 afx_msg void OnUpdateNoPrediffer(CCmdUI* pCmdUI);
316 afx_msg void OnUpdatePrediffer(CCmdUI* pCmdUI);
317 afx_msg void OnNoPrediffer();
318 afx_msg void OnPrediffer(UINT nID );
319 afx_msg void OnMergingMode();
320 afx_msg void OnUpdateMergingMode(CCmdUI* pCmdUI);
321 afx_msg void OnUpdateMergingStatus(CCmdUI* pCmdUI);
322 afx_msg void OnHScroll (UINT nSBCode, UINT nPos, CScrollBar * pScrollBar);
323 afx_msg void OnVScroll (UINT nSBCode, UINT nPos, CScrollBar * pScrollBar);
324 afx_msg void OnEditCopyLineNumbers();
325 afx_msg void OnUpdateEditCopyLinenumbers(CCmdUI* pCmdUI);
326 afx_msg void OnViewLineDiffs();
327 afx_msg void OnUpdateViewLineDiffs(CCmdUI* pCmdUI);
328 afx_msg void OnViewLineNumbers();
329 afx_msg void OnUpdateViewLineNumbers(CCmdUI* pCmdUI);
330 afx_msg void OnViewWordWrap();
331 afx_msg void OnUpdateViewWordWrap(CCmdUI* pCmdUI);
332 afx_msg void OnOpenFile();
333 afx_msg void OnOpenFileWith();
334 afx_msg void OnOpenFileWithEditor();
335 afx_msg void OnViewSwapPanes();
336 afx_msg void OnUpdateViewSwapPanes(CCmdUI* pCmdUI);
337 afx_msg void OnUpdateNoEditScripts(CCmdUI* pCmdUI);
338 afx_msg void OnSize(UINT nType, int cx, int cy);
339 afx_msg void OnHelp();
340 afx_msg void OnViewMargin();
341 afx_msg void OnUpdateViewMargin(CCmdUI* pCmdUI);
342 afx_msg void OnUpdateViewChangeScheme(CCmdUI *pCmdUI);
343 afx_msg void OnChangeScheme(UINT nID);
344 afx_msg void OnUpdateChangeScheme(CCmdUI* pCmdUI);
345 afx_msg BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt);
346 afx_msg void OnViewZoomIn();
347 afx_msg void OnViewZoomOut();
348 afx_msg void OnViewZoomNormal();
350 DECLARE_MESSAGE_MAP()
353 #ifndef _DEBUG // debug version in DiffView.cpp
354 inline CMergeDoc* CMergeEditView::GetDocument()
355 { return (CMergeDoc*)m_pDocument; }
358 /////////////////////////////////////////////////////////////////////////////
360 //{{AFX_INSERT_LOCATION}}
361 // Microsoft Visual C++ will insert additional declarations immediately before the previous line.
363 #endif // !defined(AFX_MERGEEDITVIEW_H__0CE31CFD_4BEE_4378_ADB4_B7C9F50A9F53__INCLUDED_)