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