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