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

Generated by: LCOV version 1.10