Update ooo320-m1
[ooovba.git] / vcl / source / gdi / gradient.cxx
blobc000bc8106e62001bd67c6256e4511e1bd31140a
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: gradient.cxx,v $
10 * $Revision: 1.7 $
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/gradient.hxx>
38 // =======================================================================
40 DBG_NAME( Gradient )
42 // -----------------------------------------------------------------------
44 Impl_Gradient::Impl_Gradient() :
45 maStartColor( COL_BLACK ),
46 maEndColor( COL_WHITE )
48 mnRefCount = 1;
49 meStyle = GRADIENT_LINEAR;
50 mnAngle = 0;
51 mnBorder = 0;
52 mnOfsX = 50;
53 mnOfsY = 50;
54 mnIntensityStart = 100;
55 mnIntensityEnd = 100;
56 mnStepCount = 0;
59 // -----------------------------------------------------------------------
61 Impl_Gradient::Impl_Gradient( const Impl_Gradient& rImplGradient ) :
62 maStartColor( rImplGradient.maStartColor ),
63 maEndColor( rImplGradient.maEndColor )
65 mnRefCount = 1;
66 meStyle = rImplGradient.meStyle;
67 mnAngle = rImplGradient.mnAngle;
68 mnBorder = rImplGradient.mnBorder;
69 mnOfsX = rImplGradient.mnOfsX;
70 mnOfsY = rImplGradient.mnOfsY;
71 mnIntensityStart = rImplGradient.mnIntensityStart;
72 mnIntensityEnd = rImplGradient.mnIntensityEnd;
73 mnStepCount = rImplGradient.mnStepCount;
76 // -----------------------------------------------------------------------
78 void Gradient::MakeUnique()
80 // Falls noch andere Referenzen bestehen, dann kopieren
81 if ( mpImplGradient->mnRefCount != 1 )
83 if( mpImplGradient->mnRefCount )
84 mpImplGradient->mnRefCount--;
86 mpImplGradient = new Impl_Gradient( *mpImplGradient );
90 // -----------------------------------------------------------------------
92 Gradient::Gradient()
94 DBG_CTOR( Gradient, NULL );
96 mpImplGradient = new Impl_Gradient;
99 // -----------------------------------------------------------------------
101 Gradient::Gradient( const Gradient& rGradient )
103 DBG_CTOR( Gradient, NULL );
104 DBG_CHKOBJ( &rGradient, Gradient, NULL );
106 // Instance Daten uebernehmen und Referenzcounter erhoehen
107 mpImplGradient = rGradient.mpImplGradient;
108 mpImplGradient->mnRefCount++;
111 // -----------------------------------------------------------------------
113 Gradient::Gradient( GradientStyle eStyle )
115 DBG_CTOR( Gradient, NULL );
117 mpImplGradient = new Impl_Gradient;
118 mpImplGradient->meStyle = eStyle;
121 // -----------------------------------------------------------------------
123 Gradient::Gradient( GradientStyle eStyle,
124 const Color& rStartColor, const Color& rEndColor )
126 DBG_CTOR( Gradient, NULL );
128 mpImplGradient = new Impl_Gradient;
129 mpImplGradient->meStyle = eStyle;
130 mpImplGradient->maStartColor = rStartColor;
131 mpImplGradient->maEndColor = rEndColor;
134 // -----------------------------------------------------------------------
136 Gradient::~Gradient()
138 DBG_DTOR( Gradient, NULL );
140 // Wenn es die letzte Referenz ist, loeschen,
141 // sonst Referenzcounter decrementieren
142 if ( mpImplGradient->mnRefCount == 1 )
143 delete mpImplGradient;
144 else
145 mpImplGradient->mnRefCount--;
148 // -----------------------------------------------------------------------
150 void Gradient::SetStyle( GradientStyle eStyle )
152 DBG_CHKTHIS( Gradient, NULL );
154 MakeUnique();
155 mpImplGradient->meStyle = eStyle;
158 // -----------------------------------------------------------------------
160 void Gradient::SetStartColor( const Color& rColor )
162 DBG_CHKTHIS( Gradient, NULL );
164 MakeUnique();
165 mpImplGradient->maStartColor = rColor;
168 // -----------------------------------------------------------------------
170 void Gradient::SetEndColor( const Color& rColor )
172 DBG_CHKTHIS( Gradient, NULL );
174 MakeUnique();
175 mpImplGradient->maEndColor = rColor;
178 // -----------------------------------------------------------------------
180 void Gradient::SetAngle( USHORT nAngle )
182 DBG_CHKTHIS( Gradient, NULL );
184 MakeUnique();
185 mpImplGradient->mnAngle = nAngle;
188 // -----------------------------------------------------------------------
190 void Gradient::SetBorder( USHORT nBorder )
192 DBG_CHKTHIS( Gradient, NULL );
194 MakeUnique();
195 mpImplGradient->mnBorder = nBorder;
198 // -----------------------------------------------------------------------
200 void Gradient::SetOfsX( USHORT nOfsX )
202 DBG_CHKTHIS( Gradient, NULL );
204 MakeUnique();
205 mpImplGradient->mnOfsX = nOfsX;
208 // -----------------------------------------------------------------------
210 void Gradient::SetOfsY( USHORT nOfsY )
212 DBG_CHKTHIS( Gradient, NULL );
214 MakeUnique();
215 mpImplGradient->mnOfsY = nOfsY;
218 // -----------------------------------------------------------------------
220 void Gradient::SetStartIntensity( USHORT nIntens )
222 DBG_CHKTHIS( Gradient, NULL );
224 MakeUnique();
225 mpImplGradient->mnIntensityStart = nIntens;
228 // -----------------------------------------------------------------------
230 void Gradient::SetEndIntensity( USHORT nIntens )
232 DBG_CHKTHIS( Gradient, NULL );
234 MakeUnique();
235 mpImplGradient->mnIntensityEnd = nIntens;
238 // -----------------------------------------------------------------------
240 void Gradient::SetSteps( USHORT nSteps )
242 DBG_CHKTHIS( Gradient, NULL );
244 MakeUnique();
245 mpImplGradient->mnStepCount = nSteps;
248 // -----------------------------------------------------------------------
250 Gradient& Gradient::operator=( const Gradient& rGradient )
252 DBG_CHKTHIS( Gradient, NULL );
253 DBG_CHKOBJ( &rGradient, Gradient, NULL );
255 // Zuerst Referenzcounter erhoehen, damit man sich selbst zuweisen kann
256 rGradient.mpImplGradient->mnRefCount++;
258 // Wenn es die letzte Referenz ist, loeschen,
259 // sonst Referenzcounter decrementieren
260 if ( mpImplGradient->mnRefCount == 1 )
261 delete mpImplGradient;
262 else
263 mpImplGradient->mnRefCount--;
264 mpImplGradient = rGradient.mpImplGradient;
266 return *this;
269 // -----------------------------------------------------------------------
271 BOOL Gradient::operator==( const Gradient& rGradient ) const
273 DBG_CHKTHIS( Gradient, NULL );
274 DBG_CHKOBJ( &rGradient, Gradient, NULL );
276 if ( mpImplGradient == rGradient.mpImplGradient )
277 return TRUE;
279 if ( (mpImplGradient->meStyle == rGradient.mpImplGradient->meStyle) ||
280 (mpImplGradient->mnAngle == rGradient.mpImplGradient->mnAngle) ||
281 (mpImplGradient->mnBorder == rGradient.mpImplGradient->mnBorder) ||
282 (mpImplGradient->mnOfsX == rGradient.mpImplGradient->mnOfsX) ||
283 (mpImplGradient->mnOfsY == rGradient.mpImplGradient->mnOfsY) ||
284 (mpImplGradient->mnStepCount == rGradient.mpImplGradient->mnStepCount) ||
285 (mpImplGradient->mnIntensityStart == rGradient.mpImplGradient->mnIntensityStart) ||
286 (mpImplGradient->mnIntensityEnd == rGradient.mpImplGradient->mnIntensityEnd) ||
287 (mpImplGradient->maStartColor == rGradient.mpImplGradient->maStartColor) ||
288 (mpImplGradient->maEndColor == rGradient.mpImplGradient->maEndColor) )
289 return TRUE;
290 else
291 return FALSE;
294 SvStream& operator>>( SvStream& rIStm, Impl_Gradient& rImpl_Gradient )
296 VersionCompat aCompat( rIStm, STREAM_READ );
297 UINT16 nTmp16;
299 rIStm >> nTmp16; rImpl_Gradient.meStyle = (GradientStyle) nTmp16;
301 rIStm >> rImpl_Gradient.maStartColor >>
302 rImpl_Gradient.maEndColor >>
303 rImpl_Gradient.mnAngle >>
304 rImpl_Gradient.mnBorder >>
305 rImpl_Gradient.mnOfsX >>
306 rImpl_Gradient.mnOfsY >>
307 rImpl_Gradient.mnIntensityStart >>
308 rImpl_Gradient.mnIntensityEnd >>
309 rImpl_Gradient.mnStepCount;
311 return rIStm;
314 // -----------------------------------------------------------------------
316 SvStream& operator<<( SvStream& rOStm, const Impl_Gradient& rImpl_Gradient )
318 VersionCompat aCompat( rOStm, STREAM_WRITE, 1 );
320 rOStm << (UINT16) rImpl_Gradient.meStyle <<
321 rImpl_Gradient.maStartColor <<
322 rImpl_Gradient.maEndColor <<
323 rImpl_Gradient.mnAngle <<
324 rImpl_Gradient.mnBorder <<
325 rImpl_Gradient.mnOfsX <<
326 rImpl_Gradient.mnOfsY <<
327 rImpl_Gradient.mnIntensityStart <<
328 rImpl_Gradient.mnIntensityEnd <<
329 rImpl_Gradient.mnStepCount;
331 return rOStm;
334 // -----------------------------------------------------------------------
336 SvStream& operator>>( SvStream& rIStm, Gradient& rGradient )
338 rGradient.MakeUnique();
339 return( rIStm >> *rGradient.mpImplGradient );
342 // -----------------------------------------------------------------------
344 SvStream& operator<<( SvStream& rOStm, const Gradient& rGradient )
346 return( rOStm << *rGradient.mpImplGradient );