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