LCOV - code coverage report
Current view: top level - libreoffice/sw/inc - fldbas.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 24 26 92.3 %
Date: 2012-12-27 Functions: 17 22 77.3 %
Legend: Lines: hit not hit

          Line data    Source code
       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             : #ifndef SW_FLDBAS_HXX
      20             : #define SW_FLDBAS_HXX
      21             : 
      22             : #include <i18npool/lang.h>
      23             : #include <tools/string.hxx>
      24             : #include "swdllapi.h"
      25             : #include <calbck.hxx>
      26             : #include <com/sun/star/uno/Any.hxx>
      27             : #include <vector>
      28             : 
      29             : class SwDoc;
      30             : class SvNumberFormatter;
      31             : 
      32             : enum RES_FIELDS
      33             : {
      34             :  /// For old documents the Field-Which IDs must be preserved !!!
      35             :     RES_FIELDS_BEGIN,
      36             :     RES_DBFLD = RES_FIELDS_BEGIN,
      37             :     RES_USERFLD,
      38             :     RES_FILENAMEFLD,
      39             :     RES_DBNAMEFLD,
      40             :     RES_DATEFLD,
      41             :     RES_TIMEFLD,
      42             :     RES_PAGENUMBERFLD,
      43             :     RES_AUTHORFLD,
      44             :     RES_CHAPTERFLD,
      45             :     RES_DOCSTATFLD,
      46             :     RES_GETEXPFLD,
      47             :     RES_SETEXPFLD,
      48             :     RES_GETREFFLD,
      49             :     RES_HIDDENTXTFLD,
      50             :     RES_POSTITFLD,
      51             :     RES_FIXDATEFLD,
      52             :     RES_FIXTIMEFLD,
      53             :     RES_REGFLD,
      54             :     RES_VARREGFLD,
      55             :     RES_SETREFFLD,
      56             :     RES_INPUTFLD,
      57             :     RES_MACROFLD,
      58             :     RES_DDEFLD,
      59             :     RES_TABLEFLD,
      60             :     RES_HIDDENPARAFLD,
      61             :     RES_DOCINFOFLD,
      62             :     RES_TEMPLNAMEFLD,
      63             :     RES_DBNEXTSETFLD,
      64             :     RES_DBNUMSETFLD,
      65             :     RES_DBSETNUMBERFLD,
      66             :     RES_EXTUSERFLD,
      67             :     RES_REFPAGESETFLD,
      68             :     RES_REFPAGEGETFLD,
      69             :     RES_INTERNETFLD,
      70             :     RES_JUMPEDITFLD,
      71             :     RES_SCRIPTFLD,
      72             :     RES_DATETIMEFLD,
      73             :     RES_AUTHORITY,  ///< Table of authorities
      74             :     RES_COMBINED_CHARS,
      75             :     RES_DROPDOWN,
      76             :     RES_FIELDS_END
      77             : };
      78             : 
      79             :  /// List of FieldTypes at UI.
      80             : enum SwFldTypesEnum
      81             : {
      82             :     TYP_BEGIN,
      83             :     TYP_DATEFLD = TYP_BEGIN,    // 0
      84             :     TYP_TIMEFLD,
      85             :     TYP_FILENAMEFLD,
      86             :     TYP_DBNAMEFLD,
      87             :     TYP_CHAPTERFLD,
      88             :     TYP_PAGENUMBERFLD,
      89             :     TYP_DOCSTATFLD,
      90             :     TYP_AUTHORFLD,
      91             :     TYP_SETFLD,
      92             :     TYP_GETFLD,
      93             :     TYP_FORMELFLD,              // 10
      94             :     TYP_HIDDENTXTFLD,
      95             :     TYP_SETREFFLD,
      96             :     TYP_GETREFFLD,
      97             :     TYP_DDEFLD,
      98             :     TYP_MACROFLD,
      99             :     TYP_INPUTFLD,
     100             :     TYP_HIDDENPARAFLD,
     101             :     TYP_DOCINFOFLD,
     102             :     TYP_DBFLD,
     103             :     TYP_USERFLD,                // 20
     104             :     TYP_POSTITFLD,
     105             :     TYP_TEMPLNAMEFLD,
     106             :     TYP_SEQFLD,
     107             :     TYP_DBNEXTSETFLD,
     108             :     TYP_DBNUMSETFLD,
     109             :     TYP_DBSETNUMBERFLD,
     110             :     TYP_CONDTXTFLD,
     111             :     TYP_NEXTPAGEFLD,
     112             :     TYP_PREVPAGEFLD,
     113             :     TYP_EXTUSERFLD,             // 30
     114             :     TYP_FIXDATEFLD,
     115             :     TYP_FIXTIMEFLD,
     116             :     TYP_SETINPFLD,
     117             :     TYP_USRINPFLD,
     118             :     TYP_SETREFPAGEFLD,
     119             :     TYP_GETREFPAGEFLD,
     120             :     TYP_INTERNETFLD,
     121             :     TYP_JUMPEDITFLD,
     122             :     TYP_SCRIPTFLD,
     123             :     TYP_AUTHORITY,              // 40
     124             :     TYP_COMBINED_CHARS,
     125             :     TYP_DROPDOWN,
     126             :     TYP_END
     127             : };
     128             : 
     129             : 
     130             : enum SwFileNameFormat
     131             : {
     132             :     FF_BEGIN,
     133             :     FF_NAME = FF_BEGIN,
     134             :     FF_PATHNAME,
     135             :     FF_PATH,
     136             :     FF_NAME_NOEXT,
     137             :     FF_UI_NAME,
     138             :     FF_UI_RANGE,
     139             :     FF_END,
     140             :     FF_FIXED = 0x8000
     141             : };
     142             : 
     143             : enum SwVarFormat
     144             : {
     145             :     VVF_CMD         = 0x0010,   ///< Show command.
     146             :     VVF_INVISIBLE   = 0x0040,   ///< Invisible.
     147             :     VVF_XXP         = 0x0400,   ///< 1234%
     148             :     VVF_XX_XXP      = 0x0800,   ///< 1.234,56%
     149             :     VVF_CLEAR       = 0x000f,
     150             : 
     151             : // From here new formats:
     152             :     VVF_SYS         = 0x2000,   ///< Format for numbers from system.
     153             :     VVF_X           = 0x2100,   ///< 1234
     154             :     VVF_X_X         = 0x2200,   ///< 1234.5
     155             :     VVF_X_XX        = 0x2300,   ///< 1245.56
     156             :     VVF_XX_X        = 0x2400,   ///< 1.234.5
     157             :     VVF_XX_XX       = 0x2500,   ///< 1.234.56
     158             :     VVF_XX_XXX      = 0x2600,   ///< 1.234.567
     159             :     VVF_SYS_CUR     = 0x2700,   ///< Format for currency from system.
     160             :     VVF_CUR_X       = 0x2800,   ///< EUR 1234
     161             :     VVF_CUR_XX_XX   = 0x2900,   ///< EUR 1234.56 EUR 1234.00
     162             :     VVF_CUR_XX_X0   = 0x2a00,   ///< EUR 1234.56 EUR 1234.--
     163             :     VVF_X_CUR       = 0x2b00,   ///< 1234 EUR
     164             :     VVF_XX_XX_CUR   = 0x2c00,   ///< 1234.56 EUR 1234.00 EUR
     165             :     VVF_XX_X0_CUR   = 0x2d00,   ///< 1234.56 EUR 1234.-- EUR
     166             : /// Compatibility:
     167             :     VF_CMD          = VVF_CMD,
     168             :     VF_INVISIBLE    = VVF_INVISIBLE,
     169             :     VF_XXP          = VVF_XXP,
     170             :     VF_XX_XXP       = VVF_XX_XXP,
     171             :     VF_VISIBLE      = VVF_SYS,
     172             :     VF_XX           = VVF_X,
     173             :     VF_XX_XX        = VVF_XX_XX,
     174             :     VF_XX_XX_CUR    = VVF_SYS_CUR,
     175             :     VF_CLEAR        = VVF_CLEAR
     176             : 
     177             : };
     178             : 
     179             : typedef sal_uInt16 SwGetSetExpType;
     180             : namespace nsSwGetSetExpType
     181             : {
     182             :     const SwGetSetExpType GSE_STRING  = 0x0001; ///< String
     183             :     const SwGetSetExpType GSE_EXPR    = 0x0002; ///< Expression
     184             :     const SwGetSetExpType GSE_INP     = 0x0004; ///< InputField
     185             :     const SwGetSetExpType GSE_SEQ     = 0x0008; ///< Sequence
     186             :     const SwGetSetExpType GSE_FORMULA = 0x0010; ///< Formula
     187             : }
     188             : 
     189             : typedef sal_uInt16 SwExtendedSubType;
     190             : namespace nsSwExtendedSubType
     191             : {
     192             :     const SwExtendedSubType SUB_CMD         = 0x0100;   ///< Show command.
     193             :     const SwExtendedSubType SUB_INVISIBLE   = 0x0200;   ///< Invisible.
     194             :     const SwExtendedSubType SUB_OWN_FMT     = 0x0400;   ///< SwDBField: Don't accept formating from database.
     195             : }
     196             : 
     197             : enum SwInputFieldSubType
     198             : {
     199             :     INP_TXT     = 0x01,
     200             :     INP_USR     = 0x02,
     201             :     INP_VAR     = 0x03
     202             : };
     203             : 
     204             : 
     205             : enum SwUserType
     206             : {
     207             :     UF_STRING   = 0x01,
     208             :     UF_EXPR     = 0x02
     209             : };
     210             : 
     211             : enum SwDateTimeSubType
     212             : {
     213             :     FIXEDFLD = 1,
     214             :     DATEFLD  = 2,
     215             :     TIMEFLD  = 4
     216             : };
     217             : 
     218             : 
     219             : extern sal_uInt16 aTypeTab[];
     220             : 
     221             : /// General tools.
     222             : String  GetResult(double nVal, sal_uInt32 nNumFmt, sal_uInt16 nLang = LANGUAGE_SYSTEM);
     223             : void    SetErrorStr(const String& rStr);
     224             : String  FormatNumber(sal_uInt32 nNum, sal_uInt32 nFormat);
     225             : 
     226             : /** Instances of SwFields and those derived from it occur 0 to n times.
     227             :  For each class there is one instance of the associated type class.
     228             :  Base class of all field types is SwFieldType. */
     229             : 
     230        3267 : class SW_DLLPUBLIC SwFieldType : public SwModify
     231             : {
     232             :     sal_uInt16 nWhich;
     233             : 
     234             :     friend void _FinitUI();     ///< In order to delete pointer!
     235             :     static  std::vector<String>* pFldNames;
     236             : 
     237             :     static void _GetFldName();  ///< Sets up FldNames; fldmgr.cxx!
     238             : 
     239             : protected:
     240             :     /// Single argument ctors shall be explicit.
     241             :     explicit SwFieldType( sal_uInt16 nWhichId );
     242             : 
     243             : public:
     244             : 
     245             :     static  const String&   GetTypeStr( sal_uInt16 nTypeId );
     246             : 
     247             :     /// Only in derived classes.
     248             :     virtual const rtl::OUString&   GetName() const;
     249             :     virtual SwFieldType*    Copy()    const = 0;
     250             :     virtual bool QueryValue( com::sun::star::uno::Any& rVal, sal_uInt16 nWhich ) const;
     251             :     virtual bool PutValue( const com::sun::star::uno::Any& rVal, sal_uInt16 nWhich );
     252             : 
     253      156094 :             sal_uInt16          Which() const { return nWhich; }
     254             : 
     255             :     inline  void            UpdateFlds() const;
     256             : };
     257             : 
     258        1395 : inline void SwFieldType::UpdateFlds() const
     259             : {
     260        1395 :     ((SwFieldType*)this)->ModifyNotification( 0, 0 );
     261        1395 : }
     262             : 
     263             : /** Base class of all fields.
     264             :  Type of field is queried via Which.
     265             :  Expanded content of field is queried via Expand(). */
     266           0 : class SW_DLLPUBLIC SwField
     267             : {
     268             : private:
     269             :     mutable String      m_Cache;     ///< Cached expansion (for clipboard).
     270             :     sal_uInt16              nLang;   ///< Always change via SetLanguage!
     271             :     sal_Bool                bIsAutomaticLanguage;
     272             :     sal_uInt32          nFormat;
     273             : 
     274             :     SwFieldType*        pType;
     275             : 
     276             :     virtual String      Expand() const = 0;
     277             :     virtual SwField*    Copy() const = 0;
     278             : 
     279             : protected:
     280           0 :     void                SetFormat(sal_uInt32 nSet) {nFormat = nSet;}
     281             : 
     282             :     SwField(SwFieldType* pTyp, sal_uInt32 nFmt = 0, sal_uInt16 nLang = LANGUAGE_SYSTEM);
     283             : 
     284             : public:
     285             :     virtual             ~SwField();
     286             : 
     287             :     inline SwFieldType* GetTyp() const;
     288             : 
     289             :     /// Set new type (used for copying among documents).
     290             :     virtual SwFieldType* ChgTyp( SwFieldType* );
     291             : 
     292             :     /** expand the field.
     293             :         @param  bCached     return cached field value.
     294             :         @remark     most callers should use the cached field value.
     295             :                     this is because various fields need special handing
     296             :                     (ChangeExpansion()) to return correct values, and only
     297             :                     SwTxtFormatter::NewFldPortion() sets things up properly.
     298             :         @return     the generated text (suitable for display)
     299             :       */
     300             :     String              ExpandField(bool const bCached) const;
     301             : 
     302             :     /// @return name or content.
     303             :     virtual String      GetFieldName() const;
     304             : 
     305             :     SwField *           CopyField() const;
     306             : 
     307             :     /// ResId
     308          53 :     sal_uInt16              Which() const
     309             : #ifdef DBG_UTIL
     310             :         ;       // implemented in fldbas.cxx
     311             : #else
     312          53 :         { return pType->Which(); }
     313             : #endif
     314             : 
     315             :     // TYP_ID
     316             :             sal_uInt16      GetTypeId() const;
     317             :     virtual sal_uInt16      GetSubType() const;
     318             :     virtual void        SetSubType(sal_uInt16);
     319             : 
     320             :     /// Language at field position.
     321             :     inline sal_uInt16       GetLanguage() const;
     322             :     virtual void        SetLanguage(sal_uInt16 nLng);
     323             : 
     324             :     /// Query parameters for dialog and for BASIC.
     325             :     inline sal_uInt32   GetFormat() const;
     326             :     virtual const rtl::OUString& GetPar1() const;
     327             :     virtual rtl::OUString GetPar2()   const;
     328             : 
     329             :     virtual String      GetFormula() const;
     330             : 
     331             :     virtual void        ChangeFormat(sal_uInt32 n);
     332             :     virtual void        SetPar1(const rtl::OUString& rStr);
     333             :     virtual void        SetPar2(const rtl::OUString& rStr);
     334             : 
     335             :     virtual bool        QueryValue( com::sun::star::uno::Any& rVal, sal_uInt16 nWhichId ) const;
     336             :     virtual bool        PutValue( const com::sun::star::uno::Any& rVal, sal_uInt16 nWhichId );
     337             : 
     338             :     /// Does the field possess an action on its ClickHandler? (e.g. INetFields, ...).
     339             :     sal_Bool            HasClickHdl() const;
     340             :     sal_Bool            IsFixed() const;
     341             : 
     342          23 :     sal_Bool                IsAutomaticLanguage() const { return bIsAutomaticLanguage;}
     343          27 :     void                SetAutomaticLanguage(sal_Bool bSet){bIsAutomaticLanguage = bSet;}
     344             : 
     345             :     virtual String      GetDescription() const;
     346             : };
     347             : 
     348      130929 : inline SwFieldType* SwField::GetTyp() const
     349      130929 :     { return pType;     }
     350             : 
     351        2446 : inline sal_uInt32 SwField::GetFormat() const
     352        2446 :     { return nFormat;   }
     353             : 
     354        1961 : inline sal_uInt16 SwField::GetLanguage() const
     355        1961 :     { return nLang;     }
     356             : 
     357             : 
     358             :  /// Fields containing values that have to be formated via number formatter.
     359         818 : class SwValueFieldType : public SwFieldType
     360             : {
     361             :     SwDoc*  pDoc;
     362             :     sal_Bool    bUseFormat; ///< Use number formatter.
     363             : 
     364             : protected:
     365             :     SwValueFieldType( SwDoc* pDocPtr, sal_uInt16 nWhichId );
     366             :     SwValueFieldType( const SwValueFieldType& rTyp );
     367             : 
     368             : public:
     369          13 :     inline SwDoc*   GetDoc() const                      { return pDoc; }
     370           2 :     inline void     SetDoc(SwDoc* pNewDoc)              { pDoc = pNewDoc; }
     371             : 
     372           4 :     inline sal_Bool     UseFormat() const                   { return bUseFormat; }
     373        1114 :     inline void     EnableFormat(sal_Bool bFormat = sal_True)   { bUseFormat = bFormat; }
     374             : 
     375             :     String          ExpandValue(const double& rVal, sal_uInt32 nFmt, sal_uInt16 nLng=0) const;
     376             :     void            DoubleToString(String &rValue, const double &rVal, LanguageType eLng) const;
     377             :     void            DoubleToString(String &rValue, const double &rVal, sal_uInt32 nFmt) const;
     378             : };
     379             : 
     380             : class SW_DLLPUBLIC SwValueField : public SwField
     381             : {
     382             :     double fValue;
     383             : 
     384             : protected:
     385             :     SwValueField( SwValueFieldType* pFldType, sal_uInt32 nFmt = 0, sal_uInt16 nLang = LANGUAGE_SYSTEM, const double fVal = 0.0 );
     386             :     SwValueField( const SwValueField& rFld );
     387             : 
     388             : public:
     389             :     virtual                 ~SwValueField();
     390             : 
     391             :     virtual SwFieldType*    ChgTyp( SwFieldType* );
     392             :     virtual void            SetLanguage(sal_uInt16 nLng);
     393             : 
     394          10 :     inline SwDoc*           GetDoc() const          { return ((SwValueFieldType*)GetTyp())->GetDoc(); }
     395             : 
     396             :     virtual double          GetValue() const;
     397             :     virtual void            SetValue( const double& rVal );
     398             : 
     399           2 :     inline String   ExpandValue(const double& rVal, sal_uInt32 nFmt, sal_uInt16 nLng=0) const
     400           2 :         { return ((SwValueFieldType*)GetTyp())->ExpandValue(rVal, nFmt, nLng); }
     401             : 
     402             :     static sal_uInt32       GetSystemFormat(SvNumberFormatter* pFormatter, sal_uInt32 nFmt);
     403             : };
     404             : 
     405           8 : class SW_DLLPUBLIC SwFormulaField : public SwValueField
     406             : {
     407             :     String sFormula;
     408             : 
     409             : protected:
     410             :     SwFormulaField( SwValueFieldType* pFldType, sal_uInt32 nFmt = 0, const double fVal = 0.0 );
     411             :     SwFormulaField( const SwFormulaField& rFld );
     412             : 
     413             : public:
     414             :     virtual String          GetFormula() const;
     415             :     void                    SetFormula(const String& rStr);
     416             : 
     417             :     void                    SetExpandedFormula(const String& rStr);
     418             :     String                  GetExpandedFormula() const;
     419             : };
     420             : 
     421             : #endif // SW_FLDBAS_HXX
     422             : 
     423             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10