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