1 ////////////////////////////////////////////////////////////////////////////
2 // File: GhostTextView.h
4 // Created: 31-Jul-2003
6 /////////////////////////////////////////////////////////////////////////////
7 // WinMerge: an interactive diff/merge utility
8 // Copyright (C) 1997-2000 Thingamahoochie Software
11 // This program is free software; you can redistribute it and/or modify
12 // it under the terms of the GNU General Public License as published by
13 // the Free Software Foundation; either version 2 of the License, or
14 // (at your option) any later version.
16 // This program is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 // GNU General Public License for more details.
21 // You should have received a copy of the GNU General Public License
22 // along with this program; if not, write to the Free Software
23 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 /////////////////////////////////////////////////////////////////////////////
29 #include "GhostTextView.h"
30 #include "GhostTextBuffer.h"
35 static char THIS_FILE[] = __FILE__;
39 IMPLEMENT_DYNCREATE (CGhostTextView, CCrystalEditViewEx)
44 AttachToBuffer (CCrystalTextBuffer * pBuf /*= NULL*/ )
48 pBuf = LocateTextBuffer ();
51 m_pGhostTextBuffer = dynamic_cast<CGhostTextBuffer*> (pBuf);
52 CCrystalEditViewEx::AttachToBuffer(pBuf);
58 if (m_pGhostTextBuffer != NULL)
59 m_pGhostTextBuffer = NULL;
60 CCrystalEditViewEx::DetachFromBuffer();
70 void CGhostTextView::popPosition(SCursorPushed Ssrc, CPoint & pt)
73 pt.y = m_pGhostTextBuffer->ComputeApparentLine(Ssrc.y, Ssrc.nToFirstReal);
74 // if the cursor was in a trailing ghost line, and this disappeared,
75 // got at the end of the last line
76 if (pt.y >= GetLineCount())
78 pt.y = GetLineCount()-1;
79 pt.x = GetLineLength(pt.y);
83 void CGhostTextView::pushPosition(SCursorPushed & Sdest, CPoint pt)
86 Sdest.y = m_pGhostTextBuffer->ComputeRealLineAndGhostAdjustment(pt.y, Sdest.nToFirstReal);
92 CPoint ptCursorLast = m_ptCursorLast;
93 popPosition(m_ptCursorPosPushed, ptCursorLast);
95 ASSERT_VALIDTEXTPOS (ptCursorLast);
96 SetCursorPos (ptCursorLast);
98 popPosition(m_ptSelStartPushed, m_ptSelStart);
99 ASSERT_VALIDTEXTPOS (m_ptSelStart);
100 popPosition(m_ptSelEndPushed, m_ptSelEnd);
101 ASSERT_VALIDTEXTPOS (m_ptSelEnd);
102 popPosition(m_ptAnchorPushed, m_ptAnchor);
103 ASSERT_VALIDTEXTPOS (m_ptAnchor);
105 // here is what we did before, maybe we have to do it, but test with pushed positions
106 // SetSelection (ptCursorLast, ptCursorLast);
107 // SetAnchor (ptCursorLast);
109 if (m_bDraggingText == TRUE)
111 popPosition(m_ptDraggedTextBeginPushed, m_ptDraggedTextBegin);
112 ASSERT_VALIDTEXTPOS(m_ptDraggedTextBegin);
113 popPosition(m_ptDraggedTextEndPushed, m_ptDraggedTextEnd);
114 ASSERT_VALIDTEXTPOS(m_ptDraggedTextEnd);
116 if (m_bDropPosVisible == TRUE)
118 popPosition(m_ptSavedCaretPosPushed, m_ptSavedCaretPos);
119 ASSERT_VALIDTEXTPOS(m_ptSavedCaretPos);
121 if (m_bSelectionPushed == TRUE)
123 popPosition(m_ptSavedSelStartPushed, m_ptSavedSelStart);
124 ASSERT_VALIDTEXTPOS(m_ptSavedSelStart);
125 popPosition(m_ptSavedSelEndPushed, m_ptSavedSelEnd);
126 ASSERT_VALIDTEXTPOS(m_ptSavedSelEnd);
130 if (m_ptLastChangePushed.y == 0 && m_ptLastChangePushed.nToFirstReal == 1)
131 ptLastChange = CPoint(-1,-1);
134 popPosition(m_ptLastChangePushed, ptLastChange);
135 ASSERT_VALIDTEXTPOS(ptLastChange);
137 m_pGhostTextBuffer->RestoreLastChangePos(ptLastChange);
140 void CGhostTextView::
143 pushPosition(m_ptCursorPosPushed, m_ptCursorPos);
144 pushPosition(m_ptSelStartPushed, m_ptSelStart);
145 pushPosition(m_ptSelEndPushed, m_ptSelEnd);
146 pushPosition(m_ptAnchorPushed, m_ptAnchor);
147 if (m_bDraggingText == TRUE)
149 pushPosition(m_ptDraggedTextBeginPushed, m_ptDraggedTextBegin);
150 pushPosition(m_ptDraggedTextEndPushed, m_ptDraggedTextEnd);
152 if (m_bDropPosVisible == TRUE)
153 pushPosition(m_ptSavedCaretPosPushed, m_ptSavedCaretPos);
154 if (m_bSelectionPushed == TRUE)
156 pushPosition(m_ptSavedSelStartPushed, m_ptSavedSelStart);
157 pushPosition(m_ptSavedSelEndPushed, m_ptSavedSelEnd);
160 pushPosition(m_ptLastChangePushed, m_pGhostTextBuffer->GetLastChangePos());
166 int CGhostTextView::ComputeRealLine (int nApparentLine) const
168 return m_pGhostTextBuffer->ComputeRealLine(nApparentLine);
171 int CGhostTextView::ComputeApparentLine (int nRealLine) const
173 return m_pGhostTextBuffer->ComputeApparentLine(nRealLine);
176 void CGhostTextView::GetTextWithoutEmptys (int nStartLine, int nStartChar, int nEndLine, int nEndChar, CString &text, int nCrlfStyle /*=CRLF_STYLE_AUTOMATIC*/ )
178 if (m_pGhostTextBuffer != NULL)
179 m_pGhostTextBuffer->GetTextWithoutEmptys (nStartLine, nStartChar, nEndLine, nEndChar, text, nCrlfStyle);