2 * @file GhostTextView.h
4 * @brief Declaration of CGhostTextView (subclasses CCrystalEditViewEx to handle ghost lines)
8 #include "crystalEditViewex.h"
10 ////////////////////////////////////////////////////////////////////////////
11 // Forward class declarations
13 class CGhostTextBuffer;
16 ////////////////////////////////////////////////////////////////////////////
17 // CCrystalTextView class declaration
20 This class hooks CCrystalEditViewEx to work with ghost lines.
22 Use a CGhostTextBuffer buffer and virtualize some functions
23 to handle apparent/real lines differences.
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).
30 class EDITPADC_CLASS CGhostTextView : public CCrystalEditViewEx
32 DECLARE_DYNCREATE (CGhostTextView)
34 CGhostTextView(); // protected constructor used by dynamic creation
37 CGhostTextBuffer * m_pGhostTextBuffer;
40 * @brief Real point structure to preserve a position during Rescan
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
50 /// real line number of itself (is the line is real)/the first real line after this line (else)
52 /// 0 (is the line is real)/ distance to the first real line after this one
55 SCursorPushed() : x(0), y(0), nToFirstReal(0) { }
59 * @brief Save a position to be able to restore it after Rescan.
60 * The saved position is based only on real lines
62 * @note We can only push/pop valid positions
63 * For positions which are sometimes invalid, use a flag
65 void pushPosition(SCursorPushed & Sdest, CPoint pt);
67 * @brief Restore cursors after Rescan.
69 * @note : also scroll to the old top line
71 void popPosition(SCursorPushed Ssrc, CPoint & pt);
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
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
98 virtual void ReAttachToBuffer (CCrystalTextBuffer * pBuf = nullptr) override;
99 virtual void AttachToBuffer (CCrystalTextBuffer * pBuf = nullptr) override;
100 virtual void DetachFromBuffer () override;
102 /** real cursor function to preserve cursor during Rescan */
104 /** real cursor function to preserve cursor during Rescan */
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);
114 * @brief Override this drag-n-drop function to call GetTextWithoutEmptys
116 virtual HGLOBAL PrepareDragData () override;
118 int ComputeApparentLine (int nRealLine) const;
119 int ComputeRealLine (int nApparentLine) const;
120 virtual void DrawMargin (const CRect & rect, int nLineIndex, int nLineNumber) override;