]> git.lyx.org Git - lyx.git/blobdiff - src/Text2.cpp
Routines for calculating numerical labels for BibTeX citations.
[lyx.git] / src / Text2.cpp
index 5eedf4f3078bcf079c0844e8ec7924c8f8596f01..974f9a89a1ab1241a048ae63e2457a109b7aebdf 100644 (file)
@@ -40,7 +40,6 @@
 #include "LyXFunc.h"
 #include "LyXRC.h"
 #include "Paragraph.h"
-#include "paragraph_funcs.h"
 #include "ParagraphParameters.h"
 #include "TextClass.h"
 #include "TextMetrics.h"
@@ -85,7 +84,7 @@ FontInfo Text::layoutFont(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.
-               InsetCollapsable const * icp = pars_[pit].inInset().asInsetCollapsable();
+               InsetCollapsable const * icp = owner_->asInsetCollapsable();
                if (!icp)
                        return lf;
                FontInfo icf = icp->getLayout().font();
@@ -95,7 +94,7 @@ FontInfo Text::layoutFont(pit_type const pit) const
 
        FontInfo font = layout.font;
        // Realize with the fonts of lesser depth.
-       //font.realize(outerFont(pit, paragraphs()));
+       //font.realize(outerFont(pit));
        font.realize(owner_->buffer().params().getFont().fontInfo());
 
        return font;
@@ -145,7 +144,7 @@ void Text::setCharFont(pit_type pit,
                while (!layoutfont.resolved() &&
                       tp != pit_type(paragraphs().size()) &&
                       pars_[tp].getDepth()) {
-                       tp = outerHook(tp, paragraphs());
+                       tp = outerHook(tp);
                        if (tp != pit_type(paragraphs().size()))
                                layoutfont.realize(pars_[tp].layout().font);
                }
@@ -432,6 +431,32 @@ docstring Text::getStringToIndex(Cursor const & cur)
 }
 
 
+void Text::setLabelWidthStringToSequence(pit_type const par_offset,
+               docstring const & s)
+{
+       pit_type offset = par_offset;
+       // Find first of same layout in sequence
+       while (!isFirstInSequence(offset)) {
+               offset = depthHook(offset, pars_[offset].getDepth());
+       }
+
+       // now apply label width string to every par
+       // in sequence
+       pit_type const end = pars_.size();
+       depth_type const depth = pars_[offset].getDepth();
+       Layout const & layout = pars_[offset].layout();
+       for (pit_type pit = 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);
+       }
+}
+
+
 void Text::setParagraphs(Cursor & cur, docstring arg, bool merge) 
 {
        LASSERT(cur.text(), /**/);
@@ -453,8 +478,7 @@ void Text::setParagraphs(Cursor & cur, docstring arg, bool merge)
                // Do this only once for a selected range of paragraphs
                // of the same layout and depth.
                if (par.getDepth() != priordepth || par.layout() != priorlayout)
-                       setLabelWidthStringToSequence(pit, pars_,
-                                       params.labelWidthString());
+                       setLabelWidthStringToSequence(pit, params.labelWidthString());
                par.params().apply(params, par.layout());
                priordepth = par.getDepth();
                priorlayout = par.layout();
@@ -482,8 +506,8 @@ void Text::setParagraphs(Cursor & cur, ParagraphParameters const & p)
                // Do this only once for a selected range of paragraphs
                // of the same layout and depth.
                if (par.getDepth() != priordepth || par.layout() != priorlayout)
-                       setLabelWidthStringToSequence(pit, pars_,
-                                       par.params().labelWidthString());
+                       setLabelWidthStringToSequence(pit,
+                               par.params().labelWidthString());
                par.params().apply(p, par.layout());
                priordepth = par.getDepth();
                priorlayout = par.layout();
@@ -502,85 +526,6 @@ void Text::insertInset(Cursor & cur, Inset * inset)
 }
 
 
-// needed to insert the selection
-void Text::insertStringAsLines(DocIterator const & dit, docstring const & str,
-               Font const & font)
-{
-       BufferParams const & bparams = owner_->buffer().params();
-       pit_type pit = dit.pit();
-       pos_type pos = dit.pos();
-
-       // insert the string, don't insert doublespace
-       bool space_inserted = true;
-       for (docstring::const_iterator cit = str.begin();
-           cit != str.end(); ++cit) {
-               Paragraph & par = pars_[pit];
-               if (*cit == '\n') {
-                       if (autoBreakRows_ && (!par.empty() || par.allowEmpty())) {
-                               lyx::breakParagraph(bparams, pars_, pit, pos,
-                                              par.layout().isEnvironment());
-                               ++pit;
-                               pos = 0;
-                               space_inserted = true;
-                       } else {
-                               continue;
-                       }
-                       // do not insert consecutive spaces if !free_spacing
-               } else if ((*cit == ' ' || *cit == '\t') &&
-                          space_inserted && !par.isFreeSpacing()) {
-                       continue;
-               } else if (*cit == '\t') {
-                       if (!par.isFreeSpacing()) {
-                               // tabs are like spaces here
-                               par.insertChar(pos, ' ', font, bparams.trackChanges);
-                               ++pos;
-                               space_inserted = true;
-                       } else {
-                               par.insertChar(pos, *cit, font, bparams.trackChanges);
-                               ++pos;
-                               space_inserted = true;
-                       }
-               } else if (!isPrintable(*cit)) {
-                       // Ignore unprintables
-                       continue;
-               } else {
-                       // just insert the character
-                       par.insertChar(pos, *cit, font, bparams.trackChanges);
-                       ++pos;
-                       space_inserted = (*cit == ' ');
-               }
-       }
-}
-
-
-// turn double CR to single CR, others are converted into one
-// blank. Then insertStringAsLines is called
-void Text::insertStringAsParagraphs(DocIterator const & dit, docstring const & str,
-               Font const & font)
-{
-       docstring linestr = str;
-       bool newline_inserted = false;
-
-       for (string::size_type i = 0, siz = linestr.size(); i < siz; ++i) {
-               if (linestr[i] == '\n') {
-                       if (newline_inserted) {
-                               // we know that \r will be ignored by
-                               // insertStringAsLines. Of course, it is a dirty
-                               // trick, but it works...
-                               linestr[i - 1] = '\r';
-                               linestr[i] = '\n';
-                       } else {
-                               linestr[i] = ' ';
-                               newline_inserted = true;
-                       }
-               } else if (isPrintable(linestr[i])) {
-                       newline_inserted = false;
-               }
-       }
-       insertStringAsLines(dit, linestr, font);
-}
-
-
 bool Text::setCursor(Cursor & cur, pit_type par, pos_type pos,
                        bool setfont, bool boundary)
 {
@@ -603,12 +548,12 @@ void Text::setCursor(CursorSlice & cur, pit_type par, pos_type pos)
 
        // None of these should happen, but we're scaredy-cats
        if (pos < 0) {
-               lyxerr << "dont like -1" << endl;
+               lyxerr << "don't like -1" << endl;
                LASSERT(false, /**/);
        }
 
        if (pos > para.size()) {
-               lyxerr << "dont like 1, pos: " << pos
+               lyxerr << "don't like 1, pos: " << pos
                       << " size: " << para.size()
                       << " par: " << par << endl;
                LASSERT(false, /**/);