LCOV - code coverage report
Current view: top level - sw/source/core/fields - fldbas.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 125 284 44.0 %
Date: 2012-08-25 Functions: 30 53 56.6 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 79 309 25.6 %

           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                 :            : 
      29                 :            : 
      30                 :            : #include <float.h>
      31                 :            : #include <rtl/math.hxx>
      32                 :            : #include <svl/zforlist.hxx>
      33                 :            : #include <svl/zformat.hxx>
      34                 :            : #include <editeng/unolingu.hxx>
      35                 :            : #include <unofldmid.h>
      36                 :            : #include <doc.hxx>
      37                 :            : #include <editsh.hxx>
      38                 :            : #include <frame.hxx>
      39                 :            : #include <fldbas.hxx>
      40                 :            : #include <flddat.hxx>
      41                 :            : #include <ndtxt.hxx>
      42                 :            : #include <fmtfld.hxx>
      43                 :            : #include <txtfld.hxx>
      44                 :            : #include <pam.hxx>
      45                 :            : #include <docfld.hxx>
      46                 :            : #include <swtable.hxx>
      47                 :            : #include <docufld.hxx>
      48                 :            : #include <expfld.hxx>
      49                 :            : #include <shellres.hxx>
      50                 :            : #include <calc.hxx>
      51                 :            : #include <comcore.hrc>
      52                 :            : #include <docary.hxx>
      53                 :            : 
      54                 :            : #include <math.h>
      55                 :            : 
      56                 :            : using namespace ::com::sun::star;
      57                 :            : using namespace nsSwDocInfoSubType;
      58                 :            : 
      59                 :         42 : sal_uInt16 lcl_GetLanguageOfFormat( sal_uInt16 nLng, sal_uLong nFmt,
      60                 :            :                                 const SvNumberFormatter& rFormatter )
      61                 :            : {
      62         [ -  + ]:         42 :     if( nLng == LANGUAGE_NONE ) // wegen Bug #60010
      63                 :          0 :         nLng = LANGUAGE_SYSTEM;
      64         [ +  + ]:         42 :     else if( nLng == ::GetAppLanguage() )
      65         [ -  + ]:         12 :         switch( rFormatter.GetIndexTableOffset( nFmt ))
      66                 :            :         {
      67                 :            :         case NF_NUMBER_SYSTEM:
      68                 :            :         case NF_DATE_SYSTEM_SHORT:
      69                 :            :         case NF_DATE_SYSTEM_LONG:
      70                 :            :         case NF_DATETIME_SYSTEM_SHORT_HHMM:
      71                 :          0 :             nLng = LANGUAGE_SYSTEM;
      72                 :          0 :             break;
      73                 :         12 :         default: break;
      74                 :            :         }
      75                 :         42 :     return nLng;
      76                 :            : }
      77                 :            : 
      78                 :            : /*--------------------------------------------------------------------
      79                 :            :     Beschreibung: Globals
      80                 :            :  --------------------------------------------------------------------*/
      81                 :            : // Array der Feldname
      82                 :            : 
      83                 :            : std::vector<String>* SwFieldType::pFldNames = 0;
      84                 :            : 
      85                 :            :     sal_uInt16 aTypeTab[] = {
      86                 :            :     /* RES_DBFLD            */      TYP_DBFLD,
      87                 :            :     /* RES_USERFLD          */      TYP_USERFLD,
      88                 :            :     /* RES_FILENAMEFLD      */      TYP_FILENAMEFLD,
      89                 :            :     /* RES_DBNAMEFLD        */      TYP_DBNAMEFLD,
      90                 :            :     /* RES_DATEFLD          */      TYP_DATEFLD,
      91                 :            :     /* RES_TIMEFLD          */      TYP_TIMEFLD,
      92                 :            :     /* RES_PAGENUMBERFLD    */      TYP_PAGENUMBERFLD,  // dynamisch
      93                 :            :     /* RES_AUTHORFLD        */      TYP_AUTHORFLD,
      94                 :            :     /* RES_CHAPTERFLD       */      TYP_CHAPTERFLD,
      95                 :            :     /* RES_DOCSTATFLD       */      TYP_DOCSTATFLD,
      96                 :            :     /* RES_GETEXPFLD        */      TYP_GETFLD,         // dynamisch
      97                 :            :     /* RES_SETEXPFLD        */      TYP_SETFLD,         // dynamisch
      98                 :            :     /* RES_GETREFFLD        */      TYP_GETREFFLD,
      99                 :            :     /* RES_HIDDENTXTFLD     */      TYP_HIDDENTXTFLD,
     100                 :            :     /* RES_POSTITFLD        */      TYP_POSTITFLD,
     101                 :            :     /* RES_FIXDATEFLD       */      TYP_FIXDATEFLD,
     102                 :            :     /* RES_FIXTIMEFLD       */      TYP_FIXTIMEFLD,
     103                 :            :     /* RES_REGFLD           */      0,                  // alt
     104                 :            :     /* RES_VARREGFLD        */      0,                  // alt
     105                 :            :     /* RES_SETREFFLD        */      TYP_SETREFFLD,
     106                 :            :     /* RES_INPUTFLD         */      TYP_INPUTFLD,
     107                 :            :     /* RES_MACROFLD         */      TYP_MACROFLD,
     108                 :            :     /* RES_DDEFLD           */      TYP_DDEFLD,
     109                 :            :     /* RES_TABLEFLD         */      TYP_FORMELFLD,
     110                 :            :     /* RES_HIDDENPARAFLD    */      TYP_HIDDENPARAFLD,
     111                 :            :     /* RES_DOCINFOFLD       */      TYP_DOCINFOFLD,
     112                 :            :     /* RES_TEMPLNAMEFLD     */      TYP_TEMPLNAMEFLD,
     113                 :            :     /* RES_DBNEXTSETFLD     */      TYP_DBNEXTSETFLD,
     114                 :            :     /* RES_DBNUMSETFLD      */      TYP_DBNUMSETFLD,
     115                 :            :     /* RES_DBSETNUMBERFLD   */      TYP_DBSETNUMBERFLD,
     116                 :            :     /* RES_EXTUSERFLD       */      TYP_EXTUSERFLD,
     117                 :            :     /* RES_REFPAGESETFLD    */      TYP_SETREFPAGEFLD,
     118                 :            :     /* RES_REFPAGEGETFLD    */      TYP_GETREFPAGEFLD,
     119                 :            :     /* RES_INTERNETFLD      */      TYP_INTERNETFLD,
     120                 :            :     /* RES_JUMPEDITFLD      */      TYP_JUMPEDITFLD,
     121                 :            :     /* RES_SCRIPTFLD        */      TYP_SCRIPTFLD,
     122                 :            :     /* RES_DATETIMEFLD      */      0,                  // dynamisch
     123                 :            :     /* RES_AUTHORITY        */      TYP_AUTHORITY,
     124                 :            :     /* RES_COMBINED_CHARS   */      TYP_COMBINED_CHARS,
     125                 :            :     /* RES_DROPDOWN         */      TYP_DROPDOWN
     126                 :            :     };
     127                 :            :         // ????? TYP_USRINPFLD,
     128                 :            : 
     129                 :            : 
     130                 :            : 
     131                 :          9 : const String& SwFieldType::GetTypeStr(sal_uInt16 nTypeId)
     132                 :            : {
     133         [ +  + ]:          9 :     if( !pFldNames )
     134                 :          5 :         _GetFldName();
     135                 :            : 
     136         [ +  - ]:          9 :     if( nTypeId < SwFieldType::pFldNames->size() )
     137                 :          9 :         return (*SwFieldType::pFldNames)[nTypeId];
     138                 :            :     else
     139                 :          9 :         return aEmptyStr;
     140                 :            : }
     141                 :            : 
     142                 :            : /*---------------------------------------------------
     143                 :            :  Jedes Feld referenziert einen Feldtypen, der fuer
     144                 :            :  jedes Dokument einmalig ist.
     145                 :            :  --------------------------------------------------*/
     146                 :            : 
     147                 :      49711 : SwFieldType::SwFieldType( sal_uInt16 nWhichId )
     148                 :            :     : SwModify(0),
     149                 :      49711 :     nWhich( nWhichId )
     150                 :            : {
     151                 :      49711 : }
     152                 :            : 
     153                 :            : namespace
     154                 :            : {
     155                 :         73 :     rtl::OUString aEmptyOUStr;
     156                 :            : }
     157                 :            : 
     158                 :      13212 : const rtl::OUString& SwFieldType::GetName() const
     159                 :            : {
     160                 :      13212 :     return aEmptyOUStr;
     161                 :            : }
     162                 :            : 
     163                 :          0 : bool SwFieldType::QueryValue( uno::Any&, sal_uInt16 ) const
     164                 :            : {
     165                 :          0 :     return false;
     166                 :            : }
     167                 :          0 : bool SwFieldType::PutValue( const uno::Any& , sal_uInt16 )
     168                 :            : {
     169                 :          0 :     return false;
     170                 :            : }
     171                 :            : 
     172                 :            : /*--------------------------------------------------------------------
     173                 :            :     Beschreibung:   Basisklasse aller Felder
     174                 :            :                     Felder referenzieren einen Feldtyp
     175                 :            :                     Felder sind n-mal vorhanden, Feldtypen nur einmal
     176                 :            :  --------------------------------------------------------------------*/
     177                 :            : 
     178                 :       7878 : SwField::SwField(SwFieldType* pTyp, sal_uInt32 nFmt, sal_uInt16 nLng) :
     179                 :            :     nLang(nLng),
     180                 :            :     bIsAutomaticLanguage(sal_True),
     181                 :       7878 :     nFormat(nFmt)
     182                 :            : {
     183                 :            :     OSL_ENSURE( pTyp, "SwField: no SwFieldType" );
     184                 :       7878 :     pType = pTyp;
     185                 :       7878 : }
     186                 :            : 
     187                 :       7871 : SwField::~SwField()
     188                 :            : {
     189         [ -  + ]:       7871 : }
     190                 :            : 
     191                 :            : /*--------------------------------------------------------------------
     192                 :            :     Beschreibung: Statt Umweg ueber den Typ
     193                 :            :  --------------------------------------------------------------------*/
     194                 :            : 
     195                 :            : #ifdef DBG_UTIL
     196                 :            : sal_uInt16 SwField::Which() const
     197                 :            : {
     198                 :            :     OSL_ENSURE(pType, "SwField: No FieldType");
     199                 :            :     return pType->Which();
     200                 :            : }
     201                 :            : #endif
     202                 :            : 
     203                 :          0 : sal_uInt16 SwField::GetTypeId() const
     204                 :            : {
     205                 :            : 
     206                 :            :     sal_uInt16 nRet;
     207   [ #  #  #  #  :          0 :     switch( pType->Which() )
                   #  # ]
     208                 :            :     {
     209                 :            :     case RES_DATETIMEFLD:
     210         [ #  # ]:          0 :         if (GetSubType() & FIXEDFLD)
     211         [ #  # ]:          0 :             nRet = static_cast<sal_uInt16>(GetSubType() & DATEFLD ? TYP_FIXDATEFLD : TYP_FIXTIMEFLD);
     212                 :            :         else
     213                 :          0 :             nRet = static_cast<sal_uInt16>(GetSubType() & DATEFLD ? TYP_DATEFLD : TYP_TIMEFLD);
     214                 :          0 :         break;
     215                 :            :     case RES_GETEXPFLD:
     216         [ #  # ]:          0 :         nRet = static_cast<sal_uInt16>(nsSwGetSetExpType::GSE_FORMULA & GetSubType() ? TYP_FORMELFLD : TYP_GETFLD);
     217                 :          0 :         break;
     218                 :            : 
     219                 :            :     case RES_HIDDENTXTFLD:
     220                 :          0 :         nRet = GetSubType();
     221                 :          0 :         break;
     222                 :            : 
     223                 :            :     case RES_SETEXPFLD:
     224         [ #  # ]:          0 :         if( nsSwGetSetExpType::GSE_SEQ & GetSubType() )
     225                 :          0 :             nRet = TYP_SEQFLD;
     226         [ #  # ]:          0 :         else if( ((SwSetExpField*)this)->GetInputFlag() )
     227                 :          0 :             nRet = TYP_SETINPFLD;
     228                 :            :         else
     229                 :          0 :             nRet = TYP_SETFLD;
     230                 :          0 :         break;
     231                 :            : 
     232                 :            :     case RES_PAGENUMBERFLD:
     233                 :          0 :         nRet = GetSubType();
     234         [ #  # ]:          0 :         if( PG_NEXT == nRet )
     235                 :          0 :             nRet = TYP_NEXTPAGEFLD;
     236         [ #  # ]:          0 :         else if( PG_PREV == nRet )
     237                 :          0 :             nRet = TYP_PREVPAGEFLD;
     238                 :            :         else
     239                 :          0 :             nRet = TYP_PAGENUMBERFLD;
     240                 :          0 :         break;
     241                 :            : 
     242                 :            :     default:
     243                 :          0 :         nRet = aTypeTab[ pType->Which() ];
     244                 :            :     }
     245                 :          0 :     return nRet;
     246                 :            : }
     247                 :            : 
     248                 :            : 
     249                 :            : /*--------------------------------------------------------------------
     250                 :            :     Beschreibung: liefert den Namen oder den Inhalt
     251                 :            :  --------------------------------------------------------------------*/
     252                 :            : 
     253                 :          0 : String SwField::GetFieldName() const
     254                 :            : {
     255                 :          0 :     sal_uInt16 nTypeId = GetTypeId();
     256         [ #  # ]:          0 :     if (RES_DATETIMEFLD == GetTyp()->Which())
     257                 :            :     {
     258                 :            :         nTypeId = static_cast<sal_uInt16>(
     259                 :          0 :             ((GetSubType() & DATEFLD) != 0) ? TYP_DATEFLD : TYP_TIMEFLD);
     260                 :            :     }
     261                 :          0 :     String sRet = SwFieldType::GetTypeStr( nTypeId );
     262 [ #  # ][ #  # ]:          0 :     if (IsFixed())
     263                 :            :     {
     264         [ #  # ]:          0 :         sRet += ' ';
     265 [ #  # ][ #  # ]:          0 :         sRet += ViewShell::GetShellRes()->aFixedStr;
     266                 :            :     }
     267                 :          0 :     return sRet;
     268                 :            : }
     269                 :            : 
     270                 :            : /*--------------------------------------------------------------------
     271                 :            :     Beschreibung: Parameter setzen auslesen
     272                 :            :  --------------------------------------------------------------------*/
     273                 :            : 
     274                 :          0 : const rtl::OUString& SwField::GetPar1() const
     275                 :            : {
     276                 :          0 :     return aEmptyOUStr;
     277                 :            : }
     278                 :            : 
     279                 :          0 : rtl::OUString SwField::GetPar2() const
     280                 :            : {
     281                 :          0 :     return rtl::OUString();
     282                 :            : }
     283                 :            : 
     284                 :          0 : String SwField::GetFormula() const
     285                 :            : {
     286         [ #  # ]:          0 :     return GetPar2();
     287                 :            : }
     288                 :            : 
     289                 :          0 : void SwField::SetPar1(const rtl::OUString& )
     290                 :          0 : {}
     291                 :            : 
     292                 :          0 : void SwField::SetPar2(const rtl::OUString& )
     293                 :          0 : {}
     294                 :            : 
     295                 :          6 : sal_uInt16 SwField::GetSubType() const
     296                 :            : {
     297                 :          6 :     return 0;
     298                 :            : }
     299                 :            : 
     300                 :          0 : void SwField::SetSubType(sal_uInt16 )
     301                 :            : {
     302                 :          0 : }
     303                 :            : 
     304                 :          0 : bool  SwField::QueryValue( uno::Any& rVal, sal_uInt16 nWhichId ) const
     305                 :            : {
     306         [ #  # ]:          0 :     switch( nWhichId )
     307                 :            :     {
     308                 :            :         case FIELD_PROP_BOOL4:
     309                 :            :         {
     310                 :          0 :             sal_Bool bFixed = !bIsAutomaticLanguage;
     311         [ #  # ]:          0 :             rVal.setValue(&bFixed, ::getCppuBooleanType());
     312                 :            :         }
     313                 :          0 :         break;
     314                 :            :         default:
     315                 :            :             OSL_FAIL("illegal property");
     316                 :            :     }
     317                 :          0 :     return true;
     318                 :            : }
     319                 :          0 : bool SwField::PutValue( const uno::Any& rVal, sal_uInt16 nWhichId )
     320                 :            : {
     321         [ #  # ]:          0 :     switch( nWhichId )
     322                 :            :     {
     323                 :            :         case FIELD_PROP_BOOL4:
     324                 :            :         {
     325                 :          0 :             sal_Bool bFixed = sal_False;
     326         [ #  # ]:          0 :             if(rVal >>= bFixed)
     327                 :          0 :                 bIsAutomaticLanguage = !bFixed;
     328                 :            :         }
     329                 :          0 :         break;
     330                 :            :         default:
     331                 :            :             OSL_FAIL("illegal property");
     332                 :            :     }
     333                 :          0 :     return true;
     334                 :            : }
     335                 :            : 
     336                 :            : 
     337                 :            : /*--------------------------------------------------------------------
     338                 :            :     Beschreibung:   neuen Typ setzen
     339                 :            :                     (wird fuer das Kopieren zwischen Dokumenten benutzt)
     340                 :            :                     muss immer vom gleichen Typ sein.
     341                 :            :  --------------------------------------------------------------------*/
     342                 :            : 
     343                 :          2 : SwFieldType* SwField::ChgTyp( SwFieldType* pNewType )
     344                 :            : {
     345                 :            :     OSL_ENSURE( pNewType && pNewType->Which() == pType->Which(),
     346                 :            :             "kein Typ oder ungleiche Typen" );
     347                 :            : 
     348                 :          2 :     SwFieldType* pOld = pType;
     349                 :          2 :     pType = pNewType;
     350                 :          2 :     return pOld;
     351                 :            : }
     352                 :            : 
     353                 :            :     // hat das Feld eine Action auf dem ClickHandler ? (z.B. INetFelder,..)
     354                 :          0 : sal_Bool SwField::HasClickHdl() const
     355                 :            : {
     356                 :          0 :     sal_Bool bRet = sal_False;
     357      [ #  #  # ]:          0 :     switch( pType->Which() )
     358                 :            :     {
     359                 :            :     case RES_INTERNETFLD:
     360                 :            :     case RES_JUMPEDITFLD:
     361                 :            :     case RES_GETREFFLD:
     362                 :            :     case RES_MACROFLD:
     363                 :            :     case RES_INPUTFLD:
     364                 :            :     case RES_DROPDOWN :
     365                 :          0 :         bRet = sal_True;
     366                 :          0 :         break;
     367                 :            : 
     368                 :            :     case RES_SETEXPFLD:
     369                 :          0 :         bRet = ((SwSetExpField*)this)->GetInputFlag();
     370                 :          0 :         break;
     371                 :            :     }
     372                 :          0 :     return bRet;
     373                 :            : }
     374                 :            : 
     375                 :       5875 : void SwField::SetLanguage(sal_uInt16 nLng)
     376                 :            : {
     377                 :       5875 :     nLang = nLng;
     378                 :       5875 : }
     379                 :            : 
     380                 :          4 : void SwField::ChangeFormat(sal_uInt32 n)
     381                 :            : {
     382                 :          4 :     nFormat = n;
     383                 :          4 : }
     384                 :            : 
     385                 :        297 : sal_Bool SwField::IsFixed() const
     386                 :            : {
     387                 :        297 :     sal_Bool bRet = sal_False;
     388   [ -  +  +  -  :        297 :     switch( pType->Which() )
                   -  - ]
     389                 :            :     {
     390                 :            :     case RES_FIXDATEFLD:
     391                 :            :     case RES_FIXTIMEFLD:
     392                 :          0 :         bRet = sal_True;
     393                 :          0 :         break;
     394                 :            : 
     395                 :            :     case RES_DATETIMEFLD:
     396                 :        141 :         bRet = 0 != (GetSubType() & FIXEDFLD);
     397                 :        141 :         break;
     398                 :            : 
     399                 :            :     case RES_EXTUSERFLD:
     400                 :            :     case RES_AUTHORFLD:
     401                 :        156 :         bRet = 0 != (GetFormat() & AF_FIXED);
     402                 :        156 :         break;
     403                 :            : 
     404                 :            :     case RES_FILENAMEFLD:
     405                 :          0 :         bRet = 0 != (GetFormat() & FF_FIXED);
     406                 :          0 :         break;
     407                 :            : 
     408                 :            :     case RES_DOCINFOFLD:
     409                 :          0 :         bRet = 0 != (GetSubType() & DI_SUB_FIXED);
     410                 :          0 :         break;
     411                 :            :     }
     412                 :        297 :     return bRet;
     413                 :            : }
     414                 :            : 
     415                 :       2242 : String SwField::ExpandField(bool const bCached) const
     416                 :            : {
     417         [ +  + ]:       2242 :     if (!bCached) // #i85766# do not expand fields in clipboard documents
     418                 :            :     {
     419         [ +  - ]:       2026 :         m_Cache = Expand();
     420                 :            :     }
     421                 :       2242 :     return m_Cache;
     422                 :            : }
     423                 :            : 
     424                 :       6329 : SwField * SwField::CopyField() const
     425                 :            : {
     426                 :       6329 :     SwField *const pNew = Copy();
     427                 :            :     // #i85766# cache expansion of source (for clipboard)
     428                 :            :     // use this->cache, not this->Expand(): only text formatting calls Expand()
     429                 :       6329 :     pNew->m_Cache = m_Cache;
     430                 :       6329 :     return pNew;
     431                 :            : }
     432                 :            : 
     433                 :            : /*--------------------------------------------------------------------
     434                 :            :     Beschreibung: Numerierung expandieren
     435                 :            :  --------------------------------------------------------------------*/
     436                 :            : 
     437                 :         16 : String FormatNumber(sal_uInt32 nNum, sal_uInt32 nFormat)
     438                 :            : {
     439         [ -  + ]:         16 :     if(SVX_NUM_PAGEDESC == nFormat)
     440         [ #  # ]:          0 :         return  String::CreateFromInt32( nNum );
     441         [ +  - ]:         16 :     SvxNumberType aNumber;
     442                 :            : 
     443                 :            :     OSL_ENSURE(nFormat != SVX_NUM_NUMBER_NONE, "Falsches Nummern-Format" );
     444                 :            : 
     445                 :         16 :     aNumber.SetNumberingType((sal_Int16)nFormat);
     446 [ +  - ][ +  - ]:         16 :     return aNumber.GetNumStr(nNum);
     447                 :            : }
     448                 :            : 
     449                 :            : /*--------------------------------------------------------------------
     450                 :            :     Beschreibung: CTOR SwValueFieldType
     451                 :            :  --------------------------------------------------------------------*/
     452                 :            : 
     453                 :      12524 : SwValueFieldType::SwValueFieldType( SwDoc* pDocPtr, sal_uInt16 nWhichId )
     454                 :            :     : SwFieldType(nWhichId),
     455                 :            :     pDoc(pDocPtr),
     456                 :      12524 :     bUseFormat(sal_True)
     457                 :            : {
     458                 :      12524 : }
     459                 :            : 
     460                 :          0 : SwValueFieldType::SwValueFieldType( const SwValueFieldType& rTyp )
     461                 :          0 :     : SwFieldType(rTyp.Which()),
     462                 :          0 :     pDoc(rTyp.GetDoc()),
     463                 :          0 :     bUseFormat(rTyp.UseFormat())
     464                 :            : {
     465                 :          0 : }
     466                 :            : 
     467                 :            : /*--------------------------------------------------------------------
     468                 :            :     Beschreibung: Wert formatiert als String zurueckgeben
     469                 :            :  --------------------------------------------------------------------*/
     470                 :            : 
     471                 :         22 : String SwValueFieldType::ExpandValue( const double& rVal,
     472                 :            :                                         sal_uInt32 nFmt, sal_uInt16 nLng) const
     473                 :            : {
     474         [ -  + ]:         22 :     if (rVal >= DBL_MAX)        // FehlerString fuer Calculator
     475 [ #  # ][ #  # ]:          0 :         return ViewShell::GetShellRes()->aCalc_Error;
     476                 :            : 
     477         [ +  - ]:         22 :     String sExpand;
     478         [ +  - ]:         22 :     SvNumberFormatter* pFormatter = pDoc->GetNumberFormatter();
     479                 :         22 :     Color* pCol = 0;
     480                 :            : 
     481                 :            :     // wegen Bug #60010
     482         [ +  - ]:         22 :     sal_uInt16 nFmtLng = ::lcl_GetLanguageOfFormat( nLng, nFmt, *pFormatter );
     483                 :            : 
     484 [ +  + ][ +  + ]:         22 :     if( nFmt < SV_COUNTRY_LANGUAGE_OFFSET && LANGUAGE_SYSTEM != nFmtLng )
     485                 :            :     {
     486                 :          6 :         short nType = NUMBERFORMAT_DEFINED;
     487                 :            :         xub_StrLen nDummy;
     488                 :            : 
     489         [ +  - ]:          6 :         const SvNumberformat* pEntry = pFormatter->GetEntry(nFmt);
     490                 :            : 
     491 [ +  - ][ +  - ]:          6 :         if (pEntry && nLng != pEntry->GetLanguage())
                 [ +  - ]
     492                 :            :         {
     493                 :            :             sal_uInt32 nNewFormat = pFormatter->GetFormatForLanguageIfBuiltIn(nFmt,
     494         [ +  - ]:          6 :                                                     (LanguageType)nFmtLng);
     495                 :            : 
     496         [ -  + ]:          6 :             if (nNewFormat == nFmt)
     497                 :            :             {
     498                 :            :                 // Warscheinlich benutzerdefiniertes Format
     499         [ #  # ]:          0 :                 String sFmt(pEntry->GetFormatstring());
     500                 :            : 
     501                 :            :                 pFormatter->PutandConvertEntry(sFmt, nDummy, nType, nFmt,
     502 [ #  # ][ #  # ]:          0 :                                         pEntry->GetLanguage(), nFmtLng );
     503                 :            :             }
     504                 :            :             else
     505                 :          6 :                 nFmt = nNewFormat;
     506                 :            :         }
     507                 :            :         OSL_ENSURE(pEntry, "Unbekanntes Zahlenformat!");
     508                 :            :     }
     509                 :            : 
     510 [ +  - ][ -  + ]:         22 :     if( pFormatter->IsTextFormat( nFmt ) )
     511                 :            :     {
     512         [ #  # ]:          0 :         String sValue;
     513         [ #  # ]:          0 :         DoubleToString(sValue, rVal, nFmtLng);
     514 [ #  # ][ #  # ]:          0 :         pFormatter->GetOutputString(sValue, nFmt, sExpand, &pCol);
     515                 :            :     }
     516                 :            :     else
     517         [ +  - ]:         22 :         pFormatter->GetOutputString(rVal, nFmt, sExpand, &pCol);
     518                 :            : 
     519 [ +  - ][ +  - ]:         22 :     return sExpand;
     520                 :            : }
     521                 :            : 
     522                 :          0 : void SwValueFieldType::DoubleToString( String &rValue, const double &rVal,
     523                 :            :                                         sal_uInt32 nFmt) const
     524                 :            : {
     525                 :          0 :     SvNumberFormatter* pFormatter = pDoc->GetNumberFormatter();
     526                 :          0 :     const SvNumberformat* pEntry = pFormatter->GetEntry(nFmt);
     527                 :            : 
     528         [ #  # ]:          0 :     if (pEntry)
     529                 :          0 :         DoubleToString(rValue, rVal, pEntry->GetLanguage());
     530                 :          0 : }
     531                 :            : 
     532                 :          0 : void SwValueFieldType::DoubleToString( String &rValue, const double &rVal,
     533                 :            :                                         sal_uInt16 nLng ) const
     534                 :            : {
     535                 :          0 :     SvNumberFormatter* pFormatter = pDoc->GetNumberFormatter();
     536                 :            : 
     537                 :            :     // wegen Bug #60010
     538         [ #  # ]:          0 :     if( nLng == LANGUAGE_NONE ) // wegen Bug #60010
     539                 :          0 :         nLng = LANGUAGE_SYSTEM;
     540                 :            : 
     541                 :          0 :     pFormatter->ChangeIntl( nLng ); // Separator in der richtigen Sprache besorgen
     542                 :            :     rValue = ::rtl::math::doubleToUString( rVal, rtl_math_StringFormat_F, 12,
     543         [ #  # ]:          0 :                                     pFormatter->GetDecSep(), true );
     544                 :          0 : }
     545                 :            : 
     546                 :            : /*--------------------------------------------------------------------
     547                 :            :     Beschreibung: CTOR SwValueField
     548                 :            :  --------------------------------------------------------------------*/
     549                 :            : 
     550                 :        137 : SwValueField::SwValueField( SwValueFieldType* pFldType, sal_uInt32 nFmt,
     551                 :            :                             sal_uInt16 nLng, const double fVal )
     552                 :            :     : SwField(pFldType, nFmt, nLng),
     553                 :        137 :     fValue(fVal)
     554                 :            : {
     555                 :        137 : }
     556                 :            : 
     557                 :          0 : SwValueField::SwValueField( const SwValueField& rFld )
     558                 :            :     : SwField(rFld),
     559         [ #  # ]:          0 :     fValue(rFld.GetValue())
     560                 :            : {
     561                 :          0 : }
     562                 :            : 
     563                 :        133 : SwValueField::~SwValueField()
     564                 :            : {
     565         [ -  + ]:        133 : }
     566                 :            : /*--------------------------------------------------------------------
     567                 :            :     Beschreibung:   neuen Typ setzen
     568                 :            :                     (wird fuer das Kopieren zwischen Dokumenten benutzt)
     569                 :            :                     muss immer vom gleichen Typ sein.
     570                 :            :  --------------------------------------------------------------------*/
     571                 :            : 
     572                 :          2 : SwFieldType* SwValueField::ChgTyp( SwFieldType* pNewType )
     573                 :            : {
     574                 :          2 :     SwDoc* pNewDoc = ((SwValueFieldType *)pNewType)->GetDoc();
     575                 :          2 :     SwDoc* pDoc    = GetDoc();
     576                 :            : 
     577 [ +  - ][ -  + ]:          2 :     if( pNewDoc && pDoc && pDoc != pNewDoc)
                 [ +  - ]
     578                 :            :     {
     579                 :          0 :         SvNumberFormatter* pFormatter = pNewDoc->GetNumberFormatter();
     580                 :            : 
     581   [ #  #  #  # ]:          0 :         if( pFormatter && pFormatter->HasMergeFmtTbl() &&
         [ #  # ][ #  # ]
     582                 :          0 :             ((SwValueFieldType *)GetTyp())->UseFormat() )
     583                 :          0 :             SetFormat(pFormatter->GetMergeFmtIndex( GetFormat() ));
     584                 :            :     }
     585                 :            : 
     586                 :          2 :     return SwField::ChgTyp(pNewType);
     587                 :            : }
     588                 :            : 
     589                 :            : /*--------------------------------------------------------------------
     590                 :            :     Beschreibung: Format in Office-Sprache ermitteln
     591                 :            :  --------------------------------------------------------------------*/
     592                 :            : 
     593                 :          0 : sal_uInt32 SwValueField::GetSystemFormat(SvNumberFormatter* pFormatter, sal_uInt32 nFmt)
     594                 :            : {
     595                 :          0 :     const SvNumberformat* pEntry = pFormatter->GetEntry(nFmt);
     596 [ #  # ][ #  # ]:          0 :     sal_uInt16 nLng = SvxLocaleToLanguage( SvtSysLocale().GetLocaleData().getLocale() );
                 [ #  # ]
     597                 :            : 
     598 [ #  # ][ #  # ]:          0 :     if (pEntry && nLng != pEntry->GetLanguage())
                 [ #  # ]
     599                 :            :     {
     600                 :            :         sal_uInt32 nNewFormat = pFormatter->GetFormatForLanguageIfBuiltIn(nFmt,
     601                 :          0 :                                                         (LanguageType)nLng);
     602                 :            : 
     603         [ #  # ]:          0 :         if (nNewFormat == nFmt)
     604                 :            :         {
     605                 :            :             // Warscheinlich benutzerdefiniertes Format
     606                 :          0 :             short nType = NUMBERFORMAT_DEFINED;
     607                 :            :             xub_StrLen nDummy;
     608                 :            : 
     609         [ #  # ]:          0 :             String sFmt(pEntry->GetFormatstring());
     610                 :            : 
     611                 :          0 :             sal_uInt32 nFormat = nFmt;
     612                 :            :             pFormatter->PutandConvertEntry(sFmt, nDummy, nType,
     613         [ #  # ]:          0 :                                 nFormat, pEntry->GetLanguage(), nLng);
     614         [ #  # ]:          0 :             nFmt = nFormat;
     615                 :            :         }
     616                 :            :         else
     617                 :          0 :             nFmt = nNewFormat;
     618                 :            :     }
     619                 :            : 
     620                 :          0 :     return nFmt;
     621                 :            : }
     622                 :            : 
     623                 :            : /*--------------------------------------------------------------------
     624                 :            :     Beschreibung: Sprache im Format anpassen
     625                 :            :  --------------------------------------------------------------------*/
     626                 :            : 
     627                 :         45 : void SwValueField::SetLanguage( sal_uInt16 nLng )
     628                 :            : {
     629   [ +  +  +  -  :         85 :     if( IsAutomaticLanguage() &&
           +  - ][ +  + ]
     630                 :         20 :             ((SwValueFieldType *)GetTyp())->UseFormat() &&
     631                 :         20 :         GetFormat() != SAL_MAX_UINT32 )
     632                 :            :     {
     633                 :            :         // wegen Bug #60010
     634                 :         20 :         SvNumberFormatter* pFormatter = GetDoc()->GetNumberFormatter();
     635                 :            :         sal_uInt16 nFmtLng = ::lcl_GetLanguageOfFormat( nLng, GetFormat(),
     636                 :         20 :                                                     *pFormatter );
     637                 :            : 
     638   [ +  +  -  + ]:         28 :         if( (GetFormat() >= SV_COUNTRY_LANGUAGE_OFFSET ||
         [ +  + ][ +  - ]
     639                 :            :              LANGUAGE_SYSTEM != nFmtLng ) &&
     640         [ #  # ]:          8 :             !(Which() == RES_USERFLD && (GetSubType()&nsSwExtendedSubType::SUB_CMD) ) )
     641                 :            :         {
     642                 :          8 :             const SvNumberformat* pEntry = pFormatter->GetEntry(GetFormat());
     643                 :            : 
     644 [ +  - ][ +  - ]:          8 :             if( pEntry && nFmtLng != pEntry->GetLanguage() )
                 [ +  - ]
     645                 :            :             {
     646                 :            :                 sal_uInt32 nNewFormat = pFormatter->GetFormatForLanguageIfBuiltIn(
     647         [ +  - ]:          8 :                                         GetFormat(), (LanguageType)nFmtLng );
     648                 :            : 
     649         [ -  + ]:          8 :                 if( nNewFormat == GetFormat() )
     650                 :            :                 {
     651                 :            :                     // Warscheinlich benutzerdefiniertes Format
     652                 :          0 :                     short nType = NUMBERFORMAT_DEFINED;
     653                 :            :                     xub_StrLen nDummy;
     654         [ #  # ]:          0 :                     String sFmt( pEntry->GetFormatstring() );
     655                 :            :                     pFormatter->PutandConvertEntry( sFmt, nDummy, nType,
     656                 :            :                                                     nNewFormat,
     657                 :          0 :                                                     pEntry->GetLanguage(),
     658 [ #  # ][ #  # ]:          0 :                                                     nFmtLng );
     659                 :            :                 }
     660                 :          8 :                 SetFormat( nNewFormat );
     661                 :            :             }
     662                 :            :             OSL_ENSURE(pEntry, "Unbekanntes Zahlenformat!");
     663                 :            :         }
     664                 :            :     }
     665                 :            : 
     666                 :         45 :     SwField::SetLanguage(nLng);
     667                 :         45 : }
     668                 :            : 
     669                 :         62 : double SwValueField::GetValue() const
     670                 :            : {
     671                 :         62 :     return fValue;
     672                 :            : }
     673                 :            : 
     674                 :        114 : void SwValueField::SetValue( const double& rVal )
     675                 :            : {
     676                 :        114 :     fValue = rVal;
     677                 :        114 : }
     678                 :            : 
     679                 :            : /*--------------------------------------------------------------------
     680                 :            :     Beschreibung: SwFormulaField
     681                 :            :  --------------------------------------------------------------------*/
     682                 :            : 
     683                 :         30 : SwFormulaField::SwFormulaField( SwValueFieldType* pFldType, sal_uInt32 nFmt, const double fVal)
     684         [ +  - ]:         30 :     : SwValueField(pFldType, nFmt, LANGUAGE_SYSTEM, fVal)
     685                 :            : {
     686                 :         30 : }
     687                 :            : 
     688                 :          0 : SwFormulaField::SwFormulaField( const SwFormulaField& rFld )
     689                 :          0 :     : SwValueField((SwValueFieldType *)rFld.GetTyp(), rFld.GetFormat(),
     690         [ #  # ]:          0 :                     rFld.GetLanguage(), rFld.GetValue())
     691                 :            : {
     692                 :          0 : }
     693                 :            : 
     694                 :         30 : String SwFormulaField::GetFormula() const
     695                 :            : {
     696                 :         30 :     return sFormula;
     697                 :            : }
     698                 :            : 
     699                 :         30 : void SwFormulaField::SetFormula(const String& rStr)
     700                 :            : {
     701                 :         30 :     sFormula = rStr;
     702                 :            : 
     703                 :         30 :     sal_uLong nFmt(GetFormat());
     704                 :            : 
     705 [ -  + ][ +  + ]:         30 :     if( nFmt && SAL_MAX_UINT32 != nFmt )
     706                 :            :     {
     707                 :          0 :         xub_StrLen nPos = 0;
     708                 :            :         double fTmpValue;
     709 [ #  # ][ #  # ]:          0 :         if( SwCalc::Str2Double( rStr, nPos, fTmpValue, GetDoc() ) )
     710         [ #  # ]:          0 :             SwValueField::SetValue( fTmpValue );
     711                 :            :     }
     712                 :         30 : }
     713                 :            : 
     714                 :          0 : void SwFormulaField::SetExpandedFormula( const String& rStr )
     715                 :            : {
     716                 :          0 :     sal_uInt32 nFmt(GetFormat());
     717                 :            : 
     718 [ #  # ][ #  # ]:          0 :     if (nFmt && nFmt != SAL_MAX_UINT32 && ((SwValueFieldType *)GetTyp())->UseFormat())
         [ #  # ][ #  # ]
     719                 :            :     {
     720                 :            :         double fTmpValue;
     721                 :            : 
     722         [ #  # ]:          0 :         SvNumberFormatter* pFormatter = GetDoc()->GetNumberFormatter();
     723                 :            : 
     724 [ #  # ][ #  # ]:          0 :         if (pFormatter->IsNumberFormat(rStr, nFmt, fTmpValue))
     725                 :            :         {
     726         [ #  # ]:          0 :             SwValueField::SetValue(fTmpValue);
     727         [ #  # ]:          0 :             sFormula.Erase();
     728                 :            : 
     729         [ #  # ]:          0 :             ((SwValueFieldType *)GetTyp())->DoubleToString(sFormula, fTmpValue, nFmt);
     730                 :          0 :             return;
     731                 :            :         }
     732                 :            :     }
     733         [ #  # ]:          0 :     sFormula = rStr;
     734                 :            : }
     735                 :            : 
     736                 :          0 : String SwFormulaField::GetExpandedFormula() const
     737                 :            : {
     738                 :          0 :     sal_uInt32 nFmt(GetFormat());
     739                 :            : 
     740 [ #  # ][ #  # ]:          0 :     if (nFmt && nFmt != SAL_MAX_UINT32 && ((SwValueFieldType *)GetTyp())->UseFormat())
         [ #  # ][ #  # ]
     741                 :            :     {
     742         [ #  # ]:          0 :         String sFormattedValue;
     743                 :          0 :         Color* pCol = 0;
     744                 :            : 
     745         [ #  # ]:          0 :         SvNumberFormatter* pFormatter = GetDoc()->GetNumberFormatter();
     746                 :            : 
     747 [ #  # ][ #  # ]:          0 :         if (pFormatter->IsTextFormat(nFmt))
     748                 :            :         {
     749         [ #  # ]:          0 :             String sValue;
     750 [ #  # ][ #  # ]:          0 :             ((SwValueFieldType *)GetTyp())->DoubleToString(sValue, GetValue(), nFmt);
     751 [ #  # ][ #  # ]:          0 :             pFormatter->GetOutputString(sValue, nFmt, sFormattedValue, &pCol);
     752                 :            :         }
     753                 :            :         else
     754 [ #  # ][ #  # ]:          0 :             pFormatter->GetOutputString(GetValue(), nFmt, sFormattedValue, &pCol);
     755                 :            : 
     756 [ #  # ][ #  # ]:          0 :         return sFormattedValue;
     757                 :            :     }
     758                 :            :     else
     759                 :          0 :         return GetFormula();
     760                 :            : }
     761                 :            : 
     762                 :         25 : String SwField::GetDescription() const
     763                 :            : {
     764         [ +  - ]:         25 :     return SW_RES(STR_FIELD);
     765                 :            : }
     766                 :            : 
     767                 :          8 : sal_uInt16 SwFldTypes::GetPos(const SwFieldType* pFieldType) const
     768                 :            : {
     769         [ +  - ]:          8 :     const_iterator it = std::find(begin(), end(), pFieldType);
     770 [ +  - ][ +  + ]:          8 :     return it == end() ? USHRT_MAX : it - begin();
         [ +  - ][ +  + ]
                 [ #  # ]
     771                 :            : }
     772                 :            : 
     773                 :       1458 : SwFldTypes::~SwFldTypes()
     774                 :            : {
     775 [ +  - ][ +  - ]:      48156 :     for(const_iterator it = begin(); it != end(); ++it)
         [ +  - ][ +  + ]
     776 [ +  - ][ +  - ]:      46698 :         delete *it;
                 [ +  - ]
     777 [ +  - ][ +  - ]:       1677 : }
     778                 :            : 
     779                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10