[Libreoffice-commits] core.git: editeng/inc editeng/qa editeng/source include/editeng include/svx sc/inc sc/source starmath/source svx/source

Noel Grandin noel.grandin at collabora.co.uk
Thu May 10 06:43:13 UTC 2018


 editeng/inc/editattr.hxx                               |   11 +++----
 editeng/qa/unit/core-test.cxx                          |    2 -
 editeng/source/editeng/editattr.cxx                    |   26 +++++++----------
 editeng/source/editeng/editeng.cxx                     |    2 -
 editeng/source/editeng/impedit2.cxx                    |    2 -
 editeng/source/outliner/outleeng.cxx                   |    2 -
 editeng/source/outliner/outleeng.hxx                   |    2 -
 editeng/source/outliner/outliner.cxx                   |   11 +++----
 editeng/source/uno/unoedprx.cxx                        |    2 -
 editeng/source/uno/unofored.cxx                        |    2 -
 editeng/source/uno/unoforou.cxx                        |    2 -
 editeng/source/uno/unotext.cxx                         |    9 +----
 include/editeng/editeng.hxx                            |    3 +
 include/editeng/outliner.hxx                           |    2 -
 include/editeng/unoedprx.hxx                           |    2 -
 include/editeng/unoedsrc.hxx                           |    2 -
 include/editeng/unofored.hxx                           |    2 -
 include/editeng/unoforou.hxx                           |    2 -
 include/editeng/unotext.hxx                            |    2 -
 include/svx/ClassificationEditView.hxx                 |    2 -
 include/svx/svdomeas.hxx                               |    2 -
 include/svx/svdotext.hxx                               |    2 -
 include/svx/svdoutl.hxx                                |    2 -
 sc/inc/editutil.hxx                                    |    6 +--
 sc/source/core/tool/editutil.cxx                       |    8 ++---
 sc/source/ui/pagedlg/scuitphfedit.cxx                  |    4 +-
 sc/source/ui/unoobj/fielduno.cxx                       |    4 +-
 starmath/source/accessibility.cxx                      |    2 -
 starmath/source/accessibility.hxx                      |    2 -
 svx/source/accessibility/AccessibleEmptyEditSource.cxx |    2 -
 svx/source/dialog/ClassificationEditView.cxx           |    2 -
 svx/source/svdraw/svdedxv.cxx                          |   10 ++----
 svx/source/svdraw/svdomeas.cxx                         |   11 ++-----
 svx/source/svdraw/svdotxfl.cxx                         |    2 -
 svx/source/svdraw/svdoutl.cxx                          |    2 -
 35 files changed, 72 insertions(+), 79 deletions(-)

New commits:
commit 5c9ae702b42745bf6963d1cbb4e779b66ade0825
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Wed May 9 12:17:08 2018 +0200

    store Color using boost::optional in EditCharAttribField
    
    Change-Id: If4af5991be51cdb035c0bc0fb7668844df703073
    Reviewed-on: https://gerrit.libreoffice.org/54022
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/editeng/inc/editattr.hxx b/editeng/inc/editattr.hxx
index b93c0bdd5f3a..fd0e0de509c2 100644
--- a/editeng/inc/editattr.hxx
+++ b/editeng/inc/editattr.hxx
@@ -22,8 +22,9 @@
 
 #include <editeng/eeitem.hxx>
 #include <svl/poolitem.hxx>
+#include <boost/optional.hpp>
+#include <tools/color.hxx>
 
-class Color;
 class SvxFont;
 class SvxFontItem;
 class SvxWeightItem;
@@ -363,8 +364,8 @@ public:
 class EditCharAttribField: public EditCharAttrib
 {
     OUString   aFieldValue;
-    Color*          pTxtColor;
-    Color*          pFldColor;
+    boost::optional<Color>  mxTxtColor;
+    boost::optional<Color>  mxFldColor;
 
     EditCharAttribField& operator = ( const EditCharAttribField& rAttr ) = delete;
 
@@ -378,8 +379,8 @@ public:
                                     { return !(operator == ( rAttr ) ); }
 
     virtual void    SetFont( SvxFont& rFont, OutputDevice* pOutDev ) override;
-    Color*&         GetTextColor()           { return pTxtColor; }
-    Color*&         GetFieldColor()           { return pFldColor; }
+    boost::optional<Color>&   GetTextColor()      { return mxTxtColor; }
+    boost::optional<Color>&   GetFieldColor()     { return mxFldColor; }
 
     const OUString& GetFieldValue() const { return aFieldValue;}
     void SetFieldValue(const OUString& rVal);
diff --git a/editeng/qa/unit/core-test.cxx b/editeng/qa/unit/core-test.cxx
index 9e882ad77b5c..7cd582a6a91e 100644
--- a/editeng/qa/unit/core-test.cxx
+++ b/editeng/qa/unit/core-test.cxx
@@ -805,7 +805,7 @@ class UrlEditEngine : public EditEngine
 public:
     explicit UrlEditEngine(SfxItemPool *pPool) : EditEngine(pPool) {}
 
-    virtual OUString CalcFieldValue( const SvxFieldItem&, sal_Int32, sal_Int32, Color*&, Color*& ) override
+    virtual OUString CalcFieldValue( const SvxFieldItem&, sal_Int32, sal_Int32, boost::optional<Color>&, boost::optional<Color>& ) override
     {
         return OUString("jim at bob.com"); // a sophisticated view of value:
     }
diff --git a/editeng/source/editeng/editattr.cxx b/editeng/source/editeng/editattr.cxx
index 13ed53906ebf..c20e03d21a51 100644
--- a/editeng/source/editeng/editattr.cxx
+++ b/editeng/source/editeng/editattr.cxx
@@ -345,19 +345,17 @@ EditCharAttribField::EditCharAttribField( const SvxFieldItem& rAttr, sal_Int32 n
     : EditCharAttrib( rAttr, nPos, nPos+1 )
 {
     SetFeature( true ); // !!!
-    pTxtColor = nullptr;
-    pFldColor = nullptr;
 }
 
 void EditCharAttribField::SetFont( SvxFont& rFont, OutputDevice* )
 {
-    if ( pFldColor )
+    if ( mxFldColor )
     {
-        rFont.SetFillColor( *pFldColor );
+        rFont.SetFillColor( *mxFldColor );
         rFont.SetTransparent( false );
     }
-    if ( pTxtColor )
-        rFont.SetColor( *pTxtColor );
+    if ( mxTxtColor )
+        rFont.SetColor( *mxTxtColor );
 }
 
 
@@ -369,8 +367,8 @@ void EditCharAttribField::SetFieldValue(const OUString& rVal)
 void EditCharAttribField::Reset()
 {
     aFieldValue.clear();
-    delete pTxtColor; pTxtColor = nullptr;
-    delete pFldColor; pFldColor = nullptr;
+    mxTxtColor.reset();
+    mxFldColor.reset();
 }
 
 EditCharAttribField::EditCharAttribField( const EditCharAttribField& rAttr )
@@ -378,8 +376,8 @@ EditCharAttribField::EditCharAttribField( const EditCharAttribField& rAttr )
         aFieldValue( rAttr.aFieldValue )
 {
     // Use this constructor only for temporary Objects, Item is not pooled.
-    pTxtColor = rAttr.pTxtColor ? new Color( *rAttr.pTxtColor ) : nullptr;
-    pFldColor = rAttr.pFldColor ? new Color( *rAttr.pFldColor ) : nullptr;
+    mxTxtColor = rAttr.mxTxtColor;
+    mxFldColor = rAttr.mxFldColor;
 }
 
 EditCharAttribField::~EditCharAttribField()
@@ -392,14 +390,14 @@ bool EditCharAttribField::operator == ( const EditCharAttribField& rAttr ) const
     if ( aFieldValue != rAttr.aFieldValue )
         return false;
 
-    if ( ( pTxtColor && !rAttr.pTxtColor ) || ( !pTxtColor && rAttr.pTxtColor ) )
+    if ( ( mxTxtColor && !rAttr.mxTxtColor ) || ( !mxTxtColor && rAttr.mxTxtColor ) )
         return false;
-    if ( ( pTxtColor && rAttr.pTxtColor ) && ( *pTxtColor != *rAttr.pTxtColor ) )
+    if ( ( mxTxtColor && rAttr.mxTxtColor ) && ( *mxTxtColor != *rAttr.mxTxtColor ) )
         return false;
 
-    if ( ( pFldColor && !rAttr.pFldColor ) || ( !pFldColor && rAttr.pFldColor ) )
+    if ( ( mxFldColor && !rAttr.mxFldColor ) || ( !mxFldColor && rAttr.mxFldColor ) )
         return false;
-    if ( ( pFldColor && rAttr.pFldColor ) && ( *pFldColor != *rAttr.pFldColor ) )
+    if ( ( mxFldColor && rAttr.mxFldColor ) && ( *mxFldColor != *rAttr.mxFldColor ) )
         return false;
 
     return true;
diff --git a/editeng/source/editeng/editeng.cxx b/editeng/source/editeng/editeng.cxx
index d09e37dd4952..4f8acffacdd4 100644
--- a/editeng/source/editeng/editeng.cxx
+++ b/editeng/source/editeng/editeng.cxx
@@ -2590,7 +2590,7 @@ tools::Rectangle EditEngine::GetBulletArea( sal_Int32 )
     return tools::Rectangle( Point(), Point() );
 }
 
-OUString EditEngine::CalcFieldValue( const SvxFieldItem&, sal_Int32, sal_Int32, Color*&, Color*& )
+OUString EditEngine::CalcFieldValue( const SvxFieldItem&, sal_Int32, sal_Int32, boost::optional<Color>&, boost::optional<Color>& )
 {
     return OUString(' ');
 }
diff --git a/editeng/source/editeng/impedit2.cxx b/editeng/source/editeng/impedit2.cxx
index 04a7c959278a..4c2c0c73a3e4 100644
--- a/editeng/source/editeng/impedit2.cxx
+++ b/editeng/source/editeng/impedit2.cxx
@@ -2968,7 +2968,7 @@ bool ImpEditEngine::UpdateFields()
                 rField.Reset();
 
                 if ( aStatus.MarkFields() )
-                    rField.GetFieldColor() = new Color( GetColorConfig().GetColorValue( svtools::WRITERFIELDSHADINGS ).nColor );
+                    rField.GetFieldColor() = GetColorConfig().GetColorValue( svtools::WRITERFIELDSHADINGS ).nColor;
 
                 const OUString aFldValue =
                     GetEditEnginePtr()->CalcFieldValue(
diff --git a/editeng/source/outliner/outleeng.cxx b/editeng/source/outliner/outleeng.cxx
index ea698471b6e9..8fb8f7ee7284 100644
--- a/editeng/source/outliner/outleeng.cxx
+++ b/editeng/source/outliner/outleeng.cxx
@@ -169,7 +169,7 @@ void OutlinerEditEng::DrawingTab( const Point& rStartPos, long nWidth, const OUS
             bEndOfLine, bEndOfParagraph, rOverlineColor, rTextLineColor );
 }
 
-OUString OutlinerEditEng::CalcFieldValue( const SvxFieldItem& rField, sal_Int32 nPara, sal_Int32 nPos, Color*& rpTxtColor, Color*& rpFldColor )
+OUString OutlinerEditEng::CalcFieldValue( const SvxFieldItem& rField, sal_Int32 nPara, sal_Int32 nPos, boost::optional<Color>& rpTxtColor, boost::optional<Color>& rpFldColor )
 {
     return pOwner->CalcFieldValue( rField, nPara, nPos, rpTxtColor, rpFldColor );
 }
diff --git a/editeng/source/outliner/outleeng.hxx b/editeng/source/outliner/outleeng.hxx
index 2b45610c16d3..5110d8be28ef 100644
--- a/editeng/source/outliner/outleeng.hxx
+++ b/editeng/source/outliner/outleeng.hxx
@@ -71,7 +71,7 @@ public:
     // for text conversion
     virtual bool        ConvertNextDocument() override;
 
-    virtual OUString    CalcFieldValue( const SvxFieldItem& rField, sal_Int32 nPara, sal_Int32 nPos, Color*& rTxtColor, Color*& rFldColor ) override;
+    virtual OUString    CalcFieldValue( const SvxFieldItem& rField, sal_Int32 nPara, sal_Int32 nPos, boost::optional<Color>& rTxtColor, boost::optional<Color>& rFldColor ) override;
 
     virtual tools::Rectangle   GetBulletArea( sal_Int32 nPara ) override;
 
diff --git a/editeng/source/outliner/outliner.cxx b/editeng/source/outliner/outliner.cxx
index 97291995a7db..cc19399e1812 100644
--- a/editeng/source/outliner/outliner.cxx
+++ b/editeng/source/outliner/outliner.cxx
@@ -635,7 +635,7 @@ void Outliner::AddText( const OutlinerParaObject& rPObj )
     pEditEngine->SetUpdateMode( bUpdate );
 }
 
-OUString Outliner::CalcFieldValue( const SvxFieldItem& rField, sal_Int32 nPara, sal_Int32 nPos, Color*& rpTxtColor, Color*& rpFldColor )
+OUString Outliner::CalcFieldValue( const SvxFieldItem& rField, sal_Int32 nPara, sal_Int32 nPos, boost::optional<Color>& rpTxtColor, boost::optional<Color>& rpFldColor )
 {
     if ( !aCalcFieldValueHdl.IsSet() )
         return OUString( ' ' );
@@ -648,12 +648,13 @@ OUString Outliner::CalcFieldValue( const SvxFieldItem& rField, sal_Int32 nPara,
     aCalcFieldValueHdl.Call( &aFldInfo );
     if ( aFldInfo.GetTextColor() )
     {
-        delete rpTxtColor;
-        rpTxtColor = new Color( *aFldInfo.GetTextColor() );
+        rpTxtColor = *aFldInfo.GetTextColor();
     }
 
-    delete rpFldColor;
-    rpFldColor = aFldInfo.GetFieldColor() ? new Color( *aFldInfo.GetFieldColor() ) : nullptr;
+    if (aFldInfo.GetFieldColor())
+        rpFldColor = *aFldInfo.GetFieldColor();
+    else
+        rpFldColor.reset();
 
     return aFldInfo.GetRepresentation();
 }
diff --git a/editeng/source/uno/unoedprx.cxx b/editeng/source/uno/unoedprx.cxx
index 2ebc9bf56a01..f647de146794 100644
--- a/editeng/source/uno/unoedprx.cxx
+++ b/editeng/source/uno/unoedprx.cxx
@@ -614,7 +614,7 @@ SfxItemPool* SvxAccessibleTextAdapter::GetPool() const
     return mpTextForwarder->GetPool();
 }
 
-OUString SvxAccessibleTextAdapter::CalcFieldValue( const SvxFieldItem& rField, sal_Int32 nPara, sal_Int32 nPos, Color*& rpTxtColor, Color*& rpFldColor )
+OUString SvxAccessibleTextAdapter::CalcFieldValue( const SvxFieldItem& rField, sal_Int32 nPara, sal_Int32 nPos, boost::optional<Color>& rpTxtColor, boost::optional<Color>& rpFldColor )
 {
     assert(mpTextForwarder && "SvxAccessibleTextAdapter: no forwarder");
 
diff --git a/editeng/source/uno/unofored.cxx b/editeng/source/uno/unofored.cxx
index 31c3e4a05def..69ce16ec84f0 100644
--- a/editeng/source/uno/unofored.cxx
+++ b/editeng/source/uno/unofored.cxx
@@ -151,7 +151,7 @@ bool SvxEditEngineForwarder::IsValid() const
     return rEditEngine.GetUpdateMode();
 }
 
-OUString SvxEditEngineForwarder::CalcFieldValue( const SvxFieldItem& rField, sal_Int32 nPara, sal_Int32 nPos, Color*& rpTxtColor, Color*& rpFldColor )
+OUString SvxEditEngineForwarder::CalcFieldValue( const SvxFieldItem& rField, sal_Int32 nPara, sal_Int32 nPos, boost::optional<Color>& rpTxtColor, boost::optional<Color>& rpFldColor )
 {
     return rEditEngine.CalcFieldValue( rField, nPara, nPos, rpTxtColor, rpFldColor );
 }
diff --git a/editeng/source/uno/unoforou.cxx b/editeng/source/uno/unoforou.cxx
index 4abad85c0dff..3db46f1a83e9 100644
--- a/editeng/source/uno/unoforou.cxx
+++ b/editeng/source/uno/unoforou.cxx
@@ -223,7 +223,7 @@ void SvxOutlinerForwarder::QuickSetAttribs( const SfxItemSet& rSet, const ESelec
     rOutliner.QuickSetAttribs( rSet, rSel );
 }
 
-OUString SvxOutlinerForwarder::CalcFieldValue( const SvxFieldItem& rField, sal_Int32 nPara, sal_Int32 nPos, Color*& rpTxtColor, Color*& rpFldColor )
+OUString SvxOutlinerForwarder::CalcFieldValue( const SvxFieldItem& rField, sal_Int32 nPara, sal_Int32 nPos, boost::optional<Color>& rpTxtColor, boost::optional<Color>& rpFldColor )
 {
     return rOutliner.CalcFieldValue( rField, nPara, nPos, rpTxtColor, rpFldColor );
 }
diff --git a/editeng/source/uno/unotext.cxx b/editeng/source/uno/unotext.cxx
index 39cff94eb2d6..776296be22a1 100644
--- a/editeng/source/uno/unotext.cxx
+++ b/editeng/source/uno/unotext.cxx
@@ -633,15 +633,12 @@ void SvxUnoTextRangeBase::getPropertyValue( const SfxItemPropertySimpleEntry* pM
             uno::Reference< text::XTextRange > xAnchor( this );
 
             // get presentation string for field
-            Color* pTColor = nullptr;
-            Color* pFColor = nullptr;
+            boost::optional<Color> pTColor;
+            boost::optional<Color> pFColor;
 
             SvxTextForwarder* pForwarder = mpEditSource->GetTextForwarder();
             OUString aPresentation( pForwarder->CalcFieldValue( SvxFieldItem(*pData, EE_FEATURE_FIELD), maSelection.nStartPara, maSelection.nStartPos, pTColor, pFColor ) );
 
-            delete pTColor;
-            delete pFColor;
-
             uno::Reference< text::XTextField > xField( new SvxUnoTextField( xAnchor, aPresentation, pData ) );
             rAny <<= xField;
         }
@@ -2377,7 +2374,7 @@ void SvxDummyTextSource::QuickInsertLineBreak( const ESelection& )
 {
 };
 
-OUString SvxDummyTextSource::CalcFieldValue( const SvxFieldItem&, sal_Int32, sal_Int32, Color*&, Color*& )
+OUString SvxDummyTextSource::CalcFieldValue( const SvxFieldItem&, sal_Int32, sal_Int32, boost::optional<Color>&, boost::optional<Color>& )
 {
     return OUString();
 }
diff --git a/include/editeng/editeng.hxx b/include/editeng/editeng.hxx
index 393e0068cb64..52a052570dd0 100644
--- a/include/editeng/editeng.hxx
+++ b/include/editeng/editeng.hxx
@@ -41,6 +41,7 @@
 #include <o3tl/typed_flags_set.hxx>
 #include <svl/languageoptions.hxx>
 #include <vcl/errcode.hxx>
+#include <boost/optional.hpp>
 #include <functional>
 
 namespace com { namespace sun { namespace star {
@@ -508,7 +509,7 @@ public:
     virtual OUString  GetUndoComment( sal_uInt16 nUndoId ) const;
     virtual bool    SpellNextDocument();
     virtual void    FieldClicked( const SvxFieldItem& rField, sal_Int32 nPara, sal_Int32 nPos );
-    virtual OUString CalcFieldValue( const SvxFieldItem& rField, sal_Int32 nPara, sal_Int32 nPos, Color*& rTxtColor, Color*& rFldColor );
+    virtual OUString CalcFieldValue( const SvxFieldItem& rField, sal_Int32 nPara, sal_Int32 nPos, boost::optional<Color>& rTxtColor, boost::optional<Color>& rFldColor );
 
     // override this if access to bullet information needs to be provided
     virtual const SvxNumberFormat * GetNumberFormat( sal_Int32 nPara ) const;
diff --git a/include/editeng/outliner.hxx b/include/editeng/outliner.hxx
index a5f0d4b1b1e3..31ba68c2c5f9 100644
--- a/include/editeng/outliner.hxx
+++ b/include/editeng/outliner.hxx
@@ -900,7 +900,7 @@ public:
     bool            UpdateFields();
     void            RemoveFields( const std::function<bool ( const SvxFieldData* )>& isFieldData = [] (const SvxFieldData* ){return true;} );
 
-    virtual OUString CalcFieldValue( const SvxFieldItem& rField, sal_Int32 nPara, sal_Int32 nPos, Color*& rTxtColor, Color*& rFldColor );
+    virtual OUString CalcFieldValue( const SvxFieldItem& rField, sal_Int32 nPara, sal_Int32 nPos, boost::optional<Color>& rTxtColor, boost::optional<Color>& rFldColor );
 
     void            SetSpeller( css::uno::Reference< css::linguistic2::XSpellChecker1 > const &xSpeller );
     css::uno::Reference< css::linguistic2::XSpellChecker1 > const &
diff --git a/include/editeng/unoedprx.hxx b/include/editeng/unoedprx.hxx
index f4f9cd66c0a5..dd296af6375f 100644
--- a/include/editeng/unoedprx.hxx
+++ b/include/editeng/unoedprx.hxx
@@ -54,7 +54,7 @@ public:
 
     virtual SfxItemPool*    GetPool() const override;
 
-    virtual OUString        CalcFieldValue( const SvxFieldItem& rField, sal_Int32 nPara, sal_Int32 nPos, Color*& rpTxtColor, Color*& rpFldColor ) override;
+    virtual OUString        CalcFieldValue( const SvxFieldItem& rField, sal_Int32 nPara, sal_Int32 nPos, boost::optional<Color>& rpTxtColor, boost::optional<Color>& rpFldColor ) override;
     virtual void            FieldClicked( const SvxFieldItem& rField, sal_Int32 nPara, sal_Int32 nPos ) override;
 
     virtual bool            IsValid() const override;
diff --git a/include/editeng/unoedsrc.hxx b/include/editeng/unoedsrc.hxx
index 026f887f0c41..c4077bccc758 100644
--- a/include/editeng/unoedsrc.hxx
+++ b/include/editeng/unoedsrc.hxx
@@ -155,7 +155,7 @@ public:
     virtual void        QuickSetAttribs( const SfxItemSet& rSet, const ESelection& rSel ) = 0;
     virtual void        QuickInsertLineBreak( const ESelection& rSel ) = 0;
 
-    virtual OUString    CalcFieldValue( const SvxFieldItem& rField, sal_Int32 nPara, sal_Int32 nPos, Color*& rpTxtColor, Color*& rpFldColor ) = 0;
+    virtual OUString    CalcFieldValue( const SvxFieldItem& rField, sal_Int32 nPara, sal_Int32 nPos, boost::optional<Color>& rpTxtColor, boost::optional<Color>& rpFldColor ) = 0;
     virtual void         FieldClicked( const SvxFieldItem& rField, sal_Int32 nPara, sal_Int32 nPos ) = 0;
 
     virtual SfxItemPool* GetPool() const = 0;
diff --git a/include/editeng/unofored.hxx b/include/editeng/unofored.hxx
index c450598f1c1c..58ae00896756 100644
--- a/include/editeng/unofored.hxx
+++ b/include/editeng/unofored.hxx
@@ -54,7 +54,7 @@ public:
 
     virtual SfxItemPool* GetPool() const override;
 
-    virtual OUString     CalcFieldValue( const SvxFieldItem& rField, sal_Int32 nPara, sal_Int32 nPos, Color*& rpTxtColor, Color*& rpFldColor ) override;
+    virtual OUString     CalcFieldValue( const SvxFieldItem& rField, sal_Int32 nPara, sal_Int32 nPos, boost::optional<Color>& rpTxtColor, boost::optional<Color>& rpFldColor ) override;
     virtual void         FieldClicked( const SvxFieldItem& rField, sal_Int32 nPara, sal_Int32 nPos ) override;
     virtual bool         IsValid() const override;
 
diff --git a/include/editeng/unoforou.hxx b/include/editeng/unoforou.hxx
index a26fc406c220..b04fdcdb59f5 100644
--- a/include/editeng/unoforou.hxx
+++ b/include/editeng/unoforou.hxx
@@ -72,7 +72,7 @@ public:
 
     virtual SfxItemPool* GetPool() const override;
 
-    virtual OUString    CalcFieldValue( const SvxFieldItem& rField, sal_Int32 nPara, sal_Int32 nPos, Color*& rpTxtColor, Color*& rpFldColor ) override;
+    virtual OUString    CalcFieldValue( const SvxFieldItem& rField, sal_Int32 nPara, sal_Int32 nPos, boost::optional<Color>& rpTxtColor, boost::optional<Color>& rpFldColor ) override;
     virtual void        FieldClicked( const SvxFieldItem& rField, sal_Int32 nPara, sal_Int32 nPos ) override;
 
     virtual bool        IsValid() const override;
diff --git a/include/editeng/unotext.hxx b/include/editeng/unotext.hxx
index ca263071bf98..3c94d3675e61 100644
--- a/include/editeng/unotext.hxx
+++ b/include/editeng/unotext.hxx
@@ -196,7 +196,7 @@ public:
     virtual void            QuickSetAttribs( const SfxItemSet& rSet, const ESelection& rSel ) override;
     virtual void            QuickInsertLineBreak( const ESelection& rSel ) override;
 
-    virtual OUString        CalcFieldValue( const SvxFieldItem& rField, sal_Int32 nPara, sal_Int32 nPos, Color*& rpTxtColor, Color*& rpFldColor ) override;
+    virtual OUString        CalcFieldValue( const SvxFieldItem& rField, sal_Int32 nPara, sal_Int32 nPos, boost::optional<Color>& rpTxtColor, boost::optional<Color>& rpFldColor ) override;
     virtual void            FieldClicked( const SvxFieldItem& rField, sal_Int32 nPara, sal_Int32 nPos ) override;
 
     virtual bool            IsValid() const override;
diff --git a/include/svx/ClassificationEditView.hxx b/include/svx/ClassificationEditView.hxx
index cc2a30df78db..beb2fbc75a1e 100644
--- a/include/svx/ClassificationEditView.hxx
+++ b/include/svx/ClassificationEditView.hxx
@@ -27,7 +27,7 @@ class ClassificationEditEngine : public EditEngine
 public:
     ClassificationEditEngine(SfxItemPool* pItemPool);
 
-    virtual OUString CalcFieldValue(const SvxFieldItem& rField, sal_Int32 nPara, sal_Int32 nPos, Color*& rTxtColor, Color*& rFldColor) override;
+    virtual OUString CalcFieldValue(const SvxFieldItem& rField, sal_Int32 nPara, sal_Int32 nPos, boost::optional<Color>& rTxtColor, boost::optional<Color>& rFldColor) override;
 };
 
 class SVX_DLLPUBLIC ClassificationEditView : public Control
diff --git a/include/svx/svdomeas.hxx b/include/svx/svdomeas.hxx
index 8b1a79797b30..72abb9abefcd 100644
--- a/include/svx/svdomeas.hxx
+++ b/include/svx/svdomeas.hxx
@@ -140,7 +140,7 @@ public:
     virtual OutlinerParaObject* GetOutlinerParaObject() const override;
 
     virtual bool CalcFieldValue(const SvxFieldItem& rField, sal_Int32 nPara, sal_uInt16 nPos,
-        bool bEdit, Color*& rpTxtColor, Color*& rpFldColor, OUString& rRet) const override;
+        bool bEdit, boost::optional<Color>& rpTxtColor, boost::optional<Color>& rpFldColor, OUString& rRet) const override;
 
     // #i97878#
     virtual bool TRGetBaseGeometry(basegfx::B2DHomMatrix& rMatrix, basegfx::B2DPolyPolygon& rPolyPolygon) const override;
diff --git a/include/svx/svdotext.hxx b/include/svx/svdotext.hxx
index e0b9bbe434ba..daa749d2bf08 100644
--- a/include/svx/svdotext.hxx
+++ b/include/svx/svdotext.hxx
@@ -496,7 +496,7 @@ public:
     virtual void ReformatText() override;
 
     virtual bool CalcFieldValue(const SvxFieldItem& rField, sal_Int32 nPara, sal_uInt16 nPos,
-        bool bEdit, Color*& rpTxtColor, Color*& rpFldColor, OUString& rRet) const;
+        bool bEdit, boost::optional<Color>& rpTxtColor, boost::optional<Color>& rpFldColor, OUString& rRet) const;
 
     virtual SdrObject* DoConvertToPolyObj(bool bBezier, bool bAddText) const override;
 
diff --git a/include/svx/svdoutl.hxx b/include/svx/svdoutl.hxx
index c1ec4636dff6..61f889ebd57a 100644
--- a/include/svx/svdoutl.hxx
+++ b/include/svx/svdoutl.hxx
@@ -44,7 +44,7 @@ public:
     void setVisualizedPage(const SdrPage* pPage) { if(pPage != mpVisualizedPage) mpVisualizedPage = pPage; }
     const SdrPage* getVisualizedPage() const { return mpVisualizedPage; }
 
-    virtual OUString CalcFieldValue(const SvxFieldItem& rField, sal_Int32 nPara, sal_Int32 nPos, Color*& rpTxtColor, Color*& rpFldColor) override;
+    virtual OUString CalcFieldValue(const SvxFieldItem& rField, sal_Int32 nPara, sal_Int32 nPos, boost::optional<Color>& rpTxtColor, boost::optional<Color>& rpFldColor) override;
 
     bool hasEditViewCallbacks() const;
 };
diff --git a/sc/inc/editutil.hxx b/sc/inc/editutil.hxx
index f70453bdec40..1e06b7b9c3d4 100644
--- a/sc/inc/editutil.hxx
+++ b/sc/inc/editutil.hxx
@@ -75,7 +75,7 @@ public:
     static std::unique_ptr<EditTextObject> Clone( const EditTextObject& rSrc, ScDocument& rDestDoc );
 
     static OUString GetCellFieldValue(
-        const SvxFieldData& rFieldData, const ScDocument* pDoc, Color** ppTextColor );
+        const SvxFieldData& rFieldData, const ScDocument* pDoc, boost::optional<Color>* ppTextColor );
 
 public:
                 ScEditUtil( ScDocument* pDocument, SCCOL nX, SCROW nY, SCTAB nZ,
@@ -214,7 +214,7 @@ public:
     void SetExecuteURL(bool bSet)    { bExecuteURL = bSet; }
 
     virtual void    FieldClicked( const SvxFieldItem& rField, sal_Int32, sal_Int32 ) override;
-    virtual OUString CalcFieldValue( const SvxFieldItem& rField, sal_Int32 nPara, sal_Int32 nPos, Color*& rTxtColor, Color*& rFldColor ) override;
+    virtual OUString CalcFieldValue( const SvxFieldItem& rField, sal_Int32 nPara, sal_Int32 nPos, boost::optional<Color>& rTxtColor, boost::optional<Color>& rFldColor ) override;
 };
 
 // for headers/footers with fields
@@ -225,7 +225,7 @@ private:
 
 public:
     ScHeaderEditEngine( SfxItemPool* pEnginePool );
-    virtual OUString CalcFieldValue( const SvxFieldItem& rField, sal_Int32 nPara, sal_Int32 nPos, Color*& rTxtColor, Color*& rFldColor ) override;
+    virtual OUString CalcFieldValue( const SvxFieldItem& rField, sal_Int32 nPara, sal_Int32 nPos, boost::optional<Color>& rTxtColor, boost::optional<Color>& rFldColor ) override;
 
     void SetNumType(SvxNumType eNew)                { aData.eNumType = eNew; }
     void SetData(const ScHeaderFieldData& rNew)     { aData = rNew; }
diff --git a/sc/source/core/tool/editutil.cxx b/sc/source/core/tool/editutil.cxx
index 4ce542a51b20..e56a1b2ca437 100644
--- a/sc/source/core/tool/editutil.cxx
+++ b/sc/source/core/tool/editutil.cxx
@@ -191,7 +191,7 @@ std::unique_ptr<EditTextObject> ScEditUtil::Clone( const EditTextObject& rObj, S
 }
 
 OUString ScEditUtil::GetCellFieldValue(
-    const SvxFieldData& rFieldData, const ScDocument* pDoc, Color** ppTextColor )
+    const SvxFieldData& rFieldData, const ScDocument* pDoc, boost::optional<Color>* ppTextColor )
 {
     OUString aRet;
     switch (rFieldData.GetClassId())
@@ -218,7 +218,7 @@ OUString ScEditUtil::GetCellFieldValue(
                 INetURLHistory::GetOrCreate()->QueryUrl(aURL) ? svtools::LINKSVISITED : svtools::LINKS;
 
             if (ppTextColor)
-                *ppTextColor = new Color( SC_MOD()->GetColorConfig().GetColorValue(eEntry).nColor );
+                *ppTextColor = SC_MOD()->GetColorConfig().GetColorValue(eEntry).nColor;
         }
         break;
         case text::textfield::Type::EXTENDED_TIME:
@@ -796,7 +796,7 @@ ScHeaderEditEngine::ScHeaderEditEngine( SfxItemPool* pEnginePoolP )
 
 OUString ScHeaderEditEngine::CalcFieldValue( const SvxFieldItem& rField,
                                     sal_Int32 /* nPara */, sal_Int32 /* nPos */,
-                                    Color*& /* rTxtColor */, Color*& /* rFldColor */ )
+                                    boost::optional<Color>& /* rTxtColor */, boost::optional<Color>& /* rFldColor */ )
 {
     const SvxFieldData* pFieldData = rField.GetField();
     if (!pFieldData)
@@ -860,7 +860,7 @@ ScFieldEditEngine::ScFieldEditEngine(
 
 OUString ScFieldEditEngine::CalcFieldValue( const SvxFieldItem& rField,
                                     sal_Int32 /* nPara */, sal_Int32 /* nPos */,
-                                    Color*& rTxtColor, Color*& /* rFldColor */ )
+                                    boost::optional<Color>& rTxtColor, boost::optional<Color>& /* rFldColor */ )
 {
     const SvxFieldData* pFieldData = rField.GetField();
 
diff --git a/sc/source/ui/pagedlg/scuitphfedit.cxx b/sc/source/ui/pagedlg/scuitphfedit.cxx
index 3d1192b7f7fc..46d94e7d751d 100644
--- a/sc/source/ui/pagedlg/scuitphfedit.cxx
+++ b/sc/source/ui/pagedlg/scuitphfedit.cxx
@@ -231,8 +231,8 @@ void ScHFEditPage::InitPreDefinedList()
 {
     SvtUserOptions aUserOpt;
 
-    Color* pTxtColour = nullptr;
-    Color* pFldColour = nullptr;
+    boost::optional<Color> pTxtColour;
+    boost::optional<Color> pFldColour;
 
     // Get the all field values at the outset.
     OUString aPageFieldValue(m_pWndLeft->GetEditEngine()->CalcFieldValue(SvxFieldItem(SvxPageField(), EE_FEATURE_FIELD), 0,0, pTxtColour, pFldColour));
diff --git a/sc/source/ui/unoobj/fielduno.cxx b/sc/source/ui/unoobj/fielduno.cxx
index eeda77b2e53c..4b33ea74f000 100644
--- a/sc/source/ui/unoobj/fielduno.cxx
+++ b/sc/source/ui/unoobj/fielduno.cxx
@@ -177,7 +177,7 @@ public:
     explicit ScUnoEditEngine(ScEditEngineDefaulter* pSource);
 
     virtual OUString  CalcFieldValue( const SvxFieldItem& rField, sal_Int32 nPara, sal_Int32 nPos,
-                                    Color*& rTxtColor, Color*& rFldColor ) override;
+                                   boost::optional<Color>& rTxtColor, boost::optional<Color>& rFldColor ) override;
 
     sal_uInt16 CountFields();
     SvxFieldData* FindByIndex(sal_uInt16 nIndex);
@@ -202,7 +202,7 @@ ScUnoEditEngine::ScUnoEditEngine(ScEditEngineDefaulter* pSource)
 }
 
 OUString ScUnoEditEngine::CalcFieldValue( const SvxFieldItem& rField,
-            sal_Int32 nPara, sal_Int32 nPos, Color*& rTxtColor, Color*& rFldColor )
+            sal_Int32 nPara, sal_Int32 nPos, boost::optional<Color>& rTxtColor, boost::optional<Color>& rFldColor )
 {
     OUString aRet(EditEngine::CalcFieldValue( rField, nPara, nPos, rTxtColor, rFldColor ));
     if (eMode != SC_UNO_COLLECT_NONE)
diff --git a/starmath/source/accessibility.cxx b/starmath/source/accessibility.cxx
index 9b2bf3a3b97b..988931c5a540 100644
--- a/starmath/source/accessibility.cxx
+++ b/starmath/source/accessibility.cxx
@@ -1023,7 +1023,7 @@ bool SmTextForwarder::IsValid() const
     return pEditEngine && pEditEngine->GetUpdateMode();
 }
 
-OUString SmTextForwarder::CalcFieldValue( const SvxFieldItem& rField, sal_Int32 nPara, sal_Int32 nPos, Color*& rpTxtColor, Color*& rpFldColor )
+OUString SmTextForwarder::CalcFieldValue( const SvxFieldItem& rField, sal_Int32 nPara, sal_Int32 nPos, boost::optional<Color>& rpTxtColor, boost::optional<Color>& rpFldColor )
 {
     EditEngine *pEditEngine = rEditAcc.GetEditEngine();
     return pEditEngine ? pEditEngine->CalcFieldValue(rField, nPara, nPos, rpTxtColor, rpFldColor) : OUString();
diff --git a/starmath/source/accessibility.hxx b/starmath/source/accessibility.hxx
index 2dc092af1099..9c669e51f177 100644
--- a/starmath/source/accessibility.hxx
+++ b/starmath/source/accessibility.hxx
@@ -201,7 +201,7 @@ public:
 
     virtual SfxItemPool* GetPool() const override;
 
-    virtual OUString        CalcFieldValue( const SvxFieldItem& rField, sal_Int32 nPara, sal_Int32 nPos, Color*& rpTxtColor, Color*& rpFldColor ) override;
+    virtual OUString        CalcFieldValue( const SvxFieldItem& rField, sal_Int32 nPara, sal_Int32 nPos, boost::optional<Color>& rpTxtColor, boost::optional<Color>& rpFldColor ) override;
     virtual void            FieldClicked(const SvxFieldItem&, sal_Int32, sal_Int32) override;
     virtual bool            IsValid() const override;
 
diff --git a/svx/source/accessibility/AccessibleEmptyEditSource.cxx b/svx/source/accessibility/AccessibleEmptyEditSource.cxx
index f42ba7221187..0b87947ce329 100644
--- a/svx/source/accessibility/AccessibleEmptyEditSource.cxx
+++ b/svx/source/accessibility/AccessibleEmptyEditSource.cxx
@@ -120,7 +120,7 @@ namespace accessibility
         //XTextCopy
         void        CopyText(const SvxTextForwarder& ) override {}
 
-        OUString    CalcFieldValue( const SvxFieldItem& /*rField*/, sal_Int32 /*nPara*/, sal_Int32 /*nPos*/, Color*& /*rpTxtColor*/, Color*& /*rpFldColor*/ ) override
+        OUString    CalcFieldValue( const SvxFieldItem& /*rField*/, sal_Int32 /*nPara*/, sal_Int32 /*nPos*/, boost::optional<Color>& /*rpTxtColor*/, boost::optional<Color>& /*rpFldColor*/ ) override
         {
             return  OUString();
         }
diff --git a/svx/source/dialog/ClassificationEditView.cxx b/svx/source/dialog/ClassificationEditView.cxx
index aad04dcfd8ac..3fda7b5dc6c9 100644
--- a/svx/source/dialog/ClassificationEditView.cxx
+++ b/svx/source/dialog/ClassificationEditView.cxx
@@ -29,7 +29,7 @@ ClassificationEditEngine::ClassificationEditEngine(SfxItemPool* pItemPool)
 {}
 
 OUString ClassificationEditEngine::CalcFieldValue(const SvxFieldItem& rField, sal_Int32 /*nPara*/,
-                                                  sal_Int32 /*nPos*/, Color*& /*rTxtColor*/, Color*& /*rFldColor*/)
+                                                  sal_Int32 /*nPos*/, boost::optional<Color>& /*rTxtColor*/, boost::optional<Color>& /*rFldColor*/)
 {
     OUString aString;
     const ClassificationField* pClassificationField = dynamic_cast<const ClassificationField*>(rField.GetField());
diff --git a/svx/source/svdraw/svdedxv.cxx b/svx/source/svdraw/svdedxv.cxx
index bab1f5e71898..93d317ff0fbf 100644
--- a/svx/source/svdraw/svdedxv.cxx
+++ b/svx/source/svdraw/svdedxv.cxx
@@ -975,17 +975,15 @@ IMPL_LINK(SdrObjEditView,ImpOutlinerCalcFieldValueHdl,EditFieldInfo*,pFI,void)
     rStr.clear();
     SdrTextObj* pTextObj = mxTextEditObj.get();
     if (pTextObj!=nullptr) {
-        Color* pTxtCol=nullptr;
-        Color* pFldCol=nullptr;
+        boost::optional<Color> pTxtCol;
+        boost::optional<Color> pFldCol;
         bOk=pTextObj->CalcFieldValue(pFI->GetField(),pFI->GetPara(),pFI->GetPos(),true,pTxtCol,pFldCol,rStr);
         if (bOk) {
-            if (pTxtCol!=nullptr) {
+            if (pTxtCol) {
                 pFI->SetTextColor(*pTxtCol);
-                delete pTxtCol;
             }
-            if (pFldCol!=nullptr) {
+            if (pFldCol) {
                 pFI->SetFieldColor(*pFldCol);
-                delete pFldCol;
             } else {
                 pFI->SetFieldColor(COL_LIGHTGRAY); // TODO: remove this later on (357)
             }
diff --git a/svx/source/svdraw/svdomeas.cxx b/svx/source/svdraw/svdomeas.cxx
index a7cbdda2297d..918b6fd4ebce 100644
--- a/svx/source/svdraw/svdomeas.cxx
+++ b/svx/source/svdraw/svdomeas.cxx
@@ -549,18 +549,15 @@ basegfx::B2DPolyPolygon SdrMeasureObj::ImpCalcXPoly(const ImpMeasurePoly& rPol)
 
 bool SdrMeasureObj::CalcFieldValue(const SvxFieldItem& rField, sal_Int32 nPara, sal_uInt16 nPos,
     bool bEdit,
-    Color*& rpTxtColor, Color*& rpFldColor, OUString& rRet) const
+    boost::optional<Color>& rpTxtColor, boost::optional<Color>& rpFldColor, OUString& rRet) const
 {
     const SvxFieldData* pField=rField.GetField();
     const SdrMeasureField* pMeasureField=dynamic_cast<const SdrMeasureField*>( pField );
     if (pMeasureField!=nullptr) {
         rRet = TakeRepresentation(pMeasureField->GetMeasureFieldKind());
-        if (rpFldColor!=nullptr) {
-            if (!bEdit)
-            {
-                delete rpFldColor;
-                rpFldColor=nullptr;
-            }
+        if (rpFldColor && !bEdit)
+        {
+            rpFldColor.reset();
         }
         return true;
     } else {
diff --git a/svx/source/svdraw/svdotxfl.cxx b/svx/source/svdraw/svdotxfl.cxx
index 4fe84291dc80..c8e82711b6a3 100644
--- a/svx/source/svdraw/svdotxfl.cxx
+++ b/svx/source/svdraw/svdotxfl.cxx
@@ -22,7 +22,7 @@
 #include <svx/svdotext.hxx>
 
 bool SdrTextObj::CalcFieldValue(const SvxFieldItem& /*rField*/, sal_Int32 /*nPara*/, sal_uInt16 /*nPos*/,
-    bool /*bEdit*/, Color*& /*rpTxtColor*/, Color*& /*rpFldColor*/, OUString& /*rRet*/) const
+    bool /*bEdit*/, boost::optional<Color>& /*rpTxtColor*/, boost::optional<Color>& /*rpFldColor*/, OUString& /*rRet*/) const
 {
     return false;
 }
diff --git a/svx/source/svdraw/svdoutl.cxx b/svx/source/svdraw/svdoutl.cxx
index bebb82b76c54..c2befff17c15 100644
--- a/svx/source/svdraw/svdoutl.cxx
+++ b/svx/source/svdraw/svdoutl.cxx
@@ -72,7 +72,7 @@ void SdrOutliner::SetTextObjNoInit( const SdrTextObj* pObj )
 }
 
 OUString SdrOutliner::CalcFieldValue(const SvxFieldItem& rField, sal_Int32 nPara, sal_Int32 nPos,
-                                     Color*& rpTxtColor, Color*& rpFldColor)
+                                     boost::optional<Color>& rpTxtColor, boost::optional<Color>& rpFldColor)
 {
     bool bOk = false;
     OUString aRet;


More information about the Libreoffice-commits mailing list