]> git.lyx.org Git - features.git/blobdiff - src/insets/insettext.C
make ParagraphList::push_back take a reference instead of a pointer.
[features.git] / src / insets / insettext.C
index f0cc7fb301d577000761d2a61490767338244de3..d74aea11ded64147f5d154367a7223a0b6f17ae7 100644 (file)
@@ -139,7 +139,7 @@ InsetText::InsetText(BufferParams const & bp)
        : UpdatableInset(), lt(0), in_update(false), do_resize(0),
          do_reinit(false)
 {
-       paragraphs.push_back(new Paragraph);
+       paragraphs.push_back(Paragraph());
        paragraphs.begin()->layout(bp.getLyXTextClass().defaultLayout());
        if (bp.tracking_changes)
                paragraphs.begin()->trackChanges();
@@ -181,9 +181,6 @@ void InsetText::init(InsetText const * ins, bool same_id)
                autoBreakRows = false;
        }
        top_y = 0;
-       insetAscent = 0;
-       insetDescent = 0;
-       insetWidth = 0;
        old_max_width = 0;
        no_selection = true;
        need_update = FULL;
@@ -220,7 +217,7 @@ void InsetText::clear(bool just_mark_erased)
        LyXLayout_ptr old_layout = paragraphs.begin()->layout();
 
        paragraphs.clear();
-       paragraphs.push_back(new Paragraph);
+       paragraphs.push_back(Paragraph());
        paragraphs.begin()->setInsetOwner(this);
        paragraphs.begin()->layout(old_layout);
 
@@ -306,6 +303,8 @@ void InsetText::dimension(BufferView * bv, LyXFont const &,
        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_ = dim;
 }
 
 
@@ -339,11 +338,8 @@ void InsetText::draw(BufferView * bv, LyXFont const & f,
 
        Painter & pain = bv->painter();
 
-       // call these methods so that insetWidth, insetAscent and
-       // insetDescent have the right values.
-       width(bv, f);
-       ascent(bv, f);
-       descent(bv, f);
+       // call this method so that dim_ has the right value
+       dimension(bv, f, dim_);
 
        // repaint the background if needed
        if (backgroundColor() != LColor::background)
@@ -361,11 +357,11 @@ void InsetText::draw(BufferView * bv, LyXFont const & f,
                x += static_cast<float>(scroll());
 
        top_baseline = baseline;
-       top_y = baseline - insetAscent;
+       top_y = baseline - dim_.a;
 
-       if (last_drawn_width != insetWidth) {
+       if (last_drawn_width != dim_.w) {
                need_update |= FULL;
-               last_drawn_width = insetWidth;
+               last_drawn_width = dim_.w;
        }
 
        if (the_locking_inset && (cpar(bv) == inset_par)
@@ -421,7 +417,7 @@ void InsetText::draw(BufferView * bv, LyXFont const & f,
                drawFrame(pain, int(start_x));
        }
 
-       x += insetWidth - TEXT_TO_INSET_OFFSET;
+       x += dim_.w - TEXT_TO_INSET_OFFSET;
 
        if (need_update != INIT) {
                need_update = NONE;
@@ -435,9 +431,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 - insetAscent + ttoD2;
-       frame_w = insetWidth - TEXT_TO_INSET_OFFSET;
-       frame_h = insetAscent + insetDescent - TEXT_TO_INSET_OFFSET;
+       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;
        pain.rectangle(frame_x, frame_y, frame_w, frame_h,
                       frame_color);
 }
@@ -811,7 +807,7 @@ void InsetText::lfunMousePress(FuncRequest const & cmd)
                lockInset(bv);
 
        int tmp_x = cmd.x - drawTextXOffset;
-       int tmp_y = cmd.y + insetAscent - getLyXText(bv)->top_y();
+       int tmp_y = cmd.y + dim_.a - getLyXText(bv)->top_y();
        Inset * inset = getLyXText(bv)->checkInsetHit(tmp_x, tmp_y);
 
        if (the_locking_inset) {
@@ -854,7 +850,7 @@ void InsetText::lfunMousePress(FuncRequest const & cmd)
                int old_top_y = lt->top_y();
 
                lt->setCursorFromCoordinates(cmd.x - drawTextXOffset,
-                                            cmd.y + insetAscent);
+                                            cmd.y + dim_.a);
                // set the selection cursor!
                lt->selection.cursor = lt->cursor;
                lt->cursor.x_fix(lt->cursor.x());
@@ -903,7 +899,7 @@ bool InsetText::lfunMouseRelease(FuncRequest const & cmd)
                return the_locking_inset->localDispatch(cmd1);
 
        int tmp_x = cmd.x - drawTextXOffset;
-       int tmp_y = cmd.y + insetAscent - getLyXText(bv)->top_y();
+       int tmp_y = cmd.y + dim_.a - getLyXText(bv)->top_y();
        Inset * inset = getLyXText(bv)->checkInsetHit(tmp_x, tmp_y);
        bool ret = false;
        if (inset) {
@@ -954,7 +950,7 @@ void InsetText::lfunMouseMotion(FuncRequest const & cmd)
        }
        LyXCursor cur = lt->cursor;
        lt->setCursorFromCoordinates
-               (cmd.x - drawTextXOffset, cmd.y + insetAscent);
+               (cmd.x - drawTextXOffset, cmd.y + dim_.a);
        lt->cursor.x_fix(lt->cursor.x());
        if (cur == lt->cursor) {
                if (clear)
@@ -1016,7 +1012,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 + insetAscent);
+                                                                       cmd.y + dim_.a);
                                lt->cursor.x_fix(lt->cursor.x());
                        }
                }
@@ -1138,8 +1134,7 @@ Inset::RESULT InsetText::localDispatch(FuncRequest const & cmd)
                         * true (on). */
 #if 0
                        // This should not be needed here and is also WRONG!
-                       setUndo(bv, Undo::INSERT,
-                               lt->cursor.par(), boost::next(lt->cursor.par()));
+                       setUndo(bv, Undo::INSERT, lt->cursor.par());
 #endif
                        bv->switchKeyMap();
                        if (lyxrc.auto_region_delete) {
@@ -1451,10 +1446,11 @@ Inset::RESULT InsetText::localDispatch(FuncRequest const & cmd)
 }
 
 
-int InsetText::latex(Buffer const * buf, ostream & os, bool fragile, bool) const
+int InsetText::latex(Buffer const * buf, ostream & os,
+                    LatexRunParams const & runparams) const
 {
        TexRow texrow;
-       latexParagraphs(buf, paragraphs, os, texrow, fragile);
+       latexParagraphs(buf, paragraphs, os, texrow, runparams);
        return texrow.rows();
 }
 
@@ -1532,7 +1528,7 @@ int InsetText::docbook(Buffer const * buf, ostream & os, bool mixcont) const
                        break;
 
                case LATEX_COMMAND:
-                       buf->sgmlError(&*pit, 0,  _("Error: LatexType Command not allowed here.\n"));
+                       buf->sgmlError(pit, 0,  _("Error: LatexType Command not allowed here.\n"));
                        return -1;
                        break;
 
@@ -1856,7 +1852,7 @@ void InsetText::setFont(BufferView * bv, LyXFont const & font, bool toggleall,
                clear = true;
        }
        if (lt->selection.set()) {
-               setUndo(bv, Undo::EDIT, lt->cursor.par(), boost::next(lt->cursor.par()));
+               setUndo(bv, Undo::EDIT, lt->cursor.par());
        }
        if (selectall)
                selectAll(bv);
@@ -1897,7 +1893,7 @@ bool InsetText::checkAndActivateInset(BufferView * bv, int x, int y,
 {
        x -= drawTextXOffset;
        int dummyx = x;
-       int dummyy = y + insetAscent;
+       int dummyy = y + dim_.a;
        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
@@ -1909,9 +1905,9 @@ bool InsetText::checkAndActivateInset(BufferView * bv, int x, int y,
 
        if (inset) {
                if (x < 0)
-                       x = insetWidth;
+                       x = dim_.w;
                if (y < 0)
-                       y = insetDescent;
+                       y = dim_.d;
                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);
@@ -1949,13 +1945,34 @@ 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;
 
-       paragraphs.clear();
-       ParagraphList::iterator pit = plist.begin();
-       ParagraphList::iterator pend = plist.end();
-       for (; pit != pend; ++pit) {
-               Paragraph * new_par = new Paragraph(*pit, same_id);
-               new_par->setInsetOwner(this);
-               paragraphs.push_back(new_par);
+       #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();
@@ -2319,9 +2336,9 @@ void InsetText::clearSelection(BufferView * bv)
 void InsetText::clearInset(BufferView * bv, int start_x, int baseline) const
 {
        Painter & pain = bv->painter();
-       int w = insetWidth;
-       int h = insetAscent + insetDescent;
-       int ty = baseline - insetAscent;
+       int w = dim_.w;
+       int h = dim_.a + dim_.d;
+       int ty = baseline - dim_.a;
 
        if (ty < 0) {
                h += ty;
@@ -2350,24 +2367,6 @@ LyXCursor const & InsetText::cursor(BufferView * bv) const
 }
 
 
-void InsetText::paragraph(Paragraph * p)
-{
-       // GENERAL COMMENT: We don't have to free the old paragraphs as the
-       // caller of this function has to take care of it. This IS important
-       // as we could have to insert a paragraph before this one and just
-       // link the actual to a new ones next and set it with this function
-       // and are done!
-       paragraphs.set(p);
-       // set ourself as owner for all the paragraphs inserted!
-       for_each(paragraphs.begin(), paragraphs.end(),
-                boost::bind(&Paragraph::setInsetOwner, _1, this));
-
-       reinitLyXText();
-       // redraw myself when asked for
-       need_update = INIT;
-}
-
-
 Inset * InsetText::getInsetFromID(int id_arg) const
 {
        if (id_arg == id())
@@ -2657,7 +2656,7 @@ void InsetText::appendParagraphs(Buffer * buffer, ParagraphList & plist)
 
        ParagraphList::iterator pend = plist.end();
        for (; pit != pend; ++pit) {
-               paragraphs.push_back(new Paragraph(*pit, false));
+               paragraphs.push_back(*pit);
        }
 
 #endif