]> git.lyx.org Git - lyx.git/blobdiff - src/text3.C
Alfredo's second patch
[lyx.git] / src / text3.C
index 34885b68033ae55c82c9b64dd5e190530907b54b..3aa80b5bbdf3dd98cea6f4ed2102a5ed3faceda2 100644 (file)
@@ -35,6 +35,7 @@
 #include "insets/insetcommand.h"
 #include "insets/insetnewline.h"
 #include "undo_funcs.h"
+#include "text_funcs.h"
 
 #include <ctime>
 #include <clocale>
@@ -42,6 +43,7 @@
 using std::endl;
 using std::find;
 using std::vector;
+using lyx::pos_type;
 
 extern string current_layout;
 extern int bibitemMaxWidth(BufferView *, LyXFont const &);
@@ -169,28 +171,29 @@ Inset * LyXText::checkInsetHit(int & x, int & y)
 bool LyXText::gotoNextInset(vector<Inset::Code> const & codes,
                            string const & contents)
 {
-       LyXCursor res = cursor;
+       ParagraphList::iterator end = ownerParagraphs().end();
+       ParagraphList::iterator pit = cursor.par();
+       pos_type pos = cursor.pos();
+
        Inset * inset;
        do {
-               if (res.pos() < res.par()->size() - 1) {
-                       res.pos(res.pos() + 1);
+               if (pos + 1 < pit->size()) {
+                       ++pos;
                } else  {
-                       res.par(res.par()->next());
-                       res.pos(0);
+                       ++pit;
+                       pos = 0;
                }
 
-       } while (res.par() &&
-                !(res.par()->isInset(res.pos())
-                  && (inset = res.par()->getInset(res.pos())) != 0
-                  && find(codes.begin(), codes.end(), inset->lyxCode())
-                  != codes.end()
-                  && (contents.empty() ||
-                      static_cast<InsetCommand *>(
-                                                       res.par()->getInset(res.pos()))->getContents()
-                      == contents)));
-
-       if (res.par()) {
-               setCursor(res.par(), res.pos(), false);
+       } while (pit != end &&
+                !(pit->isInset(pos) &&
+                  (inset = pit->getInset(pos)) != 0 &&
+                  find(codes.begin(), codes.end(), inset->lyxCode()) != codes.end() &&
+                  (contents.empty() ||
+                   static_cast<InsetCommand *>(pit->getInset(pos))->getContents()
+                   == contents)));
+
+       if (pit != end) {
+               setCursor(pit, pos, false);
                return true;
        }
        return false;
@@ -198,14 +201,15 @@ bool LyXText::gotoNextInset(vector<Inset::Code> const & codes,
 
 
 void LyXText::gotoInset(vector<Inset::Code> const & codes,
-                                 bool same_content)
+                       bool same_content)
 {
        bv()->hideCursor();
        bv()->beforeChange(this);
        update();
 
        string contents;
-       if (same_content && cursor.par()->isInset(cursor.pos())) {
+       if (same_content && cursor.pos() < cursor.par()->size()
+           && cursor.par()->isInset(cursor.pos())) {
                Inset const * inset = cursor.par()->getInset(cursor.pos());
                if (find(codes.begin(), codes.end(), inset->lyxCode())
                    != codes.end())
@@ -213,9 +217,9 @@ void LyXText::gotoInset(vector<Inset::Code> const & codes,
        }
 
        if (!gotoNextInset(codes, contents)) {
-               if (cursor.pos() || cursor.par() != ownerParagraph()) {
+               if (cursor.pos() || cursor.par() != ownerParagraphs().begin()) {
                        LyXCursor tmp = cursor;
-                       cursor.par(ownerParagraph());
+                       cursor.par(ownerParagraphs().begin());
                        cursor.pos(0);
                        if (!gotoNextInset(codes, contents)) {
                                cursor = tmp;
@@ -240,7 +244,7 @@ void LyXText::cursorPrevious()
 {
        int y = top_y();
 
-       if (!cursor.row()->previous()) {
+       if (cursor.row() == rows().begin()) {
                if (y > 0) {
                        int new_y = bv()->text->top_y() - bv()->workHeight();
                        bv()->screen().draw(bv()->text, bv(), new_y < 0 ? 0 : new_y);
@@ -249,7 +253,7 @@ void LyXText::cursorPrevious()
                return;
        }
 
-       Row * cursorrow = cursor.row();
+       RowList::iterator cursorrow = cursor.row();
 
        setCursorFromCoordinates(cursor.x_fix(), y);
        finishUndo();
@@ -279,10 +283,10 @@ void LyXText::cursorPrevious()
                }
        }
        bv()->screen().draw(bv()->text, bv(), new_y < 0 ? 0 : new_y);
-       if (cursor.row()->previous()) {
+       if (cursor.row() != rows().begin()) {
                LyXCursor cur;
-               setCursor(cur, cursor.row()->previous()->par(),
-                         cursor.row()->previous()->pos(), false);
+               setCursor(cur, boost::prior(cursor.row())->par(),
+                         boost::prior(cursor.row())->pos(), false);
                if (cur.y() > top_y()) {
                        cursorUp(true);
                }
@@ -295,7 +299,7 @@ void LyXText::cursorNext()
 {
        int topy = top_y();
 
-       if (!cursor.row()->next()) {
+       if (boost::next(cursor.row()) == rows().end()) {
                int y = cursor.y() - cursor.row()->baseline() +
                        cursor.row()->height();
                if (y > topy + bv()->workHeight()) {
@@ -314,7 +318,7 @@ void LyXText::cursorNext()
 
        getRowNearY(y);
 
-       Row * cursorrow = cursor.row();
+       RowList::iterator cursorrow = cursor.row();
        setCursorFromCoordinates(cursor.x_fix(), y);
        // + bv->workHeight());
        finishUndo();
@@ -340,10 +344,10 @@ void LyXText::cursorNext()
                }
        }
        bv()->screen().draw(bv()->text, bv(), new_y);
-       if (cursor.row()->next()) {
+       if (boost::next(cursor.row()) != rows().end()) {
                LyXCursor cur;
-               setCursor(cur, cursor.row()->next()->par(),
-                                               cursor.row()->next()->pos(), false);
+               setCursor(cur, boost::next(cursor.row())->par(),
+                         boost::next(cursor.row())->pos(), false);
                if (cur.y() < top_y() + bv()->workHeight()) {
                        cursorDown(true);
                }
@@ -406,14 +410,16 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
        switch (cmd.action) {
 
        case LFUN_APPENDIX: {
-               Paragraph * par = cursor.par();
-               bool start = !par->params().startOfAppendix();
+               ParagraphList::iterator pit = cursor.par();
+               bool start = !pit->params().startOfAppendix();
 
                // ensure that we have only one start_of_appendix in this document
-               Paragraph * tmp = ownerParagraph();
-               for (; tmp; tmp = tmp->next()) {
+               ParagraphList::iterator tmp = ownerParagraphs().begin();
+               ParagraphList::iterator end = ownerParagraphs().end();
+
+               for (; tmp != end; ++tmp) {
                        if (tmp->params().startOfAppendix()) {
-                               setUndo(bv, Undo::EDIT, tmp, tmp->next());
+                               setUndo(bv, Undo::EDIT, tmp, boost::next(tmp));
                                tmp->params().startOfAppendix(false);
                                int tmpy;
                                setHeightOfRow(getRow(tmp, 0, tmpy));
@@ -421,8 +427,8 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
                        }
                }
 
-               setUndo(bv, Undo::EDIT, par, par->next());
-               par->params().startOfAppendix(start);
+               setUndo(bv, Undo::EDIT, pit, boost::next(pit));
+               pit->params().startOfAppendix(start);
 
                // we can set the refreshing parameters now
                updateCounters();
@@ -457,15 +463,6 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
                finishChange(bv);
                break;
 
-       case LFUN_SHIFT_TAB:
-       case LFUN_TAB:
-               if (!selection.mark())
-                       bv->beforeChange(this);
-               update();
-               cursorTab();
-               finishChange(bv);
-               break;
-
        case LFUN_WORDRIGHT:
                if (!selection.mark())
                        bv->beforeChange(this);
@@ -880,11 +877,11 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
        }
 
        case LFUN_PARAGRAPH_SPACING: {
-               Paragraph * par = cursor.par();
-               Spacing::Space cur_spacing = par->params().spacing().getSpace();
+               ParagraphList::iterator pit = 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 is(cmd.argument.c_str());
                string tmp;
@@ -914,13 +911,18 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
                               << 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));
                        redoParagraph();
                        update();
                }
                break;
        }
 
+       case LFUN_INSET_SETTINGS:
+               lyx::Assert(bv->theLockingInset());
+               bv->theLockingInset()->getLockingInset()->showInsetDialog(bv);
+               break;
+
        case LFUN_INSET_TOGGLE:
                bv->hideCursor();
                bv->beforeChange(this);
@@ -1014,7 +1016,7 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
 
        case LFUN_TRANSPOSE_CHARS:
                update();
-               transposeChars();
+               transposeChars(*this, cursor);
                if (inset_owner)
                        bv->updateInset(inset_owner);
                update();
@@ -1129,14 +1131,14 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
                if (!change_layout && selection.set() &&
                        selection.start.par() != selection.end.par())
                {
-                       Paragraph * spar = selection.start.par();
-                       Paragraph * epar = selection.end.par()->next();
-                       while (spar != epar) {
-                               if (spar->layout()->name() != current_layout) {
+                       ParagraphList::iterator spit = selection.start.par();
+                       ParagraphList::iterator epit = boost::next(selection.end.par());
+                       while (spit != epit) {
+                               if (spit->layout()->name() != current_layout) {
                                        change_layout = true;
                                        break;
                                }
-                               spar = spar->next();
+                               ++spit;
                        }
                }
                if (change_layout) {
@@ -1188,21 +1190,21 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
        }
 
        case LFUN_QUOTE: {
-               Paragraph const * par = cursor.par();
+               ParagraphList::iterator pit = cursor.par();
                lyx::pos_type pos = cursor.pos();
                char c;
                if (!pos)
                        c = ' ';
-               else if (par->isInset(pos - 1) && par->getInset(pos - 1)->isSpace())
+               else if (pit->isInset(pos - 1) && pit->getInset(pos - 1)->isSpace())
                        c = ' ';
                else
-                       c = par->getChar(pos - 1);
+                       c = pit->getChar(pos - 1);
 
                bv->hideCursor();
-               LyXLayout_ptr const & style = par->layout();
+               LyXLayout_ptr const & style = pit->layout();
 
                if (style->pass_thru ||
-                               par->getFontSettings(bv->buffer()->params,
+                               pit->getFontSettings(bv->buffer()->params,
                                         pos).language()->lang() == "hebrew" ||
                        (!bv->insertInset(new InsetQuotes(c, bv->buffer()->params))))
                        bv->owner()->dispatch(FuncRequest(LFUN_SELFINSERT, "\""));
@@ -1285,7 +1287,7 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
                        Inset * tli = bv->theLockingInset();
                        LyXCursor cursor = bv->text->cursor;
                        LyXFont font = bv->text->getFont(bv->buffer(),
-                                                               cursor.par(), cursor.pos());
+                                                        cursor.par(), cursor.pos());
                        int width = tli->width(bv, font);
                        int inset_x = font.isVisibleRightToLeft()
                                ? cursor.ix() - width : cursor.ix();
@@ -1308,7 +1310,7 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
 
                bv->screen().hideCursor();
 
-               Row * cursorrow = bv->text->cursor.row();
+               RowList::iterator cursorrow = bv->text->cursor.row();
                bv->text->setCursorFromCoordinates(cmd.x, cmd.y + bv->text->top_y());
        #if 0
                // sorry for this but I have a strange error that the y value jumps at
@@ -1402,9 +1404,7 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
                        UpdatableInset * inset = static_cast<UpdatableInset *>(inset_hit);
                        selection_possible = false;
                        bv->owner()->message(inset->editMessage());
-                       //inset->edit(bv, x, y, cmd.button());
                        // We just have to lock the inset before calling a PressEvent on it!
-                       // we don't need the edit() call here! (Jug20020329)
                        if (!bv->lockInset(inset))
                                lyxerr[Debug::INSETS] << "Cannot lock inset" << endl;
                        FuncRequest cmd1(bv, LFUN_MOUSE_PRESS, x, y, cmd.button());