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 "formulacell.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->EnsureTable(nTab);
65 0 : pDoc->SetTextCell(ScAddress(nCol,nRow,nTab), aLabel);
66 : }
67 : else
68 0 : eRet = eERR_FORMAT;
69 : }
70 0 : break;
71 :
72 : case 0x00cb: // End of sheet
73 0 : bEndOfSheet = true;
74 0 : break;
75 :
76 : case 0x000c: // Blank cell
77 0 : *mpStream >> nCol >> nDummy >> nRow >> nStyle;
78 0 : nStyle = nStyle >> 3;
79 0 : pStyle->SetFormat( pDoc, nCol, nRow, nTab, nStyle );
80 0 : break;
81 :
82 : case 0x000d:{ // Integer cell
83 : sal_Int16 nValue;
84 0 : *mpStream >> nCol >> nDummy >> nRow >> nStyle >> nValue;
85 0 : nStyle = nStyle >> 3;
86 0 : pStyle->SetFormat( pDoc, nCol, nRow, nTab, nStyle );
87 0 : pDoc->EnsureTable(nTab);
88 0 : pDoc->SetValue(ScAddress(nCol,nRow,nTab), static_cast<double>(nValue));
89 : }
90 0 : break;
91 :
92 : case 0x000e:{ // Floating point cell
93 : double nValue;
94 0 : *mpStream >> nCol >> nDummy >> nRow >> nStyle >> nValue;
95 0 : nStyle = nStyle >> 3;
96 0 : pStyle->SetFormat( pDoc, nCol, nRow, nTab, nStyle );
97 0 : pDoc->EnsureTable(nTab);
98 0 : pDoc->SetValue(ScAddress(nCol,nRow,nTab), nValue);
99 : }
100 0 : break;
101 :
102 : case 0x0010:{ // Formula cell
103 : double nValue;
104 : sal_uInt16 nState, nLen;
105 1 : *mpStream >> nCol >> nDummy >> nRow >> nStyle >> nValue >> nState >> nLen;
106 1 : ScAddress aAddr( nCol, nRow, nTab );
107 : const ScTokenArray *pArray;
108 1 : QProToSc aConv( *mpStream, aAddr );
109 1 : if (ConvOK != aConv.Convert( pArray, nLen ))
110 1 : eRet = eERR_FORMAT;
111 : else
112 : {
113 0 : ScFormulaCell *pFormula = new ScFormulaCell( pDoc, aAddr, pArray );
114 0 : nStyle = nStyle >> 3;
115 0 : pFormula->AddRecalcMode( RECALCMODE_ONLOAD_ONCE );
116 0 : pStyle->SetFormat( pDoc, nCol, nRow, nTab, nStyle );
117 0 : pDoc->EnsureTable(nTab);
118 0 : pDoc->SetFormulaCell(ScAddress(nCol,nRow,nTab), pFormula);
119 1 : }
120 : }
121 1 : break;
122 : }
123 : }
124 1 : return eRet;
125 : }
126 :
127 3 : FltError ScFormatFilterPluginImpl::ScImportQuattroPro( SfxMedium &rMedium, ScDocument *pDoc )
128 : {
129 3 : ScQProReader aReader( rMedium );
130 3 : FltError eRet = aReader.import( pDoc );
131 3 : return eRet;
132 : }
133 :
134 3 : ScQProReader::ScQProReader( SfxMedium &rMedium ):
135 3 : ScBiffReader( rMedium )
136 : {
137 3 : }
138 :
139 3 : FltError ScQProReader::import( ScDocument *pDoc )
140 : {
141 3 : FltError eRet = eERR_OK;
142 : sal_uInt16 nVersion;
143 3 : sal_uInt16 i = 1, j = 1;
144 3 : SCTAB nTab = 0;
145 3 : SetEof( false );
146 :
147 3 : if( !recordsLeft() )
148 0 : return eERR_OPEN;
149 :
150 3 : ScQProStyle *pStyleElement = new ScQProStyle;
151 :
152 10012 : while( nextRecord() && eRet == eERR_OK)
153 : {
154 10006 : switch( getId() )
155 : {
156 : case 0x0000: // Begginning of file
157 5 : *mpStream >> nVersion;
158 5 : break;
159 :
160 : case 0x00ca: // Beginning of sheet
161 1 : if( nTab <= MAXTAB )
162 : {
163 1 : if( nTab < 26 )
164 : {
165 1 : String aName;
166 1 : aName.Append( sal_Unicode( 'A' + nTab ) );
167 1 : if (!nTab)
168 1 : pDoc->RenameTab( nTab, aName, false, false);
169 : else
170 0 : pDoc->InsertTab( nTab, aName );
171 : }
172 1 : eRet = readSheet( nTab, pDoc, pStyleElement );
173 1 : nTab++;
174 : }
175 1 : break;
176 :
177 : case 0x0001: // End of file
178 0 : SetEof( sal_True );
179 0 : break;
180 :
181 : case 0x00ce:{ // Attribute cell
182 : sal_uInt8 nFormat, nAlign, nFont;
183 : sal_Int16 nColor;
184 5000 : *mpStream >> nFormat >> nAlign >> nColor >> nFont;
185 5000 : pStyleElement->setAlign( i, nAlign );
186 5000 : pStyleElement->setFont( i, nFont );
187 5000 : i++;
188 : }
189 5000 : break;
190 :
191 : case 0x00cf:{ // Font description
192 : sal_uInt16 nPtSize, nFontAttr;
193 5000 : String aLabel;
194 5000 : *mpStream >> nPtSize >> nFontAttr;
195 5000 : pStyleElement->setFontRecord( j, nFontAttr, nPtSize );
196 5000 : sal_uInt16 nLen = getLength();
197 5000 : if (nLen >= 4)
198 5000 : readString( aLabel, nLen - 4 );
199 : else
200 0 : eRet = eERR_FORMAT;
201 5000 : pStyleElement->setFontType( j, aLabel );
202 5000 : j++;
203 : }
204 5000 : break;
205 : }
206 : }
207 3 : pDoc->CalcAfterLoad();
208 3 : delete pStyleElement;
209 3 : return eRet;
210 : }
211 :
212 3 : bool ScQProReader::recordsLeft()
213 : {
214 3 : bool bValue = ScBiffReader::recordsLeft();
215 3 : return bValue;
216 : }
217 :
218 10010 : bool ScQProReader::nextRecord()
219 : {
220 10010 : bool bValue = ScBiffReader::nextRecord();
221 10010 : return bValue;
222 : }
223 :
224 5000 : void ScQProReader::readString( String &rString, sal_uInt16 nLength )
225 : {
226 5000 : sal_Char* pText = new sal_Char[ nLength + 1 ];
227 5000 : mpStream->Read( pText, nLength );
228 5000 : pText[ nLength ] = 0;
229 5000 : rString = String( pText, mpStream->GetStreamCharSet() );
230 5000 : delete [] pText;
231 5000 : }
232 :
233 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|