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