Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include <sal/config.h>
31 : : #include <stdio.h>
32 : : #include <sfx2/docfile.hxx>
33 : :
34 : : #include "qproform.hxx"
35 : : #include "qpro.hxx"
36 : : #include "qprostyle.hxx"
37 : :
38 : : #include "global.hxx"
39 : : #include "scerrors.hxx"
40 : : #include "docpool.hxx"
41 : : #include "patattr.hxx"
42 : : #include "filter.hxx"
43 : : #include "document.hxx"
44 : : #include "cell.hxx"
45 : : #include "biff.hxx"
46 : : #include <tools/stream.hxx>
47 : :
48 : 3 : FltError ScQProReader::readSheet( SCTAB nTab, ScDocument* pDoc, ScQProStyle *pStyle )
49 : : {
50 : 3 : FltError eRet = eERR_OK;
51 : : sal_uInt8 nCol, nDummy;
52 : : sal_uInt16 nRow;
53 : : sal_uInt16 nStyle;
54 : 3 : bool bEndOfSheet = false;
55 : :
56 : : #if OSL_DEBUG_LEVEL > 1
57 : : fprintf( stderr, "Read sheet (%d)\n", nTab );
58 : : #endif
59 : :
60 [ + + ][ + - ]: 6 : while( eERR_OK == eRet && !bEndOfSheet && nextRecord() )
[ + - ][ + - ]
[ + + ]
61 : : {
62 [ - - - - : 3 : switch( getId() )
- + - ]
63 : : {
64 : : case 0x000f:{ // Label cell
65 [ # # ]: 0 : String aLabel;
66 [ # # ][ # # ]: 0 : *mpStream >> nCol >> nDummy >> nRow >> nStyle >> nDummy;
[ # # ][ # # ]
[ # # ]
67 : 0 : sal_uInt16 nLen = getLength();
68 [ # # ]: 0 : if (nLen >= 7)
69 : : {
70 [ # # ]: 0 : readString( aLabel, nLen - 7 );
71 : 0 : nStyle = nStyle >> 3;
72 [ # # ]: 0 : pStyle->SetFormat( pDoc, nCol, nRow, nTab, nStyle );
73 [ # # ][ # # ]: 0 : pDoc->PutCell( nCol, nRow, nTab, ScBaseCell::CreateTextCell( aLabel, pDoc ), true );
[ # # ]
74 : : }
75 : : else
76 [ # # ]: 0 : eRet = eERR_FORMAT;
77 : : }
78 : 0 : break;
79 : :
80 : : case 0x00cb: // End of sheet
81 : 0 : bEndOfSheet = true;
82 : 0 : break;
83 : :
84 : : case 0x000c: // Blank cell
85 [ # # ][ # # ]: 0 : *mpStream >> nCol >> nDummy >> nRow >> nStyle;
[ # # ][ # # ]
86 : 0 : nStyle = nStyle >> 3;
87 [ # # ]: 0 : pStyle->SetFormat( pDoc, nCol, nRow, nTab, nStyle );
88 : 0 : break;
89 : :
90 : : case 0x000d:{ // Integer cell
91 : : sal_Int16 nValue;
92 [ # # ][ # # ]: 0 : *mpStream >> nCol >> nDummy >> nRow >> nStyle >> nValue;
[ # # ][ # # ]
[ # # ]
93 [ # # ][ # # ]: 0 : ScValueCell* pInteger = new ScValueCell( ( double ) nValue );
94 : 0 : nStyle = nStyle >> 3;
95 [ # # ]: 0 : pStyle->SetFormat( pDoc, nCol, nRow, nTab, nStyle );
96 [ # # ]: 0 : pDoc->PutCell(nCol ,nRow, nTab ,pInteger,true);
97 : : }
98 : 0 : break;
99 : :
100 : : case 0x000e:{ // Floating point cell
101 : : double nValue;
102 [ # # ][ # # ]: 0 : *mpStream >> nCol >> nDummy >> nRow >> nStyle >> nValue;
[ # # ][ # # ]
[ # # ]
103 [ # # ][ # # ]: 0 : ScValueCell* pFloat = new ScValueCell( nValue );
104 : 0 : nStyle = nStyle >> 3;
105 [ # # ]: 0 : pStyle->SetFormat( pDoc, nCol, nRow, nTab, nStyle );
106 [ # # ]: 0 : pDoc->PutCell( nCol, nRow, nTab, pFloat, true );
107 : : }
108 : 0 : break;
109 : :
110 : : case 0x0010:{ // Formula cell
111 : : double nValue;
112 : : sal_uInt16 nState, nLen;
113 [ + - ][ + - ]: 3 : *mpStream >> nCol >> nDummy >> nRow >> nStyle >> nValue >> nState >> nLen;
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ]
114 : 3 : ScAddress aAddr( nCol, nRow, nTab );
115 : : const ScTokenArray *pArray;
116 [ + - ]: 3 : QProToSc aConv( *mpStream, aAddr );
117 [ + - ][ + - ]: 3 : if (ConvOK != aConv.Convert( pArray, nLen ))
118 : 3 : eRet = eERR_FORMAT;
119 : : else
120 : : {
121 [ # # ][ # # ]: 0 : ScFormulaCell *pFormula = new ScFormulaCell( pDoc, aAddr, pArray );
122 : 0 : nStyle = nStyle >> 3;
123 [ # # ]: 0 : pFormula->AddRecalcMode( RECALCMODE_ONLOAD_ONCE );
124 [ # # ]: 0 : pStyle->SetFormat( pDoc, nCol, nRow, nTab, nStyle );
125 [ # # ][ # # ]: 0 : pDoc->PutCell( nCol, nRow, nTab, pFormula, true );
126 [ + - ]: 3 : }
127 : : }
128 : 3 : break;
129 : : }
130 : : }
131 : 3 : return eRet;
132 : : }
133 : :
134 : 9 : FltError ScFormatFilterPluginImpl::ScImportQuattroPro( SfxMedium &rMedium, ScDocument *pDoc )
135 : : {
136 : 9 : FltError eRet = eERR_OK;
137 [ + - ]: 9 : ScQProReader aReader( rMedium );
138 [ + - ]: 9 : eRet = aReader.import( pDoc );
139 [ + - ]: 9 : return eRet;
140 : : }
141 : :
142 : 9 : ScQProReader::ScQProReader( SfxMedium &rMedium ):
143 : 9 : ScBiffReader( rMedium )
144 : : {
145 : 9 : }
146 : :
147 : 9 : FltError ScQProReader::import( ScDocument *pDoc )
148 : : {
149 : 9 : FltError eRet = eERR_OK;
150 : : sal_uInt16 nVersion;
151 : 9 : sal_uInt16 i = 1, j = 1;
152 : 9 : SCTAB nTab = 0;
153 : 9 : SetEof( false );
154 : :
155 [ - + ]: 9 : if( !recordsLeft() )
156 : 0 : return eERR_OPEN;
157 : :
158 [ + - ][ + - ]: 9 : ScQProStyle *pStyleElement = new ScQProStyle;
159 : :
160 [ + - ][ + + ]: 30027 : while( nextRecord() && eRet == eERR_OK)
[ + + ][ + + ]
161 : : {
162 [ + + - + : 30018 : switch( getId() )
+ - ]
163 : : {
164 : : case 0x0000: // Begginning of file
165 [ + - ]: 15 : *mpStream >> nVersion;
166 : 15 : break;
167 : :
168 : : case 0x00ca: // Beginning of sheet
169 [ + - ]: 3 : if( nTab <= MAXTAB )
170 : : {
171 [ + - ]: 3 : if( nTab < 26 )
172 : : {
173 [ + - ]: 3 : String aName;
174 [ + - ]: 3 : aName.Append( sal_Unicode( 'A' + nTab ) );
175 [ + - ]: 3 : if (!nTab)
176 [ + - ][ + - ]: 3 : pDoc->RenameTab( nTab, aName, false, false);
177 : : else
178 [ # # ][ # # ]: 3 : pDoc->InsertTab( nTab, aName );
[ + - ]
179 : : }
180 [ + - ]: 3 : eRet = readSheet( nTab, pDoc, pStyleElement );
181 : 3 : nTab++;
182 : : }
183 : 3 : break;
184 : :
185 : : case 0x0001: // End of file
186 : 0 : SetEof( sal_True );
187 : 0 : break;
188 : :
189 : : case 0x00ce:{ // Attribute cell
190 : : sal_uInt8 nFormat, nAlign, nFont;
191 : : sal_Int16 nColor;
192 [ + - ][ + - ]: 15000 : *mpStream >> nFormat >> nAlign >> nColor >> nFont;
[ + - ][ + - ]
193 : 15000 : pStyleElement->setAlign( i, nAlign );
194 : 15000 : pStyleElement->setFont( i, nFont );
195 : 15000 : i++;
196 : : }
197 : 15000 : break;
198 : :
199 : : case 0x00cf:{ // Font description
200 : : sal_uInt16 nPtSize, nFontAttr;
201 [ + - ]: 15000 : String aLabel;
202 [ + - ][ + - ]: 15000 : *mpStream >> nPtSize >> nFontAttr;
203 : 15000 : pStyleElement->setFontRecord( j, nFontAttr, nPtSize );
204 : 15000 : sal_uInt16 nLen = getLength();
205 [ + - ]: 15000 : if (nLen >= 4)
206 [ + - ]: 15000 : readString( aLabel, nLen - 4 );
207 : : else
208 : 0 : eRet = eERR_FORMAT;
209 [ + - ]: 15000 : pStyleElement->setFontType( j, aLabel );
210 [ + - ]: 15000 : j++;
211 : : }
212 : 15000 : break;
213 : : }
214 : : }
215 [ + - ]: 9 : pDoc->CalcAfterLoad();
216 [ + - ][ + - ]: 9 : delete pStyleElement;
217 : 9 : return eRet;
218 : : }
219 : :
220 : 9 : bool ScQProReader::recordsLeft()
221 : : {
222 : 9 : bool bValue = ScBiffReader::recordsLeft();
223 : 9 : return bValue;
224 : : }
225 : :
226 : 30030 : bool ScQProReader::nextRecord()
227 : : {
228 : 30030 : bool bValue = ScBiffReader::nextRecord();
229 : 30030 : return bValue;
230 : : }
231 : :
232 : 15000 : void ScQProReader::readString( String &rString, sal_uInt16 nLength )
233 : : {
234 : 15000 : sal_Char* pText = new sal_Char[ nLength + 1 ];
235 : 15000 : mpStream->Read( pText, nLength );
236 : 15000 : pText[ nLength ] = 0;
237 [ + - ]: 15000 : rString = String( pText, mpStream->GetStreamCharSet() );
238 [ + - ]: 15000 : delete [] pText;
239 : 15000 : }
240 : :
241 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|