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

Generated by: LCOV version 1.10