]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insettext.C
Enable the external inset to handle unknown templates gracefully.
[lyx.git] / src / insets / insettext.C
index c2e92f51d6be2529ec2c574669afad8bd8ea6ec4..d13ead97c16267b2df8f63debfe2b316b9bcac6c 100644 (file)
@@ -39,7 +39,7 @@
 #include "sgml.h"
 #include "rowpainter.h"
 #include "insetnewline.h"
-#include "Lsstream.h"
+#include "metricsinfo.h"
 
 #include "frontends/Alert.h"
 #include "frontends/Dialogs.h"
@@ -224,7 +224,7 @@ void InsetText::clear(bool just_mark_erased)
 }
 
 
-Inset * InsetText::clone(Buffer const &) const
+Inset * InsetText::clone() const
 {
        return new InsetText(*this);
 }
@@ -293,15 +293,14 @@ void InsetText::read(Buffer const * buf, LyXLex & lex)
 }
 
 
-void InsetText::dimension(BufferView * bv, LyXFont const &,
-       Dimension & dim) const
+void InsetText::metrics(MetricsInfo & mi, Dimension & dim) const
 {
+       BufferView * bv = mi.base.bv;
        LyXText * text = getLyXText(bv);
        dim.asc = text->rows().begin()->ascent_of_text() + TEXT_TO_INSET_OFFSET;
        dim.des = text->height - dim.asc + TEXT_TO_INSET_OFFSET;
        dim.wid = max(textWidth(bv), int(text->width)) + 2 * TEXT_TO_INSET_OFFSET;
        dim.wid = max(dim.wid, 10);
-       // cache it
        dim_ = dim;
 }
 
@@ -321,38 +320,34 @@ int InsetText::textWidth(BufferView * bv, bool fordraw) const
 }
 
 
-void InsetText::draw(BufferView * bv, LyXFont const & f,
-                    int baseline, float & x) const
+void InsetText::draw(PainterInfo & pi, int x, int baseline) const
 {
        if (nodraw())
                return;
 
        // update our idea of where we are. Clearly, we should
        // not have to know this information.
-       if (top_x != int(x))
-               top_x = int(x);
-
-       int const start_x = int(x);
+       if (top_x != x)
+               top_x = x;
 
-       Painter & pain = bv->painter();
+       int const start_x = x;
 
-       // call this method so that dim_ has the right value
-       dimension(bv, f, dim_);
+       BufferView * bv = pi.base.bv;
+       Painter & pain = pi.pain;
 
        // repaint the background if needed
        if (backgroundColor() != LColor::background)
                clearInset(bv, start_x + TEXT_TO_INSET_OFFSET, baseline);
 
        // no draw is necessary !!!
-       if ((drawFrame_ == LOCKED) && !locked && paragraphs.begin()->empty()) {
+       if (drawFrame_ == LOCKED && !locked && paragraphs.begin()->empty()) {
                top_baseline = baseline;
-               x += width(bv, f);
                need_update = NONE;
                return;
        }
 
        if (!owner())
-               x += static_cast<float>(scroll());
+               x += scroll();
 
        top_baseline = baseline;
        top_y = baseline - dim_.asc;
@@ -2598,40 +2593,6 @@ void InsetText::appendParagraphs(Buffer * buffer, ParagraphList & plist)
 #warning FIXME Check if Changes stuff needs changing here. (Lgb)
 // And it probably does. You have to take a look at this John. (Lgb)
 #warning John, have a look here. (Lgb)
-#if 0
-       BufferParams const & bparams = buffer->params;
-       Paragraph * buf;
-       Paragraph * tmpbuf = newpar;
-       Paragraph * lastbuffer = buf = new Paragraph(*tmpbuf, false);
-       if (bparams.tracking_changes)
-               buf->cleanChanges();
-
-       while (tmpbuf->next()) {
-               tmpbuf = tmpbuf->next();
-               lastbuffer->next(new Paragraph(*tmpbuf, false));
-               lastbuffer->next()->previous(lastbuffer);
-               lastbuffer = lastbuffer->next();
-               if (bparams.tracking_changes)
-                       lastbuffer->cleanChanges();
-       }
-
-       lastbuffer = &*(paragraphs.begin());
-       while (lastbuffer->next())
-               lastbuffer = lastbuffer->next();
-       if (!newpar->empty() && !lastbuffer->empty() &&
-               !lastbuffer->isSeparator(lastbuffer->size() - 1))
-       {
-               lastbuffer->insertChar(lastbuffer->size(), ' ');
-       }
-
-       // make the buf exactly the same layout than our last paragraph
-       buf->makeSameLayout(lastbuffer);
-
-       // paste it!
-       lastbuffer->next(buf);
-       buf->previous(lastbuffer);
-       mergeParagraph(buffer->params, paragraphs, lastbuffer);
-#else
        ParagraphList::iterator pit = plist.begin();
        ParagraphList::iterator ins = paragraphs.insert(paragraphs.end(), *pit);
        ++pit;
@@ -2642,8 +2603,6 @@ void InsetText::appendParagraphs(Buffer * buffer, ParagraphList & plist)
                paragraphs.push_back(*pit);
        }
 
-#endif
-
        reinitLyXText();
 }