merge the formfield patch from ooo-build
[ooovba.git] / vcl / source / gdi / lineinfo.cxx
blob8f43bf76fb877b492092d5aa62ae0698a52ae250
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: lineinfo.cxx,v $
10 * $Revision: 1.7 $
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>
36 #include <vcl/lineinfo.hxx>
38 DBG_NAME( LineInfo )
40 // ----------------
41 // - ImplLineInfo -
42 // ----------------
44 ImplLineInfo::ImplLineInfo() :
45 mnRefCount ( 1 ),
46 meStyle ( LINE_SOLID ),
47 mnWidth ( 0 ),
48 mnDashCount ( 0 ),
49 mnDashLen ( 0 ),
50 mnDotCount ( 0 ),
51 mnDotLen ( 0 ),
52 mnDistance ( 0 )
56 // -----------------------------------------------------------------------
58 ImplLineInfo::ImplLineInfo( const ImplLineInfo& rImplLineInfo ) :
59 mnRefCount ( 1 ),
60 meStyle ( rImplLineInfo.meStyle ),
61 mnWidth ( rImplLineInfo.mnWidth ),
62 mnDashCount ( rImplLineInfo.mnDashCount ),
63 mnDashLen ( rImplLineInfo.mnDashLen ),
64 mnDotCount ( rImplLineInfo.mnDotCount ),
65 mnDotLen ( rImplLineInfo.mnDotLen ),
66 mnDistance ( rImplLineInfo.mnDistance )
70 // ------------
71 // - LineInfo -
72 // ------------
74 LineInfo::LineInfo( LineStyle eStyle, long nWidth )
76 DBG_CTOR( LineInfo, NULL );
77 mpImplLineInfo = new ImplLineInfo;
78 mpImplLineInfo->meStyle = eStyle;
79 mpImplLineInfo->mnWidth = nWidth;
82 // -----------------------------------------------------------------------
84 LineInfo::LineInfo( const LineInfo& rLineInfo )
86 DBG_CTOR( LineInfo, NULL );
87 DBG_CHKOBJ( &rLineInfo, LineInfo, NULL );
88 mpImplLineInfo = rLineInfo.mpImplLineInfo;
89 mpImplLineInfo->mnRefCount++;
92 // -----------------------------------------------------------------------
94 LineInfo::~LineInfo()
96 DBG_DTOR( LineInfo, NULL );
97 if( !( --mpImplLineInfo->mnRefCount ) )
98 delete mpImplLineInfo;
101 // -----------------------------------------------------------------------
103 LineInfo& LineInfo::operator=( const LineInfo& rLineInfo )
105 DBG_CHKTHIS( LineInfo, NULL );
106 DBG_CHKOBJ( &rLineInfo, LineInfo, NULL );
108 rLineInfo.mpImplLineInfo->mnRefCount++;
110 if( !( --mpImplLineInfo->mnRefCount ) )
111 delete mpImplLineInfo;
113 mpImplLineInfo = rLineInfo.mpImplLineInfo;
114 return *this;
117 // -----------------------------------------------------------------------
119 BOOL LineInfo::operator==( const LineInfo& rLineInfo ) const
121 DBG_CHKTHIS( LineInfo, NULL );
122 DBG_CHKOBJ( &rLineInfo, LineInfo, NULL );
124 return( mpImplLineInfo == rLineInfo.mpImplLineInfo ||
125 ( mpImplLineInfo->meStyle == rLineInfo.mpImplLineInfo->meStyle &&
126 mpImplLineInfo->mnWidth == rLineInfo.mpImplLineInfo->mnWidth &&
127 mpImplLineInfo->mnDashCount == rLineInfo.mpImplLineInfo->mnDashCount &&
128 mpImplLineInfo->mnDashLen == rLineInfo.mpImplLineInfo->mnDashLen &&
129 mpImplLineInfo->mnDotCount == rLineInfo.mpImplLineInfo->mnDotCount &&
130 mpImplLineInfo->mnDotLen == rLineInfo.mpImplLineInfo->mnDotLen &&
131 mpImplLineInfo->mnDistance == rLineInfo.mpImplLineInfo->mnDistance ) );
134 // -----------------------------------------------------------------------
136 void LineInfo::ImplMakeUnique()
138 if( mpImplLineInfo->mnRefCount != 1 )
140 if( mpImplLineInfo->mnRefCount )
141 mpImplLineInfo->mnRefCount--;
143 mpImplLineInfo = new ImplLineInfo( *mpImplLineInfo );
147 // -----------------------------------------------------------------------
149 void LineInfo::SetStyle( LineStyle eStyle )
151 DBG_CHKTHIS( LineInfo, NULL );
152 ImplMakeUnique();
153 mpImplLineInfo->meStyle = eStyle;
156 // -----------------------------------------------------------------------
158 void LineInfo::SetWidth( long nWidth )
160 DBG_CHKTHIS( LineInfo, NULL );
161 ImplMakeUnique();
162 mpImplLineInfo->mnWidth = nWidth;
165 // -----------------------------------------------------------------------
167 void LineInfo::SetDashCount( USHORT nDashCount )
169 DBG_CHKTHIS( LineInfo, NULL );
170 ImplMakeUnique();
171 mpImplLineInfo->mnDashCount = nDashCount;
174 // -----------------------------------------------------------------------
176 void LineInfo::SetDashLen( long nDashLen )
178 DBG_CHKTHIS( LineInfo, NULL );
179 ImplMakeUnique();
180 mpImplLineInfo->mnDashLen = nDashLen;
183 // -----------------------------------------------------------------------
185 void LineInfo::SetDotCount( USHORT nDotCount )
187 DBG_CHKTHIS( LineInfo, NULL );
188 ImplMakeUnique();
189 mpImplLineInfo->mnDotCount = nDotCount;
192 // -----------------------------------------------------------------------
194 void LineInfo::SetDotLen( long nDotLen )
196 DBG_CHKTHIS( LineInfo, NULL );
197 ImplMakeUnique();
198 mpImplLineInfo->mnDotLen = nDotLen;
201 // -----------------------------------------------------------------------
203 void LineInfo::SetDistance( long nDistance )
205 DBG_CHKTHIS( LineInfo, NULL );
206 ImplMakeUnique();
207 mpImplLineInfo->mnDistance = nDistance;
210 // -----------------------------------------------------------------------
212 SvStream& operator>>( SvStream& rIStm, ImplLineInfo& rImplLineInfo )
214 VersionCompat aCompat( rIStm, STREAM_READ );
215 UINT16 nTmp16;
217 rIStm >> nTmp16; rImplLineInfo.meStyle = (LineStyle) nTmp16;
218 rIStm >> rImplLineInfo.mnWidth;
220 if( aCompat.GetVersion() >= 2 )
222 // version 2
223 rIStm >> rImplLineInfo.mnDashCount >> rImplLineInfo.mnDashLen;
224 rIStm >> rImplLineInfo.mnDotCount >> rImplLineInfo.mnDotLen;
225 rIStm >> rImplLineInfo.mnDistance;
228 return rIStm;
231 // -----------------------------------------------------------------------
233 SvStream& operator<<( SvStream& rOStm, const ImplLineInfo& rImplLineInfo )
235 VersionCompat aCompat( rOStm, STREAM_WRITE, 2 );
237 // version 1
238 rOStm << (UINT16) rImplLineInfo.meStyle << rImplLineInfo.mnWidth;
240 // since version2
241 rOStm << rImplLineInfo.mnDashCount << rImplLineInfo.mnDashLen;
242 rOStm << rImplLineInfo.mnDotCount << rImplLineInfo.mnDotLen;
243 rOStm << rImplLineInfo.mnDistance;
245 return rOStm;
248 // -----------------------------------------------------------------------
250 SvStream& operator>>( SvStream& rIStm, LineInfo& rLineInfo )
252 rLineInfo.ImplMakeUnique();
253 return( rIStm >> *rLineInfo.mpImplLineInfo );
256 // -----------------------------------------------------------------------
258 SvStream& operator<<( SvStream& rOStm, const LineInfo& rLineInfo )
260 return( rOStm << *rLineInfo.mpImplLineInfo );