LCOV - code coverage report
Current view: top level - sc/source/core/tool - cellform.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 91 111 82.0 %
Date: 2014-04-11 Functions: 3 3 100.0 %
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 "cellform.hxx"
      21             : 
      22             : #include <sfx2/objsh.hxx>
      23             : #include <svl/smplhint.hxx>
      24             : #include <svl/zforlist.hxx>
      25             : #include "svl/sharedstring.hxx"
      26             : 
      27             : #include "formulacell.hxx"
      28             : #include "document.hxx"
      29             : #include "cellvalue.hxx"
      30             : #include "formula/errorcodes.hxx"
      31             : #include "sc.hrc"
      32             : 
      33             : // STATIC DATA
      34             : // Err527 Workaround
      35             : const ScFormulaCell* pLastFormulaTreeTop = 0;
      36             : 
      37       54584 : void ScCellFormat::GetString( ScRefCellValue& rCell, sal_uLong nFormat, OUString& rString,
      38             :                               Color** ppColor, SvNumberFormatter& rFormatter, const ScDocument* pDoc,
      39             :                               bool bNullVals, bool bFormula, ScForceTextFmt eForceTextFmt,
      40             :                               bool bUseStarFormat )
      41             : {
      42       54584 :     *ppColor = NULL;
      43       54584 :     if (&rFormatter==NULL)
      44             :     {
      45           0 :         rString = EMPTY_OUSTRING;
      46       54584 :         return;
      47             :     }
      48             : 
      49       54584 :     switch (rCell.meType)
      50             :     {
      51             :         case CELLTYPE_STRING:
      52       13112 :             rFormatter.GetOutputString(rCell.mpString->getString(), nFormat, rString, ppColor, bUseStarFormat);
      53       13112 :         break;
      54             :         case CELLTYPE_EDIT:
      55         148 :             rFormatter.GetOutputString(rCell.getString(pDoc), nFormat, rString, ppColor );
      56         148 :         break;
      57             :         case CELLTYPE_VALUE:
      58             :         {
      59       36684 :             double nValue = rCell.mfValue;
      60       36684 :             if (!bNullVals && nValue == 0.0)
      61           0 :                 rString = "";
      62             :             else
      63             :             {
      64       36684 :                 if( eForceTextFmt == ftCheck )
      65             :                 {
      66        9398 :                     if( nFormat && rFormatter.IsTextFormat( nFormat ) )
      67         109 :                         eForceTextFmt = ftForce;
      68             :                 }
      69       36684 :                 if( eForceTextFmt == ftForce )
      70             :                 {
      71         109 :                     OUString aTemp;
      72         109 :                     rFormatter.GetOutputString( nValue, 0, aTemp, ppColor );
      73         109 :                     rFormatter.GetOutputString( aTemp, nFormat, rString, ppColor );
      74             :                 }
      75             :                 else
      76       36575 :                     rFormatter.GetOutputString( nValue, nFormat, rString, ppColor, bUseStarFormat );
      77             :             }
      78             :         }
      79       36684 :         break;
      80             :         case CELLTYPE_FORMULA:
      81             :         {
      82        1388 :             ScFormulaCell*  pFCell = rCell.mpFormula;
      83        1388 :             if ( bFormula )
      84             :             {
      85           0 :                 pFCell->GetFormula( rString );
      86             :             }
      87             :             else
      88             :             {
      89             :                 // A macro started from the interpreter, which has
      90             :                 // access to Formular Cells, becomes a CellText, even if
      91             :                 // that triggers further interpretation, except if those
      92             :                 // cells are already being interpreted.
      93             :                 // IdleCalc generally doesn't trigger futher interpretation,
      94             :                 // as not to get Err522 (circular).
      95        1388 :                 if ( pFCell->GetDocument()->IsInInterpreter() &&
      96           0 :                         (!pFCell->GetDocument()->GetMacroInterpretLevel()
      97           0 :                         || pFCell->IsRunning()) )
      98             :                 {
      99           0 :                     rString = "...";
     100             :                 }
     101             :                 else
     102             :                 {
     103        1388 :                     sal_uInt16 nErrCode = pFCell->GetErrCode();
     104             : 
     105        1388 :                     if (nErrCode != 0)
     106         139 :                         rString = ScGlobal::GetErrorString(nErrCode);
     107        1249 :                     else if ( pFCell->IsEmptyDisplayedAsString() )
     108           3 :                         rString = "";
     109        1246 :                     else if ( pFCell->IsValue() )
     110             :                     {
     111         982 :                         double fValue = pFCell->GetValue();
     112         982 :                         if ( !bNullVals && fValue == 0.0 )
     113           0 :                             rString = "";
     114         982 :                         else if ( pFCell->IsHybridValueCell() )
     115           0 :                             rString = pFCell->GetString().getString();
     116             :                         else
     117         982 :                             rFormatter.GetOutputString( fValue, nFormat, rString, ppColor, bUseStarFormat );
     118             :                     }
     119             :                     else
     120             :                     {
     121             :                         rFormatter.GetOutputString( pFCell->GetString().getString(),
     122         264 :                                                     nFormat, rString, ppColor, bUseStarFormat );
     123             :                     }
     124             :                 }
     125             :             }
     126             :         }
     127        1388 :         break;
     128             :         default:
     129        3252 :             rString = "";
     130        3252 :             break;
     131             :     }
     132             : }
     133             : 
     134        3989 : OUString ScCellFormat::GetString(
     135             :     ScDocument& rDoc, const ScAddress& rPos, sal_uLong nFormat, Color** ppColor,
     136             :     SvNumberFormatter& rFormatter, bool bNullVals, bool bFormula, ScForceTextFmt eForceTextFmt,
     137             :     bool bUseStarFormat )
     138             : {
     139        3989 :     OUString aString;
     140        3989 :     *ppColor = NULL;
     141             : 
     142        3989 :     CellType eType = rDoc.GetCellType(rPos);
     143        3989 :     switch (eType)
     144             :     {
     145             :         case CELLTYPE_STRING:
     146             :         {
     147        1611 :             ScRefCellValue aCell;
     148        1611 :             aCell.assign(rDoc, rPos);
     149        1611 :             rFormatter.GetOutputString(aCell.mpString->getString(), nFormat, aString, ppColor, bUseStarFormat);
     150             :         }
     151        1611 :         break;
     152             :         case CELLTYPE_EDIT:
     153             :         {
     154          90 :             ScRefCellValue aCell;
     155          90 :             aCell.assign(rDoc, rPos);
     156          90 :             rFormatter.GetOutputString(aCell.getString(&rDoc), nFormat, aString, ppColor);
     157             :         }
     158          90 :         break;
     159             :         case CELLTYPE_VALUE:
     160             :         {
     161        2182 :             double nValue = rDoc.GetValue(rPos);
     162        2182 :             if (!bNullVals && nValue == 0.0) aString = "";
     163             :             else
     164             :             {
     165        2182 :                 if (eForceTextFmt == ftCheck)
     166             :                 {
     167           0 :                     if (nFormat && rFormatter.IsTextFormat(nFormat)) eForceTextFmt = ftForce;
     168             :                 }
     169        2182 :                 if (eForceTextFmt == ftForce)
     170             :                 {
     171           0 :                     OUString aTemp;
     172           0 :                     rFormatter.GetOutputString(nValue, 0, aTemp, ppColor);
     173           0 :                     rFormatter.GetOutputString(aTemp, nFormat, aString, ppColor);
     174             :                 }
     175        2182 :                 else rFormatter.GetOutputString(nValue, nFormat, aString, ppColor, bUseStarFormat);
     176             :             }
     177             :         }
     178        2182 :         break;
     179             :         case CELLTYPE_FORMULA:
     180             :         {
     181         106 :             ScFormulaCell* pFCell = rDoc.GetFormulaCell(rPos);
     182         106 :             if (!pFCell)
     183           0 :                 return aString;
     184         106 :             if (bFormula)
     185             :             {
     186           0 :                 pFCell->GetFormula(aString);
     187             :             }
     188             :             else
     189             :             {
     190             :                 // A macro started from the interpreter, which has
     191             :                 // access to Formular Cells, becomes a CellText, even if
     192             :                 // that triggers further interpretation, except if those
     193             :                 // cells are already being interpreted.
     194             :                 // IdleCalc generally doesn't trigger futher interpretation,
     195             :                 // as not to get Err522 (circular).
     196         106 :                 if (pFCell->GetDocument()->IsInInterpreter() &&
     197           0 :                     (!pFCell->GetDocument()->GetMacroInterpretLevel()
     198           0 :                      || pFCell->IsRunning()))
     199             :                 {
     200           0 :                     aString = "...";
     201             :                 }
     202             :                 else
     203             :                 {
     204         106 :                     sal_uInt16 nErrCode = pFCell->GetErrCode();
     205             : 
     206         106 :                     if (nErrCode != 0) aString = ScGlobal::GetErrorString(nErrCode);
     207         105 :                     else if (pFCell->IsEmptyDisplayedAsString()) aString = "";
     208         105 :                     else if (pFCell->IsValue())
     209             :                     {
     210          89 :                         double fValue = pFCell->GetValue();
     211          89 :                         if (!bNullVals && fValue == 0.0) aString = "";
     212          89 :                         else if (pFCell->IsHybridValueCell()) aString = pFCell->GetString().getString();
     213          89 :                         else rFormatter.GetOutputString(fValue, nFormat, aString, ppColor, bUseStarFormat);
     214             :                     }
     215             :                     else
     216             :                     {
     217             :                         rFormatter.GetOutputString(pFCell->GetString().getString(),
     218          16 :                                                    nFormat, aString, ppColor, bUseStarFormat);
     219             :                     }
     220             :                 }
     221             :             }
     222             :         }
     223         106 :         break;
     224             :         default:
     225             :             ;
     226             :     }
     227        3989 :     return aString;
     228             : }
     229             : 
     230        3794 : void ScCellFormat::GetInputString(
     231             :     ScRefCellValue& rCell, sal_uLong nFormat, OUString& rString, SvNumberFormatter& rFormatter, const ScDocument* pDoc )
     232             : {
     233        3794 :     if (&rFormatter == NULL)
     234             :     {
     235           0 :         rString = EMPTY_OUSTRING;
     236        3794 :         return;
     237             :     }
     238             : 
     239        3794 :     OUString aString = rString;
     240        3794 :     switch (rCell.meType)
     241             :     {
     242             :         case CELLTYPE_STRING:
     243             :         case CELLTYPE_EDIT:
     244        1384 :             aString = rCell.getString(pDoc);
     245        1384 :         break;
     246             :         case CELLTYPE_VALUE:
     247         276 :             rFormatter.GetInputLineString(rCell.mfValue, nFormat, aString );
     248         276 :         break;
     249             :         case CELLTYPE_FORMULA:
     250             :         {
     251          25 :             ScFormulaCell* pFC = rCell.mpFormula;
     252          25 :             if (pFC->IsEmptyDisplayedAsString())
     253           0 :                 aString = EMPTY_OUSTRING;
     254          25 :             else if (pFC->IsValue())
     255           5 :                 rFormatter.GetInputLineString(pFC->GetValue(), nFormat, aString);
     256             :             else
     257          20 :                 aString = pFC->GetString().getString();
     258             : 
     259          25 :             sal_uInt16 nErrCode = pFC->GetErrCode();
     260          25 :             if (nErrCode != 0)
     261           0 :                 aString = EMPTY_OUSTRING;
     262             :         }
     263          25 :         break;
     264             :         default:
     265        2109 :             aString = EMPTY_OUSTRING;
     266        2109 :             break;
     267             :     }
     268        3794 :     rString = aString;
     269             : }
     270             : 
     271             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10