LCOV - code coverage report
Current view: top level - sc/source/core/tool - cellform.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 103 121 85.1 %
Date: 2014-11-03 Functions: 6 6 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             : #include <editutil.hxx>
      33             : 
      34             : // STATIC DATA
      35             : // Err527 Workaround
      36             : const ScFormulaCell* pLastFormulaTreeTop = 0;
      37             : 
      38      108413 : void ScCellFormat::GetString( ScRefCellValue& rCell, sal_uLong nFormat, OUString& rString,
      39             :                               Color** ppColor, SvNumberFormatter& rFormatter, const ScDocument* pDoc,
      40             :                               bool bNullVals, bool bFormula, ScForceTextFmt eForceTextFmt,
      41             :                               bool bUseStarFormat )
      42             : {
      43      108413 :     *ppColor = NULL;
      44             : 
      45      108413 :     switch (rCell.meType)
      46             :     {
      47             :         case CELLTYPE_STRING:
      48       24536 :             rFormatter.GetOutputString(rCell.mpString->getString(), nFormat, rString, ppColor, bUseStarFormat);
      49       24536 :         break;
      50             :         case CELLTYPE_EDIT:
      51         170 :             rFormatter.GetOutputString(rCell.getString(pDoc), nFormat, rString, ppColor );
      52         170 :         break;
      53             :         case CELLTYPE_VALUE:
      54             :         {
      55       72690 :             double nValue = rCell.mfValue;
      56       72690 :             if (!bNullVals && nValue == 0.0)
      57           0 :                 rString = "";
      58             :             else
      59             :             {
      60       72690 :                 if( eForceTextFmt == ftCheck )
      61             :                 {
      62       15855 :                     if( nFormat && rFormatter.IsTextFormat( nFormat ) )
      63         218 :                         eForceTextFmt = ftForce;
      64             :                 }
      65       72690 :                 if( eForceTextFmt == ftForce )
      66             :                 {
      67         218 :                     OUString aTemp;
      68         218 :                     rFormatter.GetOutputString( nValue, 0, aTemp, ppColor );
      69         218 :                     rFormatter.GetOutputString( aTemp, nFormat, rString, ppColor );
      70             :                 }
      71             :                 else
      72       72472 :                     rFormatter.GetOutputString( nValue, nFormat, rString, ppColor, bUseStarFormat );
      73             :             }
      74             :         }
      75       72690 :         break;
      76             :         case CELLTYPE_FORMULA:
      77             :         {
      78        4575 :             ScFormulaCell*  pFCell = rCell.mpFormula;
      79        4575 :             if ( bFormula )
      80             :             {
      81           0 :                 pFCell->GetFormula( rString );
      82             :             }
      83             :             else
      84             :             {
      85             :                 // A macro started from the interpreter, which has
      86             :                 // access to Formular Cells, becomes a CellText, even if
      87             :                 // that triggers further interpretation, except if those
      88             :                 // cells are already being interpreted.
      89             :                 // IdleCalc generally doesn't trigger further interpretation,
      90             :                 // as not to get Err522 (circular).
      91        4575 :                 if ( pFCell->GetDocument()->IsInInterpreter() &&
      92           0 :                         (!pFCell->GetDocument()->GetMacroInterpretLevel()
      93           0 :                         || pFCell->IsRunning()) )
      94             :                 {
      95           0 :                     rString = "...";
      96             :                 }
      97             :                 else
      98             :                 {
      99        4575 :                     sal_uInt16 nErrCode = pFCell->GetErrCode();
     100             : 
     101        4575 :                     if (nErrCode != 0)
     102         314 :                         rString = ScGlobal::GetErrorString(nErrCode);
     103        4261 :                     else if ( pFCell->IsEmptyDisplayedAsString() )
     104           6 :                         rString = "";
     105        4255 :                     else if ( pFCell->IsValue() )
     106             :                     {
     107        3612 :                         double fValue = pFCell->GetValue();
     108        3612 :                         if ( !bNullVals && fValue == 0.0 )
     109           0 :                             rString = "";
     110        3612 :                         else if ( pFCell->IsHybridValueCell() )
     111           0 :                             rString = pFCell->GetString().getString();
     112             :                         else
     113        3612 :                             rFormatter.GetOutputString( fValue, nFormat, rString, ppColor, bUseStarFormat );
     114             :                     }
     115             :                     else
     116             :                     {
     117             :                         rFormatter.GetOutputString( pFCell->GetString().getString(),
     118         643 :                                                     nFormat, rString, ppColor, bUseStarFormat );
     119             :                     }
     120             :                 }
     121             :             }
     122             :         }
     123        4575 :         break;
     124             :         default:
     125        6442 :             rString = "";
     126        6442 :             break;
     127             :     }
     128      108413 : }
     129             : 
     130        8701 : OUString ScCellFormat::GetString(
     131             :     ScDocument& rDoc, const ScAddress& rPos, sal_uLong nFormat, Color** ppColor,
     132             :     SvNumberFormatter& rFormatter, bool bNullVals, bool bFormula, ScForceTextFmt eForceTextFmt,
     133             :     bool bUseStarFormat )
     134             : {
     135        8701 :     OUString aString;
     136        8701 :     *ppColor = NULL;
     137             : 
     138        8701 :     CellType eType = rDoc.GetCellType(rPos);
     139        8701 :     switch (eType)
     140             :     {
     141             :         case CELLTYPE_STRING:
     142             :         {
     143        3194 :             ScRefCellValue aCell;
     144        3194 :             aCell.assign(rDoc, rPos);
     145        3194 :             rFormatter.GetOutputString(aCell.mpString->getString(), nFormat, aString, ppColor, bUseStarFormat);
     146             :         }
     147        3194 :         break;
     148             :         case CELLTYPE_EDIT:
     149             :         {
     150         180 :             ScRefCellValue aCell;
     151         180 :             aCell.assign(rDoc, rPos);
     152         180 :             rFormatter.GetOutputString(aCell.getString(&rDoc), nFormat, aString, ppColor);
     153             :         }
     154         180 :         break;
     155             :         case CELLTYPE_VALUE:
     156             :         {
     157        4835 :             double nValue = rDoc.GetValue(rPos);
     158        4835 :             if (!bNullVals && nValue == 0.0) aString = "";
     159             :             else
     160             :             {
     161        4835 :                 if (eForceTextFmt == ftCheck)
     162             :                 {
     163           0 :                     if (nFormat && rFormatter.IsTextFormat(nFormat)) eForceTextFmt = ftForce;
     164             :                 }
     165        4835 :                 if (eForceTextFmt == ftForce)
     166             :                 {
     167           0 :                     OUString aTemp;
     168           0 :                     rFormatter.GetOutputString(nValue, 0, aTemp, ppColor);
     169           0 :                     rFormatter.GetOutputString(aTemp, nFormat, aString, ppColor);
     170             :                 }
     171        4835 :                 else rFormatter.GetOutputString(nValue, nFormat, aString, ppColor, bUseStarFormat);
     172             :             }
     173             :         }
     174        4835 :         break;
     175             :         case CELLTYPE_FORMULA:
     176             :         {
     177         492 :             ScFormulaCell* pFCell = rDoc.GetFormulaCell(rPos);
     178         492 :             if (!pFCell)
     179           0 :                 return aString;
     180         492 :             if (bFormula)
     181             :             {
     182           0 :                 pFCell->GetFormula(aString);
     183             :             }
     184             :             else
     185             :             {
     186             :                 // A macro started from the interpreter, which has
     187             :                 // access to Formular Cells, becomes a CellText, even if
     188             :                 // that triggers further interpretation, except if those
     189             :                 // cells are already being interpreted.
     190             :                 // IdleCalc generally doesn't trigger further interpretation,
     191             :                 // as not to get Err522 (circular).
     192         492 :                 if (pFCell->GetDocument()->IsInInterpreter() &&
     193           0 :                     (!pFCell->GetDocument()->GetMacroInterpretLevel()
     194           0 :                      || pFCell->IsRunning()))
     195             :                 {
     196           0 :                     aString = "...";
     197             :                 }
     198             :                 else
     199             :                 {
     200         492 :                     sal_uInt16 nErrCode = pFCell->GetErrCode();
     201             : 
     202         492 :                     if (nErrCode != 0) aString = ScGlobal::GetErrorString(nErrCode);
     203         488 :                     else if (pFCell->IsEmptyDisplayedAsString()) aString = "";
     204         488 :                     else if (pFCell->IsValue())
     205             :                     {
     206         449 :                         double fValue = pFCell->GetValue();
     207         449 :                         if (!bNullVals && fValue == 0.0) aString = "";
     208         449 :                         else if (pFCell->IsHybridValueCell()) aString = pFCell->GetString().getString();
     209         449 :                         else rFormatter.GetOutputString(fValue, nFormat, aString, ppColor, bUseStarFormat);
     210             :                     }
     211             :                     else
     212             :                     {
     213             :                         rFormatter.GetOutputString(pFCell->GetString().getString(),
     214          39 :                                                    nFormat, aString, ppColor, bUseStarFormat);
     215             :                     }
     216             :                 }
     217             :             }
     218             :         }
     219         492 :         break;
     220             :         default:
     221             :             ;
     222             :     }
     223        8701 :     return aString;
     224             : }
     225             : 
     226        6717 : void ScCellFormat::GetInputString(
     227             :     ScRefCellValue& rCell, sal_uLong nFormat, OUString& rString, SvNumberFormatter& rFormatter, const ScDocument* pDoc )
     228             : {
     229        6717 :     OUString aString = rString;
     230        6717 :     switch (rCell.meType)
     231             :     {
     232             :         case CELLTYPE_STRING:
     233             :         case CELLTYPE_EDIT:
     234        2756 :             aString = rCell.getString(pDoc);
     235        2756 :         break;
     236             :         case CELLTYPE_VALUE:
     237         528 :             rFormatter.GetInputLineString(rCell.mfValue, nFormat, aString );
     238         528 :         break;
     239             :         case CELLTYPE_FORMULA:
     240             :         {
     241          44 :             ScFormulaCell* pFC = rCell.mpFormula;
     242          44 :             if (pFC->IsEmptyDisplayedAsString())
     243           0 :                 aString = EMPTY_OUSTRING;
     244          44 :             else if (pFC->IsValue())
     245           8 :                 rFormatter.GetInputLineString(pFC->GetValue(), nFormat, aString);
     246             :             else
     247          36 :                 aString = pFC->GetString().getString();
     248             : 
     249          44 :             sal_uInt16 nErrCode = pFC->GetErrCode();
     250          44 :             if (nErrCode != 0)
     251           0 :                 aString = EMPTY_OUSTRING;
     252             :         }
     253          44 :         break;
     254             :         default:
     255        3389 :             aString = EMPTY_OUSTRING;
     256        3389 :             break;
     257             :     }
     258        6717 :     rString = aString;
     259        6717 : }
     260             : 
     261        1334 : OUString ScCellFormat::GetOutputString( ScDocument& rDoc, const ScAddress& rPos, ScRefCellValue& rCell )
     262             : {
     263        1334 :     if (rCell.isEmpty())
     264          94 :         return EMPTY_OUSTRING;
     265             : 
     266        1240 :     OUString aVal;
     267             : 
     268        1240 :     if (rCell.meType == CELLTYPE_EDIT)
     269             :     {
     270             :         //  GetString an der EditCell macht Leerzeichen aus Umbruechen,
     271             :         //  hier werden die Umbrueche aber gebraucht
     272           2 :         const EditTextObject* pData = rCell.mpEditText;
     273           2 :         if (pData)
     274             :         {
     275           2 :             ScFieldEditEngine& rEngine = rDoc.GetEditEngine();
     276           2 :             rEngine.SetText(*pData);
     277           2 :             aVal = rEngine.GetText(LINEEND_LF);
     278             :         }
     279             :         //  Edit-Zellen auch nicht per NumberFormatter formatieren
     280             :         //  (passend zur Ausgabe)
     281             :     }
     282             :     else
     283             :     {
     284             :         //  wie in GetString am Dokument (column)
     285             :         Color* pColor;
     286        1238 :         sal_uLong nNumFmt = rDoc.GetNumberFormat(rPos);
     287        1238 :         aVal = GetString(rDoc, rPos, nNumFmt, &pColor, *rDoc.GetFormatTable());
     288             :     }
     289        1240 :     return aVal;
     290         228 : }
     291             : 
     292             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10