Update git submodules
[LibreOffice.git] / sw / inc / usrfld.hxx
blob949d84f930ccb9fcf8e462ced8f4f5e53f325cd5
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #pragma once
21 #include "swdllapi.h"
22 #include "fldbas.hxx"
24 class SfxPoolItem;
25 class SwCalc;
26 class SwDoc;
28 /**
29 * The shared part of a user field.
31 * Tracks the value, but conversion between the float and string representation
32 * always happens with the system locale.
34 class SW_DLLPUBLIC SwUserFieldType final : public SwValueFieldType
36 bool m_bValidValue : 1;
37 bool m_bDeleted : 1;
38 /// Float value type.
39 double m_nValue;
40 OUString m_aName;
41 /// String value type.
42 OUString m_aContent;
43 /// Language used by m_aContents
44 OUString m_aContentLang;
45 sal_uInt16 m_nType;
47 public:
48 SwUserFieldType( SwDoc* pDocPtr, const OUString& );
50 virtual OUString GetName() const override;
51 virtual std::unique_ptr<SwFieldType> Copy() const override;
53 OUString Expand(sal_uInt32 nFormat, sal_uInt16 nSubType, LanguageType nLng);
55 OUString GetContent( sal_uInt32 nFormat = 0 ) const;
56 void SetContent( const OUString& rStr, sal_uInt32 nFormat = 0 );
58 OUString GetInputOrDateTime( sal_uInt32 nFormat ) const;
60 inline bool IsValid() const;
62 double GetValue(SwCalc& rCalc); // Recalculate member nValue.
63 inline double GetValue() const;
64 inline void SetValue(const double nVal);
66 inline sal_uInt16 GetType() const;
67 inline void SetType(sal_uInt16);
69 bool IsDeleted() const { return m_bDeleted; }
70 void SetDeleted( bool b ) { m_bDeleted = b; }
72 virtual void QueryValue( css::uno::Any& rVal, sal_uInt16 nMId ) const override;
73 virtual void PutValue( const css::uno::Any& rVal, sal_uInt16 nMId ) override;
74 virtual void UpdateFields() override;
75 void EnsureValid();
76 void dumpAsXml(xmlTextWriterPtr pWriter) const override;
78 private:
79 virtual void SwClientNotify(const SwModify&, const SfxHint&) override;
82 inline bool SwUserFieldType::IsValid() const
83 { return m_bValidValue; }
85 inline double SwUserFieldType::GetValue() const
86 { return m_nValue; }
88 inline void SwUserFieldType::SetValue(const double nVal)
89 { m_nValue = nVal; }
91 inline sal_uInt16 SwUserFieldType::GetType() const
92 { return m_nType; }
94 inline void SwUserFieldType::SetType(sal_uInt16 nSub)
96 m_nType = nSub;
97 EnableFormat(!(nSub & nsSwGetSetExpType::GSE_STRING));
101 * The non-shared part of a user field.
103 * Tracks the number format and the language, conversion between the float and
104 * string representation is independent from the system locale.
106 class SW_DLLPUBLIC SwUserField final : public SwValueField
108 sal_uInt16 m_nSubType;
110 virtual OUString ExpandImpl(SwRootFrame const* pLayout) const override;
111 virtual std::unique_ptr<SwField> Copy() const override;
113 public:
114 SwUserField(SwUserFieldType*, sal_uInt16 nSub, sal_uInt32 nFormat);
116 virtual sal_uInt16 GetSubType() const override;
117 virtual void SetSubType(sal_uInt16 nSub) override;
119 virtual double GetValue() const override;
120 virtual void SetValue( const double& rVal ) override;
122 virtual OUString GetFieldName() const override;
124 // Name cannot be changed.
125 virtual OUString GetPar1() const override;
127 // Content.
128 virtual OUString GetPar2() const override;
129 virtual void SetPar2(const OUString& rStr) override;
130 virtual bool QueryValue( css::uno::Any& rVal, sal_uInt16 nWhichId ) const override;
131 virtual bool PutValue( const css::uno::Any& rVal, sal_uInt16 nWhichId ) override;
132 void dumpAsXml(xmlTextWriterPtr pWriter) const override;
135 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */