1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: gradient.cxx,v $
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 // =======================================================================
42 // -----------------------------------------------------------------------
44 Impl_Gradient::Impl_Gradient() :
45 maStartColor( COL_BLACK
),
46 maEndColor( COL_WHITE
)
49 meStyle
= GRADIENT_LINEAR
;
54 mnIntensityStart
= 100;
59 // -----------------------------------------------------------------------
61 Impl_Gradient::Impl_Gradient( const Impl_Gradient
& rImplGradient
) :
62 maStartColor( rImplGradient
.maStartColor
),
63 maEndColor( rImplGradient
.maEndColor
)
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 // -----------------------------------------------------------------------
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
;
145 mpImplGradient
->mnRefCount
--;
148 // -----------------------------------------------------------------------
150 void Gradient::SetStyle( GradientStyle eStyle
)
152 DBG_CHKTHIS( Gradient
, NULL
);
155 mpImplGradient
->meStyle
= eStyle
;
158 // -----------------------------------------------------------------------
160 void Gradient::SetStartColor( const Color
& rColor
)
162 DBG_CHKTHIS( Gradient
, NULL
);
165 mpImplGradient
->maStartColor
= rColor
;
168 // -----------------------------------------------------------------------
170 void Gradient::SetEndColor( const Color
& rColor
)
172 DBG_CHKTHIS( Gradient
, NULL
);
175 mpImplGradient
->maEndColor
= rColor
;
178 // -----------------------------------------------------------------------
180 void Gradient::SetAngle( USHORT nAngle
)
182 DBG_CHKTHIS( Gradient
, NULL
);
185 mpImplGradient
->mnAngle
= nAngle
;
188 // -----------------------------------------------------------------------
190 void Gradient::SetBorder( USHORT nBorder
)
192 DBG_CHKTHIS( Gradient
, NULL
);
195 mpImplGradient
->mnBorder
= nBorder
;
198 // -----------------------------------------------------------------------
200 void Gradient::SetOfsX( USHORT nOfsX
)
202 DBG_CHKTHIS( Gradient
, NULL
);
205 mpImplGradient
->mnOfsX
= nOfsX
;
208 // -----------------------------------------------------------------------
210 void Gradient::SetOfsY( USHORT nOfsY
)
212 DBG_CHKTHIS( Gradient
, NULL
);
215 mpImplGradient
->mnOfsY
= nOfsY
;
218 // -----------------------------------------------------------------------
220 void Gradient::SetStartIntensity( USHORT nIntens
)
222 DBG_CHKTHIS( Gradient
, NULL
);
225 mpImplGradient
->mnIntensityStart
= nIntens
;
228 // -----------------------------------------------------------------------
230 void Gradient::SetEndIntensity( USHORT nIntens
)
232 DBG_CHKTHIS( Gradient
, NULL
);
235 mpImplGradient
->mnIntensityEnd
= nIntens
;
238 // -----------------------------------------------------------------------
240 void Gradient::SetSteps( USHORT nSteps
)
242 DBG_CHKTHIS( Gradient
, NULL
);
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
;
263 mpImplGradient
->mnRefCount
--;
264 mpImplGradient
= rGradient
.mpImplGradient
;
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
)
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
) )
294 SvStream
& operator>>( SvStream
& rIStm
, Impl_Gradient
& rImpl_Gradient
)
296 VersionCompat
aCompat( rIStm
, STREAM_READ
);
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
;
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
;
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
);