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