]> git.lyx.org Git - lyx.git/blobdiff - src/BufferView.cpp
fix "make check" with gcc 4.3
[lyx.git] / src / BufferView.cpp
index 01ee8fd0a5fb1e390cf336ac153a8b7c731ee8ab..3b31fd5b5f0192eeb9e0770f1d0bb35dadf1c1bf 100644 (file)
@@ -150,11 +150,13 @@ bool findInset(DocIterator & dit, vector<InsetCode> const & codes,
 
        if (!findNextInset(tmpdit, codes, contents)) {
                if (dit.depth() != 1 || dit.pit() != 0 || dit.pos() != 0) {
-                       tmpdit  = doc_iterator_begin(tmpdit.bottom().inset());
+                       Inset * inset = &tmpdit.bottom().inset();
+                       tmpdit = doc_iterator_begin(&inset->buffer(), inset);
                        if (!findNextInset(tmpdit, codes, contents))
                                return false;
-               } else
+               } else {
                        return false;
+               }
        }
 
        dit = tmpdit;
@@ -216,7 +218,7 @@ struct BufferView::Private
        Private(BufferView & bv): wh_(0), cursor_(bv),
                anchor_pit_(0), anchor_ypos_(0),
                inlineCompletionUniqueChars_(0),
-               last_inset_(0), gui_(0)
+               last_inset_(0), bookmark_edit_position_(0), gui_(0)
        {}
 
        ///
@@ -259,6 +261,9 @@ struct BufferView::Private
          */
        Inset * last_inset_;
 
+       // cache for id of the paragraph which was edited the last time
+       int bookmark_edit_position_;
+
        mutable TextMetricsCache text_metrics_;
 
        /// Whom to notify.
@@ -272,11 +277,13 @@ struct BufferView::Private
 
 
 BufferView::BufferView(Buffer & buf)
-       : width_(0), height_(0), full_screen_(false), buffer_(buf), d(new Private(*this))
+       : width_(0), height_(0), full_screen_(false), buffer_(buf),
+      d(new Private(*this))
 {
        d->xsel_cache_.set = false;
        d->intl_.initKeyMapper(lyxrc.use_kbmap);
 
+       d->cursor_.setBuffer(&buf);
        d->cursor_.push(buffer_.inset());
        d->cursor_.resetAnchor();
        d->cursor_.setCurrentFont();
@@ -564,7 +571,7 @@ void BufferView::scrollDocView(int value)
 
        // cut off at the top
        if (value <= d->scrollbarParameters_.min) {
-               DocIterator dit = doc_iterator_begin(buffer_.inset());
+               DocIterator dit = doc_iterator_begin(&buffer_);
                showCursor(dit);
                LYXERR(Debug::SCROLLING, "scroll to top");
                return;
@@ -572,7 +579,7 @@ void BufferView::scrollDocView(int value)
 
        // cut off at the bottom
        if (value >= d->scrollbarParameters_.max) {
-               DocIterator dit = doc_iterator_end(buffer_.inset());
+               DocIterator dit = doc_iterator_end(&buffer_);
                dit.backwardPos();
                showCursor(dit);
                LYXERR(Debug::SCROLLING, "scroll to bottom");
@@ -596,7 +603,7 @@ void BufferView::scrollDocView(int value)
                return;
        }
 
-       DocIterator dit = doc_iterator_begin(buffer_.inset());
+       DocIterator dit = doc_iterator_begin(&buffer_);
        dit.pit() = i;
        LYXERR(Debug::SCROLLING, "value = " << value << " -> scroll to pit " << i);
        showCursor(dit);
@@ -666,9 +673,19 @@ CursorStatus BufferView::cursorStatus(DocIterator const & dit) const
 }
 
 
+void BufferView::bookmarkEditPosition()
+{
+       // Don't eat cpu time for each keystroke
+       if (d->cursor_.paragraph().id() == d->bookmark_edit_position_)
+               return;
+       saveBookmark(0);
+       d->bookmark_edit_position_ = d->cursor_.paragraph().id();
+}
+
+
 void BufferView::saveBookmark(unsigned int idx)
 {
-       // tenatively save bookmark, id and pos will be used to
+       // tentatively save bookmark, id and pos will be used to
        // acturately locate a bookmark in a 'live' lyx session.
        // pit and pos will be updated with bottom level pit/pos
        // when lyx exits.
@@ -724,7 +741,7 @@ bool BufferView::moveToPosition(pit_type bottom_pit, pos_type bottom_pos,
        // it will be restored to the left of the outmost inset that contains
        // the bookmark.
        if (bottom_pit < int(buffer_.paragraphs().size())) {
-               dit = doc_iterator_begin(buffer_.inset());
+               dit = doc_iterator_begin(&buffer_);
                                
                dit.pit() = bottom_pit;
                dit.pos() = min(bottom_pos, dit.paragraph().size());
@@ -815,7 +832,8 @@ void BufferView::showCursor(DocIterator const & dit)
                if (ypos - row_dim.ascent() < 0)
                        scrolled = scrollUp(- ypos + row_dim.ascent());
                else if (ypos + row_dim.descent() > height_)
-                       scrolled = scrollDown(ypos - height_ + row_dim.descent());
+                       scrolled = scrollDown(ypos - height_ + defaultRowHeight() ); 
+
                // else, nothing to do, the cursor is already visible so we just return.
                if (scrolled != 0) {
                        updateMetrics();
@@ -841,8 +859,10 @@ void BufferView::showCursor(DocIterator const & dit)
                d->anchor_ypos_ = offset + pm.ascent();
        else if (d->anchor_pit_ == max_pit)
                d->anchor_ypos_ = height_ - offset - row_dim.descent();
+       else if (offset > height_)
+               d->anchor_ypos_ = height_ - offset - defaultRowHeight();
        else
-               d->anchor_ypos_ = defaultRowHeight() * 2 - offset - row_dim.descent();
+               d->anchor_ypos_ = defaultRowHeight() * 2;
 
        updateMetrics();
        buffer_.changed();
@@ -899,10 +919,10 @@ FuncStatus BufferView::getStatus(FuncRequest const & cmd)
 
        case LFUN_COPY_LABEL_AS_REF: {
                // if there is an inset at cursor, see whether it
-               // handles the lfun, other start from scratch
+               // handles the lfun
                Inset * inset = cur.nextInset();
                if (!inset || !inset->getStatus(cur, cmd, flag))
-                       flag = lyx::getStatus(cmd);
+                       flag.setEnabled(false);
                break;
        }
 
@@ -989,6 +1009,7 @@ FuncStatus BufferView::getStatus(FuncRequest const & cmd)
                        case WRAP_CODE:
                        case NOTE_CODE:
                        case BRANCH_CODE:
+                       case PHANTOM_CODE:
                        case BOX_CODE:
                        case LISTINGS_CODE:
                                enable = (cmd.argument().empty() ||
@@ -1158,19 +1179,19 @@ bool BufferView::dispatch(FuncRequest const & cmd)
                buffer_.params().outputChanges = !buffer_.params().outputChanges;
                if (buffer_.params().outputChanges) {
                        bool dvipost    = LaTeXFeatures::isAvailable("dvipost");
-                       bool xcolorsoul = LaTeXFeatures::isAvailable("soul") &&
+                       bool xcolorulem = LaTeXFeatures::isAvailable("ulem") &&
                                          LaTeXFeatures::isAvailable("xcolor");
 
-                       if (!dvipost && !xcolorsoul) {
+                       if (!dvipost && !xcolorulem) {
                                Alert::warning(_("Changes not shown in LaTeX output"),
                                               _("Changes will not be highlighted in LaTeX output, "
-                                                "because neither dvipost nor xcolor/soul are installed.\n"
+                                                "because neither dvipost nor xcolor/ulem are installed.\n"
                                                 "Please install these packages or redefine "
                                                 "\\lyxadded and \\lyxdeleted in the LaTeX preamble."));
-                       } else if (!xcolorsoul) {
+                       } else if (!xcolorulem) {
                                Alert::warning(_("Changes not shown in LaTeX output"),
                                               _("Changes will not be highlighted in LaTeX output "
-                                                "when using pdflatex, because xcolor and soul are not installed.\n"
+                                                "when using pdflatex, because xcolor and ulem are not installed.\n"
                                                 "Please install both packages or redefine "
                                                 "\\lyxadded and \\lyxdeleted in the LaTeX preamble."));
                        }
@@ -1308,8 +1329,8 @@ bool BufferView::dispatch(FuncRequest const & cmd)
                        from = cur.selectionBegin();
                        to = cur.selectionEnd();
                } else {
-                       from = doc_iterator_begin(buffer_.inset());
-                       to = doc_iterator_end(buffer_.inset());
+                       from = doc_iterator_begin(&buffer_);
+                       to = doc_iterator_end(&buffer_);
                }
                int const words = countWords(from, to);
                int const chars = countChars(from, to, false);
@@ -1395,11 +1416,15 @@ bool BufferView::dispatch(FuncRequest const & cmd)
                // if there is an inset at cursor, see whether it
                // can be modified.
                Inset * inset = cur.nextInset();
-               if (inset)
+               if (inset) {
+                       cur.recordUndo();
                        inset->dispatch(cur, tmpcmd);
+               }
                // if it did not work, try the underlying inset.
-               if (!inset || !cur.result().dispatched())
+               if (!inset || !cur.result().dispatched()) {
+                       cur.recordUndo();
                        cur.dispatch(tmpcmd);
+               }
 
                if (!cur.result().dispatched())
                        // It did not work too; no action needed.
@@ -1495,7 +1520,7 @@ bool BufferView::dispatch(FuncRequest const & cmd)
 
                FuncRequest fr(LFUN_INSET_TOGGLE, action);
 
-               Inset & inset = cur.buffer().inset();
+               Inset & inset = cur.buffer()->inset();
                InsetIterator it  = inset_iterator_begin(inset);
                InsetIterator const end = inset_iterator_end(inset);
                for (; it != end; ++it) {
@@ -2218,10 +2243,11 @@ Point BufferView::coordOffset(DocIterator const & dit, bool boundary) const
 
 Point BufferView::getPos(DocIterator const & dit, bool boundary) const
 {
+       if (!paragraphVisible(dit))
+               return Point(-1, -1);
+
        CursorSlice const & bot = dit.bottom();
        TextMetrics const & tm = textMetrics(bot.text());
-       if (!tm.contains(bot.pit()))
-               return Point(-1, -1);
 
        Point p = coordOffset(dit, boundary); // offset from outer paragraph
        p.y_ += tm.parMetrics(bot.pit()).position();
@@ -2229,6 +2255,15 @@ Point BufferView::getPos(DocIterator const & dit, bool boundary) const
 }
 
 
+bool BufferView::paragraphVisible(DocIterator const & dit) const
+{
+       CursorSlice const & bot = dit.bottom();
+       TextMetrics const & tm = textMetrics(bot.text());
+
+       return tm.contains(bot.pit());
+}
+
+
 void BufferView::draw(frontend::Painter & pain)
 {
        if (height_ == 0 || width_ == 0)
@@ -2418,6 +2453,8 @@ bool samePar(DocIterator const & a, DocIterator const & b)
                return true;
        if (a.empty() || b.empty())
                return false;
+       if (a.depth() != b.depth())
+               return false;
        return &a.innerParagraph() == &b.innerParagraph();
 }