xref: /aoo41x/main/sc/source/filter/inc/xelink.hxx (revision 38d50f7b)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #ifndef SC_XELINK_HXX
25 #define SC_XELINK_HXX
26 
27 #include "markdata.hxx"
28 #include "xllink.hxx"
29 #include "xerecord.hxx"
30 #include "xehelper.hxx"
31 #include "xeformula.hxx"
32 #include "externalrefmgr.hxx"
33 
34 class ScRange;
35 struct ScSingleRefData;
36 struct ScComplexRefData;
37 
38 /* ============================================================================
39 Classes for export of different kinds of internal/external references.
40 - 3D cell and cell range links
41 - External cell and cell range links
42 - External defined names
43 - Macro calls
44 - Add-in functions
45 - DDE links
46 - OLE object links
47 ============================================================================ */
48 
49 // Excel sheet indexes ========================================================
50 
51 /** Stores the correct Excel sheet index for each Calc sheet.
52     @descr  The class knows all sheets which will not exported
53     (i.e. external link sheets, scenario sheets). */
54 class XclExpTabInfo : protected XclExpRoot
55 {
56 public:
57     /** Initializes the complete buffer from the current exported document. */
58     explicit            XclExpTabInfo( const XclExpRoot& rRoot );
59 
60     /** Returns true, if the specified Calc sheet will be exported. */
61     bool                IsExportTab( SCTAB nScTab ) const;
62     /** Returns true, if the specified Calc sheet is used to store external cell contents. */
63     bool                IsExternalTab( SCTAB nScTab ) const;
64     /** Returns true, if the specified Calc sheet is visible and will be exported. */
65     bool                IsVisibleTab( SCTAB nScTab ) const;
66     /** Returns true, if the specified Calc sheet is selected and will be exported. */
67     bool                IsSelectedTab( SCTAB nScTab ) const;
68     /** Returns true, if the specified Calc sheet is the displayed (active) sheet. */
69     bool                IsDisplayedTab( SCTAB nScTab ) const;
70     /** Returns true, if the specified Calc sheet is displayed in right-to-left mode. */
71     bool                IsMirroredTab( SCTAB nScTab ) const;
72     /** Returns the Calc name of the specified sheet. */
73     const String&       GetScTabName( SCTAB nScTab ) const;
74 
75     /** Returns the Excel sheet index for a given Calc sheet. */
76     sal_uInt16          GetXclTab( SCTAB nScTab ) const;
77 
78     /** Returns the Calc sheet index of the nSortedTab-th entry in the sorted sheet names list. */
79     SCTAB               GetRealScTab( SCTAB nSortedScTab ) const;
80 //UNUSED2009-05 /** Returns the index of the passed Calc sheet in the sorted sheet names list. */
81 //UNUSED2009-05 SCTAB               GetSortedScTab( SCTAB nScTab ) const;
82 
83     /** Returns the number of Calc sheets. */
GetScTabCount() const84     inline SCTAB        GetScTabCount() const { return mnScCnt; }
85 
86     /** Returns the number of Excel sheets to be exported. */
GetXclTabCount() const87     inline sal_uInt16   GetXclTabCount() const { return mnXclCnt; }
88     /** Returns the number of external linked sheets. */
GetXclExtTabCount() const89     inline sal_uInt16   GetXclExtTabCount() const { return mnXclExtCnt; }
90     /** Returns the number of exported selected sheets. */
GetXclSelectedCount() const91     inline sal_uInt16   GetXclSelectedCount() const { return mnXclSelCnt; }
92 
93     /** Returns the Excel index of the active, displayed sheet. */
GetDisplayedXclTab() const94     inline sal_uInt16   GetDisplayedXclTab() const { return mnDisplXclTab; }
95     /** Returns the Excel index of the first visible sheet. */
GetFirstVisXclTab() const96     inline sal_uInt16   GetFirstVisXclTab() const { return mnFirstVisXclTab; }
97 
98 private:
99     /** Returns true, if any of the passed flags is set for the specified Calc sheet. */
100     bool                GetFlag( SCTAB nScTab, sal_uInt8 nFlags ) const;
101     /** Sets or clears (depending on bSet) all passed flags for the specified Calc sheet. */
102     void                SetFlag( SCTAB nScTab, sal_uInt8 nFlags, bool bSet = true );
103 
104     /** Searches for sheets not to be exported. */
105     void                CalcXclIndexes();
106     /** Sorts the names of all tables and stores the indexes of the sorted indexes. */
107     void                CalcSortedIndexes();
108 
109 private:
110     /** Data structure with infoemation about one Calc sheet. */
111     struct XclExpTabInfoEntry
112     {
113         String              maScName;
114         sal_uInt16          mnXclTab;
115         sal_uInt8           mnFlags;
XclExpTabInfoEntryXclExpTabInfo::XclExpTabInfoEntry116         inline explicit     XclExpTabInfoEntry() : mnXclTab( 0 ), mnFlags( 0 ) {}
117     };
118 
119     typedef ::std::vector< XclExpTabInfoEntry > XclExpTabInfoVec;
120     typedef ::std::vector< SCTAB >              ScTabVec;
121 
122     XclExpTabInfoVec    maTabInfoVec;       /// Array of Calc sheet index information.
123 
124     SCTAB               mnScCnt;            /// Count of Calc sheets.
125     sal_uInt16          mnXclCnt;           /// Count of Excel sheets to be exported.
126     sal_uInt16          mnXclExtCnt;        /// Count of external link sheets.
127     sal_uInt16          mnXclSelCnt;        /// Count of selected and exported sheets.
128     sal_uInt16          mnDisplXclTab;      /// Displayed (active) sheet.
129     sal_uInt16          mnFirstVisXclTab;   /// First visible sheet.
130 
131     ScTabVec            maFromSortedVec;    /// Sorted Calc sheet index -> real Calc sheet index.
132     ScTabVec            maToSortedVec;      /// Real Calc sheet index -> sorted Calc sheet index.
133 };
134 
135 // Export link manager ========================================================
136 
137 class XclExpLinkManagerImpl;
138 
139 /** Stores all data for internal/external references (the link table). */
140 class XclExpLinkManager : public XclExpRecordBase, protected XclExpRoot
141 {
142 public:
143     explicit            XclExpLinkManager( const XclExpRoot& rRoot );
144     virtual             ~XclExpLinkManager();
145 
146     /** Searches for an EXTERNSHEET index for the given Calc sheet.
147         @descr  See above for the meaning of EXTERNSHEET indexes.
148         @param rnExtSheet  (out-param)  Returns the EXTERNSHEET index.
149         @param rnXclTab  (out-param)  Returns the Excel sheet index.
150         @param nScTab  The Calc sheet index to process.
151         param pRefLogEntry  If not 0, data about the external link is stored here. */
152     void                FindExtSheet( sal_uInt16& rnExtSheet,
153                             sal_uInt16& rnXclTab, SCTAB nScTab,
154                             XclExpRefLogEntry* pRefLogEntry = 0 );
155     /** Searches for an EXTERNSHEET index for the given Calc sheet range.
156         @descr  See above for the meaning of EXTERNSHEET indexes.
157         @param rnExtSheet  (out-param)  Returns the EXTERNSHEET index.
158         @param rnFirstXclTab  (out-param)  Returns the Excel sheet index of the first sheet.
159         @param rnXclTab  (out-param)  Returns the Excel sheet index of the last sheet.
160         @param nFirstScTab  The first Calc sheet index to process.
161         @param nLastScTab  The last Calc sheet index to process.
162         param pRefLogEntry  If not 0, data about the external link is stored here. */
163     void                FindExtSheet( sal_uInt16& rnExtSheet,
164                             sal_uInt16& rnFirstXclTab, sal_uInt16& rnLastXclTab,
165                             SCTAB nFirstScTab, SCTAB nLastScTab,
166                             XclExpRefLogEntry* pRefLogEntry = 0 );
167     /** Searches for a special EXTERNSHEET index for the own document. */
168     sal_uInt16          FindExtSheet( sal_Unicode cCode );
169 
170     void                FindExtSheet( sal_uInt16 nFileId, const String& rTabName, sal_uInt16 nXclTabSpan,
171                                       sal_uInt16& rnExtSheet, sal_uInt16& rnFirstSBTab, sal_uInt16& rnLastSBTab,
172                                       XclExpRefLogEntry* pRefLogEntry = NULL );
173 
174     /** Stores the cell with the given address in a CRN record list. */
175     void                StoreCell( const ScSingleRefData& rRef );
176     /** Stores all cells in the given range in a CRN record list. */
177     void                StoreCellRange( const ScComplexRefData& rRef );
178 
179     void                StoreCell( sal_uInt16 nFileId, const String& rTabName, const ScSingleRefData& rRef );
180 
181     void                StoreCellRange( sal_uInt16 nFileId, const String& rTabName, const ScComplexRefData& rRef );
182 
183     /** Finds or inserts an EXTERNNAME record for an add-in function name.
184         @param rnExtSheet  (out-param) Returns the index of the EXTSHEET structure for the add-in function name.
185         @param rnExtName  (out-param) Returns the 1-based EXTERNNAME record index.
186         @return  true = add-in function inserted; false = error (i.e. not supported in current BIFF). */
187     bool                InsertAddIn(
188                             sal_uInt16& rnExtSheet, sal_uInt16& rnExtName,
189                             const String& rName );
190     /** InsertEuroTool */
191     bool                InsertEuroTool(
192                             sal_uInt16& rnExtSheet, sal_uInt16& rnExtName,
193                             const String& rName );
194     /** Finds or inserts an EXTERNNAME record for DDE links.
195         @param rnExtSheet  (out-param) Returns the index of the EXTSHEET structure for the DDE link.
196         @param rnExtName  (out-param) Returns the 1-based EXTERNNAME record index.
197         @return  true = DDE link inserted; false = error (i.e. not supported in current BIFF). */
198     bool                InsertDde(
199                             sal_uInt16& rnExtSheet, sal_uInt16& rnExtName,
200                             const String& rApplic, const String& rTopic, const String& rItem );
201 
202     bool                InsertExtName(
203                             sal_uInt16& rnExtSheet, sal_uInt16& rnExtName, const String& rUrl,
204                             const String& rName, const ScExternalRefCache::TokenArrayRef pArray );
205 
206     /** Writes the entire Link table. */
207     virtual void        Save( XclExpStream& rStrm );
208 
209 private:
210     typedef ScfRef< XclExpLinkManagerImpl > XclExpLinkMgrImplPtr;
211     XclExpLinkMgrImplPtr mxImpl;
212 };
213 
214 // ============================================================================
215 
216 #endif
217 
218