xref: /aoo42x/main/svl/source/items/cenumitm.cxx (revision cdf0e10c)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_svl.hxx"
30*cdf0e10cSrcweir #include <com/sun/star/uno/Any.hxx>
31*cdf0e10cSrcweir #include <tools/stream.hxx>
32*cdf0e10cSrcweir #include <svl/cenumitm.hxx>
33*cdf0e10cSrcweir #include <whassert.hxx>
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir #ifndef _CPPUHELPER_EXTRACT_HXX_
36*cdf0e10cSrcweir #include <comphelper/extract.hxx>
37*cdf0e10cSrcweir #endif
38*cdf0e10cSrcweir 
39*cdf0e10cSrcweir //============================================================================
40*cdf0e10cSrcweir //
41*cdf0e10cSrcweir //  class SfxEnumItemInterface
42*cdf0e10cSrcweir //
43*cdf0e10cSrcweir //============================================================================
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir DBG_NAME(SfxEnumItemInterface)
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir //============================================================================
48*cdf0e10cSrcweir TYPEINIT1(SfxEnumItemInterface, SfxPoolItem)
49*cdf0e10cSrcweir 
50*cdf0e10cSrcweir //============================================================================
51*cdf0e10cSrcweir // virtual
52*cdf0e10cSrcweir int SfxEnumItemInterface::operator ==(const SfxPoolItem & rItem) const
53*cdf0e10cSrcweir {
54*cdf0e10cSrcweir 	SFX_ASSERT(SfxPoolItem::operator ==(rItem), Which(), "unequal type");
55*cdf0e10cSrcweir 	return GetEnumValue()
56*cdf0e10cSrcweir 		       == static_cast< const SfxEnumItemInterface * >(&rItem)->
57*cdf0e10cSrcweir 		              GetEnumValue();
58*cdf0e10cSrcweir }
59*cdf0e10cSrcweir 
60*cdf0e10cSrcweir //============================================================================
61*cdf0e10cSrcweir // virtual
62*cdf0e10cSrcweir SfxItemPresentation
63*cdf0e10cSrcweir SfxEnumItemInterface::GetPresentation(SfxItemPresentation, SfxMapUnit,
64*cdf0e10cSrcweir 									  SfxMapUnit, XubString & rText,
65*cdf0e10cSrcweir                                       const IntlWrapper *) const
66*cdf0e10cSrcweir {
67*cdf0e10cSrcweir 	rText = XubString::CreateFromInt32(GetEnumValue());
68*cdf0e10cSrcweir 	return SFX_ITEM_PRESENTATION_NAMELESS;
69*cdf0e10cSrcweir }
70*cdf0e10cSrcweir 
71*cdf0e10cSrcweir //============================================================================
72*cdf0e10cSrcweir // virtual
73*cdf0e10cSrcweir sal_Bool SfxEnumItemInterface::QueryValue(com::sun::star::uno::Any& rVal, sal_uInt8)
74*cdf0e10cSrcweir 	const
75*cdf0e10cSrcweir {
76*cdf0e10cSrcweir 	rVal <<= sal_Int32(GetEnumValue());
77*cdf0e10cSrcweir 	return true;
78*cdf0e10cSrcweir }
79*cdf0e10cSrcweir 
80*cdf0e10cSrcweir //============================================================================
81*cdf0e10cSrcweir // virtual
82*cdf0e10cSrcweir sal_Bool SfxEnumItemInterface::PutValue(const com::sun::star::uno::Any& rVal,
83*cdf0e10cSrcweir 									sal_uInt8)
84*cdf0e10cSrcweir {
85*cdf0e10cSrcweir 	sal_Int32 nTheValue = 0;
86*cdf0e10cSrcweir 
87*cdf0e10cSrcweir 	if ( ::cppu::enum2int( nTheValue, rVal ) )
88*cdf0e10cSrcweir 	{
89*cdf0e10cSrcweir 		SetEnumValue(sal_uInt16(nTheValue));
90*cdf0e10cSrcweir 		return true;
91*cdf0e10cSrcweir 	}
92*cdf0e10cSrcweir 	DBG_ERROR("SfxEnumItemInterface::PutValue(): Wrong type");
93*cdf0e10cSrcweir 	return false;
94*cdf0e10cSrcweir }
95*cdf0e10cSrcweir 
96*cdf0e10cSrcweir //============================================================================
97*cdf0e10cSrcweir XubString SfxEnumItemInterface::GetValueTextByPos(sal_uInt16) const
98*cdf0e10cSrcweir {
99*cdf0e10cSrcweir 	DBG_WARNING("SfxEnumItemInterface::GetValueTextByPos(): Pure virtual");
100*cdf0e10cSrcweir 	return XubString();
101*cdf0e10cSrcweir }
102*cdf0e10cSrcweir 
103*cdf0e10cSrcweir //============================================================================
104*cdf0e10cSrcweir // virtual
105*cdf0e10cSrcweir sal_uInt16 SfxEnumItemInterface::GetValueByPos(sal_uInt16 nPos) const
106*cdf0e10cSrcweir {
107*cdf0e10cSrcweir 	return nPos;
108*cdf0e10cSrcweir }
109*cdf0e10cSrcweir 
110*cdf0e10cSrcweir //============================================================================
111*cdf0e10cSrcweir // virtual
112*cdf0e10cSrcweir sal_uInt16 SfxEnumItemInterface::GetPosByValue(sal_uInt16 nValue) const
113*cdf0e10cSrcweir {
114*cdf0e10cSrcweir 	sal_uInt16 nCount = GetValueCount();
115*cdf0e10cSrcweir 	for (sal_uInt16 i = 0; i < nCount; ++i)
116*cdf0e10cSrcweir 		if (GetValueByPos(i) == nValue)
117*cdf0e10cSrcweir 			return i;
118*cdf0e10cSrcweir 	return USHRT_MAX;
119*cdf0e10cSrcweir }
120*cdf0e10cSrcweir 
121*cdf0e10cSrcweir sal_Bool SfxEnumItemInterface::IsEnabled(sal_uInt16) const
122*cdf0e10cSrcweir {
123*cdf0e10cSrcweir 	return sal_True;
124*cdf0e10cSrcweir }
125*cdf0e10cSrcweir 
126*cdf0e10cSrcweir //============================================================================
127*cdf0e10cSrcweir // virtual
128*cdf0e10cSrcweir int SfxEnumItemInterface::HasBoolValue() const
129*cdf0e10cSrcweir {
130*cdf0e10cSrcweir 	return false;
131*cdf0e10cSrcweir }
132*cdf0e10cSrcweir 
133*cdf0e10cSrcweir //============================================================================
134*cdf0e10cSrcweir // virtual
135*cdf0e10cSrcweir sal_Bool SfxEnumItemInterface::GetBoolValue() const
136*cdf0e10cSrcweir {
137*cdf0e10cSrcweir 	return false;
138*cdf0e10cSrcweir }
139*cdf0e10cSrcweir 
140*cdf0e10cSrcweir //============================================================================
141*cdf0e10cSrcweir // virtual
142*cdf0e10cSrcweir void SfxEnumItemInterface::SetBoolValue(sal_Bool)
143*cdf0e10cSrcweir {}
144*cdf0e10cSrcweir 
145*cdf0e10cSrcweir //============================================================================
146*cdf0e10cSrcweir //
147*cdf0e10cSrcweir //  class CntEnumItem
148*cdf0e10cSrcweir //
149*cdf0e10cSrcweir //============================================================================
150*cdf0e10cSrcweir 
151*cdf0e10cSrcweir DBG_NAME(CntEnumItem)
152*cdf0e10cSrcweir 
153*cdf0e10cSrcweir //============================================================================
154*cdf0e10cSrcweir CntEnumItem::CntEnumItem(sal_uInt16 which, SvStream & rStream):
155*cdf0e10cSrcweir 	SfxEnumItemInterface(which)
156*cdf0e10cSrcweir {
157*cdf0e10cSrcweir 	m_nValue = 0;
158*cdf0e10cSrcweir 	rStream >> m_nValue;
159*cdf0e10cSrcweir }
160*cdf0e10cSrcweir 
161*cdf0e10cSrcweir //============================================================================
162*cdf0e10cSrcweir TYPEINIT1(CntEnumItem, SfxEnumItemInterface)
163*cdf0e10cSrcweir 
164*cdf0e10cSrcweir //============================================================================
165*cdf0e10cSrcweir // virtual
166*cdf0e10cSrcweir SvStream & CntEnumItem::Store(SvStream & rStream, sal_uInt16) const
167*cdf0e10cSrcweir {
168*cdf0e10cSrcweir 	rStream << m_nValue;
169*cdf0e10cSrcweir 	return rStream;
170*cdf0e10cSrcweir }
171*cdf0e10cSrcweir 
172*cdf0e10cSrcweir //============================================================================
173*cdf0e10cSrcweir // virtual
174*cdf0e10cSrcweir sal_uInt16 CntEnumItem::GetEnumValue() const
175*cdf0e10cSrcweir {
176*cdf0e10cSrcweir 	return GetValue();
177*cdf0e10cSrcweir }
178*cdf0e10cSrcweir 
179*cdf0e10cSrcweir //============================================================================
180*cdf0e10cSrcweir // virtual
181*cdf0e10cSrcweir void CntEnumItem::SetEnumValue(sal_uInt16 nTheValue)
182*cdf0e10cSrcweir {
183*cdf0e10cSrcweir 	SetValue(nTheValue);
184*cdf0e10cSrcweir }
185*cdf0e10cSrcweir 
186*cdf0e10cSrcweir //============================================================================
187*cdf0e10cSrcweir //
188*cdf0e10cSrcweir //  class CntBoolItem
189*cdf0e10cSrcweir //
190*cdf0e10cSrcweir //============================================================================
191*cdf0e10cSrcweir 
192*cdf0e10cSrcweir DBG_NAME(CntBoolItem)
193*cdf0e10cSrcweir 
194*cdf0e10cSrcweir //============================================================================
195*cdf0e10cSrcweir TYPEINIT1_AUTOFACTORY(CntBoolItem, SfxPoolItem)
196*cdf0e10cSrcweir 
197*cdf0e10cSrcweir //============================================================================
198*cdf0e10cSrcweir CntBoolItem::CntBoolItem(sal_uInt16 which, SvStream & rStream):
199*cdf0e10cSrcweir 	SfxPoolItem(which)
200*cdf0e10cSrcweir {
201*cdf0e10cSrcweir 	m_bValue = false;
202*cdf0e10cSrcweir 	rStream >> m_bValue;
203*cdf0e10cSrcweir }
204*cdf0e10cSrcweir 
205*cdf0e10cSrcweir //============================================================================
206*cdf0e10cSrcweir // virtual
207*cdf0e10cSrcweir int CntBoolItem::operator ==(const SfxPoolItem & rItem) const
208*cdf0e10cSrcweir {
209*cdf0e10cSrcweir 	DBG_ASSERT(rItem.ISA(CntBoolItem),
210*cdf0e10cSrcweir 			   "CntBoolItem::operator ==(): Bad type");
211*cdf0e10cSrcweir 	return m_bValue == static_cast< CntBoolItem const * >(&rItem)->m_bValue;
212*cdf0e10cSrcweir }
213*cdf0e10cSrcweir 
214*cdf0e10cSrcweir //============================================================================
215*cdf0e10cSrcweir // virtual
216*cdf0e10cSrcweir int CntBoolItem::Compare(const SfxPoolItem & rWith) const
217*cdf0e10cSrcweir {
218*cdf0e10cSrcweir 	DBG_ASSERT(rWith.ISA(CntBoolItem), "CntBoolItem::Compare(): Bad type");
219*cdf0e10cSrcweir 	return m_bValue == static_cast< CntBoolItem const * >(&rWith)->m_bValue ?
220*cdf0e10cSrcweir 		       0 : m_bValue ? -1 : 1;
221*cdf0e10cSrcweir }
222*cdf0e10cSrcweir 
223*cdf0e10cSrcweir //============================================================================
224*cdf0e10cSrcweir // virtual
225*cdf0e10cSrcweir SfxItemPresentation CntBoolItem::GetPresentation(SfxItemPresentation,
226*cdf0e10cSrcweir 												 SfxMapUnit, SfxMapUnit,
227*cdf0e10cSrcweir 												 UniString & rText,
228*cdf0e10cSrcweir                                                  const IntlWrapper *) const
229*cdf0e10cSrcweir {
230*cdf0e10cSrcweir 	rText = GetValueTextByVal(m_bValue);
231*cdf0e10cSrcweir 	return SFX_ITEM_PRESENTATION_NAMELESS;
232*cdf0e10cSrcweir }
233*cdf0e10cSrcweir 
234*cdf0e10cSrcweir //============================================================================
235*cdf0e10cSrcweir // virtual
236*cdf0e10cSrcweir sal_Bool CntBoolItem::QueryValue(com::sun::star::uno::Any& rVal, sal_uInt8) const
237*cdf0e10cSrcweir {
238*cdf0e10cSrcweir 	rVal <<= sal_Bool(m_bValue);
239*cdf0e10cSrcweir 	return true;
240*cdf0e10cSrcweir }
241*cdf0e10cSrcweir 
242*cdf0e10cSrcweir //============================================================================
243*cdf0e10cSrcweir // virtual
244*cdf0e10cSrcweir sal_Bool CntBoolItem::PutValue(const com::sun::star::uno::Any& rVal, sal_uInt8)
245*cdf0e10cSrcweir {
246*cdf0e10cSrcweir 	sal_Bool bTheValue = sal_Bool();
247*cdf0e10cSrcweir 	if (rVal >>= bTheValue)
248*cdf0e10cSrcweir 	{
249*cdf0e10cSrcweir 		m_bValue = bTheValue;
250*cdf0e10cSrcweir 		return true;
251*cdf0e10cSrcweir 	}
252*cdf0e10cSrcweir 	DBG_ERROR("CntBoolItem::PutValue(): Wrong type");
253*cdf0e10cSrcweir 	return false;
254*cdf0e10cSrcweir }
255*cdf0e10cSrcweir 
256*cdf0e10cSrcweir //============================================================================
257*cdf0e10cSrcweir // virtual
258*cdf0e10cSrcweir SfxPoolItem * CntBoolItem::Create(SvStream & rStream, sal_uInt16) const
259*cdf0e10cSrcweir {
260*cdf0e10cSrcweir 	return new CntBoolItem(Which(), rStream);
261*cdf0e10cSrcweir }
262*cdf0e10cSrcweir 
263*cdf0e10cSrcweir //============================================================================
264*cdf0e10cSrcweir // virtual
265*cdf0e10cSrcweir SvStream & CntBoolItem::Store(SvStream & rStream, sal_uInt16) const
266*cdf0e10cSrcweir {
267*cdf0e10cSrcweir 	rStream << m_bValue;
268*cdf0e10cSrcweir 	return rStream;
269*cdf0e10cSrcweir }
270*cdf0e10cSrcweir 
271*cdf0e10cSrcweir //============================================================================
272*cdf0e10cSrcweir // virtual
273*cdf0e10cSrcweir SfxPoolItem * CntBoolItem::Clone(SfxItemPool *) const
274*cdf0e10cSrcweir {
275*cdf0e10cSrcweir 	return new CntBoolItem(*this);
276*cdf0e10cSrcweir }
277*cdf0e10cSrcweir 
278*cdf0e10cSrcweir //============================================================================
279*cdf0e10cSrcweir // virtual
280*cdf0e10cSrcweir sal_uInt16 CntBoolItem::GetValueCount() const
281*cdf0e10cSrcweir {
282*cdf0e10cSrcweir 	return 2;
283*cdf0e10cSrcweir }
284*cdf0e10cSrcweir 
285*cdf0e10cSrcweir //============================================================================
286*cdf0e10cSrcweir // virtual
287*cdf0e10cSrcweir UniString CntBoolItem::GetValueTextByVal(sal_Bool bTheValue) const
288*cdf0e10cSrcweir {
289*cdf0e10cSrcweir 	return
290*cdf0e10cSrcweir 		bTheValue ?
291*cdf0e10cSrcweir 		    UniString::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM("sal_True")) :
292*cdf0e10cSrcweir 		    UniString::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM("sal_False"));
293*cdf0e10cSrcweir }
294*cdf0e10cSrcweir 
295