]> 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 0c50c6c0c1a17c667d1b1d3e1117bd52b02fbc0b..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"
@@ -155,14 +155,6 @@ InsetText::InsetText(InsetText const & in)
 }
 
 
-// InsetText::InsetText(InsetText const & in, bool same_id)
-//     : UpdatableInset(in, same_id), lt(0), in_update(false), do_resize(0),
-//       do_reinit(false)
-// {
-//     init(&in, same_id);
-// }
-
-
 InsetText & InsetText::operator=(InsetText const & it)
 {
        init(&it);
@@ -201,39 +193,6 @@ void InsetText::init(InsetText const * ins)
 }
 
 
-// void InsetText::init(InsetText const * ins, bool same_id)
-// {
-//     if (ins) {
-//             setParagraphData(ins->paragraphs, same_id);
-//             autoBreakRows = ins->autoBreakRows;
-//             drawFrame_ = ins->drawFrame_;
-//             frame_color = ins->frame_color;
-//             if (same_id)
-//                     id_ = ins->id_;
-//     } else {
-//             for_each(paragraphs.begin(), paragraphs.end(),
-//                      boost::bind(&Paragraph::setInsetOwner, _1, this));
-
-//             the_locking_inset = 0;
-//             drawFrame_ = NEVER;
-//             frame_color = LColor::insetframe;
-//             autoBreakRows = false;
-//     }
-//     top_y = 0;
-//     old_max_width = 0;
-//     no_selection = true;
-//     need_update = FULL;
-//     drawTextXOffset = 0;
-//     drawTextYOffset = 0;
-//     locked = false;
-//     old_par = 0;
-//     last_drawn_width = -1;
-//     cached_bview = 0;
-//     sstate.lpar = 0;
-//     in_insetAllowed = false;
-// }
-
-
 InsetText::~InsetText()
 {
        paragraphs.clear();
@@ -265,18 +224,12 @@ void InsetText::clear(bool just_mark_erased)
 }
 
 
-Inset * InsetText::clone(Buffer const &) const
+Inset * InsetText::clone() const
 {
        return new InsetText(*this);
 }
 
 
-// Inset * InsetText::clone(Buffer const &, bool same_id) const
-// {
-//     return new InsetText(*this, same_id);
-// }
-
-
 void InsetText::write(Buffer const * buf, ostream & os) const
 {
        os << "Text\n";
@@ -340,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;
 }
 
@@ -362,44 +314,40 @@ int InsetText::textWidth(BufferView * bv, bool fordraw) const
                           (int)getLyXText(bv)->width);
 
        if (w < 0)
-    return -1;
+               return -1;
 
        return w - 2 * TEXT_TO_INSET_OFFSET;
 }
 
 
-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);
+       if (top_x != x)
+               top_x = x;
 
-       int const start_x = int(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;
@@ -728,14 +676,14 @@ bool InsetText::lockInsetInInset(BufferView * bv, UpdatableInset * inset)
                        InsetList::iterator const end =
                                pit->insetlist.end();
                        for (; it != end; ++it) {
-                               if (it.getInset() == inset) {
-                                       getLyXText(bv)->setCursorIntern(pit, it.getPos());
+                               if (it->inset == inset) {
+                                       getLyXText(bv)->setCursorIntern(pit, it->pos);
                                        lockInset(bv, inset);
                                        return true;
                                }
-                               if (it.getInset()->getInsetFromID(id)) {
-                                       getLyXText(bv)->setCursorIntern(pit, it.getPos());
-                                       it.getInset()->localDispatch(FuncRequest(bv, LFUN_INSET_EDIT));
+                               if (it->inset->getInsetFromID(id)) {
+                                       getLyXText(bv)->setCursorIntern(pit, it->pos);
+                                       it->inset->localDispatch(FuncRequest(bv, LFUN_INSET_EDIT));
                                        return the_locking_inset->lockInsetInInset(bv, inset);
                                }
                        }
@@ -1868,10 +1816,10 @@ vector<string> const InsetText::getLabelList() const
        ParagraphList::const_iterator pit = paragraphs.begin();
        ParagraphList::const_iterator pend = paragraphs.end();
        for (; pit != pend; ++pit) {
-               InsetList::iterator beg = pit->insetlist.begin();
-               InsetList::iterator end = pit->insetlist.end();
+               InsetList::const_iterator beg = pit->insetlist.begin();
+               InsetList::const_iterator end = pit->insetlist.end();
                for (; beg != end; ++beg) {
-                       vector<string> const l = beg.getInset()->getLabelList();
+                       vector<string> const l = beg->inset->getLabelList();
                        label_list.insert(label_list.end(), l.begin(), l.end());
                }
        }
@@ -2008,46 +1956,6 @@ void InsetText::setParagraphData(ParagraphList const & plist)
 }
 
 
-// void InsetText::setParagraphData(ParagraphList const & plist, bool same_id)
-// {
-//     // we have to unlock any locked inset otherwise we're in troubles
-//     the_locking_inset = 0;
-
-//     #warning CHECK not adhering to same_id here might wreck havoc (Lgb)
-//     // But it it makes no difference that is a lot better.
-//     if (same_id) {
-//             lyxerr << "Same_id called with 'true'" << endl;
-//             lyxerr << "Please report this to the list." << endl;
-
-//             paragraphs.clear();
-//             ParagraphList::iterator it = plist.begin();
-//             ParagraphList::iterator end = plist.end();
-//             for (; it != end; ++it) {
-//                     int const id = it->id();
-//                     paragraphs.push_back(*it);
-//                     Paragraph & tmp = paragraphs.back();
-//                     tmp.setInsetOwner(this);
-//                     tmp.id(id);
-//             }
-//     } else {
-// #warning FIXME.
-//             // See if this can be simplified when std::list is in effect.
-//             paragraphs.clear();
-
-//             ParagraphList::iterator it = plist.begin();
-//             ParagraphList::iterator end = plist.end();
-//             for (; it != end; ++it) {
-//                     paragraphs.push_back(*it);
-//                     Paragraph & tmp = paragraphs.back();
-//                     tmp.setInsetOwner(this);
-//             }
-//     }
-
-//     reinitLyXText();
-//     need_update = INIT;
-// }
-
-
 void InsetText::markNew(bool track_changes)
 {
        ParagraphList::iterator pit = paragraphs.begin();
@@ -2446,12 +2354,12 @@ Inset * InsetText::getInsetFromID(int id_arg) const
        ParagraphList::const_iterator pit = paragraphs.begin();
        ParagraphList::const_iterator pend = paragraphs.end();
        for (; pit != pend; ++pit) {
-               InsetList::iterator it = pit->insetlist.begin();
-               InsetList::iterator end = pit->insetlist.end();
+               InsetList::const_iterator it = pit->insetlist.begin();
+               InsetList::const_iterator end = pit->insetlist.end();
                for (; it != end; ++it) {
-                       if (it.getInset()->id() == id_arg)
-                               return it.getInset();
-                       Inset * in = it.getInset()->getInsetFromID(id_arg);
+                       if (it->inset->id() == id_arg)
+                               return it->inset;
+                       Inset * in = it->inset->getInsetFromID(id_arg);
                        if (in)
                                return in;
                }
@@ -2685,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;
@@ -2729,8 +2603,6 @@ void InsetText::appendParagraphs(Buffer * buffer, ParagraphList & plist)
                paragraphs.push_back(*pit);
        }
 
-#endif
-
        reinitLyXText();
 }
 
@@ -2741,10 +2613,10 @@ void InsetText::addPreview(grfx::PreviewLoader & loader) const
        ParagraphList::const_iterator pend = paragraphs.end();
 
        for (; pit != pend; ++pit) {
-               InsetList::iterator it  = pit->insetlist.begin();
-               InsetList::iterator end = pit->insetlist.end();
+               InsetList::const_iterator it  = pit->insetlist.begin();
+               InsetList::const_iterator end = pit->insetlist.end();
                for (; it != end; ++it) {
-                       it.getInset()->addPreview(loader);
+                       it->inset->addPreview(loader);
                }
        }
 }