summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThorsten Behrens <Thorsten.Behrens@CIB.de>2015-05-24 12:41:24 +0200
committerThorsten Behrens <Thorsten.Behrens@CIB.de>2015-05-24 21:49:53 +0200
commit6a42657fa9afc93c3e4b7afc0c00c0de8e704169 (patch)
tree13c380b26e357764fe2f9dd98669a05d012a4888
parent551c204740a37c8dbc7acd35bc9fe683ade3fe80 (diff)
tdf#62525: use cow_wrapper for SdrFormTextAttribute
Change-Id: I0fd55ea6c775d771e001c0db78bb72c50e9b81cf
-rw-r--r--include/svx/sdr/attribute/sdrformtextattribute.hxx7
-rw-r--r--svx/source/sdr/attribute/sdrformtextattribute.cxx73
2 files changed, 20 insertions, 60 deletions
diff --git a/include/svx/sdr/attribute/sdrformtextattribute.hxx b/include/svx/sdr/attribute/sdrformtextattribute.hxx
index 970fbb50872c..466b95ee37db 100644
--- a/include/svx/sdr/attribute/sdrformtextattribute.hxx
+++ b/include/svx/sdr/attribute/sdrformtextattribute.hxx
@@ -23,7 +23,7 @@
#include <sal/types.h>
#include <svx/xenum.hxx>
#include <tools/color.hxx>
-
+#include <o3tl/cow_wrapper.hxx>
// predefines
@@ -42,8 +42,11 @@ namespace drawinglayer
{
class SdrFormTextAttribute
{
+ public:
+ typedef o3tl::cow_wrapper< ImpSdrFormTextAttribute > ImplType;
+
private:
- ImpSdrFormTextAttribute* mpSdrFormTextAttribute;
+ ImplType mpSdrFormTextAttribute;
public:
/// constructors/assignmentoperator/destructor
diff --git a/svx/source/sdr/attribute/sdrformtextattribute.cxx b/svx/source/sdr/attribute/sdrformtextattribute.cxx
index 221019184a77..03af4df32def 100644
--- a/svx/source/sdr/attribute/sdrformtextattribute.cxx
+++ b/svx/source/sdr/attribute/sdrformtextattribute.cxx
@@ -45,6 +45,7 @@
#include <sdr/attribute/sdrformtextoutlineattribute.hxx>
#include <com/sun/star/drawing/LineCap.hpp>
#include <com/sun/star/drawing/LineStyle.hpp>
+#include <rtl/instance.hxx>
// helper to get line, stroke and transparence attributes from SfxItemSet
@@ -150,9 +151,6 @@ namespace drawinglayer
class ImpSdrFormTextAttribute
{
public:
- // refcounter
- sal_uInt32 mnRefCount;
-
// FormText (FontWork) Attributes
sal_Int32 mnFormTextDistance; // distance from line in upright direction
sal_Int32 mnFormTextStart; // shift from polygon start
@@ -174,8 +172,7 @@ namespace drawinglayer
bool mbFormTextOutline : 1; // show contour of objects
explicit ImpSdrFormTextAttribute(const SfxItemSet& rSet)
- : mnRefCount(0),
- mnFormTextDistance(static_cast<const XFormTextDistanceItem&>(rSet.Get(XATTR_FORMTXTDISTANCE)).GetValue()),
+ : mnFormTextDistance(static_cast<const XFormTextDistanceItem&>(rSet.Get(XATTR_FORMTXTDISTANCE)).GetValue()),
mnFormTextStart(static_cast<const XFormTextStartItem&>(rSet.Get(XATTR_FORMTXTSTART)).GetValue()),
mnFormTextShdwXVal(static_cast<const XFormTextShadowXValItem&>(rSet.Get(XATTR_FORMTXTSHDWXVAL)).GetValue()),
mnFormTextShdwYVal(static_cast<const XFormTextShadowYValItem&>(rSet.Get(XATTR_FORMTXTSHDWYVAL)).GetValue()),
@@ -215,8 +212,7 @@ namespace drawinglayer
}
ImpSdrFormTextAttribute()
- : mnRefCount(0),
- mnFormTextDistance(0),
+ : mnFormTextDistance(0),
mnFormTextStart(0),
mnFormTextShdwXVal(0),
mnFormTextShdwYVal(0),
@@ -264,90 +260,51 @@ namespace drawinglayer
&& getFormTextMirror() == rCandidate.getFormTextMirror()
&& getFormTextOutline() == rCandidate.getFormTextOutline());
}
-
- static ImpSdrFormTextAttribute* get_global_default()
- {
- static ImpSdrFormTextAttribute* pDefault = 0;
-
- if(!pDefault)
- {
- pDefault = new ImpSdrFormTextAttribute();
-
- // never delete; start with RefCount 1, not 0
- pDefault->mnRefCount++;
- }
-
- return pDefault;
- }
};
+ namespace
+ {
+ struct theGlobalDefault :
+ public rtl::Static< SdrFormTextAttribute::ImplType, theGlobalDefault > {};
+ }
+
SdrFormTextAttribute::SdrFormTextAttribute(const SfxItemSet& rSet)
- : mpSdrFormTextAttribute(new ImpSdrFormTextAttribute(rSet))
+ : mpSdrFormTextAttribute(ImpSdrFormTextAttribute(rSet))
{
}
SdrFormTextAttribute::SdrFormTextAttribute()
- : mpSdrFormTextAttribute(ImpSdrFormTextAttribute::get_global_default())
+ : mpSdrFormTextAttribute(theGlobalDefault::get())
{
- mpSdrFormTextAttribute->mnRefCount++;
}
SdrFormTextAttribute::SdrFormTextAttribute(const SdrFormTextAttribute& rCandidate)
: mpSdrFormTextAttribute(rCandidate.mpSdrFormTextAttribute)
{
- mpSdrFormTextAttribute->mnRefCount++;
}
SdrFormTextAttribute::~SdrFormTextAttribute()
{
- if(mpSdrFormTextAttribute->mnRefCount)
- {
- mpSdrFormTextAttribute->mnRefCount--;
- }
- else
- {
- delete mpSdrFormTextAttribute;
- }
}
bool SdrFormTextAttribute::isDefault() const
{
- return mpSdrFormTextAttribute == ImpSdrFormTextAttribute::get_global_default();
+ return mpSdrFormTextAttribute.same_object(theGlobalDefault::get());
}
SdrFormTextAttribute& SdrFormTextAttribute::operator=(const SdrFormTextAttribute& rCandidate)
{
- if(rCandidate.mpSdrFormTextAttribute != mpSdrFormTextAttribute)
- {
- if(mpSdrFormTextAttribute->mnRefCount)
- {
- mpSdrFormTextAttribute->mnRefCount--;
- }
- else
- {
- delete mpSdrFormTextAttribute;
- }
-
- mpSdrFormTextAttribute = rCandidate.mpSdrFormTextAttribute;
- mpSdrFormTextAttribute->mnRefCount++;
- }
-
+ mpSdrFormTextAttribute = rCandidate.mpSdrFormTextAttribute;
return *this;
}
bool SdrFormTextAttribute::operator==(const SdrFormTextAttribute& rCandidate) const
{
- if(rCandidate.mpSdrFormTextAttribute == mpSdrFormTextAttribute)
- {
- return true;
- }
-
+ // tdf#87509 default attr is always != non-default attr, even with same values
if(rCandidate.isDefault() != isDefault())
- {
return false;
- }
- return (*rCandidate.mpSdrFormTextAttribute == *mpSdrFormTextAttribute);
+ return rCandidate.mpSdrFormTextAttribute == mpSdrFormTextAttribute;
}
sal_Int32 SdrFormTextAttribute::getFormTextDistance() const