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 SwMsgPoolItem aHint(RES_HIDDENPARA_PRINT);
152  SwClientNotify(*this, sw::LegacyModifyHint(&aHint, nullptr));
153 }
154 
156 {
157  std::vector<SwFormatField*> vFields;
158  GatherFields(vFields);
159  if(!vFields.size())
160  return;
161  (void)xmlTextWriterStartElement(pWriter, BAD_CAST("SwFieldType"));
162  (void)xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("ptr"), "%p", this);
163  (void)xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("symbol"), "%s", BAD_CAST(typeid(*this).name()));
164  for(const auto pFormatField: vFields)
165  pFormatField->dumpAsXml(pWriter);
166  (void)xmlTextWriterEndElement(pWriter);
167 }
168 
170  SwFormatField* pFormat = nullptr;
172  return pFormat;
173 }
174 
175 SwFormatField* SwFieldType::FindFormatForPostItId(sal_uInt32 nPostItId) const {
176  SwFormatField* pFormat = nullptr;
178  return pFormat;
179 }
180 
181 void SwFieldType::CollectPostIts(std::vector<SwFormatField*>& rvFormatFields, IDocumentRedlineAccess const& rIDRA, const bool bHideRedlines)
182 {
183  CallSwClientNotify(sw::CollectPostItsHint(rvFormatFields, rIDRA, bHideRedlines));
184 }
185 
187 {
188  bool bHasHiddenInformationNotes = false;
189  CallSwClientNotify(sw::HasHiddenInformationNotesHint(bHasHiddenInformationNotes));
190  return bHasHiddenInformationNotes;
191 }
192 
193 void SwFieldType::GatherNodeIndex(std::vector<SwNodeOffset>& rvNodeIndex)
194 {
196 }
197 
198 void SwFieldType::GatherRefFields(std::vector<SwGetRefField*>& rvRFields, const sal_uInt16 nTyp)
199 {
201 }
202 
203 void SwFieldType::GatherFields(std::vector<SwFormatField*>& rvFields, bool bCollectOnlyInDocNodes) const
204 {
205  CallSwClientNotify(sw::GatherFieldsHint(rvFields, bCollectOnlyInDocNodes));
206 }
207 
208 void SwFieldType::GatherDdeTables(std::vector<SwDDETable*>& rvTables) const
209 {
211 }
212 
214 {
215  CallSwClientNotify(sw::LegacyModifyHint(nullptr, nullptr));
216 };
217 
219 {
220  (void)xmlTextWriterStartElement(pWriter, BAD_CAST("SwFieldTypes"));
221  sal_uInt16 nCount = size();
222  for (sal_uInt16 nType = 0; nType < nCount; ++nType)
223  (*this)[nType]->dumpAsXml(pWriter);
224  (void)xmlTextWriterEndElement(pWriter);
225 }
226 
227 // Base class for all fields.
228 // A field (multiple can exist) references a field type (can exists only once)
230  SwFieldType* pType,
231  sal_uInt32 nFormat,
233  bool bUseFieldValueCache)
234  : m_pType( pType )
235  , m_nFormat( nFormat )
236  , m_nLang( nLang )
237  , m_bUseFieldValueCache( bUseFieldValueCache )
238  , m_bIsAutomaticLanguage( true )
239 {
240  assert(m_pType);
241 }
242 
244 {
245 }
246 
247 // instead of indirectly via the type
248 
249 #ifdef DBG_UTIL
251 {
252  assert(m_pType);
253  return m_pType->Which();
254 }
255 #endif
256 
258 {
259 
260  SwFieldTypesEnum nRet;
261  switch (m_pType->Which())
262  {
264  if (GetSubType() & FIXEDFLD)
266  else
268  break;
269  case SwFieldIds::GetExp:
271  break;
272 
274  nRet = static_cast<SwFieldTypesEnum>(GetSubType());
275  break;
276 
277  case SwFieldIds::SetExp:
280  else if( static_cast<const SwSetExpField*>(this)->GetInputFlag() )
282  else
283  nRet = SwFieldTypesEnum::Set;
284  break;
285 
287  {
288  auto nSubType = GetSubType();
289  if( PG_NEXT == nSubType )
291  else if( PG_PREV == nSubType )
293  else
295  }
296  break;
297 
298  default:
299  nRet = aTypeTab[ m_pType->Which() ];
300  }
301  return nRet;
302 }
303 
305 OUString SwField::GetFieldName() const
306 {
307  SwFieldTypesEnum nTypeId = GetTypeId();
308  if (SwFieldIds::DateTime == GetTyp()->Which())
309  {
310  nTypeId =
312  }
313  OUString sRet = SwFieldType::GetTypeStr( nTypeId );
314  if (IsFixed())
315  {
316  sRet += " " + SwViewShell::GetShellRes()->aFixedStr;
317  }
318  return sRet;
319 }
320 
321 OUString SwField::GetPar1() const
322 {
323  return OUString();
324 }
325 
326 OUString SwField::GetPar2() const
327 {
328  return OUString();
329 }
330 
331 OUString SwField::GetFormula() const
332 {
333  return GetPar2();
334 }
335 
336 void SwField::SetPar1(const OUString& )
337 {}
338 
339 void SwField::SetPar2(const OUString& )
340 {}
341 
342 sal_uInt16 SwField::GetSubType() const
343 {
344  return 0;
345 }
346 
347 void SwField::SetSubType(sal_uInt16 )
348 {
349 }
350 
351 bool SwField::QueryValue( uno::Any& rVal, sal_uInt16 nWhichId ) const
352 {
353  switch( nWhichId )
354  {
355  case FIELD_PROP_BOOL4:
356  rVal <<= !m_bIsAutomaticLanguage;
357  break;
358  default:
359  assert(false);
360  }
361  return true;
362 }
363 
364 bool SwField::PutValue( const uno::Any& rVal, sal_uInt16 nWhichId )
365 {
366  switch( nWhichId )
367  {
368  case FIELD_PROP_BOOL4:
369  {
370  bool bFixed = false;
371  if(rVal >>= bFixed)
372  m_bIsAutomaticLanguage = !bFixed;
373  }
374  break;
375  default:
376  assert(false);
377  }
378  return true;
379 }
380 
389 {
390  assert(pNewType && pNewType->Which() == m_pType->Which());
391 
392  SwFieldType* pOld = m_pType;
393  m_pType = pNewType;
394  return pOld;
395 }
396 
399 {
400  bool bRet = false;
401  switch (m_pType->Which())
402  {
405  case SwFieldIds::GetRef:
406  case SwFieldIds::Macro:
407  case SwFieldIds::Input:
408  case SwFieldIds::Dropdown :
409  bRet = true;
410  break;
411 
412  case SwFieldIds::SetExp:
413  bRet = static_cast<const SwSetExpField*>(this)->GetInputFlag();
414  break;
415 
417  {
418  const auto pAuthorityField = static_cast<const SwAuthorityField*>(this);
419  bRet = pAuthorityField->HasURL();
420  break;
421  }
422 
423  default: break;
424  }
425  return bRet;
426 }
427 
429 {
430  m_nLang = nLang;
431 }
432 
433 void SwField::ChangeFormat(sal_uInt32 const nFormat)
434 {
435  m_nFormat = nFormat;
436 }
437 
438 bool SwField::IsFixed() const
439 {
440  bool bRet = false;
441  switch (m_pType->Which())
442  {
443  case SwFieldIds::FixDate:
444  case SwFieldIds::FixTime:
445  bRet = true;
446  break;
447 
449  bRet = 0 != (GetSubType() & FIXEDFLD);
450  break;
451 
452  case SwFieldIds::ExtUser:
453  case SwFieldIds::Author:
454  bRet = 0 != (GetFormat() & AF_FIXED);
455  break;
456 
458  bRet = 0 != (GetFormat() & FF_FIXED);
459  break;
460 
461  case SwFieldIds::DocInfo:
462  bRet = 0 != (GetSubType() & DI_SUB_FIXED);
463  break;
464  default: break;
465  }
466  return bRet;
467 }
468 
469 OUString
470 SwField::ExpandField(bool const bCached, SwRootFrame const*const pLayout) const
471 {
472  if ( m_bUseFieldValueCache )
473  {
474  if (!bCached) // #i85766# do not expand fields in clipboard documents
475  {
477  {
478  const SwAuthorityField* pAuthorityField = static_cast<const SwAuthorityField*>(this);
479  m_Cache = pAuthorityField->ConditionalExpandAuthIdentifier(pLayout);
480  }
481  else
482  m_Cache = ExpandImpl(pLayout);
483  }
484  return m_Cache;
485  }
486 
487  return ExpandImpl(pLayout);
488 }
489 
490 std::unique_ptr<SwField> SwField::CopyField() const
491 {
492  std::unique_ptr<SwField> pNew = Copy();
493  // #i85766# cache expansion of source (for clipboard)
494  // use this->cache, not this->Expand(): only text formatting calls Expand()
495  pNew->m_Cache = m_Cache;
496  pNew->m_bUseFieldValueCache = m_bUseFieldValueCache;
497 
498  return pNew;
499 }
500 
502 OUString FormatNumber(sal_uInt32 nNum, SvxNumType nFormat, LanguageType nLang)
503 {
504  if(SVX_NUM_PAGEDESC == nFormat)
505  return OUString::number( nNum );
506  SvxNumberType aNumber;
507 
508  OSL_ENSURE(nFormat != SVX_NUM_NUMBER_NONE, "wrong number format" );
509 
510  aNumber.SetNumberingType(nFormat);
511 
512  if (nLang == LANGUAGE_NONE)
513  return aNumber.GetNumStr(nNum);
514  else
515  return aNumber.GetNumStr(nNum, LanguageTag::convertToLocale(nLang));
516 }
517 
519  : SwFieldType(nWhichId)
520  , m_pDoc(pDoc)
521  , m_bUseFormat(true)
522 {
523 }
524 
526  : SwFieldType(rTyp.Which())
527  , m_pDoc(rTyp.GetDoc())
528  , m_bUseFormat(rTyp.UseFormat())
529 {
530 }
531 
533 OUString SwValueFieldType::ExpandValue( const double& rVal,
534  sal_uInt32 nFormat, LanguageType nLng) const
535 {
536  if (rVal >= DBL_MAX) // error string for calculator
538 
539  OUString sExpand;
541  const Color* pCol = nullptr;
542 
543  // Bug #60010
544  LanguageType nFormatLng = ::lcl_GetLanguageOfFormat( nLng, nFormat, *pFormatter );
545 
546  if( nFormat < SV_COUNTRY_LANGUAGE_OFFSET && LANGUAGE_SYSTEM != nFormatLng )
547  {
548  const SvNumberformat* pEntry = pFormatter->GetEntry(nFormat);
549 
550  if (pEntry && nLng != pEntry->GetLanguage())
551  {
552  sal_uInt32 nNewFormat = pFormatter->GetFormatForLanguageIfBuiltIn(nFormat,
553  nFormatLng);
554  if (nNewFormat == nFormat)
555  {
556  // probably user-defined format
557  OUString sFormat(pEntry->GetFormatstring());
558  sal_Int32 nDummy;
559  SvNumFormatType nType = SvNumFormatType::DEFINED;
560 
561  pFormatter->PutandConvertEntry(sFormat, nDummy, nType, nFormat,
562  pEntry->GetLanguage(), nFormatLng, false);
563  }
564  else
565  nFormat = nNewFormat;
566  }
567  OSL_ENSURE(pEntry, "unknown number format!");
568  }
569 
570  if( pFormatter->IsTextFormat( nFormat ) )
571  {
572  pFormatter->GetOutputString(DoubleToString(rVal, nFormatLng), nFormat,
573  sExpand, &pCol);
574  }
575  else
576  {
577  pFormatter->GetOutputString(rVal, nFormat, sExpand, &pCol);
578  }
579  return sExpand;
580 }
581 
582 OUString SwValueFieldType::DoubleToString(const double &rVal,
583  sal_uInt32 nFormat) const
584 {
586  const SvNumberformat* pEntry = pFormatter->GetEntry(nFormat);
587 
588  if (!pEntry)
589  return OUString();
590 
591  return DoubleToString(rVal, pEntry->GetLanguage());
592 }
593 
594 OUString SwValueFieldType::DoubleToString( const double &rVal,
595  LanguageType nLng ) const
596 {
598 
599  // Bug #60010
600  if( nLng == LANGUAGE_NONE )
601  nLng = LANGUAGE_SYSTEM;
602 
603  pFormatter->ChangeIntl( nLng ); // get separator in the correct language
604  return ::rtl::math::doubleToUString( rVal, rtl_math_StringFormat_F, 12,
605  pFormatter->GetNumDecimalSep()[0], true );
606 }
607 
608 SwValueField::SwValueField( SwValueFieldType* pFieldType, sal_uInt32 nFormat,
609  LanguageType nLng, const double fVal )
610  : SwField(pFieldType, nFormat, nLng)
611  , m_fValue(fVal)
612 {
613 }
614 
616  : SwField(rField)
617  , m_fValue(rField.GetValue())
618 {
619 }
620 
622 {
623 }
624 
633 {
634  SwDoc* pNewDoc = static_cast<SwValueFieldType *>(pNewType)->GetDoc();
635  SwDoc* pDoc = GetDoc();
636 
637  if( pNewDoc && pDoc && pDoc != pNewDoc)
638  {
639  SvNumberFormatter* pFormatter = pNewDoc->GetNumberFormatter();
640 
641  if( pFormatter && pFormatter->HasMergeFormatTable() &&
642  static_cast<SwValueFieldType *>(GetTyp())->UseFormat() )
643  SetFormat(pFormatter->GetMergeFormatIndex( GetFormat() ));
644  }
645 
646  return SwField::ChgTyp(pNewType);
647 }
648 
650 sal_uInt32 SwValueField::GetSystemFormat(SvNumberFormatter* pFormatter, sal_uInt32 nFormat)
651 {
652  const SvNumberformat* pEntry = pFormatter->GetEntry(nFormat);
654 
655  if (pEntry && nLng != pEntry->GetLanguage())
656  {
657  sal_uInt32 nNewFormat = pFormatter->GetFormatForLanguageIfBuiltIn(nFormat,
658  nLng);
659 
660  if (nNewFormat == nFormat)
661  {
662  // probably user-defined format
663  SvNumFormatType nType = SvNumFormatType::DEFINED;
664  sal_Int32 nDummy;
665 
666  OUString sFormat(pEntry->GetFormatstring());
667 
668  sal_uInt32 nTempFormat = nFormat;
669  pFormatter->PutandConvertEntry(sFormat, nDummy, nType,
670  nTempFormat, pEntry->GetLanguage(), nLng, true);
671  nFormat = nTempFormat;
672  }
673  else
674  nFormat = nNewFormat;
675  }
676 
677  return nFormat;
678 }
679 
681 {
682  (void)xmlTextWriterStartElement(pWriter, BAD_CAST("SwValueField"));
683  (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("m_fValue"), BAD_CAST(OString::number(m_fValue).getStr()));
684  SwField::dumpAsXml(pWriter);
685  (void)xmlTextWriterEndElement(pWriter);
686 }
687 
690 {
691  if( IsAutomaticLanguage() &&
692  static_cast<SwValueFieldType *>(GetTyp())->UseFormat() &&
694  {
695  // Bug #60010
696  SvNumberFormatter* pFormatter = GetDoc()->GetNumberFormatter();
697  LanguageType nFormatLng = ::lcl_GetLanguageOfFormat( nLng, GetFormat(),
698  *pFormatter );
699 
701  LANGUAGE_SYSTEM != nFormatLng ) &&
703  {
704  const SvNumberformat* pEntry = pFormatter->GetEntry(GetFormat());
705 
706  if( pEntry && nFormatLng != pEntry->GetLanguage() )
707  {
708  sal_uInt32 nNewFormat = pFormatter->GetFormatForLanguageIfBuiltIn(
709  GetFormat(), nFormatLng );
710 
711  if( nNewFormat == GetFormat() )
712  {
713  // probably user-defined format
714  SvNumFormatType nType = SvNumFormatType::DEFINED;
715  sal_Int32 nDummy;
716  OUString sFormat( pEntry->GetFormatstring() );
717  pFormatter->PutandConvertEntry( sFormat, nDummy, nType,
718  nNewFormat,
719  pEntry->GetLanguage(),
720  nFormatLng, false);
721  }
722  SetFormat( nNewFormat );
723  }
724  OSL_ENSURE(pEntry, "unknown number format!");
725  }
726  }
727 
728  SwField::SetLanguage(nLng);
729 }
730 
732 {
733  return m_fValue;
734 }
735 
736 void SwValueField::SetValue( const double& rVal )
737 {
738  m_fValue = rVal;
739 }
740 
741 SwFormulaField::SwFormulaField( SwValueFieldType* pFieldType, sal_uInt32 nFormat, const double fVal)
742  : SwValueField(pFieldType, nFormat, LANGUAGE_SYSTEM, fVal)
743 {
744 }
745 
747  : SwValueField(static_cast<SwValueFieldType *>(rField.GetTyp()), rField.GetFormat(),
748  rField.GetLanguage(), rField.GetValue())
749 {
750 }
751 
753 {
754  return m_sFormula;
755 }
756 
757 void SwFormulaField::SetFormula(const OUString& rStr)
758 {
759  m_sFormula = rStr;
760 
761  sal_uLong nFormat(GetFormat());
762 
763  if( nFormat && SAL_MAX_UINT32 != nFormat )
764  {
765  sal_Int32 nPos = 0;
766  double fTmpValue;
767  if( SwCalc::Str2Double( rStr, nPos, fTmpValue, GetDoc() ) )
768  SwValueField::SetValue( fTmpValue );
769  }
770 }
771 
772 void SwFormulaField::SetExpandedFormula( const OUString& rStr )
773 {
774  sal_uInt32 nFormat(GetFormat());
775 
776  if (nFormat && nFormat != SAL_MAX_UINT32 && static_cast<SwValueFieldType *>(GetTyp())->UseFormat())
777  {
778  double fTmpValue;
779 
780  if (GetDoc()->IsNumberFormat(rStr, nFormat, fTmpValue))
781  {
782  SwValueField::SetValue(fTmpValue);
783 
784  m_sFormula = static_cast<SwValueFieldType *>(GetTyp())->DoubleToString(fTmpValue, nFormat);
785  return;
786  }
787  }
788  m_sFormula = rStr;
789 }
790 
792 {
793  sal_uInt32 nFormat(GetFormat());
794 
795  if (nFormat && nFormat != SAL_MAX_UINT32 && static_cast<SwValueFieldType *>(GetTyp())->UseFormat())
796  {
797  OUString sFormattedValue;
798  const Color* pCol = nullptr;
799 
800  SvNumberFormatter* pFormatter = GetDoc()->GetNumberFormatter();
801 
802  if (pFormatter->IsTextFormat(nFormat))
803  {
804  OUString sTempIn(static_cast<SwValueFieldType *>(GetTyp())->DoubleToString(GetValue(), nFormat));
805  pFormatter->GetOutputString(sTempIn, nFormat, sFormattedValue, &pCol);
806  }
807  else
808  {
809  pFormatter->GetOutputString(GetValue(), nFormat, sFormattedValue, &pCol);
810  }
811  return sFormattedValue;
812  }
813  else
814  return GetFormula();
815 }
816 
817 OUString SwField::GetDescription() const
818 {
819  return SwResId(STR_FIELD);
820 }
821 
823 {
824  switch (Which())
825  {
827  case SwFieldIds::Macro:
828  case SwFieldIds::GetRef:
829  case SwFieldIds::Input:
830  case SwFieldIds::SetExp:
833  return true;
834  default: break;
835  }
836  return false;
837 }
838 
840 {
841  (void)xmlTextWriterStartElement(pWriter, BAD_CAST("SwField"));
842  (void)xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("symbol"), "%s", BAD_CAST(typeid(*this).name()));
843  (void)xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("ptr"), "%p", this);
844  (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("m_nFormat"), BAD_CAST(OString::number(m_nFormat).getStr()));
845  (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("m_nLang"), BAD_CAST(OString::number(m_nLang.get()).getStr()));
846 
847  (void)xmlTextWriterEndElement(pWriter);
848 }
849 
850 /* 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:242
SwValueField(SwValueFieldType *pFieldType, sal_uInt32 nFormat, LanguageType nLang=LANGUAGE_SYSTEM, const double fVal=0.0)
Definition: fldbas.cxx:608
sal_uInt32 GetFormatForLanguageIfBuiltIn(sal_uInt32 nFormat, LanguageType eLnge=LANGUAGE_DONTKNOW)
virtual ~SwField()
Definition: fldbas.cxx:243
#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:839
const OUString & GetNumDecimalSep() const
OUString m_Cache
Cached expansion (for clipboard).
Definition: fldbas.hxx:295
sal_uInt16 const m_nFormat
static ShellResource * GetShellRes()
Definition: viewsh.cxx:2652
sal_uInt32 GetFormat() const
Query parameters for dialog and for BASIC.
Definition: fldbas.hxx:400
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:181
LanguageType getLanguageType(bool bResolveSystem=true) const
SVX_NUM_NUMBER_NONE
sal_uIntPtr sal_uLong
bool IsFixed() const
Definition: fldbas.cxx:438
Base class of all fields.
Definition: fldbas.hxx:292
LanguageType GetLanguage(SfxItemSet const &aSet, sal_uInt16 nLangWhichId)
Definition: langhelper.cxx:390
virtual SwFieldType * ChgTyp(SwFieldType *) override
Set a new type.
Definition: fldbas.cxx:632
Definition: doc.hxx:188
std::unique_ptr< SwField > CopyField() const
Definition: fldbas.cxx:490
#define FIELD_PROP_BOOL4
Definition: unofldmid.h:41
SwValueFieldType(SwDoc *pDocPtr, SwFieldIds nWhichId)
Definition: fldbas.cxx:518
NfIndexTableOffset GetIndexTableOffset(sal_uInt32 nFormat) const
SwFormatField * FindFormatForField(const SwField *) const
Definition: fldbas.cxx:169
LanguageType m_nLang
this can be either SvxNumType or SwChapterFormat depending on the subtype
Definition: fldbas.hxx:298
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:300
SwDoc * GetDoc() const
Definition: fldbas.hxx:456
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:296
void GatherDdeTables(std::vector< SwDDETable * > &rvTables) const
Definition: fldbas.cxx:208
OUString GetExpandedFormula() const
Definition: fldbas.cxx:791
SvxNumType
static LanguageType nLang
Definition: srtdlg.cxx:51
void GatherFields(std::vector< SwFormatField * > &rvFormatFields, bool bCollectOnlyInDocNodes=true) const
Definition: fldbas.cxx:203
bool HasHiddenInformationNotes() const
Definition: fldbas.cxx:186
OUString SwResId(TranslateId aId)
Definition: swmodule.cxx:165
#define SAL_MAX_UINT32
virtual OUString GetPar1() const
Definition: fldbas.cxx:321
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:339
static std::vector< OUString > * s_pFieldNames
field names
Definition: fldbas.hxx:249
virtual bool PutValue(const css::uno::Any &rVal, sal_uInt16 nWhichId)
Definition: fldbas.cxx:364
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:689
OUString FormatNumber(sal_uInt32 nNum, SvxNumType nFormat, LanguageType nLang)
expand numbering
Definition: fldbas.cxx:502
void SetExpandedFormula(const OUString &rStr)
Definition: fldbas.cxx:772
bool HasURL() const
Definition: authfld.cxx:609
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt16 nWhichId) const
Definition: fldbas.cxx:351
bool HasClickHdl() const
Does the field possess an action on its ClickHandler? (e.g. INetFields, ...).
Definition: fldbas.cxx:398
virtual OUString GetDescription() const
Definition: fldbas.cxx:817
void SetFormula(const OUString &rStr)
Definition: fldbas.cxx:757
virtual SwFieldType * ChgTyp(SwFieldType *)
Set new type (used for copying among documents).
Definition: fldbas.cxx:388
virtual void UpdateFields()
Definition: fldbas.cxx:213
void GatherNodeIndex(std::vector< SwNodeOffset > &rvNodeIndex)
Definition: fldbas.cxx:193
SwField(SwFieldType *pTyp, sal_uInt32 nFormat=0, LanguageType nLang=LANGUAGE_SYSTEM, bool m_bUseFieldValueCache=true)
Definition: fldbas.cxx:229
virtual void SetPar1(const OUString &rStr)
Definition: fldbas.cxx:336
UNDERLYING_TYPE get() const
virtual std::unique_ptr< SwField > Copy() const =0
bool m_bUseFieldValueCache
Definition: fldbas.hxx:299
const SwExtendedSubType SUB_CMD
Show command.
Definition: fldbas.hxx:213
virtual ~SwValueField() override
Definition: fldbas.cxx:621
#define LANGUAGE_SYSTEM
bool IsTextFormat(sal_uInt32 nFIndex) const
virtual void dumpAsXml(xmlTextWriterPtr pWriter) const
Definition: fldbas.cxx:155
SwFormulaField(SwValueFieldType *pFieldType, sal_uInt32 nFormat, const double fVal)
Definition: fldbas.cxx:741
SwFieldTypesEnum
List of FieldTypes at UI.
Definition: fldbas.hxx:95
SwFieldIds
Definition: fldbas.hxx:46
sal_uInt32 m_nFormat
Definition: fldbas.hxx:297
void dumpAsXml(xmlTextWriterPtr pWriter) const
Definition: fldbas.cxx:218
void SetFormat(sal_uInt32 const nSet)
Definition: fldbas.hxx:306
virtual OUString GetFormula() const override
Definition: fldbas.cxx:752
SvNumFormatType
size
OUString m_sFormula
Definition: fldbas.hxx:474
bool HasMergeFormatTable() const
#define SV_COUNTRY_LANGUAGE_OFFSET
virtual OUString GetPar2() const
Definition: fldbas.cxx:326
bool IsAutomaticLanguage() const
Definition: fldbas.hxx:382
virtual sal_uInt16 GetSubType() const
Definition: fldbas.cxx:342
virtual void QueryValue(css::uno::Any &rVal, sal_uInt16 nWhich) const
Definition: fldbas.cxx:142
virtual SotClipboardFormatId GetFormat(const TransferableDataHelper &aHelper) override
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:395
NF_NUMBER_SYSTEM
Fields containing values that have to be formatted via number formatter.
Definition: fldbas.hxx:411
SwFieldTypesEnum GetTypeId() const
Definition: fldbas.cxx:257
SVX_NUM_PAGEDESC
OUString ExpandField(bool bCached, SwRootFrame const *pLayout) const
expand the field.
Definition: fldbas.cxx:470
const SwGetSetExpType GSE_SEQ
Sequence.
Definition: fldbas.hxx:206
SwFormatField * FindFormatForPostItId(sal_uInt32 nPostItId) const
Definition: fldbas.cxx:175
SwFieldIds Which() const
ResId.
Definition: fldbas.cxx:250
virtual void SetLanguage(LanguageType nLng)
Definition: fldbas.cxx:428
void ChangeIntl(LanguageType eLnge)
void GatherRefFields(std::vector< SwGetRefField * > &rvRFields, const sal_uInt16 nTyp)
Definition: fldbas.cxx:198
OUString ExpandValue(const double &rVal, sal_uInt32 nFormat, LanguageType nLng) const
return value formatted as string
Definition: fldbas.cxx:533
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:680
double m_fValue
Definition: fldbas.hxx:444
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:305
const SwGetSetExpType GSE_FORMULA
Formula.
Definition: fldbas.hxx:207
virtual void CallSwClientNotify(const SfxHint &rHint) const override
Definition: calbck.cxx:326
void ChangeFormat(sal_uInt32 n)
Definition: fldbas.cxx:433
static sal_uInt32 GetSystemFormat(SvNumberFormatter *pFormatter, sal_uInt32 nFormat)
get format in office language
Definition: fldbas.cxx:650
NF_DATETIME_SYSTEM_SHORT_HHMM
const LanguageTag & GetLanguageTag() const
OUString aFixedStr
Definition: shellres.hxx:48
struct _xmlTextWriter * xmlTextWriterPtr
virtual void SetValue(const double &rVal)
Definition: fldbas.cxx:736
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:594
void SetNumberingType(SvxNumType nSet)
virtual void SetSubType(sal_uInt16)
Definition: fldbas.cxx:347
virtual OUString GetFormula() const
Definition: fldbas.cxx:331
SwDoc * m_pDoc
Definition: fldbas.hxx:414
SwFieldIds Which() const
Definition: fldbas.hxx:274
bool IsClickable() const
Is this field clickable?
Definition: fldbas.cxx:822
virtual double GetValue() const
Definition: fldbas.cxx:731
void GetOutputString(const double &fOutNumber, sal_uInt32 nFIndex, OUString &sOutString, const Color **ppColor, bool bUseStarFormat=false)
void PrintHiddenPara()
Definition: fldbas.cxx:149
LanguageType GetLanguage() const
sal_uInt16 nPos
static css::lang::Locale convertToLocale(LanguageType nLangID, bool bResolveSystem=true)
typedef void(CALLTYPE *GetFuncDataPtr)(sal_uInt16 &nNo