[Libreoffice-commits] core.git: sw/source

Noel (via logerrit) logerrit at kemper.freedesktop.org
Mon Oct 26 15:49:47 UTC 2020


 sw/source/core/access/accpara.cxx   |    8 ++++----
 sw/source/core/doc/notxtfrm.cxx     |    4 ++--
 sw/source/core/inc/frame.hxx        |    3 ++-
 sw/source/core/inc/swfont.hxx       |    9 +++++----
 sw/source/core/layout/paintfrm.cxx  |   24 ++++++++++++------------
 sw/source/core/text/atrstck.cxx     |    2 +-
 sw/source/core/text/inftxt.cxx      |   10 +++++-----
 sw/source/core/text/redlnitr.cxx    |    2 +-
 sw/source/core/text/txtftn.cxx      |    2 +-
 sw/source/core/txtnode/fntcache.cxx |   14 ++++++++------
 sw/source/core/txtnode/swfont.cxx   |   14 +++++++-------
 11 files changed, 48 insertions(+), 44 deletions(-)

New commits:
commit 799d158790cfe14edb93c4225a446cd804c82f80
Author:     Noel <noelgrandin at gmail.com>
AuthorDate: Mon Oct 26 11:39:26 2020 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Mon Oct 26 16:49:02 2020 +0100

    std::unique_ptr -> std::optional
    
    Change-Id: I48195e5bd61f9b662481da0efc6165ced794600c
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/104801
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/sw/source/core/access/accpara.cxx b/sw/source/core/access/accpara.cxx
index 4f60b2b9dff0..8e3bf82bb749 100644
--- a/sw/source/core/access/accpara.cxx
+++ b/sw/source/core/access/accpara.cxx
@@ -808,16 +808,16 @@ static bool lcl_GetBackgroundColor( Color & rColor,
                              SwCursorShell* pCursorSh )
 {
     const SvxBrushItem* pBackgrdBrush = nullptr;
-    const Color* pSectionTOXColor = nullptr;
+    std::optional<Color> xSectionTOXColor;
     SwRect aDummyRect;
     drawinglayer::attribute::SdrAllFillAttributesHelperPtr aFillAttributes;
 
     if ( pFrame &&
-         pFrame->GetBackgroundBrush( aFillAttributes, pBackgrdBrush, pSectionTOXColor, aDummyRect, false, /*bConsiderTextBox=*/false ) )
+         pFrame->GetBackgroundBrush( aFillAttributes, pBackgrdBrush, xSectionTOXColor, aDummyRect, false, /*bConsiderTextBox=*/false ) )
     {
-        if ( pSectionTOXColor )
+        if ( xSectionTOXColor )
         {
-            rColor = *pSectionTOXColor;
+            rColor = *xSectionTOXColor;
             return true;
         }
         else
diff --git a/sw/source/core/doc/notxtfrm.cxx b/sw/source/core/doc/notxtfrm.cxx
index f51bc19bc9c0..2fcf84602d62 100644
--- a/sw/source/core/doc/notxtfrm.cxx
+++ b/sw/source/core/doc/notxtfrm.cxx
@@ -187,11 +187,11 @@ static void lcl_ClearArea( const SwFrame &rFrame,
         return;
 
     const SvxBrushItem *pItem;
-    const Color *pCol;
+    std::optional<Color> xCol;
     SwRect aOrigRect;
     drawinglayer::attribute::SdrAllFillAttributesHelperPtr aFillAttributes;
 
-    if ( rFrame.GetBackgroundBrush( aFillAttributes, pItem, pCol, aOrigRect, false, /*bConsiderTextBox=*/false ) )
+    if ( rFrame.GetBackgroundBrush( aFillAttributes, pItem, xCol, aOrigRect, false, /*bConsiderTextBox=*/false ) )
     {
         SwRegionRects const region(rPtArea);
         basegfx::utils::B2DClipState aClipState;
diff --git a/sw/source/core/inc/frame.hxx b/sw/source/core/inc/frame.hxx
index 27622be75dbb..1c099696c504 100644
--- a/sw/source/core/inc/frame.hxx
+++ b/sw/source/core/inc/frame.hxx
@@ -33,6 +33,7 @@
 #include <vcl/outdev.hxx>
 
 #include <memory>
+#include <optional>
 
 namespace drawinglayer::processor2d { class BaseProcessor2D; }
 
@@ -571,7 +572,7 @@ public:
     bool GetBackgroundBrush(
         drawinglayer::attribute::SdrAllFillAttributesHelperPtr& rFillAttributes,
         const SvxBrushItem*& rpBrush,
-        const Color*& rpColor,
+        std::optional<Color>& rxColor,
         SwRect &rOrigRect,
         bool bLowerMode,
         bool bConsiderTextBox ) const;
diff --git a/sw/source/core/inc/swfont.hxx b/sw/source/core/inc/swfont.hxx
index f58a65ac9455..d1c5d7841369 100644
--- a/sw/source/core/inc/swfont.hxx
+++ b/sw/source/core/inc/swfont.hxx
@@ -30,6 +30,7 @@
 #include <editeng/borderline.hxx>
 #include <optional>
 #include <o3tl/enumarray.hxx>
+#include <optional>
 
 class SfxItemSet;
 class SwAttrSet;
@@ -133,8 +134,8 @@ class SwFont
     // CTL == Complex text layout ( Hebrew, Arabic )
     o3tl::enumarray<SwFontScript, SwSubFont>   m_aSub; // Latin-, CJK- and CTL-font
 
-    std::unique_ptr<Color>
-                m_pBackColor;     // background color (i.e. at character styles)
+    std::optional<Color>
+                mxBackColor;     // background color (i.e. at character styles)
     Color       m_aHighlightColor;   // highlight color
     Color       m_aUnderColor;    // color of the underlining
     Color       m_aOverColor;     // color of the overlining
@@ -186,8 +187,8 @@ public:
     // gets a font cache id via SwFntAccess
     void AllocFontCacheId( SwViewShell const *pSh, SwFontScript nWhich );
     // set background color
-    void SetBackColor( Color* pNewColor );
-    const Color* GetBackColor() const{ return m_pBackColor.get(); }
+    void SetBackColor( std::optional<Color> xNewColor );
+    const std::optional<Color>& GetBackColor() const{ return mxBackColor; }
     void SetHighlightColor( const Color& aNewColor );
     const Color& GetHighlightColor() const { return m_aHighlightColor; }
 
diff --git a/sw/source/core/layout/paintfrm.cxx b/sw/source/core/layout/paintfrm.cxx
index ffd391d0d13c..b06341cb9ecb 100644
--- a/sw/source/core/layout/paintfrm.cxx
+++ b/sw/source/core/layout/paintfrm.cxx
@@ -3752,15 +3752,15 @@ bool SwFlyFrame::IsBackgroundTransparent() const
          GetFormat()->IsBackgroundBrushInherited() )
     {
         const SvxBrushItem* pBackgrdBrush = nullptr;
-        const Color* pSectionTOXColor = nullptr;
+        std::optional<Color> xSectionTOXColor;
         SwRect aDummyRect;
         drawinglayer::attribute::SdrAllFillAttributesHelperPtr aFillAttributes;
 
-        if ( GetBackgroundBrush( aFillAttributes, pBackgrdBrush, pSectionTOXColor, aDummyRect, false, /*bConsiderTextBox=*/false) )
+        if ( GetBackgroundBrush( aFillAttributes, pBackgrdBrush, xSectionTOXColor, aDummyRect, false, /*bConsiderTextBox=*/false) )
         {
-            if ( pSectionTOXColor &&
-                 (pSectionTOXColor->GetTransparency() != 0) &&
-                 (*pSectionTOXColor != COL_TRANSPARENT) )
+            if ( xSectionTOXColor &&
+                 (xSectionTOXColor->GetTransparency() != 0) &&
+                 (xSectionTOXColor != COL_TRANSPARENT) )
             {
                 bBackgroundTransparent = true;
             }
@@ -6202,7 +6202,7 @@ void SwFrame::PaintSwFrameBackground( const SwRect &rRect, const SwPageFrame *pP
     const SvxBrushItem* pItem;
     // temporary background brush for a fly frame without a background brush
     std::unique_ptr<SvxBrushItem> pTmpBackBrush;
-    const Color* pCol;
+    std::optional<Color> pCol;
     SwRect aOrigBackRect;
     const bool bPageFrame = IsPageFrame();
     bool bLowMode = true;
@@ -7010,11 +7010,11 @@ void SwLayoutFrame::RefreshExtraData( const SwRect &rRect ) const
 Color SwPageFrame::GetDrawBackgrdColor() const
 {
     const SvxBrushItem* pBrushItem;
-    const Color* pDummyColor;
+    std::optional<Color> xDummyColor;
     SwRect aDummyRect;
     drawinglayer::attribute::SdrAllFillAttributesHelperPtr aFillAttributes;
 
-    if ( GetBackgroundBrush( aFillAttributes, pBrushItem, pDummyColor, aDummyRect, true, /*bConsiderTextBox=*/false) )
+    if ( GetBackgroundBrush( aFillAttributes, pBrushItem, xDummyColor, aDummyRect, true, /*bConsiderTextBox=*/false) )
     {
         if(aFillAttributes && aFillAttributes->isUsed())
         {
@@ -7187,7 +7187,7 @@ void SwFrame::Retouch( const SwPageFrame * pPage, const SwRect &rRect ) const
 bool SwFrame::GetBackgroundBrush(
     drawinglayer::attribute::SdrAllFillAttributesHelperPtr& rFillAttributes,
     const SvxBrushItem* & rpBrush,
-    const Color*& rpCol,
+    std::optional<Color>& rxCol,
     SwRect &rOrigRect,
     bool bLowerMode,
     bool bConsiderTextBox ) const
@@ -7196,7 +7196,7 @@ bool SwFrame::GetBackgroundBrush(
     SwViewShell *pSh = getRootFrame()->GetCurrShell();
     const SwViewOption *pOpt = pSh->GetViewOptions();
     rpBrush = nullptr;
-    rpCol = nullptr;
+    rxCol.reset();
     do
     {
         if ( pFrame->IsPageFrame() && !pOpt->IsPageBack() )
@@ -7252,7 +7252,7 @@ bool SwFrame::GetBackgroundBrush(
                 !pOpt->IsPDFExport() &&
                 pSh->GetOut()->GetOutDevType() != OUTDEV_PRINTER )
             {
-                rpCol = &SwViewOption::GetIndexShadingsColor();
+                rxCol = SwViewOption::GetIndexShadingsColor();
             }
         }
 
@@ -7300,7 +7300,7 @@ bool SwFrame::GetBackgroundBrush(
             !rBack.GetColor().GetTransparency() || rBack.GetGraphicPos() != GPOS_NONE ||
 
             // done when direct color is forced
-            rpCol ||
+            rxCol ||
 
             // done when consider BG transparency and color is not completely transparent
             (bConsiderBackgroundTransparency && (rBack.GetColor() != COL_TRANSPARENT))
diff --git a/sw/source/core/text/atrstck.cxx b/sw/source/core/text/atrstck.cxx
index 8bac38c92c7e..b1dc40bf4879 100644
--- a/sw/source/core/text/atrstck.cxx
+++ b/sw/source/core/text/atrstck.cxx
@@ -669,7 +669,7 @@ void SwAttrHandler::FontChg(const SfxPoolItem& rItem, SwFont& rFnt, bool bPush )
                 rFnt.SetAutoKern( FontKerning::NONE );
             break;
         case RES_CHRATR_BACKGROUND :
-            rFnt.SetBackColor(new Color( static_cast<const SvxBrushItem&>(rItem).GetColor() ) );
+            rFnt.SetBackColor(static_cast<const SvxBrushItem&>(rItem).GetColor());
             break;
         case RES_CHRATR_HIGHLIGHT :
             rFnt.SetHighlightColor( static_cast<const SvxBrushItem&>(rItem).GetColor() );
diff --git a/sw/source/core/text/inftxt.cxx b/sw/source/core/text/inftxt.cxx
index 846701fd240b..ac0b61f29a79 100644
--- a/sw/source/core/text/inftxt.cxx
+++ b/sw/source/core/text/inftxt.cxx
@@ -524,7 +524,7 @@ SwTextPaintInfo::SwTextPaintInfo( SwTextFrame *pFrame, const SwRect &rPaint )
 /// Returns if the current background color is dark.
 static bool lcl_IsDarkBackground( const SwTextPaintInfo& rInf )
 {
-    const Color* pCol = rInf.GetFont()->GetBackColor();
+    std::optional<Color> pCol = rInf.GetFont()->GetBackColor();
     if( ! pCol || COL_TRANSPARENT == *pCol )
     {
         const SvxBrushItem* pItem;
@@ -538,18 +538,18 @@ static bool lcl_IsDarkBackground( const SwTextPaintInfo& rInf )
         if( rInf.GetTextFrame()->GetBackgroundBrush( aFillAttributes, pItem, pCol, aOrigBackRect, false, /*bConsiderTextBox=*/false ) )
         {
             if ( !pCol )
-                pCol = &pItem->GetColor();
+                pCol = pItem->GetColor();
 
             // Determined color <pCol> can be <COL_TRANSPARENT>. Thus, check it.
             if ( *pCol == COL_TRANSPARENT)
-                pCol = nullptr;
+                pCol.reset();
         }
         else
-            pCol = nullptr;
+            pCol.reset();
     }
 
     if( !pCol )
-        pCol = &aGlobalRetoucheColor;
+        pCol = aGlobalRetoucheColor;
 
     return pCol->IsDark();
 }
diff --git a/sw/source/core/text/redlnitr.cxx b/sw/source/core/text/redlnitr.cxx
index 2bd0c2ccdc23..03b67b9b4784 100644
--- a/sw/source/core/text/redlnitr.cxx
+++ b/sw/source/core/text/redlnitr.cxx
@@ -860,7 +860,7 @@ void SwExtend::ActualizeFont( SwFont &rFnt, ExtTextInputAttr nAttr )
     {
         const StyleSettings& rStyleSettings = Application::GetSettings().GetStyleSettings();
         rFnt.SetColor( rStyleSettings.GetHighlightTextColor() );
-        rFnt.SetBackColor( new Color( rStyleSettings.GetHighlightColor() ) );
+        rFnt.SetBackColor( rStyleSettings.GetHighlightColor() );
     }
     if ( nAttr & ExtTextInputAttr::GrayWaveline )
         rFnt.SetGreyWave( true );
diff --git a/sw/source/core/text/txtftn.cxx b/sw/source/core/text/txtftn.cxx
index 1d340d4a2d81..ecab7583e3b0 100644
--- a/sw/source/core/text/txtftn.cxx
+++ b/sw/source/core/text/txtftn.cxx
@@ -1321,7 +1321,7 @@ SwFootnoteSave::SwFootnoteSave( const SwTextSizeInfo &rInf,
 
         if( SfxItemState::SET == rSet.GetItemState( RES_CHRATR_BACKGROUND,
             true, &pItem ))
-            pFnt->SetBackColor( new Color( static_cast<const SvxBrushItem*>(pItem)->GetColor() ) );
+            pFnt->SetBackColor( static_cast<const SvxBrushItem*>(pItem)->GetColor() );
     }
     else
         pFnt = nullptr;
diff --git a/sw/source/core/txtnode/fntcache.cxx b/sw/source/core/txtnode/fntcache.cxx
index 34bb365233c3..a1430890f010 100644
--- a/sw/source/core/txtnode/fntcache.cxx
+++ b/sw/source/core/txtnode/fntcache.cxx
@@ -2610,7 +2610,9 @@ bool SwDrawTextInfo::ApplyAutoColor( vcl::Font* pFont )
         if ( bChgFntColor )
         {
             // check if current background has a user defined setting
-            const Color* pCol = GetFont() ? GetFont()->GetBackColor() : nullptr;
+            std::optional<Color> pCol;
+            if (GetFont())
+                pCol = GetFont()->GetBackColor();
             Color aColor;
             if( ! pCol || COL_TRANSPARENT == *pCol )
             {
@@ -2630,27 +2632,27 @@ bool SwDrawTextInfo::ApplyAutoColor( vcl::Font* pFont )
                     {
                         // First see if fill attributes provide a color.
                         aColor = Color(aFillAttributes->getAverageColor(aGlobalRetoucheColor.getBColor()));
-                        pCol = &aColor;
+                        pCol = aColor;
                     }
 
                     // If not, then fall back to the old brush item.
                     if ( !pCol )
                     {
-                        pCol = &pItem->GetColor();
+                        pCol = pItem->GetColor();
                     }
 
                     /// OD 30.08.2002 #99657#
                     /// determined color <pCol> can be <COL_TRANSPARENT>. Thus, check it.
                     if ( *pCol == COL_TRANSPARENT)
-                        pCol = nullptr;
+                        pCol.reset();
                 }
                 else
-                    pCol = nullptr;
+                    pCol.reset();
             }
 
             // no user defined color at paragraph or font background
             if ( ! pCol )
-                pCol = &aGlobalRetoucheColor;
+                pCol = aGlobalRetoucheColor;
 
             if( GetShell() && GetShell()->GetWin() )
             {
diff --git a/sw/source/core/txtnode/swfont.cxx b/sw/source/core/txtnode/swfont.cxx
index e2f0b0b71d6c..1bc5a3f6ba3b 100644
--- a/sw/source/core/txtnode/swfont.cxx
+++ b/sw/source/core/txtnode/swfont.cxx
@@ -62,9 +62,9 @@ SvStatistics g_SvStat;
 using namespace ::com::sun::star;
 
 // set background brush, depending on character formatting
-void SwFont::SetBackColor( Color* pNewColor )
+void SwFont::SetBackColor( std::optional<Color> xNewColor )
 {
-    m_pBackColor.reset( pNewColor );
+    mxBackColor = xNewColor;
     m_bFontChg = true;
     m_aSub[SwFontScript::Latin].m_nFontCacheId = m_aSub[SwFontScript::CJK].m_nFontCacheId = m_aSub[SwFontScript::CTL].m_nFontCacheId = nullptr;
 }
@@ -494,7 +494,7 @@ sal_uInt16 SwSubFont::CalcEscAscent( const sal_uInt16 nOldAscent ) const
 void SwFont::SetDiffFnt( const SfxItemSet *pAttrSet,
                          const IDocumentSettingAccess *pIDocumentSettingAccess )
 {
-    m_pBackColor.reset();
+    mxBackColor.reset();
 
     if( pAttrSet )
     {
@@ -667,7 +667,7 @@ void SwFont::SetDiffFnt( const SfxItemSet *pAttrSet,
             SetVertical( static_cast<const SvxCharRotateItem*>(pItem)->GetValue() );
         if( SfxItemState::SET == pAttrSet->GetItemState( RES_CHRATR_BACKGROUND,
             true, &pItem ))
-            m_pBackColor.reset( new Color( static_cast<const SvxBrushItem*>(pItem)->GetColor() ) );
+            mxBackColor = static_cast<const SvxBrushItem*>(pItem)->GetColor();
         if( SfxItemState::SET == pAttrSet->GetItemState( RES_CHRATR_HIGHLIGHT,
             true, &pItem ))
             SetHighlightColor(static_cast<const SvxBrushItem*>(pItem)->GetColor());
@@ -710,7 +710,7 @@ SwFont::SwFont( const SwFont &rFont )
     : m_aSub(rFont.m_aSub)
 {
     m_nActual = rFont.m_nActual;
-    m_pBackColor.reset( rFont.m_pBackColor ? new Color( *rFont.m_pBackColor ) : nullptr );
+    mxBackColor = rFont.mxBackColor;
     m_aHighlightColor = rFont.m_aHighlightColor;
     m_aTopBorder = rFont.m_aTopBorder;
     m_aBottomBorder = rFont.m_aBottomBorder;
@@ -833,7 +833,7 @@ SwFont::SwFont( const SwAttrSet* pAttrSet,
     const SfxPoolItem* pItem;
     if( SfxItemState::SET == pAttrSet->GetItemState( RES_CHRATR_BACKGROUND,
         true, &pItem ))
-        m_pBackColor.reset( new Color( static_cast<const SvxBrushItem*>(pItem)->GetColor() ) );
+        mxBackColor = static_cast<const SvxBrushItem*>(pItem)->GetColor();
     if( SfxItemState::SET == pAttrSet->GetItemState( RES_CHRATR_HIGHLIGHT,
         true, &pItem ))
         SetHighlightColor(static_cast<const SvxBrushItem*>(pItem)->GetColor());
@@ -904,7 +904,7 @@ SwFont& SwFont::operator=( const SwFont &rFont )
         m_aSub[SwFontScript::CJK] = rFont.m_aSub[SwFontScript::CJK];
         m_aSub[SwFontScript::CTL] = rFont.m_aSub[SwFontScript::CTL];
         m_nActual = rFont.m_nActual;
-        m_pBackColor.reset( rFont.m_pBackColor ? new Color( *rFont.m_pBackColor ) : nullptr );
+        mxBackColor = rFont.mxBackColor;
         m_aHighlightColor = rFont.m_aHighlightColor;
         m_aTopBorder = rFont.m_aTopBorder;
         m_aBottomBorder = rFont.m_aBottomBorder;


More information about the Libreoffice-commits mailing list