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 10cdf0e10cSrcweir * 11*40df464eSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 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. 19cdf0e10cSrcweir * 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 59cdf0e10cSrcweir 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 69cdf0e10cSrcweir 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 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 //============================================================================ 93cdf0e10cSrcweir XubString SfxEnumItemInterface::GetValueTextByPos(sal_uInt16) const 94cdf0e10cSrcweir { 95cdf0e10cSrcweir DBG_WARNING("SfxEnumItemInterface::GetValueTextByPos(): Pure virtual"); 96cdf0e10cSrcweir return XubString(); 97cdf0e10cSrcweir } 98cdf0e10cSrcweir 99cdf0e10cSrcweir //============================================================================ 100cdf0e10cSrcweir // virtual 101cdf0e10cSrcweir sal_uInt16 SfxEnumItemInterface::GetValueByPos(sal_uInt16 nPos) const 102cdf0e10cSrcweir { 103cdf0e10cSrcweir return nPos; 104cdf0e10cSrcweir } 105cdf0e10cSrcweir 106cdf0e10cSrcweir //============================================================================ 107cdf0e10cSrcweir // virtual 108cdf0e10cSrcweir 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 117cdf0e10cSrcweir sal_Bool SfxEnumItemInterface::IsEnabled(sal_uInt16) const 118cdf0e10cSrcweir { 119cdf0e10cSrcweir return sal_True; 120cdf0e10cSrcweir } 121cdf0e10cSrcweir 122cdf0e10cSrcweir //============================================================================ 123cdf0e10cSrcweir // virtual 124cdf0e10cSrcweir int SfxEnumItemInterface::HasBoolValue() const 125cdf0e10cSrcweir { 126cdf0e10cSrcweir return false; 127cdf0e10cSrcweir } 128cdf0e10cSrcweir 129cdf0e10cSrcweir //============================================================================ 130cdf0e10cSrcweir // virtual 131cdf0e10cSrcweir sal_Bool SfxEnumItemInterface::GetBoolValue() const 132cdf0e10cSrcweir { 133cdf0e10cSrcweir return false; 134cdf0e10cSrcweir } 135cdf0e10cSrcweir 136cdf0e10cSrcweir //============================================================================ 137cdf0e10cSrcweir // virtual 138cdf0e10cSrcweir void SfxEnumItemInterface::SetBoolValue(sal_Bool) 139cdf0e10cSrcweir {} 140cdf0e10cSrcweir 141cdf0e10cSrcweir //============================================================================ 142cdf0e10cSrcweir // 143cdf0e10cSrcweir // class CntEnumItem 144cdf0e10cSrcweir // 145cdf0e10cSrcweir //============================================================================ 146cdf0e10cSrcweir 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 //============================================================================ 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 170cdf0e10cSrcweir sal_uInt16 CntEnumItem::GetEnumValue() const 171cdf0e10cSrcweir { 172cdf0e10cSrcweir return GetValue(); 173cdf0e10cSrcweir } 174cdf0e10cSrcweir 175cdf0e10cSrcweir //============================================================================ 176cdf0e10cSrcweir // virtual 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 //============================================================================ 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 203cdf0e10cSrcweir 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 212cdf0e10cSrcweir 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 221cdf0e10cSrcweir 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 232cdf0e10cSrcweir 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 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 254cdf0e10cSrcweir SfxPoolItem * CntBoolItem::Create(SvStream & rStream, sal_uInt16) const 255cdf0e10cSrcweir { 256cdf0e10cSrcweir return new CntBoolItem(Which(), rStream); 257cdf0e10cSrcweir } 258cdf0e10cSrcweir 259cdf0e10cSrcweir //============================================================================ 260cdf0e10cSrcweir // virtual 261cdf0e10cSrcweir SvStream & CntBoolItem::Store(SvStream & rStream, sal_uInt16) const 262cdf0e10cSrcweir { 263cdf0e10cSrcweir rStream << m_bValue; 264cdf0e10cSrcweir return rStream; 265cdf0e10cSrcweir } 266cdf0e10cSrcweir 267cdf0e10cSrcweir //============================================================================ 268cdf0e10cSrcweir // virtual 269cdf0e10cSrcweir SfxPoolItem * CntBoolItem::Clone(SfxItemPool *) const 270cdf0e10cSrcweir { 271cdf0e10cSrcweir return new CntBoolItem(*this); 272cdf0e10cSrcweir } 273cdf0e10cSrcweir 274cdf0e10cSrcweir //============================================================================ 275cdf0e10cSrcweir // virtual 276cdf0e10cSrcweir sal_uInt16 CntBoolItem::GetValueCount() const 277cdf0e10cSrcweir { 278cdf0e10cSrcweir return 2; 279cdf0e10cSrcweir } 280cdf0e10cSrcweir 281cdf0e10cSrcweir //============================================================================ 282cdf0e10cSrcweir // virtual 283cdf0e10cSrcweir 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