fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / ui / inc / impex.hxx
blob3aca0c89fefdc84e4c7ae2cb1a2416d1866fbe0b
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 INCLUDED_SC_SOURCE_UI_INC_IMPEX_HXX
21 #define INCLUDED_SC_SOURCE_UI_INC_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 OUString maFilterOptions;
57 sal_uLong nSizeLimit;
58 sal_Unicode cSep; // Separator
59 sal_Unicode cStr; // String Delimiter
60 bool bFormulas; // Formula in Text?
61 bool bIncludeFiltered; // include filtered rows? (default true)
62 bool bAll; // no selection
63 bool bSingle; // Single selection
64 bool bUndo; // with Undo?
65 bool bOverflowRow; // too many rows
66 bool bOverflowCol; // too many columns
67 bool bOverflowCell; // too much data for a cell
68 bool mbApi;
69 bool mbImportBroadcast; // whether or not to broadcast after data import.
70 bool mbOverwriting; // Whether we could be overwriting existing values (paste).
71 // In this case we cannot use the insert optimization, but we
72 // do not need to broadcast after the import.
73 ScExportTextOptions mExportTextOptions;
75 ScAsciiOptions* pExtOptions; // extended options
77 bool StartPaste(); // Protect check, set up Undo
78 void EndPaste(bool bAutoRowHeight = true); // Undo/Redo actions, Repaint
79 bool Doc2Text( SvStream& );
80 bool Text2Doc( SvStream& );
81 bool Doc2Sylk( SvStream& );
82 bool Sylk2Doc( SvStream& );
83 bool Doc2HTML( SvStream&, const OUString& );
84 bool Doc2RTF( SvStream& );
85 bool Doc2Dif( SvStream& );
86 bool Dif2Doc( SvStream& );
87 bool ExtText2Doc( SvStream& ); // with pExtOptions
88 bool RTF2Doc( SvStream&, const OUString& rBaseURL );
89 bool HTML2Doc( SvStream&, const OUString& rBaseURL );
91 public:
92 ScImportExport( ScDocument* ); // the whole document
93 ScImportExport( ScDocument*, const OUString& ); // Range/cell input
94 ScImportExport( ScDocument*, const ScAddress& );
95 ScImportExport( ScDocument*, const ScRange& );
96 ~ScImportExport();
98 void SetExtOptions( const ScAsciiOptions& rOpt );
99 void SetFilterOptions( const OUString& rFilterOptions );
101 bool IsDoubleRef() const { return !( bAll || bSingle ); }
102 bool IsSingleRef() const { return bSingle; }
103 bool IsNoRef() const { return bAll; }
104 bool IsRef() const { return !bAll; }
106 const ScRange& GetRange() const { return aRange; }
108 bool IsUndo() const { return bUndo; }
109 void SetUndo( bool b ) { bUndo = b; }
111 SC_DLLPUBLIC static void EmbeddedNullTreatment( OUString & rStr );
113 static bool IsFormatSupported( SotClipboardFormatId nFormat );
114 static const sal_Unicode* ScanNextFieldFromString( const sal_Unicode* p,
115 OUString& rField, sal_Unicode cStr, const sal_Unicode* pSeps,
116 bool bMergeSeps, bool& rbIsQuoted, bool& rbOverflowCell );
117 static void WriteUnicodeOrByteString( SvStream& rStrm, const OUString& rString, bool bZero = false );
118 static void WriteUnicodeOrByteEndl( SvStream& rStrm );
119 static inline bool IsEndianSwap( const SvStream& rStrm );
121 //! only if stream is only used in own (!) memory
122 static inline void SetNoEndianSwap( SvStream& rStrm );
124 sal_Unicode GetSeparator() const { return cSep; }
125 void SetSeparator( sal_Unicode c ) { cSep = c; }
126 sal_Unicode GetDelimiter() const { return cStr; }
127 void SetDelimiter( sal_Unicode c ) { cStr = c; }
128 bool IsFormulas() const { return bFormulas; }
129 void SetFormulas( bool b ) { bFormulas = b; }
130 bool IsIncludeFiltered() const { return bIncludeFiltered; }
131 void SetIncludeFiltered( bool b ) { bIncludeFiltered = b; }
133 void SetSizeLimit( sal_uLong nNew ) { nSizeLimit = nNew; } // for the moment only for Ascii
135 void SetStreamPath( const OUString& rPath ) { aStreamPath = rPath; }
136 const OUString& GetStreamPath() const { return aStreamPath; }
138 bool ImportString( const OUString&, SotClipboardFormatId=SotClipboardFormatId::STRING );
139 bool ExportString( OUString&, SotClipboardFormatId=SotClipboardFormatId::STRING );
140 bool ExportByteString( OString&, rtl_TextEncoding, SotClipboardFormatId=SotClipboardFormatId::STRING );
142 bool ImportStream( SvStream&, const OUString& rBaseURL, SotClipboardFormatId=SotClipboardFormatId::STRING );
143 bool ExportStream( SvStream&, const OUString& rBaseURL, SotClipboardFormatId=SotClipboardFormatId::STRING );
145 static bool ImportData( const OUString& rMimeType,
146 const ::com::sun::star::uno::Any & rValue );
147 bool ExportData( const OUString& rMimeType,
148 ::com::sun::star::uno::Any & rValue );
150 // after import
151 bool IsOverflowRow() const { return bOverflowRow; }
152 bool IsOverflowCol() const { return bOverflowCol; }
153 bool IsOverflowCell() const { return bOverflowCell; }
154 bool IsOverflow() const { return bOverflowRow || bOverflowCol || bOverflowCell; }
156 const OUString& GetNonConvertibleChars() const { return aNonConvertibleChars; }
158 bool IsApi() const { return mbApi; }
159 void SetApi( bool bApi ) { mbApi = bApi; }
160 void SetImportBroadcast( bool b ) { mbImportBroadcast = b; }
161 void SetOverwriting( const bool bOverwriting ) { mbOverwriting = bOverwriting; }
162 const ScExportTextOptions& GetExportTextOptions() { return mExportTextOptions; }
163 void SetExportTextOptions( const ScExportTextOptions& options ) { mExportTextOptions = options; }
166 inline bool ScImportExport::IsEndianSwap( const SvStream& rStrm )
168 #ifdef OSL_BIGENDIAN
169 return rStrm.GetEndian() != SvStreamEndian::BIG;
170 #else
171 return rStrm.GetEndian() != SvStreamEndian::LITTLE;
172 #endif
175 inline void ScImportExport::SetNoEndianSwap( SvStream& rStrm )
177 #ifdef OSL_BIGENDIAN
178 rStrm.SetEndian( SvStreamEndian::BIG );
179 #else
180 rStrm.SetEndian( SvStreamEndian::LITTLE );
181 #endif
184 // Helper class for importing clipboard strings as streams.
185 class ScImportStringStream : public SvMemoryStream
187 public:
188 ScImportStringStream( const OUString& rStr )
189 : SvMemoryStream( (void*)rStr.getStr(),
190 rStr.getLength() * sizeof(sal_Unicode), StreamMode::READ)
192 SetStreamCharSet( RTL_TEXTENCODING_UNICODE );
193 #ifdef OSL_BIGENDIAN
194 SetEndian(SvStreamEndian::BIG);
195 #else
196 SetEndian(SvStreamEndian::LITTLE);
197 #endif
201 /** Read a CSV (comma separated values) data line using
202 ReadUniOrByteStringLine().
204 @param bEmbeddedLineBreak
205 If TRUE and a line-break occurs inside a field of data,
206 a line feed LF '\n' and the next line are appended. Repeats
207 until a line-break is not in a field. A field is determined
208 by delimiting rFieldSeparators and optionally surrounded by
209 a pair of cFieldQuote characters. For a line-break to be
210 within a field, the field content MUST be surrounded by
211 cFieldQuote characters, and the opening cFieldQuote MUST be
212 at the very start of a line or follow right behind a field
213 separator with no extra characters in between, with the
214 exception of blanks contradictory to RFC 4180. Anything,
215 including field separators and escaped quotes (by doubling
216 them) may appear in a quoted field.
218 If bEmbeddedLineBreak==FALSE, nothing is parsed and the
219 string returned is simply one ReadUniOrByteStringLine().
221 @param rFieldSeparators
222 A list of characters that each may act as a field separator.
224 @param cFieldQuote
225 The quote character used.
227 check Stream::good() to detect IO problems during read
229 @ATTENTION
230 Note that the string returned may be truncated even inside
231 a quoted field if some (arbritary) maximum length was reached.
232 There currently is no way to exactly determine the conditions,
233 whether this was at a line end, or whether open quotes
234 would have closed the field before the line end, as even a
235 ReadUniOrByteStringLine() may return prematurely but the
236 stream was positioned ahead until the real end of line.
237 Additionally, due to character encoding conversions, string
238 length and bytes read don't necessarily match, and
239 resyncing to a previous position matching the string's
240 length isn't always possible. As a result, a logical line
241 with embedded line breaks and more than the maximum length
242 characters will be spoiled, and a subsequent ReadCsvLine()
243 may start under false preconditions.
246 SC_DLLPUBLIC OUString ReadCsvLine( SvStream &rStream, bool bEmbeddedLineBreak,
247 const OUString& rFieldSeparators, sal_Unicode cFieldQuote );
249 #endif
251 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */