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: cenumitm.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 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svtools.hxx"
33 #include <com/sun/star/uno/Any.hxx>
34 #include <tools/stream.hxx>
35 #include <svtools/cenumitm.hxx>
36 #include <whassert.hxx>
38 #ifndef _CPPUHELPER_EXTRACT_HXX_
39 #include <cppuhelper/extract.hxx>
42 //============================================================================
44 // class SfxEnumItemInterface
46 //============================================================================
48 DBG_NAME(SfxEnumItemInterface
)
50 //============================================================================
51 TYPEINIT1(SfxEnumItemInterface
, SfxPoolItem
)
53 //============================================================================
55 int SfxEnumItemInterface::operator ==(const SfxPoolItem
& rItem
) const
57 SFX_ASSERT(SfxPoolItem::operator ==(rItem
), Which(), "unequal type");
59 == static_cast< const SfxEnumItemInterface
* >(&rItem
)->
63 //============================================================================
66 SfxEnumItemInterface::GetPresentation(SfxItemPresentation
, SfxMapUnit
,
67 SfxMapUnit
, XubString
& rText
,
68 const IntlWrapper
*) const
70 rText
= XubString::CreateFromInt32(GetEnumValue());
71 return SFX_ITEM_PRESENTATION_NAMELESS
;
74 //============================================================================
76 BOOL
SfxEnumItemInterface::QueryValue(com::sun::star::uno::Any
& rVal
, BYTE
)
79 rVal
<<= sal_Int32(GetEnumValue());
83 //============================================================================
85 BOOL
SfxEnumItemInterface::PutValue(const com::sun::star::uno::Any
& rVal
,
88 sal_Int32 nTheValue
= 0;
90 if ( ::cppu::enum2int( nTheValue
, rVal
) )
92 SetEnumValue(USHORT(nTheValue
));
95 DBG_ERROR("SfxEnumItemInterface::PutValue(): Wrong type");
99 //============================================================================
100 XubString
SfxEnumItemInterface::GetValueTextByPos(USHORT
) const
102 DBG_WARNING("SfxEnumItemInterface::GetValueTextByPos(): Pure virtual");
106 //============================================================================
108 USHORT
SfxEnumItemInterface::GetValueByPos(USHORT nPos
) const
113 //============================================================================
115 USHORT
SfxEnumItemInterface::GetPosByValue(USHORT nValue
) const
117 USHORT nCount
= GetValueCount();
118 for (USHORT i
= 0; i
< nCount
; ++i
)
119 if (GetValueByPos(i
) == nValue
)
124 BOOL
SfxEnumItemInterface::IsEnabled(USHORT
) const
129 //============================================================================
131 int SfxEnumItemInterface::HasBoolValue() const
136 //============================================================================
138 BOOL
SfxEnumItemInterface::GetBoolValue() const
143 //============================================================================
145 void SfxEnumItemInterface::SetBoolValue(BOOL
)
148 //============================================================================
152 //============================================================================
154 DBG_NAME(CntEnumItem
)
156 //============================================================================
157 CntEnumItem::CntEnumItem(USHORT which
, SvStream
& rStream
):
158 SfxEnumItemInterface(which
)
164 //============================================================================
165 TYPEINIT1(CntEnumItem
, SfxEnumItemInterface
)
167 //============================================================================
169 SvStream
& CntEnumItem::Store(SvStream
& rStream
, USHORT
) const
175 //============================================================================
177 USHORT
CntEnumItem::GetEnumValue() const
182 //============================================================================
184 void CntEnumItem::SetEnumValue(USHORT nTheValue
)
189 //============================================================================
193 //============================================================================
195 DBG_NAME(CntBoolItem
)
197 //============================================================================
198 TYPEINIT1_AUTOFACTORY(CntBoolItem
, SfxPoolItem
)
200 //============================================================================
201 CntBoolItem::CntBoolItem(USHORT which
, SvStream
& rStream
):
208 //============================================================================
210 int CntBoolItem::operator ==(const SfxPoolItem
& rItem
) const
212 DBG_ASSERT(rItem
.ISA(CntBoolItem
),
213 "CntBoolItem::operator ==(): Bad type");
214 return m_bValue
== static_cast< CntBoolItem
const * >(&rItem
)->m_bValue
;
217 //============================================================================
219 int CntBoolItem::Compare(const SfxPoolItem
& rWith
) const
221 DBG_ASSERT(rWith
.ISA(CntBoolItem
), "CntBoolItem::Compare(): Bad type");
222 return m_bValue
== static_cast< CntBoolItem
const * >(&rWith
)->m_bValue
?
223 0 : m_bValue
? -1 : 1;
226 //============================================================================
228 SfxItemPresentation
CntBoolItem::GetPresentation(SfxItemPresentation
,
229 SfxMapUnit
, SfxMapUnit
,
231 const IntlWrapper
*) const
233 rText
= GetValueTextByVal(m_bValue
);
234 return SFX_ITEM_PRESENTATION_NAMELESS
;
237 //============================================================================
239 BOOL
CntBoolItem::QueryValue(com::sun::star::uno::Any
& rVal
, BYTE
) const
241 rVal
<<= sal_Bool(m_bValue
);
245 //============================================================================
247 BOOL
CntBoolItem::PutValue(const com::sun::star::uno::Any
& rVal
, BYTE
)
249 sal_Bool bTheValue
= sal_Bool();
250 if (rVal
>>= bTheValue
)
252 m_bValue
= bTheValue
;
255 DBG_ERROR("CntBoolItem::PutValue(): Wrong type");
259 //============================================================================
261 SfxPoolItem
* CntBoolItem::Create(SvStream
& rStream
, USHORT
) const
263 return new CntBoolItem(Which(), rStream
);
266 //============================================================================
268 SvStream
& CntBoolItem::Store(SvStream
& rStream
, USHORT
) const
274 //============================================================================
276 SfxPoolItem
* CntBoolItem::Clone(SfxItemPool
*) const
278 return new CntBoolItem(*this);
281 //============================================================================
283 USHORT
CntBoolItem::GetValueCount() const
288 //============================================================================
290 UniString
CntBoolItem::GetValueTextByVal(BOOL bTheValue
) const
294 UniString::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM("TRUE")) :
295 UniString::CreateFromAscii(RTL_CONSTASCII_STRINGPARAM("FALSE"));