fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / filter / qpro / qpro.cxx
blob7a73b2ee3bd3cae7b00af2141299a8c3b11649b5
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 .
20 #include <sal/config.h>
21 #include <stdio.h>
22 #include <sfx2/docfile.hxx>
24 #include "qproform.hxx"
25 #include "qpro.hxx"
26 #include "qprostyle.hxx"
28 #include "global.hxx"
29 #include "scerrors.hxx"
30 #include "docpool.hxx"
31 #include "patattr.hxx"
32 #include "filter.hxx"
33 #include "document.hxx"
34 #include "formulacell.hxx"
35 #include "biff.hxx"
36 #include <tools/stream.hxx>
37 #include <boost/scoped_array.hpp>
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 OUString aLabel;
57 mpStream->ReadUChar( nCol ).ReadUChar( nDummy ).ReadUInt16( nRow ).ReadUInt16( nStyle ).ReadUChar( 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->ReadUChar( nCol ).ReadUChar( nDummy ).ReadUInt16( nRow ).ReadUInt16( 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->ReadUChar( nCol ).ReadUChar( nDummy ).ReadUInt16( nRow ).ReadUInt16( nStyle ).ReadInt16( 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->ReadUChar( nCol ).ReadUChar( nDummy ).ReadUInt16( nRow ).ReadUInt16( nStyle ).ReadDouble( 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:
104 // Formula cell
105 double nValue;
106 sal_uInt16 nState, nLen;
107 mpStream->ReadUChar( nCol ).ReadUChar( nDummy ).ReadUInt16( nRow ).ReadUInt16( nStyle ).ReadDouble( nValue ).ReadUInt16( nState ).ReadUInt16( nLen );
108 ScAddress aAddr( nCol, nRow, nTab );
109 const ScTokenArray *pArray;
111 QProToSc aConv(*mpStream, pDoc->GetSharedStringPool(), 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( ScRecalcMode::ONLOAD_ONCE );
119 pStyle->SetFormat( pDoc, nCol, nRow, nTab, nStyle );
120 pDoc->EnsureTable(nTab);
121 pDoc->SetFormulaCell(ScAddress(nCol,nRow,nTab), pFormula);
124 break;
127 return eRet;
130 FltError ScFormatFilterPluginImpl::ScImportQuattroPro( SfxMedium &rMedium, ScDocument *pDoc )
132 ScQProReader aReader( rMedium );
133 FltError 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->ReadUInt16( nVersion );
161 break;
163 case 0x00ca: // Beginning of sheet
164 if( nTab <= MAXTAB )
166 if( nTab < 26 )
168 OUString aName;
169 aName += OUString( 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->ReadUChar( nFormat ).ReadUChar( nAlign ).ReadInt16( nColor ).ReadUChar( 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 OUString aLabel;
197 mpStream->ReadUInt16( nPtSize ).ReadUInt16( nFontAttr );
198 pStyleElement->setFontRecord( j, nFontAttr, nPtSize );
199 sal_uInt16 nLen = getLength();
200 if (nLen >= 4)
201 readString( aLabel, nLen - 4 );
202 else
203 eRet = eERR_FORMAT;
204 pStyleElement->setFontType( j, aLabel );
205 j++;
207 break;
210 pDoc->CalcAfterLoad();
211 delete pStyleElement;
212 return eRet;
215 bool ScQProReader::recordsLeft()
217 bool bValue = ScBiffReader::recordsLeft();
218 return bValue;
221 bool ScQProReader::nextRecord()
223 bool bValue = ScBiffReader::nextRecord();
224 return bValue;
227 void ScQProReader::readString( OUString &rString, sal_uInt16 nLength )
229 boost::scoped_array<sal_Char> pText(new sal_Char[ nLength + 1 ]);
230 nLength = mpStream->Read(pText.get(), nLength);
231 pText[ nLength ] = 0;
232 rString = OUString( pText.get(), strlen(pText.get()), mpStream->GetStreamCharSet() );
235 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */