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