]> git.lyx.org Git - lyx.git/blobdiff - src/BufferView.cpp
Remove support for gcc 4.6
[lyx.git] / src / BufferView.cpp
index 50df1aade24dd36edb09bbe71c10d6d288b418df..2068f050cfeddf283516763aecc57adab3c6a8e6 100644 (file)
@@ -239,8 +239,7 @@ struct BufferView::Private
                last_inset_(0), clickable_inset_(false),
                mouse_position_cache_(),
                bookmark_edit_position_(-1), gui_(0),
-               horiz_scroll_offset_(0),
-               caret_ascent_(0), caret_descent_(0)
+               horiz_scroll_offset_(0)
        {
                xsel_cache_.set = false;
        }
@@ -253,6 +252,9 @@ struct BufferView::Private
        Update::flags update_flags_;
        ///
        CoordCache coord_cache_;
+       ///
+       typedef map<MathData const *, MathRow> MathRows;
+       MathRows math_rows_;
 
        /// Estimated average par height for scrollbar.
        int wh_;
@@ -316,12 +318,6 @@ struct BufferView::Private
        /// a slice pointing to the start of the row where the cursor
        /// is (at last draw time)
        CursorSlice current_row_slice_;
-
-       // The vertical size of the blinking caret. Only used for math
-       // Using it for text could be bad when undo restores the cursor
-       // current font, since the caret size could become wrong.
-       int caret_ascent_;
-       int caret_descent_;
 };
 
 
@@ -437,6 +433,20 @@ CoordCache const & BufferView::coordCache() const
 }
 
 
+MathRow const & BufferView::mathRow(MathData const * cell) const
+{
+       auto it = d->math_rows_.find(cell);
+       LATTEST(it != d->math_rows_.end());
+       return it->second;
+}
+
+
+void BufferView::setMathRow(MathData const * cell, MathRow const & mrow)
+{
+       d->math_rows_[cell] = mrow;
+}
+
+
 Buffer & BufferView::buffer()
 {
        return buffer_;
@@ -2542,8 +2552,9 @@ TextMetrics & BufferView::textMetrics(Text const * t)
        LBUFERR(t);
        TextMetricsCache::iterator tmc_it  = d->text_metrics_.find(t);
        if (tmc_it == d->text_metrics_.end()) {
-               tmc_it = d->text_metrics_.insert(
-                       make_pair(t, TextMetrics(this, const_cast<Text *>(t)))).first;
+               tmc_it = d->text_metrics_.emplace(std::piecewise_construct,
+                               std::forward_as_tuple(t),
+                               std::forward_as_tuple(this, const_cast<Text *>(t))).first;
        }
        return tmc_it->second;
 }
@@ -2777,6 +2788,7 @@ void BufferView::updateMetrics(Update::flags & update_flags)
 
        // Clear out the position cache in case of full screen redraw,
        d->coord_cache_.clear();
+       d->math_rows_.clear();
 
        // Clear out paragraph metrics to avoid having invalid metrics
        // in the cache from paragraphs not relayouted below
@@ -2874,7 +2886,7 @@ void BufferView::updatePosCache()
 }
 
 
-void BufferView::insertLyXFile(FileName const & fname)
+void BufferView::insertLyXFile(FileName const & fname, bool const ignorelang)
 {
        LASSERT(d->cursor_.inTexted(), return);
 
@@ -2892,8 +2904,12 @@ void BufferView::insertLyXFile(FileName const & fname)
                ErrorList & el = buffer_.errorList("Parse");
                // Copy the inserted document error list into the current buffer one.
                el = buf.errorList("Parse");
+               ParagraphList & pars = buf.paragraphs();
+               if (ignorelang)
+                       // set main language of imported file to context language
+                       buf.changeLanguage(buf.language(), d->cursor_.getFont().language());
                buffer_.undo().recordUndo(d->cursor_);
-               cap::pasteParagraphList(d->cursor_, buf.paragraphs(),
+               cap::pasteParagraphList(d->cursor_, pars,
                                             buf.params().documentClassPtr(), el);
                res = _("Document %1$s inserted.");
        } else {
@@ -3008,20 +3024,14 @@ bool BufferView::paragraphVisible(DocIterator const & dit) const
 }
 
 
-void BufferView::setCaretAscentDescent(int asc, int des)
-{
-       d->caret_ascent_ = asc;
-       d->caret_descent_ = des;
-}
-
-
 void BufferView::caretPosAndHeight(Point & p, int & h) const
 {
        int asc, des;
        Cursor const & cur = cursor();
        if (cur.inMathed()) {
-               asc = d->caret_ascent_;
-               des = d->caret_descent_;
+               MathRow const & mrow = mathRow(&cur.cell());
+               asc = mrow.caret_ascent;
+               des = mrow.caret_descent;
        } else {
                Font const font = cur.real_current_font;
                frontend::FontMetrics const & fm = theFontMetrics(font);