LCOV - code coverage report
Current view: top level - sw/inc - fldbas.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 25 26 96.2 %
Date: 2012-08-25 Functions: 18 22 81.8 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 4 8 50.0 %

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

Generated by: LCOV version 1.10