]> git.lyx.org Git - features.git/blobdiff - src/BufferView.cpp
Don't save background color in Text. Hand it down at drawing time.
[features.git] / src / BufferView.cpp
index fad8f4a43a8e2f80226be4f0bb5c98cdaa2aa615..a4185096250703965050569052e0f91350220276 100644 (file)
@@ -134,7 +134,7 @@ BufferView::BufferView(Buffer & buf)
 
        cursor_.push(buffer_.inset());
        cursor_.resetAnchor();
-       buffer_.text().setCurrentFont(cursor_);
+       cursor_.setCurrentFont();
 
        if (graphics::Previews::status() != LyXRC::PREVIEW_OFF)
                graphics::Previews::get().generateBufferPreviews(buffer_);
@@ -344,7 +344,7 @@ void BufferView::scrollDocView(int value)
 
 void BufferView::setCursorFromScrollbar()
 {
-       Text & t = buffer_.text();
+       TextMetrics & tm = text_metrics_[&buffer_.text()];
 
        int const height = 2 * defaultRowHeight();
        int const first = height;
@@ -358,14 +358,14 @@ void BufferView::setCursorFromScrollbar()
                // We reset the cursor because bv_funcs::status() does not
                // work when the cursor is within mathed.
                cur.reset(buffer_.inset());
-               t.setCursorFromCoordinates(cur, 0, first);
+               tm.setCursorFromCoordinates(cur, 0, first);
                cur.clearSelection();
                break;
        case bv_funcs::CUR_BELOW:
                // We reset the cursor because bv_funcs::status() does not
                // work when the cursor is within mathed.
                cur.reset(buffer_.inset());
-               t.setCursorFromCoordinates(cur, 0, last);
+               tm.setCursorFromCoordinates(cur, 0, last);
                cur.clearSelection();
                break;
        case bv_funcs::CUR_INSIDE:
@@ -373,7 +373,7 @@ void BufferView::setCursorFromScrollbar()
                int const newy = min(last, max(y, first));
                if (y != newy) {
                        cur.reset(buffer_.inset());
-                       t.setCursorFromCoordinates(cur, 0, newy);
+                       tm.setCursorFromCoordinates(cur, 0, newy);
                }
        }
 }
@@ -457,7 +457,7 @@ bool BufferView::moveToPosition(pit_type bottom_pit, pos_type bottom_pos,
                // Note: only bottom (document) level pit is set.
                setCursor(doc_it);
                // set the current font.
-               buffer_.text().setCurrentFont(cursor_);
+               cursor_.setCurrentFont();
                // center the screen on this new position.
                center();
        }
@@ -469,7 +469,7 @@ bool BufferView::moveToPosition(pit_type bottom_pit, pos_type bottom_pos,
 void BufferView::translateAndInsert(char_type c, Text * t, Cursor & cur)
 {
        if (lyxrc.rtl_support) {
-               if (cursor_.innerText()->real_current_font.isRightToLeft()) {
+               if (cursor_.real_current_font.isRightToLeft()) {
                        if (intl_->keymap == Intl::PRIMARY)
                                intl_->keyMapSec();
                } else {
@@ -981,15 +981,13 @@ void BufferView::resize(int width, int height)
        width_ = width;
        height_ = height;
 
-       // The complete text metrics will be redone.
-       text_metrics_.clear();
        updateMetrics(false);
 }
 
 
 Inset const * BufferView::getCoveringInset(Text const & text, int x, int y)
 {
-       pit_type pit = text.getPitNearY(*this, y);
+       pit_type pit = text_metrics_[&text].getPitNearY(y);
        BOOST_ASSERT(pit != -1);
        Paragraph const & par = text.getPar(pit);
 
@@ -1107,7 +1105,7 @@ bool BufferView::workAreaDispatch(FuncRequest const & cmd0)
        }
 
        // Build temporary cursor.
-       Inset * inset = buffer_.text().editXY(cur, cmd.x, cmd.y);
+       Inset * inset = text_metrics_[&buffer_.text()].editXY(cur, cmd.x, cmd.y);
 
        // Put anchor at the same position.
        cur.resetAnchor();
@@ -1339,7 +1337,6 @@ ViewMetricsInfo const & BufferView::viewMetricsInfo()
 void BufferView::updateMetrics(bool singlepar)
 {
        Text & buftext = buffer_.text();
-       TextMetrics & tm = textMetrics(&buftext);
        pit_type size = int(buftext.paragraphs().size());
 
        if (anchor_ref_ > int(buftext.paragraphs().size() - 1)) {
@@ -1353,9 +1350,12 @@ void BufferView::updateMetrics(bool singlepar)
        
                // Clear out paragraph metrics to avoid having invalid metrics
                // in the cache from paragraphs not relayouted below
-               tm.clear();
+               // The complete text metrics will be redone.
+               text_metrics_.clear();
        }
 
+       TextMetrics & tm = textMetrics(&buftext);
+
        // If the paragraph metrics has changed, we can not
        // use the singlepar optimisation.
        if (singlepar
@@ -1539,27 +1539,30 @@ void BufferView::draw(frontend::Painter & pain)
        // FIXME: We should also distinguish DecorationUpdate to avoid text
        // drawing if possible. This is not possible to do easily right now
        // because of the single backing pixmap.
-       bool repaintAll = select 
+       pi.full_repaint = select 
                || metrics_info_.update_strategy != SingleParUpdate;
 
-       if (repaintAll)
+       if (pi.full_repaint)
                // Clear background (if not delegated to rows)
                pain.fillRectangle(0, metrics_info_.y1, width_,
-                       metrics_info_.y2 - metrics_info_.y1, text.backgroundColor());
+                       metrics_info_.y2 - metrics_info_.y1,
+                       buffer_.inset().backgroundColor());
 
        TextMetrics const & tm = text_metrics_[&text];
 
        if (select)
-               text.drawSelection(pi, 0, 0);
+               tm.drawSelection(pi, 0, 0);
 
        int yy = metrics_info_.y1;
        // draw contents
+       LYXERR(Debug::PAINTING) << "\t\t*** START DRAWING ***" << endl;
        for (pit_type pit = metrics_info_.p1; pit <= metrics_info_.p2; ++pit) {
                ParagraphMetrics const & pm = tm.parMetrics(pit);
                yy += pm.ascent();
-               tm.drawParagraph(pi, pit, 0, yy, repaintAll);
+               tm.drawParagraph(pi, pit, 0, yy);
                yy += pm.descent();
        }
+       LYXERR(Debug::PAINTING) << "\n\t\t*** END DRAWING  ***" << endl;
 
        // and grey out above (should not happen later)
 //     lyxerr << "par ascent: " << text.getPar(metrics_info_.p1).ascent() << endl;