bump product version to 4.1.6.2
[LibreOffice.git] / svx / source / xoutdev / xtable.cxx
blobeb21b4d328cad797353f59df2151b180554bfddc
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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() );
37 return aRGBColor;
40 // static int count = 0;
42 XPropertyList::XPropertyList(
43 XPropertyListType type,
44 const String& rPath,
45 XOutdevItemPool* pInPool
46 ) : meType ( type ),
47 maName ( RTL_CONSTASCII_USTRINGPARAM( "standard" ) ),
48 maPath ( rPath ),
49 mpXPool ( pInPool ),
50 mbListDirty ( true ),
51 mbEmbedInDocument( false )
53 if( !mpXPool )
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 )
64 delete maList[ i ];
66 maList.clear();
69 long XPropertyList::Count() const
71 if( mbListDirty )
73 if( !( (XPropertyList*) this )->Load() )
74 ( (XPropertyList*) this )->Create();
76 return maList.size();
79 XPropertyEntry* XPropertyList::Get( long nIndex, sal_uInt16 /*nDummy*/) const
81 if( mbListDirty )
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)
91 if( mbListDirty )
93 if( !Load() )
94 Create();
97 for( long i = 0, n = maList.size(); i < n; ++i ) {
98 if ( maList[ i ]->GetName() == rName ) {
99 return i;
102 return -1;
105 Bitmap XPropertyList::GetUiBitmap( long nIndex ) const
107 Bitmap aRetval;
108 XPropertyEntry* pEntry = ( (size_t)nIndex < maList.size() ) ? maList[ nIndex ] : NULL;
109 if(pEntry)
111 aRetval = pEntry->GetUiBitmap();
113 if(aRetval.IsEmpty())
115 aRetval = const_cast< XPropertyList* >(this)->CreateBitmapForUI(nIndex);
116 pEntry->SetUiBitmap(aRetval);
119 return aRetval;
122 void XPropertyList::Insert( XPropertyEntry* pEntry, long nIndex )
124 if ( (size_t)nIndex < maList.size() ) {
125 maList.insert( maList.begin() + nIndex, pEntry );
126 } else {
127 maList.push_back( pEntry );
131 XPropertyEntry* XPropertyList::Replace( XPropertyEntry* pEntry, long nIndex )
133 XPropertyEntry* pOldEntry = (size_t)nIndex < maList.size() ? maList[ nIndex ] : NULL;
134 if ( pOldEntry ) {
135 maList[ nIndex ] = pEntry;
137 return pOldEntry;
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 );
147 return pEntry;
150 void XPropertyList::SetName( const String& rString )
152 if(rString.Len())
154 maName = rString;
158 bool XPropertyList::Load()
160 if( mbListDirty )
162 mbListDirty = false;
164 INetURLObject aURL( maPath );
166 if( INET_PROT_NOT_VALID == aURL.GetProtocol() )
168 DBG_ASSERT( !maPath.Len(), "invalid URL" );
169 return false;
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 );
181 return false;
184 bool XPropertyList::LoadFrom( const uno::Reference < embed::XStorage > &xStorage,
185 const OUString &rURL )
187 if( !mbListDirty )
188 return false;
189 mbListDirty = false;
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" );
200 return false;
203 aURL.Append( maName );
205 if( aURL.getExtension().isEmpty() )
206 aURL.setExtension( GetDefaultExt() );
208 return SvxXMLXTableExportComponent::save( aURL.GetMainURL( INetURLObject::NO_DECODE ),
209 createInstance(),
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,
220 const String& rPath,
221 XOutdevItemPool* pXPool )
223 XPropertyListRef pRet;
225 #define MAP(e,c) \
226 case e: pRet = XPropertyListRef (new c( rPath, pXPool ) ); break
227 switch (t) {
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 );
234 default:
235 OSL_FAIL("unknown xproperty type");
236 break;
238 #undef MAP
239 OSL_ASSERT( !pRet.is() || pRet->meType == t );
241 return pRet;
244 XPropertyListRef
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() );
259 return pList;
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 );
274 static struct {
275 XPropertyListType t;
276 const char *pExt;
277 } pExtnMap[] = {
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 );
293 return OUString();
296 OUString XPropertyList::GetDefaultExtFilter( XPropertyListType t )
298 OUString aFilter( "*." );
299 return aFilter + GetDefaultExt( t );
302 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */