xref: /aoo41x/main/svx/source/xoutdev/xtable.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_svx.hxx"
30 
31 #include <svx/xtable.hxx>
32 #include <svx/xpool.hxx>
33 
34 #define GLOBALOVERFLOW
35 
36 // Vergleichsstrings
37 sal_Unicode __FAR_DATA pszStandard[] = { 's', 't', 'a', 'n', 'd', 'a', 'r', 'd', 0 };
38 
39 // Konvertiert in echte RGB-Farben, damit in den Listboxen
40 // endlich mal richtig selektiert werden kann.
41 Color RGB_Color( ColorData nColorName )
42 {
43 	Color aColor( nColorName );
44 	Color aRGBColor( aColor.GetRed(), aColor.GetGreen(), aColor.GetBlue() );
45 	return aRGBColor;
46 }
47 
48 // ---------------------
49 // class XPropertyTable
50 // ---------------------
51 
52 /*************************************************************************
53 |*
54 |* XPropertyTable::XPropertyTable()
55 |*
56 *************************************************************************/
57 
58 XPropertyTable::XPropertyTable( const String& rPath,
59 								XOutdevItemPool* pInPool,
60 								sal_uInt16 nInitSize, sal_uInt16 nReSize ) :
61 			aName			( pszStandard, 8 ),
62 			aPath			( rPath ),
63 			pXPool			( pInPool ),
64 			aTable			( nInitSize, nReSize ),
65 			pBmpTable		( NULL ),
66 			bTableDirty		( sal_True ),
67 			bBitmapsDirty	( sal_True ),
68 			bOwnPool		( sal_False )
69 {
70 	if( !pXPool )
71 	{
72 		bOwnPool = sal_True;
73 		pXPool = new XOutdevItemPool;
74 		DBG_ASSERT( pXPool, "XOutPool konnte nicht erzeugt werden!" );
75 	}
76 }
77 
78 /*************************************************************************
79 |*
80 |* XPropertyTable::XPropertyTable( SvStraem& )
81 |*
82 *************************************************************************/
83 
84 XPropertyTable::XPropertyTable( SvStream& /*rIn*/) :
85 			pBmpTable	( NULL )
86 {
87 }
88 
89 /*************************************************************************
90 |*
91 |* XPropertyTable::~XPropertyTable()
92 |*
93 *************************************************************************/
94 
95 XPropertyTable::~XPropertyTable()
96 {
97 	XPropertyEntry* pEntry = (XPropertyEntry*)aTable.First();
98 	Bitmap* pBitmap = NULL;
99 	for (sal_uIntPtr nIndex = 0; nIndex < aTable.Count(); nIndex++)
100 	{
101 		delete pEntry;
102 		pEntry = (XPropertyEntry*)aTable.Next();
103 	}
104 	// Hier wird die Bitmaptabelle geloescht
105 	if( pBmpTable )
106 	{
107 		pBitmap = (Bitmap*) pBmpTable->First();
108 
109 		for( sal_uIntPtr nIndex = 0; nIndex < pBmpTable->Count(); nIndex++ )
110 		{
111 			delete pBitmap;
112 			pBitmap = (Bitmap*) pBmpTable->Next();
113 		}
114 		delete pBmpTable;
115 		pBmpTable = NULL;
116 	}
117 	// Eigener Pool wird geloescht
118 	if( bOwnPool && pXPool )
119 	{
120         SfxItemPool::Free(pXPool);
121 	}
122 }
123 
124 /*************************************************************************
125 |*
126 |* XPropertyTable::Clear()
127 |*
128 *************************************************************************/
129 
130 void XPropertyTable::Clear()
131 {
132 	aTable.Clear();
133 	if( pBmpTable )
134 		pBmpTable->Clear();
135 }
136 
137 /************************************************************************/
138 
139 long XPropertyTable::Count() const
140 {
141 	if( bTableDirty )
142 	{
143 		// ( (XPropertyTable*) this )->bTableDirty = sal_False; <- im Load()
144 		if( !( (XPropertyTable*) this )->Load() )
145 			( (XPropertyTable*) this )->Create();
146 	}
147 	return( aTable.Count() );
148 }
149 
150 /*************************************************************************
151 |*
152 |* XPropertyEntry* XPropertyTable::Get()
153 |*
154 *************************************************************************/
155 
156 XPropertyEntry* XPropertyTable::Get( long nIndex, sal_uInt16 /*nDummy*/) const
157 {
158 	if( bTableDirty )
159 	{
160 		// ( (XPropertyTable*) this )->bTableDirty = sal_False; <- im Load()
161 		if( !( (XPropertyTable*) this )->Load() )
162 			( (XPropertyTable*) this )->Create();
163 	}
164 	return (XPropertyEntry*) aTable.GetObject( (sal_uIntPtr) nIndex );
165 }
166 
167 /*************************************************************************
168 |*
169 |* long XPropertyTable::Get(const String& rName)
170 |*
171 *************************************************************************/
172 
173 long XPropertyTable::Get(const XubString& rName)
174 {
175 	if( bTableDirty )
176 	{
177 		// bTableDirty = sal_False;
178 		if( !Load() )
179 			Create();
180 	}
181 	long nPos = 0;
182 	XPropertyEntry* pEntry = (XPropertyEntry*)aTable.First();
183 	while (pEntry && pEntry->GetName() != rName)
184 	{
185 		nPos++;
186 		pEntry = (XPropertyEntry*)aTable.Next();
187 	}
188 	if (!pEntry) nPos = -1;
189 	return nPos;
190 }
191 
192 /*************************************************************************
193 |*
194 |* Bitmap* XPropertyTable::GetBitmap()
195 |*
196 *************************************************************************/
197 
198 Bitmap* XPropertyTable::GetBitmap( long nIndex ) const
199 {
200 	if( pBmpTable )
201 	{
202 		if( bBitmapsDirty )
203 		{
204 			( (XPropertyTable*) this )->bBitmapsDirty = sal_False;
205 			( (XPropertyTable*) this )->CreateBitmapsForUI();
206 		}
207 
208 		if( pBmpTable->Count() >= (sal_uIntPtr) nIndex )
209 			return (Bitmap*) pBmpTable->GetObject( (sal_uIntPtr) nIndex );
210 	}
211 	return( NULL );
212 }
213 
214 /*************************************************************************
215 |*
216 |* void XPropertyTable::Insert()
217 |*
218 *************************************************************************/
219 
220 sal_Bool XPropertyTable::Insert( long nIndex, XPropertyEntry* pEntry )
221 {
222 	sal_Bool bReturn = aTable.Insert( (sal_uIntPtr) nIndex, pEntry );
223 
224 	if( pBmpTable && !bBitmapsDirty )
225 	{
226 		Bitmap* pBmp = CreateBitmapForUI( (sal_uIntPtr) nIndex );
227 		pBmpTable->Insert( (sal_uIntPtr) nIndex, pBmp );
228 	}
229 	return bReturn;
230 }
231 
232 /*************************************************************************
233 |*
234 |* void XPropertyTable::Replace()
235 |*
236 *************************************************************************/
237 
238 XPropertyEntry* XPropertyTable::Replace( long nIndex, XPropertyEntry* pEntry )
239 {
240 	XPropertyEntry* pOldEntry = (XPropertyEntry*) aTable.Replace( (sal_uIntPtr) nIndex, pEntry );
241 
242 	if( pBmpTable && !bBitmapsDirty )
243 	{
244 		Bitmap* pBmp = CreateBitmapForUI( (sal_uIntPtr) nIndex );
245 		Bitmap* pOldBmp = (Bitmap*) pBmpTable->Replace( (sal_uIntPtr) nIndex, pBmp );
246 		if( pOldBmp )
247 			delete pOldBmp;
248 	}
249 	return pOldEntry;
250 }
251 
252 /*************************************************************************
253 |*
254 |* void XPropertyTable::Remove()
255 |*
256 *************************************************************************/
257 
258 XPropertyEntry* XPropertyTable::Remove( long nIndex, sal_uInt16 /*nDummy*/)
259 {
260 	if( pBmpTable && !bBitmapsDirty )
261 	{
262 		Bitmap* pOldBmp = (Bitmap*) pBmpTable->Remove( (sal_uIntPtr) nIndex );
263 		if( pOldBmp )
264 			delete pOldBmp;
265 	}
266 	return (XPropertyEntry*) aTable.Remove((sal_uIntPtr)nIndex);
267 }
268 
269 /************************************************************************/
270 
271 void XPropertyTable::SetName( const String& rString )
272 {
273 	if(rString.Len())
274 	{
275 		aName = rString;
276 	}
277 }
278 
279 // --------------------
280 // class XPropertyList
281 // --------------------
282 
283 
284 /*************************************************************************
285 |*
286 |* XPropertyList::XPropertyList()
287 |*
288 *************************************************************************/
289 
290 XPropertyList::XPropertyList( const String& rPath,
291 								XOutdevItemPool* pInPool,
292 								sal_uInt16 nInitSize, sal_uInt16 nReSize ) :
293 			aName			( pszStandard, 8 ),
294 			aPath			( rPath ),
295 			pXPool			( pInPool ),
296 			aList			( nInitSize, nReSize ),
297 			pBmpList		( NULL ),
298 			bListDirty		( sal_True ),
299 			bBitmapsDirty	( sal_True ),
300 			bOwnPool		( sal_False )
301 {
302 	if( !pXPool )
303 	{
304 		bOwnPool = sal_True;
305 		pXPool = new XOutdevItemPool;
306 		DBG_ASSERT( pXPool, "XOutPool konnte nicht erzeugt werden!" );
307 	}
308 }
309 
310 /*************************************************************************
311 |*
312 |* XPropertyList::XPropertyList( SvStraem& )
313 |*
314 *************************************************************************/
315 
316 XPropertyList::XPropertyList( SvStream& /*rIn*/) :
317 			pBmpList	( NULL )
318 {
319 }
320 
321 /*************************************************************************
322 |*
323 |* XPropertyList::~XPropertyList()
324 |*
325 *************************************************************************/
326 
327 XPropertyList::~XPropertyList()
328 {
329 	XPropertyEntry* pEntry = (XPropertyEntry*)aList.First();
330 	Bitmap* pBitmap = NULL;
331 	for( sal_uIntPtr nIndex = 0; nIndex < aList.Count(); nIndex++ )
332 	{
333 		delete pEntry;
334 		pEntry = (XPropertyEntry*)aList.Next();
335 	}
336 
337 	if( pBmpList )
338 	{
339 		pBitmap = (Bitmap*) pBmpList->First();
340 
341 		for( sal_uIntPtr nIndex = 0; nIndex < pBmpList->Count(); nIndex++ )
342 		{
343 			delete pBitmap;
344 			pBitmap = (Bitmap*) pBmpList->Next();
345 		}
346 		delete pBmpList;
347 		pBmpList = NULL;
348 	}
349 
350 	if( bOwnPool && pXPool )
351 	{
352         SfxItemPool::Free(pXPool);
353 	}
354 }
355 
356 /*************************************************************************
357 |*
358 |* XPropertyList::Clear()
359 |*
360 *************************************************************************/
361 
362 void XPropertyList::Clear()
363 {
364 	aList.Clear();
365 	if( pBmpList )
366 		pBmpList->Clear();
367 }
368 
369 /************************************************************************/
370 
371 long XPropertyList::Count() const
372 {
373 	if( bListDirty )
374 	{
375 		// ( (XPropertyList*) this )->bListDirty = sal_False; <- im Load()
376 		if( !( (XPropertyList*) this )->Load() )
377 			( (XPropertyList*) this )->Create();
378 	}
379 	return( aList.Count() );
380 }
381 
382 /*************************************************************************
383 |*
384 |* XPropertyEntry* XPropertyList::Get()
385 |*
386 *************************************************************************/
387 
388 XPropertyEntry* XPropertyList::Get( long nIndex, sal_uInt16 /*nDummy*/) const
389 {
390 	if( bListDirty )
391 	{
392 		// ( (XPropertyList*) this )->bListDirty = sal_False; <- im Load()
393 		if( !( (XPropertyList*) this )->Load() )
394 			( (XPropertyList*) this )->Create();
395 	}
396 	return (XPropertyEntry*) aList.GetObject( (sal_uIntPtr) nIndex );
397 }
398 
399 /*************************************************************************
400 |*
401 |* XPropertyList::Get()
402 |*
403 *************************************************************************/
404 
405 long XPropertyList::Get(const XubString& rName)
406 {
407 	if( bListDirty )
408 	{
409 		//bListDirty = sal_False;
410 		if( !Load() )
411 			Create();
412 	}
413 	long nPos = 0;
414 	XPropertyEntry* pEntry = (XPropertyEntry*)aList.First();
415 	while (pEntry && pEntry->GetName() != rName)
416 	{
417 		nPos++;
418 		pEntry = (XPropertyEntry*)aList.Next();
419 	}
420 	if (!pEntry) nPos = -1;
421 	return nPos;
422 }
423 
424 /*************************************************************************
425 |*
426 |* Bitmap* XPropertyList::GetBitmap()
427 |*
428 *************************************************************************/
429 
430 Bitmap* XPropertyList::GetBitmap( long nIndex ) const
431 {
432 	if( pBmpList )
433 	{
434 		if( bBitmapsDirty )
435 		{
436 			( (XPropertyList*) this )->bBitmapsDirty = sal_False;
437 			( (XPropertyList*) this )->CreateBitmapsForUI();
438 		}
439 		if( pBmpList->Count() >= (sal_uIntPtr) nIndex )
440 			return (Bitmap*) pBmpList->GetObject( (sal_uIntPtr) nIndex );
441 	}
442 	return( NULL );
443 }
444 
445 /*************************************************************************
446 |*
447 |* void XPropertyList::Insert()
448 |*
449 *************************************************************************/
450 
451 void XPropertyList::Insert( XPropertyEntry* pEntry, long nIndex )
452 {
453 	aList.Insert( pEntry, (sal_uIntPtr) nIndex );
454 
455 	if( pBmpList && !bBitmapsDirty )
456 	{
457 		Bitmap* pBmp = CreateBitmapForUI(
458 				(sal_uIntPtr) nIndex < aList.Count() ? nIndex : aList.Count() - 1 );
459 		pBmpList->Insert( pBmp, (sal_uIntPtr) nIndex );
460 	}
461 }
462 
463 /*************************************************************************
464 |*
465 |* void XPropertyList::Replace()
466 |*
467 *************************************************************************/
468 
469 XPropertyEntry* XPropertyList::Replace( XPropertyEntry* pEntry, long nIndex )
470 {
471 	XPropertyEntry* pOldEntry = (XPropertyEntry*) aList.Replace( pEntry, (sal_uIntPtr) nIndex );
472 
473 	if( pBmpList && !bBitmapsDirty )
474 	{
475 		Bitmap* pBmp = CreateBitmapForUI( (sal_uIntPtr) nIndex );
476 		Bitmap* pOldBmp = (Bitmap*) pBmpList->Replace( pBmp, (sal_uIntPtr) nIndex );
477 		if( pOldBmp )
478 			delete pOldBmp;
479 	}
480 	return pOldEntry;
481 }
482 
483 /*************************************************************************
484 |*
485 |* void XPropertyList::Remove()
486 |*
487 *************************************************************************/
488 
489 XPropertyEntry* XPropertyList::Remove( long nIndex, sal_uInt16 /*nDummy*/)
490 {
491 	if( pBmpList && !bBitmapsDirty )
492 	{
493 		Bitmap* pOldBmp = (Bitmap*) pBmpList->Remove( (sal_uIntPtr) nIndex );
494 		if( pOldBmp )
495 			delete pOldBmp;
496 	}
497 	return (XPropertyEntry*) aList.Remove( (sal_uIntPtr) nIndex );
498 }
499 
500 /************************************************************************/
501 
502 void XPropertyList::SetName( const String& rString )
503 {
504 	if(rString.Len())
505 	{
506 		aName = rString;
507 	}
508 }
509 
510 
511 
512