1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <tools/stream.hxx>
21 #include <svl/rngitem.hxx>
23 static inline sal_uInt16
Count_Impl(const sal_uInt16
* pRanges
)
25 sal_uInt16 nCount
= 0;
26 for (; *pRanges
; pRanges
+= 2) nCount
+= 2;
30 // -----------------------------------------------------------------------
32 TYPEINIT1_AUTOFACTORY(SfxRangeItem
, SfxPoolItem
);
33 TYPEINIT1_AUTOFACTORY(SfxUShortRangesItem
, SfxPoolItem
);
35 sal_uInt16
Count_Impl( const sal_uInt16
*pRanges
);
37 // -----------------------------------------------------------------------
39 SfxRangeItem::SfxRangeItem()
45 // -----------------------------------------------------------------------
47 SfxRangeItem::SfxRangeItem( sal_uInt16 which
, sal_uInt16 from
, sal_uInt16 to
):
54 // -----------------------------------------------------------------------
56 SfxRangeItem::SfxRangeItem( const SfxRangeItem
& rItem
) :
63 // -----------------------------------------------------------------------
65 SfxItemPresentation
SfxRangeItem::GetPresentation
67 SfxItemPresentation
/*ePresentation*/,
68 SfxMapUnit
/*eCoreMetric*/,
69 SfxMapUnit
/*ePresentationMetric*/,
74 rText
= OUString::number(nFrom
) + ":" + OUString::number(nTo
);
75 return SFX_ITEM_PRESENTATION_NAMELESS
;
78 // -----------------------------------------------------------------------
80 int SfxRangeItem::operator==( const SfxPoolItem
& rItem
) const
82 DBG_ASSERT( SfxPoolItem::operator==( rItem
), "unequal type" );
83 SfxRangeItem
* pT
= (SfxRangeItem
*)&rItem
;
84 if( nFrom
==pT
->nFrom
&& nTo
==pT
->nTo
)
89 // -----------------------------------------------------------------------
91 SfxPoolItem
* SfxRangeItem::Clone(SfxItemPool
*) const
93 return new SfxRangeItem( Which(), nFrom
, nTo
);
96 // -----------------------------------------------------------------------
98 SfxPoolItem
* SfxRangeItem::Create(SvStream
&rStream
, sal_uInt16
) const
100 sal_uInt16
nVon(0), nBis(0);
103 return new SfxRangeItem( Which(), nVon
, nBis
);
106 // -----------------------------------------------------------------------
108 SvStream
& SfxRangeItem::Store(SvStream
&rStream
, sal_uInt16
) const
116 SfxUShortRangesItem::SfxUShortRangesItem()
122 SfxUShortRangesItem::SfxUShortRangesItem( sal_uInt16 nWID
, SvStream
&rStream
)
123 : SfxPoolItem( nWID
)
125 sal_uInt16
nCount(0);
127 _pRanges
= new sal_uInt16
[nCount
+ 1];
128 for ( sal_uInt16 n
= 0; n
< nCount
; ++n
)
129 rStream
>> _pRanges
[n
];
130 _pRanges
[nCount
] = 0;
134 SfxUShortRangesItem::SfxUShortRangesItem( const SfxUShortRangesItem
& rItem
)
135 : SfxPoolItem( rItem
)
137 sal_uInt16 nCount
= Count_Impl(rItem
._pRanges
) + 1;
138 _pRanges
= new sal_uInt16
[nCount
];
139 memcpy( _pRanges
, rItem
._pRanges
, sizeof(sal_uInt16
) * nCount
);
143 SfxUShortRangesItem::~SfxUShortRangesItem()
149 int SfxUShortRangesItem::operator==( const SfxPoolItem
&rItem
) const
151 const SfxUShortRangesItem
&rOther
= (const SfxUShortRangesItem
&) rItem
;
152 if ( !_pRanges
&& !rOther
._pRanges
)
154 if ( _pRanges
|| rOther
._pRanges
)
158 for ( n
= 0; _pRanges
[n
] && rOther
._pRanges
[n
]; ++n
)
159 if ( *_pRanges
!= rOther
._pRanges
[n
] )
162 return !_pRanges
[n
] && !rOther
._pRanges
[n
];
166 SfxItemPresentation
SfxUShortRangesItem::GetPresentation( SfxItemPresentation
/*ePres*/,
167 SfxMapUnit
/*eCoreMetric*/,
168 SfxMapUnit
/*ePresMetric*/,
169 OUString
& /*rText*/,
170 const IntlWrapper
* ) const
173 return SFX_ITEM_PRESENTATION_NONE
;
177 SfxPoolItem
* SfxUShortRangesItem::Clone( SfxItemPool
* ) const
179 return new SfxUShortRangesItem( *this );
183 SfxPoolItem
* SfxUShortRangesItem::Create( SvStream
&rStream
, sal_uInt16
) const
185 return new SfxUShortRangesItem( Which(), rStream
);
189 SvStream
& SfxUShortRangesItem::Store( SvStream
&rStream
, sal_uInt16
) const
191 sal_uInt16 nCount
= Count_Impl( _pRanges
);
193 for ( sal_uInt16 n
= 0; _pRanges
[n
]; ++n
)
194 rStream
>> _pRanges
[n
];
198 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */