xref: /aoo42x/main/svl/source/items/cenumitm.cxx (revision 40df464e)
1*40df464eSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*40df464eSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*40df464eSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*40df464eSAndrew Rist  * distributed with this work for additional information
6*40df464eSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*40df464eSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*40df464eSAndrew Rist  * "License"); you may not use this file except in compliance
9*40df464eSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*40df464eSAndrew Rist  *
11*40df464eSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*40df464eSAndrew Rist  *
13*40df464eSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*40df464eSAndrew Rist  * software distributed under the License is distributed on an
15*40df464eSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*40df464eSAndrew Rist  * KIND, either express or implied.  See the License for the
17*40df464eSAndrew Rist  * specific language governing permissions and limitations
18*40df464eSAndrew Rist  * under the License.
19*40df464eSAndrew Rist  *
20*40df464eSAndrew Rist  *************************************************************/
21*40df464eSAndrew Rist 
22*40df464eSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svl.hxx"
26cdf0e10cSrcweir #include <com/sun/star/uno/Any.hxx>
27cdf0e10cSrcweir #include <tools/stream.hxx>
28cdf0e10cSrcweir #include <svl/cenumitm.hxx>
29cdf0e10cSrcweir #include <whassert.hxx>
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #ifndef _CPPUHELPER_EXTRACT_HXX_
32cdf0e10cSrcweir #include <comphelper/extract.hxx>
33cdf0e10cSrcweir #endif
34cdf0e10cSrcweir 
35cdf0e10cSrcweir //============================================================================
36cdf0e10cSrcweir //
37cdf0e10cSrcweir //  class SfxEnumItemInterface
38cdf0e10cSrcweir //
39cdf0e10cSrcweir //============================================================================
40cdf0e10cSrcweir 
41cdf0e10cSrcweir DBG_NAME(SfxEnumItemInterface)
42cdf0e10cSrcweir 
43cdf0e10cSrcweir //============================================================================
44cdf0e10cSrcweir TYPEINIT1(SfxEnumItemInterface, SfxPoolItem)
45cdf0e10cSrcweir 
46cdf0e10cSrcweir //============================================================================
47cdf0e10cSrcweir // virtual
48cdf0e10cSrcweir int SfxEnumItemInterface::operator ==(const SfxPoolItem & rItem) const
49cdf0e10cSrcweir {
50cdf0e10cSrcweir 	SFX_ASSERT(SfxPoolItem::operator ==(rItem), Which(), "unequal type");
51cdf0e10cSrcweir 	return GetEnumValue()
52cdf0e10cSrcweir 		       == static_cast< const SfxEnumItemInterface * >(&rItem)->
53cdf0e10cSrcweir 		              GetEnumValue();
54cdf0e10cSrcweir }
55cdf0e10cSrcweir 
56cdf0e10cSrcweir //============================================================================
57cdf0e10cSrcweir // virtual
58cdf0e10cSrcweir SfxItemPresentation
GetPresentation(SfxItemPresentation,SfxMapUnit,SfxMapUnit,XubString & rText,const IntlWrapper *) const59cdf0e10cSrcweir SfxEnumItemInterface::GetPresentation(SfxItemPresentation, SfxMapUnit,
60cdf0e10cSrcweir 									  SfxMapUnit, XubString & rText,
61cdf0e10cSrcweir                                       const IntlWrapper *) const
62cdf0e10cSrcweir {
63cdf0e10cSrcweir 	rText = XubString::CreateFromInt32(GetEnumValue());
64cdf0e10cSrcweir 	return SFX_ITEM_PRESENTATION_NAMELESS;
65cdf0e10cSrcweir }
66cdf0e10cSrcweir 
67cdf0e10cSrcweir //============================================================================
68cdf0e10cSrcweir // virtual
QueryValue(com::sun::star::uno::Any & rVal,sal_uInt8) const69cdf0e10cSrcweir sal_Bool SfxEnumItemInterface::QueryValue(com::sun::star::uno::Any& rVal, sal_uInt8)
70cdf0e10cSrcweir 	const
71cdf0e10cSrcweir {
72cdf0e10cSrcweir 	rVal <<= sal_Int32(GetEnumValue());
73cdf0e10cSrcweir 	return true;
74cdf0e10cSrcweir }
75cdf0e10cSrcweir 
76cdf0e10cSrcweir //============================================================================
77cdf0e10cSrcweir // virtual
PutValue(const com::sun::star::uno::Any & rVal,sal_uInt8)78cdf0e10cSrcweir sal_Bool SfxEnumItemInterface::PutValue(const com::sun::star::uno::Any& rVal,
79cdf0e10cSrcweir 									sal_uInt8)
80cdf0e10cSrcweir {
81cdf0e10cSrcweir 	sal_Int32 nTheValue = 0;
82cdf0e10cSrcweir 
83cdf0e10cSrcweir 	if ( ::cppu::enum2int( nTheValue, rVal ) )
84cdf0e10cSrcweir 	{
85cdf0e10cSrcweir 		SetEnumValue(sal_uInt16(nTheValue));
86cdf0e10cSrcweir 		return true;
87cdf0e10cSrcweir 	}
88cdf0e10cSrcweir 	DBG_ERROR("SfxEnumItemInterface::PutValue(): Wrong type");
89cdf0e10cSrcweir 	return false;
90cdf0e10cSrcweir }
91cdf0e10cSrcweir 
92cdf0e10cSrcweir //============================================================================
GetValueTextByPos(sal_uInt16) const93cdf0e10cSrcweir XubString SfxEnumItemInterface::GetValueTextByPos(sal_uInt16) const
94cdf0e10cSrcweir {
95cdf0e10cSrcweir 	DBG_WARNING("SfxEnumItemInterface::GetValueTextByPos(): Pure virtual");
96cdf0e10cSrcweir 	return XubString();
97cdf0e10cSrcweir }
98cdf0e10cSrcweir 
99cdf0e10cSrcweir //============================================================================
100cdf0e10cSrcweir // virtual
GetValueByPos(sal_uInt16 nPos) const101cdf0e10cSrcweir sal_uInt16 SfxEnumItemInterface::GetValueByPos(sal_uInt16 nPos) const
102cdf0e10cSrcweir {
103cdf0e10cSrcweir 	return nPos;
104cdf0e10cSrcweir }
105cdf0e10cSrcweir 
106cdf0e10cSrcweir //============================================================================
107cdf0e10cSrcweir // virtual
GetPosByValue(sal_uInt16 nValue) const108cdf0e10cSrcweir sal_uInt16 SfxEnumItemInterface::GetPosByValue(sal_uInt16 nValue) const
109cdf0e10cSrcweir {
110cdf0e10cSrcweir 	sal_uInt16 nCount = GetValueCount();
111cdf0e10cSrcweir 	for (sal_uInt16 i = 0; i < nCount; ++i)
112cdf0e10cSrcweir 		if (GetValueByPos(i) == nValue)
113cdf0e10cSrcweir 			return i;
114cdf0e10cSrcweir 	return USHRT_MAX;
115cdf0e10cSrcweir }
116cdf0e10cSrcweir 
IsEnabled(sal_uInt16) const117cdf0e10cSrcweir sal_Bool SfxEnumItemInterface::IsEnabled(sal_uInt16) const
118cdf0e10cSrcweir {
119cdf0e10cSrcweir 	return sal_True;
120cdf0e10cSrcweir }
121cdf0e10cSrcweir 
122cdf0e10cSrcweir //============================================================================
123cdf0e10cSrcweir // virtual
HasBoolValue() const124cdf0e10cSrcweir int SfxEnumItemInterface::HasBoolValue() const
125cdf0e10cSrcweir {
126cdf0e10cSrcweir 	return false;
127cdf0e10cSrcweir }
128cdf0e10cSrcweir 
129cdf0e10cSrcweir //============================================================================
130cdf0e10cSrcweir // virtual
GetBoolValue() const131cdf0e10cSrcweir sal_Bool SfxEnumItemInterface::GetBoolValue() const
132cdf0e10cSrcweir {
133cdf0e10cSrcweir 	return false;
134cdf0e10cSrcweir }
135cdf0e10cSrcweir 
136cdf0e10cSrcweir //============================================================================
137cdf0e10cSrcweir // virtual
SetBoolValue(sal_Bool)138cdf0e10cSrcweir void SfxEnumItemInterface::SetBoolValue(sal_Bool)
139cdf0e10cSrcweir {}
140cdf0e10cSrcweir 
141cdf0e10cSrcweir //============================================================================
142cdf0e10cSrcweir //
143cdf0e10cSrcweir //  class CntEnumItem
144cdf0e10cSrcweir //
145cdf0e10cSrcweir //============================================================================
146cdf0e10cSrcweir 
DBG_NAME(CntEnumItem)147cdf0e10cSrcweir DBG_NAME(CntEnumItem)
148cdf0e10cSrcweir 
149cdf0e10cSrcweir //============================================================================
150cdf0e10cSrcweir CntEnumItem::CntEnumItem(sal_uInt16 which, SvStream & rStream):
151cdf0e10cSrcweir 	SfxEnumItemInterface(which)
152cdf0e10cSrcweir {
153cdf0e10cSrcweir 	m_nValue = 0;
154cdf0e10cSrcweir 	rStream >> m_nValue;
155cdf0e10cSrcweir }
156cdf0e10cSrcweir 
157cdf0e10cSrcweir //============================================================================
TYPEINIT1(CntEnumItem,SfxEnumItemInterface)158cdf0e10cSrcweir TYPEINIT1(CntEnumItem, SfxEnumItemInterface)
159cdf0e10cSrcweir 
160cdf0e10cSrcweir //============================================================================
161cdf0e10cSrcweir // virtual
162cdf0e10cSrcweir SvStream & CntEnumItem::Store(SvStream & rStream, sal_uInt16) const
163cdf0e10cSrcweir {
164cdf0e10cSrcweir 	rStream << m_nValue;
165cdf0e10cSrcweir 	return rStream;
166cdf0e10cSrcweir }
167cdf0e10cSrcweir 
168cdf0e10cSrcweir //============================================================================
169cdf0e10cSrcweir // virtual
GetEnumValue() const170cdf0e10cSrcweir sal_uInt16 CntEnumItem::GetEnumValue() const
171cdf0e10cSrcweir {
172cdf0e10cSrcweir 	return GetValue();
173cdf0e10cSrcweir }
174cdf0e10cSrcweir 
175cdf0e10cSrcweir //============================================================================
176cdf0e10cSrcweir // virtual
SetEnumValue(sal_uInt16 nTheValue)177cdf0e10cSrcweir void CntEnumItem::SetEnumValue(sal_uInt16 nTheValue)
178cdf0e10cSrcweir {
179cdf0e10cSrcweir 	SetValue(nTheValue);
180cdf0e10cSrcweir }
181cdf0e10cSrcweir 
182cdf0e10cSrcweir //============================================================================
183cdf0e10cSrcweir //
184cdf0e10cSrcweir //  class CntBoolItem
185cdf0e10cSrcweir //
186cdf0e10cSrcweir //============================================================================
187cdf0e10cSrcweir 
188cdf0e10cSrcweir DBG_NAME(CntBoolItem)
189cdf0e10cSrcweir 
190cdf0e10cSrcweir //============================================================================
TYPEINIT1_AUTOFACTORY(CntBoolItem,SfxPoolItem)191cdf0e10cSrcweir TYPEINIT1_AUTOFACTORY(CntBoolItem, SfxPoolItem)
192cdf0e10cSrcweir 
193cdf0e10cSrcweir //============================================================================
194cdf0e10cSrcweir CntBoolItem::CntBoolItem(sal_uInt16 which, SvStream & rStream):
195cdf0e10cSrcweir 	SfxPoolItem(which)
196cdf0e10cSrcweir {
197cdf0e10cSrcweir 	m_bValue = false;
198cdf0e10cSrcweir 	rStream >> m_bValue;
199cdf0e10cSrcweir }
200cdf0e10cSrcweir 
201cdf0e10cSrcweir //============================================================================
202cdf0e10cSrcweir // virtual
operator ==(const SfxPoolItem & rItem) const203cdf0e10cSrcweir int CntBoolItem::operator ==(const SfxPoolItem & rItem) const
204cdf0e10cSrcweir {
205cdf0e10cSrcweir 	DBG_ASSERT(rItem.ISA(CntBoolItem),
206cdf0e10cSrcweir 			   "CntBoolItem::operator ==(): Bad type");
207cdf0e10cSrcweir 	return m_bValue == static_cast< CntBoolItem const * >(&rItem)->m_bValue;
208cdf0e10cSrcweir }
209cdf0e10cSrcweir 
210cdf0e10cSrcweir //============================================================================
211cdf0e10cSrcweir // virtual
Compare(const SfxPoolItem & rWith) const212cdf0e10cSrcweir int CntBoolItem::Compare(const SfxPoolItem & rWith) const
213cdf0e10cSrcweir {
214cdf0e10cSrcweir 	DBG_ASSERT(rWith.ISA(CntBoolItem), "CntBoolItem::Compare(): Bad type");
215cdf0e10cSrcweir 	return m_bValue == static_cast< CntBoolItem const * >(&rWith)->m_bValue ?
216cdf0e10cSrcweir 		       0 : m_bValue ? -1 : 1;
217cdf0e10cSrcweir }
218cdf0e10cSrcweir 
219cdf0e10cSrcweir //============================================================================
220cdf0e10cSrcweir // virtual
GetPresentation(SfxItemPresentation,SfxMapUnit,SfxMapUnit,UniString & rText,const IntlWrapper *) const221cdf0e10cSrcweir SfxItemPresentation CntBoolItem::GetPresentation(SfxItemPresentation,
222cdf0e10cSrcweir 												 SfxMapUnit, SfxMapUnit,
223cdf0e10cSrcweir 												 UniString & rText,
224cdf0e10cSrcweir                                                  const IntlWrapper *) const
225cdf0e10cSrcweir {
226cdf0e10cSrcweir 	rText = GetValueTextByVal(m_bValue);
227cdf0e10cSrcweir 	return SFX_ITEM_PRESENTATION_NAMELESS;
228cdf0e10cSrcweir }
229cdf0e10cSrcweir 
230cdf0e10cSrcweir //============================================================================
231cdf0e10cSrcweir // virtual
QueryValue(com::sun::star::uno::Any & rVal,sal_uInt8) const232cdf0e10cSrcweir sal_Bool CntBoolItem::QueryValue(com::sun::star::uno::Any& rVal, sal_uInt8) const
233cdf0e10cSrcweir {
234cdf0e10cSrcweir 	rVal <<= sal_Bool(m_bValue);
235cdf0e10cSrcweir 	return true;
236cdf0e10cSrcweir }
237cdf0e10cSrcweir 
238cdf0e10cSrcweir //============================================================================
239cdf0e10cSrcweir // virtual
PutValue(const com::sun::star::uno::Any & rVal,sal_uInt8)240cdf0e10cSrcweir sal_Bool CntBoolItem::PutValue(const com::sun::star::uno::Any& rVal, sal_uInt8)
241cdf0e10cSrcweir {
242cdf0e10cSrcweir 	sal_Bool bTheValue = sal_Bool();
243cdf0e10cSrcweir 	if (rVal >>= bTheValue)
244cdf0e10cSrcweir 	{
245cdf0e10cSrcweir 		m_bValue = bTheValue;
246cdf0e10cSrcweir 		return true;
247cdf0e10cSrcweir 	}
248cdf0e10cSrcweir 	DBG_ERROR("CntBoolItem::PutValue(): Wrong type");
249cdf0e10cSrcweir 	return false;
250cdf0e10cSrcweir }
251cdf0e10cSrcweir 
252cdf0e10cSrcweir //============================================================================
253cdf0e10cSrcweir // virtual
Create(SvStream & rStream,sal_uInt16) const254cdf0e10cSrcweir SfxPoolItem * CntBoolItem::Create(SvStream & rStream, sal_uInt16) const
255cdf0e10cSrcweir {
256cdf0e10cSrcweir 	return new CntBoolItem(Which(), rStream);
257cdf0e10cSrcweir }
258cdf0e10cSrcweir 
259cdf0e10cSrcweir //============================================================================
260cdf0e10cSrcweir // virtual
Store(SvStream & rStream,sal_uInt16) const261cdf0e10cSrcweir SvStream & CntBoolItem::Store(SvStream & rStream, sal_uInt16) const
262cdf0e10cSrcweir {
263cdf0e10cSrcweir 	rStream << m_bValue;
264cdf0e10cSrcweir 	return rStream;
265cdf0e10cSrcweir }
266cdf0e10cSrcweir 
267cdf0e10cSrcweir //============================================================================
268cdf0e10cSrcweir // virtual
Clone(SfxItemPool *) const269cdf0e10cSrcweir SfxPoolItem * CntBoolItem::Clone(SfxItemPool *) const
270cdf0e10cSrcweir {
271cdf0e10cSrcweir 	return new CntBoolItem(*this);
272cdf0e10cSrcweir }
273cdf0e10cSrcweir 
274cdf0e10cSrcweir //============================================================================
275cdf0e10cSrcweir // virtual
GetValueCount() const276cdf0e10cSrcweir sal_uInt16 CntBoolItem::GetValueCount() const
277cdf0e10cSrcweir {
278cdf0e10cSrcweir 	return 2;
279cdf0e10cSrcweir }
280cdf0e10cSrcweir 
281cdf0e10cSrcweir //============================================================================
282cdf0e10cSrcweir // virtual
GetValueTextByVal(sal_Bool bTheValue) const283cdf0e10cSrcweir UniString CntBoolItem::GetValueTextByVal(sal_Bool bTheValue) const
284cdf0e10cSrcweir {
285cdf0e10cSrcweir 	return
286cdf0e10cSrcweir 		bTheValue ?
287cdf0e10cSrcweir 		    UniString::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM("sal_True")) :
288cdf0e10cSrcweir 		    UniString::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM("sal_False"));
289cdf0e10cSrcweir }
290cdf0e10cSrcweir 
291