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

Generated by: LCOV version 1.10