xref: /trunk/main/sc/source/filter/lotus/lotread.cxx (revision b77af630)
1b3f79822SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3b3f79822SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4b3f79822SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5b3f79822SAndrew Rist  * distributed with this work for additional information
6b3f79822SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7b3f79822SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8b3f79822SAndrew Rist  * "License"); you may not use this file except in compliance
9b3f79822SAndrew Rist  * with the License.  You may obtain a copy of the License at
10b3f79822SAndrew Rist  *
11b3f79822SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12b3f79822SAndrew Rist  *
13b3f79822SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14b3f79822SAndrew Rist  * software distributed under the License is distributed on an
15b3f79822SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16b3f79822SAndrew Rist  * KIND, either express or implied.  See the License for the
17b3f79822SAndrew Rist  * specific language governing permissions and limitations
18b3f79822SAndrew Rist  * under the License.
19b3f79822SAndrew Rist  *
20b3f79822SAndrew Rist  *************************************************************/
21b3f79822SAndrew Rist 
22b3f79822SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25*b77af630Sdamjan #include "precompiled_scfilt.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir 
28cdf0e10cSrcweir 
29cdf0e10cSrcweir //------------------------------------------------------------------------
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include "document.hxx"
32cdf0e10cSrcweir 
33cdf0e10cSrcweir #include "scerrors.hxx"
34cdf0e10cSrcweir #include "root.hxx"
35cdf0e10cSrcweir #include "lotimpop.hxx"
36cdf0e10cSrcweir #include "lotattr.hxx"
37cdf0e10cSrcweir #include "fprogressbar.hxx"
38cdf0e10cSrcweir 
39cdf0e10cSrcweir 
40cdf0e10cSrcweir class ScFormulaCell;
41cdf0e10cSrcweir 
42cdf0e10cSrcweir 
Read()43cdf0e10cSrcweir FltError ImportLotus::Read()
44cdf0e10cSrcweir {
45cdf0e10cSrcweir 	enum STATE
46cdf0e10cSrcweir 	{
47cdf0e10cSrcweir 		S_START,		// analyse first BOF
48cdf0e10cSrcweir 		S_WK1,			// in WK1-Stream
49cdf0e10cSrcweir 		S_WK3,			// in WK3-Section
50cdf0e10cSrcweir 		S_WK4,			// ...
51cdf0e10cSrcweir 		S_FM3,			// ...
52cdf0e10cSrcweir 		S_END			// Import finished
53cdf0e10cSrcweir 	};
54cdf0e10cSrcweir 
55cdf0e10cSrcweir 	sal_uInt16			nOp;
56cdf0e10cSrcweir 	sal_uInt16			nSubType;
57cdf0e10cSrcweir 	sal_uInt16			nRecLen;
58cdf0e10cSrcweir 	sal_uInt32			nNextRec = 0UL;
59cdf0e10cSrcweir 	FltError		eRet = eERR_OK;
60cdf0e10cSrcweir //	ScFormulaCell	*pLastFormCell;
61cdf0e10cSrcweir 
62cdf0e10cSrcweir 	STATE			eAkt = S_START;
63cdf0e10cSrcweir 
64cdf0e10cSrcweir 	nTab = 0;
65cdf0e10cSrcweir 	nExtTab = -2;
66cdf0e10cSrcweir 
67cdf0e10cSrcweir 	pIn->Seek( nNextRec );
68cdf0e10cSrcweir 
69cdf0e10cSrcweir 	// Progressbar starten
70cdf0e10cSrcweir     ScfStreamProgressBar aPrgrsBar( *pIn, pD->GetDocumentShell() );
71cdf0e10cSrcweir 
72cdf0e10cSrcweir 	while( eAkt != S_END )
73cdf0e10cSrcweir 	{
74cdf0e10cSrcweir 		*pIn >> nOp >> nRecLen;
75cdf0e10cSrcweir 
763ee7c2dbSArmin Le Grand 		if( pIn->IsEof() || nNextRec > SAL_MAX_UINT32 - nRecLen - 4 )
77cdf0e10cSrcweir 			eAkt = S_END;
78cdf0e10cSrcweir 
79cdf0e10cSrcweir 		nNextRec += nRecLen + 4;
80cdf0e10cSrcweir 
81cdf0e10cSrcweir 		switch( eAkt )
82cdf0e10cSrcweir 		{
83cdf0e10cSrcweir 			// -----------------------------------------------------------
84cdf0e10cSrcweir 			case S_START:											// S_START
85cdf0e10cSrcweir 			if( nOp )
86cdf0e10cSrcweir 			{
87cdf0e10cSrcweir 				eRet = SCERR_IMPORT_UNKNOWN_WK;
88cdf0e10cSrcweir 				eAkt = S_END;
89cdf0e10cSrcweir 			}
90cdf0e10cSrcweir 			else
91cdf0e10cSrcweir 			{
92cdf0e10cSrcweir 				if( nRecLen > 2 )
93cdf0e10cSrcweir 				{
94cdf0e10cSrcweir 					Bof();
95cdf0e10cSrcweir 					switch( pLotusRoot->eFirstType )
96cdf0e10cSrcweir 					{
97cdf0e10cSrcweir 						case Lotus_WK1:	eAkt = S_WK1; break;
98cdf0e10cSrcweir 						case Lotus_WK3:	eAkt = S_WK3; break;
99cdf0e10cSrcweir 						case Lotus_WK4:	eAkt = S_WK4; break;
100cdf0e10cSrcweir 						case Lotus_FM3: eAkt = S_FM3; break;
101cdf0e10cSrcweir 						default:
102cdf0e10cSrcweir 						eRet = SCERR_IMPORT_UNKNOWN_WK;
103cdf0e10cSrcweir 						eAkt = S_END;
104cdf0e10cSrcweir 					}
105cdf0e10cSrcweir 				}
106cdf0e10cSrcweir 				else
107cdf0e10cSrcweir 				{
108cdf0e10cSrcweir 					eAkt = S_END;	// hier kommt wat fuer <= WK1 hinne!
109cdf0e10cSrcweir 					eRet = 0xFFFFFFFF;
110cdf0e10cSrcweir 				}
111cdf0e10cSrcweir 			}
112cdf0e10cSrcweir 			break;
113cdf0e10cSrcweir 			// -----------------------------------------------------------
114cdf0e10cSrcweir 			case S_WK1:												// S_WK1
115cdf0e10cSrcweir 			break;
116cdf0e10cSrcweir 			// -----------------------------------------------------------
117cdf0e10cSrcweir 			case S_WK3:												// S_WK3
118cdf0e10cSrcweir 			case S_WK4:												// S_WK4
119cdf0e10cSrcweir 			switch( nOp )
120cdf0e10cSrcweir 			{
121cdf0e10cSrcweir 				case 0x0001:							// EOF
122cdf0e10cSrcweir 				eAkt = S_FM3;
123cdf0e10cSrcweir 				nTab++;
124cdf0e10cSrcweir 				break;
125cdf0e10cSrcweir 
126cdf0e10cSrcweir 				case 0x0002:							// PASSWORD
127cdf0e10cSrcweir 				eRet = eERR_FILEPASSWD;
128cdf0e10cSrcweir 				eAkt = S_END;
129cdf0e10cSrcweir 				break;
130cdf0e10cSrcweir 
131cdf0e10cSrcweir 				case 0x0007:							// COLUMNWIDTH
132cdf0e10cSrcweir 				Columnwidth( nRecLen );
133cdf0e10cSrcweir 				break;
134cdf0e10cSrcweir 
135cdf0e10cSrcweir 				case 0x0008:							// HIDDENCOLUMN
136cdf0e10cSrcweir 				Hiddencolumn( nRecLen );
137cdf0e10cSrcweir 				break;
138cdf0e10cSrcweir 
139cdf0e10cSrcweir 				case 0x0009:							// USERRANGE
140cdf0e10cSrcweir 				Userrange();
141cdf0e10cSrcweir 				break;
142cdf0e10cSrcweir 
143cdf0e10cSrcweir 				case 0x0013:							// FORMAT
144cdf0e10cSrcweir 
145cdf0e10cSrcweir 				break;
146cdf0e10cSrcweir 				case 0x0014:							// ERRCELL
147cdf0e10cSrcweir 				Errcell();
148cdf0e10cSrcweir 				break;
149cdf0e10cSrcweir 
150cdf0e10cSrcweir 				case 0x0015:							// NACELL
151cdf0e10cSrcweir 				Nacell();
152cdf0e10cSrcweir 				break;
153cdf0e10cSrcweir 
154cdf0e10cSrcweir 				case 0x0016:							// LABELCELL
155cdf0e10cSrcweir 				Labelcell();
156cdf0e10cSrcweir 				break;
157cdf0e10cSrcweir 
158cdf0e10cSrcweir 				case 0x0017:							// NUMBERCELL
159cdf0e10cSrcweir 				Numbercell();
160cdf0e10cSrcweir 				break;
161cdf0e10cSrcweir 
162cdf0e10cSrcweir 				case 0x0018:							// SMALLNUMCELL
163cdf0e10cSrcweir 				Smallnumcell();
164cdf0e10cSrcweir 				break;
165cdf0e10cSrcweir 
166cdf0e10cSrcweir 				case 0x0019:							// FORMULACELL
167cdf0e10cSrcweir 				Formulacell( nRecLen );
168cdf0e10cSrcweir 				break;
169cdf0e10cSrcweir 
170cdf0e10cSrcweir 				case 0x001b:							// extended attributes
1713ee7c2dbSArmin Le Grand                 if (nRecLen > 2)
1723ee7c2dbSArmin Le Grand                 {
1733ee7c2dbSArmin Le Grand                     Read( nSubType );
1743ee7c2dbSArmin Le Grand                     nRecLen -= 2;
1753ee7c2dbSArmin Le Grand                     switch( nSubType )
1763ee7c2dbSArmin Le Grand                     {
1773ee7c2dbSArmin Le Grand                         case 2007:                      // ROW PRESENTATION
1783ee7c2dbSArmin Le Grand                             RowPresentation( nRecLen );
1793ee7c2dbSArmin Le Grand                             break;
1803ee7c2dbSArmin Le Grand 
1813ee7c2dbSArmin Le Grand                         case 14000:                     // NAMED SHEET
1823ee7c2dbSArmin Le Grand                             NamedSheet();
1833ee7c2dbSArmin Le Grand                             break;
1843ee7c2dbSArmin Le Grand                     }
1853ee7c2dbSArmin Le Grand                 }
1863ee7c2dbSArmin Le Grand                 else
1873ee7c2dbSArmin Le Grand                 {
1883ee7c2dbSArmin Le Grand                     eRet = eERR_FORMAT;
1893ee7c2dbSArmin Le Grand                     eAkt = S_END;
1903ee7c2dbSArmin Le Grand                 }
191cdf0e10cSrcweir 			}
192cdf0e10cSrcweir 
193cdf0e10cSrcweir 			break;
194cdf0e10cSrcweir 			// -----------------------------------------------------------
195cdf0e10cSrcweir 			case S_FM3:												// S_FM3
196cdf0e10cSrcweir 			break;
197cdf0e10cSrcweir 			// -----------------------------------------------------------
198cdf0e10cSrcweir 			case S_END:												// S_END
199cdf0e10cSrcweir 			break;
200cdf0e10cSrcweir 		}
201cdf0e10cSrcweir 
202cdf0e10cSrcweir 		DBG_ASSERT( nNextRec >= pIn->Tell(),
203cdf0e10cSrcweir 			"*ImportLotus::Read(): Etwas zu gierig..." );
204cdf0e10cSrcweir 
205cdf0e10cSrcweir 		pIn->Seek( nNextRec );
206cdf0e10cSrcweir 		aPrgrsBar.Progress();
207cdf0e10cSrcweir 	}
208cdf0e10cSrcweir 
209cdf0e10cSrcweir 	// duemmliche Namen eliminieren
210cdf0e10cSrcweir 	SCTAB		nTabs = pD->GetTableCount();
211cdf0e10cSrcweir 	SCTAB		nCnt;
212cdf0e10cSrcweir 	String		aTabName;
213cdf0e10cSrcweir 	String		aBaseName;
214cdf0e10cSrcweir 	String		aRef( RTL_CONSTASCII_USTRINGPARAM( "temp" ) );
215cdf0e10cSrcweir 	if( nTabs != 0 )
216cdf0e10cSrcweir 	{
217cdf0e10cSrcweir 		if( nTabs > 1 )
218cdf0e10cSrcweir 		{
219cdf0e10cSrcweir 			pD->GetName( 0, aBaseName );
220cdf0e10cSrcweir 			aBaseName.Erase( aBaseName.Len() - 1 );
221cdf0e10cSrcweir 		}
222cdf0e10cSrcweir 		for( nCnt = 1 ; nCnt < nTabs ; nCnt++ )
223cdf0e10cSrcweir 		{
224cdf0e10cSrcweir 			DBG_ASSERT( pD->HasTable( nCnt ),
225cdf0e10cSrcweir 				"-ImportLotus::Read(): Wo ist meine Tabelle?!" );
226cdf0e10cSrcweir 			pD->GetName( nCnt, aTabName );
227cdf0e10cSrcweir 			if( aTabName == aRef )
228cdf0e10cSrcweir 			{
229cdf0e10cSrcweir 				aTabName = aBaseName;
230cdf0e10cSrcweir 				pD->CreateValidTabName( aTabName );
231cdf0e10cSrcweir 				pD->RenameTab( nCnt, aTabName );
232cdf0e10cSrcweir 			}
233cdf0e10cSrcweir 		}
234cdf0e10cSrcweir 	}
235cdf0e10cSrcweir 
236cdf0e10cSrcweir 	pD->CalcAfterLoad();
237cdf0e10cSrcweir 
238cdf0e10cSrcweir 	return eRet;
239cdf0e10cSrcweir }
240cdf0e10cSrcweir 
241cdf0e10cSrcweir 
Read(SvStream & rIn)242cdf0e10cSrcweir FltError ImportLotus::Read( SvStream& rIn )
243cdf0e10cSrcweir {
244cdf0e10cSrcweir 	pIn = &rIn;
245cdf0e10cSrcweir 
246cdf0e10cSrcweir 	sal_Bool			bRead = sal_True;
247cdf0e10cSrcweir 	sal_uInt16			nOp;
248cdf0e10cSrcweir 	sal_uInt16			nRecLen;
249cdf0e10cSrcweir 	sal_uInt32			nNextRec = 0UL;
250cdf0e10cSrcweir 	FltError		eRet = eERR_OK;
251cdf0e10cSrcweir 
252cdf0e10cSrcweir 	nTab = 0;
253cdf0e10cSrcweir 	nExtTab = -1;
254cdf0e10cSrcweir 
255cdf0e10cSrcweir 	pIn->Seek( nNextRec );
256cdf0e10cSrcweir 
257cdf0e10cSrcweir 	// Progressbar starten
258cdf0e10cSrcweir     ScfStreamProgressBar aPrgrsBar( *pIn, pD->GetDocumentShell() );
259cdf0e10cSrcweir 
260cdf0e10cSrcweir 	while( bRead )
261cdf0e10cSrcweir 	{
262cdf0e10cSrcweir 		*pIn >> nOp >> nRecLen;
263cdf0e10cSrcweir 
2643ee7c2dbSArmin Le Grand 		if( pIn->IsEof() || nNextRec > SAL_MAX_UINT32 - nRecLen - 4 )
265cdf0e10cSrcweir 			bRead = sal_False;
266cdf0e10cSrcweir 		else
267cdf0e10cSrcweir 		{
268cdf0e10cSrcweir 			nNextRec += nRecLen + 4;
269cdf0e10cSrcweir 
270cdf0e10cSrcweir 			switch( nOp )
271cdf0e10cSrcweir 			{
272cdf0e10cSrcweir 				case 0x0000:							// BOF
273cdf0e10cSrcweir 				if( nRecLen != 26 || !BofFm3() )
274cdf0e10cSrcweir 				{
275cdf0e10cSrcweir 					bRead = sal_False;
276cdf0e10cSrcweir 					eRet = eERR_FORMAT;
277cdf0e10cSrcweir 				}
278cdf0e10cSrcweir 				break;
279cdf0e10cSrcweir 
280cdf0e10cSrcweir 				case 0x0001:							// EOF
281cdf0e10cSrcweir 					bRead = sal_False;
282cdf0e10cSrcweir 					DBG_ASSERT( nTab == 0,
283cdf0e10cSrcweir 						"-ImportLotus::Read( SvStream& ): Zweimal EOF nicht erlaubt" );
284cdf0e10cSrcweir 					nTab++;
285cdf0e10cSrcweir 				break;
286cdf0e10cSrcweir 
287cdf0e10cSrcweir 				case 174:								// FONT_FACE
288cdf0e10cSrcweir 					Font_Face();
289cdf0e10cSrcweir 				break;
290cdf0e10cSrcweir 
291cdf0e10cSrcweir 				case 176:								// FONT_TYPE
292cdf0e10cSrcweir 					Font_Type();
293cdf0e10cSrcweir 				break;
294cdf0e10cSrcweir 
295cdf0e10cSrcweir 				case 177:								// FONT_YSIZE
296cdf0e10cSrcweir 					Font_Ysize();
297cdf0e10cSrcweir 				break;
298cdf0e10cSrcweir 
299cdf0e10cSrcweir 				case 195:
300cdf0e10cSrcweir 					if( nExtTab >= 0 )
301cdf0e10cSrcweir 						pLotusRoot->pAttrTable->Apply( ( SCTAB ) nExtTab );
302cdf0e10cSrcweir 					nExtTab++;
303cdf0e10cSrcweir 					break;
304cdf0e10cSrcweir 				case 197:
305cdf0e10cSrcweir 					_Row( nRecLen );
306cdf0e10cSrcweir 				break;
307cdf0e10cSrcweir 			}
308cdf0e10cSrcweir 
309cdf0e10cSrcweir 			DBG_ASSERT( nNextRec >= pIn->Tell(),
310cdf0e10cSrcweir 				"*ImportLotus::Read(): Etwas zu gierig..." );
311cdf0e10cSrcweir 			pIn->Seek( nNextRec );
312cdf0e10cSrcweir 			aPrgrsBar.Progress();
313cdf0e10cSrcweir 		}
314cdf0e10cSrcweir 	}
315cdf0e10cSrcweir 
316cdf0e10cSrcweir 	pLotusRoot->pAttrTable->Apply( ( SCTAB ) nExtTab );
317cdf0e10cSrcweir 
318cdf0e10cSrcweir 	return eRet;
319cdf0e10cSrcweir }
320cdf0e10cSrcweir 
321cdf0e10cSrcweir 
322cdf0e10cSrcweir 
323