Kaydet (Commit) 6a42657f authored tarafından Thorsten Behrens's avatar Thorsten Behrens

tdf#62525: use cow_wrapper for SdrFormTextAttribute

Change-Id: I0fd55ea6c775d771e001c0db78bb72c50e9b81cf
üst 551c2047
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
#include <sal/types.h> #include <sal/types.h>
#include <svx/xenum.hxx> #include <svx/xenum.hxx>
#include <tools/color.hxx> #include <tools/color.hxx>
#include <o3tl/cow_wrapper.hxx>
// predefines // predefines
...@@ -42,8 +42,11 @@ namespace drawinglayer ...@@ -42,8 +42,11 @@ namespace drawinglayer
{ {
class SdrFormTextAttribute class SdrFormTextAttribute
{ {
public:
typedef o3tl::cow_wrapper< ImpSdrFormTextAttribute > ImplType;
private: private:
ImpSdrFormTextAttribute* mpSdrFormTextAttribute; ImplType mpSdrFormTextAttribute;
public: public:
/// constructors/assignmentoperator/destructor /// constructors/assignmentoperator/destructor
......
...@@ -45,6 +45,7 @@ ...@@ -45,6 +45,7 @@
#include <sdr/attribute/sdrformtextoutlineattribute.hxx> #include <sdr/attribute/sdrformtextoutlineattribute.hxx>
#include <com/sun/star/drawing/LineCap.hpp> #include <com/sun/star/drawing/LineCap.hpp>
#include <com/sun/star/drawing/LineStyle.hpp> #include <com/sun/star/drawing/LineStyle.hpp>
#include <rtl/instance.hxx>
// helper to get line, stroke and transparence attributes from SfxItemSet // helper to get line, stroke and transparence attributes from SfxItemSet
...@@ -150,9 +151,6 @@ namespace drawinglayer ...@@ -150,9 +151,6 @@ namespace drawinglayer
class ImpSdrFormTextAttribute class ImpSdrFormTextAttribute
{ {
public: public:
// refcounter
sal_uInt32 mnRefCount;
// FormText (FontWork) Attributes // FormText (FontWork) Attributes
sal_Int32 mnFormTextDistance; // distance from line in upright direction sal_Int32 mnFormTextDistance; // distance from line in upright direction
sal_Int32 mnFormTextStart; // shift from polygon start sal_Int32 mnFormTextStart; // shift from polygon start
...@@ -174,8 +172,7 @@ namespace drawinglayer ...@@ -174,8 +172,7 @@ namespace drawinglayer
bool mbFormTextOutline : 1; // show contour of objects bool mbFormTextOutline : 1; // show contour of objects
explicit ImpSdrFormTextAttribute(const SfxItemSet& rSet) 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()), mnFormTextStart(static_cast<const XFormTextStartItem&>(rSet.Get(XATTR_FORMTXTSTART)).GetValue()),
mnFormTextShdwXVal(static_cast<const XFormTextShadowXValItem&>(rSet.Get(XATTR_FORMTXTSHDWXVAL)).GetValue()), mnFormTextShdwXVal(static_cast<const XFormTextShadowXValItem&>(rSet.Get(XATTR_FORMTXTSHDWXVAL)).GetValue()),
mnFormTextShdwYVal(static_cast<const XFormTextShadowYValItem&>(rSet.Get(XATTR_FORMTXTSHDWYVAL)).GetValue()), mnFormTextShdwYVal(static_cast<const XFormTextShadowYValItem&>(rSet.Get(XATTR_FORMTXTSHDWYVAL)).GetValue()),
...@@ -215,8 +212,7 @@ namespace drawinglayer ...@@ -215,8 +212,7 @@ namespace drawinglayer
} }
ImpSdrFormTextAttribute() ImpSdrFormTextAttribute()
: mnRefCount(0), : mnFormTextDistance(0),
mnFormTextDistance(0),
mnFormTextStart(0), mnFormTextStart(0),
mnFormTextShdwXVal(0), mnFormTextShdwXVal(0),
mnFormTextShdwYVal(0), mnFormTextShdwYVal(0),
...@@ -264,90 +260,51 @@ namespace drawinglayer ...@@ -264,90 +260,51 @@ namespace drawinglayer
&& getFormTextMirror() == rCandidate.getFormTextMirror() && getFormTextMirror() == rCandidate.getFormTextMirror()
&& getFormTextOutline() == rCandidate.getFormTextOutline()); && getFormTextOutline() == rCandidate.getFormTextOutline());
} }
};
static ImpSdrFormTextAttribute* get_global_default() namespace
{
static ImpSdrFormTextAttribute* pDefault = 0;
if(!pDefault)
{ {
pDefault = new ImpSdrFormTextAttribute(); struct theGlobalDefault :
public rtl::Static< SdrFormTextAttribute::ImplType, theGlobalDefault > {};
// never delete; start with RefCount 1, not 0
pDefault->mnRefCount++;
}
return pDefault;
} }
};
SdrFormTextAttribute::SdrFormTextAttribute(const SfxItemSet& rSet) SdrFormTextAttribute::SdrFormTextAttribute(const SfxItemSet& rSet)
: mpSdrFormTextAttribute(new ImpSdrFormTextAttribute(rSet)) : mpSdrFormTextAttribute(ImpSdrFormTextAttribute(rSet))
{ {
} }
SdrFormTextAttribute::SdrFormTextAttribute() SdrFormTextAttribute::SdrFormTextAttribute()
: mpSdrFormTextAttribute(ImpSdrFormTextAttribute::get_global_default()) : mpSdrFormTextAttribute(theGlobalDefault::get())
{ {
mpSdrFormTextAttribute->mnRefCount++;
} }
SdrFormTextAttribute::SdrFormTextAttribute(const SdrFormTextAttribute& rCandidate) SdrFormTextAttribute::SdrFormTextAttribute(const SdrFormTextAttribute& rCandidate)
: mpSdrFormTextAttribute(rCandidate.mpSdrFormTextAttribute) : mpSdrFormTextAttribute(rCandidate.mpSdrFormTextAttribute)
{ {
mpSdrFormTextAttribute->mnRefCount++;
} }
SdrFormTextAttribute::~SdrFormTextAttribute() SdrFormTextAttribute::~SdrFormTextAttribute()
{ {
if(mpSdrFormTextAttribute->mnRefCount)
{
mpSdrFormTextAttribute->mnRefCount--;
}
else
{
delete mpSdrFormTextAttribute;
}
} }
bool SdrFormTextAttribute::isDefault() const bool SdrFormTextAttribute::isDefault() const
{ {
return mpSdrFormTextAttribute == ImpSdrFormTextAttribute::get_global_default(); return mpSdrFormTextAttribute.same_object(theGlobalDefault::get());
} }
SdrFormTextAttribute& SdrFormTextAttribute::operator=(const SdrFormTextAttribute& rCandidate) SdrFormTextAttribute& SdrFormTextAttribute::operator=(const SdrFormTextAttribute& rCandidate)
{ {
if(rCandidate.mpSdrFormTextAttribute != mpSdrFormTextAttribute)
{
if(mpSdrFormTextAttribute->mnRefCount)
{
mpSdrFormTextAttribute->mnRefCount--;
}
else
{
delete mpSdrFormTextAttribute;
}
mpSdrFormTextAttribute = rCandidate.mpSdrFormTextAttribute; mpSdrFormTextAttribute = rCandidate.mpSdrFormTextAttribute;
mpSdrFormTextAttribute->mnRefCount++;
}
return *this; return *this;
} }
bool SdrFormTextAttribute::operator==(const SdrFormTextAttribute& rCandidate) const bool SdrFormTextAttribute::operator==(const SdrFormTextAttribute& rCandidate) const
{ {
if(rCandidate.mpSdrFormTextAttribute == mpSdrFormTextAttribute) // tdf#87509 default attr is always != non-default attr, even with same values
{
return true;
}
if(rCandidate.isDefault() != isDefault()) if(rCandidate.isDefault() != isDefault())
{
return false; return false;
}
return (*rCandidate.mpSdrFormTextAttribute == *mpSdrFormTextAttribute); return rCandidate.mpSdrFormTextAttribute == mpSdrFormTextAttribute;
} }
sal_Int32 SdrFormTextAttribute::getFormTextDistance() const sal_Int32 SdrFormTextAttribute::getFormTextDistance() const
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment