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: hatch.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>
37 #include <vcl/hatch.hxx>
46 ImplHatch::ImplHatch() :
48 maColor ( COL_BLACK
),
49 meStyle ( HATCH_SINGLE
),
55 // -----------------------------------------------------------------------
57 ImplHatch::ImplHatch( const ImplHatch
& rImplHatch
) :
59 maColor ( rImplHatch
.maColor
),
60 meStyle ( rImplHatch
.meStyle
),
61 mnDistance ( rImplHatch
.mnDistance
),
62 mnAngle ( rImplHatch
.mnAngle
)
72 DBG_CTOR( Hatch
, NULL
);
73 mpImplHatch
= new ImplHatch
;
76 // -----------------------------------------------------------------------
78 Hatch::Hatch( const Hatch
& rHatch
)
80 DBG_CTOR( Hatch
, NULL
);
81 DBG_CHKOBJ( &rHatch
, Hatch
, NULL
);
82 mpImplHatch
= rHatch
.mpImplHatch
;
83 mpImplHatch
->mnRefCount
++;
86 // -----------------------------------------------------------------------
88 Hatch::Hatch( HatchStyle eStyle
, const Color
& rColor
,
89 long nDistance
, USHORT nAngle10
)
91 DBG_CTOR( Hatch
, NULL
);
92 mpImplHatch
= new ImplHatch
;
93 mpImplHatch
->maColor
= rColor
;
94 mpImplHatch
->meStyle
= eStyle
;
95 mpImplHatch
->mnDistance
= nDistance
;
96 mpImplHatch
->mnAngle
= nAngle10
;
99 // -----------------------------------------------------------------------
103 DBG_DTOR( Hatch
, NULL
);
104 if( !( --mpImplHatch
->mnRefCount
) )
108 // -----------------------------------------------------------------------
110 Hatch
& Hatch::operator=( const Hatch
& rHatch
)
112 DBG_CHKTHIS( Hatch
, NULL
);
113 DBG_CHKOBJ( &rHatch
, Hatch
, NULL
);
115 rHatch
.mpImplHatch
->mnRefCount
++;
117 if( !( --mpImplHatch
->mnRefCount
) )
120 mpImplHatch
= rHatch
.mpImplHatch
;
124 // -----------------------------------------------------------------------
126 BOOL
Hatch::operator==( const Hatch
& rHatch
) const
128 DBG_CHKTHIS( Hatch
, NULL
);
129 DBG_CHKOBJ( &rHatch
, Hatch
, NULL
);
131 return( mpImplHatch
== rHatch
.mpImplHatch
||
132 ( mpImplHatch
->maColor
== rHatch
.mpImplHatch
->maColor
&&
133 mpImplHatch
->meStyle
== rHatch
.mpImplHatch
->meStyle
&&
134 mpImplHatch
->mnDistance
== rHatch
.mpImplHatch
->mnDistance
&&
135 mpImplHatch
->mnAngle
== rHatch
.mpImplHatch
->mnAngle
) );
138 // -----------------------------------------------------------------------
140 void Hatch::ImplMakeUnique()
142 if( mpImplHatch
->mnRefCount
!= 1 )
144 if( mpImplHatch
->mnRefCount
)
145 mpImplHatch
->mnRefCount
--;
147 mpImplHatch
= new ImplHatch( *mpImplHatch
);
151 // -----------------------------------------------------------------------
153 void Hatch::SetStyle( HatchStyle eStyle
)
155 DBG_CHKTHIS( Hatch
, NULL
);
157 mpImplHatch
->meStyle
= eStyle
;
160 // -----------------------------------------------------------------------
162 void Hatch::SetColor( const Color
& rColor
)
164 DBG_CHKTHIS( Hatch
, NULL
);
166 mpImplHatch
->maColor
= rColor
;
169 // -----------------------------------------------------------------------
171 void Hatch::SetDistance( long nDistance
)
173 DBG_CHKTHIS( Hatch
, NULL
);
175 mpImplHatch
->mnDistance
= nDistance
;
178 // -----------------------------------------------------------------------
180 void Hatch::SetAngle( USHORT nAngle10
)
182 DBG_CHKTHIS( Hatch
, NULL
);
184 mpImplHatch
->mnAngle
= nAngle10
;
187 // -----------------------------------------------------------------------
189 SvStream
& operator>>( SvStream
& rIStm
, ImplHatch
& rImplHatch
)
191 VersionCompat
aCompat( rIStm
, STREAM_READ
);
194 rIStm
>> nTmp16
; rImplHatch
.meStyle
= (HatchStyle
) nTmp16
;
195 rIStm
>> rImplHatch
.maColor
>> rImplHatch
.mnDistance
>> rImplHatch
.mnAngle
;
200 // -----------------------------------------------------------------------
202 SvStream
& operator<<( SvStream
& rOStm
, const ImplHatch
& rImplHatch
)
204 VersionCompat
aCompat( rOStm
, STREAM_WRITE
, 1 );
206 rOStm
<< (UINT16
) rImplHatch
.meStyle
<< rImplHatch
.maColor
;
207 rOStm
<< rImplHatch
.mnDistance
<< rImplHatch
.mnAngle
;
212 // -----------------------------------------------------------------------
214 SvStream
& operator>>( SvStream
& rIStm
, Hatch
& rHatch
)
216 rHatch
.ImplMakeUnique();
217 return( rIStm
>> *rHatch
.mpImplHatch
);
220 // -----------------------------------------------------------------------
222 SvStream
& operator<<( SvStream
& rOStm
, const Hatch
& rHatch
)
224 return( rOStm
<< *rHatch
.mpImplHatch
);