[Libreoffice-commits] core.git: include/svx svx/source

Noel Grandin (via logerrit) logerrit at kemper.freedesktop.org
Tue Aug 4 07:32:30 UTC 2020


 include/svx/framelink.hxx       |   86 +++++-----------
 svx/source/dialog/framelink.cxx |  212 ++++++++++------------------------------
 2 files changed, 82 insertions(+), 216 deletions(-)

New commits:
commit 58937aa4a50ecd681382f03331340da4c843b01e
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Mon Aug 3 18:38:58 2020 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Tue Aug 4 09:31:54 2020 +0200

    simplify svx::frame::Style
    
    no need to use shared_ptr here, this class is not doing copy-on-write.
    
    Change-Id: I4e921bfc789cc5989d98b5f9ab7074eb7d5ac33e
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/100022
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/include/svx/framelink.hxx b/include/svx/framelink.hxx
index 1af8abc6599b..b98ea5eab9aa 100644
--- a/include/svx/framelink.hxx
+++ b/include/svx/framelink.hxx
@@ -35,7 +35,7 @@ namespace svx::frame {
 
 /** Specifies how the reference points for frame borders are used.
  */
-enum class RefMode
+enum class RefMode : sal_uInt8
 {
     /** Frame borders are drawn centered to the reference points. */
     Centered,
@@ -100,45 +100,17 @@ enum class RefMode
 class SAL_WARN_UNUSED SVXCORE_DLLPUBLIC Style
 {
 private:
-    class implStyle
-    {
-    private:
-        friend class Style;
-
-        Color               maColorPrim;
-        Color               maColorSecn;
-        Color               maColorGap;
-        bool                mbUseGapColor;
-        RefMode             meRefMode;  /// Reference point handling for this frame border.
-        double              mfPrim;     /// Width of primary (single, left, or top) line.
-        double              mfDist;     /// Distance between primary and secondary line.
-        double              mfSecn;     /// Width of secondary (right or bottom) line.
-        double              mfPatternScale; /// Scale used for line pattern spacing.
-        SvxBorderLineStyle  mnType;
-        bool mbWordTableCell;
-
-    public:
-        /** Constructs an invisible frame style. */
-        explicit implStyle() :
-            maColorPrim(),
-            maColorSecn(),
-            maColorGap(),
-            mbUseGapColor(false),
-            meRefMode(RefMode::Centered),
-            mfPrim(0.0),
-            mfDist(0.0),
-            mfSecn(0.0),
-            mfPatternScale(1.0),
-            mnType(SvxBorderLineStyle::SOLID),
-            mbWordTableCell(false)
-        {}
-    };
-
-    /// the impl class holding the data
-    std::shared_ptr< implStyle >        maImplStyle;
-
-    /// call to set maImplStyle on demand
-    void implEnsureImplStyle();
+    Color               maColorPrim;
+    Color               maColorSecn;
+    Color               maColorGap;
+    double              mfPrim;     /// Width of primary (single, left, or top) line.
+    double              mfDist;     /// Distance between primary and secondary line.
+    double              mfSecn;     /// Width of secondary (right or bottom) line.
+    double              mfPatternScale; /// Scale used for line pattern spacing.
+    RefMode             meRefMode;  /// Reference point handling for this frame border.
+    SvxBorderLineStyle  mnType;
+    bool                mbWordTableCell : 1;
+    bool                mbUseGapColor : 1;
 
 public:
     /** Constructs an invisible frame style. */
@@ -150,23 +122,23 @@ public:
     /** Constructs a frame style from the passed SvxBorderLine struct. */
     explicit Style( const editeng::SvxBorderLine* pBorder, double fScale );
 
-    RefMode GetRefMode() const { if(!maImplStyle) return RefMode::Centered; return maImplStyle->meRefMode; }
-    Color GetColorPrim() const { if(!maImplStyle) return Color(); return maImplStyle->maColorPrim; }
-    Color GetColorSecn() const { if(!maImplStyle) return Color(); return maImplStyle->maColorSecn; }
-    Color GetColorGap() const { if(!maImplStyle) return Color(); return maImplStyle->maColorGap; }
-    bool UseGapColor() const { if(!maImplStyle) return false; return maImplStyle->mbUseGapColor; }
-    double Prim() const { if(!maImplStyle) return 0.0; return maImplStyle->mfPrim; }
-    double Dist() const { if(!maImplStyle) return 0.0; return maImplStyle->mfDist; }
-    double Secn() const { if(!maImplStyle) return 0.0; return maImplStyle->mfSecn; }
-    double PatternScale() const { if(!maImplStyle) return 1.0; return maImplStyle->mfPatternScale;}
-    SvxBorderLineStyle Type() const { if(!maImplStyle) return SvxBorderLineStyle::SOLID; return maImplStyle->mnType; }
+    RefMode GetRefMode() const { return meRefMode; }
+    Color GetColorPrim() const { return maColorPrim; }
+    Color GetColorSecn() const { return maColorSecn; }
+    Color GetColorGap() const { return maColorGap; }
+    bool UseGapColor() const { return mbUseGapColor; }
+    double Prim() const { return mfPrim; }
+    double Dist() const { return mfDist; }
+    double Secn() const { return mfSecn; }
+    double PatternScale() const { return mfPatternScale;}
+    SvxBorderLineStyle Type() const { return mnType; }
 
     /// Check if this style is used - this depends on it having any width definition.
     /// As can be seen in the definition comment above, Prim() *must* be non zero to have a width
-    bool IsUsed() const { if(!maImplStyle) return false; return 0.0 != maImplStyle->mfPrim; }
+    bool IsUsed() const { return 0.0 != mfPrim; }
 
     /** Returns the total width of this frame style. */
-    double GetWidth() const { if(!maImplStyle) return 0.0; implStyle* pTarget = maImplStyle.get(); return pTarget->mfPrim + pTarget->mfDist + pTarget->mfSecn; }
+    double GetWidth() const { return mfPrim + mfDist + mfSecn; }
 
     /** Sets the frame style to invisible state. */
     void Clear();
@@ -178,18 +150,18 @@ public:
     void Set( const editeng::SvxBorderLine* pBorder, double fScale, sal_uInt16 nMaxWidth = SAL_MAX_UINT16 );
 
     /** Sets a new reference point handling mode, does not modify other settings. */
-    void SetRefMode( RefMode eRefMode );
+    void SetRefMode( RefMode eRefMode ) { meRefMode = eRefMode; }
     /** Sets a new color, does not modify other settings. */
-    void SetColorPrim( const Color& rColor );
-    void SetColorSecn( const Color& rColor );
+    void SetColorPrim( const Color& rColor ) { maColorPrim = rColor; }
+    void SetColorSecn( const Color& rColor ) { maColorSecn = rColor; }
     /** Sets whether to use dotted style for single hair lines. */
-    void SetType( SvxBorderLineStyle nType );
+    void SetType( SvxBorderLineStyle nType ) { mnType = nType; }
 
     /** Mirrors this style (exchanges primary and secondary), if it is a double frame style. */
     Style& MirrorSelf();
 
     /** Enables the Word-compatible Style comparison code. */
-    void SetWordTableCell(bool bWordTableCell);
+    void SetWordTableCell(bool bWordTableCell) { mbWordTableCell = bWordTableCell; }
 
     bool operator==( const Style& rOther) const;
     bool operator<( const Style& rOther) const;
diff --git a/svx/source/dialog/framelink.cxx b/svx/source/dialog/framelink.cxx
index 62d60094b1e2..6400eb33d8b0 100644
--- a/svx/source/dialog/framelink.cxx
+++ b/svx/source/dialog/framelink.cxx
@@ -31,53 +31,50 @@ using namespace editeng;
 namespace svx::frame
 {
 
-// Classes
-void Style::implEnsureImplStyle()
-{
-    if(!maImplStyle)
-    {
-        maImplStyle = std::make_shared<implStyle>();
-    }
-}
-
-Style::Style() :
-    maImplStyle()
+Style::Style()
 {
+    Clear();
 }
 
-Style::Style( double nP, double nD, double nS, SvxBorderLineStyle nType, double fScale ) :
-    maImplStyle(std::make_shared<implStyle>())
+Style::Style( double nP, double nD, double nS, SvxBorderLineStyle nType, double fScale )
 {
-    maImplStyle->mnType = nType;
-    maImplStyle->mfPatternScale = fScale;
+    Clear();
+    mnType = nType;
+    mfPatternScale = fScale;
     Set( nP, nD, nS );
 }
 
-Style::Style( const Color& rColorPrim, const Color& rColorSecn, const Color& rColorGap, bool bUseGapColor, double nP, double nD, double nS, SvxBorderLineStyle nType, double fScale ) :
-    maImplStyle(std::make_shared<implStyle>())
+Style::Style( const Color& rColorPrim, const Color& rColorSecn, const Color& rColorGap, bool bUseGapColor, double nP, double nD, double nS, SvxBorderLineStyle nType, double fScale )
 {
-    maImplStyle->mnType = nType;
-    maImplStyle->mfPatternScale = fScale;
+    Clear();
+    mnType = nType;
+    mfPatternScale = fScale;
     Set( rColorPrim, rColorSecn, rColorGap, bUseGapColor, nP, nD, nS );
 }
 
-Style::Style( const editeng::SvxBorderLine* pBorder, double fScale ) :
-    maImplStyle()
+Style::Style( const editeng::SvxBorderLine* pBorder, double fScale )
 {
+    Clear();
     if(nullptr != pBorder)
     {
-        maImplStyle = std::make_shared<implStyle>();
-        maImplStyle->mfPatternScale = fScale;
+        mfPatternScale = fScale;
         Set( pBorder, fScale );
     }
 }
 
 void Style::Clear()
 {
-    if(maImplStyle)
-    {
-        maImplStyle.reset();
-    }
+    maColorPrim = Color();
+    maColorSecn = Color();
+    maColorGap = Color();
+    mbUseGapColor = false;
+    meRefMode = RefMode::Centered;
+    mfPrim = 0.0;
+    mfDist = 0.0;
+    mfSecn = 0.0;
+    mfPatternScale = 1.0;
+    mnType = SvxBorderLineStyle::SOLID;
+    mbWordTableCell = false;
 }
 
 void Style::Set( double nP, double nD, double nS )
@@ -89,21 +86,17 @@ void Style::Set( double nP, double nD, double nS )
         >0  0   >0      nP      0       0
         >0  >0  >0      nP      nD      nS
      */
-    implEnsureImplStyle();
-    implStyle* pTarget = maImplStyle.get();
-    pTarget->mfPrim = rtl::math::round(nP ? nP : nS, 2);
-    pTarget->mfDist = rtl::math::round((nP && nS) ? nD : 0, 2);
-    pTarget->mfSecn = rtl::math::round((nP && nD) ? nS : 0, 2);
+    mfPrim = rtl::math::round(nP ? nP : nS, 2);
+    mfDist = rtl::math::round((nP && nS) ? nD : 0, 2);
+    mfSecn = rtl::math::round((nP && nD) ? nS : 0, 2);
 }
 
 void Style::Set( const Color& rColorPrim, const Color& rColorSecn, const Color& rColorGap, bool bUseGapColor, double nP, double nD, double nS )
 {
-    implEnsureImplStyle();
-    implStyle* pTarget = maImplStyle.get();
-    pTarget->maColorPrim = rColorPrim;
-    pTarget->maColorSecn = rColorSecn;
-    pTarget->maColorGap = rColorGap;
-    pTarget->mbUseGapColor = bUseGapColor;
+    maColorPrim = rColorPrim;
+    maColorSecn = rColorSecn;
+    maColorGap = rColorGap;
+    mbUseGapColor = bUseGapColor;
     Set( nP, nD, nS );
 }
 
@@ -115,19 +108,17 @@ void Style::Set( const SvxBorderLine* pBorder, double fScale, sal_uInt16 nMaxWid
         return;
     }
 
-    implEnsureImplStyle();
-    implStyle* pTarget = maImplStyle.get();
-    pTarget->maColorPrim = pBorder->GetColorOut();
-    pTarget->maColorSecn = pBorder->GetColorIn();
-    pTarget->maColorGap = pBorder->GetColorGap();
-    pTarget->mbUseGapColor = pBorder->HasGapColor();
+    maColorPrim = pBorder->GetColorOut();
+    maColorSecn = pBorder->GetColorIn();
+    maColorGap = pBorder->GetColorGap();
+    mbUseGapColor = pBorder->HasGapColor();
 
     const sal_uInt16 nPrim(pBorder->GetOutWidth());
     const sal_uInt16 nDist(pBorder->GetDistance());
     const sal_uInt16 nSecn(pBorder->GetInWidth());
 
-    pTarget->mnType = pBorder->GetBorderLineStyle();
-    pTarget->mfPatternScale = fScale;
+    mnType = pBorder->GetBorderLineStyle();
+    mfPatternScale = fScale;
 
     if( !nSecn )    // no or single frame border
     {
@@ -141,148 +132,57 @@ void Style::Set( const SvxBorderLine* pBorder, double fScale, sal_uInt16 nMaxWid
 
         if( nPixWidth > GetWidth() )
         {
-            pTarget->mfDist = nPixWidth - pTarget->mfPrim - pTarget->mfSecn;
+            mfDist = nPixWidth - mfPrim - mfSecn;
         }
 
         // Shrink the style if it is too thick for the control.
         while( GetWidth() > nMaxWidth )
         {
             // First decrease space between lines.
-            if (pTarget->mfDist)
+            if (mfDist)
             {
-                --(pTarget->mfDist);
+                --mfDist;
                 continue;
             }
 
             // Still too thick? Decrease the line widths.
-            if (pTarget->mfPrim != 0.0 && rtl::math::approxEqual(pTarget->mfPrim, pTarget->mfSecn))
+            if (mfPrim != 0.0 && rtl::math::approxEqual(mfPrim, mfSecn))
             {
                 // Both lines equal - decrease both to keep symmetry.
-                --(pTarget->mfPrim);
-                --(pTarget->mfSecn);
+                --mfPrim;
+                --mfSecn;
                 continue;
             }
 
             // Decrease each line for itself
-            if (pTarget->mfPrim)
-            {
-                --(pTarget->mfPrim);
-            }
-
-            if ((GetWidth() > nMaxWidth) && pTarget->mfSecn != 0.0)
-            {
-                --(pTarget->mfSecn);
-            }
-        }
-    }
-}
-
-void Style::SetRefMode( RefMode eRefMode )
-{
-    if(!maImplStyle)
-    {
-        if(RefMode::Centered == eRefMode)
-        {
-            return;
-        }
-
-        implEnsureImplStyle();
-    }
-
-    maImplStyle->meRefMode = eRefMode;
-}
-
-void Style::SetColorPrim( const Color& rColor )
-{
-    if(!maImplStyle)
-    {
-        if(Color() == rColor)
-        {
-            return;
-        }
-
-        implEnsureImplStyle();
-    }
-
-    maImplStyle->maColorPrim = rColor;
-}
+            if (mfPrim)
+                --mfPrim;
 
-void Style::SetColorSecn( const Color& rColor )
-{
-    if(!maImplStyle)
-    {
-        if(Color() == rColor)
-        {
-            return;
+            if ((GetWidth() > nMaxWidth) && mfSecn != 0.0)
+                --mfSecn;
         }
-
-        implEnsureImplStyle();
     }
-
-    maImplStyle->maColorSecn = rColor;
-}
-
-void Style::SetType( SvxBorderLineStyle nType )
-{
-    if(!maImplStyle)
-    {
-        if(SvxBorderLineStyle::SOLID == nType)
-        {
-            return;
-        }
-
-        implEnsureImplStyle();
-    }
-
-    maImplStyle->mnType = nType;
 }
 
 Style& Style::MirrorSelf()
 {
-    if(!maImplStyle)
+    if (mfSecn)
     {
-        return *this;
-    }
-
-    implStyle* pTarget = maImplStyle.get();
-
-    if (pTarget->mfSecn)
-    {
-        std::swap( pTarget->mfPrim, pTarget->mfSecn );
+        std::swap( mfPrim, mfSecn );
         // also need to swap colors
-        std::swap( pTarget->maColorPrim, pTarget->maColorSecn );
+        std::swap( maColorPrim, maColorSecn );
     }
 
-    if( pTarget->meRefMode != RefMode::Centered )
+    if( meRefMode != RefMode::Centered )
     {
-        pTarget->meRefMode = (pTarget->meRefMode == RefMode::Begin) ? RefMode::End : RefMode::Begin;
+        meRefMode = (meRefMode == RefMode::Begin) ? RefMode::End : RefMode::Begin;
     }
 
     return *this;
 }
 
-void Style::SetWordTableCell(bool bWordTableCell)
-{
-    if (!maImplStyle)
-    {
-        implEnsureImplStyle();
-    }
-
-    maImplStyle->mbWordTableCell = bWordTableCell;
-}
-
 bool Style::operator==( const Style& rOther) const
 {
-    if(!maImplStyle && !rOther.maImplStyle)
-    {
-        return true;
-    }
-
-    if(maImplStyle && rOther.maImplStyle && maImplStyle.get() == rOther.maImplStyle.get())
-    {
-        return true;
-    }
-
     return (Prim() == rOther.Prim()
         && Dist() == rOther.Dist()
         && Secn() == rOther.Secn()
@@ -391,13 +291,7 @@ double GetWordTableCellBorderWeight(const Style& rStyle)
 
 bool Style::operator<( const Style& rOther) const
 {
-    if(!maImplStyle && !rOther.maImplStyle)
-    {
-        // are equal
-        return false;
-    }
-
-    if (maImplStyle && maImplStyle->mbWordTableCell)
+    if (mbWordTableCell)
     {
         // The below code would first compare based on the border width, Word compares based on its
         // calculated weight, do that in the compat case.


More information about the Libreoffice-commits mailing list