xref: /aoo42x/main/sc/source/ui/inc/impex.hxx (revision 38d50f7b)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef SC_IMPEX_HXX
25 #define SC_IMPEX_HXX
26 
27 #include <osl/endian.h>
28 #include <sot/exchange.hxx>
29 #include "global.hxx"
30 #include "address.hxx"
31 
32 class ScDocShell;
33 class ScDocument;
34 class SvStream;
35 class SfxMedium;
36 class ScAsciiOptions;
37 
38 struct ScExportTextOptions
39 {
40     enum NewlineConversion { ToSystem, ToSpace, None };
ScExportTextOptionsScExportTextOptions41     ScExportTextOptions( NewlineConversion eNewlineConversion = ToSystem, sal_Unicode cSeparatorConvertTo = 0, bool bAddQuotes = false ) :
42         meNewlineConversion( eNewlineConversion ), mcSeparatorConvertTo( cSeparatorConvertTo ), mbAddQuotes( bAddQuotes ) {}
43 
44     NewlineConversion meNewlineConversion;
45     sal_Unicode mcSeparatorConvertTo;   // Convert separator to this character
46     bool mbAddQuotes;
47 };
48 
49 class ScImportExport
50 {
51 	ScDocShell* pDocSh;
52 	ScDocument* pDoc;
53 	ScDocument* pUndoDoc;
54 	ScRange     aRange;
55 	String		aStreamPath;
56     String      aNonConvertibleChars;
57 	sal_uLong		nSizeLimit;
58 	sal_Unicode	cSep;					// Separator
59 	sal_Unicode	cStr;					// String Delimiter
60 	sal_Bool		bFormulas;				// Formeln im Text?
61 	sal_Bool		bIncludeFiltered;		// include filtered rows? (default true)
62 	sal_Bool		bAll;					// keine Selektion
63 	sal_Bool		bSingle;				// Einfachselektion
64 	sal_Bool		bUndo;					// Mit Undo?
65 	sal_Bool		bOverflow;				// zuviele Zeilen/Spalten
66     bool        mbApi;
67     ScExportTextOptions mExportTextOptions;
68 
69 	ScAsciiOptions*	pExtOptions;		// erweiterte Optionen
70 
71 	sal_Bool StartPaste();					// Protect-Check, Undo einrichten
72 	void EndPaste();					// Undo/Redo-Aktionen, Repaint
73 	sal_Bool Doc2Text( SvStream& );
74 	sal_Bool Text2Doc( SvStream& );
75 	sal_Bool Doc2Sylk( SvStream& );
76 	sal_Bool Sylk2Doc( SvStream& );
77     sal_Bool Doc2HTML( SvStream&, const String& );
78 	sal_Bool Doc2RTF( SvStream& );
79 	sal_Bool Doc2Dif( SvStream& );
80 	sal_Bool Dif2Doc( SvStream& );
81 	sal_Bool ExtText2Doc( SvStream& );		// mit pExtOptions
82     sal_Bool RTF2Doc( SvStream&, const String& rBaseURL );
83     sal_Bool HTML2Doc( SvStream&, const String& rBaseURL );
84 
85 public:
86 	ScImportExport( ScDocument* );					// Gesamtdokument
87 	ScImportExport( ScDocument*, const String& );	// Bereichs/Zellangabe
88 	ScImportExport( ScDocument*, const ScAddress& );
89 	ScImportExport( ScDocument*, const ScRange& );
90    ~ScImportExport();
91 
92 	void SetExtOptions( const ScAsciiOptions& rOpt );
93 
IsDoubleRef() const94 	sal_Bool IsDoubleRef() const { return sal_Bool( !( bAll || bSingle ) ); }
IsSingleRef() const95 	sal_Bool IsSingleRef() const { return bSingle; }
IsNoRef() const96 	sal_Bool IsNoRef() const	 { return bAll;    }
IsRef() const97 	sal_Bool IsRef() const	 	 { return sal_Bool( !bAll ); }
98 
GetRange() const99 	const ScRange& GetRange() const { return aRange; }
100 
IsUndo() const101 	sal_Bool IsUndo() const		 { return bUndo; }
SetUndo(sal_Bool b)102 	void SetUndo( sal_Bool b )	 { bUndo = b;	 }
103 
104 	static sal_Bool  IsFormatSupported( sal_uLong nFormat );
105 	static const sal_Unicode* ScanNextFieldFromString( const sal_Unicode* p,
106 			String& rField, sal_Unicode cStr, const sal_Unicode* pSeps, bool bMergeSeps, bool& rbIsQuoted );
107 	static	void	WriteUnicodeOrByteString( SvStream& rStrm, const String& rString, sal_Bool bZero = sal_False );
108 	static	void	WriteUnicodeOrByteEndl( SvStream& rStrm );
109 	static	inline	sal_Bool	IsEndianSwap( const SvStream& rStrm );
110 
111     //! only if stream is only used in own (!) memory
112     static  inline  void    SetNoEndianSwap( SvStream& rStrm );
113 
GetSeparator() const114 	sal_Unicode GetSeparator() const { return cSep; }
SetSeparator(sal_Unicode c)115 	void SetSeparator( sal_Unicode c ) { cSep = c; }
GetDelimiter() const116 	sal_Unicode GetDelimiter() const { return cStr; }
SetDelimiter(sal_Unicode c)117 	void SetDelimiter( sal_Unicode c ) { cStr = c; }
IsFormulas() const118 	sal_Bool IsFormulas() const { return bFormulas; }
SetFormulas(sal_Bool b)119 	void SetFormulas( sal_Bool b ) { bFormulas = b; }
IsIncludeFiltered() const120 	sal_Bool IsIncludeFiltered() const { return bIncludeFiltered; }
SetIncludeFiltered(sal_Bool b)121 	void SetIncludeFiltered( sal_Bool b ) { bIncludeFiltered = b; }
122 
SetSizeLimit(sal_uLong nNew)123 	void SetSizeLimit( sal_uLong nNew ) { nSizeLimit = nNew; }	// momentan nur fuer Ascii
124 
SetStreamPath(const String & rPath)125 	void			SetStreamPath( const String& rPath ) { aStreamPath = rPath; }
GetStreamPath() const126 	const String&	GetStreamPath() const { return aStreamPath; }
127 
128     sal_Bool ImportString( const ::rtl::OUString&, sal_uLong=FORMAT_STRING );
129 	sal_Bool ExportString( ::rtl::OUString&, sal_uLong=FORMAT_STRING );
130 	sal_Bool ExportByteString( ByteString&, rtl_TextEncoding, sal_uLong=FORMAT_STRING );
131 
132     sal_Bool ImportStream( SvStream&, const String& rBaseURL, sal_uLong=FORMAT_STRING );
133     sal_Bool ExportStream( SvStream&, const String& rBaseURL, sal_uLong=FORMAT_STRING );
134 
135 	sal_Bool ImportData( const String& rMimeType,
136 					 const ::com::sun::star::uno::Any & rValue );
137     sal_Bool ExportData( const String& rMimeType,
138 					 ::com::sun::star::uno::Any & rValue  );
139 
IsOverflow() const140 	sal_Bool IsOverflow() const	{ return bOverflow; }		// nach dem Importieren
141 
GetNonConvertibleChars() const142     const String& GetNonConvertibleChars() const { return aNonConvertibleChars; }
143 
IsApi() const144     bool IsApi() const { return mbApi; }
SetApi(bool bApi)145     void SetApi( bool bApi ) { mbApi = bApi; }
GetExportTextOptions()146     const ScExportTextOptions& GetExportTextOptions() { return mExportTextOptions; }
SetExportTextOptions(const ScExportTextOptions & options)147     void SetExportTextOptions( const ScExportTextOptions& options ) { mExportTextOptions = options; }
148 };
149 
150 
151 // static
IsEndianSwap(const SvStream & rStrm)152 inline sal_Bool ScImportExport::IsEndianSwap( const SvStream& rStrm )
153 {
154 #ifdef OSL_BIGENDIAN
155 	return rStrm.GetNumberFormatInt() != NUMBERFORMAT_INT_BIGENDIAN;
156 #else
157 	return rStrm.GetNumberFormatInt() != NUMBERFORMAT_INT_LITTLEENDIAN;
158 #endif
159 }
160 
161 // static
SetNoEndianSwap(SvStream & rStrm)162 inline void ScImportExport::SetNoEndianSwap( SvStream& rStrm )
163 {
164 #ifdef OSL_BIGENDIAN
165     rStrm.SetNumberFormatInt( NUMBERFORMAT_INT_BIGENDIAN );
166 #else
167     rStrm.SetNumberFormatInt( NUMBERFORMAT_INT_LITTLEENDIAN );
168 #endif
169 }
170 
171 
172 // Helper class for importing clipboard strings as streams.
173 class ScImportStringStream : public SvMemoryStream
174 {
175 public:
ScImportStringStream(const::rtl::OUString rStr)176     ScImportStringStream( const ::rtl::OUString rStr )
177         : SvMemoryStream( (void*)rStr.getStr(),
178                 rStr.getLength() * sizeof(sal_Unicode), STREAM_READ)
179     {
180         SetStreamCharSet( RTL_TEXTENCODING_UNICODE );
181         SetEndianSwap( sal_False );
182     }
183 };
184 
185 
186 #endif
187 
188