LCOV - code coverage report
Current view: top level - sc/source/ui/inc - impex.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 16 30 53.3 %
Date: 2015-06-13 12:38:46 Functions: 10 22 45.5 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       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/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      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 .
      18             :  */
      19             : 
      20             : #ifndef INCLUDED_SC_SOURCE_UI_INC_IMPEX_HXX
      21             : #define INCLUDED_SC_SOURCE_UI_INC_IMPEX_HXX
      22             : 
      23             : #include <osl/endian.h>
      24             : #include <sot/exchange.hxx>
      25             : #include "global.hxx"
      26             : #include "address.hxx"
      27             : 
      28             : class ScDocShell;
      29             : class ScDocument;
      30             : class SvStream;
      31             : class ScAsciiOptions;
      32             : 
      33             : /**
      34             :  * These options control how multi-line cells are converted during export in
      35             :  * certain lossy formats (such as csv).
      36             :  */
      37             : struct ScExportTextOptions
      38             : {
      39             :     enum NewlineConversion { ToSystem, ToSpace, None };
      40          20 :     ScExportTextOptions( NewlineConversion eNewlineConversion = ToSystem, sal_Unicode cSeparatorConvertTo = 0, bool bAddQuotes = false ) :
      41          20 :         meNewlineConversion( eNewlineConversion ), mcSeparatorConvertTo( cSeparatorConvertTo ), mbAddQuotes( bAddQuotes ) {}
      42             : 
      43             :     NewlineConversion meNewlineConversion;
      44             :     sal_Unicode mcSeparatorConvertTo;   // Convert separator to this character
      45             :     bool mbAddQuotes;
      46             : };
      47             : 
      48             : class ScImportExport
      49             : {
      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;
      74             : 
      75             :     ScAsciiOptions* pExtOptions;        // extended options
      76             : 
      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 );
      90             : 
      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();
      97             : 
      98             :     void SetExtOptions( const ScAsciiOptions& rOpt );
      99             :     void SetFilterOptions( const OUString& rFilterOptions );
     100             : 
     101             :     bool IsDoubleRef() const { return !( bAll || bSingle ); }
     102             :     bool IsSingleRef() const { return bSingle; }
     103             :     bool IsNoRef() const     { return bAll;    }
     104           0 :     bool IsRef() const       { return !bAll; }
     105             : 
     106           0 :     const ScRange& GetRange() const { return aRange; }
     107             : 
     108             :     bool IsUndo() const      { return bUndo; }
     109             :     void SetUndo( bool b )   { bUndo = b;    }
     110             : 
     111             :     SC_DLLPUBLIC static void EmbeddedNullTreatment( OUString & rStr );
     112             : 
     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 );
     120             : 
     121             :     //! only if stream is only used in own (!) memory
     122             :     static  inline  void    SetNoEndianSwap( SvStream& rStrm );
     123             : 
     124             :     sal_Unicode GetSeparator() const { return cSep; }
     125           0 :     void SetSeparator( sal_Unicode c ) { cSep = c; }
     126             :     sal_Unicode GetDelimiter() const { return cStr; }
     127           0 :     void SetDelimiter( sal_Unicode c ) { cStr = c; }
     128             :     bool IsFormulas() const { return bFormulas; }
     129           0 :     void SetFormulas( bool b ) { bFormulas = b; }
     130             :     bool IsIncludeFiltered() const { return bIncludeFiltered; }
     131           0 :     void SetIncludeFiltered( bool b ) { bIncludeFiltered = b; }
     132             : 
     133             :     void SetSizeLimit( sal_uLong nNew ) { nSizeLimit = nNew; }  // for the moment only for Ascii
     134             : 
     135           3 :     void            SetStreamPath( const OUString& rPath ) { aStreamPath = rPath; }
     136             :     const OUString& GetStreamPath() const { return aStreamPath; }
     137             : 
     138             :     bool ImportString( const OUString&, SotClipboardFormatId=SotClipboardFormatId::STRING );
     139             :     bool ExportString( OUString&, SotClipboardFormatId=SotClipboardFormatId::STRING );
     140             :     bool ExportByteString( OString&, rtl_TextEncoding, SotClipboardFormatId=SotClipboardFormatId::STRING );
     141             : 
     142             :     bool ImportStream( SvStream&, const OUString& rBaseURL, SotClipboardFormatId=SotClipboardFormatId::STRING );
     143             :     bool ExportStream( SvStream&, const OUString& rBaseURL, SotClipboardFormatId=SotClipboardFormatId::STRING );
     144             : 
     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  );
     149             : 
     150             :     // after import
     151           2 :     bool IsOverflowRow() const { return bOverflowRow; }
     152           2 :     bool IsOverflowCol() const { return bOverflowCol; }
     153           2 :     bool IsOverflowCell() const { return bOverflowCell; }
     154           0 :     bool IsOverflow() const { return bOverflowRow || bOverflowCol || bOverflowCell; }
     155             : 
     156           3 :     const OUString& GetNonConvertibleChars() const { return aNonConvertibleChars; }
     157             : 
     158             :     bool IsApi() const { return mbApi; }
     159           0 :     void SetApi( bool bApi ) { mbApi = bApi; }
     160           1 :     void SetImportBroadcast( bool b ) { mbImportBroadcast = b; }
     161           0 :     void SetOverwriting( const bool bOverwriting ) { mbOverwriting = bOverwriting; }
     162             :     const ScExportTextOptions& GetExportTextOptions() { return mExportTextOptions; }
     163           5 :     void SetExportTextOptions( const ScExportTextOptions& options ) { mExportTextOptions = options; }
     164             : };
     165             : 
     166           0 : inline bool ScImportExport::IsEndianSwap( const SvStream& rStrm )
     167             : {
     168             : #ifdef OSL_BIGENDIAN
     169             :     return rStrm.GetEndian() != SvStreamEndian::BIG;
     170             : #else
     171           0 :     return rStrm.GetEndian() != SvStreamEndian::LITTLE;
     172             : #endif
     173             : }
     174             : 
     175           0 : inline void ScImportExport::SetNoEndianSwap( SvStream& rStrm )
     176             : {
     177             : #ifdef OSL_BIGENDIAN
     178             :     rStrm.SetEndian( SvStreamEndian::BIG );
     179             : #else
     180           0 :     rStrm.SetEndian( SvStreamEndian::LITTLE );
     181             : #endif
     182           0 : }
     183             : 
     184             : // Helper class for importing clipboard strings as streams.
     185           1 : class ScImportStringStream : public SvMemoryStream
     186             : {
     187             : public:
     188           1 :     ScImportStringStream( const OUString& rStr )
     189           1 :         : SvMemoryStream( const_cast<sal_Unicode *>(rStr.getStr()),
     190           2 :                 rStr.getLength() * sizeof(sal_Unicode), StreamMode::READ)
     191             :     {
     192           1 :         SetStreamCharSet( RTL_TEXTENCODING_UNICODE );
     193             : #ifdef OSL_BIGENDIAN
     194             :         SetEndian(SvStreamEndian::BIG);
     195             : #else
     196           1 :         SetEndian(SvStreamEndian::LITTLE);
     197             : #endif
     198           1 :     }
     199             : };
     200             : 
     201             : /** Read a CSV (comma separated values) data line using
     202             :     ReadUniOrByteStringLine().
     203             : 
     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.
     217             : 
     218             :     If bEmbeddedLineBreak==FALSE, nothing is parsed and the
     219             :     string returned is simply one ReadUniOrByteStringLine().
     220             : 
     221             :     @param rFieldSeparators
     222             :     A list of characters that each may act as a field separator.
     223             : 
     224             :     @param cFieldQuote
     225             :     The quote character used.
     226             : 
     227             :     check Stream::good() to detect IO problems during read
     228             : 
     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.
     244             : 
     245             :   */
     246             : SC_DLLPUBLIC OUString ReadCsvLine( SvStream &rStream, bool bEmbeddedLineBreak,
     247             :         const OUString& rFieldSeparators, sal_Unicode cFieldQuote );
     248             : 
     249             : #endif
     250             : 
     251             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11