OSDN Git Service

PATCH: [ 1493742 ] Limit vertical scrolling to last line of files
authorKimmo Varis <kimmov@gmail.com>
Wed, 24 May 2006 16:34:12 +0000 (16:34 +0000)
committerKimmo Varis <kimmov@gmail.com>
Wed, 24 May 2006 16:34:12 +0000 (16:34 +0000)
Src/Changes.txt
Src/editlib/ccrystaltextview.cpp

index efa3ecb..4b73c7c 100644 (file)
@@ -2,6 +2,10 @@ Src\Changes.txt
 Add new items to top.
 (This summarizes all changes to all files under Src, including Src\Languages.)
 
+2006-05-24 Kimmo
+ PATCH: [ 1493742 ] Limit vertical scrolling to last line of files
+  Src/editlib: ccrystaltextview.cpp
+
 2006-05-23 Tim
  PATCH: [ 1493713 ] Translate 'Bookmarks' feature to German
   Src/Languages/German: MergeGerman.rc
index 087f545..2752cc8 100644 (file)
 //                  (see OnChar())
 ///////////////////////////////////////////////////////////////////////////////
 
+/**
+ * @file  ccrystaltextview.cpp
+ *
+ * @brief Implementation of the CCrystalTextView class
+ */
+// RCS ID line follows -- this is updated by CVS
+// $Id$
+
 #include "stdafx.h"
 #include <malloc.h>
 #include <imm.h> /* IME */
@@ -691,7 +699,17 @@ ScrollToChar (int nNewOffsetChar, BOOL bNoSmoothScroll /*= FALSE*/ , BOOL bTrack
     }
 }
 
-//BEGIN SW
+/**
+ * @brief Scroll view to given line.
+ * Scrolls view so that given line is first line in the view. We limit
+ * scrolling so that there is only one empty line visible after the last
+ * line at max. So we don't allow user to scroll last line being at top or
+ * even at middle of the screen. This is how many editors behave and I
+ * (Kimmo) think it is good for us too.
+ * @param [in] nNewTopSubLine New top line for view.
+ * @param [in] bNoSmoothScroll if TRUE don't use smooth scrolling.
+ * @param [in] bTrackScrollBar if TRUE scrollbar is updated after scroll.
+ */
 void CCrystalTextView::ScrollToSubLine( int nNewTopSubLine, 
                   BOOL bNoSmoothScroll /*= FALSE*/, BOOL bTrackScrollBar /*= TRUE*/ )
 {
@@ -699,6 +717,12 @@ void CCrystalTextView::ScrollToSubLine( int nNewTopSubLine,
     {
       if (bNoSmoothScroll || ! m_bSmoothScroll)
         {
+          // Limit scrolling so that we show one empty line at end of file
+          const int nScreenLines = GetScreenLines();
+          const int nLineCount = GetSubLineCount();
+          if (nNewTopSubLine > (nLineCount - nScreenLines))
+             nNewTopSubLine = nLineCount - nScreenLines;
+
           int nScrollLines = m_nTopSubLine - nNewTopSubLine;
           m_nTopSubLine = nNewTopSubLine;
           // OnDraw() uses m_nTopLine to determine topline
@@ -751,13 +775,6 @@ void CCrystalTextView::ScrollToSubLine( int nNewTopSubLine,
     }
 }
 
-/*void CCrystalTextView::GoToLine( int nLine )
-{
-  SetCursorPos( CPoint( 0, (nLine > 0)? nLine - 1 : 0 ) );
-  EnsureVisible( GetCursorPos() );
-}*/
-//END SW
-
 void CCrystalTextView::
 ScrollToLine (int nNewTopLine, BOOL bNoSmoothScroll /*= FALSE*/ , BOOL bTrackScrollBar /*= TRUE*/ )
 {