1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <tools/stream.hxx>
21 #include <tools/vcompat.hxx>
22 #include <tools/debug.hxx>
23 #include <vcl/hatch.hxx>
25 ImplHatch::ImplHatch() :
27 maColor ( COL_BLACK
),
28 meStyle ( HATCH_SINGLE
),
34 ImplHatch::ImplHatch( const ImplHatch
& rImplHatch
) :
36 maColor ( rImplHatch
.maColor
),
37 meStyle ( rImplHatch
.meStyle
),
38 mnDistance ( rImplHatch
.mnDistance
),
39 mnAngle ( rImplHatch
.mnAngle
)
45 mpImplHatch
= new ImplHatch
;
48 Hatch::Hatch( const Hatch
& rHatch
)
50 mpImplHatch
= rHatch
.mpImplHatch
;
51 mpImplHatch
->mnRefCount
++;
54 Hatch::Hatch( HatchStyle eStyle
, const Color
& rColor
,
55 long nDistance
, sal_uInt16 nAngle10
)
57 mpImplHatch
= new ImplHatch
;
58 mpImplHatch
->maColor
= rColor
;
59 mpImplHatch
->meStyle
= eStyle
;
60 mpImplHatch
->mnDistance
= nDistance
;
61 mpImplHatch
->mnAngle
= nAngle10
;
66 if( !( --mpImplHatch
->mnRefCount
) )
70 Hatch
& Hatch::operator=( const Hatch
& rHatch
)
73 rHatch
.mpImplHatch
->mnRefCount
++;
75 if( !( --mpImplHatch
->mnRefCount
) )
78 mpImplHatch
= rHatch
.mpImplHatch
;
82 bool Hatch::operator==( const Hatch
& rHatch
) const
85 return( mpImplHatch
== rHatch
.mpImplHatch
||
86 ( mpImplHatch
->maColor
== rHatch
.mpImplHatch
->maColor
&&
87 mpImplHatch
->meStyle
== rHatch
.mpImplHatch
->meStyle
&&
88 mpImplHatch
->mnDistance
== rHatch
.mpImplHatch
->mnDistance
&&
89 mpImplHatch
->mnAngle
== rHatch
.mpImplHatch
->mnAngle
) );
92 void Hatch::ImplMakeUnique()
94 if( mpImplHatch
->mnRefCount
!= 1 )
96 if( mpImplHatch
->mnRefCount
)
97 mpImplHatch
->mnRefCount
--;
99 mpImplHatch
= new ImplHatch( *mpImplHatch
);
103 void Hatch::SetColor( const Color
& rColor
)
106 mpImplHatch
->maColor
= rColor
;
109 void Hatch::SetDistance( long nDistance
)
112 mpImplHatch
->mnDistance
= nDistance
;
115 void Hatch::SetAngle( sal_uInt16 nAngle10
)
118 mpImplHatch
->mnAngle
= nAngle10
;
121 SvStream
& ReadImplHatch( SvStream
& rIStm
, ImplHatch
& rImplHatch
)
123 VersionCompat
aCompat( rIStm
, StreamMode::READ
);
127 rIStm
.ReadUInt16( nTmp16
); rImplHatch
.meStyle
= (HatchStyle
) nTmp16
;
128 ReadColor( rIStm
, rImplHatch
.maColor
).ReadInt32( nTmp32
).ReadUInt16( rImplHatch
.mnAngle
);
129 rImplHatch
.mnDistance
= nTmp32
;
134 SvStream
& WriteImplHatch( SvStream
& rOStm
, const ImplHatch
& rImplHatch
)
136 VersionCompat
aCompat( rOStm
, StreamMode::WRITE
, 1 );
138 rOStm
.WriteUInt16( rImplHatch
.meStyle
);
139 WriteColor( rOStm
, rImplHatch
.maColor
);
140 rOStm
.WriteInt32( rImplHatch
.mnDistance
).WriteUInt16( rImplHatch
.mnAngle
);
145 SvStream
& ReadHatch( SvStream
& rIStm
, Hatch
& rHatch
)
147 rHatch
.ImplMakeUnique();
148 return ReadImplHatch( rIStm
, *rHatch
.mpImplHatch
);
151 SvStream
& WriteHatch( SvStream
& rOStm
, const Hatch
& rHatch
)
153 return WriteImplHatch( rOStm
, *rHatch
.mpImplHatch
);
156 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */