Update ooo320-m1
[ooovba.git] / sc / source / filter / qpro / qpro.cxx
blobdf1a0d6143502267bac04aa4d4449f706976a750
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: qpro.cxx,v $
10 * $Revision: 1.6 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sc.hxx"
34 #include <sal/config.h>
35 #include <stdio.h>
36 #include <sfx2/docfile.hxx>
38 #include "qproform.hxx"
39 #include "qpro.hxx"
40 #include "qprostyle.hxx"
42 #include "global.hxx"
43 #include "scerrors.hxx"
44 #include "docpool.hxx"
45 #include "patattr.hxx"
46 #include "filter.hxx"
47 #include "document.hxx"
48 #include "cell.hxx"
49 #include "biff.hxx"
50 #include <tools/stream.hxx>
52 FltError ScQProReader::readSheet( SCTAB nTab, ScDocument* pDoc, ScQProStyle *pStyle )
54 FltError eRet = eERR_OK;
55 sal_uInt8 nCol, nDummy;
56 sal_uInt16 nRow;
57 sal_uInt16 nStyle;
58 bool bEndOfSheet = false;
60 #ifdef DEBUG
61 fprintf( stderr, "Read sheet (%d)\n", nTab );
62 #endif
64 while( eERR_OK == eRet && !bEndOfSheet && nextRecord() )
66 switch( getId() )
68 case 0x000f:{ // Label cell
69 String aLabel;
70 *mpStream >> nCol >> nDummy >> nRow >> nStyle >> nDummy;
71 readString( aLabel, getLength() - 7 );
72 nStyle = nStyle >> 3;
73 pStyle->SetFormat( pDoc, nCol, nRow, nTab, nStyle );
74 pDoc->PutCell( nCol, nRow, nTab, ScBaseCell::CreateTextCell( aLabel, pDoc ), (BOOL) TRUE );
76 break;
78 case 0x00cb: // End of sheet
79 bEndOfSheet = true;
80 break;
82 case 0x000c: // Blank cell
83 *mpStream >> nCol >> nDummy >> nRow >> nStyle;
84 nStyle = nStyle >> 3;
85 pStyle->SetFormat( pDoc, nCol, nRow, nTab, nStyle );
86 break;
88 case 0x000d:{ // Integer cell
89 sal_Int16 nValue;
90 *mpStream >> nCol >> nDummy >> nRow >> nStyle >> nValue;
91 ScValueCell* pInteger = new ScValueCell( ( double ) nValue );
92 nStyle = nStyle >> 3;
93 pStyle->SetFormat( pDoc, nCol, nRow, nTab, nStyle );
94 pDoc->PutCell(nCol ,nRow, nTab ,pInteger,(BOOL) TRUE);
96 break;
98 case 0x000e:{ // Floating point cell
99 double nValue;
100 *mpStream >> nCol >> nDummy >> nRow >> nStyle >> nValue;
101 ScValueCell* pFloat = new ScValueCell( nValue );
102 nStyle = nStyle >> 3;
103 pStyle->SetFormat( pDoc, nCol, nRow, nTab, nStyle );
104 pDoc->PutCell( nCol, nRow, nTab, pFloat, (BOOL) TRUE );
106 break;
108 case 0x0010:{ // Formula cell
109 double nValue;
110 sal_uInt16 nState, nLen;
111 *mpStream >> nCol >> nDummy >> nRow >> nStyle >> nValue >> nState >> nLen;
112 ScAddress aAddr( nCol, nRow, nTab );
113 const ScTokenArray *pArray;
114 QProToSc aConv( *mpStream, aAddr );
115 if (ConvOK != aConv.Convert( pArray, nLen ))
116 eRet = eERR_FORMAT;
117 else
119 ScFormulaCell *pFormula = new ScFormulaCell( pDoc, aAddr, pArray );
120 nStyle = nStyle >> 3;
121 pFormula->AddRecalcMode( RECALCMODE_ONLOAD_ONCE );
122 pStyle->SetFormat( pDoc, nCol, nRow, nTab, nStyle );
123 pDoc->PutCell( nCol, nRow, nTab, pFormula, ( BOOL ) TRUE );
126 break;
129 return eRet;
132 FltError ScFormatFilterPluginImpl::ScImportQuattroPro( SfxMedium &rMedium, ScDocument *pDoc )
134 FltError eRet = eERR_OK;
135 ScQProReader aReader( rMedium );
136 eRet = aReader.import( pDoc );
137 return eRet;
140 ScQProReader::ScQProReader( SfxMedium &rMedium ):
141 ScBiffReader( rMedium )
145 FltError ScQProReader::import( ScDocument *pDoc )
147 FltError eRet = eERR_OK;
148 sal_uInt16 nVersion;
149 sal_uInt16 i = 1, j = 1;
150 SCTAB nTab = 0;
151 SetEof( FALSE );
153 if( !recordsLeft() )
154 return eERR_OPEN;
156 ScQProStyle *pStyleElement = new ScQProStyle;
158 while( nextRecord() && eRet == eERR_OK)
160 switch( getId() )
162 case 0x0000: // Begginning of file
163 *mpStream >> nVersion;
164 break;
166 case 0x00ca: // Beginning of sheet
167 if( nTab <= MAXTAB )
169 if( nTab < 26 )
171 String aName;
172 aName.Append( sal_Unicode( 'A' + nTab ) );
173 if (!nTab)
174 pDoc->RenameTab( nTab, aName, FALSE, FALSE);
175 else
176 pDoc->InsertTab( nTab, aName );
178 eRet = readSheet( nTab, pDoc, pStyleElement );
179 nTab++;
181 break;
183 case 0x0001: // End of file
184 SetEof( TRUE );
185 break;
187 case 0x00ce:{ // Attribute cell
188 sal_uInt8 nFormat, nAlign, nFont;
189 sal_Int16 nColor;
190 *mpStream >> nFormat >> nAlign >> nColor >> nFont;
191 pStyleElement->setAlign( i, nAlign );
192 pStyleElement->setFont( i, nFont );
193 i++;
195 break;
197 case 0x00cf:{ // Font description
198 sal_uInt16 nPtSize, nFontAttr;
199 String aLabel;
200 *mpStream >> nPtSize >> nFontAttr;
201 pStyleElement->setFontRecord( j, nFontAttr, nPtSize );
202 readString( aLabel, getLength() - 4 );
203 pStyleElement->setFontType( j, aLabel );
204 j++;
206 break;
209 pDoc->CalcAfterLoad();
210 delete pStyleElement;
211 return eRet;
214 bool ScQProReader::recordsLeft()
216 bool bValue = ScBiffReader::recordsLeft();
217 return bValue;
220 bool ScQProReader::nextRecord()
222 bool bValue = ScBiffReader::nextRecord();
223 return bValue;
226 void ScQProReader::readString( String &rString, sal_uInt16 nLength )
228 sal_Char* pText = new sal_Char[ nLength + 1 ];
229 mpStream->Read( pText, nLength );
230 pText[ nLength ] = 0;
231 rString = String( pText, mpStream->GetStreamCharSet() );
232 delete [] pText;