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