LCOV - code coverage report
Current view: top level - sc/source/filter/inc - xihelper.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 7 10 70.0 %
Date: 2015-06-13 12:38:46 Functions: 8 12 66.7 %
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_FILTER_INC_XIHELPER_HXX
      21             : #define INCLUDED_SC_SOURCE_FILTER_INC_XIHELPER_HXX
      22             : 
      23             : #include <editeng/editdata.hxx>
      24             : #include <boost/noncopyable.hpp>
      25             : #include <boost/shared_ptr.hpp>
      26             : #include <boost/ptr_container/ptr_vector.hpp>
      27             : #include "types.hxx"
      28             : #include "xladdress.hxx"
      29             : #include "xiroot.hxx"
      30             : #include "xistring.hxx"
      31             : 
      32             : class ScRangeList;
      33             : 
      34             : namespace svl {
      35             : 
      36             : class SharedStringPool;
      37             : 
      38             : }
      39             : 
      40             : // Excel->Calc cell address/range conversion ==================================
      41             : 
      42             : /** Provides functions to convert Excel cell addresses to Calc cell addresses. */
      43         168 : class XclImpAddressConverter : public XclAddressConverterBase
      44             : {
      45             : public:
      46             :     explicit            XclImpAddressConverter( const XclImpRoot& rRoot );
      47             : 
      48             :     // cell address -----------------------------------------------------------
      49             : 
      50             :     /** Checks if the passed Excel cell address is valid.
      51             :         @param rXclPos  The Excel cell address to check.
      52             :         @param bWarn  true = Sets the internal flag that produces a warning box
      53             :             after loading/saving the file, if the cell address is not valid.
      54             :         @return  true = Cell address in rXclPos is valid. */
      55             :     bool                CheckAddress( const XclAddress& rXclPos, bool bWarn );
      56             : 
      57             :     /** Converts the passed Excel cell address to a Calc cell address.
      58             :         @param rScPos  (Out) The converted Calc cell address, if valid.
      59             :         @param rXclPos  The Excel cell address to convert.
      60             :         @param bWarn  true = Sets the internal flag that produces a warning box
      61             :             after loading/saving the file, if the cell address is invalid.
      62             :         @return  true = Cell address returned in rScPos is valid. */
      63             :     bool                ConvertAddress( ScAddress& rScPos,
      64             :                             const XclAddress& rXclPos, SCTAB nScTab, bool bWarn );
      65             : 
      66             :     /** Returns a valid cell address by moving it into allowed dimensions.
      67             :         @param rXclPos  The Excel cell address to convert.
      68             :         @param bWarn  true = Sets the internal flag that produces a warning box
      69             :             after loading/saving the file, if the cell address is invalid.
      70             :         @return  The converted Calc cell address. */
      71             :     ScAddress           CreateValidAddress( const XclAddress& rXclPos,
      72             :                             SCTAB nScTab, bool bWarn );
      73             : 
      74             :     // cell range -------------------------------------------------------------
      75             : 
      76             :     /** Converts the passed Excel cell range to a Calc cell range.
      77             :         @param rScRange  (Out) The converted Calc cell range, if valid.
      78             :         @param rXclRange  The Excel cell range to convert.
      79             :         @param bWarn  true = Sets the internal flag that produces a warning box
      80             :             after loading/saving the file, if the cell range contains invalid cells.
      81             :         @return  true = Cell range returned in rScRange is valid (original or cropped). */
      82             :     bool                ConvertRange( ScRange& rScRange, const XclRange& rXclRange,
      83             :                             SCTAB nScTab1, SCTAB nScTab2, bool bWarn );
      84             : 
      85             :     // cell range list --------------------------------------------------------
      86             : 
      87             :     /** Converts the passed Excel cell range list to a Calc cell range list.
      88             :         @descr  The start position of the ranges will not be modified. Cell
      89             :             ranges that fit partly into valid dimensions are cropped
      90             :             accordingly. Cell ranges that do not fit at all, are not inserted
      91             :             into the Calc cell range list.
      92             :         @param rScRanges  (Out) The converted Calc cell range list.
      93             :         @param rXclRanges  The Excel cell range list to convert.
      94             :         @param bWarn  true = Sets the internal flag that produces a warning box
      95             :             after loading/saving the file, if at least one of the cell ranges
      96             :             contains invalid cells. */
      97             :     void                ConvertRangeList( ScRangeList& rScRanges,
      98             :                             const XclRangeList& rXclRanges, SCTAB nScTab, bool bWarn );
      99             : };
     100             : 
     101             : // String->EditEngine conversion ==============================================
     102             : 
     103             : class EditTextObject;
     104             : 
     105             : /** This class provides methods to convert an XclImpString.
     106             :     @The string can be converted to an edit engine text object or directly
     107             :     to a Calc edit cell. */
     108             : class XclImpStringHelper : boost::noncopyable
     109             : {
     110             : public:
     111             :     /** Returns a new edit engine text object.
     112             :         @param nXFIndex  Index to XF for first text portion (for escapement). */
     113             :     static EditTextObject* CreateTextObject(
     114             :                             const XclImpRoot& rRoot,
     115             :                             const XclImpString& rString );
     116             : 
     117             :     static void SetToDocument(
     118             :         ScDocumentImport& rDoc, const ScAddress& rPos, const XclImpRoot& rRoot,
     119             :         const XclImpString& rString, sal_uInt16 nXFIndex = 0 );
     120             : 
     121             : private:
     122             :     /** We don't want anybody to instantiate this class, since it is just a
     123             :         collection of static methods. To enforce this, the default constructor
     124             :         is made private */
     125             :     XclImpStringHelper();
     126             : };
     127             : 
     128             : // Header/footer conversion ===================================================
     129             : 
     130             : class EditEngine;
     131             : class EditTextObject;
     132             : class SfxItemSet;
     133             : class SvxFieldItem;
     134             : struct XclFontData;
     135             : 
     136             : /** Converts an Excel header/footer string into three edit engine text objects.
     137             :     @descr  Header/footer content is divided into three parts: Left, center and
     138             :     right portion. All formatting information is encoded in the Excel string
     139             :     using special character seuences. A control sequence starts with the ampersand
     140             :     character.
     141             : 
     142             :     Supported control sequences:
     143             :     &L                      start of left portion
     144             :     &C                      start of center portion
     145             :     &R                      start of right portion
     146             :     &P                      current page number
     147             :     &N                      page count
     148             :     &D                      current date
     149             :     &T                      current time
     150             :     &A                      table name
     151             :     &F                      file name without path (see also &Z&F)
     152             :     &Z                      file path without file name (converted to full file name, see also &Z&F)
     153             :     &Z&F                    file path and name
     154             :     &U                      underlining on/off
     155             :     &E                      double underlining on/off
     156             :     &S                      strikeout characters on/off
     157             :     &X                      superscript on/off
     158             :     &Y                      subscript on/off
     159             :     &"fontname,fontstyle"   use font with name 'fontname' and style 'fontstyle'
     160             :     &fontheight             set font height in points ('fontheight' is a decimal value)
     161             : 
     162             :     Known but unsupported control sequences:
     163             :     &G                      picture
     164             :  */
     165             : class XclImpHFConverter : protected XclImpRoot, private boost::noncopyable
     166             : {
     167             : public:
     168             :     explicit            XclImpHFConverter( const XclImpRoot& rRoot );
     169             :                         virtual ~XclImpHFConverter();
     170             : 
     171             :     /** Parses the passed string and creates three new edit engine text objects. */
     172             :     void                ParseString( const OUString& rHFString );
     173             : 
     174             :     /** Creates a ScPageHFItem and inserts it into the passed item set. */
     175             :     void                FillToItemSet( SfxItemSet& rItemSet, sal_uInt16 nWhichId ) const;
     176             :     /** Returns the total height of the converted header or footer in twips. */
     177             :     sal_Int32           GetTotalHeight() const;
     178             : 
     179             : private:    // types
     180             :     typedef ::std::unique_ptr< XclFontData > XclFontDataPtr;
     181             : 
     182             :     /** Enumerates the supported header/footer portions. */
     183             :     enum XclImpHFPortion { EXC_HF_LEFT, EXC_HF_CENTER, EXC_HF_RIGHT, EXC_HF_PORTION_COUNT };
     184             : 
     185             :     /** Contains all information about a header/footer portion. */
     186         216 :     struct XclImpHFPortionInfo
     187             :     {
     188             :         typedef boost::shared_ptr< EditTextObject > EditTextObjectRef;
     189             :         EditTextObjectRef   mxObj;          /// Edit engine text object.
     190             :         ESelection          maSel;          /// Edit engine selection.
     191             :         sal_Int32           mnHeight;       /// Height of previous lines in twips.
     192             :         sal_uInt16          mnMaxLineHt;    /// Maximum font height for the current text line.
     193             :         explicit            XclImpHFPortionInfo();
     194             :     };
     195             :     typedef ::std::vector< XclImpHFPortionInfo > XclImpHFPortionInfoVec;
     196             : 
     197             : private:
     198             :     /** Returns the current edit engine text object. */
     199         344 :     inline XclImpHFPortionInfo& GetCurrInfo() { return maInfos[ meCurrObj ]; }
     200             :     /** Returns the current edit engine text object. */
     201         108 :     inline XclImpHFPortionInfo::EditTextObjectRef& GetCurrObj() { return GetCurrInfo().mxObj; }
     202             :     /** Returns the current selection. */
     203         236 :     inline ESelection&  GetCurrSel() { return GetCurrInfo().maSel; }
     204             : 
     205             :     /** Returns the maximum line height of the specified portion. */
     206             :     sal_uInt16          GetMaxLineHeight( XclImpHFPortion ePortion ) const;
     207             :     /** Returns the current maximum line height. */
     208             :     sal_uInt16          GetCurrMaxLineHeight() const;
     209             : 
     210             :     /** Updates the maximum line height of the specified portion, using the current font size. */
     211             :     void                UpdateMaxLineHeight( XclImpHFPortion ePortion );
     212             :     /** Updates the current maximum line height, using the current font size. */
     213             :     void                UpdateCurrMaxLineHeight();
     214             : 
     215             :     /** Sets the font attributes at the current selection.
     216             :         @descr  After that, the start position of the current selection object is
     217             :         adjusted to the end of the selection. */
     218             :     void                SetAttribs();
     219             :     /** Resets font data to application default font. */
     220             :     void                ResetFontData();
     221             : 
     222             :     /** Inserts maCurrText into edit engine and adjusts the current selection object.
     223             :         @descr  The text shall not contain a newline character.
     224             :         The text will be cleared after insertion. */
     225             :     void                InsertText();
     226             :     /** Inserts the passed text field and adjusts the current selection object. */
     227             :     void                InsertField( const SvxFieldItem& rFieldItem );
     228             :     /** Inserts a line break and adjusts the current selection object. */
     229             :     void                InsertLineBreak();
     230             : 
     231             :     /** Creates the edit engine text object of current portion from edit engine. */
     232             :     void                CreateCurrObject();
     233             :     /** Changes current header/footer portion to eNew.
     234             :         @descr  Creates text object of current portion and reinitializes edit engine. */
     235             :     void                SetNewPortion( XclImpHFPortion eNew );
     236             : 
     237             : private:
     238             :     EditEngine&         mrEE;               /// The header/footer edit engine.
     239             :     XclImpHFPortionInfoVec maInfos;         /// Edit engine text objects for all portions.
     240             :     OUString            maCurrText;         /// Current text to insert into edit engine.
     241             :     XclFontDataPtr      mxFontData;         /// Font data of current text.
     242             :     XclImpHFPortion     meCurrObj;          /// The current portion.
     243             : };
     244             : 
     245             : // URL conversion =============================================================
     246             : 
     247             : /** This class contains static methods to decode an URL stored in an Excel file.
     248             :     @descr  Excel URLs can contain a sheet name, for instance: path\[test.xls]Sheet1
     249             :     This sheet name will be extracted automatically. */
     250             : class XclImpUrlHelper : boost::noncopyable
     251             : {
     252             : public:
     253             :     /** Decodes an encoded external document URL with optional sheet name.
     254             :         @param rUrl  Returns the decoded file name incl. path.
     255             :         @param rTabName  Returns the decoded sheet name.
     256             :         @param rbSameWb  Returns true, if the URL is a reference to the own workbook.
     257             :         @param rEncodedUrl   An encoded URL from Excel. */
     258             :     static void         DecodeUrl(
     259             :                             OUString& rUrl,
     260             :                             OUString& rTabName,
     261             :                             bool& rbSameWb,
     262             :                             const XclImpRoot& rRoot,
     263             :                             const OUString& rEncodedUrl );
     264             : 
     265             :     /** Decodes an encoded external document URL without sheet name.
     266             :         @param rUrl  Returns the decoded file name incl. path.
     267             :         @param rbSameWb  Returns true, if the URL is a reference to the own workbook.
     268             :         @param rEncodedUrl   An encoded URL from Excel. */
     269             : 
     270             :     static void         DecodeUrl(
     271             :                             OUString& rUrl,
     272             :                             bool& rbSameWb,
     273             :                             const XclImpRoot& rRoot,
     274             :                             const OUString& rEncodedUrl );
     275             : 
     276             :     /** Decodes the passed URL to OLE or DDE link components.
     277             :         @descr  For DDE links: Decodes to application name and topic.
     278             :         For OLE object links: Decodes to class name and document URL.
     279             :         @return  true = decoding was successful, returned strings are valid (not empty). */
     280             :     static bool         DecodeLink( OUString& rApplic, OUString& rTopic, const OUString& rEncUrl );
     281             : 
     282             : private:
     283             :     /** We don't want anybody to instantiate this class, since it is just a
     284             :         collection of static methods. To enforce this, the default constructor
     285             :         is made private */
     286             :     XclImpUrlHelper();
     287             : };
     288             : 
     289             : // Cached values ==============================================================
     290             : 
     291             : class ScTokenArray;
     292             : 
     293             : /** This class stores one cached value of a cached value list (used for instance in
     294             :     CRN, EXTERNNAME, tArray). */
     295             : class XclImpCachedValue : boost::noncopyable
     296             : {
     297             : public:
     298             :     /** Creates a cached value and reads contents from stream and stores it with its array address. */
     299             :     explicit            XclImpCachedValue( XclImpStream& rStrm );
     300             :     virtual             ~XclImpCachedValue();
     301             : 
     302             :     /** Returns the type of the cached value (EXC_CACHEDVAL_*). */
     303           2 :     inline sal_uInt8    GetType() const     { return mnType; }
     304             :     /** Returns the cached string value, if this value is a string, else an empty string. */
     305           2 :     const OUString& GetString() const { return maStr;}
     306             :     /** Returns the cached number, if this value has number type, else 0.0. */
     307           0 :     inline double       GetValue() const    { return mfValue; }
     308             :     /** Returns the cached Boolean value, if this value has Boolean type, else false. */
     309           0 :     inline bool         GetBool() const     { return (mnType == EXC_CACHEDVAL_BOOL) && (mnBoolErr != 0); }
     310             :     /** Returns the cached Calc error code, if this value has Error type, else 0. */
     311           0 :     inline sal_uInt8    GetXclError() const { return (mnType == EXC_CACHEDVAL_ERROR) ? mnBoolErr : EXC_ERR_NA; }
     312             :     /** Returns the cached Calc error code, if this value has Error type, else 0. */
     313             :     sal_uInt16              GetScError() const;
     314             : 
     315             : protected:
     316             :     typedef ::std::unique_ptr< const ScTokenArray >   ScTokenArrayPtr;
     317             : 
     318             :     OUString            maStr;      /// Cached value is a string.
     319             :     double              mfValue;    /// Cached value is a double.
     320             :     ScTokenArrayPtr     mxTokArr;   /// Cached value is a formula or error code or Boolean.
     321             :     sal_uInt8           mnBoolErr;  /// Boolean value or Excel error code.
     322             :     sal_uInt8           mnType;     /// The type of the cached value (EXC_CACHEDVAL_*).
     323             : };
     324             : 
     325             : /** Contains cached values in a 2-dimensional array. */
     326             : class XclImpCachedMatrix
     327             : {
     328             : public:
     329             :     explicit            XclImpCachedMatrix( XclImpStream& rStrm );
     330             :                         ~XclImpCachedMatrix();
     331             : 
     332             :     /** Creates a new ScMatrix object and fills it with the contained values. */
     333             :     ScMatrixRef CreateScMatrix( svl::SharedStringPool& rPool ) const;
     334             : 
     335             : private:
     336             :     typedef boost::ptr_vector< XclImpCachedValue > XclImpValueList;
     337             : 
     338             :     XclImpValueList     maValueList;    /// List of cached cell values.
     339             :     SCSIZE              mnScCols;       /// Number of cached columns.
     340             :     SCSIZE              mnScRows;       /// Number of cached rows.
     341             : };
     342             : 
     343             : #endif
     344             : 
     345             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11