xref: /AOO41X/main/vcl/source/gdi/gradient.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_vcl.hxx"
30*cdf0e10cSrcweir #include <tools/stream.hxx>
31*cdf0e10cSrcweir #include <tools/vcompat.hxx>
32*cdf0e10cSrcweir #include <tools/debug.hxx>
33*cdf0e10cSrcweir #include <vcl/gradient.hxx>
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir // =======================================================================
36*cdf0e10cSrcweir 
37*cdf0e10cSrcweir DBG_NAME( Gradient )
38*cdf0e10cSrcweir 
39*cdf0e10cSrcweir // -----------------------------------------------------------------------
40*cdf0e10cSrcweir 
41*cdf0e10cSrcweir Impl_Gradient::Impl_Gradient() :
42*cdf0e10cSrcweir     maStartColor( COL_BLACK ),
43*cdf0e10cSrcweir     maEndColor( COL_WHITE )
44*cdf0e10cSrcweir {
45*cdf0e10cSrcweir     mnRefCount          = 1;
46*cdf0e10cSrcweir     meStyle             = GRADIENT_LINEAR;
47*cdf0e10cSrcweir     mnAngle             = 0;
48*cdf0e10cSrcweir     mnBorder            = 0;
49*cdf0e10cSrcweir     mnOfsX              = 50;
50*cdf0e10cSrcweir     mnOfsY              = 50;
51*cdf0e10cSrcweir     mnIntensityStart    = 100;
52*cdf0e10cSrcweir     mnIntensityEnd      = 100;
53*cdf0e10cSrcweir     mnStepCount         = 0;
54*cdf0e10cSrcweir }
55*cdf0e10cSrcweir 
56*cdf0e10cSrcweir // -----------------------------------------------------------------------
57*cdf0e10cSrcweir 
58*cdf0e10cSrcweir Impl_Gradient::Impl_Gradient( const Impl_Gradient& rImplGradient ) :
59*cdf0e10cSrcweir     maStartColor( rImplGradient.maStartColor ),
60*cdf0e10cSrcweir     maEndColor( rImplGradient.maEndColor )
61*cdf0e10cSrcweir {
62*cdf0e10cSrcweir     mnRefCount          = 1;
63*cdf0e10cSrcweir     meStyle             = rImplGradient.meStyle;
64*cdf0e10cSrcweir     mnAngle             = rImplGradient.mnAngle;
65*cdf0e10cSrcweir     mnBorder            = rImplGradient.mnBorder;
66*cdf0e10cSrcweir     mnOfsX              = rImplGradient.mnOfsX;
67*cdf0e10cSrcweir     mnOfsY              = rImplGradient.mnOfsY;
68*cdf0e10cSrcweir     mnIntensityStart    = rImplGradient.mnIntensityStart;
69*cdf0e10cSrcweir     mnIntensityEnd      = rImplGradient.mnIntensityEnd;
70*cdf0e10cSrcweir     mnStepCount         = rImplGradient.mnStepCount;
71*cdf0e10cSrcweir }
72*cdf0e10cSrcweir 
73*cdf0e10cSrcweir // -----------------------------------------------------------------------
74*cdf0e10cSrcweir 
75*cdf0e10cSrcweir void Gradient::MakeUnique()
76*cdf0e10cSrcweir {
77*cdf0e10cSrcweir     // Falls noch andere Referenzen bestehen, dann kopieren
78*cdf0e10cSrcweir     if ( mpImplGradient->mnRefCount != 1 )
79*cdf0e10cSrcweir 	{
80*cdf0e10cSrcweir 		if( mpImplGradient->mnRefCount )
81*cdf0e10cSrcweir 			mpImplGradient->mnRefCount--;
82*cdf0e10cSrcweir 
83*cdf0e10cSrcweir         mpImplGradient = new Impl_Gradient( *mpImplGradient );
84*cdf0e10cSrcweir 	}
85*cdf0e10cSrcweir }
86*cdf0e10cSrcweir 
87*cdf0e10cSrcweir // -----------------------------------------------------------------------
88*cdf0e10cSrcweir 
89*cdf0e10cSrcweir Gradient::Gradient()
90*cdf0e10cSrcweir {
91*cdf0e10cSrcweir     DBG_CTOR( Gradient, NULL );
92*cdf0e10cSrcweir 
93*cdf0e10cSrcweir     mpImplGradient = new Impl_Gradient;
94*cdf0e10cSrcweir }
95*cdf0e10cSrcweir 
96*cdf0e10cSrcweir // -----------------------------------------------------------------------
97*cdf0e10cSrcweir 
98*cdf0e10cSrcweir Gradient::Gradient( const Gradient& rGradient )
99*cdf0e10cSrcweir {
100*cdf0e10cSrcweir     DBG_CTOR( Gradient, NULL );
101*cdf0e10cSrcweir     DBG_CHKOBJ( &rGradient, Gradient, NULL );
102*cdf0e10cSrcweir 
103*cdf0e10cSrcweir     // Instance Daten uebernehmen und Referenzcounter erhoehen
104*cdf0e10cSrcweir     mpImplGradient = rGradient.mpImplGradient;
105*cdf0e10cSrcweir     mpImplGradient->mnRefCount++;
106*cdf0e10cSrcweir }
107*cdf0e10cSrcweir 
108*cdf0e10cSrcweir // -----------------------------------------------------------------------
109*cdf0e10cSrcweir 
110*cdf0e10cSrcweir Gradient::Gradient( GradientStyle eStyle )
111*cdf0e10cSrcweir {
112*cdf0e10cSrcweir     DBG_CTOR( Gradient, NULL );
113*cdf0e10cSrcweir 
114*cdf0e10cSrcweir     mpImplGradient          = new Impl_Gradient;
115*cdf0e10cSrcweir     mpImplGradient->meStyle = eStyle;
116*cdf0e10cSrcweir }
117*cdf0e10cSrcweir 
118*cdf0e10cSrcweir // -----------------------------------------------------------------------
119*cdf0e10cSrcweir 
120*cdf0e10cSrcweir Gradient::Gradient( GradientStyle eStyle,
121*cdf0e10cSrcweir                     const Color& rStartColor, const Color& rEndColor )
122*cdf0e10cSrcweir {
123*cdf0e10cSrcweir     DBG_CTOR( Gradient, NULL );
124*cdf0e10cSrcweir 
125*cdf0e10cSrcweir     mpImplGradient                  = new Impl_Gradient;
126*cdf0e10cSrcweir     mpImplGradient->meStyle         = eStyle;
127*cdf0e10cSrcweir     mpImplGradient->maStartColor    = rStartColor;
128*cdf0e10cSrcweir     mpImplGradient->maEndColor      = rEndColor;
129*cdf0e10cSrcweir }
130*cdf0e10cSrcweir 
131*cdf0e10cSrcweir // -----------------------------------------------------------------------
132*cdf0e10cSrcweir 
133*cdf0e10cSrcweir Gradient::~Gradient()
134*cdf0e10cSrcweir {
135*cdf0e10cSrcweir     DBG_DTOR( Gradient, NULL );
136*cdf0e10cSrcweir 
137*cdf0e10cSrcweir     // Wenn es die letzte Referenz ist, loeschen,
138*cdf0e10cSrcweir     // sonst Referenzcounter decrementieren
139*cdf0e10cSrcweir     if ( mpImplGradient->mnRefCount == 1 )
140*cdf0e10cSrcweir         delete mpImplGradient;
141*cdf0e10cSrcweir     else
142*cdf0e10cSrcweir         mpImplGradient->mnRefCount--;
143*cdf0e10cSrcweir }
144*cdf0e10cSrcweir 
145*cdf0e10cSrcweir // -----------------------------------------------------------------------
146*cdf0e10cSrcweir 
147*cdf0e10cSrcweir void Gradient::SetStyle( GradientStyle eStyle )
148*cdf0e10cSrcweir {
149*cdf0e10cSrcweir     DBG_CHKTHIS( Gradient, NULL );
150*cdf0e10cSrcweir 
151*cdf0e10cSrcweir     MakeUnique();
152*cdf0e10cSrcweir     mpImplGradient->meStyle = eStyle;
153*cdf0e10cSrcweir }
154*cdf0e10cSrcweir 
155*cdf0e10cSrcweir // -----------------------------------------------------------------------
156*cdf0e10cSrcweir 
157*cdf0e10cSrcweir void Gradient::SetStartColor( const Color& rColor )
158*cdf0e10cSrcweir {
159*cdf0e10cSrcweir     DBG_CHKTHIS( Gradient, NULL );
160*cdf0e10cSrcweir 
161*cdf0e10cSrcweir     MakeUnique();
162*cdf0e10cSrcweir     mpImplGradient->maStartColor = rColor;
163*cdf0e10cSrcweir }
164*cdf0e10cSrcweir 
165*cdf0e10cSrcweir // -----------------------------------------------------------------------
166*cdf0e10cSrcweir 
167*cdf0e10cSrcweir void Gradient::SetEndColor( const Color& rColor )
168*cdf0e10cSrcweir {
169*cdf0e10cSrcweir     DBG_CHKTHIS( Gradient, NULL );
170*cdf0e10cSrcweir 
171*cdf0e10cSrcweir     MakeUnique();
172*cdf0e10cSrcweir     mpImplGradient->maEndColor = rColor;
173*cdf0e10cSrcweir }
174*cdf0e10cSrcweir 
175*cdf0e10cSrcweir // -----------------------------------------------------------------------
176*cdf0e10cSrcweir 
177*cdf0e10cSrcweir void Gradient::SetAngle( sal_uInt16 nAngle )
178*cdf0e10cSrcweir {
179*cdf0e10cSrcweir     DBG_CHKTHIS( Gradient, NULL );
180*cdf0e10cSrcweir 
181*cdf0e10cSrcweir     MakeUnique();
182*cdf0e10cSrcweir     mpImplGradient->mnAngle = nAngle;
183*cdf0e10cSrcweir }
184*cdf0e10cSrcweir 
185*cdf0e10cSrcweir // -----------------------------------------------------------------------
186*cdf0e10cSrcweir 
187*cdf0e10cSrcweir void Gradient::SetBorder( sal_uInt16 nBorder )
188*cdf0e10cSrcweir {
189*cdf0e10cSrcweir     DBG_CHKTHIS( Gradient, NULL );
190*cdf0e10cSrcweir 
191*cdf0e10cSrcweir     MakeUnique();
192*cdf0e10cSrcweir     mpImplGradient->mnBorder = nBorder;
193*cdf0e10cSrcweir }
194*cdf0e10cSrcweir 
195*cdf0e10cSrcweir // -----------------------------------------------------------------------
196*cdf0e10cSrcweir 
197*cdf0e10cSrcweir void Gradient::SetOfsX( sal_uInt16 nOfsX )
198*cdf0e10cSrcweir {
199*cdf0e10cSrcweir     DBG_CHKTHIS( Gradient, NULL );
200*cdf0e10cSrcweir 
201*cdf0e10cSrcweir     MakeUnique();
202*cdf0e10cSrcweir     mpImplGradient->mnOfsX = nOfsX;
203*cdf0e10cSrcweir }
204*cdf0e10cSrcweir 
205*cdf0e10cSrcweir // -----------------------------------------------------------------------
206*cdf0e10cSrcweir 
207*cdf0e10cSrcweir void Gradient::SetOfsY( sal_uInt16 nOfsY )
208*cdf0e10cSrcweir {
209*cdf0e10cSrcweir     DBG_CHKTHIS( Gradient, NULL );
210*cdf0e10cSrcweir 
211*cdf0e10cSrcweir     MakeUnique();
212*cdf0e10cSrcweir     mpImplGradient->mnOfsY = nOfsY;
213*cdf0e10cSrcweir }
214*cdf0e10cSrcweir 
215*cdf0e10cSrcweir // -----------------------------------------------------------------------
216*cdf0e10cSrcweir 
217*cdf0e10cSrcweir void Gradient::SetStartIntensity( sal_uInt16 nIntens )
218*cdf0e10cSrcweir {
219*cdf0e10cSrcweir     DBG_CHKTHIS( Gradient, NULL );
220*cdf0e10cSrcweir 
221*cdf0e10cSrcweir     MakeUnique();
222*cdf0e10cSrcweir     mpImplGradient->mnIntensityStart = nIntens;
223*cdf0e10cSrcweir }
224*cdf0e10cSrcweir 
225*cdf0e10cSrcweir // -----------------------------------------------------------------------
226*cdf0e10cSrcweir 
227*cdf0e10cSrcweir void Gradient::SetEndIntensity( sal_uInt16 nIntens )
228*cdf0e10cSrcweir {
229*cdf0e10cSrcweir     DBG_CHKTHIS( Gradient, NULL );
230*cdf0e10cSrcweir 
231*cdf0e10cSrcweir     MakeUnique();
232*cdf0e10cSrcweir     mpImplGradient->mnIntensityEnd = nIntens;
233*cdf0e10cSrcweir }
234*cdf0e10cSrcweir 
235*cdf0e10cSrcweir // -----------------------------------------------------------------------
236*cdf0e10cSrcweir 
237*cdf0e10cSrcweir void Gradient::SetSteps( sal_uInt16 nSteps )
238*cdf0e10cSrcweir {
239*cdf0e10cSrcweir     DBG_CHKTHIS( Gradient, NULL );
240*cdf0e10cSrcweir 
241*cdf0e10cSrcweir     MakeUnique();
242*cdf0e10cSrcweir     mpImplGradient->mnStepCount = nSteps;
243*cdf0e10cSrcweir }
244*cdf0e10cSrcweir 
245*cdf0e10cSrcweir // -----------------------------------------------------------------------
246*cdf0e10cSrcweir 
247*cdf0e10cSrcweir Gradient& Gradient::operator=( const Gradient& rGradient )
248*cdf0e10cSrcweir {
249*cdf0e10cSrcweir     DBG_CHKTHIS( Gradient, NULL );
250*cdf0e10cSrcweir     DBG_CHKOBJ( &rGradient, Gradient, NULL );
251*cdf0e10cSrcweir 
252*cdf0e10cSrcweir     // Zuerst Referenzcounter erhoehen, damit man sich selbst zuweisen kann
253*cdf0e10cSrcweir     rGradient.mpImplGradient->mnRefCount++;
254*cdf0e10cSrcweir 
255*cdf0e10cSrcweir     // Wenn es die letzte Referenz ist, loeschen,
256*cdf0e10cSrcweir     // sonst Referenzcounter decrementieren
257*cdf0e10cSrcweir     if ( mpImplGradient->mnRefCount == 1 )
258*cdf0e10cSrcweir         delete mpImplGradient;
259*cdf0e10cSrcweir     else
260*cdf0e10cSrcweir         mpImplGradient->mnRefCount--;
261*cdf0e10cSrcweir     mpImplGradient = rGradient.mpImplGradient;
262*cdf0e10cSrcweir 
263*cdf0e10cSrcweir     return *this;
264*cdf0e10cSrcweir }
265*cdf0e10cSrcweir 
266*cdf0e10cSrcweir // -----------------------------------------------------------------------
267*cdf0e10cSrcweir 
268*cdf0e10cSrcweir sal_Bool Gradient::operator==( const Gradient& rGradient ) const
269*cdf0e10cSrcweir {
270*cdf0e10cSrcweir     DBG_CHKTHIS( Gradient, NULL );
271*cdf0e10cSrcweir     DBG_CHKOBJ( &rGradient, Gradient, NULL );
272*cdf0e10cSrcweir 
273*cdf0e10cSrcweir     if ( mpImplGradient == rGradient.mpImplGradient )
274*cdf0e10cSrcweir         return sal_True;
275*cdf0e10cSrcweir 
276*cdf0e10cSrcweir     if ( (mpImplGradient->meStyle           == rGradient.mpImplGradient->meStyle)           ||
277*cdf0e10cSrcweir          (mpImplGradient->mnAngle           == rGradient.mpImplGradient->mnAngle)           ||
278*cdf0e10cSrcweir          (mpImplGradient->mnBorder          == rGradient.mpImplGradient->mnBorder)          ||
279*cdf0e10cSrcweir          (mpImplGradient->mnOfsX            == rGradient.mpImplGradient->mnOfsX)            ||
280*cdf0e10cSrcweir          (mpImplGradient->mnOfsY            == rGradient.mpImplGradient->mnOfsY)            ||
281*cdf0e10cSrcweir          (mpImplGradient->mnStepCount       == rGradient.mpImplGradient->mnStepCount)       ||
282*cdf0e10cSrcweir          (mpImplGradient->mnIntensityStart  == rGradient.mpImplGradient->mnIntensityStart)  ||
283*cdf0e10cSrcweir          (mpImplGradient->mnIntensityEnd    == rGradient.mpImplGradient->mnIntensityEnd)    ||
284*cdf0e10cSrcweir          (mpImplGradient->maStartColor      == rGradient.mpImplGradient->maStartColor)      ||
285*cdf0e10cSrcweir          (mpImplGradient->maEndColor        == rGradient.mpImplGradient->maEndColor) )
286*cdf0e10cSrcweir          return sal_True;
287*cdf0e10cSrcweir     else
288*cdf0e10cSrcweir         return sal_False;
289*cdf0e10cSrcweir }
290*cdf0e10cSrcweir 
291*cdf0e10cSrcweir SvStream& operator>>( SvStream& rIStm, Impl_Gradient& rImpl_Gradient )
292*cdf0e10cSrcweir {
293*cdf0e10cSrcweir     VersionCompat	aCompat( rIStm, STREAM_READ );
294*cdf0e10cSrcweir     sal_uInt16			nTmp16;
295*cdf0e10cSrcweir 
296*cdf0e10cSrcweir     rIStm >> nTmp16; rImpl_Gradient.meStyle = (GradientStyle) nTmp16;
297*cdf0e10cSrcweir 
298*cdf0e10cSrcweir     rIStm >> rImpl_Gradient.maStartColor >>
299*cdf0e10cSrcweir              rImpl_Gradient.maEndColor >>
300*cdf0e10cSrcweir              rImpl_Gradient.mnAngle >>
301*cdf0e10cSrcweir              rImpl_Gradient.mnBorder >>
302*cdf0e10cSrcweir              rImpl_Gradient.mnOfsX >>
303*cdf0e10cSrcweir              rImpl_Gradient.mnOfsY >>
304*cdf0e10cSrcweir              rImpl_Gradient.mnIntensityStart >>
305*cdf0e10cSrcweir              rImpl_Gradient.mnIntensityEnd >>
306*cdf0e10cSrcweir              rImpl_Gradient.mnStepCount;
307*cdf0e10cSrcweir 
308*cdf0e10cSrcweir     return rIStm;
309*cdf0e10cSrcweir }
310*cdf0e10cSrcweir 
311*cdf0e10cSrcweir // -----------------------------------------------------------------------
312*cdf0e10cSrcweir 
313*cdf0e10cSrcweir SvStream& operator<<( SvStream& rOStm, const Impl_Gradient& rImpl_Gradient )
314*cdf0e10cSrcweir {
315*cdf0e10cSrcweir     VersionCompat aCompat( rOStm, STREAM_WRITE, 1 );
316*cdf0e10cSrcweir 
317*cdf0e10cSrcweir     rOStm << (sal_uInt16) rImpl_Gradient.meStyle <<
318*cdf0e10cSrcweir              rImpl_Gradient.maStartColor <<
319*cdf0e10cSrcweir              rImpl_Gradient.maEndColor <<
320*cdf0e10cSrcweir              rImpl_Gradient.mnAngle <<
321*cdf0e10cSrcweir              rImpl_Gradient.mnBorder <<
322*cdf0e10cSrcweir              rImpl_Gradient.mnOfsX <<
323*cdf0e10cSrcweir              rImpl_Gradient.mnOfsY <<
324*cdf0e10cSrcweir              rImpl_Gradient.mnIntensityStart <<
325*cdf0e10cSrcweir              rImpl_Gradient.mnIntensityEnd <<
326*cdf0e10cSrcweir              rImpl_Gradient.mnStepCount;
327*cdf0e10cSrcweir 
328*cdf0e10cSrcweir     return rOStm;
329*cdf0e10cSrcweir }
330*cdf0e10cSrcweir 
331*cdf0e10cSrcweir // -----------------------------------------------------------------------
332*cdf0e10cSrcweir 
333*cdf0e10cSrcweir SvStream& operator>>( SvStream& rIStm, Gradient& rGradient )
334*cdf0e10cSrcweir {
335*cdf0e10cSrcweir     rGradient.MakeUnique();
336*cdf0e10cSrcweir     return( rIStm >> *rGradient.mpImplGradient );
337*cdf0e10cSrcweir }
338*cdf0e10cSrcweir 
339*cdf0e10cSrcweir // -----------------------------------------------------------------------
340*cdf0e10cSrcweir 
341*cdf0e10cSrcweir SvStream& operator<<( SvStream& rOStm, const Gradient& rGradient )
342*cdf0e10cSrcweir {
343*cdf0e10cSrcweir     return( rOStm << *rGradient.mpImplGradient );
344*cdf0e10cSrcweir }
345