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
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 Color settings.
37 COLORREF clrDiff; /**< Difference color */
38 COLORREF clrSelDiff; /**< Selected difference color */
39 COLORREF clrDiffDeleted; /**< Difference deleted color */
40 COLORREF clrSelDiffDeleted; /**< Selected difference deleted color */
41 COLORREF clrDiffText; /**< Difference text color */
42 COLORREF clrSelDiffText; /**< Selected difference text color */
43 COLORREF clrTrivial; /**< Ignored difference color */
44 COLORREF clrTrivialDeleted; /**< Ignored difference deleted color */
45 COLORREF clrTrivialText; /**< Ignored difference text color */
46 COLORREF clrMoved; /**< Moved block color */
47 COLORREF clrMovedDeleted; /**< Moved block deleted color */
48 COLORREF clrMovedText; /**< Moved block text color */
49 COLORREF clrSelMoved; /**< Selected moved block color */
50 COLORREF clrSelMovedDeleted; /**< Selected moved block deleted color */
51 COLORREF clrSelMovedText; /**< Selected moved block text color */
52 COLORREF clrWordDiff; /**< Word difference color */
53 COLORREF clrWordDiffText; /**< Word difference text color */
54 COLORREF clrSelWordDiff; /**< Selected word difference color */
55 COLORREF clrSelWordDiffText; /**< Selected word difference text color */
59 * @brief Non-diff lines shown above diff when scrolling to it
61 const UINT CONTEXT_LINES_ABOVE = 5;
64 * @brief Non-diff lines shown below diff when scrolling to it
66 const UINT CONTEXT_LINES_BELOW = 3;
69 #define FLAG_RESCAN_WAITS_FOR_IDLE 1
72 /////////////////////////////////////////////////////////////////////////////
73 // CMergeEditView view
77 #include "GhostTextView.h"
79 class IMergeEditStatus;
85 This class is the base class for WinMerge editor panels.
86 It hooks the painting of ghost lines (GetLineColors), the shared
87 scrollbar (OnUpdateSibling...).
88 It offers the UI interface commands to work with diffs
91 If we keep GetLineColors here, we should clear DIFF flag here
92 and not in CGhostTextBuffer (when insertText/deleteText).
93 Small problem... This class doesn't derives from CGhostTextBuffer...
94 We could define a new class which derives from CGhostTextBuffer to clear the DIFF flag.
95 and calls a virtual function for additional things to do on the flag.
96 Maybe in the future...
98 class CMergeEditView : public CGhostTextView
101 CMergeEditView(); // protected constructor used by dynamic creation
102 DECLARE_DYNCREATE(CMergeEditView)
103 CCrystalParser m_xParser;
108 LONG m_nModifications;
109 IMergeEditStatus * m_piMergeEditStatus; /**< interface to status bar */
112 /** Controls if rescan is done after edit events */
113 BOOL m_bAutomaticRescan;
117 This flag is set when we receive an OnTimer command, and we want
118 to wait for theApp::OnIdle before processing it
120 BOOL fTimerWaitingForIdle;
121 COLORSETTINGS m_cachedColors; /**< Cached color settings */
123 /// active prediffer ID : helper to check the radio button
124 int m_CurrentPredifferID;
126 BOOL m_bCurrentLineIsDiff; /**< TRUE if current line is diff-line */
127 CLocationView * m_pLocationView; /**< Pointer to locationview */
128 HWND m_hLocationview; /**< Handle to locationview */
132 void RefreshOptions();
133 BOOL EnableRescan(BOOL bEnable);
134 BOOL IsReadOnly(int pane);
135 void ShowDiff(BOOL bScroll, BOOL bSelectText);
136 virtual void OnEditOperation(int nAction, LPCTSTR pszText);
137 void UpdateLineLengths();
138 BOOL IsLineInCurrentDiff(int nLine);
140 void SelectDiff(int nDiff, BOOL bScroll =TRUE, BOOL bSelectText =TRUE);
141 virtual CCrystalTextBuffer *LocateTextBuffer ();
142 void GetFullySelectedDiffs(int & firstDiff, int & lastDiff);
143 CString GetSelectedText();
144 CString GetLineText(int idx);
145 CMergeDoc* GetDocument();
146 void UpdateResources();
147 BOOL IsModified() { return (LocateTextBuffer()->IsModified()); }
148 BOOL PrimeListWithFile();
149 void SetStatusInterface(IMergeEditStatus * piMergeEditStatus);
150 void SelectArea(const CPoint & ptStart, const CPoint & ptEnd) { SetSelection(ptStart, ptEnd); } // make public
151 virtual void UpdateSiblingScrollPos (BOOL bHorz);
152 virtual int GetAdditionalTextBlocks (int nLineIndex, TEXTBLOCK *pBuf);
153 virtual COLORREF GetColor(int nColorIndex);
154 virtual void GetLineColors (int nLineIndex, COLORREF & crBkgnd,
155 COLORREF & crText, BOOL & bDrawWhitespace);
156 virtual void GetLineColors2 (int nLineIndex, DWORD ignoreFlags
157 , COLORREF & crBkgnd, COLORREF & crText, BOOL & bDrawWhitespace);
158 void WMGoto() { OnWMGoto(); };
159 void GotoLine(UINT nLine, BOOL bRealLine, int pane);
160 int GetTopLine() { return m_nTopLine; }
161 int GetScreenLines() { return CCrystalTextView::GetScreenLines(); }
162 int GetTopSubLine() { return m_nTopSubLine; }
163 int GetSubLines(int nLineIndex) { return CCrystalTextView::GetSubLines(nLineIndex); }
164 virtual int GetSubLineCount() { return CCrystalTextView::GetSubLineCount(); }
165 virtual int GetSubLineIndex(int nLineIndex) { return CCrystalTextView::GetSubLineIndex(nLineIndex); }
166 virtual void GetLineBySubLine(int nSubLineIndex, int &nLine, int &nSubLine) {
167 CCrystalTextView::GetLineBySubLine(nSubLineIndex, nLine, nSubLine);
169 virtual int GetEmptySubLines( int nLineIndex );
170 virtual void InvalidateSubLineIndexCache( int nLineIndex );
171 void RepaintLocationPane();
172 bool SetPredifferByName(const CString & prediffer);
173 void SetPredifferByMenu(UINT nID);
174 void DocumentsLoaded();
175 void SetLocationView(HWND hView, const CLocationView * pView = NULL);
176 void UpdateLocationViewPosition(int nTopLine = -1, int nBottomLine = -1);
177 virtual void RecalcPageLayouts(CDC * pdc, CPrintInfo * pInfo);
178 virtual void GetPrintHeaderText(int nPageNum, CString & text);
179 virtual void PrintHeader(CDC * pdc, int nPageNum);
180 virtual void PrintFooter(CDC * pdc, int nPageNum);
182 // to customize the mergeview menu
183 static HMENU createScriptsSubmenu(HMENU hMenu);
184 HMENU createPrediffersSubmenu(HMENU hMenu);
186 bool IsInitialized() const;
187 BOOL IsCursorInDiff() const;
188 BOOL IsDiffVisible(int nDiff);
191 // ClassWizard generated virtual function overrides
192 //{{AFX_VIRTUAL(CMergeEditView)
194 virtual void OnInitialUpdate();
196 virtual void OnActivateView(BOOL bActivate, CView* pActivateView, CView* pDeactiveView);
197 virtual void OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint);
198 virtual BOOL PreTranslateMessage(MSG* pMsg);
199 virtual void OnBeginPrinting (CDC * pDC, CPrintInfo * pInfo);
200 virtual void OnEndPrinting (CDC * pDC, CPrintInfo * pInfo);
201 virtual void OnPrint(CDC* pDC, CPrintInfo* pInfo);
206 virtual ~CMergeEditView();
207 virtual void OnUpdateSibling (CCrystalTextView * pUpdateSource, BOOL bHorz);
208 virtual void OnUpdateCaret();
209 BOOL MergeModeKeyDown(MSG* pMsg);
210 int FindPrediffer(const CString & prediffer) const;
211 BOOL IsDiffVisible(const DIFFRANGE& diff, int nLinesBelow = 0);
213 // Generated message map functions
215 //{{AFX_MSG(CMergeEditView)
216 afx_msg void OnCurdiff();
217 afx_msg void OnUpdateCurdiff(CCmdUI* pCmdUI);
218 afx_msg void OnEditCopy();
219 afx_msg void OnUpdateEditCopy(CCmdUI* pCmdUI);
220 afx_msg void OnEditCut();
221 afx_msg void OnUpdateEditCut(CCmdUI* pCmdUI);
222 afx_msg void OnEditPaste();
223 afx_msg void OnUpdateEditPaste(CCmdUI* pCmdUI);
224 afx_msg void OnEditUndo();
225 afx_msg void OnFirstdiff();
226 afx_msg void OnUpdateFirstdiff(CCmdUI* pCmdUI);
227 afx_msg void OnLastdiff();
228 afx_msg void OnUpdateLastdiff(CCmdUI* pCmdUI);
229 afx_msg void OnNextdiff();
230 afx_msg void OnUpdateNextdiff(CCmdUI* pCmdUI);
231 afx_msg void OnPrevdiff();
232 afx_msg void OnUpdatePrevdiff(CCmdUI* pCmdUI);
233 afx_msg void OnLButtonDblClk(UINT nFlags, CPoint point);
234 afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
235 afx_msg void OnAllLeft();
236 afx_msg void OnUpdateAllLeft(CCmdUI* pCmdUI);
237 afx_msg void OnAllRight();
238 afx_msg void OnUpdateAllRight(CCmdUI* pCmdUI);
239 afx_msg void OnL2r();
240 afx_msg void OnUpdateL2r(CCmdUI* pCmdUI);
241 afx_msg void OnR2l();
242 afx_msg void OnUpdateR2l(CCmdUI* pCmdUI);
243 afx_msg void OnUpdateEditUndo(CCmdUI* pCmdUI);
244 afx_msg void OnEditRedo();
245 afx_msg void OnUpdateEditRedo(CCmdUI* pCmdUI);
246 afx_msg void OnTimer(UINT_PTR nIDEvent);
247 afx_msg void OnUpdateFileSaveLeft(CCmdUI* pCmdUI);
248 afx_msg void OnUpdateFileSaveRight(CCmdUI* pCmdUI);
249 afx_msg void OnRefresh();
250 afx_msg void OnUpdateFileSave(CCmdUI* pCmdUI);
251 afx_msg void OnSelectLineDiff();
252 afx_msg void OnUpdateSelectLineDiff(CCmdUI* pCmdUI);
253 afx_msg void OnContextMenu(CWnd* pWnd, CPoint point);
254 afx_msg void OnUpdateEditReplace(CCmdUI* pCmdUI);
255 afx_msg void OnLeftReadOnly();
256 afx_msg void OnUpdateLeftReadOnly(CCmdUI* pCmdUI);
257 afx_msg void OnRightReadOnly();
258 afx_msg void OnUpdateRightReadOnly(CCmdUI* pCmdUI);
259 afx_msg void OnUpdateStatusLeftRO(CCmdUI* pCmdUI);
260 afx_msg void OnUpdateStatusRightRO(CCmdUI* pCmdUI);
261 afx_msg void OnConvertEolTo(UINT nID );
262 afx_msg void OnUpdateConvertEolTo(CCmdUI* pCmdUI);
263 afx_msg void OnUpdateStatusLeftEOL(CCmdUI* pCmdUI);
264 afx_msg void OnUpdateStatusRightEOL(CCmdUI* pCmdUI);
265 afx_msg void OnL2RNext();
266 afx_msg void OnUpdateL2RNext(CCmdUI* pCmdUI);
267 afx_msg void OnR2LNext();
268 afx_msg void OnUpdateR2LNext(CCmdUI* pCmdUI);
269 afx_msg void OnChangePane();
270 afx_msg void OnUpdateChangePane(CCmdUI* pCmdUI);
271 afx_msg void OnWMGoto();
272 afx_msg void OnUpdateWMGoto(CCmdUI* pCmdUI);
273 afx_msg void OnUpdateScripts(CCmdUI* pCmdUI);
274 afx_msg void OnScripts(UINT nID );
275 afx_msg void OnUpdateNoPrediffer(CCmdUI* pCmdUI);
276 afx_msg void OnUpdatePrediffer(CCmdUI* pCmdUI);
277 afx_msg void OnNoPrediffer();
278 afx_msg void OnPrediffer(UINT nID );
279 afx_msg void OnMergingMode();
280 afx_msg void OnUpdateMergingMode(CCmdUI* pCmdUI);
281 afx_msg void OnUpdateMergingStatus(CCmdUI* pCmdUI);
282 afx_msg void OnWindowClose();
283 afx_msg void OnVScroll (UINT nSBCode, UINT nPos, CScrollBar * pScrollBar);
284 afx_msg void OnEditCopyLineNumbers();
285 afx_msg void OnUpdateEditCopyLinenumbers(CCmdUI* pCmdUI);
286 afx_msg void OnViewLineDiffs();
287 afx_msg void OnUpdateViewLineDiffs(CCmdUI* pCmdUI);
288 afx_msg void OnViewLineNumbers();
289 afx_msg void OnUpdateViewLineNumbers(CCmdUI* pCmdUI);
290 afx_msg void OnViewWordWrap();
291 afx_msg void OnUpdateViewWordWrap(CCmdUI* pCmdUI);
292 afx_msg void OnOpenFile();
293 afx_msg void OnOpenFileWith();
294 afx_msg void OnOpenFileWithEditor();
295 afx_msg void OnViewSwapPanes();
296 afx_msg void OnUpdateViewSwapPanes(CCmdUI* pCmdUI);
297 afx_msg void OnUpdateNoEditScripts(CCmdUI* pCmdUI);
298 afx_msg void OnSize(UINT nType, int cx, int cy);
299 afx_msg void OnHelp();
300 afx_msg void OnViewMargin();
301 afx_msg void OnUpdateViewMargin(CCmdUI* pCmdUI);
302 afx_msg void OnUpdateViewChangeScheme(CCmdUI *pCmdUI);
303 afx_msg void OnChangeScheme(UINT nID);
304 afx_msg void OnUpdateChangeScheme(CCmdUI* pCmdUI);
306 DECLARE_MESSAGE_MAP()
309 #ifndef _DEBUG // debug version in DiffView.cpp
310 inline CMergeDoc* CMergeEditView::GetDocument()
311 { return (CMergeDoc*)m_pDocument; }
314 /////////////////////////////////////////////////////////////////////////////
316 //{{AFX_INSERT_LOCATION}}
317 // Microsoft Visual C++ will insert additional declarations immediately before the previous line.
319 #endif // !defined(AFX_MERGEEDITVIEW_H__0CE31CFD_4BEE_4378_ADB4_B7C9F50A9F53__INCLUDED_)