xref: /aoo42x/main/sc/source/ui/inc/impex.hxx (revision cdf0e10c)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir #ifndef SC_IMPEX_HXX
29*cdf0e10cSrcweir #define SC_IMPEX_HXX
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include <osl/endian.h>
32*cdf0e10cSrcweir #include <sot/exchange.hxx>
33*cdf0e10cSrcweir #include "global.hxx"
34*cdf0e10cSrcweir #include "address.hxx"
35*cdf0e10cSrcweir 
36*cdf0e10cSrcweir class ScDocShell;
37*cdf0e10cSrcweir class ScDocument;
38*cdf0e10cSrcweir class SvStream;
39*cdf0e10cSrcweir class SfxMedium;
40*cdf0e10cSrcweir class ScAsciiOptions;
41*cdf0e10cSrcweir 
42*cdf0e10cSrcweir struct ScExportTextOptions
43*cdf0e10cSrcweir {
44*cdf0e10cSrcweir     enum NewlineConversion { ToSystem, ToSpace, None };
45*cdf0e10cSrcweir     ScExportTextOptions( NewlineConversion eNewlineConversion = ToSystem, sal_Unicode cSeparatorConvertTo = 0, bool bAddQuotes = false ) :
46*cdf0e10cSrcweir         meNewlineConversion( eNewlineConversion ), mcSeparatorConvertTo( cSeparatorConvertTo ), mbAddQuotes( bAddQuotes ) {}
47*cdf0e10cSrcweir 
48*cdf0e10cSrcweir     NewlineConversion meNewlineConversion;
49*cdf0e10cSrcweir     sal_Unicode mcSeparatorConvertTo;   // Convert separator to this character
50*cdf0e10cSrcweir     bool mbAddQuotes;
51*cdf0e10cSrcweir };
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir class ScImportExport
54*cdf0e10cSrcweir {
55*cdf0e10cSrcweir 	ScDocShell* pDocSh;
56*cdf0e10cSrcweir 	ScDocument* pDoc;
57*cdf0e10cSrcweir 	ScDocument* pUndoDoc;
58*cdf0e10cSrcweir 	ScRange     aRange;
59*cdf0e10cSrcweir 	String		aStreamPath;
60*cdf0e10cSrcweir     String      aNonConvertibleChars;
61*cdf0e10cSrcweir 	sal_uLong		nSizeLimit;
62*cdf0e10cSrcweir 	sal_Unicode	cSep;					// Separator
63*cdf0e10cSrcweir 	sal_Unicode	cStr;					// String Delimiter
64*cdf0e10cSrcweir 	sal_Bool		bFormulas;				// Formeln im Text?
65*cdf0e10cSrcweir 	sal_Bool		bIncludeFiltered;		// include filtered rows? (default true)
66*cdf0e10cSrcweir 	sal_Bool		bAll;					// keine Selektion
67*cdf0e10cSrcweir 	sal_Bool		bSingle;				// Einfachselektion
68*cdf0e10cSrcweir 	sal_Bool		bUndo;					// Mit Undo?
69*cdf0e10cSrcweir 	sal_Bool		bOverflow;				// zuviele Zeilen/Spalten
70*cdf0e10cSrcweir     bool        mbApi;
71*cdf0e10cSrcweir     ScExportTextOptions mExportTextOptions;
72*cdf0e10cSrcweir 
73*cdf0e10cSrcweir 	ScAsciiOptions*	pExtOptions;		// erweiterte Optionen
74*cdf0e10cSrcweir 
75*cdf0e10cSrcweir 	sal_Bool StartPaste();					// Protect-Check, Undo einrichten
76*cdf0e10cSrcweir 	void EndPaste();					// Undo/Redo-Aktionen, Repaint
77*cdf0e10cSrcweir 	sal_Bool Doc2Text( SvStream& );
78*cdf0e10cSrcweir 	sal_Bool Text2Doc( SvStream& );
79*cdf0e10cSrcweir 	sal_Bool Doc2Sylk( SvStream& );
80*cdf0e10cSrcweir 	sal_Bool Sylk2Doc( SvStream& );
81*cdf0e10cSrcweir     sal_Bool Doc2HTML( SvStream&, const String& );
82*cdf0e10cSrcweir 	sal_Bool Doc2RTF( SvStream& );
83*cdf0e10cSrcweir 	sal_Bool Doc2Dif( SvStream& );
84*cdf0e10cSrcweir 	sal_Bool Dif2Doc( SvStream& );
85*cdf0e10cSrcweir 	sal_Bool ExtText2Doc( SvStream& );		// mit pExtOptions
86*cdf0e10cSrcweir     sal_Bool RTF2Doc( SvStream&, const String& rBaseURL );
87*cdf0e10cSrcweir     sal_Bool HTML2Doc( SvStream&, const String& rBaseURL );
88*cdf0e10cSrcweir 
89*cdf0e10cSrcweir public:
90*cdf0e10cSrcweir 	ScImportExport( ScDocument* );					// Gesamtdokument
91*cdf0e10cSrcweir 	ScImportExport( ScDocument*, const String& );	// Bereichs/Zellangabe
92*cdf0e10cSrcweir 	ScImportExport( ScDocument*, const ScAddress& );
93*cdf0e10cSrcweir 	ScImportExport( ScDocument*, const ScRange& );
94*cdf0e10cSrcweir    ~ScImportExport();
95*cdf0e10cSrcweir 
96*cdf0e10cSrcweir 	void SetExtOptions( const ScAsciiOptions& rOpt );
97*cdf0e10cSrcweir 
98*cdf0e10cSrcweir 	sal_Bool IsDoubleRef() const { return sal_Bool( !( bAll || bSingle ) ); }
99*cdf0e10cSrcweir 	sal_Bool IsSingleRef() const { return bSingle; }
100*cdf0e10cSrcweir 	sal_Bool IsNoRef() const	 { return bAll;    }
101*cdf0e10cSrcweir 	sal_Bool IsRef() const	 	 { return sal_Bool( !bAll ); }
102*cdf0e10cSrcweir 
103*cdf0e10cSrcweir 	const ScRange& GetRange() const { return aRange; }
104*cdf0e10cSrcweir 
105*cdf0e10cSrcweir 	sal_Bool IsUndo() const		 { return bUndo; }
106*cdf0e10cSrcweir 	void SetUndo( sal_Bool b )	 { bUndo = b;	 }
107*cdf0e10cSrcweir 
108*cdf0e10cSrcweir 	static sal_Bool  IsFormatSupported( sal_uLong nFormat );
109*cdf0e10cSrcweir 	static const sal_Unicode* ScanNextFieldFromString( const sal_Unicode* p,
110*cdf0e10cSrcweir 			String& rField, sal_Unicode cStr, const sal_Unicode* pSeps, bool bMergeSeps, bool& rbIsQuoted );
111*cdf0e10cSrcweir 	static	void	WriteUnicodeOrByteString( SvStream& rStrm, const String& rString, sal_Bool bZero = sal_False );
112*cdf0e10cSrcweir 	static	void	WriteUnicodeOrByteEndl( SvStream& rStrm );
113*cdf0e10cSrcweir 	static	inline	sal_Bool	IsEndianSwap( const SvStream& rStrm );
114*cdf0e10cSrcweir 
115*cdf0e10cSrcweir     //! only if stream is only used in own (!) memory
116*cdf0e10cSrcweir     static  inline  void    SetNoEndianSwap( SvStream& rStrm );
117*cdf0e10cSrcweir 
118*cdf0e10cSrcweir 	sal_Unicode GetSeparator() const { return cSep; }
119*cdf0e10cSrcweir 	void SetSeparator( sal_Unicode c ) { cSep = c; }
120*cdf0e10cSrcweir 	sal_Unicode GetDelimiter() const { return cStr; }
121*cdf0e10cSrcweir 	void SetDelimiter( sal_Unicode c ) { cStr = c; }
122*cdf0e10cSrcweir 	sal_Bool IsFormulas() const { return bFormulas; }
123*cdf0e10cSrcweir 	void SetFormulas( sal_Bool b ) { bFormulas = b; }
124*cdf0e10cSrcweir 	sal_Bool IsIncludeFiltered() const { return bIncludeFiltered; }
125*cdf0e10cSrcweir 	void SetIncludeFiltered( sal_Bool b ) { bIncludeFiltered = b; }
126*cdf0e10cSrcweir 
127*cdf0e10cSrcweir 	void SetSizeLimit( sal_uLong nNew ) { nSizeLimit = nNew; }	// momentan nur fuer Ascii
128*cdf0e10cSrcweir 
129*cdf0e10cSrcweir 	void			SetStreamPath( const String& rPath ) { aStreamPath = rPath; }
130*cdf0e10cSrcweir 	const String&	GetStreamPath() const { return aStreamPath; }
131*cdf0e10cSrcweir 
132*cdf0e10cSrcweir     sal_Bool ImportString( const ::rtl::OUString&, sal_uLong=FORMAT_STRING );
133*cdf0e10cSrcweir 	sal_Bool ExportString( ::rtl::OUString&, sal_uLong=FORMAT_STRING );
134*cdf0e10cSrcweir 	sal_Bool ExportByteString( ByteString&, rtl_TextEncoding, sal_uLong=FORMAT_STRING );
135*cdf0e10cSrcweir 
136*cdf0e10cSrcweir     sal_Bool ImportStream( SvStream&, const String& rBaseURL, sal_uLong=FORMAT_STRING );
137*cdf0e10cSrcweir     sal_Bool ExportStream( SvStream&, const String& rBaseURL, sal_uLong=FORMAT_STRING );
138*cdf0e10cSrcweir 
139*cdf0e10cSrcweir 	sal_Bool ImportData( const String& rMimeType,
140*cdf0e10cSrcweir 					 const ::com::sun::star::uno::Any & rValue );
141*cdf0e10cSrcweir     sal_Bool ExportData( const String& rMimeType,
142*cdf0e10cSrcweir 					 ::com::sun::star::uno::Any & rValue  );
143*cdf0e10cSrcweir 
144*cdf0e10cSrcweir 	sal_Bool IsOverflow() const	{ return bOverflow; }		// nach dem Importieren
145*cdf0e10cSrcweir 
146*cdf0e10cSrcweir     const String& GetNonConvertibleChars() const { return aNonConvertibleChars; }
147*cdf0e10cSrcweir 
148*cdf0e10cSrcweir     bool IsApi() const { return mbApi; }
149*cdf0e10cSrcweir     void SetApi( bool bApi ) { mbApi = bApi; }
150*cdf0e10cSrcweir     const ScExportTextOptions& GetExportTextOptions() { return mExportTextOptions; }
151*cdf0e10cSrcweir     void SetExportTextOptions( const ScExportTextOptions& options ) { mExportTextOptions = options; }
152*cdf0e10cSrcweir };
153*cdf0e10cSrcweir 
154*cdf0e10cSrcweir 
155*cdf0e10cSrcweir // static
156*cdf0e10cSrcweir inline sal_Bool ScImportExport::IsEndianSwap( const SvStream& rStrm )
157*cdf0e10cSrcweir {
158*cdf0e10cSrcweir #ifdef OSL_BIGENDIAN
159*cdf0e10cSrcweir 	return rStrm.GetNumberFormatInt() != NUMBERFORMAT_INT_BIGENDIAN;
160*cdf0e10cSrcweir #else
161*cdf0e10cSrcweir 	return rStrm.GetNumberFormatInt() != NUMBERFORMAT_INT_LITTLEENDIAN;
162*cdf0e10cSrcweir #endif
163*cdf0e10cSrcweir }
164*cdf0e10cSrcweir 
165*cdf0e10cSrcweir // static
166*cdf0e10cSrcweir inline void ScImportExport::SetNoEndianSwap( SvStream& rStrm )
167*cdf0e10cSrcweir {
168*cdf0e10cSrcweir #ifdef OSL_BIGENDIAN
169*cdf0e10cSrcweir     rStrm.SetNumberFormatInt( NUMBERFORMAT_INT_BIGENDIAN );
170*cdf0e10cSrcweir #else
171*cdf0e10cSrcweir     rStrm.SetNumberFormatInt( NUMBERFORMAT_INT_LITTLEENDIAN );
172*cdf0e10cSrcweir #endif
173*cdf0e10cSrcweir }
174*cdf0e10cSrcweir 
175*cdf0e10cSrcweir 
176*cdf0e10cSrcweir // Helper class for importing clipboard strings as streams.
177*cdf0e10cSrcweir class ScImportStringStream : public SvMemoryStream
178*cdf0e10cSrcweir {
179*cdf0e10cSrcweir public:
180*cdf0e10cSrcweir     ScImportStringStream( const ::rtl::OUString rStr )
181*cdf0e10cSrcweir         : SvMemoryStream( (void*)rStr.getStr(),
182*cdf0e10cSrcweir                 rStr.getLength() * sizeof(sal_Unicode), STREAM_READ)
183*cdf0e10cSrcweir     {
184*cdf0e10cSrcweir         SetStreamCharSet( RTL_TEXTENCODING_UNICODE );
185*cdf0e10cSrcweir         SetEndianSwap( sal_False );
186*cdf0e10cSrcweir     }
187*cdf0e10cSrcweir };
188*cdf0e10cSrcweir 
189*cdf0e10cSrcweir 
190*cdf0e10cSrcweir #endif
191*cdf0e10cSrcweir 
192