LCOV - code coverage report
Current view: top level - sc/source/ui/inc - impex.hxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 29 0.0 %
Date: 2014-04-14 Functions: 0 21 0.0 %
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 SC_IMPEX_HXX
      21             : #define SC_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           0 :     ScExportTextOptions( NewlineConversion eNewlineConversion = ToSystem, sal_Unicode cSeparatorConvertTo = 0, bool bAddQuotes = false ) :
      41           0 :         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             :     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             :     bool        mbImportBroadcast; // whether or not to broadcast after data import.
      69             :     ScExportTextOptions mExportTextOptions;
      70             : 
      71             :     ScAsciiOptions* pExtOptions;        // extended options
      72             : 
      73             :     bool StartPaste();                  // Protect check, set up Undo
      74             :     void EndPaste(bool bAutoRowHeight = true);                    // Undo/Redo actions, Repaint
      75             :     bool Doc2Text( SvStream& );
      76             :     bool Text2Doc( SvStream& );
      77             :     bool Doc2Sylk( SvStream& );
      78             :     bool Sylk2Doc( SvStream& );
      79             :     bool Doc2HTML( SvStream&, const OUString& );
      80             :     bool Doc2RTF( SvStream& );
      81             :     bool Doc2Dif( SvStream& );
      82             :     bool Dif2Doc( SvStream& );
      83             :     bool ExtText2Doc( SvStream& );      // with pExtOptions
      84             :     bool RTF2Doc( SvStream&, const OUString& rBaseURL );
      85             :     bool HTML2Doc( SvStream&, const OUString& rBaseURL );
      86             : 
      87             : public:
      88             :     ScImportExport( ScDocument* );                  // the whole document
      89             :     ScImportExport( ScDocument*, const OUString& );   // Range/cell input
      90             :     ScImportExport( ScDocument*, const ScAddress& );
      91             :     ScImportExport( ScDocument*, const ScRange& );
      92             :    ~ScImportExport();
      93             : 
      94             :     void SetExtOptions( const ScAsciiOptions& rOpt );
      95             : 
      96             :     bool IsDoubleRef() const { return !( bAll || bSingle ); }
      97             :     bool IsSingleRef() const { return bSingle; }
      98             :     bool IsNoRef() const     { return bAll;    }
      99           0 :     bool IsRef() const       { return !bAll; }
     100             : 
     101           0 :     const ScRange& GetRange() const { return aRange; }
     102             : 
     103             :     bool IsUndo() const      { return bUndo; }
     104             :     void SetUndo( bool b )   { bUndo = b;    }
     105             : 
     106             :     SC_DLLPUBLIC static void EmbeddedNullTreatment( OUString & rStr );
     107             : 
     108             :     static bool  IsFormatSupported( sal_uLong nFormat );
     109             :     static const sal_Unicode* ScanNextFieldFromString( const sal_Unicode* p,
     110             :             OUString& rField, sal_Unicode cStr, const sal_Unicode* pSeps,
     111             :             bool bMergeSeps, bool& rbIsQuoted, bool& rbOverflowCell );
     112             :     static  void    WriteUnicodeOrByteString( SvStream& rStrm, const OUString& rString, bool bZero = false );
     113             :     static  void    WriteUnicodeOrByteEndl( SvStream& rStrm );
     114             :     static  inline  bool    IsEndianSwap( const SvStream& rStrm );
     115             : 
     116             :     //! only if stream is only used in own (!) memory
     117             :     static  inline  void    SetNoEndianSwap( SvStream& rStrm );
     118             : 
     119             :     sal_Unicode GetSeparator() const { return cSep; }
     120           0 :     void SetSeparator( sal_Unicode c ) { cSep = c; }
     121             :     sal_Unicode GetDelimiter() const { return cStr; }
     122           0 :     void SetDelimiter( sal_Unicode c ) { cStr = c; }
     123             :     bool IsFormulas() const { return bFormulas; }
     124           0 :     void SetFormulas( bool b ) { bFormulas = b; }
     125             :     bool IsIncludeFiltered() const { return bIncludeFiltered; }
     126           0 :     void SetIncludeFiltered( bool b ) { bIncludeFiltered = b; }
     127             : 
     128             :     void SetSizeLimit( sal_uLong nNew ) { nSizeLimit = nNew; }  // for the moment only for Ascii
     129             : 
     130           0 :     void            SetStreamPath( const OUString& rPath ) { aStreamPath = rPath; }
     131             :     const OUString& GetStreamPath() const { return aStreamPath; }
     132             : 
     133             :     bool ImportString( const OUString&, sal_uLong=FORMAT_STRING );
     134             :     bool ExportString( OUString&, sal_uLong=FORMAT_STRING );
     135             :     bool ExportByteString( OString&, rtl_TextEncoding, sal_uLong=FORMAT_STRING );
     136             : 
     137             :     bool ImportStream( SvStream&, const OUString& rBaseURL, sal_uLong=FORMAT_STRING );
     138             :     bool ExportStream( SvStream&, const OUString& rBaseURL, sal_uLong=FORMAT_STRING );
     139             : 
     140             :     bool ImportData( const OUString& rMimeType,
     141             :                      const ::com::sun::star::uno::Any & rValue );
     142             :     bool ExportData( const OUString& rMimeType,
     143             :                      ::com::sun::star::uno::Any & rValue  );
     144             : 
     145             :     // after import
     146           0 :     bool IsOverflowRow() const { return bOverflowRow; }
     147           0 :     bool IsOverflowCol() const { return bOverflowCol; }
     148           0 :     bool IsOverflowCell() const { return bOverflowCell; }
     149           0 :     bool IsOverflow() const { return bOverflowRow || bOverflowCol || bOverflowCell; }
     150             : 
     151           0 :     const OUString& GetNonConvertibleChars() const { return aNonConvertibleChars; }
     152             : 
     153             :     bool IsApi() const { return mbApi; }
     154           0 :     void SetApi( bool bApi ) { mbApi = bApi; }
     155           0 :     void SetImportBroadcast( bool b ) { mbImportBroadcast = b; }
     156             :     const ScExportTextOptions& GetExportTextOptions() { return mExportTextOptions; }
     157           0 :     void SetExportTextOptions( const ScExportTextOptions& options ) { mExportTextOptions = options; }
     158             : };
     159             : 
     160             : 
     161           0 : inline bool ScImportExport::IsEndianSwap( const SvStream& rStrm )
     162             : {
     163             : #ifdef OSL_BIGENDIAN
     164             :     return rStrm.GetNumberFormatInt() != NUMBERFORMAT_INT_BIGENDIAN;
     165             : #else
     166           0 :     return rStrm.GetNumberFormatInt() != NUMBERFORMAT_INT_LITTLEENDIAN;
     167             : #endif
     168             : }
     169             : 
     170           0 : inline void ScImportExport::SetNoEndianSwap( SvStream& rStrm )
     171             : {
     172             : #ifdef OSL_BIGENDIAN
     173             :     rStrm.SetNumberFormatInt( NUMBERFORMAT_INT_BIGENDIAN );
     174             : #else
     175           0 :     rStrm.SetNumberFormatInt( NUMBERFORMAT_INT_LITTLEENDIAN );
     176             : #endif
     177           0 : }
     178             : 
     179             : 
     180             : // Helper class for importing clipboard strings as streams.
     181           0 : class ScImportStringStream : public SvMemoryStream
     182             : {
     183             : public:
     184           0 :     ScImportStringStream( const OUString& rStr )
     185           0 :         : SvMemoryStream( (void*)rStr.getStr(),
     186           0 :                 rStr.getLength() * sizeof(sal_Unicode), STREAM_READ)
     187             :     {
     188           0 :         SetStreamCharSet( RTL_TEXTENCODING_UNICODE );
     189           0 :         SetEndianSwap( false );
     190           0 :     }
     191             : };
     192             : 
     193             : /** Read a CSV (comma separated values) data line using
     194             :     ReadUniOrByteStringLine().
     195             : 
     196             :     @param bEmbeddedLineBreak
     197             :     If TRUE and a line-break occurs inside a field of data,
     198             :     a line feed LF '\n' and the next line are appended. Repeats
     199             :     until a line-break is not in a field. A field is determined
     200             :     by delimiting rFieldSeparators and optionally surrounded by
     201             :     a pair of cFieldQuote characters. For a line-break to be
     202             :     within a field, the field content MUST be surrounded by
     203             :     cFieldQuote characters, and the opening cFieldQuote MUST be
     204             :     at the very start of a line or follow right behind a field
     205             :     separator with no extra characters in between, with the
     206             :     exception of blanks contradictory to RFC 4180. Anything,
     207             :     including field separators and escaped quotes (by doubling
     208             :     them) may appear in a quoted field.
     209             : 
     210             :     If bEmbeddedLineBreak==FALSE, nothing is parsed and the
     211             :     string returned is simply one ReadUniOrByteStringLine().
     212             : 
     213             :     @param rFieldSeparators
     214             :     A list of characters that each may act as a field separator.
     215             : 
     216             :     @param cFieldQuote
     217             :     The quote character used.
     218             : 
     219             :     check Stream::good() to detect IO problems during read
     220             : 
     221             :     @ATTENTION
     222             :     Note that the string returned may be truncated even inside
     223             :     a quoted field if some (arbritary) maximum length was reached.
     224             :     There currently is no way to exactly determine the conditions,
     225             :     whether this was at a line end, or whether open quotes
     226             :     would have closed the field before the line end, as even a
     227             :     ReadUniOrByteStringLine() may return prematurely but the
     228             :     stream was positioned ahead until the real end of line.
     229             :     Additionally, due to character encoding conversions, string
     230             :     length and bytes read don't necessarily match, and
     231             :     resyncing to a previous position matching the string's
     232             :     length isn't always possible. As a result, a logical line
     233             :     with embedded line breaks and more than the maximum length
     234             :     characters will be spoiled, and a subsequent ReadCsvLine()
     235             :     may start under false preconditions.
     236             : 
     237             :   */
     238             : SC_DLLPUBLIC OUString ReadCsvLine( SvStream &rStream, bool bEmbeddedLineBreak,
     239             :         const OUString& rFieldSeparators, sal_Unicode cFieldQuote );
     240             : 
     241             : #endif
     242             : 
     243             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10