]> git.lyx.org Git - lyx.git/blobdiff - src/Paragraph.cpp
Allow using \binom without amsmath and add support for \brace and \brack
[lyx.git] / src / Paragraph.cpp
index 1d9330ce66346f595e6ab71bbb27154c3bcffbb2..ce45db9bfe55362dfee95898a107a57fb253eb88 100644 (file)
@@ -19,7 +19,7 @@
 
 #include "Paragraph.h"
 
-#include "BaseClassList.h"
+#include "LayoutFile.h"
 #include "Buffer.h"
 #include "BufferParams.h"
 #include "Changes.h"
@@ -190,13 +190,6 @@ public:
        ///
        InsetList insetlist_;
 
-       // This little bit of indirection is needed so that we can protect
-       // the layout as const but still be able to change layout_.
-       ///
-       Layout const & layout() const { return *layout_; }
-       ///
-       void setLayout(Layout const & layout) { layout_ = &layout; }
-
        /// end of label
        pos_type begin_of_body_;
 
@@ -207,7 +200,6 @@ public:
        typedef std::set<docstring> Words;
        ///
        Words words_;
-private:
        ///
        Layout const * layout_;
 };
@@ -1103,7 +1095,7 @@ void Paragraph::write(ostream & os, BufferParams const & bparams,
        }
 
        // First write the layout
-       os << "\n\\begin_layout " << to_utf8(d->layout().name()) << '\n';
+       os << "\n\\begin_layout " << to_utf8(d->layout_->name()) << '\n';
 
        d->params_.write(os);
 
@@ -1183,7 +1175,7 @@ void Paragraph::write(ostream & os, BufferParams const & bparams,
 
 void Paragraph::validate(LaTeXFeatures & features) const
 {
-       d->validate(features, d->layout());
+       d->validate(features, *d->layout_);
 }
 
 
@@ -1347,9 +1339,9 @@ Font const Paragraph::getFont(BufferParams const & bparams, pos_type pos,
 
        pos_type const body_pos = beginOfBody();
        if (pos < body_pos)
-               font.fontInfo().realize(d->layout().labelfont);
+               font.fontInfo().realize(d->layout_->labelfont);
        else
-               font.fontInfo().realize(d->layout().font);
+               font.fontInfo().realize(d->layout_->font);
 
        font.fontInfo().realize(outerfont.fontInfo());
        font.fontInfo().realize(bparams.getFont().fontInfo());
@@ -1361,7 +1353,7 @@ Font const Paragraph::getFont(BufferParams const & bparams, pos_type pos,
 Font const Paragraph::getLabelFont
        (BufferParams const & bparams, Font const & outerfont) const
 {
-       FontInfo tmpfont = d->layout().labelfont;
+       FontInfo tmpfont = d->layout_->labelfont;
        tmpfont.realize(outerfont.fontInfo());
        tmpfont.realize(bparams.getFont().fontInfo());
        return Font(tmpfont, getParLanguage(bparams));
@@ -1371,7 +1363,7 @@ Font const Paragraph::getLabelFont
 Font const Paragraph::getLayoutFont
        (BufferParams const & bparams, Font const & outerfont) const
 {
-       FontInfo tmpfont = d->layout().font;
+       FontInfo tmpfont = d->layout_->font;
        tmpfont.realize(outerfont.fontInfo());
        tmpfont.realize(bparams.getFont().fontInfo());
        return Font(tmpfont, getParLanguage(bparams));
@@ -1441,7 +1433,7 @@ void Paragraph::setFont(pos_type pos, Font const & font)
 
 void Paragraph::makeSameLayout(Paragraph const & par)
 {
-       d->setLayout(par.d->layout());
+       d->layout_ = par.d->layout_;
        d->params_ = par.d->params_;
 }
 
@@ -1467,7 +1459,7 @@ bool Paragraph::stripLeadingSpaces(bool trackChanges)
 
 bool Paragraph::hasSameLayout(Paragraph const & par) const
 {
-       return par.d->layout() == d->layout()
+       return par.d->layout_ == d->layout_
                && d->params_.sameLayout(par.d->params_);
 }
 
@@ -1480,7 +1472,7 @@ depth_type Paragraph::getDepth() const
 
 depth_type Paragraph::getMaxDepthAfter() const
 {
-       if (d->layout().isEnvironment())
+       if (d->layout_->isEnvironment())
                return d->params_.depth() + 1;
        else
                return d->params_.depth();
@@ -1490,7 +1482,7 @@ depth_type Paragraph::getMaxDepthAfter() const
 char Paragraph::getAlign() const
 {
        if (d->params_.align() == LYX_ALIGN_LAYOUT)
-               return d->layout().align;
+               return d->layout_->align;
        else
                return d->params_.align();
 }
@@ -1505,7 +1497,7 @@ docstring const & Paragraph::labelString() const
 // the next two functions are for the manual labels
 docstring const Paragraph::getLabelWidthString() const
 {
-       if (d->layout().margintype == MARGIN_MANUAL)
+       if (d->layout_->margintype == MARGIN_MANUAL)
                return d->params_.labelWidthString();
        else
                return _("Senseless with this layout!");
@@ -1570,10 +1562,10 @@ docstring Paragraph::expandLabel(Layout const & layout,
 
 void Paragraph::applyLayout(Layout const & new_layout)
 {
-       d->setLayout(new_layout);
+       d->layout_ = &new_layout;
        LyXAlignment const oldAlign = d->params_.align();
        
-       if (!(oldAlign & d->layout().alignpossible)) {
+       if (!(oldAlign & d->layout_->alignpossible)) {
                frontend::Alert::warning(_("Alignment not permitted"), 
                        _("The new layout does not permit the alignment previously used.\nSetting to default."));
                d->params_.align(LYX_ALIGN_LAYOUT);
@@ -1589,7 +1581,7 @@ pos_type Paragraph::beginOfBody() const
 
 void Paragraph::setBeginOfBody()
 {
-       if (d->layout().labeltype != LABEL_MANUAL) {
+       if (d->layout_->labeltype != LABEL_MANUAL) {
                d->begin_of_body_ = 0;
                return;
        }
@@ -1624,19 +1616,28 @@ void Paragraph::setBeginOfBody()
 
 bool Paragraph::forceEmptyLayout() const
 {
-       return inInset() && inInset()->forceEmptyLayout();
+       Inset const * const inset = inInset();
+       if (!inset)
+               return true;
+       return inset->forceEmptyLayout();
 }
 
 
 bool Paragraph::allowParagraphCustomization() const
 {
-       return inInset() && inInset()->allowParagraphCustomization(0);
+       Inset const * const inset = inInset();
+       if (!inset)
+               return true;
+       return inset->allowParagraphCustomization();
 }
 
 
 bool Paragraph::useEmptyLayout() const
 {
-       return inInset() && inInset()->useEmptyLayout();
+       Inset const * const inset = inInset();
+       if (!inset)
+               return false;
+       return inset->useEmptyLayout();
 }
 
 
@@ -1830,14 +1831,11 @@ bool Paragraph::latex(BufferParams const & bparams,
 
        bool return_value = false;
 
-       Layout style;
-
        bool asdefault = forceEmptyLayout();
 
-       if (asdefault)
-               style = bparams.documentClass().emptyLayout();
-        else
-               style = d->layout();
+       Layout const & style = asdefault ?
+               bparams.documentClass().emptyLayout() :
+               *d->layout_;
 
        // Current base font for all inherited font changes, without any
        // change caused by an individual character, except for the language:
@@ -2178,7 +2176,7 @@ void Paragraph::simpleDocBookOnePar(Buffer const & buf,
 {
        bool emph_flag = false;
 
-       Layout const & style = d->layout();
+       Layout const & style = *d->layout_;
        FontInfo font_old =
                style.labeltype == LABEL_MANUAL ? style.labelfont : style.font;
 
@@ -2227,7 +2225,8 @@ void Paragraph::simpleDocBookOnePar(Buffer const & buf,
 bool Paragraph::isHfill(pos_type pos) const
 {
        Inset const * inset = getInset(pos);
-       return inset && inset->lyxCode() == HFILL_CODE;
+       return inset && (inset->lyxCode() == SPACE_CODE &&
+                        inset->isStretchableSpace());
 }
 
 
@@ -2346,13 +2345,13 @@ int Paragraph::id() const
 
 Layout const & Paragraph::layout() const
 {
-       return d->layout();
+       return *d->layout_;
 }
 
 
 void Paragraph::setLayout(Layout const & layout)
 {
-       d->setLayout(layout);
+       d->layout_ = &layout;
 }
 
 
@@ -2391,7 +2390,7 @@ ParagraphParameters const & Paragraph::params() const
 
 bool Paragraph::isFreeSpacing() const
 {
-       if (d->layout().free_spacing)
+       if (d->layout_->free_spacing)
                return true;
        return d->inset_owner_ && d->inset_owner_->isFreeSpacing();
 }
@@ -2399,7 +2398,7 @@ bool Paragraph::isFreeSpacing() const
 
 bool Paragraph::allowEmpty() const
 {
-       if (d->layout().keepempty)
+       if (d->layout_->keepempty)
                return true;
        return d->inset_owner_ && d->inset_owner_->allowEmpty();
 }
@@ -2407,7 +2406,7 @@ bool Paragraph::allowEmpty() const
 
 char_type Paragraph::transformChar(char_type c, pos_type pos) const
 {
-       if (!Encodings::is_arabic(c))
+       if (!Encodings::isArabicChar(c))
                return c;
 
        char_type prev_char = ' ';
@@ -2415,7 +2414,7 @@ char_type Paragraph::transformChar(char_type c, pos_type pos) const
 
        for (pos_type i = pos - 1; i >= 0; --i) {
                char_type const par_char = d->text_[i];
-               if (!Encodings::isComposeChar_arabic(par_char)) {
+               if (!Encodings::isArabicComposeChar(par_char)) {
                        prev_char = par_char;
                        break;
                }
@@ -2423,21 +2422,21 @@ char_type Paragraph::transformChar(char_type c, pos_type pos) const
 
        for (pos_type i = pos + 1, end = size(); i < end; ++i) {
                char_type const par_char = d->text_[i];
-               if (!Encodings::isComposeChar_arabic(par_char)) {
+               if (!Encodings::isArabicComposeChar(par_char)) {
                        next_char = par_char;
                        break;
                }
        }
 
-       if (Encodings::is_arabic(next_char)) {
-               if (Encodings::is_arabic(prev_char) &&
-                       !Encodings::is_arabic_special(prev_char))
+       if (Encodings::isArabicChar(next_char)) {
+               if (Encodings::isArabicChar(prev_char) &&
+                       !Encodings::isArabicSpecialChar(prev_char))
                        return Encodings::transformChar(c, Encodings::FORM_MEDIAL);
                else
                        return Encodings::transformChar(c, Encodings::FORM_INITIAL);
        } else {
-               if (Encodings::is_arabic(prev_char) &&
-                       !Encodings::is_arabic_special(prev_char))
+               if (Encodings::isArabicChar(prev_char) &&
+                       !Encodings::isArabicSpecialChar(prev_char))
                        return Encodings::transformChar(c, Encodings::FORM_FINAL);
                else
                        return Encodings::transformChar(c, Encodings::FORM_ISOLATED);
@@ -2452,7 +2451,7 @@ int Paragraph::checkBiblio(Buffer const & buffer)
        // up this bibitem issue for 1.6. See also bug 2743.
 
        // Add bibitem insets if necessary
-       if (d->layout().labeltype != LABEL_BIBLIO)
+       if (d->layout_->labeltype != LABEL_BIBLIO)
                return 0;
 
        bool hasbibitem = !d->insetlist_.empty()