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
29 * @brief Non-diff lines shown above diff when scrolling to it
31 const UINT CONTEXT_LINES_ABOVE = 5;
34 * @brief Non-diff lines shown below diff when scrolling to it
36 const UINT CONTEXT_LINES_BELOW = 3;
39 #define FLAG_RESCAN_WAITS_FOR_IDLE 1
42 /////////////////////////////////////////////////////////////////////////////
43 // CMergeEditView view
45 #include "GhostTextView.h"
46 #include "OptionsDiffColors.h"
48 class IMergeEditStatus;
54 This class is the base class for WinMerge editor panels.
55 It hooks the painting of ghost lines (GetLineColors), the shared
56 scrollbar (OnUpdateSibling...).
57 It offers the UI interface commands to work with diffs
60 If we keep GetLineColors here, we should clear DIFF flag here
61 and not in CGhostTextBuffer (when insertText/deleteText).
62 Small problem... This class doesn't derives from CGhostTextBuffer...
63 We could define a new class which derives from CGhostTextBuffer to clear the DIFF flag.
64 and calls a virtual function for additional things to do on the flag.
65 Maybe in the future...
67 class CMergeEditView : public CGhostTextView
70 CMergeEditView(); // protected constructor used by dynamic creation
71 DECLARE_DYNCREATE(CMergeEditView)
72 CCrystalParser m_xParser; /**< Syntax parser used for syntax highlighting. */
77 * Index of pane this view is attached to.
78 * This indicates the pane number the view is attached to. If we swap panes
79 * then these indexes are changed.
82 IMergeEditStatus * m_piMergeEditStatus; /**< interface to status bar */
86 * Are automatic rescans enabled?
87 * If automatic rescans are enabled then we rescan files after edit
88 * events, unless timer suppresses rescan. We suppress rescans within
89 * certain time from previous rescan.
91 bool m_bAutomaticRescan;
92 /// first line of diff (first displayable line)
94 /// last line of diff (last displayable line)
99 This flag is set when we receive an OnTimer command, and we want
100 to wait for theApp::OnIdle before processing it
102 bool fTimerWaitingForIdle;
103 COLORSETTINGS m_cachedColors; /**< Cached color settings */
105 /// active prediffer ID : helper to check the radio button
106 int m_CurrentPredifferID;
108 bool m_bCurrentLineIsDiff; /**< TRUE if cursor is in diff line */
109 CLocationView * m_pLocationView; /**< Pointer to locationview */
113 void RefreshOptions();
114 bool EnableRescan(bool bEnable);
115 bool IsReadOnly(int pane) const;
116 void ShowDiff(bool bScroll, bool bSelectText);
117 virtual void OnEditOperation(int nAction, LPCTSTR pszText, int cchText);
118 void UpdateLineLengths();
119 bool IsLineInCurrentDiff(int nLine) const;
121 void SelectDiff(int nDiff, bool bScroll = true, bool bSelectText = true);
122 virtual CCrystalTextBuffer *LocateTextBuffer ();
123 const CCrystalTextBuffer *LocateTextBuffer () const { return const_cast<CMergeEditView *>(this)->LocateTextBuffer(); };
124 void GetFullySelectedDiffs(int & firstDiff, int & lastDiff);
125 CString GetSelectedText();
126 CString GetLineText(int idx);
127 CMergeDoc* GetDocument();
128 const CMergeDoc *GetDocument() const { return const_cast<CMergeEditView *>(this)->GetDocument(); }
129 void UpdateResources();
130 BOOL IsModified() { return (LocateTextBuffer()->IsModified()); }
131 void PrimeListWithFile();
132 void SetStatusInterface(IMergeEditStatus * piMergeEditStatus);
133 void SelectArea(const CPoint & ptStart, const CPoint & ptEnd) { SetSelection(ptStart, ptEnd); } // make public
134 void GetSelection(CPoint &ptStart, CPoint &ptEnd) { CCrystalTextView::GetSelection(ptStart, ptEnd); }
135 virtual void UpdateSiblingScrollPos (bool bHorz);
136 virtual int GetAdditionalTextBlocks (int nLineIndex, TEXTBLOCK *&pBuf);
137 virtual COLORREF GetColor(int nColorIndex);
138 virtual void GetLineColors (int nLineIndex, COLORREF & crBkgnd,
139 COLORREF & crText, bool & bDrawWhitespace);
140 virtual void GetLineColors2 (int nLineIndex, DWORD ignoreFlags
141 , COLORREF & crBkgnd, COLORREF & crText, bool & bDrawWhitespace);
142 void WMGoto() { OnWMGoto(); };
143 void GotoLine(UINT nLine, bool bRealLine, int pane);
144 int GetTopLine() const { return m_nTopLine; }
145 int GetScreenLines() { return CCrystalTextView::GetScreenLines(); }
146 int GetTopSubLine() const { return m_nTopSubLine; }
147 int GetSubLines(int nLineIndex) { return CCrystalTextView::GetSubLines(nLineIndex); }
148 virtual int GetSubLineCount() { return CCrystalTextView::GetSubLineCount(); }
149 virtual int GetSubLineIndex(int nLineIndex) { return CCrystalTextView::GetSubLineIndex(nLineIndex); }
150 virtual void GetLineBySubLine(int nSubLineIndex, int &nLine, int &nSubLine) {
151 CCrystalTextView::GetLineBySubLine(nSubLineIndex, nLine, nSubLine);
153 virtual int GetEmptySubLines( int nLineIndex );
154 virtual void InvalidateSubLineIndexCache( int nLineIndex );
155 void RepaintLocationPane();
156 bool SetPredifferByName(const CString & prediffer);
157 void SetPredifferByMenu(UINT nID);
158 void DocumentsLoaded();
159 void SetLocationView(const CLocationView * pView = NULL);
160 void UpdateLocationViewPosition(int nTopLine = -1, int nBottomLine = -1);
161 virtual void RecalcPageLayouts(CDC * pdc, CPrintInfo * pInfo);
162 virtual void GetPrintHeaderText(int nPageNum, CString & text);
163 virtual void PrintHeader(CDC * pdc, int nPageNum);
164 virtual void PrintFooter(CDC * pdc, int nPageNum);
165 virtual void SetWordWrapping( bool bWordWrap );
166 void UpdateStatusbar();
167 CMergeEditView *GetGroupView(int nPane) const;
168 bool IsDetailViewPane() const;
170 virtual void OnDisplayDiff(int nDiff=0);
172 // to customize the mergeview menu
173 static HMENU createScriptsSubmenu(HMENU hMenu);
174 HMENU createPrediffersSubmenu(HMENU hMenu);
176 bool IsInitialized() const;
177 bool IsCursorInDiff() const;
178 bool IsDiffVisible(int nDiff);
179 void ZoomText(short amount);
182 // ClassWizard generated virtual function overrides
183 //{{AFX_VIRTUAL(CMergeEditView)
185 virtual void OnInitialUpdate();
187 virtual void OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView);
188 virtual void OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint);
189 virtual BOOL PreTranslateMessage(MSG* pMsg);
190 virtual void OnBeginPrinting (CDC * pDC, CPrintInfo * pInfo);
191 virtual void OnEndPrinting (CDC * pDC, CPrintInfo * pInfo);
192 virtual void OnPrint(CDC* pDC, CPrintInfo* pInfo);
197 virtual ~CMergeEditView();
198 virtual void OnUpdateSibling (CCrystalTextView * pUpdateSource, BOOL bHorz);
199 virtual void OnUpdateCaret();
200 bool MergeModeKeyDown(MSG* pMsg);
201 int FindPrediffer(LPCTSTR prediffer) const;
202 bool IsDiffVisible(const DIFFRANGE& diff, int nLinesBelow = 0);
203 void OnNext3wayDiff(int type);
204 void OnUpdateNext3wayDiff(CCmdUI* pCmdUI, int type);
205 void OnPrev3wayDiff(int type);
206 void OnUpdatePrev3wayDiff(CCmdUI* pCmdUI, int type);
208 // Generated message map functions
210 //{{AFX_MSG(CMergeEditView)
211 afx_msg void OnCurdiff();
212 afx_msg void OnUpdateCurdiff(CCmdUI* pCmdUI);
213 afx_msg void OnEditCopy();
214 afx_msg void OnUpdateEditCopy(CCmdUI* pCmdUI);
215 afx_msg void OnEditCut();
216 afx_msg void OnUpdateEditCut(CCmdUI* pCmdUI);
217 afx_msg void OnEditPaste();
218 afx_msg void OnUpdateEditPaste(CCmdUI* pCmdUI);
219 afx_msg void OnEditUndo();
220 afx_msg void OnFirstdiff();
221 afx_msg void OnUpdateFirstdiff(CCmdUI* pCmdUI);
222 afx_msg void OnLastdiff();
223 afx_msg void OnUpdateLastdiff(CCmdUI* pCmdUI);
224 afx_msg void OnNextdiff();
225 afx_msg void OnUpdateNextdiff(CCmdUI* pCmdUI);
226 afx_msg void OnPrevdiff();
227 afx_msg void OnUpdatePrevdiff(CCmdUI* pCmdUI);
228 afx_msg void OnNextConflict();
229 afx_msg void OnUpdateNextConflict(CCmdUI* pCmdUI);
230 afx_msg void OnPrevConflict();
231 afx_msg void OnUpdatePrevConflict(CCmdUI* pCmdUI);
232 afx_msg void OnNextdiffLM();
233 afx_msg void OnUpdateNextdiffLM(CCmdUI* pCmdUI);
234 afx_msg void OnPrevdiffLM();
235 afx_msg void OnUpdatePrevdiffLM(CCmdUI* pCmdUI);
236 afx_msg void OnNextdiffLR();
237 afx_msg void OnUpdateNextdiffLR(CCmdUI* pCmdUI);
238 afx_msg void OnPrevdiffLR();
239 afx_msg void OnUpdatePrevdiffLR(CCmdUI* pCmdUI);
240 afx_msg void OnNextdiffMR();
241 afx_msg void OnUpdateNextdiffMR(CCmdUI* pCmdUI);
242 afx_msg void OnPrevdiffMR();
243 afx_msg void OnUpdatePrevdiffMR(CCmdUI* pCmdUI);
244 afx_msg void OnNextdiffLO();
245 afx_msg void OnUpdateNextdiffLO(CCmdUI* pCmdUI);
246 afx_msg void OnPrevdiffLO();
247 afx_msg void OnUpdatePrevdiffLO(CCmdUI* pCmdUI);
248 afx_msg void OnNextdiffMO();
249 afx_msg void OnUpdateNextdiffMO(CCmdUI* pCmdUI);
250 afx_msg void OnPrevdiffMO();
251 afx_msg void OnUpdatePrevdiffMO(CCmdUI* pCmdUI);
252 afx_msg void OnNextdiffRO();
253 afx_msg void OnUpdateNextdiffRO(CCmdUI* pCmdUI);
254 afx_msg void OnPrevdiffRO();
255 afx_msg void OnUpdatePrevdiffRO(CCmdUI* pCmdUI);
256 afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
257 afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
258 afx_msg void OnAllLeft();
259 afx_msg void OnUpdateAllLeft(CCmdUI* pCmdUI);
260 afx_msg void OnAllRight();
261 afx_msg void OnUpdateAllRight(CCmdUI* pCmdUI);
262 afx_msg void OnAutoMerge();
263 afx_msg void OnUpdateAutoMerge(CCmdUI* pCmdUI);
264 afx_msg void OnX2Y(int srcPane, int dstPane, const String& message);
265 afx_msg void OnUpdateX2Y(int dstPane, CCmdUI* pCmdUI);
266 afx_msg void OnL2r();
267 afx_msg void OnUpdateL2r(CCmdUI* pCmdUI);
268 afx_msg void OnR2l();
269 afx_msg void OnUpdateR2l(CCmdUI* pCmdUI);
270 afx_msg void OnCopyFromLeft();
271 afx_msg void OnUpdateCopyFromLeft(CCmdUI* pCmdUI);
272 afx_msg void OnCopyFromRight();
273 afx_msg void OnUpdateCopyFromRight(CCmdUI* pCmdUI);
274 afx_msg void OnAddSyncPoint();
275 afx_msg void OnUpdateAddSyncPoint(CCmdUI* pCmdUI);
276 afx_msg void OnClearSyncPoints();
277 afx_msg void OnUpdateClearSyncPoints(CCmdUI* pCmdUI);
278 afx_msg void OnUpdateEditUndo(CCmdUI* pCmdUI);
279 afx_msg void OnEditRedo();
280 afx_msg void OnUpdateEditRedo(CCmdUI* pCmdUI);
281 afx_msg void OnTimer(UINT_PTR nIDEvent);
282 afx_msg void OnUpdateFileSaveLeft(CCmdUI* pCmdUI);
283 afx_msg void OnUpdateFileSaveMiddle(CCmdUI* pCmdUI);
284 afx_msg void OnUpdateFileSaveRight(CCmdUI* pCmdUI);
285 afx_msg void OnRefresh();
286 afx_msg void OnUpdateFileSave(CCmdUI* pCmdUI);
287 template<bool reversed>
288 afx_msg void OnSelectLineDiff();
289 afx_msg void OnUpdateSelectLineDiff(CCmdUI* pCmdUI);
290 afx_msg void OnContextMenu(CWnd* pWnd, CPoint point);
291 afx_msg void OnUpdateEditReplace(CCmdUI* pCmdUI);
292 afx_msg void OnLeftReadOnly();
293 afx_msg void OnUpdateLeftReadOnly(CCmdUI* pCmdUI);
294 afx_msg void OnMiddleReadOnly();
295 afx_msg void OnUpdateMiddleReadOnly(CCmdUI* pCmdUI);
296 afx_msg void OnRightReadOnly();
297 afx_msg void OnUpdateRightReadOnly(CCmdUI* pCmdUI);
298 afx_msg void OnUpdateStatusRO(CCmdUI* pCmdUI);
299 afx_msg void OnConvertEolTo(UINT nID );
300 afx_msg void OnUpdateConvertEolTo(CCmdUI* pCmdUI);
301 afx_msg void OnUpdateStatusEOL(CCmdUI* pCmdUI);
302 afx_msg void OnL2RNext();
303 afx_msg void OnUpdateL2RNext(CCmdUI* pCmdUI);
304 afx_msg void OnR2LNext();
305 afx_msg void OnUpdateR2LNext(CCmdUI* pCmdUI);
306 afx_msg void OnChangePane();
307 afx_msg void OnUpdateChangePane(CCmdUI* pCmdUI);
308 afx_msg void OnWMGoto();
309 afx_msg void OnUpdateWMGoto(CCmdUI* pCmdUI);
310 afx_msg void OnUpdateScripts(CCmdUI* pCmdUI);
311 afx_msg void OnScripts(UINT nID );
312 afx_msg void OnUpdateNoPrediffer(CCmdUI* pCmdUI);
313 afx_msg void OnUpdatePrediffer(CCmdUI* pCmdUI);
314 afx_msg void OnNoPrediffer();
315 afx_msg void OnPrediffer(UINT nID );
316 afx_msg void OnHScroll (UINT nSBCode, UINT nPos, CScrollBar * pScrollBar);
317 afx_msg void OnVScroll (UINT nSBCode, UINT nPos, CScrollBar * pScrollBar);
318 afx_msg void OnEditCopyLineNumbers();
319 afx_msg void OnUpdateEditCopyLinenumbers(CCmdUI* pCmdUI);
320 afx_msg void OnViewLineDiffs();
321 afx_msg void OnUpdateViewLineDiffs(CCmdUI* pCmdUI);
322 afx_msg void OnViewLineNumbers();
323 afx_msg void OnUpdateViewLineNumbers(CCmdUI* pCmdUI);
324 afx_msg void OnViewWordWrap();
325 afx_msg void OnUpdateViewWordWrap(CCmdUI* pCmdUI);
326 afx_msg void OnOpenFile();
327 afx_msg void OnOpenFileWith();
328 afx_msg void OnOpenFileWithEditor();
329 afx_msg void OnViewSwapPanes();
330 afx_msg void OnUpdateViewSwapPanes(CCmdUI* pCmdUI);
331 afx_msg void OnUpdateNoEditScripts(CCmdUI* pCmdUI);
332 afx_msg void OnSize(UINT nType, int cx, int cy);
333 afx_msg void OnHelp();
334 afx_msg void OnViewMargin();
335 afx_msg void OnUpdateViewMargin(CCmdUI* pCmdUI);
336 afx_msg void OnUpdateViewChangeScheme(CCmdUI *pCmdUI);
337 afx_msg void OnChangeScheme(UINT nID);
338 afx_msg void OnUpdateChangeScheme(CCmdUI* pCmdUI);
339 afx_msg BOOL OnMouseWheel(UINT nFlags, short zDelta, CPoint pt);
340 afx_msg void OnViewZoomIn();
341 afx_msg void OnViewZoomOut();
342 afx_msg void OnViewZoomNormal();
344 DECLARE_MESSAGE_MAP()
347 #ifndef _DEBUG // debug version in DiffView.cpp
348 inline CMergeDoc* CMergeEditView::GetDocument()
349 { return (CMergeDoc*)m_pDocument; }
352 /////////////////////////////////////////////////////////////////////////////
354 //{{AFX_INSERT_LOCATION}}
355 // Microsoft Visual C++ will insert additional declarations immediately before the previous line.