1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <svx/XPropertyTable.hxx>
22 #include "xmlxtexp.hxx"
23 #include "xmlxtimp.hxx"
24 #include <tools/urlobj.hxx>
25 #include <svx/xtable.hxx>
26 #include <svx/xpool.hxx>
27 #include <svx/svdobj.hxx>
28 #include <svx/svdpool.hxx>
30 using namespace com::sun::star
;
32 // Helper for other sub-classes to have easy-to-read constructors
33 Color
RGB_Color( ColorData nColorName
)
35 Color
aColor( nColorName
);
36 Color
aRGBColor( aColor
.GetRed(), aColor
.GetGreen(), aColor
.GetBlue() );
40 // static int count = 0;
42 XPropertyList::XPropertyList(
43 XPropertyListType type
,
45 XOutdevItemPool
* pInPool
47 maName ( RTL_CONSTASCII_USTRINGPARAM( "standard" ) ),
51 mbEmbedInDocument( false )
55 mpXPool
= static_cast< XOutdevItemPool
* >(&SdrObject::GetGlobalDrawObjectItemPool());
57 // fprintf (stderr, "Create type %d count %d\n", (int)meType, count++);
60 XPropertyList::~XPropertyList()
62 // fprintf (stderr, "Destroy type %d count %d\n", (int)meType, --count);
63 for( size_t i
= 0, n
= maList
.size(); i
< n
; ++i
)
69 long XPropertyList::Count() const
73 if( !( (XPropertyList
*) this )->Load() )
74 ( (XPropertyList
*) this )->Create();
79 XPropertyEntry
* XPropertyList::Get( long nIndex
, sal_uInt16
/*nDummy*/) const
83 if( !( (XPropertyList
*) this )->Load() )
84 ( (XPropertyList
*) this )->Create();
86 return ( (size_t)nIndex
< maList
.size() ) ? maList
[ nIndex
] : NULL
;
89 long XPropertyList::Get(const XubString
& rName
)
97 for( long i
= 0, n
= maList
.size(); i
< n
; ++i
) {
98 if ( maList
[ i
]->GetName() == rName
) {
105 Bitmap
XPropertyList::GetUiBitmap( long nIndex
) const
108 XPropertyEntry
* pEntry
= ( (size_t)nIndex
< maList
.size() ) ? maList
[ nIndex
] : NULL
;
111 aRetval
= pEntry
->GetUiBitmap();
113 if(aRetval
.IsEmpty())
115 aRetval
= const_cast< XPropertyList
* >(this)->CreateBitmapForUI(nIndex
);
116 pEntry
->SetUiBitmap(aRetval
);
122 void XPropertyList::Insert( XPropertyEntry
* pEntry
, long nIndex
)
124 if ( (size_t)nIndex
< maList
.size() ) {
125 maList
.insert( maList
.begin() + nIndex
, pEntry
);
127 maList
.push_back( pEntry
);
131 XPropertyEntry
* XPropertyList::Replace( XPropertyEntry
* pEntry
, long nIndex
)
133 XPropertyEntry
* pOldEntry
= (size_t)nIndex
< maList
.size() ? maList
[ nIndex
] : NULL
;
135 maList
[ nIndex
] = pEntry
;
140 XPropertyEntry
* XPropertyList::Remove( long nIndex
)
142 XPropertyEntry
* pEntry
= NULL
;
143 if ( (size_t)nIndex
< maList
.size() ) {
144 pEntry
= maList
[ nIndex
];
145 maList
.erase( maList
.begin() + nIndex
);
150 void XPropertyList::SetName( const String
& rString
)
158 bool XPropertyList::Load()
164 INetURLObject
aURL( maPath
);
166 if( INET_PROT_NOT_VALID
== aURL
.GetProtocol() )
168 DBG_ASSERT( !maPath
.Len(), "invalid URL" );
172 aURL
.Append( maName
);
174 if( aURL
.getExtension().isEmpty() )
175 aURL
.setExtension( GetDefaultExt() );
177 return SvxXMLXTableImport::load( aURL
.GetMainURL( INetURLObject::NO_DECODE
),
178 uno::Reference
< embed::XStorage
>(),
179 createInstance(), NULL
);
184 bool XPropertyList::LoadFrom( const uno::Reference
< embed::XStorage
> &xStorage
,
185 const OUString
&rURL
)
190 return SvxXMLXTableImport::load( rURL
, xStorage
, createInstance(), &mbEmbedInDocument
);
193 bool XPropertyList::Save()
195 INetURLObject
aURL( maPath
);
197 if( INET_PROT_NOT_VALID
== aURL
.GetProtocol() )
199 DBG_ASSERT( !maPath
.Len(), "invalid URL" );
203 aURL
.Append( maName
);
205 if( aURL
.getExtension().isEmpty() )
206 aURL
.setExtension( GetDefaultExt() );
208 return SvxXMLXTableExportComponent::save( aURL
.GetMainURL( INetURLObject::NO_DECODE
),
210 uno::Reference
< embed::XStorage
>(), NULL
);
213 bool XPropertyList::SaveTo( const uno::Reference
< embed::XStorage
> &xStorage
,
214 const OUString
&rURL
, OUString
*pOptName
)
216 return SvxXMLXTableExportComponent::save( rURL
, createInstance(), xStorage
, pOptName
);
219 XPropertyListRef
XPropertyList::CreatePropertyList( XPropertyListType t
,
221 XOutdevItemPool
* pXPool
)
223 XPropertyListRef pRet
;
226 case e: pRet = XPropertyListRef (new c( rPath, pXPool ) ); break
228 MAP( XCOLOR_LIST
, XColorList
);
229 MAP( XLINE_END_LIST
, XLineEndList
);
230 MAP( XDASH_LIST
, XDashList
);
231 MAP( XHATCH_LIST
, XHatchList
);
232 MAP( XGRADIENT_LIST
, XGradientList
);
233 MAP( XBITMAP_LIST
, XBitmapList
);
235 OSL_FAIL("unknown xproperty type");
239 OSL_ASSERT( !pRet
.is() || pRet
->meType
== t
);
245 XPropertyList::CreatePropertyListFromURL( XPropertyListType t
,
246 const OUString
& rURLStr
,
247 XOutdevItemPool
* pXPool
)
249 INetURLObject
aURL( rURLStr
);
250 INetURLObject
aPathURL( aURL
);
252 aPathURL
.removeSegment();
253 aPathURL
.removeFinalSlash();
255 XPropertyListRef pList
= XPropertyList::CreatePropertyList(
256 t
, aPathURL
.GetMainURL( INetURLObject::NO_DECODE
), pXPool
);
257 pList
->SetName( aURL
.getName() );
262 // catch people being silly with ref counting ...
264 void* XPropertyList::operator new (size_t nCount
)
266 return rtl_allocateMemory( nCount
);
269 void XPropertyList::operator delete(void *pPtr
)
271 return rtl_freeMemory( pPtr
);
278 { XCOLOR_LIST
, "soc" },
279 { XLINE_END_LIST
, "soe" },
280 { XDASH_LIST
, "sod" },
281 { XHATCH_LIST
, "soh" },
282 { XGRADIENT_LIST
, "sog" },
283 { XBITMAP_LIST
, "sob" }
286 OUString
XPropertyList::GetDefaultExt( XPropertyListType t
)
288 for (size_t i
= 0; i
< SAL_N_ELEMENTS (pExtnMap
); i
++)
290 if( pExtnMap
[i
].t
== t
)
291 return OUString::createFromAscii( pExtnMap
[ i
].pExt
);
296 OUString
XPropertyList::GetDefaultExtFilter( XPropertyListType t
)
298 OUString
aFilter( "*." );
299 return aFilter
+ GetDefaultExt( t
);
302 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */