xref: /trunk/main/sw/inc/fldbas.hxx (revision ca62e2c2083b5d0995f1245bad6c2edfb455fbec)
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_FLDBAS_HXX
24 #define SW_FLDBAS_HXX
25 
26 #include <i18npool/lang.h>
27 #include <tools/debug.hxx>
28 #include <tools/string.hxx>
29 #include "swdllapi.h"
30 #include <calbck.hxx>
31 #include <com/sun/star/uno/Any.hxx>
32 
33 class SwDoc;
34 class SvStringsDtor;
35 class SvNumberFormatter;
36 
37 
38 /*--------------------------------------------------------------------
39     Beschreibung:   die ID's fuer die Feldtypen
40  --------------------------------------------------------------------*/
41 
42 enum RES_FIELDS
43 {
44 // Fuer die alten Dokumente muessen die Field-Which IDS erhalten bleiben !!!!
45     RES_FIELDS_BEGIN,
46     RES_DBFLD = RES_FIELDS_BEGIN,
47     RES_USERFLD,
48     RES_FILENAMEFLD,
49     RES_DBNAMEFLD,
50     RES_DATEFLD,
51     RES_TIMEFLD,
52     RES_PAGENUMBERFLD,
53     RES_AUTHORFLD,
54     RES_CHAPTERFLD,
55     RES_DOCSTATFLD,
56     RES_GETEXPFLD,
57     RES_SETEXPFLD,
58     RES_GETREFFLD,
59     RES_HIDDENTXTFLD,
60     RES_POSTITFLD,
61     RES_FIXDATEFLD,
62     RES_FIXTIMEFLD,
63     RES_REGFLD,
64     RES_VARREGFLD,
65     RES_SETREFFLD,
66     RES_INPUTFLD,
67     RES_MACROFLD,
68     RES_DDEFLD,
69     RES_TABLEFLD,
70     RES_HIDDENPARAFLD,
71     RES_DOCINFOFLD,
72     RES_TEMPLNAMEFLD,
73     RES_DBNEXTSETFLD,
74     RES_DBNUMSETFLD,
75     RES_DBSETNUMBERFLD,
76     RES_EXTUSERFLD,
77     RES_REFPAGESETFLD,
78     RES_REFPAGEGETFLD,
79     RES_INTERNETFLD,
80     RES_JUMPEDITFLD,
81     RES_SCRIPTFLD,
82     RES_DATETIMEFLD,
83     RES_AUTHORITY,  //Table of authorities
84     RES_COMBINED_CHARS,
85     RES_DROPDOWN,
86     RES_FIELDS_END
87 };
88 
89 /*--------------------------------------------------------------------
90     Beschreibung: Liste der FieldTypes am UI
91  --------------------------------------------------------------------*/
92 
93 enum SwFldTypesEnum
94 {
95     TYP_BEGIN,
96     TYP_DATEFLD = TYP_BEGIN,    // 0
97     TYP_TIMEFLD,
98     TYP_FILENAMEFLD,
99     TYP_DBNAMEFLD,
100     TYP_CHAPTERFLD,
101     TYP_PAGENUMBERFLD,
102     TYP_DOCSTATFLD,
103     TYP_AUTHORFLD,
104     TYP_SETFLD,
105     TYP_GETFLD,
106     TYP_FORMELFLD,              // 10
107     TYP_HIDDENTXTFLD,
108     TYP_SETREFFLD,
109     TYP_GETREFFLD,
110     TYP_DDEFLD,
111     TYP_MACROFLD,
112     TYP_INPUTFLD,
113     TYP_HIDDENPARAFLD,
114     TYP_DOCINFOFLD,
115     TYP_DBFLD,
116     TYP_USERFLD,                // 20
117     TYP_POSTITFLD,
118     TYP_TEMPLNAMEFLD,
119     TYP_SEQFLD,
120     TYP_DBNEXTSETFLD,
121     TYP_DBNUMSETFLD,
122     TYP_DBSETNUMBERFLD,
123     TYP_CONDTXTFLD,
124     TYP_NEXTPAGEFLD,
125     TYP_PREVPAGEFLD,
126     TYP_EXTUSERFLD,             // 30
127     TYP_FIXDATEFLD,
128     TYP_FIXTIMEFLD,
129     TYP_SETINPFLD,
130     TYP_USRINPFLD,
131     TYP_SETREFPAGEFLD,
132     TYP_GETREFPAGEFLD,
133     TYP_INTERNETFLD,
134     TYP_JUMPEDITFLD,
135     TYP_SCRIPTFLD,              // 40
136     TYP_AUTHORITY,
137     TYP_COMBINED_CHARS,
138     TYP_DROPDOWN,
139     TYP_END
140 };
141 //IAccessibility2 Implementation 2009-----
142 enum SwAttrFieldTYpe
143 {
144     ATTR_NONE,
145     ATTR_DATEFLD,
146     ATTR_TIMEFLD,
147     ATTR_PAGENUMBERFLD,
148     ATTR_PAGECOOUNTFLD,
149     ATTR_BOOKMARKFLD,
150     ATTR_SETREFATTRFLD
151 };
152 //-----IAccessibility2 Implementation 2009
153 enum SwFileNameFormat
154 {
155     FF_BEGIN,
156     FF_NAME = FF_BEGIN,
157     FF_PATHNAME,
158     FF_PATH,
159     FF_NAME_NOEXT,
160     FF_UI_NAME,
161     FF_UI_RANGE,
162     FF_END,
163     FF_FIXED = 0x8000
164 };
165 
166 enum SwVarFormat
167 {
168     VVF_CMD         = 0x0010,   // Kommando anzeigen
169     VVF_INVISIBLE   = 0x0040,   // unsichtbar
170     VVF_XXP         = 0x0400,   // 1234%
171     VVF_XX_XXP      = 0x0800,   // 1.234,56%
172     VVF_CLEAR       = 0x000f,
173 
174 // ab hier neue Formate
175     VVF_SYS         = 0x2000,   //Zahlenformat aus der Systemeinstellung
176     VVF_X           = 0x2100,   // 1234
177     VVF_X_X         = 0x2200,   // 1234,5
178     VVF_X_XX        = 0x2300,   // 1245,56
179     VVF_XX_X        = 0x2400,   // 1.234,5
180     VVF_XX_XX       = 0x2500,   // 1.234,56
181     VVF_XX_XXX      = 0x2600,   // 1.234,567
182     VVF_SYS_CUR     = 0x2700,   // W???hrungsformat aus der Systemeinstellung
183     VVF_CUR_X       = 0x2800,   // DM 1234
184     VVF_CUR_XX_XX   = 0x2900,   // DM 1234,56 DM 1234,00
185     VVF_CUR_XX_X0   = 0x2a00,   // DM 1234,56 DM 1234,--
186     VVF_X_CUR       = 0x2b00,   // 1234 DM
187     VVF_XX_XX_CUR   = 0x2c00,   // 1234,56 DM 1234,00 DM
188     VVF_XX_X0_CUR   = 0x2d00,    // 1234,56 DM 1234,-- DM
189 // Kompatibilitaet:
190     VF_CMD          = VVF_CMD,
191     VF_INVISIBLE    = VVF_INVISIBLE,
192     VF_XXP          = VVF_XXP,
193     VF_XX_XXP       = VVF_XX_XXP,
194     VF_VISIBLE      = VVF_SYS,
195     VF_XX           = VVF_X,
196     VF_XX_XX        = VVF_XX_XX,
197     VF_XX_XX_CUR    = VVF_SYS_CUR,
198     VF_CLEAR        = VVF_CLEAR
199 
200 };
201 
202 typedef sal_uInt16 SwGetSetExpType;
203 namespace nsSwGetSetExpType
204 {
205     const SwGetSetExpType GSE_STRING  = 0x0001; // String
206     const SwGetSetExpType GSE_EXPR    = 0x0002; // Expression
207     const SwGetSetExpType GSE_INP     = 0x0004; // InputField
208     const SwGetSetExpType GSE_SEQ     = 0x0008; // Sequence
209     const SwGetSetExpType GSE_FORMULA = 0x0010; // Formel
210 }
211 
212 typedef sal_uInt16 SwExtendedSubType;
213 namespace nsSwExtendedSubType
214 {
215     const SwExtendedSubType SUB_CMD         = 0x0100;   // Kommando anzeigen
216     const SwExtendedSubType SUB_INVISIBLE   = 0x0200;   // unsichtbar
217     const SwExtendedSubType SUB_OWN_FMT     = 0x0400;   // SwDBField: Uebernimmt Formatierung nicht
218                                                         // aus Datenbank
219 }
220 
221 enum SwInputFieldSubType
222 {
223     INP_TXT     = 0x01,
224     INP_USR     = 0x02,
225     INP_VAR     = 0x03
226 };
227 
228 
229 enum SwUserType
230 {
231     UF_STRING   = 0x01,
232     UF_EXPR     = 0x02
233 };
234 
235 enum SwDateTimeSubType
236 {
237     FIXEDFLD = 1,
238     DATEFLD  = 2,
239     TIMEFLD  = 4
240 };
241 
242 
243 extern sal_uInt16 __FAR_DATA aTypeTab[];
244 
245 /*--------------------------------------------------------------------
246     Beschreibung: Allgemeine Tools
247  --------------------------------------------------------------------*/
248 
249 String  GetResult(double nVal, sal_uInt32 nNumFmt, sal_uInt16 nLang = LANGUAGE_SYSTEM);
250 void    SetErrorStr(const String& rStr);
251 //String    ExpandDate(const Date& rDate, sal_uLong nFmt, sal_uInt16 nLang);
252 //String    ExpandTime(const Time& rTime, sal_uLong nFmt, sal_uInt16 nLang);
253 String  FormatNumber(sal_uInt16 nNum, sal_uInt32 nFormat);
254 
255 /*--------------------------------------------------------------------
256     Beschreibung:   Instanzen von SwFields und Abgeleiteten kommen 0-n mal vor.
257                     Zu jeder Klasse SwFields existiert
258                     1 Instanz der zugehoerigen Typenklasse
259                     Basisklasse aller Feldtypen ist SwFieldType
260  --------------------------------------------------------------------*/
261 
262 DBG_NAMEEX(SwFieldType)
263 
264 class SW_DLLPUBLIC SwFieldType : public SwModify
265 {
266     sal_uInt16 nWhich;
267 
268     friend void _FinitUI();     // um den Pointer zu loeschen!
269     static  SvStringsDtor*  pFldNames;
270 
271     static void _GetFldName();          // legt die FldNames an, fldmgr.cxx!
272 
273 protected:
274     // single argument ctors shall be explicit.
275     explicit SwFieldType( sal_uInt16 nWhichId );
276 
277 public:
278 
279 #ifdef DBG_UTIL
280     virtual ~SwFieldType();
281 #endif
282     static  const String&   GetTypeStr( sal_uInt16 nTypeId );
283 
284     // nur in abgeleiteten Klassen
285     virtual const String&   GetName() const;
286     virtual SwFieldType*    Copy()    const = 0;
287     virtual sal_Bool QueryValue( com::sun::star::uno::Any& rVal, sal_uInt16 nWhich ) const;
288     virtual sal_Bool PutValue( const com::sun::star::uno::Any& rVal, sal_uInt16 nWhich );
289 
290             sal_uInt16          Which() const { return nWhich; }
291 
292     inline  void            UpdateFlds() const;
293 };
294 
295 inline void SwFieldType::UpdateFlds() const
296 {
297     ((SwFieldType*)this)->ModifyNotification( 0, 0 );
298 }
299 
300 /*--------------------------------------------------------------------
301     Beschreibung:  Basisklasse aller Felder.
302                    Ueber Which wird der Typ des Feldes abgefragt.
303                    Ueber Expand() wird der expandierte Inhalt
304                    des Feldes in Erfahrung gebracht.
305  --------------------------------------------------------------------*/
306 
307 class SW_DLLPUBLIC SwField
308 {
309 private:
310     mutable String      m_Cache; /// #i85766# cached expansion (for clipboard)
311     sal_uInt16              nLang;  // Immer ueber SetLanguage aendern!
312     sal_Bool                bIsAutomaticLanguage;
313     sal_uInt32          nFormat;
314 
315     SwFieldType*        pType;
316 
317     virtual String      Expand() const = 0;
318     virtual SwField*    Copy() const = 0;
319 
320 protected:
321     void                SetFormat(sal_uInt32 nSet) {nFormat = nSet;}
322 
323     SwField(SwFieldType* pTyp, sal_uInt32 nFmt = 0, sal_uInt16 nLang = LANGUAGE_SYSTEM);
324 
325 public:
326     virtual             ~SwField();
327 
328     // Typ feststellen
329     inline SwFieldType* GetTyp() const;
330 
331     // neuen Typ setzen (wird fuer das Kopieren zwischen Dokumenten benutzt)
332     virtual SwFieldType* ChgTyp( SwFieldType* );
333 
334     /** expand the field.
335         @param  bCached     return cached field value.
336         @remark     most callers should use the cached field value.
337                     this is because various fields need special handing
338                     (ChangeExpansion()) to return correct values, and only
339                     SwTxtFormatter::NewFldPortion() sets things up properly.
340         @return     the generated text (suitable for display)
341       */
342     String              ExpandField(bool const bCached) const;
343 
344     virtual String      GetFieldName() const;
345 
346     SwField *           CopyField() const;
347 
348     // ResId
349     sal_uInt16              Which() const
350 #ifndef DBG_UTIL
351         { return pType->Which(); }
352 #else
353         ;       // in fldbas.cxx implementiert
354 #endif
355 
356     // TYP_ID
357             sal_uInt16      GetTypeId() const;
358     virtual sal_uInt16      GetSubType() const;
359     virtual void        SetSubType(sal_uInt16);
360 
361     // Sprache an der Feldposition
362     inline sal_uInt16       GetLanguage() const;
363     virtual void        SetLanguage(sal_uInt16 nLng);
364 
365     // Parameter fuer Dialog und BASIC erfragen
366     inline sal_uInt32   GetFormat() const;
367     virtual const String& GetPar1() const;
368     virtual String      GetPar2()   const;
369 
370     virtual String      GetFormula() const;
371 
372     virtual void        ChangeFormat(sal_uInt32 n);
373     virtual void        SetPar1(const String& rStr);
374     virtual void        SetPar2(const String& rStr);
375 
376     virtual sal_Bool        QueryValue( com::sun::star::uno::Any& rVal, sal_uInt16 nWhichId ) const;
377     virtual sal_Bool        PutValue( const com::sun::star::uno::Any& rVal, sal_uInt16 nWhichId );
378     // hat das Feld eine Action auf dem ClickHandler ? (z.B. INetFelder,..)
379     sal_Bool            HasClickHdl() const;
380     // ist es ein Fix-Feld?
381     sal_Bool            IsFixed() const;
382 
383     sal_Bool                IsAutomaticLanguage() const { return bIsAutomaticLanguage;}
384     void                SetAutomaticLanguage(sal_Bool bSet){bIsAutomaticLanguage = bSet;}
385 
386     virtual String      GetDescription() const;
387 };
388 
389 inline SwFieldType* SwField::GetTyp() const
390     { return pType;     }
391 
392 inline sal_uInt32 SwField::GetFormat() const
393     { return nFormat;   }
394 
395 inline sal_uInt16 SwField::GetLanguage() const
396     { return nLang;     }
397 
398 /*--------------------------------------------------------------------
399     Beschreibung:   Felder mit Values, die ueber der Numberformatter
400                     formatiert werden muessen
401  --------------------------------------------------------------------*/
402 
403 class SwValueFieldType : public SwFieldType
404 {
405     SwDoc*  pDoc;
406     sal_Bool    bUseFormat; // Numberformatter verwenden
407 
408 protected:
409     SwValueFieldType( SwDoc* pDocPtr, sal_uInt16 nWhichId );
410     SwValueFieldType( const SwValueFieldType& rTyp );
411 
412 public:
413     inline SwDoc*   GetDoc() const                      { return pDoc; }
414     inline void     SetDoc(SwDoc* pNewDoc)              { pDoc = pNewDoc; }
415 
416     inline sal_Bool     UseFormat() const                   { return bUseFormat; }
417     inline void     EnableFormat(sal_Bool bFormat = sal_True)   { bUseFormat = bFormat; }
418 
419     String          ExpandValue(const double& rVal, sal_uInt32 nFmt, sal_uInt16 nLng=0) const;
420     void            DoubleToString(String &rValue, const double &rVal, LanguageType eLng) const;
421     void            DoubleToString(String &rValue, const double &rVal, sal_uInt32 nFmt) const;
422 };
423 
424 class SW_DLLPUBLIC SwValueField : public SwField
425 {
426     double fValue;
427 //  String sExpand;
428 
429 protected:
430     SwValueField( SwValueFieldType* pFldType, sal_uInt32 nFmt = 0, sal_uInt16 nLang = LANGUAGE_SYSTEM, const double fVal = 0.0 );
431     SwValueField( const SwValueField& rFld );
432 
433 public:
434     virtual                 ~SwValueField();
435 
436     virtual SwFieldType*    ChgTyp( SwFieldType* );
437     virtual void            SetLanguage(sal_uInt16 nLng);
438 //  os: wozu war das denn da?
439 //  virtual void            ChangeFormat(sal_uLong n);
440 
441     inline SwDoc*           GetDoc() const          { return ((SwValueFieldType*)GetTyp())->GetDoc(); }
442 
443     virtual double          GetValue() const;
444     virtual void            SetValue( const double& rVal );
445 
446     inline String   ExpandValue(const double& rVal, sal_uInt32 nFmt, sal_uInt16 nLng=0) const
447         { return ((SwValueFieldType*)GetTyp())->ExpandValue(rVal, nFmt, nLng); }
448 
449     static sal_uInt32       GetSystemFormat(SvNumberFormatter* pFormatter, sal_uInt32 nFmt);
450 };
451 
452 class SW_DLLPUBLIC SwFormulaField : public SwValueField
453 {
454     String sFormula;
455 
456 protected:
457     SwFormulaField( SwValueFieldType* pFldType, sal_uInt32 nFmt = 0, const double fVal = 0.0 );
458     SwFormulaField( const SwFormulaField& rFld );
459 
460 public:
461     virtual String          GetFormula() const;
462     void                    SetFormula(const String& rStr);
463 
464     void                    SetExpandedFormula(const String& rStr);
465     String                  GetExpandedFormula() const;
466 };
467 
468 #endif // SW_FLDBAS_HXX
469