/*************************************************************************
 *
 *  $RCSfile: lotpar.cxx,v $
 *
 *  $Revision: 1.1.1.1 $
 *
 *  last change: $Author: hr $ $Date: 2000/09/18 17:14:56 $
 *
 *  The Contents of this file are made available subject to the terms of
 *  either of the following licenses
 *
 *         - GNU Lesser General Public License Version 2.1
 *         - Sun Industry Standards Source License Version 1.1
 *
 *  Sun Microsystems Inc., October, 2000
 *
 *  GNU Lesser General Public License Version 2.1
 *  =============================================
 *  Copyright 2000 by Sun Microsystems, Inc.
 *  901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License version 2.1, as published by the Free Software Foundation.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *  MA  02111-1307  USA
 *
 *
 *  Sun Industry Standards Source License Version 1.1
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.1 (the "License"); You may not use this file
 *  except in compliance with the License. You may obtain a copy of the
 *  License at http://www.openoffice.org/license.html.
 *
 *  Software provided under this License is provided on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *  The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *  Copyright: 2000 by Sun Microsystems, Inc.
 *
 *  All Rights Reserved.
 *
 *  Contributor(s): _______________________________________
 *
 *
 ************************************************************************/

#ifdef PRECOMPILED
#include "filt_pch.hxx"
#endif

#pragma hdrstop

#ifndef _ERRHDL_HXX
#include <errhdl.hxx>
#endif
#ifndef _DOC_HXX
#include <doc.hxx>
#endif
#ifndef _SWSWERROR_H
#include <swerror.h>
#endif
#ifndef _FLTGLBLS_HXX
#include <fltglbls.hxx>
#endif
#ifndef _FLTINI_HXX
#include <fltini.hxx>
#endif
#ifndef _LOTPAR_HXX
#include <lotpar.hxx>
#endif

LotGlob *pLotGlob = NULL;





SwLotusParser::SwLotusParser( SwDoc &rD, const SwPaM & rCrsr,
								SvStream& rInInit, int bReadNewDoc,
								CharSet eQ )
	: bNewDoc( bReadNewDoc )
{
	eQuellChar = eQ;
	pIn = &rInInit;
	pLotGlob = new LotGlob( rD, rCrsr );

	nReadBuffSize = 2048;
	pReadBuff = new char[ nReadBuffSize ];

//	aColRowBuff.SetDefWidth( ( USHORT ) ( 9192 ) );	// 4 Zeichen Standardbreite
}

SwLotusParser::~SwLotusParser()
{
	delete[] pReadBuff;
	delete pLotGlob;
	pLotGlob = NULL;
}


ULONG SwLotusParser::CallParser()
{
	USHORT nMinRow = ( USHORT ) ReadFilterFlags( "EXCELMINROW" );
	USHORT nMaxRow = ( USHORT ) ReadFilterFlags( "EXCELMAXROW" );
	USHORT nMinCol = ( USHORT ) ReadFilterFlags( "EXCELMINCOL" );
	USHORT nMaxCol = ( USHORT ) ReadFilterFlags( "EXCELMAXCOL" );

	USHORT nAnzNodes = 65000U - pLotGlob->pD->GetNodes().Count();

	if( nMaxRow < nMinRow )
	{
		USHORT nTemp = nMinRow;
		nMinRow = nMaxRow;
		nMaxRow = nTemp;
	}

	if( nMaxCol < nMinCol )
	{
		USHORT nTemp = nMinCol;
		nMinCol = nMaxCol;
		nMaxCol = nTemp;
	}

	if( nMaxRow - nMinRow == 0 )
		nMaxRow = nMinRow + 30;		// Default bei 0 Rows

	if( nMaxCol - nMinCol == 0 )
		nMaxCol = nMinCol + 15;		// Default bei 0 Cols

	if( nAnzNodes < ( nMaxRow - nMinRow ) * ( nMaxCol - nMinCol ) * 3 )
		return ERR_EXCLOT_WRONG_RANGE;

	pLotGlob->SetRange( nMinCol, nMaxCol, nMinRow, nMaxRow ); // Default-Einstellung

	Parse();

	return 0;	// kein Fehler
}


ULONG LotusReader::Read( SwDoc &rDoc, SwPaM &rPam,
					const String & /* FileName, falls benoetigt wird */ )
{
	ULONG nRet;
	if( !pStrm )
	{
		ASSERT( FALSE, "Lotus-Read ohne Stream" );
		nRet = ERR_SWG_READ_ERROR;
	}
	else
	{
		SwLotusParser* pParser = new SwLotusParser( rDoc, rPam, *pStrm,
													!bInsertMode, eCodeSet );
		nRet = pParser->CallParser();		// 0 == kein Fehler aufgetreten
		delete pParser;
	}

	return nRet;
}

/*************************************************************************

	  Source Code Control System - Header

	  $Header: /cvs/oo/sw/sw/source/filter/lotus/lotpar.cxx,v 1.1.1.1 2000/09/18 17:14:56 hr Exp $

	  Source Code Control System - Update

	  $Log: lotpar.cxx,v $
	  Revision 1.1.1.1  2000/09/18 17:14:56  hr
	  initial import
	
	  Revision 1.23  2000/09/18 16:04:49  willem.vandorp
	  OpenOffice header added.
	
	  Revision 1.22  2000/05/15 16:37:07  jp
	  Changes for Unicode
	
	  Revision 1.21  2000/05/15 10:12:32  os
	  UNICODE - ReadFilterFlags

	  Revision 1.20  2000/05/09 11:11:14  os
	  UNICODE

	  Revision 1.19  1998/07/23 09:12:42  JP
	  Task #52654#: Einfuegen Doc nicht mit einer CrsrShell sondern mit einen PaM


	  Rev 1.18   23 Jul 1998 11:12:42   JP
   Task #52654#: Einfuegen Doc nicht mit einer CrsrShell sondern mit einen PaM

	  Rev 1.17   26 Nov 1997 14:21:56   MA
   headerfiles

	  Rev 1.16   03 Nov 1997 14:09:32   MA
   precomp entfernt

	  Rev 1.15   04 Sep 1997 12:38:20   JP
   Umstellungen fuer FilterDetection im SwModule und SwDLL

	  Rev 1.14   29 Oct 1996 12:16:44   JP
   am Doc ist das NodesArray nur noch ueber Get..() zugaenglich

	  Rev 1.13   28 Jun 1996 13:26:18   MA
   includes

	  Rev 1.12   14 Dec 1995 23:04:26   JP
   Filter Umstellung: ErrorHandling und Read/Write-Parameter

	  Rev 1.11   30 Nov 1995 21:22:26   JP
   ReadFilterFlags: StringParameter zu char*

	  Rev 1.10   24 Nov 1995 17:25:00   OM
   PCH->PRECOMPILED

	  Rev 1.9   10 Oct 1995 12:11:22   JP
   Umstellung Reader - FilterDetection

	  Rev 1.8   30 Sep 1995 21:23:32   JP
   Charset am Reader setzen

	  Rev 1.7   21 Sep 1995 15:54:56   GT
	*	SwLotusParser::CallParser(): Begrenzer aus ini-File

	  Rev 1.6   17 Jul 1995 18:19:46   JP
   CallParser: returne die Fehlernummer oder 0

	  Rev 1.5   14 Jul 1995 20:34:20   JP
   Optimiert, ueberfluessige Methoden entfernt / auskommentiert

	  Rev 1.4   08 Jun 1995 17:22:48   ER
   zweites Filtersegment

	  Rev 1.3   04 Apr 1995 17:49:48   JP
   Read ohne Stream ohne Absturz

	  Rev 1.2   02 Mar 1995 19:50:54   GT
   Lotus Import, Parse-Automat

	  Rev 1.1   01 Mar 1995 11:54:38   GT
   Abhaengigkeiten zu Excel-Aenderungen entfernt

	  Rev 1.0   01 Mar 1995 11:04:46   GT
   Initial revision.

*************************************************************************/



