Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #ifndef OOX_XLS_WORKSHEETHELPER_HXX
30 : : #define OOX_XLS_WORKSHEETHELPER_HXX
31 : :
32 : : #include "oox/helper/containerhelper.hxx"
33 : : #include "oox/helper/progressbar.hxx"
34 : : #include "oox/ole/olehelper.hxx"
35 : : #include "addressconverter.hxx"
36 : : #include "formulabase.hxx"
37 : :
38 : : namespace com { namespace sun { namespace star {
39 : : namespace awt { struct Point; }
40 : : namespace awt { struct Rectangle; }
41 : : namespace awt { struct Size; }
42 : : namespace drawing { class XDrawPage; }
43 : : namespace sheet { class XSheetCellRanges; }
44 : : namespace sheet { class XSpreadsheet; }
45 : : namespace table { class XCell; }
46 : : namespace table { class XCell2; }
47 : : namespace table { class XCellRange; }
48 : : namespace table { class XTableColumns; }
49 : : namespace table { class XTableRows; }
50 : : } } }
51 : :
52 : : namespace oox {
53 : : namespace xls {
54 : :
55 : : class AutoFilterBuffer;
56 : : struct BinAddress;
57 : : struct BinRange;
58 : : class CommentsBuffer;
59 : : class CondFormatBuffer;
60 : : class Font;
61 : : class PageSettings;
62 : : class QueryTableBuffer;
63 : : class RichString;
64 : : class SheetDataBuffer;
65 : : class SheetViewSettings;
66 : : class VmlDrawing;
67 : : class WorksheetSettings;
68 : :
69 : : typedef ::std::map< rtl::OUString, void* > ExtLst;
70 : : // ============================================================================
71 : : // ============================================================================
72 : :
73 : : typedef ::std::map< BinAddress, sal_Int32 > SharedFormulaMap;
74 : :
75 : : /** An enumeration for all types of sheets in a workbook. */
76 : : enum WorksheetType
77 : : {
78 : : SHEETTYPE_WORKSHEET, /// Worksheet.
79 : : SHEETTYPE_CHARTSHEET, /// Chart sheet.
80 : : SHEETTYPE_MACROSHEET, /// Macro sheet.
81 : : SHEETTYPE_DIALOGSHEET, /// Dialog sheet (BIFF5+).
82 : : SHEETTYPE_MODULESHEET, /// VB module sheet (BIFF5 only).
83 : : SHEETTYPE_EMPTYSHEET /// Other (unsupported) sheet type.
84 : : };
85 : :
86 : : // ============================================================================
87 : :
88 : : /** Stores settings and formatting data about a range of sheet columns. */
89 : : struct ColumnModel
90 : : {
91 : : ValueRange maRange; /// 1-based (!) range of the described columns.
92 : : double mfWidth; /// Column width in number of characters.
93 : : sal_Int32 mnXfId; /// Column default formatting.
94 : : sal_Int32 mnLevel; /// Column outline level.
95 : : bool mbShowPhonetic; /// True = cells in column show phonetic settings.
96 : : bool mbHidden; /// True = column is hidden.
97 : : bool mbCollapsed; /// True = column outline is collapsed.
98 : :
99 : : explicit ColumnModel();
100 : :
101 : : /** Returns true, if this entry can be merged with the passed column range (column settings are equal). */
102 : : bool isMergeable( const ColumnModel& rModel ) const;
103 : : };
104 : :
105 : : // ----------------------------------------------------------------------------
106 : :
107 : : /** Stores settings and formatting data about a sheet row. */
108 : 1215 : struct RowModel
109 : : {
110 : : sal_Int32 mnRow; /// 1-based (!) index of the described row.
111 : : ValueRangeSet maColSpans; /// 0-based (!) column ranges of used cells.
112 : : double mfHeight; /// Row height in points.
113 : : sal_Int32 mnXfId; /// Row default formatting (see mbIsFormatted).
114 : : sal_Int32 mnLevel; /// Row outline level.
115 : : bool mbCustomHeight; /// True = row has custom height.
116 : : bool mbCustomFormat; /// True = cells in row have explicit formatting.
117 : : bool mbShowPhonetic; /// True = cells in row show phonetic settings.
118 : : bool mbHidden; /// True = row is hidden.
119 : : bool mbCollapsed; /// True = row outline is collapsed.
120 : : bool mbThickTop; /// True = row has extra space above text.
121 : : bool mbThickBottom; /// True = row has extra space below text.
122 : :
123 : : explicit RowModel();
124 : :
125 : : /** Inserts the passed column span into the row model. */
126 : : void insertColSpan( const ValueRange& rColSpan );
127 : : /** Returns true, if this entry can be merged with the passed row range (row settings are equal). */
128 : : bool isMergeable( const RowModel& rModel ) const;
129 : : };
130 : :
131 : : // ----------------------------------------------------------------------------
132 : :
133 : : /** Stores formatting data about a page break. */
134 : : struct PageBreakModel
135 : : {
136 : : sal_Int32 mnColRow; /// 0-based (!) index of column/row.
137 : : sal_Int32 mnMin; /// Start of limited break.
138 : : sal_Int32 mnMax; /// End of limited break.
139 : : bool mbManual; /// True = manual page break.
140 : :
141 : : explicit PageBreakModel();
142 : : };
143 : :
144 : : // ----------------------------------------------------------------------------
145 : :
146 : : /** Stores data about a hyperlink range. */
147 : 0 : struct HyperlinkModel : public ::oox::ole::StdHlinkInfo
148 : : {
149 : : ::com::sun::star::table::CellRangeAddress
150 : : maRange; /// The cell area containing the hyperlink.
151 : : ::rtl::OUString maTooltip; /// Additional tooltip text.
152 : :
153 : : explicit HyperlinkModel();
154 : : };
155 : :
156 : : // ----------------------------------------------------------------------------
157 : :
158 : : /** Stores data about ranges with data validation settings. */
159 [ # # # # ]: 0 : struct ValidationModel
[ # # # # ]
[ # # ][ # # ]
160 : : {
161 : : ApiCellRangeList maRanges;
162 : : ApiTokenSequence maTokens1;
163 : : ApiTokenSequence maTokens2;
164 : : ::rtl::OUString maInputTitle;
165 : : ::rtl::OUString maInputMessage;
166 : : ::rtl::OUString maErrorTitle;
167 : : ::rtl::OUString maErrorMessage;
168 : : sal_Int32 mnType;
169 : : sal_Int32 mnOperator;
170 : : sal_Int32 mnErrorStyle;
171 : : bool mbShowInputMsg;
172 : : bool mbShowErrorMsg;
173 : : bool mbNoDropDown;
174 : : bool mbAllowBlank;
175 : :
176 : : explicit ValidationModel();
177 : :
178 : : /** Sets the passed BIFF validation type. */
179 : : void setBiffType( sal_uInt8 nType );
180 : : /** Sets the passed BIFF operator. */
181 : : void setBiffOperator( sal_uInt8 nOperator );
182 : : /** Sets the passed BIFF error style. */
183 : : void setBiffErrorStyle( sal_uInt8 nErrorStyle );
184 : : };
185 : :
186 : : // ============================================================================
187 : : // ============================================================================
188 : :
189 : : class WorksheetGlobals;
190 : : typedef ::boost::shared_ptr< WorksheetGlobals > WorksheetGlobalsRef;
191 : :
192 [ # # ][ - + ]: 1938 : class WorksheetHelper : public WorkbookHelper
193 : : {
194 : : public:
195 : : /*implicit*/ WorksheetHelper( WorksheetGlobals& rSheetGlob );
196 : :
197 : : static WorksheetGlobalsRef constructGlobals(
198 : : const WorkbookHelper& rHelper,
199 : : const ISegmentProgressBarRef& rxProgressBar,
200 : : WorksheetType eSheetType,
201 : : sal_Int16 nSheet );
202 : :
203 : : // ------------------------------------------------------------------------
204 : :
205 : : /** Returns the type of this sheet. */
206 : : WorksheetType getSheetType() const;
207 : : /** Returns the index of the current sheet. */
208 : : sal_Int16 getSheetIndex() const;
209 : : /** Returns the XSpreadsheet interface of the current sheet. */
210 : : const ::com::sun::star::uno::Reference< ::com::sun::star::sheet::XSpreadsheet >&
211 : : getSheet() const;
212 : :
213 : : /** Returns the XCell interface for the passed cell address. */
214 : : ::com::sun::star::uno::Reference< ::com::sun::star::table::XCell >
215 : : getCell( const ::com::sun::star::table::CellAddress& rAddress ) const;
216 : : /** Returns the XCellRange interface for the passed cell range address. */
217 : : ::com::sun::star::uno::Reference< ::com::sun::star::table::XCellRange >
218 : : getCellRange( const ::com::sun::star::table::CellRangeAddress& rRange ) const;
219 : :
220 : : /** Returns the XDrawPage interface of the draw page of the current sheet. */
221 : : ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XDrawPage >
222 : : getDrawPage() const;
223 : :
224 : : /** Returns the absolute cell position in 1/100 mm. */
225 : : ::com::sun::star::awt::Point getCellPosition( sal_Int32 nCol, sal_Int32 nRow ) const;
226 : : /** Returns the cell size in 1/100 mm. */
227 : : ::com::sun::star::awt::Size getCellSize( sal_Int32 nCol, sal_Int32 nRow ) const;
228 : : /** Returns the size of the entire drawing page in 1/100 mm. */
229 : : ::com::sun::star::awt::Size getDrawPageSize() const;
230 : :
231 : : /** Returns the buffer for cell contents and cell formatting. */
232 : : SheetDataBuffer& getSheetData() const;
233 : : /** Returns the conditional formatting in this sheet. */
234 : : CondFormatBuffer& getCondFormats() const;
235 : : /** Returns the buffer for all cell comments in this sheet. */
236 : : CommentsBuffer& getComments() const;
237 : : /** Returns the auto filters for the sheet. */
238 : : AutoFilterBuffer& getAutoFilters() const;
239 : : /** Returns the buffer for all web query tables in this sheet. */
240 : : QueryTableBuffer& getQueryTables() const;
241 : : /** Returns the worksheet settings object. */
242 : : WorksheetSettings& getWorksheetSettings() const;
243 : : /** Returns the page/print settings for this sheet. */
244 : : PageSettings& getPageSettings() const;
245 : : /** Returns the view settings for this sheet. */
246 : : SheetViewSettings& getSheetViewSettings() const;
247 : : /** Returns the VML drawing page for this sheet (OOXML/BIFF12 only). */
248 : : VmlDrawing& getVmlDrawing() const;
249 : :
250 : : ExtLst& getExtLst() const;
251 : :
252 : : /** Sets a column or row page break described in the passed struct. */
253 : : void setPageBreak( const PageBreakModel& rModel, bool bRowBreak );
254 : : /** Inserts the hyperlink URL into the spreadsheet. */
255 : : void setHyperlink( const HyperlinkModel& rModel );
256 : : /** Inserts the data validation settings into the spreadsheet. */
257 : : void setValidation( const ValidationModel& rModel );
258 : : /** Sets the path to the DrawingML fragment of this sheet. */
259 : : void setDrawingPath( const ::rtl::OUString& rDrawingPath );
260 : : /** Sets the path to the legacy VML drawing fragment of this sheet. */
261 : : void setVmlDrawingPath( const ::rtl::OUString& rVmlDrawingPath );
262 : :
263 : : /** Extends the used area of this sheet by the passed cell position. */
264 : : void extendUsedArea( const ::com::sun::star::table::CellAddress& rAddress );
265 : : /** Extends the used area of this sheet by the passed cell range. */
266 : : void extendUsedArea( const ::com::sun::star::table::CellRangeAddress& rRange );
267 : : /** Extends the shape bounding box by the position and size of the passed rectangle (in 1/100 mm). */
268 : : void extendShapeBoundingBox( const ::com::sun::star::awt::Rectangle& rShapeRect );
269 : :
270 : : /** Sets base width for all columns (without padding pixels). This value
271 : : is only used, if width has not been set with setDefaultColumnWidth(). */
272 : : void setBaseColumnWidth( sal_Int32 nWidth );
273 : : /** Sets default width for all columns. This function overrides the base
274 : : width set with the setBaseColumnWidth() function. */
275 : : void setDefaultColumnWidth( double fWidth );
276 : : /** Sets column settings for a specific range of columns.
277 : : @descr Column default formatting is converted directly, other settings
278 : : are cached and converted in the finalizeWorksheetImport() call. */
279 : : void setColumnModel( const ColumnModel& rModel );
280 : :
281 : : /** Sets default height and hidden state for all unused rows in the sheet. */
282 : : void setDefaultRowSettings(
283 : : double fHeight, bool bCustomHeight,
284 : : bool bHidden, bool bThickTop, bool bThickBottom );
285 : : /** Sets row settings for a specific range of rows.
286 : : @descr Row default formatting is converted directly, other settings
287 : : are cached and converted in the finalizeWorksheetImport() call. */
288 : : void setRowModel( const RowModel& rModel );
289 : : /** Specifies that the passed row needs to set its height manually. */
290 : : void setManualRowHeight( sal_Int32 nRow );
291 : :
292 : : /** Inserts a value cell directly into the Calc sheet. */
293 : : void putValue(
294 : : const ::com::sun::star::table::CellAddress& rAddress,
295 : : double fValue ) const;
296 : :
297 : : /** Inserts a string cell directly into the Calc sheet. */
298 : : void putString(
299 : : const ::com::sun::star::table::CellAddress& rAddress,
300 : : const ::rtl::OUString& rText ) const;
301 : : /** Inserts a rich-string cell directly into the Calc sheet. */
302 : : void putRichString(
303 : : const ::com::sun::star::table::CellAddress& rAddress,
304 : : const RichString& rString,
305 : : const Font* pFirstPortionFont ) const;
306 : : /** Inserts a formula cell directly into the Calc sheet. */
307 : : void putFormulaTokens(
308 : : const ::com::sun::star::table::CellAddress& rAddress,
309 : : const ApiTokenSequence& rTokens ) const;
310 : :
311 : : /** Initial conversion before importing the worksheet. */
312 : : void initializeWorksheetImport();
313 : : /** Final conversion after importing the worksheet. */
314 : : void finalizeWorksheetImport();
315 : :
316 : : void setCellFormula( const ::com::sun::star::table::CellAddress& rTokenAddress, const rtl::OUString& );
317 : : void setCellFormula( const ::com::sun::star::table::CellAddress& rTokenAddress, sal_Int32 );
318 : : void setCellArrayFormula( const ::com::sun::star::table::CellRangeAddress& rRangeAddress, const ::com::sun::star::table::CellAddress& rTokenAddress, const rtl::OUString& );
319 : : void createSharedFormulaMapEntry( const ::com::sun::star::table::CellAddress& rAddress, sal_Int32 nSharedId, const rtl::OUString& rTokens );
320 : : void setCellFormulaValue( const ::com::sun::star::table::CellAddress& rAddress,
321 : : double fValue );
322 : : private:
323 : : WorksheetGlobals& mrSheetGlob;
324 : : };
325 : :
326 : : // ============================================================================
327 : : // ============================================================================
328 : :
329 : : } // namespace xls
330 : : } // namespace oox
331 : :
332 : : #endif
333 : :
334 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|