]> git.lyx.org Git - features.git/commitdiff
Alfredo's patch.
authorJohn Levon <levon@movementarian.org>
Thu, 6 Mar 2003 20:21:21 +0000 (20:21 +0000)
committerJohn Levon <levon@movementarian.org>
Thu, 6 Mar 2003 20:21:21 +0000 (20:21 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@6372 a592a061-630c-0410-9148-cb99ea01b6c8

15 files changed:
src/BufferView_pimpl.C
src/ChangeLog
src/frontends/ChangeLog
src/frontends/qt2/ChangeLog
src/frontends/qt2/qscreen.C
src/frontends/screen.C
src/frontends/xforms/ChangeLog
src/frontends/xforms/xscreen.C
src/insets/ChangeLog
src/insets/insettabular.C
src/insets/insettext.C
src/lyxtext.h
src/text.C
src/text2.C
src/text3.C

index b8f690713e4441fa6238366c762d975857aa1d42..21e40f877ee3dd188113e599537ca468f30c1f45 100644 (file)
@@ -184,8 +184,7 @@ void BufferView::Pimpl::buffer(Buffer * b)
                }
 
                // FIXME: needed when ?
-               bv_->text->first_y =
-                       screen().topCursorVisible(bv_->text->cursor, bv_->text->first_y);
+               bv_->text->top_y(screen().topCursorVisible(bv_->text->cursor, bv_->text->top_y()));
 
                // Similarly, buffer-dependent dialogs should be updated or
                // hidden. This should go here because some dialogs (eg ToC)
@@ -322,7 +321,7 @@ int BufferView::Pimpl::resizeCurrentBuffer()
                bv_->theLockingInset(the_locking_inset);
        }
 
-       bv_->text->first_y = screen().topCursorVisible(bv_->text->cursor, bv_->text->first_y);
+       bv_->text->top_y(screen().topCursorVisible(bv_->text->cursor, bv_->text->top_y()));
 
        switchKeyMap();
        owner_->busy(false);
@@ -350,10 +349,10 @@ void BufferView::Pimpl::updateScrollbar()
 
        LyXText const & t = *bv_->text;
 
-       lyxerr[Debug::GUI] << "Updating scrollbar: h " << t.height << ", first_y "
-               << t.first_y << ", default height " << defaultRowHeight() << endl;
+       lyxerr[Debug::GUI] << "Updating scrollbar: h " << t.height << ", top_y() "
+               << t.top_y() << ", default height " << defaultRowHeight() << endl;
 
-       workarea().setScrollbarParams(t.height, t.first_y, defaultRowHeight());
+       workarea().setScrollbarParams(t.height, t.top_y(), defaultRowHeight());
 }
 
 
@@ -372,8 +371,8 @@ void BufferView::Pimpl::scrollDocView(int value)
        LyXText * vbt = bv_->text;
 
        int const height = defaultRowHeight();
-       int const first = static_cast<int>((bv_->text->first_y + height));
-       int const last = static_cast<int>((bv_->text->first_y + workarea().workHeight() - height));
+       int const first = static_cast<int>((bv_->text->top_y() + height));
+       int const last = static_cast<int>((bv_->text->top_y() + workarea().workHeight() - height));
 
        if (vbt->cursor.y() < first)
                vbt->setCursorFromCoordinates(bv_, 0, first);
@@ -392,16 +391,16 @@ void BufferView::Pimpl::scroll(int lines)
        int const line_height = defaultRowHeight();
 
        // The new absolute coordinate
-       int new_first_y = t->first_y + lines * line_height;
+       int new_top_y = t->top_y() + lines * line_height;
 
        // Restrict to a valid value
-       new_first_y = std::min(t->height - 4 * line_height, new_first_y);
-       new_first_y = std::max(0, new_first_y);
+       new_top_y = std::min(t->height - 4 * line_height, new_top_y);
+       new_top_y = std::max(0, new_top_y);
 
-       scrollDocView(new_first_y);
+       scrollDocView(new_top_y);
 
        // Update the scrollbar.
-       workarea().setScrollbarParams(t->height, t->first_y, defaultRowHeight());
+       workarea().setScrollbarParams(t->height, t->top_y(), defaultRowHeight());
 }
 
 
@@ -777,14 +776,14 @@ void BufferView::Pimpl::center()
        }
 
        // FIXME: can we do this w/o calling screen directly ?
-       // This updates first_y but means the fitCursor() call
+       // This updates top_y() but means the fitCursor() call
        // from the update(FITCUR) doesn't realise that we might
        // have moved (e.g. from GOTOPARAGRAPH), so doesn't cause
        // the scrollbar to be updated as it should, so we have
        // to do it manually. Any operation that does a center()
-       // and also might have moved first_y must make sure to call
+       // 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->first_y
+       // pretty obfuscated way of updating t->top_y()
        screen().draw(t, bv_, new_y);
 
        update(t, BufferView::SELECT | BufferView::FITCUR);
index a64a70cc731829a632e7ea05aa64c30ceec577ab..cefb00cc4d9016f10a5f82cc861585ca7d3e2fc6 100644 (file)
@@ -1,3 +1,13 @@
+2003-03-06  Alfredo Braunstein  <abraunst@libero.it>
+
+       * lyxtext.h (top_y): added these 2 methods, and private vars top_row_ 
+       and top_row_offset_. removed var first_y.
+       * text.C (top_y): 
+       * text2.C (LyXText, removeRow): 
+       * text3.C:
+       * BufferView_pimpl.C: 
+       use these methods instead of using first_y
+
 2003-03-06  Lars Gullik Bjønnes  <larsbj@gullik.net>
 
        * CutAndPaste.h: make CutAndPaste a namespace.
index 86efa68edcb7a5780a9f92e49840511d32c00f88..abc24731993a5f4385b76f4e36c88412e9677e6e 100644 (file)
@@ -1,3 +1,7 @@
+2003-03-06  Alfredo Braunstein  <abraunst@libero.it>
+
+       * screen.C: use LyXText::top_y() instead of LyXText::first_y
+
 2003-03-05  Angus Leeming  <leeming@lyx.org>
 
        * Dialogs.h: remove showWrap.
index b59d9bb2ceb1362b38e1d4e2ce8edad64efa94de..5ac87ba107511701d02a55657a9901629ef3f735 100644 (file)
@@ -1,3 +1,7 @@
+2003-03-06  Alfredo Braunstein  <abraunst@libero.it>
+
+       * qscreen.C: use LyXText::top_y() instead of LyXText::first_y
+
 2003-03-06  John Levon  <levon@movementarian.org>
 
        * ui/QPrefUIModule.ui: make max last files reflect reality,
index 175d116cec378308f518e90c0861b181d6d02af0..0d9cab5259362e93587c8a84fe452b45b3bc6974 100644 (file)
@@ -58,8 +58,8 @@ void QScreen::showManualCursor(LyXText const * text, int x, int y,
        if (!qApp->focusWidget())
                return;
 
-       int const y1 = max(y - text->first_y - asc, 0);
-       int const y_tmp = min(y - text->first_y + desc, owner_.height());
+       int const y1 = max(y - text->top_y() - asc, 0);
+       int const y_tmp = min(y - text->top_y() + desc, owner_.height());
 
        // secure against very strange situations
        // which would be when .... ?
@@ -160,9 +160,9 @@ void QScreen::draw(LyXText * text, BufferView * bv, unsigned int y)
 
        if (cursor_visible_) hideCursor();
 
-       int const old_first = text->first_y;
+       int const old_first = text->top_y();
        bool const internal = (text == bv->text);
-       text->first_y = y;
+       text->top_y(y);
 
        // If you want to fix the warning below, fix it so it
        // actually scrolls properly. Hint: a cast won't do.
@@ -170,13 +170,13 @@ void QScreen::draw(LyXText * text, BufferView * bv, unsigned int y)
        // is any optimization possible?
        if (y - old_first < owner_.workHeight()
            && old_first - y < owner_.workHeight()) {
-               if (text->first_y < old_first) {
-                       int const dest_y = old_first - text->first_y;
+               if (text->top_y() < old_first) {
+                       int const dest_y = old_first - text->top_y();
                        drawFromTo(text, bv, 0, dest_y, 0, 0, internal);
                        copyInPixmap(p, dest_y, 0, owner_.workWidth(), owner_.height() - dest_y);
                        expose(0, 0, owner_.workWidth(), dest_y);
                } else  {
-                       int const src_y = text->first_y - old_first;
+                       int const src_y = text->top_y() - old_first;
                        drawFromTo(text, bv, owner_.height() - src_y, owner_.height(), 0, 0, internal);
                        copyInPixmap(p, 0, 0, owner_.workWidth(), owner_.height() - src_y);
                        expose(0, owner_.height() - src_y, owner_.workWidth(), src_y);
index 93f7064ef7503bda204930f8f543919b14e28052..0abd95b123a6e7434155113cdad0d093c8537193 100644 (file)
@@ -160,20 +160,20 @@ bool LyXScreen::fitManualCursor(BufferView * bv, LyXText * text,
        int /*x*/, int y, int asc, int desc)
 {
        int const vheight = workarea().workHeight();
-       int newtop = text->first_y;
+       int newtop = text->top_y();
 
-       if (y + desc - text->first_y >= vheight)
+       if (y + desc - text->top_y() >= vheight)
                newtop = y - 3 * vheight / 4;  // the scroll region must be so big!!
-       else if (y - asc < text->first_y
-               && text->first_y > 0) {
+       else if (y - asc < text->top_y()
+               && text->top_y() > 0) {
                newtop = y - vheight / 4;
        }
 
        newtop = max(newtop, 0); // can newtop ever be < 0? (Lgb)
 
-       if (newtop != text->first_y) {
+       if (newtop != text->top_y()) {
                draw(text, bv, newtop);
-               text->first_y = newtop;
+               text->top_y(newtop);
                return true;
        }
 
@@ -234,8 +234,8 @@ unsigned int LyXScreen::topCursorVisible(LyXCursor const & cursor, int top_y)
 bool LyXScreen::fitCursor(LyXText * text, BufferView * bv)
 {
        // Is a change necessary?
-       int const newtop = topCursorVisible(text->cursor, text->first_y);
-       bool const result = (newtop != text->first_y);
+       int const newtop = topCursorVisible(text->cursor, text->top_y());
+       bool const result = (newtop != text->top_y());
        if (result) {
                draw(text, bv, newtop);
        }
@@ -255,7 +255,7 @@ void LyXScreen::update(LyXText * text, BufferView * bv,
        switch (text->status()) {
        case LyXText::NEED_MORE_REFRESH:
        {
-               int const y = max(int(text->refresh_y - text->first_y), 0);
+               int const y = max(int(text->refresh_y - text->top_y()), 0);
                drawFromTo(text, bv, y, vheight, yo, xo);
                text->refresh_y = 0;
                // otherwise this is called ONLY from BufferView_pimpl(update)
@@ -277,7 +277,7 @@ void LyXScreen::update(LyXText * text, BufferView * bv,
                        // or we should see to set this flag accordingly
                        if (text != bv->text)
                                text->status(bv, LyXText::UNCHANGED);
-                       expose(0, text->refresh_y - text->first_y + yo,
+                       expose(0, text->refresh_y - text->top_y() + yo,
                                   vwidth, text->refresh_row->height());
                }
        }
@@ -303,24 +303,24 @@ void LyXScreen::toggleSelection(LyXText * text, BufferView * bv,
                max(static_cast<int>(text->selection.end.y()
                                     - text->selection.end.row()->baseline()
                                     + text->selection.end.row()->height()),
-                   text->first_y),
-               static_cast<int>(text->first_y + workarea().workHeight()));
+                   text->top_y()),
+               static_cast<int>(text->top_y() + workarea().workHeight()));
        int const top = min(
                max(static_cast<int>(text->selection.start.y() -
                                     text->selection.start.row()->baseline()),
-                   text->first_y),
-               static_cast<int>(text->first_y + workarea().workHeight()));
+                   text->top_y()),
+               static_cast<int>(text->top_y() + workarea().workHeight()));
 
        if (kill_selection)
                text->selection.set(false);
 
        workarea().getPainter().start();
 
-       drawFromTo(text, bv, top - text->first_y, bottom - text->first_y,
+       drawFromTo(text, bv, top - text->top_y(), bottom - text->top_y(),
                   yo, xo);
-       expose(0, top - text->first_y,
+       expose(0, top - text->top_y(),
               workarea().workWidth(),
-              bottom - text->first_y - (top - text->first_y));
+              bottom - text->top_y() - (top - text->top_y()));
 
        workarea().getPainter().end();
 }
@@ -340,18 +340,18 @@ void LyXScreen::toggleToggle(LyXText * text, BufferView * bv,
                + text->toggle_end_cursor.row()->height();
 
        int const offset = yo < 0 ? yo : 0;
-       int const bottom = min(max(bottom_tmp, text->first_y),
-               static_cast<int>(text->first_y + workarea().workHeight())) - offset;
-       int const top = min(max(top_tmp, text->first_y),
-               static_cast<int>(text->first_y + workarea().workHeight())) - offset;
+       int const bottom = min(max(bottom_tmp, text->top_y()),
+               static_cast<int>(text->top_y() + workarea().workHeight())) - offset;
+       int const top = min(max(top_tmp, text->top_y()),
+               static_cast<int>(text->top_y() + workarea().workHeight())) - offset;
 
        workarea().getPainter().start();
 
-       drawFromTo(text, bv, top - text->first_y,
-                  bottom - text->first_y, yo,
+       drawFromTo(text, bv, top - text->top_y(),
+                  bottom - text->top_y(), yo,
                   xo);
-       expose(0, top - text->first_y, workarea().workWidth(),
-              bottom - text->first_y - (top - text->first_y));
+       expose(0, top - text->top_y(), workarea().workWidth(),
+              bottom - text->top_y() - (top - text->top_y()));
 
        workarea().getPainter().end();
 }
@@ -366,6 +366,8 @@ void LyXScreen::redraw(LyXText * text, BufferView * bv)
                return;
        }
 
+       
+
        workarea().getPainter().start();
 
        drawFromTo(text, bv, 0, workarea().workHeight(), 0, 0, text == bv->text);
@@ -423,22 +425,24 @@ void LyXScreen::drawFromTo(LyXText * text, BufferView * bv,
 {
        lyxerr[Debug::GUI] << "screen: drawFromTo " << y1 << '-' << y2 << endl;
 
-       int y_text = text->first_y + y1;
+       int y_text = text->top_y() + y1;
 
        // get the first needed row
        Row * row = text->getRowNearY(y_text);
        // y_text is now the real beginning of the row
 
-       int y = y_text - text->first_y;
+       int y = y_text - text->top_y();
        // y1 is now the real beginning of row on the screen
 
+
        while (row != 0 && y < y2) {
                LyXText::text_status st = text->status();
                // we need this here as the row pointer may be illegal
                // at a later time (Jug20020502)
                Row * prev = row->previous();
                RowPainter rp(*bv, *text, *row);
-               if (rp.paint(y + yo, xo, y + text->first_y))
+
+               if (rp.paint(y + yo, xo, y + text->top_y()))
                        text->markChangeInDraw(bv, row, prev);
 
                internal = internal && (st != LyXText::CHANGED_IN_DRAW);
@@ -449,7 +453,7 @@ void LyXScreen::drawFromTo(LyXText * text, BufferView * bv,
                        text->status(bv, st);
                        Row * prev = row->previous();
                        RowPainter rp(*bv, *text, *row);
-                       if (rp.paint(y + yo, xo, y + text->first_y))
+                       if (rp.paint(y + yo, xo, y + text->top_y()))
                                text->markChangeInDraw(bv, row, prev);
                }
                y += row->height();
@@ -469,13 +473,13 @@ void LyXScreen::drawFromTo(LyXText * text, BufferView * bv,
 void LyXScreen::drawOneRow(LyXText * text, BufferView * bv, Row * row,
        int y_text, int yo, int xo)
 {
-       int const y = y_text - text->first_y + yo;
+       int const y = y_text - text->top_y() + yo;
 
        if (((y + row->height()) > 0) &&
            ((y - row->height()) <= static_cast<int>(workarea().workHeight()))) {
                Row * prev = row->previous();
                RowPainter rp(*bv, *text, *row);
-               if (rp.paint(y, xo, y + text->first_y))
+               if (rp.paint(y, xo, y + text->top_y()))
                        text->markChangeInDraw(bv, row, prev);
        }
        force_clear_ = false;
index 0f8a3ee2f9b74ed9e58fa584831b1134ca3c5cca..e2b18b5d34a6e834f9575366d8a9023161632005 100644 (file)
@@ -1,3 +1,7 @@
+2003-03-06  Alfredo Braunstein  <abraunst@libero.it>
+
+       * xscreen.C: use LyXText::top_y() instead of LyXText::first_y
+
 2003-02-28  Rob Lahaye  <lahaye@snu.ac.kr>
 
        * FormTabularCreate.C: remove slider settings (now part of .fd file)
index 6d07ac4fcc256f5cd3b5278e5b5b028a69ba7811..233122f2d9b4d456a44b42989cf631b4dec117c3 100644 (file)
@@ -95,8 +95,8 @@ void XScreen::showManualCursor(LyXText const * text, int x, int y,
        // Update the cursor color.
        setCursorColor();
 
-       int const y1 = max(y - text->first_y - asc, 0);
-       int const y_tmp = min(y - text->first_y + desc,
+       int const y1 = max(y - text->top_y() - asc, 0);
+       int const y_tmp = min(y - text->top_y() + desc,
                              static_cast<int>(owner_.workHeight()));
 
        // Secure against very strange situations
@@ -205,17 +205,17 @@ void XScreen::draw(LyXText * text, BufferView * bv, unsigned int y)
        if (cursor_visible_)
                hideCursor();
 
-       int const old_first = text->first_y;
+       int const old_first = text->top_y();
        bool const internal = (text == bv->text);
-       text->first_y = y;
+       text->top_y(y);
 
        // is any optimization possible?
        if ((y - old_first) < owner_.workHeight()
            && (old_first - y) < owner_.workHeight())
        {
-               if (text->first_y < old_first) {
+               if (text->top_y() < old_first) {
                        drawFromTo(text, bv, 0,
-                                  old_first - text->first_y, 0, 0, internal);
+                                  old_first - text->top_y(), 0, 0, internal);
                        XCopyArea (fl_get_display(),
                                   owner_.getWin(),
                                   owner_.getWin(),
@@ -223,31 +223,31 @@ void XScreen::draw(LyXText * text, BufferView * bv, unsigned int y)
                                   owner_.xpos(),
                                   owner_.ypos(),
                                   owner_.workWidth(),
-                                  owner_.workHeight() - old_first + text->first_y,
+                                  owner_.workHeight() - old_first + text->top_y(),
                                   owner_.xpos(),
-                                  owner_.ypos() + old_first - text->first_y
+                                  owner_.ypos() + old_first - text->top_y()
                                );
                        // expose the area drawn
                        expose(0, 0,
                               owner_.workWidth(),
-                              old_first - text->first_y);
+                              old_first - text->top_y());
                } else  {
                        drawFromTo(text, bv,
-                                  owner_.workHeight() + old_first - text->first_y,
+                                  owner_.workHeight() + old_first - text->top_y(),
                                   owner_.workHeight(), 0, 0, internal);
                        XCopyArea (fl_get_display(),
                                   owner_.getWin(),
                                   owner_.getWin(),
                                   gc_copy,
                                   owner_.xpos(),
-                                  owner_.ypos() + text->first_y - old_first,
+                                  owner_.ypos() + text->top_y() - old_first,
                                   owner_.workWidth(),
-                                  owner_.workHeight() + old_first - text->first_y,
+                                  owner_.workHeight() + old_first - text->top_y(),
                                   owner_.xpos(),
                                   owner_.ypos());
                        // expose the area drawn
-                       expose(0, owner_.workHeight() + old_first - text->first_y,
-                              owner_.workWidth(), text->first_y - old_first);
+                       expose(0, owner_.workHeight() + old_first - text->top_y(),
+                              owner_.workWidth(), text->top_y() - old_first);
                }
        } else {
                // make a dumb new-draw
index e7c484c17a523f2417d047e2844e4ebcd6537239..68147b94664d7548bd5dc6b2af3bb294a88ed7b5 100644 (file)
@@ -1,3 +1,8 @@
+2003-03-06  Alfredo Braunstein  <abraunst@libero.it>
+
+       * insettext.C:
+       * insettabular.C: use LyXText::top_y() instead of LyXText::first_y
+
 2003-03-06  Lars Gullik Bjønnes  <larsbj@gullik.net>
 
        * insettext.C (updateLocal): un-const function
index 22a564ebe85032aea9e069958ab4813a3aa6fd4b..9a729f08783e59ffec84c9cb49d34c414d4c9868 100644 (file)
@@ -1080,10 +1080,10 @@ Inset::RESULT InsetTabular::localDispatch(FuncRequest const & cmd)
                }
                int column = actcol;
                unlockInsetInInset(bv, the_locking_inset);
-               if (bv->text->first_y + bv->painter().paperHeight() <
+               if (bv->text->top_y() + bv->painter().paperHeight() <
                    (top_baseline + tabular->GetHeightOfTabular()))
                        {
-                               bv->scrollDocView(bv->text->first_y + bv->painter().paperHeight());
+                               bv->scrollDocView(bv->text->top_y() + bv->painter().paperHeight());
                                code = FULL;
                                actcell = tabular->GetCellBelow(first_visible_cell) + column;
                        } else {
@@ -1102,7 +1102,7 @@ Inset::RESULT InsetTabular::localDispatch(FuncRequest const & cmd)
                int column = actcol;
                unlockInsetInInset(bv, the_locking_inset);
                if (top_baseline < 0) {
-                       bv->scrollDocView(bv->text->first_y - bv->painter().paperHeight());
+                       bv->scrollDocView(bv->text->top_y() - bv->painter().paperHeight());
                        code = FULL;
                        if (top_baseline > 0)
                                actcell = column;
@@ -1495,9 +1495,9 @@ void InsetTabular::hideInsetCursor(BufferView * bv)
 void InsetTabular::fitInsetCursor(BufferView * bv) const
 {
        if (the_locking_inset) {
-               int old_first_y = bv->text->first_y;
+               int old_top_y = bv->text->top_y();
                the_locking_inset->fitInsetCursor(bv);
-               if (old_first_y != bv->text->first_y)
+               if (old_top_y != bv->text->top_y())
                        need_update = FULL;
                return;
        }
index f814cdf59495d084522f7403c12825d15a78acbf..48f014694cba8a5d77c0995e577303129d0ad1a6 100644 (file)
@@ -458,11 +458,11 @@ void InsetText::draw(BufferView * bv, LyXFont const & f,
                row = row->next();
        }
        if (y_offset < 0) {
-               lt->first_y = -y_offset;
+               lt->top_y(-y_offset);
                first = y;
                y_offset = 0;
        } else {
-               lt->first_y = first;
+               lt->top_y(first);
                first = 0;
        }
        if (cleared || (need_update&(INIT|FULL))) {
@@ -471,7 +471,7 @@ void InsetText::draw(BufferView * bv, LyXFont const & f,
                while ((row != 0) && (yf < ph)) {
                        Row * prev = row->previous();
                        RowPainter rp(*bv, *lt, *row);
-                       if (rp.paint(y + y_offset + first, int(x), y + lt->first_y, cleared))
+                       if (rp.paint(y + y_offset + first, int(x), y + lt->top_y(), cleared))
                                lt->markChangeInDraw(bv, row, prev);
                        if (bv->text->status() == LyXText::CHANGED_IN_DRAW) {
                                lt->need_break_row = row;
@@ -1020,7 +1020,7 @@ void InsetText::lfunMousePress(FuncRequest const & cmd)
                lockInset(bv);
 
        int tmp_x = cmd.x - drawTextXOffset;
-       int tmp_y = cmd.y + insetAscent - getLyXText(bv)->first_y;
+       int tmp_y = cmd.y + insetAscent - getLyXText(bv)->top_y();
        Inset * inset = getLyXText(bv)->checkInsetHit(bv, tmp_x, tmp_y);
 
        hideInsetCursor(bv);
@@ -1075,7 +1075,7 @@ void InsetText::lfunMousePress(FuncRequest const & cmd)
                        lt = getLyXText(bv);
                        clear = true;
                }
-               int old_first_y = lt->first_y;
+               int old_top_y = lt->top_y();
 
                lt->setCursorFromCoordinates(bv, cmd.x - drawTextXOffset,
                                             cmd.y + insetAscent);
@@ -1098,7 +1098,7 @@ void InsetText::lfunMousePress(FuncRequest const & cmd)
                bv->owner()->setLayout(cpar(bv)->layout()->name());
 
                // we moved the view we cannot do mouse selection in this case!
-               if (getLyXText(bv)->first_y != old_first_y)
+               if (getLyXText(bv)->top_y() != old_top_y)
                        no_selection = true;
                old_par = cpar(bv);
                // Insert primary selection with middle mouse
@@ -1129,7 +1129,7 @@ bool InsetText::lfunMouseRelease(FuncRequest const & cmd)
                return the_locking_inset->localDispatch(cmd1);
 
        int tmp_x = cmd.x - drawTextXOffset;
-       int tmp_y = cmd.y + insetAscent - getLyXText(bv)->first_y;
+       int tmp_y = cmd.y + insetAscent - getLyXText(bv)->top_y();
        Inset * inset = getLyXText(bv)->checkInsetHit(bv, tmp_x, tmp_y);
        bool ret = false;
        if (inset) {
@@ -2386,7 +2386,7 @@ void InsetText::resizeLyXText(BufferView * bv, bool force) const
                inset_y = ciy(bv) + drawTextYOffset;
        }
 
-       t->first_y = bv->screen().topCursorVisible(t->cursor, t->first_y);
+       t->top_y(bv->screen().topCursorVisible(t->cursor, t->top_y()));
        if (!owner()) {
                const_cast<InsetText*>(this)->updateLocal(bv, FULL, false);
                // this will scroll the screen such that the cursor becomes visible
@@ -2425,7 +2425,7 @@ void InsetText::reinitLyXText() const
                        inset_x = cix(bv) - top_x + drawTextXOffset;
                        inset_y = ciy(bv) + drawTextYOffset;
                }
-               t->first_y = bv->screen().topCursorVisible(t->cursor, t->first_y);
+               t->top_y(bv->screen().topCursorVisible(t->cursor, t->top_y()));
                if (!owner()) {
                        const_cast<InsetText*>(this)->updateLocal(bv, FULL, false);
                        // this will scroll the screen such that the cursor becomes visible
index 9cda952b798ee8fcee7985bf829fddad4ce9f25e..e0dc6015ea5bee52a802835b8effb1a17b649ba9 100644 (file)
@@ -79,9 +79,20 @@ public:
        mutable LyXFont current_font;
        /// the current font
        mutable LyXFont real_current_font;
-       /// first visible pixel-row is set from LyXScreen!!!
-       // unsigned is wrong here for text-insets!
-       int first_y;
+private:
+       /** the first visible row on screen
+        *  declared mutable because removeRow is const
+        */
+       mutable Row * top_row_;
+       /** the pixel offset with respect to this row of top_y 
+        *  declared mutable because removeRow is const
+        */
+       mutable int top_row_offset_;
+public:
+       /// get the y coord. of the top of the screen (relative to doc start)
+       int top_y() const;
+       /// set it
+       void top_y(int newy);
        ///
        InsetText * inset_owner;
        ///
index 1d237f18717ba6e77c0f5ca875dd6447ceb3cce5..9715db5a43ea62d3489bf45c8e71716ac00d5001 100644 (file)
@@ -58,6 +58,33 @@ extern int const LEFT_MARGIN = PAPER_MARGIN + CHANGEBAR_MARGIN;
 extern int bibitemMaxWidth(BufferView *, LyXFont const &);
 
 
+int LyXText::top_y() const
+{
+       if (!top_row_)
+               return 0;
+       
+       int y = 0;
+       for (Row * row = firstrow; row && row != top_row_; row = row->next()) {
+               y += row->height();
+       }
+       return y + top_row_offset_;
+}
+
+
+void LyXText::top_y(int newy)
+{
+       if (!firstrow)
+               return;
+       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;
+}
+
+
 int LyXText::workWidth(BufferView & bview) const
 {
        if (inset_owner) {
index bb72fc1778c531b10e72178234b03e5f423a1278..4e0cfe1f8b99d2f0e2e53522354747fe58782b41 100644 (file)
@@ -52,7 +52,7 @@ using lyx::pos_type;
 
 
 LyXText::LyXText(BufferView * bv)
-       : height(0), width(0), first_y(0),
+       : height(0), width(0), top_row_(0), top_row_offset_(0), 
          inset_owner(0), the_locking_inset(0), need_break_row(0),
          refresh_y(0), refresh_row(0), bv_owner(bv),
          status_(LyXText::UNCHANGED), firstrow(0), lastrow(0)
@@ -60,7 +60,7 @@ LyXText::LyXText(BufferView * bv)
 
 
 LyXText::LyXText(InsetText * inset)
-       : height(0), width(0), first_y(0),
+       : height(0), width(0), top_row_(0), top_row_offset_(0), 
          inset_owner(inset), the_locking_inset(0), need_break_row(0),
          refresh_y(0), refresh_row(0), bv_owner(0),
          status_(LyXText::UNCHANGED), firstrow(0), lastrow(0)
@@ -83,7 +83,7 @@ void LyXText::init(BufferView * bview, bool reinit)
                need_break_row = 0;
                width = height = 0;
                copylayouttype.erase();
-               first_y = refresh_y = 0;
+               top_y(refresh_y = 0);
                status_ = LyXText::UNCHANGED;
        } else if (firstrow)
                return;
@@ -326,6 +326,15 @@ void LyXText::removeRow(Row * row) const
                refresh_row = row_prev ? row_prev : row->next();
                // what about refresh_y, refresh_height
        }
+       if (top_row_ == row) {
+               if (row->next()) {
+                       top_row_ = row->next();
+                       top_row_offset_ -= row->height();
+               } else {
+                       top_row_ = row_prev;
+                       top_row_offset_ = 0;
+               }
+       }
 
        height -= row->height(); // the text becomes smaller
 
@@ -2034,9 +2043,10 @@ void LyXText::cursorUp(BufferView * bview, bool selecting) const
        int y = cursor.y() - cursor.row()->baseline() - 1;
        setCursorFromCoordinates(bview, x, y);
        if (!selecting) {
-               int y1 = cursor.iy() - first_y;
+               int topy = top_y();
+               int y1 = cursor.iy() - topy;
                int y2 = y1;
-               y -= first_y;
+               y -= topy;
                Inset * inset_hit = checkInsetHit(bview, x, y1);
                if (inset_hit && isHighlyEditableInset(inset_hit)) {
                        inset_hit->edit(bview, x, y - (y2 - y1), mouse_button::none);
@@ -2057,9 +2067,10 @@ void LyXText::cursorDown(BufferView * bview, bool selecting) const
                cursor.row()->height() + 1;
        setCursorFromCoordinates(bview, x, y);
        if (!selecting && cursor.row() == cursor.irow()) {
-               int y1 = cursor.iy() - first_y;
+               int topy = top_y();
+               int y1 = cursor.iy() - topy;
                int y2 = y1;
-               y -= first_y;
+               y -= topy;
                Inset * inset_hit = checkInsetHit(bview, x, y1);
                if (inset_hit && isHighlyEditableInset(inset_hit)) {
                        inset_hit->edit(bview, x, y - (y2 - y1), mouse_button::none);
index bb4da122a5304a1be1dcc2813389968e39e48be7..fe595ee31ede8f253f1b66ef62639b2a3a99ee6b 100644 (file)
@@ -143,7 +143,7 @@ namespace {
 
 Inset * LyXText::checkInsetHit(BufferView * bv, int & x, int & y) const
 {
-       int y_tmp = y + first_y;
+       int y_tmp = y + top_y();
 
        LyXCursor cur;
        setCursorFromCoordinates(bv, cur, x, y_tmp);
@@ -241,15 +241,15 @@ void LyXText::gotoInset(BufferView * bv, Inset::Code code, bool same_content)
 void LyXText::cursorPrevious(BufferView * bv)
 {
        if (!cursor.row()->previous()) {
-               if (first_y > 0) {
-                       int new_y = bv->text->first_y - bv->workHeight();
+               if (top_y() > 0) {
+                       int new_y = top_y() - bv->workHeight();
                        bv->screen().draw(bv->text, bv, new_y < 0 ? 0 : new_y);
                        bv->updateScrollbar();
                }
                return;
        }
 
-       int y = first_y;
+       int y = top_y();
        Row * cursorrow = cursor.row();
 
        setCursorFromCoordinates(bv, cursor.x_fix(), y);
@@ -264,7 +264,7 @@ void LyXText::cursorPrevious(BufferView * bv)
                // 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->first_y - bv->workHeight();
+               new_y = bv->text->top_y() - bv->workHeight();
 #endif
        } else {
                if (inset_owner) {
@@ -284,7 +284,7 @@ void LyXText::cursorPrevious(BufferView * bv)
                LyXCursor cur;
                setCursor(bv, cur, cursor.row()->previous()->par(),
                                                cursor.row()->previous()->pos(), false);
-               if (cur.y() > first_y) {
+               if (cur.y() > top_y()) {
                        cursorUp(bv, true);
                }
        }
@@ -297,18 +297,17 @@ void LyXText::cursorNext(BufferView * bv)
        if (!cursor.row()->next()) {
                int y = cursor.y() - cursor.row()->baseline() +
                        cursor.row()->height();
-               if (y > int(first_y + bv->workHeight())) {
-                       bv->screen().draw(bv->text, bv,
-                                                 bv->text->first_y + bv->workHeight());
+               if (y > top_y() + bv->workHeight()) {
+                       bv->screen().draw(bv->text, bv, top_y() + bv->workHeight());
                        bv->updateScrollbar();
                }
                return;
        }
 
-       int y = first_y + bv->workHeight();
-       if (inset_owner && !first_y) {
+       int y = top_y() + bv->workHeight();
+       if (inset_owner && !top_y()) {
                y -= (bv->text->cursor.iy()
-                         - bv->text->first_y
+                         - bv->text->top_y()
                          + bv->theLockingInset()->insetInInsetY());
        }
 
@@ -328,7 +327,7 @@ void LyXText::cursorNext(BufferView * bv)
                // 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->first_y + bv->workHeight();
+               new_y = bv->text->top_y() + bv->workHeight();
 #endif
        } else {
                if (inset_owner) {
@@ -344,7 +343,7 @@ void LyXText::cursorNext(BufferView * bv)
                LyXCursor cur;
                setCursor(bv, cur, cursor.row()->next()->par(),
                                                cursor.row()->next()->pos(), false);
-               if (cur.y() < int(first_y + bv->workHeight())) {
+               if (cur.y() < top_y() + bv->workHeight()) {
                        cursorDown(bv, true);
                }
        }
@@ -1298,7 +1297,7 @@ Inset::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->first_y;
+                       cmd1.y = cmd.y - cursor.iy() + bv->text->top_y();
                        tli->localDispatch(cmd1);
                        break;
                }
@@ -1315,7 +1314,7 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
                bv->screen().hideCursor();
 
                Row * cursorrow = bv->text->cursor.row();
-               bv->text->setCursorFromCoordinates(bv, cmd.x, cmd.y + bv->text->first_y);
+               bv->text->setCursorFromCoordinates(bv, cmd.x, cmd.y + bv->text->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
@@ -1327,7 +1326,7 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
        #endif
                // This is to allow jumping over large insets
                if (cursorrow == bv->text->cursor.row()) {
-                       if (cmd.y >= int(bv->workHeight()))
+                       if (cmd.y >= bv->workHeight())
                                bv->text->cursorDown(bv, false);
                        else if (cmd.y < 0)
                                bv->text->cursorUp(bv, false);
@@ -1376,7 +1375,7 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
                        paste_internally = true;
                }
 
-               int const screen_first = bv->text->first_y;
+               int const screen_first = bv->text->top_y();
 
                if (bv->theLockingInset()) {
                        // We are in inset locking mode