]> git.lyx.org Git - lyx.git/blobdiff - src/Text2.cpp
Fix compilation on win
[lyx.git] / src / Text2.cpp
index 65c08044c2160156ffdaabadfa3b7b3e77ba8266..9da71eb76eaa9eb7ee149b7587989150a47be2c0 100644 (file)
@@ -4,16 +4,16 @@
  * Licence details can be found in the file COPYING.
  *
  * \author Asger Alstrup
- * \author Lars Gullik Bjønnes
+ * \author Lars Gullik Bjønnes
  * \author Alfredo Braunstein
  * \author Jean-Marc Lasgouttes
  * \author Angus Leeming
  * \author John Levon
- * \author André Pönitz
+ * \author André Pönitz
  * \author Allan Rae
  * \author Stefan Schimanski
  * \author Dekel Tsur
- * \author Jürgen Vigna
+ * \author Jürgen Vigna
  *
  * Full author contact details are available in file CREDITS.
  */
@@ -90,8 +90,7 @@ FontInfo Text::layoutFont(Buffer const & buffer, pit_type const pit) const
                // now, because Inset::getLayout() will return a default-constructed
                // InsetLayout, and that e.g. sets the foreground color to red. So we
                // need to do some work to make that possible.
-               Inset const * inset = pars_[pit].inInset();
-               InsetCollapsable const * icp = inset? inset->asInsetCollapsable() : 0;
+               InsetCollapsable const * icp = pars_[pit].inInset().asInsetCollapsable();
                if (!icp)
                        return lf;
                FontInfo icf = icp->getLayout().font();
@@ -118,14 +117,7 @@ FontInfo Text::labelFont(Buffer const & buffer, Paragraph const & par) const
                // In case the default family has been customized
                if (layout.labelfont.family() == INHERIT_FAMILY)
                        lf.setFamily(buffer.params().getFont().fontInfo().family());
-               // FIXME As above....
-               Inset const * inset = par.inInset();
-               InsetCollapsable const * icp = inset? inset->asInsetCollapsable() : 0;
-               if (!icp)
-                       return lf;
-               FontInfo icf = icp->getLayout().labelfont();
-               icf.realize(lf);
-               return icf;
+               return lf;
        }
 
        FontInfo font = layout.labelfont;
@@ -199,7 +191,7 @@ void Text::setInsetFont(BufferView const & bv, pit_type pit,
 // return past-the-last paragraph influenced by a layout change on pit
 pit_type Text::undoSpan(pit_type pit)
 {
-       pit_type end = paragraphs().size();
+       pit_type const end = paragraphs().size();
        pit_type nextpit = pit + 1;
        if (nextpit == end)
                return nextpit;
@@ -242,8 +234,8 @@ void Text::setLayout(Cursor & cur, docstring const & layout)
        pit_type end = cur.selEnd().pit() + 1;
        pit_type undopit = undoSpan(end - 1);
        recUndo(cur, start, undopit - 1);
-       setLayout(cur.buffer(), start, end, layout);
-       updateLabels(cur.buffer());
+       setLayout(*cur.buffer(), start, end, layout);
+       cur.buffer()->updateLabels();
 }
 
 
@@ -302,7 +294,7 @@ void Text::changeDepth(Cursor & cur, DEPTH_CHANGE type)
        }
        // this handles the counter labels, and also fixes up
        // depth values for follow-on (child) paragraphs
-       updateLabels(cur.buffer());
+       cur.buffer()->updateLabels();
 }
 
 
@@ -314,13 +306,13 @@ void Text::setFont(Cursor & cur, Font const & font, bool toggleall)
        FontInfo layoutfont;
        pit_type pit = cur.pit();
        if (cur.pos() < pars_[pit].beginOfBody())
-               layoutfont = labelFont(cur.buffer(), pars_[pit]);
+               layoutfont = labelFont(*cur.buffer(), pars_[pit]);
        else
-               layoutfont = layoutFont(cur.buffer(), pit);
+               layoutfont = layoutFont(*cur.buffer(), pit);
 
        // Update current font
        cur.real_current_font.update(font,
-                                       cur.buffer().params().language,
+                                       cur.buffer()->params().language,
                                        toggleall);
 
        // Reduce to implicit settings
@@ -457,6 +449,10 @@ void Text::setParagraphs(Cursor & cur, docstring arg, bool merge)
                Paragraph & par = pars_[pit];
                ParagraphParameters params = par.params();
                params.read(argument, merge);
+               // changes to label width string apply to all
+               // paragraph with same layout in a sequence
+               setLabelWidthStringToSequence(pit, pars_,
+                               params.labelWidthString());
                par.params().apply(params, par.layout());
        }
 }
@@ -475,6 +471,10 @@ void Text::setParagraphs(Cursor & cur, ParagraphParameters const & p)
        for (pit_type pit = cur.selBegin().pit(), end = cur.selEnd().pit();
             pit <= end; ++pit) {
                Paragraph & par = pars_[pit];
+               // changes to label width string apply to all
+               // paragraph with same layout in a sequence
+               setLabelWidthStringToSequence(pit, pars_,
+                               par.params().labelWidthString());
                par.params().apply(p, par.layout());
        }       
 }
@@ -486,7 +486,7 @@ void Text::insertInset(Cursor & cur, Inset * inset)
        LASSERT(this == cur.text(), /**/);
        LASSERT(inset, /**/);
        cur.paragraph().insertInset(cur.pos(), inset, cur.current_font,
-               Change(cur.buffer().params().trackChanges
+               Change(cur.buffer()->params().trackChanges
                ? Change::INSERTED : Change::UNCHANGED));
 }
 
@@ -494,7 +494,7 @@ void Text::insertInset(Cursor & cur, Inset * inset)
 // needed to insert the selection
 void Text::insertStringAsLines(Cursor & cur, docstring const & str)
 {
-       cur.buffer().insertStringAsLines(pars_, cur.pit(), cur.pos(),
+       cur.buffer()->insertStringAsLines(pars_, cur.pit(), cur.pos(),
                cur.current_font, str, autoBreakRows_);
 }
 
@@ -581,7 +581,7 @@ bool Text::checkAndActivateInset(Cursor & cur, bool front)
        if (!front && cur.pos() == 0)
                return false;
        Inset * inset = front ? cur.nextInset() : cur.prevInset();
-       if (!inset || inset->editable() != Inset::HIGHLY_EDITABLE)
+       if (!inset || !inset->editable())
                return false;
        /*
         * Apparently, when entering an inset we are expected to be positioned
@@ -607,7 +607,7 @@ bool Text::checkAndActivateInsetVisual(Cursor & cur, bool movingForward, bool mo
                return false;
        Paragraph & par = cur.paragraph();
        Inset * inset = par.isInset(cur.pos()) ? par.getInset(cur.pos()) : 0;
-       if (!inset || inset->editable() != Inset::HIGHLY_EDITABLE)
+       if (!inset || !inset->editable())
                return false;
        inset->edit(cur, movingForward, 
                movingLeft ? Inset::ENTRY_DIRECTION_RIGHT : Inset::ENTRY_DIRECTION_LEFT);
@@ -810,10 +810,18 @@ bool Text::deleteEmptyParagraphMechanism(Cursor & cur,
        // delete the LineSeparator.
        // MISSING
 
-       bool const same_inset = &old.inset() == &cur.inset();
-       bool const same_par = same_inset && old.pit() == cur.pit();
-       bool const same_par_pos = same_par && old.pos() == cur.pos();
+       // Find a common inset and the corresponding depth.
+       size_t depth = 0;
+       for (; depth < cur.depth(); ++depth)
+               if (&old.inset() == &cur[depth].inset())
+                       break;
 
+       // Whether a common inset is found and whether the cursor is still in 
+       // the same paragraph (possibly nested).
+       bool const same_par = depth < cur.depth() && old.pit() == cur[depth].pit();
+       bool const same_par_pos = depth == cur.depth() - 1 && same_par 
+               && old.pos() == cur[depth].pos();
+       
        // If the chars around the old cursor were spaces, delete one of them.
        if (!same_par_pos) {
                // Only if the cursor has really moved.
@@ -823,14 +831,14 @@ bool Text::deleteEmptyParagraphMechanism(Cursor & cur,
                    && oldpar.isLineSeparator(old.pos() - 1)
                    && !oldpar.isDeleted(old.pos() - 1)
                    && !oldpar.isDeleted(old.pos())) {
-                       oldpar.eraseChar(old.pos() - 1, cur.buffer().params().trackChanges);
+                       oldpar.eraseChar(old.pos() - 1, cur.buffer()->params().trackChanges);
 // FIXME: This will not work anymore when we have multiple views of the same buffer
 // In this case, we will have to correct also the cursors held by
 // other bufferviews. It will probably be easier to do that in a more
 // automated way in CursorSlice code. (JMarc 26/09/2001)
                        // correct all cursor parts
                        if (same_par) {
-                               fixCursorAfterDelete(cur.top(), old.top());
+                               fixCursorAfterDelete(cur[depth], old.top());
                                need_anchor_change = true;
                        }
                        return true;
@@ -878,7 +886,7 @@ bool Text::deleteEmptyParagraphMechanism(Cursor & cur,
                return true;
        }
 
-       if (oldpar.stripLeadingSpaces(cur.buffer().params().trackChanges)) {
+       if (oldpar.stripLeadingSpaces(cur.buffer()->params().trackChanges)) {
                need_anchor_change = true;
                // We return true here because the Paragraph contents changed and
                // we need a redraw before further action is processed.