]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insettext.C
* src/LyXAction.C: mark goto-clear-bookmark as working without buffer
[lyx.git] / src / insets / insettext.C
index d8c7718f0bf79fe1e2f550f84c5224e1ddf78503..9b2233c5ddd22bf0687262998cb62bdd4505d5fd 100644 (file)
@@ -76,7 +76,7 @@ int InsetText::border_ = 2;
 
 
 InsetText::InsetText(BufferParams const & bp)
-       : drawFrame_(false), frame_color_(LColor::insetframe), text_(0)
+       : drawFrame_(false), frame_color_(LColor::insetframe)
 {
        paragraphs().push_back(Paragraph());
        paragraphs().back().layout(bp.getLyXTextClass().defaultLayout());
@@ -103,7 +103,6 @@ InsetText::InsetText(InsetText const & in)
 
 
 InsetText::InsetText()
-       : text_(0)
 {}
 
 
@@ -164,36 +163,41 @@ void InsetText::read(Buffer const & buf, LyXLex & lex)
 }
 
 
-void InsetText::metrics(MetricsInfo & mi, Dimension & dim) const
+bool InsetText::metrics(MetricsInfo & mi, Dimension & dim) const
 {
+       TextMetrics & tm = mi.base.bv->textMetrics(&text_);
+
        //lyxerr << "InsetText::metrics: width: " << mi.base.textwidth << endl;
        mi.base.textwidth -= 2 * border_;
        font_ = mi.base.font;
        // Hand font through to contained lyxtext:
        text_.font_ = mi.base.font;
-       text_.metrics(mi, dim);
+       tm.metrics(mi, dim);
        dim.asc += border_;
        dim.des += border_;
        dim.wid += 2 * border_;
        mi.base.textwidth += 2 * border_;
+       bool const changed = dim_ != dim;
        dim_ = dim;
+       return changed;
 }
 
 
 void InsetText::draw(PainterInfo & pi, int x, int y) const
 {
-       BOOST_ASSERT(!text_.paragraphs().front().rows().empty());
        // update our idea of where we are
        setPosCache(pi, x, y);
 
+       TextMetrics & tm = pi.base.bv->textMetrics(&text_);
+
        text_.background_color_ = backgroundColor();
        text_.draw(pi, x + border_, y);
 
        if (drawFrame_) {
-               int const w = text_.width() + 2 * border_;
-               int const a = text_.ascent() + border_;
-               int const h = a + text_.descent() + border_;
-               pi.pain.rectangle(x, y - a, (Wide() ? text_.maxwidth_ : w), h,
+               int const w = tm.width() + 2 * border_;
+               int const a = tm.ascent() + border_;
+               int const h = a + tm.descent() + border_;
+               pi.pain.rectangle(x, y - a, (wide() ? tm.maxWidth() : w), h,
                        frameColor());
        }
 }
@@ -201,10 +205,12 @@ void InsetText::draw(PainterInfo & pi, int x, int y) const
 
 void InsetText::drawSelection(PainterInfo & pi, int x, int y) const
 {
-       int const w = text_.width() + 2 * border_;
-       int const a = text_.ascent() + border_;
-       int const h = a + text_.descent() + border_;
-       pi.pain.fillRectangle(x, y - a, (Wide() ? text_.maxwidth_ : w), h,
+       TextMetrics & tm = pi.base.bv->textMetrics(&text_);
+
+       int const w = tm.width() + 2 * border_;
+       int const a = tm.ascent() + border_;
+       int const h = a + tm.descent() + border_;
+       pi.pain.fillRectangle(x, y - a, (wide() ? tm.maxWidth() : w), h,
                backgroundColor());
        text_.drawSelection(pi, x, y);
 }
@@ -212,9 +218,11 @@ void InsetText::drawSelection(PainterInfo & pi, int x, int y) const
 
 bool InsetText::covers(BufferView const & bv, int x, int y) const
 {
+       TextMetrics const & tm = bv.textMetrics(&text_);
+
        return bv.coordCache().getInsets().has(this)
                        && x >= xo(bv)
-                       && x <= xo(bv) + width() + (Wide() ? text_.maxwidth_ : 0)
+                       && x <= xo(bv) + width() + (wide() ? tm.maxWidth() : 0)
                        && y >= yo(bv) - ascent()
                        && y <= yo(bv) + descent();
 }
@@ -311,7 +319,7 @@ int InsetText::plaintext(Buffer const & buf, odocstream & os,
        bool ref_printed = false;
        odocstringstream oss;
        for (; it != end; ++it)
-               asciiParagraph(buf, *it, oss, runparams, ref_printed);
+               writePlaintextParagraph(buf, *it, oss, runparams, ref_printed);
 
        docstring const str = oss.str();
        os << str;
@@ -338,8 +346,8 @@ void InsetText::validate(LaTeXFeatures & features) const
 void InsetText::cursorPos(BufferView const & bv,
                CursorSlice const & sl, bool boundary, int & x, int & y) const
 {
-       x = text_.cursorX(*bv.buffer(), sl, boundary) + border_;
-       y = text_.cursorY(sl, boundary);
+       x = text_.cursorX(bv, sl, boundary) + border_;
+       y = text_.cursorY(bv, sl, boundary);
 }