1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: xtable.cxx,v $
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
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() );
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 ),
67 aTable ( nInitSize
, nReSize
),
70 bBitmapsDirty ( 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*/) :
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
++)
105 pEntry
= (XPropertyEntry
*)aTable
.Next();
107 // Hier wird die Bitmaptabelle geloescht
110 pBitmap
= (Bitmap
*) pBmpTable
->First();
112 for( ULONG nIndex
= 0; nIndex
< pBmpTable
->Count(); nIndex
++ )
115 pBitmap
= (Bitmap
*) pBmpTable
->Next();
120 // Eigener Pool wird geloescht
121 if( bOwnPool
&& pXPool
)
123 SfxItemPool::Free(pXPool
);
127 /*************************************************************************
129 |* XPropertyTable::Clear()
131 *************************************************************************/
133 void XPropertyTable::Clear()
140 /************************************************************************/
142 long XPropertyTable::Count() const
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
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
)
180 // bTableDirty = FALSE;
185 XPropertyEntry
* pEntry
= (XPropertyEntry
*)aTable
.First();
186 while (pEntry
&& pEntry
->GetName() != rName
)
189 pEntry
= (XPropertyEntry
*)aTable
.Next();
191 if (!pEntry
) nPos
= -1;
195 /*************************************************************************
197 |* Bitmap* XPropertyTable::GetBitmap()
199 *************************************************************************/
201 Bitmap
* XPropertyTable::GetBitmap( long nIndex
) const
207 ( (XPropertyTable
*) this )->bBitmapsDirty
= FALSE
;
208 ( (XPropertyTable
*) this )->CreateBitmapsForUI();
211 if( pBmpTable
->Count() >= (ULONG
) nIndex
)
212 return (Bitmap
*) pBmpTable
->GetObject( (ULONG
) nIndex
);
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
);
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
);
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
);
269 return (XPropertyEntry
*) aTable
.Remove((ULONG
)nIndex
);
272 /************************************************************************/
274 void XPropertyTable::SetName( const String
& 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 ),
299 aList ( nInitSize
, nReSize
),
302 bBitmapsDirty ( 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*/) :
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
++ )
337 pEntry
= (XPropertyEntry
*)aList
.Next();
342 pBitmap
= (Bitmap
*) pBmpList
->First();
344 for( ULONG nIndex
= 0; nIndex
< pBmpList
->Count(); nIndex
++ )
347 pBitmap
= (Bitmap
*) pBmpList
->Next();
353 if( bOwnPool
&& pXPool
)
355 SfxItemPool::Free(pXPool
);
359 /*************************************************************************
361 |* XPropertyList::Clear()
363 *************************************************************************/
365 void XPropertyList::Clear()
372 /************************************************************************/
374 long XPropertyList::Count() const
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
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
)
412 //bListDirty = FALSE;
417 XPropertyEntry
* pEntry
= (XPropertyEntry
*)aList
.First();
418 while (pEntry
&& pEntry
->GetName() != rName
)
421 pEntry
= (XPropertyEntry
*)aList
.Next();
423 if (!pEntry
) nPos
= -1;
427 /*************************************************************************
429 |* Bitmap* XPropertyList::GetBitmap()
431 *************************************************************************/
433 Bitmap
* XPropertyList::GetBitmap( long nIndex
) const
439 ( (XPropertyList
*) this )->bBitmapsDirty
= FALSE
;
440 ( (XPropertyList
*) this )->CreateBitmapsForUI();
442 if( pBmpList
->Count() >= (ULONG
) nIndex
)
443 return (Bitmap
*) pBmpList
->GetObject( (ULONG
) nIndex
);
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
);
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
);
500 return (XPropertyEntry
*) aList
.Remove( (ULONG
) nIndex
);
503 /************************************************************************/
505 void XPropertyList::SetName( const String
& rString
)