xref: /AOO41X/main/sw/inc/expfld.hxx (revision 1bf9188d51af09ae398172576afbe6ea8b0dcaa3)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 #ifndef SW_EXPFLD_HXX
24 #define SW_EXPFLD_HXX
25 
26 #include <svl/svarray.hxx>
27 #include "swdllapi.h"
28 #include <fldbas.hxx>
29 #include <cellfml.hxx>
30 
31 class SfxPoolItem;
32 class SwTxtNode;
33 class SwFrm;
34 struct SwPosition;
35 class SwTxtFld;
36 class SwDoc;
37 class SwFmtFld;
38 class _SetGetExpFlds;
39 class SwEditShell;
40 
41 // Vorwaertsdeklaration: besorge den "Body-TextNode", fuer Exp.Fld in Fly's
42 //                      Header/Footers/Footnodes
43 const SwTxtNode* GetBodyTxtNode( const SwDoc& pDoc, SwPosition& rPos,
44                                  const SwFrm& rFrm );
45 // Wandlung Address -> Adressen
46 void ReplacePoint(String& sTmpName, sal_Bool bWithCommandType = sal_False);
47 
48 struct _SeqFldLstElem
49 {
50     String sDlgEntry;
51     sal_uInt16 nSeqNo;
52 
_SeqFldLstElem_SeqFldLstElem53     _SeqFldLstElem( const String& rStr, sal_uInt16 nNo )
54         : sDlgEntry( rStr ), nSeqNo( nNo )
55     {}
56 };
57 SV_DECL_PTRARR_DEL( _SwSeqFldList, _SeqFldLstElem*, 10, 10 )
58 
59 class SW_DLLPUBLIC SwSeqFldList : public _SwSeqFldList
60 {
61 public:
SwSeqFldList()62     SwSeqFldList()  : _SwSeqFldList( 10, 10 ) {}
63 
64     sal_Bool InsertSort( _SeqFldLstElem* );
65     sal_Bool SeekEntry( const _SeqFldLstElem& , sal_uInt16* pPos = 0 );
66 };
67 
68 /*--------------------------------------------------------------------
69     Beschreibung: Ausdruck
70  --------------------------------------------------------------------*/
71 
72 class SwGetExpFieldType : public SwValueFieldType
73 {
74 public:
75         SwGetExpFieldType(SwDoc* pDoc);
76         virtual SwFieldType*    Copy() const;
77 
78         // ueberlagert, weil das Get-Field nicht veraendert werden kann
79         // und dann auch nicht aktualisiert werden muss. Aktualisierung
80         // erfolgt beim Aendern von Set-Werten !
81 protected:
82    virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew );
83 };
84 
85 /*--------------------------------------------------------------------
86     Beschreibung: GetExperession
87  --------------------------------------------------------------------*/
88 
89 class SW_DLLPUBLIC SwGetExpField : public SwFormulaField
90 {
91     String          sExpand;
92     sal_Bool            bIsInBodyTxt;
93     sal_uInt16          nSubType;
94 
95     bool            bLateInitialization; // #i82544#
96 
97     virtual String              Expand() const;
98     virtual SwField*            Copy() const;
99 
100 public:
101     SwGetExpField( SwGetExpFieldType*, const String& rFormel,
102                    sal_uInt16 nSubType = nsSwGetSetExpType::GSE_EXPR, sal_uLong nFmt = 0);
103 
104     virtual void                SetValue( const double& rVal );
105     virtual void                SetLanguage(sal_uInt16 nLng);
106 
107     inline const String&        GetExpStr() const;
108     inline void                 ChgExpStr(const String& rExpand);
109 
110     // wird von der Formatierung abgefragt
111     inline sal_Bool                 IsInBodyTxt() const;
112     // wird von UpdateExpFlds gesetzt (dort ist die Node-Position bekannt)
113     inline void                 ChgBodyTxtFlag( sal_Bool bIsInBody );
114     // fuer Felder in Header/Footer/Footnotes/Flys:
115     // (wird nur von der Formatierung aufgerufen!!)
116     void                        ChangeExpansion( const SwFrm&, const SwTxtFld& );
117 
118     virtual String      GetFieldName() const;
119 
120     // Die Formel aendern
121     virtual String              GetPar2() const;
122     virtual void                SetPar2(const String& rStr);
123 
124     virtual sal_uInt16              GetSubType() const;
125     virtual void                SetSubType(sal_uInt16 nType);
126     virtual sal_Bool        QueryValue( com::sun::star::uno::Any& rVal, sal_uInt16 nWhich ) const;
127     virtual sal_Bool        PutValue( const com::sun::star::uno::Any& rVal, sal_uInt16 nWhich );
128 
129     static sal_uInt16       GetReferenceTextPos( const SwFmtFld& rFmt, SwDoc& rDoc);
130     // #i82544#
SetLateInitialization()131     void                SetLateInitialization() { bLateInitialization = true;}
132 };
133 
ChgExpStr(const String & rExpand)134 inline void SwGetExpField::ChgExpStr(const String& rExpand)
135     { sExpand = rExpand;}
136 
GetExpStr() const137 inline const String& SwGetExpField::GetExpStr() const
138     { return sExpand;   }
139 
140 // wird von der Formatierung abgefragt
IsInBodyTxt() const141 inline sal_Bool SwGetExpField::IsInBodyTxt() const
142     { return bIsInBodyTxt; }
143 
144 // wird von UpdateExpFlds gesetzt (dort ist die Node-Position bekannt)
ChgBodyTxtFlag(sal_Bool bIsInBody)145 inline void SwGetExpField::ChgBodyTxtFlag( sal_Bool bIsInBody )
146     { bIsInBodyTxt = bIsInBody; }
147 
148 
149 /*--------------------------------------------------------------------
150     Beschreibung: Ausdruck setzen
151  --------------------------------------------------------------------*/
152 
153 class SwSetExpField;
154 
155 class SW_DLLPUBLIC SwSetExpFieldType : public SwValueFieldType
156 {
157     String      sName;
158     const SwNode* pOutlChgNd;
159     String      sDelim;
160     sal_uInt16      nType;
161     sal_uInt8       nLevel;
162     sal_Bool        bDeleted;
163 
164 protected:
165    virtual void Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew );
166 
167 public:
168     SwSetExpFieldType( SwDoc* pDoc, const String& rName,
169                         sal_uInt16 nType = nsSwGetSetExpType::GSE_EXPR );
170     virtual SwFieldType*    Copy() const;
171     virtual const String&   GetName() const;
172 
173     inline void             SetType(sal_uInt16 nTyp);
174     inline sal_uInt16           GetType() const;
175 
176     void                    SetSeqFormat(sal_uLong nFormat);
177     sal_uLong                   GetSeqFormat();
178 
IsDeleted() const179     sal_Bool                    IsDeleted() const       { return bDeleted; }
SetDeleted(sal_Bool b)180     void                    SetDeleted( sal_Bool b )    { bDeleted = b; }
181 
182     // ueberlagert, weil das Set-Field selbst dafuer sorgt, das
183     // es aktualisiert wird.
184     inline const String&    GetSetRefName() const;
185 
186     sal_uInt16 SetSeqRefNo( SwSetExpField& rFld );
187 
188     sal_uInt16 GetSeqFldList( SwSeqFldList& rList );
189     String MakeSeqName( sal_uInt16 nSeqNo );
190 
191     // Seqencefelder ggfs. Kapitelweise numerieren
192 //  sal_Unicode GetDelimiter() const        { return cDelim; }
193 //  void SetDelimiter( sal_Unicode c )      { cDelim = c; }
GetDelimiter() const194     const String& GetDelimiter() const      { return sDelim; }
SetDelimiter(const String & s)195     void SetDelimiter( const String& s )    { sDelim = s; }
GetOutlineLvl() const196     sal_uInt8 GetOutlineLvl() const                 { return nLevel; }
SetOutlineLvl(sal_uInt8 n)197     void SetOutlineLvl( sal_uInt8 n )           { nLevel = n; }
198     void SetChapter( SwSetExpField& rFld, const SwNode& rNd );
199     // Member nur fuers SwDoc::UpdateExpFld - wird nur waehrend der Laufzeit
200     // von SequencefeldTypen benoetigt!!!
GetOutlineChgNd() const201     const SwNode* GetOutlineChgNd() const   { return pOutlChgNd; }
SetOutlineChgNd(const SwNode * p)202     void SetOutlineChgNd( const SwNode* p ) { pOutlChgNd = p; }
203 
204     virtual sal_Bool        QueryValue( com::sun::star::uno::Any& rVal, sal_uInt16 nWhich ) const;
205     virtual sal_Bool        PutValue( const com::sun::star::uno::Any& rVal, sal_uInt16 nWhich );
206 };
207 
SetType(sal_uInt16 nTyp)208 inline void SwSetExpFieldType::SetType( sal_uInt16 nTyp )
209 {
210         nType = nTyp;
211         EnableFormat( !(nType & (nsSwGetSetExpType::GSE_SEQ|nsSwGetSetExpType::GSE_STRING)));
212 }
213 
GetType() const214 inline sal_uInt16 SwSetExpFieldType::GetType() const
215     { return nType;   }
216 
GetSetRefName() const217 inline const String& SwSetExpFieldType::GetSetRefName() const
218     { return sName; }
219 
220 
221 /*--------------------------------------------------------------------
222     Beschreibung: Ausdruck
223  --------------------------------------------------------------------*/
224 
225 class SW_DLLPUBLIC SwSetExpField : public SwFormulaField
226 {
227     String          sExpand;
228     String          aPText;
229     String          aSeqText;
230     sal_Bool            bInput;
231     sal_uInt16          nSeqNo;
232     sal_uInt16          nSubType;
233 
234     virtual String              Expand() const;
235     virtual SwField*            Copy() const;
236 
237 public:
238     SwSetExpField(SwSetExpFieldType*, const String& rFormel, sal_uLong nFmt = 0);
239 
240     virtual void                SetValue( const double& rVal );
241 
242     inline const String&        GetExpStr() const;
243 
244     inline void                 ChgExpStr( const String& rExpand );
245 
246     inline void                 SetPromptText(const String& rStr);
247     inline const                String& GetPromptText() const;
248 
249     inline void                 SetInputFlag(sal_Bool bInp);
250     inline sal_Bool                 GetInputFlag() const;
251 
252     virtual String              GetFieldName() const;
253 
254     virtual sal_uInt16              GetSubType() const;
255     virtual void                SetSubType(sal_uInt16 nType);
256 
257     inline sal_Bool                 IsSequenceFld() const;
258 
259     // fuer SequenceFelder - logische Nummer
SetSeqNumber(sal_uInt16 n)260     inline void                 SetSeqNumber( sal_uInt16 n )    { nSeqNo = n; }
GetSeqNumber() const261     inline sal_uInt16               GetSeqNumber() const        { return nSeqNo; }
262 
263     // Der Name nur erfragen
264     virtual const String&       GetPar1()   const;
265 
266     // Die Formel
267     virtual String              GetPar2()   const;
268     virtual void                SetPar2(const String& rStr);
269     virtual sal_Bool        QueryValue( com::sun::star::uno::Any& rVal, sal_uInt16 nWhich ) const;
270     virtual sal_Bool        PutValue( const com::sun::star::uno::Any& rVal, sal_uInt16 nWhich );
271 };
272 
GetExpStr() const273 inline const String& SwSetExpField::GetExpStr() const
274     { return sExpand;       }
275 
ChgExpStr(const String & rExpand)276 inline void SwSetExpField::ChgExpStr( const String& rExpand )
277     { sExpand = rExpand;    }
278 
SetPromptText(const String & rStr)279 inline void  SwSetExpField::SetPromptText(const String& rStr)
280     { aPText = rStr;        }
281 
GetPromptText() const282 inline const String& SwSetExpField::GetPromptText() const
283     { return aPText;        }
284 
SetInputFlag(sal_Bool bInp)285 inline void SwSetExpField::SetInputFlag(sal_Bool bInp)
286     { bInput = bInp; }
287 
GetInputFlag() const288 inline sal_Bool SwSetExpField::GetInputFlag() const
289     { return bInput; }
290 
IsSequenceFld() const291 inline sal_Bool SwSetExpField::IsSequenceFld() const
292     { return 0 != (nsSwGetSetExpType::GSE_SEQ & ((SwSetExpFieldType*)GetTyp())->GetType()); }
293 
294 /*--------------------------------------------------------------------
295     Beschreibung: Eingabe im Text/Variable setzen
296  --------------------------------------------------------------------*/
297 
298 class SwInputFieldType : public SwFieldType
299 {
300     SwDoc* pDoc;
301 public:
302     SwInputFieldType( SwDoc* pDoc );
303 
304     virtual SwFieldType* Copy() const;
305 
GetDoc() const306     SwDoc* GetDoc() const { return pDoc; }
307 };
308 
309 /*--------------------------------------------------------------------
310     Beschreibung: Eingabefeld
311  --------------------------------------------------------------------*/
312 
313 class SW_DLLPUBLIC SwInputField : public SwField
314 {
315     mutable String aContent;
316     String aPText;
317     String aHelp;
318     String aToolTip;
319     sal_uInt16 nSubType;
320     bool mbIsFormField;
321 
322     SwFmtFld* mpFmtFld; // attribute to which the <SwInputField> belongs to
323 
324     virtual String          Expand() const;
325     virtual SwField*        Copy() const;
326 
327     // Accessing Input Field's content
328     const String& getContent() const;
329 
330     void LockNotifyContentChange();
331     void UnlockNotifyContentChange();
332 
333 public:
334     // Direkte Eingabe ueber Dialog alten Wert loeschen
335     SwInputField(
336         SwInputFieldType* pFieldType,
337         const String& rContent,
338         const String& rPrompt,
339         sal_uInt16 nSubType = 0,
340         sal_uLong nFmt = 0,
341         bool bIsFormField = true );
342     virtual ~SwInputField();
343 
344     void SetFmtFld( SwFmtFld& rFmtFld );
345     SwFmtFld* GetFmtFld();
346 
347     // Providing new Input Field's content:
348     // Fill Input Field's content depending on <nSupType>.
349     void applyFieldContent( const String& rNewFieldContent );
350 
351     bool isFormField() const;
352 
353     virtual String          GetFieldName() const;
354 
355     // Content
356     virtual const String&   GetPar1() const;
357     virtual void            SetPar1(const String& rStr);
358 
359     // aPromptText
360     virtual String          GetPar2() const;
361     virtual void            SetPar2(const String& rStr);
362 
363     virtual String          GetHelp() const;
364     virtual void            SetHelp(const String & rStr);
365 
366     virtual String          GetToolTip() const;
367     virtual void            SetToolTip(const String & rStr);
368 
369     virtual sal_uInt16      GetSubType() const;
370     virtual void            SetSubType(sal_uInt16 nSub);
371     virtual sal_Bool        QueryValue( com::sun::star::uno::Any& rVal, sal_uInt16 nWhich ) const;
372     virtual sal_Bool        PutValue( const com::sun::star::uno::Any& rVal, sal_uInt16 nWhich );
373 };
374 
375 /*--------------------------------------------------------------------
376     Description: Sorted list of input fields and DropDown fields
377  --------------------------------------------------------------------*/
378 
379 class SwInputFieldList
380 {
381 public:
382     SwInputFieldList( SwEditShell* pShell, sal_Bool bBuildTmpLst = sal_False );
383     ~SwInputFieldList();
384 
385     sal_uInt16      Count() const;
386     SwField*    GetField(sal_uInt16 nId);
387 
388     void        GotoFieldPos(sal_uInt16 nId);
389     void        PushCrsr();
390     void        PopCrsr();
391 
392     // vergleiche TmpLst mit akt Feldern. Alle neue kommen in die SortLst
393     // damit sie geupdatet werden koennen. Returnt die Anzahl.
394     // (Fuer Textbausteine: nur seine Input-Felder aktualisieren)
395     sal_uInt16      BuildSortLst();
396 
397     // Alle unselektierten Felder aus Liste entfernen
398     void        RemoveUnselectedFlds();
399 
400 private:
401     SwEditShell*    pSh;
402     _SetGetExpFlds* pSrtLst;
403     SvPtrarr        aTmpLst;
404 };
405 
406 /*--------------------------------------------------------------------
407     Beschreibung: Tabellen-Formelfeld
408                   (Implementierung steht in tblcalc.cxx)
409  --------------------------------------------------------------------*/
410 
411 class SwTblFieldType : public SwValueFieldType
412 {
413 public:
414     SwTblFieldType(SwDoc* pDocPtr);
415     virtual SwFieldType* Copy() const;
416 };
417 
418 
419 // MSC will den hier nicht
420 //typedef void (SwField:: *FnScanFormel)( const SwTable&, String&,
421 //                                   String&, String* = 0, void* = 0 );
422 
423 
424 class SwTblField : public SwValueField, public SwTableFormula
425 {
426     String      sExpand;
427     sal_uInt16      nSubType;
428 
429     virtual String      Expand() const;
430     virtual SwField*    Copy() const;
431 
432     // suche den TextNode, in dem das Feld steht
433     virtual const SwNode* GetNodeOfFormula() const;
434 
435     String GetCommand();
436 
437 public:
438     SwTblField( SwTblFieldType*, const String& rFormel,
439                 sal_uInt16 nSubType = 0, sal_uLong nFmt = 0);
440 
441     virtual void        SetValue( const double& rVal );
442     virtual sal_uInt16      GetSubType() const;
443     virtual void        SetSubType(sal_uInt16 nType);
444 
GetExpStr() const445     const String&       GetExpStr() const               { return sExpand; }
ChgExpStr(const String & rStr)446     void                ChgExpStr(const String& rStr)   { sExpand = rStr; }
447 
448     // berechne sich selbst
449     void                CalcField( SwTblCalcPara& rCalcPara );
450 
451     virtual String      GetFieldName() const;
452 
453     // Die Formel
454     virtual String      GetPar2()   const;
455     virtual void        SetPar2(const String& rStr);
456     virtual sal_Bool        QueryValue( com::sun::star::uno::Any& rVal, sal_uInt16 nWhich ) const;
457     virtual sal_Bool        PutValue( const com::sun::star::uno::Any& rVal, sal_uInt16 nWhich );
458 };
459 
460 
461 #endif // SW_EXPFLD_HXX
462