xref: /aoo41x/main/svx/source/xoutdev/xtable.cxx (revision c7be74b1)
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 		// ( (XPropertyList*) this )->bListDirty = sal_False; <- im Load()
163 		if( !( (XPropertyList*) this )->Load() )
164 			( (XPropertyList*) this )->Create();
165 	}
166 
167     return maContent.size();
168 }
169 
170 /*************************************************************************
171 |*
172 |* XPropertyEntry* XPropertyList::Get()
173 |*
174 *************************************************************************/
175 
176 XPropertyEntry* XPropertyList::Get( long nIndex ) const
177 {
178     if( mbListDirty )
179     {
180         if( !( (XPropertyList*) this )->Load() )
181             ( (XPropertyList*) this )->Create();
182     }
183 
184     if(nIndex >= maContent.size())
185     {
186         return 0;
187     }
188 
189     return maContent[nIndex];
190 }
191 
192 /*************************************************************************
193 |*
194 |* XPropertyList::Get()
195 |*
196 *************************************************************************/
197 
198 long XPropertyList::GetIndex(const XubString& rName) const
199 {
200     if( mbListDirty )
201     {
202         if( !( (XPropertyList*) this )->Load() )
203             ( (XPropertyList*) this )->Create();
204     }
205 
206     ::std::vector< XPropertyEntry* >::const_iterator aStart(maContent.begin());
207     const ::std::vector< XPropertyEntry* >::const_iterator aEnd(maContent.end());
208 
209     for(long a(0); aStart != aEnd; a++, aStart++)
210     {
211         const XPropertyEntry* pEntry = *aStart;
212 
213         if(pEntry && pEntry->GetName() == rName)
214         {
215             return a;
216         }
217     }
218 
219     return -1;
220 }
221 
222 /*************************************************************************
223 |*
224 |* Bitmap* XPropertyList::GetBitmap()
225 |*
226 *************************************************************************/
227 
228 Bitmap XPropertyList::GetUiBitmap( long nIndex ) const
229 {
230     Bitmap aRetval;
231     XPropertyEntry* pEntry = Get(nIndex);
232 
233     if(pEntry)
234     {
235         aRetval = pEntry->GetUiBitmap();
236 
237         if(aRetval.IsEmpty())
238         {
239             aRetval = const_cast< XPropertyList* >(this)->CreateBitmapForUI(nIndex);
240             pEntry->SetUiBitmap(aRetval);
241         }
242     }
243 
244     return aRetval;
245 }
246 
247 /*************************************************************************
248 |*
249 |* void XPropertyList::Insert()
250 |*
251 *************************************************************************/
252 
253 void XPropertyList::Insert( XPropertyEntry* pEntry, long nIndex )
254 {
255     if(pEntry)
256     {
257         if(nIndex >= maContent.size())
258         {
259             maContent.push_back(pEntry);
260         }
261         else
262         {
263             maContent.insert(maContent.begin() + nIndex, pEntry);
264         }
265     }
266 }
267 
268 /*************************************************************************
269 |*
270 |* void XPropertyList::Replace()
271 |*
272 *************************************************************************/
273 
274 XPropertyEntry* XPropertyList::Replace( XPropertyEntry* pEntry, long nIndex )
275 {
276     XPropertyEntry* pRetval = 0;
277 
278     if(pEntry)
279     {
280         if(nIndex < maContent.size())
281         {
282             pRetval = maContent[nIndex];
283             maContent[nIndex] = pEntry;
284         }
285     }
286 
287     return pRetval;
288 }
289 
290 /*************************************************************************
291 |*
292 |* void XPropertyList::Remove()
293 |*
294 *************************************************************************/
295 
296 XPropertyEntry* XPropertyList::Remove( long nIndex )
297 {
298     XPropertyEntry* pRetval = 0;
299 
300     if(nIndex < maContent.size())
301     {
302         if(nIndex + 1 == maContent.size())
303         {
304             pRetval = maContent.back();
305             maContent.pop_back();
306         }
307         else
308         {
309             pRetval = maContent[nIndex];
310             maContent.erase(maContent.begin() + nIndex);
311         }
312     }
313 
314     return pRetval;
315 }
316 
317 /************************************************************************/
318 
319 void XPropertyList::SetName( const String& rString )
320 {
321 	if(rString.Len())
322 	{
323 		maName = rString;
324 	}
325 }
326 
327 //////////////////////////////////////////////////////////////////////////////
328 
329 XColorListSharedPtr XPropertyListFactory::CreateSharedXColorList( const String& rPath )
330 {
331     return XColorListSharedPtr(new XColorList(rPath));
332 }
333 
334 XLineEndListSharedPtr XPropertyListFactory::CreateSharedXLineEndList( const String& rPath )
335 {
336     return XLineEndListSharedPtr(new XLineEndList(rPath));
337 }
338 
339 XDashListSharedPtr XPropertyListFactory::CreateSharedXDashList( const String& rPath )
340 {
341     return XDashListSharedPtr(new XDashList(rPath));
342 }
343 
344 XHatchListSharedPtr XPropertyListFactory::CreateSharedXHatchList( const String& rPath )
345 {
346     return XHatchListSharedPtr(new XHatchList(rPath));
347 }
348 
349 XGradientListSharedPtr XPropertyListFactory::CreateSharedXGradientList( const String& rPath )
350 {
351     return XGradientListSharedPtr(new XGradientList(rPath));
352 }
353 
354 XBitmapListSharedPtr XPropertyListFactory::CreateSharedXBitmapList( const String& rPath )
355 {
356     return XBitmapListSharedPtr(new XBitmapList(rPath));
357 }
358 
359 //////////////////////////////////////////////////////////////////////////////
360 // eof
361