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