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_editeng.hxx" 26 #include <vcl/metaact.hxx> 27 #include <svl/zforlist.hxx> 28 #include <tools/urlobj.hxx> 29 30 #define _SVX_FLDITEM_CXX 31 #include <unotools/localfilehelper.hxx> 32 33 #include <editeng/flditem.hxx> 34 35 #include <editeng/measfld.hxx> 36 37 // #90477# 38 #include <tools/tenccvt.hxx> 39 40 #define FRAME_MARKER (sal_uInt32)0x21981357 41 #define CHARSET_MARKER (FRAME_MARKER+1) 42 43 // ----------------------------------------------------------------------- 44 45 TYPEINIT1( SvxFieldItem, SfxPoolItem ); 46 47 SV_IMPL_PERSIST1( SvxFieldData, SvPersistBase ); 48 49 // ----------------------------------------------------------------------- 50 51 SvxFieldData::SvxFieldData() 52 { 53 } 54 55 // ----------------------------------------------------------------------- 56 57 SvxFieldData::~SvxFieldData() 58 { 59 } 60 61 // ----------------------------------------------------------------------- 62 63 SvxFieldData* SvxFieldData::Clone() const 64 { 65 return new SvxFieldData; 66 } 67 68 // ----------------------------------------------------------------------- 69 70 int SvxFieldData::operator==( const SvxFieldData& rFld ) const 71 { 72 DBG_ASSERT( Type() == rFld.Type(), "==: Verschiedene Typen" ); 73 (void)rFld; 74 return sal_True; // Basicklasse immer gleich. 75 } 76 77 // ----------------------------------------------------------------------- 78 79 void SvxFieldData::Load( SvPersistStream & /*rStm*/ ) 80 { 81 } 82 83 // ----------------------------------------------------------------------- 84 85 void SvxFieldData::Save( SvPersistStream & /*rStm*/ ) 86 { 87 } 88 89 90 MetaAction* SvxFieldData::createBeginComment() const 91 { 92 return new MetaCommentAction( "FIELD_SEQ_BEGIN" ); 93 } 94 95 MetaAction* SvxFieldData::createEndComment() const 96 { 97 return new MetaCommentAction( "FIELD_SEQ_END" ); 98 } 99 100 // ----------------------------------------------------------------------- 101 102 SvxFieldItem::SvxFieldItem( SvxFieldData* pFld, const sal_uInt16 nId ) : 103 SfxPoolItem( nId ) 104 { 105 pField = pFld; // gehoert direkt dem Item 106 } 107 108 // ----------------------------------------------------------------------- 109 110 SvxFieldItem::SvxFieldItem( const SvxFieldData& rField, const sal_uInt16 nId ) : 111 SfxPoolItem( nId ) 112 { 113 pField = rField.Clone(); 114 } 115 116 // ----------------------------------------------------------------------- 117 118 SvxFieldItem::SvxFieldItem( const SvxFieldItem& rItem ) : 119 SfxPoolItem ( rItem ) 120 { 121 pField = rItem.GetField() ? rItem.GetField()->Clone() : 0; 122 } 123 124 // ----------------------------------------------------------------------- 125 126 SvxFieldItem::~SvxFieldItem() 127 { 128 delete pField; 129 } 130 131 // ----------------------------------------------------------------------- 132 133 SfxPoolItem* SvxFieldItem::Clone( SfxItemPool* ) const 134 { 135 return new SvxFieldItem(*this); 136 } 137 138 // ----------------------------------------------------------------------- 139 140 SfxPoolItem* SvxFieldItem::Create( SvStream& rStrm, sal_uInt16 ) const 141 { 142 SvxFieldData* pData = 0; 143 SvPersistStream aPStrm( GetClassManager(), &rStrm ); 144 aPStrm >> pData; 145 146 if( aPStrm.IsEof() ) 147 aPStrm.SetError( SVSTREAM_GENERALERROR ); 148 149 if ( aPStrm.GetError() == ERRCODE_IO_NOFACTORY ) 150 aPStrm.ResetError(); // Eigentlich einen Code, dass nicht alle Attr gelesen wurden... 151 152 return new SvxFieldItem( pData, Which() ); 153 } 154 155 // ----------------------------------------------------------------------- 156 157 SvStream& SvxFieldItem::Store( SvStream& rStrm, sal_uInt16 /*nItemVersion*/ ) const 158 { 159 DBG_ASSERT( pField, "SvxFieldItem::Store: Feld?!" ); 160 SvPersistStream aPStrm( GetClassManager(), &rStrm ); 161 // Das ResetError in der obigen Create-Methode gab es in 3.1 noch nicht, 162 // deshalb duerfen beim 3.x-Export neuere Items nicht gespeichert werden! 163 if ( ( rStrm.GetVersion() <= SOFFICE_FILEFORMAT_31 ) && pField && 164 pField->GetClassId() == 50 /* SdrMeasureField */ ) 165 { 166 // SvxFieldData reicht nicht, weil auch nicht am ClassMgr angemeldet 167 SvxURLField aDummyData; 168 aPStrm << &aDummyData; 169 } 170 else 171 aPStrm << pField; 172 173 return rStrm; 174 } 175 176 // ----------------------------------------------------------------------- 177 178 int SvxFieldItem::operator==( const SfxPoolItem& rItem ) const 179 { 180 DBG_ASSERT( SfxPoolItem::operator==( rItem ), "unequal which or type" ); 181 182 const SvxFieldData* pOtherFld = ((const SvxFieldItem&)rItem).GetField(); 183 if ( !pField && !pOtherFld ) 184 return sal_True; 185 186 if ( ( !pField && pOtherFld ) || ( pField && !pOtherFld ) ) 187 return sal_False; 188 189 return ( ( pField->Type() == pOtherFld->Type() ) 190 && ( *pField == *pOtherFld ) ); 191 } 192 193 // ================================================================= 194 // Es folgen die Ableitungen von SvxFieldData... 195 // ================================================================= 196 197 SV_IMPL_PERSIST1( SvxDateField, SvxFieldData ); 198 199 // ----------------------------------------------------------------------- 200 201 SvxDateField::SvxDateField() 202 { 203 nFixDate = Date().GetDate(); 204 eType = SVXDATETYPE_VAR; 205 eFormat = SVXDATEFORMAT_STDSMALL; 206 } 207 208 // ----------------------------------------------------------------------- 209 210 SvxDateField::SvxDateField( const Date& rDate, SvxDateType eT, SvxDateFormat eF ) 211 { 212 nFixDate = rDate.GetDate(); 213 eType = eT; 214 eFormat = eF; 215 } 216 217 // ----------------------------------------------------------------------- 218 219 SvxFieldData* SvxDateField::Clone() const 220 { 221 return new SvxDateField( *this ); 222 } 223 224 // ----------------------------------------------------------------------- 225 226 int SvxDateField::operator==( const SvxFieldData& rOther ) const 227 { 228 if ( rOther.Type() != Type() ) 229 return sal_False; 230 231 const SvxDateField& rOtherFld = (const SvxDateField&) rOther; 232 return ( ( nFixDate == rOtherFld.nFixDate ) && 233 ( eType == rOtherFld.eType ) && 234 ( eFormat == rOtherFld.eFormat ) ); 235 } 236 237 // ----------------------------------------------------------------------- 238 239 void SvxDateField::Load( SvPersistStream & rStm ) 240 { 241 sal_uInt16 nType, nFormat; 242 243 rStm >> nFixDate; 244 rStm >> nType; 245 rStm >> nFormat; 246 247 eType = (SvxDateType)nType; 248 eFormat= (SvxDateFormat)nFormat; 249 } 250 251 // ----------------------------------------------------------------------- 252 253 void SvxDateField::Save( SvPersistStream & rStm ) 254 { 255 rStm << nFixDate; 256 rStm << (sal_uInt16)eType; 257 rStm << (sal_uInt16)eFormat; 258 } 259 260 // ----------------------------------------------------------------------- 261 262 String SvxDateField::GetFormatted( SvNumberFormatter& rFormatter, LanguageType eLang ) const 263 { 264 Date aDate; // current date 265 if ( eType == SVXDATETYPE_FIX ) 266 aDate.SetDate( nFixDate ); 267 268 return GetFormatted( aDate, eFormat, rFormatter, eLang ); 269 } 270 271 String SvxDateField::GetFormatted( Date& aDate, SvxDateFormat eFormat, SvNumberFormatter& rFormatter, LanguageType eLang ) 272 { 273 if ( eFormat == SVXDATEFORMAT_SYSTEM ) 274 { 275 DBG_ERROR( "SVXDATEFORMAT_SYSTEM nicht implementiert!" ); 276 eFormat = SVXDATEFORMAT_STDSMALL; 277 } 278 else if ( eFormat == SVXDATEFORMAT_APPDEFAULT ) 279 { 280 DBG_ERROR( "SVXDATEFORMAT_APPDEFAULT: Woher nehmen?" ); 281 eFormat = SVXDATEFORMAT_STDSMALL; 282 } 283 284 sal_uLong nFormatKey; 285 286 switch( eFormat ) 287 { 288 case SVXDATEFORMAT_STDSMALL: 289 // short 290 nFormatKey = rFormatter.GetFormatIndex( NF_DATE_SYSTEM_SHORT, eLang ); 291 break; 292 case SVXDATEFORMAT_STDBIG: 293 // long 294 nFormatKey = rFormatter.GetFormatIndex( NF_DATE_SYSTEM_LONG, eLang ); 295 break; 296 case SVXDATEFORMAT_A: 297 // 13.02.96 298 nFormatKey = rFormatter.GetFormatIndex( NF_DATE_SYS_DDMMYY, eLang ); 299 break; 300 case SVXDATEFORMAT_B: 301 // 13.02.1996 302 nFormatKey = rFormatter.GetFormatIndex( NF_DATE_SYS_DDMMYYYY, eLang ); 303 break; 304 case SVXDATEFORMAT_C: 305 // 13. Feb 1996 306 nFormatKey = rFormatter.GetFormatIndex( NF_DATE_SYS_DMMMYYYY, eLang ); 307 break; 308 case SVXDATEFORMAT_D: 309 // 13. Februar 1996 310 nFormatKey = rFormatter.GetFormatIndex( NF_DATE_SYS_DMMMMYYYY, eLang ); 311 break; 312 case SVXDATEFORMAT_E: 313 // Die, 13. Februar 1996 314 nFormatKey = rFormatter.GetFormatIndex( NF_DATE_SYS_NNDMMMMYYYY, eLang ); 315 break; 316 case SVXDATEFORMAT_F: 317 // Dienstag, 13. Februar 1996 318 nFormatKey = rFormatter.GetFormatIndex( NF_DATE_SYS_NNNNDMMMMYYYY, eLang ); 319 break; 320 default: 321 nFormatKey = rFormatter.GetStandardFormat( NUMBERFORMAT_DATE, eLang ); 322 } 323 324 double fDiffDate = aDate - *(rFormatter.GetNullDate()); 325 String aStr; 326 Color* pColor = NULL; 327 rFormatter.GetOutputString( fDiffDate, nFormatKey, aStr, &pColor ); 328 return aStr; 329 } 330 331 MetaAction* SvxDateField::createBeginComment() const 332 { 333 return new MetaCommentAction( "FIELD_SEQ_BEGIN" ); 334 } 335 336 SV_IMPL_PERSIST1( SvxURLField, SvxFieldData ); 337 338 // ----------------------------------------------------------------------- 339 340 SvxURLField::SvxURLField() 341 { 342 eFormat = SVXURLFORMAT_URL; 343 } 344 345 // ----------------------------------------------------------------------- 346 347 SvxURLField::SvxURLField( const XubString& rURL, const XubString& rRepres, SvxURLFormat eFmt ) 348 : aURL( rURL ), aRepresentation( rRepres ) 349 { 350 eFormat = eFmt; 351 } 352 353 // ----------------------------------------------------------------------- 354 355 SvxFieldData* SvxURLField::Clone() const 356 { 357 return new SvxURLField( *this ); 358 } 359 360 // ----------------------------------------------------------------------- 361 362 int SvxURLField::operator==( const SvxFieldData& rOther ) const 363 { 364 if ( rOther.Type() != Type() ) 365 return sal_False; 366 367 const SvxURLField& rOtherFld = (const SvxURLField&) rOther; 368 return ( ( eFormat == rOtherFld.eFormat ) && 369 ( aURL == rOtherFld.aURL ) && 370 ( aRepresentation == rOtherFld.aRepresentation ) && 371 ( aTargetFrame == rOtherFld.aTargetFrame ) ); 372 } 373 374 // ----------------------------------------------------------------------- 375 376 static void write_unicode( SvPersistStream & rStm, const String& rString ) 377 { 378 sal_uInt16 nL = rString.Len(); 379 rStm << nL; 380 rStm.Write( rString.GetBuffer(), nL*sizeof(sal_Unicode) ); 381 } 382 383 static void read_unicode( SvPersistStream & rStm, String& rString ) 384 { 385 sal_uInt16 nL = 0; 386 rStm >> nL; 387 if ( nL ) 388 { 389 rString.AllocBuffer( nL ); 390 rStm.Read( rString.GetBufferAccess(), nL*sizeof(sal_Unicode) ); 391 rString.ReleaseBufferAccess( nL ); 392 } 393 } 394 395 void SvxURLField::Load( SvPersistStream & rStm ) 396 { 397 sal_uInt16 nFormat = 0; 398 399 rStm >> nFormat; 400 eFormat= (SvxURLFormat)nFormat; 401 402 read_unicode( rStm, aURL ); 403 read_unicode( rStm, aRepresentation ); 404 read_unicode( rStm, aTargetFrame ); 405 } 406 407 // ----------------------------------------------------------------------- 408 409 void SvxURLField::Save( SvPersistStream & rStm ) 410 { 411 rStm << (sal_uInt16)eFormat; 412 413 write_unicode( rStm, aURL ); 414 write_unicode( rStm, aRepresentation ); 415 write_unicode( rStm, aTargetFrame ); 416 } 417 418 MetaAction* SvxURLField::createBeginComment() const 419 { 420 // #i46618# Adding target URL to metafile comment 421 return new MetaCommentAction( "FIELD_SEQ_BEGIN", 422 0, 423 reinterpret_cast<const sal_uInt8*>(aURL.GetBuffer()), 424 2*aURL.Len() ); 425 } 426 427 // ================================================================= 428 // Die Felder, die aus Calc ausgebaut wurden: 429 // ================================================================= 430 431 SV_IMPL_PERSIST1( SvxPageField, SvxFieldData ); 432 433 SvxFieldData* __EXPORT SvxPageField::Clone() const 434 { 435 return new SvxPageField; // leer 436 } 437 438 int __EXPORT SvxPageField::operator==( const SvxFieldData& rCmp ) const 439 { 440 return ( rCmp.Type() == TYPE(SvxPageField) ); 441 } 442 443 void __EXPORT SvxPageField::Load( SvPersistStream & /*rStm*/ ) 444 { 445 } 446 447 void __EXPORT SvxPageField::Save( SvPersistStream & /*rStm*/ ) 448 { 449 } 450 451 MetaAction* SvxPageField::createBeginComment() const 452 { 453 return new MetaCommentAction( "FIELD_SEQ_BEGIN;PageField" ); 454 } 455 456 457 SV_IMPL_PERSIST1( SvxPagesField, SvxFieldData ); 458 459 SvxFieldData* __EXPORT SvxPagesField::Clone() const 460 { 461 return new SvxPagesField; // leer 462 } 463 464 int __EXPORT SvxPagesField::operator==( const SvxFieldData& rCmp ) const 465 { 466 return ( rCmp.Type() == TYPE(SvxPagesField) ); 467 } 468 469 void __EXPORT SvxPagesField::Load( SvPersistStream & /*rStm*/ ) 470 { 471 } 472 473 void __EXPORT SvxPagesField::Save( SvPersistStream & /*rStm*/ ) 474 { 475 } 476 477 SV_IMPL_PERSIST1( SvxTimeField, SvxFieldData ); 478 479 SvxFieldData* __EXPORT SvxTimeField::Clone() const 480 { 481 return new SvxTimeField; // leer 482 } 483 484 int __EXPORT SvxTimeField::operator==( const SvxFieldData& rCmp ) const 485 { 486 return ( rCmp.Type() == TYPE(SvxTimeField) ); 487 } 488 489 void __EXPORT SvxTimeField::Load( SvPersistStream & /*rStm*/ ) 490 { 491 } 492 493 void __EXPORT SvxTimeField::Save( SvPersistStream & /*rStm*/ ) 494 { 495 } 496 497 MetaAction* SvxTimeField::createBeginComment() const 498 { 499 return new MetaCommentAction( "FIELD_SEQ_BEGIN" ); 500 } 501 502 SV_IMPL_PERSIST1( SvxFileField, SvxFieldData ); 503 504 SvxFieldData* __EXPORT SvxFileField::Clone() const 505 { 506 return new SvxFileField; // leer 507 } 508 509 int __EXPORT SvxFileField::operator==( const SvxFieldData& rCmp ) const 510 { 511 return ( rCmp.Type() == TYPE(SvxFileField) ); 512 } 513 514 void __EXPORT SvxFileField::Load( SvPersistStream & /*rStm*/ ) 515 { 516 } 517 518 void __EXPORT SvxFileField::Save( SvPersistStream & /*rStm*/ ) 519 { 520 } 521 522 SV_IMPL_PERSIST1( SvxTableField, SvxFieldData ); 523 524 SvxFieldData* __EXPORT SvxTableField::Clone() const 525 { 526 return new SvxTableField; // leer 527 } 528 529 int __EXPORT SvxTableField::operator==( const SvxFieldData& rCmp ) const 530 { 531 return ( rCmp.Type() == TYPE(SvxTableField) ); 532 } 533 534 void __EXPORT SvxTableField::Load( SvPersistStream & /*rStm*/ ) 535 { 536 } 537 538 void __EXPORT SvxTableField::Save( SvPersistStream & /*rStm*/ ) 539 { 540 } 541 542 //---------------------------------------------------------------------------- 543 // SvxExtTimeField 544 //---------------------------------------------------------------------------- 545 546 SV_IMPL_PERSIST1( SvxExtTimeField, SvxFieldData ); 547 548 //---------------------------------------------------------------------------- 549 550 SvxExtTimeField::SvxExtTimeField() 551 { 552 nFixTime = Time().GetTime(); 553 eType = SVXTIMETYPE_VAR; 554 eFormat = SVXTIMEFORMAT_STANDARD; 555 } 556 557 //---------------------------------------------------------------------------- 558 559 SvxExtTimeField::SvxExtTimeField( const Time& rTime, SvxTimeType eT, SvxTimeFormat eF ) 560 { 561 nFixTime = rTime.GetTime(); 562 eType = eT; 563 eFormat = eF; 564 } 565 566 //---------------------------------------------------------------------------- 567 568 SvxFieldData* SvxExtTimeField::Clone() const 569 { 570 return new SvxExtTimeField( *this ); 571 } 572 573 //---------------------------------------------------------------------------- 574 575 int SvxExtTimeField::operator==( const SvxFieldData& rOther ) const 576 { 577 if ( rOther.Type() != Type() ) 578 return sal_False; 579 580 const SvxExtTimeField& rOtherFld = (const SvxExtTimeField&) rOther; 581 return ( ( nFixTime == rOtherFld.nFixTime ) && 582 ( eType == rOtherFld.eType ) && 583 ( eFormat == rOtherFld.eFormat ) ); 584 } 585 586 //---------------------------------------------------------------------------- 587 588 void SvxExtTimeField::Load( SvPersistStream & rStm ) 589 { 590 sal_uInt16 nType, nFormat; 591 592 rStm >> nFixTime; 593 rStm >> nType; 594 rStm >> nFormat; 595 596 eType = (SvxTimeType) nType; 597 eFormat= (SvxTimeFormat) nFormat; 598 } 599 600 //---------------------------------------------------------------------------- 601 602 void SvxExtTimeField::Save( SvPersistStream & rStm ) 603 { 604 rStm << nFixTime; 605 rStm << (sal_uInt16) eType; 606 rStm << (sal_uInt16) eFormat; 607 } 608 609 //---------------------------------------------------------------------------- 610 611 String SvxExtTimeField::GetFormatted( SvNumberFormatter& rFormatter, LanguageType eLang ) const 612 { 613 Time aTime; // current time 614 if ( eType == SVXTIMETYPE_FIX ) 615 aTime.SetTime( nFixTime ); 616 return GetFormatted( aTime, eFormat, rFormatter, eLang ); 617 } 618 619 String SvxExtTimeField::GetFormatted( Time& aTime, SvxTimeFormat eFormat, SvNumberFormatter& rFormatter, LanguageType eLang ) 620 { 621 switch( eFormat ) 622 { 623 case SVXTIMEFORMAT_SYSTEM : 624 DBG_ERROR( "SVXTIMEFORMAT_SYSTEM: not implemented" ); 625 eFormat = SVXTIMEFORMAT_STANDARD; 626 break; 627 case SVXTIMEFORMAT_APPDEFAULT : 628 DBG_ERROR( "SVXTIMEFORMAT_APPDEFAULT: not implemented" ); 629 eFormat = SVXTIMEFORMAT_STANDARD; 630 break; 631 default: ;//prevent warning 632 } 633 634 sal_uInt32 nFormatKey; 635 636 switch( eFormat ) 637 { 638 case SVXTIMEFORMAT_12_HM: 639 nFormatKey = rFormatter.GetFormatIndex( NF_TIME_HHMMAMPM, eLang ); 640 break; 641 case SVXTIMEFORMAT_12_HMSH: 642 { // no builtin format available, try to insert or reuse 643 String aFormatCode( RTL_CONSTASCII_USTRINGPARAM( "HH:MM:SS.00 AM/PM" ) ); 644 xub_StrLen nCheckPos; 645 short nType; 646 /*sal_Bool bInserted = */rFormatter.PutandConvertEntry( aFormatCode, 647 nCheckPos, nType, nFormatKey, LANGUAGE_ENGLISH_US, eLang ); 648 DBG_ASSERT( nCheckPos == 0, "SVXTIMEFORMAT_12_HMSH: could not insert format code" ); 649 if ( nCheckPos ) 650 nFormatKey = rFormatter.GetFormatIndex( NF_TIME_HH_MMSS00, eLang ); 651 } 652 break; 653 case SVXTIMEFORMAT_24_HM: 654 nFormatKey = rFormatter.GetFormatIndex( NF_TIME_HHMM, eLang ); 655 break; 656 case SVXTIMEFORMAT_24_HMSH: 657 nFormatKey = rFormatter.GetFormatIndex( NF_TIME_HH_MMSS00, eLang ); 658 break; 659 case SVXTIMEFORMAT_12_HMS: 660 nFormatKey = rFormatter.GetFormatIndex( NF_TIME_HHMMSSAMPM, eLang ); 661 break; 662 case SVXTIMEFORMAT_24_HMS: 663 nFormatKey = rFormatter.GetFormatIndex( NF_TIME_HHMMSS, eLang ); 664 break; 665 case SVXTIMEFORMAT_STANDARD: 666 default: 667 nFormatKey = rFormatter.GetStandardFormat( NUMBERFORMAT_TIME, eLang ); 668 } 669 670 double fFracTime = aTime.GetTimeInDays(); 671 String aStr; 672 Color* pColor = NULL; 673 rFormatter.GetOutputString( fFracTime, nFormatKey, aStr, &pColor ); 674 return aStr; 675 } 676 677 MetaAction* SvxExtTimeField::createBeginComment() const 678 { 679 return new MetaCommentAction( "FIELD_SEQ_BEGIN" ); 680 } 681 682 //---------------------------------------------------------------------------- 683 // SvxExtFileField 684 //---------------------------------------------------------------------------- 685 686 SV_IMPL_PERSIST1( SvxExtFileField, SvxFieldData ); 687 688 //---------------------------------------------------------------------------- 689 690 SvxExtFileField::SvxExtFileField() 691 { 692 eType = SVXFILETYPE_VAR; 693 eFormat = SVXFILEFORMAT_FULLPATH; 694 } 695 696 //---------------------------------------------------------------------------- 697 698 SvxExtFileField::SvxExtFileField( const XubString& rStr, SvxFileType eT, SvxFileFormat eF ) 699 { 700 aFile = rStr; 701 eType = eT; 702 eFormat = eF; 703 } 704 705 //---------------------------------------------------------------------------- 706 707 SvxFieldData* SvxExtFileField::Clone() const 708 { 709 return new SvxExtFileField( *this ); 710 } 711 712 //---------------------------------------------------------------------------- 713 714 int SvxExtFileField::operator==( const SvxFieldData& rOther ) const 715 { 716 if ( rOther.Type() != Type() ) 717 return sal_False; 718 719 const SvxExtFileField& rOtherFld = (const SvxExtFileField&) rOther; 720 return ( ( aFile == rOtherFld.aFile ) && 721 ( eType == rOtherFld.eType ) && 722 ( eFormat == rOtherFld.eFormat ) ); 723 } 724 725 //---------------------------------------------------------------------------- 726 727 void SvxExtFileField::Load( SvPersistStream & rStm ) 728 { 729 sal_uInt16 nType, nFormat; 730 731 // UNICODE: rStm >> aFile; 732 rStm.ReadByteString(aFile); 733 734 rStm >> nType; 735 rStm >> nFormat; 736 737 eType = (SvxFileType) nType; 738 eFormat= (SvxFileFormat) nFormat; 739 } 740 741 //---------------------------------------------------------------------------- 742 743 void SvxExtFileField::Save( SvPersistStream & rStm ) 744 { 745 // UNICODE: rStm << aFile; 746 rStm.WriteByteString(aFile); 747 748 rStm << (sal_uInt16) eType; 749 rStm << (sal_uInt16) eFormat; 750 } 751 752 //---------------------------------------------------------------------------- 753 754 XubString SvxExtFileField::GetFormatted() const 755 { 756 XubString aString; 757 758 INetURLObject aURLObj( aFile ); 759 760 if( INET_PROT_NOT_VALID == aURLObj.GetProtocol() ) 761 { 762 // invalid? try to interpret string as system file name 763 String aURLStr; 764 765 ::utl::LocalFileHelper::ConvertPhysicalNameToURL( aFile, aURLStr ); 766 767 aURLObj.SetURL( aURLStr ); 768 } 769 770 // #92009# Be somewhat liberate when trying to 771 // get formatted content out of the FileField 772 if( INET_PROT_NOT_VALID == aURLObj.GetProtocol() ) 773 { 774 // still not valid? Then output as is 775 aString = aFile; 776 } 777 else if( INET_PROT_FILE == aURLObj.GetProtocol() ) 778 { 779 switch( eFormat ) 780 { 781 case SVXFILEFORMAT_FULLPATH: 782 aString = aURLObj.getFSysPath(INetURLObject::FSYS_DETECT); 783 break; 784 785 case SVXFILEFORMAT_PATH: 786 aURLObj.removeSegment(INetURLObject::LAST_SEGMENT, false); 787 // #101742# Leave trailing slash at the pathname 788 aURLObj.setFinalSlash(); 789 aString = aURLObj.getFSysPath(INetURLObject::FSYS_DETECT); 790 break; 791 792 case SVXFILEFORMAT_NAME: 793 aString = aURLObj.getBase(INetURLObject::LAST_SEGMENT,true,INetURLObject::DECODE_UNAMBIGUOUS); 794 break; 795 796 case SVXFILEFORMAT_NAME_EXT: 797 aString = aURLObj.getName(INetURLObject::LAST_SEGMENT,true,INetURLObject::DECODE_UNAMBIGUOUS); 798 break; 799 } 800 } 801 else 802 { 803 switch( eFormat ) 804 { 805 case SVXFILEFORMAT_FULLPATH: 806 aString = aURLObj.GetMainURL( INetURLObject::DECODE_TO_IURI ); 807 break; 808 809 case SVXFILEFORMAT_PATH: 810 aURLObj.removeSegment(INetURLObject::LAST_SEGMENT, false); 811 // #101742# Leave trailing slash at the pathname 812 aURLObj.setFinalSlash(); 813 aString = aURLObj.GetMainURL( INetURLObject::DECODE_TO_IURI ); 814 break; 815 816 case SVXFILEFORMAT_NAME: 817 aString = aURLObj.getBase(); 818 break; 819 820 case SVXFILEFORMAT_NAME_EXT: 821 aString = aURLObj.getName(); 822 break; 823 } 824 } 825 826 return( aString ); 827 } 828 829 //---------------------------------------------------------------------------- 830 // SvxAuthorField 831 //---------------------------------------------------------------------------- 832 833 SV_IMPL_PERSIST1( SvxAuthorField, SvxFieldData ); 834 835 //---------------------------------------------------------------------------- 836 837 SvxAuthorField::SvxAuthorField() 838 { 839 eType = SVXAUTHORTYPE_VAR; 840 eFormat = SVXAUTHORFORMAT_FULLNAME; 841 } 842 843 //---------------------------------------------------------------------------- 844 845 SvxAuthorField::SvxAuthorField( const XubString& rFirstName, 846 const XubString& rLastName, 847 const XubString& rShortName, 848 SvxAuthorType eT, SvxAuthorFormat eF ) 849 { 850 aName = rLastName; 851 aFirstName = rFirstName; 852 aShortName = rShortName; 853 eType = eT; 854 eFormat = eF; 855 } 856 857 //---------------------------------------------------------------------------- 858 859 SvxFieldData* SvxAuthorField::Clone() const 860 { 861 return new SvxAuthorField( *this ); 862 } 863 864 //---------------------------------------------------------------------------- 865 866 int SvxAuthorField::operator==( const SvxFieldData& rOther ) const 867 { 868 if ( rOther.Type() != Type() ) 869 return sal_False; 870 871 const SvxAuthorField& rOtherFld = (const SvxAuthorField&) rOther; 872 return ( ( aName == rOtherFld.aName ) && 873 ( aFirstName == rOtherFld.aFirstName ) && 874 ( aShortName == rOtherFld.aShortName ) && 875 ( eType == rOtherFld.eType ) && 876 ( eFormat == rOtherFld.eFormat ) ); 877 } 878 879 //---------------------------------------------------------------------------- 880 881 void SvxAuthorField::Load( SvPersistStream & rStm ) 882 { 883 sal_uInt16 nType = 0, nFormat = 0; 884 885 read_unicode( rStm, aName ); 886 read_unicode( rStm, aFirstName ); 887 read_unicode( rStm, aShortName ); 888 889 rStm >> nType; 890 rStm >> nFormat; 891 892 eType = (SvxAuthorType) nType; 893 eFormat= (SvxAuthorFormat) nFormat; 894 } 895 896 //---------------------------------------------------------------------------- 897 898 void SvxAuthorField::Save( SvPersistStream & rStm ) 899 { 900 write_unicode( rStm, aName ); 901 write_unicode( rStm, aFirstName ); 902 write_unicode( rStm, aShortName ); 903 904 rStm << (sal_uInt16) eType; 905 rStm << (sal_uInt16) eFormat; 906 } 907 908 //---------------------------------------------------------------------------- 909 910 XubString SvxAuthorField::GetFormatted() const 911 { 912 XubString aString; 913 914 switch( eFormat ) 915 { 916 case SVXAUTHORFORMAT_FULLNAME: 917 aString = aFirstName; 918 aString += sal_Unicode(' '); 919 aString += aName; 920 break; 921 922 case SVXAUTHORFORMAT_NAME: 923 aString = aName; 924 break; 925 926 case SVXAUTHORFORMAT_FIRSTNAME: 927 aString = aFirstName; 928 break; 929 930 case SVXAUTHORFORMAT_SHORTNAME: 931 aString = aShortName; 932 break; 933 } 934 935 return( aString ); 936 } 937 938 static SvClassManager* pClassMgr=0; 939 940 SvClassManager& SvxFieldItem::GetClassManager() 941 { 942 if ( !pClassMgr ) 943 { 944 pClassMgr = new SvClassManager; 945 pClassMgr->SV_CLASS_REGISTER( SvxFieldData ); 946 pClassMgr->SV_CLASS_REGISTER( SvxURLField ); 947 pClassMgr->SV_CLASS_REGISTER( SvxDateField ); 948 pClassMgr->SV_CLASS_REGISTER( SvxPageField ); 949 pClassMgr->SV_CLASS_REGISTER( SvxTimeField ); 950 pClassMgr->SV_CLASS_REGISTER( SvxExtTimeField ); 951 pClassMgr->SV_CLASS_REGISTER( SvxExtFileField ); 952 pClassMgr->SV_CLASS_REGISTER( SvxAuthorField ); 953 } 954 955 return *pClassMgr; 956 } 957 958 /////////////////////////////////////////////////////////////////////// 959 960 SV_IMPL_PERSIST1( SvxHeaderField, SvxFieldData ); 961 962 SvxFieldData* __EXPORT SvxHeaderField::Clone() const 963 { 964 return new SvxHeaderField; // leer 965 } 966 967 int __EXPORT SvxHeaderField::operator==( const SvxFieldData& rCmp ) const 968 { 969 return ( rCmp.Type() == TYPE(SvxHeaderField) ); 970 } 971 972 void __EXPORT SvxHeaderField::Load( SvPersistStream & /*rStm*/ ) 973 { 974 } 975 976 void __EXPORT SvxHeaderField::Save( SvPersistStream & /*rStm*/ ) 977 { 978 } 979 980 /////////////////////////////////////////////////////////////////////// 981 982 SV_IMPL_PERSIST1( SvxFooterField, SvxFieldData ); 983 984 SvxFieldData* __EXPORT SvxFooterField::Clone() const 985 { 986 return new SvxFooterField; // leer 987 } 988 989 int __EXPORT SvxFooterField::operator==( const SvxFieldData& rCmp ) const 990 { 991 return ( rCmp.Type() == TYPE(SvxFooterField) ); 992 } 993 994 void __EXPORT SvxFooterField::Load( SvPersistStream & /*rStm*/ ) 995 { 996 } 997 998 void __EXPORT SvxFooterField::Save( SvPersistStream & /*rStm*/ ) 999 { 1000 } 1001 1002 /////////////////////////////////////////////////////////////////////// 1003 1004 SV_IMPL_PERSIST1( SvxDateTimeField, SvxFieldData ); 1005 1006 SvxFieldData* __EXPORT SvxDateTimeField::Clone() const 1007 { 1008 return new SvxDateTimeField; // leer 1009 } 1010 1011 int __EXPORT SvxDateTimeField::operator==( const SvxFieldData& rCmp ) const 1012 { 1013 return ( rCmp.Type() == TYPE(SvxDateTimeField) ); 1014 } 1015 1016 void __EXPORT SvxDateTimeField::Load( SvPersistStream & /*rStm*/ ) 1017 { 1018 } 1019 1020 void __EXPORT SvxDateTimeField::Save( SvPersistStream & /*rStm*/ ) 1021 { 1022 } 1023 1024 String SvxDateTimeField::GetFormatted( Date& rDate, Time& rTime, int eFormat, SvNumberFormatter& rFormatter, LanguageType eLanguage ) 1025 { 1026 String aRet; 1027 1028 SvxDateFormat eDateFormat = (SvxDateFormat)(eFormat & 0x0f); 1029 1030 if(eDateFormat) 1031 { 1032 aRet = SvxDateField::GetFormatted( rDate, eDateFormat, rFormatter, eLanguage ); 1033 } 1034 1035 SvxTimeFormat eTimeFormat = (SvxTimeFormat)((eFormat >> 4) & 0x0f); 1036 1037 if(eTimeFormat) 1038 { 1039 if(aRet.Len()) 1040 aRet += sal_Unicode(' '); 1041 1042 aRet += SvxExtTimeField::GetFormatted( rTime, eTimeFormat, rFormatter, eLanguage ); 1043 } 1044 1045 return aRet; 1046 } 1047 1048