]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insettext.C
rename the members of Dimension
[lyx.git] / src / insets / insettext.C
index 90a2b6f26d68f60622f3080b2bac47c24dadbb55..ffcd351f4f8e458eb705be34d2c2586f050dd729 100644 (file)
 #include "BufferView.h"
 #include "CutAndPaste.h"
 #include "debug.h"
+#include "dimension.h"
 #include "funcrequest.h"
 #include "gettext.h"
 #include "intl.h"
 #include "LaTeXFeatures.h"
 #include "LColor.h"
+#include "Lsstream.h"
 #include "lyxfont.h"
 #include "lyxcursor.h"
 #include "lyxfind.h"
@@ -71,6 +73,7 @@ using std::for_each;
 using lyx::pos_type;
 using lyx::textclass_type;
 
+
 // These functions should probably go into bufferview_funcs somehow (Jug)
 
 void InsetText::saveLyXTextState(LyXText * t) const
@@ -136,22 +139,30 @@ 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();
-       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);
 }
 
 
+// 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);
@@ -159,15 +170,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));
@@ -178,9 +187,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;
@@ -195,6 +201,39 @@ void InsetText::init(InsetText const * ins, bool same_id)
 }
 
 
+// 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();
@@ -217,7 +256,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);
 
@@ -226,12 +265,18 @@ void InsetText::clear(bool just_mark_erased)
 }
 
 
-Inset * InsetText::clone(Buffer const &, bool same_id) const
+Inset * InsetText::clone(Buffer const &) const
 {
-       return new InsetText(*this, same_id);
+       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";
@@ -295,47 +340,31 @@ void InsetText::read(Buffer const * buf, LyXLex & lex)
 }
 
 
-int InsetText::ascent(BufferView * bv, LyXFont const &) const
+void InsetText::dimension(BufferView * bv, LyXFont const &,
+       Dimension & dim) const
 {
-       insetAscent = getLyXText(bv)->rows().begin()->ascent_of_text() +
-               TEXT_TO_INSET_OFFSET;
-       return insetAscent;
+       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;
 }
 
 
-int InsetText::descent(BufferView * bv, LyXFont const &) const
+int InsetText::textWidth(BufferView * bv, bool fordraw) const
 {
-       LyXText * llt = getLyXText(bv);
-       insetDescent = llt->height - llt->rows().begin()->ascent_of_text() +
-               TEXT_TO_INSET_OFFSET;
-       return insetDescent;
-}
-
+       int w = autoBreakRows ? getMaxWidth(bv, this) : -1;
 
-int InsetText::width(BufferView * bv, LyXFont const &) const
-{
-       insetWidth = max(textWidth(bv), (int)getLyXText(bv)->width) +
-               (2 * TEXT_TO_INSET_OFFSET);
-       insetWidth = max(insetWidth, 10);
-       return insetWidth;
-}
+       if (fordraw)
+               return max(w - 2 * TEXT_TO_INSET_OFFSET,
+                          (int)getLyXText(bv)->width);
 
+       if (w < 0)
+    return -1;
 
-int InsetText::textWidth(BufferView * bv, bool fordraw) const
-{
-       int w;
-       if (!autoBreakRows) {
-               w = -1;
-       } else {
-               w = getMaxWidth(bv, this);
-       }
-       if (fordraw) {
-               return max(w - (2 * TEXT_TO_INSET_OFFSET),
-                          (int)getLyXText(bv)->width);
-       } else if (w < 0) {
-           return -1;
-       }
-       return w - (2 * TEXT_TO_INSET_OFFSET);
+       return w - 2 * TEXT_TO_INSET_OFFSET;
 }
 
 
@@ -354,11 +383,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)
@@ -376,11 +402,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_.asc;
 
-       if (last_drawn_width != insetWidth) {
+       if (last_drawn_width != dim_.wid) {
                need_update |= FULL;
-               last_drawn_width = insetWidth;
+               last_drawn_width = dim_.wid;
        }
 
        if (the_locking_inset && (cpar(bv) == inset_par)
@@ -436,7 +462,7 @@ void InsetText::draw(BufferView * bv, LyXFont const & f,
                drawFrame(pain, int(start_x));
        }
 
-       x += insetWidth - TEXT_TO_INSET_OFFSET;
+       x += dim_.wid - TEXT_TO_INSET_OFFSET;
 
        if (need_update != INIT) {
                need_update = NONE;
@@ -450,9 +476,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_.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);
 }
@@ -598,109 +624,6 @@ string const InsetText::editMessage() const
 }
 
 
-void InsetText::edit(BufferView * bv, int x, int y, mouse_button::state button)
-{
-       UpdatableInset::edit(bv, x, y, button);
-
-       if (!bv->lockInset(this)) {
-               lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
-               return;
-       }
-       locked = true;
-       the_locking_inset = 0;
-       inset_pos = inset_x = inset_y = 0;
-       inset_boundary = false;
-       inset_par = 0;
-       old_par = 0;
-       int tmp_y = (y < 0) ? 0 : y;
-       bool clear = false;
-       if (!lt) {
-               lt = getLyXText(bv);
-               clear = true;
-       }
-       // we put here -1 and not button as now the button in the
-       // edit call should not be needed we will fix this in 1.3.x
-       // cycle hopefully (Jug 20020509)
-       // FIXME: GUII I've changed this to none: probably WRONG
-       if (!checkAndActivateInset(bv, x, tmp_y, mouse_button::none)) {
-               lt->setCursorFromCoordinates(x - drawTextXOffset,
-                                           y + insetAscent);
-               lt->cursor.x_fix(lt->cursor.x());
-       }
-       lt->clearSelection();
-       finishUndo();
-       // If the inset is empty set the language of the current font to the
-       // language to the surronding text (if different).
-       if (paragraphs.begin()->empty() &&
-           boost::next(paragraphs.begin()) == paragraphs.end()&&
-               bv->getParentLanguage(this) != lt->current_font.language())
-       {
-               LyXFont font(LyXFont::ALL_IGNORE);
-               font.setLanguage(bv->getParentLanguage(this));
-               setFont(bv, font, false);
-       }
-       if (clear)
-               lt = 0;
-
-       int code = CURSOR;
-       if (drawFrame_ == LOCKED)
-               code = CURSOR|DRAW_FRAME;
-       updateLocal(bv, code, false);
-
-       // Tell the paragraph dialog that we've entered an insettext.
-       bv->dispatch(FuncRequest(LFUN_PARAGRAPH_UPDATE));
-}
-
-
-void InsetText::edit(BufferView * bv, bool front)
-{
-       UpdatableInset::edit(bv, front);
-
-       if (!bv->lockInset(this)) {
-               lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
-               return;
-       }
-       locked = true;
-       the_locking_inset = 0;
-       inset_pos = inset_x = inset_y = 0;
-       inset_boundary = false;
-       inset_par = 0;
-       old_par = 0;
-       bool clear = false;
-       if (!lt) {
-               lt = getLyXText(bv);
-               clear = true;
-       }
-       if (front)
-               lt->setCursor(paragraphs.begin(), 0);
-       else {
-               ParagraphList::iterator it = paragraphs.begin();
-               ParagraphList::iterator end = paragraphs.end();
-               while (boost::next(it) != end)
-                       ++it;
-//             int const pos = (p->size() ? p->size()-1 : p->size());
-               lt->setCursor(it, it->size());
-       }
-       lt->clearSelection();
-       finishUndo();
-       // If the inset is empty set the language of the current font to the
-       // language to the surronding text (if different).
-       if (paragraphs.begin()->empty() &&
-           boost::next(paragraphs.begin()) == paragraphs.end() &&
-               bv->getParentLanguage(this) != lt->current_font.language()) {
-               LyXFont font(LyXFont::ALL_IGNORE);
-               font.setLanguage(bv->getParentLanguage(this));
-               setFont(bv, font, false);
-       }
-       if (clear)
-               lt = 0;
-       int code = CURSOR;
-       if (drawFrame_ == LOCKED)
-               code = CURSOR|DRAW_FRAME;
-       updateLocal(bv, code, false);
-}
-
-
 void InsetText::insetUnlock(BufferView * bv)
 {
        if (the_locking_inset) {
@@ -812,7 +735,7 @@ bool InsetText::lockInsetInInset(BufferView * bv, UpdatableInset * inset)
                                }
                                if (it.getInset()->getInsetFromID(id)) {
                                        getLyXText(bv)->setCursorIntern(pit, it.getPos());
-                                       it.getInset()->edit(bv);
+                                       it.getInset()->localDispatch(FuncRequest(bv, LFUN_INSET_EDIT));
                                        return the_locking_inset->lockInsetInInset(bv, inset);
                                }
                        }
@@ -929,7 +852,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_.asc - getLyXText(bv)->top_y();
        Inset * inset = getLyXText(bv)->checkInsetHit(tmp_x, tmp_y);
 
        if (the_locking_inset) {
@@ -972,7 +895,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_.asc);
                // set the selection cursor!
                lt->selection.cursor = lt->cursor;
                lt->cursor.x_fix(lt->cursor.x());
@@ -1021,7 +944,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_.asc - getLyXText(bv)->top_y();
        Inset * inset = getLyXText(bv)->checkInsetHit(tmp_x, tmp_y);
        bool ret = false;
        if (inset) {
@@ -1072,7 +995,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_.asc);
        lt->cursor.x_fix(lt->cursor.x());
        if (cur == lt->cursor) {
                if (clear)
@@ -1090,18 +1013,91 @@ void InsetText::lfunMouseMotion(FuncRequest const & cmd)
 }
 
 
-Inset::RESULT InsetText::localDispatch(FuncRequest const & ev)
+Inset::RESULT InsetText::localDispatch(FuncRequest const & cmd)
 {
-       BufferView * bv = ev.view();
-       switch (ev.action) {
+       BufferView * bv = cmd.view();
+
+       if (cmd.action == LFUN_INSET_EDIT) {
+               UpdatableInset::localDispatch(cmd);
+
+               if (!bv->lockInset(this)) {
+                       lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
+                       return DISPATCHED;
+               }
+
+               locked = true;
+               the_locking_inset = 0;
+               inset_pos = inset_x = inset_y = 0;
+               inset_boundary = false;
+               inset_par = 0;
+               old_par = 0;
+
+               bool clear = false;
+               if (!lt) {
+                       lt = getLyXText(bv);
+                       clear = true;
+               }
+
+               if (cmd.argument.size()) {
+                       if (cmd.argument == "left")
+                               lt->setCursor(paragraphs.begin(), 0);
+                       else {
+                               ParagraphList::iterator it = paragraphs.begin();
+                               ParagraphList::iterator end = paragraphs.end();
+                               while (boost::next(it) != end)
+                                       ++it;
+               //              int const pos = (p->size() ? p->size()-1 : p->size());
+                               lt->setCursor(it, it->size());
+                       }
+               } else {
+                       int tmp_y = (cmd.y < 0) ? 0 : cmd.y;
+                       // we put here -1 and not button as now the button in the
+                       // edit call should not be needed we will fix this in 1.3.x
+                       // cycle hopefully (Jug 20020509)
+                       // 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_.asc);
+                               lt->cursor.x_fix(lt->cursor.x());
+                       }
+               }
+
+               lt->clearSelection();
+               finishUndo();
+
+               // If the inset is empty set the language of the current font to the
+               // language to the surronding text (if different).
+               if (paragraphs.begin()->empty() &&
+                               boost::next(paragraphs.begin()) == paragraphs.end()&&
+                       bv->getParentLanguage(this) != lt->current_font.language())
+               {
+                       LyXFont font(LyXFont::ALL_IGNORE);
+                       font.setLanguage(bv->getParentLanguage(this));
+                       setFont(bv, font, false);
+               }
+
+               if (clear)
+                       lt = 0;
+               int code = CURSOR;
+               if (drawFrame_ == LOCKED)
+                       code = CURSOR | DRAW_FRAME;
+
+               updateLocal(bv, code, false);
+               // Tell the paragraph dialog that we've entered an insettext.
+               bv->dispatch(FuncRequest(LFUN_PARAGRAPH_UPDATE));
+               return DISPATCHED;
+       }
+
+
+       switch (cmd.action) {
                case LFUN_MOUSE_PRESS:
-                       lfunMousePress(ev);
+                       lfunMousePress(cmd);
                        return DISPATCHED;
                case LFUN_MOUSE_MOTION:
-                       lfunMouseMotion(ev);
+                       lfunMouseMotion(cmd);
                        return DISPATCHED;
                case LFUN_MOUSE_RELEASE:
-                       return lfunMouseRelease(ev) ? DISPATCHED : UNDISPATCHED;
+                       return lfunMouseRelease(cmd) ? DISPATCHED : UNDISPATCHED;
                default:
                        break;
        }
@@ -1109,16 +1105,16 @@ Inset::RESULT InsetText::localDispatch(FuncRequest const & ev)
        bool was_empty = (paragraphs.begin()->empty() &&
                          boost::next(paragraphs.begin()) == paragraphs.end());
        no_selection = false;
-       RESULT result = UpdatableInset::localDispatch(ev);
+       RESULT result = UpdatableInset::localDispatch(cmd);
        if (result != UNDISPATCHED)
                return DISPATCHED;
 
        result = DISPATCHED;
-       if (ev.action < 0 && ev.argument.empty())
+       if (cmd.action < 0 && cmd.argument.empty())
                return FINISHED;
 
        if (the_locking_inset) {
-               result = the_locking_inset->localDispatch(ev);
+               result = the_locking_inset->localDispatch(cmd);
                if (result == DISPATCHED_NOUPDATE)
                        return result;
                else if (result == DISPATCHED) {
@@ -1167,7 +1163,7 @@ Inset::RESULT InsetText::localDispatch(FuncRequest const & ev)
        if (lt->selection.set())
                cursor_update = SELECTION;
 
-       switch (ev.action) {
+       switch (cmd.action) {
 
        // Normal chars
        case LFUN_SELFINSERT:
@@ -1175,7 +1171,7 @@ Inset::RESULT InsetText::localDispatch(FuncRequest const & ev)
 //         setErrorMessage(N_("Document is read only"));
                        break;
                }
-               if (!ev.argument.empty()) {
+               if (!cmd.argument.empty()) {
                        /* Automatically delete the currently selected
                         * text and replace it with what is being
                         * typed in now. Depends on lyxrc settings
@@ -1183,8 +1179,7 @@ Inset::RESULT InsetText::localDispatch(FuncRequest const & ev)
                         * 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) {
@@ -1193,9 +1188,9 @@ Inset::RESULT InsetText::localDispatch(FuncRequest const & ev)
                                }
                        }
                        lt->clearSelection();
-                       for (string::size_type i = 0; i < ev.argument.length(); ++i) {
+                       for (string::size_type i = 0; i < cmd.argument.length(); ++i) {
                                bv->owner()->getIntl().getTransManager().
-                                       TranslateAndInsert(ev.argument[i], lt);
+                                       TranslateAndInsert(cmd.argument[i], lt);
                        }
                }
                lt->selection.cursor = lt->cursor;
@@ -1289,7 +1284,7 @@ Inset::RESULT InsetText::localDispatch(FuncRequest const & ev)
 
                if (clip.empty())
                        break;
-               if (ev.argument == "paragraph") {
+               if (cmd.argument == "paragraph") {
                        lt->insertStringAsParagraphs(clip);
                } else {
                        lt->insertStringAsLines(clip);
@@ -1362,7 +1357,7 @@ Inset::RESULT InsetText::localDispatch(FuncRequest const & ev)
                        // and current buffer's textclass (number). */
                        LyXTextClass const & tclass =
                                bv->buffer()->params.getLyXTextClass();
-                       string layout = ev.argument;
+                       string layout = cmd.argument;
                        bool hasLayout = tclass.hasLayout(layout);
 
                        // If the entry is obsolete, use the new one instead.
@@ -1375,7 +1370,7 @@ Inset::RESULT InsetText::localDispatch(FuncRequest const & ev)
 
                        // see if we found the layout number:
                        if (!hasLayout) {
-                               FuncRequest lf(LFUN_MESSAGE, N_("Layout ") + ev.argument + N_(" not known"));
+                               FuncRequest lf(LFUN_MESSAGE, N_("Layout ") + cmd.argument + N_(" not known"));
                                bv->owner()->dispatch(lf);
                                break;
                        }
@@ -1405,7 +1400,7 @@ Inset::RESULT InsetText::localDispatch(FuncRequest const & ev)
                        cur_value = pit->params().spacing().getValue();
                }
 
-               istringstream istr(STRCONV(ev.argument));
+               istringstream istr(STRCONV(cmd.argument));
                string tmp;
                istr >> tmp;
                Spacing::Space new_spacing = cur_spacing;
@@ -1430,7 +1425,7 @@ Inset::RESULT InsetText::localDispatch(FuncRequest const & ev)
                        new_spacing = Spacing::Default;
                } else {
                        lyxerr << _("Unknown spacing argument: ")
-                                  << ev.argument << endl;
+                                  << cmd.argument << endl;
                }
                if (cur_spacing != new_spacing || cur_value != new_value) {
                        pit->params().spacing(Spacing(new_spacing, new_value));
@@ -1452,7 +1447,7 @@ Inset::RESULT InsetText::localDispatch(FuncRequest const & ev)
        case LFUN_ENDBUF:
        case LFUN_BEGINNINGBUF:
                updwhat = cursor_update;
-               if (!bv->dispatch(ev))
+               if (!bv->dispatch(cmd))
                        result = UNDISPATCHED;
                break;
 
@@ -1469,7 +1464,7 @@ Inset::RESULT InsetText::localDispatch(FuncRequest const & ev)
                // fallthrough
 
        default:
-               if (!bv->dispatch(ev))
+               if (!bv->dispatch(cmd))
                        result = UNDISPATCHED;
                break;
        }
@@ -1497,12 +1492,10 @@ Inset::RESULT InsetText::localDispatch(FuncRequest const & ev)
 
 
 int InsetText::latex(Buffer const * buf, ostream & os,
-                    bool moving_arg, bool) const
+                    LatexRunParams const & runparams) const
 {
        TexRow texrow;
-       latexParagraphs(buf, paragraphs,
-                       paragraphs.begin(), paragraphs.end(),
-                       os, texrow, moving_arg);
+       latexParagraphs(buf, paragraphs, os, texrow, runparams);
        return texrow.rows();
 }
 
@@ -1580,7 +1573,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;
 
@@ -1904,7 +1897,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);
@@ -1929,7 +1922,8 @@ bool InsetText::checkAndActivateInset(BufferView * bv, bool front)
                        static_cast<UpdatableInset*>(cpar(bv)->getInset(cpos(bv)));
                if (!isHighlyEditableInset(inset))
                        return false;
-               inset->edit(bv, front);
+               FuncRequest cmd(bv, LFUN_INSET_EDIT, front ? "left" : "right");
+               inset->localDispatch(cmd);
                if (!the_locking_inset)
                        return false;
                updateLocal(bv, CURSOR, false);
@@ -1944,7 +1938,7 @@ bool InsetText::checkAndActivateInset(BufferView * bv, int x, int y,
 {
        x -= drawTextXOffset;
        int dummyx = x;
-       int dummyy = y + insetAscent;
+       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
@@ -1956,12 +1950,13 @@ bool InsetText::checkAndActivateInset(BufferView * bv, int x, int y,
 
        if (inset) {
                if (x < 0)
-                       x = insetWidth;
+                       x = dim_.wid;
                if (y < 0)
-                       y = insetDescent;
+                       y = dim_.des;
                inset_x = cix(bv) - top_x + drawTextXOffset;
                inset_y = ciy(bv) + drawTextYOffset;
-               inset->edit(bv, x - inset_x, y - inset_y, button);
+               FuncRequest cmd(bv, LFUN_INSET_EDIT, x - inset_x, y - inset_y, button);
+               inset->localDispatch(cmd);
                if (!the_locking_inset)
                        return false;
                updateLocal(bv, CURSOR, false);
@@ -1990,18 +1985,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;
 
+       // But it it makes no difference that is a lot better.
+#warning FIXME.
+       // See if this can be simplified when std::list is in effect.
        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);
+
+       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();
@@ -2009,6 +2008,46 @@ void InsetText::setParagraphData(ParagraphList const & plist, bool same_id)
 }
 
 
+// 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();
@@ -2365,9 +2404,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_.wid;
+       int h = dim_.asc + dim_.des;
+       int ty = baseline - dim_.asc;
 
        if (ty < 0) {
                h += ty;
@@ -2396,24 +2435,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())
@@ -2656,14 +2677,13 @@ void InsetText::getDrawFont(LyXFont & font) const
 }
 
 
-void InsetText::appendParagraphs(Buffer * buffer,
-                                ParagraphList & plist)
+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)
-       BufferParams const & bparams = buffer->params;
 #if 0
+       BufferParams const & bparams = buffer->params;
        Paragraph * buf;
        Paragraph * tmpbuf = newpar;
        Paragraph * lastbuffer = buf = new Paragraph(*tmpbuf, false);
@@ -2697,14 +2717,13 @@ void InsetText::appendParagraphs(Buffer * buffer,
        mergeParagraph(buffer->params, paragraphs, lastbuffer);
 #else
        ParagraphList::iterator pit = plist.begin();
-       ParagraphList::iterator ins = paragraphs.insert(paragraphs.end(),
-                                                       new Paragraph(*pit, false));
+       ParagraphList::iterator ins = paragraphs.insert(paragraphs.end(), *pit);
        ++pit;
        mergeParagraph(buffer->params, paragraphs, boost::prior(ins));
 
        ParagraphList::iterator pend = plist.end();
        for (; pit != pend; ++pit) {
-               paragraphs.push_back(new Paragraph(*pit, false));
+               paragraphs.push_back(*pit);
        }
 
 #endif