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