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 <comphelper/string.hxx>
28#include <svl/numformat.hxx>
29#include <svl/zforlist.hxx>
30#include <svl/zformat.hxx>
31#include <o3tl/enumarray.hxx>
32#include <osl/diagnose.h>
33#include <unofldmid.h>
34#include <doc.hxx>
35#include <fmtfld.hxx>
36#include <docufld.hxx>
37#include <expfld.hxx>
38#include <shellres.hxx>
39#include <calc.hxx>
40#include <strings.hrc>
41#include <docary.hxx>
42#include <authfld.hxx>
43#include <calbck.hxx>
44#include <viewsh.hxx>
45#include <hints.hxx>
46#include <unofield.hxx>
47
48using namespace ::com::sun::star;
49using namespace nsSwDocInfoSubType;
50
52 const SvNumberFormatter& rFormatter )
53{
54 if( nLng == LANGUAGE_NONE ) // Bug #60010
55 nLng = LANGUAGE_SYSTEM;
56 else if( nLng == ::GetAppLanguage() )
57 switch( rFormatter.GetIndexTableOffset( nFormat ))
58 {
63 nLng = LANGUAGE_SYSTEM;
64 break;
65 default: break;
66 }
67 return nLng;
68}
69
70// Globals
71
73std::vector<OUString>* SwFieldType::s_pFieldNames = nullptr;
74
75namespace
76{
77
79 /* SwFieldIds::Database */ SwFieldTypesEnum::Database,
80 /* SwFieldIds::User */ SwFieldTypesEnum::User,
81 /* SwFieldIds::Filename */ SwFieldTypesEnum::Filename,
82 /* SwFieldIds::DatabaseName */ SwFieldTypesEnum::DatabaseName,
83 /* SwFieldIds::Date */ SwFieldTypesEnum::Date,
84 /* SwFieldIds::Time */ SwFieldTypesEnum::Time,
85 /* SwFieldIds::PageNumber */ SwFieldTypesEnum::PageNumber, // dynamic
86 /* SwFieldIds::Author */ SwFieldTypesEnum::Author,
87 /* SwFieldIds::Chapter */ SwFieldTypesEnum::Chapter,
88 /* SwFieldIds::DocStat */ SwFieldTypesEnum::DocumentStatistics,
89 /* SwFieldIds::GetExp */ SwFieldTypesEnum::Get, // dynamic
90 /* SwFieldIds::SetExp */ SwFieldTypesEnum::Set, // dynamic
91 /* SwFieldIds::GetRef */ SwFieldTypesEnum::GetRef,
92 /* SwFieldIds::HiddenText */ SwFieldTypesEnum::HiddenText,
93 /* SwFieldIds::Postit */ SwFieldTypesEnum::Postit,
94 /* SwFieldIds::FixDate */ SwFieldTypesEnum::FixedDate,
95 /* SwFieldIds::FixTime */ SwFieldTypesEnum::FixedTime,
96 /* SwFieldIds::Reg */ SwFieldTypesEnum::Begin, // old (no change since 2000)
97 /* SwFieldIds::VarReg */ SwFieldTypesEnum::Begin, // old (no change since 2000)
98 /* SwFieldIds::SetRef */ SwFieldTypesEnum::SetRef,
99 /* SwFieldIds::Input */ SwFieldTypesEnum::Input,
100 /* SwFieldIds::Macro */ SwFieldTypesEnum::Macro,
101 /* SwFieldIds::Dde */ SwFieldTypesEnum::DDE,
102 /* SwFieldIds::Table */ SwFieldTypesEnum::Formel,
103 /* SwFieldIds::HiddenPara */ SwFieldTypesEnum::HiddenParagraph,
104 /* SwFieldIds::DocInfo */ SwFieldTypesEnum::DocumentInfo,
105 /* SwFieldIds::TemplateName */ SwFieldTypesEnum::TemplateName,
106 /* SwFieldIds::DbNextSet */ SwFieldTypesEnum::DatabaseNextSet,
107 /* SwFieldIds::DbNumSet */ SwFieldTypesEnum::DatabaseNumberSet,
108 /* SwFieldIds::DbSetNumber */ SwFieldTypesEnum::DatabaseSetNumber,
109 /* SwFieldIds::ExtUser */ SwFieldTypesEnum::ExtendedUser,
110 /* SwFieldIds::RefPageSet */ SwFieldTypesEnum::SetRefPage,
111 /* SwFieldIds::RefPageGet */ SwFieldTypesEnum::GetRefPage,
112 /* SwFieldIds::Internet */ SwFieldTypesEnum::Internet,
113 /* SwFieldIds::JumpEdit */ SwFieldTypesEnum::JumpEdit,
114 /* SwFieldIds::Script */ SwFieldTypesEnum::Script,
115 /* SwFieldIds::DateTime */ SwFieldTypesEnum::Begin, // dynamic
116 /* SwFieldIds::TableOfAuthorities*/ SwFieldTypesEnum::Authority,
117 /* SwFieldIds::CombinedChars */ SwFieldTypesEnum::CombinedChars,
118 /* SwFieldIds::Dropdown */ SwFieldTypesEnum::Dropdown,
119 /* SwFieldIds::ParagraphSignature */ SwFieldTypesEnum::ParagraphSignature
120 };
121
122}
123
125{
126 if (!s_pFieldNames)
128
129 return (*SwFieldType::s_pFieldNames)[static_cast<int>(nTypeId)];
130}
131
132// each field references a field type that is unique for each document
134 : sw::BroadcastingModify()
135 , m_nWhich(nWhichId)
136{
137}
138
139OUString SwFieldType::GetName() const
140{
141 return OUString();
142}
143
144void SwFieldType::QueryValue( uno::Any&, sal_uInt16 ) const
145{
146}
147void SwFieldType::PutValue( const uno::Any& , sal_uInt16 )
148{
149}
150
152{
154 SwClientNotify(*this, sw::LegacyModifyHint(&aHint, nullptr));
155}
156
158{
159 std::vector<SwFormatField*> vFields;
160 GatherFields(vFields);
161 if(!vFields.size())
162 return;
163 (void)xmlTextWriterStartElement(pWriter, BAD_CAST("SwFieldType"));
164 (void)xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("ptr"), "%p", this);
165 (void)xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("symbol"), "%s", BAD_CAST(typeid(*this).name()));
166 for(const auto pFormatField: vFields)
167 pFormatField->dumpAsXml(pWriter);
168 (void)xmlTextWriterEndElement(pWriter);
169}
170
172 SwFormatField* pFormat = nullptr;
173 CallSwClientNotify(sw::FindFormatForFieldHint(pField, pFormat));
174 return pFormat;
175}
176
178 SwFormatField* pFormat = nullptr;
179 CallSwClientNotify(sw::FindFormatForPostItIdHint(nPostItId, pFormat));
180 return pFormat;
181}
182
183void SwFieldType::CollectPostIts(std::vector<SwFormatField*>& rvFormatFields, IDocumentRedlineAccess const& rIDRA, const bool bHideRedlines)
184{
185 CallSwClientNotify(sw::CollectPostItsHint(rvFormatFields, rIDRA, bHideRedlines));
186}
187
189{
190 bool bHasHiddenInformationNotes = false;
191 CallSwClientNotify(sw::HasHiddenInformationNotesHint(bHasHiddenInformationNotes));
192 return bHasHiddenInformationNotes;
193}
194
195void SwFieldType::GatherNodeIndex(std::vector<SwNodeOffset>& rvNodeIndex)
196{
197 CallSwClientNotify(sw::GatherNodeIndexHint(rvNodeIndex));
198}
199
200void SwFieldType::GatherRefFields(std::vector<SwGetRefField*>& rvRFields, const sal_uInt16 nTyp)
201{
202 CallSwClientNotify(sw::GatherRefFieldsHint(rvRFields, nTyp));
203}
204
205void SwFieldType::GatherFields(std::vector<SwFormatField*>& rvFields, bool bCollectOnlyInDocNodes) const
206{
207 CallSwClientNotify(sw::GatherFieldsHint(rvFields, bCollectOnlyInDocNodes));
208}
209
210void SwFieldType::GatherDdeTables(std::vector<SwDDETable*>& rvTables) const
211{
212 CallSwClientNotify(sw::GatherDdeTablesHint(rvTables));
213}
214
216{
217 CallSwClientNotify(sw::DocPosUpdate(nDocPos));
218}
220{
221 CallSwClientNotify(sw::LegacyModifyHint(nullptr, nullptr));
222};
223
225{
226 m_wXFieldMaster = xFieldMaster.get();
227}
228
230{
231 (void)xmlTextWriterStartElement(pWriter, BAD_CAST("SwFieldTypes"));
232 sal_uInt16 nCount = size();
233 for (sal_uInt16 nType = 0; nType < nCount; ++nType)
234 (*this)[nType]->dumpAsXml(pWriter);
235 (void)xmlTextWriterEndElement(pWriter);
236}
237
238
239
240// Base class for all fields.
241// A field (multiple can exist) references a field type (can exists only once)
243 SwFieldType* pType,
244 sal_uInt32 nFormat,
246 bool bUseFieldValueCache)
247 : m_pType( pType )
248 , m_nFormat( nFormat )
249 , m_nLang( nLang )
250 , m_bUseFieldValueCache( bUseFieldValueCache )
251 , m_bIsAutomaticLanguage( true )
252{
253 assert(m_pType);
254}
255
257{
258}
259
260// instead of indirectly via the type
261
262#ifdef DBG_UTIL
264{
265 assert(m_pType);
266 return m_pType->Which();
267}
268#endif
269
271{
272
273 SwFieldTypesEnum nRet;
274 switch (m_pType->Which())
275 {
277 if (GetSubType() & FIXEDFLD)
279 else
281 break;
284 break;
285
287 nRet = static_cast<SwFieldTypesEnum>(GetSubType());
288 break;
289
293 else if( static_cast<const SwSetExpField*>(this)->GetInputFlag() )
295 else
297 break;
298
300 {
301 auto nSubType = GetSubType();
302 if( PG_NEXT == nSubType )
304 else if( PG_PREV == nSubType )
306 else
308 }
309 break;
310
311 default:
312 nRet = aTypeTab[ m_pType->Which() ];
313 }
314 return nRet;
315}
316
318OUString SwField::GetFieldName() const
319{
320 SwFieldTypesEnum nTypeId = GetTypeId();
322 {
323 nTypeId =
325 }
326 OUString sRet = SwFieldType::GetTypeStr( nTypeId );
327 if (IsFixed())
328 {
329 sRet += " " + SwViewShell::GetShellRes()->aFixedStr;
330 }
331 return sRet;
332}
333
334OUString SwField::GetPar1() const
335{
336 return OUString();
337}
338
339OUString SwField::GetPar2() const
340{
341 return OUString();
342}
343
344OUString SwField::GetFormula() const
345{
346 return GetPar2();
347}
348
349void SwField::SetPar1(const OUString& )
350{}
351
352void SwField::SetPar2(const OUString& )
353{}
354
355sal_uInt16 SwField::GetSubType() const
356{
357 return 0;
358}
359
360void SwField::SetSubType(sal_uInt16 )
361{
362}
363
364bool SwField::QueryValue( uno::Any& rVal, sal_uInt16 nWhichId ) const
365{
366 switch( nWhichId )
367 {
368 case FIELD_PROP_BOOL4:
369 rVal <<= !m_bIsAutomaticLanguage;
370 break;
371 case FIELD_PROP_TITLE:
372 {
373 rVal <<= m_aTitle;
374 }
375 break;
376 default:
377 assert(false);
378 }
379 return true;
380}
381
382bool SwField::PutValue( const uno::Any& rVal, sal_uInt16 nWhichId )
383{
384 switch( nWhichId )
385 {
386 case FIELD_PROP_BOOL4:
387 {
388 bool bFixed = false;
389 if(rVal >>= bFixed)
390 m_bIsAutomaticLanguage = !bFixed;
391 }
392 break;
393 case FIELD_PROP_TITLE:
394 {
395 OUString aTitle;
396 if (rVal >>= aTitle)
397 {
398 m_aTitle = aTitle;
399 }
400 }
401 break;
402 default:
403 assert(false);
404 }
405 return true;
406}
407
416{
417 assert(pNewType && pNewType->Which() == m_pType->Which());
418
419 SwFieldType* pOld = m_pType;
420 m_pType = pNewType;
421 return pOld;
422}
423
426{
427 bool bRet = false;
428 switch (m_pType->Which())
429 {
437 bRet = true;
438 break;
439
441 bRet = static_cast<const SwSetExpField*>(this)->GetInputFlag();
442 break;
443
444 default: break;
445 }
446 return bRet;
447}
448
450{
451 m_nLang = nLang;
452}
453
454void SwField::ChangeFormat(sal_uInt32 const nFormat)
455{
456 m_nFormat = nFormat;
457}
458
460{
461 bool bRet = false;
462 switch (m_pType->Which())
463 {
466 bRet = true;
467 break;
468
470 bRet = 0 != (GetSubType() & FIXEDFLD);
471 break;
472
475 bRet = 0 != (GetFormat() & AF_FIXED);
476 break;
477
479 bRet = 0 != (GetFormat() & FF_FIXED);
480 break;
481
483 bRet = 0 != (GetSubType() & DI_SUB_FIXED);
484 break;
485 default: break;
486 }
487 return bRet;
488}
489
490OUString
491SwField::ExpandField(bool const bCached, SwRootFrame const*const pLayout) const
492{
494 {
495 if (!bCached) // #i85766# do not expand fields in clipboard documents
496 {
498 {
499 const SwAuthorityField* pAuthorityField = static_cast<const SwAuthorityField*>(this);
500 m_Cache = pAuthorityField->ConditionalExpandAuthIdentifier(pLayout);
501 }
502 else
503 m_Cache = ExpandImpl(pLayout);
504 }
505 return m_Cache;
506 }
507
508 return ExpandImpl(pLayout);
509}
510
511std::unique_ptr<SwField> SwField::CopyField() const
512{
513 std::unique_ptr<SwField> pNew = Copy();
514 // #i85766# cache expansion of source (for clipboard)
515 // use this->cache, not this->Expand(): only text formatting calls Expand()
516 pNew->m_Cache = m_Cache;
517 pNew->m_bUseFieldValueCache = m_bUseFieldValueCache;
518
519 return pNew;
520}
521
523OUString FormatNumber(sal_uInt32 nNum, SvxNumType nFormat, LanguageType nLang)
524{
525 if(SVX_NUM_PAGEDESC == nFormat)
526 return OUString::number( nNum );
527 SvxNumberType aNumber;
528
529 OSL_ENSURE(nFormat != SVX_NUM_NUMBER_NONE, "wrong number format" );
530
531 aNumber.SetNumberingType(nFormat);
532
533 if (nLang == LANGUAGE_NONE)
534 return aNumber.GetNumStr(nNum);
535 else
536 return aNumber.GetNumStr(nNum, LanguageTag::convertToLocale(nLang));
537}
538
539SwFieldTypesEnum SwFieldTypeFromString(std::u16string_view rString)
540{
541 if (rString == u"Date")
543 if (rString == u"Time")
545 if (rString == u"Filename")
547 if (rString == u"DatabaseName")
549 if (rString == u"Chapter")
551 if (rString == u"PageNumber")
553 if (rString == u"DocumentStatistics")
555 if (rString == u"Author")
557 if (rString == u"Set")
559 if (rString == u"Get")
561 if (rString == u"Formel")
563 if (rString == u"HiddenText")
565 if (rString == u"SetRef")
568}
569
571 : SwFieldType(nWhichId)
572 , m_pDoc(pDoc)
573 , m_bUseFormat(true)
574{
575}
576
578 : SwFieldType(rTyp.Which())
579 , m_pDoc(rTyp.GetDoc())
580 , m_bUseFormat(rTyp.UseFormat())
581{
582}
583
585OUString SwValueFieldType::ExpandValue( const double& rVal,
586 sal_uInt32 nFormat, LanguageType nLng) const
587{
588 if (rVal >= DBL_MAX) // error string for calculator
590
591 OUString sExpand;
593 const Color* pCol = nullptr;
594
595 // Bug #60010
596 LanguageType nFormatLng = ::lcl_GetLanguageOfFormat( nLng, nFormat, *pFormatter );
597
598 if( nFormat < SV_COUNTRY_LANGUAGE_OFFSET && LANGUAGE_SYSTEM != nFormatLng )
599 {
600 const SvNumberformat* pEntry = pFormatter->GetEntry(nFormat);
601
602 if (pEntry && nLng != pEntry->GetLanguage())
603 {
604 sal_uInt32 nNewFormat = pFormatter->GetFormatForLanguageIfBuiltIn(nFormat,
605 nFormatLng);
606 if (nNewFormat == nFormat)
607 {
608 // probably user-defined format
609 OUString sFormat(pEntry->GetFormatstring());
610 sal_Int32 nDummy;
611 SvNumFormatType nType = SvNumFormatType::DEFINED;
612
613 pFormatter->PutandConvertEntry(sFormat, nDummy, nType, nFormat,
614 pEntry->GetLanguage(), nFormatLng, false);
615 }
616 else
617 nFormat = nNewFormat;
618 }
619 OSL_ENSURE(pEntry, "unknown number format!");
620 }
621
622 if( pFormatter->IsTextFormat( nFormat ) )
623 {
624 pFormatter->GetOutputString(DoubleToString(rVal, nFormatLng), nFormat,
625 sExpand, &pCol);
626 }
627 else
628 {
629 pFormatter->GetOutputString(rVal, nFormat, sExpand, &pCol);
630 }
631 return sExpand;
632}
633
634OUString SwValueFieldType::DoubleToString(const double &rVal,
635 sal_uInt32 nFormat) const
636{
638 const SvNumberformat* pEntry = pFormatter->GetEntry(nFormat);
639
640 if (!pEntry)
641 return OUString();
642
643 return DoubleToString(rVal, pEntry->GetLanguage());
644}
645
646OUString SwValueFieldType::DoubleToString( const double &rVal,
647 LanguageType nLng ) const
648{
650
651 // Bug #60010
652 if( nLng == LANGUAGE_NONE )
653 nLng = LANGUAGE_SYSTEM;
654
655 pFormatter->ChangeIntl( nLng ); // get separator in the correct language
656 return ::rtl::math::doubleToUString( rVal, rtl_math_StringFormat_F, 12,
657 pFormatter->GetNumDecimalSep()[0], true );
658}
659
660OUString SwValueFieldType::GetInputOrDateTime( const OUString& rInput, const double& rVal, sal_uInt32 nFormat ) const
661{
662 if (nFormat && nFormat != SAL_MAX_UINT32 && UseFormat())
663 {
665 const SvNumberformat* pEntry = pFormatter->GetEntry(nFormat);
666 if (pEntry && (pEntry->GetType() & SvNumFormatType::DATETIME))
667 {
668 OUString aEdit;
669 pFormatter->GetInputLineString( rVal, nFormat, aEdit);
670 return aEdit;
671 }
672 }
673 return rInput;
674}
675
676SwValueField::SwValueField( SwValueFieldType* pFieldType, sal_uInt32 nFormat,
677 LanguageType nLng, const double fVal )
678 : SwField(pFieldType, nFormat, nLng)
679 , m_fValue(fVal)
680{
681}
682
684 : SwField(rField)
685 , m_fValue(rField.GetValue())
686{
687}
688
690{
691}
692
701{
702 SwDoc* pNewDoc = static_cast<SwValueFieldType *>(pNewType)->GetDoc();
703 SwDoc* pDoc = GetDoc();
704
705 if( pNewDoc && pDoc && pDoc != pNewDoc)
706 {
707 SvNumberFormatter* pFormatter = pNewDoc->GetNumberFormatter();
708
709 if( pFormatter && pFormatter->HasMergeFormatTable() &&
710 static_cast<SwValueFieldType *>(GetTyp())->UseFormat() )
711 SetFormat(pFormatter->GetMergeFormatIndex( GetFormat() ));
712 }
713
714 return SwField::ChgTyp(pNewType);
715}
716
718sal_uInt32 SwValueField::GetSystemFormat(SvNumberFormatter* pFormatter, sal_uInt32 nFormat)
719{
720 const SvNumberformat* pEntry = pFormatter->GetEntry(nFormat);
722
723 if (pEntry && nLng != pEntry->GetLanguage())
724 {
725 sal_uInt32 nNewFormat = pFormatter->GetFormatForLanguageIfBuiltIn(nFormat,
726 nLng);
727
728 if (nNewFormat == nFormat)
729 {
730 // probably user-defined format
731 SvNumFormatType nType = SvNumFormatType::DEFINED;
732 sal_Int32 nDummy;
733
734 OUString sFormat(pEntry->GetFormatstring());
735
736 sal_uInt32 nTempFormat = nFormat;
737 pFormatter->PutandConvertEntry(sFormat, nDummy, nType,
738 nTempFormat, pEntry->GetLanguage(), nLng, true);
739 nFormat = nTempFormat;
740 }
741 else
742 nFormat = nNewFormat;
743 }
744
745 return nFormat;
746}
747
749{
750 (void)xmlTextWriterStartElement(pWriter, BAD_CAST("SwValueField"));
751 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("m_fValue"), BAD_CAST(OString::number(m_fValue).getStr()));
752 SwField::dumpAsXml(pWriter);
753 (void)xmlTextWriterEndElement(pWriter);
754}
755
758{
759 if( IsAutomaticLanguage() &&
760 static_cast<SwValueFieldType *>(GetTyp())->UseFormat() &&
762 {
763 // Bug #60010
766 *pFormatter );
767
769 LANGUAGE_SYSTEM != nFormatLng ) &&
771 {
772 const SvNumberformat* pEntry = pFormatter->GetEntry(GetFormat());
773
774 if( pEntry && nFormatLng != pEntry->GetLanguage() )
775 {
776 sal_uInt32 nNewFormat = pFormatter->GetFormatForLanguageIfBuiltIn(
777 GetFormat(), nFormatLng );
778
779 if( nNewFormat == GetFormat() )
780 {
781 // probably user-defined format
782 SvNumFormatType nType = SvNumFormatType::DEFINED;
783 sal_Int32 nDummy;
784 OUString sFormat( pEntry->GetFormatstring() );
785 pFormatter->PutandConvertEntry( sFormat, nDummy, nType,
786 nNewFormat,
787 pEntry->GetLanguage(),
788 nFormatLng, false);
789 }
790 SetFormat( nNewFormat );
791 }
792 OSL_ENSURE(pEntry, "unknown number format!");
793 }
794 }
795
797}
798
800{
801 return m_fValue;
802}
803
804void SwValueField::SetValue( const double& rVal )
805{
806 m_fValue = rVal;
807}
808
809SwFormulaField::SwFormulaField( SwValueFieldType* pFieldType, sal_uInt32 nFormat, const double fVal)
810 : SwValueField(pFieldType, nFormat, LANGUAGE_SYSTEM, fVal)
811{
812}
813
815 : SwValueField(static_cast<SwValueFieldType *>(rField.GetTyp()), rField.GetFormat(),
816 rField.GetLanguage(), rField.GetValue())
817{
818}
819
821{
822 return m_sFormula;
823}
824
825void SwFormulaField::SetFormula(const OUString& rStr)
826{
827 m_sFormula = rStr;
828
829 sal_uLong nFormat(GetFormat());
830
831 if( nFormat && SAL_MAX_UINT32 != nFormat )
832 {
833 sal_Int32 nPos = 0;
834 double fTmpValue;
835 // Uses the SwCalc document locale.
836 if( SwCalc::Str2Double( rStr, nPos, fTmpValue, GetDoc() ) )
837 SwValueField::SetValue( fTmpValue );
838 }
839}
840
841void SwFormulaField::SetExpandedFormula( const OUString& rStr )
842{
843 sal_uInt32 nFormat(GetFormat());
844
845 if (nFormat && nFormat != SAL_MAX_UINT32 && static_cast<SwValueFieldType *>(GetTyp())->UseFormat())
846 {
847 double fTmpValue;
848
849 if (GetDoc()->IsNumberFormat(rStr, nFormat, fTmpValue))
850 {
851 SwValueField::SetValue(fTmpValue);
852
853 // Will get reinterpreted by SwCalc when updating fields, so use
854 // the proper locale.
855 m_sFormula = static_cast<SwValueFieldType *>(GetTyp())->DoubleToString( fTmpValue,
857 return;
858 }
859 }
860 m_sFormula = rStr;
861}
862
864{
865 sal_uInt32 nFormat(GetFormat());
866
867 if (nFormat && nFormat != SAL_MAX_UINT32 && static_cast<SwValueFieldType *>(GetTyp())->UseFormat())
868 {
869 OUString sFormattedValue;
870 const Color* pCol = nullptr;
871
873
874 if (pFormatter->IsTextFormat(nFormat))
875 {
876 OUString sTempIn(static_cast<SwValueFieldType *>(GetTyp())->DoubleToString(GetValue(), nFormat));
877 pFormatter->GetOutputString(sTempIn, nFormat, sFormattedValue, &pCol);
878 }
879 else
880 {
881 pFormatter->GetOutputString(GetValue(), nFormat, sFormattedValue, &pCol);
882 }
883 return sFormattedValue;
884 }
885 else
886 return GetFormula();
887}
888
890{
891 // GetFormula() leads to problems with date formats because only the
892 // number string without formatting is returned (additionally that may or
893 // may not use a localized decimal separator due to the convoluted handling
894 // of "formula"). It must be used for expressions though because otherwise
895 // with GetPar2() only the value calculated by SwCalc would be displayed
896 // (instead of test2 = test + 1).
897 // Force a formatted edit value for date+time formats, assuming they are
898 // not editable calculated expressions if the formula doesn't contain
899 // arithmetic operators or assignment.
900
901 const OUString aFormula( GetFormula());
902
903 if (comphelper::string::indexOfAny( aFormula, u"=+-*/", 0) == -1)
904 return static_cast<SwValueFieldType*>(GetTyp())->GetInputOrDateTime( aFormula, GetValue(), GetFormat());
905
906 return aFormula;
907}
908
910{
911 return SwResId(STR_FIELD);
912}
913
915{
916 switch (Which())
917 {
925 return true;
926 default: break;
927 }
928 return false;
929}
930
932{
933 (void)xmlTextWriterStartElement(pWriter, BAD_CAST("SwField"));
934 (void)xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("symbol"), "%s", BAD_CAST(typeid(*this).name()));
935 (void)xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("ptr"), "%p", this);
936 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("m_nFormat"), BAD_CAST(OString::number(m_nFormat).getStr()));
937 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("m_nLang"), BAD_CAST(OString::number(m_nLang.get()).getStr()));
938 (void)xmlTextWriterWriteAttribute(pWriter, BAD_CAST("m_aTitle"), BAD_CAST(m_aTitle.toUtf8().getStr()));
939
940 (void)xmlTextWriterEndElement(pWriter);
941}
942
943/* 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 GetInputLineString(const double &fOutNumber, sal_uInt32 nFIndex, OUString &rOutString, bool bFiltering=false, bool bForceSystemLocale=false)
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
SvNumFormatType GetType() const
const LanguageTag & GetLanguageTag() const
void SetNumberingType(SvxNumType nSet)
OUString GetNumStr(sal_Int32 nNo) const
Represents an inserted bibliography entry, created using Insert -> Table of Contents and Index -> Bib...
Definition: authfld.hxx:161
OUString ConditionalExpandAuthIdentifier(SwRootFrame const *pLayout) const
For internal use only, in general continue using ExpandField() instead.
Definition: authfld.cxx:485
static LanguageType GetDocAppScriptLang(SwDoc const &rDoc)
Definition: calc.cxx:199
static bool Str2Double(const OUString &rStr, sal_Int32 &rPos, double &rVal)
Definition: calc.cxx:1393
Definition: doc.hxx:197
SvNumberFormatter * GetNumberFormatter(bool bCreate=true)
Definition: doc.hxx:1429
Instances of SwFields and those derived from it occur 0 to n times.
Definition: fldbas.hxx:247
void SetXObject(rtl::Reference< SwXFieldMaster > const &xFieldMaster)
Definition: fldbas.cxx:224
virtual void UpdateFields()
Definition: fldbas.cxx:219
virtual OUString GetName() const
Only in derived classes.
Definition: fldbas.cxx:139
void GatherRefFields(std::vector< SwGetRefField * > &rvRFields, const sal_uInt16 nTyp)
Definition: fldbas.cxx:200
virtual void QueryValue(css::uno::Any &rVal, sal_uInt16 nWhich) const
Definition: fldbas.cxx:144
void GatherDdeTables(std::vector< SwDDETable * > &rvTables) const
Definition: fldbas.cxx:210
virtual void PutValue(const css::uno::Any &rVal, sal_uInt16 nWhich)
Definition: fldbas.cxx:147
void PrintHiddenPara()
Definition: fldbas.cxx:151
SwFieldIds Which() const
Definition: fldbas.hxx:276
static void GetFieldName_()
Sets up FieldNames; fldmgr.cxx!
Definition: fldmgr.cxx:1788
SwFormatField * FindFormatForField(const SwField *) const
Definition: fldbas.cxx:171
void CollectPostIts(std::vector< SwFormatField * > &rvFormatFields, IDocumentRedlineAccess const &rIDRA, bool HideRedlines)
Definition: fldbas.cxx:183
static const OUString & GetTypeStr(SwFieldTypesEnum nTypeId)
Definition: fldbas.cxx:124
void GatherNodeIndex(std::vector< SwNodeOffset > &rvNodeIndex)
Definition: fldbas.cxx:195
SwFieldType(SwFieldIds nWhichId)
Single argument ctors shall be explicit.
Definition: fldbas.cxx:133
void GatherFields(std::vector< SwFormatField * > &rvFormatFields, bool bCollectOnlyInDocNodes=true) const
Definition: fldbas.cxx:205
void UpdateDocPos(const SwTwips nDocPos)
Definition: fldbas.cxx:215
SwFormatField * FindFormatForPostItId(sal_uInt32 nPostItId) const
Definition: fldbas.cxx:177
unotools::WeakReference< SwXFieldMaster > m_wXFieldMaster
Definition: fldbas.hxx:248
virtual void dumpAsXml(xmlTextWriterPtr pWriter) const
Definition: fldbas.cxx:157
static std::vector< OUString > * s_pFieldNames
field names
Definition: fldbas.hxx:253
bool HasHiddenInformationNotes() const
Definition: fldbas.cxx:188
void dumpAsXml(xmlTextWriterPtr pWriter) const
Definition: fldbas.cxx:229
Base class of all fields.
Definition: fldbas.hxx:296
virtual void SetLanguage(LanguageType nLng)
Definition: fldbas.cxx:449
SwFieldTypesEnum GetTypeId() const
Definition: fldbas.cxx:270
SwFieldType * m_pType
Definition: fldbas.hxx:299
virtual OUString GetFormula() const
Definition: fldbas.cxx:344
virtual void dumpAsXml(xmlTextWriterPtr pWriter) const
Definition: fldbas.cxx:931
bool HasClickHdl() const
Does the field possess an action on its ClickHandler? (e.g. INetFields, ...).
Definition: fldbas.cxx:425
virtual OUString GetPar1() const
Definition: fldbas.cxx:334
std::unique_ptr< SwField > CopyField() const
Definition: fldbas.cxx:511
virtual ~SwField()
Definition: fldbas.cxx:256
virtual void SetPar1(const OUString &rStr)
Definition: fldbas.cxx:349
virtual void SetPar2(const OUString &rStr)
Definition: fldbas.cxx:352
virtual OUString ExpandImpl(SwRootFrame const *pLayout) const =0
bool IsClickable() const
Is this field clickable?
Definition: fldbas.cxx:914
void ChangeFormat(sal_uInt32 n)
Definition: fldbas.cxx:454
bool IsAutomaticLanguage() const
Definition: fldbas.hxx:387
SwField(SwFieldType *pTyp, sal_uInt32 nFormat=0, LanguageType nLang=LANGUAGE_SYSTEM, bool m_bUseFieldValueCache=true)
Definition: fldbas.cxx:242
virtual sal_uInt16 GetSubType() const
Definition: fldbas.cxx:355
OUString m_Cache
Cached expansion (for clipboard).
Definition: fldbas.hxx:298
OUString m_aTitle
Used for tooltip purposes when it's not-empty.
Definition: fldbas.hxx:305
void SetFormat(sal_uInt32 const nSet)
Definition: fldbas.hxx:311
sal_uInt32 m_nFormat
Definition: fldbas.hxx:300
LanguageType m_nLang
this can be either SvxNumType or SwChapterFormat depending on the subtype
Definition: fldbas.hxx:301
sal_uInt32 GetFormat() const
Query parameters for dialog and for BASIC.
Definition: fldbas.hxx:407
virtual bool QueryValue(css::uno::Any &rVal, sal_uInt16 nWhichId) const
Definition: fldbas.cxx:364
OUString ExpandField(bool bCached, SwRootFrame const *pLayout) const
expand the field.
Definition: fldbas.cxx:491
bool m_bIsAutomaticLanguage
control the usage of the cached field value
Definition: fldbas.hxx:303
virtual OUString GetFieldName() const
get name or content
Definition: fldbas.cxx:318
virtual bool PutValue(const css::uno::Any &rVal, sal_uInt16 nWhichId)
Definition: fldbas.cxx:382
virtual SwFieldType * ChgTyp(SwFieldType *)
Set new type (used for copying among documents).
Definition: fldbas.cxx:415
virtual OUString GetDescription() const
Definition: fldbas.cxx:909
SwFieldType * GetTyp() const
Definition: fldbas.hxx:402
SwFieldIds Which() const
ResId.
Definition: fldbas.cxx:263
virtual std::unique_ptr< SwField > Copy() const =0
virtual OUString GetPar2() const
Definition: fldbas.cxx:339
bool m_bUseFieldValueCache
Definition: fldbas.hxx:302
virtual void SetSubType(sal_uInt16)
Definition: fldbas.cxx:360
bool IsFixed() const
Definition: fldbas.cxx:459
OUString GetInputOrDateTime() const
Query formula or formatted value for dialog.
Definition: fldbas.cxx:889
SwFormulaField(SwValueFieldType *pFieldType, sal_uInt32 nFormat, const double fVal)
Definition: fldbas.cxx:809
OUString m_sFormula
Definition: fldbas.hxx:483
OUString GetExpandedFormula() const
Definition: fldbas.cxx:863
void SetExpandedFormula(const OUString &rStr)
Definition: fldbas.cxx:841
void SetFormula(const OUString &rStr)
Definition: fldbas.cxx:825
virtual OUString GetFormula() const override
Definition: fldbas.cxx:820
The root element of a Writer document layout.
Definition: rootfrm.hxx:85
bool GetInputFlag() const
Definition: expfld.hxx:269
Fields containing values that have to be formatted via number formatter.
Definition: fldbas.hxx:419
bool UseFormat() const
Definition: fldbas.hxx:436
OUString ExpandValue(const double &rVal, sal_uInt32 nFormat, LanguageType nLng) const
return value formatted as string
Definition: fldbas.cxx:585
SwValueFieldType(SwDoc *pDocPtr, SwFieldIds nWhichId)
Definition: fldbas.cxx:570
OUString DoubleToString(const double &rVal, LanguageType eLng) const
Definition: fldbas.cxx:646
SwDoc * m_pDoc
Definition: fldbas.hxx:421
OUString GetInputOrDateTime(const OUString &rInput, const double &rVal, sal_uInt32 nFormat) const
Query input or formatted value for dialog.
Definition: fldbas.cxx:660
virtual void SetLanguage(LanguageType nLng) override
set language of the format
Definition: fldbas.cxx:757
virtual SwFieldType * ChgTyp(SwFieldType *) override
Set a new type.
Definition: fldbas.cxx:700
void dumpAsXml(xmlTextWriterPtr pWriter) const override
Definition: fldbas.cxx:748
virtual double GetValue() const
Definition: fldbas.cxx:799
virtual ~SwValueField() override
Definition: fldbas.cxx:689
static sal_uInt32 GetSystemFormat(SvNumberFormatter *pFormatter, sal_uInt32 nFormat)
get format in office language
Definition: fldbas.cxx:718
SwDoc * GetDoc() const
Definition: fldbas.hxx:465
double m_fValue
Definition: fldbas.hxx:453
virtual void SetValue(const double &rVal)
Definition: fldbas.cxx:804
SwValueField(SwValueFieldType *pFieldType, sal_uInt32 nFormat, LanguageType nLang=LANGUAGE_SYSTEM, const double fVal=0.0)
Definition: fldbas.cxx:676
static ShellResource * GetShellRes()
Definition: viewsh.cxx:2664
DocPosUpdate is sent to signal that only the frames from or to a specified document-global position h...
Definition: hints.hxx:146
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:523
static LanguageType lcl_GetLanguageOfFormat(LanguageType nLng, sal_uLong nFormat, const SvNumberFormatter &rFormatter)
Definition: fldbas.cxx:51
SwFieldTypesEnum SwFieldTypeFromString(std::u16string_view rString)
Definition: fldbas.cxx:539
SwFieldTypesEnum
List of FieldTypes at UI.
Definition: fldbas.hxx:98
@ FF_FIXED
Definition: fldbas.hxx:166
@ FIXEDFLD
Definition: fldbas.hxx:233
@ DATEFLD
Definition: fldbas.hxx:234
SwFieldIds
Definition: fldbas.hxx:49
@ TableOfAuthorities
constexpr TypedWhichId< SwMsgPoolItem > RES_HIDDENPARA_PRINT(178)
LanguageType GetAppLanguage()
Definition: init.cxx:741
#define LANGUAGE_SYSTEM
#define LANGUAGE_NONE
sal_uInt16 nPos
LanguageType GetLanguage(SfxItemSet const &aSet, sal_uInt16 nLangWhichId)
Definition: langhelper.cxx:365
size
sal_Int32 indexOfAny(std::u16string_view rIn, sal_Unicode const *const pChars, sal_Int32 const nPos)
const SwDocInfoSubType DI_SUB_FIXED
Definition: docufld.hxx:86
const SwExtendedSubType SUB_CMD
Show command.
Definition: fldbas.hxx:216
const SwGetSetExpType GSE_SEQ
Sequence.
Definition: fldbas.hxx:209
const SwGetSetExpType GSE_FORMULA
Formula.
Definition: fldbas.hxx:210
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
tools::Long SwTwips
Definition: swtypes.hxx:51
#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