OSDN Git Service

Add "" at dir and url of clone dialog to avoid space in path
[tortoisegit/TortoiseGitJp.git] / src / TortoiseMerge / BaseView.h
1 // TortoiseMerge - a Diff/Patch program\r
2 \r
3 // Copyright (C) 2003-2008 - TortoiseSVN\r
4 \r
5 // This program is free software; you can redistribute it and/or\r
6 // modify it under the terms of the GNU General Public License\r
7 // as published by the Free Software Foundation; either version 2\r
8 // of the License, or (at your option) any later version.\r
9 \r
10 // This program is distributed in the hope that it will be useful,\r
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of\r
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
13 // GNU General Public License for more details.\r
14 \r
15 // You should have received a copy of the GNU General Public License\r
16 // along with this program; if not, write to the Free Software Foundation,\r
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.\r
18 //\r
19 #pragma once\r
20 #include "DiffData.h"\r
21 //#include "SVNLineDiff.h"\r
22 #include "ScrollTool.h"\r
23 #include "Undo.h"\r
24 #include "LocatorBar.h"\r
25 \r
26 /**\r
27  * \ingroup TortoiseMerge\r
28  *\r
29  * View class providing the basic functionality for\r
30  * showing diffs. Has three parent classes which inherit\r
31  * from this base class: CLeftView, CRightView and CBottomView.\r
32  */\r
33 class CBaseView : public CView\r
34 {\r
35     DECLARE_DYNCREATE(CBaseView)\r
36 friend class CLineDiffBar;\r
37 public:\r
38         CBaseView();\r
39         virtual ~CBaseView();\r
40 \r
41 public:\r
42         /**\r
43          * Indicates that the underlying document has been updated. Reloads all\r
44          * data and redraws the view.\r
45          */\r
46         virtual void    DocumentUpdated();\r
47         /**\r
48          * Returns the number of lines visible on the view.\r
49          */\r
50         int                             GetScreenLines();\r
51         /**\r
52          * Scrolls the view to the given line.\r
53          * \param nNewTopLine The new top line to scroll the view to\r
54          * \param bTrackScrollBar If TRUE, then the scrollbars are affected too.\r
55          */\r
56         void                    ScrollToLine(int nNewTopLine, BOOL bTrackScrollBar = TRUE);\r
57         void                    ScrollAllToLine(int nNewTopLine, BOOL bTrackScrollBar = TRUE);\r
58         void                    ScrollSide(int delta);\r
59         void                    GoToLine(int nNewLine, BOOL bAll = TRUE);\r
60         void                    ScrollToChar(int nNewOffsetChar, BOOL bTrackScrollBar = TRUE);\r
61         void                    UseCaret(bool bUse = true) {m_bCaretHidden = !bUse;}\r
62         bool                    HasCaret() {return !m_bCaretHidden;}\r
63         void                    SetCaretPosition(POINT pt) {m_ptCaretPos = pt ; m_nCaretGoalPos = pt.x; UpdateCaret();}\r
64         void                    EnsureCaretVisible();\r
65         void                    UpdateCaret();\r
66         void                    ClearSelection();\r
67         void                    RefreshViews();\r
68 \r
69         void                    SelectLines(int nLine1, int nLine2 = -1);\r
70         void                    HiglightLines(int start, int end = -1);\r
71         inline BOOL             IsHidden() const  {return m_bIsHidden;}\r
72         inline void             SetHidden(BOOL bHidden) {m_bIsHidden = bHidden;}\r
73         inline BOOL             IsModified() const  {return m_bModified;}\r
74         void                    SetModified(BOOL bModified = TRUE) {m_bModified = bModified;}\r
75         BOOL                    HasSelection() {return (!((m_nSelBlockEnd < 0)||(m_nSelBlockStart < 0)||(m_nSelBlockStart > m_nSelBlockEnd)));}\r
76         BOOL                    HasTextSelection() {return ((m_ptSelectionStartPos.x != m_ptSelectionEndPos.x)||(m_ptSelectionStartPos.y != m_ptSelectionEndPos.y));}\r
77         BOOL                    GetSelection(int& start, int& end) {start=m_nSelBlockStart; end=m_nSelBlockEnd; return HasSelection();}\r
78         void                    SetInlineWordDiff(bool bWord) {m_bInlineWordDiff = bWord;}\r
79 \r
80         BOOL                    IsLineRemoved(int nLineIndex);\r
81         bool                    IsBlockWhitespaceOnly(int nLineIndex, bool& bIdentical);\r
82         bool                    IsLineConflicted(int nLineIndex);\r
83 \r
84         CViewData *             m_pViewData;\r
85         CViewData *             m_pOtherViewData;\r
86 \r
87         CString                 m_sWindowName;          ///< The name of the view which is shown as a window title to the user\r
88         CString                 m_sFullFilePath;        ///< The full path of the file shown\r
89         CFileTextLines::UnicodeType texttype;   ///< the text encoding this view uses\r
90         EOL lineendings; ///< the line endings the view uses\r
91 \r
92         BOOL                    m_bViewWhitespace;      ///< If TRUE, then SPACE and TAB are shown as special characters\r
93         BOOL                    m_bShowInlineDiff;      ///< If TRUE, diffs in lines are marked colored\r
94         bool                    m_bShowSelection;       ///< If true, selection bars are shown and selected text darkened\r
95         int                             m_nTopLine;                     ///< The topmost text line in the view\r
96 \r
97         static CLocatorBar * m_pwndLocator;     ///< Pointer to the locator bar on the left\r
98         static CLineDiffBar * m_pwndLineDiffBar;        ///< Pointer to the line diff bar at the bottom\r
99         static CMFCStatusBar * m_pwndStatusBar;///< Pointer to the status bar\r
100         static CMainFrame * m_pMainFrame;       ///< Pointer to the mainframe\r
101 \r
102         void                    GoToFirstDifference();\r
103         void                    AddEmptyLine(int nLineIndex);\r
104 protected:\r
105         virtual BOOL    PreCreateWindow(CREATESTRUCT& cs);\r
106         virtual void    OnDraw(CDC * pDC);\r
107         virtual INT_PTR OnToolHitTest(CPoint point, TOOLINFO* pTI) const;\r
108         BOOL                    OnToolTipNotify(UINT id, NMHDR *pNMHDR, LRESULT *pResult);\r
109         afx_msg void    OnHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);\r
110         afx_msg void    OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar);\r
111         afx_msg BOOL    OnEraseBkgnd(CDC* pDC);\r
112         afx_msg int             OnCreate(LPCREATESTRUCT lpCreateStruct);\r
113         afx_msg void    OnDestroy();\r
114         afx_msg void    OnSize(UINT nType, int cx, int cy);\r
115         afx_msg BOOL    OnMouseWheel(UINT nFlags, short zDelta, CPoint pt);\r
116         afx_msg BOOL    OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);\r
117         afx_msg void    OnKillFocus(CWnd* pNewWnd);\r
118         afx_msg void    OnSetFocus(CWnd* pOldWnd);\r
119         afx_msg void    OnContextMenu(CWnd* pWnd, CPoint point);\r
120         afx_msg void    OnMergeNextdifference();\r
121         afx_msg void    OnMergePreviousdifference();\r
122         afx_msg void    OnMergePreviousconflict();\r
123         afx_msg void    OnMergeNextconflict();\r
124         afx_msg void    OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags);\r
125         afx_msg void    OnLButtonDown(UINT nFlags, CPoint point);\r
126         afx_msg void    OnEditCopy();\r
127         afx_msg void    OnMouseMove(UINT nFlags, CPoint point);\r
128         afx_msg void    OnMouseLeave();\r
129         afx_msg void    OnChar(UINT nChar, UINT nRepCnt, UINT nFlags);\r
130         afx_msg void    OnCaretDown();\r
131         afx_msg void    OnCaretLeft();\r
132         afx_msg void    OnCaretRight();\r
133         afx_msg void    OnCaretUp();\r
134         afx_msg void    OnCaretWordleft();\r
135         afx_msg void    OnCaretWordright();\r
136         afx_msg void    OnEditCut();\r
137         afx_msg void    OnEditPaste();\r
138 \r
139         DECLARE_MESSAGE_MAP()\r
140 \r
141 protected:\r
142         void                    DrawHeader(CDC *pdc, const CRect &rect);\r
143         void                    DrawMargin(CDC *pdc, const CRect &rect, int nLineIndex);\r
144         void                    DrawSingleLine(CDC *pDC, const CRect &rc, int nLineIndex);\r
145         bool                    DrawInlineDiff(CDC *pDC, const CRect &rc, int nLineIndex, const CString &line, CPoint &origin);\r
146         /**\r
147          * Draws the horizontal lines around current diff block or selection block.\r
148          */\r
149         void                    DrawBlockLine(CDC *pDC, const CRect &rc, int nLineIndex);\r
150         /**\r
151          * Draws the line ending 'char'.\r
152          */\r
153         void                    DrawLineEnding(CDC *pDC, const CRect &rc, int nLineIndex, const CPoint& origin);\r
154         void                    ExpandChars(LPCTSTR pszChars, int nOffset, int nCount, CString &line);\r
155 \r
156         void                    RecalcVertScrollBar(BOOL bPositionOnly = FALSE);\r
157         void                    RecalcAllVertScrollBars(BOOL bPositionOnly = FALSE);\r
158         void                    RecalcHorzScrollBar(BOOL bPositionOnly = FALSE);\r
159         void                    RecalcAllHorzScrollBars(BOOL bPositionOnly = FALSE);\r
160 \r
161         void                    OnDoMouseWheel(UINT nFlags, short zDelta, CPoint pt);\r
162         void                    OnDoHScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar, CBaseView * master);\r
163         void                    OnDoVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar, CBaseView * master);\r
164 \r
165         void                    SetupSelection(int start, int end);\r
166         void                    ShowDiffLines(int nLine);\r
167         \r
168         int                             GetTabSize() const {return m_nTabSize;}\r
169 \r
170         int                             GetLineActualLength(int index) const;\r
171         int                             GetLineCount() const;\r
172         void                    CalcLineCharDim();\r
173         int                             GetLineHeight();\r
174         int                             GetCharWidth();\r
175         int                             GetMaxLineLength();\r
176         int                             GetLineLength(int index) const;\r
177         int                             GetScreenChars();\r
178         int                             GetAllMinScreenChars() const;\r
179         int                             GetAllMaxLineLength() const;\r
180         int                             GetAllLineCount() const;\r
181         int                             GetAllMinScreenLines() const;\r
182         LPCTSTR                 GetLineChars(int index) const;\r
183         int                             GetLineNumber(int index) const;\r
184         CFont *                 GetFont(BOOL bItalic = FALSE, BOOL bBold = FALSE, BOOL bStrikeOut = FALSE);\r
185         int                             GetLineFromPoint(CPoint point);\r
186         int                             GetMarginWidth();\r
187         COLORREF                IntenseColor(long scale, COLORREF col);\r
188         COLORREF                InlineDiffColor(int nLineIndex);\r
189         void                    CheckOtherView();\r
190         static CString  GetWhitespaceBlock(CViewData *viewData, int nLineIndex);\r
191 \r
192         /// Returns true if selection should be kept\r
193         virtual bool    OnContextMenu(CPoint point, int nLine, DiffStates state);\r
194         /**\r
195          * Updates the status bar pane. Call this if the document changed.\r
196          */\r
197         void                    UpdateStatusBar();\r
198 \r
199         void                    UseTheirAndYourBlock(viewstate &rightstate, viewstate &bottomstate, viewstate &leftstate);\r
200         void                    UseYourAndTheirBlock(viewstate &rightstate, viewstate &bottomstate, viewstate &leftstate);\r
201         void                    UseBothLeftFirst(viewstate &rightstate, viewstate &leftstate);\r
202         void                    UseBothRightFirst(viewstate &rightstate, viewstate &leftstate);\r
203 \r
204         bool                    IsLeftViewGood() const {return ((m_pwndLeft)&&(m_pwndLeft->IsWindowVisible()));}\r
205         bool                    IsRightViewGood() const {return ((m_pwndRight)&&(m_pwndRight->IsWindowVisible()));}\r
206         bool                    IsBottomViewGood() const {return ((m_pwndBottom)&&(m_pwndBottom->IsWindowVisible()));}\r
207 \r
208         int                             CalculateActualOffset(int nLineIndex, int nCharIndex) const;\r
209         int                             CalculateCharIndex(int nLineIndex, int nActualOffset) const;\r
210         POINT                   TextToClient(const POINT& point);\r
211         void                    DrawText(CDC * pDC, const CRect &rc, LPCTSTR text, int textlength, int nLineIndex, POINT coords, bool bModified, bool bInlineDiff);\r
212         void                    ClearCurrentSelection();\r
213         void                    AdjustSelection();\r
214         void            SelectNextBlock(int nDirection, bool bConflict);\r
215 \r
216         void                    RemoveLine(int nLineIndex);\r
217         void                    RemoveSelectedText();\r
218         void                    PasteText();\r
219         void                    AddUndoLine(int nLine, bool bAddEmptyLine = false);\r
220         \r
221         bool                    MoveCaretLeft();\r
222         bool                    MoveCaretRight();\r
223         void                    UpdateGoalPos();\r
224 \r
225         bool                    IsWordSeparator(wchar_t ch) const;\r
226         bool                    IsCaretAtWordBoundary() const;\r
227 \r
228 protected:\r
229         COLORREF                m_InlineRemovedBk;\r
230         COLORREF                m_InlineAddedBk;\r
231         COLORREF                m_ModifiedBk;\r
232         COLORREF                m_WhiteSpaceFg;\r
233         UINT                    m_nStatusBarID;         ///< The ID of the status bar pane used by this view. Must be set by the parent class.\r
234 \r
235 //      SVNLineDiff             m_svnlinediff;\r
236         BOOL                    m_bOtherDiffChecked;\r
237         BOOL                    m_bModified;\r
238         BOOL                    m_bFocused;\r
239         BOOL                    m_bViewLinenumbers;\r
240         BOOL                    m_bIsHidden;\r
241         BOOL                    m_bMouseWithin;\r
242         BOOL                    m_bIconLFs;\r
243         int                             m_nLineHeight;\r
244         int                             m_nCharWidth;\r
245         int                             m_nMaxLineLength;\r
246         int                             m_nScreenLines;\r
247         int                             m_nScreenChars;\r
248         int                             m_nOffsetChar;\r
249         int                             m_nTabSize;\r
250         int                             m_nDigits;\r
251         bool                    m_bInlineWordDiff;\r
252 \r
253         int                             m_nSelBlockStart;\r
254         int                             m_nSelBlockEnd;\r
255 \r
256         int                             m_nMouseLine;\r
257 \r
258         bool                    m_bCaretHidden;\r
259         POINT                   m_ptCaretPos;\r
260         int                             m_nCaretGoalPos;\r
261         POINT                   m_ptSelectionStartPos;\r
262         POINT                   m_ptSelectionEndPos;\r
263         POINT                   m_ptSelectionOrigin;\r
264 \r
265 \r
266         HICON                   m_hAddedIcon;\r
267         HICON                   m_hRemovedIcon;\r
268         HICON                   m_hConflictedIcon;\r
269         HICON                   m_hConflictedIgnoredIcon;\r
270         HICON                   m_hWhitespaceBlockIcon;\r
271         HICON                   m_hEqualIcon;\r
272         HICON                   m_hEditedIcon;\r
273 \r
274         HICON                   m_hLineEndingCR;\r
275         HICON                   m_hLineEndingCRLF;\r
276         HICON                   m_hLineEndingLF;\r
277 \r
278         LOGFONT                 m_lfBaseFont;\r
279         CFont *                 m_apFonts[8];\r
280         CString                 m_sConflictedText;\r
281         CString                 m_sNoLineNr;\r
282 \r
283         CBitmap *               m_pCacheBitmap;\r
284         CDC *                   m_pDC;\r
285         CScrollTool             m_ScrollTool;\r
286         CString                 m_sWordSeparators;\r
287         \r
288         char                    m_szTip[MAX_PATH*2+1];\r
289         wchar_t                 m_wszTip[MAX_PATH*2+1];\r
290         // These three pointers lead to the three parent\r
291         // classes CLeftView, CRightView and CBottomView\r
292         // and are used for the communication between\r
293         // the views (e.g. synchronized scrolling, ...)\r
294         // To find out which parent class this object\r
295         // is made of just compare e.g. (m_pwndLeft==this).\r
296         static CBaseView * m_pwndLeft;          ///< Pointer to the left view. Must be set by the CLeftView parent class.\r
297         static CBaseView * m_pwndRight;         ///< Pointer to the right view. Must be set by the CRightView parent class.\r
298         static CBaseView * m_pwndBottom;        ///< Pointer to the bottom view. Must be set by the CBottomView parent class.\r
299 };\r
300 \r
301 \r