]> git.lyx.org Git - lyx.git/blobdiff - src/BufferView_pimpl.C
Forgot to save changed file ;)
[lyx.git] / src / BufferView_pimpl.C
index 05c59edf11d8d5ab07c1d826c5c38508ae648306..be1e1020be14f96ed295139960179bd0de536acc 100644 (file)
@@ -397,10 +397,8 @@ void BufferView::Pimpl::updateScreen()
 
 void BufferView::Pimpl::updateScrollbar()
 {
-       /* If the text is smaller than the working area, the scrollbar
-        * maximum must be the working area height. No scrolling will
-        * be possible */
        if (!bv_->text) {
+               lyxerr[Debug::GUI] << "no text in updateScrollbar" << endl;
                workarea_.setScrollbar(0, 1.0);
                return;
        }
@@ -408,42 +406,36 @@ void BufferView::Pimpl::updateScrollbar()
        long const text_height = bv_->text->height;
        long const work_height = workarea_.height();
 
-       if (text_height <= work_height) {
-               workarea_.setScrollbarBounds(0.0, 0.0);
-               current_scrollbar_value = bv_->text->first_y;
-               workarea_.setScrollbar(current_scrollbar_value, 1.0);
-               return;
-       }
-
        double const lineh = bv_->text->defaultHeight();
        double const slider_size =
                (text_height == 0) ? 1.0 : 1.0 / double(text_height);
 
-       static long old_text_height;
-       static double old_lineh;
-       static double old_slider_size;
+       lyxerr[Debug::GUI] << "text_height now " << text_height << endl;
+       lyxerr[Debug::GUI] << "work_height " << work_height << endl;
 
-       if (text_height != old_text_height) {
-               workarea_.setScrollbarBounds(0.0,
-                                            text_height - work_height);
-               old_text_height = text_height;
-       }
-       if (lineh != old_lineh) {
-               workarea_.setScrollbarIncrements(lineh);
-               old_lineh = lineh;
-       }
-       if (current_scrollbar_value != bv_->text->first_y
-           || slider_size != old_slider_size) {
+       /* If the text is smaller than the working area, the scrollbar
+        * maximum must be the working area height. No scrolling will
+        * be possible */
+       if (text_height <= work_height) {
+               lyxerr[Debug::GUI] << "doc smaller than workarea !" << endl;
+               workarea_.setScrollbarBounds(0.0, 0.0);
                current_scrollbar_value = bv_->text->first_y;
-               workarea_.setScrollbar(current_scrollbar_value, slider_size);
-               old_slider_size = slider_size;
+               workarea_.setScrollbar(current_scrollbar_value, 1.0);
+               return;
        }
+
+       workarea_.setScrollbarBounds(0.0, text_height - work_height);
+       workarea_.setScrollbarIncrements(lineh);
+       current_scrollbar_value = bv_->text->first_y;
+       workarea_.setScrollbar(current_scrollbar_value, slider_size);
 }
 
 
 // Callback for scrollbar slider
 void BufferView::Pimpl::scrollCB(double value)
 {
+       lyxerr[Debug::GUI] << "scrollCB of " << value << endl;
+
        if (!buffer_) return;
 
        current_scrollbar_value = long(value);
@@ -555,12 +547,12 @@ void BufferView::Pimpl::workAreaMotionNotify(int x, int y, unsigned int state)
                                                  cursor.par(), cursor.pos());
                int width = bv_->theLockingInset()->width(bv_, font);
                int inset_x = font.isVisibleRightToLeft()
-                       ? cursor.x() - width : cursor.x();
+                       ? cursor.ix() - width : cursor.ix();
                int start_x = inset_x + bv_->theLockingInset()->scroll();
                bv_->theLockingInset()->
                        insetMotionNotify(bv_,
                                          x - start_x,
-                                         y - cursor.y() + bv_->text->first_y,
+                                         y - cursor.iy() + bv_->text->first_y,
                                          state);
                return;
        }
@@ -616,6 +608,8 @@ void BufferView::Pimpl::workAreaButtonPress(int xpos, int ypos,
                paste_internally = true;
        }
 
+       int const screen_first = bv_->text->first_y;
+
        if (bv_->theLockingInset()) {
                // We are in inset locking mode
 
@@ -634,8 +628,6 @@ void BufferView::Pimpl::workAreaButtonPress(int xpos, int ypos,
                selection_possible = true;
        screen_->hideCursor();
 
-       int const screen_first = bv_->text->first_y;
-
        // Clear the selection
        screen_->toggleSelection(bv_->text, bv_);
        bv_->text->clearSelection();
@@ -650,12 +642,16 @@ void BufferView::Pimpl::workAreaButtonPress(int xpos, int ypos,
                selection_possible = false;
                owner_->updateLayoutChoice();
                owner_->message(inset->editMessage());
-               // IMO the inset has to be first in edit-mode and then we send the
-               // button press. (Jug 20020222)
-               inset->edit(bv_); //, xpos, ypos, button);
+               //inset->edit(bv_, xpos, ypos, button);
+               // We just have to lock the inset before calling a PressEvent on it!
+               // we don't need the edit() call here! (Jug20020329)
+               if (!bv_->lockInset(inset)) {
+                       lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
+               }
                inset->insetButtonPress(bv_, xpos, ypos, button);
                return;
        }
+       // I'm not sure we should continue here if we hit an inset (Jug20020403)
 
        // Right click on a footnote flag opens float menu
        if (button == 3) {
@@ -883,6 +879,10 @@ void BufferView::Pimpl::workAreaButtonRelease(int x, int y,
                        inset->insetButtonRelease(bv_, x, y, button);
                } else {
                        inset_hit->insetButtonRelease(bv_, x, y, button);
+                       // IMO this is a grosshack! Inset's should be changed so that
+                       // they call the actions they have to do with the insetButtonRel.
+                       // function and not in the edit(). This should be changed
+                       // (Jug 20020329)
                        inset_hit->edit(bv_, x, y, button);
                }
                return;
@@ -912,13 +912,13 @@ Box BufferView::Pimpl::insetDimensions(LyXText const & text,
 
        int const width = inset.width(bv_, font);
        int const inset_x = font.isVisibleRightToLeft()
-               ? (cursor.x() - width) : cursor.x();
+               ? (cursor.ix() - width) : cursor.ix();
 
        return Box(
                inset_x + inset.scroll(),
                inset_x + width,
-               cursor.y() - inset.ascent(bv_, font),
-               cursor.y() + inset.descent(bv_, font));
+               cursor.iy() - inset.ascent(bv_, font),
+               cursor.iy() + inset.descent(bv_, font));
 }
 
 
@@ -951,7 +951,7 @@ Inset * BufferView::Pimpl::checkInset(LyXText const & text,
 
        x -= b.x1;
        // The origin of an inset is on the baseline
-       y -= (text.cursor.y());
+       y -= text.cursor.iy();
 
        return inset;
 }
@@ -1167,19 +1167,27 @@ void BufferView::Pimpl::cursorPrevious(LyXText * text)
        int y = text->first_y;
        Row * cursorrow = text->cursor.row();
 
-       text->setCursorFromCoordinates(bv_, bv_->text->cursor.x_fix(), y);
+       text->setCursorFromCoordinates(bv_, text->cursor.x_fix(), y);
        finishUndo();
        // This is to allow jumping over large insets
        if ((cursorrow == text->cursor.row()))
                text->cursorUp(bv_);
 
-       if (text->inset_owner ||
-           text->cursor.row()->height() < workarea_.height())
-               screen_->draw(bv_->text, bv_,
+       if (text->inset_owner) {
+               int new_y = bv_->text->cursor.iy()
+                       + bv_->theLockingInset()->insetInInsetY()
+                       + y
+                       + text->cursor.row()->height()
+                       - workarea_.height() + 1;
+
+               screen_->draw(bv_->text, bv_, new_y < 0 ? 0 : new_y);
+       } else if (text->cursor.row()->height() < workarea_.height()) {
+               screen_->draw(text, bv_,
                              text->cursor.y()
                              - text->cursor.row()->baseline()
                              + text->cursor.row()->height()
                              - workarea_.height() + 1);
+       }
        updateScrollbar();
 }
 
@@ -1190,8 +1198,11 @@ void BufferView::Pimpl::cursorNext(LyXText * text)
                return;
 
        int y = text->first_y + workarea_.height();
-//     if (text->inset_owner)
-//             y += bv_->text->first;
+       if (text->inset_owner && !text->first_y) {
+               y -= (bv_->text->cursor.iy()
+                         - bv_->text->first_y
+                         + bv_->theLockingInset()->insetInInsetY());
+       }
        text->getRowNearY(y);
 
        Row * cursorrow = text->cursor.row();
@@ -1201,10 +1212,16 @@ void BufferView::Pimpl::cursorNext(LyXText * text)
        if ((cursorrow == bv_->text->cursor.row()))
                text->cursorDown(bv_);
 
-       if (text->inset_owner ||
-           text->cursor.row()->height() < workarea_.height())
-               screen_->draw(bv_->text, bv_, text->cursor.y() -
+       if (text->inset_owner) {
+               screen_->draw(bv_->text, bv_,
+                             bv_->text->cursor.iy()
+                                 + bv_->theLockingInset()->insetInInsetY()
+                                 + y - text->cursor.row()->baseline());
+       } else if (text->cursor.irow()->height() < workarea_.height()) {
+               screen_->draw(text, bv_, text->cursor.y() -
                              text->cursor.row()->baseline());
+       } else {
+       }
        updateScrollbar();
 }
 
@@ -1438,7 +1455,7 @@ void BufferView::Pimpl::stuffClipboard(string const & stuff) const
 
 
 inline
-void BufferView::Pimpl::moveCursorUpdate(bool selecting)
+void BufferView::Pimpl::moveCursorUpdate(bool selecting, bool fitcur)
 {
        LyXText * lt = bv_->getLyXText();
 
@@ -1450,7 +1467,10 @@ void BufferView::Pimpl::moveCursorUpdate(bool selecting)
                        updateInset(lt->inset_owner, false);
        }
        if (lt->bv_owner) {
-               update(lt, BufferView::SELECT|BufferView::FITCUR);
+               if (fitcur)
+                       update(lt, BufferView::SELECT|BufferView::FITCUR);
+               else
+                       update(lt, BufferView::SELECT);
                showCursor();
        }
 
@@ -2040,7 +2060,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
                update(lt, BufferView::UPDATE);
                cursorNext(lt);
                finishUndo();
-               moveCursorUpdate(false);
+               moveCursorUpdate(false, false);
                owner_->showState();
        }
        break;
@@ -2193,7 +2213,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
 
                update(lt,
                       BufferView::SELECT|BufferView::FITCUR);
-               lt->cursorUp(bv_);
+               lt->cursorUp(bv_, true);
                finishUndo();
                moveCursorUpdate(true);
                owner_->showState();
@@ -2206,7 +2226,7 @@ bool BufferView::Pimpl::Dispatch(kb_action action, string const & argument)
 
                update(lt,
                       BufferView::SELECT|BufferView::FITCUR);
-               lt->cursorDown(bv_);
+               lt->cursorDown(bv_, true);
                finishUndo();
                moveCursorUpdate(true);
                owner_->showState();