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

Generated by: LCOV version 1.10