xref: /trunk/main/svx/source/xoutdev/xtable.cxx (revision 6b4168e0)
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 #include <svx/svdobj.hxx>
30 #include <svx/svdpool.hxx>
31 #include <vcl/virdev.hxx>
32 #include <svx/svdmodel.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 sharedModelAndVDev::sharedModelAndVDev()
49 :   mnUseCount(0),
50     mpVirtualDevice(0),
51     mpSdrModel(0)
52 {
53 }
54 
55 sharedModelAndVDev::~sharedModelAndVDev()
56 {
57     delete mpVirtualDevice;
58     delete mpSdrModel;
59 }
60 
61 void sharedModelAndVDev::increaseUseCount()
62 {
63     mnUseCount++;
64 }
65 
66 bool sharedModelAndVDev::decreaseUseCount()
67 {
68     if(mnUseCount)
69     {
70         mnUseCount--;
71     }
72 
73     return 0 == mnUseCount;
74 }
75 
76 SdrModel& sharedModelAndVDev::getSharedSdrModel()
77 {
78     if(!mpSdrModel)
79     {
80         mpSdrModel = new SdrModel();
81         OSL_ENSURE(0 != mpSdrModel, "XPropertyList sharedModelAndVDev: no SdrModel created!" );
82         mpSdrModel->GetItemPool().FreezeIdRanges();
83     }
84 
85     return *mpSdrModel;
86 }
87 
88 VirtualDevice& sharedModelAndVDev::getSharedVirtualDevice()
89 {
90     if(!mpVirtualDevice)
91     {
92         mpVirtualDevice = new VirtualDevice;
93         OSL_ENSURE(0 != mpVirtualDevice, "XPropertyList sharedModelAndVDev: no VirtualDevice created!" );
94         mpVirtualDevice->SetMapMode(MAP_100TH_MM);
95     }
96 
97     return *mpVirtualDevice;
98 }
99 
100 sharedModelAndVDev* XPropertyList::pGlobalsharedModelAndVDev = 0;
101 
102 // --------------------
103 // class XPropertyList
104 // --------------------
105 
106 XPropertyList::XPropertyList( const String& rPath ) :
107 			maName			( pszStandard, 8 ),
108 			maPath			( rPath ),
109 			maContent(),
110 			mbListDirty		(true)
111 {
112     if(!pGlobalsharedModelAndVDev)
113     {
114         pGlobalsharedModelAndVDev = new sharedModelAndVDev();
115     }
116 
117     pGlobalsharedModelAndVDev->increaseUseCount();
118 }
119 
120 /*************************************************************************
121 |*
122 |* XPropertyList::~XPropertyList()
123 |*
124 *************************************************************************/
125 
126 XPropertyList::~XPropertyList()
127 {
128     while(!maContent.empty())
129     {
130         delete maContent.back();
131         maContent.pop_back();
132     }
133 
134     if(pGlobalsharedModelAndVDev && pGlobalsharedModelAndVDev->decreaseUseCount())
135     {
136         delete pGlobalsharedModelAndVDev;
137         pGlobalsharedModelAndVDev = 0;
138     }
139 }
140 
141 /*************************************************************************
142 |*
143 |* XPropertyList::Clear()
144 |*
145 *************************************************************************/
146 
147 void XPropertyList::Clear()
148 {
149     while(!maContent.empty())
150     {
151         delete maContent.back();
152         maContent.pop_back();
153     }
154 }
155 
156 /************************************************************************/
157 
158 long XPropertyList::Count() const
159 {
160     if( mbListDirty )
161     {
162         if(!const_cast< XPropertyList* >(this)->Load())
163         {
164             const_cast< XPropertyList* >(this)->Create();
165         }
166     }
167 
168     return maContent.size();
169 }
170 
171 /*************************************************************************
172 |*
173 |* XPropertyEntry* XPropertyList::Get()
174 |*
175 *************************************************************************/
176 
177 XPropertyEntry* XPropertyList::Get( long nIndex ) const
178 {
179     if( mbListDirty )
180     {
181         if(!const_cast< XPropertyList* >(this)->Load())
182         {
183             const_cast< XPropertyList* >(this)->Create();
184         }
185     }
186 
187     const long nObjectCount(maContent.size());
188 
189     if(nIndex >= nObjectCount)
190     {
191         return 0;
192     }
193 
194     return maContent[nIndex];
195 }
196 
197 /*************************************************************************
198 |*
199 |* XPropertyList::Get()
200 |*
201 *************************************************************************/
202 
203 long XPropertyList::GetIndex(const XubString& rName) const
204 {
205     if( mbListDirty )
206     {
207         if(!const_cast< XPropertyList* >(this)->Load())
208         {
209             const_cast< XPropertyList* >(this)->Create();
210         }
211     }
212 
213     ::std::vector< XPropertyEntry* >::const_iterator aStart(maContent.begin());
214     const ::std::vector< XPropertyEntry* >::const_iterator aEnd(maContent.end());
215 
216     for(long a(0); aStart != aEnd; a++, aStart++)
217     {
218         const XPropertyEntry* pEntry = *aStart;
219 
220         if(pEntry && pEntry->GetName() == rName)
221         {
222             return a;
223         }
224     }
225 
226     return -1;
227 }
228 
229 /*************************************************************************
230 |*
231 |* Bitmap* XPropertyList::GetBitmap()
232 |*
233 *************************************************************************/
234 
235 Bitmap XPropertyList::GetUiBitmap( long nIndex ) const
236 {
237     Bitmap aRetval;
238     XPropertyEntry* pEntry = Get(nIndex);
239 
240     if(pEntry)
241     {
242         aRetval = pEntry->GetUiBitmap();
243 
244         if(aRetval.IsEmpty())
245         {
246             aRetval = const_cast< XPropertyList* >(this)->CreateBitmapForUI(nIndex);
247             pEntry->SetUiBitmap(aRetval);
248         }
249     }
250 
251     return aRetval;
252 }
253 
254 /*************************************************************************
255 |*
256 |* void XPropertyList::Insert()
257 |*
258 *************************************************************************/
259 
260 void XPropertyList::Insert( XPropertyEntry* pEntry, long nIndex )
261 {
262     if(pEntry)
263     {
264         const long nObjectCount(maContent.size());
265 
266         if(LIST_APPEND == nIndex || nIndex >= nObjectCount)
267         {
268             maContent.push_back(pEntry);
269         }
270         else
271         {
272             maContent.insert(maContent.begin() + nIndex, pEntry);
273         }
274     }
275 }
276 
277 /*************************************************************************
278 |*
279 |* void XPropertyList::Replace()
280 |*
281 *************************************************************************/
282 
283 XPropertyEntry* XPropertyList::Replace( XPropertyEntry* pEntry, long nIndex )
284 {
285     XPropertyEntry* pRetval = 0;
286 
287     if(pEntry)
288     {
289         const long nObjectCount(maContent.size());
290 
291         if(nIndex < nObjectCount)
292         {
293             pRetval = maContent[nIndex];
294             maContent[nIndex] = pEntry;
295         }
296     }
297 
298     return pRetval;
299 }
300 
301 /*************************************************************************
302 |*
303 |* void XPropertyList::Remove()
304 |*
305 *************************************************************************/
306 
307 XPropertyEntry* XPropertyList::Remove( long nIndex )
308 {
309     XPropertyEntry* pRetval = 0;
310     const long nObjectCount(maContent.size());
311 
312     if(nIndex < nObjectCount)
313     {
314         if(nIndex + 1 == nObjectCount)
315         {
316             pRetval = maContent.back();
317             maContent.pop_back();
318         }
319         else
320         {
321             pRetval = maContent[nIndex];
322             maContent.erase(maContent.begin() + nIndex);
323         }
324     }
325 
326     return pRetval;
327 }
328 
329 /************************************************************************/
330 
331 void XPropertyList::SetName( const String& rString )
332 {
333 	if(rString.Len())
334 	{
335 		maName = rString;
336 	}
337 }
338 
339 //////////////////////////////////////////////////////////////////////////////
340 
341 XColorListSharedPtr XPropertyListFactory::CreateSharedXColorList( const String& rPath )
342 {
343     return XColorListSharedPtr(new XColorList(rPath));
344 }
345 
346 XLineEndListSharedPtr XPropertyListFactory::CreateSharedXLineEndList( const String& rPath )
347 {
348     return XLineEndListSharedPtr(new XLineEndList(rPath));
349 }
350 
351 XDashListSharedPtr XPropertyListFactory::CreateSharedXDashList( const String& rPath )
352 {
353     return XDashListSharedPtr(new XDashList(rPath));
354 }
355 
356 XHatchListSharedPtr XPropertyListFactory::CreateSharedXHatchList( const String& rPath )
357 {
358     return XHatchListSharedPtr(new XHatchList(rPath));
359 }
360 
361 XGradientListSharedPtr XPropertyListFactory::CreateSharedXGradientList( const String& rPath )
362 {
363     return XGradientListSharedPtr(new XGradientList(rPath));
364 }
365 
366 XBitmapListSharedPtr XPropertyListFactory::CreateSharedXBitmapList( const String& rPath )
367 {
368     return XBitmapListSharedPtr(new XBitmapList(rPath));
369 }
370 
371 //////////////////////////////////////////////////////////////////////////////
372 // eof
373