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

Generated by: LCOV version 1.10