LCOV - code coverage report
Current view: top level - sw/source/core/fields - usrfld.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 43 155 27.7 %
Date: 2012-08-25 Functions: 8 23 34.8 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 13 128 10.2 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : 
      30                 :            : #include <svl/zforlist.hxx>
      31                 :            : #include <svl/zformat.hxx>
      32                 :            : 
      33                 :            : #include <svx/svdmodel.hxx>
      34                 :            : 
      35                 :            : #include <calbck.hxx>
      36                 :            : #include <calc.hxx>
      37                 :            : #include <usrfld.hxx>
      38                 :            : #include <doc.hxx>
      39                 :            : #include <IDocumentUndoRedo.hxx>
      40                 :            : #include <editsh.hxx>
      41                 :            : #include <dpage.hxx>
      42                 :            : #include <unofldmid.h>
      43                 :            : 
      44                 :            : 
      45                 :            : using namespace ::com::sun::star;
      46                 :            : using ::rtl::OUString;
      47                 :            : 
      48                 :            : /*--------------------------------------------------------------------
      49                 :            :     Beschreibung: Benutzerfelder
      50                 :            :  --------------------------------------------------------------------*/
      51                 :            : 
      52                 :          0 : SwUserField::SwUserField(SwUserFieldType* pTyp, sal_uInt16 nSub, sal_uInt32 nFmt)
      53                 :            :     : SwValueField(pTyp, nFmt),
      54                 :          0 :     nSubType(nSub)
      55                 :            : {
      56                 :          0 : }
      57                 :            : 
      58                 :          0 : String SwUserField::Expand() const
      59                 :            : {
      60                 :          0 :     String sStr;
      61         [ #  # ]:          0 :     if(!(nSubType & nsSwExtendedSubType::SUB_INVISIBLE))
      62 [ #  # ][ #  # ]:          0 :         sStr = ((SwUserFieldType*)GetTyp())->Expand(GetFormat(), nSubType, GetLanguage());
                 [ #  # ]
      63                 :            : 
      64                 :          0 :     return sStr;
      65                 :            : }
      66                 :            : 
      67                 :          0 : SwField* SwUserField::Copy() const
      68                 :            : {
      69         [ #  # ]:          0 :     SwField* pTmp = new SwUserField((SwUserFieldType*)GetTyp(), nSubType, GetFormat());
      70                 :          0 :     pTmp->SetAutomaticLanguage(IsAutomaticLanguage());
      71                 :          0 :     return pTmp;
      72                 :            : }
      73                 :            : 
      74                 :          0 : String SwUserField::GetFieldName() const
      75                 :            : {
      76                 :          0 :     String aStr(SwFieldType::GetTypeStr(TYP_USERFLD));
      77         [ #  # ]:          0 :     aStr += ' ';
      78 [ #  # ][ #  # ]:          0 :     aStr += GetTyp()->GetName();
      79         [ #  # ]:          0 :     aStr.AppendAscii(" = ");
      80 [ #  # ][ #  # ]:          0 :     aStr += static_cast<SwUserFieldType*>(GetTyp())->GetContent();
                 [ #  # ]
      81                 :          0 :     return aStr;
      82                 :            : }
      83                 :            : 
      84                 :          0 : double SwUserField::GetValue() const
      85                 :            : {
      86                 :          0 :     return ((SwUserFieldType*)GetTyp())->GetValue();
      87                 :            : }
      88                 :            : 
      89                 :          0 : void SwUserField::SetValue( const double& rVal )
      90                 :            : {
      91                 :          0 :     ((SwUserFieldType*)GetTyp())->SetValue(rVal);
      92                 :          0 : }
      93                 :            : 
      94                 :            : /*--------------------------------------------------------------------
      95                 :            :     Beschreibung: Name
      96                 :            :  --------------------------------------------------------------------*/
      97                 :            : 
      98                 :          0 : const rtl::OUString& SwUserField::GetPar1() const
      99                 :            : {
     100                 :          0 :     return ((const SwUserFieldType*)GetTyp())->GetName();
     101                 :            : }
     102                 :            : 
     103                 :            : /*--------------------------------------------------------------------
     104                 :            :     Beschreibung: Content
     105                 :            :  --------------------------------------------------------------------*/
     106                 :            : 
     107                 :          0 : rtl::OUString SwUserField::GetPar2() const
     108                 :            : {
     109         [ #  # ]:          0 :     return ((SwUserFieldType*)GetTyp())->GetContent(GetFormat());
     110                 :            : }
     111                 :            : 
     112                 :          0 : void SwUserField::SetPar2(const rtl::OUString& rStr)
     113                 :            : {
     114         [ #  # ]:          0 :     ((SwUserFieldType*)GetTyp())->SetContent(rStr, GetFormat());
     115                 :          0 : }
     116                 :            : 
     117                 :          0 : sal_uInt16 SwUserField::GetSubType() const
     118                 :            : {
     119                 :          0 :     return ((SwUserFieldType*)GetTyp())->GetType() | nSubType;
     120                 :            : }
     121                 :            : 
     122                 :          0 : void SwUserField::SetSubType(sal_uInt16 nSub)
     123                 :            : {
     124                 :          0 :     ((SwUserFieldType*)GetTyp())->SetType(nSub & 0x00ff);
     125                 :          0 :     nSubType = nSub & 0xff00;
     126                 :          0 : }
     127                 :            : 
     128                 :          0 : bool SwUserField::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const
     129                 :            : {
     130   [ #  #  #  # ]:          0 :     switch( nWhichId )
     131                 :            :     {
     132                 :            :     case FIELD_PROP_BOOL2:
     133                 :            :         {
     134                 :          0 :             sal_Bool bTmp = 0 != (nSubType & nsSwExtendedSubType::SUB_CMD);
     135         [ #  # ]:          0 :             rAny.setValue(&bTmp, ::getBooleanCppuType());
     136                 :            :         }
     137                 :          0 :         break;
     138                 :            :     case FIELD_PROP_BOOL1:
     139                 :            :         {
     140                 :          0 :             sal_Bool bTmp = 0 == (nSubType & nsSwExtendedSubType::SUB_INVISIBLE);
     141         [ #  # ]:          0 :             rAny.setValue(&bTmp, ::getBooleanCppuType());
     142                 :            :         }
     143                 :          0 :         break;
     144                 :            :     case FIELD_PROP_FORMAT:
     145         [ #  # ]:          0 :         rAny <<= (sal_Int32)GetFormat();
     146                 :          0 :         break;
     147                 :            :     default:
     148                 :          0 :         return SwField::QueryValue(rAny, nWhichId);
     149                 :            :     }
     150                 :          0 :     return true;
     151                 :            : }
     152                 :            : 
     153                 :          0 : bool SwUserField::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
     154                 :            : {
     155   [ #  #  #  # ]:          0 :     switch( nWhichId )
     156                 :            :     {
     157                 :            :     case FIELD_PROP_BOOL1:
     158         [ #  # ]:          0 :         if(*(sal_Bool*) rAny.getValue())
     159                 :          0 :             nSubType &= (~nsSwExtendedSubType::SUB_INVISIBLE);
     160                 :            :         else
     161                 :          0 :             nSubType |= nsSwExtendedSubType::SUB_INVISIBLE;
     162                 :          0 :         break;
     163                 :            :     case FIELD_PROP_BOOL2:
     164         [ #  # ]:          0 :         if(*(sal_Bool*) rAny.getValue())
     165                 :          0 :             nSubType |= nsSwExtendedSubType::SUB_CMD;
     166                 :            :         else
     167                 :          0 :             nSubType &= (~nsSwExtendedSubType::SUB_CMD);
     168                 :          0 :         break;
     169                 :            :     case FIELD_PROP_FORMAT:
     170                 :            :         {
     171                 :          0 :             sal_Int32 nTmp = 0;
     172                 :          0 :             rAny >>= nTmp;
     173                 :          0 :             SetFormat(nTmp);
     174                 :            :         }
     175                 :          0 :         break;
     176                 :            :     default:
     177                 :          0 :         return SwField::PutValue(rAny, nWhichId);
     178                 :            :     }
     179                 :          0 :     return true;
     180                 :            : }
     181                 :            : 
     182                 :            : /*--------------------------------------------------------------------
     183                 :            :     Beschreibung: Benutzerfeldtypen
     184                 :            :  --------------------------------------------------------------------*/
     185                 :            : 
     186                 :        108 : SwUserFieldType::SwUserFieldType( SwDoc* pDocPtr, const String& aNam )
     187                 :            :     : SwValueFieldType( pDocPtr, RES_USERFLD ),
     188                 :            :     nValue( 0 ),
     189         [ +  - ]:        108 :     nType(nsSwGetSetExpType::GSE_STRING)
     190                 :            : {
     191                 :        108 :     bValidValue = bDeleted = sal_False;
     192         [ +  - ]:        108 :     aName = aNam;
     193                 :            : 
     194         [ +  - ]:        108 :     if (nType & nsSwGetSetExpType::GSE_STRING)
     195                 :        108 :         EnableFormat(sal_False);    // Numberformatter nicht einsetzen
     196                 :        108 : }
     197                 :            : 
     198                 :          3 : String SwUserFieldType::Expand(sal_uInt32 nFmt, sal_uInt16 nSubType, sal_uInt16 nLng)
     199                 :            : {
     200                 :          3 :     String aStr(aContent);
     201 [ #  # ][ -  + ]:          3 :     if((nType & nsSwGetSetExpType::GSE_EXPR) && !(nSubType & nsSwExtendedSubType::SUB_CMD))
     202                 :            :     {
     203                 :          0 :         EnableFormat(sal_True);
     204 [ #  # ][ #  # ]:          0 :         aStr = ExpandValue(nValue, nFmt, nLng);
                 [ #  # ]
     205                 :            :     }
     206                 :            :     else
     207                 :          3 :         EnableFormat(sal_False);    // Numberformatter nicht einsetzen
     208                 :            : 
     209                 :          3 :     return aStr;
     210                 :            : }
     211                 :            : 
     212                 :         54 : SwFieldType* SwUserFieldType::Copy() const
     213                 :            : {
     214 [ +  - ][ +  - ]:         54 :     SwUserFieldType *pTmp = new SwUserFieldType( GetDoc(), aName );
     215                 :         54 :     pTmp->aContent      = aContent;
     216                 :         54 :     pTmp->nType         = nType;
     217                 :         54 :     pTmp->bValidValue   = bValidValue;
     218                 :         54 :     pTmp->nValue        = nValue;
     219                 :         54 :     pTmp->bDeleted      = bDeleted;
     220                 :            : 
     221                 :         54 :     return pTmp;
     222                 :            : }
     223                 :            : 
     224                 :       1206 : const rtl::OUString& SwUserFieldType::GetName() const
     225                 :            : {
     226                 :       1206 :     return aName;
     227                 :            : }
     228                 :            : 
     229                 :          3 : void SwUserFieldType::Modify( const SfxPoolItem* pOld, const SfxPoolItem* pNew )
     230                 :            : {
     231 [ +  - ][ +  - ]:          3 :     if( !pOld && !pNew )
     232                 :          3 :         ChgValid( sal_False );
     233                 :            : 
     234                 :          3 :     NotifyClients( pOld, pNew );
     235                 :            :     // und ggfs. am UserFeld haengende InputFelder updaten!
     236                 :          3 :     GetDoc()->GetSysFldType( RES_INPUTFLD )->UpdateFlds();
     237                 :          3 : }
     238                 :            : 
     239                 :          0 : double SwUserFieldType::GetValue( SwCalc& rCalc )
     240                 :            : {
     241         [ #  # ]:          0 :     if(bValidValue)
     242                 :          0 :         return nValue;
     243                 :            : 
     244         [ #  # ]:          0 :     if(!rCalc.Push( this ))
     245                 :            :     {
     246                 :          0 :         rCalc.SetCalcError( CALC_SYNTAX );
     247                 :          0 :         return 0;
     248                 :            :     }
     249         [ #  # ]:          0 :     nValue = rCalc.Calculate( aContent ).GetDouble();
     250                 :          0 :     rCalc.Pop();
     251                 :            : 
     252         [ #  # ]:          0 :     if( !rCalc.IsCalcError() )
     253                 :          0 :         bValidValue = sal_True;
     254                 :            :     else
     255                 :          0 :         nValue = 0;
     256                 :            : 
     257                 :          0 :     return nValue;
     258                 :            : }
     259                 :            : 
     260                 :          6 : String SwUserFieldType::GetContent( sal_uInt32 nFmt )
     261                 :            : {
     262 [ -  + ][ #  # ]:          6 :     if (nFmt && nFmt != SAL_MAX_UINT32)
     263                 :            :     {
     264         [ #  # ]:          0 :         String sFormattedValue;
     265                 :          0 :         Color* pCol = 0;
     266                 :            : 
     267         [ #  # ]:          0 :         SvNumberFormatter* pFormatter = GetDoc()->GetNumberFormatter();
     268                 :            : 
     269         [ #  # ]:          0 :         pFormatter->GetOutputString(GetValue(), nFmt, sFormattedValue, &pCol);
     270 [ #  # ][ #  # ]:          0 :         return sFormattedValue;
     271                 :            :     }
     272                 :            :     else
     273                 :          6 :         return aContent;
     274                 :            : }
     275                 :            : 
     276                 :         54 : void SwUserFieldType::SetContent( const String& rStr, sal_uInt32 nFmt )
     277                 :            : {
     278         [ -  + ]:         54 :     if( aContent != rStr )
     279                 :            :     {
     280                 :          0 :         aContent = rStr;
     281                 :            : 
     282 [ #  # ][ #  # ]:          0 :         if (nFmt && nFmt != SAL_MAX_UINT32)
     283                 :            :         {
     284                 :            :             double fValue;
     285                 :            : 
     286         [ #  # ]:          0 :             SvNumberFormatter* pFormatter = GetDoc()->GetNumberFormatter();
     287                 :            : 
     288 [ #  # ][ #  # ]:          0 :             if (pFormatter->IsNumberFormat(rStr, nFmt, fValue))
     289                 :            :             {
     290                 :          0 :                 SetValue(fValue);
     291         [ #  # ]:          0 :                 aContent.Erase();
     292         [ #  # ]:          0 :                 DoubleToString(aContent, fValue, nFmt);
     293                 :            :             }
     294                 :            :         }
     295                 :            : 
     296                 :          0 :         sal_Bool bModified = GetDoc()->IsModified();
     297                 :          0 :         GetDoc()->SetModified();
     298         [ #  # ]:          0 :         if( !bModified )    // Bug 57028
     299                 :            :         {
     300                 :          0 :             GetDoc()->GetIDocumentUndoRedo().SetUndoNoResetModified();
     301                 :            :         }
     302                 :            :     }
     303                 :         54 : }
     304                 :            : 
     305                 :          0 : bool SwUserFieldType::QueryValue( uno::Any& rAny, sal_uInt16 nWhichId ) const
     306                 :            : {
     307   [ #  #  #  # ]:          0 :     switch( nWhichId )
     308                 :            :     {
     309                 :            :     case FIELD_PROP_DOUBLE:
     310         [ #  # ]:          0 :         rAny <<= (double) nValue;
     311                 :          0 :         break;
     312                 :            :     case FIELD_PROP_PAR2:
     313         [ #  # ]:          0 :         rAny <<= rtl::OUString(aContent);
     314                 :          0 :         break;
     315                 :            :     case FIELD_PROP_BOOL1:
     316                 :            :         {
     317                 :          0 :             sal_Bool bExpression = 0 != (nsSwGetSetExpType::GSE_EXPR&nType);
     318         [ #  # ]:          0 :             rAny.setValue(&bExpression, ::getBooleanCppuType());
     319                 :            :         }
     320                 :          0 :         break;
     321                 :            :     default:
     322                 :            :         OSL_FAIL("illegal property");
     323                 :            :     }
     324                 :          0 :     return true;
     325                 :            : }
     326                 :            : 
     327                 :        111 : bool SwUserFieldType::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId )
     328                 :            : {
     329   [ -  +  +  - ]:        111 :     switch( nWhichId )
     330                 :            :     {
     331                 :            :     case FIELD_PROP_DOUBLE:
     332                 :            :         {
     333                 :          0 :             double fVal = 0;
     334                 :          0 :             rAny >>= fVal;
     335                 :          0 :             nValue = fVal;
     336                 :            : 
     337                 :            :             // Folgende Zeile ist eigentlich falsch, da die Sprache unbekannt ist
     338                 :            :             // (haengt am Feld) und aContent daher auch eigentlich ans Feld gehoeren
     339                 :            :             // muesste. Jedes Feld kann eine andere Sprache, aber den gleichen Inhalt
     340                 :            :             // haben, nur die Formatierung ist unterschiedlich.
     341         [ #  # ]:          0 :             DoubleToString(aContent, nValue, (sal_uInt16)LANGUAGE_SYSTEM);
     342                 :            :         }
     343                 :          0 :         break;
     344                 :            :     case FIELD_PROP_PAR2:
     345                 :         57 :         ::GetString( rAny, aContent );
     346                 :         57 :         break;
     347                 :            :     case FIELD_PROP_BOOL1:
     348         [ -  + ]:         54 :         if(*(sal_Bool*)rAny.getValue())
     349                 :            :         {
     350                 :          0 :             nType |= nsSwGetSetExpType::GSE_EXPR;
     351                 :          0 :             nType &= ~nsSwGetSetExpType::GSE_STRING;
     352                 :            :         }
     353                 :            :         else
     354                 :            :         {
     355                 :         54 :             nType &= ~nsSwGetSetExpType::GSE_EXPR;
     356                 :         54 :             nType |= nsSwGetSetExpType::GSE_STRING;
     357                 :            :         }
     358                 :         54 :         break;
     359                 :            :     default:
     360                 :            :         OSL_FAIL("illegal property");
     361                 :            :     }
     362                 :        111 :     return true;
     363                 :            : }
     364                 :            : 
     365                 :            : 
     366                 :            : 
     367                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10