1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
30 #include <svx/XPropertyTable.hxx>
31 #include "xmlxtexp.hxx"
32 #include "xmlxtimp.hxx"
33 #include <tools/urlobj.hxx>
34 #include <svx/xtable.hxx>
35 #include <svx/xpool.hxx>
37 using namespace com::sun::star
;
39 // Helper for other sub-classes to have easy-to-read constructors
40 Color
RGB_Color( ColorData nColorName
)
42 Color
aColor( nColorName
);
43 Color
aRGBColor( aColor
.GetRed(), aColor
.GetGreen(), aColor
.GetBlue() );
47 // static int count = 0;
49 XPropertyList::XPropertyList(
50 XPropertyListType type
,
52 XOutdevItemPool
* pInPool
54 aName ( RTL_CONSTASCII_USTRINGPARAM( "standard" ) ),
59 bBitmapsDirty ( true ),
61 bEmbedInDocument( false )
66 pXPool
= new XOutdevItemPool
;
67 DBG_ASSERT( pXPool
, "XOutPool konnte nicht erzeugt werden!" );
69 // fprintf (stderr, "Create type %d count %d\n", (int)eType, count++);
72 XPropertyList::~XPropertyList()
74 // fprintf (stderr, "Destroy type %d count %d\n", (int)eType, --count);
75 for( size_t i
= 0, n
= aList
.size(); i
< n
; ++i
)
82 for ( size_t i
= 0, n
= pBmpList
->size(); i
< n
; ++i
) {
83 delete (*pBmpList
)[ i
];
90 if( bOwnPool
&& pXPool
)
91 SfxItemPool::Free(pXPool
);
94 long XPropertyList::Count() const
98 if( !( (XPropertyList
*) this )->Load() )
99 ( (XPropertyList
*) this )->Create();
101 return( aList
.size() );
104 XPropertyEntry
* XPropertyList::Get( long nIndex
, sal_uInt16
/*nDummy*/) const
108 if( !( (XPropertyList
*) this )->Load() )
109 ( (XPropertyList
*) this )->Create();
111 return ( (size_t)nIndex
< aList
.size() ) ? aList
[ nIndex
] : NULL
;
114 long XPropertyList::Get(const XubString
& rName
)
122 for( long i
= 0, n
= aList
.size(); i
< n
; ++i
) {
123 if ( aList
[ i
]->GetName() == rName
) {
130 Bitmap
* XPropertyList::GetBitmap( long nIndex
) const
136 ( (XPropertyList
*) this )->bBitmapsDirty
= false;
137 ( (XPropertyList
*) this )->CreateBitmapsForUI();
139 if( (size_t)nIndex
< pBmpList
->size() )
140 return (*pBmpList
)[ nIndex
];
145 void XPropertyList::Insert( XPropertyEntry
* pEntry
, long nIndex
)
147 if ( (size_t)nIndex
< aList
.size() ) {
148 aList
.insert( aList
.begin() + nIndex
, pEntry
);
150 aList
.push_back( pEntry
);
153 if( pBmpList
&& !bBitmapsDirty
)
155 Bitmap
* pBmp
= CreateBitmapForUI(
156 (size_t)nIndex
< aList
.size() ? nIndex
: aList
.size() - 1
158 if ( (size_t)nIndex
< pBmpList
->size() ) {
159 pBmpList
->insert( pBmpList
->begin() + nIndex
, pBmp
);
161 pBmpList
->push_back( pBmp
);
166 XPropertyEntry
* XPropertyList::Replace( XPropertyEntry
* pEntry
, long nIndex
)
168 XPropertyEntry
* pOldEntry
= (size_t)nIndex
< aList
.size() ? aList
[ nIndex
] : NULL
;
170 aList
[ nIndex
] = pEntry
;
173 if( pBmpList
&& !bBitmapsDirty
)
175 Bitmap
* pBmp
= CreateBitmapForUI( (sal_uIntPtr
) nIndex
);
176 if ( (size_t)nIndex
< pBmpList
->size() )
178 delete (*pBmpList
)[ nIndex
];
179 (*pBmpList
)[ nIndex
] = pBmp
;
182 pBmpList
->push_back( pBmp
);
188 XPropertyEntry
* XPropertyList::Remove( long nIndex
)
190 if( pBmpList
&& !bBitmapsDirty
)
192 if ( (size_t)nIndex
< pBmpList
->size() )
194 delete (*pBmpList
)[ nIndex
];
195 pBmpList
->erase( pBmpList
->begin() + nIndex
);
199 XPropertyEntry
* pEntry
= NULL
;
200 if ( (size_t)nIndex
< aList
.size() ) {
201 pEntry
= aList
[ nIndex
];
202 aList
.erase( aList
.begin() + nIndex
);
207 void XPropertyList::SetName( const String
& rString
)
215 bool XPropertyList::Load()
221 INetURLObject
aURL( aPath
);
223 if( INET_PROT_NOT_VALID
== aURL
.GetProtocol() )
225 DBG_ASSERT( !aPath
.Len(), "invalid URL" );
229 aURL
.Append( aName
);
231 if( aURL
.getExtension().isEmpty() )
232 aURL
.setExtension( GetDefaultExt() );
234 return SvxXMLXTableImport::load( aURL
.GetMainURL( INetURLObject::NO_DECODE
),
235 uno::Reference
< embed::XStorage
>(),
236 createInstance(), NULL
);
242 bool XPropertyList::LoadFrom( const uno::Reference
< embed::XStorage
> &xStorage
,
243 const rtl::OUString
&rURL
)
248 return SvxXMLXTableImport::load( rURL
, xStorage
, createInstance(), &bEmbedInDocument
);
251 bool XPropertyList::Save()
253 INetURLObject
aURL( aPath
);
255 if( INET_PROT_NOT_VALID
== aURL
.GetProtocol() )
257 DBG_ASSERT( !aPath
.Len(), "invalid URL" );
261 aURL
.Append( aName
);
263 if( aURL
.getExtension().isEmpty() )
264 aURL
.setExtension( GetDefaultExt() );
266 return SvxXMLXTableExportComponent::save( aURL
.GetMainURL( INetURLObject::NO_DECODE
),
268 uno::Reference
< embed::XStorage
>(), NULL
);
271 bool XPropertyList::SaveTo( const uno::Reference
< embed::XStorage
> &xStorage
,
272 const rtl::OUString
&rURL
, rtl::OUString
*pOptName
)
274 return SvxXMLXTableExportComponent::save( rURL
, createInstance(), xStorage
, pOptName
);
277 XPropertyListRef
XPropertyList::CreatePropertyList( XPropertyListType t
,
279 XOutdevItemPool
* pXPool
)
281 XPropertyListRef pRet
;
284 case e: pRet = XPropertyListRef (new c( rPath, pXPool ) ); break
286 MAP( XCOLOR_LIST
, XColorList
);
287 MAP( XLINE_END_LIST
, XLineEndList
);
288 MAP( XDASH_LIST
, XDashList
);
289 MAP( XHATCH_LIST
, XHatchList
);
290 MAP( XGRADIENT_LIST
, XGradientList
);
291 MAP( XBITMAP_LIST
, XBitmapList
);
293 OSL_FAIL("unknown xproperty type");
297 OSL_ASSERT( !pRet
.is() || pRet
->eType
== t
);
303 XPropertyList::CreatePropertyListFromURL( XPropertyListType t
,
304 const rtl::OUString
& rURLStr
,
305 XOutdevItemPool
* pXPool
)
307 INetURLObject
aURL( rURLStr
);
308 INetURLObject
aPathURL( aURL
);
310 aPathURL
.removeSegment();
311 aPathURL
.removeFinalSlash();
313 XPropertyListRef pList
= XPropertyList::CreatePropertyList(
314 t
, aPathURL
.GetMainURL( INetURLObject::NO_DECODE
), pXPool
);
315 pList
->SetName( aURL
.getName() );
320 // catch people being silly with ref counting ...
322 void* XPropertyList::operator new (size_t nCount
)
324 return rtl_allocateMemory( nCount
);
327 void XPropertyList::operator delete(void *pPtr
)
329 return rtl_freeMemory( pPtr
);
336 { XCOLOR_LIST
, "soc" },
337 { XLINE_END_LIST
, "soe" },
338 { XDASH_LIST
, "sod" },
339 { XHATCH_LIST
, "soh" },
340 { XGRADIENT_LIST
, "sog" },
341 { XBITMAP_LIST
, "sob" }
344 rtl::OUString
XPropertyList::GetDefaultExt( XPropertyListType t
)
346 for (size_t i
= 0; i
< SAL_N_ELEMENTS (pExtnMap
); i
++)
348 if( pExtnMap
[i
].t
== t
)
349 return rtl::OUString::createFromAscii( pExtnMap
[ i
].pExt
);
351 return rtl::OUString();
354 rtl::OUString
XPropertyList::GetDefaultExtFilter( XPropertyListType t
)
356 rtl::OUString
aFilter( RTL_CONSTASCII_USTRINGPARAM( "*." ) );
357 return aFilter
+ GetDefaultExt( t
);
360 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */