1 /**************************************************************
2 *
3 * Licensed to the Apache Software Foundation (ASF) under one
4 * or more contributor license agreements. See the NOTICE file
5 * distributed with this work for additional information
6 * regarding copyright ownership. The ASF licenses this file
7 * to you under the Apache License, Version 2.0 (the
8 * "License"); you may not use this file except in compliance
9 * with the License. You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing,
14 * software distributed under the License is distributed on an
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 * KIND, either express or implied. See the License for the
17 * specific language governing permissions and limitations
18 * under the License.
19 *
20 *************************************************************/
21
22
23
24 // This snippet of code is included by rngitem.cxx but not compiled directly.
25 // Ugly hack, probably due to lack of templates in the 20th century.
26
Count_Impl(const NUMTYPE * pRanges)27 static inline NUMTYPE Count_Impl(const NUMTYPE * pRanges)
28 {
29 NUMTYPE nCount = 0;
30 for (; *pRanges; pRanges += 2) nCount += 2;
31 return nCount;
32 }
33
34 // -----------------------------------------------------------------------
35
36 TYPEINIT1_AUTOFACTORY(SfxXRangeItem, SfxPoolItem);
37 TYPEINIT1_AUTOFACTORY(SfxXRangesItem, SfxPoolItem);
38
39 NUMTYPE Count_Impl( const NUMTYPE *pRanges );
40
41 // -----------------------------------------------------------------------
42
SfxXRangeItem()43 SfxXRangeItem::SfxXRangeItem()
44 {
45 nFrom = 0;
46 nTo = 0;
47 }
48
49 // -----------------------------------------------------------------------
50
SfxXRangeItem(sal_uInt16 which,NUMTYPE from,NUMTYPE to)51 SfxXRangeItem::SfxXRangeItem( sal_uInt16 which, NUMTYPE from, NUMTYPE to ):
52 SfxPoolItem( which ),
53 nFrom( from ),
54 nTo( to )
55 {
56 }
57
58
59 // -----------------------------------------------------------------------
60
SfxXRangeItem(sal_uInt16 nW,SvStream & rStream)61 SfxXRangeItem::SfxXRangeItem( sal_uInt16 nW, SvStream &rStream ) :
62 SfxPoolItem( nW )
63 {
64 rStream >> nFrom;
65 rStream >> nTo;
66 }
67
68 // -----------------------------------------------------------------------
69
SfxXRangeItem(const SfxXRangeItem & rItem)70 SfxXRangeItem::SfxXRangeItem( const SfxXRangeItem& rItem ) :
71 SfxPoolItem( rItem )
72 {
73 nFrom = rItem.nFrom;
74 nTo = rItem.nTo;
75 }
76
77 // -----------------------------------------------------------------------
78
GetPresentation(SfxItemPresentation,SfxMapUnit,SfxMapUnit,XubString & rText,const IntlWrapper *) const79 SfxItemPresentation SfxXRangeItem::GetPresentation
80 (
81 SfxItemPresentation /*ePresentation*/,
82 SfxMapUnit /*eCoreMetric*/,
83 SfxMapUnit /*ePresentationMetric*/,
84 XubString& rText,
85 const IntlWrapper *
86 ) const
87 {
88 rText = UniString::CreateFromInt64(nFrom);
89 rText += ':';
90 rText += UniString::CreateFromInt64(nTo);
91 return SFX_ITEM_PRESENTATION_NAMELESS;
92 }
93
94 // -----------------------------------------------------------------------
95
operator ==(const SfxPoolItem & rItem) const96 int SfxXRangeItem::operator==( const SfxPoolItem& rItem ) const
97 {
98 DBG_ASSERT( SfxPoolItem::operator==( rItem ), "unequal type" );
99 SfxXRangeItem* pT = (SfxXRangeItem*)&rItem;
100 if( nFrom==pT->nFrom && nTo==pT->nTo )
101 return 1;
102 return 0;
103 }
104
105 // -----------------------------------------------------------------------
106
Clone(SfxItemPool *) const107 SfxPoolItem* SfxXRangeItem::Clone(SfxItemPool *) const
108 {
109 return new SfxXRangeItem( Which(), nFrom, nTo );
110 }
111
112 // -----------------------------------------------------------------------
113
Create(SvStream & rStream,sal_uInt16) const114 SfxPoolItem* SfxXRangeItem::Create(SvStream &rStream, sal_uInt16) const
115 {
116 NUMTYPE nVon, nBis;
117 rStream >> nVon;
118 rStream >> nBis;
119 return new SfxXRangeItem( Which(), nVon, nBis );
120 }
121
122 // -----------------------------------------------------------------------
123
Store(SvStream & rStream,sal_uInt16) const124 SvStream& SfxXRangeItem::Store(SvStream &rStream, sal_uInt16) const
125 {
126 rStream << nFrom;
127 rStream << nTo;
128 return rStream;
129 }
130
131 //=========================================================================
132
SfxXRangesItem()133 SfxXRangesItem::SfxXRangesItem()
134 : _pRanges(0)
135 {
136 }
137
138 //-------------------------------------------------------------------------
139
SfxXRangesItem(sal_uInt16 nWID,const NUMTYPE * pRanges)140 SfxXRangesItem::SfxXRangesItem( sal_uInt16 nWID, const NUMTYPE *pRanges )
141 : SfxPoolItem( nWID )
142 {
143 NUMTYPE nCount = Count_Impl(pRanges) + 1;
144 _pRanges = new NUMTYPE[nCount];
145 memcpy( _pRanges, pRanges, sizeof(NUMTYPE) * nCount );
146 }
147
148 //-------------------------------------------------------------------------
149
SfxXRangesItem(sal_uInt16 nWID,SvStream & rStream)150 SfxXRangesItem::SfxXRangesItem( sal_uInt16 nWID, SvStream &rStream )
151 : SfxPoolItem( nWID )
152 {
153 NUMTYPE nCount;
154 rStream >> nCount;
155 _pRanges = new NUMTYPE[nCount + 1];
156 for ( NUMTYPE n = 0; n < nCount; ++n )
157 rStream >> _pRanges[n];
158 _pRanges[nCount] = 0;
159 }
160
161 //-------------------------------------------------------------------------
162
SfxXRangesItem(const SfxXRangesItem & rItem)163 SfxXRangesItem::SfxXRangesItem( const SfxXRangesItem& rItem )
164 : SfxPoolItem( rItem )
165 {
166 NUMTYPE nCount = Count_Impl(rItem._pRanges) + 1;
167 _pRanges = new NUMTYPE[nCount];
168 memcpy( _pRanges, rItem._pRanges, sizeof(NUMTYPE) * nCount );
169 }
170
171 //-------------------------------------------------------------------------
172
~SfxXRangesItem()173 SfxXRangesItem::~SfxXRangesItem()
174 {
175 delete _pRanges;
176 }
177
178 //-------------------------------------------------------------------------
179
operator ==(const SfxPoolItem & rItem) const180 int SfxXRangesItem::operator==( const SfxPoolItem &rItem ) const
181 {
182 const SfxXRangesItem &rOther = (const SfxXRangesItem&) rItem;
183 if ( !_pRanges && !rOther._pRanges )
184 return sal_True;
185 if ( _pRanges || rOther._pRanges )
186 return sal_False;
187
188 NUMTYPE n;
189 for ( n = 0; _pRanges[n] && rOther._pRanges[n]; ++n )
190 if ( *_pRanges != rOther._pRanges[n] )
191 return 0;
192
193 return !_pRanges[n] && !rOther._pRanges[n];
194 }
195
196 //-------------------------------------------------------------------------
197
GetPresentation(SfxItemPresentation,SfxMapUnit,SfxMapUnit,XubString &,const IntlWrapper *) const198 SfxItemPresentation SfxXRangesItem::GetPresentation( SfxItemPresentation /*ePres*/,
199 SfxMapUnit /*eCoreMetric*/,
200 SfxMapUnit /*ePresMetric*/,
201 XubString &/*rText*/,
202 const IntlWrapper * ) const
203 {
204 HACK(n. i.)
205 return SFX_ITEM_PRESENTATION_NONE;
206 }
207
208 //-------------------------------------------------------------------------
209
Clone(SfxItemPool *) const210 SfxPoolItem* SfxXRangesItem::Clone( SfxItemPool * ) const
211 {
212 return new SfxXRangesItem( *this );
213 }
214
215 //-------------------------------------------------------------------------
216
Create(SvStream & rStream,sal_uInt16) const217 SfxPoolItem* SfxXRangesItem::Create( SvStream &rStream, sal_uInt16 ) const
218 {
219 return new SfxXRangesItem( Which(), rStream );
220 }
221
222 //-------------------------------------------------------------------------
223
Store(SvStream & rStream,sal_uInt16) const224 SvStream& SfxXRangesItem::Store( SvStream &rStream, sal_uInt16 ) const
225 {
226 NUMTYPE nCount = Count_Impl( _pRanges );
227 rStream >> nCount;
228 for ( NUMTYPE n = 0; _pRanges[n]; ++n )
229 rStream >> _pRanges[n];
230 return rStream;
231 }
232
233
234 #undef NUMTYPE
235 #undef SfxXRangeItem
236 #undef SfxXRangesItem
237