LCOV - code coverage report
Current view: top level - sc/source/filter/qpro - qpro.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 69 109 63.3 %
Date: 2014-04-11 Functions: 7 7 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             : 
      21             : #include <sal/config.h>
      22             : #include <stdio.h>
      23             : #include <sfx2/docfile.hxx>
      24             : 
      25             : #include "qproform.hxx"
      26             : #include "qpro.hxx"
      27             : #include "qprostyle.hxx"
      28             : 
      29             : #include "global.hxx"
      30             : #include "scerrors.hxx"
      31             : #include "docpool.hxx"
      32             : #include "patattr.hxx"
      33             : #include "filter.hxx"
      34             : #include "document.hxx"
      35             : #include "formulacell.hxx"
      36             : #include "biff.hxx"
      37             : #include <tools/stream.hxx>
      38             : #include <boost/scoped_array.hpp>
      39             : 
      40           1 : FltError ScQProReader::readSheet( SCTAB nTab, ScDocument* pDoc, ScQProStyle *pStyle )
      41             : {
      42           1 :     FltError eRet = eERR_OK;
      43             :     sal_uInt8  nCol, nDummy;
      44             :     sal_uInt16 nRow;
      45             :     sal_uInt16 nStyle;
      46           1 :     bool bEndOfSheet = false;
      47             : 
      48             : #if OSL_DEBUG_LEVEL > 1
      49             :     fprintf( stderr, "Read sheet (%d)\n", nTab );
      50             : #endif
      51             : 
      52           3 :     while( eERR_OK == eRet && !bEndOfSheet && nextRecord() )
      53             :     {
      54           1 :         switch( getId() )
      55             :         {
      56             :             case 0x000f:{ // Label cell
      57           0 :                 OUString aLabel;
      58           0 :                 mpStream->ReadUChar( nCol ).ReadUChar( nDummy ).ReadUInt16( nRow ).ReadUInt16( nStyle ).ReadUChar( nDummy );
      59           0 :                 sal_uInt16 nLen = getLength();
      60           0 :                 if (nLen >= 7)
      61             :                 {
      62           0 :                     readString( aLabel, nLen - 7 );
      63           0 :                     nStyle = nStyle >> 3;
      64           0 :                     pStyle->SetFormat( pDoc, nCol, nRow, nTab, nStyle );
      65           0 :                     pDoc->EnsureTable(nTab);
      66           0 :                     pDoc->SetTextCell(ScAddress(nCol,nRow,nTab), aLabel);
      67             :                 }
      68             :                 else
      69           0 :                     eRet = eERR_FORMAT;
      70             :                 }
      71           0 :                 break;
      72             : 
      73             :             case 0x00cb: // End of sheet
      74           0 :                 bEndOfSheet = true;
      75           0 :                 break;
      76             : 
      77             :             case 0x000c: // Blank cell
      78           0 :                 mpStream->ReadUChar( nCol ).ReadUChar( nDummy ).ReadUInt16( nRow ).ReadUInt16( nStyle );
      79           0 :                 nStyle = nStyle >> 3;
      80           0 :                 pStyle->SetFormat( pDoc, nCol, nRow, nTab, nStyle );
      81           0 :                 break;
      82             : 
      83             :             case 0x000d:{ // Integer cell
      84             :                 sal_Int16 nValue;
      85           0 :                 mpStream->ReadUChar( nCol ).ReadUChar( nDummy ).ReadUInt16( nRow ).ReadUInt16( nStyle ).ReadInt16( nValue );
      86           0 :                 nStyle = nStyle >> 3;
      87           0 :                 pStyle->SetFormat( pDoc, nCol, nRow, nTab, nStyle );
      88           0 :                 pDoc->EnsureTable(nTab);
      89           0 :                 pDoc->SetValue(ScAddress(nCol,nRow,nTab), static_cast<double>(nValue));
      90             :                 }
      91           0 :                 break;
      92             : 
      93             :             case 0x000e:{ // Floating point cell
      94             :                 double nValue;
      95           0 :                 mpStream->ReadUChar( nCol ).ReadUChar( nDummy ).ReadUInt16( nRow ).ReadUInt16( nStyle ).ReadDouble( nValue );
      96           0 :                 nStyle = nStyle >> 3;
      97           0 :                 pStyle->SetFormat( pDoc, nCol, nRow, nTab, nStyle );
      98           0 :                 pDoc->EnsureTable(nTab);
      99           0 :                 pDoc->SetValue(ScAddress(nCol,nRow,nTab), nValue);
     100             :                 }
     101           0 :                 break;
     102             : 
     103             :             case 0x0010:{ // Formula cell
     104             :                 double nValue;
     105             :                 sal_uInt16 nState, nLen;
     106           1 :                 mpStream->ReadUChar( nCol ).ReadUChar( nDummy ).ReadUInt16( nRow ).ReadUInt16( nStyle ).ReadDouble( nValue ).ReadUInt16( nState ).ReadUInt16( nLen );
     107           1 :                 ScAddress aAddr( nCol, nRow, nTab );
     108             :                 const ScTokenArray *pArray;
     109           1 :                 QProToSc aConv( *mpStream, aAddr );
     110           1 :                 if (ConvOK != aConv.Convert( pArray, nLen ))
     111           1 :                     eRet = eERR_FORMAT;
     112             :                 else
     113             :                 {
     114           0 :                     ScFormulaCell* pFormula = new ScFormulaCell(pDoc, aAddr, *pArray);
     115           0 :                     nStyle = nStyle >> 3;
     116           0 :                     pFormula->AddRecalcMode( RECALCMODE_ONLOAD_ONCE );
     117           0 :                     pStyle->SetFormat( pDoc, nCol, nRow, nTab, nStyle );
     118           0 :                     pDoc->EnsureTable(nTab);
     119           0 :                     pDoc->SetFormulaCell(ScAddress(nCol,nRow,nTab), pFormula);
     120           1 :                 }
     121             :                 }
     122           1 :                 break;
     123             :         }
     124             :     }
     125           1 :     return eRet;
     126             : }
     127             : 
     128           3 : FltError ScFormatFilterPluginImpl::ScImportQuattroPro( SfxMedium &rMedium, ScDocument *pDoc )
     129             : {
     130           3 :     ScQProReader aReader( rMedium );
     131           3 :     FltError eRet = aReader.import( pDoc );
     132           3 :     return eRet;
     133             : }
     134             : 
     135           3 : ScQProReader::ScQProReader( SfxMedium &rMedium ):
     136           3 :     ScBiffReader( rMedium )
     137             : {
     138           3 : }
     139             : 
     140           3 : FltError ScQProReader::import( ScDocument *pDoc )
     141             : {
     142           3 :     FltError eRet = eERR_OK;
     143             :     sal_uInt16 nVersion;
     144           3 :     sal_uInt16 i = 1, j = 1;
     145           3 :     SCTAB nTab = 0;
     146           3 :     SetEof( false );
     147             : 
     148           3 :     if( !recordsLeft() )
     149           0 :         return eERR_OPEN;
     150             : 
     151           3 :     ScQProStyle *pStyleElement = new ScQProStyle;
     152             : 
     153       10012 :     while( nextRecord() && eRet == eERR_OK)
     154             :     {
     155       10006 :         switch( getId() )
     156             :         {
     157             :             case 0x0000: // Begginning of file
     158           5 :                 mpStream->ReadUInt16( nVersion );
     159           5 :                 break;
     160             : 
     161             :             case 0x00ca: // Beginning of sheet
     162           1 :                 if( nTab <= MAXTAB )
     163             :                 {
     164           1 :                     if( nTab < 26 )
     165             :                     {
     166           1 :                         OUString aName;
     167           1 :                         aName += OUString( sal_Unicode( 'A' + nTab ) );
     168           1 :                         if (!nTab)
     169           1 :                             pDoc->RenameTab( nTab, aName, false, false);
     170             :                         else
     171           0 :                             pDoc->InsertTab( nTab, aName );
     172             :                     }
     173           1 :                     eRet = readSheet( nTab, pDoc, pStyleElement );
     174           1 :                     nTab++;
     175             :                 }
     176           1 :                 break;
     177             : 
     178             :             case 0x0001: // End of file
     179           0 :                 SetEof( true );
     180           0 :                 break;
     181             : 
     182             :             case 0x00ce:{ // Attribute cell
     183             :                 sal_uInt8 nFormat, nAlign, nFont;
     184             :                 sal_Int16 nColor;
     185        5000 :                 mpStream->ReadUChar( nFormat ).ReadUChar( nAlign ).ReadInt16( nColor ).ReadUChar( nFont );
     186        5000 :                 pStyleElement->setAlign( i, nAlign );
     187        5000 :                 pStyleElement->setFont( i, nFont );
     188        5000 :                 i++;
     189             :                 }
     190        5000 :                 break;
     191             : 
     192             :             case 0x00cf:{ // Font description
     193             :                 sal_uInt16 nPtSize, nFontAttr;
     194        5000 :                 OUString aLabel;
     195        5000 :                 mpStream->ReadUInt16( nPtSize ).ReadUInt16( nFontAttr );
     196        5000 :                 pStyleElement->setFontRecord( j, nFontAttr, nPtSize );
     197        5000 :                 sal_uInt16 nLen = getLength();
     198        5000 :                 if (nLen >= 4)
     199        5000 :                     readString( aLabel, nLen - 4 );
     200             :                 else
     201           0 :                     eRet = eERR_FORMAT;
     202        5000 :                 pStyleElement->setFontType( j, aLabel );
     203        5000 :                 j++;
     204             :                 }
     205        5000 :                 break;
     206             :         }
     207             :     }
     208           3 :     pDoc->CalcAfterLoad();
     209           3 :     delete pStyleElement;
     210           3 :     return eRet;
     211             : }
     212             : 
     213           3 : bool ScQProReader::recordsLeft()
     214             : {
     215           3 :     bool bValue = ScBiffReader::recordsLeft();
     216           3 :     return bValue;
     217             : }
     218             : 
     219       10010 : bool ScQProReader::nextRecord()
     220             : {
     221       10010 :     bool bValue = ScBiffReader::nextRecord();
     222       10010 :     return bValue;
     223             : }
     224             : 
     225        5000 : void ScQProReader::readString( OUString &rString, sal_uInt16 nLength )
     226             : {
     227        5000 :     boost::scoped_array<sal_Char> pText(new sal_Char[ nLength + 1 ]);
     228        5000 :     nLength = mpStream->Read(pText.get(), nLength);
     229        5000 :     pText[ nLength ] = 0;
     230        5000 :     rString = OUString( pText.get(), strlen(pText.get()), mpStream->GetStreamCharSet() );
     231        5000 : }
     232             : 
     233             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10