Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : // This snippet of code is included by rngitem.cxx but not compiled directly.
21 : // Ugly hack, probably due to lack of templates in the 20th century.
22 :
23 0 : static inline NUMTYPE Count_Impl(const NUMTYPE * pRanges)
24 : {
25 0 : NUMTYPE nCount = 0;
26 0 : for (; *pRanges; pRanges += 2) nCount += 2;
27 0 : return nCount;
28 : }
29 :
30 : // -----------------------------------------------------------------------
31 :
32 0 : TYPEINIT1_AUTOFACTORY(SfxXRangeItem, SfxPoolItem);
33 0 : TYPEINIT1_AUTOFACTORY(SfxXRangesItem, SfxPoolItem);
34 :
35 : NUMTYPE Count_Impl( const NUMTYPE *pRanges );
36 :
37 : // -----------------------------------------------------------------------
38 :
39 0 : SfxXRangeItem::SfxXRangeItem()
40 : {
41 0 : nFrom = 0;
42 0 : nTo = 0;
43 0 : }
44 :
45 : // -----------------------------------------------------------------------
46 :
47 0 : SfxXRangeItem::SfxXRangeItem( sal_uInt16 which, NUMTYPE from, NUMTYPE to ):
48 : SfxPoolItem( which ),
49 : nFrom( from ),
50 0 : nTo( to )
51 : {
52 0 : }
53 :
54 : // -----------------------------------------------------------------------
55 :
56 0 : SfxXRangeItem::SfxXRangeItem( const SfxXRangeItem& rItem ) :
57 0 : SfxPoolItem( rItem )
58 : {
59 0 : nFrom = rItem.nFrom;
60 0 : nTo = rItem.nTo;
61 0 : }
62 :
63 : // -----------------------------------------------------------------------
64 :
65 0 : SfxItemPresentation SfxXRangeItem::GetPresentation
66 : (
67 : SfxItemPresentation /*ePresentation*/,
68 : SfxMapUnit /*eCoreMetric*/,
69 : SfxMapUnit /*ePresentationMetric*/,
70 : XubString& rText,
71 : const IntlWrapper *
72 : ) const
73 : {
74 0 : rText = rtl::OUString::valueOf(static_cast<sal_Int64>(nFrom));
75 0 : rText += ':';
76 0 : rText += rtl::OUString::valueOf(static_cast<sal_Int64>(nTo));
77 0 : return SFX_ITEM_PRESENTATION_NAMELESS;
78 : }
79 :
80 : // -----------------------------------------------------------------------
81 :
82 0 : int SfxXRangeItem::operator==( const SfxPoolItem& rItem ) const
83 : {
84 : DBG_ASSERT( SfxPoolItem::operator==( rItem ), "unequal type" );
85 0 : SfxXRangeItem* pT = (SfxXRangeItem*)&rItem;
86 0 : if( nFrom==pT->nFrom && nTo==pT->nTo )
87 0 : return 1;
88 0 : return 0;
89 : }
90 :
91 : // -----------------------------------------------------------------------
92 :
93 0 : SfxPoolItem* SfxXRangeItem::Clone(SfxItemPool *) const
94 : {
95 0 : return new SfxXRangeItem( Which(), nFrom, nTo );
96 : }
97 :
98 : // -----------------------------------------------------------------------
99 :
100 0 : SfxPoolItem* SfxXRangeItem::Create(SvStream &rStream, sal_uInt16) const
101 : {
102 0 : NUMTYPE nVon(0), nBis(0);
103 0 : rStream >> nVon;
104 0 : rStream >> nBis;
105 0 : return new SfxXRangeItem( Which(), nVon, nBis );
106 : }
107 :
108 : // -----------------------------------------------------------------------
109 :
110 0 : SvStream& SfxXRangeItem::Store(SvStream &rStream, sal_uInt16) const
111 : {
112 0 : rStream << nFrom;
113 0 : rStream << nTo;
114 0 : return rStream;
115 : }
116 :
117 : //=========================================================================
118 :
119 0 : SfxXRangesItem::SfxXRangesItem()
120 0 : : _pRanges(0)
121 : {
122 0 : }
123 :
124 : //-------------------------------------------------------------------------
125 :
126 0 : SfxXRangesItem::SfxXRangesItem( sal_uInt16 nWID, SvStream &rStream )
127 0 : : SfxPoolItem( nWID )
128 : {
129 0 : NUMTYPE nCount(0);
130 0 : rStream >> nCount;
131 0 : _pRanges = new NUMTYPE[nCount + 1];
132 0 : for ( NUMTYPE n = 0; n < nCount; ++n )
133 0 : rStream >> _pRanges[n];
134 0 : _pRanges[nCount] = 0;
135 0 : }
136 :
137 : //-------------------------------------------------------------------------
138 :
139 0 : SfxXRangesItem::SfxXRangesItem( const SfxXRangesItem& rItem )
140 0 : : SfxPoolItem( rItem )
141 : {
142 0 : NUMTYPE nCount = Count_Impl(rItem._pRanges) + 1;
143 0 : _pRanges = new NUMTYPE[nCount];
144 0 : memcpy( _pRanges, rItem._pRanges, sizeof(NUMTYPE) * nCount );
145 0 : }
146 :
147 : //-------------------------------------------------------------------------
148 :
149 0 : SfxXRangesItem::~SfxXRangesItem()
150 : {
151 0 : delete _pRanges;
152 0 : }
153 :
154 : //-------------------------------------------------------------------------
155 :
156 0 : int SfxXRangesItem::operator==( const SfxPoolItem &rItem ) const
157 : {
158 0 : const SfxXRangesItem &rOther = (const SfxXRangesItem&) rItem;
159 0 : if ( !_pRanges && !rOther._pRanges )
160 0 : return sal_True;
161 0 : if ( _pRanges || rOther._pRanges )
162 0 : return sal_False;
163 :
164 : NUMTYPE n;
165 0 : for ( n = 0; _pRanges[n] && rOther._pRanges[n]; ++n )
166 0 : if ( *_pRanges != rOther._pRanges[n] )
167 0 : return 0;
168 :
169 0 : return !_pRanges[n] && !rOther._pRanges[n];
170 : }
171 :
172 : //-------------------------------------------------------------------------
173 :
174 0 : SfxItemPresentation SfxXRangesItem::GetPresentation( SfxItemPresentation /*ePres*/,
175 : SfxMapUnit /*eCoreMetric*/,
176 : SfxMapUnit /*ePresMetric*/,
177 : XubString &/*rText*/,
178 : const IntlWrapper * ) const
179 : {
180 : // not implemented
181 0 : return SFX_ITEM_PRESENTATION_NONE;
182 : }
183 :
184 : //-------------------------------------------------------------------------
185 :
186 0 : SfxPoolItem* SfxXRangesItem::Clone( SfxItemPool * ) const
187 : {
188 0 : return new SfxXRangesItem( *this );
189 : }
190 :
191 : //-------------------------------------------------------------------------
192 :
193 0 : SfxPoolItem* SfxXRangesItem::Create( SvStream &rStream, sal_uInt16 ) const
194 : {
195 0 : return new SfxXRangesItem( Which(), rStream );
196 : }
197 :
198 : //-------------------------------------------------------------------------
199 :
200 0 : SvStream& SfxXRangesItem::Store( SvStream &rStream, sal_uInt16 ) const
201 : {
202 0 : NUMTYPE nCount = Count_Impl( _pRanges );
203 0 : rStream >> nCount;
204 0 : for ( NUMTYPE n = 0; _pRanges[n]; ++n )
205 0 : rStream >> _pRanges[n];
206 0 : return rStream;
207 : }
208 :
209 :
210 : #undef NUMTYPE
211 : #undef SfxXRangeItem
212 : #undef SfxXRangesItem
213 :
214 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|