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: rngitem_inc.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 // 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
)
37 for (; *pRanges
; pRanges
+= 2) nCount
+= 2;
41 // -----------------------------------------------------------------------
43 TYPEINIT1_AUTOFACTORY(SfxXRangeItem
, SfxPoolItem
);
44 TYPEINIT1_AUTOFACTORY(SfxXRangesItem
, SfxPoolItem
);
46 NUMTYPE
Count_Impl( const NUMTYPE
*pRanges
);
48 // -----------------------------------------------------------------------
50 SfxXRangeItem::SfxXRangeItem()
56 // -----------------------------------------------------------------------
58 SfxXRangeItem::SfxXRangeItem( USHORT which
, NUMTYPE from
, NUMTYPE to
):
66 // -----------------------------------------------------------------------
68 SfxXRangeItem::SfxXRangeItem( USHORT nW
, SvStream
&rStream
) :
75 // -----------------------------------------------------------------------
77 SfxXRangeItem::SfxXRangeItem( const SfxXRangeItem
& rItem
) :
84 // -----------------------------------------------------------------------
86 SfxItemPresentation
SfxXRangeItem::GetPresentation
88 SfxItemPresentation
/*ePresentation*/,
89 SfxMapUnit
/*eCoreMetric*/,
90 SfxMapUnit
/*ePresentationMetric*/,
95 rText
= UniString::CreateFromInt64(nFrom
);
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
)
112 // -----------------------------------------------------------------------
114 SfxPoolItem
* SfxXRangeItem::Clone(SfxItemPool
*) const
116 return new SfxXRangeItem( Which(), nFrom
, nTo
);
119 // -----------------------------------------------------------------------
121 SfxPoolItem
* SfxXRangeItem::Create(SvStream
&rStream
, USHORT
) const
126 return new SfxXRangeItem( Which(), nVon
, nBis
);
129 // -----------------------------------------------------------------------
131 SvStream
& SfxXRangeItem::Store(SvStream
&rStream
, USHORT
) const
138 //=========================================================================
140 SfxXRangesItem::SfxXRangesItem()
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
)
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()
185 //-------------------------------------------------------------------------
187 int SfxXRangesItem::operator==( const SfxPoolItem
&rItem
) const
189 const SfxXRangesItem
&rOther
= (const SfxXRangesItem
&) rItem
;
190 if ( !_pRanges
&& !rOther
._pRanges
)
192 if ( _pRanges
|| rOther
._pRanges
)
196 for ( n
= 0; _pRanges
[n
] && rOther
._pRanges
[n
]; ++n
)
197 if ( *_pRanges
!= rOther
._pRanges
[n
] )
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
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
);
235 for ( NUMTYPE n
= 0; _pRanges
[n
]; ++n
)
236 rStream
>> _pRanges
[n
];
243 #undef SfxXRangesItem