bump product version to 4.1.6.2
[LibreOffice.git] / sc / source / filter / qpro / qpro.cxx
blobf6658845a78441da6f3cc7eee36b849115a09d5f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include <sal/config.h>
22 #include <stdio.h>
23 #include <sfx2/docfile.hxx>
25 #include "qproform.hxx"
26 #include "qpro.hxx"
27 #include "qprostyle.hxx"
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>
39 FltError ScQProReader::readSheet( SCTAB nTab, ScDocument* pDoc, ScQProStyle *pStyle )
41 FltError eRet = eERR_OK;
42 sal_uInt8 nCol, nDummy;
43 sal_uInt16 nRow;
44 sal_uInt16 nStyle;
45 bool bEndOfSheet = false;
47 #if OSL_DEBUG_LEVEL > 1
48 fprintf( stderr, "Read sheet (%d)\n", nTab );
49 #endif
51 while( eERR_OK == eRet && !bEndOfSheet && nextRecord() )
53 switch( getId() )
55 case 0x000f:{ // Label cell
56 String aLabel;
57 *mpStream >> nCol >> nDummy >> nRow >> nStyle >> nDummy;
58 sal_uInt16 nLen = getLength();
59 if (nLen >= 7)
61 readString( aLabel, nLen - 7 );
62 nStyle = nStyle >> 3;
63 pStyle->SetFormat( pDoc, nCol, nRow, nTab, nStyle );
64 pDoc->EnsureTable(nTab);
65 pDoc->SetTextCell(ScAddress(nCol,nRow,nTab), aLabel);
67 else
68 eRet = eERR_FORMAT;
70 break;
72 case 0x00cb: // End of sheet
73 bEndOfSheet = true;
74 break;
76 case 0x000c: // Blank cell
77 *mpStream >> nCol >> nDummy >> nRow >> nStyle;
78 nStyle = nStyle >> 3;
79 pStyle->SetFormat( pDoc, nCol, nRow, nTab, nStyle );
80 break;
82 case 0x000d:{ // Integer cell
83 sal_Int16 nValue;
84 *mpStream >> nCol >> nDummy >> nRow >> nStyle >> nValue;
85 nStyle = nStyle >> 3;
86 pStyle->SetFormat( pDoc, nCol, nRow, nTab, nStyle );
87 pDoc->EnsureTable(nTab);
88 pDoc->SetValue(ScAddress(nCol,nRow,nTab), static_cast<double>(nValue));
90 break;
92 case 0x000e:{ // Floating point cell
93 double nValue;
94 *mpStream >> nCol >> nDummy >> nRow >> nStyle >> nValue;
95 nStyle = nStyle >> 3;
96 pStyle->SetFormat( pDoc, nCol, nRow, nTab, nStyle );
97 pDoc->EnsureTable(nTab);
98 pDoc->SetValue(ScAddress(nCol,nRow,nTab), nValue);
100 break;
102 case 0x0010:{ // Formula cell
103 double nValue;
104 sal_uInt16 nState, nLen;
105 *mpStream >> nCol >> nDummy >> nRow >> nStyle >> nValue >> nState >> nLen;
106 ScAddress aAddr( nCol, nRow, nTab );
107 const ScTokenArray *pArray;
108 QProToSc aConv( *mpStream, aAddr );
109 if (ConvOK != aConv.Convert( pArray, nLen ))
110 eRet = eERR_FORMAT;
111 else
113 ScFormulaCell *pFormula = new ScFormulaCell( pDoc, aAddr, pArray );
114 nStyle = nStyle >> 3;
115 pFormula->AddRecalcMode( RECALCMODE_ONLOAD_ONCE );
116 pStyle->SetFormat( pDoc, nCol, nRow, nTab, nStyle );
117 pDoc->EnsureTable(nTab);
118 pDoc->SetFormulaCell(ScAddress(nCol,nRow,nTab), pFormula);
121 break;
124 return eRet;
127 FltError ScFormatFilterPluginImpl::ScImportQuattroPro( SfxMedium &rMedium, ScDocument *pDoc )
129 ScQProReader aReader( rMedium );
130 FltError eRet = aReader.import( pDoc );
131 return eRet;
134 ScQProReader::ScQProReader( SfxMedium &rMedium ):
135 ScBiffReader( rMedium )
139 FltError ScQProReader::import( ScDocument *pDoc )
141 FltError eRet = eERR_OK;
142 sal_uInt16 nVersion;
143 sal_uInt16 i = 1, j = 1;
144 SCTAB nTab = 0;
145 SetEof( false );
147 if( !recordsLeft() )
148 return eERR_OPEN;
150 ScQProStyle *pStyleElement = new ScQProStyle;
152 while( nextRecord() && eRet == eERR_OK)
154 switch( getId() )
156 case 0x0000: // Begginning of file
157 *mpStream >> nVersion;
158 break;
160 case 0x00ca: // Beginning of sheet
161 if( nTab <= MAXTAB )
163 if( nTab < 26 )
165 String aName;
166 aName.Append( sal_Unicode( 'A' + nTab ) );
167 if (!nTab)
168 pDoc->RenameTab( nTab, aName, false, false);
169 else
170 pDoc->InsertTab( nTab, aName );
172 eRet = readSheet( nTab, pDoc, pStyleElement );
173 nTab++;
175 break;
177 case 0x0001: // End of file
178 SetEof( sal_True );
179 break;
181 case 0x00ce:{ // Attribute cell
182 sal_uInt8 nFormat, nAlign, nFont;
183 sal_Int16 nColor;
184 *mpStream >> nFormat >> nAlign >> nColor >> nFont;
185 pStyleElement->setAlign( i, nAlign );
186 pStyleElement->setFont( i, nFont );
187 i++;
189 break;
191 case 0x00cf:{ // Font description
192 sal_uInt16 nPtSize, nFontAttr;
193 String aLabel;
194 *mpStream >> nPtSize >> nFontAttr;
195 pStyleElement->setFontRecord( j, nFontAttr, nPtSize );
196 sal_uInt16 nLen = getLength();
197 if (nLen >= 4)
198 readString( aLabel, nLen - 4 );
199 else
200 eRet = eERR_FORMAT;
201 pStyleElement->setFontType( j, aLabel );
202 j++;
204 break;
207 pDoc->CalcAfterLoad();
208 delete pStyleElement;
209 return eRet;
212 bool ScQProReader::recordsLeft()
214 bool bValue = ScBiffReader::recordsLeft();
215 return bValue;
218 bool ScQProReader::nextRecord()
220 bool bValue = ScBiffReader::nextRecord();
221 return bValue;
224 void ScQProReader::readString( String &rString, sal_uInt16 nLength )
226 sal_Char* pText = new sal_Char[ nLength + 1 ];
227 mpStream->Read( pText, nLength );
228 pText[ nLength ] = 0;
229 rString = String( pText, mpStream->GetStreamCharSet() );
230 delete [] pText;
233 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */