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: lineinfo.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>
36 #include <vcl/lineinfo.hxx>
44 ImplLineInfo::ImplLineInfo() :
46 meStyle ( LINE_SOLID
),
56 // -----------------------------------------------------------------------
58 ImplLineInfo::ImplLineInfo( const ImplLineInfo
& rImplLineInfo
) :
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
)
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 // -----------------------------------------------------------------------
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
;
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
);
153 mpImplLineInfo
->meStyle
= eStyle
;
156 // -----------------------------------------------------------------------
158 void LineInfo::SetWidth( long nWidth
)
160 DBG_CHKTHIS( LineInfo
, NULL
);
162 mpImplLineInfo
->mnWidth
= nWidth
;
165 // -----------------------------------------------------------------------
167 void LineInfo::SetDashCount( USHORT nDashCount
)
169 DBG_CHKTHIS( LineInfo
, NULL
);
171 mpImplLineInfo
->mnDashCount
= nDashCount
;
174 // -----------------------------------------------------------------------
176 void LineInfo::SetDashLen( long nDashLen
)
178 DBG_CHKTHIS( LineInfo
, NULL
);
180 mpImplLineInfo
->mnDashLen
= nDashLen
;
183 // -----------------------------------------------------------------------
185 void LineInfo::SetDotCount( USHORT nDotCount
)
187 DBG_CHKTHIS( LineInfo
, NULL
);
189 mpImplLineInfo
->mnDotCount
= nDotCount
;
192 // -----------------------------------------------------------------------
194 void LineInfo::SetDotLen( long nDotLen
)
196 DBG_CHKTHIS( LineInfo
, NULL
);
198 mpImplLineInfo
->mnDotLen
= nDotLen
;
201 // -----------------------------------------------------------------------
203 void LineInfo::SetDistance( long nDistance
)
205 DBG_CHKTHIS( LineInfo
, NULL
);
207 mpImplLineInfo
->mnDistance
= nDistance
;
210 // -----------------------------------------------------------------------
212 SvStream
& operator>>( SvStream
& rIStm
, ImplLineInfo
& rImplLineInfo
)
214 VersionCompat
aCompat( rIStm
, STREAM_READ
);
217 rIStm
>> nTmp16
; rImplLineInfo
.meStyle
= (LineStyle
) nTmp16
;
218 rIStm
>> rImplLineInfo
.mnWidth
;
220 if( aCompat
.GetVersion() >= 2 )
223 rIStm
>> rImplLineInfo
.mnDashCount
>> rImplLineInfo
.mnDashLen
;
224 rIStm
>> rImplLineInfo
.mnDotCount
>> rImplLineInfo
.mnDotLen
;
225 rIStm
>> rImplLineInfo
.mnDistance
;
231 // -----------------------------------------------------------------------
233 SvStream
& operator<<( SvStream
& rOStm
, const ImplLineInfo
& rImplLineInfo
)
235 VersionCompat
aCompat( rOStm
, STREAM_WRITE
, 2 );
238 rOStm
<< (UINT16
) rImplLineInfo
.meStyle
<< rImplLineInfo
.mnWidth
;
241 rOStm
<< rImplLineInfo
.mnDashCount
<< rImplLineInfo
.mnDashLen
;
242 rOStm
<< rImplLineInfo
.mnDotCount
<< rImplLineInfo
.mnDotLen
;
243 rOStm
<< rImplLineInfo
.mnDistance
;
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
);