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