]> git.lyx.org Git - lyx.git/blobdiff - src/insets/insettext.C
Final touch 'inset display()'; fix 'is a bit silly' bug
[lyx.git] / src / insets / insettext.C
index 921289d1cd057afb241156d3a2ae2b7eefdc2121..941877d16fd9aa20fc9a36eb08b95c5d3978c7c3 100644 (file)
@@ -33,7 +33,7 @@
 #include "rowpainter.h"
 #include "sgml.h"
 #include "texrow.h"
-#include "undo_funcs.h"
+#include "undo.h"
 #include "WordLangTuple.h"
 
 #include "frontends/Alert.h"
@@ -399,7 +399,7 @@ bool InsetText::lockInsetInInset(BufferView * bv, UpdatableInset * inset)
                        for (; it != end; ++it) {
                                if (it->inset == inset) {
                                        lyxerr << "InsetText::lockInsetInInset: 1 a" << endl;
-                                       text_.setCursorIntern(  
+                                       text_.setCursorIntern(
                                                std::distance(paragraphs.begin(), pit), it->pos);
                                        lyxerr << "InsetText::lockInsetInInset: 1 b" << endl;
                                        lyxerr << "bv: " << bv << " inset: " << inset << endl;
@@ -477,7 +477,7 @@ void InsetText::lfunMousePress(FuncRequest const & cmd)
 
        if (the_locking_inset) {
                if (the_locking_inset == inset) {
-                       the_locking_inset->localDispatch(cmd1);
+                       the_locking_inset->dispatch(cmd1);
                        return;
                }
                // otherwise only unlock the_locking_inset
@@ -495,7 +495,7 @@ void InsetText::lfunMousePress(FuncRequest const & cmd)
                        if (!bv->lockInset(uinset)) {
                                lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
                        }
-                       inset->localDispatch(cmd1);
+                       inset->dispatch(cmd1);
                        if (the_locking_inset)
                                updateLocal(bv, false);
                        return;
@@ -504,7 +504,7 @@ void InsetText::lfunMousePress(FuncRequest const & cmd)
        if (!inset) {
                bool paste_internally = false;
                if (cmd.button() == mouse_button::button2 && getLyXText(bv)->selection.set()) {
-                       localDispatch(FuncRequest(bv, LFUN_COPY));
+                       dispatch(FuncRequest(bv, LFUN_COPY));
                        paste_internally = true;
                }
                int old_top_y = bv->top_y();
@@ -528,9 +528,9 @@ void InsetText::lfunMousePress(FuncRequest const & cmd)
                // insert this
                if (cmd.button() == mouse_button::button2) {
                        if (paste_internally)
-                               localDispatch(FuncRequest(bv, LFUN_PASTE));
+                               dispatch(FuncRequest(bv, LFUN_PASTE));
                        else
-                               localDispatch(FuncRequest(bv, LFUN_PASTESELECTION, "paragraph"));
+                               dispatch(FuncRequest(bv, LFUN_PASTESELECTION, "paragraph"));
                }
        } else {
                getLyXText(bv)->clearSelection();
@@ -547,7 +547,7 @@ bool InsetText::lfunMouseRelease(FuncRequest const & cmd)
 
        no_selection = true;
        if (the_locking_inset)
-               return the_locking_inset->localDispatch(cmd1);
+               return the_locking_inset->dispatch(cmd1);
 
        int tmp_x = cmd.x;
        int tmp_y = cmd.y + dim_.asc - bv->top_y();
@@ -557,7 +557,7 @@ bool InsetText::lfunMouseRelease(FuncRequest const & cmd)
 
        // We still need to deal properly with the whole relative vs.
        // absolute mouse co-ords thing in a realiable, sensible way
-       bool ret = inset->localDispatch(cmd1);
+       bool ret = inset->dispatch(cmd1);
        updateLocal(bv, false);
        return ret;
 }
@@ -570,7 +570,7 @@ void InsetText::lfunMouseMotion(FuncRequest const & cmd)
        cmd1.y -= inset_y;
 
        if (the_locking_inset) {
-               the_locking_inset->localDispatch(cmd1);
+               the_locking_inset->dispatch(cmd1);
                return;
        }
 
@@ -588,14 +588,16 @@ void InsetText::lfunMouseMotion(FuncRequest const & cmd)
 }
 
 
-InsetOld::RESULT InsetText::localDispatch(FuncRequest const & cmd)
+dispatch_result
+InsetText::priv_dispatch(FuncRequest const & cmd,
+                        idx_type & idx, pos_type & pos)
 {
        BufferView * bv = cmd.view();
        setViewCache(bv);
 
        switch (cmd.action) {
        case LFUN_INSET_EDIT: {
-               UpdatableInset::localDispatch(cmd);
+               UpdatableInset::priv_dispatch(cmd, idx, pos);
 
                if (!bv->lockInset(this)) {
                        lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
@@ -615,7 +617,7 @@ InsetOld::RESULT InsetText::localDispatch(FuncRequest const & cmd)
                if (cmd.argument.size()) {
                        if (cmd.argument == "left")
                                text_.setCursorIntern(0, 0);
-                       else 
+                       else
                                text_.setCursor(paragraphs.size() - 1, paragraphs.back().size());
                } else {
                        int tmp_y = (cmd.y < 0) ? 0 : cmd.y;
@@ -668,7 +670,7 @@ InsetOld::RESULT InsetText::localDispatch(FuncRequest const & cmd)
        bool was_empty = paragraphs.begin()->empty() && paragraphs.size() == 1;
        no_selection = false;
 
-       RESULT result = UpdatableInset::localDispatch(cmd);
+       dispatch_result result = UpdatableInset::priv_dispatch(cmd, idx, pos);
        if (result != UNDISPATCHED)
                return DISPATCHED;
 
@@ -677,7 +679,7 @@ InsetOld::RESULT InsetText::localDispatch(FuncRequest const & cmd)
                return FINISHED;
 
        if (the_locking_inset) {
-               result = the_locking_inset->localDispatch(cmd);
+               result = the_locking_inset->dispatch(cmd);
                if (result == DISPATCHED_NOUPDATE)
                        return result;
                if (result == DISPATCHED) {
@@ -1177,7 +1179,7 @@ void InsetText::fitInsetCursor(BufferView * bv) const
 }
 
 
-InsetOld::RESULT InsetText::moveRight(BufferView * bv)
+dispatch_result InsetText::moveRight(BufferView * bv)
 {
        if (text_.cursorPar()->isRightToLeftPar(bv->buffer()->params()))
                return moveLeftIntern(bv, false, true, false);
@@ -1186,7 +1188,7 @@ InsetOld::RESULT InsetText::moveRight(BufferView * bv)
 }
 
 
-InsetOld::RESULT InsetText::moveLeft(BufferView * bv)
+dispatch_result InsetText::moveLeft(BufferView * bv)
 {
        if (text_.cursorPar()->isRightToLeftPar(bv->buffer()->params()))
                return moveRightIntern(bv, true, true, false);
@@ -1195,7 +1197,7 @@ InsetOld::RESULT InsetText::moveLeft(BufferView * bv)
 }
 
 
-InsetOld::RESULT
+dispatch_result
 InsetText::moveRightIntern(BufferView * bv, bool front,
                           bool activate_inset, bool selecting)
 {
@@ -1212,7 +1214,7 @@ InsetText::moveRightIntern(BufferView * bv, bool front,
 }
 
 
-InsetOld::RESULT
+dispatch_result
 InsetText::moveLeftIntern(BufferView * bv, bool front,
                          bool activate_inset, bool selecting)
 {
@@ -1227,7 +1229,7 @@ InsetText::moveLeftIntern(BufferView * bv, bool front,
 }
 
 
-InsetOld::RESULT InsetText::moveUp(BufferView * bv)
+dispatch_result InsetText::moveUp(BufferView * bv)
 {
        if (crow() == text_.firstRow())
                return FINISHED_UP;
@@ -1237,7 +1239,7 @@ InsetOld::RESULT InsetText::moveUp(BufferView * bv)
 }
 
 
-InsetOld::RESULT InsetText::moveDown(BufferView * bv)
+dispatch_result InsetText::moveDown(BufferView * bv)
 {
        if (crow() == text_.lastRow())
                return FINISHED_DOWN;
@@ -1336,7 +1338,7 @@ void InsetText::setFont(BufferView * bv, LyXFont const & font, bool toggleall,
 
 
        if (text_.selection.set())
-               recordUndo(bv, Undo::ATOMIC, text_.cursorPar());
+               text_.recUndo(text_.cursor.par());
 
        if (selectall) {
                text_.cursorTop();
@@ -1363,7 +1365,7 @@ bool InsetText::checkAndActivateInset(BufferView * bv, bool front)
        if (!isHighlyEditableInset(inset))
                return false;
        FuncRequest cmd(bv, LFUN_INSET_EDIT, front ? "left" : "right");
-       inset->localDispatch(cmd);
+       inset->dispatch(cmd);
        if (!the_locking_inset)
                return false;
        updateLocal(bv, false);
@@ -1394,7 +1396,7 @@ bool InsetText::checkAndActivateInset(BufferView * bv, int x, int y,
        inset_x = cx() - top_x;
        inset_y = cy();
        FuncRequest cmd(bv, LFUN_INSET_EDIT, x - inset_x, y - inset_y, button);
-       inset->localDispatch(cmd);
+       inset->dispatch(cmd);
        if (!the_locking_inset)
                return false;
        updateLocal(bv, false);
@@ -1582,6 +1584,12 @@ ParagraphList * InsetText::getParagraphs(int i) const
 }
 
 
+LyXText * InsetText::getText(int i) const
+{
+       return (i == 0) ? const_cast<LyXText*>(&text_) : 0;
+}
+
+
 LyXCursor const & InsetText::cursor(BufferView * bv) const
 {
        if (the_locking_inset)