]> git.lyx.org Git - lyx.git/blobdiff - src/text3.C
Alfredo's second patch
[lyx.git] / src / text3.C
index 1e445f459f02049472c507ea3b69671ddf1a6313..3aa80b5bbdf3dd98cea6f4ed2102a5ed3faceda2 100644 (file)
@@ -43,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 &);
@@ -170,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;
@@ -199,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())
@@ -216,7 +219,7 @@ void LyXText::gotoInset(vector<Inset::Code> const & codes,
        if (!gotoNextInset(codes, contents)) {
                if (cursor.pos() || cursor.par() != ownerParagraphs().begin()) {
                        LyXCursor tmp = cursor;
-                       cursor.par(&*ownerParagraphs().begin());
+                       cursor.par(ownerParagraphs().begin());
                        cursor.pos(0);
                        if (!gotoNextInset(codes, contents)) {
                                cursor = tmp;
@@ -407,8 +410,8 @@ 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
                ParagraphList::iterator tmp = ownerParagraphs().begin();
@@ -416,16 +419,16 @@ Inset::RESULT LyXText::dispatch(FuncRequest const & cmd)
 
                for (; tmp != end; ++tmp) {
                        if (tmp->params().startOfAppendix()) {
-                               setUndo(bv, Undo::EDIT, &*tmp, &*boost::next(tmp));
+                               setUndo(bv, Undo::EDIT, tmp, boost::next(tmp));
                                tmp->params().startOfAppendix(false);
                                int tmpy;
-                               setHeightOfRow(getRow(&*tmp, 0, tmpy));
+                               setHeightOfRow(getRow(tmp, 0, tmpy));
                                break;
                        }
                }
 
-               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();
@@ -460,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);
@@ -883,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;
@@ -917,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);
@@ -1132,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) {
@@ -1191,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, "\""));
@@ -1288,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();
@@ -1405,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());