merge the formfield patch from ooo-build
[ooovba.git] / svx / source / xoutdev / xtable.cxx
blob882a4a0a9804a1639888c885fca00fef92a18588
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xtable.cxx,v $
10 * $Revision: 1.7 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 #include <svx/xtable.hxx>
35 #include <svx/xpool.hxx>
37 #define GLOBALOVERFLOW
39 // Vergleichsstrings
40 sal_Unicode __FAR_DATA pszStandard[] = { 's', 't', 'a', 'n', 'd', 'a', 'r', 'd', 0 };
42 // Konvertiert in echte RGB-Farben, damit in den Listboxen
43 // endlich mal richtig selektiert werden kann.
44 Color RGB_Color( ColorData nColorName )
46 Color aColor( nColorName );
47 Color aRGBColor( aColor.GetRed(), aColor.GetGreen(), aColor.GetBlue() );
48 return aRGBColor;
51 // ---------------------
52 // class XPropertyTable
53 // ---------------------
55 /*************************************************************************
57 |* XPropertyTable::XPropertyTable()
59 *************************************************************************/
61 XPropertyTable::XPropertyTable( const String& rPath,
62 XOutdevItemPool* pInPool,
63 USHORT nInitSize, USHORT nReSize ) :
64 aName ( pszStandard, 8 ),
65 aPath ( rPath ),
66 pXPool ( pInPool ),
67 aTable ( nInitSize, nReSize ),
68 pBmpTable ( NULL ),
69 bTableDirty ( TRUE ),
70 bBitmapsDirty ( TRUE ),
71 bOwnPool ( FALSE )
73 if( !pXPool )
75 bOwnPool = TRUE;
76 pXPool = new XOutdevItemPool;
77 DBG_ASSERT( pXPool, "XOutPool konnte nicht erzeugt werden!" );
81 /*************************************************************************
83 |* XPropertyTable::XPropertyTable( SvStraem& )
85 *************************************************************************/
87 XPropertyTable::XPropertyTable( SvStream& /*rIn*/) :
88 pBmpTable ( NULL )
92 /*************************************************************************
94 |* XPropertyTable::~XPropertyTable()
96 *************************************************************************/
98 XPropertyTable::~XPropertyTable()
100 XPropertyEntry* pEntry = (XPropertyEntry*)aTable.First();
101 Bitmap* pBitmap = NULL;
102 for (ULONG nIndex = 0; nIndex < aTable.Count(); nIndex++)
104 delete pEntry;
105 pEntry = (XPropertyEntry*)aTable.Next();
107 // Hier wird die Bitmaptabelle geloescht
108 if( pBmpTable )
110 pBitmap = (Bitmap*) pBmpTable->First();
112 for( ULONG nIndex = 0; nIndex < pBmpTable->Count(); nIndex++ )
114 delete pBitmap;
115 pBitmap = (Bitmap*) pBmpTable->Next();
117 delete pBmpTable;
118 pBmpTable = NULL;
120 // Eigener Pool wird geloescht
121 if( bOwnPool && pXPool )
123 SfxItemPool::Free(pXPool);
127 /*************************************************************************
129 |* XPropertyTable::Clear()
131 *************************************************************************/
133 void XPropertyTable::Clear()
135 aTable.Clear();
136 if( pBmpTable )
137 pBmpTable->Clear();
140 /************************************************************************/
142 long XPropertyTable::Count() const
144 if( bTableDirty )
146 // ( (XPropertyTable*) this )->bTableDirty = FALSE; <- im Load()
147 if( !( (XPropertyTable*) this )->Load() )
148 ( (XPropertyTable*) this )->Create();
150 return( aTable.Count() );
153 /*************************************************************************
155 |* XPropertyEntry* XPropertyTable::Get()
157 *************************************************************************/
159 XPropertyEntry* XPropertyTable::Get( long nIndex, USHORT /*nDummy*/) const
161 if( bTableDirty )
163 // ( (XPropertyTable*) this )->bTableDirty = FALSE; <- im Load()
164 if( !( (XPropertyTable*) this )->Load() )
165 ( (XPropertyTable*) this )->Create();
167 return (XPropertyEntry*) aTable.GetObject( (ULONG) nIndex );
170 /*************************************************************************
172 |* long XPropertyTable::Get(const String& rName)
174 *************************************************************************/
176 long XPropertyTable::Get(const XubString& rName)
178 if( bTableDirty )
180 // bTableDirty = FALSE;
181 if( !Load() )
182 Create();
184 long nPos = 0;
185 XPropertyEntry* pEntry = (XPropertyEntry*)aTable.First();
186 while (pEntry && pEntry->GetName() != rName)
188 nPos++;
189 pEntry = (XPropertyEntry*)aTable.Next();
191 if (!pEntry) nPos = -1;
192 return nPos;
195 /*************************************************************************
197 |* Bitmap* XPropertyTable::GetBitmap()
199 *************************************************************************/
201 Bitmap* XPropertyTable::GetBitmap( long nIndex ) const
203 if( pBmpTable )
205 if( bBitmapsDirty )
207 ( (XPropertyTable*) this )->bBitmapsDirty = FALSE;
208 ( (XPropertyTable*) this )->CreateBitmapsForUI();
211 if( pBmpTable->Count() >= (ULONG) nIndex )
212 return (Bitmap*) pBmpTable->GetObject( (ULONG) nIndex );
214 return( NULL );
217 /*************************************************************************
219 |* void XPropertyTable::Insert()
221 *************************************************************************/
223 BOOL XPropertyTable::Insert( long nIndex, XPropertyEntry* pEntry )
225 BOOL bReturn = aTable.Insert( (ULONG) nIndex, pEntry );
227 if( pBmpTable && !bBitmapsDirty )
229 Bitmap* pBmp = CreateBitmapForUI( (ULONG) nIndex );
230 pBmpTable->Insert( (ULONG) nIndex, pBmp );
232 return bReturn;
235 /*************************************************************************
237 |* void XPropertyTable::Replace()
239 *************************************************************************/
241 XPropertyEntry* XPropertyTable::Replace( long nIndex, XPropertyEntry* pEntry )
243 XPropertyEntry* pOldEntry = (XPropertyEntry*) aTable.Replace( (ULONG) nIndex, pEntry );
245 if( pBmpTable && !bBitmapsDirty )
247 Bitmap* pBmp = CreateBitmapForUI( (ULONG) nIndex );
248 Bitmap* pOldBmp = (Bitmap*) pBmpTable->Replace( (ULONG) nIndex, pBmp );
249 if( pOldBmp )
250 delete pOldBmp;
252 return pOldEntry;
255 /*************************************************************************
257 |* void XPropertyTable::Remove()
259 *************************************************************************/
261 XPropertyEntry* XPropertyTable::Remove( long nIndex, USHORT /*nDummy*/)
263 if( pBmpTable && !bBitmapsDirty )
265 Bitmap* pOldBmp = (Bitmap*) pBmpTable->Remove( (ULONG) nIndex );
266 if( pOldBmp )
267 delete pOldBmp;
269 return (XPropertyEntry*) aTable.Remove((ULONG)nIndex);
272 /************************************************************************/
274 void XPropertyTable::SetName( const String& rString )
276 if(rString.Len())
278 aName = rString;
282 // --------------------
283 // class XPropertyList
284 // --------------------
287 /*************************************************************************
289 |* XPropertyList::XPropertyList()
291 *************************************************************************/
293 XPropertyList::XPropertyList( const String& rPath,
294 XOutdevItemPool* pInPool,
295 USHORT nInitSize, USHORT nReSize ) :
296 aName ( pszStandard, 8 ),
297 aPath ( rPath ),
298 pXPool ( pInPool ),
299 aList ( nInitSize, nReSize ),
300 pBmpList ( NULL ),
301 bListDirty ( TRUE ),
302 bBitmapsDirty ( TRUE ),
303 bOwnPool ( FALSE )
305 if( !pXPool )
307 bOwnPool = TRUE;
308 pXPool = new XOutdevItemPool;
309 DBG_ASSERT( pXPool, "XOutPool konnte nicht erzeugt werden!" );
313 /*************************************************************************
315 |* XPropertyList::XPropertyList( SvStraem& )
317 *************************************************************************/
319 XPropertyList::XPropertyList( SvStream& /*rIn*/) :
320 pBmpList ( NULL )
324 /*************************************************************************
326 |* XPropertyList::~XPropertyList()
328 *************************************************************************/
330 XPropertyList::~XPropertyList()
332 XPropertyEntry* pEntry = (XPropertyEntry*)aList.First();
333 Bitmap* pBitmap = NULL;
334 for( ULONG nIndex = 0; nIndex < aList.Count(); nIndex++ )
336 delete pEntry;
337 pEntry = (XPropertyEntry*)aList.Next();
340 if( pBmpList )
342 pBitmap = (Bitmap*) pBmpList->First();
344 for( ULONG nIndex = 0; nIndex < pBmpList->Count(); nIndex++ )
346 delete pBitmap;
347 pBitmap = (Bitmap*) pBmpList->Next();
349 delete pBmpList;
350 pBmpList = NULL;
353 if( bOwnPool && pXPool )
355 SfxItemPool::Free(pXPool);
359 /*************************************************************************
361 |* XPropertyList::Clear()
363 *************************************************************************/
365 void XPropertyList::Clear()
367 aList.Clear();
368 if( pBmpList )
369 pBmpList->Clear();
372 /************************************************************************/
374 long XPropertyList::Count() const
376 if( bListDirty )
378 // ( (XPropertyList*) this )->bListDirty = FALSE; <- im Load()
379 if( !( (XPropertyList*) this )->Load() )
380 ( (XPropertyList*) this )->Create();
382 return( aList.Count() );
385 /*************************************************************************
387 |* XPropertyEntry* XPropertyList::Get()
389 *************************************************************************/
391 XPropertyEntry* XPropertyList::Get( long nIndex, USHORT /*nDummy*/) const
393 if( bListDirty )
395 // ( (XPropertyList*) this )->bListDirty = FALSE; <- im Load()
396 if( !( (XPropertyList*) this )->Load() )
397 ( (XPropertyList*) this )->Create();
399 return (XPropertyEntry*) aList.GetObject( (ULONG) nIndex );
402 /*************************************************************************
404 |* XPropertyList::Get()
406 *************************************************************************/
408 long XPropertyList::Get(const XubString& rName)
410 if( bListDirty )
412 //bListDirty = FALSE;
413 if( !Load() )
414 Create();
416 long nPos = 0;
417 XPropertyEntry* pEntry = (XPropertyEntry*)aList.First();
418 while (pEntry && pEntry->GetName() != rName)
420 nPos++;
421 pEntry = (XPropertyEntry*)aList.Next();
423 if (!pEntry) nPos = -1;
424 return nPos;
427 /*************************************************************************
429 |* Bitmap* XPropertyList::GetBitmap()
431 *************************************************************************/
433 Bitmap* XPropertyList::GetBitmap( long nIndex ) const
435 if( pBmpList )
437 if( bBitmapsDirty )
439 ( (XPropertyList*) this )->bBitmapsDirty = FALSE;
440 ( (XPropertyList*) this )->CreateBitmapsForUI();
442 if( pBmpList->Count() >= (ULONG) nIndex )
443 return (Bitmap*) pBmpList->GetObject( (ULONG) nIndex );
445 return( NULL );
448 /*************************************************************************
450 |* void XPropertyList::Insert()
452 *************************************************************************/
454 void XPropertyList::Insert( XPropertyEntry* pEntry, long nIndex )
456 aList.Insert( pEntry, (ULONG) nIndex );
458 if( pBmpList && !bBitmapsDirty )
460 Bitmap* pBmp = CreateBitmapForUI(
461 (ULONG) nIndex < aList.Count() ? nIndex : aList.Count() - 1 );
462 pBmpList->Insert( pBmp, (ULONG) nIndex );
466 /*************************************************************************
468 |* void XPropertyList::Replace()
470 *************************************************************************/
472 XPropertyEntry* XPropertyList::Replace( XPropertyEntry* pEntry, long nIndex )
474 XPropertyEntry* pOldEntry = (XPropertyEntry*) aList.Replace( pEntry, (ULONG) nIndex );
476 if( pBmpList && !bBitmapsDirty )
478 Bitmap* pBmp = CreateBitmapForUI( (ULONG) nIndex );
479 Bitmap* pOldBmp = (Bitmap*) pBmpList->Replace( pBmp, (ULONG) nIndex );
480 if( pOldBmp )
481 delete pOldBmp;
483 return pOldEntry;
486 /*************************************************************************
488 |* void XPropertyList::Remove()
490 *************************************************************************/
492 XPropertyEntry* XPropertyList::Remove( long nIndex, USHORT /*nDummy*/)
494 if( pBmpList && !bBitmapsDirty )
496 Bitmap* pOldBmp = (Bitmap*) pBmpList->Remove( (ULONG) nIndex );
497 if( pOldBmp )
498 delete pOldBmp;
500 return (XPropertyEntry*) aList.Remove( (ULONG) nIndex );
503 /************************************************************************/
505 void XPropertyList::SetName( const String& rString )
507 if(rString.Len())
509 aName = rString;