]> git.lyx.org Git - features.git/commitdiff
moves top_y from lyxtext to BufferView
authorAlfredo Braunstein <abraunst@lyx.org>
Wed, 27 Aug 2003 14:55:20 +0000 (14:55 +0000)
committerAlfredo Braunstein <abraunst@lyx.org>
Wed, 27 Aug 2003 14:55:20 +0000 (14:55 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@7616 a592a061-630c-0410-9148-cb99ea01b6c8

14 files changed:
src/BufferView.C
src/BufferView.h
src/BufferView_pimpl.C
src/BufferView_pimpl.h
src/ChangeLog
src/frontends/screen.C
src/insets/insettabular.C
src/insets/insettext.C
src/lyxtext.h
src/rowpainter.C
src/rowpainter.h
src/text.C
src/text2.C
src/text3.C

index 41b8c53efb3dfef02168429967245e7595ca21d9..a5541ed7f2f8c04b8e9d3267811a2fca7d33d9cf 100644 (file)
@@ -225,6 +225,18 @@ void BufferView::center()
 }
 
 
+int BufferView::top_y() const
+{
+       return pimpl_->top_y();
+}
+
+
+void BufferView::top_y(int y)
+{
+       pimpl_->top_y(y);
+}
+
+
 string const BufferView::getClipboard() const
 {
        return pimpl_->workarea().getClipboard();
index 076361c14ea53f47b62b0a5758f014e581a101f3..5848a4639ec3d5ec3bb8e5a72a586e19369848a9 100644 (file)
@@ -64,6 +64,12 @@ public:
        /// return the owning main view
        LyXView * owner() const;
 
+       /// return the visible top y
+       int top_y() const;
+       
+       /// set the visible top y
+       void top_y(int);
+       
        /// resize event has happened
        void resize();
 
index a62e5004f99fa74d357fd246b769bedfe5f2012d..59716a1171ef4ff66cc460d2ae1dca7d866963f2 100644 (file)
@@ -273,6 +273,18 @@ Painter & BufferView::Pimpl::painter() const
 }
 
 
+void BufferView::Pimpl::top_y(int y)
+{
+       top_y_ = y;
+}
+
+
+int BufferView::Pimpl::top_y() const
+{
+       return top_y_;
+}
+
+
 void BufferView::Pimpl::buffer(Buffer * b)
 {
        lyxerr[Debug::INFO] << "Setting buffer in BufferView ("
@@ -293,6 +305,8 @@ void BufferView::Pimpl::buffer(Buffer * b)
        // set current buffer
        buffer_ = b;
 
+       top_y_ = 0;
+       
        // if we're quitting lyx, don't bother updating stuff
        if (quitting)
                return;
@@ -310,7 +324,7 @@ void BufferView::Pimpl::buffer(Buffer * b)
                        resizeCurrentBuffer();
 
                // FIXME: needed when ?
-               bv_->text->top_y(screen().topCursorVisible(bv_->text));
+               top_y(screen().topCursorVisible(bv_->text));
 
                // Buffer-dependent dialogs should be updated or
                // hidden. This should go here because some dialogs (eg ToC)
@@ -461,7 +475,7 @@ void BufferView::Pimpl::resizeCurrentBuffer()
                bv_->theLockingInset(the_locking_inset);
        }
 
-       bv_->text->top_y(screen().topCursorVisible(bv_->text));
+       top_y(screen().topCursorVisible(bv_->text));
 
        switchKeyMap();
        owner_->busy(false);
@@ -484,9 +498,9 @@ void BufferView::Pimpl::updateScrollbar()
        LyXText const & t = *bv_->text;
 
        lyxerr[Debug::GUI] << "Updating scrollbar: h " << t.height << ", top_y() "
-               << t.top_y() << ", default height " << defaultRowHeight() << endl;
+               << top_y() << ", default height " << defaultRowHeight() << endl;
 
-       workarea().setScrollbarParams(t.height, t.top_y(), defaultRowHeight());
+       workarea().setScrollbarParams(t.height, top_y(), defaultRowHeight());
 }
 
 
@@ -499,15 +513,15 @@ void BufferView::Pimpl::scrollDocView(int value)
 
        screen().hideCursor();
 
-       bv_->text->top_y(value);
+       top_y(value);
        screen().redraw(*bv_);
 
        if (!lyxrc.cursor_follows_scrollbar)
                return;
 
        int const height = defaultRowHeight();
-       int const first = int((bv_->text->top_y() + height));
-       int const last = int((bv_->text->top_y() + workarea().workHeight() - height));
+       int const first = top_y() + height;
+       int const last = top_y() + workarea().workHeight() - height;
 
        LyXText * text = bv_->text;
        if (text->cursor.y() < first)
@@ -529,7 +543,7 @@ void BufferView::Pimpl::scroll(int lines)
        int const line_height = defaultRowHeight();
 
        // The new absolute coordinate
-       int new_top_y = t->top_y() + lines * line_height;
+       int new_top_y = top_y() + lines * line_height;
 
        // Restrict to a valid value
        new_top_y = std::min(t->height - 4 * line_height, new_top_y);
@@ -538,7 +552,7 @@ void BufferView::Pimpl::scroll(int lines)
        scrollDocView(new_top_y);
 
        // Update the scrollbar.
-       workarea().setScrollbarParams(t->height, t->top_y(), defaultRowHeight());
+       workarea().setScrollbarParams(t->height, top_y(), defaultRowHeight());
 }
 
 
@@ -797,7 +811,7 @@ void BufferView::Pimpl::center()
        // and also might have moved top_y() must make sure to call
        // updateScrollbar() currently. Never mind that this is a
        // pretty obfuscated way of updating t->top_y()
-       text->top_y(new_y);
+       top_y(new_y);
        //screen().draw();
        update();
 }
index df03767e9ce231e33c8680efe922342e50e3446e..2032a09ec374afe611052a9dd483ef4906743473 100644 (file)
@@ -106,7 +106,13 @@ struct BufferView::Pimpl : public boost::signals::trackable {
        bool workAreaDispatch(FuncRequest const & ev);
        /// a function should be executed
        bool dispatch(FuncRequest const & ev);
+       ///
+       int top_y() const;
+       ///
+       void top_y(int y);
 private:
+       /// the y coordinate of the top of the screen
+       int top_y_;
        /// An error list (replaces the error insets)
        ErrorList errorlist_;
        /// add an error to the list
index 1b3f994fa8499c160546ba45166599570fae2dc9..828203c8f1997320369731039f4e68d08a437e32 100644 (file)
@@ -1,3 +1,17 @@
+
+2003-08-27  Alfredo Braunstein  <abraunst@libero.it>
+
+       * lyxtext.h (top_y): move top_y from here
+       * text.C:
+       * text2.C:
+       * text3.C:
+       * BufferView.[Ch]:
+       * BufferView_pimpl.[Ch]: to here
+       * frontends/screen.C:
+       * insets/insettabular.C:
+       * insets/insettext.C: adjust  
+       * rowpainter.[Ch] (paintRows): remove LyXText & argument
+
 2003-08-27  Alfredo Braunstein  <abraunst@libero.it>
 
        * BufferView.[Ch]:
index 9da9ef054543db7c6aa8358b6e5182007a7c53fa..5f647b5a51d25074945d6286905640eb20c6b4a5 100644 (file)
@@ -163,7 +163,7 @@ void LyXScreen::showCursor(BufferView & bv)
        int h = ascent + descent;
        int x = 0;
        int y = 0;
-       int const top_y = bv.text->top_y();
+       int const top_y = bv.top_y();
 
        if (bv.theLockingInset()) {
                // Would be nice to clean this up to make some understandable sense...
@@ -220,23 +220,25 @@ void LyXScreen::toggleCursor(BufferView & bv)
 }
 
 
-bool LyXScreen::fitManualCursor(BufferView * /*bv*/, LyXText * text,
+bool LyXScreen::fitManualCursor(BufferView * bv, LyXText * text,
        int /*x*/, int y, int asc, int desc)
 {
        int const vheight = workarea().workHeight();
-       int newtop = text->top_y();
-
-       if (y + desc - text->top_y() >= vheight)
+       int const topy = bv->top_y();
+       int newtop = topy;
+       
+       
+       if (y + desc - topy >= vheight)
                newtop = y - 3 * vheight / 4;  // the scroll region must be so big!!
-       else if (y - asc < text->top_y() && text->top_y() > 0)
+       else if (y - asc < topy && topy > 0)
                newtop = y - vheight / 4;
 
        newtop = max(newtop, 0); // can newtop ever be < 0? (Lgb)
 
-       if (newtop == text->top_y())
+       if (newtop == topy)
                return false;
 
-       text->top_y(newtop);
+       bv->top_y(newtop);
        return true;
 }
 
@@ -244,7 +246,7 @@ bool LyXScreen::fitManualCursor(BufferView * /*bv*/, LyXText * text,
 unsigned int LyXScreen::topCursorVisible(LyXText * text)
 {
        LyXCursor const & cursor = text->cursor;
-       int top_y = text->top_y();
+       int top_y = text->bv()->top_y();
        int newtop = top_y;
        int const vheight = workarea().workHeight();
 
@@ -279,8 +281,8 @@ bool LyXScreen::fitCursor(LyXText * text, BufferView * bv)
 {
        // Is a change necessary?
        int const newtop = topCursorVisible(text);
-       bool const result = (newtop != text->top_y());
-       text->top_y(newtop);
+       bool const result = (newtop != bv->top_y());
+       bv->top_y(newtop);
        return result;
 }
 
@@ -298,7 +300,7 @@ void LyXScreen::redraw(BufferView & bv)
 
        hideCursor();
 
-       int const y = paintText(bv, *bv.text);
+       int const y = paintText(bv);
 
        // maybe we have to clear the screen at the bottom
        int const y2 = workarea().workHeight();
index 72068ed5503fda40315d1b2b7c7abf6edb8aa4cf..fd20f0a99de6fad60a171cc94bc6f9abc0b30b5c 100644 (file)
@@ -860,10 +860,10 @@ InsetOld::RESULT InsetTabular::localDispatch(FuncRequest const & cmd)
                        clearSelection();
                int column = actcol;
                unlockInsetInInset(bv, the_locking_inset);
-               if (bv->text->top_y() + bv->painter().paperHeight() <
+               if (bv->top_y() + bv->painter().paperHeight() <
                    top_baseline + tabular.getHeightOfTabular())
                        {
-                               bv->scrollDocView(bv->text->top_y() + bv->painter().paperHeight());
+                               bv->scrollDocView(bv->top_y() + bv->painter().paperHeight());
                                actcell = tabular.getCellBelow(first_visible_cell) + column;
                        } else {
                                actcell = tabular.getFirstCellInRow(tabular.rows() - 1) + column;
@@ -878,7 +878,7 @@ InsetOld::RESULT InsetTabular::localDispatch(FuncRequest const & cmd)
                int column = actcol;
                unlockInsetInInset(bv, the_locking_inset);
                if (top_baseline < 0) {
-                       bv->scrollDocView(bv->text->top_y() - bv->painter().paperHeight());
+                       bv->scrollDocView(bv->top_y() - bv->painter().paperHeight());
                        if (top_baseline > 0)
                                actcell = column;
                        else
index e2d4f469816b61f1a0979a4339bdddf68ca4f1e5..53e160cc790e62f2f78295b5f147e1d039306bac 100644 (file)
@@ -489,7 +489,7 @@ void InsetText::lfunMousePress(FuncRequest const & cmd)
                lockInset(bv);
 
        int tmp_x = cmd.x - drawTextXOffset;
-       int tmp_y = cmd.y + dim_.asc - getLyXText(bv)->top_y();
+       int tmp_y = cmd.y + dim_.asc - bv->top_y();
        InsetOld * inset = getLyXText(bv)->checkInsetHit(tmp_x, tmp_y);
 
        if (the_locking_inset) {
@@ -524,7 +524,7 @@ void InsetText::lfunMousePress(FuncRequest const & cmd)
                        localDispatch(FuncRequest(bv, LFUN_COPY));
                        paste_internally = true;
                }
-               int old_top_y = text_.top_y();
+               int old_top_y = bv->top_y();
 
                text_.setCursorFromCoordinates(cmd.x - drawTextXOffset,
                                             cmd.y + dim_.asc);
@@ -538,7 +538,7 @@ void InsetText::lfunMousePress(FuncRequest const & cmd)
                bv->owner()->setLayout(cpar()->layout()->name());
 
                // we moved the view we cannot do mouse selection in this case!
-               if (getLyXText(bv)->top_y() != old_top_y)
+               if (bv->top_y() != old_top_y)
                        no_selection = true;
                old_par = cpar();
                // Insert primary selection with middle mouse
@@ -568,7 +568,7 @@ bool InsetText::lfunMouseRelease(FuncRequest const & cmd)
                return the_locking_inset->localDispatch(cmd1);
 
        int tmp_x = cmd.x - drawTextXOffset;
-       int tmp_y = cmd.y + dim_.asc - getLyXText(bv)->top_y();
+       int tmp_y = cmd.y + dim_.asc - bv->top_y();
        InsetOld * inset = getLyXText(bv)->checkInsetHit(tmp_x, tmp_y);
        bool ret = false;
        if (inset) {
index 827f768aeafee7efccda7758be9501aff74220de..abf6aae77f838cee6d1c41d4515210a8d6433d88 100644 (file)
@@ -70,12 +70,6 @@ private:
 public:
        /// update all cached row positions
        void updateRowPositions();
-       /// get the y coord. of the top of the screen (relative to doc start)
-       int top_y() const;
-       /// 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(RowList::iterator rit);
        ///
        InsetText * inset_owner;
        ///
index f90f0f2cbf3b41fa40b6295f1be8d2bb6b72dafb..be7f7e3130b2cf63b54710f7a3c4d33aceafe30d 100644 (file)
@@ -1062,7 +1062,7 @@ int paintRows(BufferView const & bv, LyXText const & text,
                        if (row == rit)
                                active = true;
                        if (active) {
-                               RowPainter painter(bv, text, pit, row, y + yo, xo, y + text.top_y());
+                               RowPainter painter(bv, text, pit, row, y + yo, xo, y + bv.top_y());
                                painter.paint();
                                y += row->height();
                                if (yy + y >= y2)
@@ -1080,13 +1080,13 @@ int paintRows(BufferView const & bv, LyXText const & text,
 } // namespace anon
 
 
-int paintText(BufferView & bv, LyXText & text)
+int paintText(BufferView & bv)
 {
-       int const topy = text.top_y();
+       int const topy = bv.top_y();
        ParagraphList::iterator pit;
-       RowList::iterator rit = text.getRowNearY(topy, pit);
+       RowList::iterator rit = bv.text->getRowNearY(topy, pit);
        int y = rit->y() - topy;
-       return paintRows(bv, text, pit, rit, 0, y, y, 0);
+       return paintRows(bv, *bv.text, pit, rit, 0, y, y, 0);
 }
 
 
@@ -1102,13 +1102,10 @@ void paintTextInset(BufferView & bv, LyXText & text, int x, int baseline)
                y += rit->height();
                text.nextRow(pit, rit);
        }
-       if (y_offset < 0) {
-               text.top_y(-y_offset);
+       if (y_offset < 0)
                paintRows(bv, text, pit, rit, x, 0, y, y);
-       } else {
-               text.top_y(y - y_offset);
+       else
                paintRows(bv, text, pit, rit, x, 0, y_offset, y_offset);
-       }
 }
 
 
index 4c5b5175aaf9618d1e0cf47a5d33add793b7cce1..b663ae847156328b7e1c490d8e489850be156d85 100644 (file)
@@ -21,7 +21,7 @@ class VSpace;
 int getLengthMarkerHeight(BufferView const & bv, VSpace const & vsp);
 
 /// paint the rows of the main text, return last drawn y value
-int paintText(BufferView & bv, LyXText & text);
+int paintText(BufferView & bv);
 
 /// paint the rows of a text inset
 void paintTextInset(BufferView & bv, LyXText & text, int x, int y);
index 2eeb91d5465c9f3fc0187beca8c04f9a5c7f136d..1c3f07b9c1197908b943c869e1a8b7e96cad469e 100644 (file)
@@ -103,19 +103,6 @@ void LyXText::updateRowPositions()
 }
 
 
-int LyXText::top_y() const
-{
-       return anchor_y_;
-}
-
-
-void LyXText::top_y(int newy)
-{
-       anchor_y_ = newy;
-       lyxerr[Debug::GUI] << "changing reference to offset: " << anchor_y_ << endl;
-}
-
-
 int LyXText::workWidth() const
 {
        return inset_owner ? inset_owner->textWidth() : bv()->workWidth();
index 45d3be00ceae4936c7c741c029d831e190c0910a..da8ebec8b1f50a237988883d2c6dd584a3ab15f7 100644 (file)
@@ -1399,17 +1399,6 @@ void LyXText::setCursor(LyXCursor & cur, ParagraphList::iterator pit,
                cur.ix(int(x));
        } else
                cur.ix(cur.x());
-/* We take out this for the time being because 1) the redraw code is not
-   prepared to this yet and 2) because some good policy has yet to be decided
-   while editting: for instance how to act on rows being created/deleted
-   because of DEPM.
-*/
-#if 0
-       //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);
-#endif
 }
 
 
@@ -1694,7 +1683,7 @@ void LyXText::cursorUp(bool selecting)
        int y = cursor.y() - cursorRow()->baseline() - 1;
        setCursorFromCoordinates(x, y);
        if (!selecting) {
-               int topy = top_y();
+               int topy = bv_owner->top_y();
                int y1 = cursor.iy() - topy;
                int y2 = y1;
                y -= topy;
@@ -1720,7 +1709,7 @@ void LyXText::cursorDown(bool selecting)
        int y = cursor.y() - cursorRow()->baseline() + cursorRow()->height() + 1;
        setCursorFromCoordinates(x, y);
        if (!selecting && cursorRow() == cursorIRow()) {
-               int topy = top_y();
+               int topy = bv_owner->top_y();
                int y1 = cursor.iy() - topy;
                int y2 = y1;
                y -= topy;
index e2795e8239abd518c6df3485818dd5d13c0aee21..35cacddf2f6c084ecfe04f1b15f069e771fb6d96 100644 (file)
@@ -146,7 +146,7 @@ namespace {
 
 InsetOld * LyXText::checkInsetHit(int & x, int & y)
 {
-       int y_tmp = y + top_y();
+       int y_tmp = y + bv_owner->top_y();
 
        LyXCursor cur;
        setCursorFromCoordinates(cur, x, y_tmp);
@@ -243,7 +243,7 @@ void LyXText::gotoInset(InsetOld::Code code, bool same_content)
 
 void LyXText::cursorPrevious()
 {
-       int y = top_y();
+       int y = bv_owner->top_y();
 
        RowList::iterator rit = cursorRow();
 
@@ -282,7 +282,7 @@ void LyXText::cursorPrevious()
        ParagraphList::iterator pit = cursor.par();
        previousRow(pit, rit);
        setCursor(cur, pit, rit->pos(), false);
-       if (cur.y() > top_y())
+       if (cur.y() > bv_owner->top_y())
                cursorUp(true);
        bv()->updateScrollbar();
 }
@@ -290,21 +290,21 @@ void LyXText::cursorPrevious()
 
 void LyXText::cursorNext()
 {
-       int topy = top_y();
+       int topy = bv_owner->top_y();
 
        RowList::iterator rit = cursorRow();
        if (rit == lastRow()) {
                int y = cursor.y() - rit->baseline() + cursorRow()->height();
                if (y > topy + bv()->workHeight())
-                       bv()->updateScrollbar();
+                       bv_owner->updateScrollbar();
                return;
        }
 
-       int y = topy + bv()->workHeight();
+       int y = topy + bv_owner->workHeight();
        if (inset_owner && !topy) {
-               y -= (bv()->text->cursor.iy()
-                         - bv()->text->top_y()
-                         + bv()->theLockingInset()->insetInInsetY());
+               y -= (bv_owner->text->cursor.iy()
+                         - bv_owner->top_y()
+                         + bv_owner->theLockingInset()->insetInInsetY());
        }
 
        ParagraphList::iterator dummypit;
@@ -315,7 +315,7 @@ void LyXText::cursorNext()
        finishUndo();
 
        int new_y;
-       if (rit == bv()->text->cursorRow()) {
+       if (rit == bv_owner->text->cursorRow()) {
                // we have a row which is taller than the workarea. The
                // simplest solution is to move to the next row instead.
                cursorDown(true);
@@ -323,7 +323,7 @@ void LyXText::cursorNext()
                // This is what we used to do, so we wouldn't skip right past
                // tall rows, but it's not working right now.
 #if 0
-               new_y = bv->text->top_y() + bv->workHeight();
+               new_y = bv->top_y() + bv->workHeight();
 #endif
        } else {
                if (inset_owner) {
@@ -339,7 +339,7 @@ void LyXText::cursorNext()
        nextRow(pit, rit);      
        LyXCursor cur;
        setCursor(cur, pit, rit->pos(), false);
-       if (cur.y() < top_y() + bv()->workHeight())
+       if (cur.y() < bv_owner->top_y() + bv()->workHeight())
                cursorDown(true);
        bv()->updateScrollbar();
 }
@@ -1218,7 +1218,7 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
                        int start_x = inset_x + tli->scroll();
                        FuncRequest cmd1 = cmd;
                        cmd1.x = cmd.x - start_x;
-                       cmd1.y = cmd.y - cursor.iy() + bv->text->top_y();
+                       cmd1.y = cmd.y - cursor.iy() + bv->top_y();
                        tli->localDispatch(cmd1);
                        break;
                }
@@ -1233,7 +1233,7 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
                }
 
                RowList::iterator cursorrow = bv->text->cursorRow();
-               bv->text->setCursorFromCoordinates(cmd.x, cmd.y + bv->text->top_y());
+               bv->text->setCursorFromCoordinates(cmd.x, cmd.y + bv->top_y());
        #if 0
                // sorry for this but I have a strange error that the y value jumps at
                // a certain point. This seems like an error in my xforms library or
@@ -1289,7 +1289,7 @@ InsetOld::RESULT LyXText::dispatch(FuncRequest const & cmd)
                        paste_internally = true;
                }
 
-               int const screen_first = bv->text->top_y();
+               int const screen_first = bv->top_y();
 
                if (bv->theLockingInset()) {
                        // We are in inset locking mode