]> git.lyx.org Git - lyx.git/blobdiff - src/Paragraph.cpp
Some comments.
[lyx.git] / src / Paragraph.cpp
index 1d9330ce66346f595e6ab71bbb27154c3bcffbb2..44164943c529c6d7e677b7456c4fd58604d861f6 100644 (file)
@@ -19,7 +19,7 @@
 
 #include "Paragraph.h"
 
-#include "BaseClassList.h"
+#include "LayoutFile.h"
 #include "Buffer.h"
 #include "BufferParams.h"
 #include "Changes.h"
@@ -49,6 +49,7 @@
 #include "insets/InsetBibitem.h"
 #include "insets/InsetLabel.h"
 
+#include "support/assert.h"
 #include "support/convert.h"
 #include "support/debug.h"
 #include "support/gettext.h"
@@ -190,13 +191,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 +201,6 @@ public:
        typedef std::set<docstring> Words;
        ///
        Words words_;
-private:
        ///
        Layout const * layout_;
 };
@@ -256,8 +249,8 @@ Paragraph::Private::Private(Private const & p, Paragraph * owner)
 
 bool Paragraph::isChanged(pos_type start, pos_type end) const
 {
-       BOOST_ASSERT(start >= 0 && start <= size());
-       BOOST_ASSERT(end > start && end <= size() + 1);
+       LASSERT(start >= 0 && start <= size(), /**/);
+       LASSERT(end > start && end <= size() + 1, /**/);
 
        return d->changes_.isChanged(start, end);
 }
@@ -302,7 +295,7 @@ void Paragraph::setChange(Change const & change)
 
 void Paragraph::setChange(pos_type pos, Change const & change)
 {
-       BOOST_ASSERT(pos >= 0 && pos <= size());
+       LASSERT(pos >= 0 && pos <= size(), /**/);
        d->changes_.set(change, pos);
 
        // see comment in setChange(Change const &) above
@@ -314,7 +307,7 @@ void Paragraph::setChange(pos_type pos, Change const & change)
 
 Change const & Paragraph::lookupChange(pos_type pos) const
 {
-       BOOST_ASSERT(pos >= 0 && pos <= size());
+       LASSERT(pos >= 0 && pos <= size(), /**/);
        return d->changes_.lookup(pos);
 }
 
@@ -322,8 +315,8 @@ Change const & Paragraph::lookupChange(pos_type pos) const
 void Paragraph::acceptChanges(BufferParams const & bparams, pos_type start,
                pos_type end)
 {
-       BOOST_ASSERT(start >= 0 && start <= size());
-       BOOST_ASSERT(end > start && end <= size() + 1);
+       LASSERT(start >= 0 && start <= size(), /**/);
+       LASSERT(end > start && end <= size() + 1, /**/);
 
        for (pos_type pos = start; pos < end; ++pos) {
                switch (lookupChange(pos).type) {
@@ -358,8 +351,8 @@ void Paragraph::acceptChanges(BufferParams const & bparams, pos_type start,
 void Paragraph::rejectChanges(BufferParams const & bparams,
                pos_type start, pos_type end)
 {
-       BOOST_ASSERT(start >= 0 && start <= size());
-       BOOST_ASSERT(end > start && end <= size() + 1);
+       LASSERT(start >= 0 && start <= size(), /**/);
+       LASSERT(end > start && end <= size() + 1, /**/);
 
        for (pos_type pos = start; pos < end; ++pos) {
                switch (lookupChange(pos).type) {
@@ -394,7 +387,7 @@ void Paragraph::rejectChanges(BufferParams const & bparams,
 void Paragraph::Private::insertChar(pos_type pos, char_type c,
                Change const & change)
 {
-       BOOST_ASSERT(pos >= 0 && pos <= int(text_.size()));
+       LASSERT(pos >= 0 && pos <= int(text_.size()), /**/);
 
        // track change
        changes_.insert(change, pos);
@@ -420,11 +413,11 @@ void Paragraph::Private::insertChar(pos_type pos, char_type c,
 void Paragraph::insertInset(pos_type pos, Inset * inset,
                                   Change const & change)
 {
-       BOOST_ASSERT(inset);
-       BOOST_ASSERT(pos >= 0 && pos <= size());
+       LASSERT(inset, /**/);
+       LASSERT(pos >= 0 && pos <= size(), /**/);
 
        d->insertChar(pos, META_INSET, change);
-       BOOST_ASSERT(d->text_[pos] == META_INSET);
+       LASSERT(d->text_[pos] == META_INSET, /**/);
 
        // Add a new entry in the insetlist_.
        d->insetlist_.insert(inset, pos);
@@ -433,7 +426,7 @@ void Paragraph::insertInset(pos_type pos, Inset * inset,
 
 bool Paragraph::eraseChar(pos_type pos, bool trackChanges)
 {
-       BOOST_ASSERT(pos >= 0 && pos <= size());
+       LASSERT(pos >= 0 && pos <= size(), /**/);
 
        // keep the logic here in sync with the logic of isMergedOnEndOfParDeletion()
 
@@ -482,8 +475,8 @@ bool Paragraph::eraseChar(pos_type pos, bool trackChanges)
 
 int Paragraph::eraseChars(pos_type start, pos_type end, bool trackChanges)
 {
-       BOOST_ASSERT(start >= 0 && start <= size());
-       BOOST_ASSERT(end >= start && end <= size() + 1);
+       LASSERT(start >= 0 && start <= size(), /**/);
+       LASSERT(end >= start && end <= size() + 1, /**/);
 
        pos_type i = start;
        for (pos_type count = end - start; count; --count) {
@@ -655,7 +648,7 @@ void Paragraph::Private::latexInset(
                                             unsigned int & column)
 {
        Inset * inset = owner_->getInset(i);
-       BOOST_ASSERT(inset);
+       LASSERT(inset, /**/);
 
        if (style.pass_thru) {
                inset->plaintext(os, runparams);
@@ -1103,7 +1096,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);
 
@@ -1170,8 +1163,7 @@ void Paragraph::write(ostream & os, BufferParams const & bparams,
                        if (c != '\0')
                                os << to_utf8(docstring(1, c));
                        else
-                               lyxerr << "ERROR (Paragraph::writeFile):"
-                                       " NULL char in structure." << endl;
+                               LYXERR0("NUL char in structure.");
                        ++column;
                        break;
                }
@@ -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_);
 }
 
 
@@ -1281,8 +1273,8 @@ Font const Paragraph::getFontSettings(BufferParams const & bparams,
                                         pos_type pos) const
 {
        if (pos > size()) {
-               lyxerr << " pos: " << pos << " size: " << size() << endl;
-               BOOST_ASSERT(pos <= size());
+               LYXERR0("pos: " << pos << " size: " << size());
+               LASSERT(pos <= size(), /**/);
        }
 
        FontList::const_iterator cit = d->fontlist_.fontIterator(pos);
@@ -1298,7 +1290,7 @@ Font const Paragraph::getFontSettings(BufferParams const & bparams,
 
 FontSpan Paragraph::fontSpan(pos_type pos) const
 {
-       BOOST_ASSERT(pos <= size());
+       LASSERT(pos <= size(), /**/);
        pos_type start = 0;
 
        FontList::const_iterator cit = d->fontlist_.begin();
@@ -1317,8 +1309,7 @@ FontSpan Paragraph::fontSpan(pos_type pos) const
        }
 
        // This should not happen, but if so, we take no chances.
-       //lyxerr << "Paragraph::getEndPosOfFontSpan: This should not happen!"
-       //      << endl;
+       // LYXERR0("Paragraph::getEndPosOfFontSpan: This should not happen!");
        return FontSpan(pos, pos);
 }
 
@@ -1341,15 +1332,15 @@ Font const Paragraph::getFirstFontSettings(BufferParams const & bparams) const
 Font const Paragraph::getFont(BufferParams const & bparams, pos_type pos,
                                 Font const & outerfont) const
 {
-       BOOST_ASSERT(pos >= 0);
+       LASSERT(pos >= 0, /**/);
 
        Font font = getFontSettings(bparams, 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 +1352,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 +1362,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));
@@ -1386,8 +1377,7 @@ FontSize Paragraph::highestFontInRange
 }
 
 
-char_type
-Paragraph::getUChar(BufferParams const & bparams, pos_type pos) const
+char_type Paragraph::getUChar(BufferParams const & bparams, pos_type pos) const
 {
        char_type c = d->text_[pos];
        if (!lyxrc.rtl_support)
@@ -1422,14 +1412,13 @@ Paragraph::getUChar(BufferParams const & bparams, pos_type pos) const
        }
        if (uc != c && getFontSettings(bparams, pos).isRightToLeft())
                return uc;
-       else
-               return c;
+       return c;
 }
 
 
 void Paragraph::setFont(pos_type pos, Font const & font)
 {
-       BOOST_ASSERT(pos <= size());
+       LASSERT(pos <= size(), /**/);
 
        // First, reduce font against layout/label font
        // Update: The setCharFont() routine in text2.cpp already
@@ -1441,7 +1430,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 +1456,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 +1469,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 +1479,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 +1494,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 +1559,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 +1578,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 +1613,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 +1828,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 +2173,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 +2222,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 +2342,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 +2387,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 +2395,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 +2403,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 +2411,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 +2419,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 +2448,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()
@@ -2753,7 +2749,7 @@ void Paragraph::registerWords()
 
 void Paragraph::updateWords(CursorSlice const & sl)
 {
-       BOOST_ASSERT(&sl.paragraph() == this);
+       LASSERT(&sl.paragraph() == this, /**/);
        deregisterWords();
        collectWords(sl);
        registerWords();