LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sc/source/ui/inc - impex.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 6 28 21.4 %
Date: 2013-07-09 Functions: 5 20 25.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          22 :     ScExportTextOptions( NewlineConversion eNewlineConversion = ToSystem, sal_Unicode cSeparatorConvertTo = 0, bool bAddQuotes = false ) :
      41          22 :         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             :     String      aStreamPath;
      55             :     String      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;
      69             : 
      70             :     ScAsciiOptions* pExtOptions;        // extended options
      71             : 
      72             :     bool StartPaste();                  // Protect check, set up Undo
      73             :     void EndPaste();                    // 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 String& );
      79             :     bool Doc2RTF( SvStream& );
      80             :     bool Doc2Dif( SvStream& );
      81             :     bool Dif2Doc( SvStream& );
      82             :     bool ExtText2Doc( SvStream& );      // with pExtOptions
      83             :     bool RTF2Doc( SvStream&, const String& rBaseURL );
      84             :     bool HTML2Doc( SvStream&, const String& rBaseURL );
      85             : 
      86             : public:
      87             :     ScImportExport( ScDocument* );                  // the whole document
      88             :     ScImportExport( ScDocument*, const String& );   // Range/cell input
      89             :     ScImportExport( ScDocument*, const ScAddress& );
      90             :     ScImportExport( ScDocument*, const ScRange& );
      91             :    ~ScImportExport();
      92             : 
      93             :     void SetExtOptions( const ScAsciiOptions& rOpt );
      94             : 
      95             :     bool IsDoubleRef() const { return !( bAll || bSingle ); }
      96             :     bool IsSingleRef() const { return bSingle; }
      97             :     bool IsNoRef() const     { return bAll;    }
      98           0 :     bool IsRef() const       { return !bAll; }
      99             : 
     100           0 :     const ScRange& GetRange() const { return aRange; }
     101             : 
     102             :     bool IsUndo() const      { return bUndo; }
     103             :     void SetUndo( bool b )   { bUndo = b;    }
     104             : 
     105             :     SC_DLLPUBLIC static void EmbeddedNullTreatment( OUString & rStr );
     106             : 
     107             :     static bool  IsFormatSupported( sal_uLong nFormat );
     108             :     static const sal_Unicode* ScanNextFieldFromString( const sal_Unicode* p,
     109             :             String& rField, sal_Unicode cStr, const sal_Unicode* pSeps,
     110             :             bool bMergeSeps, bool& rbIsQuoted, bool& rbOverflowCell );
     111             :     static  void    WriteUnicodeOrByteString( SvStream& rStrm, const String& rString, bool bZero = false );
     112             :     static  void    WriteUnicodeOrByteEndl( SvStream& rStrm );
     113             :     static  inline  bool    IsEndianSwap( const SvStream& rStrm );
     114             : 
     115             :     //! only if stream is only used in own (!) memory
     116             :     static  inline  void    SetNoEndianSwap( SvStream& rStrm );
     117             : 
     118             :     sal_Unicode GetSeparator() const { return cSep; }
     119           0 :     void SetSeparator( sal_Unicode c ) { cSep = c; }
     120             :     sal_Unicode GetDelimiter() const { return cStr; }
     121           0 :     void SetDelimiter( sal_Unicode c ) { cStr = c; }
     122             :     bool IsFormulas() const { return bFormulas; }
     123           0 :     void SetFormulas( bool b ) { bFormulas = b; }
     124             :     bool IsIncludeFiltered() const { return bIncludeFiltered; }
     125           0 :     void SetIncludeFiltered( bool b ) { bIncludeFiltered = b; }
     126             : 
     127             :     void SetSizeLimit( sal_uLong nNew ) { nSizeLimit = nNew; }  // for the moment only for Ascii
     128             : 
     129           0 :     void            SetStreamPath( const String& rPath ) { aStreamPath = rPath; }
     130             :     const String&   GetStreamPath() const { return aStreamPath; }
     131             : 
     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 );
     135             : 
     136             :     bool ImportStream( SvStream&, const String& rBaseURL, sal_uLong=FORMAT_STRING );
     137             :     bool ExportStream( SvStream&, const String& rBaseURL, sal_uLong=FORMAT_STRING );
     138             : 
     139             :     bool ImportData( const String& rMimeType,
     140             :                      const ::com::sun::star::uno::Any & rValue );
     141             :     bool ExportData( const String& rMimeType,
     142             :                      ::com::sun::star::uno::Any & rValue  );
     143             : 
     144             :     // after import
     145           2 :     bool IsOverflowRow() const { return bOverflowRow; }
     146           2 :     bool IsOverflowCol() const { return bOverflowCol; }
     147           2 :     bool IsOverflowCell() const { return bOverflowCell; }
     148           0 :     bool IsOverflow() const { return bOverflowRow || bOverflowCol || bOverflowCell; }
     149             : 
     150           0 :     const String& GetNonConvertibleChars() const { return aNonConvertibleChars; }
     151             : 
     152             :     bool IsApi() const { return mbApi; }
     153           0 :     void SetApi( bool bApi ) { mbApi = bApi; }
     154             :     const ScExportTextOptions& GetExportTextOptions() { return mExportTextOptions; }
     155           8 :     void SetExportTextOptions( const ScExportTextOptions& options ) { mExportTextOptions = options; }
     156             : };
     157             : 
     158             : 
     159           0 : inline bool ScImportExport::IsEndianSwap( const SvStream& rStrm )
     160             : {
     161             : #ifdef OSL_BIGENDIAN
     162             :     return rStrm.GetNumberFormatInt() != NUMBERFORMAT_INT_BIGENDIAN;
     163             : #else
     164           0 :     return rStrm.GetNumberFormatInt() != NUMBERFORMAT_INT_LITTLEENDIAN;
     165             : #endif
     166             : }
     167             : 
     168           0 : inline void ScImportExport::SetNoEndianSwap( SvStream& rStrm )
     169             : {
     170             : #ifdef OSL_BIGENDIAN
     171             :     rStrm.SetNumberFormatInt( NUMBERFORMAT_INT_BIGENDIAN );
     172             : #else
     173           0 :     rStrm.SetNumberFormatInt( NUMBERFORMAT_INT_LITTLEENDIAN );
     174             : #endif
     175           0 : }
     176             : 
     177             : 
     178             : // Helper class for importing clipboard strings as streams.
     179           0 : class ScImportStringStream : public SvMemoryStream
     180             : {
     181             : public:
     182           0 :     ScImportStringStream( const OUString rStr )
     183           0 :         : SvMemoryStream( (void*)rStr.getStr(),
     184           0 :                 rStr.getLength() * sizeof(sal_Unicode), STREAM_READ)
     185             :     {
     186           0 :         SetStreamCharSet( RTL_TEXTENCODING_UNICODE );
     187           0 :         SetEndianSwap( false );
     188           0 :     }
     189             : };
     190             : 
     191             : /** Read a CSV (comma separated values) data line using
     192             :     ReadUniOrByteStringLine().
     193             : 
     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.
     207             : 
     208             :     If bEmbeddedLineBreak==FALSE, nothing is parsed and the
     209             :     string returned is simply one ReadUniOrByteStringLine().
     210             : 
     211             :     @param rFieldSeparators
     212             :     A list of characters that each may act as a field separator.
     213             : 
     214             :     @param cFieldQuote
     215             :     The quote character used.
     216             : 
     217             :     check Stream::good() to detect IO problems during read
     218             : 
     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.
     234             : 
     235             :   */
     236             : SC_DLLPUBLIC OUString ReadCsvLine( SvStream &rStream, bool bEmbeddedLineBreak,
     237             :         const String& rFieldSeparators, sal_Unicode cFieldQuote );
     238             : 
     239             : #endif
     240             : 
     241             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10