]> git.lyx.org Git - features.git/commitdiff
Use new display() values to remove some inset hardcoding. betterbreak
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Tue, 22 Mar 2016 15:53:25 +0000 (16:53 +0100)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Thu, 18 Jun 2020 13:48:57 +0000 (15:48 +0200)
The enum is now made of flags that can be combined.

This introduces several new values for Inset::DisplayType:
BreakBefore, BreakAfter and Display=BreakBefore|BreakAfter. This
last value replaces AlignCenter.

Additionally the flags NoBoundary and CanBreakAfter are introduced for
future use.

Now a left aligned displayed inset will be defined as Display|LeftAlign.

A newline inset is characterized as BreakAfter.

This structure is used in breakRow to avoid explicit calls to
isNewline() or isEnvSeparator(). More improvements will be built on
top of this.

Additionally several redundant display() methods (which returned
Inline) have been removed.

21 files changed:
src/TextMetrics.cpp
src/insets/Inset.h
src/insets/InsetBibtex.h
src/insets/InsetBox.h
src/insets/InsetCaption.h
src/insets/InsetFloatList.h
src/insets/InsetInclude.cpp
src/insets/InsetIndex.h
src/insets/InsetListings.cpp
src/insets/InsetNewline.h
src/insets/InsetNewpage.h
src/insets/InsetNomencl.h
src/insets/InsetNote.cpp
src/insets/InsetNote.h
src/insets/InsetRef.h
src/insets/InsetScript.cpp
src/insets/InsetSeparator.h
src/insets/InsetTOC.h
src/insets/InsetTabular.cpp
src/insets/InsetVSpace.h
src/mathed/InsetMathHull.cpp

index c92af02184c5721d821d45806fadc779a4fab9ca..c0556ee2584e481aeab909308f4b26d137f2a21e 100644 (file)
@@ -622,19 +622,13 @@ LyXAlignment TextMetrics::getAlign(Paragraph const & par, Row const & row) const
 
        // Display-style insets should always be on a centered row
        if (Inset const * inset = par.getInset(row.pos())) {
-               switch (inset->display()) {
-               case Inset::AlignLeft:
-                       align = LYX_ALIGN_BLOCK;
-                       break;
-               case Inset::AlignCenter:
-                       align = LYX_ALIGN_CENTER;
-                       break;
-               case Inset::Inline:
-                       // unchanged (use align)
-                       break;
-               case Inset::AlignRight:
-                       align = LYX_ALIGN_RIGHT;
-                       break;
+               if (inset->display() & Inset::Display) {
+                       if (inset->display() & Inset::AlignLeft)
+                               align = LYX_ALIGN_BLOCK;
+                       else if (inset->display() & Inset::AlignRight)
+                               align = LYX_ALIGN_RIGHT;
+                       else
+                               align = LYX_ALIGN_CENTER;
                }
        }
 
@@ -976,15 +970,12 @@ bool TextMetrics::breakRow(Row & row, int const right_margin) const
                }
 
                // Handle some situations that abruptly terminate the row
-               // - A newline inset
-               // - Before a display inset
-               // - After a display inset
-               Inset const * inset = 0;
-               if (par.isNewline(i) || par.isEnvSeparator(i)
-                   || (i + 1 < end && (inset = par.getInset(i + 1))
-                       && inset->display())
-                   || (!row.empty() && row.back().inset
-                       && row.back().inset->display())) {
+               // - Before an inset with BreakBefore
+               // - After an inset with BreakAfter
+               Inset const * prevInset = !row.empty() ? row.back().inset : 0;
+               Inset const * nextInset = (i + 1 < end) ? par.getInset(i + 1) : 0;
+               if ((nextInset && nextInset->display() & Inset::BreakBefore)
+                   || (prevInset && prevInset->display() & Inset::BreakAfter)) {
                        row.flushed(true);
                        // We will force a row creation after either
                        // - a newline;
@@ -1774,7 +1765,7 @@ int TextMetrics::leftMargin(pit_type const pit, pos_type const pos) const
            // display style insets are always centered, omit indentation
            && !(!par.empty()
                 && par.isInset(pos)
-                && par.getInset(pos)->display())
+                && par.getInset(pos)->display() & Inset::Display)
            && (!(tclass.isDefaultLayout(par.layout())
                || tclass.isPlainLayout(par.layout()))
                || buffer.params().paragraph_separation
index 457ff44cb916095218ec24ea255853c888268206..c5acc6800c14808134f3d9cde52c0015de9c8fec 100644 (file)
@@ -487,12 +487,23 @@ public:
 
        enum DisplayType {
                Inline = 0,
-               AlignLeft,
-               AlignCenter,
-               AlignRight
+               // break row before this inset
+               BreakBefore = 1,
+               // break row after this inset
+               BreakAfter = 2,
+               // optionally break row after this inset (not used yet)
+               CanBreakAfter = 4,
+               // specify an alignment (left, right) for a display inset (default is center)
+               AlignLeft = 8,
+               AlignRight = 16,
+               // do not allow cursor to go at the end of the row before
+               // a display inset (not used yet)
+               NoBoundary = 32,
+               // A display inset breaks row at both ends
+               Display = BreakBefore | BreakAfter
        };
 
-       /// should we have a non-filled line before this inset?
+       /// How should this inset be typeset?
        virtual DisplayType display() const { return Inline; }
        /// indentation before this inset (only needed for displayed hull insets with fleqn option)
        virtual int indent(BufferView const &) const { return 0; }
@@ -652,6 +663,21 @@ protected:
        Buffer * buffer_;
 };
 
+
+inline Inset::DisplayType operator|(Inset::DisplayType const d1,
+                                    Inset::DisplayType const d2)
+{
+       return static_cast<Inset::DisplayType>(int(d1) | int(d2));
+}
+
+
+inline Inset::DisplayType operator&(Inset::DisplayType const d1,
+                                    Inset::DisplayType const d2)
+{
+       return static_cast<Inset::DisplayType>(int(d1) & int(d2));
+}
+
+
 } // namespace lyx
 
 #endif
index a46619367bc4df2ab02f826f64ead6c8331d9939..70319c5ff3c12e8fd39535e6b31a41fba3f1dd5e 100644 (file)
@@ -48,7 +48,7 @@ public:
        ///
        InsetCode lyxCode() const { return BIBTEX_CODE; }
        ///
-       DisplayType display() const { return AlignCenter; }
+       DisplayType display() const { return Display; }
        ///
        void latex(otexstream &, OutputParams const &) const;
        ///
index 6dd671c9a4deaad01b8e0c1d7dc685a4b9e03c5f..50a8ea25685e1463e843dd71e91ef0dbd7aced0e 100644 (file)
@@ -111,8 +111,6 @@ public:
        ///
        void metrics(MetricsInfo &, Dimension &) const;
        ///
-       DisplayType display() const { return Inline; }
-       ///
        ColorCode backgroundColor(PainterInfo const &) const;
        ///
        LyXAlignment contentAlignment() const;
index a651a71a5641be5e9dfcd3e0df51be982dba31b7..faacadadf7ede995caed99b3df819e268c479fee 100644 (file)
@@ -38,7 +38,7 @@ private:
        ///
        void write(std::ostream & os) const;
        ///
-       DisplayType display() const { return AlignCenter; }
+       DisplayType display() const { return Display; }
        ///
        bool neverIndent() const { return true; }
        ///
index 7d1df4765aa015fa1a4dda8d02aef84744078016..eabd7ceed47273ca71f1c954f564204bb1695a27 100644 (file)
@@ -32,7 +32,7 @@ public:
        ///
        InsetCode lyxCode() const { return FLOAT_LIST_CODE; }
        ///
-       DisplayType display() const { return AlignCenter; }
+       DisplayType display() const { return Display; }
        ///
        void write(std::ostream &) const;
        ///
index 6dca350078518ccf827e8a69d95dfce314e70eec..305927f28a823fe92ea1bbc3fb406e0069997fd9 100644 (file)
@@ -1228,7 +1228,7 @@ string InsetInclude::contextMenuName() const
 
 Inset::DisplayType InsetInclude::display() const
 {
-       return type(params()) == INPUT ? Inline : AlignCenter;
+       return type(params()) == INPUT ? Inline : Display;
 }
 
 
index 504eb84720a860b6107ec8634c5dc1c3cc04b8fa..93007e92a960bee0e77d41bc3d6b8a782665de20 100644 (file)
@@ -119,7 +119,7 @@ public:
        ///
        bool hasSettings() const;
        ///
-       DisplayType display() const { return AlignCenter; }
+       DisplayType display() const { return Display; }
        //@}
 
        /// \name Static public methods obligated for InsetCommand derived classes
index f2af5813bd625e30bde7c0729fb8476526a491d8..c421b467c976b7c3ad9a8f4fe680e5b46af41ad6 100644 (file)
@@ -68,7 +68,7 @@ InsetListings::~InsetListings()
 
 Inset::DisplayType InsetListings::display() const
 {
-       return params().isInline() || params().isFloat() ? Inline : AlignLeft;
+       return params().isInline() || params().isFloat() ? Inline : Display | AlignLeft;
 }
 
 
index e0a13f38d415172d62f489973b5f5d9732058ece..472006322e08c88141b8f0429aa56f499b898939 100644 (file)
@@ -47,6 +47,8 @@ public:
        explicit InsetNewline(InsetNewlineParams par) : Inset(0)
        { params_.kind = par.kind; }
        ///
+       DisplayType display() const { return BreakAfter | NoBoundary; }
+       ///
        static void string2params(std::string const &, InsetNewlineParams &);
        ///
        static std::string params2string(InsetNewlineParams const &);
index 4a7d60d0103d7c09f0e9442f703c1cfcdc8e5d65..2a2772405fd46c3f3684cd73d1ef5b064e10fd11 100644 (file)
@@ -74,7 +74,7 @@ private:
        ///
        void write(std::ostream & os) const;
        ///
-       DisplayType display() const { return AlignCenter; }
+       DisplayType display() const { return Display; }
        ///
        docstring insetLabel() const;
        ///
index 4d11a47d793c0bfd7f99f442558440dc300053d0..b5a4e9315c64f087432b94f66bcb7df7f8d2cd9b 100644 (file)
@@ -100,7 +100,7 @@ public:
        ///
        bool hasSettings() const { return true; }
        ///
-       DisplayType display() const { return AlignCenter; }
+       DisplayType display() const { return Display; }
        ///
        void latex(otexstream &, OutputParams const &) const;
        ///
index 9f4c5ed1d0349b130c81a6bf214db737b183bd1a..868ff83e2ce6de0c675f274cf389411eb8c2c892 100644 (file)
@@ -116,12 +116,6 @@ docstring InsetNote::layoutName() const
 }
 
 
-Inset::DisplayType InsetNote::display() const
-{
-       return Inline;
-}
-
-
 void InsetNote::write(ostream & os) const
 {
        params_.write(os);
index 9df1a501a29c75ba12c7ebc3c8f13517f7f4d3c4..5c99df19092913f5fd499f928245dab99501ad5a 100644 (file)
@@ -61,8 +61,6 @@ private:
        InsetCode lyxCode() const { return NOTE_CODE; }
        ///
        docstring layoutName() const;
-       ///
-       DisplayType display() const;
        /** returns false if, when outputing LaTeX, font changes should
            be closed before generating this inset. This is needed for
            insets that may contain several paragraphs */
index 8683ecf9899b9de82de088c70ee3164c31d4cb41..b595e4130aa0ed80e0a8375ad9a3fc7c8fbb28e4 100644 (file)
@@ -56,8 +56,6 @@ public:
        ///
        InsetCode lyxCode() const { return REF_CODE; }
        ///
-       DisplayType display() const { return Inline; }
-       ///
        void latex(otexstream &, OutputParams const &) const;
        ///
        int plaintext(odocstringstream & ods, OutputParams const & op,
index f87f6c474765f4a6b6888b442f8580cb69f4dbc8..13b67e16e149371e0f0dddca22e03f9e50c6d93c 100644 (file)
@@ -151,12 +151,6 @@ docstring InsetScript::layoutName() const
 }
 
 
-Inset::DisplayType InsetScript::display() const
-{
-       return Inline;
-}
-
-
 void InsetScript::metrics(MetricsInfo & mi, Dimension & dim) const
 {
        int const shift = params_.shift(mi.base.font);
index 2d256d6bee1b5593976f459e3aead29c35cd31aa..e9701ad78b2780277798932803fe8e8eba775422 100644 (file)
@@ -64,6 +64,8 @@ public:
                // remove warning
                return docstring();
        }
+       ///
+       DisplayType display() const { return BreakAfter | NoBoundary; }
 private:
        ///
        InsetCode lyxCode() const { return SEPARATOR_CODE; }
index 4d48c3220f5ce40acf031689966539ca7290e3c0..29d5e91e76d4c2fc76ccbb748fd6218c523d8c8c 100644 (file)
@@ -37,7 +37,7 @@ public:
        ///
        docstring layoutName() const;
        ///
-       DisplayType display() const { return AlignCenter; }
+       DisplayType display() const { return Display; }
        ///
        virtual void validate(LaTeXFeatures &) const;
        ///
index dc8be284b2955f496545febcdf1979e51986e08d..e8de0705cdbdd5fe2c7cc158d4f442ccfbdb9ba3 100644 (file)
@@ -5972,13 +5972,13 @@ Inset::DisplayType InsetTabular::display() const
                if (tabular.is_long_tabular) {
                        switch (tabular.longtabular_alignment) {
                        case Tabular::LYX_LONGTABULAR_ALIGN_LEFT:
-                               return AlignLeft;
+                               return Display | AlignLeft;
                        case Tabular::LYX_LONGTABULAR_ALIGN_CENTER:
-                               return AlignCenter;
+                               return Display;
                        case Tabular::LYX_LONGTABULAR_ALIGN_RIGHT:
-                               return AlignRight;
+                               return Display | AlignRight;
                        default:
-                               return AlignCenter;
+                               return Display;
                        }
                } else
                        return Inline;
index b2c8ac9780bb799af576770e4ece9bff7fdc3dc9..aadffb0003ed43ee17768f938c5ad55563337ea4 100644 (file)
@@ -62,7 +62,7 @@ private:
        ///
        void write(std::ostream & os) const;
        ///
-       DisplayType display() const { return AlignCenter; }
+       DisplayType display() const { return Display; }
        ///
        void doDispatch(Cursor & cur, FuncRequest & cmd);
        ///
index 7754e4dcd639d087649d09832bec69ccd84ba03d..496a5414bb5554f4fcbf1a51fc2b027f2ab2de20 100644 (file)
@@ -536,7 +536,7 @@ void InsetMathHull::metrics(MetricsInfo & mi, Dimension & dim) const
                        // insert a gap in front of the formula
                        // value was hardcoded to 1 pixel
                        dim.wid += mi.base.bv->zoomedPixels(1) ;
-                       if (display()) {
+                       if (display() != Inline) {
                                dim.asc += display_margin;
                                dim.des += display_margin;
                        }
@@ -546,7 +546,7 @@ void InsetMathHull::metrics(MetricsInfo & mi, Dimension & dim) const
 
        {
                Changer dummy1 = mi.base.changeFontSet(standardFont());
-               Changer dummy2 = mi.base.font.changeStyle(display() ? DISPLAY_STYLE
+               Changer dummy2 = mi.base.font.changeStyle(display() != Inline ? DISPLAY_STYLE
                                                                                                  : TEXT_STYLE);
 
                // let the cells adjust themselves
@@ -691,7 +691,7 @@ void InsetMathHull::draw(PainterInfo & pi, int x, int y) const
 
        // Then the equations
        Changer dummy1 = pi.base.changeFontSet(standardFont());
-       Changer dummy2 = pi.base.font.changeStyle(display() ? DISPLAY_STYLE
+       Changer dummy2 = pi.base.font.changeStyle(display() != Inline ? DISPLAY_STYLE
                                                            : TEXT_STYLE);
        InsetMathGrid::draw(pi, x + 1, y);
        drawMarkers(pi, x, y);
@@ -699,7 +699,7 @@ void InsetMathHull::draw(PainterInfo & pi, int x, int y) const
        // drawing change line
        if (canPaintChange(*bv)) {
                // like in metrics()
-               int const display_margin = display() ? pi.base.inPixels(Length(12, Length::PT)) : 0;
+               int const display_margin = display() != Inline ? pi.base.inPixels(Length(12, Length::PT)) : 0;
                pi.change.paintCue(pi, x + 1, y + 1 - dim.asc + display_margin,
                                    x + dim.wid, y + dim.des - display_margin);
        }
@@ -708,7 +708,7 @@ void InsetMathHull::draw(PainterInfo & pi, int x, int y) const
 
 void InsetMathHull::metricsT(TextMetricsInfo const & mi, Dimension & dim) const
 {
-       if (display()) {
+       if (display() != Inline) {
                InsetMathGrid::metricsT(mi, dim);
        } else {
                odocstringstream os;
@@ -724,7 +724,7 @@ void InsetMathHull::metricsT(TextMetricsInfo const & mi, Dimension & dim) const
 
 void InsetMathHull::drawT(TextPainter & pain, int x, int y) const
 {
-       if (display()) {
+       if (display() != Inline) {
                InsetMathGrid::drawT(pain, x, y);
        } else {
                odocstringstream os;
@@ -1035,12 +1035,12 @@ Inset::DisplayType InsetMathHull::display() const
        case hullMultline:
        case hullGather:
                if (buffer().params().is_math_indent)
-                       return AlignLeft;
+                       return Display | AlignLeft;
                else
-                       return AlignCenter;
+                       return Display;
        }
        // avoid warning
-       return AlignCenter;
+       return Display;
 }
 
 
@@ -2368,7 +2368,7 @@ int InsetMathHull::plaintext(odocstringstream & os,
         OutputParams const & op, size_t max_length) const
 {
        // Try enabling this now that there is a flag as requested at #2275.
-       if (buffer().isExporting() && display()) {
+       if (buffer().isExporting() && display() != Inline) {
                Dimension dim;
                TextMetricsInfo mi;
                metricsT(mi, dim);