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 
24 #include <libxml/xmlwriter.h>
25 
26 #include <rtl/math.hxx>
27 #include <svl/zforlist.hxx>
28 #include <svl/zformat.hxx>
29 #include <o3tl/enumarray.hxx>
30 #include <osl/diagnose.h>
31 #include <unofldmid.h>
32 #include <doc.hxx>
33 #include <fmtfld.hxx>
34 #include <docufld.hxx>
35 #include <expfld.hxx>
36 #include <shellres.hxx>
37 #include <calc.hxx>
38 #include <strings.hrc>
39 #include <docary.hxx>
40 #include <authfld.hxx>
41 #include <calbck.hxx>
42 #include <viewsh.hxx>
43 
44 using namespace ::com::sun::star;
45 using namespace nsSwDocInfoSubType;
46 
48  const SvNumberFormatter& rFormatter )
49 {
50  if( nLng == LANGUAGE_NONE ) // Bug #60010
51  nLng = LANGUAGE_SYSTEM;
52  else if( nLng == ::GetAppLanguage() )
53  switch( rFormatter.GetIndexTableOffset( nFormat ))
54  {
55  case NF_NUMBER_SYSTEM:
59  nLng = LANGUAGE_SYSTEM;
60  break;
61  default: break;
62  }
63  return nLng;
64 }
65 
66 // Globals
67 
69 std::vector<OUString>* SwFieldType::s_pFieldNames = nullptr;
70 
71 namespace
72 {
73 
75  /* SwFieldIds::Database */ SwFieldTypesEnum::Database,
76  /* SwFieldIds::User */ SwFieldTypesEnum::User,
77  /* SwFieldIds::Filename */ SwFieldTypesEnum::Filename,
78  /* SwFieldIds::DatabaseName */ SwFieldTypesEnum::DatabaseName,
79  /* SwFieldIds::Date */ SwFieldTypesEnum::Date,
80  /* SwFieldIds::Time */ SwFieldTypesEnum::Time,
81  /* SwFieldIds::PageNumber */ SwFieldTypesEnum::PageNumber, // dynamic
82  /* SwFieldIds::Author */ SwFieldTypesEnum::Author,
83  /* SwFieldIds::Chapter */ SwFieldTypesEnum::Chapter,
84  /* SwFieldIds::DocStat */ SwFieldTypesEnum::DocumentStatistics,
85  /* SwFieldIds::GetExp */ SwFieldTypesEnum::Get, // dynamic
86  /* SwFieldIds::SetExp */ SwFieldTypesEnum::Set, // dynamic
87  /* SwFieldIds::GetRef */ SwFieldTypesEnum::GetRef,
88  /* SwFieldIds::HiddenText */ SwFieldTypesEnum::HiddenText,
89  /* SwFieldIds::Postit */ SwFieldTypesEnum::Postit,
90  /* SwFieldIds::FixDate */ SwFieldTypesEnum::FixedDate,
91  /* SwFieldIds::FixTime */ SwFieldTypesEnum::FixedTime,
92  /* SwFieldIds::Reg */ SwFieldTypesEnum::Begin, // old (no change since 2000)
93  /* SwFieldIds::VarReg */ SwFieldTypesEnum::Begin, // old (no change since 2000)
94  /* SwFieldIds::SetRef */ SwFieldTypesEnum::SetRef,
95  /* SwFieldIds::Input */ SwFieldTypesEnum::Input,
96  /* SwFieldIds::Macro */ SwFieldTypesEnum::Macro,
97  /* SwFieldIds::Dde */ SwFieldTypesEnum::DDE,
98  /* SwFieldIds::Table */ SwFieldTypesEnum::Formel,
99  /* SwFieldIds::HiddenPara */ SwFieldTypesEnum::HiddenParagraph,
100  /* SwFieldIds::DocInfo */ SwFieldTypesEnum::DocumentInfo,
101  /* SwFieldIds::TemplateName */ SwFieldTypesEnum::TemplateName,
102  /* SwFieldIds::DbNextSet */ SwFieldTypesEnum::DatabaseNextSet,
103  /* SwFieldIds::DbNumSet */ SwFieldTypesEnum::DatabaseNumberSet,
104  /* SwFieldIds::DbSetNumber */ SwFieldTypesEnum::DatabaseSetNumber,
105  /* SwFieldIds::ExtUser */ SwFieldTypesEnum::ExtendedUser,
106  /* SwFieldIds::RefPageSet */ SwFieldTypesEnum::SetRefPage,
107  /* SwFieldIds::RefPageGet */ SwFieldTypesEnum::GetRefPage,
108  /* SwFieldIds::Internet */ SwFieldTypesEnum::Internet,
109  /* SwFieldIds::JumpEdit */ SwFieldTypesEnum::JumpEdit,
110  /* SwFieldIds::Script */ SwFieldTypesEnum::Script,
111  /* SwFieldIds::DateTime */ SwFieldTypesEnum::Begin, // dynamic
112  /* SwFieldIds::TableOfAuthorities*/ SwFieldTypesEnum::Authority,
113  /* SwFieldIds::CombinedChars */ SwFieldTypesEnum::CombinedChars,
114  /* SwFieldIds::Dropdown */ SwFieldTypesEnum::Dropdown,
115  /* SwFieldIds::ParagraphSignature */ SwFieldTypesEnum::ParagraphSignature
116  };
117 
118 }
119 
121 {
122  if (!s_pFieldNames)
123  GetFieldName_();
124 
125  return (*SwFieldType::s_pFieldNames)[static_cast<int>(nTypeId)];
126 }
127 
128 // each field references a field type that is unique for each document
130  : SwModify()
131  , m_nWhich(nWhichId)
132 {
133 }
134 
135 OUString SwFieldType::GetName() const
136 {
137  return OUString();
138 }
139 
140 void SwFieldType::QueryValue( uno::Any&, sal_uInt16 ) const
141 {
142 }
143 void SwFieldType::PutValue( const uno::Any& , sal_uInt16 )
144 {
145 }
146 
148 {
149  std::vector<SwFormatField*> vFields;
150  GatherFields(vFields);
151  if(!vFields.size())
152  return;
153  xmlTextWriterStartElement(pWriter, BAD_CAST("SwFieldType"));
154  for(const auto pFormatField: vFields)
155  pFormatField->dumpAsXml(pWriter);
156  xmlTextWriterEndElement(pWriter);
157 }
158 
160  SwFormatField* pFormat = nullptr;
162  return pFormat;
163 }
164 
165 SwFormatField* SwFieldType::FindFormatForPostItId(sal_uInt32 nPostItId) const {
166  SwFormatField* pFormat = nullptr;
168  return pFormat;
169 }
170 
171 void SwFieldType::CollectPostIts(std::vector<SwFormatField*>& rvFormatFields, IDocumentRedlineAccess const& rIDRA, const bool bHideRedlines)
172 {
173  CallSwClientNotify(sw::CollectPostItsHint(rvFormatFields, rIDRA, bHideRedlines));
174 }
175 
177 {
178  bool bHasHiddenInformationNotes = false;
179  CallSwClientNotify(sw::HasHiddenInformationNotesHint(bHasHiddenInformationNotes));
180  return bHasHiddenInformationNotes;
181 }
182 
183 void SwFieldType::GatherNodeIndex(std::vector<sal_uLong>& rvNodeIndex)
184 {
186 }
187 
188 void SwFieldType::GatherRefFields(std::vector<SwGetRefField*>& rvRFields, const sal_uInt16 nTyp)
189 {
191 }
192 
193 void SwFieldType::GatherFields(std::vector<SwFormatField*>& rvFields, bool bCollectOnlyInDocNodes) const
194 {
195  CallSwClientNotify(sw::GatherFieldsHint(rvFields, bCollectOnlyInDocNodes));
196 }
197 
199 {
200  xmlTextWriterStartElement(pWriter, BAD_CAST("SwFieldTypes"));
201  sal_uInt16 nCount = size();
202  for (sal_uInt16 nType = 0; nType < nCount; ++nType)
203  (*this)[nType]->dumpAsXml(pWriter);
204  xmlTextWriterEndElement(pWriter);
205 }
206 
207 // Base class for all fields.
208 // A field (multiple can exist) references a field type (can exists only once)
210  SwFieldType* pType,
211  sal_uInt32 nFormat,
213  bool bUseFieldValueCache)
214  : m_Cache()
215  , m_pType( pType )
216  , m_nFormat( nFormat )
217  , m_nLang( nLang )
218  , m_bUseFieldValueCache( bUseFieldValueCache )
219  , m_bIsAutomaticLanguage( true )
220 {
221  assert(m_pType);
222 }
223 
225 {
226 }
227 
228 // instead of indirectly via the type
229 
230 #ifdef DBG_UTIL
232 {
233  assert(m_pType);
234  return m_pType->Which();
235 }
236 #endif
237 
239 {
240 
241  SwFieldTypesEnum nRet;
242  switch (m_pType->Which())
243  {
245  if (GetSubType() & FIXEDFLD)
247  else
249  break;
250  case SwFieldIds::GetExp:
252  break;
253 
255  nRet = static_cast<SwFieldTypesEnum>(GetSubType());
256  break;
257 
258  case SwFieldIds::SetExp:
261  else if( static_cast<const SwSetExpField*>(this)->GetInputFlag() )
263  else
264  nRet = SwFieldTypesEnum::Set;
265  break;
266 
268  {
269  auto nSubType = GetSubType();
270  if( PG_NEXT == nSubType )
272  else if( PG_PREV == nSubType )
274  else
276  }
277  break;
278 
279  default:
280  nRet = aTypeTab[ m_pType->Which() ];
281  }
282  return nRet;
283 }
284 
286 OUString SwField::GetFieldName() const
287 {
288  SwFieldTypesEnum nTypeId = GetTypeId();
289  if (SwFieldIds::DateTime == GetTyp()->Which())
290  {
291  nTypeId =
293  }
294  OUString sRet = SwFieldType::GetTypeStr( nTypeId );
295  if (IsFixed())
296  {
297  sRet += " " + SwViewShell::GetShellRes()->aFixedStr;
298  }
299  return sRet;
300 }
301 
302 OUString SwField::GetPar1() const
303 {
304  return OUString();
305 }
306 
307 OUString SwField::GetPar2() const
308 {
309  return OUString();
310 }
311 
312 OUString SwField::GetFormula() const
313 {
314  return GetPar2();
315 }
316 
317 void SwField::SetPar1(const OUString& )
318 {}
319 
320 void SwField::SetPar2(const OUString& )
321 {}
322 
323 sal_uInt16 SwField::GetSubType() const
324 {
325  return 0;
326 }
327 
328 void SwField::SetSubType(sal_uInt16 )
329 {
330 }
331 
332 bool SwField::QueryValue( uno::Any& rVal, sal_uInt16 nWhichId ) const
333 {
334  switch( nWhichId )
335  {
336  case FIELD_PROP_BOOL4:
337  rVal <<= !m_bIsAutomaticLanguage;
338  break;
339  default:
340  assert(false);
341  }
342  return true;
343 }
344 
345 bool SwField::PutValue( const uno::Any& rVal, sal_uInt16 nWhichId )
346 {
347  switch( nWhichId )
348  {
349  case FIELD_PROP_BOOL4:
350  {
351  bool bFixed = false;
352  if(rVal >>= bFixed)
353  m_bIsAutomaticLanguage = !bFixed;
354  }
355  break;
356  default:
357  assert(false);
358  }
359  return true;
360 }
361 
370 {
371  assert(pNewType && pNewType->Which() == m_pType->Which());
372 
373  SwFieldType* pOld = m_pType;
374  m_pType = pNewType;
375  return pOld;
376 }
377 
380 {
381  bool bRet = false;
382  switch (m_pType->Which())
383  {
386  case SwFieldIds::GetRef:
387  case SwFieldIds::Macro:
388  case SwFieldIds::Input:
389  case SwFieldIds::Dropdown :
390  bRet = true;
391  break;
392 
393  case SwFieldIds::SetExp:
394  bRet = static_cast<const SwSetExpField*>(this)->GetInputFlag();
395  break;
396  default: break;
397  }
398  return bRet;
399 }
400 
402 {
403  m_nLang = nLang;
404 }
405 
406 void SwField::ChangeFormat(sal_uInt32 const nFormat)
407 {
408  m_nFormat = nFormat;
409 }
410 
411 bool SwField::IsFixed() const
412 {
413  bool bRet = false;
414  switch (m_pType->Which())
415  {
416  case SwFieldIds::FixDate:
417  case SwFieldIds::FixTime:
418  bRet = true;
419  break;
420 
422  bRet = 0 != (GetSubType() & FIXEDFLD);
423  break;
424 
425  case SwFieldIds::ExtUser:
426  case SwFieldIds::Author:
427  bRet = 0 != (GetFormat() & AF_FIXED);
428  break;
429 
431  bRet = 0 != (GetFormat() & FF_FIXED);
432  break;
433 
434  case SwFieldIds::DocInfo:
435  bRet = 0 != (GetSubType() & DI_SUB_FIXED);
436  break;
437  default: break;
438  }
439  return bRet;
440 }
441 
442 OUString
443 SwField::ExpandField(bool const bCached, SwRootFrame const*const pLayout) const
444 {
445  if ( m_bUseFieldValueCache )
446  {
447  if (!bCached) // #i85766# do not expand fields in clipboard documents
448  {
450  {
451  const SwAuthorityField* pAuthorityField = static_cast<const SwAuthorityField*>(this);
452  m_Cache = pAuthorityField->ConditionalExpandAuthIdentifier(pLayout);
453  }
454  else
455  m_Cache = ExpandImpl(pLayout);
456  }
457  return m_Cache;
458  }
459 
460  return ExpandImpl(pLayout);
461 }
462 
463 std::unique_ptr<SwField> SwField::CopyField() const
464 {
465  std::unique_ptr<SwField> pNew = Copy();
466  // #i85766# cache expansion of source (for clipboard)
467  // use this->cache, not this->Expand(): only text formatting calls Expand()
468  pNew->m_Cache = m_Cache;
469  pNew->m_bUseFieldValueCache = m_bUseFieldValueCache;
470 
471  return pNew;
472 }
473 
475 OUString FormatNumber(sal_uInt32 nNum, SvxNumType nFormat, LanguageType nLang)
476 {
477  if(SVX_NUM_PAGEDESC == nFormat)
478  return OUString::number( nNum );
479  SvxNumberType aNumber;
480 
481  OSL_ENSURE(nFormat != SVX_NUM_NUMBER_NONE, "wrong number format" );
482 
483  aNumber.SetNumberingType(nFormat);
484 
485  if (nLang == LANGUAGE_NONE)
486  return aNumber.GetNumStr(nNum);
487  else
488  return aNumber.GetNumStr(nNum, LanguageTag::convertToLocale(nLang));
489 }
490 
492  : SwFieldType(nWhichId)
493  , m_pDoc(pDoc)
494  , m_bUseFormat(true)
495 {
496 }
497 
499  : SwFieldType(rTyp.Which())
500  , m_pDoc(rTyp.GetDoc())
501  , m_bUseFormat(rTyp.UseFormat())
502 {
503 }
504 
506 OUString SwValueFieldType::ExpandValue( const double& rVal,
507  sal_uInt32 nFormat, LanguageType nLng) const
508 {
509  if (rVal >= DBL_MAX) // error string for calculator
511 
512  OUString sExpand;
514  Color* pCol = nullptr;
515 
516  // Bug #60010
517  LanguageType nFormatLng = ::lcl_GetLanguageOfFormat( nLng, nFormat, *pFormatter );
518 
519  if( nFormat < SV_COUNTRY_LANGUAGE_OFFSET && LANGUAGE_SYSTEM != nFormatLng )
520  {
521  SvNumFormatType nType = SvNumFormatType::DEFINED;
522  sal_Int32 nDummy;
523 
524  const SvNumberformat* pEntry = pFormatter->GetEntry(nFormat);
525 
526  if (pEntry && nLng != pEntry->GetLanguage())
527  {
528  sal_uInt32 nNewFormat = pFormatter->GetFormatForLanguageIfBuiltIn(nFormat,
529  nFormatLng);
530 
531  if (nNewFormat == nFormat)
532  {
533  // probably user-defined format
534  OUString sFormat(pEntry->GetFormatstring());
535 
536  pFormatter->PutandConvertEntry(sFormat, nDummy, nType, nFormat,
537  pEntry->GetLanguage(), nFormatLng, false);
538  }
539  else
540  nFormat = nNewFormat;
541  }
542  OSL_ENSURE(pEntry, "unknown number format!");
543  }
544 
545  if( pFormatter->IsTextFormat( nFormat ) )
546  {
547  pFormatter->GetOutputString(DoubleToString(rVal, nFormatLng), nFormat,
548  sExpand, &pCol);
549  }
550  else
551  {
552  pFormatter->GetOutputString(rVal, nFormat, sExpand, &pCol);
553  }
554  return sExpand;
555 }
556 
557 OUString SwValueFieldType::DoubleToString(const double &rVal,
558  sal_uInt32 nFormat) const
559 {
561  const SvNumberformat* pEntry = pFormatter->GetEntry(nFormat);
562 
563  if (!pEntry)
564  return OUString();
565 
566  return DoubleToString(rVal, pEntry->GetLanguage());
567 }
568 
569 OUString SwValueFieldType::DoubleToString( const double &rVal,
570  LanguageType nLng ) const
571 {
573 
574  // Bug #60010
575  if( nLng == LANGUAGE_NONE )
576  nLng = LANGUAGE_SYSTEM;
577 
578  pFormatter->ChangeIntl( nLng ); // get separator in the correct language
579  return ::rtl::math::doubleToUString( rVal, rtl_math_StringFormat_F, 12,
580  pFormatter->GetNumDecimalSep()[0], true );
581 }
582 
583 SwValueField::SwValueField( SwValueFieldType* pFieldType, sal_uInt32 nFormat,
584  LanguageType nLng, const double fVal )
585  : SwField(pFieldType, nFormat, nLng)
586  , m_fValue(fVal)
587 {
588 }
589 
591  : SwField(rField)
592  , m_fValue(rField.GetValue())
593 {
594 }
595 
597 {
598 }
599 
608 {
609  SwDoc* pNewDoc = static_cast<SwValueFieldType *>(pNewType)->GetDoc();
610  SwDoc* pDoc = GetDoc();
611 
612  if( pNewDoc && pDoc && pDoc != pNewDoc)
613  {
614  SvNumberFormatter* pFormatter = pNewDoc->GetNumberFormatter();
615 
616  if( pFormatter && pFormatter->HasMergeFormatTable() &&
617  static_cast<SwValueFieldType *>(GetTyp())->UseFormat() )
618  SetFormat(pFormatter->GetMergeFormatIndex( GetFormat() ));
619  }
620 
621  return SwField::ChgTyp(pNewType);
622 }
623 
625 sal_uInt32 SwValueField::GetSystemFormat(SvNumberFormatter* pFormatter, sal_uInt32 nFormat)
626 {
627  const SvNumberformat* pEntry = pFormatter->GetEntry(nFormat);
629 
630  if (pEntry && nLng != pEntry->GetLanguage())
631  {
632  sal_uInt32 nNewFormat = pFormatter->GetFormatForLanguageIfBuiltIn(nFormat,
633  nLng);
634 
635  if (nNewFormat == nFormat)
636  {
637  // probably user-defined format
638  SvNumFormatType nType = SvNumFormatType::DEFINED;
639  sal_Int32 nDummy;
640 
641  OUString sFormat(pEntry->GetFormatstring());
642 
643  sal_uInt32 nTempFormat = nFormat;
644  pFormatter->PutandConvertEntry(sFormat, nDummy, nType,
645  nTempFormat, pEntry->GetLanguage(), nLng, true);
646  nFormat = nTempFormat;
647  }
648  else
649  nFormat = nNewFormat;
650  }
651 
652  return nFormat;
653 }
654 
656 {
657  xmlTextWriterStartElement(pWriter, BAD_CAST("SwValueField"));
658  xmlTextWriterWriteAttribute(pWriter, BAD_CAST("m_fValue"), BAD_CAST(OString::number(m_fValue).getStr()));
659  SwField::dumpAsXml(pWriter);
660  xmlTextWriterEndElement(pWriter);
661 }
662 
665 {
666  if( IsAutomaticLanguage() &&
667  static_cast<SwValueFieldType *>(GetTyp())->UseFormat() &&
669  {
670  // Bug #60010
671  SvNumberFormatter* pFormatter = GetDoc()->GetNumberFormatter();
672  LanguageType nFormatLng = ::lcl_GetLanguageOfFormat( nLng, GetFormat(),
673  *pFormatter );
674 
676  LANGUAGE_SYSTEM != nFormatLng ) &&
678  {
679  const SvNumberformat* pEntry = pFormatter->GetEntry(GetFormat());
680 
681  if( pEntry && nFormatLng != pEntry->GetLanguage() )
682  {
683  sal_uInt32 nNewFormat = pFormatter->GetFormatForLanguageIfBuiltIn(
684  GetFormat(), nFormatLng );
685 
686  if( nNewFormat == GetFormat() )
687  {
688  // probably user-defined format
689  SvNumFormatType nType = SvNumFormatType::DEFINED;
690  sal_Int32 nDummy;
691  OUString sFormat( pEntry->GetFormatstring() );
692  pFormatter->PutandConvertEntry( sFormat, nDummy, nType,
693  nNewFormat,
694  pEntry->GetLanguage(),
695  nFormatLng, false);
696  }
697  SetFormat( nNewFormat );
698  }
699  OSL_ENSURE(pEntry, "unknown number format!");
700  }
701  }
702 
703  SwField::SetLanguage(nLng);
704 }
705 
707 {
708  return m_fValue;
709 }
710 
711 void SwValueField::SetValue( const double& rVal )
712 {
713  m_fValue = rVal;
714 }
715 
716 SwFormulaField::SwFormulaField( SwValueFieldType* pFieldType, sal_uInt32 nFormat, const double fVal)
717  : SwValueField(pFieldType, nFormat, LANGUAGE_SYSTEM, fVal)
718 {
719 }
720 
722  : SwValueField(static_cast<SwValueFieldType *>(rField.GetTyp()), rField.GetFormat(),
723  rField.GetLanguage(), rField.GetValue())
724 {
725 }
726 
728 {
729  return m_sFormula;
730 }
731 
732 void SwFormulaField::SetFormula(const OUString& rStr)
733 {
734  m_sFormula = rStr;
735 
736  sal_uLong nFormat(GetFormat());
737 
738  if( nFormat && SAL_MAX_UINT32 != nFormat )
739  {
740  sal_Int32 nPos = 0;
741  double fTmpValue;
742  if( SwCalc::Str2Double( rStr, nPos, fTmpValue, GetDoc() ) )
743  SwValueField::SetValue( fTmpValue );
744  }
745 }
746 
747 void SwFormulaField::SetExpandedFormula( const OUString& rStr )
748 {
749  sal_uInt32 nFormat(GetFormat());
750 
751  if (nFormat && nFormat != SAL_MAX_UINT32 && static_cast<SwValueFieldType *>(GetTyp())->UseFormat())
752  {
753  double fTmpValue;
754 
755  if (GetDoc()->IsNumberFormat(rStr, nFormat, fTmpValue))
756  {
757  SwValueField::SetValue(fTmpValue);
758 
759  m_sFormula = static_cast<SwValueFieldType *>(GetTyp())->DoubleToString(fTmpValue, nFormat);
760  return;
761  }
762  }
763  m_sFormula = rStr;
764 }
765 
767 {
768  sal_uInt32 nFormat(GetFormat());
769 
770  if (nFormat && nFormat != SAL_MAX_UINT32 && static_cast<SwValueFieldType *>(GetTyp())->UseFormat())
771  {
772  OUString sFormattedValue;
773  Color* pCol = nullptr;
774 
775  SvNumberFormatter* pFormatter = GetDoc()->GetNumberFormatter();
776 
777  if (pFormatter->IsTextFormat(nFormat))
778  {
779  OUString sTempIn(static_cast<SwValueFieldType *>(GetTyp())->DoubleToString(GetValue(), nFormat));
780  pFormatter->GetOutputString(sTempIn, nFormat, sFormattedValue, &pCol);
781  }
782  else
783  {
784  pFormatter->GetOutputString(GetValue(), nFormat, sFormattedValue, &pCol);
785  }
786  return sFormattedValue;
787  }
788  else
789  return GetFormula();
790 }
791 
792 OUString SwField::GetDescription() const
793 {
794  return SwResId(STR_FIELD);
795 }
796 
798 {
799  switch (Which())
800  {
802  case SwFieldIds::Macro:
803  case SwFieldIds::GetRef:
804  case SwFieldIds::Input:
805  case SwFieldIds::SetExp:
807  return true;
808  default: break;
809  }
810  return false;
811 }
812 
814 {
815  xmlTextWriterStartElement(pWriter, BAD_CAST("SwField"));
816  xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("symbol"), "%s", BAD_CAST(typeid(*this).name()));
817  xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("ptr"), "%p", this);
818  xmlTextWriterWriteAttribute(pWriter, BAD_CAST("m_nFormat"), BAD_CAST(OString::number(m_nFormat).getStr()));
819  xmlTextWriterWriteAttribute(pWriter, BAD_CAST("m_nLang"), BAD_CAST(OString::number(m_nLang.get()).getStr()));
820 
821  xmlTextWriterEndElement(pWriter);
822 }
823 
824 /* 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:240
SwValueField(SwValueFieldType *pFieldType, sal_uInt32 nFormat, LanguageType nLang=LANGUAGE_SYSTEM, const double fVal=0.0)
Definition: fldbas.cxx:583
sal_uInt32 GetFormatForLanguageIfBuiltIn(sal_uInt32 nFormat, LanguageType eLnge=LANGUAGE_DONTKNOW)
virtual ~SwField()
Definition: fldbas.cxx:224
#define LANGUAGE_NONE
OUString ConditionalExpandAuthIdentifier(SwRootFrame const *pLayout) const
For internal use only, in general continue using ExpandField() instead.
Definition: authfld.cxx:470
virtual void dumpAsXml(xmlTextWriterPtr pWriter) const
Definition: fldbas.cxx:813
const OUString & GetNumDecimalSep() const
OUString m_Cache
Cached expansion (for clipboard).
Definition: fldbas.hxx:296
sal_uInt16 const m_nFormat
static ShellResource * GetShellRes()
Definition: viewsh.cxx:2485
sal_uInt32 GetFormat() const
Query parameters for dialog and for BASIC.
Definition: fldbas.hxx:401
static LanguageType lcl_GetLanguageOfFormat(LanguageType nLng, sal_uLong nFormat, const SvNumberFormatter &rFormatter)
Definition: fldbas.cxx:47
std::string GetValue
SvNumberFormatter * GetNumberFormatter(bool bCreate=true)
Definition: doc.hxx:1407
void CollectPostIts(std::vector< SwFormatField * > &rvFormatFields, IDocumentRedlineAccess const &rIDRA, bool HideRedlines)
Definition: fldbas.cxx:171
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:411
Base class of all fields.
Definition: fldbas.hxx:293
LanguageType GetLanguage(SfxItemSet const &aSet, sal_uInt16 nLangWhichId)
Definition: langhelper.cxx:399
virtual SwFieldType * ChgTyp(SwFieldType *) override
Set a new type.
Definition: fldbas.cxx:607
Definition: doc.hxx:184
std::unique_ptr< SwField > CopyField() const
Definition: fldbas.cxx:463
#define FIELD_PROP_BOOL4
Definition: unofldmid.h:41
SwValueFieldType(SwDoc *pDocPtr, SwFieldIds nWhichId)
Definition: fldbas.cxx:491
NfIndexTableOffset GetIndexTableOffset(sal_uInt32 nFormat) const
SwFormatField * FindFormatForField(const SwField *) const
Definition: fldbas.cxx:159
LanguageType m_nLang
this can be either SvxNumType or SwChapterFormat depending on the subtype
Definition: fldbas.hxx:299
OUString aCalc_Error
Definition: shellres.hxx:40
bool m_bIsAutomaticLanguage
control the usage of the cached field value
Definition: fldbas.hxx:301
SwDoc * GetDoc() const
Definition: fldbas.hxx:457
The root element of a Writer document layout.
Definition: rootfrm.hxx:79
const OUString & GetFormatstring() const
SwFieldType * m_pType
Definition: fldbas.hxx:297
OUString GetExpandedFormula() const
Definition: fldbas.cxx:766
SvxNumType
static LanguageType nLang
Definition: srtdlg.cxx:51
void GatherFields(std::vector< SwFormatField * > &rvFormatFields, bool bCollectOnlyInDocNodes=true) const
Definition: fldbas.cxx:193
SwDoc * m_pDoc
Definition: docbm.cxx:1190
#define SAL_MAX_UINT32
virtual OUString GetPar1() const
Definition: fldbas.cxx:302
virtual OUString ExpandImpl(SwRootFrame const *pLayout) const =0
static bool Str2Double(const OUString &rStr, sal_Int32 &rPos, double &rVal)
Definition: calc.cxx:1343
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:320
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
static std::vector< OUString > * s_pFieldNames
field names
Definition: fldbas.hxx:247
virtual bool PutValue(const css::uno::Any &rVal, sal_uInt16 nWhichId)
Definition: fldbas.cxx:345
int nCount
SwFieldType(SwFieldIds nWhichId)
Single argument ctors shall be explicit.
Definition: fldbas.cxx:129
virtual void SetLanguage(LanguageType nLng) override
set language of the format
Definition: fldbas.cxx:664
OUString FormatNumber(sal_uInt32 nNum, SvxNumType nFormat, LanguageType nLang)
expand numbering
Definition: fldbas.cxx:475
void SetExpandedFormula(const OUString &rStr)
Definition: fldbas.cxx:747
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt16 nWhichId) const
Definition: fldbas.cxx:332
bool HasClickHdl() const
Does the field possess an action on its ClickHandler? (e.g. INetFields, ...).
Definition: fldbas.cxx:379
virtual OUString GetDescription() const
Definition: fldbas.cxx:792
void SetFormula(const OUString &rStr)
Definition: fldbas.cxx:732
virtual SwFieldType * ChgTyp(SwFieldType *)
Set new type (used for copying among documents).
Definition: fldbas.cxx:369
struct _xmlTextWriter * xmlTextWriterPtr
SwField(SwFieldType *pTyp, sal_uInt32 nFormat=0, LanguageType nLang=LANGUAGE_SYSTEM, bool m_bUseFieldValueCache=true)
Definition: fldbas.cxx:209
virtual void SetPar1(const OUString &rStr)
Definition: fldbas.cxx:317
static OUString GetTypeStr(SwFieldTypesEnum nTypeId)
Definition: fldbas.cxx:120
UNDERLYING_TYPE get() const
virtual std::unique_ptr< SwField > Copy() const =0
bool m_bUseFieldValueCache
Definition: fldbas.hxx:300
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:211
virtual ~SwValueField() override
Definition: fldbas.cxx:596
#define LANGUAGE_SYSTEM
bool IsTextFormat(sal_uInt32 nFIndex) const
virtual void dumpAsXml(xmlTextWriterPtr pWriter) const
Definition: fldbas.cxx:147
SwFormulaField(SwValueFieldType *pFieldType, sal_uInt32 nFormat, const double fVal)
Definition: fldbas.cxx:716
SwFieldTypesEnum
List of FieldTypes at UI.
Definition: fldbas.hxx:93
SwFieldIds
Definition: fldbas.hxx:44
sal_uInt32 m_nFormat
Definition: fldbas.hxx:298
void dumpAsXml(xmlTextWriterPtr pWriter) const
Definition: fldbas.cxx:198
virtual void CallSwClientNotify(const SfxHint &rHint) const
Definition: calbck.cxx:369
void SetFormat(sal_uInt32 const nSet)
Definition: fldbas.hxx:307
virtual OUString GetFormula() const override
Definition: fldbas.cxx:727
SvNumFormatType
void GatherNodeIndex(std::vector< sal_uLong > &rvNodeIndex)
Definition: fldbas.cxx:183
size
OUString m_sFormula
Definition: fldbas.hxx:475
OUString SwResId(const char *pId)
Definition: swmodule.cxx:165
bool HasMergeFormatTable() const
#define SV_COUNTRY_LANGUAGE_OFFSET
virtual OUString GetPar2() const
Definition: fldbas.cxx:307
bool IsAutomaticLanguage() const
Definition: fldbas.hxx:383
virtual sal_uInt16 GetSubType() const
Definition: fldbas.cxx:323
virtual void QueryValue(css::uno::Any &rVal, sal_uInt16 nWhich) const
Definition: fldbas.cxx:140
SwFieldType * GetTyp() const
Definition: fldbas.hxx:396
NF_NUMBER_SYSTEM
Fields containing values that have to be formatted via number formatter.
Definition: fldbas.hxx:412
SwFieldTypesEnum GetTypeId() const
Definition: fldbas.cxx:238
SVX_NUM_PAGEDESC
OUString ExpandField(bool bCached, SwRootFrame const *pLayout) const
expand the field.
Definition: fldbas.cxx:443
const SwGetSetExpType GSE_SEQ
Sequence.
Definition: fldbas.hxx:204
SwFormatField * FindFormatForPostItId(sal_uInt32 nPostItId) const
Definition: fldbas.cxx:165
SwFieldIds Which() const
ResId.
Definition: fldbas.cxx:231
virtual void SetLanguage(LanguageType nLng)
Definition: fldbas.cxx:401
void ChangeIntl(LanguageType eLnge)
void GatherRefFields(std::vector< SwGetRefField * > &rvRFields, const sal_uInt16 nTyp)
Definition: fldbas.cxx:188
OUString ExpandValue(const double &rVal, sal_uInt32 nFormat, LanguageType nLng) const
return value formatted as string
Definition: fldbas.cxx:506
virtual OUString GetName() const
Only in derived classes.
Definition: fldbas.cxx:135
NF_DATE_SYSTEM_LONG
sal_uInt32 GetMergeFormatIndex(sal_uInt32 nOldFmt) const
const SvNumberformat * GetEntry(sal_uInt32 nKey) const
void dumpAsXml(xmlTextWriterPtr pWriter) const override
Definition: fldbas.cxx:655
double m_fValue
Definition: fldbas.hxx:445
LanguageType GetAppLanguage()
Definition: init.cxx:728
NF_DATE_SYSTEM_SHORT
virtual void PutValue(const css::uno::Any &rVal, sal_uInt16 nWhich)
Definition: fldbas.cxx:143
QPRO_FUNC_TYPE nType
virtual OUString GetFieldName() const
get name or content
Definition: fldbas.cxx:286
const SwGetSetExpType GSE_FORMULA
Formula.
Definition: fldbas.hxx:205
void ChangeFormat(sal_uInt32 n)
Definition: fldbas.cxx:406
static sal_uInt32 GetSystemFormat(SvNumberFormatter *pFormatter, sal_uInt32 nFormat)
get format in office language
Definition: fldbas.cxx:625
NF_DATETIME_SYSTEM_SHORT_HHMM
const LanguageTag & GetLanguageTag() const
OUString aFixedStr
Definition: shellres.hxx:47
virtual void SetValue(const double &rVal)
Definition: fldbas.cxx:711
const SwDocInfoSubType DI_SUB_FIXED
Definition: docufld.hxx:81
OUString DoubleToString(const double &rVal, LanguageType eLng) const
Definition: fldbas.cxx:569
void SetNumberingType(SvxNumType nSet)
virtual void SetSubType(sal_uInt16)
Definition: fldbas.cxx:328
virtual OUString GetFormula() const
Definition: fldbas.cxx:312
bool HasHiddenInformationNotes()
Definition: fldbas.cxx:176
SwDoc * m_pDoc
Definition: fldbas.hxx:415
SwFieldIds Which() const
Definition: fldbas.hxx:272
bool IsClickable() const
Is this field clickable?
Definition: fldbas.cxx:797
virtual double GetValue() const
Definition: fldbas.cxx:706
LanguageType GetLanguage() const
sal_uInt16 nPos
static css::lang::Locale convertToLocale(LanguageType nLangID, bool bResolveSystem=true)