]> git.lyx.org Git - lyx.git/blobdiff - src/text3.C
don't rm emergency saves ever
[lyx.git] / src / text3.C
index fb2c66dfc27633bd6440ec44f3b8b61c99d055fb..ff12e1fcb6bda77e34c5838ac477e9bd4ecf2a32 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 &);
@@ -66,11 +68,8 @@ namespace {
                }
                if (!lt->isInInset()) {
                        bv->update(lt, BufferView::SELECT);
-                       bv->showCursor();
-               } else if (bv->text->status() != LyXText::UNCHANGED) {
-                       bv->theLockingInset()->hideInsetCursor(bv);
+               } else if (bv->text->refreshStatus() != LyXText::REFRESH_NONE) {
                        bv->update(BufferView::SELECT);
-                       bv->showCursor();
                }
 
                if (!lt->selection.set())
@@ -169,28 +168,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 +198,14 @@ 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 +213,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 +240,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 +249,7 @@ void LyXText::cursorPrevious()
                return;
        }
 
-       Row * cursorrow = cursor.row();
+       RowList::iterator cursorrow = cursor.row();
 
        setCursorFromCoordinates(cursor.x_fix(), y);
        finishUndo();
@@ -279,10 +279,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);
                }
@@ -293,20 +293,20 @@ void LyXText::cursorPrevious()
 
 void LyXText::cursorNext()
 {
-       int top_y = top_y();
+       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 > top_y + bv()->workHeight()) {
+               if (y > topy + bv()->workHeight()) {
                        bv()->screen().draw(bv()->text, bv(), bv()->text->top_y() + bv()->workHeight());
                        bv()->updateScrollbar();
                }
                return;
        }
 
-       int y = top_y + bv()->workHeight();
-       if (inset_owner && !top_y) {
+       int y = topy + bv()->workHeight();
+       if (inset_owner && !topy) {
                y -= (bv()->text->cursor.iy()
                          - bv()->text->top_y()
                          + bv()->theLockingInset()->insetInInsetY());
@@ -314,7 +314,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 +340,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);
                }
@@ -361,7 +361,6 @@ namespace {
 
 void specialChar(LyXText * lt, BufferView * bv, InsetSpecialChar::Kind kind)
 {
-       bv->hideCursor();
        lt->update();
        InsetSpecialChar * new_inset = new InsetSpecialChar(kind);
        if (!bv->insertInset(new_inset))
@@ -406,14 +405,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 +422,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 +458,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);
@@ -736,7 +728,6 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
                        update();
                        // It is possible to make it a lot faster still
                        // just comment out the line below...
-                       bv->showCursor();
                } else {
                        update();
                        cutSelection(bv, true);
@@ -794,7 +785,6 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
                                update();
                                // It is possible to make it a lot faster still
                                // just comment out the line below...
-                               bv->showCursor();
                        }
                } else {
                        update();
@@ -880,11 +870,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,15 +904,19 @@ 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);
                update();
                toggleInset();
@@ -1014,7 +1008,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();
@@ -1022,7 +1016,6 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
 
        case LFUN_PASTE:
                cmd.message(_("Paste"));
-               bv->hideCursor();
                // clear the selection
                bv->toggleSelection();
                clearSelection();
@@ -1034,7 +1027,6 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
                break;
 
        case LFUN_CUT:
-               bv->hideCursor();
                update();
                cutSelection(bv, true);
                update();
@@ -1129,18 +1121,17 @@ 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) {
-                       bv->hideCursor();
                        current_layout = layout;
                        update();
                        setLayout(layout);
@@ -1154,7 +1145,6 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
        case LFUN_PASTESELECTION: {
                if (!bv->buffer())
                        break;
-               bv->hideCursor();
                // this was originally a beforeChange(bv->text), i.e
                // the outermost LyXText!
                bv->beforeChange(this);
@@ -1188,21 +1178,20 @@ 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, "\""));
@@ -1238,7 +1227,6 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
                        break;
                if (cmd.button() == mouse_button::button1) {
                        if (!isInInset()) {
-                               bv->screen().hideCursor();
                                bv->screen().toggleSelection(this, bv);
                        }
                        cursorHome();
@@ -1259,7 +1247,6 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
                        break;
                if (cmd.button() == mouse_button::button1) {
                        if (!isInInset()) {
-                               bv->screen().hideCursor();
                                bv->screen().toggleSelection(this, bv);
                                selectWord(LyXText::WHOLE_WORD_STRICT);
                                bv->screen().toggleSelection(this, bv, false);
@@ -1285,7 +1272,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();
@@ -1306,9 +1293,7 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
                        break;
                }
 
-               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
@@ -1333,7 +1318,6 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
                bv->text->setSelection();
                bv->screen().toggleToggle(bv->text, bv);
                bv->fitCursor();
-               bv->showCursor();
                break;
        }
 
@@ -1387,7 +1371,6 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
 
                if (!inset_hit)
                        selection_possible = true;
-               bv->screen().hideCursor();
 
                // Clear the selection
                bv->screen().toggleSelection(bv->text, bv);
@@ -1402,9 +1385,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());