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