LibreOffice Module sw (master)  1
fldbas.cxx
Go to the documentation of this file.
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 <fldbas.hxx>
21 
22 #include <float.h>
23 #include <math.h>
24 
25 #include <libxml/xmlwriter.h>
26 
27 #include <rtl/math.hxx>
28 #include <svl/zforlist.hxx>
29 #include <svl/zformat.hxx>
30 #include <editeng/unolingu.hxx>
31 #include <o3tl/enumarray.hxx>
32 #include <unofldmid.h>
33 #include <doc.hxx>
34 #include <editsh.hxx>
35 #include <frame.hxx>
36 #include <flddat.hxx>
37 #include <ndtxt.hxx>
38 #include <fmtfld.hxx>
39 #include <txtfld.hxx>
40 #include <pam.hxx>
41 #include <docfld.hxx>
42 #include <swtable.hxx>
43 #include <docufld.hxx>
44 #include <expfld.hxx>
45 #include <shellres.hxx>
46 #include <calc.hxx>
47 #include <strings.hrc>
48 #include <docary.hxx>
49 #include <authfld.hxx>
50 #include <calbck.hxx>
51 
52 using namespace ::com::sun::star;
53 using namespace nsSwDocInfoSubType;
54 
56  const SvNumberFormatter& rFormatter )
57 {
58  if( nLng == LANGUAGE_NONE ) // Bug #60010
59  nLng = LANGUAGE_SYSTEM;
60  else if( nLng == ::GetAppLanguage() )
61  switch( rFormatter.GetIndexTableOffset( nFormat ))
62  {
63  case NF_NUMBER_SYSTEM:
67  nLng = LANGUAGE_SYSTEM;
68  break;
69  default: break;
70  }
71  return nLng;
72 }
73 
74 // Globals
75 
77 std::vector<OUString>* SwFieldType::s_pFieldNames = nullptr;
78 
79 namespace
80 {
81 
83  /* SwFieldIds::Database */ TYP_DBFLD,
84  /* SwFieldIds::User */ TYP_USERFLD,
85  /* SwFieldIds::Filename */ TYP_FILENAMEFLD,
86  /* SwFieldIds::DatabaseName */ TYP_DBNAMEFLD,
87  /* SwFieldIds::Date */ TYP_DATEFLD,
88  /* SwFieldIds::Time */ TYP_TIMEFLD,
89  /* SwFieldIds::PageNumber */ TYP_PAGENUMBERFLD, // dynamic
90  /* SwFieldIds::Author */ TYP_AUTHORFLD,
91  /* SwFieldIds::Chapter */ TYP_CHAPTERFLD,
92  /* SwFieldIds::DocStat */ TYP_DOCSTATFLD,
93  /* SwFieldIds::GetExp */ TYP_GETFLD, // dynamic
94  /* SwFieldIds::SetExp */ TYP_SETFLD, // dynamic
95  /* SwFieldIds::GetRef */ TYP_GETREFFLD,
96  /* SwFieldIds::HiddenText */ TYP_HIDDENTXTFLD,
97  /* SwFieldIds::Postit */ TYP_POSTITFLD,
98  /* SwFieldIds::FixDate */ TYP_FIXDATEFLD,
99  /* SwFieldIds::FixTime */ TYP_FIXTIMEFLD,
100  /* SwFieldIds::Reg */ TYP_BEGIN, // old (no change since 2000)
101  /* SwFieldIds::VarReg */ TYP_BEGIN, // old (no change since 2000)
102  /* SwFieldIds::SetRef */ TYP_SETREFFLD,
103  /* SwFieldIds::Input */ TYP_INPUTFLD,
104  /* SwFieldIds::Macro */ TYP_MACROFLD,
105  /* SwFieldIds::Dde */ TYP_DDEFLD,
106  /* SwFieldIds::Table */ TYP_FORMELFLD,
107  /* SwFieldIds::HiddenPara */ TYP_HIDDENPARAFLD,
108  /* SwFieldIds::DocInfo */ TYP_DOCINFOFLD,
109  /* SwFieldIds::TemplateName */ TYP_TEMPLNAMEFLD,
110  /* SwFieldIds::DbNextSet */ TYP_DBNEXTSETFLD,
111  /* SwFieldIds::DbNumSet */ TYP_DBNUMSETFLD,
112  /* SwFieldIds::DbSetNumber */ TYP_DBSETNUMBERFLD,
113  /* SwFieldIds::ExtUser */ TYP_EXTUSERFLD,
114  /* SwFieldIds::RefPageSet */ TYP_SETREFPAGEFLD,
115  /* SwFieldIds::RefPageGet */ TYP_GETREFPAGEFLD,
116  /* SwFieldIds::Internet */ TYP_INTERNETFLD,
117  /* SwFieldIds::JumpEdit */ TYP_JUMPEDITFLD,
118  /* SwFieldIds::Script */ TYP_SCRIPTFLD,
119  /* SwFieldIds::DateTime */ TYP_BEGIN, // dynamic
120  /* SwFieldIds::TableOfAuthorities*/ TYP_AUTHORITY,
121  /* SwFieldIds::CombinedChars */ TYP_COMBINED_CHARS,
122  /* SwFieldIds::Dropdown */ TYP_DROPDOWN,
123  /* SwFieldIds::ParagraphSignature */ TYP_PARAGRAPHSIGFLD
124  };
125 
126 }
127 
128 OUString SwFieldType::GetTypeStr(sal_uInt16 nTypeId)
129 {
130  if (!s_pFieldNames)
131  GetFieldName_();
132 
133  if (nTypeId < SwFieldType::s_pFieldNames->size())
134  return (*SwFieldType::s_pFieldNames)[nTypeId];
135  return OUString();
136 }
137 
138 // each field references a field type that is unique for each document
140  : SwModify(nullptr)
141  , m_nWhich(nWhichId)
142 {
143 }
144 
145 OUString SwFieldType::GetName() const
146 {
147  return OUString();
148 }
149 
150 void SwFieldType::QueryValue( uno::Any&, sal_uInt16 ) const
151 {
152 }
153 void SwFieldType::PutValue( const uno::Any& , sal_uInt16 )
154 {
155 }
156 
158 {
160  if (!aIter.First())
161  return;
162  xmlTextWriterStartElement(pWriter, BAD_CAST("SwFieldType"));
163  for (const SwFormatField* pFormatField = aIter.First(); pFormatField;
164  pFormatField = aIter.Next())
165  pFormatField->dumpAsXml(pWriter);
166  xmlTextWriterEndElement(pWriter);
167 }
168 
170 {
171  xmlTextWriterStartElement(pWriter, BAD_CAST("SwFieldTypes"));
172  sal_uInt16 nCount = size();
173  for (sal_uInt16 nType = 0; nType < nCount; ++nType)
174  (*this)[nType]->dumpAsXml(pWriter);
175  xmlTextWriterEndElement(pWriter);
176 }
177 
178 // Base class for all fields.
179 // A field (multiple can exist) references a field type (can exists only once)
181  SwFieldType* pType,
182  sal_uInt32 nFormat,
184  bool bUseFieldValueCache)
185  : m_Cache()
186  , m_bUseFieldValueCache( bUseFieldValueCache )
187  , m_nLang( nLang )
188  , m_bIsAutomaticLanguage( true )
189  , m_nFormat( nFormat )
190  , m_pType( pType )
191 {
192  assert(m_pType);
193 }
194 
196 {
197 }
198 
199 // instead of indirectly via the type
200 
201 #ifdef DBG_UTIL
203 {
204  assert(m_pType);
205  return m_pType->Which();
206 }
207 #endif
208 
209 sal_uInt16 SwField::GetTypeId() const
210 {
211 
212  sal_uInt16 nRet;
213  switch (m_pType->Which())
214  {
216  if (GetSubType() & FIXEDFLD)
217  nRet = static_cast<sal_uInt16>(GetSubType() & DATEFLD ? TYP_FIXDATEFLD : TYP_FIXTIMEFLD);
218  else
219  nRet = static_cast<sal_uInt16>(GetSubType() & DATEFLD ? TYP_DATEFLD : TYP_TIMEFLD);
220  break;
221  case SwFieldIds::GetExp:
222  nRet = static_cast<sal_uInt16>(nsSwGetSetExpType::GSE_FORMULA & GetSubType() ? TYP_FORMELFLD : TYP_GETFLD);
223  break;
224 
226  nRet = GetSubType();
227  break;
228 
229  case SwFieldIds::SetExp:
231  nRet = TYP_SEQFLD;
232  else if( static_cast<const SwSetExpField*>(this)->GetInputFlag() )
233  nRet = TYP_SETINPFLD;
234  else
235  nRet = TYP_SETFLD;
236  break;
237 
239  nRet = GetSubType();
240  if( PG_NEXT == nRet )
241  nRet = TYP_NEXTPAGEFLD;
242  else if( PG_PREV == nRet )
243  nRet = TYP_PREVPAGEFLD;
244  else
245  nRet = TYP_PAGENUMBERFLD;
246  break;
247 
248  default:
249  nRet = aTypeTab[ m_pType->Which() ];
250  }
251  return nRet;
252 }
253 
255 OUString SwField::GetFieldName() const
256 {
257  sal_uInt16 nTypeId = GetTypeId();
258  if (SwFieldIds::DateTime == GetTyp()->Which())
259  {
260  nTypeId = static_cast<sal_uInt16>(
261  ((GetSubType() & DATEFLD) != 0) ? TYP_DATEFLD : TYP_TIMEFLD);
262  }
263  OUString sRet = SwFieldType::GetTypeStr( nTypeId );
264  if (IsFixed())
265  {
266  sRet += " " + SwViewShell::GetShellRes()->aFixedStr;
267  }
268  return sRet;
269 }
270 
271 OUString SwField::GetPar1() const
272 {
273  return OUString();
274 }
275 
276 OUString SwField::GetPar2() const
277 {
278  return OUString();
279 }
280 
281 OUString SwField::GetFormula() const
282 {
283  return GetPar2();
284 }
285 
286 void SwField::SetPar1(const OUString& )
287 {}
288 
289 void SwField::SetPar2(const OUString& )
290 {}
291 
292 sal_uInt16 SwField::GetSubType() const
293 {
294  return 0;
295 }
296 
297 void SwField::SetSubType(sal_uInt16 )
298 {
299 }
300 
301 bool SwField::QueryValue( uno::Any& rVal, sal_uInt16 nWhichId ) const
302 {
303  switch( nWhichId )
304  {
305  case FIELD_PROP_BOOL4:
306  rVal <<= !m_bIsAutomaticLanguage;
307  break;
308  default:
309  assert(false);
310  }
311  return true;
312 }
313 
314 bool SwField::PutValue( const uno::Any& rVal, sal_uInt16 nWhichId )
315 {
316  switch( nWhichId )
317  {
318  case FIELD_PROP_BOOL4:
319  {
320  bool bFixed = false;
321  if(rVal >>= bFixed)
322  m_bIsAutomaticLanguage = !bFixed;
323  }
324  break;
325  default:
326  assert(false);
327  }
328  return true;
329 }
330 
339 {
340  assert(pNewType && pNewType->Which() == m_pType->Which());
341 
342  SwFieldType* pOld = m_pType;
343  m_pType = pNewType;
344  return pOld;
345 }
346 
349 {
350  bool bRet = false;
351  switch (m_pType->Which())
352  {
355  case SwFieldIds::GetRef:
356  case SwFieldIds::Macro:
357  case SwFieldIds::Input:
358  case SwFieldIds::Dropdown :
359  bRet = true;
360  break;
361 
362  case SwFieldIds::SetExp:
363  bRet = static_cast<const SwSetExpField*>(this)->GetInputFlag();
364  break;
365  default: break;
366  }
367  return bRet;
368 }
369 
371 {
372  m_nLang = nLang;
373 }
374 
375 void SwField::ChangeFormat(sal_uInt32 const nFormat)
376 {
377  m_nFormat = nFormat;
378 }
379 
380 bool SwField::IsFixed() const
381 {
382  bool bRet = false;
383  switch (m_pType->Which())
384  {
385  case SwFieldIds::FixDate:
386  case SwFieldIds::FixTime:
387  bRet = true;
388  break;
389 
391  bRet = 0 != (GetSubType() & FIXEDFLD);
392  break;
393 
394  case SwFieldIds::ExtUser:
395  case SwFieldIds::Author:
396  bRet = 0 != (GetFormat() & AF_FIXED);
397  break;
398 
400  bRet = 0 != (GetFormat() & FF_FIXED);
401  break;
402 
403  case SwFieldIds::DocInfo:
404  bRet = 0 != (GetSubType() & DI_SUB_FIXED);
405  break;
406  default: break;
407  }
408  return bRet;
409 }
410 
411 OUString
412 SwField::ExpandField(bool const bCached, SwRootFrame const*const pLayout) const
413 {
414  if ( m_bUseFieldValueCache )
415  {
416  if (!bCached) // #i85766# do not expand fields in clipboard documents
417  {
418  if (GetTypeId() == TYP_AUTHORITY)
419  {
420  const SwAuthorityField* pAuthorityField = static_cast<const SwAuthorityField*>(this);
421  m_Cache = pAuthorityField->ConditionalExpandAuthIdentifier(pLayout);
422  }
423  else
424  m_Cache = ExpandImpl(pLayout);
425  }
426  return m_Cache;
427  }
428 
429  return ExpandImpl(pLayout);
430 }
431 
432 std::unique_ptr<SwField> SwField::CopyField() const
433 {
434  std::unique_ptr<SwField> pNew = Copy();
435  // #i85766# cache expansion of source (for clipboard)
436  // use this->cache, not this->Expand(): only text formatting calls Expand()
437  pNew->m_Cache = m_Cache;
438  pNew->m_bUseFieldValueCache = m_bUseFieldValueCache;
439 
440  return pNew;
441 }
442 
444 OUString FormatNumber(sal_uInt32 nNum, SvxNumType nFormat, LanguageType nLang)
445 {
446  if(SVX_NUM_PAGEDESC == nFormat)
447  return OUString::number( nNum );
448  SvxNumberType aNumber;
449 
450  OSL_ENSURE(nFormat != SVX_NUM_NUMBER_NONE, "wrong number format" );
451 
452  aNumber.SetNumberingType(nFormat);
453 
454  if (nLang == LANGUAGE_NONE)
455  return aNumber.GetNumStr(nNum);
456  else
457  return aNumber.GetNumStr(nNum, LanguageTag::convertToLocale(nLang));
458 }
459 
461  : SwFieldType(nWhichId)
462  , m_pDoc(pDoc)
463  , m_bUseFormat(true)
464 {
465 }
466 
468  : SwFieldType(rTyp.Which())
469  , m_pDoc(rTyp.GetDoc())
470  , m_bUseFormat(rTyp.UseFormat())
471 {
472 }
473 
475 OUString SwValueFieldType::ExpandValue( const double& rVal,
476  sal_uInt32 nFormat, LanguageType nLng) const
477 {
478  if (rVal >= DBL_MAX) // error string for calculator
480 
481  OUString sExpand;
483  Color* pCol = nullptr;
484 
485  // Bug #60010
486  LanguageType nFormatLng = ::lcl_GetLanguageOfFormat( nLng, nFormat, *pFormatter );
487 
488  if( nFormat < SV_COUNTRY_LANGUAGE_OFFSET && LANGUAGE_SYSTEM != nFormatLng )
489  {
490  SvNumFormatType nType = SvNumFormatType::DEFINED;
491  sal_Int32 nDummy;
492 
493  const SvNumberformat* pEntry = pFormatter->GetEntry(nFormat);
494 
495  if (pEntry && nLng != pEntry->GetLanguage())
496  {
497  sal_uInt32 nNewFormat = pFormatter->GetFormatForLanguageIfBuiltIn(nFormat,
498  nFormatLng);
499 
500  if (nNewFormat == nFormat)
501  {
502  // probably user-defined format
503  OUString sFormat(pEntry->GetFormatstring());
504 
505  pFormatter->PutandConvertEntry(sFormat, nDummy, nType, nFormat,
506  pEntry->GetLanguage(), nFormatLng, false);
507  }
508  else
509  nFormat = nNewFormat;
510  }
511  OSL_ENSURE(pEntry, "unknown number format!");
512  }
513 
514  if( pFormatter->IsTextFormat( nFormat ) )
515  {
516  pFormatter->GetOutputString(DoubleToString(rVal, nFormatLng), nFormat,
517  sExpand, &pCol);
518  }
519  else
520  {
521  pFormatter->GetOutputString(rVal, nFormat, sExpand, &pCol);
522  }
523  return sExpand;
524 }
525 
526 OUString SwValueFieldType::DoubleToString(const double &rVal,
527  sal_uInt32 nFormat) const
528 {
530  const SvNumberformat* pEntry = pFormatter->GetEntry(nFormat);
531 
532  if (!pEntry)
533  return OUString();
534 
535  return DoubleToString(rVal, pEntry->GetLanguage());
536 }
537 
538 OUString SwValueFieldType::DoubleToString( const double &rVal,
539  LanguageType nLng ) const
540 {
542 
543  // Bug #60010
544  if( nLng == LANGUAGE_NONE )
545  nLng = LANGUAGE_SYSTEM;
546 
547  pFormatter->ChangeIntl( nLng ); // get separator in the correct language
548  return ::rtl::math::doubleToUString( rVal, rtl_math_StringFormat_F, 12,
549  pFormatter->GetNumDecimalSep()[0], true );
550 }
551 
552 SwValueField::SwValueField( SwValueFieldType* pFieldType, sal_uInt32 nFormat,
553  LanguageType nLng, const double fVal )
554  : SwField(pFieldType, nFormat, nLng)
555  , m_fValue(fVal)
556 {
557 }
558 
560  : SwField(rField)
561  , m_fValue(rField.GetValue())
562 {
563 }
564 
566 {
567 }
568 
577 {
578  SwDoc* pNewDoc = static_cast<SwValueFieldType *>(pNewType)->GetDoc();
579  SwDoc* pDoc = GetDoc();
580 
581  if( pNewDoc && pDoc && pDoc != pNewDoc)
582  {
583  SvNumberFormatter* pFormatter = pNewDoc->GetNumberFormatter();
584 
585  if( pFormatter && pFormatter->HasMergeFormatTable() &&
586  static_cast<SwValueFieldType *>(GetTyp())->UseFormat() )
587  SetFormat(pFormatter->GetMergeFormatIndex( GetFormat() ));
588  }
589 
590  return SwField::ChgTyp(pNewType);
591 }
592 
594 sal_uInt32 SwValueField::GetSystemFormat(SvNumberFormatter* pFormatter, sal_uInt32 nFormat)
595 {
596  const SvNumberformat* pEntry = pFormatter->GetEntry(nFormat);
598 
599  if (pEntry && nLng != pEntry->GetLanguage())
600  {
601  sal_uInt32 nNewFormat = pFormatter->GetFormatForLanguageIfBuiltIn(nFormat,
602  nLng);
603 
604  if (nNewFormat == nFormat)
605  {
606  // probably user-defined format
607  SvNumFormatType nType = SvNumFormatType::DEFINED;
608  sal_Int32 nDummy;
609 
610  OUString sFormat(pEntry->GetFormatstring());
611 
612  sal_uInt32 nTempFormat = nFormat;
613  pFormatter->PutandConvertEntry(sFormat, nDummy, nType,
614  nTempFormat, pEntry->GetLanguage(), nLng, true);
615  nFormat = nTempFormat;
616  }
617  else
618  nFormat = nNewFormat;
619  }
620 
621  return nFormat;
622 }
623 
625 {
626  xmlTextWriterStartElement(pWriter, BAD_CAST("SwValueField"));
627  xmlTextWriterWriteAttribute(pWriter, BAD_CAST("m_fValue"), BAD_CAST(OString::number(m_fValue).getStr()));
628  SwField::dumpAsXml(pWriter);
629  xmlTextWriterEndElement(pWriter);
630 }
631 
634 {
635  if( IsAutomaticLanguage() &&
636  static_cast<SwValueFieldType *>(GetTyp())->UseFormat() &&
638  {
639  // Bug #60010
640  SvNumberFormatter* pFormatter = GetDoc()->GetNumberFormatter();
641  LanguageType nFormatLng = ::lcl_GetLanguageOfFormat( nLng, GetFormat(),
642  *pFormatter );
643 
645  LANGUAGE_SYSTEM != nFormatLng ) &&
647  {
648  const SvNumberformat* pEntry = pFormatter->GetEntry(GetFormat());
649 
650  if( pEntry && nFormatLng != pEntry->GetLanguage() )
651  {
652  sal_uInt32 nNewFormat = pFormatter->GetFormatForLanguageIfBuiltIn(
653  GetFormat(), nFormatLng );
654 
655  if( nNewFormat == GetFormat() )
656  {
657  // probably user-defined format
658  SvNumFormatType nType = SvNumFormatType::DEFINED;
659  sal_Int32 nDummy;
660  OUString sFormat( pEntry->GetFormatstring() );
661  pFormatter->PutandConvertEntry( sFormat, nDummy, nType,
662  nNewFormat,
663  pEntry->GetLanguage(),
664  nFormatLng, false);
665  }
666  SetFormat( nNewFormat );
667  }
668  OSL_ENSURE(pEntry, "unknown number format!");
669  }
670  }
671 
672  SwField::SetLanguage(nLng);
673 }
674 
676 {
677  return m_fValue;
678 }
679 
680 void SwValueField::SetValue( const double& rVal )
681 {
682  m_fValue = rVal;
683 }
684 
685 SwFormulaField::SwFormulaField( SwValueFieldType* pFieldType, sal_uInt32 nFormat, const double fVal)
686  : SwValueField(pFieldType, nFormat, LANGUAGE_SYSTEM, fVal)
687 {
688 }
689 
691  : SwValueField(static_cast<SwValueFieldType *>(rField.GetTyp()), rField.GetFormat(),
692  rField.GetLanguage(), rField.GetValue())
693 {
694 }
695 
697 {
698  return m_sFormula;
699 }
700 
701 void SwFormulaField::SetFormula(const OUString& rStr)
702 {
703  m_sFormula = rStr;
704 
705  sal_uLong nFormat(GetFormat());
706 
707  if( nFormat && SAL_MAX_UINT32 != nFormat )
708  {
709  sal_Int32 nPos = 0;
710  double fTmpValue;
711  if( SwCalc::Str2Double( rStr, nPos, fTmpValue, GetDoc() ) )
712  SwValueField::SetValue( fTmpValue );
713  }
714 }
715 
716 void SwFormulaField::SetExpandedFormula( const OUString& rStr )
717 {
718  sal_uInt32 nFormat(GetFormat());
719 
720  if (nFormat && nFormat != SAL_MAX_UINT32 && static_cast<SwValueFieldType *>(GetTyp())->UseFormat())
721  {
722  double fTmpValue;
723 
724  if (GetDoc()->IsNumberFormat(rStr, nFormat, fTmpValue))
725  {
726  SwValueField::SetValue(fTmpValue);
727 
728  m_sFormula = static_cast<SwValueFieldType *>(GetTyp())->DoubleToString(fTmpValue, nFormat);
729  return;
730  }
731  }
732  m_sFormula = rStr;
733 }
734 
736 {
737  sal_uInt32 nFormat(GetFormat());
738 
739  if (nFormat && nFormat != SAL_MAX_UINT32 && static_cast<SwValueFieldType *>(GetTyp())->UseFormat())
740  {
741  OUString sFormattedValue;
742  Color* pCol = nullptr;
743 
744  SvNumberFormatter* pFormatter = GetDoc()->GetNumberFormatter();
745 
746  if (pFormatter->IsTextFormat(nFormat))
747  {
748  OUString sTempIn(static_cast<SwValueFieldType *>(GetTyp())->DoubleToString(GetValue(), nFormat));
749  pFormatter->GetOutputString(sTempIn, nFormat, sFormattedValue, &pCol);
750  }
751  else
752  {
753  pFormatter->GetOutputString(GetValue(), nFormat, sFormattedValue, &pCol);
754  }
755  return sFormattedValue;
756  }
757  else
758  return GetFormula();
759 }
760 
761 OUString SwField::GetDescription() const
762 {
763  return SwResId(STR_FIELD);
764 }
765 
767 {
768  switch (Which())
769  {
771  case SwFieldIds::Macro:
772  case SwFieldIds::GetRef:
773  case SwFieldIds::Input:
774  case SwFieldIds::SetExp:
776  return true;
777  default: break;
778  }
779  return false;
780 }
781 
783 {
784  xmlTextWriterStartElement(pWriter, BAD_CAST("SwField"));
785  xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("symbol"), "%s", BAD_CAST(typeid(*this).name()));
786  xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("ptr"), "%p", this);
787  xmlTextWriterWriteAttribute(pWriter, BAD_CAST("m_nFormat"), BAD_CAST(OString::number(m_nFormat).getStr()));
788  xmlTextWriterWriteAttribute(pWriter, BAD_CAST("m_nLang"), BAD_CAST(OString::number(m_nLang.get()).getStr()));
789 
790  xmlTextWriterEndElement(pWriter);
791 }
792 
793 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OUString GetNumStr(sal_Int32 nNo) const
Instances of SwFields and those derived from it occur 0 to n times.
Definition: fldbas.hxx:233
SwValueField(SwValueFieldType *pFieldType, sal_uInt32 nFormat, LanguageType nLang=LANGUAGE_SYSTEM, const double fVal=0.0)
Definition: fldbas.cxx:552
sal_uInt32 GetFormatForLanguageIfBuiltIn(sal_uInt32 nFormat, LanguageType eLnge=LANGUAGE_DONTKNOW)
virtual ~SwField()
Definition: fldbas.cxx:195
#define LANGUAGE_NONE
OUString ConditionalExpandAuthIdentifier(SwRootFrame const *pLayout) const
For internal use only, in general continue using ExpandField() instead.
Definition: authfld.cxx:487
virtual void dumpAsXml(xmlTextWriterPtr pWriter) const
Definition: fldbas.cxx:782
const OUString & GetNumDecimalSep() const
OUString m_Cache
Cached expansion (for clipboard).
Definition: fldbas.hxx:282
static ShellResource * GetShellRes()
Definition: viewsh.cxx:2490
sal_uInt32 GetFormat() const
Query parameters for dialog and for BASIC.
Definition: fldbas.hxx:387
static LanguageType lcl_GetLanguageOfFormat(LanguageType nLng, sal_uLong nFormat, const SvNumberFormatter &rFormatter)
Definition: fldbas.cxx:55
std::string GetValue
SvNumberFormatter * GetNumberFormatter(bool bCreate=true)
Definition: doc.hxx:1399
LanguageType getLanguageType(bool bResolveSystem=true) const
void GetOutputString(const double &fOutNumber, sal_uInt32 nFIndex, OUString &sOutString, Color **ppColor, bool bUseStarFormat=false)
SVX_NUM_NUMBER_NONE
sal_uIntPtr sal_uLong
bool IsFixed() const
Definition: fldbas.cxx:380
Base class of all fields.
Definition: fldbas.hxx:279
LanguageType GetLanguage(SfxItemSet const &aSet, sal_uInt16 nLangWhichId)
Definition: langhelper.cxx:402
virtual SwFieldType * ChgTyp(SwFieldType *) override
Set a new type.
Definition: fldbas.cxx:576
sal_uInt16 GetTypeId() const
Definition: fldbas.cxx:209
Definition: doc.hxx:185
TElementType * Next()
Definition: calbck.hxx:376
std::unique_ptr< SwField > CopyField() const
Definition: fldbas.cxx:432
#define FIELD_PROP_BOOL4
Definition: unofldmid.h:41
SwValueFieldType(SwDoc *pDocPtr, SwFieldIds nWhichId)
Definition: fldbas.cxx:460
NfIndexTableOffset GetIndexTableOffset(sal_uInt32 nFormat) const
LanguageType m_nLang
control the usage of the cached field value
Definition: fldbas.hxx:284
bool m_bIsAutomaticLanguage
Definition: fldbas.hxx:285
SwDoc * GetDoc() const
Definition: fldbas.hxx:443
The root element of a Writer document layout.
Definition: rootfrm.hxx:79
const OUString & GetFormatstring() const
SwFieldType * m_pType
this can be either SvxNumType or SwChapterFormat depending on the subtype
Definition: fldbas.hxx:287
OUString GetExpandedFormula() const
Definition: fldbas.cxx:735
SvxNumType
static LanguageType nLang
Definition: srtdlg.cxx:58
#define SAL_MAX_UINT32
virtual OUString GetPar1() const
Definition: fldbas.cxx:271
virtual OUString ExpandImpl(SwRootFrame const *pLayout) const =0
FUNC_TYPE const nType
static bool Str2Double(const OUString &rStr, sal_Int32 &rPos, double &rVal)
Definition: calc.cxx:1337
invariant for SwAuthorityField is that it is always registered at its SwAuthorityFieldType via AddFie...
Definition: authfld.hxx:148
virtual void SetPar2(const OUString &rStr)
Definition: fldbas.cxx:289
static std::vector< OUString > * s_pFieldNames
field names
Definition: fldbas.hxx:240
virtual bool PutValue(const css::uno::Any &rVal, sal_uInt16 nWhichId)
Definition: fldbas.cxx:314
SwFieldType(SwFieldIds nWhichId)
Single argument ctors shall be explicit.
Definition: fldbas.cxx:139
virtual void SetLanguage(LanguageType nLng) override
set language of the format
Definition: fldbas.cxx:633
OUString FormatNumber(sal_uInt32 nNum, SvxNumType nFormat, LanguageType nLang)
expand numbering
Definition: fldbas.cxx:444
void SetExpandedFormula(const OUString &rStr)
Definition: fldbas.cxx:716
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt16 nWhichId) const
Definition: fldbas.cxx:301
bool HasClickHdl() const
Does the field possess an action on its ClickHandler? (e.g. INetFields, ...).
Definition: fldbas.cxx:348
virtual OUString GetDescription() const
Definition: fldbas.cxx:761
void SetFormula(const OUString &rStr)
Definition: fldbas.cxx:701
virtual SwFieldType * ChgTyp(SwFieldType *)
Set new type (used for copying among documents).
Definition: fldbas.cxx:338
struct _xmlTextWriter * xmlTextWriterPtr
SwField(SwFieldType *pTyp, sal_uInt32 nFormat=0, LanguageType nLang=LANGUAGE_SYSTEM, bool m_bUseFieldValueCache=true)
Definition: fldbas.cxx:180
virtual void SetPar1(const OUString &rStr)
Definition: fldbas.cxx:286
UNDERLYING_TYPE get() const
virtual std::unique_ptr< SwField > Copy() const =0
bool m_bUseFieldValueCache
Definition: fldbas.hxx:283
bool PutandConvertEntry(OUString &rString, sal_Int32 &nCheckPos, SvNumFormatType &nType, sal_uInt32 &nKey, LanguageType eLnge, LanguageType eNewLnge, bool bConvertDateOrder)
const SwExtendedSubType SUB_CMD
Show command.
Definition: fldbas.hxx:204
virtual ~SwValueField() override
Definition: fldbas.cxx:565
#define LANGUAGE_SYSTEM
bool IsTextFormat(sal_uInt32 nFIndex) const
virtual void dumpAsXml(xmlTextWriterPtr pWriter) const
Definition: fldbas.cxx:157
SwFormulaField(SwValueFieldType *pFieldType, sal_uInt32 nFormat, const double fVal)
Definition: fldbas.cxx:685
TElementType * First()
Definition: calbck.hxx:345
SwFieldIds
Definition: fldbas.hxx:38
sal_uInt32 m_nFormat
Definition: fldbas.hxx:286
void dumpAsXml(xmlTextWriterPtr pWriter) const
Definition: fldbas.cxx:169
void SetFormat(sal_uInt32 const nSet)
Definition: fldbas.hxx:293
virtual OUString GetFormula() const override
Definition: fldbas.cxx:696
SvNumFormatType
size
OUString m_sFormula
Definition: fldbas.hxx:461
OUString SwResId(const char *pId)
Definition: swmodule.cxx:191
bool HasMergeFormatTable() const
#define SV_COUNTRY_LANGUAGE_OFFSET
virtual OUString GetPar2() const
Definition: fldbas.cxx:276
bool IsAutomaticLanguage() const
Definition: fldbas.hxx:369
virtual sal_uInt16 GetSubType() const
Definition: fldbas.cxx:292
virtual void QueryValue(css::uno::Any &rVal, sal_uInt16 nWhich) const
Definition: fldbas.cxx:150
SwFieldType * GetTyp() const
Definition: fldbas.hxx:382
NF_NUMBER_SYSTEM
Fields containing values that have to be formatted via number formatter.
Definition: fldbas.hxx:398
SVX_NUM_PAGEDESC
OUString ExpandField(bool bCached, SwRootFrame const *pLayout) const
expand the field.
Definition: fldbas.cxx:412
const SwGetSetExpType GSE_SEQ
Sequence.
Definition: fldbas.hxx:197
SwFieldIds Which() const
ResId.
Definition: fldbas.cxx:202
virtual void SetLanguage(LanguageType nLng)
Definition: fldbas.cxx:370
void ChangeIntl(LanguageType eLnge)
OUString ExpandValue(const double &rVal, sal_uInt32 nFormat, LanguageType nLng) const
return value formatted as string
Definition: fldbas.cxx:475
virtual OUString GetName() const
Only in derived classes.
Definition: fldbas.cxx:145
NF_DATE_SYSTEM_LONG
static OUString GetTypeStr(sal_uInt16 nTypeId)
Definition: fldbas.cxx:128
sal_uInt32 GetMergeFormatIndex(sal_uInt32 nOldFmt) const
const SvNumberformat * GetEntry(sal_uInt32 nKey) const
void dumpAsXml(xmlTextWriterPtr pWriter) const override
Definition: fldbas.cxx:624
double m_fValue
Definition: fldbas.hxx:431
LanguageType GetAppLanguage()
Definition: init.cxx:771
NF_DATE_SYSTEM_SHORT
virtual void PutValue(const css::uno::Any &rVal, sal_uInt16 nWhich)
Definition: fldbas.cxx:153
virtual OUString GetFieldName() const
get name or content
Definition: fldbas.cxx:255
const SwGetSetExpType GSE_FORMULA
Formula.
Definition: fldbas.hxx:198
OUString const aFixedStr
Definition: shellres.hxx:47
void ChangeFormat(sal_uInt32 n)
Definition: fldbas.cxx:375
static sal_uInt32 GetSystemFormat(SvNumberFormatter *pFormatter, sal_uInt32 nFormat)
get format in office language
Definition: fldbas.cxx:594
NF_DATETIME_SYSTEM_SHORT_HHMM
const LanguageTag & GetLanguageTag() const
virtual void SetValue(const double &rVal)
Definition: fldbas.cxx:680
const SwDocInfoSubType DI_SUB_FIXED
Definition: docufld.hxx:81
OUString DoubleToString(const double &rVal, LanguageType eLng) const
Definition: fldbas.cxx:538
void SetNumberingType(SvxNumType nSet)
virtual void SetSubType(sal_uInt16)
Definition: fldbas.cxx:297
virtual OUString GetFormula() const
Definition: fldbas.cxx:281
sal_Int32 nPos
SwDoc * m_pDoc
Definition: fldbas.hxx:401
OUString const aCalc_Error
Definition: shellres.hxx:40
SwFieldIds Which() const
Definition: fldbas.hxx:265
bool IsClickable() const
Is this field clickable?
Definition: fldbas.cxx:766
virtual double GetValue() const
Definition: fldbas.cxx:675
LanguageType GetLanguage() const
static css::lang::Locale convertToLocale(LanguageType nLangID, bool bResolveSystem=true)