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