]> 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 20599f503e850b2c3971eb9fb95297918423761c..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"
@@ -79,34 +79,34 @@ using lyx::textclass_type;
 void InsetText::saveLyXTextState(LyXText * t) const
 {
        // check if my paragraphs are still valid
-       ParagraphList::iterator it = paragraphs.begin();
-       ParagraphList::iterator end = paragraphs.end();
+       ParagraphList::iterator it = const_cast<ParagraphList&>(paragraphs).begin();
+       ParagraphList::iterator end = const_cast<ParagraphList&>(paragraphs).end();
        for (; it != end; ++it) {
-               if (&*it == t->cursor.par())
+               if (it == t->cursor.par())
                        break;
        }
 
        if (it != end && t->cursor.pos() <= it->size()) {
-               sstate.lpar = &*t->cursor.par();
+               sstate.lpar = t->cursor.par();
                sstate.pos = t->cursor.pos();
                sstate.boundary = t->cursor.boundary();
-               sstate.selstartpar = &*t->selection.start.par();
+               sstate.selstartpar = t->selection.start.par();
                sstate.selstartpos = t->selection.start.pos();
                sstate.selstartboundary = t->selection.start.boundary();
-               sstate.selendpar = &*t->selection.end.par();
+               sstate.selendpar = t->selection.end.par();
                sstate.selendpos = t->selection.end.pos();
                sstate.selendboundary = t->selection.end.boundary();
                sstate.selection = t->selection.set();
                sstate.mark_set = t->selection.mark();
        } else {
-               sstate.lpar = 0;
+               sstate.lpar = const_cast<ParagraphList&>(paragraphs).end();
        }
 }
 
 
 void InsetText::restoreLyXTextState(LyXText * t) const
 {
-       if (!sstate.lpar)
+       if (sstate.lpar == const_cast<ParagraphList&>(paragraphs).end())
                return;
 
        t->selection.set(true);
@@ -143,15 +143,15 @@ InsetText::InsetText(BufferParams const & bp)
        paragraphs.begin()->layout(bp.getLyXTextClass().defaultLayout());
        if (bp.tracking_changes)
                paragraphs.begin()->trackChanges();
-       init();
+       init(0);
 }
 
 
-InsetText::InsetText(InsetText const & in, bool same_id)
-       : UpdatableInset(in, same_id), lt(0), in_update(false), do_resize(0),
+InsetText::InsetText(InsetText const & in)
+       : UpdatableInset(in), lt(0), in_update(false), do_resize(0),
          do_reinit(false)
 {
-       init(&in, same_id);
+       init(&in);
 }
 
 
@@ -162,15 +162,13 @@ InsetText & InsetText::operator=(InsetText const & it)
 }
 
 
-void InsetText::init(InsetText const * ins, bool same_id)
+void InsetText::init(InsetText const * ins)
 {
        if (ins) {
-               setParagraphData(ins->paragraphs, same_id);
+               setParagraphData(ins->paragraphs);
                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));
@@ -187,10 +185,10 @@ void InsetText::init(InsetText const * ins, bool same_id)
        drawTextXOffset = 0;
        drawTextYOffset = 0;
        locked = false;
-       old_par = 0;
+       old_par = paragraphs.end();
        last_drawn_width = -1;
        cached_bview = 0;
-       sstate.lpar = 0;
+       sstate.lpar = paragraphs.end();
        in_insetAllowed = false;
 }
 
@@ -226,9 +224,9 @@ void InsetText::clear(bool just_mark_erased)
 }
 
 
-Inset * InsetText::clone(Buffer const &, bool same_id) const
+Inset * InsetText::clone() const
 {
-       return new InsetText(*this, same_id);
+       return new InsetText(*this);
 }
 
 
@@ -241,8 +239,8 @@ void InsetText::write(Buffer const * buf, ostream & os) const
 
 void InsetText::writeParagraphData(Buffer const * buf, ostream & os) const
 {
-       ParagraphList::iterator it = paragraphs.begin();
-       ParagraphList::iterator end = paragraphs.end();
+       ParagraphList::const_iterator it = paragraphs.begin();
+       ParagraphList::const_iterator end = paragraphs.end();
        Paragraph::depth_type dth = 0;
        for (; it != end; ++it) {
                it->write(buf, os, buf->params, dth);
@@ -295,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.a = text->rows().begin()->ascent_of_text() + TEXT_TO_INSET_OFFSET;
-       dim.d = text->height - dim.a + TEXT_TO_INSET_OFFSET;
-       dim.w = max(textWidth(bv), int(text->width)) + 2 * TEXT_TO_INSET_OFFSET;
-       dim.w = max(dim.w, 10);
-       // cache it
+       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);
        dim_ = dim;
 }
 
@@ -317,51 +314,47 @@ 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);
-
-       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_.a;
+       top_y = baseline - dim_.asc;
 
-       if (last_drawn_width != dim_.w) {
+       if (last_drawn_width != dim_.wid) {
                need_update |= FULL;
-               last_drawn_width = dim_.w;
+               last_drawn_width = dim_.wid;
        }
 
        if (the_locking_inset && (cpar(bv) == inset_par)
@@ -417,7 +410,7 @@ void InsetText::draw(BufferView * bv, LyXFont const & f,
                drawFrame(pain, int(start_x));
        }
 
-       x += dim_.w - TEXT_TO_INSET_OFFSET;
+       x += dim_.wid - TEXT_TO_INSET_OFFSET;
 
        if (need_update != INIT) {
                need_update = NONE;
@@ -431,9 +424,9 @@ void InsetText::drawFrame(Painter & pain, int x) const
 {
        static int const ttoD2 = TEXT_TO_INSET_OFFSET / 2;
        frame_x = x + ttoD2;
-       frame_y = top_baseline - dim_.a + ttoD2;
-       frame_w = dim_.w - TEXT_TO_INSET_OFFSET;
-       frame_h = dim_.a + dim_.d - TEXT_TO_INSET_OFFSET;
+       frame_y = top_baseline - dim_.asc + ttoD2;
+       frame_w = dim_.wid - TEXT_TO_INSET_OFFSET;
+       frame_h = dim_.asc + dim_.des - TEXT_TO_INSET_OFFSET;
        pain.rectangle(frame_x, frame_y, frame_w, frame_h,
                       frame_color);
 }
@@ -626,8 +619,8 @@ void InsetText::lockInset(BufferView * bv)
        the_locking_inset = 0;
        inset_pos = inset_x = inset_y = 0;
        inset_boundary = false;
-       inset_par = 0;
-       old_par = 0;
+       inset_par = paragraphs.end();
+       old_par = paragraphs.end();
        bool clear = false;
        if (!lt) {
                lt = getLyXText(bv);
@@ -683,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);
                                }
                        }
@@ -729,7 +722,7 @@ bool InsetText::unlockInsetInInset(BufferView * bv, UpdatableInset * inset,
                the_locking_inset = 0;
                if (lr)
                        moveRightIntern(bv, true, false);
-               old_par = 0; // force layout setting
+               old_par = paragraphs.end(); // force layout setting
                if (scroll())
                        scroll(bv, 0.0F);
                else
@@ -807,7 +800,7 @@ void InsetText::lfunMousePress(FuncRequest const & cmd)
                lockInset(bv);
 
        int tmp_x = cmd.x - drawTextXOffset;
-       int tmp_y = cmd.y + dim_.a - getLyXText(bv)->top_y();
+       int tmp_y = cmd.y + dim_.asc - getLyXText(bv)->top_y();
        Inset * inset = getLyXText(bv)->checkInsetHit(tmp_x, tmp_y);
 
        if (the_locking_inset) {
@@ -850,7 +843,7 @@ void InsetText::lfunMousePress(FuncRequest const & cmd)
                int old_top_y = lt->top_y();
 
                lt->setCursorFromCoordinates(cmd.x - drawTextXOffset,
-                                            cmd.y + dim_.a);
+                                            cmd.y + dim_.asc);
                // set the selection cursor!
                lt->selection.cursor = lt->cursor;
                lt->cursor.x_fix(lt->cursor.x());
@@ -899,7 +892,7 @@ bool InsetText::lfunMouseRelease(FuncRequest const & cmd)
                return the_locking_inset->localDispatch(cmd1);
 
        int tmp_x = cmd.x - drawTextXOffset;
-       int tmp_y = cmd.y + dim_.a - getLyXText(bv)->top_y();
+       int tmp_y = cmd.y + dim_.asc - getLyXText(bv)->top_y();
        Inset * inset = getLyXText(bv)->checkInsetHit(tmp_x, tmp_y);
        bool ret = false;
        if (inset) {
@@ -950,7 +943,7 @@ void InsetText::lfunMouseMotion(FuncRequest const & cmd)
        }
        LyXCursor cur = lt->cursor;
        lt->setCursorFromCoordinates
-               (cmd.x - drawTextXOffset, cmd.y + dim_.a);
+               (cmd.x - drawTextXOffset, cmd.y + dim_.asc);
        lt->cursor.x_fix(lt->cursor.x());
        if (cur == lt->cursor) {
                if (clear)
@@ -984,8 +977,8 @@ Inset::RESULT InsetText::localDispatch(FuncRequest const & cmd)
                the_locking_inset = 0;
                inset_pos = inset_x = inset_y = 0;
                inset_boundary = false;
-               inset_par = 0;
-               old_par = 0;
+               inset_par = paragraphs.end();
+               old_par = paragraphs.end();
 
                bool clear = false;
                if (!lt) {
@@ -1012,7 +1005,7 @@ Inset::RESULT InsetText::localDispatch(FuncRequest const & cmd)
                        // FIXME: GUII I've changed this to none: probably WRONG
                        if (!checkAndActivateInset(bv, cmd.x, tmp_y, mouse_button::none)) {
                                lt->setCursorFromCoordinates(cmd.x - drawTextXOffset,
-                                                                       cmd.y + dim_.a);
+                                                                       cmd.y + dim_.asc);
                                lt->cursor.x_fix(lt->cursor.x());
                        }
                }
@@ -1459,9 +1452,9 @@ int InsetText::ascii(Buffer const * buf, ostream & os, int linelen) const
 {
        unsigned int lines = 0;
 
-       ParagraphList::iterator beg = paragraphs.begin();
-       ParagraphList::iterator end = paragraphs.end();
-       ParagraphList::iterator it = beg;
+       ParagraphList::const_iterator beg = paragraphs.begin();
+       ParagraphList::const_iterator end = paragraphs.end();
+       ParagraphList::const_iterator it = beg;
        for (; it != end; ++it) {
                string const tmp = buf->asciiParagraph(*it, linelen, it == beg);
                lines += lyx::count(tmp.begin(), tmp.end(), '\n');
@@ -1483,8 +1476,8 @@ int InsetText::docbook(Buffer const * buf, ostream & os, bool mixcont) const
 
        Paragraph::depth_type depth = 0; // paragraph depth
 
-       ParagraphList::iterator pit = paragraphs.begin();
-       ParagraphList::iterator pend = paragraphs.end();
+       ParagraphList::iterator pit = const_cast<ParagraphList&>(paragraphs).begin();
+       ParagraphList::iterator pend = const_cast<ParagraphList&>(paragraphs).end();
 
        for (; pit != pend; ++pit) {
                string sgmlparam;
@@ -1820,13 +1813,13 @@ vector<string> const InsetText::getLabelList() const
 {
        vector<string> label_list;
 
-       ParagraphList::iterator pit = paragraphs.begin();
-       ParagraphList::iterator pend = paragraphs.end();
+       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());
                }
        }
@@ -1893,7 +1886,7 @@ bool InsetText::checkAndActivateInset(BufferView * bv, int x, int y,
 {
        x -= drawTextXOffset;
        int dummyx = x;
-       int dummyy = y + dim_.a;
+       int dummyy = y + dim_.asc;
        Inset * inset = getLyXText(bv)->checkInsetHit(dummyx, dummyy);
        // we only do the edit() call if the inset was hit by the mouse
        // or if it is a highly editable inset. So we should call this
@@ -1905,9 +1898,9 @@ bool InsetText::checkAndActivateInset(BufferView * bv, int x, int y,
 
        if (inset) {
                if (x < 0)
-                       x = dim_.w;
+                       x = dim_.wid;
                if (y < 0)
-                       y = dim_.d;
+                       y = dim_.des;
                inset_x = cix(bv) - top_x + drawTextXOffset;
                inset_y = ciy(bv) + drawTextYOffset;
                FuncRequest cmd(bv, LFUN_INSET_EDIT, x - inset_x, y - inset_y, button);
@@ -1940,39 +1933,22 @@ int InsetText::getMaxWidth(BufferView * bv, UpdatableInset const * inset) const
 }
 
 
-void InsetText::setParagraphData(ParagraphList const & plist, bool same_id)
+void InsetText::setParagraphData(ParagraphList const & plist)
 {
        // 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();
+       // 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);
-               }
+       ParagraphList::const_iterator it = plist.begin();
+       ParagraphList::const_iterator end = plist.end();
+       for (; it != end; ++it) {
+               paragraphs.push_back(*it);
+               Paragraph & tmp = paragraphs.back();
+               tmp.setInsetOwner(this);
        }
 
        reinitLyXText();
@@ -2110,7 +2086,7 @@ LyXText * InsetText::getLyXText(BufferView const * lbv,
                if (recursive && the_locking_inset)
                        return the_locking_inset->getLyXText(lbv, true);
                LyXText * lt = cached_text.get();
-               lyx::Assert(lt && lt->rows().begin()->par() == paragraphs.begin());
+               lyx::Assert(lt && lt->rows().begin()->par() == const_cast<ParagraphList&>(paragraphs).begin());
                return lt;
        }
        // Super UGLY! (Lgb)
@@ -2136,7 +2112,7 @@ LyXText * InsetText::getLyXText(BufferView const * lbv,
                                if (locked) {
                                        saveLyXTextState(it->second.text.get());
                                } else {
-                                       sstate.lpar = 0;
+                                       sstate.lpar = const_cast<ParagraphList&>(paragraphs).end();
                                }
                        }
                        //
@@ -2183,7 +2159,8 @@ void InsetText::deleteLyXText(BufferView * bv, bool recursive) const
        it->second.remove = true;
        if (recursive) {
                /// then remove all LyXText in text-insets
-               for_each(paragraphs.begin(), paragraphs.end(),
+               for_each(const_cast<ParagraphList&>(paragraphs).begin(),
+                        const_cast<ParagraphList&>(paragraphs).end(),
                         boost::bind(&Paragraph::deleteInsetsLyXText, _1, bv));
        }
 }
@@ -2220,7 +2197,8 @@ void InsetText::resizeLyXText(BufferView * bv, bool force) const
        LyXText * t = it->second.text.get();
        saveLyXTextState(t);
 
-       for_each(paragraphs.begin(), paragraphs.end(),
+       for_each(const_cast<ParagraphList&>(paragraphs).begin(),
+                const_cast<ParagraphList&>(paragraphs).end(),
                 boost::bind(&Paragraph::resizeInsetsLyXText, _1, bv));
 
        t->init(bv, true);
@@ -2259,7 +2237,8 @@ void InsetText::reinitLyXText() const
 
                saveLyXTextState(t);
 
-               for_each(paragraphs.begin(), paragraphs.end(),
+               for_each(const_cast<ParagraphList&>(paragraphs).begin(),
+                        const_cast<ParagraphList&>(paragraphs).end(),
                         boost::bind(&Paragraph::resizeInsetsLyXText, _1, bv));
 
                t->init(bv, true);
@@ -2336,9 +2315,9 @@ void InsetText::clearSelection(BufferView * bv)
 void InsetText::clearInset(BufferView * bv, int start_x, int baseline) const
 {
        Painter & pain = bv->painter();
-       int w = dim_.w;
-       int h = dim_.a + dim_.d;
-       int ty = baseline - dim_.a;
+       int w = dim_.wid;
+       int h = dim_.asc + dim_.des;
+       int ty = baseline - dim_.asc;
 
        if (ty < 0) {
                h += ty;
@@ -2372,15 +2351,15 @@ Inset * InsetText::getInsetFromID(int id_arg) const
        if (id_arg == id())
                return const_cast<InsetText *>(this);
 
-       ParagraphList::iterator pit = paragraphs.begin();
-       ParagraphList::iterator pend = paragraphs.end();
+       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;
                }
@@ -2614,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;
@@ -2658,22 +2603,20 @@ void InsetText::appendParagraphs(Buffer * buffer, ParagraphList & plist)
                paragraphs.push_back(*pit);
        }
 
-#endif
-
        reinitLyXText();
 }
 
 
 void InsetText::addPreview(grfx::PreviewLoader & loader) const
 {
-       ParagraphList::iterator pit = paragraphs.begin();
-       ParagraphList::iterator pend = paragraphs.end();
+       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) {
-                       it.getInset()->addPreview(loader);
+                       it->inset->addPreview(loader);
                }
        }
 }