merged tag ooo/OOO330_m14
[LibreOffice.git] / sc / source / filter / qpro / qpro.cxx
blob084aab135f706f0c74c5c27401985c422fc85f8b
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sc.hxx"
31 #include <sal/config.h>
32 #include <stdio.h>
33 #include <sfx2/docfile.hxx>
35 #include "qproform.hxx"
36 #include "qpro.hxx"
37 #include "qprostyle.hxx"
39 #include "global.hxx"
40 #include "scerrors.hxx"
41 #include "docpool.hxx"
42 #include "patattr.hxx"
43 #include "filter.hxx"
44 #include "document.hxx"
45 #include "cell.hxx"
46 #include "biff.hxx"
47 #include <tools/stream.hxx>
49 FltError ScQProReader::readSheet( SCTAB nTab, ScDocument* pDoc, ScQProStyle *pStyle )
51 FltError eRet = eERR_OK;
52 sal_uInt8 nCol, nDummy;
53 sal_uInt16 nRow;
54 sal_uInt16 nStyle;
55 bool bEndOfSheet = false;
57 #ifdef DEBUG
58 fprintf( stderr, "Read sheet (%d)\n", nTab );
59 #endif
61 while( eERR_OK == eRet && !bEndOfSheet && nextRecord() )
63 switch( getId() )
65 case 0x000f:{ // Label cell
66 String aLabel;
67 *mpStream >> nCol >> nDummy >> nRow >> nStyle >> nDummy;
68 readString( aLabel, getLength() - 7 );
69 nStyle = nStyle >> 3;
70 pStyle->SetFormat( pDoc, nCol, nRow, nTab, nStyle );
71 pDoc->PutCell( nCol, nRow, nTab, ScBaseCell::CreateTextCell( aLabel, pDoc ), (BOOL) TRUE );
73 break;
75 case 0x00cb: // End of sheet
76 bEndOfSheet = true;
77 break;
79 case 0x000c: // Blank cell
80 *mpStream >> nCol >> nDummy >> nRow >> nStyle;
81 nStyle = nStyle >> 3;
82 pStyle->SetFormat( pDoc, nCol, nRow, nTab, nStyle );
83 break;
85 case 0x000d:{ // Integer cell
86 sal_Int16 nValue;
87 *mpStream >> nCol >> nDummy >> nRow >> nStyle >> nValue;
88 ScValueCell* pInteger = new ScValueCell( ( double ) nValue );
89 nStyle = nStyle >> 3;
90 pStyle->SetFormat( pDoc, nCol, nRow, nTab, nStyle );
91 pDoc->PutCell(nCol ,nRow, nTab ,pInteger,(BOOL) TRUE);
93 break;
95 case 0x000e:{ // Floating point cell
96 double nValue;
97 *mpStream >> nCol >> nDummy >> nRow >> nStyle >> nValue;
98 ScValueCell* pFloat = new ScValueCell( nValue );
99 nStyle = nStyle >> 3;
100 pStyle->SetFormat( pDoc, nCol, nRow, nTab, nStyle );
101 pDoc->PutCell( nCol, nRow, nTab, pFloat, (BOOL) TRUE );
103 break;
105 case 0x0010:{ // Formula cell
106 double nValue;
107 sal_uInt16 nState, nLen;
108 *mpStream >> nCol >> nDummy >> nRow >> nStyle >> nValue >> nState >> nLen;
109 ScAddress aAddr( nCol, nRow, nTab );
110 const ScTokenArray *pArray;
111 QProToSc aConv( *mpStream, aAddr );
112 if (ConvOK != aConv.Convert( pArray, nLen ))
113 eRet = eERR_FORMAT;
114 else
116 ScFormulaCell *pFormula = new ScFormulaCell( pDoc, aAddr, pArray );
117 nStyle = nStyle >> 3;
118 pFormula->AddRecalcMode( RECALCMODE_ONLOAD_ONCE );
119 pStyle->SetFormat( pDoc, nCol, nRow, nTab, nStyle );
120 pDoc->PutCell( nCol, nRow, nTab, pFormula, ( BOOL ) TRUE );
123 break;
126 return eRet;
129 FltError ScFormatFilterPluginImpl::ScImportQuattroPro( SfxMedium &rMedium, ScDocument *pDoc )
131 FltError eRet = eERR_OK;
132 ScQProReader aReader( rMedium );
133 eRet = aReader.import( pDoc );
134 return eRet;
137 ScQProReader::ScQProReader( SfxMedium &rMedium ):
138 ScBiffReader( rMedium )
142 FltError ScQProReader::import( ScDocument *pDoc )
144 FltError eRet = eERR_OK;
145 sal_uInt16 nVersion;
146 sal_uInt16 i = 1, j = 1;
147 SCTAB nTab = 0;
148 SetEof( FALSE );
150 if( !recordsLeft() )
151 return eERR_OPEN;
153 ScQProStyle *pStyleElement = new ScQProStyle;
155 while( nextRecord() && eRet == eERR_OK)
157 switch( getId() )
159 case 0x0000: // Begginning of file
160 *mpStream >> nVersion;
161 break;
163 case 0x00ca: // Beginning of sheet
164 if( nTab <= MAXTAB )
166 if( nTab < 26 )
168 String aName;
169 aName.Append( sal_Unicode( 'A' + nTab ) );
170 if (!nTab)
171 pDoc->RenameTab( nTab, aName, FALSE, FALSE);
172 else
173 pDoc->InsertTab( nTab, aName );
175 eRet = readSheet( nTab, pDoc, pStyleElement );
176 nTab++;
178 break;
180 case 0x0001: // End of file
181 SetEof( TRUE );
182 break;
184 case 0x00ce:{ // Attribute cell
185 sal_uInt8 nFormat, nAlign, nFont;
186 sal_Int16 nColor;
187 *mpStream >> nFormat >> nAlign >> nColor >> nFont;
188 pStyleElement->setAlign( i, nAlign );
189 pStyleElement->setFont( i, nFont );
190 i++;
192 break;
194 case 0x00cf:{ // Font description
195 sal_uInt16 nPtSize, nFontAttr;
196 String aLabel;
197 *mpStream >> nPtSize >> nFontAttr;
198 pStyleElement->setFontRecord( j, nFontAttr, nPtSize );
199 readString( aLabel, getLength() - 4 );
200 pStyleElement->setFontType( j, aLabel );
201 j++;
203 break;
206 pDoc->CalcAfterLoad();
207 delete pStyleElement;
208 return eRet;
211 bool ScQProReader::recordsLeft()
213 bool bValue = ScBiffReader::recordsLeft();
214 return bValue;
217 bool ScQProReader::nextRecord()
219 bool bValue = ScBiffReader::nextRecord();
220 return bValue;
223 void ScQProReader::readString( String &rString, sal_uInt16 nLength )
225 sal_Char* pText = new sal_Char[ nLength + 1 ];
226 mpStream->Read( pText, nLength );
227 pText[ nLength ] = 0;
228 rString = String( pText, mpStream->GetStreamCharSet() );
229 delete [] pText;