xref: /aoo41x/main/svl/source/items/rngitem_inc.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 // This snippet of code is included by rngitem.cxx but not compiled directly.
29 // Ugly hack, probably due to lack of templates in the 20th century.
30 
31 static inline NUMTYPE Count_Impl(const NUMTYPE * pRanges)
32 {
33 	NUMTYPE nCount = 0;
34 	for (; *pRanges; pRanges += 2) nCount += 2;
35 	return nCount;
36 }
37 
38 // -----------------------------------------------------------------------
39 
40 TYPEINIT1_AUTOFACTORY(SfxXRangeItem, SfxPoolItem);
41 TYPEINIT1_AUTOFACTORY(SfxXRangesItem, SfxPoolItem);
42 
43 NUMTYPE Count_Impl( const NUMTYPE *pRanges );
44 
45 // -----------------------------------------------------------------------
46 
47 SfxXRangeItem::SfxXRangeItem()
48 {
49 	nFrom = 0;
50 	nTo = 0;
51 }
52 
53 // -----------------------------------------------------------------------
54 
55 SfxXRangeItem::SfxXRangeItem( sal_uInt16 which, NUMTYPE from, NUMTYPE to ):
56 	SfxPoolItem( which ),
57 	nFrom( from ),
58 	nTo( to )
59 {
60 }
61 
62 
63 // -----------------------------------------------------------------------
64 
65 SfxXRangeItem::SfxXRangeItem( sal_uInt16 nW, SvStream &rStream ) :
66 	SfxPoolItem( nW )
67 {
68 	rStream >> nFrom;
69 	rStream >> nTo;
70 }
71 
72 // -----------------------------------------------------------------------
73 
74 SfxXRangeItem::SfxXRangeItem( const SfxXRangeItem& rItem ) :
75 	SfxPoolItem( rItem )
76 {
77 	nFrom = rItem.nFrom;
78 	nTo = rItem.nTo;
79 }
80 
81 // -----------------------------------------------------------------------
82 
83 SfxItemPresentation SfxXRangeItem::GetPresentation
84 (
85 	SfxItemPresentation 	/*ePresentation*/,
86 	SfxMapUnit				/*eCoreMetric*/,
87 	SfxMapUnit				/*ePresentationMetric*/,
88 	XubString& 				rText,
89     const IntlWrapper *
90 )	const
91 {
92 	rText = UniString::CreateFromInt64(nFrom);
93 	rText += ':';
94 	rText += UniString::CreateFromInt64(nTo);
95 	return SFX_ITEM_PRESENTATION_NAMELESS;
96 }
97 
98 // -----------------------------------------------------------------------
99 
100 int SfxXRangeItem::operator==( const SfxPoolItem& rItem ) const
101 {
102 	DBG_ASSERT( SfxPoolItem::operator==( rItem ), "unequal type" );
103 	SfxXRangeItem* pT = (SfxXRangeItem*)&rItem;
104 	if( nFrom==pT->nFrom && nTo==pT->nTo )
105 		return 1;
106 	return 0;
107 }
108 
109 // -----------------------------------------------------------------------
110 
111 SfxPoolItem* SfxXRangeItem::Clone(SfxItemPool *) const
112 {
113 	return new SfxXRangeItem( Which(), nFrom, nTo );
114 }
115 
116 // -----------------------------------------------------------------------
117 
118 SfxPoolItem* SfxXRangeItem::Create(SvStream &rStream, sal_uInt16) const
119 {
120 	NUMTYPE		nVon, nBis;
121 	rStream >> nVon;
122 	rStream >> nBis;
123 	return new SfxXRangeItem( Which(), nVon, nBis );
124 }
125 
126 // -----------------------------------------------------------------------
127 
128 SvStream& SfxXRangeItem::Store(SvStream &rStream, sal_uInt16) const
129 {
130 	rStream << nFrom;
131 	rStream << nTo;
132 	return rStream;
133 }
134 
135 //=========================================================================
136 
137 SfxXRangesItem::SfxXRangesItem()
138 :	_pRanges(0)
139 {
140 }
141 
142 //-------------------------------------------------------------------------
143 
144 SfxXRangesItem::SfxXRangesItem( sal_uInt16 nWID, const NUMTYPE *pRanges )
145 :	SfxPoolItem( nWID )
146 {
147 	NUMTYPE nCount = Count_Impl(pRanges) + 1;
148 	_pRanges = new NUMTYPE[nCount];
149 	memcpy( _pRanges, pRanges, sizeof(NUMTYPE) * nCount );
150 }
151 
152 //-------------------------------------------------------------------------
153 
154 SfxXRangesItem::SfxXRangesItem( sal_uInt16 nWID, SvStream &rStream )
155 :	SfxPoolItem( nWID )
156 {
157 	NUMTYPE nCount;
158 	rStream >> nCount;
159 	_pRanges = new NUMTYPE[nCount + 1];
160 	for ( NUMTYPE n = 0; n < nCount; ++n )
161 		rStream >> _pRanges[n];
162 	_pRanges[nCount] = 0;
163 }
164 
165 //-------------------------------------------------------------------------
166 
167 SfxXRangesItem::SfxXRangesItem( const SfxXRangesItem& rItem )
168 :	SfxPoolItem( rItem )
169 {
170 	NUMTYPE nCount = Count_Impl(rItem._pRanges) + 1;
171 	_pRanges = new NUMTYPE[nCount];
172 	memcpy( _pRanges, rItem._pRanges, sizeof(NUMTYPE) * nCount );
173 }
174 
175 //-------------------------------------------------------------------------
176 
177 SfxXRangesItem::~SfxXRangesItem()
178 {
179 	delete _pRanges;
180 }
181 
182 //-------------------------------------------------------------------------
183 
184 int SfxXRangesItem::operator==( const SfxPoolItem &rItem ) const
185 {
186 	const SfxXRangesItem &rOther = (const SfxXRangesItem&) rItem;
187 	if ( !_pRanges && !rOther._pRanges )
188 		return sal_True;
189 	if ( _pRanges || rOther._pRanges )
190 		return sal_False;
191 
192 	NUMTYPE n;
193 	for ( n = 0; _pRanges[n] && rOther._pRanges[n]; ++n )
194 		if ( *_pRanges != rOther._pRanges[n] )
195 			return 0;
196 
197 	return !_pRanges[n] && !rOther._pRanges[n];
198 }
199 
200 //-------------------------------------------------------------------------
201 
202 SfxItemPresentation SfxXRangesItem::GetPresentation( SfxItemPresentation /*ePres*/,
203 									SfxMapUnit /*eCoreMetric*/,
204 									SfxMapUnit /*ePresMetric*/,
205 									XubString &/*rText*/,
206                                     const IntlWrapper * ) const
207 {
208 	HACK(n. i.)
209 	return SFX_ITEM_PRESENTATION_NONE;
210 }
211 
212 //-------------------------------------------------------------------------
213 
214 SfxPoolItem* SfxXRangesItem::Clone( SfxItemPool * ) const
215 {
216 	return new SfxXRangesItem( *this );
217 }
218 
219 //-------------------------------------------------------------------------
220 
221 SfxPoolItem* SfxXRangesItem::Create( SvStream &rStream, sal_uInt16 ) const
222 {
223 	return new SfxXRangesItem( Which(), rStream );
224 }
225 
226 //-------------------------------------------------------------------------
227 
228 SvStream& SfxXRangesItem::Store( SvStream &rStream, sal_uInt16 ) const
229 {
230 	NUMTYPE nCount = Count_Impl( _pRanges );
231 	rStream >> nCount;
232 	for ( NUMTYPE n = 0; _pRanges[n]; ++n )
233 		rStream >> _pRanges[n];
234 	return rStream;
235 }
236 
237 
238 #undef NUMTYPE
239 #undef SfxXRangeItem
240 #undef SfxXRangesItem
241