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