]> git.lyx.org Git - lyx.git/blobdiff - src/paragraph_funcs.cpp
fix a couple warnings after the number localization patch
[lyx.git] / src / paragraph_funcs.cpp
index 46d4c17a01354d83216ab63cc31cb717b2ca8d9f..0d626e3d64f11dac0cbebadce2aee3d76a7a3092 100644 (file)
@@ -3,7 +3,7 @@
  * This file is part of LyX, the document processor.
  * Licence details can be found in the file COPYING.
  *
- * \author Lars Gullik Bjønnes
+ * \author Lars Gullik Bjønnes
  *
  * Full author contact details are available in file CREDITS.
  */
@@ -14,7 +14,6 @@
 
 #include "BufferParams.h"
 #include "Changes.h"
-#include "debug.h"
 #include "InsetList.h"
 #include "Layout.h"
 #include "Paragraph.h"
 #include "Text.h"
 #include "TextClass.h"
 
+#include "support/debug.h"
+
+#include "support/lassert.h"
 #include <boost/next_prior.hpp>
 
+using namespace std;
 
 namespace lyx {
 
-using std::endl;
-
-
 static bool moveItem(Paragraph & fromPar, pos_type fromPos,
        Paragraph & toPar, pos_type toPos, BufferParams const & params)
 {
        // Note: moveItem() does not honour change tracking!
        // Therefore, it should only be used for breaking and merging paragraphs
 
-       char_type const tmpChar = fromPar.getChar(fromPos);
+       // We need a copy here because the character at fromPos is going to be erased.
        Font const tmpFont = fromPar.getFontSettings(params, fromPos);
        Change const tmpChange = fromPar.lookupChange(fromPos);
 
-       if (fromPar.isInset(fromPos)) {
-               Inset * tmpInset = 0;
-               if (fromPar.getInset(fromPos)) {
-                       // the inset is not in the paragraph any more
-                       tmpInset = fromPar.releaseInset(fromPos);
-               }
-
-               if (!toPar.insetAllowed(tmpInset->lyxCode())) {
+       if (Inset * tmpInset = fromPar.getInset(fromPos)) {
+               fromPar.releaseInset(fromPos);
+               // The inset is not in fromPar any more.
+               if (!toPar.insertInset(toPos, tmpInset, tmpFont, tmpChange)) {
                        delete tmpInset;
                        return false;
                }
-
-               toPar.insertInset(toPos, tmpInset, tmpFont, tmpChange);
-       } else {
-               fromPar.eraseChar(fromPos, false);
-               toPar.insertChar(toPos, tmpChar, tmpFont, tmpChange);
+               return true;
        }
 
+       char_type const tmpChar = fromPar.getChar(fromPos);
+       fromPar.eraseChar(fromPos, false);
+       toPar.insertChar(toPos, tmpChar, tmpFont, tmpChange);
        return true;
 }
 
@@ -73,20 +68,20 @@ void breakParagraph(BufferParams const & bparams,
 
        Paragraph & par = pars[par_offset];
 
+       // remember to set the inset_owner
+       tmp->setInsetOwner(&par.inInset());
        // without doing that we get a crash when typing <Return> at the
        // end of a paragraph
-       tmp->layout(bparams.getTextClass().defaultLayout());
-       // remember to set the inset_owner
-       tmp->setInsetOwner(par.inInset());
+       tmp->setPlainOrDefaultLayout(bparams.documentClass());
 
        // layout stays the same with latex-environments
        if (keep_layout) {
-               tmp->layout(par.layout());
+               tmp->setLayout(par.layout());
                tmp->setLabelWidthString(par.params().labelWidthString());
                tmp->params().depth(par.params().depth());
        } else if (par.params().depth() > 0) {
                Paragraph const & hook = pars[outerHook(par_offset, pars)];
-               tmp->layout(hook.layout());
+               tmp->setLayout(hook.layout());
                // not sure the line below is useful
                tmp->setLabelWidthString(par.params().labelWidthString());
                tmp->params().depth(hook.params().depth());
@@ -95,7 +90,7 @@ void breakParagraph(BufferParams const & bparams,
        bool const isempty = (par.allowEmpty() && par.empty());
 
        if (!isempty && (par.size() > pos || par.empty())) {
-               tmp->layout(par.layout());
+               tmp->setLayout(par.layout());
                tmp->params().align(par.params().align());
                tmp->setLabelWidthString(par.params().labelWidthString());
 
@@ -129,7 +124,7 @@ void breakParagraph(BufferParams const & bparams,
                // breaking paragraph.
                if (tmp->empty()) {
                        Font changed = tmp->getFirstFontSettings(bparams);
-                       Font old = par.getFontSettings(bparams, par.size());
+                       Font const & old = par.getFontSettings(bparams, par.size());
                        changed.setLanguage(old.language());
                        tmp->setFont(0, changed);
                }
@@ -142,12 +137,12 @@ void breakParagraph(BufferParams const & bparams,
                par.params().clear();
                // do not lose start of appendix marker (bug 4212)
                par.params().startOfAppendix(soa);
-               par.layout(bparams.getTextClass().defaultLayout());
+               par.setPlainOrDefaultLayout(bparams.documentClass());
        }
 
        // layout stays the same with latex-environments
        if (keep_layout) {
-               par.layout(tmp->layout());
+               par.setLayout(tmp->layout());
                par.setLabelWidthString(tmp->params().labelWidthString());
                par.params().depth(tmp->params().depth());
        }
@@ -162,9 +157,10 @@ void breakParagraphConservative(BufferParams const & bparams,
                                       Paragraph());
        Paragraph & par = pars[par_offset];
 
+       tmp.setInsetOwner(&par.inInset());
        tmp.makeSameLayout(par);
 
-       BOOST_ASSERT(pos <= par.size());
+       LASSERT(pos <= par.size(), /**/);
 
        if (pos < par.size()) {
                // move everything behind the break position to the new paragraph
@@ -260,13 +256,40 @@ bool isFirstInSequence(pit_type par_offset, ParagraphList const & pars)
 }
 
 
+void setLabelWidthStringToSequence(pit_type par_offset,
+       ParagraphList & pars, docstring const & s)
+{
+       Paragraph & par = pars[par_offset];
+       // Find first of same layout in sequence
+       while (!isFirstInSequence(par_offset, pars)) {
+               par_offset = depthHook(par_offset, pars, par.getDepth());
+               par = pars[par_offset];
+       }
+
+       // now apply label width string to every par
+       // in sequence
+       pit_type const end = pars.size();
+       depth_type const depth = par.getDepth();
+       Layout const & layout = par.layout();
+       for (pit_type pit = par_offset; pit != end; ++pit) {
+               while (pars[pit].getDepth() > depth)
+                       ++pit;
+               if (pars[pit].getDepth() < depth)
+                       return;
+               if (pars[pit].layout() != layout)
+                       return;
+               pars[pit].setLabelWidthString(s);
+       }
+}
+
+
 int getEndLabel(pit_type p, ParagraphList const & pars)
 {
        pit_type pit = p;
        depth_type par_depth = pars[p].getDepth();
        while (pit != pit_type(pars.size())) {
-               LayoutPtr const & layout = pars[pit].layout();
-               int const endlabeltype = layout->endlabeltype;
+               Layout const & layout = pars[pit].layout();
+               int const endlabeltype = layout.endlabeltype;
 
                if (endlabeltype != END_LABEL_NO_LABEL) {
                        if (p + 1 == pit_type(pars.size()))
@@ -300,7 +323,7 @@ Font const outerFont(pit_type par_offset, ParagraphList const & pars)
               && !tmpfont.resolved()) {
                par_offset = outerHook(par_offset, pars);
                if (par_offset != pit_type(pars.size())) {
-                       tmpfont.realize(pars[par_offset].layout()->font);
+                       tmpfont.realize(pars[par_offset].layout().font);
                        par_depth = pars[par_offset].getDepth();
                }
        }
@@ -309,6 +332,20 @@ Font const outerFont(pit_type par_offset, ParagraphList const & pars)
 }
 
 
+bool isFullyDeleted(ParagraphList const & pars)
+{
+       pit_type const pars_size = static_cast<pit_type>(pars.size());
+
+       // check all paragraphs
+       for (pit_type pit = 0; pit < pars_size; ++pit) {
+               if (!pars[pit].empty())   // prevent assertion failure
+                       if (!pars[pit].isFullyDeleted(0, pars[pit].size()))
+                               return false;
+       }
+       return true;
+}
+
+
 void acceptChanges(ParagraphList & pars, BufferParams const & bparams)
 {
        pit_type pars_size = static_cast<pit_type>(pars.size());