xref: /trunk/main/vcl/source/gdi/hatch.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_vcl.hxx"
30 #include <tools/stream.hxx>
31 #include <tools/vcompat.hxx>
32 #include <tools/debug.hxx>
33 #ifndef _SV_HATCX_HXX
34 #include <vcl/hatch.hxx>
35 #endif
36 
37 DBG_NAME( Hatch )
38 
39 // --------------
40 // - ImplHatch -
41 // --------------
42 
43 ImplHatch::ImplHatch() :
44     mnRefCount	( 1 ),
45     maColor		( COL_BLACK ),
46     meStyle		( HATCH_SINGLE ),
47 	mnDistance	( 1 ),
48     mnAngle		( 0 )
49 {
50 }
51 
52 // -----------------------------------------------------------------------
53 
54 ImplHatch::ImplHatch( const ImplHatch& rImplHatch ) :
55 	mnRefCount	( 1 ),
56     maColor		( rImplHatch.maColor ),
57     meStyle		( rImplHatch.meStyle ),
58 	mnDistance	( rImplHatch.mnDistance ),
59     mnAngle		( rImplHatch.mnAngle )
60 {
61 }
62 
63 // ---------
64 // - Hatch -
65 // ---------
66 
67 Hatch::Hatch()
68 {
69     DBG_CTOR( Hatch, NULL );
70     mpImplHatch = new ImplHatch;
71 }
72 
73 // -----------------------------------------------------------------------
74 
75 Hatch::Hatch( const Hatch& rHatch )
76 {
77     DBG_CTOR( Hatch, NULL );
78     DBG_CHKOBJ( &rHatch, Hatch, NULL );
79     mpImplHatch = rHatch.mpImplHatch;
80     mpImplHatch->mnRefCount++;
81 }
82 
83 // -----------------------------------------------------------------------
84 
85 Hatch::Hatch( HatchStyle eStyle, const Color& rColor,
86 			  long nDistance, sal_uInt16 nAngle10 )
87 {
88     DBG_CTOR( Hatch, NULL );
89     mpImplHatch = new ImplHatch;
90     mpImplHatch->maColor = rColor;
91     mpImplHatch->meStyle = eStyle;
92     mpImplHatch->mnDistance = nDistance;
93     mpImplHatch->mnAngle = nAngle10;
94 }
95 
96 // -----------------------------------------------------------------------
97 
98 Hatch::~Hatch()
99 {
100     DBG_DTOR( Hatch, NULL );
101     if( !( --mpImplHatch->mnRefCount ) )
102         delete mpImplHatch;
103 }
104 
105 // -----------------------------------------------------------------------
106 
107 Hatch& Hatch::operator=( const Hatch& rHatch )
108 {
109     DBG_CHKTHIS( Hatch, NULL );
110     DBG_CHKOBJ( &rHatch, Hatch, NULL );
111 
112     rHatch.mpImplHatch->mnRefCount++;
113 
114     if( !( --mpImplHatch->mnRefCount ) )
115         delete mpImplHatch;
116 
117 	mpImplHatch = rHatch.mpImplHatch;
118     return *this;
119 }
120 
121 // -----------------------------------------------------------------------
122 
123 sal_Bool Hatch::operator==( const Hatch& rHatch ) const
124 {
125     DBG_CHKTHIS( Hatch, NULL );
126     DBG_CHKOBJ( &rHatch, Hatch, NULL );
127 
128     return( mpImplHatch == rHatch.mpImplHatch ||
129 			( mpImplHatch->maColor == rHatch.mpImplHatch->maColor &&
130 			  mpImplHatch->meStyle == rHatch.mpImplHatch->meStyle &&
131 			  mpImplHatch->mnDistance == rHatch.mpImplHatch->mnDistance &&
132 			  mpImplHatch->mnAngle == rHatch.mpImplHatch->mnAngle ) );
133 }
134 
135 // -----------------------------------------------------------------------
136 
137 void Hatch::ImplMakeUnique()
138 {
139     if( mpImplHatch->mnRefCount != 1 )
140 	{
141 		if( mpImplHatch->mnRefCount )
142 			mpImplHatch->mnRefCount--;
143 
144         mpImplHatch = new ImplHatch( *mpImplHatch );
145 	}
146 }
147 
148 // -----------------------------------------------------------------------
149 
150 void Hatch::SetStyle( HatchStyle eStyle )
151 {
152     DBG_CHKTHIS( Hatch, NULL );
153     ImplMakeUnique();
154     mpImplHatch->meStyle = eStyle;
155 }
156 
157 // -----------------------------------------------------------------------
158 
159 void Hatch::SetColor( const Color& rColor )
160 {
161     DBG_CHKTHIS( Hatch, NULL );
162     ImplMakeUnique();
163     mpImplHatch->maColor = rColor;
164 }
165 
166 // -----------------------------------------------------------------------
167 
168 void Hatch::SetDistance( long nDistance )
169 {
170     DBG_CHKTHIS( Hatch, NULL );
171     ImplMakeUnique();
172     mpImplHatch->mnDistance = nDistance;
173 }
174 
175 // -----------------------------------------------------------------------
176 
177 void Hatch::SetAngle( sal_uInt16 nAngle10 )
178 {
179     DBG_CHKTHIS( Hatch, NULL );
180     ImplMakeUnique();
181     mpImplHatch->mnAngle = nAngle10;
182 }
183 
184 // -----------------------------------------------------------------------
185 
186 SvStream& operator>>( SvStream& rIStm, ImplHatch& rImplHatch )
187 {
188     VersionCompat	aCompat( rIStm, STREAM_READ );
189     sal_uInt16			nTmp16;
190 
191     rIStm >> nTmp16; rImplHatch.meStyle = (HatchStyle) nTmp16;
192     rIStm >> rImplHatch.maColor >> rImplHatch.mnDistance >> rImplHatch.mnAngle;
193 
194     return rIStm;
195 }
196 
197 // -----------------------------------------------------------------------
198 
199 SvStream& operator<<( SvStream& rOStm, const ImplHatch& rImplHatch )
200 {
201     VersionCompat aCompat( rOStm, STREAM_WRITE, 1 );
202 
203     rOStm << (sal_uInt16) rImplHatch.meStyle << rImplHatch.maColor;
204 	rOStm << rImplHatch.mnDistance << rImplHatch.mnAngle;
205 
206     return rOStm;
207 }
208 
209 // -----------------------------------------------------------------------
210 
211 SvStream& operator>>( SvStream& rIStm, Hatch& rHatch )
212 {
213     rHatch.ImplMakeUnique();
214     return( rIStm >> *rHatch.mpImplHatch );
215 }
216 
217 // -----------------------------------------------------------------------
218 
219 SvStream& operator<<( SvStream& rOStm, const Hatch& rHatch )
220 {
221     return( rOStm << *rHatch.mpImplHatch );
222 }
223