LCOV - code coverage report
Current view: top level - libreoffice/sc/source/core/tool - cellform.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 61 76 80.3 %
Date: 2012-12-27 Functions: 2 2 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 <sfx2/objsh.hxx>
      21             : #include <svl/smplhint.hxx>
      22             : #include <svl/zforlist.hxx>
      23             : 
      24             : #include "cellform.hxx"
      25             : #include "cell.hxx"
      26             : #include "document.hxx"
      27             : #include "formula/errorcodes.hxx"
      28             : #include "sc.hrc"
      29             : 
      30             : // STATIC DATA -----------------------------------------------------------
      31             : 
      32             : // Err527 Workaround
      33             : const ScFormulaCell* pLastFormulaTreeTop = 0;
      34             : 
      35             : // -----------------------------------------------------------------------
      36             : 
      37        8046 : void ScCellFormat::GetString( ScBaseCell* pCell, sal_uLong nFormat, rtl::OUString& rString,
      38             :                               Color** ppColor, SvNumberFormatter& rFormatter,
      39             :                               sal_Bool bNullVals,
      40             :                               sal_Bool bFormula,
      41             :                               ScForceTextFmt eForceTextFmt,
      42             :                               bool bUseStarFormat )
      43             : {
      44        8046 :     *ppColor = NULL;
      45        8046 :     if (&rFormatter==NULL)
      46             :     {
      47           0 :         rString = rtl::OUString();
      48        8046 :         return;
      49             :     }
      50             : 
      51        8046 :     CellType eType = pCell->GetCellType();
      52        8046 :     switch(eType)
      53             :     {
      54             :         case CELLTYPE_STRING:
      55             :             {
      56        3275 :                 rtl::OUString aCellString = ((ScStringCell*)pCell)->GetString();
      57        3275 :                 rFormatter.GetOutputString( aCellString, nFormat, rString, ppColor, bUseStarFormat );
      58             :             }
      59        3275 :             break;
      60             :         case CELLTYPE_EDIT:
      61             :             {
      62          51 :                 rtl::OUString aCellString = ((ScEditCell*)pCell)->GetString();
      63          51 :                 rFormatter.GetOutputString( aCellString, nFormat, rString, ppColor );
      64             :             }
      65          51 :             break;
      66             :         case CELLTYPE_VALUE:
      67             :             {
      68        4185 :                 double nValue = ((ScValueCell*)pCell)->GetValue();
      69        4185 :                 if ( !bNullVals && nValue == 0.0 )
      70           0 :                     rString = rtl::OUString();
      71             :                 else
      72             :                 {
      73        4185 :                     if( eForceTextFmt == ftCheck )
      74             :                     {
      75        1470 :                         if( nFormat && rFormatter.IsTextFormat( nFormat ) )
      76         109 :                             eForceTextFmt = ftForce;
      77             :                     }
      78        4185 :                     if( eForceTextFmt == ftForce )
      79             :                     {
      80         109 :                         rtl::OUString aTemp;
      81         109 :                         rFormatter.GetOutputString( nValue, 0, aTemp, ppColor );
      82         109 :                         rFormatter.GetOutputString( aTemp, nFormat, rString, ppColor );
      83             :                     }
      84             :                     else
      85        4076 :                         rFormatter.GetOutputString( nValue, nFormat, rString, ppColor, bUseStarFormat );
      86             :                 }
      87             :             }
      88        4185 :             break;
      89             :         case CELLTYPE_FORMULA:
      90             :             {
      91         534 :                 ScFormulaCell*  pFCell = (ScFormulaCell*)pCell;
      92         534 :                 if ( bFormula )
      93             :                 {
      94           0 :                     pFCell->GetFormula( rString );
      95             :                 }
      96             :                 else
      97             :                 {
      98             :                     // A macro started from the interpreter, which has
      99             :                     // access to Formular Cells, becomes a CellText, even if
     100             :                     // that triggers further interpretation, except if those
     101             :                     // cells are already being interpreted.
     102             :                     // IdleCalc generally doesn't trigger futher interpretation,
     103             :                     // as not to get Err522 (circular).
     104         534 :                     if ( pFCell->GetDocument()->IsInInterpreter() &&
     105           0 :                             (!pFCell->GetDocument()->GetMacroInterpretLevel()
     106           0 :                             || pFCell->IsRunning()) )
     107             :                     {
     108           0 :                         rString = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("..."));
     109             :                     }
     110             :                     else
     111             :                     {
     112         534 :                         sal_uInt16 nErrCode = pFCell->GetErrCode();
     113             : 
     114             :                         // get the number format only after interpretation (GetErrCode):
     115         534 :                         if ( (nFormat % SV_COUNTRY_LANGUAGE_OFFSET) == 0 )
     116             :                             nFormat = pFCell->GetStandardFormat( rFormatter,
     117         364 :                                 nFormat );
     118             : 
     119         534 :                         if (nErrCode != 0)
     120          32 :                             rString = ScGlobal::GetErrorString(nErrCode);
     121         502 :                         else if ( pFCell->IsEmptyDisplayedAsString() )
     122           0 :                             rString = rtl::OUString();
     123         502 :                         else if ( pFCell->IsValue() )
     124             :                         {
     125         426 :                             double fValue = pFCell->GetValue();
     126         426 :                             if ( !bNullVals && fValue == 0.0 )
     127           0 :                                 rString = rtl::OUString();
     128             :                             else
     129         426 :                                 rFormatter.GetOutputString( fValue, nFormat, rString, ppColor, bUseStarFormat );
     130             :                         }
     131             :                         else
     132             :                         {
     133          76 :                             rtl::OUString aCellString = pFCell->GetString();
     134          76 :                             rFormatter.GetOutputString( aCellString, nFormat, rString, ppColor, bUseStarFormat );
     135             :                         }
     136             :                     }
     137             :                 }
     138             :             }
     139         534 :             break;
     140             :         default:
     141           1 :             rString = rtl::OUString();
     142           1 :             break;
     143             :     }
     144             : }
     145             : 
     146         239 : void ScCellFormat::GetInputString( ScBaseCell* pCell, sal_uLong nFormat, rtl::OUString& rString,
     147             :                                       SvNumberFormatter& rFormatter )
     148             : {
     149         239 :     if (&rFormatter==NULL)
     150             :     {
     151           0 :         rString = rtl::OUString();
     152         239 :         return;
     153             :     }
     154             : 
     155         239 :     String aString = rString;
     156         239 :     CellType eType = pCell->GetCellType();
     157         239 :     switch(eType)
     158             :     {
     159             :         case CELLTYPE_STRING:
     160             :             {
     161         207 :                 aString = ((ScStringCell*)pCell)->GetString();
     162             :             }
     163         207 :             break;
     164             :         case CELLTYPE_EDIT:
     165             :             {
     166           0 :                 aString = ((ScEditCell*)pCell)->GetString();
     167             :             }
     168           0 :             break;
     169             :         case CELLTYPE_VALUE:
     170             :             {
     171          20 :                 double nValue = ((ScValueCell*)pCell)->GetValue();
     172          20 :                 rFormatter.GetInputLineString( nValue, nFormat, aString );
     173             :             }
     174          20 :             break;
     175             :         case CELLTYPE_FORMULA:
     176             :             {
     177          12 :                 if (((ScFormulaCell*)pCell)->IsEmptyDisplayedAsString())
     178             :                 {
     179           0 :                     aString.Erase();
     180             :                 }
     181          12 :                 else if (((ScFormulaCell*)pCell)->IsValue())
     182             :                 {
     183           5 :                     double nValue = ((ScFormulaCell*)pCell)->GetValue();
     184           5 :                     rFormatter.GetInputLineString( nValue, nFormat, aString );
     185             :                 }
     186             :                 else
     187             :                 {
     188           7 :                     aString = ((ScFormulaCell*)pCell)->GetString();
     189             :                 }
     190             : 
     191          12 :                 sal_uInt16 nErrCode = ((ScFormulaCell*)pCell)->GetErrCode();
     192          12 :                 if (nErrCode != 0)
     193             :                 {
     194           0 :                     aString.Erase();
     195             :                 }
     196             :             }
     197          12 :             break;
     198             :         default:
     199           0 :             aString.Erase();
     200           0 :             break;
     201             :     }
     202         239 :     rString = aString;
     203             : }
     204             : 
     205             : 
     206             : 
     207             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10