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 
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  xmlTextWriterStartElement(pWriter, BAD_CAST("SwFieldType"));
166  for(const auto pFormatField: vFields)
167  pFormatField->dumpAsXml(pWriter);
168  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  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  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  default: break;
409  }
410  return bRet;
411 }
412 
414 {
415  m_nLang = nLang;
416 }
417 
418 void SwField::ChangeFormat(sal_uInt32 const nFormat)
419 {
420  m_nFormat = nFormat;
421 }
422 
423 bool SwField::IsFixed() const
424 {
425  bool bRet = false;
426  switch (m_pType->Which())
427  {
428  case SwFieldIds::FixDate:
429  case SwFieldIds::FixTime:
430  bRet = true;
431  break;
432 
434  bRet = 0 != (GetSubType() & FIXEDFLD);
435  break;
436 
437  case SwFieldIds::ExtUser:
438  case SwFieldIds::Author:
439  bRet = 0 != (GetFormat() & AF_FIXED);
440  break;
441 
443  bRet = 0 != (GetFormat() & FF_FIXED);
444  break;
445 
446  case SwFieldIds::DocInfo:
447  bRet = 0 != (GetSubType() & DI_SUB_FIXED);
448  break;
449  default: break;
450  }
451  return bRet;
452 }
453 
454 OUString
455 SwField::ExpandField(bool const bCached, SwRootFrame const*const pLayout) const
456 {
457  if ( m_bUseFieldValueCache )
458  {
459  if (!bCached) // #i85766# do not expand fields in clipboard documents
460  {
462  {
463  const SwAuthorityField* pAuthorityField = static_cast<const SwAuthorityField*>(this);
464  m_Cache = pAuthorityField->ConditionalExpandAuthIdentifier(pLayout);
465  }
466  else
467  m_Cache = ExpandImpl(pLayout);
468  }
469  return m_Cache;
470  }
471 
472  return ExpandImpl(pLayout);
473 }
474 
475 std::unique_ptr<SwField> SwField::CopyField() const
476 {
477  std::unique_ptr<SwField> pNew = Copy();
478  // #i85766# cache expansion of source (for clipboard)
479  // use this->cache, not this->Expand(): only text formatting calls Expand()
480  pNew->m_Cache = m_Cache;
481  pNew->m_bUseFieldValueCache = m_bUseFieldValueCache;
482 
483  return pNew;
484 }
485 
487 OUString FormatNumber(sal_uInt32 nNum, SvxNumType nFormat, LanguageType nLang)
488 {
489  if(SVX_NUM_PAGEDESC == nFormat)
490  return OUString::number( nNum );
491  SvxNumberType aNumber;
492 
493  OSL_ENSURE(nFormat != SVX_NUM_NUMBER_NONE, "wrong number format" );
494 
495  aNumber.SetNumberingType(nFormat);
496 
497  if (nLang == LANGUAGE_NONE)
498  return aNumber.GetNumStr(nNum);
499  else
500  return aNumber.GetNumStr(nNum, LanguageTag::convertToLocale(nLang));
501 }
502 
504  : SwFieldType(nWhichId)
505  , m_pDoc(pDoc)
506  , m_bUseFormat(true)
507 {
508 }
509 
511  : SwFieldType(rTyp.Which())
512  , m_pDoc(rTyp.GetDoc())
513  , m_bUseFormat(rTyp.UseFormat())
514 {
515 }
516 
518 OUString SwValueFieldType::ExpandValue( const double& rVal,
519  sal_uInt32 nFormat, LanguageType nLng) const
520 {
521  if (rVal >= DBL_MAX) // error string for calculator
523 
524  OUString sExpand;
526  const Color* pCol = nullptr;
527 
528  // Bug #60010
529  LanguageType nFormatLng = ::lcl_GetLanguageOfFormat( nLng, nFormat, *pFormatter );
530 
531  if( nFormat < SV_COUNTRY_LANGUAGE_OFFSET && LANGUAGE_SYSTEM != nFormatLng )
532  {
533  const SvNumberformat* pEntry = pFormatter->GetEntry(nFormat);
534 
535  if (pEntry && nLng != pEntry->GetLanguage())
536  {
537  sal_uInt32 nNewFormat = pFormatter->GetFormatForLanguageIfBuiltIn(nFormat,
538  nFormatLng);
539  if (nNewFormat == nFormat)
540  {
541  // probably user-defined format
542  OUString sFormat(pEntry->GetFormatstring());
543  sal_Int32 nDummy;
544  SvNumFormatType nType = SvNumFormatType::DEFINED;
545 
546  pFormatter->PutandConvertEntry(sFormat, nDummy, nType, nFormat,
547  pEntry->GetLanguage(), nFormatLng, false);
548  }
549  else
550  nFormat = nNewFormat;
551  }
552  OSL_ENSURE(pEntry, "unknown number format!");
553  }
554 
555  if( pFormatter->IsTextFormat( nFormat ) )
556  {
557  pFormatter->GetOutputString(DoubleToString(rVal, nFormatLng), nFormat,
558  sExpand, &pCol);
559  }
560  else
561  {
562  pFormatter->GetOutputString(rVal, nFormat, sExpand, &pCol);
563  }
564  return sExpand;
565 }
566 
567 OUString SwValueFieldType::DoubleToString(const double &rVal,
568  sal_uInt32 nFormat) const
569 {
571  const SvNumberformat* pEntry = pFormatter->GetEntry(nFormat);
572 
573  if (!pEntry)
574  return OUString();
575 
576  return DoubleToString(rVal, pEntry->GetLanguage());
577 }
578 
579 OUString SwValueFieldType::DoubleToString( const double &rVal,
580  LanguageType nLng ) const
581 {
583 
584  // Bug #60010
585  if( nLng == LANGUAGE_NONE )
586  nLng = LANGUAGE_SYSTEM;
587 
588  pFormatter->ChangeIntl( nLng ); // get separator in the correct language
589  return ::rtl::math::doubleToUString( rVal, rtl_math_StringFormat_F, 12,
590  pFormatter->GetNumDecimalSep()[0], true );
591 }
592 
593 SwValueField::SwValueField( SwValueFieldType* pFieldType, sal_uInt32 nFormat,
594  LanguageType nLng, const double fVal )
595  : SwField(pFieldType, nFormat, nLng)
596  , m_fValue(fVal)
597 {
598 }
599 
601  : SwField(rField)
602  , m_fValue(rField.GetValue())
603 {
604 }
605 
607 {
608 }
609 
618 {
619  SwDoc* pNewDoc = static_cast<SwValueFieldType *>(pNewType)->GetDoc();
620  SwDoc* pDoc = GetDoc();
621 
622  if( pNewDoc && pDoc && pDoc != pNewDoc)
623  {
624  SvNumberFormatter* pFormatter = pNewDoc->GetNumberFormatter();
625 
626  if( pFormatter && pFormatter->HasMergeFormatTable() &&
627  static_cast<SwValueFieldType *>(GetTyp())->UseFormat() )
628  SetFormat(pFormatter->GetMergeFormatIndex( GetFormat() ));
629  }
630 
631  return SwField::ChgTyp(pNewType);
632 }
633 
635 sal_uInt32 SwValueField::GetSystemFormat(SvNumberFormatter* pFormatter, sal_uInt32 nFormat)
636 {
637  const SvNumberformat* pEntry = pFormatter->GetEntry(nFormat);
639 
640  if (pEntry && nLng != pEntry->GetLanguage())
641  {
642  sal_uInt32 nNewFormat = pFormatter->GetFormatForLanguageIfBuiltIn(nFormat,
643  nLng);
644 
645  if (nNewFormat == nFormat)
646  {
647  // probably user-defined format
648  SvNumFormatType nType = SvNumFormatType::DEFINED;
649  sal_Int32 nDummy;
650 
651  OUString sFormat(pEntry->GetFormatstring());
652 
653  sal_uInt32 nTempFormat = nFormat;
654  pFormatter->PutandConvertEntry(sFormat, nDummy, nType,
655  nTempFormat, pEntry->GetLanguage(), nLng, true);
656  nFormat = nTempFormat;
657  }
658  else
659  nFormat = nNewFormat;
660  }
661 
662  return nFormat;
663 }
664 
666 {
667  xmlTextWriterStartElement(pWriter, BAD_CAST("SwValueField"));
668  xmlTextWriterWriteAttribute(pWriter, BAD_CAST("m_fValue"), BAD_CAST(OString::number(m_fValue).getStr()));
669  SwField::dumpAsXml(pWriter);
670  xmlTextWriterEndElement(pWriter);
671 }
672 
675 {
676  if( IsAutomaticLanguage() &&
677  static_cast<SwValueFieldType *>(GetTyp())->UseFormat() &&
679  {
680  // Bug #60010
681  SvNumberFormatter* pFormatter = GetDoc()->GetNumberFormatter();
682  LanguageType nFormatLng = ::lcl_GetLanguageOfFormat( nLng, GetFormat(),
683  *pFormatter );
684 
686  LANGUAGE_SYSTEM != nFormatLng ) &&
688  {
689  const SvNumberformat* pEntry = pFormatter->GetEntry(GetFormat());
690 
691  if( pEntry && nFormatLng != pEntry->GetLanguage() )
692  {
693  sal_uInt32 nNewFormat = pFormatter->GetFormatForLanguageIfBuiltIn(
694  GetFormat(), nFormatLng );
695 
696  if( nNewFormat == GetFormat() )
697  {
698  // probably user-defined format
699  SvNumFormatType nType = SvNumFormatType::DEFINED;
700  sal_Int32 nDummy;
701  OUString sFormat( pEntry->GetFormatstring() );
702  pFormatter->PutandConvertEntry( sFormat, nDummy, nType,
703  nNewFormat,
704  pEntry->GetLanguage(),
705  nFormatLng, false);
706  }
707  SetFormat( nNewFormat );
708  }
709  OSL_ENSURE(pEntry, "unknown number format!");
710  }
711  }
712 
713  SwField::SetLanguage(nLng);
714 }
715 
717 {
718  return m_fValue;
719 }
720 
721 void SwValueField::SetValue( const double& rVal )
722 {
723  m_fValue = rVal;
724 }
725 
726 SwFormulaField::SwFormulaField( SwValueFieldType* pFieldType, sal_uInt32 nFormat, const double fVal)
727  : SwValueField(pFieldType, nFormat, LANGUAGE_SYSTEM, fVal)
728 {
729 }
730 
732  : SwValueField(static_cast<SwValueFieldType *>(rField.GetTyp()), rField.GetFormat(),
733  rField.GetLanguage(), rField.GetValue())
734 {
735 }
736 
738 {
739  return m_sFormula;
740 }
741 
742 void SwFormulaField::SetFormula(const OUString& rStr)
743 {
744  m_sFormula = rStr;
745 
746  sal_uLong nFormat(GetFormat());
747 
748  if( nFormat && SAL_MAX_UINT32 != nFormat )
749  {
750  sal_Int32 nPos = 0;
751  double fTmpValue;
752  if( SwCalc::Str2Double( rStr, nPos, fTmpValue, GetDoc() ) )
753  SwValueField::SetValue( fTmpValue );
754  }
755 }
756 
757 void SwFormulaField::SetExpandedFormula( const OUString& rStr )
758 {
759  sal_uInt32 nFormat(GetFormat());
760 
761  if (nFormat && nFormat != SAL_MAX_UINT32 && static_cast<SwValueFieldType *>(GetTyp())->UseFormat())
762  {
763  double fTmpValue;
764 
765  if (GetDoc()->IsNumberFormat(rStr, nFormat, fTmpValue))
766  {
767  SwValueField::SetValue(fTmpValue);
768 
769  m_sFormula = static_cast<SwValueFieldType *>(GetTyp())->DoubleToString(fTmpValue, nFormat);
770  return;
771  }
772  }
773  m_sFormula = rStr;
774 }
775 
777 {
778  sal_uInt32 nFormat(GetFormat());
779 
780  if (nFormat && nFormat != SAL_MAX_UINT32 && static_cast<SwValueFieldType *>(GetTyp())->UseFormat())
781  {
782  OUString sFormattedValue;
783  const Color* pCol = nullptr;
784 
785  SvNumberFormatter* pFormatter = GetDoc()->GetNumberFormatter();
786 
787  if (pFormatter->IsTextFormat(nFormat))
788  {
789  OUString sTempIn(static_cast<SwValueFieldType *>(GetTyp())->DoubleToString(GetValue(), nFormat));
790  pFormatter->GetOutputString(sTempIn, nFormat, sFormattedValue, &pCol);
791  }
792  else
793  {
794  pFormatter->GetOutputString(GetValue(), nFormat, sFormattedValue, &pCol);
795  }
796  return sFormattedValue;
797  }
798  else
799  return GetFormula();
800 }
801 
802 OUString SwField::GetDescription() const
803 {
804  return SwResId(STR_FIELD);
805 }
806 
808 {
809  switch (Which())
810  {
812  case SwFieldIds::Macro:
813  case SwFieldIds::GetRef:
814  case SwFieldIds::Input:
815  case SwFieldIds::SetExp:
817  return true;
818  default: break;
819  }
820  return false;
821 }
822 
824 {
825  xmlTextWriterStartElement(pWriter, BAD_CAST("SwField"));
826  xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("symbol"), "%s", BAD_CAST(typeid(*this).name()));
827  xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("ptr"), "%p", this);
828  xmlTextWriterWriteAttribute(pWriter, BAD_CAST("m_nFormat"), BAD_CAST(OString::number(m_nFormat).getStr()));
829  xmlTextWriterWriteAttribute(pWriter, BAD_CAST("m_nLang"), BAD_CAST(OString::number(m_nLang.get()).getStr()));
830 
831  xmlTextWriterEndElement(pWriter);
832 }
833 
834 /* 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:593
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:470
virtual void dumpAsXml(xmlTextWriterPtr pWriter) const
Definition: fldbas.cxx:823
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:2539
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:1411
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:423
Base class of all fields.
Definition: fldbas.hxx:289
LanguageType GetLanguage(SfxItemSet const &aSet, sal_uInt16 nLangWhichId)
Definition: langhelper.cxx:395
virtual SwFieldType * ChgTyp(SwFieldType *) override
Set a new type.
Definition: fldbas.cxx:617
Definition: doc.hxx:186
std::unique_ptr< SwField > CopyField() const
Definition: fldbas.cxx:475
#define FIELD_PROP_BOOL4
Definition: unofldmid.h:41
SwValueFieldType(SwDoc *pDocPtr, SwFieldIds nWhichId)
Definition: fldbas.cxx:503
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
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:776
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:1393
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: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:674
OUString FormatNumber(sal_uInt32 nNum, SvxNumType nFormat, LanguageType nLang)
expand numbering
Definition: fldbas.cxx:487
void SetExpandedFormula(const OUString &rStr)
Definition: fldbas.cxx:757
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:802
void SetFormula(const OUString &rStr)
Definition: fldbas.cxx:742
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
static OUString GetTypeStr(SwFieldTypesEnum nTypeId)
Definition: fldbas.cxx:121
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:606
#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:726
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:737
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:455
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:413
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:518
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:665
double m_fValue
Definition: fldbas.hxx:441
LanguageType GetAppLanguage()
Definition: init.cxx:728
NF_DATE_SYSTEM_SHORT
constexpr TypedWhichId< SwMsgPoolItem > RES_HIDDENPARA_PRINT(176)
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:363
void ChangeFormat(sal_uInt32 n)
Definition: fldbas.cxx:418
static sal_uInt32 GetSystemFormat(SvNumberFormatter *pFormatter, sal_uInt32 nFormat)
get format in office language
Definition: fldbas.cxx:635
NF_DATETIME_SYSTEM_SHORT_HHMM
const LanguageTag & GetLanguageTag() const
OUString aFixedStr
Definition: shellres.hxx:47
virtual void SetValue(const double &rVal)
Definition: fldbas.cxx:721
virtual void SwClientNotify(const SwModify &, const SfxHint &rHint) override
Definition: calbck.cxx:339
const SwDocInfoSubType DI_SUB_FIXED
Definition: docufld.hxx:85
OUString DoubleToString(const double &rVal, LanguageType eLng) const
Definition: fldbas.cxx:579
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:807
virtual double GetValue() const
Definition: fldbas.cxx:716
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)