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

Generated by: LCOV version 1.10