LCOV - code coverage report
Current view: top level - libreoffice/sc/source/filter/inc - externallinkbuffer.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 3 19 15.8 %
Date: 2012-12-27 Functions: 5 22 22.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 OOX_XLS_EXTERNALLINKBUFFER_HXX
      21             : #define OOX_XLS_EXTERNALLINKBUFFER_HXX
      22             : 
      23             : #include <com/sun/star/sheet/ExternalLinkInfo.hpp>
      24             : #include "oox/helper/containerhelper.hxx"
      25             : #include "defnamesbuffer.hxx"
      26             : 
      27             : namespace com { namespace sun { namespace star {
      28             :     namespace sheet { struct DDEItemInfo; }
      29             :     namespace sheet { class XDDELink; }
      30             :     namespace sheet { class XExternalDocLink; }
      31             :     namespace sheet { class XExternalSheetCache; }
      32             : } } }
      33             : 
      34             : namespace oox { namespace core {
      35             :     class Relations;
      36             : } }
      37             : 
      38             : namespace oox {
      39             : namespace xls {
      40             : 
      41             : // ============================================================================
      42             : 
      43             : struct ExternalNameModel
      44             : {
      45             :     bool                mbBuiltIn;          /// Name is a built-in name.
      46             :     bool                mbNotify;           /// Notify application on data change.
      47             :     bool                mbPreferPic;        /// Picture link.
      48             :     bool                mbStdDocName;       /// Name is the StdDocumentName for DDE.
      49             :     bool                mbOleObj;           /// Name is an OLE object.
      50             :     bool                mbIconified;        /// Iconified object link.
      51             : 
      52             :     explicit            ExternalNameModel();
      53             : };
      54             : 
      55             : // ============================================================================
      56             : 
      57             : class ExternalLink;
      58             : 
      59           0 : class ExternalName : public DefinedNameBase
      60             : {
      61             : public:
      62             :     explicit            ExternalName( const ExternalLink& rParentLink );
      63             : 
      64             :     /** Appends the passed value to the result set. */
      65             :     template< typename Type >
      66           0 :     inline void         appendResultValue( const Type& rValue )
      67           0 :                             { if( maCurrIt != maResults.end() ) (*maCurrIt++) <<= rValue; }
      68             : 
      69             :     /** Imports the definedName element. */
      70             :     void                importDefinedName( const AttributeList& rAttribs );
      71             :     /** Imports the ddeItem element describing an item of a DDE link. */
      72             :     void                importDdeItem( const AttributeList& rAttribs );
      73             :     /** Imports the values element containing the size of the DDE result matrix. */
      74             :     void                importValues( const AttributeList& rAttribs );
      75             :     /** Imports the oleItem element describing an object of an OLE link. */
      76             :     void                importOleItem( const AttributeList& rAttribs );
      77             : 
      78             :     /** Imports the EXTERNALNAME record containing the name (only). */
      79             :     void                importExternalName( SequenceInputStream& rStrm );
      80             :     /** Imports the EXTERNALNAMEFLAGS record containing the settings of an external name. */
      81             :     void                importExternalNameFlags( SequenceInputStream& rStrm );
      82             :     /** Imports the DDEITEMVALUES record containing the size of the DDE result matrix. */
      83             :     void                importDdeItemValues( SequenceInputStream& rStrm );
      84             :     /** Imports the DDEITEM_BOOL record containing a boolean value in a link result. */
      85             :     void                importDdeItemBool( SequenceInputStream& rStrm );
      86             :     /** Imports the DDEITEM_DOUBLE record containing a double value in a link result. */
      87             :     void                importDdeItemDouble( SequenceInputStream& rStrm );
      88             :     /** Imports the DDEITEM_ERROR record containing an error code in a link result. */
      89             :     void                importDdeItemError( SequenceInputStream& rStrm );
      90             :     /** Imports the DDEITEM_STRING record containing a string in a link result. */
      91             :     void                importDdeItemString( SequenceInputStream& rStrm );
      92             : 
      93             :     /** Returns true, if the name refers to an OLE object. */
      94             :     inline bool         isOleObject() const { return maExtNameModel.mbOleObj; }
      95             : 
      96             : #if 0
      97             :     /** Returns the sheet cache index if this is a sheet-local external name. */
      98             :     sal_Int32           getSheetCacheIndex() const;
      99             : #endif
     100             : 
     101             :     /** Returns the DDE item info needed by the XML formula parser. */
     102             :     bool                getDdeItemInfo(
     103             :                             ::com::sun::star::sheet::DDEItemInfo& orItemInfo ) const;
     104             : 
     105             :     /** Returns the complete DDE link data of this DDE item. */
     106             :     bool                getDdeLinkData(
     107             :                             ::rtl::OUString& orDdeServer,
     108             :                             ::rtl::OUString& orDdeTopic,
     109             :                             ::rtl::OUString& orDdeItem );
     110             : 
     111             : private:
     112             :     /** Sets the size of the result matrix. */
     113             :     void                setResultSize( sal_Int32 nColumns, sal_Int32 nRows );
     114             : 
     115             : private:
     116             :     typedef Matrix< ::com::sun::star::uno::Any > ResultMatrix;
     117             : 
     118             :     const ExternalLink& mrParentLink;       /// External link this name belongs to.
     119             :     ExternalNameModel   maExtNameModel;     /// Additional name data.
     120             :     ResultMatrix        maResults;          /// DDE/OLE link results.
     121             :     ResultMatrix::iterator maCurrIt;        /// Current position in result matrix.
     122             :     ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XDDELink >
     123             :                         mxDdeLink;          /// Interface of a DDE link.
     124             :     bool                mbDdeLinkCreated;   /// True = already tried to create the DDE link.
     125             : };
     126             : 
     127             : typedef ::boost::shared_ptr< ExternalName > ExternalNameRef;
     128             : 
     129             : // ============================================================================
     130             : 
     131             : /** Contains indexes for a range of sheets in the spreadsheet document. */
     132             : class LinkSheetRange
     133             : {
     134             : public:
     135           0 :     inline explicit     LinkSheetRange() { setDeleted(); }
     136             :     inline explicit     LinkSheetRange( sal_Int32 nFirst, sal_Int32 nLast ) { setRange( nFirst, nLast ); }
     137             :     inline explicit     LinkSheetRange( sal_Int32 nDocLink, sal_Int32 nFirst, sal_Int32 nLast ) { setExternalRange( nDocLink, nFirst, nLast ); }
     138             : 
     139             :     /** Sets this struct to deleted state. */
     140             :     void                setDeleted();
     141             :     /** Sets this struct to "use current sheet" state. */
     142             :     void                setSameSheet();
     143             :     /** Sets the passed absolute sheet range to the members of this struct. */
     144             :     void                setRange( sal_Int32 nFirst, sal_Int32 nLast );
     145             :     /** Sets the passed external sheet cache range to the members of this struct. */
     146             :     void                setExternalRange( sal_Int32 nDocLink, sal_Int32 nFirst, sal_Int32 nLast );
     147             : 
     148             :     /** Returns true, if the sheet indexes are valid and different. */
     149           0 :     inline bool         isDeleted() const { return mnFirst < 0; }
     150             :     /** Returns true, if the sheet range points to an external document. */
     151           0 :     inline bool         isExternal() const { return !isDeleted() && (meType == LINKSHEETRANGE_EXTERNAL); }
     152             :     /** Returns true, if the sheet indexes are valid and different. */
     153           0 :     inline bool         isSameSheet() const { return meType == LINKSHEETRANGE_SAMESHEET; }
     154             :     /** Returns true, if the sheet indexes are valid and different. */
     155           0 :     inline bool         is3dRange() const { return (0 <= mnFirst) && (mnFirst < mnLast); }
     156             : 
     157           0 :     inline sal_Int32    getDocLinkIndex() const { return mnDocLink; }
     158           0 :     inline sal_Int32    getFirstSheet() const { return mnFirst; }
     159           0 :     inline sal_Int32    getLastSheet() const { return mnLast; }
     160             : 
     161             : private:
     162             :     enum LinkSheetRangeType
     163             :     {
     164             :         LINKSHEETRANGE_INTERNAL,    /// Sheet range in the own document.
     165             :         LINKSHEETRANGE_EXTERNAL,    /// Sheet range in an external document.
     166             :         LINKSHEETRANGE_SAMESHEET    /// Current sheet depending on context.
     167             :     };
     168             : 
     169             :     LinkSheetRangeType  meType;         /// Link sheet range type.
     170             :     sal_Int32           mnDocLink;      /// Document link token index for external links.
     171             :     sal_Int32           mnFirst;        /// Index of the first sheet or index of first external sheet cache.
     172             :     sal_Int32           mnLast;         /// Index of the last sheet or index of last external sheet cache.
     173             : };
     174             : 
     175             : // ============================================================================
     176             : 
     177             : enum ExternalLinkType
     178             : {
     179             :     LINKTYPE_SELF,          /// Link refers to the current workbook.
     180             :     LINKTYPE_SAME,          /// Link refers to the current sheet.
     181             :     LINKTYPE_INTERNAL,      /// Link refers to a sheet in the own workbook.
     182             :     LINKTYPE_EXTERNAL,      /// Link refers to an external spreadsheet document.
     183             :     LINKTYPE_ANALYSIS,      /// Link refers to the Analysis add-in.
     184             :     LINKTYPE_LIBRARY,       /// Link refers to an external add-in.
     185             :     LINKTYPE_DDE,           /// DDE link.
     186             :     LINKTYPE_OLE,           /// OLE link.
     187             :     LINKTYPE_MAYBE_DDE_OLE, /// Could be DDE or OLE link (BIFF only).
     188             :     LINKTYPE_UNKNOWN        /// Unknown or unsupported link type.
     189             : };
     190             : 
     191             : // ----------------------------------------------------------------------------
     192             : 
     193          22 : class ExternalLink : public WorkbookHelper
     194             : {
     195             : public:
     196             :     explicit            ExternalLink( const WorkbookHelper& rHelper );
     197             : 
     198             :     /** Imports the externalReference element containing the relation identifier. */
     199             :     void                importExternalReference( const AttributeList& rAttribs );
     200             :     /** Imports the externalBook element describing an externally linked document. */
     201             :     void                importExternalBook( const ::oox::core::Relations& rRelations, const AttributeList& rAttribs );
     202             :     /** Imports the sheetName element containing the sheet name in an externally linked document. */
     203             :     void                importSheetName( const AttributeList& rAttribs );
     204             :     /** Imports the definedName element describing an external name. */
     205             :     void                importDefinedName( const AttributeList& rAttribs );
     206             :     /** Imports the ddeLink element describing a DDE link. */
     207             :     void                importDdeLink( const AttributeList& rAttribs );
     208             :     /** Imports the ddeItem element describing an item of a DDE link. */
     209             :     ExternalNameRef     importDdeItem( const AttributeList& rAttribs );
     210             :     /** Imports the oleLink element describing an OLE link. */
     211             :     void                importOleLink( const ::oox::core::Relations& rRelations, const AttributeList& rAttribs );
     212             :     /** Imports the oleItem element describing an object of an OLE link. */
     213             :     ExternalNameRef     importOleItem( const AttributeList& rAttribs );
     214             : 
     215             :     /** Imports the EXTERNALBOOK record describing an externally linked document, DDE link, or OLE link. */
     216             :     void                importExternalBook( const ::oox::core::Relations& rRelations, SequenceInputStream& rStrm );
     217             :     /** Imports the EXTSHEETNAMES record containing the sheet names in an externally linked document. */
     218             :     void                importExtSheetNames( SequenceInputStream& rStrm );
     219             :     /** Imports the EXTERNALNAME record describing an external name. */
     220             :     ExternalNameRef     importExternalName( SequenceInputStream& rStrm );
     221             :     /** Imports the EXTERNALREF record from the passed stream. */
     222             :     void                importExternalRef( SequenceInputStream& rStrm );
     223             :     /** Imports the EXTERNALSELF record from the passed stream. */
     224             :     void                importExternalSelf( SequenceInputStream& rStrm );
     225             :     /** Imports the EXTERNALSAME record from the passed stream. */
     226             :     void                importExternalSame( SequenceInputStream& rStrm );
     227             :     /** Imports the EXTERNALADDIN record from the passed stream. */
     228             :     void                importExternalAddin( SequenceInputStream& rStrm );
     229             : 
     230             :     /** Sets the link type to 'self reference'. */
     231          11 :     inline void         setSelfLinkType() { meLinkType = LINKTYPE_SELF; }
     232             : 
     233             :     /** Returns the type of this external link. */
     234           0 :     inline ExternalLinkType getLinkType() const { return meLinkType; }
     235             :     /** Returns true, if the link refers to the current workbook. */
     236           0 :     inline bool         isInternalLink() const { return (meLinkType == LINKTYPE_SELF) || (meLinkType == LINKTYPE_INTERNAL); }
     237             : 
     238             :     /** Returns the relation identifier for the external link fragment. */
     239           0 :     inline const ::rtl::OUString& getRelId() const { return maRelId; }
     240             :     /** Returns the class name of this external link. */
     241           0 :     inline const ::rtl::OUString& getClassName() const { return maClassName; }
     242             :     /** Returns the target URL of this external link. */
     243           0 :     inline const ::rtl::OUString& getTargetUrl() const { return maTargetUrl; }
     244             :     /** Returns the link info needed by the XML formula parser. */
     245             :     ::com::sun::star::sheet::ExternalLinkInfo getLinkInfo() const;
     246             : 
     247             :     /** Returns the type of the external library if this is a library link. */
     248             :     FunctionLibraryType getFuncLibraryType() const;
     249             : 
     250             :     /** Returns the token index of the external document. */
     251             :     sal_Int32           getDocumentLinkIndex() const;
     252             :     /** Returns the external sheet cache index or for the passed sheet. */
     253             :     sal_Int32           getSheetCacheIndex( sal_Int32 nTabId = 0 ) const;
     254             :     /** Returns the sheet cache of the external sheet with the passed index. */
     255             :     ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XExternalSheetCache >
     256             :                         getSheetCache( sal_Int32 nTabId ) const;
     257             : 
     258             :     /** Returns the internal sheet range or range of external sheet caches for the passed sheet range (BIFF only). */
     259             :     void                getSheetRange( LinkSheetRange& orSheetRange, sal_Int32 nTabId1, sal_Int32 nTabId2 ) const;
     260             : 
     261             :     /** Returns the external name with the passed zero-based index. */
     262             :     ExternalNameRef     getNameByIndex( sal_Int32 nIndex ) const;
     263             : 
     264             : private:
     265             :     void                setExternalTargetUrl( const ::rtl::OUString& rTargetUrl, const ::rtl::OUString& rTargetType );
     266             :     void                setDdeOleTargetUrl( const ::rtl::OUString& rClassName, const ::rtl::OUString& rTargetUrl, ExternalLinkType eLinkType );
     267             :     void                parseExternalReference( const ::oox::core::Relations& rRelations, const ::rtl::OUString& rRelId );
     268             : 
     269             :     /** Creates an external locument link and the sheet cache for the passed sheet name. */
     270             :     void                insertExternalSheet( const ::rtl::OUString& rSheetName );
     271             : 
     272             :     ExternalNameRef     createExternalName();
     273             : 
     274             : private:
     275             :     typedef ::std::vector< sal_Int16 >  Int16Vector;
     276             :     typedef ::std::vector< sal_Int32 >  Int32Vector;
     277             :     typedef RefVector< ExternalName >   ExternalNameVector;
     278             : 
     279             :     ExternalLinkType    meLinkType;         /// Type of this link object.
     280             :     FunctionLibraryType meFuncLibType;      /// Type of the function library, if link type is LINKTYPE_LIBRARY.
     281             :     ::rtl::OUString     maRelId;            /// Relation identifier for the external link fragment.
     282             :     ::rtl::OUString     maClassName;        /// DDE service, OLE class name.
     283             :     ::rtl::OUString     maTargetUrl;        /// Target link, DDE topic, OLE target.
     284             :     ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XExternalDocLink >
     285             :                         mxDocLink;          /// Interface for an external document.
     286             :     Int16Vector         maCalcSheets;       /// Internal sheet indexes.
     287             :     Int32Vector         maSheetCaches;      /// External sheet cache indexes.
     288             :     ExternalNameVector  maExtNames;         /// Defined names in external document.
     289             : };
     290             : 
     291             : typedef ::boost::shared_ptr< ExternalLink > ExternalLinkRef;
     292             : 
     293             : // ============================================================================
     294             : 
     295             : /** Represents a REF entry in the BIFF12 EXTERNALSHEETS or in the BIFF8
     296             :     EXTERNSHEET record.
     297             : 
     298             :     This struct is used to map ref identifiers to external books (BIFF12:
     299             :     EXTERNALREF records, BIFF8: EXTERNALBOOK records), and provides sheet
     300             :     indexes into the sheet list of the external document.
     301             :  */
     302             : struct RefSheetsModel
     303             : {
     304             :     sal_Int32           mnExtRefId;         /// Zero-based index into list of external documents.
     305             :     sal_Int32           mnTabId1;           /// Zero-based index to first sheet in external document.
     306             :     sal_Int32           mnTabId2;           /// Zero-based index to last sheet in external document.
     307             : 
     308             :     explicit            RefSheetsModel();
     309             : 
     310             :     void                readBiff12Data( SequenceInputStream& rStrm );
     311             : };
     312             : 
     313             : // ----------------------------------------------------------------------------
     314             : 
     315          22 : class ExternalLinkBuffer : public WorkbookHelper
     316             : {
     317             : public:
     318             :     explicit            ExternalLinkBuffer( const WorkbookHelper& rHelper );
     319             : 
     320             :     /** Imports the externalReference element containing . */
     321             :     ExternalLinkRef     importExternalReference( const AttributeList& rAttribs );
     322             : 
     323             :     /** Imports the EXTERNALREF record from the passed stream. */
     324             :     ExternalLinkRef     importExternalRef( SequenceInputStream& rStrm );
     325             :     /** Imports the EXTERNALSELF record from the passed stream. */
     326             :     void                importExternalSelf( SequenceInputStream& rStrm );
     327             :     /** Imports the EXTERNALSAME record from the passed stream. */
     328             :     void                importExternalSame( SequenceInputStream& rStrm );
     329             :     /** Imports the EXTERNALADDIN record from the passed stream. */
     330             :     void                importExternalAddin( SequenceInputStream& rStrm );
     331             :     /** Imports the EXTERNALSHEETS record from the passed stream. */
     332             :     void                importExternalSheets( SequenceInputStream& rStrm );
     333             : 
     334             :     /** Returns the sequence of link infos needed by the XML formula parser. */
     335             :     ::com::sun::star::uno::Sequence< ::com::sun::star::sheet::ExternalLinkInfo >
     336             :                         getLinkInfos() const;
     337             : 
     338             :     /** Returns the external link for the passed reference identifier. */
     339             :     ExternalLinkRef     getExternalLink( sal_Int32 nRefId, bool bUseRefSheets = true ) const;
     340             : 
     341             :     /** Returns the sheet range for the specified reference (BIFF2-BIFF5 only). */
     342             :     LinkSheetRange      getSheetRange( sal_Int32 nRefId, sal_Int16 nTabId1, sal_Int16 nTabId2 ) const;
     343             :     /** Returns the sheet range for the specified reference (BIFF8 only). */
     344             :     LinkSheetRange      getSheetRange( sal_Int32 nRefId ) const;
     345             : 
     346             : private:
     347             :     /** Creates a new external link and inserts it into the list of links. */
     348             :     ExternalLinkRef     createExternalLink();
     349             : 
     350             :     /** Returns the specified sheet indexes for a reference identifier. */
     351             :     const RefSheetsModel* getRefSheets( sal_Int32 nRefId ) const;
     352             : 
     353             : private:
     354             :     typedef RefVector< ExternalLink >       ExternalLinkVec;
     355             :     typedef ::std::vector< RefSheetsModel > RefSheetsModelVec;
     356             : 
     357             :     ExternalLinkRef     mxSelfRef;          /// Implicit self reference at index 0.
     358             :     ExternalLinkVec     maLinks;            /// List of link structures for all kinds of links.
     359             :     ExternalLinkVec     maExtLinks;         /// Real external links needed for formula parser.
     360             :     RefSheetsModelVec   maRefSheets;        /// Sheet indexes for reference ids.
     361             :     bool                mbUseRefSheets;     /// True = use maRefSheets list (BIFF12 only).
     362             : };
     363             : 
     364             : // ============================================================================
     365             : 
     366             : } // namespace xls
     367             : } // namespace oox
     368             : 
     369             : #endif
     370             : 
     371             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10