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

Generated by: LCOV version 1.10