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_sw.hxx" 26 27 #include <textapi.hxx> 28 29 #include <tools/pstm.hxx> 30 #include <hintids.hxx> 31 #include <com/sun/star/text/XText.hpp> 32 #include <com/sun/star/script/XTypeConverter.hpp> 33 #include <com/sun/star/text/SetVariableType.hpp> 34 #include <com/sun/star/text/XTextFieldsSupplier.hpp> 35 #include <com/sun/star/text/UserDataPart.hpp> 36 #include <com/sun/star/text/ChapterFormat.hpp> 37 #include <com/sun/star/text/XTextField.hpp> 38 #include <com/sun/star/text/PlaceholderType.hpp> 39 #include <com/sun/star/text/TemplateDisplayFormat.hpp> 40 #include <com/sun/star/text/UserFieldFormat.hpp> 41 #include <com/sun/star/text/PageNumberType.hpp> 42 #include <com/sun/star/text/ReferenceFieldPart.hpp> 43 #include <com/sun/star/text/FilenameDisplayFormat.hpp> 44 #include <com/sun/star/text/XDependentTextField.hpp> 45 #include <com/sun/star/text/DocumentStatistic.hpp> 46 #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp> 47 #include <com/sun/star/document/XDocumentProperties.hpp> 48 #include <com/sun/star/util/Date.hpp> 49 #include <com/sun/star/util/Duration.hpp> 50 #include <unotools/localedatawrapper.hxx> 51 #include <editeng/unolingu.hxx> 52 #include <comphelper/processfactory.hxx> 53 #include <comphelper/types.hxx> 54 #include <comphelper/string.hxx> 55 #include <tools/urlobj.hxx> 56 #include <vcl/svapp.hxx> 57 #include <svl/urihelper.hxx> 58 #include <unotools/useroptions.hxx> 59 #include <unotools/syslocale.hxx> 60 #include <svl/zforlist.hxx> 61 62 #include <tools/time.hxx> 63 #include <tools/datetime.hxx> 64 65 #include <com/sun/star/beans/PropertyAttribute.hpp> 66 #include <com/sun/star/util/Date.hpp> 67 #include <com/sun/star/util/DateTime.hpp> 68 #include <com/sun/star/util/Time.hpp> 69 70 #include <tools/shl.hxx> 71 #include <swmodule.hxx> 72 #include <sfx2/app.hxx> 73 #include <sfx2/docfile.hxx> 74 #include <sfx2/doctempl.hxx> 75 #include <fmtfld.hxx> 76 #include <txtfld.hxx> 77 #include <charfmt.hxx> 78 #include <docstat.hxx> 79 #include <pagedesc.hxx> 80 #include <fmtpdsc.hxx> 81 #include <doc.hxx> 82 #include <rootfrm.hxx> // AuthorField 83 #include <pagefrm.hxx> // 84 #include <cntfrm.hxx> // 85 #include <pam.hxx> 86 #include <viewsh.hxx> 87 #include <dbmgr.hxx> 88 #include <shellres.hxx> 89 #include <docufld.hxx> 90 #include <flddat.hxx> 91 #include <docfld.hxx> 92 #include <ndtxt.hxx> 93 #include <expfld.hxx> 94 #include <poolfmt.hxx> 95 #include <docsh.hxx> 96 #include <unofldmid.h> 97 #include <swunohelper.hxx> 98 #include <comcore.hrc> 99 100 #include <editeng/outliner.hxx> 101 #include <editeng/outlobj.hxx> 102 #include <switerator.hxx> 103 104 #define URL_DECODE INetURLObject::DECODE_UNAMBIGUOUS 105 106 using ::rtl::OUString; 107 using namespace ::com::sun::star; 108 using namespace ::com::sun::star::uno; 109 using namespace nsSwDocInfoSubType; 110 111 /*-------------------------------------------------------------------- 112 Beschreibung: SwPageNumberFieldType 113 --------------------------------------------------------------------*/ 114 115 SwPageNumberFieldType::SwPageNumberFieldType() 116 : SwFieldType( RES_PAGENUMBERFLD ), 117 nNumberingType( SVX_NUM_ARABIC ), 118 nNum( 0 ), 119 nMax( USHRT_MAX ), 120 bVirtuell( sal_False ) 121 { 122 } 123 124 String& SwPageNumberFieldType::Expand( sal_uInt32 nFmt, short nOff, 125 const String& rUserStr, String& rRet ) const 126 { 127 sal_uInt32 nTmpFmt = (SVX_NUM_PAGEDESC == nFmt) ? (sal_uInt32)nNumberingType : nFmt; 128 long nTmp = nNum + nOff; 129 130 if( 0 >= nTmp || SVX_NUM_NUMBER_NONE == nTmpFmt || (!bVirtuell && nTmp > nMax) ) 131 rRet = aEmptyStr; 132 else if( SVX_NUM_CHAR_SPECIAL == nTmpFmt ) 133 rRet = rUserStr; 134 else 135 rRet = FormatNumber( (sal_uInt16)nTmp, nTmpFmt ); 136 return rRet; 137 } 138 139 SwFieldType* SwPageNumberFieldType::Copy() const 140 { 141 SwPageNumberFieldType *pTmp = new SwPageNumberFieldType(); 142 143 pTmp->nNum = nNum; 144 pTmp->nMax = nMax; 145 pTmp->nNumberingType = nNumberingType; 146 pTmp->bVirtuell = bVirtuell; 147 148 return pTmp; 149 } 150 151 /*-------------------------------------------------------------------- 152 Beschreibung: Verschiedene Expandierung 153 --------------------------------------------------------------------*/ 154 155 void SwPageNumberFieldType::ChangeExpansion( SwDoc* pDoc, sal_uInt16 nPage, 156 sal_uInt16 nNumPages, sal_Bool bVirt, 157 const sal_Int16* pNumFmt ) 158 { 159 nNum = nPage; 160 nMax = nNumPages; 161 if( pNumFmt ) 162 nNumberingType = *pNumFmt; 163 164 bVirtuell = sal_False; 165 if( bVirt ) 166 { 167 // dann muss das Flag ueberprueft werden, denn das Layout setzt 168 // es NIE zurueck 169 const SfxItemPool &rPool = pDoc->GetAttrPool(); 170 const SwFmtPageDesc *pDesc; 171 sal_uInt32 nMaxItems = rPool.GetItemCount2( RES_PAGEDESC ); 172 for( sal_uInt32 n = 0; n < nMaxItems; ++n ) 173 if( 0 != (pDesc = (SwFmtPageDesc*)rPool.GetItem2( RES_PAGEDESC, n ) ) 174 && pDesc->GetNumOffset() && pDesc->GetDefinedIn() ) 175 { 176 SwCntntNode* pNd = PTR_CAST( SwCntntNode, pDesc->GetDefinedIn() ); 177 if( pNd ) 178 { 179 if ( SwIterator<SwFrm,SwCntntNode>::FirstElement(*pNd) ) 180 bVirtuell = sal_True; 181 } 182 else if( pDesc->GetDefinedIn()->ISA( SwFmt )) 183 { 184 SwAutoFmtGetDocNode aGetHt( &pDoc->GetNodes() ); 185 bVirtuell = !pDesc->GetDefinedIn()->GetInfo( aGetHt ); 186 break; 187 } 188 } 189 } 190 } 191 192 /*-------------------------------------------------------------------- 193 Beschreibung: SwPageNumberField 194 --------------------------------------------------------------------*/ 195 196 SwPageNumberField::SwPageNumberField(SwPageNumberFieldType* pTyp, 197 sal_uInt16 nSub, sal_uInt32 nFmt, short nOff) 198 : SwField(pTyp, nFmt), nSubType(nSub), nOffset(nOff) 199 { 200 } 201 202 String SwPageNumberField::Expand() const 203 { 204 String sRet; 205 SwPageNumberFieldType* pFldType = (SwPageNumberFieldType*)GetTyp(); 206 207 if( PG_NEXT == nSubType && 1 != nOffset ) 208 { 209 if( pFldType->Expand( GetFormat(), 1, sUserStr, sRet ).Len() ) 210 pFldType->Expand( GetFormat(), nOffset, sUserStr, sRet ); 211 } 212 else if( PG_PREV == nSubType && -1 != nOffset ) 213 { 214 if( pFldType->Expand( GetFormat(), -1, sUserStr, sRet ).Len() ) 215 pFldType->Expand( GetFormat(), nOffset, sUserStr, sRet ); 216 } 217 else 218 pFldType->Expand( GetFormat(), nOffset, sUserStr, sRet ); 219 return sRet; 220 } 221 222 SwField* SwPageNumberField::Copy() const 223 { 224 SwPageNumberField *pTmp = 225 new SwPageNumberField((SwPageNumberFieldType*)GetTyp(), nSubType, GetFormat(), nOffset); 226 pTmp->SetLanguage( GetLanguage() ); 227 pTmp->SetUserString( sUserStr ); 228 return pTmp; 229 } 230 231 String SwPageNumberField::GetPar2() const 232 { 233 return String::CreateFromInt32(nOffset); 234 } 235 236 void SwPageNumberField::SetPar2(const String& rStr) 237 { 238 nOffset = (short)rStr.ToInt32(); 239 } 240 241 sal_uInt16 SwPageNumberField::GetSubType() const 242 { 243 return nSubType; 244 } 245 246 sal_Bool SwPageNumberField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const 247 { 248 switch( nWhichId ) 249 { 250 case FIELD_PROP_FORMAT: 251 rAny <<= (sal_Int16)GetFormat(); 252 break; 253 case FIELD_PROP_USHORT1: 254 rAny <<= nOffset; 255 break; 256 case FIELD_PROP_SUBTYPE: 257 { 258 text::PageNumberType eType; 259 eType = text::PageNumberType_CURRENT; 260 if(nSubType == PG_PREV) 261 eType = text::PageNumberType_PREV; 262 else if(nSubType == PG_NEXT) 263 eType = text::PageNumberType_NEXT; 264 rAny.setValue(&eType, ::getCppuType((const text::PageNumberType*)0)); 265 } 266 break; 267 case FIELD_PROP_PAR1: 268 rAny <<= OUString(sUserStr); 269 break; 270 271 default: 272 DBG_ERROR("illegal property"); 273 } 274 return sal_True; 275 } 276 277 sal_Bool SwPageNumberField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId ) 278 { 279 sal_Bool bRet = sal_True; 280 sal_Int16 nSet = 0; 281 switch( nWhichId ) 282 { 283 case FIELD_PROP_FORMAT: 284 rAny >>= nSet; 285 286 // TODO: woher kommen die defines? 287 if(nSet <= SVX_NUM_PAGEDESC ) 288 SetFormat(nSet); 289 else { 290 //exception(wrong_value) 291 ; 292 } 293 break; 294 case FIELD_PROP_USHORT1: 295 rAny >>= nSet; 296 nOffset = nSet; 297 break; 298 case FIELD_PROP_SUBTYPE: 299 switch( SWUnoHelper::GetEnumAsInt32( rAny ) ) 300 { 301 case text::PageNumberType_CURRENT: 302 nSubType = PG_RANDOM; 303 break; 304 case text::PageNumberType_PREV: 305 nSubType = PG_PREV; 306 break; 307 case text::PageNumberType_NEXT: 308 nSubType = PG_NEXT; 309 break; 310 default: 311 bRet = sal_False; 312 } 313 break; 314 case FIELD_PROP_PAR1: 315 ::GetString( rAny, sUserStr ); 316 break; 317 318 default: 319 DBG_ERROR("illegal property"); 320 } 321 return bRet; 322 } 323 /*-------------------------------------------------------------------- 324 Beschreibung: SwAuthorFieldType 325 --------------------------------------------------------------------*/ 326 327 SwAuthorFieldType::SwAuthorFieldType() 328 : SwFieldType( RES_AUTHORFLD ) 329 { 330 } 331 332 String SwAuthorFieldType::Expand(sal_uLong nFmt) const 333 { 334 String sRet; 335 SvtUserOptions& rOpt = SW_MOD()->GetUserOptions(); 336 if((nFmt & 0xff) == AF_NAME) 337 sRet = rOpt.GetFullName(); 338 else 339 sRet = rOpt.GetID(); 340 return sRet; 341 } 342 343 SwFieldType* SwAuthorFieldType::Copy() const 344 { 345 return new SwAuthorFieldType; 346 } 347 348 /*-------------------------------------------------------------------- 349 Beschreibung: SwAuthorField 350 --------------------------------------------------------------------*/ 351 352 SwAuthorField::SwAuthorField(SwAuthorFieldType* pTyp, sal_uInt32 nFmt) 353 : SwField(pTyp, nFmt) 354 { 355 aContent = ((SwAuthorFieldType*)GetTyp())->Expand(GetFormat()); 356 } 357 358 String SwAuthorField::Expand() const 359 { 360 if (!IsFixed()) 361 ((SwAuthorField*)this)->aContent = 362 ((SwAuthorFieldType*)GetTyp())->Expand(GetFormat()); 363 364 return aContent; 365 } 366 367 SwField* SwAuthorField::Copy() const 368 { 369 SwAuthorField *pTmp = new SwAuthorField( (SwAuthorFieldType*)GetTyp(), 370 GetFormat()); 371 pTmp->SetExpansion(aContent); 372 return pTmp; 373 } 374 375 sal_Bool SwAuthorField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const 376 { 377 sal_Bool bVal; 378 switch( nWhichId ) 379 { 380 case FIELD_PROP_BOOL1: 381 bVal = (GetFormat() & 0xff) == AF_NAME; 382 rAny.setValue(&bVal, ::getBooleanCppuType()); 383 break; 384 385 case FIELD_PROP_BOOL2: 386 bVal = IsFixed(); 387 rAny.setValue(&bVal, ::getBooleanCppuType()); 388 break; 389 390 case FIELD_PROP_PAR1: 391 rAny <<= rtl::OUString(GetContent()); 392 break; 393 394 default: 395 DBG_ERROR("illegal property"); 396 } 397 return sal_True; 398 } 399 400 sal_Bool SwAuthorField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId ) 401 { 402 switch( nWhichId ) 403 { 404 case FIELD_PROP_BOOL1: 405 SetFormat( *(sal_Bool*)rAny.getValue() ? AF_NAME : AF_SHORTCUT ); 406 break; 407 408 case FIELD_PROP_BOOL2: 409 if( *(sal_Bool*)rAny.getValue() ) 410 SetFormat( GetFormat() | AF_FIXED); 411 else 412 SetFormat( GetFormat() & ~AF_FIXED); 413 break; 414 415 case FIELD_PROP_PAR1: 416 ::GetString( rAny, aContent ); 417 break; 418 419 default: 420 DBG_ERROR("illegal property"); 421 } 422 return sal_True; 423 } 424 425 /*-------------------------------------------------------------------- 426 Beschreibung: SwFileNameFieldType 427 --------------------------------------------------------------------*/ 428 429 SwFileNameFieldType::SwFileNameFieldType(SwDoc *pDocument) 430 : SwFieldType( RES_FILENAMEFLD ) 431 { 432 pDoc = pDocument; 433 } 434 435 String SwFileNameFieldType::Expand(sal_uLong nFmt) const 436 { 437 String aRet; 438 const SwDocShell* pDShell = pDoc->GetDocShell(); 439 if( pDShell && pDShell->HasName() ) 440 { 441 const INetURLObject& rURLObj = pDShell->GetMedium()->GetURLObject(); 442 switch( nFmt & ~FF_FIXED ) 443 { 444 case FF_PATH: 445 { 446 if( INET_PROT_FILE == rURLObj.GetProtocol() ) 447 { 448 INetURLObject aTemp(rURLObj); 449 aTemp.removeSegment(); 450 // #101947# last slash should belong to the pathname 451 aRet = aTemp.PathToFileName();//GetFull(); 452 } 453 else 454 { 455 aRet = URIHelper::removePassword( 456 rURLObj.GetMainURL( INetURLObject::NO_DECODE ), 457 INetURLObject::WAS_ENCODED, URL_DECODE ); 458 aRet.Erase( aRet.Search( String(rURLObj.GetLastName( 459 URL_DECODE )) ) ); 460 } 461 } 462 break; 463 464 case FF_NAME: 465 aRet = rURLObj.GetLastName( URL_DECODE ); 466 break; 467 468 case FF_NAME_NOEXT: 469 aRet = rURLObj.GetBase(); 470 break; 471 472 default: 473 if( INET_PROT_FILE == rURLObj.GetProtocol() ) 474 aRet = rURLObj.GetFull(); 475 else 476 aRet = URIHelper::removePassword( 477 rURLObj.GetMainURL( INetURLObject::NO_DECODE ), 478 INetURLObject::WAS_ENCODED, URL_DECODE ); 479 } 480 } 481 return aRet; 482 } 483 484 SwFieldType* SwFileNameFieldType::Copy() const 485 { 486 SwFieldType *pTmp = new SwFileNameFieldType(pDoc); 487 return pTmp; 488 } 489 /*-------------------------------------------------------------------- 490 Beschreibung: SwFileNameField 491 --------------------------------------------------------------------*/ 492 493 SwFileNameField::SwFileNameField(SwFileNameFieldType* pTyp, sal_uInt32 nFmt) 494 : SwField(pTyp, nFmt) 495 { 496 aContent = ((SwFileNameFieldType*)GetTyp())->Expand(GetFormat()); 497 } 498 499 String SwFileNameField::Expand() const 500 { 501 if (!IsFixed()) 502 ((SwFileNameField*)this)->aContent = ((SwFileNameFieldType*)GetTyp())->Expand(GetFormat()); 503 504 return aContent; 505 } 506 507 SwField* SwFileNameField::Copy() const 508 { 509 SwFileNameField *pTmp = 510 new SwFileNameField((SwFileNameFieldType*)GetTyp(), GetFormat()); 511 pTmp->SetExpansion(aContent); 512 513 return pTmp; 514 } 515 516 sal_Bool SwFileNameField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const 517 { 518 switch( nWhichId ) 519 { 520 case FIELD_PROP_FORMAT: 521 { 522 sal_Int16 nRet; 523 switch( GetFormat() &(~FF_FIXED) ) 524 { 525 case FF_PATH: 526 nRet = text::FilenameDisplayFormat::PATH; 527 break; 528 case FF_NAME_NOEXT: 529 nRet = text::FilenameDisplayFormat::NAME; 530 break; 531 case FF_NAME: 532 nRet = text::FilenameDisplayFormat::NAME_AND_EXT; 533 break; 534 default: nRet = text::FilenameDisplayFormat::FULL; 535 } 536 rAny <<= nRet; 537 } 538 break; 539 540 case FIELD_PROP_BOOL2: 541 { 542 sal_Bool bVal = IsFixed(); 543 rAny.setValue(&bVal, ::getBooleanCppuType()); 544 } 545 break; 546 547 case FIELD_PROP_PAR3: 548 rAny <<= OUString(GetContent()); 549 break; 550 default: 551 DBG_ERROR("illegal property"); 552 } 553 return sal_True; 554 } 555 556 sal_Bool SwFileNameField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId ) 557 { 558 switch( nWhichId ) 559 { 560 case FIELD_PROP_FORMAT: 561 { 562 //JP 24.10.2001: int32 because in UnoField.cxx a putvalue is 563 // called with a int32 value! But normally we need 564 // here only a int16 565 sal_Int32 nType = 0; 566 rAny >>= nType; 567 sal_Bool bFixed = IsFixed(); 568 switch( nType ) 569 { 570 case text::FilenameDisplayFormat::PATH: 571 nType = FF_PATH; 572 break; 573 case text::FilenameDisplayFormat::NAME: 574 nType = FF_NAME_NOEXT; 575 break; 576 case text::FilenameDisplayFormat::NAME_AND_EXT: 577 nType = FF_NAME; 578 break; 579 default: nType = FF_PATHNAME; 580 } 581 if(bFixed) 582 nType |= FF_FIXED; 583 SetFormat(nType); 584 } 585 break; 586 587 case FIELD_PROP_BOOL2: 588 if( *(sal_Bool*)rAny.getValue() ) 589 SetFormat( GetFormat() | FF_FIXED); 590 else 591 SetFormat( GetFormat() & ~FF_FIXED); 592 break; 593 594 case FIELD_PROP_PAR3: 595 ::GetString( rAny, aContent ); 596 break; 597 598 default: 599 DBG_ERROR("illegal property"); 600 } 601 return sal_True; 602 } 603 /*-------------------------------------------------------------------- 604 Beschreibung: SwTemplNameFieldType 605 --------------------------------------------------------------------*/ 606 607 SwTemplNameFieldType::SwTemplNameFieldType(SwDoc *pDocument) 608 : SwFieldType( RES_TEMPLNAMEFLD ) 609 { 610 pDoc = pDocument; 611 } 612 613 String SwTemplNameFieldType::Expand(sal_uLong nFmt) const 614 { 615 ASSERT( nFmt < FF_END, "Expand: kein guelt. Fmt!" ); 616 617 String aRet; 618 SwDocShell *pDocShell(pDoc->GetDocShell()); 619 DBG_ASSERT(pDocShell, "no SwDocShell"); 620 if (pDocShell) { 621 uno::Reference<document::XDocumentPropertiesSupplier> xDPS( 622 pDocShell->GetModel(), uno::UNO_QUERY_THROW); 623 uno::Reference<document::XDocumentProperties> xDocProps( 624 xDPS->getDocumentProperties()); 625 DBG_ASSERT(xDocProps.is(), "Doc has no DocumentProperties"); 626 627 if( FF_UI_NAME == nFmt ) 628 aRet = xDocProps->getTemplateName(); 629 else if( !xDocProps->getTemplateURL().equalsAscii("") ) 630 { 631 if( FF_UI_RANGE == nFmt ) 632 { 633 // fuers besorgen vom RegionNamen !! 634 SfxDocumentTemplates aFac; 635 aFac.Construct(); 636 String sTmp; 637 aFac.GetLogicNames( xDocProps->getTemplateURL(), aRet, sTmp ); 638 } 639 else 640 { 641 INetURLObject aPathName( xDocProps->getTemplateURL() ); 642 if( FF_NAME == nFmt ) 643 aRet = aPathName.GetName(URL_DECODE); 644 else if( FF_NAME_NOEXT == nFmt ) 645 aRet = aPathName.GetBase(); 646 else 647 { 648 if( FF_PATH == nFmt ) 649 { 650 aPathName.removeSegment(); 651 aRet = aPathName.GetFull(); 652 } 653 else 654 aRet = aPathName.GetFull(); 655 } 656 } 657 } 658 } 659 return aRet; 660 } 661 662 SwFieldType* SwTemplNameFieldType::Copy() const 663 { 664 SwFieldType *pTmp = new SwTemplNameFieldType(pDoc); 665 return pTmp; 666 } 667 /*-------------------------------------------------------------------- 668 Beschreibung: SwTemplNameField 669 --------------------------------------------------------------------*/ 670 671 SwTemplNameField::SwTemplNameField(SwTemplNameFieldType* pTyp, sal_uInt32 nFmt) 672 : SwField(pTyp, nFmt) 673 {} 674 675 String SwTemplNameField::Expand() const 676 { 677 return((SwTemplNameFieldType*)GetTyp())->Expand(GetFormat()); 678 } 679 680 SwField* SwTemplNameField::Copy() const 681 { 682 SwTemplNameField *pTmp = 683 new SwTemplNameField((SwTemplNameFieldType*)GetTyp(), GetFormat()); 684 return pTmp; 685 } 686 687 sal_Bool SwTemplNameField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const 688 { 689 switch ( nWhichId ) 690 { 691 case FIELD_PROP_FORMAT: 692 { 693 sal_Int16 nRet; 694 switch( GetFormat() ) 695 { 696 case FF_PATH: nRet = text::FilenameDisplayFormat::PATH; break; 697 case FF_NAME_NOEXT: nRet = text::FilenameDisplayFormat::NAME; break; 698 case FF_NAME: nRet = text::FilenameDisplayFormat::NAME_AND_EXT; break; 699 case FF_UI_RANGE: nRet = text::TemplateDisplayFormat::AREA; break; 700 case FF_UI_NAME: nRet = text::TemplateDisplayFormat::TITLE; break; 701 default: nRet = text::FilenameDisplayFormat::FULL; 702 703 } 704 rAny <<= nRet; 705 } 706 break; 707 default: 708 DBG_ERROR("illegal property"); 709 } 710 return sal_True; 711 } 712 713 sal_Bool SwTemplNameField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId ) 714 { 715 switch ( nWhichId ) 716 { 717 case FIELD_PROP_FORMAT: 718 { 719 //JP 24.10.2001: int32 because in UnoField.cxx a putvalue is 720 // called with a int32 value! But normally we need 721 // here only a int16 722 sal_Int32 nType = 0; 723 rAny >>= nType; 724 switch( nType ) 725 { 726 case text::FilenameDisplayFormat::PATH: 727 SetFormat(FF_PATH); 728 break; 729 case text::FilenameDisplayFormat::NAME: 730 SetFormat(FF_NAME_NOEXT); 731 break; 732 case text::FilenameDisplayFormat::NAME_AND_EXT: 733 SetFormat(FF_NAME); 734 break; 735 case text::TemplateDisplayFormat::AREA : 736 SetFormat(FF_UI_RANGE); 737 break; 738 case text::TemplateDisplayFormat::TITLE : 739 SetFormat(FF_UI_NAME); 740 break; 741 default: SetFormat(FF_PATHNAME); 742 } 743 } 744 break; 745 default: 746 DBG_ERROR("illegal property"); 747 } 748 return sal_True; 749 } 750 /*-------------------------------------------------------------------- 751 Beschreibung: SwDocStatFieldType 752 --------------------------------------------------------------------*/ 753 754 SwDocStatFieldType::SwDocStatFieldType(SwDoc* pDocument) 755 : SwFieldType( RES_DOCSTATFLD ), nNumberingType( SVX_NUM_ARABIC ) 756 { 757 pDoc = pDocument; 758 } 759 760 String SwDocStatFieldType::Expand(sal_uInt16 nSubType, sal_uInt32 nFmt) const 761 { 762 sal_uInt32 nVal = 0; 763 const SwDocStat& rDStat = pDoc->GetDocStat(); 764 switch( nSubType ) 765 { 766 case DS_TBL: nVal = rDStat.nTbl; break; 767 case DS_GRF: nVal = rDStat.nGrf; break; 768 case DS_OLE: nVal = rDStat.nOLE; break; 769 case DS_PARA: nVal = rDStat.nPara; break; 770 case DS_WORD: nVal = rDStat.nWord; break; 771 case DS_CHAR: nVal = rDStat.nChar; break; 772 case DS_PAGE: 773 if( pDoc->GetCurrentLayout() )//swmod 080218 774 ((SwDocStat &)rDStat).nPage = pDoc->GetCurrentLayout()->GetPageNum(); //swmod 080218 775 nVal = rDStat.nPage; 776 if( SVX_NUM_PAGEDESC == nFmt ) 777 nFmt = (sal_uInt32)nNumberingType; 778 break; 779 default: 780 ASSERT( sal_False, "SwDocStatFieldType::Expand: unbekannter SubType" ); 781 } 782 783 String sRet; 784 if( nVal <= SHRT_MAX ) 785 sRet = FormatNumber( (sal_uInt16)nVal, nFmt ); 786 else 787 sRet = String::CreateFromInt32( nVal ); 788 return sRet; 789 } 790 791 SwFieldType* SwDocStatFieldType::Copy() const 792 { 793 SwDocStatFieldType *pTmp = new SwDocStatFieldType(pDoc); 794 return pTmp; 795 } 796 797 /*-------------------------------------------------------------------- 798 Beschreibung: SwDocStatFieldType 799 Aus historischen Gruenden steht in nFormat der 800 SubType 801 --------------------------------------------------------------------*/ 802 803 SwDocStatField::SwDocStatField(SwDocStatFieldType* pTyp, sal_uInt16 nSub, sal_uInt32 nFmt) 804 : SwField(pTyp, nFmt), 805 nSubType(nSub) 806 {} 807 808 String SwDocStatField::Expand() const 809 { 810 return((SwDocStatFieldType*)GetTyp())->Expand(nSubType, GetFormat()); 811 } 812 813 SwField* SwDocStatField::Copy() const 814 { 815 SwDocStatField *pTmp = new SwDocStatField( 816 (SwDocStatFieldType*)GetTyp(), nSubType, GetFormat() ); 817 return pTmp; 818 } 819 820 sal_uInt16 SwDocStatField::GetSubType() const 821 { 822 return nSubType; 823 } 824 825 void SwDocStatField::SetSubType(sal_uInt16 nSub) 826 { 827 nSubType = nSub; 828 } 829 830 void SwDocStatField::ChangeExpansion( const SwFrm* pFrm ) 831 { 832 if( DS_PAGE == nSubType && SVX_NUM_PAGEDESC == GetFormat() ) 833 ((SwDocStatFieldType*)GetTyp())->SetNumFormat( 834 pFrm->FindPageFrm()->GetPageDesc()->GetNumType().GetNumberingType() ); 835 } 836 837 sal_Bool SwDocStatField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const 838 { 839 switch ( nWhichId ) 840 { 841 case FIELD_PROP_USHORT2: 842 rAny <<= (sal_Int16)GetFormat(); 843 break; 844 default: 845 DBG_ERROR("illegal property"); 846 } 847 return sal_True; 848 } 849 850 sal_Bool SwDocStatField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId ) 851 { 852 sal_Bool bRet = sal_False; 853 switch ( nWhichId ) 854 { 855 case FIELD_PROP_USHORT2: 856 { 857 sal_Int16 nSet = 0; 858 rAny >>= nSet; 859 if(nSet <= SVX_NUM_CHARS_LOWER_LETTER_N && 860 nSet != SVX_NUM_CHAR_SPECIAL && 861 nSet != SVX_NUM_BITMAP) 862 { 863 SetFormat(nSet); 864 bRet = sal_True; 865 } 866 } 867 break; 868 869 default: 870 DBG_ERROR("illegal property"); 871 } 872 return bRet; 873 } 874 875 /*-------------------------------------------------------------------- 876 Beschreibung: DokumentinfoFields 877 --------------------------------------------------------------------*/ 878 879 SwDocInfoFieldType::SwDocInfoFieldType(SwDoc* pDc) 880 : SwValueFieldType( pDc, RES_DOCINFOFLD ) 881 { 882 } 883 884 // --------------------------------------------------------------------------- 885 SwFieldType* SwDocInfoFieldType::Copy() const 886 { 887 SwDocInfoFieldType* pTyp = new SwDocInfoFieldType(GetDoc()); 888 return pTyp; 889 } 890 891 void lcl_GetLocalDataWrapper( sal_uLong nLang, 892 const LocaleDataWrapper **ppAppLocalData, 893 const LocaleDataWrapper **ppLocalData ) 894 { 895 SvtSysLocale aLocale; 896 *ppAppLocalData = &aLocale.GetLocaleData(); 897 *ppLocalData = *ppAppLocalData; 898 if( nLang != SvxLocaleToLanguage( (*ppLocalData)->getLocale() ) ) 899 *ppLocalData = new LocaleDataWrapper( 900 ::comphelper::getProcessServiceFactory(), 901 SvxCreateLocale( static_cast<LanguageType>(nLang) ) ); 902 } 903 904 // --------------------------------------------------------------------------- 905 String SwDocInfoFieldType::Expand( sal_uInt16 nSub, sal_uInt32 nFormat, 906 sal_uInt16 nLang, const String& rName ) const 907 { 908 String aStr; 909 const LocaleDataWrapper *pAppLocalData = 0, *pLocalData = 0; 910 SwDocShell *pDocShell(GetDoc()->GetDocShell()); 911 DBG_ASSERT(pDocShell, "no SwDocShell"); 912 if (!pDocShell) { return aStr; } 913 914 uno::Reference<document::XDocumentPropertiesSupplier> xDPS( 915 pDocShell->GetModel(), uno::UNO_QUERY_THROW); 916 uno::Reference<document::XDocumentProperties> xDocProps( 917 xDPS->getDocumentProperties()); 918 DBG_ASSERT(xDocProps.is(), "Doc has no DocumentProperties"); 919 920 sal_uInt16 nExtSub = nSub & 0xff00; 921 nSub &= 0xff; // ExtendedSubTypes nicht beachten 922 923 switch(nSub) 924 { 925 case DI_TITEL: aStr = xDocProps->getTitle(); break; 926 case DI_THEMA: aStr = xDocProps->getSubject(); break; 927 case DI_KEYS: aStr = ::comphelper::string::convertCommaSeparated( 928 xDocProps->getKeywords()); 929 break; 930 case DI_COMMENT:aStr = xDocProps->getDescription(); break; 931 case DI_DOCNO: aStr = String::CreateFromInt32( 932 xDocProps->getEditingCycles() ); 933 break; 934 case DI_EDIT: 935 if ( !nFormat ) 936 { 937 lcl_GetLocalDataWrapper( nLang, &pAppLocalData, &pLocalData ); 938 sal_Int32 dur = xDocProps->getEditingDuration(); 939 aStr = pLocalData->getTime( Time(dur/3600, (dur%3600)/60, dur%60), 940 sal_False, sal_False); 941 } 942 else 943 { 944 sal_Int32 dur = xDocProps->getEditingDuration(); 945 double fVal = Time(dur/3600, (dur%3600)/60, dur%60).GetTimeInDays(); 946 aStr = ExpandValue(fVal, nFormat, nLang); 947 } 948 break; 949 case DI_CUSTOM: 950 { 951 ::rtl::OUString sVal; 952 try 953 { 954 uno::Any aAny; 955 uno::Reference < beans::XPropertySet > xSet( 956 xDocProps->getUserDefinedProperties(), 957 uno::UNO_QUERY_THROW); 958 aAny = xSet->getPropertyValue( rName ); 959 960 uno::Reference < script::XTypeConverter > xConverter( comphelper::getProcessServiceFactory() 961 ->createInstance(::rtl::OUString::createFromAscii("com.sun.star.script.Converter")), uno::UNO_QUERY ); 962 uno::Any aNew; 963 aNew = xConverter->convertToSimpleType( aAny, uno::TypeClass_STRING ); 964 aNew >>= sVal; 965 } 966 catch (uno::Exception&) {} 967 return sVal; 968 } 969 970 default: 971 { 972 String aName( xDocProps->getAuthor() ); 973 util::DateTime uDT( xDocProps->getCreationDate() ); 974 Date aD(uDT.Day, uDT.Month, uDT.Year); 975 Time aT(uDT.Hours, uDT.Minutes, uDT.Seconds, uDT.HundredthSeconds); 976 DateTime aDate(aD,aT); 977 if( nSub == DI_CREATE ) 978 ; // das wars schon!! 979 else if( nSub == DI_CHANGE ) 980 { 981 aName = xDocProps->getModifiedBy(); 982 uDT = xDocProps->getModificationDate(); 983 Date bD(uDT.Day, uDT.Month, uDT.Year); 984 Time bT(uDT.Hours, uDT.Minutes, uDT.Seconds, uDT.HundredthSeconds); 985 DateTime bDate(bD,bT); 986 aDate = bDate; 987 } 988 else if( nSub == DI_PRINT ) 989 { 990 aName = xDocProps->getPrintedBy(); 991 uDT = xDocProps->getPrintDate(); 992 Date bD(uDT.Day, uDT.Month, uDT.Year); 993 Time bT(uDT.Hours, uDT.Minutes, uDT.Seconds, uDT.HundredthSeconds); 994 DateTime bDate(bD,bT); 995 aDate = bDate; 996 } 997 else 998 break; 999 1000 if (aDate.IsValid()) 1001 { 1002 switch (nExtSub & ~DI_SUB_FIXED) 1003 { 1004 case DI_SUB_AUTHOR: 1005 aStr = aName; 1006 break; 1007 1008 case DI_SUB_TIME: 1009 if (!nFormat) 1010 { 1011 lcl_GetLocalDataWrapper( nLang, &pAppLocalData, 1012 &pLocalData ); 1013 aStr = pLocalData->getTime( aDate, 1014 sal_False, sal_False); 1015 } 1016 else 1017 { 1018 // Numberformatter anwerfen! 1019 double fVal = SwDateTimeField::GetDateTime( GetDoc(), 1020 aDate); 1021 aStr = ExpandValue(fVal, nFormat, nLang); 1022 } 1023 break; 1024 1025 case DI_SUB_DATE: 1026 if (!nFormat) 1027 { 1028 lcl_GetLocalDataWrapper( nLang, &pAppLocalData, 1029 &pLocalData ); 1030 aStr = pLocalData->getDate( aDate ); 1031 } 1032 else 1033 { 1034 // Numberformatter anwerfen! 1035 double fVal = SwDateTimeField::GetDateTime( GetDoc(), 1036 aDate); 1037 aStr = ExpandValue(fVal, nFormat, nLang); 1038 } 1039 break; 1040 } 1041 } 1042 } 1043 break; 1044 } 1045 1046 if( pAppLocalData != pLocalData ) 1047 delete pLocalData; 1048 1049 return aStr; 1050 } 1051 1052 // --------------------------------------------------------------------------- 1053 SwDocInfoField::SwDocInfoField(SwDocInfoFieldType* pTyp, sal_uInt16 nSub, const String& rName, sal_uInt32 nFmt) : 1054 SwValueField(pTyp, nFmt), nSubType(nSub) 1055 { 1056 aName = rName; 1057 aContent = ((SwDocInfoFieldType*)GetTyp())->Expand(nSubType, nFmt, GetLanguage(), aName); 1058 } 1059 1060 SwDocInfoField::SwDocInfoField(SwDocInfoFieldType* pTyp, sal_uInt16 nSub, const String& rName, const String& rValue, sal_uInt32 nFmt) : 1061 SwValueField(pTyp, nFmt), nSubType(nSub) 1062 { 1063 aName = rName; 1064 aContent = rValue; 1065 } 1066 1067 // --------------------------------------------------------------------------- 1068 1069 template<class T> 1070 double lcl_TimeToDouble( const T& rTime ) 1071 { 1072 const double fMilliSecondsPerDay = 86400000.0; 1073 return ((rTime.Hours*3600000)+(rTime.Minutes*60000)+(rTime.Seconds*1000)+(rTime.HundredthSeconds*10)) / fMilliSecondsPerDay; 1074 } 1075 1076 template<class D> 1077 double lcl_DateToDouble( const D& rDate, const Date& rNullDate ) 1078 { 1079 long nDate = Date::DateToDays( rDate.Day, rDate.Month, rDate.Year ); 1080 long nNullDate = Date::DateToDays( rNullDate.GetDay(), rNullDate.GetMonth(), rNullDate.GetYear() ); 1081 return double( nDate - nNullDate ); 1082 } 1083 1084 String SwDocInfoField::Expand() const 1085 { 1086 if ( ( nSubType & 0xFF ) == DI_CUSTOM ) 1087 { 1088 // custom properties currently need special treatment 1089 // we don't have a secure way to detect "real" custom properties in Word Import of text fields 1090 // so we treat *every* unknown property as a custom property, even the "built-in" section in Word's document summary information stream 1091 // as these properties have not been inserted when the document summary information was imported, we do it here 1092 // this approach is still a lot better than the old one to import such fields as "user fields" and simple text 1093 SwDocShell* pDocShell = GetDoc()->GetDocShell(); 1094 if( !pDocShell ) 1095 return aContent; 1096 try 1097 { 1098 uno::Reference<document::XDocumentPropertiesSupplier> xDPS( pDocShell->GetModel(), uno::UNO_QUERY_THROW); 1099 uno::Reference<document::XDocumentProperties> xDocProps( xDPS->getDocumentProperties()); 1100 uno::Reference < beans::XPropertySet > xSet( xDocProps->getUserDefinedProperties(), uno::UNO_QUERY_THROW); 1101 uno::Reference < beans::XPropertySetInfo > xSetInfo = xSet->getPropertySetInfo(); 1102 1103 uno::Any aAny; 1104 if( xSetInfo->hasPropertyByName( aName ) ) 1105 aAny = xSet->getPropertyValue( aName ); 1106 if ( aAny.getValueType() != ::getVoidCppuType() ) 1107 { 1108 // "void" type means that the property has not been inserted until now 1109 if ( !IsFixed() ) 1110 { 1111 // if the field is "fixed" we don't update it from the property 1112 ::rtl::OUString sVal; 1113 uno::Reference < script::XTypeConverter > xConverter( comphelper::getProcessServiceFactory() 1114 ->createInstance(::rtl::OUString::createFromAscii("com.sun.star.script.Converter")), uno::UNO_QUERY ); 1115 util::Date aDate; 1116 util::DateTime aDateTime; 1117 util::Duration aDuration; 1118 if( aAny >>= aDate) 1119 { 1120 SvNumberFormatter* pFormatter = pDocShell->GetDoc()->GetNumberFormatter(); 1121 Date* pNullDate = pFormatter->GetNullDate(); 1122 sVal = ExpandValue( lcl_DateToDouble<util::Date>( aDate, *pNullDate ), GetFormat(), GetLanguage()); 1123 } 1124 else if( aAny >>= aDateTime ) 1125 { 1126 double fDateTime = lcl_TimeToDouble<util::DateTime>( aDateTime ); 1127 SvNumberFormatter* pFormatter = pDocShell->GetDoc()->GetNumberFormatter(); 1128 Date* pNullDate = pFormatter->GetNullDate(); 1129 fDateTime += lcl_DateToDouble<util::DateTime>( aDateTime, *pNullDate ); 1130 sVal = ExpandValue( fDateTime, GetFormat(), GetLanguage()); 1131 } 1132 else if( aAny >>= aDuration ) 1133 { 1134 String sText(aDuration.Negative ? '-' : '+'); 1135 sText += ViewShell::GetShellRes()->sDurationFormat; 1136 sText.SearchAndReplace(String::CreateFromAscii( "%1"), String::CreateFromInt32( aDuration.Years ) ); 1137 sText.SearchAndReplace(String::CreateFromAscii( "%2"), String::CreateFromInt32( aDuration.Months ) ); 1138 sText.SearchAndReplace(String::CreateFromAscii( "%3"), String::CreateFromInt32( aDuration.Days ) ); 1139 sText.SearchAndReplace(String::CreateFromAscii( "%4"), String::CreateFromInt32( aDuration.Hours ) ); 1140 sText.SearchAndReplace(String::CreateFromAscii( "%5"), String::CreateFromInt32( aDuration.Minutes) ); 1141 sText.SearchAndReplace(String::CreateFromAscii( "%6"), String::CreateFromInt32( aDuration.Seconds) ); 1142 sVal = sText; 1143 } 1144 else 1145 { 1146 uno::Any aNew = xConverter->convertToSimpleType( aAny, uno::TypeClass_STRING ); 1147 aNew >>= sVal; 1148 } 1149 ((SwDocInfoField*)this)->aContent = sVal; 1150 } 1151 } 1152 } 1153 catch (uno::Exception&) {} 1154 } 1155 else if ( !IsFixed() ) 1156 ((SwDocInfoField*)this)->aContent = ((SwDocInfoFieldType*)GetTyp())->Expand(nSubType, GetFormat(), GetLanguage(), aName); 1157 1158 return aContent; 1159 } 1160 /* --------------------------------------------------------------------------- 1161 1162 ---------------------------------------------------------------------------*/ 1163 String SwDocInfoField::GetFieldName() const 1164 { 1165 String aStr(SwFieldType::GetTypeStr(GetTypeId())); 1166 aStr += ':'; 1167 1168 sal_uInt16 const nSub = nSubType & 0xff; 1169 1170 switch (nSub) 1171 { 1172 case DI_CUSTOM: 1173 aStr += aName; 1174 break; 1175 1176 default: 1177 aStr += *ViewShell::GetShellRes() 1178 ->aDocInfoLst[ nSub - DI_SUBTYPE_BEGIN ]; 1179 break; 1180 } 1181 if (IsFixed()) 1182 { 1183 aStr += ' '; 1184 aStr += ViewShell::GetShellRes()->aFixedStr; 1185 } 1186 return aStr; 1187 } 1188 /* --------------------------------------------------------------------------- 1189 1190 ---------------------------------------------------------------------------*/ 1191 SwField* SwDocInfoField::Copy() const 1192 { 1193 SwDocInfoField* pFld = new SwDocInfoField((SwDocInfoFieldType*)GetTyp(), nSubType, aName, GetFormat()); 1194 pFld->SetAutomaticLanguage(IsAutomaticLanguage()); 1195 pFld->aContent = aContent; 1196 1197 return pFld; 1198 } 1199 /* --------------------------------------------------------------------------- 1200 1201 ---------------------------------------------------------------------------*/ 1202 sal_uInt16 SwDocInfoField::GetSubType() const 1203 { 1204 return nSubType; 1205 } 1206 /* --------------------------------------------------------------------------- 1207 1208 ---------------------------------------------------------------------------*/ 1209 void SwDocInfoField::SetSubType(sal_uInt16 nSub) 1210 { 1211 nSubType = nSub; 1212 } 1213 /* --------------------------------------------------------------------------- 1214 1215 ---------------------------------------------------------------------------*/ 1216 void SwDocInfoField::SetLanguage(sal_uInt16 nLng) 1217 { 1218 if (!GetFormat()) 1219 SwField::SetLanguage(nLng); 1220 else 1221 SwValueField::SetLanguage(nLng); 1222 } 1223 /* --------------------------------------------------------------------------- 1224 1225 ---------------------------------------------------------------------------*/ 1226 sal_Bool SwDocInfoField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const 1227 { 1228 switch( nWhichId ) 1229 { 1230 case FIELD_PROP_PAR1: 1231 rAny <<= OUString(aContent); 1232 break; 1233 1234 case FIELD_PROP_PAR4: 1235 rAny <<= OUString(aName); 1236 break; 1237 1238 case FIELD_PROP_USHORT1: 1239 rAny <<= (sal_Int16)aContent.ToInt32(); 1240 break; 1241 1242 case FIELD_PROP_BOOL1: 1243 { 1244 sal_Bool bVal = 0 != (nSubType & DI_SUB_FIXED); 1245 rAny.setValue(&bVal, ::getBooleanCppuType()); 1246 } 1247 break; 1248 case FIELD_PROP_FORMAT: 1249 rAny <<= (sal_Int32)GetFormat(); 1250 break; 1251 1252 case FIELD_PROP_DOUBLE: 1253 { 1254 double fVal = GetValue(); 1255 rAny.setValue(&fVal, ::getCppuType(&fVal)); 1256 } 1257 break; 1258 case FIELD_PROP_PAR3: 1259 rAny <<= rtl::OUString(Expand()); 1260 break; 1261 case FIELD_PROP_BOOL2: 1262 { 1263 sal_uInt16 nExtSub = (nSubType & 0xff00) & ~DI_SUB_FIXED; 1264 sal_Bool bVal = (nExtSub == DI_SUB_DATE); 1265 rAny.setValue(&bVal, ::getBooleanCppuType()); 1266 } 1267 break; 1268 default: 1269 return SwField::QueryValue(rAny, nWhichId); 1270 } 1271 return sal_True; 1272 } 1273 /* --------------------------------------------------------------------------- 1274 1275 ---------------------------------------------------------------------------*/ 1276 sal_Bool SwDocInfoField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId ) 1277 { 1278 sal_Int32 nValue = 0; 1279 switch( nWhichId ) 1280 { 1281 case FIELD_PROP_PAR1: 1282 if( nSubType & DI_SUB_FIXED ) 1283 ::GetString( rAny, aContent ); 1284 break; 1285 1286 case FIELD_PROP_USHORT1: 1287 if( nSubType & DI_SUB_FIXED ) 1288 { 1289 rAny >>= nValue; 1290 aContent = String::CreateFromInt32(nValue); 1291 } 1292 break; 1293 1294 case FIELD_PROP_BOOL1: 1295 if(*(sal_Bool*)rAny.getValue()) 1296 nSubType |= DI_SUB_FIXED; 1297 else 1298 nSubType &= ~DI_SUB_FIXED; 1299 break; 1300 case FIELD_PROP_FORMAT: 1301 { 1302 rAny >>= nValue; 1303 if( nValue >= 0) 1304 SetFormat(nValue); 1305 } 1306 break; 1307 1308 case FIELD_PROP_PAR3: 1309 ::GetString( rAny, aContent ); 1310 break; 1311 case FIELD_PROP_BOOL2: 1312 nSubType &= 0xf0ff; 1313 if(*(sal_Bool*)rAny.getValue()) 1314 nSubType |= DI_SUB_DATE; 1315 else 1316 nSubType |= DI_SUB_TIME; 1317 break; 1318 default: 1319 return SwField::PutValue(rAny, nWhichId); 1320 } 1321 return sal_True; 1322 } 1323 1324 /*-------------------------------------------------------------------- 1325 Beschreibung: SwHiddenTxtFieldType by JP 1326 --------------------------------------------------------------------*/ 1327 1328 SwHiddenTxtFieldType::SwHiddenTxtFieldType( sal_Bool bSetHidden ) 1329 : SwFieldType( RES_HIDDENTXTFLD ), bHidden( bSetHidden ) 1330 { 1331 } 1332 1333 SwFieldType* SwHiddenTxtFieldType::Copy() const 1334 { 1335 return new SwHiddenTxtFieldType( bHidden ); 1336 } 1337 /* --------------------------------------------------------------------------- 1338 1339 ---------------------------------------------------------------------------*/ 1340 void SwHiddenTxtFieldType::SetHiddenFlag( sal_Bool bSetHidden ) 1341 { 1342 if( bHidden != bSetHidden ) 1343 { 1344 bHidden = bSetHidden; 1345 UpdateFlds(); // alle HiddenText benachrichtigen 1346 } 1347 } 1348 /* --------------------------------------------------------------------------- 1349 1350 ---------------------------------------------------------------------------*/ 1351 SwHiddenTxtField::SwHiddenTxtField( SwHiddenTxtFieldType* pFldType, 1352 sal_Bool bConditional, 1353 const String& rCond, 1354 const String& rStr, 1355 sal_Bool bHidden, 1356 sal_uInt16 nSub) : 1357 SwField( pFldType ), aCond(rCond), nSubType(nSub), 1358 bCanToggle(bConditional), bIsHidden(bHidden), bValid(sal_False) 1359 { 1360 if(nSubType == TYP_CONDTXTFLD) 1361 { 1362 sal_uInt16 nPos = 0; 1363 aTRUETxt = rStr.GetToken(0, '|', nPos); 1364 1365 if(nPos != STRING_NOTFOUND) 1366 { 1367 aFALSETxt = rStr.GetToken(0, '|', nPos); 1368 if(nPos != STRING_NOTFOUND) 1369 { 1370 aContent = rStr.GetToken(0, '|', nPos); 1371 bValid = sal_True; 1372 } 1373 } 1374 } 1375 else 1376 aTRUETxt = rStr; 1377 } 1378 /* --------------------------------------------------------------------------- 1379 1380 ---------------------------------------------------------------------------*/ 1381 SwHiddenTxtField::SwHiddenTxtField( SwHiddenTxtFieldType* pFldType, 1382 const String& rCond, 1383 const String& rTrue, 1384 const String& rFalse, 1385 sal_uInt16 nSub) 1386 : SwField( pFldType ), aTRUETxt(rTrue), aFALSETxt(rFalse), aCond(rCond), nSubType(nSub), 1387 bIsHidden(sal_True), bValid(sal_False) 1388 { 1389 bCanToggle = aCond.Len() > 0; 1390 } 1391 /* --------------------------------------------------------------------------- 1392 1393 ---------------------------------------------------------------------------*/ 1394 String SwHiddenTxtField::Expand() const 1395 { 1396 // Type: !Hidden -> immer anzeigen 1397 // Hide -> Werte die Bedingung aus 1398 1399 if( TYP_CONDTXTFLD == nSubType ) 1400 { 1401 if( bValid ) 1402 return aContent; 1403 1404 if( bCanToggle && !bIsHidden ) 1405 return aTRUETxt; 1406 } 1407 else if( !((SwHiddenTxtFieldType*)GetTyp())->GetHiddenFlag() || 1408 ( bCanToggle && bIsHidden )) 1409 return aTRUETxt; 1410 1411 return aFALSETxt; 1412 } 1413 1414 /*-------------------------------------------------------------------- 1415 Beschreibung: Aktuellen Field-Value holen und cachen 1416 --------------------------------------------------------------------*/ 1417 1418 void SwHiddenTxtField::Evaluate(SwDoc* pDoc) 1419 { 1420 ASSERT(pDoc, Wo ist das Dokument Seniore); 1421 1422 if( TYP_CONDTXTFLD == nSubType ) 1423 { 1424 SwNewDBMgr* pMgr = pDoc->GetNewDBMgr(); 1425 1426 bValid = sal_False; 1427 String sTmpName; 1428 1429 if (bCanToggle && !bIsHidden) 1430 sTmpName = aTRUETxt; 1431 else 1432 sTmpName = aFALSETxt; 1433 1434 // OS 21.08.97: #42943# Datenbankausdruecke muessen sich von 1435 // einfachem Text unterscheiden. also wird der einfache Text 1436 // bevorzugt in Anfuehrungszeichen gesetzt. 1437 // Sind diese vorhanden werden umschliessende entfernt. 1438 // Wenn nicht, dann wird auf die Tauglichkeit als Datenbankname 1439 // geprueft. Nur wenn zwei oder mehr Punkte vorhanden sind und kein 1440 // Anfuehrungszeichen enthalten ist, gehen wir von einer DB aus. 1441 if(sTmpName.Len() > 1 && sTmpName.GetChar(0) == '\"' && 1442 sTmpName.GetChar((sTmpName.Len() - 1))== '\"') 1443 { 1444 aContent = sTmpName.Copy(1, sTmpName.Len() - 2); 1445 bValid = sal_True; 1446 } 1447 else if(sTmpName.Search('\"') == STRING_NOTFOUND && 1448 sTmpName.GetTokenCount('.') > 2) 1449 { 1450 ::ReplacePoint(sTmpName); 1451 if(sTmpName.GetChar(0) == '[' && sTmpName.GetChar(sTmpName.Len()-1) == ']') 1452 { // Eckige Klammern entfernen 1453 sTmpName.Erase(0, 1); 1454 sTmpName.Erase(sTmpName.Len()-1, 1); 1455 } 1456 1457 if( pMgr) 1458 { 1459 String sDBName( GetDBName( sTmpName, pDoc )); 1460 String sDataSource(sDBName.GetToken(0, DB_DELIM)); 1461 String sDataTableOrQuery(sDBName.GetToken(1, DB_DELIM)); 1462 if( pMgr->IsInMerge() && sDBName.Len() && 1463 pMgr->IsDataSourceOpen( sDataSource, 1464 sDataTableOrQuery, sal_False)) 1465 { 1466 double fNumber; 1467 sal_uInt32 nTmpFormat; 1468 pMgr->GetMergeColumnCnt(GetColumnName( sTmpName ), 1469 GetLanguage(), aContent, &fNumber, &nTmpFormat ); 1470 bValid = sal_True; 1471 } 1472 else if( sDBName.Len() && sDataSource.Len() && 1473 sDataTableOrQuery.Len() ) 1474 bValid = sal_True; 1475 } 1476 } 1477 } 1478 } 1479 /* --------------------------------------------------------------------------- 1480 1481 ---------------------------------------------------------------------------*/ 1482 String SwHiddenTxtField::GetFieldName() const 1483 { 1484 String aStr(SwFieldType::GetTypeStr(nSubType)); 1485 aStr += ' '; 1486 aStr += aCond; 1487 aStr += ' '; 1488 aStr += aTRUETxt; 1489 1490 if (nSubType == TYP_CONDTXTFLD) 1491 { 1492 aStr.AppendAscii(" : "); 1493 aStr += aFALSETxt; 1494 } 1495 return aStr; 1496 } 1497 /* --------------------------------------------------------------------------- 1498 1499 ---------------------------------------------------------------------------*/ 1500 SwField* SwHiddenTxtField::Copy() const 1501 { 1502 SwHiddenTxtField* pFld = 1503 new SwHiddenTxtField((SwHiddenTxtFieldType*)GetTyp(), aCond, 1504 aTRUETxt, aFALSETxt); 1505 pFld->bIsHidden = bIsHidden; 1506 pFld->bValid = bValid; 1507 pFld->aContent = aContent; 1508 pFld->SetFormat(GetFormat()); 1509 pFld->nSubType = nSubType; 1510 return pFld; 1511 } 1512 1513 1514 /*-------------------------------------------------------------------- 1515 Beschreibung: Bedingung setzen 1516 --------------------------------------------------------------------*/ 1517 1518 void SwHiddenTxtField::SetPar1(const String& rStr) 1519 { 1520 aCond = rStr; 1521 bCanToggle = aCond.Len() > 0; 1522 } 1523 /* --------------------------------------------------------------------------- 1524 1525 ---------------------------------------------------------------------------*/ 1526 const String& SwHiddenTxtField::GetPar1() const 1527 { 1528 return aCond; 1529 } 1530 1531 /*-------------------------------------------------------------------- 1532 Beschreibung: True/False Text 1533 --------------------------------------------------------------------*/ 1534 1535 void SwHiddenTxtField::SetPar2(const String& rStr) 1536 { 1537 if(nSubType == TYP_CONDTXTFLD) 1538 { 1539 sal_uInt16 nPos = rStr.Search('|'); 1540 aTRUETxt = rStr.Copy(0, nPos); 1541 1542 if(nPos != STRING_NOTFOUND) 1543 aFALSETxt = rStr.Copy(nPos + 1); 1544 } 1545 else 1546 aTRUETxt = rStr; 1547 } 1548 /* --------------------------------------------------------------------------- 1549 1550 ---------------------------------------------------------------------------*/ 1551 String SwHiddenTxtField::GetPar2() const 1552 { 1553 String aRet(aTRUETxt); 1554 if(nSubType == TYP_CONDTXTFLD) 1555 { 1556 aRet += '|'; 1557 aRet += aFALSETxt; 1558 } 1559 return aRet; 1560 } 1561 /* --------------------------------------------------------------------------- 1562 1563 ---------------------------------------------------------------------------*/ 1564 sal_uInt16 SwHiddenTxtField::GetSubType() const 1565 { 1566 return nSubType; 1567 } 1568 /* --------------------------------------------------------------------------- 1569 1570 ---------------------------------------------------------------------------*/ 1571 sal_Bool SwHiddenTxtField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const 1572 { 1573 const String* pOut = 0; 1574 switch( nWhichId ) 1575 { 1576 case FIELD_PROP_PAR1: 1577 pOut = &aCond; 1578 break; 1579 case FIELD_PROP_PAR2: 1580 pOut = &aTRUETxt; 1581 break; 1582 case FIELD_PROP_PAR3: 1583 pOut = &aFALSETxt; 1584 break; 1585 case FIELD_PROP_PAR4 : 1586 pOut = &aContent; 1587 break; 1588 case FIELD_PROP_BOOL1: 1589 { 1590 sal_Bool bHidden = bIsHidden; 1591 rAny.setValue(&bHidden, ::getBooleanCppuType()); 1592 } 1593 break; 1594 default: 1595 DBG_ERROR("illegal property"); 1596 } 1597 if( pOut ) 1598 rAny <<= OUString( *pOut ); 1599 return sal_True; 1600 } 1601 /* --------------------------------------------------------------------------- 1602 1603 ---------------------------------------------------------------------------*/ 1604 sal_Bool SwHiddenTxtField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId ) 1605 { 1606 switch( nWhichId ) 1607 { 1608 case FIELD_PROP_PAR1: 1609 { 1610 String sVal; 1611 SetPar1(::GetString( rAny, sVal )); 1612 } 1613 break; 1614 case FIELD_PROP_PAR2: 1615 ::GetString( rAny, aTRUETxt ); 1616 break; 1617 case FIELD_PROP_PAR3: 1618 ::GetString( rAny, aFALSETxt ); 1619 break; 1620 case FIELD_PROP_BOOL1: 1621 bIsHidden = *(sal_Bool*)rAny.getValue(); 1622 break; 1623 case FIELD_PROP_PAR4: 1624 ::GetString( rAny, aContent); 1625 bValid = sal_True; 1626 break; 1627 default: 1628 DBG_ERROR("illegal property"); 1629 } 1630 return sal_True; 1631 } 1632 1633 //------------------------------------------------------------------------------ 1634 1635 String SwHiddenTxtField::GetColumnName(const String& rName) 1636 { 1637 sal_uInt16 nPos = rName.Search(DB_DELIM); 1638 if( STRING_NOTFOUND != nPos ) 1639 { 1640 nPos = rName.Search(DB_DELIM, nPos + 1); 1641 1642 if( STRING_NOTFOUND != nPos ) 1643 return rName.Copy(nPos + 1); 1644 } 1645 return rName; 1646 } 1647 1648 //------------------------------------------------------------------------------ 1649 1650 String SwHiddenTxtField::GetDBName(const String& rName, SwDoc *pDoc) 1651 { 1652 sal_uInt16 nPos = rName.Search(DB_DELIM); 1653 if( STRING_NOTFOUND != nPos ) 1654 { 1655 nPos = rName.Search(DB_DELIM, nPos + 1); 1656 1657 if( STRING_NOTFOUND != nPos ) 1658 return rName.Copy( 0, nPos ); 1659 } 1660 SwDBData aData = pDoc->GetDBData(); 1661 String sRet = aData.sDataSource; 1662 sRet += DB_DELIM; 1663 sRet += String(aData.sCommand); 1664 return sRet; 1665 } 1666 1667 /*-------------------------------------------------------------------- 1668 Beschreibung: Der Feldtyp fuer Zeilenhoehe 0 1669 --------------------------------------------------------------------*/ 1670 1671 SwHiddenParaFieldType::SwHiddenParaFieldType() 1672 : SwFieldType( RES_HIDDENPARAFLD ) 1673 { 1674 } 1675 1676 SwFieldType* SwHiddenParaFieldType::Copy() const 1677 { 1678 SwHiddenParaFieldType* pTyp = new SwHiddenParaFieldType(); 1679 return pTyp; 1680 } 1681 1682 /*-------------------------------------------------------------------- 1683 Beschreibung: Das Feld Zeilenhoehe 0 1684 --------------------------------------------------------------------*/ 1685 1686 SwHiddenParaField::SwHiddenParaField(SwHiddenParaFieldType* pTyp, const String& rStr) 1687 : SwField(pTyp), aCond(rStr) 1688 { 1689 bIsHidden = sal_False; 1690 } 1691 /* --------------------------------------------------------------------------- 1692 1693 ---------------------------------------------------------------------------*/ 1694 String SwHiddenParaField::Expand() const 1695 { 1696 return aEmptyStr; 1697 } 1698 /* --------------------------------------------------------------------------- 1699 1700 ---------------------------------------------------------------------------*/ 1701 SwField* SwHiddenParaField::Copy() const 1702 { 1703 SwHiddenParaField* pFld = new SwHiddenParaField((SwHiddenParaFieldType*)GetTyp(), aCond); 1704 pFld->bIsHidden = bIsHidden; 1705 1706 return pFld; 1707 } 1708 1709 sal_Bool SwHiddenParaField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const 1710 { 1711 switch ( nWhichId ) 1712 { 1713 case FIELD_PROP_PAR1: 1714 rAny <<= OUString(aCond); 1715 break; 1716 case FIELD_PROP_BOOL1: 1717 { 1718 sal_Bool bHidden = bIsHidden; 1719 rAny.setValue(&bHidden, ::getBooleanCppuType()); 1720 } 1721 break; 1722 1723 default: 1724 DBG_ERROR("illegal property"); 1725 } 1726 return sal_True; 1727 } 1728 1729 sal_Bool SwHiddenParaField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId ) 1730 { 1731 switch ( nWhichId ) 1732 { 1733 case FIELD_PROP_PAR1: 1734 ::GetString( rAny, aCond ); 1735 break; 1736 case FIELD_PROP_BOOL1: 1737 bIsHidden = *(sal_Bool*)rAny.getValue(); 1738 break; 1739 1740 default: 1741 DBG_ERROR("illegal property"); 1742 } 1743 return sal_True; 1744 } 1745 1746 /*-------------------------------------------------------------------- 1747 Beschreibung: Bedingung setzen 1748 --------------------------------------------------------------------*/ 1749 1750 void SwHiddenParaField::SetPar1(const String& rStr) 1751 { 1752 aCond = rStr; 1753 } 1754 /* --------------------------------------------------------------------------- 1755 1756 ---------------------------------------------------------------------------*/ 1757 const String& SwHiddenParaField::GetPar1() const 1758 { 1759 return aCond; 1760 } 1761 1762 /*-------------------------------------------------------------------- 1763 Beschreibung: PostIt 1764 --------------------------------------------------------------------*/ 1765 1766 SwPostItFieldType::SwPostItFieldType(SwDoc *pDoc) 1767 : SwFieldType( RES_POSTITFLD ),mpDoc(pDoc) 1768 {} 1769 /* --------------------------------------------------------------------------- 1770 1771 ---------------------------------------------------------------------------*/ 1772 SwFieldType* SwPostItFieldType::Copy() const 1773 { 1774 return new SwPostItFieldType(mpDoc); 1775 } 1776 1777 1778 /*-------------------------------------------------------------------- 1779 Beschreibung: SwPostItFieldType 1780 --------------------------------------------------------------------*/ 1781 1782 SwPostItField::SwPostItField( SwPostItFieldType* pT, 1783 const String& rAuthor, const String& rTxt, const DateTime& rDateTime ) 1784 : SwField( pT ), sTxt( rTxt ), sAuthor( rAuthor ), aDateTime( rDateTime ), mpText(0), m_pTextObject(0) 1785 { 1786 } 1787 1788 1789 SwPostItField::~SwPostItField() 1790 { 1791 if ( m_pTextObject ) 1792 { 1793 m_pTextObject->DisposeEditSource(); 1794 m_pTextObject->release(); 1795 } 1796 } 1797 1798 /* --------------------------------------------------------------------------- 1799 1800 ---------------------------------------------------------------------------*/ 1801 String SwPostItField::Expand() const 1802 { 1803 return aEmptyStr; 1804 } 1805 1806 1807 String SwPostItField::GetDescription() const 1808 { 1809 return SW_RES(STR_NOTE); 1810 } 1811 1812 /* --------------------------------------------------------------------------- 1813 1814 ---------------------------------------------------------------------------*/ 1815 SwField* SwPostItField::Copy() const 1816 { 1817 SwPostItField* pRet = new SwPostItField( (SwPostItFieldType*)GetTyp(), sAuthor, 1818 sTxt, aDateTime); 1819 if (mpText) 1820 pRet->SetTextObject( new OutlinerParaObject(*mpText) ); 1821 return pRet; 1822 } 1823 /*-------------------------------------------------------------------- 1824 Beschreibung: Author setzen 1825 --------------------------------------------------------------------*/ 1826 1827 void SwPostItField::SetPar1(const String& rStr) 1828 { 1829 sAuthor = rStr; 1830 } 1831 1832 const String& SwPostItField::GetPar1() const 1833 { 1834 return sAuthor; 1835 } 1836 1837 /*-------------------------------------------------------------------- 1838 Beschreibung: Text fuers PostIt setzen 1839 --------------------------------------------------------------------*/ 1840 1841 void SwPostItField::SetPar2(const String& rStr) 1842 { 1843 sTxt = rStr; 1844 } 1845 /* --------------------------------------------------------------------------- 1846 1847 ---------------------------------------------------------------------------*/ 1848 String SwPostItField::GetPar2() const 1849 { 1850 return sTxt; 1851 } 1852 1853 const OutlinerParaObject* SwPostItField::GetTextObject() const 1854 { 1855 return mpText; 1856 } 1857 1858 void SwPostItField::SetTextObject( OutlinerParaObject* pText ) 1859 { 1860 delete mpText; 1861 mpText = pText; 1862 } 1863 1864 sal_uInt32 SwPostItField::GetNumberOfParagraphs() const 1865 { 1866 return (mpText) ? mpText->Count() : 1; 1867 } 1868 1869 sal_Bool SwPostItField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const 1870 { 1871 switch( nWhichId ) 1872 { 1873 case FIELD_PROP_PAR1: 1874 rAny <<= OUString(sAuthor); 1875 break; 1876 case FIELD_PROP_PAR2: 1877 { 1878 rAny <<= OUString(sTxt); 1879 break; 1880 } 1881 case FIELD_PROP_TEXT: 1882 { 1883 if ( !m_pTextObject ) 1884 { 1885 SwPostItFieldType* pGetType = (SwPostItFieldType*)GetTyp(); 1886 SwDoc* pDoc = pGetType->GetDoc(); 1887 SwTextAPIEditSource* pObj = new SwTextAPIEditSource( pDoc ); 1888 const_cast <SwPostItField*> (this)->m_pTextObject = new SwTextAPIObject( pObj ); 1889 m_pTextObject->acquire(); 1890 } 1891 1892 if ( mpText ) 1893 m_pTextObject->SetText( *mpText ); 1894 else 1895 m_pTextObject->SetString( sTxt ); 1896 1897 uno::Reference < text::XText > xText( m_pTextObject ); 1898 rAny <<= xText; 1899 break; 1900 } 1901 case FIELD_PROP_DATE: 1902 { 1903 util::Date aSetDate; 1904 aSetDate.Day = aDateTime.GetDay(); 1905 aSetDate.Month = aDateTime.GetMonth(); 1906 aSetDate.Year = aDateTime.GetYear(); 1907 rAny.setValue(&aSetDate, ::getCppuType((util::Date*)0)); 1908 } 1909 break; 1910 case FIELD_PROP_DATE_TIME: 1911 { 1912 util::DateTime DateTimeValue; 1913 DateTimeValue.HundredthSeconds = aDateTime.Get100Sec(); 1914 DateTimeValue.Seconds = aDateTime.GetSec(); 1915 DateTimeValue.Minutes = aDateTime.GetMin(); 1916 DateTimeValue.Hours = aDateTime.GetHour(); 1917 DateTimeValue.Day = aDateTime.GetDay(); 1918 DateTimeValue.Month = aDateTime.GetMonth(); 1919 DateTimeValue.Year = aDateTime.GetYear(); 1920 rAny <<= DateTimeValue; 1921 } 1922 break; 1923 default: 1924 DBG_ERROR("illegal property"); 1925 } 1926 return sal_True; 1927 } 1928 1929 sal_Bool SwPostItField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId ) 1930 { 1931 switch( nWhichId ) 1932 { 1933 case FIELD_PROP_PAR1: 1934 ::GetString( rAny, sAuthor ); 1935 break; 1936 case FIELD_PROP_PAR2: 1937 ::GetString( rAny, sTxt ); 1938 //#i100374# new string via api, delete complex text object so SwPostItNote picks up the new string 1939 if (mpText) 1940 { 1941 delete mpText; 1942 mpText = 0; 1943 } 1944 break; 1945 case FIELD_PROP_TEXT: 1946 DBG_ERROR("Not implemented!"); 1947 // ::GetString( rAny, sTxt ); 1948 break; 1949 case FIELD_PROP_DATE: 1950 if( rAny.getValueType() == ::getCppuType((util::Date*)0) ) 1951 { 1952 util::Date aSetDate = *(util::Date*)rAny.getValue(); 1953 aDateTime = Date(aSetDate.Day, aSetDate.Month, aSetDate.Year); 1954 } 1955 break; 1956 case FIELD_PROP_DATE_TIME: 1957 { 1958 util::DateTime aDateTimeValue; 1959 if(!(rAny >>= aDateTimeValue)) 1960 return sal_False; 1961 aDateTime.Set100Sec(aDateTimeValue.HundredthSeconds); 1962 aDateTime.SetSec(aDateTimeValue.Seconds); 1963 aDateTime.SetMin(aDateTimeValue.Minutes); 1964 aDateTime.SetHour(aDateTimeValue.Hours); 1965 aDateTime.SetDay(aDateTimeValue.Day); 1966 aDateTime.SetMonth(aDateTimeValue.Month); 1967 aDateTime.SetYear(aDateTimeValue.Year); 1968 } 1969 break; 1970 default: 1971 DBG_ERROR("illegal property"); 1972 } 1973 return sal_True; 1974 } 1975 /*-------------------------------------------------------------------- 1976 Beschreibung: DokumentinfoFields 1977 --------------------------------------------------------------------*/ 1978 1979 SwExtUserFieldType::SwExtUserFieldType() 1980 : SwFieldType( RES_EXTUSERFLD ) 1981 { 1982 } 1983 /* --------------------------------------------------------------------------- 1984 1985 ---------------------------------------------------------------------------*/ 1986 SwFieldType* SwExtUserFieldType::Copy() const 1987 { 1988 SwExtUserFieldType* pTyp = new SwExtUserFieldType; 1989 return pTyp; 1990 } 1991 /* --------------------------------------------------------------------------- 1992 1993 ---------------------------------------------------------------------------*/ 1994 String SwExtUserFieldType::Expand(sal_uInt16 nSub, sal_uInt32 ) const 1995 { 1996 String aRet; 1997 sal_uInt16 nRet = USHRT_MAX; 1998 switch(nSub) 1999 { 2000 case EU_FIRSTNAME: nRet = USER_OPT_FIRSTNAME; break; 2001 case EU_NAME: nRet = USER_OPT_LASTNAME; break; 2002 case EU_SHORTCUT: nRet = USER_OPT_ID; break; 2003 2004 case EU_COMPANY: nRet = USER_OPT_COMPANY; break; 2005 case EU_STREET: nRet = USER_OPT_STREET; break; 2006 case EU_TITLE: nRet = USER_OPT_TITLE; break; 2007 case EU_POSITION: nRet = USER_OPT_POSITION; break; 2008 case EU_PHONE_PRIVATE: nRet = USER_OPT_TELEPHONEHOME; break; 2009 case EU_PHONE_COMPANY: nRet = USER_OPT_TELEPHONEWORK; break; 2010 case EU_FAX: nRet = USER_OPT_FAX; break; 2011 case EU_EMAIL: nRet = USER_OPT_EMAIL; break; 2012 case EU_COUNTRY: nRet = USER_OPT_COUNTRY; break; 2013 case EU_ZIP: nRet = USER_OPT_ZIP; break; 2014 case EU_CITY: nRet = USER_OPT_CITY; break; 2015 case EU_STATE: nRet = USER_OPT_STATE; break; 2016 case EU_FATHERSNAME: nRet = USER_OPT_FATHERSNAME; break; 2017 case EU_APARTMENT: nRet = USER_OPT_APARTMENT; break; 2018 default: ASSERT( !this, "Field unknown"); 2019 } 2020 if( USHRT_MAX != nRet ) 2021 { 2022 SvtUserOptions& rUserOpt = SW_MOD()->GetUserOptions(); 2023 aRet = rUserOpt.GetToken( nRet ); 2024 } 2025 return aRet; 2026 } 2027 /* --------------------------------------------------------------------------- 2028 2029 ---------------------------------------------------------------------------*/ 2030 SwExtUserField::SwExtUserField(SwExtUserFieldType* pTyp, sal_uInt16 nSubTyp, sal_uInt32 nFmt) : 2031 SwField(pTyp, nFmt), nType(nSubTyp) 2032 { 2033 aContent = ((SwExtUserFieldType*)GetTyp())->Expand(nType, GetFormat()); 2034 } 2035 /* --------------------------------------------------------------------------- 2036 2037 ---------------------------------------------------------------------------*/ 2038 String SwExtUserField::Expand() const 2039 { 2040 if (!IsFixed()) 2041 ((SwExtUserField*)this)->aContent = ((SwExtUserFieldType*)GetTyp())->Expand(nType, GetFormat()); 2042 2043 return aContent; 2044 } 2045 /* --------------------------------------------------------------------------- 2046 2047 ---------------------------------------------------------------------------*/ 2048 SwField* SwExtUserField::Copy() const 2049 { 2050 SwExtUserField* pFld = new SwExtUserField((SwExtUserFieldType*)GetTyp(), nType, GetFormat()); 2051 pFld->SetExpansion(aContent); 2052 2053 return pFld; 2054 } 2055 /* --------------------------------------------------------------------------- 2056 2057 ---------------------------------------------------------------------------*/ 2058 sal_uInt16 SwExtUserField::GetSubType() const 2059 { 2060 return nType; 2061 } 2062 /* --------------------------------------------------------------------------- 2063 2064 ---------------------------------------------------------------------------*/ 2065 void SwExtUserField::SetSubType(sal_uInt16 nSub) 2066 { 2067 nType = nSub; 2068 } 2069 2070 sal_Bool SwExtUserField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const 2071 { 2072 switch( nWhichId ) 2073 { 2074 case FIELD_PROP_PAR1: 2075 rAny <<= OUString(aContent); 2076 break; 2077 2078 case FIELD_PROP_USHORT1: 2079 { 2080 sal_Int16 nTmp = nType; 2081 rAny <<= nTmp; 2082 } 2083 break; 2084 case FIELD_PROP_BOOL1: 2085 { 2086 sal_Bool bTmp = IsFixed(); 2087 rAny.setValue(&bTmp, ::getBooleanCppuType()); 2088 } 2089 break; 2090 default: 2091 DBG_ERROR("illegal property"); 2092 } 2093 return sal_True; 2094 } 2095 2096 sal_Bool SwExtUserField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId ) 2097 { 2098 switch( nWhichId ) 2099 { 2100 case FIELD_PROP_PAR1: 2101 ::GetString( rAny, aContent ); 2102 break; 2103 2104 case FIELD_PROP_USHORT1: 2105 { 2106 sal_Int16 nTmp = 0; 2107 rAny >>= nTmp; 2108 nType = nTmp; 2109 } 2110 break; 2111 case FIELD_PROP_BOOL1: 2112 if( *(sal_Bool*)rAny.getValue() ) 2113 SetFormat(GetFormat() | AF_FIXED); 2114 else 2115 SetFormat(GetFormat() & ~AF_FIXED); 2116 break; 2117 default: 2118 DBG_ERROR("illegal property"); 2119 } 2120 return sal_True; 2121 } 2122 //------------------------------------------------------------------------- 2123 2124 /*-------------------------------------------------------------------- 2125 Beschreibung: Relatives Seitennummern - Feld 2126 --------------------------------------------------------------------*/ 2127 2128 SwRefPageSetFieldType::SwRefPageSetFieldType() 2129 : SwFieldType( RES_REFPAGESETFLD ) 2130 { 2131 } 2132 /* --------------------------------------------------------------------------- 2133 2134 ---------------------------------------------------------------------------*/ 2135 SwFieldType* SwRefPageSetFieldType::Copy() const 2136 { 2137 return new SwRefPageSetFieldType; 2138 } 2139 /* --------------------------------------------------------------------------- 2140 2141 ---------------------------------------------------------------------------*/ 2142 // ueberlagert, weil es nichts zum Updaten gibt! 2143 void SwRefPageSetFieldType::Modify( const SfxPoolItem*, const SfxPoolItem * ) 2144 { 2145 } 2146 2147 /*-------------------------------------------------------------------- 2148 Beschreibung: Relative Seitennummerierung 2149 --------------------------------------------------------------------*/ 2150 2151 SwRefPageSetField::SwRefPageSetField( SwRefPageSetFieldType* pTyp, 2152 short nOff, sal_Bool bFlag ) 2153 : SwField( pTyp ), nOffset( nOff ), bOn( bFlag ) 2154 { 2155 } 2156 /* --------------------------------------------------------------------------- 2157 2158 ---------------------------------------------------------------------------*/ 2159 String SwRefPageSetField::Expand() const 2160 { 2161 return aEmptyStr; 2162 } 2163 /* --------------------------------------------------------------------------- 2164 2165 ---------------------------------------------------------------------------*/ 2166 SwField* SwRefPageSetField::Copy() const 2167 { 2168 return new SwRefPageSetField( (SwRefPageSetFieldType*)GetTyp(), nOffset, bOn ); 2169 } 2170 /* --------------------------------------------------------------------------- 2171 2172 ---------------------------------------------------------------------------*/ 2173 String SwRefPageSetField::GetPar2() const 2174 { 2175 return String::CreateFromInt32( GetOffset() ); 2176 } 2177 /* --------------------------------------------------------------------------- 2178 2179 ---------------------------------------------------------------------------*/ 2180 void SwRefPageSetField::SetPar2(const String& rStr) 2181 { 2182 SetOffset( (short) rStr.ToInt32() ); 2183 } 2184 2185 sal_Bool SwRefPageSetField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const 2186 { 2187 switch( nWhichId ) 2188 { 2189 case FIELD_PROP_BOOL1: 2190 rAny.setValue(&bOn, ::getBooleanCppuType()); 2191 break; 2192 case FIELD_PROP_USHORT1: 2193 rAny <<= (sal_Int16)nOffset; 2194 break; 2195 default: 2196 DBG_ERROR("illegal property"); 2197 } 2198 return sal_True; 2199 } 2200 2201 sal_Bool SwRefPageSetField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId ) 2202 { 2203 switch( nWhichId ) 2204 { 2205 case FIELD_PROP_BOOL1: 2206 bOn = *(sal_Bool*)rAny.getValue(); 2207 break; 2208 case FIELD_PROP_USHORT1: 2209 rAny >>=nOffset; 2210 break; 2211 default: 2212 DBG_ERROR("illegal property"); 2213 } 2214 return sal_True; 2215 } 2216 /*-------------------------------------------------------------------- 2217 Beschreibung: relatives Seitennummern - Abfrage Feld 2218 --------------------------------------------------------------------*/ 2219 2220 SwRefPageGetFieldType::SwRefPageGetFieldType( SwDoc* pDc ) 2221 : SwFieldType( RES_REFPAGEGETFLD ), pDoc( pDc ), nNumberingType( SVX_NUM_ARABIC ) 2222 { 2223 } 2224 /* --------------------------------------------------------------------------- 2225 2226 ---------------------------------------------------------------------------*/ 2227 SwFieldType* SwRefPageGetFieldType::Copy() const 2228 { 2229 SwRefPageGetFieldType* pNew = new SwRefPageGetFieldType( pDoc ); 2230 pNew->nNumberingType = nNumberingType; 2231 return pNew; 2232 } 2233 /* --------------------------------------------------------------------------- 2234 2235 ---------------------------------------------------------------------------*/ 2236 void SwRefPageGetFieldType::Modify( const SfxPoolItem* pOld, const SfxPoolItem* pNew ) 2237 { 2238 // Update auf alle GetReferenz-Felder 2239 if( !pNew && !pOld && GetDepends() ) 2240 { 2241 // sammel erstmal alle SetPageRefFelder ein. 2242 _SetGetExpFlds aTmpLst( 10, 5 ); 2243 if( MakeSetList( aTmpLst ) ) 2244 { 2245 SwIterator<SwFmtFld,SwFieldType> aIter( *this ); 2246 for ( SwFmtFld* pFmtFld = aIter.First(); pFmtFld; pFmtFld = aIter.Next() ) 2247 // nur die GetRef-Felder Updaten 2248 if( pFmtFld->GetTxtFld() ) 2249 UpdateField( pFmtFld->GetTxtFld(), aTmpLst ); 2250 } 2251 } 2252 2253 // weiter an die Text-Felder, diese "Expandieren" den Text 2254 NotifyClients( pOld, pNew ); 2255 } 2256 /* --------------------------------------------------------------------------- 2257 2258 ---------------------------------------------------------------------------*/ 2259 sal_uInt16 SwRefPageGetFieldType::MakeSetList( _SetGetExpFlds& rTmpLst ) 2260 { 2261 SwIterator<SwFmtFld,SwFieldType> aIter(*pDoc->GetSysFldType( RES_REFPAGESETFLD)); 2262 for ( SwFmtFld* pFmtFld = aIter.First(); pFmtFld; pFmtFld = aIter.Next() ) 2263 { 2264 // nur die GetRef-Felder Updaten 2265 const SwTxtFld* pTFld = pFmtFld->GetTxtFld(); 2266 if( pTFld ) 2267 { 2268 const SwTxtNode& rTxtNd = pTFld->GetTxtNode(); 2269 2270 // immer den ersten !! (in Tab-Headline, Kopf-/Fuss ) 2271 Point aPt; 2272 const SwCntntFrm* pFrm = rTxtNd.getLayoutFrm( rTxtNd.GetDoc()->GetCurrentLayout(), &aPt, 0, sal_False ); 2273 2274 _SetGetExpFld* pNew; 2275 2276 if( !pFrm || 2277 pFrm->IsInDocBody() || 2278 // --> FME 2004-07-27 #i31868# 2279 // Check if pFrm is not yet connected to the layout. 2280 !pFrm->FindPageFrm() ) 2281 // <-- 2282 { 2283 // einen sdbcx::Index fuers bestimmen vom TextNode anlegen 2284 SwNodeIndex aIdx( rTxtNd ); 2285 pNew = new _SetGetExpFld( aIdx, pTFld ); 2286 } 2287 else 2288 { 2289 // einen sdbcx::Index fuers bestimmen vom TextNode anlegen 2290 SwPosition aPos( pDoc->GetNodes().GetEndOfPostIts() ); 2291 #ifdef DBG_UTIL 2292 ASSERT( GetBodyTxtNode( *pDoc, aPos, *pFrm ), 2293 "wo steht das Feld" ); 2294 #else 2295 GetBodyTxtNode( *pDoc, aPos, *pFrm ); 2296 #endif 2297 pNew = new _SetGetExpFld( aPos.nNode, pTFld, 2298 &aPos.nContent ); 2299 } 2300 2301 if( !rTmpLst.Insert( pNew )) 2302 delete pNew; 2303 } 2304 } 2305 2306 return rTmpLst.Count(); 2307 } 2308 /* --------------------------------------------------------------------------- 2309 2310 ---------------------------------------------------------------------------*/ 2311 void SwRefPageGetFieldType::UpdateField( SwTxtFld* pTxtFld, 2312 _SetGetExpFlds& rSetList ) 2313 { 2314 SwRefPageGetField* pGetFld = (SwRefPageGetField*)pTxtFld->GetFld().GetFld(); 2315 pGetFld->SetText( aEmptyStr ); 2316 2317 // dann suche mal das richtige RefPageSet-Field 2318 SwTxtNode* pTxtNode = (SwTxtNode*)&pTxtFld->GetTxtNode(); 2319 if( pTxtNode->StartOfSectionIndex() > 2320 pDoc->GetNodes().GetEndOfExtras().GetIndex() ) 2321 { 2322 SwNodeIndex aIdx( *pTxtNode ); 2323 _SetGetExpFld aEndFld( aIdx, pTxtFld ); 2324 2325 sal_uInt16 nLast; 2326 rSetList.Seek_Entry( &aEndFld, &nLast ); 2327 2328 if( nLast-- ) 2329 { 2330 const SwTxtFld* pRefTxtFld = rSetList[ nLast ]->GetFld(); 2331 const SwRefPageSetField* pSetFld = 2332 (SwRefPageSetField*)pRefTxtFld->GetFld().GetFld(); 2333 if( pSetFld->IsOn() ) 2334 { 2335 // dann bestimme mal den entsp. Offset 2336 Point aPt; 2337 const SwCntntFrm* pFrm = pTxtNode->getLayoutFrm( pTxtNode->GetDoc()->GetCurrentLayout(), &aPt, 0, sal_False ); 2338 const SwCntntFrm* pRefFrm = pRefTxtFld->GetTxtNode().getLayoutFrm( pRefTxtFld->GetTxtNode().GetDoc()->GetCurrentLayout(), &aPt, 0, sal_False ); 2339 const SwPageFrm* pPgFrm = 0; 2340 sal_uInt16 nDiff = ( pFrm && pRefFrm ) 2341 ? (pPgFrm = pFrm->FindPageFrm())->GetPhyPageNum() - 2342 pRefFrm->FindPageFrm()->GetPhyPageNum() + 1 2343 : 1; 2344 2345 sal_uInt32 nTmpFmt = SVX_NUM_PAGEDESC == pGetFld->GetFormat() 2346 ? ( !pPgFrm 2347 ? (sal_uInt32)SVX_NUM_ARABIC 2348 : pPgFrm->GetPageDesc()->GetNumType().GetNumberingType() ) 2349 : pGetFld->GetFormat(); 2350 short nPageNum = static_cast<short>(Max(0, pSetFld->GetOffset() + (short)nDiff)); 2351 pGetFld->SetText( FormatNumber( nPageNum, nTmpFmt ) ); 2352 } 2353 } 2354 } 2355 // dann die Formatierung anstossen 2356 ((SwFmtFld&)pTxtFld->GetFld()).ModifyNotification( 0, 0 ); 2357 } 2358 2359 /*-------------------------------------------------------------------- 2360 Beschreibung: Relative Seitennummerierung Abfragen 2361 --------------------------------------------------------------------*/ 2362 2363 SwRefPageGetField::SwRefPageGetField( SwRefPageGetFieldType* pTyp, 2364 sal_uInt32 nFmt ) 2365 : SwField( pTyp, nFmt ) 2366 { 2367 } 2368 /* --------------------------------------------------------------------------- 2369 2370 ---------------------------------------------------------------------------*/ 2371 String SwRefPageGetField::Expand() const 2372 { 2373 return sTxt; 2374 } 2375 /* --------------------------------------------------------------------------- 2376 2377 ---------------------------------------------------------------------------*/ 2378 SwField* SwRefPageGetField::Copy() const 2379 { 2380 SwRefPageGetField* pCpy = new SwRefPageGetField( 2381 (SwRefPageGetFieldType*)GetTyp(), GetFormat() ); 2382 pCpy->SetText( sTxt ); 2383 return pCpy; 2384 } 2385 /* --------------------------------------------------------------------------- 2386 2387 ---------------------------------------------------------------------------*/ 2388 void SwRefPageGetField::ChangeExpansion( const SwFrm* pFrm, 2389 const SwTxtFld* pFld ) 2390 { 2391 // nur Felder in Footer, Header, FootNote, Flys 2392 SwTxtNode* pTxtNode = (SwTxtNode*)&pFld->GetTxtNode(); 2393 SwRefPageGetFieldType* pGetType = (SwRefPageGetFieldType*)GetTyp(); 2394 SwDoc* pDoc = pGetType->GetDoc(); 2395 if( pFld->GetTxtNode().StartOfSectionIndex() > 2396 pDoc->GetNodes().GetEndOfExtras().GetIndex() ) 2397 return; 2398 2399 sTxt.Erase(); 2400 2401 ASSERT( !pFrm->IsInDocBody(), "Flag ist nicht richtig, Frame steht im DocBody" ); 2402 2403 // sammel erstmal alle SetPageRefFelder ein. 2404 _SetGetExpFlds aTmpLst( 10, 5 ); 2405 if( !pGetType->MakeSetList( aTmpLst ) ) 2406 return ; 2407 2408 // einen sdbcx::Index fuers bestimmen vom TextNode anlegen 2409 SwPosition aPos( SwNodeIndex( pDoc->GetNodes() ) ); 2410 pTxtNode = (SwTxtNode*) GetBodyTxtNode( *pDoc, aPos, *pFrm ); 2411 2412 // Wenn kein Layout vorhanden, kommt es in Kopf und Fusszeilen dazu 2413 // das ChangeExpansion uebers Layout-Formatieren aufgerufen wird 2414 // aber kein TxtNode vorhanden ist 2415 // 2416 if(!pTxtNode) 2417 return; 2418 2419 _SetGetExpFld aEndFld( aPos.nNode, pFld, &aPos.nContent ); 2420 2421 sal_uInt16 nLast; 2422 aTmpLst.Seek_Entry( &aEndFld, &nLast ); 2423 2424 if( !nLast-- ) 2425 return ; // es gibt kein entsprechendes Set - Feld vor mir 2426 2427 const SwTxtFld* pRefTxtFld = aTmpLst[ nLast ]->GetFld(); 2428 const SwRefPageSetField* pSetFld = 2429 (SwRefPageSetField*)pRefTxtFld->GetFld().GetFld(); 2430 Point aPt; 2431 const SwCntntFrm* pRefFrm = pRefTxtFld ? pRefTxtFld->GetTxtNode().getLayoutFrm( pFrm->getRootFrm(), &aPt, 0, sal_False ) : 0; 2432 if( pSetFld->IsOn() && pRefFrm ) 2433 { 2434 // dann bestimme mal den entsp. Offset 2435 const SwPageFrm* pPgFrm = pFrm->FindPageFrm(); 2436 sal_uInt16 nDiff = pPgFrm->GetPhyPageNum() - 2437 pRefFrm->FindPageFrm()->GetPhyPageNum() + 1; 2438 2439 SwRefPageGetField* pGetFld = (SwRefPageGetField*)pFld->GetFld().GetFld(); 2440 sal_uInt32 nTmpFmt = SVX_NUM_PAGEDESC == pGetFld->GetFormat() 2441 ? pPgFrm->GetPageDesc()->GetNumType().GetNumberingType() 2442 : pGetFld->GetFormat(); 2443 short nPageNum = static_cast<short>(Max(0, pSetFld->GetOffset() + (short)nDiff )); 2444 pGetFld->SetText( FormatNumber( nPageNum, nTmpFmt ) ); 2445 } 2446 } 2447 2448 sal_Bool SwRefPageGetField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const 2449 { 2450 switch( nWhichId ) 2451 { 2452 case FIELD_PROP_USHORT1: 2453 rAny <<= (sal_Int16)GetFormat(); 2454 break; 2455 case FIELD_PROP_PAR1: 2456 rAny <<= OUString(sTxt); 2457 break; 2458 default: 2459 DBG_ERROR("illegal property"); 2460 } 2461 return sal_True; 2462 } 2463 2464 sal_Bool SwRefPageGetField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId ) 2465 { 2466 switch( nWhichId ) 2467 { 2468 case FIELD_PROP_USHORT1: 2469 { 2470 sal_Int16 nSet = 0; 2471 rAny >>= nSet; 2472 if(nSet <= SVX_NUM_PAGEDESC ) 2473 SetFormat(nSet); 2474 else { 2475 //exception(wrong_value) 2476 ; 2477 } 2478 } 2479 break; 2480 case FIELD_PROP_PAR1: 2481 { 2482 OUString sTmp; 2483 rAny >>= sTmp; 2484 sTxt = sTmp; 2485 } 2486 break; 2487 default: 2488 DBG_ERROR("illegal property"); 2489 } 2490 return sal_True; 2491 } 2492 2493 /*-------------------------------------------------------------------- 2494 Beschreibung: Feld zum Anspringen und Editieren 2495 --------------------------------------------------------------------*/ 2496 2497 SwJumpEditFieldType::SwJumpEditFieldType( SwDoc* pD ) 2498 : SwFieldType( RES_JUMPEDITFLD ), pDoc( pD ), aDep( this, 0 ) 2499 { 2500 } 2501 /* --------------------------------------------------------------------------- 2502 2503 ---------------------------------------------------------------------------*/ 2504 SwFieldType* SwJumpEditFieldType::Copy() const 2505 { 2506 return new SwJumpEditFieldType( pDoc ); 2507 } 2508 /* --------------------------------------------------------------------------- 2509 2510 ---------------------------------------------------------------------------*/ 2511 SwCharFmt* SwJumpEditFieldType::GetCharFmt() 2512 { 2513 SwCharFmt* pFmt = pDoc->GetCharFmtFromPool( RES_POOLCHR_JUMPEDIT ); 2514 2515 // noch nicht registriert ? 2516 if( !aDep.GetRegisteredIn() ) 2517 pFmt->Add( &aDep ); // anmelden 2518 2519 return pFmt; 2520 } 2521 /* --------------------------------------------------------------------------- 2522 2523 ---------------------------------------------------------------------------*/ 2524 SwJumpEditField::SwJumpEditField( SwJumpEditFieldType* pTyp, sal_uInt32 nForm, 2525 const String& rTxt, const String& rHelp ) 2526 : SwField( pTyp, nForm ), sTxt( rTxt ), sHelp( rHelp ) 2527 { 2528 } 2529 /* --------------------------------------------------------------------------- 2530 2531 ---------------------------------------------------------------------------*/ 2532 String SwJumpEditField::Expand() const 2533 { 2534 String sTmp( '<' ); 2535 sTmp += sTxt; 2536 return sTmp += '>'; 2537 } 2538 /* --------------------------------------------------------------------------- 2539 2540 ---------------------------------------------------------------------------*/ 2541 SwField* SwJumpEditField::Copy() const 2542 { 2543 return new SwJumpEditField( (SwJumpEditFieldType*)GetTyp(), GetFormat(), 2544 sTxt, sHelp ); 2545 } 2546 /* --------------------------------------------------------------------------- 2547 2548 ---------------------------------------------------------------------------*/ 2549 // Platzhalter-Text 2550 2551 const String& SwJumpEditField::GetPar1() const 2552 { 2553 return sTxt; 2554 } 2555 /* --------------------------------------------------------------------------- 2556 2557 ---------------------------------------------------------------------------*/ 2558 void SwJumpEditField::SetPar1(const String& rStr) 2559 { 2560 sTxt = rStr; 2561 } 2562 2563 // HinweisText 2564 /* --------------------------------------------------------------------------- 2565 2566 ---------------------------------------------------------------------------*/ 2567 String SwJumpEditField::GetPar2() const 2568 { 2569 return sHelp; 2570 } 2571 /* --------------------------------------------------------------------------- 2572 2573 ---------------------------------------------------------------------------*/ 2574 void SwJumpEditField::SetPar2(const String& rStr) 2575 { 2576 sHelp = rStr; 2577 } 2578 2579 sal_Bool SwJumpEditField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const 2580 { 2581 switch( nWhichId ) 2582 { 2583 case FIELD_PROP_USHORT1: 2584 { 2585 sal_Int16 nRet; 2586 switch( GetFormat() ) 2587 { 2588 case JE_FMT_TABLE: nRet = text::PlaceholderType::TABLE; break; 2589 case JE_FMT_FRAME: nRet = text::PlaceholderType::TEXTFRAME; break; 2590 case JE_FMT_GRAPHIC:nRet = text::PlaceholderType::GRAPHIC; break; 2591 case JE_FMT_OLE: nRet = text::PlaceholderType::OBJECT; break; 2592 // case JE_FMT_TEXT: 2593 default: 2594 nRet = text::PlaceholderType::TEXT; break; 2595 } 2596 rAny <<= nRet; 2597 } 2598 break; 2599 case FIELD_PROP_PAR1 : 2600 rAny <<= OUString(sHelp); 2601 break; 2602 case FIELD_PROP_PAR2 : 2603 rAny <<= OUString(sTxt); 2604 break; 2605 default: 2606 DBG_ERROR("illegal property"); 2607 } 2608 return sal_True; 2609 } 2610 2611 sal_Bool SwJumpEditField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId ) 2612 { 2613 switch( nWhichId ) 2614 { 2615 case FIELD_PROP_USHORT1: 2616 { 2617 //JP 24.10.2001: int32 because in UnoField.cxx a putvalue is 2618 // called with a int32 value! But normally we need 2619 // here only a int16 2620 sal_Int32 nSet = 0; 2621 rAny >>= nSet; 2622 switch( nSet ) 2623 { 2624 case text::PlaceholderType::TEXT : SetFormat(JE_FMT_TEXT); break; 2625 case text::PlaceholderType::TABLE : SetFormat(JE_FMT_TABLE); break; 2626 case text::PlaceholderType::TEXTFRAME: SetFormat(JE_FMT_FRAME); break; 2627 case text::PlaceholderType::GRAPHIC : SetFormat(JE_FMT_GRAPHIC); break; 2628 case text::PlaceholderType::OBJECT : SetFormat(JE_FMT_OLE); break; 2629 } 2630 } 2631 break; 2632 case FIELD_PROP_PAR1 : 2633 ::GetString( rAny, sHelp ); 2634 break; 2635 case FIELD_PROP_PAR2 : 2636 ::GetString( rAny, sTxt); 2637 break; 2638 default: 2639 DBG_ERROR("illegal property"); 2640 } 2641 return sal_True; 2642 } 2643 2644 2645 /*-------------------------------------------------------------------- 2646 Beschreibung: Combined Character Fieldtype / Field 2647 --------------------------------------------------------------------*/ 2648 2649 SwCombinedCharFieldType::SwCombinedCharFieldType() 2650 : SwFieldType( RES_COMBINED_CHARS ) 2651 { 2652 } 2653 2654 SwFieldType* SwCombinedCharFieldType::Copy() const 2655 { 2656 return new SwCombinedCharFieldType; 2657 } 2658 2659 /* --------------------------------------------------------------------*/ 2660 2661 SwCombinedCharField::SwCombinedCharField( SwCombinedCharFieldType* pFTyp, 2662 const String& rChars ) 2663 : SwField( pFTyp, 0 ), 2664 sCharacters( rChars.Copy( 0, MAX_COMBINED_CHARACTERS )) 2665 { 2666 } 2667 2668 String SwCombinedCharField::Expand() const 2669 { 2670 return sCharacters; 2671 } 2672 2673 SwField* SwCombinedCharField::Copy() const 2674 { 2675 return new SwCombinedCharField( (SwCombinedCharFieldType*)GetTyp(), 2676 sCharacters ); 2677 } 2678 2679 const String& SwCombinedCharField::GetPar1() const 2680 { 2681 return sCharacters; 2682 } 2683 2684 void SwCombinedCharField::SetPar1(const String& rStr) 2685 { 2686 sCharacters = rStr.Copy( 0, MAX_COMBINED_CHARACTERS ); 2687 } 2688 2689 sal_Bool SwCombinedCharField::QueryValue( uno::Any& rAny, 2690 sal_uInt16 nWhichId ) const 2691 { 2692 switch( nWhichId ) 2693 { 2694 case FIELD_PROP_PAR1: 2695 rAny <<= rtl::OUString( sCharacters ); 2696 break; 2697 default: 2698 DBG_ERROR("illegal property"); 2699 } 2700 return sal_True; 2701 } 2702 2703 sal_Bool SwCombinedCharField::PutValue( const uno::Any& rAny, 2704 sal_uInt16 nWhichId ) 2705 { 2706 switch( nWhichId ) 2707 { 2708 case FIELD_PROP_PAR1: 2709 ::GetString( rAny, sCharacters ).Erase( MAX_COMBINED_CHARACTERS ); 2710 break; 2711 default: 2712 DBG_ERROR("illegal property"); 2713 } 2714 return sal_True; 2715 } 2716 2717