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