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