OSDN Git Service

Update CWindowsManagerDialog - check some pointers for null and made … (#824) (2)
[winmerge-jp/winmerge-jp.git] / Src / GhostTextView.h
1 /**
2  * @file  GhostTextView.h
3  *
4  * @brief Declaration of CGhostTextView (subclasses CCrystalEditViewEx to handle ghost lines)
5  */
6 #pragma once
7
8 #include "crystalEditViewex.h"
9
10 ////////////////////////////////////////////////////////////////////////////
11 // Forward class declarations
12
13 class CGhostTextBuffer;
14
15
16 ////////////////////////////////////////////////////////////////////////////
17 // CCrystalTextView class declaration
18
19 /** 
20 This class hooks CCrystalEditViewEx to work with ghost lines. 
21
22 Use a CGhostTextBuffer buffer and virtualize some functions 
23 to handle apparent/real lines differences. 
24
25 We don't need to hook the drawing. Drawing ghost lines with the function used for
26 real lines is correct, as they are empty and have no EOL. 
27 WinMerge also paints the ghost lines in a custom color through virtualizing 
28 GetLineColors (in MergeEditView).
29 */
30 class EDITPADC_CLASS CGhostTextView : public CCrystalEditViewEx
31 {
32         DECLARE_DYNCREATE (CGhostTextView)
33 protected:
34         CGhostTextView();           // protected constructor used by dynamic creation
35
36 private:
37         CGhostTextBuffer * m_pGhostTextBuffer;
38
39         /** 
40          * @brief Real point structure to preserve a position during Rescan 
41          * 
42          * @note The preserved positions are also updated in CCrystalTextView::UpdateView
43          * or in CCrystalEditView::UpdateView
44          * except for m_ptLastChange, which is set just after the call to UpdateView
45          */
46         struct SCursorPushed
47         {
48                 /// char pos
49                 int x;
50                 /// real line number of itself (is the line is real)/the first real line after this line (else)
51                 int y;
52                 /// 0 (is the line is real)/ distance to the first real line after this one 
53                 int nToFirstReal;
54
55                 SCursorPushed() : x(0), y(0), nToFirstReal(0) { }
56         };
57         
58         /** 
59          * @brief Save a position to be able to restore it after Rescan.
60          * The saved position is based only on real lines
61          *
62          * @note We can only push/pop valid positions
63          * For positions which are sometimes invalid, use a flag
64          */
65         void pushPosition(SCursorPushed & Sdest, CPoint pt);
66         /** 
67          * @brief Restore cursors after Rescan.
68          *
69          * @note : also scroll to the old top line
70          */
71         void popPosition(SCursorPushed Ssrc, CPoint & pt);
72
73         /// basic cursor
74         SCursorPushed m_ptCursorPosPushed;
75         /// selection extremities
76         SCursorPushed m_ptSelStartPushed, m_ptSelEndPushed;
77         /// anchor point for selection (during shift is pressed)
78         SCursorPushed m_ptAnchorPushed;
79         /// during dragging, extremities of dragged text : if (m_bDraggingText == true)
80         SCursorPushed m_ptDraggedTextBeginPushed, m_ptDraggedTextEndPushed;
81         /// during drag/drop, droping position : if (m_bDropPosVisible == true)
82         SCursorPushed m_ptSavedCaretPosPushed;
83         /// memorize selected text during OnEditReplace : if (m_bSelectionPushed == true)
84         SCursorPushed m_ptSavedSelStartPushed, m_ptSavedSelEndPushed;
85         /// memorize top line positions
86         int m_nTopSubLinePushed;
87         /// memorize X offset positions
88         int m_nOffsetCharPushed;
89         /** last change position, in the buffer ; used in insertText
90          * initialized with (-1,-1), so don't assert for this invalid value
91          */
92         SCursorPushed m_ptLastChangePushed;
93         // Other CPoint used but not preserved :
94         //   m_ptDrawSelStart, m_ptDrawSelEnd : built from m_ptSelStart and m_ptSelEnd
95         //   m_ptDropPos : only used inside one function which does not change the buffer
96
97 public:
98         virtual void ReAttachToBuffer (CCrystalTextBuffer * pBuf = nullptr) override;
99         virtual void AttachToBuffer (CCrystalTextBuffer * pBuf = nullptr) override;
100         virtual void DetachFromBuffer () override;
101
102         /** real cursor function to preserve cursor during Rescan */
103         void PopCursors ();
104         /** real cursor function to preserve cursor during Rescan */
105         void PushCursors ();
106
107         void GetTextWithoutEmptys (int nStartLine, int nStartChar,
108                         int nEndLine, int nEndChar, CString &text,
109                         CRLFSTYLE nCrlfStyle = CRLFSTYLE::AUTOMATIC,
110                         bool bExcludeInvisibleLines = true);
111         void GetTextWithoutEmptysInColumnSelection (CString & text,
112                         bool bExcludeInvisibleLines = true);
113         /** 
114          * @brief Override this drag-n-drop function to call GetTextWithoutEmptys
115          */
116         virtual HGLOBAL PrepareDragData () override;
117
118         int ComputeApparentLine (int nRealLine) const;
119         int ComputeRealLine (int nApparentLine) const;
120         virtual void DrawMargin (const CRect & rect, int nLineIndex, int nLineNumber) override;
121
122 };