Update ooo320-m1
[ooovba.git] / vcl / source / gdi / mapmod.cxx
blob5fc7feff3f6e37c5a6a2f4fd600507db6321ec22
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: mapmod.cxx,v $
10 * $Revision: 1.10 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_vcl.hxx"
33 #include <tools/stream.hxx>
34 #include <tools/vcompat.hxx>
35 #include <tools/debug.hxx>
36 #include <vcl/mapmod.hxx>
38 // =======================================================================
40 DBG_NAME( MapMode )
42 // -----------------------------------------------------------------------
44 ImplMapMode::ImplMapMode() :
45 maOrigin( 0, 0 ),
46 maScaleX( 1, 1 ),
47 maScaleY( 1, 1 )
49 mnRefCount = 1;
50 meUnit = MAP_PIXEL;
51 mbSimple = FALSE;
54 // -----------------------------------------------------------------------
56 ImplMapMode::ImplMapMode( const ImplMapMode& rImplMapMode ) :
57 maOrigin( rImplMapMode.maOrigin ),
58 maScaleX( rImplMapMode.maScaleX ),
59 maScaleY( rImplMapMode.maScaleY )
61 mnRefCount = 1;
62 meUnit = rImplMapMode.meUnit;
63 mbSimple = FALSE;
66 // -----------------------------------------------------------------------
68 SvStream& operator>>( SvStream& rIStm, ImplMapMode& rImplMapMode )
70 VersionCompat aCompat( rIStm, STREAM_READ );
71 UINT16 nTmp16;
73 rIStm >> nTmp16; rImplMapMode.meUnit = (MapUnit) nTmp16;
74 rIStm >> rImplMapMode.maOrigin >> rImplMapMode.maScaleX >>
75 rImplMapMode.maScaleY >> rImplMapMode.mbSimple;
77 return rIStm;
80 // -----------------------------------------------------------------------
82 SvStream& operator<<( SvStream& rOStm, const ImplMapMode& rImplMapMode )
84 VersionCompat aCompat( rOStm, STREAM_WRITE, 1 );
86 rOStm << (UINT16) rImplMapMode.meUnit <<
87 rImplMapMode.maOrigin <<
88 rImplMapMode.maScaleX <<
89 rImplMapMode.maScaleY <<
90 rImplMapMode.mbSimple;
92 return rOStm;
95 // -----------------------------------------------------------------------
97 ImplMapMode* ImplMapMode::ImplGetStaticMapMode( MapUnit eUnit )
99 static long aStaticImplMapModeAry[(MAP_LASTENUMDUMMY)*sizeof(ImplMapMode)/sizeof(long)];
101 // #i19496 check for out-of-bounds
102 if( eUnit >= MAP_LASTENUMDUMMY )
103 return (ImplMapMode*)aStaticImplMapModeAry;
105 ImplMapMode* pImplMapMode = ((ImplMapMode*)aStaticImplMapModeAry)+eUnit;
106 if ( !pImplMapMode->mbSimple )
108 Fraction aDefFraction( 1, 1 );
109 pImplMapMode->maScaleX = aDefFraction;
110 pImplMapMode->maScaleY = aDefFraction;
111 pImplMapMode->meUnit = eUnit;
112 pImplMapMode->mbSimple = TRUE;
115 return pImplMapMode;
118 // -----------------------------------------------------------------------
120 inline void MapMode::ImplMakeUnique()
122 // Falls noch andere Referenzen bestehen, dann kopieren
123 if ( mpImplMapMode->mnRefCount != 1 )
125 if ( mpImplMapMode->mnRefCount )
126 mpImplMapMode->mnRefCount--;
127 mpImplMapMode = new ImplMapMode( *mpImplMapMode );
131 // -----------------------------------------------------------------------
133 MapMode::MapMode()
135 DBG_CTOR( MapMode, NULL );
137 mpImplMapMode = ImplMapMode::ImplGetStaticMapMode( MAP_PIXEL );
140 // -----------------------------------------------------------------------
142 MapMode::MapMode( const MapMode& rMapMode )
144 DBG_CTOR( MapMode, NULL );
145 DBG_CHKOBJ( &rMapMode, MapMode, NULL );
146 DBG_ASSERT( rMapMode.mpImplMapMode->mnRefCount < 0xFFFFFFFE, "MapMode: RefCount overflow" );
148 // shared Instance Daten uebernehmen und Referenzcounter erhoehen
149 mpImplMapMode = rMapMode.mpImplMapMode;
150 // RefCount == 0 fuer statische Objekte
151 if ( mpImplMapMode->mnRefCount )
152 mpImplMapMode->mnRefCount++;
155 // -----------------------------------------------------------------------
157 MapMode::MapMode( MapUnit eUnit )
159 DBG_CTOR( MapMode, NULL );
161 mpImplMapMode = ImplMapMode::ImplGetStaticMapMode( eUnit );
164 // -----------------------------------------------------------------------
166 MapMode::MapMode( MapUnit eUnit, const Point& rLogicOrg,
167 const Fraction& rScaleX, const Fraction& rScaleY )
169 DBG_CTOR( MapMode, NULL );
171 mpImplMapMode = new ImplMapMode;
172 mpImplMapMode->meUnit = eUnit;
173 mpImplMapMode->maOrigin = rLogicOrg;
174 mpImplMapMode->maScaleX = rScaleX;
175 mpImplMapMode->maScaleY = rScaleY;
178 // -----------------------------------------------------------------------
180 MapMode::~MapMode()
182 DBG_DTOR( MapMode, NULL );
184 // Wenn es keine statischen ImpDaten sind, dann loeschen, wenn es
185 // die letzte Referenz ist, sonst Referenzcounter decrementieren
186 if ( mpImplMapMode->mnRefCount )
188 if ( mpImplMapMode->mnRefCount == 1 )
189 delete mpImplMapMode;
190 else
191 mpImplMapMode->mnRefCount--;
195 // -----------------------------------------------------------------------
197 void MapMode::SetMapUnit( MapUnit eUnit )
199 DBG_CHKTHIS( MapMode, NULL );
201 ImplMakeUnique();
202 mpImplMapMode->meUnit = eUnit;
205 // -----------------------------------------------------------------------
207 void MapMode::SetOrigin( const Point& rLogicOrg )
209 DBG_CHKTHIS( MapMode, NULL );
211 ImplMakeUnique();
212 mpImplMapMode->maOrigin = rLogicOrg;
215 // -----------------------------------------------------------------------
217 void MapMode::SetScaleX( const Fraction& rScaleX )
219 DBG_CHKTHIS( MapMode, NULL );
221 ImplMakeUnique();
222 mpImplMapMode->maScaleX = rScaleX;
225 // -----------------------------------------------------------------------
227 void MapMode::SetScaleY( const Fraction& rScaleY )
229 DBG_CHKTHIS( MapMode, NULL );
231 ImplMakeUnique();
232 mpImplMapMode->maScaleY = rScaleY;
235 // -----------------------------------------------------------------------
237 MapMode& MapMode::operator=( const MapMode& rMapMode )
239 DBG_CHKTHIS( MapMode, NULL );
240 DBG_CHKOBJ( &rMapMode, MapMode, NULL );
241 DBG_ASSERT( rMapMode.mpImplMapMode->mnRefCount < 0xFFFFFFFE, "MapMode: RefCount overflow" );
243 // Zuerst Referenzcounter erhoehen, damit man sich selbst zuweisen kann
244 // RefCount == 0 fuer statische Objekte
245 if ( rMapMode.mpImplMapMode->mnRefCount )
246 rMapMode.mpImplMapMode->mnRefCount++;
248 // Wenn es keine statischen ImpDaten sind, dann loeschen, wenn es
249 // die letzte Referenz ist, sonst Referenzcounter decrementieren
250 if ( mpImplMapMode->mnRefCount )
252 if ( mpImplMapMode->mnRefCount == 1 )
253 delete mpImplMapMode;
254 else
255 mpImplMapMode->mnRefCount--;
258 mpImplMapMode = rMapMode.mpImplMapMode;
260 return *this;
263 // -----------------------------------------------------------------------
265 BOOL MapMode::operator==( const MapMode& rMapMode ) const
267 DBG_CHKTHIS( MapMode, NULL );
268 DBG_CHKOBJ( &rMapMode, MapMode, NULL );
270 if ( mpImplMapMode == rMapMode.mpImplMapMode )
271 return TRUE;
273 if ( (mpImplMapMode->meUnit == rMapMode.mpImplMapMode->meUnit) &&
274 (mpImplMapMode->maOrigin == rMapMode.mpImplMapMode->maOrigin) &&
275 (mpImplMapMode->maScaleX == rMapMode.mpImplMapMode->maScaleX) &&
276 (mpImplMapMode->maScaleY == rMapMode.mpImplMapMode->maScaleY) )
277 return TRUE;
278 else
279 return FALSE;
282 // -----------------------------------------------------------------------
284 BOOL MapMode::IsDefault() const
286 DBG_CHKTHIS( MapMode, NULL );
288 ImplMapMode* pDefMapMode = ImplMapMode::ImplGetStaticMapMode( MAP_PIXEL );
289 if ( mpImplMapMode == pDefMapMode )
290 return TRUE;
292 if ( (mpImplMapMode->meUnit == pDefMapMode->meUnit) &&
293 (mpImplMapMode->maOrigin == pDefMapMode->maOrigin) &&
294 (mpImplMapMode->maScaleX == pDefMapMode->maScaleX) &&
295 (mpImplMapMode->maScaleY == pDefMapMode->maScaleY) )
296 return TRUE;
297 else
298 return FALSE;
301 // -----------------------------------------------------------------------
303 SvStream& operator>>( SvStream& rIStm, MapMode& rMapMode )
305 rMapMode.ImplMakeUnique();
306 return (rIStm >> *rMapMode.mpImplMapMode);
309 // -----------------------------------------------------------------------
311 SvStream& operator<<( SvStream& rOStm, const MapMode& rMapMode )
313 return (rOStm << *rMapMode.mpImplMapMode);