]> git.lyx.org Git - features.git/commitdiff
Use isMainText() instead of doing explicit tests
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Sun, 28 Feb 2016 15:23:43 +0000 (16:23 +0100)
committerRichard Heck <rgheck@lyx.org>
Sun, 29 May 2016 21:55:45 +0000 (17:55 -0400)
src/TextMetrics.cpp
src/TextMetrics.h
src/insets/InsetText.cpp

index fdf0da692672c78798b2feb956187108df06c0b8..39eb2d441b4de05b945db46010ea838c61402519 100644 (file)
@@ -200,13 +200,13 @@ bool TextMetrics::metrics(MetricsInfo & mi, Dimension & dim, int min_width)
 
 int TextMetrics::rightMargin(ParagraphMetrics const & pm) const
 {
 
 int TextMetrics::rightMargin(ParagraphMetrics const & pm) const
 {
-       return main_text_? pm.rightMargin(*bv_) : 0;
+       return text_->isMainText() ? pm.rightMargin(*bv_) : 0;
 }
 
 
 int TextMetrics::rightMargin(pit_type const pit) const
 {
 }
 
 
 int TextMetrics::rightMargin(pit_type const pit) const
 {
-       return main_text_? par_metrics_[pit].rightMargin(*bv_) : 0;
+       return text_->isMainText() ? par_metrics_[pit].rightMargin(*bv_) : 0;
 }
 
 
 }
 
 
@@ -353,7 +353,6 @@ bool TextMetrics::redoParagraph(pit_type const pit)
        pm.reset(par);
 
        Buffer & buffer = bv_->buffer();
        pm.reset(par);
 
        Buffer & buffer = bv_->buffer();
-       main_text_ = (text_ == &buffer.text());
        bool changed = false;
 
        // Check whether there are InsetBibItems that need fixing
        bool changed = false;
 
        // Check whether there are InsetBibItems that need fixing
@@ -1087,7 +1086,7 @@ void TextMetrics::setRowHeight(Row & row, pit_type const pit,
        // following code in another method specially tailored for the
        // main Text. The following test is thus bogus.
        // Top and bottom margin of the document (only at top-level)
        // following code in another method specially tailored for the
        // main Text. The following test is thus bogus.
        // Top and bottom margin of the document (only at top-level)
-       if (main_text_ && topBottomSpace) {
+       if (text_->isMainText() && topBottomSpace) {
                if (pit == 0 && row.pos() == 0)
                        maxasc += 20;
                if (pit + 1 == pit_type(pars.size()) &&
                if (pit == 0 && row.pos() == 0)
                        maxasc += 20;
                if (pit + 1 == pit_type(pars.size()) &&
index 6f5cf687336514ca747e6d298f557d5812bd59ed..507213a5ab98f4679155e139b7800a041191a9a7 100644 (file)
@@ -35,7 +35,7 @@ class TextMetrics
 {
 public:
        /// Default constructor (only here for STL containers).
 {
 public:
        /// Default constructor (only here for STL containers).
-       TextMetrics() : bv_(0), text_(0), main_text_(false), max_width_(0) {}
+       TextMetrics() : bv_(0), text_(0), max_width_(0) {}
        /// The only useful constructor.
        TextMetrics(BufferView *, Text *);
 
        /// The only useful constructor.
        TextMetrics(BufferView *, Text *);
 
@@ -243,7 +243,6 @@ private:
        /// \todo FIXME: this should be const.
        Text * text_;
 
        /// \todo FIXME: this should be const.
        Text * text_;
 
-       bool main_text_;
        /// A map from paragraph index number to paragraph metrics
        typedef std::map<pit_type, ParagraphMetrics> ParMetricsCache;
        ///
        /// A map from paragraph index number to paragraph metrics
        typedef std::map<pit_type, ParagraphMetrics> ParMetricsCache;
        ///
index 660826309f33931a0121a51113a65a9c8a08c009..017e1445d09cdd6a6b5579c7ab83d055e0685ea5 100644 (file)
@@ -290,7 +290,7 @@ void InsetText::doDispatch(Cursor & cur, FuncRequest & cmd)
                break;
 
        case LFUN_INSET_DISSOLVE: {
                break;
 
        case LFUN_INSET_DISSOLVE: {
-               bool const main_inset = &buffer().inset() == this;
+               bool const main_inset = text_.isMainText();
                bool const target_inset = cmd.argument().empty() 
                        || cmd.getArg(0) == insetName(lyxCode());
                // cur.inset() is the tabular when this is a single cell (bug #9954)
                bool const target_inset = cmd.argument().empty() 
                        || cmd.getArg(0) == insetName(lyxCode());
                // cur.inset() is the tabular when this is a single cell (bug #9954)
@@ -323,7 +323,7 @@ bool InsetText::getStatus(Cursor & cur, FuncRequest const & cmd,
 {
        switch (cmd.action()) {
        case LFUN_INSET_DISSOLVE: {
 {
        switch (cmd.action()) {
        case LFUN_INSET_DISSOLVE: {
-               bool const main_inset = &buffer().inset() == this;
+               bool const main_inset = text_.isMainText();
                bool const target_inset = cmd.argument().empty() 
                        || cmd.getArg(0) == insetName(lyxCode());
                // cur.inset() is the tabular when this is a single cell (bug #9954)
                bool const target_inset = cmd.argument().empty() 
                        || cmd.getArg(0) == insetName(lyxCode());
                // cur.inset() is the tabular when this is a single cell (bug #9954)
@@ -340,7 +340,7 @@ bool InsetText::getStatus(Cursor & cur, FuncRequest const & cmd,
                        status.setEnabled(false);
                        return true;
                }
                        status.setEnabled(false);
                        return true;
                }
-               if (&buffer().inset() == this || !cur.paragraph().layout().args().empty())
+               if (text_.isMainText() || !cur.paragraph().layout().args().empty())
                        return text_.getStatus(cur, cmd, status);
 
                Layout::LaTeXArgMap args = getLayout().args();
                        return text_.getStatus(cur, cmd, status);
 
                Layout::LaTeXArgMap args = getLayout().args();