Stop leaking all ScPostIt instances.
[LibreOffice.git] / sc / source / ui / inc / impex.hxx
blob43561540d6628661084daf02c53b2ab7e61e336d
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef SC_IMPEX_HXX
21 #define SC_IMPEX_HXX
23 #include <osl/endian.h>
24 #include <sot/exchange.hxx>
25 #include "global.hxx"
26 #include "address.hxx"
28 class ScDocShell;
29 class ScDocument;
30 class SvStream;
31 class ScAsciiOptions;
33 /**
34 * These options control how multi-line cells are converted during export in
35 * certain lossy formats (such as csv).
37 struct ScExportTextOptions
39 enum NewlineConversion { ToSystem, ToSpace, None };
40 ScExportTextOptions( NewlineConversion eNewlineConversion = ToSystem, sal_Unicode cSeparatorConvertTo = 0, bool bAddQuotes = false ) :
41 meNewlineConversion( eNewlineConversion ), mcSeparatorConvertTo( cSeparatorConvertTo ), mbAddQuotes( bAddQuotes ) {}
43 NewlineConversion meNewlineConversion;
44 sal_Unicode mcSeparatorConvertTo; // Convert separator to this character
45 bool mbAddQuotes;
48 class ScImportExport
50 ScDocShell* pDocSh;
51 ScDocument* pDoc;
52 ScDocument* pUndoDoc;
53 ScRange aRange;
54 OUString aStreamPath;
55 OUString aNonConvertibleChars;
56 sal_uLong nSizeLimit;
57 sal_Unicode cSep; // Separator
58 sal_Unicode cStr; // String Delimiter
59 bool bFormulas; // Formula in Text?
60 bool bIncludeFiltered; // include filtered rows? (default true)
61 bool bAll; // no selection
62 bool bSingle; // Single selection
63 bool bUndo; // with Undo?
64 bool bOverflowRow; // too many rows
65 bool bOverflowCol; // too many columns
66 bool bOverflowCell; // too much data for a cell
67 bool mbApi;
68 ScExportTextOptions mExportTextOptions;
70 ScAsciiOptions* pExtOptions; // extended options
72 bool StartPaste(); // Protect check, set up Undo
73 void EndPaste(bool bAutoRowHeight = true); // Undo/Redo actions, Repaint
74 bool Doc2Text( SvStream& );
75 bool Text2Doc( SvStream& );
76 bool Doc2Sylk( SvStream& );
77 bool Sylk2Doc( SvStream& );
78 bool Doc2HTML( SvStream&, const OUString& );
79 bool Doc2RTF( SvStream& );
80 bool Doc2Dif( SvStream& );
81 bool Dif2Doc( SvStream& );
82 bool ExtText2Doc( SvStream& ); // with pExtOptions
83 bool RTF2Doc( SvStream&, const OUString& rBaseURL );
84 bool HTML2Doc( SvStream&, const OUString& rBaseURL );
86 public:
87 ScImportExport( ScDocument* ); // the whole document
88 ScImportExport( ScDocument*, const OUString& ); // Range/cell input
89 ScImportExport( ScDocument*, const ScAddress& );
90 ScImportExport( ScDocument*, const ScRange& );
91 ~ScImportExport();
93 void SetExtOptions( const ScAsciiOptions& rOpt );
95 bool IsDoubleRef() const { return !( bAll || bSingle ); }
96 bool IsSingleRef() const { return bSingle; }
97 bool IsNoRef() const { return bAll; }
98 bool IsRef() const { return !bAll; }
100 const ScRange& GetRange() const { return aRange; }
102 bool IsUndo() const { return bUndo; }
103 void SetUndo( bool b ) { bUndo = b; }
105 SC_DLLPUBLIC static void EmbeddedNullTreatment( OUString & rStr );
107 static bool IsFormatSupported( sal_uLong nFormat );
108 static const sal_Unicode* ScanNextFieldFromString( const sal_Unicode* p,
109 OUString& rField, sal_Unicode cStr, const sal_Unicode* pSeps,
110 bool bMergeSeps, bool& rbIsQuoted, bool& rbOverflowCell );
111 static void WriteUnicodeOrByteString( SvStream& rStrm, const OUString& rString, bool bZero = false );
112 static void WriteUnicodeOrByteEndl( SvStream& rStrm );
113 static inline bool IsEndianSwap( const SvStream& rStrm );
115 //! only if stream is only used in own (!) memory
116 static inline void SetNoEndianSwap( SvStream& rStrm );
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 bool IsFormulas() const { return bFormulas; }
123 void SetFormulas( bool b ) { bFormulas = b; }
124 bool IsIncludeFiltered() const { return bIncludeFiltered; }
125 void SetIncludeFiltered( bool b ) { bIncludeFiltered = b; }
127 void SetSizeLimit( sal_uLong nNew ) { nSizeLimit = nNew; } // for the moment only for Ascii
129 void SetStreamPath( const OUString& rPath ) { aStreamPath = rPath; }
130 const OUString& GetStreamPath() const { return aStreamPath; }
132 bool ImportString( const OUString&, sal_uLong=FORMAT_STRING );
133 bool ExportString( OUString&, sal_uLong=FORMAT_STRING );
134 bool ExportByteString( OString&, rtl_TextEncoding, sal_uLong=FORMAT_STRING );
136 bool ImportStream( SvStream&, const OUString& rBaseURL, sal_uLong=FORMAT_STRING );
137 bool ExportStream( SvStream&, const OUString& rBaseURL, sal_uLong=FORMAT_STRING );
139 bool ImportData( const OUString& rMimeType,
140 const ::com::sun::star::uno::Any & rValue );
141 bool ExportData( const OUString& rMimeType,
142 ::com::sun::star::uno::Any & rValue );
144 // after import
145 bool IsOverflowRow() const { return bOverflowRow; }
146 bool IsOverflowCol() const { return bOverflowCol; }
147 bool IsOverflowCell() const { return bOverflowCell; }
148 bool IsOverflow() const { return bOverflowRow || bOverflowCol || bOverflowCell; }
150 const OUString& GetNonConvertibleChars() const { return aNonConvertibleChars; }
152 bool IsApi() const { return mbApi; }
153 void SetApi( bool bApi ) { mbApi = bApi; }
154 const ScExportTextOptions& GetExportTextOptions() { return mExportTextOptions; }
155 void SetExportTextOptions( const ScExportTextOptions& options ) { mExportTextOptions = options; }
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 inline void ScImportExport::SetNoEndianSwap( SvStream& rStrm )
170 #ifdef OSL_BIGENDIAN
171 rStrm.SetNumberFormatInt( NUMBERFORMAT_INT_BIGENDIAN );
172 #else
173 rStrm.SetNumberFormatInt( NUMBERFORMAT_INT_LITTLEENDIAN );
174 #endif
178 // Helper class for importing clipboard strings as streams.
179 class ScImportStringStream : public SvMemoryStream
181 public:
182 ScImportStringStream( const OUString rStr )
183 : SvMemoryStream( (void*)rStr.getStr(),
184 rStr.getLength() * sizeof(sal_Unicode), STREAM_READ)
186 SetStreamCharSet( RTL_TEXTENCODING_UNICODE );
187 SetEndianSwap( false );
191 /** Read a CSV (comma separated values) data line using
192 ReadUniOrByteStringLine().
194 @param bEmbeddedLineBreak
195 If TRUE and a line-break occurs inside a field of data,
196 a line feed LF '\n' and the next line are appended. Repeats
197 until a line-break is not in a field. A field is determined
198 by delimiting rFieldSeparators and optionally surrounded by
199 a pair of cFieldQuote characters. For a line-break to be
200 within a field, the field content MUST be surrounded by
201 cFieldQuote characters, and the opening cFieldQuote MUST be
202 at the very start of a line or follow right behind a field
203 separator with no extra characters in between, with the
204 exception of blanks contradictory to RFC 4180. Anything,
205 including field separators and escaped quotes (by doubling
206 them) may appear in a quoted field.
208 If bEmbeddedLineBreak==FALSE, nothing is parsed and the
209 string returned is simply one ReadUniOrByteStringLine().
211 @param rFieldSeparators
212 A list of characters that each may act as a field separator.
214 @param cFieldQuote
215 The quote character used.
217 check Stream::good() to detect IO problems during read
219 @ATTENTION
220 Note that the string returned may be truncated even inside
221 a quoted field if some (arbritary) maximum length was reached.
222 There currently is no way to exactly determine the conditions,
223 whether this was at a line end, or whether open quotes
224 would have closed the field before the line end, as even a
225 ReadUniOrByteStringLine() may return prematurely but the
226 stream was positioned ahead until the real end of line.
227 Additionally, due to character encoding conversions, string
228 length and bytes read don't necessarily match, and
229 resyncing to a previous position matching the string's
230 length isn't always possible. As a result, a logical line
231 with embedded line breaks and more than the maximum length
232 characters will be spoiled, and a subsequent ReadCsvLine()
233 may start under false preconditions.
236 SC_DLLPUBLIC OUString ReadCsvLine( SvStream &rStream, bool bEmbeddedLineBreak,
237 const OUString& rFieldSeparators, sal_Unicode cFieldQuote );
239 #endif
241 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */