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