1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_sw.hxx" 30 31 32 #define _SVSTDARR_STRINGSDTOR 33 #define _SVSTDARR_USHORTS 34 #define _SVSTDARR_LONGS 35 #define _SVSTDARR_ULONGS 36 #include <hintids.hxx> 37 38 #include <svl/svstdarr.hxx> 39 #include <editeng/unolingu.hxx> 40 #include <editeng/langitem.hxx> 41 #include <swtypes.hxx> 42 #include <tools/resid.hxx> 43 #include <comcore.hrc> 44 #include <authfld.hxx> 45 #include <expfld.hxx> 46 #include <pam.hxx> 47 #include <cntfrm.hxx> 48 #include <tox.hxx> 49 #include <txmsrt.hxx> 50 #include <doctxm.hxx> 51 #include <fmtfld.hxx> 52 #include <txtfld.hxx> 53 #include <ndtxt.hxx> 54 #include <doc.hxx> 55 #include <unofldmid.h> 56 #include <unoprnms.hxx> 57 #include <switerator.hxx> 58 #include <unomid.h> 59 60 using namespace ::com::sun::star::uno; 61 using namespace ::com::sun::star::beans; 62 using namespace ::com::sun::star::lang; 63 using rtl::OUString; 64 65 66 typedef SwAuthEntry* SwAuthEntryPtr; 67 SV_DECL_PTRARR_DEL( SwAuthDataArr, SwAuthEntryPtr, 5, 5 ) 68 SV_IMPL_PTRARR( SwAuthDataArr, SwAuthEntryPtr ) 69 70 71 typedef SwTOXSortKey* TOXSortKeyPtr; 72 SV_DECL_PTRARR_DEL( SortKeyArr, TOXSortKeyPtr, 5, 5 ) 73 SV_IMPL_PTRARR( SortKeyArr, TOXSortKeyPtr ) 74 75 76 SwAuthEntry::SwAuthEntry(const SwAuthEntry& rCopy) 77 : nRefCount(0) 78 { 79 for(sal_uInt16 i = 0; i < AUTH_FIELD_END; i++) 80 aAuthFields[i] = rCopy.aAuthFields[i]; 81 } 82 // -------------------------------------------------------- 83 sal_Bool SwAuthEntry::operator==(const SwAuthEntry& rComp) 84 { 85 for(sal_uInt16 i = 0; i < AUTH_FIELD_END; i++) 86 if(aAuthFields[i] != rComp.aAuthFields[i]) 87 return sal_False; 88 return sal_True; 89 } 90 // -------------------------------------------------------- 91 SwAuthorityFieldType::SwAuthorityFieldType(SwDoc* pDoc) 92 : SwFieldType( RES_AUTHORITY ), 93 m_pDoc(pDoc), 94 m_pDataArr(new SwAuthDataArr ), 95 m_pSequArr(new SvLongs(5, 5)), 96 m_pSortKeyArr(new SortKeyArr(3, 3)), 97 m_cPrefix('['), 98 m_cSuffix(']'), 99 m_bIsSequence(sal_False), 100 m_bSortByDocument(sal_True), 101 m_eLanguage((LanguageType)::GetAppLanguage()) 102 { 103 } 104 105 SwAuthorityFieldType::SwAuthorityFieldType( const SwAuthorityFieldType& rFType) 106 : SwFieldType( RES_AUTHORITY ), 107 m_pDataArr(new SwAuthDataArr ), 108 m_pSequArr(new SvLongs(5, 5)), 109 m_pSortKeyArr(new SortKeyArr(3, 3)), 110 m_cPrefix(rFType.m_cPrefix), 111 m_cSuffix(rFType.m_cSuffix), 112 m_bIsSequence(rFType.m_bIsSequence), 113 m_bSortByDocument(rFType.m_bSortByDocument), 114 m_eLanguage(rFType.m_eLanguage), 115 m_sSortAlgorithm(rFType.m_sSortAlgorithm) 116 { 117 for(sal_uInt16 i = 0; i < rFType.m_pSortKeyArr->Count(); i++) 118 m_pSortKeyArr->Insert((*rFType.m_pSortKeyArr)[i], i); 119 } 120 121 SwAuthorityFieldType::~SwAuthorityFieldType() 122 { 123 // DBG_ASSERT(!m_pDataArr->Count(), "Array is not empty"); 124 m_pSortKeyArr->DeleteAndDestroy(0, m_pSortKeyArr->Count()); 125 delete m_pSortKeyArr; 126 delete m_pSequArr; 127 delete m_pDataArr; 128 } 129 130 SwFieldType* SwAuthorityFieldType::Copy() const 131 { 132 return new SwAuthorityFieldType(m_pDoc); 133 } 134 135 void SwAuthorityFieldType::RemoveField(long nHandle) 136 { 137 #ifdef DBG_UTIL 138 sal_Bool bRemoved = sal_False; 139 #endif 140 for(sal_uInt16 j = 0; j < m_pDataArr->Count(); j++) 141 { 142 SwAuthEntry* pTemp = m_pDataArr->GetObject(j); 143 long nRet = (long)(void*)pTemp; 144 if(nRet == nHandle) 145 { 146 #ifdef DBG_UTIL 147 bRemoved = sal_True; 148 #endif 149 pTemp->RemoveRef(); 150 if(!pTemp->GetRefCount()) 151 { 152 m_pDataArr->DeleteAndDestroy(j, 1); 153 //re-generate positions of the fields 154 DelSequenceArray(); 155 } 156 break; 157 } 158 } 159 #ifdef DBG_UTIL 160 DBG_ASSERT(bRemoved, "Field unknown" ); 161 #endif 162 } 163 164 long SwAuthorityFieldType::AddField(const String& rFieldContents) 165 { 166 long nRet = 0; 167 SwAuthEntry* pEntry = new SwAuthEntry; 168 for( sal_uInt16 i = 0; i < AUTH_FIELD_END; ++i ) 169 pEntry->SetAuthorField( (ToxAuthorityField)i, 170 rFieldContents.GetToken( i, TOX_STYLE_DELIMITER )); 171 172 for(sal_uInt16 j = 0; j < m_pDataArr->Count() && pEntry; j++) 173 { 174 SwAuthEntry* pTemp = m_pDataArr->GetObject(j); 175 if(*pTemp == *pEntry) 176 { 177 DELETEZ(pEntry); 178 nRet = (long)(void*)pTemp; 179 pTemp->AddRef(); 180 } 181 } 182 //if it is a new Entry - insert 183 if(pEntry) 184 { 185 nRet = (long)(void*)pEntry; 186 pEntry->AddRef(); 187 m_pDataArr->Insert(pEntry, m_pDataArr->Count()); 188 //re-generate positions of the fields 189 DelSequenceArray(); 190 } 191 return nRet; 192 } 193 194 sal_Bool SwAuthorityFieldType::AddField(long nHandle) 195 { 196 sal_Bool bRet = sal_False; 197 for( sal_uInt16 j = 0; j < m_pDataArr->Count(); j++ ) 198 { 199 SwAuthEntry* pTemp = m_pDataArr->GetObject(j); 200 long nTmp = (long)(void*)pTemp; 201 if( nTmp == nHandle ) 202 { 203 bRet = sal_True; 204 pTemp->AddRef(); 205 //re-generate positions of the fields 206 DelSequenceArray(); 207 break; 208 } 209 } 210 DBG_ASSERT(bRet, "::AddField(long) failed"); 211 return bRet; 212 } 213 214 const SwAuthEntry* SwAuthorityFieldType::GetEntryByHandle(long nHandle) const 215 { 216 const SwAuthEntry* pRet = 0; 217 for(sal_uInt16 j = 0; j < m_pDataArr->Count(); j++) 218 { 219 const SwAuthEntry* pTemp = m_pDataArr->GetObject(j); 220 long nTmp = (long)(void*)pTemp; 221 if( nTmp == nHandle ) 222 { 223 pRet = pTemp; 224 break; 225 } 226 } 227 ASSERT( pRet, "invalid Handle" ); 228 return pRet; 229 } 230 231 void SwAuthorityFieldType::GetAllEntryIdentifiers( 232 SvStringsDtor& rToFill )const 233 { 234 for(sal_uInt16 j = 0; j < m_pDataArr->Count(); j++) 235 { 236 SwAuthEntry* pTemp = m_pDataArr->GetObject(j); 237 rToFill.Insert( new String( pTemp->GetAuthorField( 238 AUTH_FIELD_IDENTIFIER )), rToFill.Count() ); 239 } 240 } 241 242 const SwAuthEntry* SwAuthorityFieldType::GetEntryByIdentifier( 243 const String& rIdentifier)const 244 { 245 const SwAuthEntry* pRet = 0; 246 for( sal_uInt16 j = 0; j < m_pDataArr->Count(); ++j ) 247 { 248 const SwAuthEntry* pTemp = m_pDataArr->GetObject(j); 249 if( rIdentifier == pTemp->GetAuthorField( AUTH_FIELD_IDENTIFIER )) 250 { 251 pRet = pTemp; 252 break; 253 } 254 } 255 return pRet; 256 } 257 258 bool SwAuthorityFieldType::ChangeEntryContent(const SwAuthEntry* pNewEntry) 259 { 260 bool bChanged = false; 261 for( sal_uInt16 j = 0; j < m_pDataArr->Count(); ++j ) 262 { 263 SwAuthEntry* pTemp = m_pDataArr->GetObject(j); 264 if(pTemp->GetAuthorField(AUTH_FIELD_IDENTIFIER) == 265 pNewEntry->GetAuthorField(AUTH_FIELD_IDENTIFIER)) 266 { 267 for(sal_uInt16 i = 0; i < AUTH_FIELD_END; i++) 268 pTemp->SetAuthorField((ToxAuthorityField) i, 269 pNewEntry->GetAuthorField((ToxAuthorityField)i)); 270 bChanged = true; 271 break; 272 } 273 } 274 return bChanged; 275 } 276 277 /*------------------------------------------------------------------------- 278 appends a new entry (if new) and returns the array position 279 -----------------------------------------------------------------------*/ 280 sal_uInt16 SwAuthorityFieldType::AppendField( const SwAuthEntry& rInsert ) 281 { 282 sal_uInt16 nRet = 0; 283 for( nRet = 0; nRet < m_pDataArr->Count(); ++nRet ) 284 { 285 SwAuthEntry* pTemp = m_pDataArr->GetObject( nRet ); 286 if( *pTemp == rInsert ) 287 { 288 break; 289 //ref count unchanged 290 } 291 } 292 293 //if it is a new Entry - insert 294 if( nRet == m_pDataArr->Count() ) 295 m_pDataArr->Insert( new SwAuthEntry( rInsert ), nRet ); 296 297 return nRet; 298 } 299 300 long SwAuthorityFieldType::GetHandle(sal_uInt16 nPos) 301 { 302 long nRet = 0; 303 if( nPos < m_pDataArr->Count() ) 304 { 305 SwAuthEntry* pTemp = m_pDataArr->GetObject(nPos); 306 nRet = (long)(void*)pTemp; 307 } 308 return nRet; 309 } 310 311 sal_uInt16 SwAuthorityFieldType::GetSequencePos(long nHandle) 312 { 313 //find the field in a sorted array of handles, 314 #ifdef DBG_UTIL 315 sal_Bool bCurrentFieldWithoutTextNode = sal_False; 316 #endif 317 if(m_pSequArr->Count() && m_pSequArr->Count() != m_pDataArr->Count()) 318 DelSequenceArray(); 319 if(!m_pSequArr->Count()) 320 { 321 SwTOXSortTabBases aSortArr; 322 SwIterator<SwFmtFld,SwFieldType> aIter( *this ); 323 324 SwTOXInternational aIntl(m_eLanguage, 0, m_sSortAlgorithm); 325 326 for( SwFmtFld* pFmtFld = aIter.First(); pFmtFld; pFmtFld = aIter.Next() ) 327 { 328 const SwTxtFld* pTxtFld = pFmtFld->GetTxtFld(); 329 if(!pTxtFld || !pTxtFld->GetpTxtNode()) 330 { 331 #ifdef DBG_UTIL 332 if(nHandle == ((SwAuthorityField*)pFmtFld->GetFld())->GetHandle()) 333 bCurrentFieldWithoutTextNode = sal_True; 334 #endif 335 continue; 336 } 337 const SwTxtNode& rFldTxtNode = pTxtFld->GetTxtNode(); 338 SwPosition aFldPos(rFldTxtNode); 339 SwDoc& rDoc = *(SwDoc*)rFldTxtNode.GetDoc(); 340 SwCntntFrm *pFrm = rFldTxtNode.getLayoutFrm( rDoc.GetCurrentLayout() ); 341 const SwTxtNode* pTxtNode = 0; 342 if(pFrm && !pFrm->IsInDocBody()) 343 pTxtNode = GetBodyTxtNode( rDoc, aFldPos, *pFrm ); 344 //if no text node could be found or the field is in the document 345 //body the directly available text node will be used 346 if(!pTxtNode) 347 pTxtNode = &rFldTxtNode; 348 if( pTxtNode->GetTxt().Len() && pTxtNode->getLayoutFrm( rDoc.GetCurrentLayout() ) && 349 pTxtNode->GetNodes().IsDocNodes() ) 350 { 351 SwTOXAuthority* pNew = new SwTOXAuthority( *pTxtNode, 352 *pFmtFld, aIntl ); 353 354 for(short i = 0; i < aSortArr.Count(); ++i) 355 { 356 SwTOXSortTabBase* pOld = aSortArr[i]; 357 if(*pOld == *pNew) 358 { 359 //only the first occurence in the document 360 //has to be in the array 361 if(*pOld < *pNew) 362 DELETEZ(pNew); 363 else // remove the old content 364 aSortArr.DeleteAndDestroy( i, 1 ); 365 break; 366 } 367 } 368 //if it still exists - insert at the correct position 369 if(pNew) 370 { 371 short j; 372 373 for( j = 0; j < aSortArr.Count(); ++j) 374 { 375 SwTOXSortTabBase* pOld = aSortArr[j]; 376 if(*pNew < *pOld) 377 break; 378 } 379 aSortArr.Insert(pNew, j ); 380 } 381 } 382 } 383 384 for(sal_uInt16 i = 0; i < aSortArr.Count(); i++) 385 { 386 const SwTOXSortTabBase& rBase = *aSortArr[i]; 387 SwFmtFld& rFmtFld = ((SwTOXAuthority&)rBase).GetFldFmt(); 388 SwAuthorityField* pAFld = (SwAuthorityField*)rFmtFld.GetFld(); 389 m_pSequArr->Insert(pAFld->GetHandle(), i); 390 } 391 aSortArr.DeleteAndDestroy(0, aSortArr.Count()); 392 } 393 //find nHandle 394 sal_uInt16 nRet = 0; 395 for(sal_uInt16 i = 0; i < m_pSequArr->Count(); i++) 396 { 397 if((*m_pSequArr)[i] == nHandle) 398 { 399 nRet = i + 1; 400 break; 401 } 402 } 403 ASSERT(bCurrentFieldWithoutTextNode || nRet, "Handle not found") 404 return nRet; 405 } 406 407 sal_Bool SwAuthorityFieldType::QueryValue( Any& rVal, sal_uInt16 nWhichId ) const 408 { 409 switch( nWhichId ) 410 { 411 case FIELD_PROP_PAR1: 412 case FIELD_PROP_PAR2: 413 { 414 OUString sVal; 415 sal_Unicode uRet = FIELD_PROP_PAR1 == nWhichId ? m_cPrefix : m_cSuffix; 416 if(uRet) 417 sVal = OUString(uRet); 418 rVal <<= sVal; 419 } 420 break; 421 case FIELD_PROP_PAR3: 422 rVal <<= OUString(GetSortAlgorithm()); 423 break; 424 425 case FIELD_PROP_BOOL1: 426 case FIELD_PROP_BOOL2: 427 { 428 sal_Bool bVal = FIELD_PROP_BOOL1 == nWhichId ? m_bIsSequence: m_bSortByDocument; 429 rVal.setValue(&bVal, ::getBooleanCppuType()); 430 } 431 break; 432 433 case FIELD_PROP_LOCALE: 434 rVal <<= SvxCreateLocale(GetLanguage()); 435 break; 436 437 case FIELD_PROP_PROP_SEQ: 438 { 439 Sequence<PropertyValues> aRet(m_pSortKeyArr->Count()); 440 PropertyValues* pValues = aRet.getArray(); 441 OUString sProp1( C2U(SW_PROP_NAME_STR(UNO_NAME_SORT_KEY)) ), 442 sProp2( C2U(SW_PROP_NAME_STR(UNO_NAME_IS_SORT_ASCENDING))); 443 for(sal_uInt16 i = 0; i < m_pSortKeyArr->Count(); i++) 444 { 445 const SwTOXSortKey* pKey = (*m_pSortKeyArr)[i]; 446 pValues[i].realloc(2); 447 PropertyValue* pValue = pValues[i].getArray(); 448 pValue[0].Name = sProp1; 449 pValue[0].Value <<= sal_Int16(pKey->eField); 450 pValue[1].Name = sProp2; 451 pValue[1].Value.setValue(&pKey->bSortAscending, ::getBooleanCppuType()); 452 } 453 rVal <<= aRet; 454 } 455 break; 456 default: 457 DBG_ERROR("illegal property"); 458 } 459 return sal_True; 460 } 461 462 sal_Bool SwAuthorityFieldType::PutValue( const Any& rAny, sal_uInt16 nWhichId ) 463 { 464 sal_Bool bRet = sal_True; 465 String sTmp; 466 switch( nWhichId ) 467 { 468 case FIELD_PROP_PAR1: 469 case FIELD_PROP_PAR2: 470 { 471 ::GetString( rAny, sTmp ); 472 sal_Unicode uSet = sTmp.GetChar(0); 473 if( FIELD_PROP_PAR1 == nWhichId ) 474 m_cPrefix = uSet; 475 else 476 m_cSuffix = uSet; 477 } 478 break; 479 case FIELD_PROP_PAR3: 480 SetSortAlgorithm( ::GetString( rAny, sTmp )); 481 break; 482 483 case FIELD_PROP_BOOL1: 484 m_bIsSequence = *(sal_Bool*)rAny.getValue(); 485 break; 486 case FIELD_PROP_BOOL2: 487 m_bSortByDocument = *(sal_Bool*)rAny.getValue(); 488 break; 489 490 case FIELD_PROP_LOCALE: 491 { 492 Locale aLocale; 493 if( 0 != (bRet = rAny >>= aLocale )) 494 SetLanguage( SvxLocaleToLanguage( aLocale )); 495 } 496 break; 497 498 case FIELD_PROP_PROP_SEQ: 499 { 500 Sequence<PropertyValues> aSeq; 501 if( 0 != (bRet = rAny >>= aSeq) ) 502 { 503 m_pSortKeyArr->DeleteAndDestroy(0, m_pSortKeyArr->Count()); 504 const PropertyValues* pValues = aSeq.getConstArray(); 505 for(sal_Int32 i = 0; i < aSeq.getLength() && i < USHRT_MAX / 4; i++) 506 { 507 const PropertyValue* pValue = pValues[i].getConstArray(); 508 SwTOXSortKey* pSortKey = new SwTOXSortKey; 509 for(sal_Int32 j = 0; j < pValues[i].getLength(); j++) 510 { 511 if(pValue[j].Name.equalsAsciiL(SW_PROP_NAME(UNO_NAME_SORT_KEY))) 512 { 513 sal_Int16 nVal = -1; pValue[j].Value >>= nVal; 514 if(nVal >= 0 && nVal < AUTH_FIELD_END) 515 pSortKey->eField = (ToxAuthorityField) nVal; 516 else 517 bRet = sal_False; 518 } 519 else if(pValue[j].Name.equalsAsciiL(SW_PROP_NAME(UNO_NAME_IS_SORT_ASCENDING))) 520 { 521 pSortKey->bSortAscending = *(sal_Bool*)pValue[j].Value.getValue(); 522 } 523 } 524 m_pSortKeyArr->Insert(pSortKey, m_pSortKeyArr->Count()); 525 } 526 } 527 } 528 break; 529 default: 530 DBG_ERROR("illegal property"); 531 } 532 return bRet; 533 } 534 535 void SwAuthorityFieldType::Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew ) 536 { 537 //re-generate positions of the fields 538 DelSequenceArray(); 539 NotifyClients( pOld, pNew ); 540 } 541 542 sal_uInt16 SwAuthorityFieldType::GetSortKeyCount() const 543 { 544 return m_pSortKeyArr->Count(); 545 } 546 547 const SwTOXSortKey* SwAuthorityFieldType::GetSortKey(sal_uInt16 nIdx) const 548 { 549 SwTOXSortKey* pRet = 0; 550 if(m_pSortKeyArr->Count() > nIdx) 551 pRet = (*m_pSortKeyArr)[nIdx]; 552 DBG_ASSERT(pRet, "Sort key not found"); 553 return pRet; 554 } 555 556 void SwAuthorityFieldType::SetSortKeys(sal_uInt16 nKeyCount, SwTOXSortKey aKeys[]) 557 { 558 m_pSortKeyArr->DeleteAndDestroy(0, m_pSortKeyArr->Count()); 559 sal_uInt16 nArrIdx = 0; 560 for(sal_uInt16 i = 0; i < nKeyCount; i++) 561 if(aKeys[i].eField < AUTH_FIELD_END) 562 m_pSortKeyArr->Insert(new SwTOXSortKey(aKeys[i]), nArrIdx++); 563 } 564 565 SwAuthorityField::SwAuthorityField( SwAuthorityFieldType* pInitType, 566 const String& rFieldContents ) 567 : SwField(pInitType), 568 m_nTempSequencePos( -1 ) 569 { 570 m_nHandle = pInitType->AddField( rFieldContents ); 571 } 572 573 SwAuthorityField::SwAuthorityField( SwAuthorityFieldType* pInitType, 574 long nSetHandle ) 575 : SwField( pInitType ), 576 m_nHandle( nSetHandle ), 577 m_nTempSequencePos( -1 ) 578 { 579 pInitType->AddField( m_nHandle ); 580 } 581 582 SwAuthorityField::~SwAuthorityField() 583 { 584 ((SwAuthorityFieldType* )GetTyp())->RemoveField(m_nHandle); 585 } 586 587 String SwAuthorityField::Expand() const 588 { 589 SwAuthorityFieldType* pAuthType = (SwAuthorityFieldType*)GetTyp(); 590 String sRet; 591 if(pAuthType->GetPrefix()) 592 sRet.Assign(pAuthType->GetPrefix()); 593 594 if( pAuthType->IsSequence() ) 595 { 596 if(!pAuthType->GetDoc()->IsExpFldsLocked()) 597 m_nTempSequencePos = pAuthType->GetSequencePos( m_nHandle ); 598 if( m_nTempSequencePos >= 0 ) 599 sRet += String::CreateFromInt32( m_nTempSequencePos ); 600 } 601 else 602 { 603 const SwAuthEntry* pEntry = pAuthType->GetEntryByHandle(m_nHandle); 604 //TODO: Expand to: identifier, number sequence, ... 605 if(pEntry) 606 sRet += pEntry->GetAuthorField(AUTH_FIELD_IDENTIFIER); 607 } 608 if(pAuthType->GetSuffix()) 609 sRet += pAuthType->GetSuffix(); 610 return sRet; 611 } 612 613 SwField* SwAuthorityField::Copy() const 614 { 615 SwAuthorityFieldType* pAuthType = (SwAuthorityFieldType*)GetTyp(); 616 return new SwAuthorityField(pAuthType, m_nHandle); 617 } 618 619 const String& SwAuthorityField::GetFieldText(ToxAuthorityField eField) const 620 { 621 SwAuthorityFieldType* pAuthType = (SwAuthorityFieldType*)GetTyp(); 622 const SwAuthEntry* pEntry = pAuthType->GetEntryByHandle( m_nHandle ); 623 return pEntry->GetAuthorField( eField ); 624 } 625 626 void SwAuthorityField::SetPar1(const String& rStr) 627 { 628 SwAuthorityFieldType* pInitType = (SwAuthorityFieldType* )GetTyp(); 629 pInitType->RemoveField(m_nHandle); 630 m_nHandle = pInitType->AddField(rStr); 631 } 632 633 String SwAuthorityField::GetDescription() const 634 { 635 return SW_RES(STR_AUTHORITY_ENTRY); 636 } 637 638 639 const char* aFieldNames[] = 640 { 641 "Identifier", 642 "BibiliographicType", 643 "Address", 644 "Annote", 645 "Author", 646 "Booktitle", 647 "Chapter", 648 "Edition", 649 "Editor", 650 "Howpublished", 651 "Institution", 652 "Journal", 653 "Month", 654 "Note", 655 "Number", 656 "Organizations", 657 "Pages", 658 "Publisher", 659 "School", 660 "Series", 661 "Title", 662 "Report_Type", 663 "Volume", 664 "Year", 665 "URL", 666 "Custom1", 667 "Custom2", 668 "Custom3", 669 "Custom4", 670 "Custom5", 671 "ISBN" 672 }; 673 674 sal_Bool SwAuthorityField::QueryValue( Any& rAny, sal_uInt16 /*nWhichId*/ ) const 675 { 676 if(!GetTyp()) 677 return sal_False; 678 const SwAuthEntry* pAuthEntry = ((SwAuthorityFieldType*)GetTyp())->GetEntryByHandle(m_nHandle); 679 if(!pAuthEntry) 680 return sal_False; 681 Sequence <PropertyValue> aRet(AUTH_FIELD_END); 682 PropertyValue* pValues = aRet.getArray(); 683 for(sal_Int16 i = 0; i < AUTH_FIELD_END; i++) 684 { 685 pValues[i].Name = C2U(aFieldNames[i]); 686 const String& rField = pAuthEntry->GetAuthorField((ToxAuthorityField) i); 687 if(i == AUTH_FIELD_AUTHORITY_TYPE) 688 pValues[i].Value <<= sal_Int16(rField.ToInt32()); 689 else 690 pValues[i].Value <<= OUString(rField); 691 } 692 rAny <<= aRet; 693 return sal_False; 694 } 695 696 sal_Int16 lcl_Find(const OUString& rFieldName) 697 { 698 for(sal_Int16 i = 0; i < AUTH_FIELD_END; i++) 699 if(!rFieldName.compareToAscii(aFieldNames[i])) 700 return i; 701 return -1; 702 } 703 //---------------------------------------------------------------------------- 704 sal_Bool SwAuthorityField::PutValue( const Any& rAny, sal_uInt16 /*nWhichId*/ ) 705 { 706 if(!GetTyp() || !((SwAuthorityFieldType*)GetTyp())->GetEntryByHandle(m_nHandle)) 707 return sal_False; 708 709 Sequence <PropertyValue> aParam; 710 if(!(rAny >>= aParam)) 711 return sal_False; 712 713 String sToSet; 714 sToSet.Fill(AUTH_FIELD_ISBN, TOX_STYLE_DELIMITER); 715 const PropertyValue* pParam = aParam.getConstArray(); 716 for(sal_Int32 i = 0; i < aParam.getLength(); i++) 717 { 718 sal_Int16 nFound = lcl_Find(pParam[i].Name); 719 if(nFound >= 0) 720 { 721 OUString sContent; 722 if(AUTH_FIELD_AUTHORITY_TYPE == nFound) 723 { 724 sal_Int16 nVal = 0; 725 pParam[i].Value >>= nVal; 726 sContent = OUString::valueOf((sal_Int32)nVal); 727 } 728 else 729 pParam[i].Value >>= sContent; 730 sToSet.SetToken(nFound, TOX_STYLE_DELIMITER, sContent); 731 } 732 } 733 734 ((SwAuthorityFieldType*)GetTyp())->RemoveField(m_nHandle); 735 m_nHandle = ((SwAuthorityFieldType*)GetTyp())->AddField(sToSet); 736 737 return sal_False; 738 } 739 740 SwFieldType* SwAuthorityField::ChgTyp( SwFieldType* pFldTyp ) 741 { 742 SwAuthorityFieldType* pSrcTyp = (SwAuthorityFieldType*)GetTyp(), 743 * pDstTyp = (SwAuthorityFieldType*)pFldTyp; 744 if( pSrcTyp != pDstTyp ) 745 { 746 747 const SwAuthEntry* pEntry = pSrcTyp->GetEntryByHandle( m_nHandle ); 748 sal_uInt16 nHdlPos = pDstTyp->AppendField( *pEntry ); 749 pSrcTyp->RemoveField( m_nHandle ); 750 m_nHandle = pDstTyp->GetHandle( nHdlPos ); 751 pDstTyp->AddField( m_nHandle ); 752 SwField::ChgTyp( pFldTyp ); 753 } 754 return pSrcTyp; 755 } 756 757