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

Generated by: LCOV version 1.10