]> git.lyx.org Git - lyx.git/blobdiff - src/Text.cpp
Fix shaded box UI color (#7395) as good as it gets ATM
[lyx.git] / src / Text.cpp
index 3cf1de49043f8fbb213201231caf6f3ded573af6..390b69d7146da96eaf30dcf704caf07011df7fd7 100644 (file)
 #include "insets/InsetNewline.h"
 #include "insets/InsetNewpage.h"
 #include "insets/InsetArgument.h"
+#include "insets/InsetIPAMacro.h"
 #include "insets/InsetSpace.h"
 #include "insets/InsetSpecialChar.h"
 #include "insets/InsetTabular.h"
 
+#include "support/convert.h"
 #include "support/debug.h"
 #include "support/docstream.h"
 #include "support/gettext.h"
 
 #include <boost/next_prior.hpp>
 
+#include <limits>
 #include <sstream>
 
+
+// TODO: replace if in Text::readParToken() with compile time switch
+#if 0
+
+#include "support/metahash.h"
+
+typedef boost::mpl::string<'\\end','_lay','out'> end_layout;
+typedef boost::mpl::string<'\\end','in','set'>   end_inset;
+
+void foo()
+{
+       std::string token = "\\end_layout";
+
+       switch (boost::hash_value(token)) {
+               case lyx::support::hash_string<end_layout>::value:
+                       return;
+               case lyx::support::hash_string<end_inset>::value:
+                       return;
+               default: ;
+       };
+
+}
+#endif
+
+
 using namespace std;
 using namespace lyx::support;
 
@@ -241,11 +269,13 @@ Font const Text::outerFont(pit_type par_offset) const
 {
        depth_type par_depth = pars_[par_offset].getDepth();
        FontInfo tmpfont = inherit_font;
-
+       depth_type prev_par_depth = 0;
        // Resolve against environment font information
        while (par_offset != pit_type(pars_.size())
+              && par_depth != prev_par_depth
               && par_depth
               && !tmpfont.resolved()) {
+               prev_par_depth = par_depth;
                par_offset = outerHook(par_offset);
                if (par_offset != pit_type(pars_.size())) {
                        tmpfont.realize(pars_[par_offset].layout().font);
@@ -316,6 +346,7 @@ InsetText const & Text::inset() const
 }
 
 
+
 void Text::readParToken(Paragraph & par, Lexer & lex,
        string const & token, Font & font, Change & change, ErrorList & errorList)
 {
@@ -450,6 +481,12 @@ void Text::readParToken(Paragraph & par, Lexer & lex,
                inset->read(lex);
                inset->setBuffer(*buf);
                par.insertInset(par.size(), inset.release(), font, change);
+       } else if (token == "\\IPAChar") {
+               auto_ptr<Inset> inset;
+               inset.reset(new InsetIPAChar);
+               inset->read(lex);
+               inset->setBuffer(*buf);
+               par.insertInset(par.size(), inset.release(), font, change);
        } else if (token == "\\backslash") {
                par.appendChar('\\', font, change);
        } else if (token == "\\LyXTable") {
@@ -695,8 +732,7 @@ void Text::breakParagraph(Cursor & cur, bool inverse_logic)
                return;
        }
 
-       // a layout change may affect also the following paragraph
-       recUndo(cur, cur.pit(), undoSpan(cur.pit()) - 1);
+       cur.recordUndo();
 
        // Always break behind a space
        // It is better to erase the space (Dekel)
@@ -1667,7 +1703,7 @@ bool Text::dissolveInset(Cursor & cur)
                // change it to the buffer language.
                ParagraphList::iterator it = plist.begin();
                ParagraphList::iterator it_end = plist.end();
-               for (; it != it_end; it++)
+               for (; it != it_end; ++it)
                        it->changeLanguage(b.params(), latex_language, b.language());
 
                pasteParagraphList(cur, plist, b.params().documentClassPtr(),
@@ -1776,6 +1812,7 @@ bool Text::read(Lexer & lex,
        return res;
 }
 
+
 // Returns the current font and depth as a message.
 docstring Text::currentState(Cursor const & cur) const
 {
@@ -1920,7 +1957,15 @@ docstring Text::getPossibleLabel(Cursor const & cur) const
        if (!name.empty())
                text = name + ':' + text;
 
-       return text;
+       // We need a unique label
+       docstring label = text;
+       int i = 1;
+       while (cur.buffer()->insetLabel(label)) {
+                       label = text + '-' + convert<docstring>(i);
+                       ++i;
+               }
+
+       return label;
 }
 
 
@@ -1944,7 +1989,10 @@ docstring Text::asString(pit_type beg, pit_type end, int options) const
 
 void Text::forToc(docstring & os, size_t maxlen, bool shorten) const
 {
-       LASSERT(maxlen > 10, maxlen = 30);
+       if (maxlen == 0)
+               maxlen = std::numeric_limits<std::size_t>::max();
+       else
+               LASSERT(maxlen >= 8, maxlen = TOC_ENTRY_LENGTH);
        for (size_t i = 0; i != pars_.size() && os.length() < maxlen; ++i)
                pars_[i].forToc(os, maxlen);
        if (shorten && os.length() >= maxlen)