]> git.lyx.org Git - lyx.git/blobdiff - src/BufferView.cpp
fix "make check" with gcc 4.3
[lyx.git] / src / BufferView.cpp
index 1a873581c4d261ec47c4966f0c379e2010031d8d..3b31fd5b5f0192eeb9e0770f1d0bb35dadf1c1bf 100644 (file)
@@ -218,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)
        {}
 
        ///
@@ -261,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.
@@ -670,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.
@@ -819,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();
@@ -845,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();
@@ -903,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;
        }
 
@@ -993,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() ||
@@ -1162,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."));
                        }
@@ -1399,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.
@@ -2222,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();
@@ -2233,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)
@@ -2422,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();
 }