OSDN Git Service

Plugins: Add DisassembleJVM, DisassembleIL and DisassembleNative plugin (3)
[winmerge-jp/winmerge-jp.git] / Src / GhostTextView.cpp
index 58c9a17..d16f183 100644 (file)
@@ -7,21 +7,7 @@
 //    WinMerge:  an interactive diff/merge utility
 //    Copyright (C) 1997-2000  Thingamahoochie Software
 //    Author: Dean Grimm
-//
-//    This program is free software; you can redistribute it and/or modify
-//    it under the terms of the GNU General Public License as published by
-//    the Free Software Foundation; either version 2 of the License, or
-//    (at your option) any later version.
-//
-//    This program is distributed in the hope that it will be useful,
-//    but WITHOUT ANY WARRANTY; without even the implied warranty of
-//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-//    GNU General Public License for more details.
-//
-//    You should have received a copy of the GNU General Public License
-//    along with this program; if not, write to the Free Software
-//    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-//
+//    SPDX-License-Identifier: GPL-2.0-or-later
 /////////////////////////////////////////////////////////////////////////////
 
 
@@ -40,15 +26,26 @@ IMPLEMENT_DYNCREATE (CGhostTextView, CCrystalEditViewEx)
  * @brief Constructor, initializes members.
  */
 CGhostTextView::CGhostTextView()
-: m_pGhostTextBuffer(NULL)
+: m_pGhostTextBuffer(nullptr)
+, m_ptCursorPosPushed{}
+, m_ptSelStartPushed{}
+, m_ptSelEndPushed{}
+, m_ptAnchorPushed{}
+, m_ptDraggedTextBeginPushed{}
+, m_ptDraggedTextEndPushed{}
+, m_ptSavedCaretPosPushed{}
+, m_ptSavedSelStartPushed{}
+, m_ptSavedSelEndPushed{}
+, m_ptLastChangePushed{}
 , m_nTopSubLinePushed(0)
+, m_nOffsetCharPushed(0)
 {
 }
 
 void CGhostTextView::
-ReAttachToBuffer (CCrystalTextBuffer * pBuf /*= NULL*/ )
+ReAttachToBuffer (CCrystalTextBuffer * pBuf /*= nullptr*/ )
 {
-       if (pBuf == NULL)
+       if (pBuf == nullptr)
        {
                pBuf = LocateTextBuffer ();
                // ...
@@ -58,9 +55,9 @@ ReAttachToBuffer (CCrystalTextBuffer * pBuf /*= NULL*/ )
 }
 
 void CGhostTextView::
-AttachToBuffer (CCrystalTextBuffer * pBuf /*= NULL*/ )
+AttachToBuffer (CCrystalTextBuffer * pBuf /*= nullptr*/ )
 {
-       if (pBuf == NULL)
+       if (pBuf == nullptr)
        {
                pBuf = LocateTextBuffer ();
                // ...
@@ -72,8 +69,7 @@ AttachToBuffer (CCrystalTextBuffer * pBuf /*= NULL*/ )
 void CGhostTextView::
 DetachFromBuffer ()
 {
-       if (m_pGhostTextBuffer != NULL)
-               m_pGhostTextBuffer = NULL;
+       m_pGhostTextBuffer = nullptr;
        CCrystalEditViewEx::DetachFromBuffer();
 }
 
@@ -88,12 +84,17 @@ void CGhostTextView::popPosition(SCursorPushed Ssrc, CPoint & pt)
                pt.y = GetLineCount()-1;
                pt.x = GetLineLength(pt.y);
        }
+       if (pt.y < 0)
+               pt.y = 0;
 }
 
 void CGhostTextView::pushPosition(SCursorPushed & Sdest, CPoint pt)
 {
        Sdest.x = pt.x;
-       Sdest.y = m_pGhostTextBuffer->ComputeRealLineAndGhostAdjustment(pt.y, Sdest.nToFirstReal);
+       if (m_pGhostTextBuffer)
+               Sdest.y = m_pGhostTextBuffer->ComputeRealLineAndGhostAdjustment(pt.y, Sdest.nToFirstReal);
+       else
+               Sdest.y = pt.y;
 }
 
 void CGhostTextView::PopCursors ()
@@ -153,7 +154,10 @@ void CGhostTextView::PopCursors ()
                m_nTopSubLine = 0;
        int nDummy;
        GetLineBySubLine( m_nTopSubLine, m_nTopLine, nDummy );
+       const int nMaxLineLength = GetMaxLineLength(m_nTopLine, GetScreenLines());
+       m_nOffsetChar = (m_nOffsetCharPushed < nMaxLineLength) ? m_nOffsetCharPushed : nMaxLineLength;
     RecalcVertScrollBar(true);
+    InvalidateHorzScrollBar();
 }
 
 void CGhostTextView::PushCursors ()
@@ -177,10 +181,11 @@ void CGhostTextView::PushCursors ()
                pushPosition(m_ptSavedSelEndPushed, m_ptSavedSelEnd);
        }
 
-       pushPosition(m_ptLastChangePushed, m_pGhostTextBuffer->GetLastChangePos());
+       pushPosition(m_ptLastChangePushed, m_pGhostTextBuffer ? m_pGhostTextBuffer->GetLastChangePos() : CPoint{0, 0});
 
        // and top line positions
        m_nTopSubLinePushed = m_nTopSubLine;
+       m_nOffsetCharPushed = m_nOffsetChar;
 }
 
 
@@ -188,7 +193,7 @@ void CGhostTextView::PushCursors ()
 
 int CGhostTextView::ComputeRealLine (int nApparentLine) const
 {
-       if (!m_pGhostTextBuffer)
+       if (m_pGhostTextBuffer == nullptr)
                return 0;
        return m_pGhostTextBuffer->ComputeRealLine(nApparentLine);
 }
@@ -200,10 +205,10 @@ int CGhostTextView::ComputeApparentLine (int nRealLine) const
 
 void CGhostTextView::GetTextWithoutEmptys (int nStartLine, int nStartChar,
                int nEndLine, int nEndChar, CString &text,
-               CRLFSTYLE nCrlfStyle /*= CRLF_STYLE_AUTOMATIC*/,
+               CRLFSTYLE nCrlfStyle /*= CRLFSTYLE::AUTOMATIC*/,
                bool bExcludeInvisibleLines /*= true*/)
 {
-  if (m_pGhostTextBuffer != NULL)
+  if (m_pGhostTextBuffer != nullptr)
     m_pGhostTextBuffer->GetTextWithoutEmptys (nStartLine, nStartChar, nEndLine, nEndChar, text, nCrlfStyle, bExcludeInvisibleLines);
   else
     text = _T ("");
@@ -211,7 +216,7 @@ void CGhostTextView::GetTextWithoutEmptys (int nStartLine, int nStartChar,
 
 void CGhostTextView::GetTextWithoutEmptysInColumnSelection (CString & text, bool bExcludeInvisibleLines /*= true*/)
 {
-       if (m_pGhostTextBuffer == NULL)
+       if (m_pGhostTextBuffer == nullptr)
        {
                text = _T ("");
                return;
@@ -219,7 +224,7 @@ void CGhostTextView::GetTextWithoutEmptysInColumnSelection (CString & text, bool
 
        PrepareSelBounds ();
 
-       CString sEol = m_pGhostTextBuffer->GetStringEol (CRLF_STYLE_DOS);
+       CString sEol = m_pGhostTextBuffer->GetStringEol (CRLFSTYLE::DOS);
 
        int nBufSize = 1;
        for (int L = m_ptDrawSelStart.y; L <= m_ptDrawSelEnd.y; L++)
@@ -248,18 +253,18 @@ HGLOBAL CGhostTextView::PrepareDragData ()
 {
        PrepareSelBounds ();
        if (m_ptDrawSelStart == m_ptDrawSelEnd)
-               return NULL;
+               return nullptr;
 
        CString text;
        GetTextWithoutEmptys (m_ptDrawSelStart.y, m_ptDrawSelStart.x, m_ptDrawSelEnd.y, m_ptDrawSelEnd.x, text);
        int cchText = text.GetLength();
        SIZE_T cbData = (cchText + 1) * sizeof(TCHAR);
        HGLOBAL hData =::GlobalAlloc (GMEM_MOVEABLE | GMEM_DDESHARE, cbData);
-       if (hData == NULL)
-               return NULL;
+       if (hData == nullptr)
+               return nullptr;
 
        LPTSTR pszData = (LPTSTR)::GlobalLock (hData);
-       if (pszData)
+       if (pszData != nullptr)
                memcpy (pszData, text, cbData);
        ::GlobalUnlock (hData);
 
@@ -275,12 +280,12 @@ HGLOBAL CGhostTextView::PrepareDragData ()
  * @param [in] nLineIndex  Index of line in view.
  * @param [in] nLineNumber Line number to display. if -1, it's not displayed.
  */
-void CGhostTextView::DrawMargin (CDC * pdc, const CRect & rect, int nLineIndex, int nLineNumber)
+void CGhostTextView::DrawMargin (const CRect & rect, int nLineIndex, int nLineNumber)
 {
        int nRealLineNumber;
        if (nLineIndex < 0 || GetLineFlags(nLineIndex) & LF_GHOST)
                nRealLineNumber = -1;
        else
                nRealLineNumber = ComputeRealLine(nLineIndex) + 1;
-       CCrystalTextView::DrawMargin(pdc, rect, nLineIndex, nRealLineNumber);
+       CCrystalTextView::DrawMargin(rect, nLineIndex, nRealLineNumber);
 }