xref: /aoo41x/main/sc/source/filter/inc/xecontent.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_XECONTENT_HXX
25 #define SC_XECONTENT_HXX
26 
27 #include "rangelst.hxx"
28 #include "xlcontent.hxx"
29 #include "xladdress.hxx"
30 #include "xerecord.hxx"
31 #include "xeroot.hxx"
32 #include "xestring.hxx"
33 #include "xeformula.hxx"
34 
35 /* ============================================================================
36 Classes to export the big Excel document contents (related to several cells or
37 globals for the sheet or document).
38 - Shared string table
39 - Merged cells
40 - Hyperlinks
41 - Label ranges
42 - Conditional formatting
43 - Data validation
44 - Web Queries
45 ============================================================================ */
46 
47 // Shared string table ========================================================
48 
49 class XclExpSstImpl;
50 
51 /** Provides export of the SST (shared string table) record.
52     @descr  Contains all strings in the document and writes the SST. */
53 class XclExpSst : public XclExpRecordBase
54 {
55 public:
56     explicit            XclExpSst();
57     virtual             ~XclExpSst();
58 
59     /** Inserts a new string into the table.
60         @return  The index of the string in the SST, used in other records. */
61     sal_uInt32          Insert( XclExpStringRef xString );
62 
63     /** Writes the complete SST and EXTSST records. */
64     virtual void        Save( XclExpStream& rStrm );
65     virtual void        SaveXml( XclExpXmlStream& rStrm );
66 
67 private:
68     typedef ::std::auto_ptr< XclExpSstImpl > XclExpSstImplPtr;
69     XclExpSstImplPtr    mxImpl;
70 };
71 
72 // Merged cells ===============================================================
73 
74 /** Represents a MERGEDCELLS record containing all merged cell ranges in a sheet. */
75 class XclExpMergedcells : public XclExpRecordBase, protected XclExpRoot
76 {
77 public:
78     explicit            XclExpMergedcells( const XclExpRoot& rRoot );
79 
80     /** Appends a new range to the list of merged cell ranges. */
81     void                AppendRange( const ScRange& rRange, sal_uInt32 nBaseXFId );
82     /** Returns the XF identifier of the top-left cell in a merged range. */
83     sal_uInt32          GetBaseXFId( const ScAddress& rPos ) const;
84 
85     /** Writes the record, if it contains at least one merged cell range. */
86     virtual void        Save( XclExpStream& rStrm );
87     virtual void        SaveXml( XclExpXmlStream& rStrm );
88 
89 private:
90     ScRangeList         maMergedRanges;     /// All merged cell ranges of the sheet.
91     ScfUInt32Vec        maBaseXFIds;        /// The XF identifiers of the top-left cells.
92 };
93 
94 // Hyperlinks =================================================================
95 
96 class SvxURLField;
97 class INetURLObject;
98 
99 /** Provides export of hyperlink data. */
100 class XclExpHyperlink : public XclExpRecord
101 {
102 public:
103     /** Constructs the HLINK record from an URL text field. */
104     explicit            XclExpHyperlink( const XclExpRoot& rRoot,
105                             const SvxURLField& rUrlField, const ScAddress& rScPos );
106     virtual             ~XclExpHyperlink();
107 
108     /** Returns the cell representation text or 0, if not available. */
GetRepr() const109     inline const String* GetRepr() const { return mxRepr.get(); }
110 
111     virtual void        SaveXml( XclExpXmlStream& rStrm );
112 private:
113     /** Builds file name from the passed file URL. Tries to convert to relative file name.
114         @param rnLevel  (out-param) The parent directory level.
115         @param rbRel  (out-param) true = path is relative. */
116     String              BuildFileName(
117                             sal_uInt16& rnLevel, bool& rbRel,
118                             const String& rUrl, const XclExpRoot& rRoot ) const;
119 
120     /** Writes the body of the HLINK record. */
121     virtual void        WriteBody( XclExpStream& rStrm );
122 
123 private:
124     typedef ::std::auto_ptr< String >   StringPtr;
125     typedef ::std::auto_ptr< SvStream > SvStreamPtr;
126 
127     ScAddress           maScPos;            /// Position of the hyperlink.
128     StringPtr           mxRepr;             /// Cell representation text.
129     SvStreamPtr         mxVarData;          /// Buffer stream with variable data.
130     sal_uInt32          mnFlags;            /// Option flags.
131     XclExpStringRef     mxTextMark;         /// Location within mxRepr
132     ::rtl::OUString     msTarget;           /// Target URL
133 };
134 
135 typedef XclExpRecordList< XclExpHyperlink > XclExpHyperlinkList;
136 
137 // Label ranges ===============================================================
138 
139 /** Provides export of the row/column label range list of a sheet. */
140 class XclExpLabelranges : public XclExpRecordBase, protected XclExpRoot
141 {
142 public:
143     /** Fills the cell range lists with all ranges of the current sheet. */
144     explicit            XclExpLabelranges( const XclExpRoot& rRoot );
145 
146     /** Writes the LABELRANGES record if it contains at least one range. */
147     virtual void        Save( XclExpStream& rStrm );
148 
149 private:
150     /** Fills the specified range list with all label headers of the current sheet.
151         @param rRanges  The cell range list to fill.
152         @param xLabelRangesRef  The core range list with all ranges.
153         @param nScTab  The current Calc sheet index. */
154     void                FillRangeList( ScRangeList& rScRanges,
155                             ScRangePairListRef xLabelRangesRef, SCTAB nScTab );
156 
157 private:
158     ScRangeList         maRowRanges;    /// Cell range list for row labels.
159     ScRangeList         maColRanges;    /// Cell range list for column labels.
160 };
161 
162 // Conditional formatting =====================================================
163 
164 class ScCondFormatEntry;
165 class XclExpCFImpl;
166 
167 /** Represents a CF record that contains one condition of a conditional format. */
168 class XclExpCF : public XclExpRecord, protected XclExpRoot
169 {
170 public:
171     explicit            XclExpCF( const XclExpRoot& rRoot, const ScCondFormatEntry& rFormatEntry );
172     virtual             ~XclExpCF();
173 
174 private:
175     /** Writes the body of the CF record. */
176     virtual void        WriteBody( XclExpStream& rStrm );
177 
178 private:
179     typedef ::std::auto_ptr< XclExpCFImpl > XclExpCFImplPtr;
180     XclExpCFImplPtr     mxImpl;
181 };
182 
183 // ----------------------------------------------------------------------------
184 
185 class ScConditionalFormat;
186 
187 /** Represents a CONDFMT record that contains all conditions of a conditional format.
188     @descr  Contains the conditions which are stored in CF records. */
189 class XclExpCondfmt : public XclExpRecord, protected XclExpRoot
190 {
191 public:
192     explicit            XclExpCondfmt( const XclExpRoot& rRoot, const ScConditionalFormat& rCondFormat );
193     virtual             ~XclExpCondfmt();
194 
195     /** Returns true, if this conditional format contains at least one cell range and CF record. */
196     bool                IsValid() const;
197 
198     /** Writes the CONDFMT record with following CF records, if there is valid data. */
199     virtual void        Save( XclExpStream& rStrm );
200     virtual void        SaveXml( XclExpXmlStream& rStrm );
201 
202 private:
203     /** Writes the body of the CONDFMT record. */
204     virtual void        WriteBody( XclExpStream& rStrm );
205 
206 private:
207     typedef XclExpRecordList< XclExpCF > XclExpCFList;
208 
209     XclExpCFList        maCFList;       /// List of CF records.
210     XclRangeList        maXclRanges;    /// Cell ranges for this conditional format.
211     String              msSeqRef;       /// OOXML Sequence of References
212 };
213 
214 // ----------------------------------------------------------------------------
215 
216 /** Contains all conditional formats of a specific sheet. */
217 class XclExpCondFormatBuffer : public XclExpRecordBase, protected XclExpRoot
218 {
219 public:
220     /** Constructs CONDFMT and CF records containing the conditional formats of the current sheet. */
221     explicit            XclExpCondFormatBuffer( const XclExpRoot& rRoot );
222 
223     /** Writes all contained CONDFMT records with their CF records. */
224     virtual void        Save( XclExpStream& rStrm );
225     virtual void        SaveXml( XclExpXmlStream& rStrm );
226 
227 private:
228     typedef XclExpRecordList< XclExpCondfmt > XclExpCondfmtList;
229     XclExpCondfmtList   maCondfmtList;  /// List of CONDFMT records.
230 };
231 
232 // Data Validation ============================================================
233 
234 class ScValidationData;
235 
236 /** Provides export of the data of a DV record.
237     @descr  This record contains the settings for a data validation. In detail
238     this is a pointer to the core validation data and a cell range list with all
239     affected cells. The handle index is used to optimize list search algorithm. */
240 class XclExpDV : public XclExpRecord, protected XclExpRoot
241 {
242 public:
243     explicit            XclExpDV( const XclExpRoot& rRoot, sal_uLong nScHandle );
244     virtual             ~XclExpDV();
245 
246     /** Returns the core handle of the validation data. */
GetScHandle() const247     inline sal_uLong        GetScHandle() const { return mnScHandle; }
248 
249     /** Inserts a new cell range into the cell range list. */
250     void                InsertCellRange( const ScRange& rPos );
251     /** Converts the Calc range list to the Excel range list.
252         @return  false = Resulting range list empty - do not write this record. */
253     bool                Finalize();
254 
255     virtual void        SaveXml( XclExpXmlStream& rStrm );
256 
257 private:
258     /** Writes the body of the DV record. */
259     virtual void        WriteBody( XclExpStream& rStrm );
260 
261 private:
262     ScRangeList         maScRanges;     /// Calc range list with all affected cells.
263     XclRangeList        maXclRanges;    /// Excel range list with all affected cells.
264     XclExpString        maPromptTitle;  /// The prompt title.
265     XclExpString        maPromptText;   /// The prompt text.
266     XclExpString        maErrorTitle;   /// The error title.
267     XclExpString        maErrorText;    /// The error text.
268     XclExpStringRef     mxString1;      /// String for first condition formula.
269     XclTokenArrayRef    mxTokArr1;      /// Formula for first condition.
270     ::rtl::OUString     msFormula1;     /// OOXML Formula for first condition.
271     XclTokenArrayRef    mxTokArr2;      /// Formula for second condition.
272     ::rtl::OUString     msFormula2;     /// OOXML Formula for second condition.
273     sal_uInt32          mnFlags;        /// Miscellaneous flags.
274     sal_uLong               mnScHandle;     /// The core handle for quick list search.
275 };
276 
277 // ----------------------------------------------------------------------------
278 
279 /** This class contains the DV record list following the DVAL record. */
280 class XclExpDval : public XclExpRecord, protected XclExpRoot
281 {
282 public:
283     explicit            XclExpDval( const XclExpRoot& rRoot );
284     virtual             ~XclExpDval();
285 
286     /** Inserts the cell range into the range list of the DV record with the specified handle. */
287     void                InsertCellRange( const ScRange& rRange, sal_uLong nScHandle );
288 
289     /** Writes the DVAL record and the DV record list. */
290     virtual void        Save( XclExpStream& rStrm );
291     virtual void        SaveXml( XclExpXmlStream& rStrm );
292 
293 private:
294     /** Searches for or creates a XclExpDV record object with the specified handle. */
295     XclExpDV&           SearchOrCreateDv( sal_uLong nScHandle );
296 
297     /** Writes the body of the DVAL record. */
298     virtual void        WriteBody( XclExpStream& rStrm );
299 
300 private:
301     typedef XclExpRecordList< XclExpDV >    XclExpDVList;
302     typedef XclExpDVList::RecordRefType     XclExpDVRef;
303 
304     XclExpDVList        maDVList;       /// List of DV records
305     XclExpDVRef         mxLastFoundDV;  /// For search optimization.
306 };
307 
308 // Web Queries ================================================================
309 
310 /** Contains all records for a web query (linked tables in an HTML document).
311     @descr  mode 1 (entire document): mpQryTables==0, mbEntireDoc==true;
312     mode 2 (all tables): mpQryTables==0, mbEntireDoc==false;
313     mode 3 (custom range list): mpQryTables!=0, mbEntireDoc==false. */
314 class XclExpWebQuery : public XclExpRecordBase
315 {
316 public:
317     /** Constructs a web query record container with settings from Calc. */
318     explicit            XclExpWebQuery(
319                             const String& rRangeName,
320                             const String& rUrl,
321                             const String& rSource,
322                             sal_Int32 nRefrSecs );
323     virtual             ~XclExpWebQuery();
324 
325     /** Writes all needed records for this web query. */
326     virtual void        Save( XclExpStream& rStrm );
327 
328 private:
329     XclExpString        maDestRange;    /// Destination range.
330     XclExpString        maUrl;          /// Source document URL.
331     XclExpStringRef     mxQryTables;    /// List of source range names.
332     sal_Int16           mnRefresh;      /// Refresh time in minutes.
333     bool                mbEntireDoc;    /// true = entire document.
334 };
335 
336 // ----------------------------------------------------------------------------
337 
338 /** Contains all web query records for this document. */
339 class XclExpWebQueryBuffer : public XclExpRecordList< XclExpWebQuery >
340 {
341 public:
342     explicit            XclExpWebQueryBuffer( const XclExpRoot& rRoot );
343 };
344 
345 // ============================================================================
346 
347 #endif
348 
349