]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insettext.C
Rename LatexRunParams::fragile as moving_arg.
[lyx.git] / src / insets / insettext.C
index 753161a6d560ccfb48932c215f1338321c0ceb02..981629234425abf861b8f0d1c8a444929a4aa24f 100644 (file)
 
 #include <config.h>
 
-
 #include "insettext.h"
 
 #include "buffer.h"
 #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"
@@ -38,6 +39,7 @@
 #include "sgml.h"
 #include "rowpainter.h"
 #include "insetnewline.h"
+#include "Lsstream.h"
 
 #include "frontends/Alert.h"
 #include "frontends/Dialogs.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
@@ -84,13 +87,13 @@ void InsetText::saveLyXTextState(LyXText * t) const
        }
 
        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();
@@ -136,7 +139,7 @@ InsetText::InsetText(BufferParams const & bp)
        : UpdatableInset(), lt(0), in_update(false), do_resize(0),
          do_reinit(false)
 {
-       paragraphs.set(new Paragraph);
+       paragraphs.push_back(new Paragraph);
        paragraphs.begin()->layout(bp.getLyXTextClass().defaultLayout());
        if (bp.tracking_changes)
                paragraphs.begin()->trackChanges();
@@ -162,7 +165,7 @@ InsetText & InsetText::operator=(InsetText const & it)
 void InsetText::init(InsetText const * ins, bool same_id)
 {
        if (ins) {
-               setParagraphData(&*(ins->paragraphs.begin()), same_id);
+               setParagraphData(ins->paragraphs, same_id);
                autoBreakRows = ins->autoBreakRows;
                drawFrame_ = ins->drawFrame_;
                frame_color = ins->frame_color;
@@ -178,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;
@@ -217,7 +217,7 @@ void InsetText::clear(bool just_mark_erased)
        LyXLayout_ptr old_layout = paragraphs.begin()->layout();
 
        paragraphs.clear();
-       paragraphs.set(new Paragraph);
+       paragraphs.push_back(new Paragraph);
        paragraphs.begin()->setInsetOwner(this);
        paragraphs.begin()->layout(old_layout);
 
@@ -295,47 +295,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.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_ = 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 +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)
@@ -376,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)
@@ -419,6 +400,9 @@ void InsetText::draw(BufferView * bv, LyXFont const & f,
 
        int yf = y_offset + first;
        y = 0;
+
+       bv->hideCursor();
+
        while ((rowit != end) && (yf < ph)) {
                RowPainter rp(*bv, *lt, rowit);
                rp.paint(y + y_offset + first, int(x), y + lt->top_y());
@@ -433,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;
@@ -447,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);
 }
@@ -545,9 +529,15 @@ void InsetText::setUpdateStatus(BufferView * bv, int what) const
 
 void InsetText::updateLocal(BufferView * bv, int what, bool mark_dirty)
 {
+#if 0
        if (!autoBreakRows &&
            boost::next(paragraphs.begin()) != paragraphs.end())
                collapseParagraphs(bv);
+#else
+       if (!autoBreakRows && paragraphs.size() > 1)
+               collapseParagraphs(bv);
+#endif
+
        bool clear = false;
        if (!lt) {
                lt = getLyXText(bv);
@@ -589,111 +579,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);
-       showInsetCursor(bv);
-
-       // 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);
-       showInsetCursor(bv);
-}
-
-
 void InsetText::insetUnlock(BufferView * bv)
 {
        if (the_locking_inset) {
@@ -701,7 +586,6 @@ void InsetText::insetUnlock(BufferView * bv)
                the_locking_inset = 0;
                updateLocal(bv, CURSOR_PAR, false);
        }
-       hideInsetCursor(bv);
        no_selection = true;
        locked = false;
        int code = NONE;
@@ -721,9 +605,9 @@ void InsetText::insetUnlock(BufferView * bv)
                bv->owner()->setLayout(bv->text->cursor.par()->layout()->name());
        // hack for deleteEmptyParMech
        if (!paragraphs.begin()->empty()) {
-               lt->setCursor(&*(paragraphs.begin()), 0);
+               lt->setCursor(paragraphs.begin(), 0);
        } else if (boost::next(paragraphs.begin()) != paragraphs.end()) {
-               lt->setCursor(&*boost::next(paragraphs.begin()), 0);
+               lt->setCursor(boost::next(paragraphs.begin()), 0);
        }
        if (clear)
                lt = 0;
@@ -749,7 +633,7 @@ void InsetText::lockInset(BufferView * bv)
                lt = getLyXText(bv);
                clear = true;
        }
-       lt->setCursor(&*(paragraphs.begin()), 0);
+       lt->setCursor(paragraphs.begin(), 0);
        lt->clearSelection();
        finishUndo();
        // If the inset is empty set the language of the current font to the
@@ -800,13 +684,13 @@ bool InsetText::lockInsetInInset(BufferView * bv, UpdatableInset * inset)
                                pit->insetlist.end();
                        for (; it != end; ++it) {
                                if (it.getInset() == inset) {
-                                       getLyXText(bv)->setCursorIntern(&*pit, it.getPos());
+                                       getLyXText(bv)->setCursorIntern(pit, it.getPos());
                                        lockInset(bv, inset);
                                        return true;
                                }
                                if (it.getInset()->getInsetFromID(id)) {
-                                       getLyXText(bv)->setCursorIntern(&*pit, it.getPos());
-                                       it.getInset()->edit(bv);
+                                       getLyXText(bv)->setCursorIntern(pit, it.getPos());
+                                       it.getInset()->localDispatch(FuncRequest(bv, LFUN_INSET_EDIT));
                                        return the_locking_inset->lockInsetInInset(bv, inset);
                                }
                        }
@@ -923,10 +807,9 @@ 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);
 
-       hideInsetCursor(bv);
        if (the_locking_inset) {
                if (the_locking_inset == inset) {
                        the_locking_inset->localDispatch(cmd1);
@@ -967,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());
@@ -1001,7 +884,6 @@ void InsetText::lfunMousePress(FuncRequest const & cmd)
        } else {
                getLyXText(bv)->clearSelection();
        }
-       showInsetCursor(bv);
 }
 
 
@@ -1017,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) {
@@ -1066,10 +948,9 @@ void InsetText::lfunMouseMotion(FuncRequest const & cmd)
                lt = getLyXText(bv);
                clear = true;
        }
-       hideInsetCursor(bv);
        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)
@@ -1084,22 +965,94 @@ void InsetText::lfunMouseMotion(FuncRequest const & cmd)
        if (flag) {
                updateLocal(bv, SELECTION, false);
        }
-       showInsetCursor(bv);
 }
 
 
-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_.a);
+                               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;
        }
@@ -1107,16 +1060,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) {
@@ -1151,7 +1104,6 @@ Inset::RESULT InsetText::localDispatch(FuncRequest const & ev)
                        return result;
                }
        }
-       hideInsetCursor(bv);
        bool clear = false;
        if (!lt) {
                lt = getLyXText(bv);
@@ -1166,7 +1118,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:
@@ -1174,7 +1126,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,7 +1135,7 @@ Inset::RESULT InsetText::localDispatch(FuncRequest const & ev)
 #if 0
                        // This should not be needed here and is also WRONG!
                        setUndo(bv, Undo::INSERT,
-                               lt->cursor.par(), lt->cursor.par()->next());
+                               lt->cursor.par(), boost::next(lt->cursor.par()));
 #endif
                        bv->switchKeyMap();
                        if (lyxrc.auto_region_delete) {
@@ -1192,9 +1144,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;
@@ -1288,7 +1240,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);
@@ -1361,7 +1313,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.
@@ -1374,7 +1326,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;
                        }
@@ -1397,14 +1349,14 @@ Inset::RESULT InsetText::localDispatch(FuncRequest const & ev)
                // inherit bufferparams/paragraphparams in a strange way. (Lgb)
                // FIXME: how old is this comment ? ...
        {
-               Paragraph * par = lt->cursor.par();
-               Spacing::Space cur_spacing = par->params().spacing().getSpace();
+               ParagraphList::iterator pit = lt->cursor.par();
+               Spacing::Space cur_spacing = pit->params().spacing().getSpace();
                float cur_value = 1.0;
                if (cur_spacing == Spacing::Other) {
-                       cur_value = par->params().spacing().getValue();
+                       cur_value = pit->params().spacing().getValue();
                }
 
-               istringstream istr(ev.argument.c_str());
+               istringstream istr(STRCONV(cmd.argument));
                string tmp;
                istr >> tmp;
                Spacing::Space new_spacing = cur_spacing;
@@ -1429,10 +1381,10 @@ 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) {
-                       par->params().spacing(Spacing(new_spacing, new_value));
+                       pit->params().spacing(Spacing(new_spacing, new_value));
                        updwhat = CURSOR_PAR;
                        updflag = true;
                }
@@ -1451,7 +1403,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;
 
@@ -1468,7 +1420,7 @@ Inset::RESULT InsetText::localDispatch(FuncRequest const & ev)
                // fallthrough
 
        default:
-               if (!bv->dispatch(ev))
+               if (!bv->dispatch(cmd))
                        result = UNDISPATCHED;
                break;
        }
@@ -1496,12 +1448,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();
 }
 
@@ -1579,7 +1529,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;
 
@@ -1631,7 +1581,7 @@ int InsetText::docbook(Buffer const * buf, ostream & os, bool mixcont) const
                        break;
                }
 
-               buf->simpleDocBookOnePar(os, &*pit, desc_on, depth + 1 + command_depth);
+               buf->simpleDocBookOnePar(os, pit, desc_on, depth + 1 + command_depth);
 
                string end_tag;
                // write closing SGML tags
@@ -1683,6 +1633,17 @@ void InsetText::validate(LaTeXFeatures & features) const
 }
 
 
+void InsetText::getCursor(BufferView & bv, int & x, int & y) const
+{
+       if (the_locking_inset) {
+               the_locking_inset->getCursor(bv, x, y);
+               return;
+       }
+       x = cx(&bv);
+       y = cy(&bv) + InsetText::y();
+}
+
+
 void InsetText::getCursorPos(BufferView * bv, int & x, int & y) const
 {
        if (the_locking_inset) {
@@ -1703,58 +1664,6 @@ int InsetText::insetInInsetY() const
 }
 
 
-void InsetText::toggleInsetCursor(BufferView * bv)
-{
-       if (the_locking_inset) {
-               the_locking_inset->toggleInsetCursor(bv);
-               return;
-       }
-
-       LyXFont const font(getLyXText(bv)->getFont(bv->buffer(), cpar(bv), cpos(bv)));
-
-       int const asc = font_metrics::maxAscent(font);
-       int const desc = font_metrics::maxDescent(font);
-
-       if (isCursorVisible())
-               bv->hideLockedInsetCursor();
-       else
-               bv->showLockedInsetCursor(cx(bv), cy(bv), asc, desc);
-       toggleCursorVisible();
-}
-
-
-void InsetText::showInsetCursor(BufferView * bv, bool show)
-{
-       if (the_locking_inset) {
-               the_locking_inset->showInsetCursor(bv, show);
-               return;
-       }
-       if (!isCursorVisible()) {
-               LyXFont const font =
-                       getLyXText(bv)->getFont(bv->buffer(), cpar(bv), cpos(bv));
-
-               int const asc = font_metrics::maxAscent(font);
-               int const desc = font_metrics::maxDescent(font);
-
-               bv->fitLockedInsetCursor(cx(bv), cy(bv), asc, desc);
-               if (show)
-                       bv->showLockedInsetCursor(cx(bv), cy(bv), asc, desc);
-               setCursorVisible(true);
-       }
-}
-
-
-void InsetText::hideInsetCursor(BufferView * bv)
-{
-       if (isCursorVisible()) {
-               bv->hideLockedInsetCursor();
-               setCursorVisible(false);
-       }
-       if (the_locking_inset)
-               the_locking_inset->hideInsetCursor(bv);
-}
-
-
 void InsetText::fitInsetCursor(BufferView * bv) const
 {
        if (the_locking_inset) {
@@ -1796,13 +1705,18 @@ Inset::RESULT
 InsetText::moveRightIntern(BufferView * bv, bool front,
                           bool activate_inset, bool selecting)
 {
-       if (!cpar(bv)->next() && (cpos(bv) >= cpar(bv)->size()))
+       LyXText * text = getLyXText(bv);
+
+       ParagraphList::iterator c_par = cpar(bv);
+
+       if (boost::next(c_par) == paragraphs.end() &&
+           (cpos(bv) >= c_par->size()))
                return FINISHED_RIGHT;
        if (activate_inset && checkAndActivateInset(bv, front))
                return DISPATCHED;
-       getLyXText(bv)->cursorRight(bv);
+       text->cursorRight(bv);
        if (!selecting)
-               getLyXText(bv)->clearSelection();
+               text->clearSelection();
        return DISPATCHED_NOUPDATE;
 }
 
@@ -1811,11 +1725,13 @@ Inset::RESULT
 InsetText::moveLeftIntern(BufferView * bv, bool front,
                          bool activate_inset, bool selecting)
 {
-       if (!cpar(bv)->previous() && (cpos(bv) <= 0))
+       LyXText * text = getLyXText(bv);
+
+       if (cpar(bv) == paragraphs.begin() && (cpos(bv) <= 0))
                return FINISHED;
-       getLyXText(bv)->cursorLeft(bv);
+       text->cursorLeft(bv);
        if (!selecting)
-               getLyXText(bv)->clearSelection();
+               text->clearSelection();
        if (activate_inset && checkAndActivateInset(bv, front))
                return DISPATCHED;
        return DISPATCHED_NOUPDATE;
@@ -1850,7 +1766,6 @@ bool InsetText::insertInset(BufferView * bv, Inset * inset)
                return false;
        }
        inset->setOwner(this);
-       hideInsetCursor(bv);
        getLyXText(bv)->insertInset(inset);
        bv->fitCursor();
        updateLocal(bv, CURSOR_PAR|CURSOR, true);
@@ -1938,7 +1853,7 @@ void InsetText::setFont(BufferView * bv, LyXFont const & font, bool toggleall,
                clear = true;
        }
        if (lt->selection.set()) {
-               setUndo(bv, Undo::EDIT, lt->cursor.par(), lt->cursor.par()->next());
+               setUndo(bv, Undo::EDIT, lt->cursor.par(), boost::next(lt->cursor.par()));
        }
        if (selectall)
                selectAll(bv);
@@ -1963,7 +1878,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);
@@ -1978,7 +1894,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
@@ -1990,12 +1906,13 @@ 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;
-               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);
@@ -2024,22 +1941,20 @@ int InsetText::getMaxWidth(BufferView * bv, UpdatableInset const * inset) const
 }
 
 
-void InsetText::setParagraphData(Paragraph * p, 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;
 
        paragraphs.clear();
-       paragraphs.set(new Paragraph(*p, same_id));
-       paragraphs.begin()->setInsetOwner(this);
-       Paragraph * np = &*(paragraphs.begin());
-       while (p->next()) {
-               p = p->next();
-               np->next(new Paragraph(*p, same_id));
-               np->next()->previous(np);
-               np = np->next();
-               np->setInsetOwner(this);
+       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);
        }
+
        reinitLyXText();
        need_update = INIT;
 }
@@ -2150,7 +2065,7 @@ pos_type InsetText::cpos(BufferView * bv) const
 }
 
 
-Paragraph * InsetText::cpar(BufferView * bv) const
+ParagraphList::iterator InsetText::cpar(BufferView * bv) const
 {
        return getLyXText(bv)->cursor.par();
 }
@@ -2175,7 +2090,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() == paragraphs.begin());
                return lt;
        }
        // Super UGLY! (Lgb)
@@ -2401,9 +2316,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;
@@ -2418,19 +2333,9 @@ void InsetText::clearInset(BufferView * bv, int start_x, int baseline) const
 }
 
 
-Paragraph * InsetText::firstParagraph() const
-{
-       Paragraph * result;
-       if (the_locking_inset)
-               if ((result = the_locking_inset->firstParagraph()))
-                       return result;
-       return &*(paragraphs.begin());
-}
-
-
-Paragraph * InsetText::getFirstParagraph(int i) const
+ParagraphList * InsetText::getParagraphs(int i) const
 {
-       return (i == 0) ? &*(paragraphs.begin()) : 0;
+       return (i == 0) ? const_cast<ParagraphList*>(&paragraphs) : 0;
 }
 
 
@@ -2442,24 +2347,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())
@@ -2637,7 +2524,7 @@ bool InsetText::searchBackward(BufferView * bv, string const & str,
                while (boost::next(pit) != pend)
                        ++pit;
 
-               lt->setCursor(&*pit, pit->size());
+               lt->setCursor(pit, pit->size());
        }
        lyxfind::SearchResult result =
                lyxfind::LyXFind(bv, lt, str, false, cs, mw);
@@ -2678,12 +2565,12 @@ void InsetText::collapseParagraphs(BufferView * bv)
                }
                if (llt->selection.set()) {
                        if (llt->selection.start.par() == boost::next(paragraphs.begin())) {
-                               llt->selection.start.par(&*(paragraphs.begin()));
+                               llt->selection.start.par(paragraphs.begin());
                                llt->selection.start.pos(
                                        llt->selection.start.pos() + paragraphs.begin()->size());
                        }
                        if (llt->selection.end.par() == boost::next(paragraphs.begin())) {
-                               llt->selection.end.par(&*(paragraphs.begin()));
+                               llt->selection.end.par(paragraphs.begin());
                                llt->selection.end.pos(
                                        llt->selection.end.pos() + paragraphs.begin()->size());
                        }
@@ -2702,9 +2589,12 @@ void InsetText::getDrawFont(LyXFont & font) const
 }
 
 
-void InsetText::appendParagraphs(Buffer * buffer,
-                                Paragraph * newpar)
+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;
@@ -2720,6 +2610,7 @@ void InsetText::appendParagraphs(Buffer * buffer,
                if (bparams.tracking_changes)
                        lastbuffer->cleanChanges();
        }
+
        lastbuffer = &*(paragraphs.begin());
        while (lastbuffer->next())
                lastbuffer = lastbuffer->next();
@@ -2736,6 +2627,19 @@ void InsetText::appendParagraphs(Buffer * buffer,
        lastbuffer->next(buf);
        buf->previous(lastbuffer);
        mergeParagraph(buffer->params, paragraphs, lastbuffer);
+#else
+       ParagraphList::iterator pit = plist.begin();
+       ParagraphList::iterator ins = paragraphs.insert(paragraphs.end(),
+                                                       new Paragraph(*pit, false));
+       ++pit;
+       mergeParagraph(buffer->params, paragraphs, boost::prior(ins));
+
+       ParagraphList::iterator pend = plist.end();
+       for (; pit != pend; ++pit) {
+               paragraphs.push_back(new Paragraph(*pit, false));
+       }
+
+#endif
 
        reinitLyXText();
 }