]> git.lyx.org Git - lyx.git/blobdiff - src/Text.cpp
* Call metrics of the parameters with the correct font in MathMacros, for example
[lyx.git] / src / Text.cpp
index c9bb7e3b563c5e0af33fdfab50455511c0b455ab..f6b676b57deb7b6d29fb3edd95776c6a41251552 100644 (file)
@@ -102,29 +102,24 @@ void readParToken(Buffer const & buf, Paragraph & par, Lexer & lex,
                if (layoutname.empty())
                        layoutname = tclass.defaultLayoutName();
 
-               if (par.forceEmptyLayout()) {
+               if (par.forcePlainLayout()) {
                        // in this case only the empty layout is allowed
-                       layoutname = tclass.emptyLayoutName();
-               } else if (par.useEmptyLayout()) {
+                       layoutname = tclass.plainLayoutName();
+               } else if (par.usePlainLayout()) {
                        // in this case, default layout maps to empty layout 
                        if (layoutname == tclass.defaultLayoutName())
-                               layoutname = tclass.emptyLayoutName();
+                               layoutname = tclass.plainLayoutName();
                } else { 
                        // otherwise, the empty layout maps to the default
-                       if (layoutname == tclass.emptyLayoutName())
+                       if (layoutname == tclass.plainLayoutName())
                                layoutname = tclass.defaultLayoutName();
                }
 
-               bool hasLayout = tclass.hasLayout(layoutname);
-
-               if (!hasLayout) {
-                       errorList.push_back(ErrorItem(_("Unknown layout"),
-                       bformat(_("Layout '%1$s' does not exist in textclass '%2$s'\nTrying to use the default instead.\n"),
-                       layoutname, from_utf8(tclass.name())), par.id(), 0, par.size()));
-                       layoutname = par.useEmptyLayout() ? 
-                                       tclass.emptyLayoutName() :
-                                       tclass.defaultLayoutName();
-               }
+               // When we apply an unknown layout to a document, we add this layout to the textclass
+               // of this document. For example, when you apply class article to a beamer document,
+               // all unknown layouts such as frame will be added to document class article so that
+               // these layouts can keep their original names.
+               tclass.addLayoutIfNeeded(layoutname);
 
                par.setLayout(bp.documentClass()[layoutname]);
 
@@ -207,7 +202,7 @@ void readParToken(Buffer const & buf, Paragraph & par, Lexer & lex,
        } else if (token == "\\backslash") {
                par.appendChar('\\', font, change);
        } else if (token == "\\LyXTable") {
-               auto_ptr<Inset> inset(new InsetTabular(buf));
+               auto_ptr<Inset> inset(new InsetTabular(const_cast<Buffer &>(buf)));
                inset->read(lex);
                par.insertInset(par.size(), inset.release(), font, change);
        } else if (token == "\\lyxline") {
@@ -387,11 +382,11 @@ void Text::breakParagraph(Cursor & cur, bool inverse_logic)
        if (sensitive) {
                if (cur.pos() == 0)
                        // set to standard-layout
-               //FIXME Check if this should be emptyLayout() in some cases
+               //FIXME Check if this should be plainLayout() in some cases
                        pars_[cpit].applyLayout(tclass.defaultLayout());
                else
                        // set to standard-layout
-                       //FIXME Check if this should be emptyLayout() in some cases
+                       //FIXME Check if this should be plainLayout() in some cases
                        pars_[next_par].applyLayout(tclass.defaultLayout());
        }
 
@@ -589,19 +584,38 @@ bool Text::cursorForwardOneWord(Cursor & cur)
        pos_type pos = cur.pos();
        Paragraph const & par = cur.paragraph();
 
-       // Skip over either a non-char inset or a full word
-       if (pos != lastpos && !par.isLetter(pos) && !par.isChar(pos))
-               ++pos;
-       else while (pos != lastpos && par.isLetter(pos))
-                       ++pos;
+       // Paragraph boundary is a word boundary
+       if (pos == lastpos) {
+               if (pit != cur.lastpit())
+                       return setCursor(cur, pit + 1, 0);
+               else
+                       return false;
+       }
+
+       if (lyxrc.mac_like_word_movement) {
+               // Skip through trailing punctuation and spaces.
+               while (pos != lastpos && (par.isChar(pos) || par.isSpace(pos)))
+                        ++pos;
 
-       // Skip through trailing punctuation and spaces.
-       while (pos != lastpos && par.isChar(pos))
-               ++pos;
+               // Skip over either a non-char inset or a full word
+               if (pos != lastpos && !par.isLetter(pos))
+                       ++pos;
+               else while (pos != lastpos && par.isLetter(pos))
+                            ++pos;
+       } else {
+               LASSERT(pos < lastpos, /**/); // see above
+               if (par.isLetter(pos))
+                       while (pos != lastpos && par.isLetter(pos))
+                               ++pos;
+               else if (par.isChar(pos))
+                       while (pos != lastpos && par.isChar(pos))
+                               ++pos;
+               else if (!par.isSpace(pos)) // non-char inset
+                       ++pos;
 
-       if (pos == lastpos && pit != cur.lastpit()) {
-               ++pit;
-               pos = 0;
+               // Skip over white space
+               while (pos != lastpos && par.isSpace(pos))
+                            ++pos;             
        }
 
        return setCursor(cur, pit, pos);
@@ -616,19 +630,33 @@ bool Text::cursorBackwardOneWord(Cursor & cur)
        pos_type pos = cur.pos();
        Paragraph & par = cur.paragraph();
 
-       // Skip through puctuation and spaces.
-       while (pos != 0 && par.isChar(pos - 1))
-               --pos;
+       // Paragraph boundary is a word boundary
+       if (pos == 0 && pit != 0)
+               return setCursor(cur, pit - 1, getPar(pit - 1).size());
 
-       // Skip over either a non-char inset or a full word
-       if (pos != 0 && !par.isLetter(pos) && !par.isChar(pos - 1))
-               --pos;
-       else while (pos != 0 && par.isLetter(pos - 1))
+       if (lyxrc.mac_like_word_movement) {
+               // Skip through punctuation and spaces.
+               while (pos != 0 && (par.isChar(pos - 1) || par.isSpace(pos - 1)))
                        --pos;
 
-       if (pos == 0 && pit != 0) {
-               --pit;
-               pos = getPar(cur.pit() - 1).size();
+               // Skip over either a non-char inset or a full word
+               if (pos != 0 && !par.isLetter(pos - 1) && !par.isChar(pos - 1))
+                       --pos;
+               else while (pos != 0 && par.isLetter(pos - 1))
+                            --pos;
+       } else {
+               // Skip over white space
+               while (pos != 0 && par.isSpace(pos - 1))
+                            --pos;
+
+               if (pos != 0 && par.isLetter(pos - 1))
+                       while (pos != 0 && par.isLetter(pos - 1))
+                               --pos;
+               else if (pos != 0 && par.isChar(pos - 1))
+                       while (pos != 0 && par.isChar(pos - 1))
+                               --pos;
+               else if (pos != 0 && !par.isSpace(pos - 1)) // non-char inset
+                       --pos;
        }
 
        return setCursor(cur, pit, pos);
@@ -894,7 +922,7 @@ void Text::deleteWordForward(Cursor & cur)
                cursorForward(cur);
        else {
                cur.resetAnchor();
-               cur.selection() = true;
+               cur.setSelection(true);
                cursorForwardOneWord(cur);
                cur.setSelection();
                cutSelection(cur, true, false);
@@ -910,7 +938,7 @@ void Text::deleteWordBackward(Cursor & cur)
                cursorBackward(cur);
        else {
                cur.resetAnchor();
-               cur.selection() = true;
+               cur.setSelection(true);
                cursorBackwardOneWord(cur);
                cur.setSelection();
                cutSelection(cur, true, false);
@@ -997,7 +1025,7 @@ bool Text::handleBibitems(Cursor & cur)
        } 
 
        // otherwise reset to default
-       cur.paragraph().setEmptyOrDefaultLayout(bufparams.documentClass());
+       cur.paragraph().setPlainOrDefaultLayout(bufparams.documentClass());
        return true;
 }
 
@@ -1087,7 +1115,7 @@ bool Text::backspacePos0(Cursor & cur)
        // or the empty layout.
        else if (par.layout() == prevpar.layout()
                 || tclass.isDefaultLayout(par.layout())
-                || tclass.isEmptyLayout(par.layout())) {
+                || tclass.isPlainLayout(par.layout())) {
                cur.recordUndo(ATOMIC_UNDO, prevcur.pit());
                mergeParagraph(bufparams, plist, prevcur.pit());
                needsUpdate = true;
@@ -1152,14 +1180,15 @@ bool Text::backspace(Cursor & cur)
 }
 
 
-bool Text::dissolveInset(Cursor & cur) {
-       LASSERT(this == cur.text(), /**/);
+bool Text::dissolveInset(Cursor & cur)
+{
+       LASSERT(this == cur.text(), return false);
 
        if (isMainText(cur.bv().buffer()) || cur.inset().nargs() != 1)
                return false;
 
        cur.recordUndoInset();
-       cur.mark() = false;
+       cur.setMark(false);
        cur.selHandle(false);
        // save position
        pos_type spos = cur.pos();
@@ -1276,9 +1305,9 @@ bool Text::read(Buffer const & buf, Lexer & lex,
                        lex.pushToken(token);
 
                        Paragraph par;
+                       par.setInsetOwner(insetPtr);
                        par.params().depth(depth);
                        par.setFont(0, Font(inherit_font, buf.params().language));
-                       par.setInsetOwner(insetPtr);
                        pars_.push_back(par);
 
                        // FIXME: goddamn InsetTabular makes us pass a Buffer
@@ -1304,7 +1333,7 @@ bool Text::read(Buffer const & buf, Lexer & lex,
 }
 
 // Returns the current font and depth as a message.
-docstring Text::currentState(Cursor & cur)
+docstring Text::currentState(Cursor const & cur) const
 {
        LASSERT(this == cur.text(), /**/);
        Buffer & buf = cur.buffer();
@@ -1383,7 +1412,7 @@ docstring Text::currentState(Cursor & cur)
 }
 
 
-docstring Text::getPossibleLabel(Cursor & cur) const
+docstring Text::getPossibleLabel(Cursor const & cur) const
 {
        pit_type pit = cur.pit();
 
@@ -1460,6 +1489,25 @@ docstring Text::getPossibleLabel(Cursor & cur) const
 }
 
 
+docstring Text::asString(int options) const
+{
+       return asString(0, pars_.size(), options);
+}
+
+
+docstring Text::asString(pit_type beg, pit_type end, int options) const
+{
+       size_t i = size_t(beg);
+       docstring str = pars_[i].asString(options);
+       for (++i; i != size_t(end); ++i) {
+               str += '\n';
+               str += pars_[i].asString(options);
+       }
+       return str;
+}
+
+
+
 void Text::charsTranspose(Cursor & cur)
 {
        LASSERT(this == cur.text(), /**/);