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 : #include "worksheethelper.hxx"
21 :
22 : #include <algorithm>
23 : #include <list>
24 : #include <utility>
25 : #include <com/sun/star/awt/Point.hpp>
26 : #include <com/sun/star/awt/Size.hpp>
27 : #include <com/sun/star/drawing/XDrawPageSupplier.hpp>
28 : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
29 : #include <com/sun/star/sheet/TableValidationVisibility.hpp>
30 : #include <com/sun/star/sheet/ValidationType.hpp>
31 : #include <com/sun/star/sheet/ValidationAlertStyle.hpp>
32 : #include <com/sun/star/sheet/XCellAddressable.hpp>
33 : #include <com/sun/star/sheet/XCellRangeAddressable.hpp>
34 : #include <com/sun/star/sheet/XFormulaTokens.hpp>
35 : #include <com/sun/star/sheet/XLabelRanges.hpp>
36 : #include <com/sun/star/sheet/XMultiFormulaTokens.hpp>
37 : #include <com/sun/star/sheet/XSheetCellRangeContainer.hpp>
38 : #include <com/sun/star/sheet/XSheetCondition2.hpp>
39 : #include <com/sun/star/sheet/XSheetOutline.hpp>
40 : #include <com/sun/star/sheet/XSpreadsheet.hpp>
41 : #include <com/sun/star/table/XColumnRowRange.hpp>
42 : #include <com/sun/star/text/WritingMode2.hpp>
43 : #include <com/sun/star/text/XText.hpp>
44 : #include <rtl/ustrbuf.hxx>
45 : #include "oox/core/filterbase.hxx"
46 : #include "oox/helper/propertyset.hxx"
47 : #include "addressconverter.hxx"
48 : #include "autofilterbuffer.hxx"
49 : #include "commentsbuffer.hxx"
50 : #include "condformatbuffer.hxx"
51 : #include "convuno.hxx"
52 : #include "document.hxx"
53 : #include "drawingfragment.hxx"
54 : #include "drawingmanager.hxx"
55 : #include "formulaparser.hxx"
56 : #include "pagesettings.hxx"
57 : #include "querytablebuffer.hxx"
58 : #include "sharedstringsbuffer.hxx"
59 : #include "sheetdatabuffer.hxx"
60 : #include "stylesbuffer.hxx"
61 : #include "tokenuno.hxx"
62 : #include "unitconverter.hxx"
63 : #include "viewsettings.hxx"
64 : #include "workbooksettings.hxx"
65 : #include "worksheetbuffer.hxx"
66 : #include "worksheetsettings.hxx"
67 : #include "formulabuffer.hxx"
68 : #include "scitems.hxx"
69 : #include "editutil.hxx"
70 : #include "tokenarray.hxx"
71 : #include "tablebuffer.hxx"
72 : #include "documentimport.hxx"
73 : #include "stlsheet.hxx"
74 : #include "stlpool.hxx"
75 : #include "cellvalue.hxx"
76 :
77 : #include <svl/stritem.hxx>
78 : #include <editeng/editobj.hxx>
79 : #include <editeng/flditem.hxx>
80 :
81 : namespace oox {
82 : namespace xls {
83 :
84 : using namespace ::com::sun::star;
85 : using namespace ::com::sun::star::beans;
86 : using namespace ::com::sun::star::drawing;
87 : using namespace ::com::sun::star::lang;
88 : using namespace ::com::sun::star::sheet;
89 : using namespace ::com::sun::star::table;
90 : using namespace ::com::sun::star::text;
91 : using namespace ::com::sun::star::uno;
92 : using namespace ::com::sun::star::util;
93 :
94 :
95 : namespace {
96 :
97 340 : void lclUpdateProgressBar( const ISegmentProgressBarRef& rxProgressBar, double fPosition )
98 : {
99 340 : if( rxProgressBar.get() )
100 340 : rxProgressBar->setPosition( fPosition );
101 340 : }
102 :
103 : } // namespace
104 :
105 :
106 263 : ColumnModel::ColumnModel() :
107 : maRange( -1 ),
108 : mfWidth( 0.0 ),
109 : mnXfId( -1 ),
110 : mnLevel( 0 ),
111 : mbShowPhonetic( false ),
112 : mbHidden( false ),
113 263 : mbCollapsed( false )
114 : {
115 263 : }
116 :
117 34 : bool ColumnModel::isMergeable( const ColumnModel& rModel ) const
118 : {
119 : return
120 68 : (maRange.mnFirst <= rModel.maRange.mnFirst) &&
121 68 : (rModel.maRange.mnFirst <= maRange.mnLast + 1) &&
122 34 : (mfWidth == rModel.mfWidth) &&
123 : // ignore mnXfId, cell formatting is always set directly
124 0 : (mnLevel == rModel.mnLevel) &&
125 34 : (mbHidden == rModel.mbHidden) &&
126 34 : (mbCollapsed == rModel.mbCollapsed);
127 : }
128 :
129 769 : RowModel::RowModel() :
130 : mnRow( -1 ),
131 : mfHeight( 0.0 ),
132 : mnXfId( -1 ),
133 : mnLevel( 0 ),
134 : mbCustomHeight( false ),
135 : mbCustomFormat( false ),
136 : mbShowPhonetic( false ),
137 : mbHidden( false ),
138 : mbCollapsed( false ),
139 : mbThickTop( false ),
140 769 : mbThickBottom( false )
141 : {
142 769 : }
143 :
144 274 : void RowModel::insertColSpan( const ValueRange& rColSpan )
145 : {
146 274 : if( (0 <= rColSpan.mnFirst) && (rColSpan.mnFirst <= rColSpan.mnLast) )
147 274 : maColSpans.insert( rColSpan );
148 274 : }
149 :
150 439 : bool RowModel::isMergeable( const RowModel& rModel ) const
151 : {
152 : return
153 : // ignore maColSpans - is handled separately in SheetDataBuffer class
154 838 : (mfHeight == rModel.mfHeight) &&
155 : // ignore mnXfId, mbCustomFormat, mbShowPhonetic - cell formatting is always set directly
156 798 : (mnLevel == rModel.mnLevel) &&
157 798 : (mbCustomHeight == rModel.mbCustomHeight) &&
158 1234 : (mbHidden == rModel.mbHidden) &&
159 835 : (mbCollapsed == rModel.mbCollapsed);
160 : }
161 :
162 0 : PageBreakModel::PageBreakModel()
163 : : mnColRow(0)
164 : , mnMin(0)
165 : , mnMax(0)
166 0 : , mbManual(false)
167 : {
168 0 : }
169 :
170 3 : HyperlinkModel::HyperlinkModel()
171 : {
172 3 : }
173 :
174 0 : ValidationModel::ValidationModel() :
175 : mnType( XML_none ),
176 : mnOperator( XML_between ),
177 : mnErrorStyle( XML_stop ),
178 : mbShowInputMsg( false ),
179 : mbShowErrorMsg( false ),
180 : mbNoDropDown( false ),
181 0 : mbAllowBlank( false )
182 : {
183 0 : }
184 :
185 0 : void ValidationModel::setBiffType( sal_uInt8 nType )
186 : {
187 : static const sal_Int32 spnTypeIds[] = {
188 : XML_none, XML_whole, XML_decimal, XML_list, XML_date, XML_time, XML_textLength, XML_custom };
189 0 : mnType = STATIC_ARRAY_SELECT( spnTypeIds, nType, XML_none );
190 0 : }
191 :
192 0 : void ValidationModel::setBiffOperator( sal_uInt8 nOperator )
193 : {
194 : static const sal_Int32 spnOperators[] = {
195 : XML_between, XML_notBetween, XML_equal, XML_notEqual,
196 : XML_greaterThan, XML_lessThan, XML_greaterThanOrEqual, XML_lessThanOrEqual };
197 0 : mnOperator = STATIC_ARRAY_SELECT( spnOperators, nOperator, XML_TOKEN_INVALID );
198 0 : }
199 :
200 0 : void ValidationModel::setBiffErrorStyle( sal_uInt8 nErrorStyle )
201 : {
202 : static const sal_Int32 spnErrorStyles[] = { XML_stop, XML_warning, XML_information };
203 0 : mnErrorStyle = STATIC_ARRAY_SELECT( spnErrorStyles, nErrorStyle, XML_stop );
204 0 : }
205 :
206 :
207 : class WorksheetGlobals : public WorkbookHelper, public IWorksheetProgress
208 : {
209 : public:
210 : explicit WorksheetGlobals(
211 : const WorkbookHelper& rHelper,
212 : const ISegmentProgressBarRef& rxProgressBar,
213 : WorksheetType eSheetType,
214 : sal_Int16 nSheet );
215 170 : virtual ~WorksheetGlobals() {}
216 :
217 : /** Returns true, if this helper refers to an existing Calc sheet. */
218 85 : inline bool isValidSheet() const { return mxSheet.is(); }
219 :
220 : /** Returns the type of this sheet. */
221 265 : inline WorksheetType getSheetType() const { return meSheetType; }
222 : /** Returns the index of the current sheet. */
223 2103 : inline sal_Int16 getSheetIndex() const { return maUsedArea.Sheet; }
224 : /** Returns the XSpreadsheet interface of the current sheet. */
225 215 : inline const Reference< XSpreadsheet >& getSheet() const { return mxSheet; }
226 :
227 : /** Returns the XCell interface for the passed cell address. */
228 : Reference< XCell > getCell( const CellAddress& rAddress ) const;
229 : /** Returns the XCellRange interface for the passed cell range address. */
230 : Reference< XCellRange > getCellRange( const CellRangeAddress& rRange ) const;
231 : /** Returns the XSheetCellRanges interface for the passed cell range addresses. */
232 : Reference< XSheetCellRanges > getCellRangeList( const ApiCellRangeList& rRanges ) const;
233 :
234 : /** Returns the XCellRange interface for a column. */
235 : Reference< XCellRange > getColumn( sal_Int32 nCol ) const;
236 : /** Returns the XCellRange interface for a row. */
237 : Reference< XCellRange > getRow( sal_Int32 nRow ) const;
238 :
239 : /** Returns the XDrawPage interface of the draw page of the current sheet. */
240 : Reference< XDrawPage > getDrawPage() const;
241 : /** Returns the size of the entire drawing page in 1/100 mm. */
242 : const awt::Size& getDrawPageSize() const;
243 :
244 : /** Returns the absolute position of the top-left corner of the cell in 1/100 mm. */
245 : awt::Point getCellPosition( sal_Int32 nCol, sal_Int32 nRow ) const;
246 : /** Returns the size of the cell in 1/100 mm. */
247 : awt::Size getCellSize( sal_Int32 nCol, sal_Int32 nRow ) const;
248 :
249 : /** Returns the address of the cell that contains the passed point in 1/100 mm. */
250 : CellAddress getCellAddressFromPosition( const awt::Point& rPosition ) const;
251 : /** Returns the cell range address that contains the passed rectangle in 1/100 mm. */
252 : CellRangeAddress getCellRangeFromRectangle( const awt::Rectangle& rRect ) const;
253 :
254 : /** Returns the buffer for cell contents and cell formatting. */
255 87 : inline SheetDataBuffer& getSheetData() { return maSheetData; }
256 : /** Returns the conditional formatting in this sheet. */
257 157 : inline CondFormatBuffer& getCondFormats() { return maCondFormats; }
258 : /** Returns the buffer for all cell comments in this sheet. */
259 1 : inline CommentsBuffer& getComments() { return maComments; }
260 : /** Returns the auto filters for the sheet. */
261 1 : inline AutoFilterBuffer& getAutoFilters() { return maAutoFilters; }
262 : /** Returns the buffer for all web query tables in this sheet. */
263 0 : inline QueryTableBuffer& getQueryTables() { return maQueryTables; }
264 : /** Returns the worksheet settings object. */
265 101 : inline WorksheetSettings& getWorksheetSettings() { return maSheetSett; }
266 : /** Returns the page/print settings for this sheet. */
267 334 : inline PageSettings& getPageSettings() { return maPageSett; }
268 : /** Returns the view settings for this sheet. */
269 152 : inline SheetViewSettings& getSheetViewSettings() { return maSheetViewSett; }
270 : /** Returns the VML drawing page for this sheet (OOXML/BIFF12 only). */
271 7 : inline VmlDrawing& getVmlDrawing() { return *mxVmlDrawing; }
272 : /** returns the ExtLst entries that need to be filled */
273 15 : inline ExtLst& getExtLst() { return maExtLst; }
274 :
275 : /** Returns the BIFF drawing page for this sheet (BIFF2-BIFF8 only). */
276 0 : inline BiffSheetDrawing& getBiffDrawing() const { return *mxBiffDrawing; }
277 :
278 : /** Changes the current sheet type. */
279 : inline void setSheetType( WorksheetType eSheetType ) { meSheetType = eSheetType; }
280 : /** Sets a column or row page break described in the passed struct. */
281 : void setPageBreak( const PageBreakModel& rModel, bool bRowBreak );
282 : /** Inserts the hyperlink URL into the spreadsheet. */
283 : void setHyperlink( const HyperlinkModel& rModel );
284 : /** Inserts the data validation settings into the spreadsheet. */
285 : void setValidation( const ValidationModel& rModel );
286 : /** Sets the path to the DrawingML fragment of this sheet. */
287 : void setDrawingPath( const OUString& rDrawingPath );
288 : /** Sets the path to the legacy VML drawing fragment of this sheet. */
289 : void setVmlDrawingPath( const OUString& rVmlDrawingPath );
290 :
291 : /** Extends the used area of this sheet by the passed cell position. */
292 : void extendUsedArea( const CellAddress& rAddress );
293 : /** Extends the used area of this sheet by the passed cell range. */
294 : void extendUsedArea( const CellRangeAddress& rRange );
295 : /** Extends the shape bounding box by the position and size of the passed rectangle. */
296 : void extendShapeBoundingBox( const awt::Rectangle& rShapeRect );
297 :
298 : /** Sets base width for all columns (without padding pixels). This value
299 : is only used, if base width has not been set with setDefaultColumnWidth(). */
300 : void setBaseColumnWidth( sal_Int32 nWidth );
301 : /** Sets default width for all columns. This function overrides the base
302 : width set with the setBaseColumnWidth() function. */
303 : void setDefaultColumnWidth( double fWidth );
304 : /** Sets column settings for a specific column range.
305 : @descr Column default formatting is converted directly, other settings
306 : are cached and converted in the finalizeImport() call. */
307 : void setColumnModel( const ColumnModel& rModel );
308 : /** Converts column default cell formatting. */
309 : void convertColumnFormat( sal_Int32 nFirstCol, sal_Int32 nLastCol, sal_Int32 nXfId ) const;
310 :
311 : /** Sets default height and hidden state for all unused rows in the sheet. */
312 : void setDefaultRowSettings( double fHeight, bool bCustomHeight, bool bHidden, bool bThickTop, bool bThickBottom );
313 : /** Sets row settings for a specific row.
314 : @descr Row default formatting is converted directly, other settings
315 : are cached and converted in the finalizeImport() call. */
316 : void setRowModel( const RowModel& rModel );
317 :
318 : /** Initial conversion before importing the worksheet. */
319 : void initializeWorksheetImport();
320 : /** Final conversion after importing the worksheet. */
321 : void finalizeWorksheetImport();
322 :
323 : void finalizeDrawingImport();
324 :
325 : /// Allow the threaded importer to override our progress bar impl.
326 0 : virtual ISegmentProgressBarRef getRowProgress() SAL_OVERRIDE
327 : {
328 0 : return mxRowProgress;
329 : }
330 0 : virtual void setCustomRowProgress( const ISegmentProgressBarRef &rxRowProgress ) SAL_OVERRIDE
331 : {
332 0 : mxRowProgress = rxRowProgress;
333 0 : mbFastRowProgress = true;
334 0 : }
335 :
336 : private:
337 : typedef ::std::vector< sal_Int32 > OutlineLevelVec;
338 : typedef ::std::pair< ColumnModel, sal_Int32 > ColumnModelRange;
339 : typedef ::std::map< sal_Int32, ColumnModelRange > ColumnModelRangeMap;
340 : typedef ::std::pair< RowModel, sal_Int32 > RowModelRange;
341 : typedef ::std::map< sal_Int32, RowModelRange > RowModelRangeMap;
342 : typedef ::std::list< HyperlinkModel > HyperlinkModelList;
343 : typedef ::std::list< ValidationModel > ValidationModelList;
344 :
345 : /** Inserts all imported hyperlinks into their cell ranges. */
346 : void finalizeHyperlinkRanges();
347 : /** Generates the final URL for the passed hyperlink. */
348 : OUString getHyperlinkUrl( const HyperlinkModel& rHyperlink ) const;
349 : /** Inserts a hyperlinks into the specified cell. */
350 : void insertHyperlink( const CellAddress& rAddress, const OUString& rUrl );
351 :
352 : /** Inserts all imported data validations into their cell ranges. */
353 : void finalizeValidationRanges() const;
354 :
355 : /** Converts column properties for all columns in the sheet. */
356 : void convertColumns();
357 : /** Converts column properties. */
358 : void convertColumns( OutlineLevelVec& orColLevels, const ValueRange& rColRange, const ColumnModel& rModel );
359 :
360 : /** Converts row properties for all rows in the sheet. */
361 : void convertRows();
362 : /** Converts row properties. */
363 : void convertRows( OutlineLevelVec& orRowLevels, const ValueRange& rRowRange, const RowModel& rModel, double fDefHeight = -1.0 );
364 :
365 : /** Converts outline grouping for the passed column or row. */
366 : void convertOutlines( OutlineLevelVec& orLevels, sal_Int32 nColRow, sal_Int32 nLevel, bool bCollapsed, bool bRows );
367 : /** Groups columns or rows for the given range. */
368 : void groupColumnsOrRows( sal_Int32 nFirstColRow, sal_Int32 nLastColRow, bool bCollapsed, bool bRows );
369 :
370 : /** Imports the drawings of the sheet (DML, VML, DFF) and updates the used area. */
371 : void finalizeDrawings();
372 :
373 : /** Update the row import progress bar */
374 : void UpdateRowProgress( const CellRangeAddress& rUsedArea, sal_Int32 nRow );
375 :
376 : private:
377 : typedef ::std::auto_ptr< VmlDrawing > VmlDrawingPtr;
378 : typedef ::std::auto_ptr< BiffSheetDrawing > BiffSheetDrawingPtr;
379 :
380 : const OUString maSheetCellRanges; /// Service name for a SheetCellRanges object.
381 : const OUString maUrlTextField; /// Service name for a URL text field.
382 : const CellAddress& mrMaxApiPos; /// Reference to maximum Calc cell address from address converter.
383 : CellRangeAddress maUsedArea; /// Used area of the sheet, and sheet index of the sheet.
384 : ColumnModel maDefColModel; /// Default column formatting.
385 : ColumnModelRangeMap maColModels; /// Ranges of columns sorted by first column index.
386 : RowModel maDefRowModel; /// Default row formatting.
387 : RowModelRangeMap maRowModels; /// Ranges of rows sorted by first row index.
388 : HyperlinkModelList maHyperlinks; /// Cell ranges containing hyperlinks.
389 : ValidationModelList maValidations; /// Cell ranges containing data validation settings.
390 : SheetDataBuffer maSheetData; /// Buffer for cell contents and cell formatting.
391 : CondFormatBuffer maCondFormats; /// Buffer for conditional formatting.
392 : CommentsBuffer maComments; /// Buffer for all cell comments in this sheet.
393 : AutoFilterBuffer maAutoFilters; /// Sheet auto filters (not associated to a table).
394 : QueryTableBuffer maQueryTables; /// Buffer for all web query tables in this sheet.
395 : WorksheetSettings maSheetSett; /// Global settings for this sheet.
396 : PageSettings maPageSett; /// Page/print settings for this sheet.
397 : SheetViewSettings maSheetViewSett; /// View settings for this sheet.
398 : VmlDrawingPtr mxVmlDrawing; /// Collection of all VML shapes.
399 : ExtLst maExtLst; /// List of extended elements
400 : BiffSheetDrawingPtr mxBiffDrawing; /// Collection of all BIFF/DFF shapes.
401 : OUString maDrawingPath; /// Path to DrawingML fragment.
402 : OUString maVmlDrawingPath; /// Path to legacy VML drawing fragment.
403 : awt::Size maDrawPageSize; /// Current size of the drawing page in 1/100 mm.
404 : awt::Rectangle maShapeBoundingBox; /// Bounding box for all shapes from all drawings.
405 : ISegmentProgressBarRef mxProgressBar; /// Sheet progress bar.
406 : bool mbFastRowProgress; /// Do we have a progress bar thread ?
407 : ISegmentProgressBarRef mxRowProgress; /// Progress bar for row/cell processing.
408 : ISegmentProgressBarRef mxFinalProgress; /// Progress bar for finalization.
409 : WorksheetType meSheetType; /// Type of this sheet.
410 : Reference< XSpreadsheet > mxSheet; /// Reference to the current sheet.
411 : bool mbHasDefWidth; /// True = default column width is set from defaultColWidth attribute.
412 : };
413 :
414 85 : WorksheetGlobals::WorksheetGlobals( const WorkbookHelper& rHelper, const ISegmentProgressBarRef& rxProgressBar, WorksheetType eSheetType, sal_Int16 nSheet ) :
415 : WorkbookHelper( rHelper ),
416 : maSheetCellRanges( "com.sun.star.sheet.SheetCellRanges" ),
417 : maUrlTextField( "com.sun.star.text.TextField.URL" ),
418 85 : mrMaxApiPos( rHelper.getAddressConverter().getMaxApiAddress() ),
419 : maUsedArea( nSheet, SAL_MAX_INT32, SAL_MAX_INT32, -1, -1 ),
420 : maSheetData( *this ),
421 : maCondFormats( *this ),
422 : maComments( *this ),
423 : maAutoFilters( *this ),
424 : maQueryTables( *this ),
425 : maSheetSett( *this ),
426 : maPageSett( *this ),
427 : maSheetViewSett( *this ),
428 : mxProgressBar( rxProgressBar ),
429 : mbFastRowProgress( false ),
430 : meSheetType( eSheetType ),
431 170 : mbHasDefWidth( false )
432 : {
433 85 : mxSheet = getSheetFromDoc( nSheet );
434 85 : if( !mxSheet.is() )
435 0 : maUsedArea.Sheet = -1;
436 :
437 : // default column settings (width and hidden state may be updated later)
438 85 : maDefColModel.mfWidth = 8.5;
439 85 : maDefColModel.mnXfId = -1;
440 85 : maDefColModel.mnLevel = 0;
441 85 : maDefColModel.mbHidden = false;
442 85 : maDefColModel.mbCollapsed = false;
443 :
444 : // default row settings (height and hidden state may be updated later)
445 85 : maDefRowModel.mfHeight = 0.0;
446 85 : maDefRowModel.mnXfId = -1;
447 85 : maDefRowModel.mnLevel = 0;
448 85 : maDefRowModel.mbCustomHeight = false;
449 85 : maDefRowModel.mbCustomFormat = false;
450 85 : maDefRowModel.mbShowPhonetic = false;
451 85 : maDefRowModel.mbHidden = false;
452 85 : maDefRowModel.mbCollapsed = false;
453 :
454 : // buffers
455 85 : switch( getFilterType() )
456 : {
457 : case FILTER_OOXML:
458 85 : mxVmlDrawing.reset( new VmlDrawing( *this ) );
459 85 : break;
460 : case FILTER_BIFF:
461 0 : mxBiffDrawing.reset( new BiffSheetDrawing( *this ) );
462 0 : break;
463 : case FILTER_UNKNOWN:
464 0 : break;
465 : }
466 :
467 : // prepare progress bars
468 85 : if( mxProgressBar.get() )
469 : {
470 85 : mxRowProgress = mxProgressBar->createSegment( 0.5 );
471 85 : mxFinalProgress = mxProgressBar->createSegment( 0.5 );
472 : }
473 85 : }
474 :
475 167 : Reference< XCell > WorksheetGlobals::getCell( const CellAddress& rAddress ) const
476 : {
477 167 : Reference< XCell > xCell;
478 167 : if( mxSheet.is() ) try
479 : {
480 167 : xCell = mxSheet->getCellByPosition( rAddress.Column, rAddress.Row );
481 : }
482 0 : catch( Exception& )
483 : {
484 : }
485 167 : return xCell;
486 : }
487 :
488 174 : Reference< XCellRange > WorksheetGlobals::getCellRange( const CellRangeAddress& rRange ) const
489 : {
490 174 : Reference< XCellRange > xRange;
491 174 : if( mxSheet.is() ) try
492 : {
493 174 : xRange = mxSheet->getCellRangeByPosition( rRange.StartColumn, rRange.StartRow, rRange.EndColumn, rRange.EndRow );
494 : }
495 0 : catch( Exception& )
496 : {
497 : }
498 174 : return xRange;
499 : }
500 :
501 0 : Reference< XSheetCellRanges > WorksheetGlobals::getCellRangeList( const ApiCellRangeList& rRanges ) const
502 : {
503 0 : Reference< XSheetCellRanges > xRanges;
504 0 : if( mxSheet.is() && !rRanges.empty() ) try
505 : {
506 0 : xRanges.set( getBaseFilter().getModelFactory()->createInstance( maSheetCellRanges ), UNO_QUERY_THROW );
507 0 : Reference< XSheetCellRangeContainer > xRangeCont( xRanges, UNO_QUERY_THROW );
508 0 : xRangeCont->addRangeAddresses( ContainerHelper::vectorToSequence( rRanges ), sal_False );
509 : }
510 0 : catch( Exception& )
511 : {
512 : }
513 0 : return xRanges;
514 : }
515 :
516 0 : Reference< XCellRange > WorksheetGlobals::getColumn( sal_Int32 nCol ) const
517 : {
518 0 : Reference< XCellRange > xColumn;
519 : try
520 : {
521 0 : Reference< XColumnRowRange > xColRowRange( mxSheet, UNO_QUERY_THROW );
522 0 : Reference< XTableColumns > xColumns( xColRowRange->getColumns(), UNO_SET_THROW );
523 0 : xColumn.set( xColumns->getByIndex( nCol ), UNO_QUERY );
524 : }
525 0 : catch( Exception& )
526 : {
527 : }
528 0 : return xColumn;
529 : }
530 :
531 0 : Reference< XCellRange > WorksheetGlobals::getRow( sal_Int32 nRow ) const
532 : {
533 0 : Reference< XCellRange > xRow;
534 : try
535 : {
536 0 : Reference< XColumnRowRange > xColRowRange( mxSheet, UNO_QUERY_THROW );
537 0 : Reference< XTableRows > xRows( xColRowRange->getRows(), UNO_SET_THROW );
538 0 : xRow.set( xRows->getByIndex( nRow ), UNO_QUERY );
539 : }
540 0 : catch( Exception& )
541 : {
542 : }
543 0 : return xRow;
544 : }
545 :
546 101 : Reference< XDrawPage > WorksheetGlobals::getDrawPage() const
547 : {
548 101 : Reference< XDrawPage > xDrawPage;
549 : try
550 : {
551 101 : xDrawPage = Reference< XDrawPageSupplier >( mxSheet, UNO_QUERY_THROW )->getDrawPage();
552 : }
553 0 : catch( Exception& )
554 : {
555 : }
556 101 : return xDrawPage;
557 : }
558 :
559 16 : const awt::Size& WorksheetGlobals::getDrawPageSize() const
560 : {
561 : OSL_ENSURE( (maDrawPageSize.Width > 0) && (maDrawPageSize.Height > 0), "WorksheetGlobals::getDrawPageSize - called too early, size invalid" );
562 16 : return maDrawPageSize;
563 : }
564 :
565 166 : awt::Point WorksheetGlobals::getCellPosition( sal_Int32 nCol, sal_Int32 nRow ) const
566 : {
567 166 : awt::Point aPoint;
568 166 : PropertySet aCellProp( getCell( CellAddress( getSheetIndex(), nCol, nRow ) ) );
569 166 : aCellProp.getProperty( aPoint, PROP_Position );
570 166 : return aPoint;
571 : }
572 :
573 0 : awt::Size WorksheetGlobals::getCellSize( sal_Int32 nCol, sal_Int32 nRow ) const
574 : {
575 0 : awt::Size aSize;
576 0 : PropertySet aCellProp( getCell( CellAddress( getSheetIndex(), nCol, nRow ) ) );
577 0 : aCellProp.getProperty( aSize, PROP_Size );
578 0 : return aSize;
579 : }
580 :
581 : namespace {
582 :
583 160 : inline sal_Int32 lclGetMidAddr( sal_Int32 nBegAddr, sal_Int32 nEndAddr, sal_Int32 nBegPos, sal_Int32 nEndPos, sal_Int32 nSearchPos )
584 : {
585 : // use sal_Int64 to prevent integer overflow
586 160 : return nBegAddr + 1 + static_cast< sal_Int32 >( static_cast< sal_Int64 >( nEndAddr - nBegAddr - 2 ) * (nSearchPos - nBegPos) / (nEndPos - nBegPos) );
587 : }
588 :
589 64 : bool lclPrepareInterval( sal_Int32 nBegAddr, sal_Int32& rnMidAddr, sal_Int32 nEndAddr,
590 : sal_Int32 nBegPos, sal_Int32 nEndPos, sal_Int32 nSearchPos )
591 : {
592 : // searched position before nBegPos -> use nBegAddr
593 64 : if( nSearchPos <= nBegPos )
594 : {
595 5 : rnMidAddr = nBegAddr;
596 5 : return false;
597 : }
598 :
599 : // searched position after nEndPos, or begin next to end -> use nEndAddr
600 59 : if( (nSearchPos >= nEndPos) || (nBegAddr + 1 >= nEndAddr) )
601 : {
602 0 : rnMidAddr = nEndAddr;
603 0 : return false;
604 : }
605 :
606 : /* Otherwise find mid address according to position. lclGetMidAddr() will
607 : return an address between nBegAddr and nEndAddr. */
608 59 : rnMidAddr = lclGetMidAddr( nBegAddr, nEndAddr, nBegPos, nEndPos, nSearchPos );
609 59 : return true;
610 : }
611 :
612 160 : bool lclUpdateInterval( sal_Int32& rnBegAddr, sal_Int32& rnMidAddr, sal_Int32& rnEndAddr,
613 : sal_Int32& rnBegPos, sal_Int32 nMidPos, sal_Int32& rnEndPos, sal_Int32 nSearchPos )
614 : {
615 : // nSearchPos < nMidPos: use the interval [begin,mid] in the next iteration
616 160 : if( nSearchPos < nMidPos )
617 : {
618 : // if rnBegAddr is next to rnMidAddr, the latter is the column/row in question
619 58 : if( rnBegAddr + 1 >= rnMidAddr )
620 8 : return false;
621 : // otherwise, set interval end to mid
622 50 : rnEndPos = nMidPos;
623 50 : rnEndAddr = rnMidAddr;
624 50 : rnMidAddr = lclGetMidAddr( rnBegAddr, rnEndAddr, rnBegPos, rnEndPos, nSearchPos );
625 50 : return true;
626 : }
627 :
628 : // nSearchPos > nMidPos: use the interval [mid,end] in the next iteration
629 102 : if( nSearchPos > nMidPos )
630 : {
631 : // if rnMidAddr is next to rnEndAddr, the latter is the column/row in question
632 101 : if( rnMidAddr + 1 >= rnEndAddr )
633 : {
634 50 : rnMidAddr = rnEndAddr;
635 50 : return false;
636 : }
637 : // otherwise, set interval start to mid
638 51 : rnBegPos = nMidPos;
639 51 : rnBegAddr = rnMidAddr;
640 51 : rnMidAddr = lclGetMidAddr( rnBegAddr, rnEndAddr, rnBegPos, rnEndPos, nSearchPos );
641 51 : return true;
642 : }
643 :
644 : // nSearchPos == nMidPos: rnMidAddr is the column/row in question, do not loop anymore
645 1 : return false;
646 : }
647 :
648 : } // namespace
649 :
650 32 : CellAddress WorksheetGlobals::getCellAddressFromPosition( const awt::Point& rPosition ) const
651 : {
652 : // starting cell address and its position in drawing layer (top-left edge)
653 32 : sal_Int32 nBegCol = 0;
654 32 : sal_Int32 nBegRow = 0;
655 32 : awt::Point aBegPos( 0, 0 );
656 :
657 : // end cell address and its position in drawing layer (bottom-right edge)
658 32 : sal_Int32 nEndCol = mrMaxApiPos.Column + 1;
659 32 : sal_Int32 nEndRow = mrMaxApiPos.Row + 1;
660 32 : awt::Point aEndPos( maDrawPageSize.Width, maDrawPageSize.Height );
661 :
662 : // starting point for interval search
663 : sal_Int32 nMidCol, nMidRow;
664 32 : bool bLoopCols = lclPrepareInterval( nBegCol, nMidCol, nEndCol, aBegPos.X, aEndPos.X, rPosition.X );
665 32 : bool bLoopRows = lclPrepareInterval( nBegRow, nMidRow, nEndRow, aBegPos.Y, aEndPos.Y, rPosition.Y );
666 32 : awt::Point aMidPos = getCellPosition( nMidCol, nMidRow );
667 :
668 : /* The loop will find the column/row index of the cell right of/below
669 : the cell containing the passed point, unless the point is located at
670 : the top or left border of the containing cell. */
671 150 : while( bLoopCols || bLoopRows )
672 : {
673 86 : bLoopCols = bLoopCols && lclUpdateInterval( nBegCol, nMidCol, nEndCol, aBegPos.X, aMidPos.X, aEndPos.X, rPosition.X );
674 86 : bLoopRows = bLoopRows && lclUpdateInterval( nBegRow, nMidRow, nEndRow, aBegPos.Y, aMidPos.Y, aEndPos.Y, rPosition.Y );
675 86 : aMidPos = getCellPosition( nMidCol, nMidRow );
676 : }
677 :
678 : /* The cell left of/above the current search position contains the passed
679 : point, unless the point is located on the top/left border of the cell,
680 : or the last column/row of the sheet has been reached. */
681 32 : if( aMidPos.X > rPosition.X ) --nMidCol;
682 32 : if( aMidPos.Y > rPosition.Y ) --nMidRow;
683 32 : return CellAddress( getSheetIndex(), nMidCol, nMidRow );
684 : }
685 :
686 16 : CellRangeAddress WorksheetGlobals::getCellRangeFromRectangle( const awt::Rectangle& rRect ) const
687 : {
688 16 : CellAddress aStartAddr = getCellAddressFromPosition( awt::Point( rRect.X, rRect.Y ) );
689 16 : awt::Point aBotRight( rRect.X + rRect.Width, rRect.Y + rRect.Height );
690 16 : CellAddress aEndAddr = getCellAddressFromPosition( aBotRight );
691 16 : bool bMultiCols = aStartAddr.Column < aEndAddr.Column;
692 16 : bool bMultiRows = aStartAddr.Row < aEndAddr.Row;
693 16 : if( bMultiCols || bMultiRows )
694 : {
695 : /* Reduce end position of the cell range to previous column or row, if
696 : the rectangle ends exactly between two columns or rows. */
697 16 : awt::Point aEndPos = getCellPosition( aEndAddr.Column, aEndAddr.Row );
698 16 : if( bMultiCols && (aBotRight.X <= aEndPos.X) )
699 0 : --aEndAddr.Column;
700 16 : if( bMultiRows && (aBotRight.Y <= aEndPos.Y) )
701 1 : --aEndAddr.Row;
702 : }
703 16 : return CellRangeAddress( getSheetIndex(), aStartAddr.Column, aStartAddr.Row, aEndAddr.Column, aEndAddr.Row );
704 : }
705 :
706 0 : void WorksheetGlobals::setPageBreak( const PageBreakModel& rModel, bool bRowBreak )
707 : {
708 0 : if( rModel.mbManual && (rModel.mnColRow > 0) )
709 : {
710 0 : PropertySet aPropSet( bRowBreak ? getRow( rModel.mnColRow ) : getColumn( rModel.mnColRow ) );
711 0 : aPropSet.setProperty( PROP_IsStartOfNewPage, true );
712 : }
713 0 : }
714 :
715 3 : void WorksheetGlobals::setHyperlink( const HyperlinkModel& rModel )
716 : {
717 3 : maHyperlinks.push_back( rModel );
718 3 : }
719 :
720 0 : void WorksheetGlobals::setValidation( const ValidationModel& rModel )
721 : {
722 0 : maValidations.push_back( rModel );
723 0 : }
724 :
725 16 : void WorksheetGlobals::setDrawingPath( const OUString& rDrawingPath )
726 : {
727 16 : maDrawingPath = rDrawingPath;
728 16 : }
729 :
730 3 : void WorksheetGlobals::setVmlDrawingPath( const OUString& rVmlDrawingPath )
731 : {
732 3 : maVmlDrawingPath = rVmlDrawingPath;
733 3 : }
734 :
735 2127 : void WorksheetGlobals::extendUsedArea( const CellAddress& rAddress )
736 : {
737 2127 : maUsedArea.StartColumn = ::std::min( maUsedArea.StartColumn, rAddress.Column );
738 2127 : maUsedArea.StartRow = ::std::min( maUsedArea.StartRow, rAddress.Row );
739 2127 : maUsedArea.EndColumn = ::std::max( maUsedArea.EndColumn, rAddress.Column );
740 2127 : maUsedArea.EndRow = ::std::max( maUsedArea.EndRow, rAddress.Row );
741 2127 : }
742 :
743 75 : void WorksheetGlobals::extendUsedArea( const CellRangeAddress& rRange )
744 : {
745 75 : extendUsedArea( CellAddress( rRange.Sheet, rRange.StartColumn, rRange.StartRow ) );
746 75 : extendUsedArea( CellAddress( rRange.Sheet, rRange.EndColumn, rRange.EndRow ) );
747 75 : }
748 :
749 16 : void WorksheetGlobals::extendShapeBoundingBox( const awt::Rectangle& rShapeRect )
750 : {
751 16 : if( (maShapeBoundingBox.Width == 0) && (maShapeBoundingBox.Height == 0) )
752 : {
753 : // width and height of maShapeBoundingBox are assumed to be zero on first cell
754 16 : maShapeBoundingBox = rShapeRect;
755 : }
756 : else
757 : {
758 0 : sal_Int32 nEndX = ::std::max( maShapeBoundingBox.X + maShapeBoundingBox.Width, rShapeRect.X + rShapeRect.Width );
759 0 : sal_Int32 nEndY = ::std::max( maShapeBoundingBox.Y + maShapeBoundingBox.Height, rShapeRect.Y + rShapeRect.Height );
760 0 : maShapeBoundingBox.X = ::std::min( maShapeBoundingBox.X, rShapeRect.X );
761 0 : maShapeBoundingBox.Y = ::std::min( maShapeBoundingBox.Y, rShapeRect.Y );
762 0 : maShapeBoundingBox.Width = nEndX - maShapeBoundingBox.X;
763 0 : maShapeBoundingBox.Height = nEndY - maShapeBoundingBox.Y;
764 : }
765 16 : }
766 :
767 73 : void WorksheetGlobals::setBaseColumnWidth( sal_Int32 nWidth )
768 : {
769 : // do not modify width, if setDefaultColumnWidth() has been used
770 73 : if( !mbHasDefWidth && (nWidth > 0) )
771 : {
772 : // #i3006# add 5 pixels padding to the width
773 73 : const UnitConverter& rUnitConv = getUnitConverter();
774 : maDefColModel.mfWidth = rUnitConv.scaleFromMm100(
775 73 : rUnitConv.scaleToMm100( nWidth, UNIT_DIGIT ) + rUnitConv.scaleToMm100( 5, UNIT_SCREENX ), UNIT_DIGIT );
776 : }
777 73 : }
778 :
779 73 : void WorksheetGlobals::setDefaultColumnWidth( double fWidth )
780 : {
781 : // overrides a width set with setBaseColumnWidth()
782 73 : if( fWidth > 0.0 )
783 : {
784 1 : maDefColModel.mfWidth = fWidth;
785 1 : mbHasDefWidth = true;
786 : }
787 73 : }
788 :
789 89 : void WorksheetGlobals::setColumnModel( const ColumnModel& rModel )
790 : {
791 : // convert 1-based OOXML column indexes to 0-based API column indexes
792 89 : sal_Int32 nFirstCol = rModel.maRange.mnFirst - 1;
793 89 : sal_Int32 nLastCol = rModel.maRange.mnLast - 1;
794 89 : if( getAddressConverter().checkCol( nFirstCol, true ) && (nFirstCol <= nLastCol) )
795 : {
796 : // validate last column index
797 89 : if( !getAddressConverter().checkCol( nLastCol, true ) )
798 47 : nLastCol = mrMaxApiPos.Column;
799 : // try to find entry in column model map that is able to merge with the passed model
800 89 : bool bInsertModel = true;
801 89 : if( !maColModels.empty() )
802 : {
803 : // find first column model range following nFirstCol (nFirstCol < aIt->first), or end of map
804 34 : ColumnModelRangeMap::iterator aIt = maColModels.upper_bound( nFirstCol );
805 : OSL_ENSURE( aIt == maColModels.end(), "WorksheetGlobals::setColModel - columns are unsorted" );
806 : // if inserting before another column model, get last free column
807 : OSL_ENSURE( (aIt == maColModels.end()) || (nLastCol < aIt->first), "WorksheetGlobals::setColModel - multiple models of the same column" );
808 34 : if( aIt != maColModels.end() )
809 0 : nLastCol = ::std::min( nLastCol, aIt->first - 1 );
810 34 : if( aIt != maColModels.begin() )
811 : {
812 : // go to previous map element (which may be able to merge with the passed model)
813 34 : --aIt;
814 : // the usage of upper_bound() above ensures that aIt->first is less than or equal to nFirstCol now
815 34 : sal_Int32& rnLastMapCol = aIt->second.second;
816 : OSL_ENSURE( rnLastMapCol < nFirstCol, "WorksheetGlobals::setColModel - multiple models of the same column" );
817 34 : nFirstCol = ::std::max( rnLastMapCol + 1, nFirstCol );
818 34 : if( (rnLastMapCol + 1 == nFirstCol) && (nFirstCol <= nLastCol) && aIt->second.first.isMergeable( rModel ) )
819 : {
820 : // can merge with existing model, update last column index
821 0 : rnLastMapCol = nLastCol;
822 0 : bInsertModel = false;
823 : }
824 : }
825 : }
826 89 : if( nFirstCol <= nLastCol )
827 : {
828 : // insert the column model, if it has not been merged with another
829 89 : if( bInsertModel )
830 89 : maColModels[ nFirstCol ] = ColumnModelRange( rModel, nLastCol );
831 : // set column formatting directly
832 89 : convertColumnFormat( nFirstCol, nLastCol, rModel.mnXfId );
833 : }
834 : }
835 89 : }
836 :
837 89 : void WorksheetGlobals::convertColumnFormat( sal_Int32 nFirstCol, sal_Int32 nLastCol, sal_Int32 nXfId ) const
838 : {
839 89 : CellRangeAddress aRange( getSheetIndex(), nFirstCol, 0, nLastCol, mrMaxApiPos.Row );
840 89 : if( getAddressConverter().validateCellRange( aRange, true, false ) )
841 : {
842 89 : PropertySet aPropSet( getCellRange( aRange ) );
843 89 : getStyles().writeCellXfToPropertySet( aPropSet, nXfId );
844 : }
845 89 : }
846 :
847 73 : void WorksheetGlobals::setDefaultRowSettings( double fHeight, bool bCustomHeight, bool bHidden, bool bThickTop, bool bThickBottom )
848 : {
849 73 : maDefRowModel.mfHeight = fHeight;
850 73 : maDefRowModel.mbCustomHeight = bCustomHeight;
851 73 : maDefRowModel.mbHidden = bHidden;
852 73 : maDefRowModel.mbThickTop = bThickTop;
853 73 : maDefRowModel.mbThickBottom = bThickBottom;
854 73 : }
855 :
856 540 : void WorksheetGlobals::setRowModel( const RowModel& rModel )
857 : {
858 : // convert 1-based OOXML row index to 0-based API row index
859 540 : sal_Int32 nRow = rModel.mnRow - 1;
860 540 : if( getAddressConverter().checkRow( nRow, true ) )
861 : {
862 : // try to find entry in row model map that is able to merge with the passed model
863 540 : bool bInsertModel = true;
864 540 : bool bUnusedRow = true;
865 540 : if( !maRowModels.empty() )
866 : {
867 : // find first row model range following nRow (nRow < aIt->first), or end of map
868 480 : RowModelRangeMap::iterator aIt = maRowModels.upper_bound( nRow );
869 : OSL_ENSURE( aIt == maRowModels.end(), "WorksheetGlobals::setRowModel - rows are unsorted" );
870 480 : if( aIt != maRowModels.begin() )
871 : {
872 : // go to previous map element (which may be able to merge with the passed model)
873 480 : --aIt;
874 : // the usage of upper_bound() above ensures that aIt->first is less than or equal to nRow now
875 480 : sal_Int32& rnLastMapRow = aIt->second.second;
876 480 : bUnusedRow = rnLastMapRow < nRow;
877 : OSL_ENSURE( bUnusedRow, "WorksheetGlobals::setRowModel - multiple models of the same row" );
878 480 : if( (rnLastMapRow + 1 == nRow) && aIt->second.first.isMergeable( rModel ) )
879 : {
880 : // can merge with existing model, update last row index
881 396 : ++rnLastMapRow;
882 396 : bInsertModel = false;
883 : }
884 : }
885 : }
886 540 : if( bUnusedRow )
887 : {
888 : // insert the row model, if it has not been merged with another
889 540 : if( bInsertModel )
890 144 : maRowModels[ nRow ] = RowModelRange( rModel, nRow );
891 : // set row formatting
892 540 : maSheetData.setRowFormat( nRow, rModel.mnXfId, rModel.mbCustomFormat );
893 : // set column spans
894 540 : maSheetData.setColSpans( nRow, rModel.maColSpans );
895 : }
896 : }
897 :
898 540 : UpdateRowProgress( maUsedArea, nRow );
899 540 : }
900 :
901 : // This is called at a higher frequency inside the (threaded) inner loop.
902 540 : void WorksheetGlobals::UpdateRowProgress( const CellRangeAddress& rUsedArea, sal_Int32 nRow )
903 : {
904 540 : if (!mxRowProgress || nRow < rUsedArea.StartRow || rUsedArea.EndRow < nRow)
905 556 : return;
906 :
907 524 : double fNewPos = static_cast<double>(nRow - rUsedArea.StartRow + 1.0) / (rUsedArea.EndRow - rUsedArea.StartRow + 1.0);
908 :
909 524 : if (mbFastRowProgress)
910 0 : mxRowProgress->setPosition(fNewPos);
911 : else
912 : {
913 524 : double fCurPos = mxRowProgress->getPosition();
914 524 : if (fCurPos < fNewPos && (fNewPos - fCurPos) > 0.3)
915 : // Try not to re-draw progress bar too frequently.
916 117 : mxRowProgress->setPosition(fNewPos);
917 : }
918 : }
919 :
920 :
921 85 : void WorksheetGlobals::initializeWorksheetImport()
922 : {
923 : // set default cell style for unused cells
924 85 : ScDocumentImport& rDoc = getDocImport();
925 :
926 : ScStyleSheet* pStyleSheet =
927 85 : static_cast<ScStyleSheet*>(rDoc.getDoc().GetStyleSheetPool()->Find(
928 85 : getStyles().getDefaultStyleName(), SFX_STYLE_FAMILY_PARA));
929 :
930 85 : if (pStyleSheet)
931 84 : rDoc.setCellStyleToSheet(getSheetIndex(), *pStyleSheet);
932 :
933 : /* Remember the current sheet index in global data, needed by global
934 : objects, e.g. the chart converter. */
935 85 : setCurrentSheetIndex( getSheetIndex() );
936 85 : }
937 :
938 85 : void WorksheetGlobals::finalizeWorksheetImport()
939 : {
940 85 : lclUpdateProgressBar( mxRowProgress, 1.0 );
941 85 : maSheetData.finalizeImport();
942 : // assumes getTables().finalizeImport ( which creates the DatabaseRanges )
943 : // has been called already
944 85 : getTables().applyAutoFilters();
945 :
946 85 : getCondFormats().finalizeImport();
947 85 : lclUpdateProgressBar( mxFinalProgress, 0.25 );
948 85 : finalizeHyperlinkRanges();
949 85 : finalizeValidationRanges();
950 85 : maAutoFilters.finalizeImport( getSheetIndex() );
951 85 : maQueryTables.finalizeImport();
952 85 : maSheetSett.finalizeImport();
953 85 : maPageSett.finalizeImport();
954 85 : maSheetViewSett.finalizeImport();
955 :
956 85 : lclUpdateProgressBar( mxFinalProgress, 0.5 );
957 85 : convertColumns();
958 85 : convertRows();
959 85 : lclUpdateProgressBar( mxFinalProgress, 1.0 );
960 85 : }
961 :
962 85 : void WorksheetGlobals::finalizeDrawingImport()
963 : {
964 85 : finalizeDrawings();
965 :
966 : // forget current sheet index in global data
967 85 : setCurrentSheetIndex( -1 );
968 85 : }
969 :
970 : // private --------------------------------------------------------------------
971 :
972 85 : void WorksheetGlobals::finalizeHyperlinkRanges()
973 : {
974 88 : for( HyperlinkModelList::const_iterator aIt = maHyperlinks.begin(), aEnd = maHyperlinks.end(); aIt != aEnd; ++aIt )
975 : {
976 3 : OUString aUrl = getHyperlinkUrl( *aIt );
977 : // try to insert URL into each cell of the range
978 3 : if( !aUrl.isEmpty() )
979 6 : for( CellAddress aAddress( getSheetIndex(), aIt->maRange.StartColumn, aIt->maRange.StartRow ); aAddress.Row <= aIt->maRange.EndRow; ++aAddress.Row )
980 6 : for( aAddress.Column = aIt->maRange.StartColumn; aAddress.Column <= aIt->maRange.EndColumn; ++aAddress.Column )
981 3 : insertHyperlink( aAddress, aUrl );
982 3 : }
983 85 : }
984 :
985 3 : OUString WorksheetGlobals::getHyperlinkUrl( const HyperlinkModel& rHyperlink ) const
986 : {
987 3 : OUStringBuffer aUrlBuffer;
988 3 : if( !rHyperlink.maTarget.isEmpty() )
989 0 : aUrlBuffer.append( getBaseFilter().getAbsoluteUrl( rHyperlink.maTarget ) );
990 3 : if( !rHyperlink.maLocation.isEmpty() )
991 3 : aUrlBuffer.append( '#' ).append( rHyperlink.maLocation );
992 3 : OUString aUrl = aUrlBuffer.makeStringAndClear();
993 :
994 : // convert '#SheetName!A1' to '#SheetName.A1'
995 3 : if( aUrl.startsWith("#") )
996 : {
997 3 : sal_Int32 nSepPos = aUrl.lastIndexOf( '!' );
998 3 : if( nSepPos > 0 )
999 : {
1000 : // replace the exclamation mark with a period
1001 3 : aUrl = aUrl.replaceAt( nSepPos, 1, OUString( '.' ) );
1002 : // #i66592# convert sheet names that have been renamed on import
1003 3 : OUString aSheetName = aUrl.copy( 1, nSepPos - 1 );
1004 6 : OUString aCalcName = getWorksheets().getCalcSheetName( aSheetName );
1005 3 : if( !aCalcName.isEmpty() )
1006 6 : aUrl = aUrl.replaceAt( 1, nSepPos - 1, aCalcName );
1007 : }
1008 : }
1009 :
1010 3 : return aUrl;
1011 : }
1012 :
1013 3 : void WorksheetGlobals::insertHyperlink( const CellAddress& rAddress, const OUString& rUrl )
1014 : {
1015 3 : ScDocumentImport& rDoc = getDocImport();
1016 3 : ScAddress aPos(rAddress.Column, rAddress.Row, rAddress.Sheet);
1017 3 : ScRefCellValue aCell;
1018 3 : aCell.assign(rDoc.getDoc(), aPos);
1019 :
1020 3 : if (aCell.meType == CELLTYPE_STRING || aCell.meType == CELLTYPE_EDIT)
1021 : {
1022 3 : OUString aStr = aCell.getString(&rDoc.getDoc());
1023 3 : ScFieldEditEngine& rEE = rDoc.getDoc().GetEditEngine();
1024 3 : rEE.Clear();
1025 :
1026 6 : SvxURLField aURLField(rUrl, aStr, SVXURLFORMAT_REPR);
1027 6 : SvxFieldItem aURLItem(aURLField, EE_FEATURE_FIELD);
1028 3 : rEE.QuickInsertField(aURLItem, ESelection());
1029 :
1030 6 : rDoc.setEditCell(aPos, rEE.CreateTextObject());
1031 : }
1032 : else
1033 : {
1034 : // Handle other cell types e.g. formulas ( and ? ) that have associated
1035 : // hyperlinks.
1036 : // Ideally all hyperlinks should be treated as below. For the moment,
1037 : // given the current absence of ods support lets just handle what we
1038 : // previously didn't handle the new way.
1039 : // Unfortunately we won't be able to preserve such hyperlinks when
1040 : // saving to ods. Note: when we are able to save such hyperlinks to ods
1041 : // we should handle *all* imported hyperlinks as below ( e.g. as cell
1042 : // attribute ) for better interoperability.
1043 :
1044 0 : SfxStringItem aItem(ATTR_HYPERLINK, rUrl);
1045 0 : rDoc.getDoc().ApplyAttr(rAddress.Column, rAddress.Row, rAddress.Sheet, aItem);
1046 3 : }
1047 3 : }
1048 :
1049 85 : void WorksheetGlobals::finalizeValidationRanges() const
1050 : {
1051 85 : for( ValidationModelList::const_iterator aIt = maValidations.begin(), aEnd = maValidations.end(); aIt != aEnd; ++aIt )
1052 : {
1053 0 : PropertySet aPropSet( getCellRangeList( aIt->maRanges ) );
1054 :
1055 0 : Reference< XPropertySet > xValidation( aPropSet.getAnyProperty( PROP_Validation ), UNO_QUERY );
1056 0 : if( xValidation.is() )
1057 : {
1058 0 : PropertySet aValProps( xValidation );
1059 :
1060 : try
1061 : {
1062 0 : sal_Int32 nIndex = 0;
1063 0 : OUString aToken = aIt->msRef.getToken( 0, ' ', nIndex );
1064 :
1065 0 : Reference<XSpreadsheet> xSheet = getSheetFromDoc( getCurrentSheetIndex() );
1066 0 : Reference<XCellRange> xDBCellRange;
1067 0 : Reference<XCell> xCell;
1068 0 : xDBCellRange = xSheet->getCellRangeByName( aToken );
1069 :
1070 0 : xCell = xDBCellRange->getCellByPosition( 0, 0 );
1071 0 : Reference<XCellAddressable> xCellAddressable( xCell, UNO_QUERY_THROW );
1072 0 : CellAddress aFirstCell = xCellAddressable->getCellAddress();
1073 0 : Reference<XSheetCondition> xCondition( xValidation, UNO_QUERY_THROW );
1074 0 : xCondition->setSourcePosition( aFirstCell );
1075 : }
1076 0 : catch(const Exception&)
1077 : {
1078 : }
1079 :
1080 : // convert validation type to API enum
1081 0 : ValidationType eType = ValidationType_ANY;
1082 0 : switch( aIt->mnType )
1083 : {
1084 0 : case XML_custom: eType = ValidationType_CUSTOM; break;
1085 0 : case XML_date: eType = ValidationType_DATE; break;
1086 0 : case XML_decimal: eType = ValidationType_DECIMAL; break;
1087 0 : case XML_list: eType = ValidationType_LIST; break;
1088 0 : case XML_none: eType = ValidationType_ANY; break;
1089 0 : case XML_textLength: eType = ValidationType_TEXT_LEN; break;
1090 0 : case XML_time: eType = ValidationType_TIME; break;
1091 0 : case XML_whole: eType = ValidationType_WHOLE; break;
1092 : default: OSL_FAIL( "WorksheetData::finalizeValidationRanges - unknown validation type" );
1093 : }
1094 0 : aValProps.setProperty( PROP_Type, eType );
1095 :
1096 : // convert error alert style to API enum
1097 0 : ValidationAlertStyle eAlertStyle = ValidationAlertStyle_STOP;
1098 0 : switch( aIt->mnErrorStyle )
1099 : {
1100 0 : case XML_information: eAlertStyle = ValidationAlertStyle_INFO; break;
1101 0 : case XML_stop: eAlertStyle = ValidationAlertStyle_STOP; break;
1102 0 : case XML_warning: eAlertStyle = ValidationAlertStyle_WARNING; break;
1103 : default: OSL_FAIL( "WorksheetData::finalizeValidationRanges - unknown error style" );
1104 : }
1105 0 : aValProps.setProperty( PROP_ErrorAlertStyle, eAlertStyle );
1106 :
1107 : // convert dropdown style to API visibility constants
1108 0 : sal_Int16 nVisibility = aIt->mbNoDropDown ? TableValidationVisibility::INVISIBLE : TableValidationVisibility::UNSORTED;
1109 0 : aValProps.setProperty( PROP_ShowList, nVisibility );
1110 :
1111 : // messages
1112 0 : aValProps.setProperty( PROP_ShowInputMessage, aIt->mbShowInputMsg );
1113 0 : aValProps.setProperty( PROP_InputTitle, aIt->maInputTitle );
1114 0 : aValProps.setProperty( PROP_InputMessage, aIt->maInputMessage );
1115 0 : aValProps.setProperty( PROP_ShowErrorMessage, aIt->mbShowErrorMsg );
1116 0 : aValProps.setProperty( PROP_ErrorTitle, aIt->maErrorTitle );
1117 0 : aValProps.setProperty( PROP_ErrorMessage, aIt->maErrorMessage );
1118 :
1119 : // allow blank cells
1120 0 : aValProps.setProperty( PROP_IgnoreBlankCells, aIt->mbAllowBlank );
1121 :
1122 : try
1123 : {
1124 : // condition operator
1125 0 : Reference< XSheetCondition2 > xSheetCond( xValidation, UNO_QUERY_THROW );
1126 0 : xSheetCond->setConditionOperator( CondFormatBuffer::convertToApiOperator( aIt->mnOperator ) );
1127 :
1128 : // condition formulas
1129 0 : Reference< XMultiFormulaTokens > xTokens( xValidation, UNO_QUERY_THROW );
1130 0 : xTokens->setTokens( 0, aIt->maTokens1 );
1131 0 : xTokens->setTokens( 1, aIt->maTokens2 );
1132 : }
1133 0 : catch( Exception& )
1134 : {
1135 : }
1136 :
1137 : // write back validation settings to cell range(s)
1138 0 : aPropSet.setProperty( PROP_Validation, xValidation );
1139 : }
1140 0 : }
1141 85 : }
1142 :
1143 85 : void WorksheetGlobals::convertColumns()
1144 : {
1145 85 : sal_Int32 nNextCol = 0;
1146 85 : sal_Int32 nMaxCol = mrMaxApiPos.Column;
1147 : // stores first grouped column index for each level
1148 85 : OutlineLevelVec aColLevels;
1149 :
1150 174 : for( ColumnModelRangeMap::iterator aIt = maColModels.begin(), aEnd = maColModels.end(); aIt != aEnd; ++aIt )
1151 : {
1152 : // column indexes are stored 0-based in maColModels
1153 89 : ValueRange aColRange( ::std::max( aIt->first, nNextCol ), ::std::min( aIt->second.second, nMaxCol ) );
1154 : // process gap between two column models, use default column model
1155 89 : if( nNextCol < aColRange.mnFirst )
1156 3 : convertColumns( aColLevels, ValueRange( nNextCol, aColRange.mnFirst - 1 ), maDefColModel );
1157 : // process the column model
1158 89 : convertColumns( aColLevels, aColRange, aIt->second.first );
1159 : // cache next column to be processed
1160 89 : nNextCol = aColRange.mnLast + 1;
1161 : }
1162 :
1163 : // remaining default columns to end of sheet
1164 85 : convertColumns( aColLevels, ValueRange( nNextCol, nMaxCol ), maDefColModel );
1165 : // close remaining column outlines spanning to end of sheet
1166 85 : convertOutlines( aColLevels, nMaxCol + 1, 0, false, false );
1167 85 : }
1168 :
1169 177 : void WorksheetGlobals::convertColumns( OutlineLevelVec& orColLevels,
1170 : const ValueRange& rColRange, const ColumnModel& rModel )
1171 : {
1172 : // column width: convert 'number of characters' to column width in 1/100 mm
1173 177 : sal_Int32 nWidth = getUnitConverter().scaleToMm100( rModel.mfWidth, UNIT_DIGIT );
1174 : // macro sheets have double width
1175 177 : if( meSheetType == SHEETTYPE_MACROSHEET )
1176 0 : nWidth *= 2;
1177 :
1178 177 : SCTAB nTab = getSheetIndex();
1179 177 : ScDocument& rDoc = getScDocument();
1180 177 : SCCOL nStartCol = rColRange.mnFirst;
1181 177 : SCCOL nEndCol = rColRange.mnLast;
1182 :
1183 177 : if( nWidth > 0 )
1184 : {
1185 87217 : for( SCCOL nCol = nStartCol; nCol <= nEndCol; ++nCol )
1186 : {
1187 87040 : rDoc.SetColWidthOnly( nCol, nTab, (sal_uInt16)sc::HMMToTwips( nWidth ) );
1188 : }
1189 : }
1190 :
1191 : // hidden columns: TODO: #108683# hide columns later?
1192 177 : if( rModel.mbHidden )
1193 : {
1194 0 : rDoc.SetColHidden( nStartCol, nEndCol, nTab, true );
1195 : }
1196 :
1197 : // outline settings for this column range
1198 177 : convertOutlines( orColLevels, rColRange.mnFirst, rModel.mnLevel, rModel.mbCollapsed, false );
1199 177 : }
1200 :
1201 85 : void WorksheetGlobals::convertRows()
1202 : {
1203 85 : sal_Int32 nNextRow = 0;
1204 85 : sal_Int32 nMaxRow = mrMaxApiPos.Row;
1205 : // stores first grouped row index for each level
1206 85 : OutlineLevelVec aRowLevels;
1207 :
1208 229 : for( RowModelRangeMap::iterator aIt = maRowModels.begin(), aEnd = maRowModels.end(); aIt != aEnd; ++aIt )
1209 : {
1210 : // row indexes are stored 0-based in maRowModels
1211 144 : ValueRange aRowRange( ::std::max( aIt->first, nNextRow ), ::std::min( aIt->second.second, nMaxRow ) );
1212 : // process gap between two row models, use default row model
1213 144 : if( nNextRow < aRowRange.mnFirst )
1214 57 : convertRows( aRowLevels, ValueRange( nNextRow, aRowRange.mnFirst - 1 ), maDefRowModel );
1215 : // process the row model
1216 144 : convertRows( aRowLevels, aRowRange, aIt->second.first, maDefRowModel.mfHeight );
1217 : // cache next row to be processed
1218 144 : nNextRow = aRowRange.mnLast + 1;
1219 : }
1220 :
1221 : // remaining default rows to end of sheet
1222 85 : convertRows( aRowLevels, ValueRange( nNextRow, nMaxRow ), maDefRowModel );
1223 : // close remaining row outlines spanning to end of sheet
1224 85 : convertOutlines( aRowLevels, nMaxRow + 1, 0, false, true );
1225 85 : }
1226 :
1227 286 : void WorksheetGlobals::convertRows( OutlineLevelVec& orRowLevels,
1228 : const ValueRange& rRowRange, const RowModel& rModel, double fDefHeight )
1229 : {
1230 : // row height: convert points to row height in 1/100 mm
1231 286 : double fHeight = (rModel.mfHeight >= 0.0) ? rModel.mfHeight : fDefHeight;
1232 286 : sal_Int32 nHeight = getUnitConverter().scaleToMm100( fHeight, UNIT_POINT );
1233 286 : SCROW nStartRow = rRowRange.mnFirst;
1234 286 : SCROW nEndRow = rRowRange.mnLast;
1235 286 : SCTAB nTab = getSheetIndex();
1236 286 : if( nHeight > 0 )
1237 : {
1238 : /* always import the row height, ensures better layout */
1239 270 : ScDocument& rDoc = getScDocument();
1240 270 : rDoc.SetRowHeightOnly( nStartRow, nEndRow, nTab, (sal_uInt16)sc::HMMToTwips(nHeight) );
1241 270 : if(rModel.mbCustomHeight)
1242 33 : rDoc.SetManualHeight( nStartRow, nEndRow, nTab, true );
1243 : }
1244 :
1245 : // hidden rows: TODO: #108683# hide rows later?
1246 286 : if( rModel.mbHidden )
1247 : {
1248 2 : ScDocument& rDoc = getScDocument();
1249 2 : rDoc.SetRowHidden( nStartRow, nEndRow, nTab, true );
1250 : }
1251 :
1252 : // outline settings for this row range
1253 286 : convertOutlines( orRowLevels, rRowRange.mnFirst, rModel.mnLevel, rModel.mbCollapsed, true );
1254 286 : }
1255 :
1256 633 : void WorksheetGlobals::convertOutlines( OutlineLevelVec& orLevels,
1257 : sal_Int32 nColRow, sal_Int32 nLevel, bool bCollapsed, bool bRows )
1258 : {
1259 : /* It is ensured from caller functions, that this function is called
1260 : without any gaps between the processed column or row ranges. */
1261 :
1262 : OSL_ENSURE( nLevel >= 0, "WorksheetGlobals::convertOutlines - negative outline level" );
1263 633 : nLevel = ::std::max< sal_Int32 >( nLevel, 0 );
1264 :
1265 633 : sal_Int32 nSize = orLevels.size();
1266 633 : if( nSize < nLevel )
1267 : {
1268 : // Outline level increased. Push the begin column position.
1269 0 : for( sal_Int32 nIndex = nSize; nIndex < nLevel; ++nIndex )
1270 0 : orLevels.push_back( nColRow );
1271 : }
1272 633 : else if( nLevel < nSize )
1273 : {
1274 : // Outline level decreased. Pop them all out.
1275 0 : for( sal_Int32 nIndex = nLevel; nIndex < nSize; ++nIndex )
1276 : {
1277 0 : sal_Int32 nFirstInLevel = orLevels.back();
1278 0 : orLevels.pop_back();
1279 0 : groupColumnsOrRows( nFirstInLevel, nColRow - 1, bCollapsed, bRows );
1280 0 : bCollapsed = false; // collapse only once
1281 : }
1282 : }
1283 633 : }
1284 :
1285 0 : void WorksheetGlobals::groupColumnsOrRows( sal_Int32 nFirstColRow, sal_Int32 nLastColRow, bool bCollapse, bool bRows )
1286 : {
1287 : try
1288 : {
1289 0 : Reference< XSheetOutline > xOutline( mxSheet, UNO_QUERY_THROW );
1290 0 : if( bRows )
1291 : {
1292 0 : CellRangeAddress aRange( getSheetIndex(), 0, nFirstColRow, 0, nLastColRow );
1293 0 : xOutline->group( aRange, TableOrientation_ROWS );
1294 0 : if( bCollapse )
1295 0 : xOutline->hideDetail( aRange );
1296 : }
1297 : else
1298 : {
1299 0 : CellRangeAddress aRange( getSheetIndex(), nFirstColRow, 0, nLastColRow, 0 );
1300 0 : xOutline->group( aRange, TableOrientation_COLUMNS );
1301 0 : if( bCollapse )
1302 0 : xOutline->hideDetail( aRange );
1303 0 : }
1304 : }
1305 0 : catch( Exception& )
1306 : {
1307 : }
1308 0 : }
1309 :
1310 85 : void WorksheetGlobals::finalizeDrawings()
1311 : {
1312 : // calculate the current drawing page size (after rows/columns are imported)
1313 85 : PropertySet aRangeProp( getCellRange( CellRangeAddress( getSheetIndex(), 0, 0, mrMaxApiPos.Column, mrMaxApiPos.Row ) ) );
1314 85 : aRangeProp.getProperty( maDrawPageSize, PROP_Size );
1315 :
1316 85 : switch( getFilterType() )
1317 : {
1318 : case FILTER_OOXML:
1319 : // import DML and VML
1320 85 : if( !maDrawingPath.isEmpty() )
1321 16 : importOoxFragment( new DrawingFragment( *this, maDrawingPath ) );
1322 85 : if( !maVmlDrawingPath.isEmpty() )
1323 3 : importOoxFragment( new VmlDrawingFragment( *this, maVmlDrawingPath ) );
1324 85 : break;
1325 :
1326 : case FILTER_BIFF:
1327 : // convert BIFF3-BIFF5 drawing objects, or import and convert DFF stream
1328 0 : getBiffDrawing().finalizeImport();
1329 0 : break;
1330 :
1331 : case FILTER_UNKNOWN:
1332 0 : break;
1333 : }
1334 :
1335 : // comments (after callout shapes have been imported from VML/DFF)
1336 85 : maComments.finalizeImport();
1337 :
1338 : /* Extend used area of the sheet by cells covered with drawing objects.
1339 : Needed if the imported document is inserted as "OLE object from file"
1340 : and thus does not provide an OLE size property by itself. */
1341 85 : if( (maShapeBoundingBox.Width > 0) || (maShapeBoundingBox.Height > 0) )
1342 16 : extendUsedArea( getCellRangeFromRectangle( maShapeBoundingBox ) );
1343 :
1344 : // if no used area is set, default to A1
1345 85 : if( maUsedArea.StartColumn > maUsedArea.EndColumn )
1346 25 : maUsedArea.StartColumn = maUsedArea.EndColumn = 0;
1347 85 : if( maUsedArea.StartRow > maUsedArea.EndRow )
1348 25 : maUsedArea.StartRow = maUsedArea.EndRow = 0;
1349 :
1350 : /* Register the used area of this sheet in global view settings. The
1351 : global view settings will set the visible area if this document is an
1352 : embedded OLE object. */
1353 85 : getViewSettings().setSheetUsedArea( maUsedArea );
1354 :
1355 : /* #i103686# Set right-to-left sheet layout. Must be done after all
1356 : drawing shapes to simplify calculation of shape coordinates. */
1357 85 : if( maSheetViewSett.isSheetRightToLeft() )
1358 : {
1359 0 : PropertySet aPropSet( mxSheet );
1360 0 : aPropSet.setProperty( PROP_TableLayout, WritingMode2::RL_TB );
1361 85 : }
1362 85 : }
1363 :
1364 :
1365 784 : WorksheetHelper::WorksheetHelper( WorksheetGlobals& rSheetGlob ) :
1366 : WorkbookHelper( rSheetGlob ),
1367 784 : mrSheetGlob( rSheetGlob )
1368 : {
1369 784 : }
1370 :
1371 85 : /*static*/ WorksheetGlobalsRef WorksheetHelper::constructGlobals( const WorkbookHelper& rHelper,
1372 : const ISegmentProgressBarRef& rxProgressBar, WorksheetType eSheetType, sal_Int16 nSheet )
1373 : {
1374 85 : WorksheetGlobalsRef xSheetGlob( new WorksheetGlobals( rHelper, rxProgressBar, eSheetType, nSheet ) );
1375 85 : if( !xSheetGlob->isValidSheet() )
1376 0 : xSheetGlob.reset();
1377 85 : return xSheetGlob;
1378 : }
1379 :
1380 0 : /* static */ IWorksheetProgress *WorksheetHelper::getWorksheetInterface( const WorksheetGlobalsRef &xRef )
1381 : {
1382 0 : return static_cast< IWorksheetProgress *>( xRef.get() );
1383 : }
1384 :
1385 265 : WorksheetType WorksheetHelper::getSheetType() const
1386 : {
1387 265 : return mrSheetGlob.getSheetType();
1388 : }
1389 :
1390 995 : sal_Int16 WorksheetHelper::getSheetIndex() const
1391 : {
1392 995 : return mrSheetGlob.getSheetIndex();
1393 : }
1394 :
1395 215 : const Reference< XSpreadsheet >& WorksheetHelper::getSheet() const
1396 : {
1397 215 : return mrSheetGlob.getSheet();
1398 : }
1399 :
1400 1 : Reference< XCell > WorksheetHelper::getCell( const CellAddress& rAddress ) const
1401 : {
1402 1 : return mrSheetGlob.getCell( rAddress );
1403 : }
1404 :
1405 0 : Reference< XCellRange > WorksheetHelper::getCellRange( const CellRangeAddress& rRange ) const
1406 : {
1407 0 : return mrSheetGlob.getCellRange( rRange );
1408 : }
1409 :
1410 101 : Reference< XDrawPage > WorksheetHelper::getDrawPage() const
1411 : {
1412 101 : return mrSheetGlob.getDrawPage();
1413 : }
1414 :
1415 32 : awt::Point WorksheetHelper::getCellPosition( sal_Int32 nCol, sal_Int32 nRow ) const
1416 : {
1417 32 : return mrSheetGlob.getCellPosition( nCol, nRow );
1418 : }
1419 :
1420 0 : awt::Size WorksheetHelper::getCellSize( sal_Int32 nCol, sal_Int32 nRow ) const
1421 : {
1422 0 : return mrSheetGlob.getCellSize( nCol, nRow );
1423 : }
1424 :
1425 16 : awt::Size WorksheetHelper::getDrawPageSize() const
1426 : {
1427 16 : return mrSheetGlob.getDrawPageSize();
1428 : }
1429 :
1430 87 : SheetDataBuffer& WorksheetHelper::getSheetData() const
1431 : {
1432 87 : return mrSheetGlob.getSheetData();
1433 : }
1434 :
1435 72 : CondFormatBuffer& WorksheetHelper::getCondFormats() const
1436 : {
1437 72 : return mrSheetGlob.getCondFormats();
1438 : }
1439 :
1440 1 : CommentsBuffer& WorksheetHelper::getComments() const
1441 : {
1442 1 : return mrSheetGlob.getComments();
1443 : }
1444 :
1445 1 : AutoFilterBuffer& WorksheetHelper::getAutoFilters() const
1446 : {
1447 1 : return mrSheetGlob.getAutoFilters();
1448 : }
1449 :
1450 0 : QueryTableBuffer& WorksheetHelper::getQueryTables() const
1451 : {
1452 0 : return mrSheetGlob.getQueryTables();
1453 : }
1454 :
1455 101 : WorksheetSettings& WorksheetHelper::getWorksheetSettings() const
1456 : {
1457 101 : return mrSheetGlob.getWorksheetSettings();
1458 : }
1459 :
1460 334 : PageSettings& WorksheetHelper::getPageSettings() const
1461 : {
1462 334 : return mrSheetGlob.getPageSettings();
1463 : }
1464 :
1465 152 : SheetViewSettings& WorksheetHelper::getSheetViewSettings() const
1466 : {
1467 152 : return mrSheetGlob.getSheetViewSettings();
1468 : }
1469 :
1470 7 : VmlDrawing& WorksheetHelper::getVmlDrawing() const
1471 : {
1472 7 : return mrSheetGlob.getVmlDrawing();
1473 : }
1474 :
1475 15 : ExtLst& WorksheetHelper::getExtLst() const
1476 : {
1477 15 : return mrSheetGlob.getExtLst();
1478 : }
1479 :
1480 0 : void WorksheetHelper::setPageBreak( const PageBreakModel& rModel, bool bRowBreak )
1481 : {
1482 0 : mrSheetGlob.setPageBreak( rModel, bRowBreak );
1483 0 : }
1484 :
1485 3 : void WorksheetHelper::setHyperlink( const HyperlinkModel& rModel )
1486 : {
1487 3 : mrSheetGlob.setHyperlink( rModel );
1488 3 : }
1489 :
1490 0 : void WorksheetHelper::setValidation( const ValidationModel& rModel )
1491 : {
1492 0 : mrSheetGlob.setValidation( rModel );
1493 0 : }
1494 :
1495 16 : void WorksheetHelper::setDrawingPath( const OUString& rDrawingPath )
1496 : {
1497 16 : mrSheetGlob.setDrawingPath( rDrawingPath );
1498 16 : }
1499 :
1500 3 : void WorksheetHelper::setVmlDrawingPath( const OUString& rVmlDrawingPath )
1501 : {
1502 3 : mrSheetGlob.setVmlDrawingPath( rVmlDrawingPath );
1503 3 : }
1504 :
1505 1977 : void WorksheetHelper::extendUsedArea( const CellAddress& rAddress )
1506 : {
1507 1977 : mrSheetGlob.extendUsedArea( rAddress );
1508 1977 : }
1509 :
1510 59 : void WorksheetHelper::extendUsedArea( const CellRangeAddress& rRange )
1511 : {
1512 59 : mrSheetGlob.extendUsedArea( rRange );
1513 59 : }
1514 :
1515 16 : void WorksheetHelper::extendShapeBoundingBox( const awt::Rectangle& rShapeRect )
1516 : {
1517 16 : mrSheetGlob.extendShapeBoundingBox( rShapeRect );
1518 16 : }
1519 :
1520 73 : void WorksheetHelper::setBaseColumnWidth( sal_Int32 nWidth )
1521 : {
1522 73 : mrSheetGlob.setBaseColumnWidth( nWidth );
1523 73 : }
1524 :
1525 73 : void WorksheetHelper::setDefaultColumnWidth( double fWidth )
1526 : {
1527 73 : mrSheetGlob.setDefaultColumnWidth( fWidth );
1528 73 : }
1529 :
1530 89 : void WorksheetHelper::setColumnModel( const ColumnModel& rModel )
1531 : {
1532 89 : mrSheetGlob.setColumnModel( rModel );
1533 89 : }
1534 :
1535 73 : void WorksheetHelper::setDefaultRowSettings( double fHeight, bool bCustomHeight, bool bHidden, bool bThickTop, bool bThickBottom )
1536 : {
1537 73 : mrSheetGlob.setDefaultRowSettings( fHeight, bCustomHeight, bHidden, bThickTop, bThickBottom );
1538 73 : }
1539 :
1540 540 : void WorksheetHelper::setRowModel( const RowModel& rModel )
1541 : {
1542 540 : mrSheetGlob.setRowModel( rModel );
1543 540 : }
1544 :
1545 1154 : void WorksheetHelper::putValue( const CellAddress& rAddress, double fValue )
1546 : {
1547 1154 : ScAddress aAddress;
1548 1154 : ScUnoConversion::FillScAddress( aAddress, rAddress );
1549 1154 : getDocImport().setNumericCell(aAddress, fValue);
1550 1154 : }
1551 :
1552 167 : void WorksheetHelper::setCellFormulaValue(
1553 : const css::table::CellAddress& rAddress, const OUString& rValueStr, sal_Int32 nCellType )
1554 : {
1555 167 : getFormulaBuffer().setCellFormulaValue(rAddress, rValueStr, nCellType);
1556 167 : }
1557 :
1558 274 : void WorksheetHelper::putString( const CellAddress& rAddress, const OUString& rText )
1559 : {
1560 274 : ScAddress aAddress;
1561 274 : ScUnoConversion::FillScAddress( aAddress, rAddress );
1562 274 : if ( !rText.isEmpty() )
1563 271 : getDocImport().setStringCell(aAddress, rText);
1564 274 : }
1565 :
1566 1 : void WorksheetHelper::putRichString( const CellAddress& rAddress, const RichString& rString, const Font* pFirstPortionFont )
1567 : {
1568 1 : ScEditEngineDefaulter& rEE = getEditEngine();
1569 :
1570 : // The cell will own the text object instance returned from convert().
1571 1 : ScAddress aAddress;
1572 1 : ScUnoConversion::FillScAddress( aAddress, rAddress );
1573 1 : getDocImport().setEditCell(aAddress, rString.convert(rEE, pFirstPortionFont));
1574 1 : }
1575 :
1576 0 : void WorksheetHelper::putFormulaTokens( const CellAddress& rAddress, const ApiTokenSequence& rTokens )
1577 : {
1578 0 : ScDocumentImport& rDoc = getDocImport();
1579 0 : ScTokenArray aTokenArray;
1580 0 : ScAddress aCellPos;
1581 0 : ScUnoConversion::FillScAddress( aCellPos, rAddress );
1582 0 : ScTokenConversion::ConvertToTokenArray(rDoc.getDoc(), aTokenArray, rTokens);
1583 0 : rDoc.setFormulaCell(aCellPos, new ScTokenArray(aTokenArray));
1584 0 : }
1585 :
1586 85 : void WorksheetHelper::initializeWorksheetImport()
1587 : {
1588 85 : mrSheetGlob.initializeWorksheetImport();
1589 85 : }
1590 :
1591 85 : void WorksheetHelper::finalizeWorksheetImport()
1592 : {
1593 85 : mrSheetGlob.finalizeWorksheetImport();
1594 85 : }
1595 :
1596 85 : void WorksheetHelper::finalizeDrawingImport()
1597 : {
1598 85 : mrSheetGlob.finalizeDrawingImport();
1599 85 : }
1600 :
1601 167 : void WorksheetHelper::setCellFormula( const ::com::sun::star::table::CellAddress& rTokenAddress, const OUString& rTokenStr )
1602 : {
1603 167 : getFormulaBuffer().setCellFormula( rTokenAddress, rTokenStr );
1604 167 : }
1605 :
1606 107 : void WorksheetHelper::setCellFormula(
1607 : const ::com::sun::star::table::CellAddress& rAddr, sal_Int32 nSharedId,
1608 : const OUString& rCellValue, sal_Int32 nValueType )
1609 : {
1610 107 : getFormulaBuffer().setCellFormula(rAddr, nSharedId, rCellValue, nValueType);
1611 107 : }
1612 :
1613 0 : void WorksheetHelper::setCellArrayFormula( const ::com::sun::star::table::CellRangeAddress& rRangeAddress, const ::com::sun::star::table::CellAddress& rTokenAddress, const OUString& rTokenStr )
1614 : {
1615 0 : getFormulaBuffer().setCellArrayFormula( rRangeAddress, rTokenAddress, rTokenStr );
1616 0 : }
1617 :
1618 6 : void WorksheetHelper::createSharedFormulaMapEntry(
1619 : const table::CellAddress& rAddress, const table::CellRangeAddress& rRange, sal_Int32 nSharedId, const OUString& rTokens )
1620 : {
1621 6 : getFormulaBuffer().createSharedFormulaMapEntry(rAddress, rRange, nSharedId, rTokens);
1622 6 : }
1623 :
1624 :
1625 : } // namespace xls
1626 18 : } // namespace oox
1627 :
1628 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|