summaryrefslogtreecommitdiff
path: root/editeng
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2018-05-09 12:17:08 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2018-05-10 08:42:37 +0200
commit5c9ae702b42745bf6963d1cbb4e779b66ade0825 (patch)
tree323545cbc5386b483067030b66cf5ca07bc25e45 /editeng
parentc5f8a296fcfc08f8ac441cb8300a7565caa50b53 (diff)
store Color using boost::optional in EditCharAttribField
Change-Id: If4af5991be51cdb035c0bc0fb7668844df703073 Reviewed-on: https://gerrit.libreoffice.org/54022 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'editeng')
-rw-r--r--editeng/inc/editattr.hxx11
-rw-r--r--editeng/qa/unit/core-test.cxx2
-rw-r--r--editeng/source/editeng/editattr.cxx26
-rw-r--r--editeng/source/editeng/editeng.cxx2
-rw-r--r--editeng/source/editeng/impedit2.cxx2
-rw-r--r--editeng/source/outliner/outleeng.cxx2
-rw-r--r--editeng/source/outliner/outleeng.hxx2
-rw-r--r--editeng/source/outliner/outliner.cxx11
-rw-r--r--editeng/source/uno/unoedprx.cxx2
-rw-r--r--editeng/source/uno/unofored.cxx2
-rw-r--r--editeng/source/uno/unoforou.cxx2
-rw-r--r--editeng/source/uno/unotext.cxx9
12 files changed, 35 insertions, 38 deletions
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@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();
}