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