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_vcl.hxx"
26 #include <tools/stream.hxx>
27 #include <tools/vcompat.hxx>
28 #include <tools/debug.hxx>
29 #include <vcl/gradient.hxx>
30
31 // =======================================================================
32
DBG_NAME(Gradient)33 DBG_NAME( Gradient )
34
35 // -----------------------------------------------------------------------
36
37 Impl_Gradient::Impl_Gradient() :
38 maStartColor( COL_BLACK ),
39 maEndColor( COL_WHITE )
40 {
41 mnRefCount = 1;
42 meStyle = GRADIENT_LINEAR;
43 mnAngle = 0;
44 mnBorder = 0;
45 mnOfsX = 50;
46 mnOfsY = 50;
47 mnIntensityStart = 100;
48 mnIntensityEnd = 100;
49 mnStepCount = 0;
50 }
51
52 // -----------------------------------------------------------------------
53
Impl_Gradient(const Impl_Gradient & rImplGradient)54 Impl_Gradient::Impl_Gradient( const Impl_Gradient& rImplGradient ) :
55 maStartColor( rImplGradient.maStartColor ),
56 maEndColor( rImplGradient.maEndColor )
57 {
58 mnRefCount = 1;
59 meStyle = rImplGradient.meStyle;
60 mnAngle = rImplGradient.mnAngle;
61 mnBorder = rImplGradient.mnBorder;
62 mnOfsX = rImplGradient.mnOfsX;
63 mnOfsY = rImplGradient.mnOfsY;
64 mnIntensityStart = rImplGradient.mnIntensityStart;
65 mnIntensityEnd = rImplGradient.mnIntensityEnd;
66 mnStepCount = rImplGradient.mnStepCount;
67 }
68
69 // -----------------------------------------------------------------------
70
MakeUnique()71 void Gradient::MakeUnique()
72 {
73 // Falls noch andere Referenzen bestehen, dann kopieren
74 if ( mpImplGradient->mnRefCount != 1 )
75 {
76 if( mpImplGradient->mnRefCount )
77 mpImplGradient->mnRefCount--;
78
79 mpImplGradient = new Impl_Gradient( *mpImplGradient );
80 }
81 }
82
83 // -----------------------------------------------------------------------
84
Gradient()85 Gradient::Gradient()
86 {
87 DBG_CTOR( Gradient, NULL );
88
89 mpImplGradient = new Impl_Gradient;
90 }
91
92 // -----------------------------------------------------------------------
93
Gradient(const Gradient & rGradient)94 Gradient::Gradient( const Gradient& rGradient )
95 {
96 DBG_CTOR( Gradient, NULL );
97 DBG_CHKOBJ( &rGradient, Gradient, NULL );
98
99 // Instance Daten uebernehmen und Referenzcounter erhoehen
100 mpImplGradient = rGradient.mpImplGradient;
101 mpImplGradient->mnRefCount++;
102 }
103
104 // -----------------------------------------------------------------------
105
Gradient(GradientStyle eStyle)106 Gradient::Gradient( GradientStyle eStyle )
107 {
108 DBG_CTOR( Gradient, NULL );
109
110 mpImplGradient = new Impl_Gradient;
111 mpImplGradient->meStyle = eStyle;
112 }
113
114 // -----------------------------------------------------------------------
115
Gradient(GradientStyle eStyle,const Color & rStartColor,const Color & rEndColor)116 Gradient::Gradient( GradientStyle eStyle,
117 const Color& rStartColor, const Color& rEndColor )
118 {
119 DBG_CTOR( Gradient, NULL );
120
121 mpImplGradient = new Impl_Gradient;
122 mpImplGradient->meStyle = eStyle;
123 mpImplGradient->maStartColor = rStartColor;
124 mpImplGradient->maEndColor = rEndColor;
125 }
126
127 // -----------------------------------------------------------------------
128
~Gradient()129 Gradient::~Gradient()
130 {
131 DBG_DTOR( Gradient, NULL );
132
133 // Wenn es die letzte Referenz ist, loeschen,
134 // sonst Referenzcounter decrementieren
135 if ( mpImplGradient->mnRefCount == 1 )
136 delete mpImplGradient;
137 else
138 mpImplGradient->mnRefCount--;
139 }
140
141 // -----------------------------------------------------------------------
142
SetStyle(GradientStyle eStyle)143 void Gradient::SetStyle( GradientStyle eStyle )
144 {
145 DBG_CHKTHIS( Gradient, NULL );
146
147 MakeUnique();
148 mpImplGradient->meStyle = eStyle;
149 }
150
151 // -----------------------------------------------------------------------
152
SetStartColor(const Color & rColor)153 void Gradient::SetStartColor( const Color& rColor )
154 {
155 DBG_CHKTHIS( Gradient, NULL );
156
157 MakeUnique();
158 mpImplGradient->maStartColor = rColor;
159 }
160
161 // -----------------------------------------------------------------------
162
SetEndColor(const Color & rColor)163 void Gradient::SetEndColor( const Color& rColor )
164 {
165 DBG_CHKTHIS( Gradient, NULL );
166
167 MakeUnique();
168 mpImplGradient->maEndColor = rColor;
169 }
170
171 // -----------------------------------------------------------------------
172
SetAngle(sal_uInt16 nAngle)173 void Gradient::SetAngle( sal_uInt16 nAngle )
174 {
175 DBG_CHKTHIS( Gradient, NULL );
176
177 MakeUnique();
178 mpImplGradient->mnAngle = nAngle;
179 }
180
181 // -----------------------------------------------------------------------
182
SetBorder(sal_uInt16 nBorder)183 void Gradient::SetBorder( sal_uInt16 nBorder )
184 {
185 DBG_CHKTHIS( Gradient, NULL );
186
187 MakeUnique();
188 mpImplGradient->mnBorder = nBorder;
189 }
190
191 // -----------------------------------------------------------------------
192
SetOfsX(sal_uInt16 nOfsX)193 void Gradient::SetOfsX( sal_uInt16 nOfsX )
194 {
195 DBG_CHKTHIS( Gradient, NULL );
196
197 MakeUnique();
198 mpImplGradient->mnOfsX = nOfsX;
199 }
200
201 // -----------------------------------------------------------------------
202
SetOfsY(sal_uInt16 nOfsY)203 void Gradient::SetOfsY( sal_uInt16 nOfsY )
204 {
205 DBG_CHKTHIS( Gradient, NULL );
206
207 MakeUnique();
208 mpImplGradient->mnOfsY = nOfsY;
209 }
210
211 // -----------------------------------------------------------------------
212
SetStartIntensity(sal_uInt16 nIntens)213 void Gradient::SetStartIntensity( sal_uInt16 nIntens )
214 {
215 DBG_CHKTHIS( Gradient, NULL );
216
217 MakeUnique();
218 mpImplGradient->mnIntensityStart = nIntens;
219 }
220
221 // -----------------------------------------------------------------------
222
SetEndIntensity(sal_uInt16 nIntens)223 void Gradient::SetEndIntensity( sal_uInt16 nIntens )
224 {
225 DBG_CHKTHIS( Gradient, NULL );
226
227 MakeUnique();
228 mpImplGradient->mnIntensityEnd = nIntens;
229 }
230
231 // -----------------------------------------------------------------------
232
SetSteps(sal_uInt16 nSteps)233 void Gradient::SetSteps( sal_uInt16 nSteps )
234 {
235 DBG_CHKTHIS( Gradient, NULL );
236
237 MakeUnique();
238 mpImplGradient->mnStepCount = nSteps;
239 }
240
241 // -----------------------------------------------------------------------
242
operator =(const Gradient & rGradient)243 Gradient& Gradient::operator=( const Gradient& rGradient )
244 {
245 DBG_CHKTHIS( Gradient, NULL );
246 DBG_CHKOBJ( &rGradient, Gradient, NULL );
247
248 // Zuerst Referenzcounter erhoehen, damit man sich selbst zuweisen kann
249 rGradient.mpImplGradient->mnRefCount++;
250
251 // Wenn es die letzte Referenz ist, loeschen,
252 // sonst Referenzcounter decrementieren
253 if ( mpImplGradient->mnRefCount == 1 )
254 delete mpImplGradient;
255 else
256 mpImplGradient->mnRefCount--;
257 mpImplGradient = rGradient.mpImplGradient;
258
259 return *this;
260 }
261
262 // -----------------------------------------------------------------------
263
operator ==(const Gradient & rGradient) const264 sal_Bool Gradient::operator==( const Gradient& rGradient ) const
265 {
266 DBG_CHKTHIS( Gradient, NULL );
267 DBG_CHKOBJ( &rGradient, Gradient, NULL );
268
269 if ( mpImplGradient == rGradient.mpImplGradient )
270 return sal_True;
271
272 if ( (mpImplGradient->meStyle == rGradient.mpImplGradient->meStyle) ||
273 (mpImplGradient->mnAngle == rGradient.mpImplGradient->mnAngle) ||
274 (mpImplGradient->mnBorder == rGradient.mpImplGradient->mnBorder) ||
275 (mpImplGradient->mnOfsX == rGradient.mpImplGradient->mnOfsX) ||
276 (mpImplGradient->mnOfsY == rGradient.mpImplGradient->mnOfsY) ||
277 (mpImplGradient->mnStepCount == rGradient.mpImplGradient->mnStepCount) ||
278 (mpImplGradient->mnIntensityStart == rGradient.mpImplGradient->mnIntensityStart) ||
279 (mpImplGradient->mnIntensityEnd == rGradient.mpImplGradient->mnIntensityEnd) ||
280 (mpImplGradient->maStartColor == rGradient.mpImplGradient->maStartColor) ||
281 (mpImplGradient->maEndColor == rGradient.mpImplGradient->maEndColor) )
282 return sal_True;
283 else
284 return sal_False;
285 }
286
operator >>(SvStream & rIStm,Impl_Gradient & rImpl_Gradient)287 SvStream& operator>>( SvStream& rIStm, Impl_Gradient& rImpl_Gradient )
288 {
289 VersionCompat aCompat( rIStm, STREAM_READ );
290 sal_uInt16 nTmp16;
291
292 rIStm >> nTmp16; rImpl_Gradient.meStyle = (GradientStyle) nTmp16;
293
294 rIStm >> rImpl_Gradient.maStartColor >>
295 rImpl_Gradient.maEndColor >>
296 rImpl_Gradient.mnAngle >>
297 rImpl_Gradient.mnBorder >>
298 rImpl_Gradient.mnOfsX >>
299 rImpl_Gradient.mnOfsY >>
300 rImpl_Gradient.mnIntensityStart >>
301 rImpl_Gradient.mnIntensityEnd >>
302 rImpl_Gradient.mnStepCount;
303
304 return rIStm;
305 }
306
307 // -----------------------------------------------------------------------
308
operator <<(SvStream & rOStm,const Impl_Gradient & rImpl_Gradient)309 SvStream& operator<<( SvStream& rOStm, const Impl_Gradient& rImpl_Gradient )
310 {
311 VersionCompat aCompat( rOStm, STREAM_WRITE, 1 );
312
313 rOStm << (sal_uInt16) rImpl_Gradient.meStyle <<
314 rImpl_Gradient.maStartColor <<
315 rImpl_Gradient.maEndColor <<
316 rImpl_Gradient.mnAngle <<
317 rImpl_Gradient.mnBorder <<
318 rImpl_Gradient.mnOfsX <<
319 rImpl_Gradient.mnOfsY <<
320 rImpl_Gradient.mnIntensityStart <<
321 rImpl_Gradient.mnIntensityEnd <<
322 rImpl_Gradient.mnStepCount;
323
324 return rOStm;
325 }
326
327 // -----------------------------------------------------------------------
328
operator >>(SvStream & rIStm,Gradient & rGradient)329 SvStream& operator>>( SvStream& rIStm, Gradient& rGradient )
330 {
331 rGradient.MakeUnique();
332 return( rIStm >> *rGradient.mpImplGradient );
333 }
334
335 // -----------------------------------------------------------------------
336
operator <<(SvStream & rOStm,const Gradient & rGradient)337 SvStream& operator<<( SvStream& rOStm, const Gradient& rGradient )
338 {
339 return( rOStm << *rGradient.mpImplGradient );
340 }
341