xref: /AOO41X/main/sw/inc/fldbas.hxx (revision 8809db7a87f97847b57a57f4cd2b0104b2b83182)
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 
142 
143 enum SwFileNameFormat
144 {
145     FF_BEGIN,
146     FF_NAME = FF_BEGIN,
147     FF_PATHNAME,
148     FF_PATH,
149     FF_NAME_NOEXT,
150     FF_UI_NAME,
151     FF_UI_RANGE,
152     FF_END,
153     FF_FIXED = 0x8000
154 };
155 
156 enum SwVarFormat
157 {
158     VVF_CMD         = 0x0010,   // Kommando anzeigen
159     VVF_INVISIBLE   = 0x0040,   // unsichtbar
160     VVF_XXP         = 0x0400,   // 1234%
161     VVF_XX_XXP      = 0x0800,   // 1.234,56%
162     VVF_CLEAR       = 0x000f,
163 
164 // ab hier neue Formate
165     VVF_SYS         = 0x2000,   //Zahlenformat aus der Systemeinstellung
166     VVF_X           = 0x2100,   // 1234
167     VVF_X_X         = 0x2200,   // 1234,5
168     VVF_X_XX        = 0x2300,   // 1245,56
169     VVF_XX_X        = 0x2400,   // 1.234,5
170     VVF_XX_XX       = 0x2500,   // 1.234,56
171     VVF_XX_XXX      = 0x2600,   // 1.234,567
172     VVF_SYS_CUR     = 0x2700,   // W???hrungsformat aus der Systemeinstellung
173     VVF_CUR_X       = 0x2800,   // DM 1234
174     VVF_CUR_XX_XX   = 0x2900,   // DM 1234,56 DM 1234,00
175     VVF_CUR_XX_X0   = 0x2a00,   // DM 1234,56 DM 1234,--
176     VVF_X_CUR       = 0x2b00,   // 1234 DM
177     VVF_XX_XX_CUR   = 0x2c00,   // 1234,56 DM 1234,00 DM
178     VVF_XX_X0_CUR   = 0x2d00,    // 1234,56 DM 1234,-- DM
179 // Kompatibilitaet:
180     VF_CMD          = VVF_CMD,
181     VF_INVISIBLE    = VVF_INVISIBLE,
182     VF_XXP          = VVF_XXP,
183     VF_XX_XXP       = VVF_XX_XXP,
184     VF_VISIBLE      = VVF_SYS,
185     VF_XX           = VVF_X,
186     VF_XX_XX        = VVF_XX_XX,
187     VF_XX_XX_CUR    = VVF_SYS_CUR,
188     VF_CLEAR        = VVF_CLEAR
189 
190 };
191 
192 typedef sal_uInt16 SwGetSetExpType;
193 namespace nsSwGetSetExpType
194 {
195     const SwGetSetExpType GSE_STRING  = 0x0001; // String
196     const SwGetSetExpType GSE_EXPR    = 0x0002; // Expression
197     const SwGetSetExpType GSE_INP     = 0x0004; // InputField
198     const SwGetSetExpType GSE_SEQ     = 0x0008; // Sequence
199     const SwGetSetExpType GSE_FORMULA = 0x0010; // Formel
200 }
201 
202 typedef sal_uInt16 SwExtendedSubType;
203 namespace nsSwExtendedSubType
204 {
205     const SwExtendedSubType SUB_CMD         = 0x0100;   // Kommando anzeigen
206     const SwExtendedSubType SUB_INVISIBLE   = 0x0200;   // unsichtbar
207     const SwExtendedSubType SUB_OWN_FMT     = 0x0400;   // SwDBField: Uebernimmt Formatierung nicht
208                                                         // aus Datenbank
209 }
210 
211 enum SwInputFieldSubType
212 {
213     INP_TXT     = 0x01,
214     INP_USR     = 0x02,
215     INP_VAR     = 0x03
216 };
217 
218 
219 enum SwUserType
220 {
221     UF_STRING   = 0x01,
222     UF_EXPR     = 0x02
223 };
224 
225 enum SwDateTimeSubType
226 {
227     FIXEDFLD = 1,
228     DATEFLD  = 2,
229     TIMEFLD  = 4
230 };
231 
232 
233 extern sal_uInt16 __FAR_DATA aTypeTab[];
234 
235 /*--------------------------------------------------------------------
236     Beschreibung: Allgemeine Tools
237  --------------------------------------------------------------------*/
238 
239 String  GetResult(double nVal, sal_uInt32 nNumFmt, sal_uInt16 nLang = LANGUAGE_SYSTEM);
240 void    SetErrorStr(const String& rStr);
241 //String    ExpandDate(const Date& rDate, sal_uLong nFmt, sal_uInt16 nLang);
242 //String    ExpandTime(const Time& rTime, sal_uLong nFmt, sal_uInt16 nLang);
243 String  FormatNumber(sal_uInt16 nNum, sal_uInt32 nFormat);
244 
245 /*--------------------------------------------------------------------
246     Beschreibung:   Instanzen von SwFields und Abgeleiteten kommen 0-n mal vor.
247                     Zu jeder Klasse SwFields existiert
248                     1 Instanz der zugehoerigen Typenklasse
249                     Basisklasse aller Feldtypen ist SwFieldType
250  --------------------------------------------------------------------*/
251 
252 DBG_NAMEEX(SwFieldType)
253 
254 class SW_DLLPUBLIC SwFieldType : public SwModify
255 {
256     sal_uInt16 nWhich;
257 
258     friend void _FinitUI();     // um den Pointer zu loeschen!
259     static  SvStringsDtor*  pFldNames;
260 
261     static void _GetFldName();          // legt die FldNames an, fldmgr.cxx!
262 
263 protected:
264     // single argument ctors shall be explicit.
265     explicit SwFieldType( sal_uInt16 nWhichId );
266 
267 public:
268 
269 #ifdef DBG_UTIL
270     virtual ~SwFieldType();
271 #endif
272     static  const String&   GetTypeStr( sal_uInt16 nTypeId );
273 
274     // nur in abgeleiteten Klassen
275     virtual const String&   GetName() const;
276     virtual SwFieldType*    Copy()    const = 0;
277     virtual sal_Bool QueryValue( com::sun::star::uno::Any& rVal, sal_uInt16 nWhich ) const;
278     virtual sal_Bool PutValue( const com::sun::star::uno::Any& rVal, sal_uInt16 nWhich );
279 
280             sal_uInt16          Which() const { return nWhich; }
281 
282     inline  void            UpdateFlds() const;
283 };
284 
285 inline void SwFieldType::UpdateFlds() const
286 {
287     ((SwFieldType*)this)->ModifyNotification( 0, 0 );
288 }
289 
290 /*--------------------------------------------------------------------
291     Beschreibung:  Basisklasse aller Felder.
292                    Ueber Which wird der Typ des Feldes abgefragt.
293                    Ueber Expand() wird der expandierte Inhalt
294                    des Feldes in Erfahrung gebracht.
295  --------------------------------------------------------------------*/
296 
297 class SW_DLLPUBLIC SwField
298 {
299 private:
300     mutable String      m_Cache; /// #i85766# cached expansion (for clipboard)
301     sal_uInt16              nLang;  // Immer ueber SetLanguage aendern!
302     sal_Bool                bIsAutomaticLanguage;
303     sal_uInt32          nFormat;
304 
305     SwFieldType*        pType;
306 
307     virtual String      Expand() const = 0;
308     virtual SwField*    Copy() const = 0;
309 
310 protected:
311     void                SetFormat(sal_uInt32 nSet) {nFormat = nSet;}
312 
313     SwField(SwFieldType* pTyp, sal_uInt32 nFmt = 0, sal_uInt16 nLang = LANGUAGE_SYSTEM);
314 
315 public:
316     virtual             ~SwField();
317 
318     // Typ feststellen
319     inline SwFieldType* GetTyp() const;
320 
321     // neuen Typ setzen (wird fuer das Kopieren zwischen Dokumenten benutzt)
322     virtual SwFieldType* ChgTyp( SwFieldType* );
323 
324     /** expand the field.
325         @param  bCached     return cached field value.
326         @remark     most callers should use the cached field value.
327                     this is because various fields need special handing
328                     (ChangeExpansion()) to return correct values, and only
329                     SwTxtFormatter::NewFldPortion() sets things up properly.
330         @return     the generated text (suitable for display)
331       */
332     String              ExpandField(bool const bCached) const;
333 
334     virtual String      GetFieldName() const;
335 
336     SwField *           CopyField() const;
337 
338     // ResId
339     sal_uInt16              Which() const
340 #ifndef DBG_UTIL
341         { return pType->Which(); }
342 #else
343         ;       // in fldbas.cxx implementiert
344 #endif
345 
346     // TYP_ID
347             sal_uInt16      GetTypeId() const;
348     virtual sal_uInt16      GetSubType() const;
349     virtual void        SetSubType(sal_uInt16);
350 
351     // Sprache an der Feldposition
352     inline sal_uInt16       GetLanguage() const;
353     virtual void        SetLanguage(sal_uInt16 nLng);
354 
355     // Parameter fuer Dialog und BASIC erfragen
356     inline sal_uInt32   GetFormat() const;
357     virtual const String& GetPar1() const;
358     virtual String      GetPar2()   const;
359 
360     virtual String      GetFormula() const;
361 
362     virtual void        ChangeFormat(sal_uInt32 n);
363     virtual void        SetPar1(const String& rStr);
364     virtual void        SetPar2(const String& rStr);
365 
366     virtual sal_Bool        QueryValue( com::sun::star::uno::Any& rVal, sal_uInt16 nWhichId ) const;
367     virtual sal_Bool        PutValue( const com::sun::star::uno::Any& rVal, sal_uInt16 nWhichId );
368     // hat das Feld eine Action auf dem ClickHandler ? (z.B. INetFelder,..)
369     sal_Bool            HasClickHdl() const;
370     // ist es ein Fix-Feld?
371     sal_Bool            IsFixed() const;
372 
373     sal_Bool                IsAutomaticLanguage() const { return bIsAutomaticLanguage;}
374     void                SetAutomaticLanguage(sal_Bool bSet){bIsAutomaticLanguage = bSet;}
375 
376     virtual String      GetDescription() const;
377 };
378 
379 inline SwFieldType* SwField::GetTyp() const
380     { return pType;     }
381 
382 inline sal_uInt32 SwField::GetFormat() const
383     { return nFormat;   }
384 
385 inline sal_uInt16 SwField::GetLanguage() const
386     { return nLang;     }
387 
388 /*--------------------------------------------------------------------
389     Beschreibung:   Felder mit Values, die ueber der Numberformatter
390                     formatiert werden muessen
391  --------------------------------------------------------------------*/
392 
393 class SwValueFieldType : public SwFieldType
394 {
395     SwDoc*  pDoc;
396     sal_Bool    bUseFormat; // Numberformatter verwenden
397 
398 protected:
399     SwValueFieldType( SwDoc* pDocPtr, sal_uInt16 nWhichId );
400     SwValueFieldType( const SwValueFieldType& rTyp );
401 
402 public:
403     inline SwDoc*   GetDoc() const                      { return pDoc; }
404     inline void     SetDoc(SwDoc* pNewDoc)              { pDoc = pNewDoc; }
405 
406     inline sal_Bool     UseFormat() const                   { return bUseFormat; }
407     inline void     EnableFormat(sal_Bool bFormat = sal_True)   { bUseFormat = bFormat; }
408 
409     String          ExpandValue(const double& rVal, sal_uInt32 nFmt, sal_uInt16 nLng=0) const;
410     void            DoubleToString(String &rValue, const double &rVal, LanguageType eLng) const;
411     void            DoubleToString(String &rValue, const double &rVal, sal_uInt32 nFmt) const;
412 };
413 
414 class SW_DLLPUBLIC SwValueField : public SwField
415 {
416     double fValue;
417 //  String sExpand;
418 
419 protected:
420     SwValueField( SwValueFieldType* pFldType, sal_uInt32 nFmt = 0, sal_uInt16 nLang = LANGUAGE_SYSTEM, const double fVal = 0.0 );
421     SwValueField( const SwValueField& rFld );
422 
423 public:
424     virtual                 ~SwValueField();
425 
426     virtual SwFieldType*    ChgTyp( SwFieldType* );
427     virtual void            SetLanguage(sal_uInt16 nLng);
428 //  os: wozu war das denn da?
429 //  virtual void            ChangeFormat(sal_uLong n);
430 
431     inline SwDoc*           GetDoc() const          { return ((SwValueFieldType*)GetTyp())->GetDoc(); }
432 
433     virtual double          GetValue() const;
434     virtual void            SetValue( const double& rVal );
435 
436     inline String   ExpandValue(const double& rVal, sal_uInt32 nFmt, sal_uInt16 nLng=0) const
437         { return ((SwValueFieldType*)GetTyp())->ExpandValue(rVal, nFmt, nLng); }
438 
439     static sal_uInt32       GetSystemFormat(SvNumberFormatter* pFormatter, sal_uInt32 nFmt);
440 };
441 
442 class SW_DLLPUBLIC SwFormulaField : public SwValueField
443 {
444     String sFormula;
445 
446 protected:
447     SwFormulaField( SwValueFieldType* pFldType, sal_uInt32 nFmt = 0, const double fVal = 0.0 );
448     SwFormulaField( const SwFormulaField& rFld );
449 
450 public:
451     virtual String          GetFormula() const;
452     void                    SetFormula(const String& rStr);
453 
454     void                    SetExpandedFormula(const String& rStr);
455     String                  GetExpandedFormula() const;
456 };
457 
458 #endif // SW_FLDBAS_HXX
459