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
46using namespace ::com::sun::star;
47using 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 {
61 nLng = LANGUAGE_SYSTEM;
62 break;
63 default: break;
64 }
65 return nLng;
66}
67
68// Globals
69
71std::vector<OUString>* SwFieldType::s_pFieldNames = nullptr;
72
73namespace
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
123{
124 if (!s_pFieldNames)
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
137OUString SwFieldType::GetName() const
138{
139 return OUString();
140}
141
142void SwFieldType::QueryValue( uno::Any&, sal_uInt16 ) const
143{
144}
145void SwFieldType::PutValue( const uno::Any& , sal_uInt16 )
146{
147}
148
150{
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;
171 CallSwClientNotify(sw::FindFormatForFieldHint(pField, pFormat));
172 return pFormat;
173}
174
176 SwFormatField* pFormat = nullptr;
177 CallSwClientNotify(sw::FindFormatForPostItIdHint(nPostItId, pFormat));
178 return pFormat;
179}
180
181void 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
193void SwFieldType::GatherNodeIndex(std::vector<SwNodeOffset>& rvNodeIndex)
194{
195 CallSwClientNotify(sw::GatherNodeIndexHint(rvNodeIndex));
196}
197
198void SwFieldType::GatherRefFields(std::vector<SwGetRefField*>& rvRFields, const sal_uInt16 nTyp)
199{
200 CallSwClientNotify(sw::GatherRefFieldsHint(rvRFields, nTyp));
201}
202
203void SwFieldType::GatherFields(std::vector<SwFormatField*>& rvFields, bool bCollectOnlyInDocNodes) const
204{
205 CallSwClientNotify(sw::GatherFieldsHint(rvFields, bCollectOnlyInDocNodes));
206}
207
208void SwFieldType::GatherDdeTables(std::vector<SwDDETable*>& rvTables) const
209{
210 CallSwClientNotify(sw::GatherDdeTablesHint(rvTables));
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;
271 break;
272
274 nRet = static_cast<SwFieldTypesEnum>(GetSubType());
275 break;
276
280 else if( static_cast<const SwSetExpField*>(this)->GetInputFlag() )
282 else
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
305OUString SwField::GetFieldName() const
306{
307 SwFieldTypesEnum nTypeId = GetTypeId();
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
321OUString SwField::GetPar1() const
322{
323 return OUString();
324}
325
326OUString SwField::GetPar2() const
327{
328 return OUString();
329}
330
331OUString SwField::GetFormula() const
332{
333 return GetPar2();
334}
335
336void SwField::SetPar1(const OUString& )
337{}
338
339void SwField::SetPar2(const OUString& )
340{}
341
342sal_uInt16 SwField::GetSubType() const
343{
344 return 0;
345}
346
347void SwField::SetSubType(sal_uInt16 )
348{
349}
350
351bool 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 case FIELD_PROP_TITLE:
359 {
360 rVal <<= m_aTitle;
361 }
362 break;
363 default:
364 assert(false);
365 }
366 return true;
367}
368
369bool SwField::PutValue( const uno::Any& rVal, sal_uInt16 nWhichId )
370{
371 switch( nWhichId )
372 {
373 case FIELD_PROP_BOOL4:
374 {
375 bool bFixed = false;
376 if(rVal >>= bFixed)
377 m_bIsAutomaticLanguage = !bFixed;
378 }
379 break;
380 case FIELD_PROP_TITLE:
381 {
382 OUString aTitle;
383 if (rVal >>= aTitle)
384 {
385 m_aTitle = aTitle;
386 }
387 }
388 break;
389 default:
390 assert(false);
391 }
392 return true;
393}
394
403{
404 assert(pNewType && pNewType->Which() == m_pType->Which());
405
406 SwFieldType* pOld = m_pType;
407 m_pType = pNewType;
408 return pOld;
409}
410
413{
414 bool bRet = false;
415 switch (m_pType->Which())
416 {
423 bRet = true;
424 break;
425
427 bRet = static_cast<const SwSetExpField*>(this)->GetInputFlag();
428 break;
429
431 {
432 const auto pAuthorityField = static_cast<const SwAuthorityField*>(this);
433 bRet = pAuthorityField->HasURL();
434 break;
435 }
436
437 default: break;
438 }
439 return bRet;
440}
441
443{
444 m_nLang = nLang;
445}
446
447void SwField::ChangeFormat(sal_uInt32 const nFormat)
448{
449 m_nFormat = nFormat;
450}
451
453{
454 bool bRet = false;
455 switch (m_pType->Which())
456 {
459 bRet = true;
460 break;
461
463 bRet = 0 != (GetSubType() & FIXEDFLD);
464 break;
465
468 bRet = 0 != (GetFormat() & AF_FIXED);
469 break;
470
472 bRet = 0 != (GetFormat() & FF_FIXED);
473 break;
474
476 bRet = 0 != (GetSubType() & DI_SUB_FIXED);
477 break;
478 default: break;
479 }
480 return bRet;
481}
482
483OUString
484SwField::ExpandField(bool const bCached, SwRootFrame const*const pLayout) const
485{
487 {
488 if (!bCached) // #i85766# do not expand fields in clipboard documents
489 {
491 {
492 const SwAuthorityField* pAuthorityField = static_cast<const SwAuthorityField*>(this);
493 m_Cache = pAuthorityField->ConditionalExpandAuthIdentifier(pLayout);
494 }
495 else
496 m_Cache = ExpandImpl(pLayout);
497 }
498 return m_Cache;
499 }
500
501 return ExpandImpl(pLayout);
502}
503
504std::unique_ptr<SwField> SwField::CopyField() const
505{
506 std::unique_ptr<SwField> pNew = Copy();
507 // #i85766# cache expansion of source (for clipboard)
508 // use this->cache, not this->Expand(): only text formatting calls Expand()
509 pNew->m_Cache = m_Cache;
510 pNew->m_bUseFieldValueCache = m_bUseFieldValueCache;
511
512 return pNew;
513}
514
516OUString FormatNumber(sal_uInt32 nNum, SvxNumType nFormat, LanguageType nLang)
517{
518 if(SVX_NUM_PAGEDESC == nFormat)
519 return OUString::number( nNum );
520 SvxNumberType aNumber;
521
522 OSL_ENSURE(nFormat != SVX_NUM_NUMBER_NONE, "wrong number format" );
523
524 aNumber.SetNumberingType(nFormat);
525
526 if (nLang == LANGUAGE_NONE)
527 return aNumber.GetNumStr(nNum);
528 else
529 return aNumber.GetNumStr(nNum, LanguageTag::convertToLocale(nLang));
530}
531
532SwFieldTypesEnum SwFieldTypeFromString(std::u16string_view rString)
533{
534 if (rString == u"Date")
536 if (rString == u"Time")
538 if (rString == u"Filename")
540 if (rString == u"DatabaseName")
542 if (rString == u"Chapter")
544 if (rString == u"PageNumber")
546 if (rString == u"DocumentStatistics")
548 if (rString == u"Author")
550 if (rString == u"Set")
552 if (rString == u"Get")
554 if (rString == u"Formel")
556 if (rString == u"HiddenText")
558 if (rString == u"SetRef")
561}
562
564 : SwFieldType(nWhichId)
565 , m_pDoc(pDoc)
566 , m_bUseFormat(true)
567{
568}
569
571 : SwFieldType(rTyp.Which())
572 , m_pDoc(rTyp.GetDoc())
573 , m_bUseFormat(rTyp.UseFormat())
574{
575}
576
578OUString SwValueFieldType::ExpandValue( const double& rVal,
579 sal_uInt32 nFormat, LanguageType nLng) const
580{
581 if (rVal >= DBL_MAX) // error string for calculator
583
584 OUString sExpand;
586 const Color* pCol = nullptr;
587
588 // Bug #60010
589 LanguageType nFormatLng = ::lcl_GetLanguageOfFormat( nLng, nFormat, *pFormatter );
590
591 if( nFormat < SV_COUNTRY_LANGUAGE_OFFSET && LANGUAGE_SYSTEM != nFormatLng )
592 {
593 const SvNumberformat* pEntry = pFormatter->GetEntry(nFormat);
594
595 if (pEntry && nLng != pEntry->GetLanguage())
596 {
597 sal_uInt32 nNewFormat = pFormatter->GetFormatForLanguageIfBuiltIn(nFormat,
598 nFormatLng);
599 if (nNewFormat == nFormat)
600 {
601 // probably user-defined format
602 OUString sFormat(pEntry->GetFormatstring());
603 sal_Int32 nDummy;
604 SvNumFormatType nType = SvNumFormatType::DEFINED;
605
606 pFormatter->PutandConvertEntry(sFormat, nDummy, nType, nFormat,
607 pEntry->GetLanguage(), nFormatLng, false);
608 }
609 else
610 nFormat = nNewFormat;
611 }
612 OSL_ENSURE(pEntry, "unknown number format!");
613 }
614
615 if( pFormatter->IsTextFormat( nFormat ) )
616 {
617 pFormatter->GetOutputString(DoubleToString(rVal, nFormatLng), nFormat,
618 sExpand, &pCol);
619 }
620 else
621 {
622 pFormatter->GetOutputString(rVal, nFormat, sExpand, &pCol);
623 }
624 return sExpand;
625}
626
627OUString SwValueFieldType::DoubleToString(const double &rVal,
628 sal_uInt32 nFormat) const
629{
631 const SvNumberformat* pEntry = pFormatter->GetEntry(nFormat);
632
633 if (!pEntry)
634 return OUString();
635
636 return DoubleToString(rVal, pEntry->GetLanguage());
637}
638
639OUString SwValueFieldType::DoubleToString( const double &rVal,
640 LanguageType nLng ) const
641{
643
644 // Bug #60010
645 if( nLng == LANGUAGE_NONE )
646 nLng = LANGUAGE_SYSTEM;
647
648 pFormatter->ChangeIntl( nLng ); // get separator in the correct language
649 return ::rtl::math::doubleToUString( rVal, rtl_math_StringFormat_F, 12,
650 pFormatter->GetNumDecimalSep()[0], true );
651}
652
653SwValueField::SwValueField( SwValueFieldType* pFieldType, sal_uInt32 nFormat,
654 LanguageType nLng, const double fVal )
655 : SwField(pFieldType, nFormat, nLng)
656 , m_fValue(fVal)
657{
658}
659
661 : SwField(rField)
662 , m_fValue(rField.GetValue())
663{
664}
665
667{
668}
669
678{
679 SwDoc* pNewDoc = static_cast<SwValueFieldType *>(pNewType)->GetDoc();
680 SwDoc* pDoc = GetDoc();
681
682 if( pNewDoc && pDoc && pDoc != pNewDoc)
683 {
684 SvNumberFormatter* pFormatter = pNewDoc->GetNumberFormatter();
685
686 if( pFormatter && pFormatter->HasMergeFormatTable() &&
687 static_cast<SwValueFieldType *>(GetTyp())->UseFormat() )
688 SetFormat(pFormatter->GetMergeFormatIndex( GetFormat() ));
689 }
690
691 return SwField::ChgTyp(pNewType);
692}
693
695sal_uInt32 SwValueField::GetSystemFormat(SvNumberFormatter* pFormatter, sal_uInt32 nFormat)
696{
697 const SvNumberformat* pEntry = pFormatter->GetEntry(nFormat);
699
700 if (pEntry && nLng != pEntry->GetLanguage())
701 {
702 sal_uInt32 nNewFormat = pFormatter->GetFormatForLanguageIfBuiltIn(nFormat,
703 nLng);
704
705 if (nNewFormat == nFormat)
706 {
707 // probably user-defined format
708 SvNumFormatType nType = SvNumFormatType::DEFINED;
709 sal_Int32 nDummy;
710
711 OUString sFormat(pEntry->GetFormatstring());
712
713 sal_uInt32 nTempFormat = nFormat;
714 pFormatter->PutandConvertEntry(sFormat, nDummy, nType,
715 nTempFormat, pEntry->GetLanguage(), nLng, true);
716 nFormat = nTempFormat;
717 }
718 else
719 nFormat = nNewFormat;
720 }
721
722 return nFormat;
723}
724
726{
727 (void)xmlTextWriterStartElement(pWriter, BAD_CAST("SwValueField"));
728 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("m_fValue"), BAD_CAST(OString::number(m_fValue).getStr()));
729 SwField::dumpAsXml(pWriter);
730 (void)xmlTextWriterEndElement(pWriter);
731}
732
735{
736 if( IsAutomaticLanguage() &&
737 static_cast<SwValueFieldType *>(GetTyp())->UseFormat() &&
739 {
740 // Bug #60010
743 *pFormatter );
744
746 LANGUAGE_SYSTEM != nFormatLng ) &&
748 {
749 const SvNumberformat* pEntry = pFormatter->GetEntry(GetFormat());
750
751 if( pEntry && nFormatLng != pEntry->GetLanguage() )
752 {
753 sal_uInt32 nNewFormat = pFormatter->GetFormatForLanguageIfBuiltIn(
754 GetFormat(), nFormatLng );
755
756 if( nNewFormat == GetFormat() )
757 {
758 // probably user-defined format
759 SvNumFormatType nType = SvNumFormatType::DEFINED;
760 sal_Int32 nDummy;
761 OUString sFormat( pEntry->GetFormatstring() );
762 pFormatter->PutandConvertEntry( sFormat, nDummy, nType,
763 nNewFormat,
764 pEntry->GetLanguage(),
765 nFormatLng, false);
766 }
767 SetFormat( nNewFormat );
768 }
769 OSL_ENSURE(pEntry, "unknown number format!");
770 }
771 }
772
774}
775
777{
778 return m_fValue;
779}
780
781void SwValueField::SetValue( const double& rVal )
782{
783 m_fValue = rVal;
784}
785
786SwFormulaField::SwFormulaField( SwValueFieldType* pFieldType, sal_uInt32 nFormat, const double fVal)
787 : SwValueField(pFieldType, nFormat, LANGUAGE_SYSTEM, fVal)
788{
789}
790
792 : SwValueField(static_cast<SwValueFieldType *>(rField.GetTyp()), rField.GetFormat(),
793 rField.GetLanguage(), rField.GetValue())
794{
795}
796
798{
799 return m_sFormula;
800}
801
802void SwFormulaField::SetFormula(const OUString& rStr)
803{
804 m_sFormula = rStr;
805
806 sal_uLong nFormat(GetFormat());
807
808 if( nFormat && SAL_MAX_UINT32 != nFormat )
809 {
810 sal_Int32 nPos = 0;
811 double fTmpValue;
812 if( SwCalc::Str2Double( rStr, nPos, fTmpValue, GetDoc() ) )
813 SwValueField::SetValue( fTmpValue );
814 }
815}
816
817void SwFormulaField::SetExpandedFormula( const OUString& rStr )
818{
819 sal_uInt32 nFormat(GetFormat());
820
821 if (nFormat && nFormat != SAL_MAX_UINT32 && static_cast<SwValueFieldType *>(GetTyp())->UseFormat())
822 {
823 double fTmpValue;
824
825 if (GetDoc()->IsNumberFormat(rStr, nFormat, fTmpValue))
826 {
827 SwValueField::SetValue(fTmpValue);
828
829 m_sFormula = static_cast<SwValueFieldType *>(GetTyp())->DoubleToString(fTmpValue, nFormat);
830 return;
831 }
832 }
833 m_sFormula = rStr;
834}
835
837{
838 sal_uInt32 nFormat(GetFormat());
839
840 if (nFormat && nFormat != SAL_MAX_UINT32 && static_cast<SwValueFieldType *>(GetTyp())->UseFormat())
841 {
842 OUString sFormattedValue;
843 const Color* pCol = nullptr;
844
846
847 if (pFormatter->IsTextFormat(nFormat))
848 {
849 OUString sTempIn(static_cast<SwValueFieldType *>(GetTyp())->DoubleToString(GetValue(), nFormat));
850 pFormatter->GetOutputString(sTempIn, nFormat, sFormattedValue, &pCol);
851 }
852 else
853 {
854 pFormatter->GetOutputString(GetValue(), nFormat, sFormattedValue, &pCol);
855 }
856 return sFormattedValue;
857 }
858 else
859 return GetFormula();
860}
861
863{
864 return SwResId(STR_FIELD);
865}
866
868{
869 switch (Which())
870 {
878 return true;
879 default: break;
880 }
881 return false;
882}
883
885{
886 (void)xmlTextWriterStartElement(pWriter, BAD_CAST("SwField"));
887 (void)xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("symbol"), "%s", BAD_CAST(typeid(*this).name()));
888 (void)xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("ptr"), "%p", this);
889 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("m_nFormat"), BAD_CAST(OString::number(m_nFormat).getStr()));
890 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("m_nLang"), BAD_CAST(OString::number(m_nLang.get()).getStr()));
891 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("m_aTitle"), BAD_CAST(m_aTitle.toUtf8().getStr()));
892
893 (void)xmlTextWriterEndElement(pWriter);
894}
895
896/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
LanguageType getLanguageType(bool bResolveSystem=true) const
static css::lang::Locale convertToLocale(LanguageType nLangID, bool bResolveSystem=true)
NfIndexTableOffset GetIndexTableOffset(sal_uInt32 nFormat) const
void GetOutputString(const double &fOutNumber, sal_uInt32 nFIndex, OUString &sOutString, const Color **ppColor, bool bUseStarFormat=false)
bool PutandConvertEntry(OUString &rString, sal_Int32 &nCheckPos, SvNumFormatType &nType, sal_uInt32 &nKey, LanguageType eLnge, LanguageType eNewLnge, bool bConvertDateOrder, bool bReplaceBooleanEquivalent=true)
sal_uInt32 GetMergeFormatIndex(sal_uInt32 nOldFmt) const
bool IsTextFormat(sal_uInt32 nFIndex) const
void ChangeIntl(LanguageType eLnge)
bool HasMergeFormatTable() const
const SvNumberformat * GetEntry(sal_uInt32 nKey) const
sal_uInt32 GetFormatForLanguageIfBuiltIn(sal_uInt32 nFormat, LanguageType eLnge=LANGUAGE_DONTKNOW)
const OUString & GetNumDecimalSep() const
LanguageType GetLanguage() const
const OUString & GetFormatstring() const
const LanguageTag & GetLanguageTag() const
void SetNumberingType(SvxNumType nSet)
OUString GetNumStr(sal_Int32 nNo) const
invariant for SwAuthorityField is that it is always registered at its SwAuthorityFieldType via AddFie...
Definition: authfld.hxx:155
bool HasURL() const
Definition: authfld.cxx:610
OUString ConditionalExpandAuthIdentifier(SwRootFrame const *pLayout) const
For internal use only, in general continue using ExpandField() instead.
Definition: authfld.cxx:480
static bool Str2Double(const OUString &rStr, sal_Int32 &rPos, double &rVal)
Definition: calc.cxx:1392
Definition: doc.hxx:195
SvNumberFormatter * GetNumberFormatter(bool bCreate=true)
Definition: doc.hxx:1421
Instances of SwFields and those derived from it occur 0 to n times.
Definition: fldbas.hxx:243
virtual void UpdateFields()
Definition: fldbas.cxx:213
virtual OUString GetName() const
Only in derived classes.
Definition: fldbas.cxx:137
void GatherRefFields(std::vector< SwGetRefField * > &rvRFields, const sal_uInt16 nTyp)
Definition: fldbas.cxx:198
virtual void QueryValue(css::uno::Any &rVal, sal_uInt16 nWhich) const
Definition: fldbas.cxx:142
void GatherDdeTables(std::vector< SwDDETable * > &rvTables) const
Definition: fldbas.cxx:208
virtual void PutValue(const css::uno::Any &rVal, sal_uInt16 nWhich)
Definition: fldbas.cxx:145
void PrintHiddenPara()
Definition: fldbas.cxx:149
SwFieldIds Which() const
Definition: fldbas.hxx:274
static void GetFieldName_()
Sets up FieldNames; fldmgr.cxx!
Definition: fldmgr.cxx:1790
SwFormatField * FindFormatForField(const SwField *) const
Definition: fldbas.cxx:169
void CollectPostIts(std::vector< SwFormatField * > &rvFormatFields, IDocumentRedlineAccess const &rIDRA, bool HideRedlines)
Definition: fldbas.cxx:181
static const OUString & GetTypeStr(SwFieldTypesEnum nTypeId)
Definition: fldbas.cxx:122
void GatherNodeIndex(std::vector< SwNodeOffset > &rvNodeIndex)
Definition: fldbas.cxx:193
SwFieldType(SwFieldIds nWhichId)
Single argument ctors shall be explicit.
Definition: fldbas.cxx:131
void GatherFields(std::vector< SwFormatField * > &rvFormatFields, bool bCollectOnlyInDocNodes=true) const
Definition: fldbas.cxx:203
SwFormatField * FindFormatForPostItId(sal_uInt32 nPostItId) const
Definition: fldbas.cxx:175
virtual void dumpAsXml(xmlTextWriterPtr pWriter) const
Definition: fldbas.cxx:155
static std::vector< OUString > * s_pFieldNames
field names
Definition: fldbas.hxx:249
bool HasHiddenInformationNotes() const
Definition: fldbas.cxx:186
void dumpAsXml(xmlTextWriterPtr pWriter) const
Definition: fldbas.cxx:218
Base class of all fields.
Definition: fldbas.hxx:293
virtual void SetLanguage(LanguageType nLng)
Definition: fldbas.cxx:442
SwFieldTypesEnum GetTypeId() const
Definition: fldbas.cxx:257
SwFieldType * m_pType
Definition: fldbas.hxx:296
virtual OUString GetFormula() const
Definition: fldbas.cxx:331
virtual void dumpAsXml(xmlTextWriterPtr pWriter) const
Definition: fldbas.cxx:884
bool HasClickHdl() const
Does the field possess an action on its ClickHandler? (e.g. INetFields, ...).
Definition: fldbas.cxx:412
virtual OUString GetPar1() const
Definition: fldbas.cxx:321
std::unique_ptr< SwField > CopyField() const
Definition: fldbas.cxx:504
virtual ~SwField()
Definition: fldbas.cxx:243
virtual void SetPar1(const OUString &rStr)
Definition: fldbas.cxx:336
virtual void SetPar2(const OUString &rStr)
Definition: fldbas.cxx:339
virtual OUString ExpandImpl(SwRootFrame const *pLayout) const =0
bool IsClickable() const
Is this field clickable?
Definition: fldbas.cxx:867
void ChangeFormat(sal_uInt32 n)
Definition: fldbas.cxx:447
bool IsAutomaticLanguage() const
Definition: fldbas.hxx:384
SwField(SwFieldType *pTyp, sal_uInt32 nFormat=0, LanguageType nLang=LANGUAGE_SYSTEM, bool m_bUseFieldValueCache=true)
Definition: fldbas.cxx:229
virtual sal_uInt16 GetSubType() const
Definition: fldbas.cxx:342
OUString m_Cache
Cached expansion (for clipboard).
Definition: fldbas.hxx:295
OUString m_aTitle
Used for tooltip purposes when it's not-empty.
Definition: fldbas.hxx:302
void SetFormat(sal_uInt32 const nSet)
Definition: fldbas.hxx:308
sal_uInt32 m_nFormat
Definition: fldbas.hxx:297
LanguageType m_nLang
this can be either SvxNumType or SwChapterFormat depending on the subtype
Definition: fldbas.hxx:298
sal_uInt32 GetFormat() const
Query parameters for dialog and for BASIC.
Definition: fldbas.hxx:404
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt16 nWhichId) const
Definition: fldbas.cxx:351
OUString ExpandField(bool bCached, SwRootFrame const *pLayout) const
expand the field.
Definition: fldbas.cxx:484
bool m_bIsAutomaticLanguage
control the usage of the cached field value
Definition: fldbas.hxx:300
virtual OUString GetFieldName() const
get name or content
Definition: fldbas.cxx:305
virtual bool PutValue(const css::uno::Any &rVal, sal_uInt16 nWhichId)
Definition: fldbas.cxx:369
virtual SwFieldType * ChgTyp(SwFieldType *)
Set new type (used for copying among documents).
Definition: fldbas.cxx:402
virtual OUString GetDescription() const
Definition: fldbas.cxx:862
SwFieldType * GetTyp() const
Definition: fldbas.hxx:399
SwFieldIds Which() const
ResId.
Definition: fldbas.cxx:250
virtual std::unique_ptr< SwField > Copy() const =0
virtual OUString GetPar2() const
Definition: fldbas.cxx:326
bool m_bUseFieldValueCache
Definition: fldbas.hxx:299
virtual void SetSubType(sal_uInt16)
Definition: fldbas.cxx:347
bool IsFixed() const
Definition: fldbas.cxx:452
SwFormulaField(SwValueFieldType *pFieldType, sal_uInt32 nFormat, const double fVal)
Definition: fldbas.cxx:786
OUString m_sFormula
Definition: fldbas.hxx:478
OUString GetExpandedFormula() const
Definition: fldbas.cxx:836
void SetExpandedFormula(const OUString &rStr)
Definition: fldbas.cxx:817
void SetFormula(const OUString &rStr)
Definition: fldbas.cxx:802
virtual OUString GetFormula() const override
Definition: fldbas.cxx:797
The root element of a Writer document layout.
Definition: rootfrm.hxx:83
bool GetInputFlag() const
Definition: expfld.hxx:269
Fields containing values that have to be formatted via number formatter.
Definition: fldbas.hxx:416
OUString ExpandValue(const double &rVal, sal_uInt32 nFormat, LanguageType nLng) const
return value formatted as string
Definition: fldbas.cxx:578
SwValueFieldType(SwDoc *pDocPtr, SwFieldIds nWhichId)
Definition: fldbas.cxx:563
OUString DoubleToString(const double &rVal, LanguageType eLng) const
Definition: fldbas.cxx:639
SwDoc * m_pDoc
Definition: fldbas.hxx:418
virtual void SetLanguage(LanguageType nLng) override
set language of the format
Definition: fldbas.cxx:734
virtual SwFieldType * ChgTyp(SwFieldType *) override
Set a new type.
Definition: fldbas.cxx:677
void dumpAsXml(xmlTextWriterPtr pWriter) const override
Definition: fldbas.cxx:725
virtual double GetValue() const
Definition: fldbas.cxx:776
virtual ~SwValueField() override
Definition: fldbas.cxx:666
static sal_uInt32 GetSystemFormat(SvNumberFormatter *pFormatter, sal_uInt32 nFormat)
get format in office language
Definition: fldbas.cxx:695
SwDoc * GetDoc() const
Definition: fldbas.hxx:460
double m_fValue
Definition: fldbas.hxx:448
virtual void SetValue(const double &rVal)
Definition: fldbas.cxx:781
SwValueField(SwValueFieldType *pFieldType, sal_uInt32 nFormat, LanguageType nLang=LANGUAGE_SYSTEM, const double fVal=0.0)
Definition: fldbas.cxx:653
static ShellResource * GetShellRes()
Definition: viewsh.cxx:2654
int nCount
struct _xmlTextWriter * xmlTextWriterPtr
virtual SotClipboardFormatId GetFormat(const TransferableDataHelper &aHelper) override
@ PG_NEXT
Definition: docufld.hxx:93
@ PG_PREV
Definition: docufld.hxx:94
@ AF_FIXED
Definition: docufld.hxx:47
float u
OUString FormatNumber(sal_uInt32 nNum, SvxNumType nFormat, LanguageType nLang)
expand numbering
Definition: fldbas.cxx:516
static LanguageType lcl_GetLanguageOfFormat(LanguageType nLng, sal_uLong nFormat, const SvNumberFormatter &rFormatter)
Definition: fldbas.cxx:49
SwFieldTypesEnum SwFieldTypeFromString(std::u16string_view rString)
Definition: fldbas.cxx:532
SwFieldTypesEnum
List of FieldTypes at UI.
Definition: fldbas.hxx:94
@ FF_FIXED
Definition: fldbas.hxx:162
@ FIXEDFLD
Definition: fldbas.hxx:229
@ DATEFLD
Definition: fldbas.hxx:230
SwFieldIds
Definition: fldbas.hxx:45
@ TableOfAuthorities
constexpr TypedWhichId< SwMsgPoolItem > RES_HIDDENPARA_PRINT(178)
LanguageType GetAppLanguage()
Definition: init.cxx:726
#define LANGUAGE_SYSTEM
#define LANGUAGE_NONE
sal_uInt16 nPos
LanguageType GetLanguage(SfxItemSet const &aSet, sal_uInt16 nLangWhichId)
Definition: langhelper.cxx:390
size
const SwDocInfoSubType DI_SUB_FIXED
Definition: docufld.hxx:86
const SwExtendedSubType SUB_CMD
Show command.
Definition: fldbas.hxx:212
const SwGetSetExpType GSE_SEQ
Sequence.
Definition: fldbas.hxx:205
const SwGetSetExpType GSE_FORMULA
Formula.
Definition: fldbas.hxx:206
Dialog to specify the properties of date form field.
sal_uInt16 const m_nFormat
const char GetValue[]
QPRO_FUNC_TYPE nType
sal_uIntPtr sal_uLong
static LanguageType nLang
Definition: srtdlg.cxx:51
OUString aFixedStr
Definition: shellres.hxx:48
OUString aCalc_Error
Definition: shellres.hxx:41
UNDERLYING_TYPE get() const
SvxNumType
SVX_NUM_NUMBER_NONE
SVX_NUM_PAGEDESC
OUString SwResId(TranslateId aId)
Definition: swmodule.cxx:168
#define SAL_MAX_UINT32
#define FIELD_PROP_BOOL4
Definition: unofldmid.h:41
#define FIELD_PROP_TITLE
Definition: unofldmid.h:50
SvNumFormatType
#define SV_COUNTRY_LANGUAGE_OFFSET
NF_DATE_SYSTEM_SHORT
NF_NUMBER_SYSTEM
NF_DATETIME_SYSTEM_SHORT_HHMM
NF_DATE_SYSTEM_LONG