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 31 #include <svl/intitem.hxx> 32 #include <com/sun/star/uno/Any.hxx> 33 #include <tools/bigint.hxx> 34 #include <tools/stream.hxx> 35 #include <svl/metitem.hxx> 36 37 //============================================================================ 38 // 39 // class SfxByteItem 40 // 41 //============================================================================ 42 43 TYPEINIT1_AUTOFACTORY(SfxByteItem, CntByteItem); 44 45 //============================================================================ 46 // virtual 47 SfxPoolItem * SfxByteItem::Create(SvStream & rStream, sal_uInt16) const 48 { 49 short nValue = 0; 50 rStream >> nValue; 51 return new SfxByteItem(Which(), sal_uInt8(nValue)); 52 } 53 54 //============================================================================ 55 // 56 // class SfxInt16Item 57 // 58 //============================================================================ 59 60 DBG_NAME(SfxInt16Item); 61 62 //============================================================================ 63 TYPEINIT1_AUTOFACTORY(SfxInt16Item, SfxPoolItem); 64 65 //============================================================================ 66 SfxInt16Item::SfxInt16Item(sal_uInt16 which, SvStream & rStream): 67 SfxPoolItem(which) 68 { 69 DBG_CTOR(SfxInt16Item, 0); 70 short nTheValue = 0; 71 rStream >> nTheValue; 72 m_nValue = nTheValue; 73 } 74 75 //============================================================================ 76 // virtual 77 int SfxInt16Item::operator ==(const SfxPoolItem & rItem) const 78 { 79 DBG_CHKTHIS(SfxInt16Item, 0); 80 DBG_ASSERT(SfxPoolItem::operator ==(rItem), "unequal type"); 81 return m_nValue == SAL_STATIC_CAST(const SfxInt16Item *, &rItem)-> 82 m_nValue; 83 } 84 85 //============================================================================ 86 // virtual 87 int SfxInt16Item::Compare(const SfxPoolItem & rWith) const 88 { 89 DBG_CHKTHIS(SfxInt16Item, 0); 90 DBG_ASSERT(SfxPoolItem::operator ==(rWith), "unequal type"); 91 return SAL_STATIC_CAST(const SfxInt16Item *, &rWith)->m_nValue 92 < m_nValue ? 93 -1 : 94 SAL_STATIC_CAST(const SfxInt16Item *, &rWith)->m_nValue 95 == m_nValue ? 96 0 : 1; 97 } 98 99 //============================================================================ 100 // virtual 101 SfxItemPresentation SfxInt16Item::GetPresentation(SfxItemPresentation, 102 SfxMapUnit, SfxMapUnit, 103 XubString & rText, 104 const IntlWrapper *) const 105 { 106 DBG_CHKTHIS(SfxInt16Item, 0); 107 rText = UniString::CreateFromInt32(m_nValue); 108 return SFX_ITEM_PRESENTATION_NAMELESS; 109 } 110 111 112 //============================================================================ 113 // virtual 114 sal_Bool SfxInt16Item::QueryValue(com::sun::star::uno::Any& rVal, sal_uInt8) const 115 { 116 sal_Int16 nValue = m_nValue; 117 rVal <<= nValue; 118 return sal_True; 119 } 120 121 //============================================================================ 122 // virtual 123 sal_Bool SfxInt16Item::PutValue(const com::sun::star::uno::Any& rVal, sal_uInt8 ) 124 { 125 sal_Int16 nValue = sal_Int16(); 126 if (rVal >>= nValue) 127 { 128 m_nValue = nValue; 129 return sal_True; 130 } 131 132 DBG_ERROR( "SfxInt16Item::PutValue - Wrong type!" ); 133 return sal_False; 134 } 135 136 //============================================================================ 137 // virtual 138 SfxPoolItem * SfxInt16Item::Create(SvStream & rStream, sal_uInt16) const 139 { 140 DBG_CHKTHIS(SfxInt16Item, 0); 141 return new SfxInt16Item(Which(), rStream); 142 } 143 144 //============================================================================ 145 // virtual 146 SvStream & SfxInt16Item::Store(SvStream & rStream, sal_uInt16) const 147 { 148 DBG_CHKTHIS(SfxInt16Item, 0); 149 rStream << short(m_nValue); 150 return rStream; 151 } 152 153 //============================================================================ 154 SfxPoolItem * SfxInt16Item::Clone(SfxItemPool *) const 155 { 156 DBG_CHKTHIS(SfxInt16Item, 0); 157 return new SfxInt16Item(*this); 158 } 159 160 //============================================================================ 161 sal_Int16 SfxInt16Item::GetMin() const 162 { 163 DBG_CHKTHIS(SfxInt16Item, 0); 164 return -32768; 165 } 166 167 //============================================================================ 168 sal_Int16 SfxInt16Item::GetMax() const 169 { 170 DBG_CHKTHIS(SfxInt16Item, 0); 171 return 32767; 172 } 173 174 //============================================================================ 175 SfxFieldUnit SfxInt16Item::GetUnit() const 176 { 177 DBG_CHKTHIS(SfxInt16Item, 0); 178 return SFX_FUNIT_NONE; 179 } 180 181 //============================================================================ 182 // 183 // class SfxUInt16Item 184 // 185 //============================================================================ 186 187 TYPEINIT1_AUTOFACTORY(SfxUInt16Item, CntUInt16Item); 188 189 190 //============================================================================ 191 // 192 // class SfxInt32Item 193 // 194 //============================================================================ 195 196 TYPEINIT1_AUTOFACTORY(SfxInt32Item, CntInt32Item); 197 198 199 //============================================================================ 200 // 201 // class SfxUInt32Item 202 // 203 //============================================================================ 204 205 TYPEINIT1_AUTOFACTORY(SfxUInt32Item, CntUInt32Item); 206 207 208 //============================================================================ 209 // 210 // class SfxMetricItem 211 // 212 //============================================================================ 213 214 DBG_NAME(SfxMetricItem); 215 216 //============================================================================ 217 TYPEINIT1_AUTOFACTORY(SfxMetricItem, SfxInt32Item); 218 219 //============================================================================ 220 SfxMetricItem::SfxMetricItem(sal_uInt16 which, sal_uInt32 nValue): 221 SfxInt32Item(which, nValue) 222 { 223 DBG_CTOR(SfxMetricItem, 0); 224 } 225 226 //============================================================================ 227 SfxMetricItem::SfxMetricItem(sal_uInt16 which, SvStream & rStream): 228 SfxInt32Item(which, rStream) 229 { 230 DBG_CTOR(SfxMetricItem, 0); 231 } 232 233 //============================================================================ 234 SfxMetricItem::SfxMetricItem(const SfxMetricItem & rItem): 235 SfxInt32Item(rItem) 236 { 237 DBG_CTOR(SfxMetricItem, 0); 238 } 239 240 //============================================================================ 241 // virtual 242 int SfxMetricItem::ScaleMetrics(long nMult, long nDiv) 243 { 244 BigInt aTheValue(GetValue()); 245 aTheValue *= nMult; 246 aTheValue += nDiv / 2; 247 aTheValue /= nDiv; 248 SetValue(aTheValue); 249 return 1; 250 } 251 252 //============================================================================ 253 // virtual 254 int SfxMetricItem::HasMetrics() const 255 { 256 return 1; 257 } 258 259