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