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