]> git.lyx.org Git - lyx.git/commitdiff
anchorRow
authorJohn Levon <levon@movementarian.org>
Tue, 18 Mar 2003 16:47:18 +0000 (16:47 +0000)
committerJohn Levon <levon@movementarian.org>
Tue, 18 Mar 2003 16:47:18 +0000 (16:47 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6526 a592a061-630c-0410-9148-cb99ea01b6c8

src/ChangeLog
src/lyxtext.h
src/text.C
src/text2.C

index a8f0f528b30a3e3dc97d0bc1c8d6d5fdead10e32..3543415d9350ed6366c9b469888f87e46bf88bac 100644 (file)
@@ -1,3 +1,9 @@
+2003-03-18  Alfredo Braunstein  <abraunst@libero.it>
+
+       * lyxtext.h:
+       * text.C:
+       * text2.C: anchor row on setCursor
+
 2003-03-18  Alfredo Braunstein  <abraunst@libero.it>
  
        * lyxtext.h: remove almost all mutable keywords
index e880d878c4510135eae0ad8f5441969f4f5dc721..a7446769dbc085a642427679f991a02703481fb8 100644 (file)
@@ -84,17 +84,20 @@ public:
        /// the current font
        LyXFont real_current_font;
 private:
-       /** the first visible row on screen
+       /** the 'anchor' row: the position of this row remains constant
+        *  with respect to the top of the screen
         */
-       Row * top_row_;
+       Row * anchor_row_;
        /** the pixel offset with respect to this row of top_y
         */
-       int top_row_offset_;
+       int anchor_row_offset_;
 public:
        /// get the y coord. of the top of the screen (relative to doc start)
        int top_y() const;
-       /// set it
+       /// set the y coord. of the top of the screen (relative to doc start)
        void top_y(int newy);
+       /// set the anchoring row. top_y will be computed relative to this
+       void anchor_row(Row * row);
        ///
        InsetText * inset_owner;
        ///
index e1239f2878611e8352f221ba48707c9563beefbc..5235f1611f99671db3642d698738f4e07fe2b872 100644 (file)
@@ -74,14 +74,15 @@ BufferView * LyXText::bv() const
 
 int LyXText::top_y() const
 {
-       if (!top_row_)
+       if (!anchor_row_)
                return 0;
 
        int y = 0;
-       for (Row * row = firstrow; row && row != top_row_; row = row->next()) {
+       for (Row * row = firstrow; 
+            row && row != anchor_row_; row = row->next()) {
                y += row->height();
        }
-       return y + top_row_offset_;
+       return y + anchor_row_offset_;
 }
 
 
@@ -92,10 +93,22 @@ void LyXText::top_y(int newy)
        lyxerr[Debug::GUI] << "setting top y = " << newy << endl;
 
        int y = newy;
-       top_row_ = getRowNearY(y);
-       top_row_offset_ = newy - y;
-       lyxerr[Debug::GUI] << "changing reference to row: " << top_row_
-              << " offset: " << top_row_offset_ << endl;
+       anchor_row_ = getRowNearY(y);
+       anchor_row_offset_ = newy - y;
+       lyxerr[Debug::GUI] << "changing reference to row: " << anchor_row_
+              << " offset: " << anchor_row_offset_ << endl;
+}
+
+
+void LyXText::anchor_row(Row * row)
+{
+       int old_y = top_y();
+       anchor_row_offset_ = 0;
+       anchor_row_ = row; 
+       anchor_row_offset_ = old_y - top_y();
+       lyxerr[Debug::GUI] << "anchor_row(): changing reference to row: " 
+                          << anchor_row_ << " offset: " << anchor_row_offset_ 
+                          << endl;
 }
 
 
index 75126e96c0eba03f51b589f5745b118bef6a5ad7..29ebcd2d1393408e40962ee07742e2ca7011057d 100644 (file)
@@ -52,7 +52,7 @@ using lyx::pos_type;
 
 
 LyXText::LyXText(BufferView * bv)
-       : height(0), width(0), top_row_(0), top_row_offset_(0),
+       : height(0), width(0), anchor_row_(0), anchor_row_offset_(0),
          inset_owner(0), the_locking_inset(0), need_break_row(0),
          bv_owner(bv), firstrow(0), lastrow(0)
 {
@@ -61,7 +61,7 @@ LyXText::LyXText(BufferView * bv)
 
 
 LyXText::LyXText(BufferView * bv, InsetText * inset)
-       : height(0), width(0), top_row_(0), top_row_offset_(0),
+       : height(0), width(0), anchor_row_(0), anchor_row_offset_(0),
          inset_owner(inset), the_locking_inset(0), need_break_row(0),
          bv_owner(bv), firstrow(0), lastrow(0)
 {
@@ -331,13 +331,13 @@ void LyXText::removeRow(Row * row)
                // what about refresh_y
        }
 
-       if (top_row_ == row) {
-               if (row->next()) {
-                       top_row_ = row->next();
-                       top_row_offset_ -= row->height();
+       if (anchor_row_ == row) {
+               if (row_prev) {
+                       anchor_row_ = row_prev;
+                       anchor_row_offset_ = 0;
                } else {
-                       top_row_ = row_prev;
-                       top_row_offset_ = 0;
+                       anchor_row_ = row->next();
+                       anchor_row_offset_ -= row->height();
                }
        }
 
@@ -1793,6 +1793,10 @@ void LyXText::setCursor(LyXCursor & cur, Paragraph * par,
                cur.ix(int(x));
        } else
                cur.ix(cur.x());
+       //if the cursor is in a visible row, anchor to it
+       int topy = top_y();
+       if (topy < y && y < topy + bv()->workHeight()) 
+               anchor_row(row);
 }