OSDN Git Service

PATCH: [ 1497817 ] Cleanup CCrystalTextView::GetLineBySubLine
authorKimmo Varis <kimmov@gmail.com>
Wed, 31 May 2006 17:16:02 +0000 (17:16 +0000)
committerKimmo Varis <kimmov@gmail.com>
Wed, 31 May 2006 17:16:02 +0000 (17:16 +0000)
Src/Changes.txt
Src/editlib/ccrystaltextview.cpp
Src/editlib/ccrystaltextview.h

index 3608e64..1214f49 100644 (file)
@@ -5,6 +5,8 @@ Add new items to top.
 2006-05-31 Kimmo
  BUG: [ 1494610 ] Wrong selection in ccrystalview2.cpp
   Src/editlib: ccrystaltextview2.cpp
+ PATCH: [ 1497817 ] Cleanup CCrystalTextView::GetLineBySubLine
+  Src/editlib: ccrystaltextview.cpp ccrystaltextview.h
 
 2006-05-30 Kimmo
  PATCH: [ 1497154 ] Fix memory leak in wordwrap code
index 541e2f2..e5d2afc 100644 (file)
@@ -475,6 +475,8 @@ SaveSettings ()
 }
 
 CCrystalTextView::CCrystalTextView ()
+: m_nScreenChars(-1)
+, m_nMaxLineLength(-1)
 {
   AFX_ZERO_INIT_OBJECT (CView);
   m_rxnode = NULL;
@@ -500,7 +502,6 @@ CCrystalTextView::CCrystalTextView ()
   SetTextType (SRC_PLAIN);
   m_bSingle = false; // needed to be set in descendat classes
   m_bRememberLastPos = false;
-  m_nMaxLineLength = -1;
 
   m_pColors = NULL;
 }
@@ -2808,36 +2809,37 @@ int CCrystalTextView::GetSubLineIndex( int nLineIndex )
   return nSubLineCount;
 }
 
-void CCrystalTextView::GetLineBySubLine( int nSubLineIndex, int &nLine, int &nSubLine )
+// See comment in the header file
+void CCrystalTextView::GetLineBySubLine(int nSubLineIndex, int &nLine, int &nSubLine)
 {
   ASSERT( nSubLineIndex < GetSubLineCount() );
 
   // if we do not wrap words, nLine is equal to nSubLineIndex and nSubLine is allways 0
-  if( !m_bWordWrap )
+  if (!m_bWordWrap)
     {
       nLine = nSubLineIndex;
       nSubLine = 0;
+      return;
     }
 
   // compute result
-  int  nSubLineCount = 0;
+  int nSubLineCount = 0;
   int nLastSubLines = 0;
   const int nLineCount = GetLineCount();
 
-  int i=0;
-  for( i = 0; i < nLineCount; i++ )
+  int i = 0;
+  for (i = 0; i < nLineCount; i++)
     {
-      nLastSubLines = GetSubLines( i );
+      nLastSubLines = GetSubLines(i);
       nSubLineCount += nLastSubLines;
-      if( !(nSubLineCount <= nSubLineIndex) )
+      if (nSubLineCount > nSubLineIndex)
         break;
     }
 
-  ASSERT( i < nLineCount );
+  ASSERT(i < nLineCount);
   nLine = i;
-  nSubLine = nSubLineIndex - (nSubLineCount - nLastSubLines);
+  nSubLine = nSubLineIndex - nSubLineCount + nLastSubLines;
 }
-//END SW
 
 int CCrystalTextView::
 GetLineLength (int nLineIndex) const
index 0661058..1b5c433 100644 (file)
@@ -418,15 +418,13 @@ protected :
        */
        virtual int GetSubLineIndex( int nLineIndex );
 
-       /**
-       Splits the given subline index into line and sub line of this line.
-
-       @param nSubLineIndex The zero based index of the subline to get info about
-       @param nLine Gets the line number the give subline is included in
-       @param nSubLine Get the subline of the given subline relative to nLine
-       */
-       virtual void GetLineBySubLine( int nSubLineIndex, int &nLine, int &nSubLine );
-       //END SW
+    /**
+     * @brief Splits the given subline index into line and sub line of this line.
+     * @param [in] nSubLineIndex The zero based index of the subline to get info about
+     * @param [out] nLine Gets the line number the give subline is included in
+     * @param [out] nSubLine Get the subline of the given subline relative to nLine
+     */
+    virtual void GetLineBySubLine(int nSubLineIndex, int &nLine, int &nSubLine);
 
 public:
     virtual int GetLineLength (int nLineIndex) const;