merge the formfield patch from ooo-build
[ooovba.git] / svtools / source / items / rngitem_inc.cxx
blob43d6eec0e5759e49a63d9ab45d6209f220e11516
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: rngitem_inc.cxx,v $
10 * $Revision: 1.3 $
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 // This snippet of code is included by rngitem.cxx but not compiled directly.
32 // Ugly hack, probably due to lack of templates in the 20th century.
34 static inline NUMTYPE Count_Impl(const NUMTYPE * pRanges)
36 NUMTYPE nCount = 0;
37 for (; *pRanges; pRanges += 2) nCount += 2;
38 return nCount;
41 // -----------------------------------------------------------------------
43 TYPEINIT1_AUTOFACTORY(SfxXRangeItem, SfxPoolItem);
44 TYPEINIT1_AUTOFACTORY(SfxXRangesItem, SfxPoolItem);
46 NUMTYPE Count_Impl( const NUMTYPE *pRanges );
48 // -----------------------------------------------------------------------
50 SfxXRangeItem::SfxXRangeItem()
52 nFrom = 0;
53 nTo = 0;
56 // -----------------------------------------------------------------------
58 SfxXRangeItem::SfxXRangeItem( USHORT which, NUMTYPE from, NUMTYPE to ):
59 SfxPoolItem( which ),
60 nFrom( from ),
61 nTo( to )
66 // -----------------------------------------------------------------------
68 SfxXRangeItem::SfxXRangeItem( USHORT nW, SvStream &rStream ) :
69 SfxPoolItem( nW )
71 rStream >> nFrom;
72 rStream >> nTo;
75 // -----------------------------------------------------------------------
77 SfxXRangeItem::SfxXRangeItem( const SfxXRangeItem& rItem ) :
78 SfxPoolItem( rItem )
80 nFrom = rItem.nFrom;
81 nTo = rItem.nTo;
84 // -----------------------------------------------------------------------
86 SfxItemPresentation SfxXRangeItem::GetPresentation
88 SfxItemPresentation /*ePresentation*/,
89 SfxMapUnit /*eCoreMetric*/,
90 SfxMapUnit /*ePresentationMetric*/,
91 XubString& rText,
92 const IntlWrapper *
93 ) const
95 rText = UniString::CreateFromInt64(nFrom);
96 rText += ':';
97 rText += UniString::CreateFromInt64(nTo);
98 return SFX_ITEM_PRESENTATION_NAMELESS;
101 // -----------------------------------------------------------------------
103 int SfxXRangeItem::operator==( const SfxPoolItem& rItem ) const
105 DBG_ASSERT( SfxPoolItem::operator==( rItem ), "unequal type" );
106 SfxXRangeItem* pT = (SfxXRangeItem*)&rItem;
107 if( nFrom==pT->nFrom && nTo==pT->nTo )
108 return 1;
109 return 0;
112 // -----------------------------------------------------------------------
114 SfxPoolItem* SfxXRangeItem::Clone(SfxItemPool *) const
116 return new SfxXRangeItem( Which(), nFrom, nTo );
119 // -----------------------------------------------------------------------
121 SfxPoolItem* SfxXRangeItem::Create(SvStream &rStream, USHORT) const
123 NUMTYPE nVon, nBis;
124 rStream >> nVon;
125 rStream >> nBis;
126 return new SfxXRangeItem( Which(), nVon, nBis );
129 // -----------------------------------------------------------------------
131 SvStream& SfxXRangeItem::Store(SvStream &rStream, USHORT) const
133 rStream << nFrom;
134 rStream << nTo;
135 return rStream;
138 //=========================================================================
140 SfxXRangesItem::SfxXRangesItem()
141 : _pRanges(0)
145 //-------------------------------------------------------------------------
147 SfxXRangesItem::SfxXRangesItem( USHORT nWID, const NUMTYPE *pRanges )
148 : SfxPoolItem( nWID )
150 NUMTYPE nCount = Count_Impl(pRanges) + 1;
151 _pRanges = new NUMTYPE[nCount];
152 memcpy( _pRanges, pRanges, sizeof(NUMTYPE) * nCount );
155 //-------------------------------------------------------------------------
157 SfxXRangesItem::SfxXRangesItem( USHORT nWID, SvStream &rStream )
158 : SfxPoolItem( nWID )
160 NUMTYPE nCount;
161 rStream >> nCount;
162 _pRanges = new NUMTYPE[nCount + 1];
163 for ( NUMTYPE n = 0; n < nCount; ++n )
164 rStream >> _pRanges[n];
165 _pRanges[nCount] = 0;
168 //-------------------------------------------------------------------------
170 SfxXRangesItem::SfxXRangesItem( const SfxXRangesItem& rItem )
171 : SfxPoolItem( rItem )
173 NUMTYPE nCount = Count_Impl(rItem._pRanges) + 1;
174 _pRanges = new NUMTYPE[nCount];
175 memcpy( _pRanges, rItem._pRanges, sizeof(NUMTYPE) * nCount );
178 //-------------------------------------------------------------------------
180 SfxXRangesItem::~SfxXRangesItem()
182 delete _pRanges;
185 //-------------------------------------------------------------------------
187 int SfxXRangesItem::operator==( const SfxPoolItem &rItem ) const
189 const SfxXRangesItem &rOther = (const SfxXRangesItem&) rItem;
190 if ( !_pRanges && !rOther._pRanges )
191 return TRUE;
192 if ( _pRanges || rOther._pRanges )
193 return FALSE;
195 NUMTYPE n;
196 for ( n = 0; _pRanges[n] && rOther._pRanges[n]; ++n )
197 if ( *_pRanges != rOther._pRanges[n] )
198 return 0;
200 return !_pRanges[n] && !rOther._pRanges[n];
203 //-------------------------------------------------------------------------
205 SfxItemPresentation SfxXRangesItem::GetPresentation( SfxItemPresentation /*ePres*/,
206 SfxMapUnit /*eCoreMetric*/,
207 SfxMapUnit /*ePresMetric*/,
208 XubString &/*rText*/,
209 const IntlWrapper * ) const
211 HACK(n. i.)
212 return SFX_ITEM_PRESENTATION_NONE;
215 //-------------------------------------------------------------------------
217 SfxPoolItem* SfxXRangesItem::Clone( SfxItemPool * ) const
219 return new SfxXRangesItem( *this );
222 //-------------------------------------------------------------------------
224 SfxPoolItem* SfxXRangesItem::Create( SvStream &rStream, USHORT ) const
226 return new SfxXRangesItem( Which(), rStream );
229 //-------------------------------------------------------------------------
231 SvStream& SfxXRangesItem::Store( SvStream &rStream, USHORT ) const
233 NUMTYPE nCount = Count_Impl( _pRanges );
234 rStream >> nCount;
235 for ( NUMTYPE n = 0; _pRanges[n]; ++n )
236 rStream >> _pRanges[n];
237 return rStream;
241 #undef NUMTYPE
242 #undef SfxXRangeItem
243 #undef SfxXRangesItem