merge the formfield patch from ooo-build
[ooovba.git] / sw / source / core / fields / authfld.cxx
blob281de8b636dd4eeb0800b904759de28db394614a
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: authfld.cxx,v $
10 * $Revision: 1.34 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
35 #define _SVSTDARR_STRINGSDTOR
36 #define _SVSTDARR_USHORTS
37 #define _SVSTDARR_LONGS
38 #define _SVSTDARR_ULONGS
39 #include <hintids.hxx>
41 #include <svtools/svstdarr.hxx>
42 #include <svx/unolingu.hxx>
43 #include <svx/langitem.hxx>
44 #include <swtypes.hxx>
45 #include <tools/resid.hxx>
46 #ifndef _COMCORE_HRC
47 #include <comcore.hrc>
48 #endif
49 #include <authfld.hxx>
50 #include <expfld.hxx>
51 #include <pam.hxx>
52 #include <cntfrm.hxx>
53 #include <tox.hxx>
54 #include <txmsrt.hxx>
55 #include <doctxm.hxx>
56 #include <fmtfld.hxx>
57 #include <txtfld.hxx>
58 #include <ndtxt.hxx>
59 #include <doc.hxx>
60 #ifndef _UNOFLDMID_H
61 #include <unofldmid.h>
62 #endif
63 #include <unoprnms.hxx>
65 #include <unomid.h>
67 using namespace ::com::sun::star::uno;
68 using namespace ::com::sun::star::beans;
69 using namespace ::com::sun::star::lang;
70 using rtl::OUString;
73 typedef SwAuthEntry* SwAuthEntryPtr;
74 SV_DECL_PTRARR_DEL( SwAuthDataArr, SwAuthEntryPtr, 5, 5 )
75 SV_IMPL_PTRARR( SwAuthDataArr, SwAuthEntryPtr )
78 typedef SwTOXSortKey* TOXSortKeyPtr;
79 SV_DECL_PTRARR_DEL( SortKeyArr, TOXSortKeyPtr, 5, 5 )
80 SV_IMPL_PTRARR( SortKeyArr, TOXSortKeyPtr )
83 /* -----------------16.09.99 11:53-------------------
85 --------------------------------------------------*/
86 SwAuthEntry::SwAuthEntry(const SwAuthEntry& rCopy)
87 : nRefCount(0)
89 for(USHORT i = 0; i < AUTH_FIELD_END; i++)
90 aAuthFields[i] = rCopy.aAuthFields[i];
92 // --------------------------------------------------------
93 BOOL SwAuthEntry::operator==(const SwAuthEntry& rComp)
95 for(USHORT i = 0; i < AUTH_FIELD_END; i++)
96 if(aAuthFields[i] != rComp.aAuthFields[i])
97 return FALSE;
98 return TRUE;
100 // --------------------------------------------------------
102 /* -----------------14.09.99 16:15-------------------
104 --------------------------------------------------*/
105 SwAuthorityFieldType::SwAuthorityFieldType(SwDoc* pDoc)
106 : SwFieldType( RES_AUTHORITY ),
107 m_pDoc(pDoc),
108 m_pDataArr(new SwAuthDataArr ),
109 m_pSequArr(new SvLongs(5, 5)),
110 m_pSortKeyArr(new SortKeyArr(3, 3)),
111 m_cPrefix('['),
112 m_cSuffix(']'),
113 m_bIsSequence(FALSE),
114 m_bSortByDocument(TRUE),
115 m_eLanguage((LanguageType)::GetAppLanguage())
119 SwAuthorityFieldType::SwAuthorityFieldType( const SwAuthorityFieldType& rFType)
120 : SwFieldType( RES_AUTHORITY ),
121 m_pDataArr(new SwAuthDataArr ),
122 m_pSequArr(new SvLongs(5, 5)),
123 m_pSortKeyArr(new SortKeyArr(3, 3)),
124 m_cPrefix(rFType.m_cPrefix),
125 m_cSuffix(rFType.m_cSuffix),
126 m_bIsSequence(rFType.m_bIsSequence),
127 m_bSortByDocument(rFType.m_bSortByDocument),
128 m_eLanguage(rFType.m_eLanguage),
129 m_sSortAlgorithm(rFType.m_sSortAlgorithm)
131 for(USHORT i = 0; i < rFType.m_pSortKeyArr->Count(); i++)
132 m_pSortKeyArr->Insert((*rFType.m_pSortKeyArr)[i], i);
135 /* -----------------17.09.99 13:52-------------------
137 --------------------------------------------------*/
138 SwAuthorityFieldType::~SwAuthorityFieldType()
140 // DBG_ASSERT(!m_pDataArr->Count(), "Array is not empty");
141 m_pSortKeyArr->DeleteAndDestroy(0, m_pSortKeyArr->Count());
142 delete m_pSortKeyArr;
143 delete m_pSequArr;
144 delete m_pDataArr;
146 /*-- 14.09.99 16:22:09---------------------------------------------------
148 -----------------------------------------------------------------------*/
149 SwFieldType* SwAuthorityFieldType::Copy() const
151 return new SwAuthorityFieldType(m_pDoc);
153 /* -----------------17.09.99 13:43-------------------
155 --------------------------------------------------*/
156 void SwAuthorityFieldType::RemoveField(long nHandle)
158 #ifdef DBG_UTIL
159 BOOL bRemoved = FALSE;
160 #endif
161 for(USHORT j = 0; j < m_pDataArr->Count(); j++)
163 SwAuthEntry* pTemp = m_pDataArr->GetObject(j);
164 long nRet = (long)(void*)pTemp;
165 if(nRet == nHandle)
167 #ifdef DBG_UTIL
168 bRemoved = TRUE;
169 #endif
170 pTemp->RemoveRef();
171 if(!pTemp->GetRefCount())
173 m_pDataArr->DeleteAndDestroy(j, 1);
174 //re-generate positions of the fields
175 DelSequenceArray();
177 break;
180 #ifdef DBG_UTIL
181 DBG_ASSERT(bRemoved, "Field unknown" );
182 #endif
184 /* -----------------17.09.99 13:43-------------------
186 --------------------------------------------------*/
187 long SwAuthorityFieldType::AddField(const String& rFieldContents)
189 long nRet = 0;
190 SwAuthEntry* pEntry = new SwAuthEntry;
191 for( USHORT i = 0; i < AUTH_FIELD_END; ++i )
192 pEntry->SetAuthorField( (ToxAuthorityField)i,
193 rFieldContents.GetToken( i, TOX_STYLE_DELIMITER ));
195 for(USHORT j = 0; j < m_pDataArr->Count() && pEntry; j++)
197 SwAuthEntry* pTemp = m_pDataArr->GetObject(j);
198 if(*pTemp == *pEntry)
200 DELETEZ(pEntry);
201 nRet = (long)(void*)pTemp;
202 pTemp->AddRef();
205 //if it is a new Entry - insert
206 if(pEntry)
208 nRet = (long)(void*)pEntry;
209 pEntry->AddRef();
210 m_pDataArr->Insert(pEntry, m_pDataArr->Count());
211 //re-generate positions of the fields
212 DelSequenceArray();
214 return nRet;
216 /* -----------------17.09.99 14:18-------------------
218 --------------------------------------------------*/
219 BOOL SwAuthorityFieldType::AddField(long nHandle)
221 BOOL bRet = FALSE;
222 for( USHORT j = 0; j < m_pDataArr->Count(); j++ )
224 SwAuthEntry* pTemp = m_pDataArr->GetObject(j);
225 long nTmp = (long)(void*)pTemp;
226 if( nTmp == nHandle )
228 bRet = TRUE;
229 pTemp->AddRef();
230 //re-generate positions of the fields
231 DelSequenceArray();
232 break;
235 DBG_ASSERT(bRet, "::AddField(long) failed");
236 return bRet;
238 /* -----------------17.09.99 14:52-------------------
240 --------------------------------------------------*/
241 const SwAuthEntry* SwAuthorityFieldType::GetEntryByHandle(long nHandle) const
243 const SwAuthEntry* pRet = 0;
244 for(USHORT j = 0; j < m_pDataArr->Count(); j++)
246 const SwAuthEntry* pTemp = m_pDataArr->GetObject(j);
247 long nTmp = (long)(void*)pTemp;
248 if( nTmp == nHandle )
250 pRet = pTemp;
251 break;
254 ASSERT( pRet, "invalid Handle" );
255 return pRet;
257 /* -----------------21.09.99 13:34-------------------
259 --------------------------------------------------*/
260 void SwAuthorityFieldType::GetAllEntryIdentifiers(
261 SvStringsDtor& rToFill )const
263 for(USHORT j = 0; j < m_pDataArr->Count(); j++)
265 SwAuthEntry* pTemp = m_pDataArr->GetObject(j);
266 rToFill.Insert( new String( pTemp->GetAuthorField(
267 AUTH_FIELD_IDENTIFIER )), rToFill.Count() );
270 /* -----------------21.09.99 13:34-------------------
272 --------------------------------------------------*/
273 const SwAuthEntry* SwAuthorityFieldType::GetEntryByIdentifier(
274 const String& rIdentifier)const
276 const SwAuthEntry* pRet = 0;
277 for( USHORT j = 0; j < m_pDataArr->Count(); ++j )
279 const SwAuthEntry* pTemp = m_pDataArr->GetObject(j);
280 if( rIdentifier == pTemp->GetAuthorField( AUTH_FIELD_IDENTIFIER ))
282 pRet = pTemp;
283 break;
286 return pRet;
288 /* -----------------------------21.12.99 13:20--------------------------------
290 ---------------------------------------------------------------------------*/
291 bool SwAuthorityFieldType::ChangeEntryContent(const SwAuthEntry* pNewEntry)
293 bool bChanged = false;
294 for( USHORT j = 0; j < m_pDataArr->Count(); ++j )
296 SwAuthEntry* pTemp = m_pDataArr->GetObject(j);
297 if(pTemp->GetAuthorField(AUTH_FIELD_IDENTIFIER) ==
298 pNewEntry->GetAuthorField(AUTH_FIELD_IDENTIFIER))
300 for(USHORT i = 0; i < AUTH_FIELD_END; i++)
301 pTemp->SetAuthorField((ToxAuthorityField) i,
302 pNewEntry->GetAuthorField((ToxAuthorityField)i));
303 bChanged = true;
304 break;
307 return bChanged;
309 /*-- 11.10.99 08:49:22---------------------------------------------------
310 Description: appends a new entry (if new) and returns the array position
312 -----------------------------------------------------------------------*/
313 USHORT SwAuthorityFieldType::AppendField( const SwAuthEntry& rInsert )
315 USHORT nRet = 0;
316 for( nRet = 0; nRet < m_pDataArr->Count(); ++nRet )
318 SwAuthEntry* pTemp = m_pDataArr->GetObject( nRet );
319 if( *pTemp == rInsert )
321 break;
322 //ref count unchanged
326 //if it is a new Entry - insert
327 if( nRet == m_pDataArr->Count() )
328 m_pDataArr->Insert( new SwAuthEntry( rInsert ), nRet );
330 return nRet;
333 /*-- 11.10.99 08:49:24---------------------------------------------------
335 -----------------------------------------------------------------------*/
336 long SwAuthorityFieldType::GetHandle(USHORT nPos)
338 long nRet = 0;
339 if( nPos < m_pDataArr->Count() )
341 SwAuthEntry* pTemp = m_pDataArr->GetObject(nPos);
342 nRet = (long)(void*)pTemp;
344 return nRet;
346 /* -----------------19.10.99 13:46-------------------
348 --------------------------------------------------*/
349 USHORT SwAuthorityFieldType::GetSequencePos(long nHandle)
351 //find the field in a sorted array of handles,
352 #ifdef DBG_UTIL
353 sal_Bool bCurrentFieldWithoutTextNode = sal_False;
354 #endif
355 if(m_pSequArr->Count() && m_pSequArr->Count() != m_pDataArr->Count())
356 DelSequenceArray();
357 if(!m_pSequArr->Count())
359 SwTOXSortTabBases aSortArr;
360 SwClientIter aIter( *this );
362 SwTOXInternational aIntl(m_eLanguage, 0, m_sSortAlgorithm);
364 for( SwFmtFld* pFmtFld = (SwFmtFld*)aIter.First( TYPE(SwFmtFld) );
365 pFmtFld; pFmtFld = (SwFmtFld*)aIter.Next() )
367 const SwTxtFld* pTxtFld = pFmtFld->GetTxtFld();
368 if(!pTxtFld || !pTxtFld->GetpTxtNode())
370 #ifdef DBG_UTIL
371 if(nHandle == ((SwAuthorityField*)pFmtFld->GetFld())->GetHandle())
372 bCurrentFieldWithoutTextNode = sal_True;
373 #endif
374 continue;
376 const SwTxtNode& rFldTxtNode = pTxtFld->GetTxtNode();
377 SwPosition aFldPos(rFldTxtNode);
378 SwDoc& rDoc = *(SwDoc*)rFldTxtNode.GetDoc();
379 SwCntntFrm *pFrm = rFldTxtNode.GetFrm();
380 const SwTxtNode* pTxtNode = 0;
381 if(pFrm && !pFrm->IsInDocBody())
382 pTxtNode = GetBodyTxtNode( rDoc, aFldPos, *pFrm );
383 //if no text node could be found or the field is in the document
384 //body the directly available text node will be used
385 if(!pTxtNode)
386 pTxtNode = &rFldTxtNode;
387 if( pTxtNode->GetTxt().Len() && pTxtNode->GetFrm() &&
388 pTxtNode->GetNodes().IsDocNodes() )
390 SwTOXAuthority* pNew = new SwTOXAuthority( *pTxtNode,
391 *pFmtFld, aIntl );
393 for(short i = 0; i < aSortArr.Count(); ++i)
395 SwTOXSortTabBase* pOld = aSortArr[i];
396 if(*pOld == *pNew)
398 //only the first occurence in the document
399 //has to be in the array
400 if(*pOld < *pNew)
401 DELETEZ(pNew);
402 else // remove the old content
403 aSortArr.DeleteAndDestroy( i, 1 );
404 break;
407 //if it still exists - insert at the correct position
408 if(pNew)
410 short j;
412 for( j = 0; j < aSortArr.Count(); ++j)
414 SwTOXSortTabBase* pOld = aSortArr[j];
415 if(*pNew < *pOld)
416 break;
418 aSortArr.Insert(pNew, j );
423 for(USHORT i = 0; i < aSortArr.Count(); i++)
425 const SwTOXSortTabBase& rBase = *aSortArr[i];
426 SwFmtFld& rFmtFld = ((SwTOXAuthority&)rBase).GetFldFmt();
427 SwAuthorityField* pAFld = (SwAuthorityField*)rFmtFld.GetFld();
428 m_pSequArr->Insert(pAFld->GetHandle(), i);
430 aSortArr.DeleteAndDestroy(0, aSortArr.Count());
432 //find nHandle
433 USHORT nRet = 0;
434 for(USHORT i = 0; i < m_pSequArr->Count(); i++)
436 if((*m_pSequArr)[i] == nHandle)
438 nRet = i + 1;
439 break;
442 ASSERT(bCurrentFieldWithoutTextNode || nRet, "Handle not found")
443 return nRet;
445 /* -----------------------------15.11.00 17:33--------------------------------
447 ---------------------------------------------------------------------------*/
448 BOOL SwAuthorityFieldType::QueryValue( Any& rVal, USHORT nWhichId ) const
450 switch( nWhichId )
452 case FIELD_PROP_PAR1:
453 case FIELD_PROP_PAR2:
455 OUString sVal;
456 sal_Unicode uRet = FIELD_PROP_PAR1 == nWhichId ? m_cPrefix : m_cSuffix;
457 if(uRet)
458 sVal = OUString(uRet);
459 rVal <<= sVal;
461 break;
462 case FIELD_PROP_PAR3:
463 rVal <<= OUString(GetSortAlgorithm());
464 break;
466 case FIELD_PROP_BOOL1:
467 case FIELD_PROP_BOOL2:
469 sal_Bool bVal = FIELD_PROP_BOOL1 == nWhichId ? m_bIsSequence: m_bSortByDocument;
470 rVal.setValue(&bVal, ::getBooleanCppuType());
472 break;
474 case FIELD_PROP_LOCALE:
475 rVal <<= SvxCreateLocale(GetLanguage());
476 break;
478 case FIELD_PROP_PROP_SEQ:
480 Sequence<PropertyValues> aRet(m_pSortKeyArr->Count());
481 PropertyValues* pValues = aRet.getArray();
482 OUString sProp1( C2U(SW_PROP_NAME_STR(UNO_NAME_SORT_KEY)) ),
483 sProp2( C2U(SW_PROP_NAME_STR(UNO_NAME_IS_SORT_ASCENDING)));
484 for(sal_uInt16 i = 0; i < m_pSortKeyArr->Count(); i++)
486 const SwTOXSortKey* pKey = (*m_pSortKeyArr)[i];
487 pValues[i].realloc(2);
488 PropertyValue* pValue = pValues[i].getArray();
489 pValue[0].Name = sProp1;
490 pValue[0].Value <<= sal_Int16(pKey->eField);
491 pValue[1].Name = sProp2;
492 pValue[1].Value.setValue(&pKey->bSortAscending, ::getBooleanCppuType());
494 rVal <<= aRet;
496 break;
497 default:
498 DBG_ERROR("illegal property");
500 return TRUE;
502 /* -----------------------------15.11.00 17:33--------------------------------
504 ---------------------------------------------------------------------------*/
505 BOOL SwAuthorityFieldType::PutValue( const Any& rAny, USHORT nWhichId )
507 sal_Bool bRet = TRUE;
508 String sTmp;
509 switch( nWhichId )
511 case FIELD_PROP_PAR1:
512 case FIELD_PROP_PAR2:
514 ::GetString( rAny, sTmp );
515 sal_Unicode uSet = sTmp.GetChar(0);
516 if( FIELD_PROP_PAR1 == nWhichId )
517 m_cPrefix = uSet;
518 else
519 m_cSuffix = uSet;
521 break;
522 case FIELD_PROP_PAR3:
523 SetSortAlgorithm( ::GetString( rAny, sTmp ));
524 break;
526 case FIELD_PROP_BOOL1:
527 m_bIsSequence = *(sal_Bool*)rAny.getValue();
528 break;
529 case FIELD_PROP_BOOL2:
530 m_bSortByDocument = *(sal_Bool*)rAny.getValue();
531 break;
533 case FIELD_PROP_LOCALE:
535 Locale aLocale;
536 if( 0 != (bRet = rAny >>= aLocale ))
537 SetLanguage( SvxLocaleToLanguage( aLocale ));
539 break;
541 case FIELD_PROP_PROP_SEQ:
543 Sequence<PropertyValues> aSeq;
544 if( 0 != (bRet = rAny >>= aSeq) )
546 m_pSortKeyArr->DeleteAndDestroy(0, m_pSortKeyArr->Count());
547 const PropertyValues* pValues = aSeq.getConstArray();
548 for(sal_Int32 i = 0; i < aSeq.getLength() && i < USHRT_MAX / 4; i++)
550 const PropertyValue* pValue = pValues[i].getConstArray();
551 SwTOXSortKey* pSortKey = new SwTOXSortKey;
552 for(sal_Int32 j = 0; j < pValues[i].getLength(); j++)
554 if(pValue[j].Name.equalsAsciiL(SW_PROP_NAME(UNO_NAME_SORT_KEY)))
556 sal_Int16 nVal = -1; pValue[j].Value >>= nVal;
557 if(nVal >= 0 && nVal < AUTH_FIELD_END)
558 pSortKey->eField = (ToxAuthorityField) nVal;
559 else
560 bRet = FALSE;
562 else if(pValue[j].Name.equalsAsciiL(SW_PROP_NAME(UNO_NAME_IS_SORT_ASCENDING)))
564 pSortKey->bSortAscending = *(sal_Bool*)pValue[j].Value.getValue();
567 m_pSortKeyArr->Insert(pSortKey, m_pSortKeyArr->Count());
571 break;
572 default:
573 DBG_ERROR("illegal property");
575 return bRet;
577 /* -----------------19.10.99 13:25-------------------
579 --------------------------------------------------*/
580 void SwAuthorityFieldType::Modify( SfxPoolItem *pOld, SfxPoolItem *pNew )
582 //re-generate positions of the fields
583 DelSequenceArray();
584 SwModify::Modify( pOld, pNew );
586 /* -----------------20.10.99 13:38-------------------
588 --------------------------------------------------*/
589 USHORT SwAuthorityFieldType::GetSortKeyCount() const
591 return m_pSortKeyArr->Count();
593 /* -----------------20.10.99 13:38-------------------
595 --------------------------------------------------*/
596 const SwTOXSortKey* SwAuthorityFieldType::GetSortKey(USHORT nIdx) const
598 SwTOXSortKey* pRet = 0;
599 if(m_pSortKeyArr->Count() > nIdx)
600 pRet = (*m_pSortKeyArr)[nIdx];
601 DBG_ASSERT(pRet, "Sort key not found");
602 return pRet;
604 /* -----------------20.10.99 13:38-------------------
606 --------------------------------------------------*/
607 void SwAuthorityFieldType::SetSortKeys(USHORT nKeyCount, SwTOXSortKey aKeys[])
609 m_pSortKeyArr->DeleteAndDestroy(0, m_pSortKeyArr->Count());
610 USHORT nArrIdx = 0;
611 for(USHORT i = 0; i < nKeyCount; i++)
612 if(aKeys[i].eField < AUTH_FIELD_END)
613 m_pSortKeyArr->Insert(new SwTOXSortKey(aKeys[i]), nArrIdx++);
616 /* -----------------14.09.99 16:15-------------------
618 --------------------------------------------------*/
619 SwAuthorityField::SwAuthorityField( SwAuthorityFieldType* pInitType,
620 const String& rFieldContents )
621 : SwField(pInitType),
622 m_nTempSequencePos( -1 )
624 m_nHandle = pInitType->AddField( rFieldContents );
626 /* -----------------17.09.99 14:24-------------------
628 --------------------------------------------------*/
629 SwAuthorityField::SwAuthorityField( SwAuthorityFieldType* pInitType,
630 long nSetHandle )
631 : SwField( pInitType ),
632 m_nHandle( nSetHandle ),
633 m_nTempSequencePos( -1 )
635 pInitType->AddField( m_nHandle );
637 /* -----------------15.09.99 15:00-------------------
639 --------------------------------------------------*/
640 SwAuthorityField::~SwAuthorityField()
642 ((SwAuthorityFieldType* )GetTyp())->RemoveField(m_nHandle);
644 /*-- 14.09.99 16:20:59---------------------------------------------------
646 -----------------------------------------------------------------------*/
647 String SwAuthorityField::Expand() const
649 SwAuthorityFieldType* pAuthType = (SwAuthorityFieldType*)GetTyp();
650 String sRet;
651 if(pAuthType->GetPrefix())
652 sRet.Assign(pAuthType->GetPrefix());
654 if( pAuthType->IsSequence() )
656 if(!pAuthType->GetDoc()->IsExpFldsLocked())
657 m_nTempSequencePos = pAuthType->GetSequencePos( m_nHandle );
658 if( m_nTempSequencePos >= 0 )
659 sRet += String::CreateFromInt32( m_nTempSequencePos );
661 else
663 const SwAuthEntry* pEntry = pAuthType->GetEntryByHandle(m_nHandle);
664 //TODO: Expand to: identifier, number sequence, ...
665 if(pEntry)
666 sRet += pEntry->GetAuthorField(AUTH_FIELD_IDENTIFIER);
668 if(pAuthType->GetSuffix())
669 sRet += pAuthType->GetSuffix();
670 return sRet;
672 /*-- 14.09.99 16:21:00---------------------------------------------------
674 -----------------------------------------------------------------------*/
675 SwField* SwAuthorityField::Copy() const
677 SwAuthorityFieldType* pAuthType = (SwAuthorityFieldType*)GetTyp();
678 return new SwAuthorityField(pAuthType, m_nHandle);
680 /* -----------------21.09.99 12:55-------------------
682 --------------------------------------------------*/
683 const String& SwAuthorityField::GetFieldText(ToxAuthorityField eField) const
685 SwAuthorityFieldType* pAuthType = (SwAuthorityFieldType*)GetTyp();
686 const SwAuthEntry* pEntry = pAuthType->GetEntryByHandle( m_nHandle );
687 return pEntry->GetAuthorField( eField );
689 /* -----------------21.09.99 14:57-------------------
691 --------------------------------------------------*/
692 void SwAuthorityField::SetPar1(const String& rStr)
694 SwAuthorityFieldType* pInitType = (SwAuthorityFieldType* )GetTyp();
695 pInitType->RemoveField(m_nHandle);
696 m_nHandle = pInitType->AddField(rStr);
698 /* -----------------11.10.99 09:43-------------------
700 --------------------------------------------------*/
701 String SwAuthorityField::GetDescription() const
703 return SW_RES(STR_AUTHORITY_ENTRY);
708 /* -----------------------------15.11.00 17:33--------------------------------
710 ---------------------------------------------------------------------------*/
711 const char* aFieldNames[] =
713 "Identifier",
714 "BibiliographicType",
715 "Address",
716 "Annote",
717 "Author",
718 "Booktitle",
719 "Chapter",
720 "Edition",
721 "Editor",
722 "Howpublished",
723 "Institution",
724 "Journal",
725 "Month",
726 "Note",
727 "Number",
728 "Organizations",
729 "Pages",
730 "Publisher",
731 "School",
732 "Series",
733 "Title",
734 "Report_Type",
735 "Volume",
736 "Year",
737 "URL",
738 "Custom1",
739 "Custom2",
740 "Custom3",
741 "Custom4",
742 "Custom5",
743 "ISBN"
745 /* -----------------------------16.11.00 12:27--------------------------------
747 ---------------------------------------------------------------------------*/
748 BOOL SwAuthorityField::QueryValue( Any& rAny, USHORT /*nWhichId*/ ) const
750 if(!GetTyp())
751 return FALSE;
752 const SwAuthEntry* pAuthEntry = ((SwAuthorityFieldType*)GetTyp())->GetEntryByHandle(m_nHandle);
753 if(!pAuthEntry)
754 return FALSE;
755 Sequence <PropertyValue> aRet(AUTH_FIELD_END);
756 PropertyValue* pValues = aRet.getArray();
757 for(sal_Int16 i = 0; i < AUTH_FIELD_END; i++)
759 pValues[i].Name = C2U(aFieldNames[i]);
760 const String& rField = pAuthEntry->GetAuthorField((ToxAuthorityField) i);
761 if(i == AUTH_FIELD_AUTHORITY_TYPE)
762 pValues[i].Value <<= sal_Int16(rField.ToInt32());
763 else
764 pValues[i].Value <<= OUString(rField);
766 rAny <<= aRet;
767 return FALSE;
769 /* -----------------------------15.11.00 17:33--------------------------------
771 ---------------------------------------------------------------------------*/
772 sal_Int16 lcl_Find(const OUString& rFieldName)
774 for(sal_Int16 i = 0; i < AUTH_FIELD_END; i++)
775 if(!rFieldName.compareToAscii(aFieldNames[i]))
776 return i;
777 return -1;
779 //----------------------------------------------------------------------------
780 BOOL SwAuthorityField::PutValue( const Any& rAny, USHORT /*nWhichId*/ )
782 if(!GetTyp() || !((SwAuthorityFieldType*)GetTyp())->GetEntryByHandle(m_nHandle))
783 return FALSE;
785 Sequence <PropertyValue> aParam;
786 if(!(rAny >>= aParam))
787 return FALSE;
789 String sToSet;
790 sToSet.Fill(AUTH_FIELD_ISBN, TOX_STYLE_DELIMITER);
791 const PropertyValue* pParam = aParam.getConstArray();
792 for(sal_Int32 i = 0; i < aParam.getLength(); i++)
794 sal_Int16 nFound = lcl_Find(pParam[i].Name);
795 if(nFound >= 0)
797 OUString sContent;
798 if(AUTH_FIELD_AUTHORITY_TYPE == nFound)
800 sal_Int16 nVal = 0;
801 pParam[i].Value >>= nVal;
802 sContent = OUString::valueOf((sal_Int32)nVal);
804 else
805 pParam[i].Value >>= sContent;
806 sToSet.SetToken(nFound, TOX_STYLE_DELIMITER, sContent);
810 ((SwAuthorityFieldType*)GetTyp())->RemoveField(m_nHandle);
811 m_nHandle = ((SwAuthorityFieldType*)GetTyp())->AddField(sToSet);
813 return FALSE;
815 /* -----------------11.10.99 09:43-------------------
817 --------------------------------------------------*/
818 SwFieldType* SwAuthorityField::ChgTyp( SwFieldType* pFldTyp )
820 SwAuthorityFieldType* pSrcTyp = (SwAuthorityFieldType*)GetTyp(),
821 * pDstTyp = (SwAuthorityFieldType*)pFldTyp;
822 if( pSrcTyp != pDstTyp )
825 const SwAuthEntry* pEntry = pSrcTyp->GetEntryByHandle( m_nHandle );
826 USHORT nHdlPos = pDstTyp->AppendField( *pEntry );
827 pSrcTyp->RemoveField( m_nHandle );
828 m_nHandle = pDstTyp->GetHandle( nHdlPos );
829 pDstTyp->AddField( m_nHandle );
830 SwField::ChgTyp( pFldTyp );
832 return pSrcTyp;