LCOV - code coverage report
Current view: top level - sc/source/filter/inc - xehelper.hxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 5 6 83.3 %
Date: 2015-06-13 12:38:46 Functions: 6 8 75.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 INCLUDED_SC_SOURCE_FILTER_INC_XEHELPER_HXX
      21             : #define INCLUDED_SC_SOURCE_FILTER_INC_XEHELPER_HXX
      22             : 
      23             : #include <boost/noncopyable.hpp>
      24             : #include <memory>
      25             : #include "xladdress.hxx"
      26             : #include "xeroot.hxx"
      27             : #include "xestring.hxx"
      28             : 
      29             : // Export progress bar ========================================================
      30             : 
      31             : class ScfProgressBar;
      32             : 
      33             : /** The main progress bar for the export filter.
      34             : 
      35             :     This class encapsulates creation and initialization of sub progress
      36             :     segments. The Activate***Segment() functions activate a specific segement
      37             :     of the main progress bar. The implementation of these functions contain the
      38             :     calculation of the needed size of the segment. Following calls of the
      39             :     Progress() function increase the currently activated sub segment.
      40             :  */
      41             : class XclExpProgressBar : protected XclExpRoot
      42             : {
      43             : public:
      44             :     explicit            XclExpProgressBar( const XclExpRoot& rRoot );
      45             :     virtual             ~XclExpProgressBar();
      46             : 
      47             :     /** Initializes all segments and sub progress bars. */
      48             :     void                Initialize();
      49             : 
      50             :     /** Increases the number of existing ROW records by 1. */
      51             :     void                IncRowRecordCount();
      52             : 
      53             :     /** Activates the progress segment to create ROW records. */
      54             :     void                ActivateCreateRowsSegment();
      55             :     /** Activates the progress segment to finalize ROW records. */
      56             :     void                ActivateFinalRowsSegment();
      57             : 
      58             :     /** Increases the currently activated (sub) progress bar by 1 step. */
      59             :     void                Progress();
      60             : 
      61             : private:
      62             :     typedef std::unique_ptr< ScfProgressBar > ScfProgressBarPtr;
      63             : 
      64             :     ScfProgressBarPtr   mxProgress;         /// Progress bar implementation.
      65             :     ScfProgressBar*     mpSubProgress;      /// Current sub progress bar.
      66             : 
      67             :     ScfProgressBar*     mpSubRowCreate;     /// Sub progress bar for creating table rows.
      68             :     ScfInt32Vec         maSubSegRowCreate;  /// Segment ID's for all sheets in sub progress bar.
      69             : 
      70             :     ScfProgressBar*     mpSubRowFinal;      /// Sub progress bar for finalizing ROW records.
      71             :     sal_Int32           mnSegRowFinal;      /// Progress segment for finalizing ROW records.
      72             : 
      73             :     sal_Size            mnRowCount;         /// Number of created ROW records.
      74             : };
      75             : 
      76             : // Calc->Excel cell address/range conversion ==================================
      77             : 
      78             : /** Provides functions to convert Calc cell addresses to Excel cell addresses. */
      79         144 : class XclExpAddressConverter : public XclAddressConverterBase
      80             : {
      81             : public:
      82             :     explicit            XclExpAddressConverter( const XclExpRoot& rRoot );
      83             : 
      84             :     // cell address -----------------------------------------------------------
      85             : 
      86             :     /** Checks if the passed Calc cell address is valid.
      87             :         @param rScPos  The Calc cell address to check.
      88             :         @param bWarn  true = Sets the internal flag that produces a warning box
      89             :             after loading/saving the file, if the cell address is not valid.
      90             :         @return  true = Cell address in rScPos is valid. */
      91             :     bool                CheckAddress( const ScAddress& rScPos, bool bWarn );
      92             : 
      93             :     /** Converts the passed Calc cell address to an Excel cell address.
      94             :         @param rXclPos  (Out) The converted Excel cell address, if valid.
      95             :         @param rScPos  The Calc cell address to convert.
      96             :         @param bWarn  true = Sets the internal flag that produces a warning box
      97             :             after loading/saving the file, if the cell address is not valid.
      98             :         @return  true = Cell address returned in rXclPos is valid. */
      99             :     bool                ConvertAddress( XclAddress& rXclPos,
     100             :                             const ScAddress& rScPos, bool bWarn );
     101             : 
     102             :     /** Returns a valid cell address by moving it into allowed dimensions.
     103             :         @param rScPos  The Calc cell address to convert.
     104             :         @param bWarn  true = Sets the internal flag that produces a warning box
     105             :             after loading/saving the file, if the cell address is invalid.
     106             :         @return  The converted Excel cell address. */
     107             :     XclAddress          CreateValidAddress( const ScAddress& rScPos, bool bWarn );
     108             : 
     109             :     // cell range -------------------------------------------------------------
     110             : 
     111             :     /** Checks if the passed cell range is valid (checks start and end position).
     112             :         @param rScRange  The Calc cell range to check.
     113             :         @param bWarn  true = Sets the internal flag that produces a warning box
     114             :             after loading/saving the file, if the cell range is not valid.
     115             :         @return  true = Cell range in rScRange is valid. */
     116             :     bool                CheckRange( const ScRange& rScRange, bool bWarn );
     117             : 
     118             :     /** Checks and eventually crops the cell range to valid dimensions.
     119             :         @descr  The start position of the range will not be modified.
     120             :         @param rScRange  (In/out) The cell range to validate.
     121             :         @param bWarn  true = Sets the internal flag that produces a warning box
     122             :             after loading/saving the file, if the cell range contains invalid
     123             :             cells. If the range is partly valid, this function sets the warning
     124             :             flag, corrects the range and returns true.
     125             :         @return  true = Cell range in rScRange is valid (original or cropped). */
     126             :     bool                ValidateRange( ScRange& rScRange, bool bWarn );
     127             : 
     128             :     /** Converts the passed Calc cell range to an Excel cell range.
     129             :         @param rXclRange  (Out) The converted Excel cell range, if valid.
     130             :         @param rScRange  The Calc cell range to convert.
     131             :         @param bWarn  true = Sets the internal flag that produces a warning box
     132             :             after loading/saving the file, if the cell range contains invalid cells.
     133             :         @return  true = Cell range returned in rXclRange is valid (original or cropped). */
     134             :     bool                ConvertRange( XclRange& rXclRange, const ScRange& rScRange, bool bWarn );
     135             : 
     136             :     // cell range list --------------------------------------------------------
     137             : 
     138             :     /** Checks and eventually crops the cell ranges to valid dimensions.
     139             :         @descr  The start position of the ranges will not be modified. Cell
     140             :             ranges that fit partly into valid dimensions are cropped
     141             :             accordingly. Cell ranges that do not fit at all, are removed from
     142             :             the cell range list.
     143             :         @param rScRanges  (In/out) The cell range list to check.
     144             :         @param bWarn  true = Sets the internal flag that produces a warning box
     145             :             after loading/saving the file, if at least one of the cell ranges
     146             :             contains invalid cells. */
     147             :     void                ValidateRangeList( ScRangeList& rScRanges, bool bWarn );
     148             : 
     149             :     /** Converts the passed Calc cell range list to an Excel cell range list.
     150             :         @descr  The start position of the ranges will not be modified. Cell
     151             :             ranges that fit partly into valid dimensions are cropped
     152             :             accordingly. Cell ranges that do not fit at all, are not inserted
     153             :             into the Excel cell range list.
     154             :         @param rXclRanges  (Out) The converted Excel cell range list.
     155             :         @param rScRanges  The Calc cell range list to convert.
     156             :         @param bWarn  true = Sets the internal flag that produces a warning box
     157             :             after loading/saving the file, if at least one of the cell ranges
     158             :             contains invalid cells. */
     159             :     void                ConvertRangeList( XclRangeList& rXclRanges,
     160             :                             const ScRangeList& rScRanges, bool bWarn );
     161             : };
     162             : 
     163             : // EditEngine->String conversion ==============================================
     164             : 
     165             : class SvxURLField;
     166             : class XclExpHyperlink;
     167             : 
     168             : /** Helper to create HLINK records during creation of formatted cell strings.
     169             : 
     170             :     In Excel it is not possible to have more than one hyperlink in a cell. This
     171             :     helper detects multiple occurrences of hyperlinks and fills a string which
     172             :     is used to create a cell note containing all URLs. Only cells containing
     173             :     one hyperlink are exported as hyperlink cells.
     174             :  */
     175             : class XclExpHyperlinkHelper : protected XclExpRoot
     176             : {
     177             : public:
     178             :     typedef std::shared_ptr< XclExpHyperlink > XclExpHyperlinkRef;
     179             : 
     180             :     explicit            XclExpHyperlinkHelper( const XclExpRoot& rRoot, const ScAddress& rScPos );
     181             :                         virtual ~XclExpHyperlinkHelper();
     182             : 
     183             :     /** Processes the passed URL field (tries to create a HLINK record).
     184             :         @return  The representation string of the URL field. */
     185             :     OUString ProcessUrlField( const SvxURLField& rUrlField );
     186             : 
     187             :     /** Returns true, if a single HLINK record has been created. */
     188             :     bool                HasLinkRecord() const;
     189             :     /** Returns the craeted single HLINk record, or an empty reference. */
     190             :     XclExpHyperlinkRef  GetLinkRecord();
     191             : 
     192             :     /** Returns true, if multiple URLs have been processed. */
     193           2 :     inline bool         HasMultipleUrls() const { return mbMultipleUrls; }
     194             :     /** Returns a string containing all processed URLs. */
     195           0 :     inline const OUString& GetUrlList() { return maUrlList; }
     196             : 
     197             : private:
     198             :     XclExpHyperlinkRef  mxLinkRec;          /// Created HLINK record.
     199             :     ScAddress           maScPos;            /// Cell position to set at the HLINK record.
     200             :     OUString            maUrlList;          /// List with all processed URLs.
     201             :     bool                mbMultipleUrls;     /// true = Multiple URL fields processed.
     202             : };
     203             : 
     204             : class EditEngine;
     205             : class EditTextObject;
     206             : class SdrTextObj;
     207             : class ScPatternAttr;
     208             : 
     209             : /** This class provides methods to create an XclExpString.
     210             :     @descr  The string can be created from an edit engine text object or
     211             :     directly from a Calc edit cell. */
     212             : class XclExpStringHelper : boost::noncopyable
     213             : {
     214             : public:
     215             :     /** Creates a new unformatted string from the passed string.
     216             :         @descr  Creates a Unicode string or a byte string, depending on the
     217             :                 current BIFF version contained in the passed XclExpRoot object.
     218             :         @param rString  The source string.
     219             :         @param nFlags  Modifiers for string export.
     220             :         @param nMaxLen  The maximum number of characters to store in this string.
     221             :         @return  The new string object (shared pointer). */
     222             :     static XclExpStringRef CreateString(
     223             :                             const XclExpRoot& rRoot,
     224             :                             const OUString& rString,
     225             :                             XclStrFlags nFlags = EXC_STR_DEFAULT,
     226             :                             sal_uInt16 nMaxLen = EXC_STR_MAXLEN );
     227             : 
     228             :     /** Creates a new unformatted string from the passed character.
     229             :         @descr  Creates a Unicode string or a byte string, depending on the
     230             :                 current BIFF version contained in the passed XclExpRoot object.
     231             :         @param cChar  The source character. The NUL character is explicitly allowed.
     232             :         @param nFlags  Modifiers for string export.
     233             :         @param nMaxLen  The maximum number of characters to store in this string.
     234             :         @return  The new string object (shared pointer). */
     235             :     static XclExpStringRef CreateString(
     236             :                             const XclExpRoot& rRoot,
     237             :                             sal_Unicode cChar,
     238             :                             XclStrFlags nFlags = EXC_STR_DEFAULT,
     239             :                             sal_uInt16 nMaxLen = EXC_STR_MAXLEN );
     240             : 
     241             :     /** Appends an unformatted string to an Excel string object.
     242             :         @descr  Selects the correct Append() function depending on the current
     243             :                 BIFF version contained in the passed XclExpRoot object.
     244             :         @param rXclString  The Excel string object.
     245             :         @param rString  The source string. */
     246             :     static void         AppendString(
     247             :                             XclExpString& rXclString,
     248             :                             const XclExpRoot& rRoot,
     249             :                             const OUString& rString );
     250             : 
     251             :     /** Appends a character to an Excel string object.
     252             :         @descr  Selects the correct Append() function depending on the current
     253             :                 BIFF version contained in the passed XclExpRoot object.
     254             :         @param rXclString  The Excel string object.
     255             :         @param rString  The source string. */
     256             :     static void         AppendChar(
     257             :                             XclExpString& rXclString,
     258             :                             const XclExpRoot& rRoot,
     259             :                             sal_Unicode cChar );
     260             : 
     261             :     /** Creates a new formatted string from a Calc string cell.
     262             :         @descr  Creates a Unicode string or a byte string, depending on the
     263             :                 current BIFF version contained in the passed XclExpRoot object.
     264             :                 May create a formatted string object, if the cell text contains
     265             :                 different script types.
     266             :         @param rStringCell  The Calc string cell object.
     267             :         @param pCellAttr  The set item containing the cell formatting.
     268             :         @param nFlags  Modifiers for string export.
     269             :         @param nMaxLen  The maximum number of characters to store in this string.
     270             :         @return  The new string object (shared pointer). */
     271             :     static XclExpStringRef CreateCellString(
     272             :                             const XclExpRoot& rRoot,
     273             :                             const OUString& rString,
     274             :                             const ScPatternAttr* pCellAttr,
     275             :                             XclStrFlags nFlags = EXC_STR_DEFAULT,
     276             :                             sal_uInt16 nMaxLen = EXC_STR_MAXLEN );
     277             : 
     278             :     /** Creates a new formatted string from a Calc edit cell.
     279             :         @descr  Creates a Unicode string or a byte string, depending on the
     280             :                 current BIFF version contained in the passed XclExpRoot object.
     281             :         @param rEditCell  The Calc edit cell object.
     282             :         @param pCellAttr  The set item containing the cell formatting.
     283             :         @param rLinkHelper  Helper object for hyperlink conversion.
     284             :         @param nFlags  Modifiers for string export.
     285             :         @param nMaxLen  The maximum number of characters to store in this string.
     286             :         @return  The new string object (shared pointer). */
     287             :     static XclExpStringRef CreateCellString(
     288             :                             const XclExpRoot& rRoot,
     289             :                             const EditTextObject& rEditText,
     290             :                             const ScPatternAttr* pCellAttr,
     291             :                             XclExpHyperlinkHelper& rLinkHelper,
     292             :                             XclStrFlags nFlags = EXC_STR_DEFAULT,
     293             :                             sal_uInt16 nMaxLen = EXC_STR_MAXLEN );
     294             : 
     295             :     /** Creates a new formatted string from a drawing text box.
     296             :         @descr  Creates a Unicode string or a byte string, depending on the
     297             :                 current BIFF version contained in the passed XclExpRoot object.
     298             :         @param rTextObj  The text box object.
     299             :         @param nFlags  Modifiers for string export.
     300             :         @param nMaxLen  The maximum number of characters to store in this string.
     301             :         @return  The new string object (shared pointer). */
     302             :     static XclExpStringRef CreateString(
     303             :                             const XclExpRoot& rRoot,
     304             :                             const SdrTextObj& rTextObj,
     305             :                             XclStrFlags nFlags = EXC_STR_DEFAULT,
     306             :                             sal_uInt16 nMaxLen = EXC_STR_MAXLEN );
     307             : 
     308             :     /** Creates a new formatted string from a edit text string.
     309             :         @param rEditObj  The edittext object.
     310             :         @param nFlags  Modifiers for string export.
     311             :         @param nMaxLen The maximum number of characters to store in this string.
     312             :         @return  The new string object. */
     313             :     static XclExpStringRef CreateString(
     314             :                             const XclExpRoot& rRoot,
     315             :                             const EditTextObject& rEditObj,
     316             :                             XclStrFlags nFlags = EXC_STR_DEFAULT,
     317             :                             sal_uInt16 nMaxLen = EXC_STR_MAXLEN );
     318             : 
     319             :     /** Returns the script type first text portion different to WEAK, or the system
     320             :         default script type, if there is only weak script in the passed string. */
     321             :     static sal_Int16    GetLeadingScriptType( const XclExpRoot& rRoot, const OUString& rString );
     322             : 
     323             : private:
     324             :     /** We don't want anybody to instantiate this class, since it is just a
     325             :         collection of static methods. To enforce this, the default constructor
     326             :         is made private */
     327             :     XclExpStringHelper();
     328             : };
     329             : 
     330             : // Header/footer conversion ===================================================
     331             : 
     332             : class EditEngine;
     333             : 
     334             : /** Converts edit engine text objects to an Excel header/footer string.
     335             :     @descr  Header/footer content is divided into three parts: Left, center and
     336             :     right portion. All formatting information will be encoded in the Excel string
     337             :     using special character seuences. A control sequence starts with the ampersand
     338             :     character.
     339             : 
     340             :     Supported control sequences:
     341             :     &L                      start of left portion
     342             :     &C                      start of center portion
     343             :     &R                      start of right portion
     344             :     &P                      current page number
     345             :     &N                      page count
     346             :     &D                      current date
     347             :     &T                      current time
     348             :     &A                      table name
     349             :     &F                      file name without path
     350             :     &Z                      file path without file name
     351             :     &Z&F                    file path and name
     352             :     &U                      underlining on/off
     353             :     &E                      double underlining on/off
     354             :     &S                      strikeout characters on/off
     355             :     &X                      superscript on/off
     356             :     &Y                      subscript on/off
     357             :     &"fontname,fontstyle"   use font with name 'fontname' and style 'fontstyle'
     358             :     &fontheight             set font height in points ('fontheight' is a decimal value)
     359             : 
     360             :     Known but unsupported control sequences:
     361             :     &G                      picture
     362             :  */
     363         129 : class XclExpHFConverter : protected XclExpRoot, private boost::noncopyable
     364             : {
     365             : public:
     366             :     explicit            XclExpHFConverter( const XclExpRoot& rRoot );
     367             : 
     368             :     /** Generates the header/footer string from the passed edit engine text objects. */
     369             :     void                GenerateString(
     370             :                             const EditTextObject* pLeftObj,
     371             :                             const EditTextObject* pCenterObj,
     372             :                             const EditTextObject* pRightObj );
     373             : 
     374             :     /** Returns the last generated header/footer string. */
     375          53 :     inline const OUString& GetHFString() const { return maHFString; }
     376             :     /** Returns the total height of the last generated header/footer in twips. */
     377          53 :     inline sal_Int32    GetTotalHeight() const { return mnTotalHeight; }
     378             : 
     379             : private:
     380             :     /** Converts the text object contents and stores it in the passed string. */
     381             :     void                AppendPortion(
     382             :                             const EditTextObject* pTextObj,
     383             :                             sal_Unicode cPortionCode );
     384             : 
     385             : private:
     386             :     EditEngine&         mrEE;           /// The header/footer edit engine.
     387             :     OUString            maHFString;     /// The last generated header/footer string.
     388             :     sal_Int32           mnTotalHeight;  /// Total height of the last header/footer (twips).
     389             : };
     390             : 
     391             : // URL conversion =============================================================
     392             : 
     393             : /** This class contains static methods to encode a file URL.
     394             :     @descr  Excel stores URLs in a format that contains special control characters,
     395             :     i.e. for directory separators or volume names. */
     396             : class XclExpUrlHelper : boost::noncopyable
     397             : {
     398             : public:
     399             :     /** Encodes and returns the URL passed in rAbsUrl to an Excel like URL.
     400             :         @param pTableName  Optional pointer to a table name to be encoded in this URL. */
     401             :     static OUString EncodeUrl( const XclExpRoot& rRoot, const OUString& rAbsUrl, const OUString* pTableName = 0 );
     402             :     /** Encodes and returns the passed DDE link to an Excel like DDE link. */
     403             :     static OUString EncodeDde( const OUString& rApplic, const OUString& rTopic );
     404             : 
     405             : private:
     406             :     /** We don't want anybody to instantiate this class, since it is just a
     407             :         collection of static methods. To enforce this, the default constructor
     408             :         is made private */
     409             :     XclExpUrlHelper();
     410             : };
     411             : 
     412             : class ScMatrix;
     413             : 
     414             : /** Contains cached values in a 2-dimensional array. */
     415             : class XclExpCachedMatrix
     416             : {
     417             :     void            GetDimensions( SCSIZE & nCols, SCSIZE & nRows ) const;
     418             : public:
     419             :     /** Constructs and fills a new matrix.
     420             :         @param rMatrix  The Calc value matrix. */
     421             :     explicit        XclExpCachedMatrix( const ScMatrix& rMatrix );
     422             :                    ~XclExpCachedMatrix();
     423             : 
     424             :     /** Returns the byte count of all contained data. */
     425             :     sal_Size        GetSize() const;
     426             :     /** Writes the complete matrix to stream. */
     427             :     void            Save( XclExpStream& rStrm ) const;
     428             : 
     429             : private:
     430             :     const ScMatrix& mrMatrix;
     431             : };
     432             : 
     433             : #endif
     434             : 
     435             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11