xref: /aoo41x/main/vcl/source/gdi/hatch.cxx (revision 9f62ea84)
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 #ifndef _SV_HATCX_HXX
30 #include <vcl/hatch.hxx>
31 #endif
32 
DBG_NAME(Hatch)33 DBG_NAME( Hatch )
34 
35 // --------------
36 // - ImplHatch -
37 // --------------
38 
39 ImplHatch::ImplHatch() :
40     mnRefCount	( 1 ),
41     maColor		( COL_BLACK ),
42     meStyle		( HATCH_SINGLE ),
43 	mnDistance	( 1 ),
44     mnAngle		( 0 )
45 {
46 }
47 
48 // -----------------------------------------------------------------------
49 
ImplHatch(const ImplHatch & rImplHatch)50 ImplHatch::ImplHatch( const ImplHatch& rImplHatch ) :
51 	mnRefCount	( 1 ),
52     maColor		( rImplHatch.maColor ),
53     meStyle		( rImplHatch.meStyle ),
54 	mnDistance	( rImplHatch.mnDistance ),
55     mnAngle		( rImplHatch.mnAngle )
56 {
57 }
58 
59 // ---------
60 // - Hatch -
61 // ---------
62 
Hatch()63 Hatch::Hatch()
64 {
65     DBG_CTOR( Hatch, NULL );
66     mpImplHatch = new ImplHatch;
67 }
68 
69 // -----------------------------------------------------------------------
70 
Hatch(const Hatch & rHatch)71 Hatch::Hatch( const Hatch& rHatch )
72 {
73     DBG_CTOR( Hatch, NULL );
74     DBG_CHKOBJ( &rHatch, Hatch, NULL );
75     mpImplHatch = rHatch.mpImplHatch;
76     mpImplHatch->mnRefCount++;
77 }
78 
79 // -----------------------------------------------------------------------
80 
Hatch(HatchStyle eStyle,const Color & rColor,long nDistance,sal_uInt16 nAngle10)81 Hatch::Hatch( HatchStyle eStyle, const Color& rColor,
82 			  long nDistance, sal_uInt16 nAngle10 )
83 {
84     DBG_CTOR( Hatch, NULL );
85     mpImplHatch = new ImplHatch;
86     mpImplHatch->maColor = rColor;
87     mpImplHatch->meStyle = eStyle;
88     mpImplHatch->mnDistance = nDistance;
89     mpImplHatch->mnAngle = nAngle10;
90 }
91 
92 // -----------------------------------------------------------------------
93 
~Hatch()94 Hatch::~Hatch()
95 {
96     DBG_DTOR( Hatch, NULL );
97     if( !( --mpImplHatch->mnRefCount ) )
98         delete mpImplHatch;
99 }
100 
101 // -----------------------------------------------------------------------
102 
operator =(const Hatch & rHatch)103 Hatch& Hatch::operator=( const Hatch& rHatch )
104 {
105     DBG_CHKTHIS( Hatch, NULL );
106     DBG_CHKOBJ( &rHatch, Hatch, NULL );
107 
108     rHatch.mpImplHatch->mnRefCount++;
109 
110     if( !( --mpImplHatch->mnRefCount ) )
111         delete mpImplHatch;
112 
113 	mpImplHatch = rHatch.mpImplHatch;
114     return *this;
115 }
116 
117 // -----------------------------------------------------------------------
118 
operator ==(const Hatch & rHatch) const119 sal_Bool Hatch::operator==( const Hatch& rHatch ) const
120 {
121     DBG_CHKTHIS( Hatch, NULL );
122     DBG_CHKOBJ( &rHatch, Hatch, NULL );
123 
124     return( mpImplHatch == rHatch.mpImplHatch ||
125 			( mpImplHatch->maColor == rHatch.mpImplHatch->maColor &&
126 			  mpImplHatch->meStyle == rHatch.mpImplHatch->meStyle &&
127 			  mpImplHatch->mnDistance == rHatch.mpImplHatch->mnDistance &&
128 			  mpImplHatch->mnAngle == rHatch.mpImplHatch->mnAngle ) );
129 }
130 
131 // -----------------------------------------------------------------------
132 
ImplMakeUnique()133 void Hatch::ImplMakeUnique()
134 {
135     if( mpImplHatch->mnRefCount != 1 )
136 	{
137 		if( mpImplHatch->mnRefCount )
138 			mpImplHatch->mnRefCount--;
139 
140         mpImplHatch = new ImplHatch( *mpImplHatch );
141 	}
142 }
143 
144 // -----------------------------------------------------------------------
145 
SetStyle(HatchStyle eStyle)146 void Hatch::SetStyle( HatchStyle eStyle )
147 {
148     DBG_CHKTHIS( Hatch, NULL );
149     ImplMakeUnique();
150     mpImplHatch->meStyle = eStyle;
151 }
152 
153 // -----------------------------------------------------------------------
154 
SetColor(const Color & rColor)155 void Hatch::SetColor( const Color& rColor )
156 {
157     DBG_CHKTHIS( Hatch, NULL );
158     ImplMakeUnique();
159     mpImplHatch->maColor = rColor;
160 }
161 
162 // -----------------------------------------------------------------------
163 
SetDistance(long nDistance)164 void Hatch::SetDistance( long nDistance )
165 {
166     DBG_CHKTHIS( Hatch, NULL );
167     ImplMakeUnique();
168     mpImplHatch->mnDistance = nDistance;
169 }
170 
171 // -----------------------------------------------------------------------
172 
SetAngle(sal_uInt16 nAngle10)173 void Hatch::SetAngle( sal_uInt16 nAngle10 )
174 {
175     DBG_CHKTHIS( Hatch, NULL );
176     ImplMakeUnique();
177     mpImplHatch->mnAngle = nAngle10;
178 }
179 
180 // -----------------------------------------------------------------------
181 
operator >>(SvStream & rIStm,ImplHatch & rImplHatch)182 SvStream& operator>>( SvStream& rIStm, ImplHatch& rImplHatch )
183 {
184     VersionCompat	aCompat( rIStm, STREAM_READ );
185     sal_uInt16			nTmp16;
186 
187     rIStm >> nTmp16; rImplHatch.meStyle = (HatchStyle) nTmp16;
188     rIStm >> rImplHatch.maColor >> rImplHatch.mnDistance >> rImplHatch.mnAngle;
189 
190     return rIStm;
191 }
192 
193 // -----------------------------------------------------------------------
194 
operator <<(SvStream & rOStm,const ImplHatch & rImplHatch)195 SvStream& operator<<( SvStream& rOStm, const ImplHatch& rImplHatch )
196 {
197     VersionCompat aCompat( rOStm, STREAM_WRITE, 1 );
198 
199     rOStm << (sal_uInt16) rImplHatch.meStyle << rImplHatch.maColor;
200 	rOStm << rImplHatch.mnDistance << rImplHatch.mnAngle;
201 
202     return rOStm;
203 }
204 
205 // -----------------------------------------------------------------------
206 
operator >>(SvStream & rIStm,Hatch & rHatch)207 SvStream& operator>>( SvStream& rIStm, Hatch& rHatch )
208 {
209     rHatch.ImplMakeUnique();
210     return( rIStm >> *rHatch.mpImplHatch );
211 }
212 
213 // -----------------------------------------------------------------------
214 
operator <<(SvStream & rOStm,const Hatch & rHatch)215 SvStream& operator<<( SvStream& rOStm, const Hatch& rHatch )
216 {
217     return( rOStm << *rHatch.mpImplHatch );
218 }
219