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/cintitem.hxx> 33 34 //============================================================================ 35 // 36 // class CntByteItem 37 // 38 //============================================================================ 39 40 DBG_NAME(CntByteItem) 41 42 //============================================================================ 43 TYPEINIT1_AUTOFACTORY(CntByteItem, SfxPoolItem); 44 45 //============================================================================ 46 CntByteItem::CntByteItem(sal_uInt16 which, SvStream & rStream): 47 SfxPoolItem(which) 48 { 49 DBG_CTOR(CntByteItem, 0); 50 rStream >> m_nValue; 51 } 52 53 //============================================================================ 54 // virtual 55 int CntByteItem::operator ==(const SfxPoolItem & rItem) const 56 { 57 DBG_CHKTHIS(CntByteItem, 0); 58 DBG_ASSERT(rItem.ISA(CntByteItem), 59 "CntByteItem::operator ==(): Bad type"); 60 return m_nValue == SAL_STATIC_CAST(const CntByteItem *, &rItem)->m_nValue; 61 } 62 63 //============================================================================ 64 // virtual 65 int CntByteItem::Compare(const SfxPoolItem & rWith) const 66 { 67 DBG_CHKTHIS(CntByteItem, 0); 68 DBG_ASSERT(rWith.ISA(CntByteItem), "CntByteItem::Compare(): Bad type"); 69 return SAL_STATIC_CAST(const CntByteItem *, &rWith)->m_nValue < m_nValue ? 70 -1 : 71 SAL_STATIC_CAST(const CntByteItem *, &rWith)->m_nValue 72 == m_nValue ? 73 0 : 1; 74 } 75 76 //============================================================================ 77 // virtual 78 SfxItemPresentation CntByteItem::GetPresentation(SfxItemPresentation, 79 SfxMapUnit, SfxMapUnit, 80 XubString & rText, 81 const IntlWrapper *) const 82 { 83 DBG_CHKTHIS(CntByteItem, 0); 84 rText = XubString::CreateFromInt32(m_nValue); 85 return SFX_ITEM_PRESENTATION_NAMELESS; 86 } 87 88 //============================================================================ 89 // virtual 90 sal_Bool CntByteItem::QueryValue(com::sun::star::uno::Any& rVal,sal_uInt8) const 91 { 92 sal_Int8 nValue = m_nValue; 93 rVal <<= nValue; 94 return sal_True; 95 } 96 97 //============================================================================ 98 // virtual 99 sal_Bool CntByteItem::PutValue(const com::sun::star::uno::Any& rVal,sal_uInt8) 100 { 101 sal_Int8 nValue = sal_Int8(); 102 if (rVal >>= nValue) 103 { 104 m_nValue = nValue; 105 return sal_True; 106 } 107 108 DBG_ERROR( "CntByteItem::PutValue - Wrong type!" ); 109 return sal_False; 110 } 111 112 //============================================================================ 113 // virtual 114 SfxPoolItem * CntByteItem::Create(SvStream & rStream, sal_uInt16) const 115 { 116 DBG_CHKTHIS(CntByteItem, 0); 117 short nTheValue = 0; 118 rStream >> nTheValue; 119 return new CntByteItem(Which(), sal_uInt8(nTheValue)); 120 } 121 122 //============================================================================ 123 // virtual 124 SvStream & CntByteItem::Store(SvStream & rStream, sal_uInt16) const 125 { 126 DBG_CHKTHIS(CntByteItem, 0); 127 rStream << short(m_nValue); 128 return rStream; 129 } 130 131 //============================================================================ 132 // virtual 133 SfxPoolItem * CntByteItem::Clone(SfxItemPool *) const 134 { 135 DBG_CHKTHIS(CntByteItem, 0); 136 return new CntByteItem(*this); 137 } 138 139 //============================================================================ 140 // virtual 141 sal_uInt8 CntByteItem::GetMin() const 142 { 143 DBG_CHKTHIS(CntByteItem, 0); 144 return 0; 145 } 146 147 //============================================================================ 148 // virtual 149 sal_uInt8 CntByteItem::GetMax() const 150 { 151 DBG_CHKTHIS(CntByteItem, 0); 152 return 255; 153 } 154 155 //============================================================================ 156 // virtual 157 SfxFieldUnit CntByteItem::GetUnit() const 158 { 159 DBG_CHKTHIS(CntByteItem, 0); 160 return SFX_FUNIT_NONE; 161 } 162 163 //============================================================================ 164 // 165 // class CntUInt16Item 166 // 167 //============================================================================ 168 169 DBG_NAME(CntUInt16Item); 170 171 //============================================================================ 172 TYPEINIT1_AUTOFACTORY(CntUInt16Item, SfxPoolItem); 173 174 //============================================================================ 175 CntUInt16Item::CntUInt16Item(sal_uInt16 which, SvStream & rStream) : 176 SfxPoolItem(which) 177 { 178 DBG_CTOR(CntUInt16Item, 0); 179 sal_uInt16 nTheValue = 0; 180 rStream >> nTheValue; 181 m_nValue = nTheValue; 182 } 183 184 //============================================================================ 185 // virtual 186 int CntUInt16Item::operator ==(const SfxPoolItem & rItem) const 187 { 188 DBG_CHKTHIS(CntUInt16Item, 0); 189 DBG_ASSERT(rItem.ISA(CntUInt16Item), 190 "CntUInt16Item::operator ==(): Bad type"); 191 return m_nValue == SAL_STATIC_CAST(const CntUInt16Item *, &rItem)-> 192 m_nValue; 193 } 194 195 //============================================================================ 196 // virtual 197 int CntUInt16Item::Compare(const SfxPoolItem & rWith) const 198 { 199 DBG_CHKTHIS(CntUInt16Item, 0); 200 DBG_ASSERT(rWith.ISA(CntUInt16Item), 201 "CntUInt16Item::Compare(): Bad type"); 202 return SAL_STATIC_CAST(const CntUInt16Item *, &rWith)->m_nValue 203 < m_nValue ? 204 -1 : 205 SAL_STATIC_CAST(const CntUInt16Item *, &rWith)->m_nValue 206 == m_nValue ? 207 0 : 1; 208 } 209 210 //============================================================================ 211 // virtual 212 SfxItemPresentation CntUInt16Item::GetPresentation(SfxItemPresentation, 213 SfxMapUnit, SfxMapUnit, 214 XubString & rText, 215 const IntlWrapper *) 216 const 217 { 218 DBG_CHKTHIS(CntUInt16Item, 0); 219 rText = XubString::CreateFromInt32(m_nValue); 220 return SFX_ITEM_PRESENTATION_NAMELESS; 221 } 222 223 //============================================================================ 224 // virtual 225 sal_Bool CntUInt16Item::QueryValue(com::sun::star::uno::Any& rVal,sal_uInt8) const 226 { 227 sal_Int32 nValue = m_nValue; 228 rVal <<= nValue; 229 return sal_True; 230 } 231 232 //============================================================================ 233 // virtual 234 sal_Bool CntUInt16Item::PutValue(const com::sun::star::uno::Any& rVal,sal_uInt8) 235 { 236 sal_Int32 nValue = 0; 237 if (rVal >>= nValue) 238 { 239 DBG_ASSERT( nValue <= USHRT_MAX, "Overflow in UInt16 value!"); 240 m_nValue = (sal_uInt16)nValue; 241 return sal_True; 242 } 243 244 DBG_ERROR( "CntUInt16Item::PutValue - Wrong type!" ); 245 return sal_False; 246 } 247 248 //============================================================================ 249 // virtual 250 SfxPoolItem * CntUInt16Item::Create(SvStream & rStream, sal_uInt16) const 251 { 252 DBG_CHKTHIS(CntUInt16Item, 0); 253 return new CntUInt16Item(Which(), rStream); 254 } 255 256 //============================================================================ 257 // virtual 258 SvStream & CntUInt16Item::Store(SvStream &rStream, sal_uInt16) const 259 { 260 DBG_CHKTHIS(CntUInt16Item, 0); 261 rStream << sal_uInt16(m_nValue); 262 return rStream; 263 } 264 265 //============================================================================ 266 // virtual 267 SfxPoolItem * CntUInt16Item::Clone(SfxItemPool *) const 268 { 269 DBG_CHKTHIS(CntUInt16Item, 0); 270 return new CntUInt16Item(*this); 271 } 272 273 //============================================================================ 274 // virtual 275 sal_uInt16 CntUInt16Item::GetMin() const 276 { 277 DBG_CHKTHIS(CntUInt16Item, 0); 278 return 0; 279 } 280 281 //============================================================================ 282 // virtual 283 sal_uInt16 CntUInt16Item::GetMax() const 284 { 285 DBG_CHKTHIS(CntUInt16Item, 0); 286 return 65535; 287 } 288 289 //============================================================================ 290 // virtual 291 SfxFieldUnit CntUInt16Item::GetUnit() const 292 { 293 DBG_CHKTHIS(CntUInt16Item, 0); 294 return SFX_FUNIT_NONE; 295 } 296 297 //============================================================================ 298 // 299 // class CntInt32Item 300 // 301 //============================================================================ 302 303 DBG_NAME(CntInt32Item); 304 305 //============================================================================ 306 TYPEINIT1_AUTOFACTORY(CntInt32Item, SfxPoolItem); 307 308 //============================================================================ 309 CntInt32Item::CntInt32Item(sal_uInt16 which, SvStream & rStream) : 310 SfxPoolItem(which) 311 { 312 DBG_CTOR(CntInt32Item, 0); 313 long nTheValue = 0; 314 rStream >> nTheValue; 315 m_nValue = nTheValue; 316 } 317 318 //============================================================================ 319 // virtual 320 int CntInt32Item::operator ==(const SfxPoolItem & rItem) const 321 { 322 DBG_CHKTHIS(CntInt32Item, 0); 323 DBG_ASSERT(rItem.ISA(CntInt32Item), 324 "CntInt32Item::operator ==(): Bad type"); 325 return m_nValue == SAL_STATIC_CAST(const CntInt32Item *, &rItem)-> 326 m_nValue; 327 } 328 329 //============================================================================ 330 // virtual 331 int CntInt32Item::Compare(const SfxPoolItem & rWith) const 332 { 333 DBG_CHKTHIS(CntInt32Item, 0); 334 DBG_ASSERT(rWith.ISA(CntInt32Item), "CntInt32Item::Compare(): Bad type"); 335 return SAL_STATIC_CAST(const CntInt32Item *, &rWith)->m_nValue 336 < m_nValue ? 337 -1 : 338 SAL_STATIC_CAST(const CntInt32Item *, &rWith)->m_nValue 339 == m_nValue ? 340 0 : 1; 341 } 342 343 //============================================================================ 344 // virtual 345 SfxItemPresentation CntInt32Item::GetPresentation(SfxItemPresentation, 346 SfxMapUnit, SfxMapUnit, 347 XubString & rText, 348 const IntlWrapper *) const 349 { 350 DBG_CHKTHIS(CntInt32Item, 0); 351 rText = XubString::CreateFromInt32(m_nValue); 352 return SFX_ITEM_PRESENTATION_NAMELESS; 353 } 354 355 //============================================================================ 356 // virtual 357 sal_Bool CntInt32Item::QueryValue(com::sun::star::uno::Any& rVal,sal_uInt8) const 358 { 359 sal_Int32 nValue = m_nValue; 360 rVal <<= nValue; 361 return sal_True; 362 } 363 364 //============================================================================ 365 // virtual 366 sal_Bool CntInt32Item::PutValue(const com::sun::star::uno::Any& rVal,sal_uInt8) 367 { 368 sal_Int32 nValue = 0; 369 if (rVal >>= nValue) 370 { 371 m_nValue = nValue; 372 return sal_True; 373 } 374 375 DBG_ERROR( "CntInt32Item::PutValue - Wrong type!" ); 376 return sal_False; 377 } 378 379 //============================================================================ 380 // virtual 381 SfxPoolItem * CntInt32Item::Create(SvStream & rStream, sal_uInt16) const 382 { 383 DBG_CHKTHIS(CntInt32Item, 0); 384 return new CntInt32Item(Which(), rStream); 385 } 386 387 //============================================================================ 388 // virtual 389 SvStream & CntInt32Item::Store(SvStream &rStream, sal_uInt16) const 390 { 391 DBG_CHKTHIS(CntInt32Item, 0); 392 rStream << long(m_nValue); 393 return rStream; 394 } 395 396 //============================================================================ 397 // virtual 398 SfxPoolItem * CntInt32Item::Clone(SfxItemPool *) const 399 { 400 DBG_CHKTHIS(CntInt32Item, 0); 401 return new CntInt32Item(*this); 402 } 403 404 //============================================================================ 405 // virtual 406 sal_Int32 CntInt32Item::GetMin() const 407 { 408 DBG_CHKTHIS(CntInt32Item, 0); 409 return sal_Int32(0x80000000); 410 } 411 412 //============================================================================ 413 // virtual 414 sal_Int32 CntInt32Item::GetMax() const 415 { 416 DBG_CHKTHIS(CntInt32Item, 0); 417 return 0x7FFFFFFF; 418 } 419 420 //============================================================================ 421 // virtual 422 SfxFieldUnit CntInt32Item::GetUnit() const 423 { 424 DBG_CHKTHIS(CntInt32Item, 0); 425 return SFX_FUNIT_NONE; 426 } 427 428 //============================================================================ 429 // 430 // class CntUInt32Item 431 // 432 //============================================================================ 433 434 DBG_NAME(CntUInt32Item); 435 436 //============================================================================ 437 TYPEINIT1_AUTOFACTORY(CntUInt32Item, SfxPoolItem); 438 439 //============================================================================ 440 CntUInt32Item::CntUInt32Item(sal_uInt16 which, SvStream & rStream) : 441 SfxPoolItem(which) 442 { 443 DBG_CTOR(CntUInt32Item, 0); 444 sal_uInt32 nTheValue = 0; 445 rStream >> nTheValue; 446 m_nValue = nTheValue; 447 } 448 449 //============================================================================ 450 // virtual 451 int CntUInt32Item::operator ==(const SfxPoolItem & rItem) const 452 { 453 DBG_CHKTHIS(CntUInt32Item, 0); 454 DBG_ASSERT(rItem.ISA(CntUInt32Item), 455 "CntUInt32Item::operator ==(): Bad type"); 456 return m_nValue == SAL_STATIC_CAST(const CntUInt32Item *, &rItem)-> 457 m_nValue; 458 } 459 460 //============================================================================ 461 // virtual 462 int CntUInt32Item::Compare(const SfxPoolItem & rWith) const 463 { 464 DBG_CHKTHIS(CntUInt32Item, 0); 465 DBG_ASSERT(rWith.ISA(CntUInt32Item), 466 "CntUInt32Item::operator ==(): Bad type"); 467 return SAL_STATIC_CAST(const CntUInt32Item *, &rWith)->m_nValue 468 < m_nValue ? 469 -1 : 470 SAL_STATIC_CAST(const CntUInt32Item *, &rWith)->m_nValue 471 == m_nValue ? 472 0 : 1; 473 } 474 475 //============================================================================ 476 // virtual 477 SfxItemPresentation CntUInt32Item::GetPresentation(SfxItemPresentation, 478 SfxMapUnit, SfxMapUnit, 479 XubString & rText, 480 const IntlWrapper *) 481 const 482 { 483 DBG_CHKTHIS(CntUInt32Item, 0); 484 rText = XubString::CreateFromInt64(m_nValue); 485 return SFX_ITEM_PRESENTATION_NAMELESS; 486 } 487 488 //============================================================================ 489 // virtual 490 sal_Bool CntUInt32Item::QueryValue(com::sun::star::uno::Any& rVal,sal_uInt8) const 491 { 492 sal_Int32 nValue = m_nValue; 493 DBG_ASSERT( nValue>=0, "Overflow in UInt32 value!"); 494 rVal <<= nValue; 495 return sal_True; 496 } 497 498 //============================================================================ 499 // virtual 500 sal_Bool CntUInt32Item::PutValue(const com::sun::star::uno::Any& rVal,sal_uInt8) 501 { 502 sal_Int32 nValue = 0; 503 if (rVal >>= nValue) 504 { 505 DBG_ASSERT( nValue>=0, "Overflow in UInt32 value!"); 506 m_nValue = nValue; 507 return sal_True; 508 } 509 510 DBG_ERROR( "CntUInt32Item::PutValue - Wrong type!" ); 511 return sal_False; 512 } 513 514 //============================================================================ 515 // virtual 516 SfxPoolItem * CntUInt32Item::Create(SvStream & rStream, sal_uInt16) const 517 { 518 DBG_CHKTHIS(CntUInt32Item, 0); 519 return new CntUInt32Item(Which(), rStream); 520 } 521 522 //============================================================================ 523 // virtual 524 SvStream & CntUInt32Item::Store(SvStream &rStream, sal_uInt16) const 525 { 526 DBG_CHKTHIS(CntUInt32Item, 0); 527 rStream << static_cast<sal_uInt32>(m_nValue); 528 return rStream; 529 } 530 531 //============================================================================ 532 // virtual 533 SfxPoolItem * CntUInt32Item::Clone(SfxItemPool *) const 534 { 535 DBG_CHKTHIS(CntUInt32Item, 0); 536 return new CntUInt32Item(*this); 537 } 538 539 //============================================================================ 540 // virtual 541 sal_uInt32 CntUInt32Item::GetMin() const 542 { 543 DBG_CHKTHIS(CntUInt32Item, 0); 544 return 0; 545 } 546 547 //============================================================================ 548 // virtual 549 sal_uInt32 CntUInt32Item::GetMax() const 550 { 551 DBG_CHKTHIS(CntUInt32Item, 0); 552 return 0xFFFFFFFF; 553 } 554 555 //============================================================================ 556 // virtual 557 SfxFieldUnit CntUInt32Item::GetUnit() const 558 { 559 DBG_CHKTHIS(CntUInt32Item, 0); 560 return SFX_FUNIT_NONE; 561 } 562 563