summaryrefslogtreecommitdiff
path: root/svx/source/xoutdev
diff options
context:
space:
mode:
authorMichael Meeks <michael.meeks@novell.com>2011-09-23 14:05:07 +0100
committerMichael Meeks <michael.meeks@novell.com>2011-09-24 08:33:46 +0100
commitc8dc73720883333a13187865cd0d69b64af6b4b5 (patch)
treec9037bb6e79fd49507f2de1cf2b22f7159572720 /svx/source/xoutdev
parent7fc35af5fd3171cc9bf43d2c27660afcf407d3f6 (diff)
re-factor XPropertyList derivatives to use a rtl::Reference
This cleans up a lot of lifecycle nasties and cleans up some serious cut/paste code duplication issues at the same time. Cleanup the naming of ColorTable -> ColorList to match the impl. too
Diffstat (limited to 'svx/source/xoutdev')
-rw-r--r--svx/source/xoutdev/xattr.cxx48
-rw-r--r--svx/source/xoutdev/xattrbmp.cxx14
-rw-r--r--svx/source/xoutdev/xtabcolr.cxx11
-rw-r--r--svx/source/xoutdev/xtable.cxx34
4 files changed, 56 insertions, 51 deletions
diff --git a/svx/source/xoutdev/xattr.cxx b/svx/source/xoutdev/xattr.cxx
index 2fb5b79c419a..6596e75c2e17 100644
--- a/svx/source/xoutdev/xattr.cxx
+++ b/svx/source/xoutdev/xattr.cxx
@@ -205,7 +205,7 @@ SvStream& NameOrIndex::Store( SvStream& rOut, sal_uInt16 nItemVersion ) const
Argument pPool2 can be null.
If returned string equals NameOrIndex->GetName(), the name was already unique.
*/
-String NameOrIndex::CheckNamedItem( const NameOrIndex* pCheckItem, const sal_uInt16 nWhich, const SfxItemPool* pPool1, const SfxItemPool* /*pPool2*/, SvxCompareValueFunc pCompareValueFunc, sal_uInt16 nPrefixResId, XPropertyList* pDefaults )
+String NameOrIndex::CheckNamedItem( const NameOrIndex* pCheckItem, const sal_uInt16 nWhich, const SfxItemPool* pPool1, const SfxItemPool* /*pPool2*/, SvxCompareValueFunc pCompareValueFunc, sal_uInt16 nPrefixResId, const XPropertyListRef &pDefaults )
{
sal_Bool bForceNew = sal_False;
@@ -248,7 +248,7 @@ String NameOrIndex::CheckNamedItem( const NameOrIndex* pCheckItem, const sal_uIn
String aUser( aRes );
aUser += sal_Unicode( ' ' );
- if( pDefaults )
+ if( pDefaults.get() )
{
const int nCount = pDefaults->Count();
int nIndex;
@@ -1248,19 +1248,15 @@ XLineDashItem* XLineDashItem::checkForUniqueItem( SdrModel* pModel ) const
{
if( pModel )
{
- const String aUniqueName = NameOrIndex::CheckNamedItem( this,
- XATTR_LINEDASH,
- &pModel->GetItemPool(),
- pModel->GetStyleSheetPool() ? &pModel->GetStyleSheetPool()->GetPool() : NULL,
- XLineDashItem::CompareValueFunc,
- RID_SVXSTR_DASH11,
- pModel->GetDashList() );
+ const String aUniqueName = NameOrIndex::CheckNamedItem(
+ this, XATTR_LINEDASH, &pModel->GetItemPool(),
+ pModel->GetStyleSheetPool() ? &pModel->GetStyleSheetPool()->GetPool() : NULL,
+ XLineDashItem::CompareValueFunc, RID_SVXSTR_DASH11,
+ pModel->GetPropertyList( XDASH_LIST ) );
// if the given name is not valid, replace it!
if( aUniqueName != GetName() )
- {
return new XLineDashItem( aUniqueName, aDash );
- }
}
return (XLineDashItem*)this;
@@ -3604,19 +3600,15 @@ XFillGradientItem* XFillGradientItem::checkForUniqueItem( SdrModel* pModel ) con
{
if( pModel )
{
- const String aUniqueName = NameOrIndex::CheckNamedItem( this,
- XATTR_FILLGRADIENT,
- &pModel->GetItemPool(),
- pModel->GetStyleSheetPool() ? &pModel->GetStyleSheetPool()->GetPool() : NULL,
- XFillGradientItem::CompareValueFunc,
- RID_SVXSTR_GRADIENT,
- pModel->GetGradientList() );
+ const String aUniqueName = NameOrIndex::CheckNamedItem(
+ this, XATTR_FILLGRADIENT, &pModel->GetItemPool(),
+ pModel->GetStyleSheetPool() ? &pModel->GetStyleSheetPool()->GetPool() : NULL,
+ XFillGradientItem::CompareValueFunc, RID_SVXSTR_GRADIENT,
+ pModel->GetPropertyList( XGRADIENT_LIST ) );
// if the given name is not valid, replace it!
if( aUniqueName != GetName() )
- {
return new XFillGradientItem( aUniqueName, aGradient );
- }
}
return (XFillGradientItem*)this;
@@ -3747,7 +3739,7 @@ XFillFloatTransparenceItem* XFillFloatTransparenceItem::checkForUniqueItem( SdrM
pModel->GetStyleSheetPool() ? &pModel->GetStyleSheetPool()->GetPool() : NULL,
XFillFloatTransparenceItem::CompareValueFunc,
RID_SVXSTR_TRASNGR0,
- NULL );
+ XPropertyListRef() );
// if the given name is not valid, replace it!
if( aUniqueName != GetName() )
@@ -4156,19 +4148,15 @@ XFillHatchItem* XFillHatchItem::checkForUniqueItem( SdrModel* pModel ) const
{
if( pModel )
{
- const String aUniqueName = NameOrIndex::CheckNamedItem( this,
- XATTR_FILLHATCH,
- &pModel->GetItemPool(),
- pModel->GetStyleSheetPool() ? &pModel->GetStyleSheetPool()->GetPool() : NULL,
- XFillHatchItem::CompareValueFunc,
- RID_SVXSTR_HATCH10,
- pModel->GetHatchList() );
+ const String aUniqueName = NameOrIndex::CheckNamedItem(
+ this, XATTR_FILLHATCH, &pModel->GetItemPool(),
+ pModel->GetStyleSheetPool() ? &pModel->GetStyleSheetPool()->GetPool() : NULL,
+ XFillHatchItem::CompareValueFunc, RID_SVXSTR_HATCH10,
+ pModel->GetPropertyList( XHATCH_LIST ) );
// if the given name is not valid, replace it!
if( aUniqueName != GetName() )
- {
return new XFillHatchItem( aUniqueName, aHatch );
- }
}
return (XFillHatchItem*)this;
diff --git a/svx/source/xoutdev/xattrbmp.cxx b/svx/source/xoutdev/xattrbmp.cxx
index 1f421c4a5d7b..b6df09a947fd 100644
--- a/svx/source/xoutdev/xattrbmp.cxx
+++ b/svx/source/xoutdev/xattrbmp.cxx
@@ -775,19 +775,15 @@ XFillBitmapItem* XFillBitmapItem::checkForUniqueItem( SdrModel* pModel ) const
{
if( pModel )
{
- const String aUniqueName = NameOrIndex::CheckNamedItem( this,
- XATTR_FILLBITMAP,
- &pModel->GetItemPool(),
- pModel->GetStyleSheetPool() ? &pModel->GetStyleSheetPool()->GetPool() : NULL,
- XFillBitmapItem::CompareValueFunc,
- RID_SVXSTR_BMP21,
- pModel->GetBitmapList() );
+ const String aUniqueName = NameOrIndex::CheckNamedItem(
+ this, XATTR_FILLBITMAP, &pModel->GetItemPool(),
+ pModel->GetStyleSheetPool() ? &pModel->GetStyleSheetPool()->GetPool() : NULL,
+ XFillBitmapItem::CompareValueFunc, RID_SVXSTR_BMP21,
+ pModel->GetPropertyList( XBITMAP_LIST ) );
// if the given name is not valid, replace it!
if( aUniqueName != GetName() )
- {
return new XFillBitmapItem( aUniqueName, aXOBitmap );
- }
}
return (XFillBitmapItem*)this;
diff --git a/svx/source/xoutdev/xtabcolr.cxx b/svx/source/xoutdev/xtabcolr.cxx
index ab11883e7ba8..c67a89510af3 100644
--- a/svx/source/xoutdev/xtabcolr.cxx
+++ b/svx/source/xoutdev/xtabcolr.cxx
@@ -39,9 +39,16 @@
using namespace com::sun::star;
-XColorList& XColorList::GetStdColorTable()
+
+XColorListRef XColorList::CreateStdColorList()
+{
+ return XPropertyList::CreatePropertyList(
+ XCOLOR_LIST, SvtPathOptions().GetPalettePath() )->AsColorList();
+}
+
+XColorListRef XColorList::GetStdColorList()
{
- static XColorList aTable(SvtPathOptions().GetPalettePath());
+ static XColorListRef aTable( CreateStdColorList() );
return aTable;
}
diff --git a/svx/source/xoutdev/xtable.cxx b/svx/source/xoutdev/xtable.cxx
index 84185609145f..fb0f77af2d0e 100644
--- a/svx/source/xoutdev/xtable.cxx
+++ b/svx/source/xoutdev/xtable.cxx
@@ -46,6 +46,8 @@ Color RGB_Color( ColorData nColorName )
return aRGBColor;
}
+static int count = 0;
+
XPropertyList::XPropertyList(
XPropertyListType type,
const char *pDefaultExtension,
@@ -68,13 +70,15 @@ XPropertyList::XPropertyList(
pXPool = new XOutdevItemPool;
DBG_ASSERT( pXPool, "XOutPool konnte nicht erzeugt werden!" );
}
+ fprintf (stderr, "Create type %d count %d\n", (int)eType, count++);
}
XPropertyList::~XPropertyList()
{
- for( size_t i = 0, n = aList.size(); i < n; ++i ) {
+ fprintf (stderr, "Destroy type %d count %d\n", (int)eType, --count);
+ for( size_t i = 0, n = aList.size(); i < n; ++i )
delete aList[ i ];
- }
+
aList.clear();
if( pBmpList )
@@ -88,9 +92,7 @@ XPropertyList::~XPropertyList()
}
if( bOwnPool && pXPool )
- {
SfxItemPool::Free(pXPool);
- }
}
void XPropertyList::Clear()
@@ -291,14 +293,14 @@ bool XPropertyList::SaveTo( const uno::Reference< embed::XStorage > &xStorage,
return SvxXMLXTableExportComponent::save( rURL, createInstance(), xStorage, pOptName );
}
-XPropertyList *XPropertyList::CreatePropertyList( XPropertyListType t,
- const String& rPath,
- XOutdevItemPool* pXPool )
+XPropertyListRef XPropertyList::CreatePropertyList( XPropertyListType t,
+ const String& rPath,
+ XOutdevItemPool* pXPool )
{
- XPropertyList *pRet = NULL;
+ XPropertyListRef pRet;
#define MAP(e,c) \
- case e: pRet = new c( rPath, pXPool ); break
+ case e: pRet = XPropertyListRef (new c( rPath, pXPool ) ); break
switch (t) {
MAP( XCOLOR_LIST, XColorList );
MAP( XLINE_END_LIST, XLineEndList );
@@ -311,9 +313,21 @@ XPropertyList *XPropertyList::CreatePropertyList( XPropertyListType t,
break;
}
#undef MAP
- OSL_ASSERT( !pRet || pRet->eType == t );
+ OSL_ASSERT( !pRet.is() || pRet->eType == t );
return pRet;
}
+// catch people being silly with ref counting ...
+
+void* XPropertyList::operator new (size_t nCount)
+{
+ return rtl_allocateMemory( nCount );
+}
+
+void XPropertyList::operator delete(void *pPtr)
+{
+ return rtl_freeMemory( pPtr );
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */