1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: viewsettings.cxx,v $
10 * $Revision: 1.5.20.6 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include "oox/xls/viewsettings.hxx"
32 #include <com/sun/star/beans/PropertyValue.hpp>
33 #include <com/sun/star/container/XNameContainer.hpp>
34 #include <com/sun/star/container/XIndexContainer.hpp>
35 #include <com/sun/star/document/XViewDataSupplier.hpp>
36 #include <com/sun/star/text/WritingMode2.hpp>
37 #include "properties.hxx"
38 #include "oox/helper/attributelist.hxx"
39 #include "oox/helper/containerhelper.hxx"
40 #include "oox/helper/propertymap.hxx"
41 #include "oox/helper/propertyset.hxx"
42 #include "oox/helper/recordinputstream.hxx"
43 #include "oox/core/filterbase.hxx"
44 #include "oox/xls/biffinputstream.hxx"
45 #include "oox/xls/unitconverter.hxx"
46 #include "oox/xls/workbooksettings.hxx"
47 #include "oox/xls/worksheetbuffer.hxx"
49 using ::rtl::OUString
;
50 using ::com::sun::star::uno::Any
;
51 using ::com::sun::star::uno::Reference
;
52 using ::com::sun::star::uno::Sequence
;
53 using ::com::sun::star::uno::Exception
;
54 using ::com::sun::star::uno::UNO_QUERY_THROW
;
55 using ::com::sun::star::container::XNameContainer
;
56 using ::com::sun::star::container::XIndexContainer
;
57 using ::com::sun::star::container::XIndexAccess
;
58 using ::com::sun::star::document::XViewDataSupplier
;
59 using ::com::sun::star::table::CellAddress
;
64 // ============================================================================
68 const sal_Int32 OOX_BOOKVIEW_TABBARRATIO_DEF
= 600; /// Default tabbar ratio.
69 const sal_Int32 OOX_SHEETVIEW_NORMALZOOM_DEF
= 100; /// Default zoom for normal view.
70 const sal_Int32 OOX_SHEETVIEW_SHEETLAYZOOM_DEF
= 60; /// Default zoom for pagebreak preview.
71 const sal_Int32 OOX_SHEETVIEW_PAGELAYZOOM_DEF
= 100; /// Default zoom for page layout view.
73 const sal_uInt8 OOBIN_PANE_FROZEN
= 0x01;
74 const sal_uInt8 OOBIN_PANE_FROZENNOSPLIT
= 0x02;
76 const sal_uInt16 OOBIN_SHEETVIEW_WINPROTECTED
= 0x0001;
77 const sal_uInt16 OOBIN_SHEETVIEW_SHOWFORMULAS
= 0x0002;
78 const sal_uInt16 OOBIN_SHEETVIEW_SHOWGRID
= 0x0004;
79 const sal_uInt16 OOBIN_SHEETVIEW_SHOWHEADINGS
= 0x0008;
80 const sal_uInt16 OOBIN_SHEETVIEW_SHOWZEROS
= 0x0010;
81 const sal_uInt16 OOBIN_SHEETVIEW_RIGHTTOLEFT
= 0x0020;
82 const sal_uInt16 OOBIN_SHEETVIEW_SELECTED
= 0x0040;
83 const sal_uInt16 OOBIN_SHEETVIEW_SHOWRULER
= 0x0080;
84 const sal_uInt16 OOBIN_SHEETVIEW_SHOWOUTLINE
= 0x0100;
85 const sal_uInt16 OOBIN_SHEETVIEW_DEFGRIDCOLOR
= 0x0200;
86 const sal_uInt16 OOBIN_SHEETVIEW_SHOWWHITESPACE
= 0x0400;
88 const sal_uInt16 OOBIN_CHARTSHEETVIEW_SELECTED
= 0x0001;
89 const sal_uInt16 OOBIN_CHARTSHEETVIEW_ZOOMTOFIT
= 0x0002;
91 const sal_uInt8 OOBIN_WBVIEW_HIDDEN
= 0x01;
92 const sal_uInt8 OOBIN_WBVIEW_MINIMIZED
= 0x02;
93 const sal_uInt8 OOBIN_WBVIEW_SHOWHORSCROLL
= 0x08;
94 const sal_uInt8 OOBIN_WBVIEW_SHOWVERSCROLL
= 0x10;
95 const sal_uInt8 OOBIN_WBVIEW_SHOWTABBAR
= 0x20;
96 const sal_uInt8 OOBIN_WBVIEW_AUTOFILTERGROUP
= 0x40;
98 const sal_uInt8 BIFF_PANE_BOTTOMRIGHT
= 0; /// Bottom-right pane.
99 const sal_uInt8 BIFF_PANE_TOPRIGHT
= 1; /// Right, or top-right pane.
100 const sal_uInt8 BIFF_PANE_BOTTOMLEFT
= 2; /// Bottom, or bottom-left pane.
101 const sal_uInt8 BIFF_PANE_TOPLEFT
= 3; /// Single, top, left, or top-left pane.
103 const sal_uInt16 BIFF_WINDOW1_HIDDEN
= 0x0001;
104 const sal_uInt16 BIFF_WINDOW1_MINIMIZED
= 0x0002;
105 const sal_uInt16 BIFF_WINDOW1_SHOWHORSCROLL
= 0x0008;
106 const sal_uInt16 BIFF_WINDOW1_SHOWVERSCROLL
= 0x0010;
107 const sal_uInt16 BIFF_WINDOW1_SHOWTABBAR
= 0x0020;
109 const sal_uInt16 BIFF_WINDOW2_SHOWFORMULAS
= 0x0001;
110 const sal_uInt16 BIFF_WINDOW2_SHOWGRID
= 0x0002;
111 const sal_uInt16 BIFF_WINDOW2_SHOWHEADINGS
= 0x0004;
112 const sal_uInt16 BIFF_WINDOW2_FROZEN
= 0x0008;
113 const sal_uInt16 BIFF_WINDOW2_SHOWZEROS
= 0x0010;
114 const sal_uInt16 BIFF_WINDOW2_DEFGRIDCOLOR
= 0x0020;
115 const sal_uInt16 BIFF_WINDOW2_RIGHTTOLEFT
= 0x0040;
116 const sal_uInt16 BIFF_WINDOW2_SHOWOUTLINE
= 0x0080;
117 const sal_uInt16 BIFF_WINDOW2_FROZENNOSPLIT
= 0x0100;
118 const sal_uInt16 BIFF_WINDOW2_SELECTED
= 0x0200;
119 const sal_uInt16 BIFF_WINDOW2_DISPLAYED
= 0x0400;
120 const sal_uInt16 BIFF_WINDOW2_PAGEBREAKMODE
= 0x0800;
122 // Attention: view settings in Calc do not use com.sun.star.view.DocumentZoomType!
123 const sal_Int16 API_ZOOMTYPE_PERCENT
= 0; /// Zoom value in percent.
125 const sal_Int32 API_ZOOMVALUE_MIN
= 20; /// Minimum zoom in Calc.
126 const sal_Int32 API_ZOOMVALUE_MAX
= 400; /// Maximum zoom in Calc.
128 // no predefined constants for split mode
129 const sal_Int16 API_SPLITMODE_NONE
= 0; /// No splits in window.
130 const sal_Int16 API_SPLITMODE_SPLIT
= 1; /// Window is split.
131 const sal_Int16 API_SPLITMODE_FREEZE
= 2; /// Window has frozen panes.
133 // no predefined constants for pane idetifiers
134 const sal_Int16 API_SPLITPANE_TOPLEFT
= 0; /// Top-left, or top pane.
135 const sal_Int16 API_SPLITPANE_TOPRIGHT
= 1; /// Top-right pane.
136 const sal_Int16 API_SPLITPANE_BOTTOMLEFT
= 2; /// Bottom-left, bottom, left, or single pane.
137 const sal_Int16 API_SPLITPANE_BOTTOMRIGHT
= 3; /// Bottom-right, or right pane.
139 // ----------------------------------------------------------------------------
141 /** Returns the OOXML pane identifier from the passed OOBIN or BIFF pane id. */
142 sal_Int32
lclGetOoxPaneId( sal_Int32 nBinPaneId
, sal_Int32 nDefaultPaneId
)
144 static const sal_Int32 spnPaneIds
[] = { XML_bottomRight
, XML_topRight
, XML_bottomLeft
, XML_topLeft
};
145 return STATIC_ARRAY_SELECT( spnPaneIds
, nBinPaneId
, nDefaultPaneId
);
150 // ============================================================================
152 PaneSelectionModel::PaneSelectionModel() :
157 // ----------------------------------------------------------------------------
159 SheetViewModel::SheetViewModel() :
160 mnWorkbookViewId( 0 ),
161 mnViewType( XML_normal
),
162 mnActivePaneId( XML_topLeft
),
163 mnPaneState( XML_split
),
168 mnSheetLayoutZoom( 0 ),
169 mnPageLayoutZoom( 0 ),
171 mbRightToLeft( false ),
172 mbDefGridColor( true ),
173 mbShowFormulas( false ),
175 mbShowHeadings( true ),
177 mbShowOutline( true ),
180 maGridColor
.setIndexed( OOX_COLOR_WINDOWTEXT
);
183 bool SheetViewModel::isPageBreakPreview() const
185 return mnViewType
== XML_pageBreakPreview
;
188 sal_Int32
SheetViewModel::getNormalZoom() const
190 const sal_Int32
& rnZoom
= isPageBreakPreview() ? mnNormalZoom
: mnCurrentZoom
;
191 sal_Int32 nZoom
= (rnZoom
> 0) ? rnZoom
: OOX_SHEETVIEW_NORMALZOOM_DEF
;
192 return getLimitedValue
< sal_Int32
>( nZoom
, API_ZOOMVALUE_MIN
, API_ZOOMVALUE_MAX
);
195 sal_Int32
SheetViewModel::getPageBreakZoom() const
197 const sal_Int32
& rnZoom
= isPageBreakPreview() ? mnCurrentZoom
: mnSheetLayoutZoom
;
198 sal_Int32 nZoom
= (rnZoom
> 0) ? rnZoom
: OOX_SHEETVIEW_SHEETLAYZOOM_DEF
;
199 return getLimitedValue
< sal_Int32
>( nZoom
, API_ZOOMVALUE_MIN
, API_ZOOMVALUE_MAX
);
202 const PaneSelectionModel
* SheetViewModel::getPaneSelection( sal_Int32 nPaneId
) const
204 return maPaneSelMap
.get( nPaneId
).get();
207 const PaneSelectionModel
* SheetViewModel::getActiveSelection() const
209 return getPaneSelection( mnActivePaneId
);
212 PaneSelectionModel
& SheetViewModel::createPaneSelection( sal_Int32 nPaneId
)
214 PaneSelectionModelMap::mapped_type
& rxPaneSel
= maPaneSelMap
[ nPaneId
];
216 rxPaneSel
.reset( new PaneSelectionModel
);
220 // ----------------------------------------------------------------------------
222 SheetViewSettings::SheetViewSettings( const WorksheetHelper
& rHelper
) :
223 WorksheetHelper( rHelper
)
227 void SheetViewSettings::importSheetView( const AttributeList
& rAttribs
)
229 SheetViewModel
& rModel
= *createSheetView();
230 rModel
.maGridColor
.setIndexed( rAttribs
.getInteger( XML_colorId
, OOX_COLOR_WINDOWTEXT
) );
231 rModel
.maFirstPos
= getAddressConverter().createValidCellAddress( rAttribs
.getString( XML_topLeftCell
, OUString() ), getSheetIndex(), false );
232 rModel
.mnWorkbookViewId
= rAttribs
.getToken( XML_workbookViewId
, 0 );
233 rModel
.mnViewType
= rAttribs
.getToken( XML_view
, XML_normal
);
234 rModel
.mnCurrentZoom
= rAttribs
.getInteger( XML_zoomScale
, 100 );
235 rModel
.mnNormalZoom
= rAttribs
.getInteger( XML_zoomScaleNormal
, 0 );
236 rModel
.mnSheetLayoutZoom
= rAttribs
.getInteger( XML_zoomScaleSheetLayoutView
, 0 );
237 rModel
.mnPageLayoutZoom
= rAttribs
.getInteger( XML_zoomScalePageLayoutView
, 0 );
238 rModel
.mbSelected
= rAttribs
.getBool( XML_tabSelected
, false );
239 rModel
.mbRightToLeft
= rAttribs
.getBool( XML_rightToLeft
, false );
240 rModel
.mbDefGridColor
= rAttribs
.getBool( XML_defaultGridColor
, true );
241 rModel
.mbShowFormulas
= rAttribs
.getBool( XML_showFormulas
, false );
242 rModel
.mbShowGrid
= rAttribs
.getBool( XML_showGridLines
, true );
243 rModel
.mbShowHeadings
= rAttribs
.getBool( XML_showRowColHeaders
, true );
244 rModel
.mbShowZeros
= rAttribs
.getBool( XML_showZeros
, true );
245 rModel
.mbShowOutline
= rAttribs
.getBool( XML_showOutlineSymbols
, true );
248 void SheetViewSettings::importTabColor( const AttributeList
& rAttribs
)
250 SheetViewModel
& rModel
= maSheetViews
.empty() ? *createSheetView() : *maSheetViews
.back();
251 rModel
.maTabColor
.importColor( rAttribs
);
254 void SheetViewSettings::importPane( const AttributeList
& rAttribs
)
256 OSL_ENSURE( !maSheetViews
.empty(), "SheetViewSettings::importPane - missing sheet view model" );
257 if( !maSheetViews
.empty() )
259 SheetViewModel
& rModel
= *maSheetViews
.back();
260 rModel
.maSecondPos
= getAddressConverter().createValidCellAddress( rAttribs
.getString( XML_topLeftCell
, OUString() ), getSheetIndex(), false );
261 rModel
.mnActivePaneId
= rAttribs
.getToken( XML_activePane
, XML_topLeft
);
262 rModel
.mnPaneState
= rAttribs
.getToken( XML_state
, XML_split
);
263 rModel
.mfSplitX
= rAttribs
.getDouble( XML_xSplit
, 0.0 );
264 rModel
.mfSplitY
= rAttribs
.getDouble( XML_ySplit
, 0.0 );
268 void SheetViewSettings::importSelection( const AttributeList
& rAttribs
)
270 OSL_ENSURE( !maSheetViews
.empty(), "SheetViewSettings::importSelection - missing sheet view model" );
271 if( !maSheetViews
.empty() )
273 // pane this selection belongs to
274 sal_Int32 nPaneId
= rAttribs
.getToken( XML_pane
, XML_topLeft
);
275 PaneSelectionModel
& rSelData
= maSheetViews
.back()->createPaneSelection( nPaneId
);
277 rSelData
.maActiveCell
= getAddressConverter().createValidCellAddress( rAttribs
.getString( XML_activeCell
, OUString() ), getSheetIndex(), false );
278 rSelData
.mnActiveCellId
= rAttribs
.getInteger( XML_activeCellId
, 0 );
280 rSelData
.maSelection
.clear();
281 getAddressConverter().convertToCellRangeList( rSelData
.maSelection
, rAttribs
.getString( XML_sqref
, OUString() ), getSheetIndex(), false );
285 void SheetViewSettings::importChartSheetView( const AttributeList
& rAttribs
)
287 SheetViewModel
& rModel
= *createSheetView();
288 rModel
.mnWorkbookViewId
= rAttribs
.getToken( XML_workbookViewId
, 0 );
289 rModel
.mnCurrentZoom
= rAttribs
.getInteger( XML_zoomScale
, 100 );
290 rModel
.mbSelected
= rAttribs
.getBool( XML_tabSelected
, false );
291 rModel
.mbZoomToFit
= rAttribs
.getBool( XML_zoomToFit
, false );
294 void SheetViewSettings::importSheetView( RecordInputStream
& rStrm
)
296 SheetViewModel
& rModel
= *createSheetView();
299 BinAddress aFirstPos
;
300 rStrm
>> nFlags
>> nViewType
>> aFirstPos
;
301 rModel
.maGridColor
.importColorId( rStrm
);
302 rModel
.mnCurrentZoom
= rStrm
.readuInt16();
303 rModel
.mnNormalZoom
= rStrm
.readuInt16();
304 rModel
.mnSheetLayoutZoom
= rStrm
.readuInt16();
305 rModel
.mnPageLayoutZoom
= rStrm
.readuInt16();
306 rStrm
>> rModel
.mnWorkbookViewId
;
308 rModel
.maFirstPos
= getAddressConverter().createValidCellAddress( aFirstPos
, getSheetIndex(), false );
309 static const sal_Int32 spnViewTypes
[] = { XML_normal
, XML_pageBreakPreview
, XML_pageLayout
};
310 rModel
.mnViewType
= STATIC_ARRAY_SELECT( spnViewTypes
, nViewType
, XML_normal
);
311 rModel
.mbSelected
= getFlag( nFlags
, OOBIN_SHEETVIEW_SELECTED
);
312 rModel
.mbRightToLeft
= getFlag( nFlags
, OOBIN_SHEETVIEW_RIGHTTOLEFT
);
313 rModel
.mbDefGridColor
= getFlag( nFlags
, OOBIN_SHEETVIEW_DEFGRIDCOLOR
);
314 rModel
.mbShowFormulas
= getFlag( nFlags
, OOBIN_SHEETVIEW_SHOWFORMULAS
);
315 rModel
.mbShowGrid
= getFlag( nFlags
, OOBIN_SHEETVIEW_SHOWGRID
);
316 rModel
.mbShowHeadings
= getFlag( nFlags
, OOBIN_SHEETVIEW_SHOWHEADINGS
);
317 rModel
.mbShowZeros
= getFlag( nFlags
, OOBIN_SHEETVIEW_SHOWZEROS
);
318 rModel
.mbShowOutline
= getFlag( nFlags
, OOBIN_SHEETVIEW_SHOWOUTLINE
);
321 void SheetViewSettings::importPane( RecordInputStream
& rStrm
)
323 OSL_ENSURE( !maSheetViews
.empty(), "SheetViewSettings::importPane - missing sheet view model" );
324 if( !maSheetViews
.empty() )
326 SheetViewModel
& rModel
= *maSheetViews
.back();
328 BinAddress aSecondPos
;
329 sal_Int32 nActivePaneId
;
331 rStrm
>> rModel
.mfSplitX
>> rModel
.mfSplitY
>> aSecondPos
>> nActivePaneId
>> nFlags
;
333 rModel
.maSecondPos
= getAddressConverter().createValidCellAddress( aSecondPos
, getSheetIndex(), false );
334 rModel
.mnActivePaneId
= lclGetOoxPaneId( nActivePaneId
, XML_topLeft
);
335 rModel
.mnPaneState
= getFlagValue( nFlags
, OOBIN_PANE_FROZEN
, getFlagValue( nFlags
, OOBIN_PANE_FROZENNOSPLIT
, XML_frozen
, XML_frozenSplit
), XML_split
);
339 void SheetViewSettings::importSelection( RecordInputStream
& rStrm
)
341 OSL_ENSURE( !maSheetViews
.empty(), "SheetViewSettings::importSelection - missing sheet view model" );
342 if( !maSheetViews
.empty() )
344 // pane this selection belongs to
345 sal_Int32 nPaneId
= rStrm
.readInt32();
346 PaneSelectionModel
& rPaneSel
= maSheetViews
.back()->createPaneSelection( lclGetOoxPaneId( nPaneId
, -1 ) );
348 BinAddress aActiveCell
;
349 rStrm
>> aActiveCell
>> rPaneSel
.mnActiveCellId
;
350 rPaneSel
.maActiveCell
= getAddressConverter().createValidCellAddress( aActiveCell
, getSheetIndex(), false );
352 BinRangeList aSelection
;
354 rPaneSel
.maSelection
.clear();
355 getAddressConverter().convertToCellRangeList( rPaneSel
.maSelection
, aSelection
, getSheetIndex(), false );
359 void SheetViewSettings::importChartSheetView( RecordInputStream
& rStrm
)
361 SheetViewModel
& rModel
= *createSheetView();
363 rStrm
>> nFlags
>> rModel
.mnCurrentZoom
>> rModel
.mnWorkbookViewId
;
365 rModel
.mbSelected
= getFlag( nFlags
, OOBIN_CHARTSHEETVIEW_SELECTED
);
366 rModel
.mbZoomToFit
= getFlag( nFlags
, OOBIN_CHARTSHEETVIEW_ZOOMTOFIT
);
369 void SheetViewSettings::importWindow2( BiffInputStream
& rStrm
)
371 OSL_ENSURE( maSheetViews
.empty(), "SheetViewSettings::importWindow2 - multiple WINDOW2 records" );
372 SheetViewModel
& rModel
= *createSheetView();
373 if( getBiff() == BIFF2
)
375 rModel
.mbShowFormulas
= rStrm
.readuInt8() != 0;
376 rModel
.mbShowGrid
= rStrm
.readuInt8() != 0;
377 rModel
.mbShowHeadings
= rStrm
.readuInt8() != 0;
378 rModel
.mnPaneState
= (rStrm
.readuInt8() == 0) ? XML_split
: XML_frozen
;
379 rModel
.mbShowZeros
= rStrm
.readuInt8() != 0;
380 BinAddress aFirstPos
;
382 rModel
.maFirstPos
= getAddressConverter().createValidCellAddress( aFirstPos
, getSheetIndex(), false );
383 rModel
.mbDefGridColor
= rStrm
.readuInt8() != 0;
384 rModel
.maGridColor
.importColorRgb( rStrm
);
389 BinAddress aFirstPos
;
390 rStrm
>> nFlags
>> aFirstPos
;
392 rModel
.maFirstPos
= getAddressConverter().createValidCellAddress( aFirstPos
, getSheetIndex(), false );
393 rModel
.mnPaneState
= getFlagValue( nFlags
, BIFF_WINDOW2_FROZEN
, getFlagValue( nFlags
, BIFF_WINDOW2_FROZENNOSPLIT
, XML_frozen
, XML_frozenSplit
), XML_split
);
394 rModel
.mbSelected
= getFlag( nFlags
, BIFF_WINDOW2_SELECTED
);
395 rModel
.mbRightToLeft
= getFlag( nFlags
, BIFF_WINDOW2_RIGHTTOLEFT
);
396 rModel
.mbDefGridColor
= getFlag( nFlags
, BIFF_WINDOW2_DEFGRIDCOLOR
);
397 rModel
.mbShowFormulas
= getFlag( nFlags
, BIFF_WINDOW2_SHOWFORMULAS
);
398 rModel
.mbShowGrid
= getFlag( nFlags
, BIFF_WINDOW2_SHOWGRID
);
399 rModel
.mbShowHeadings
= getFlag( nFlags
, BIFF_WINDOW2_SHOWHEADINGS
);
400 rModel
.mbShowZeros
= getFlag( nFlags
, BIFF_WINDOW2_SHOWZEROS
);
401 rModel
.mbShowOutline
= getFlag( nFlags
, BIFF_WINDOW2_SHOWOUTLINE
);
403 if( getBiff() == BIFF8
)
405 rModel
.mnViewType
= getFlagValue( nFlags
, BIFF_WINDOW2_PAGEBREAKMODE
, XML_pageBreakPreview
, XML_normal
);
407 rModel
.maGridColor
.importColorId( rStrm
);
408 // zoom data not included in chart sheets
409 if( (getSheetType() != SHEETTYPE_CHARTSHEET
) && (rStrm
.getRemaining() >= 6) )
412 sal_uInt16 nPageZoom
, nNormalZoom
;
413 rStrm
>> nPageZoom
>> nNormalZoom
;
414 rModel
.mnSheetLayoutZoom
= nPageZoom
;
415 rModel
.mnNormalZoom
= nNormalZoom
;
420 rModel
.maGridColor
.importColorRgb( rStrm
);
425 void SheetViewSettings::importPane( BiffInputStream
& rStrm
)
427 OSL_ENSURE( !maSheetViews
.empty(), "SheetViewSettings::importPane - missing leading WINDOW2 record" );
428 if( !maSheetViews
.empty() )
430 sal_uInt8 nActivePaneId
;
431 sal_uInt16 nSplitX
, nSplitY
;
432 BinAddress aSecondPos
;
433 rStrm
>> nSplitX
>> nSplitY
>> aSecondPos
>> nActivePaneId
;
435 SheetViewModel
& rModel
= *maSheetViews
.back();
436 rModel
.mfSplitX
= nSplitX
;
437 rModel
.mfSplitY
= nSplitY
;
438 rModel
.maSecondPos
= getAddressConverter().createValidCellAddress( aSecondPos
, getSheetIndex(), false );
439 rModel
.mnActivePaneId
= lclGetOoxPaneId( nActivePaneId
, XML_topLeft
);
443 void SheetViewSettings::importScl( BiffInputStream
& rStrm
)
445 OSL_ENSURE( !maSheetViews
.empty(), "SheetViewSettings::importScl - missing leading WINDOW2 record" );
446 if( !maSheetViews
.empty() )
448 sal_uInt16 nNum
, nDenom
;
449 rStrm
>> nNum
>> nDenom
;
450 OSL_ENSURE( nDenom
> 0, "SheetViewSettings::importScl - invalid denominator" );
452 maSheetViews
.back()->mnCurrentZoom
= getLimitedValue
< sal_Int32
, sal_uInt16
>( (nNum
* 100) / nDenom
, 10, 400 );
456 void SheetViewSettings::importSelection( BiffInputStream
& rStrm
)
458 OSL_ENSURE( !maSheetViews
.empty(), "SheetViewSettings::importPane - missing leading WINDOW2 record" );
459 if( !maSheetViews
.empty() )
461 // pane this selection belongs to
462 sal_uInt8 nPaneId
= rStrm
.readuInt8();
463 PaneSelectionModel
& rPaneSel
= maSheetViews
.back()->createPaneSelection( lclGetOoxPaneId( nPaneId
, -1 ) );
465 BinAddress aActiveCell
;
466 sal_uInt16 nActiveCellId
;
467 rStrm
>> aActiveCell
>> nActiveCellId
;
468 rPaneSel
.maActiveCell
= getAddressConverter().createValidCellAddress( aActiveCell
, getSheetIndex(), false );
469 rPaneSel
.mnActiveCellId
= nActiveCellId
;
471 rPaneSel
.maSelection
.clear();
472 BinRangeList aSelection
;
473 aSelection
.read( rStrm
, false );
474 getAddressConverter().convertToCellRangeList( rPaneSel
.maSelection
, aSelection
, getSheetIndex(), false );
478 void SheetViewSettings::finalizeImport()
480 // force creation of sheet view model to get the Excel defaults
481 SheetViewModelRef xModel
= maSheetViews
.empty() ? createSheetView() : maSheetViews
.front();
483 // #i59590# #158194# special handling for chart sheets (Excel ignores some settings in chart sheets)
484 if( getSheetType() == SHEETTYPE_CHARTSHEET
)
486 xModel
->maPaneSelMap
.clear();
487 xModel
->maFirstPos
= xModel
->maSecondPos
= CellAddress( getSheetIndex(), 0, 0 );
488 xModel
->mnViewType
= XML_normal
;
489 xModel
->mnActivePaneId
= XML_topLeft
;
490 xModel
->mnPaneState
= XML_split
;
491 xModel
->mfSplitX
= xModel
->mfSplitY
= 0.0;
492 xModel
->mbRightToLeft
= false;
493 xModel
->mbDefGridColor
= true;
494 xModel
->mbShowFormulas
= false;
495 xModel
->mbShowGrid
= true;
496 xModel
->mbShowHeadings
= true;
497 xModel
->mbShowZeros
= true;
498 xModel
->mbShowOutline
= true;
501 // mirrored sheet (this is not a view setting in Calc)
502 if( xModel
->mbRightToLeft
)
504 PropertySet
aPropSet( getSheet() );
505 aPropSet
.setProperty( PROP_TableLayout
, ::com::sun::star::text::WritingMode2::RL_TB
);
508 // sheet selected (active sheet must be selected)
509 bool bSelected
= xModel
->mbSelected
|| (getSheetIndex() == getViewSettings().getActiveSheetIndex());
511 // visible area and current cursor position (selection not supported via API)
512 CellAddress aFirstPos
= xModel
->maFirstPos
;
513 const PaneSelectionModel
* pPaneSel
= xModel
->getActiveSelection();
514 CellAddress aCursor
= pPaneSel
? pPaneSel
->maActiveCell
: aFirstPos
;
516 // freeze/split position default
517 sal_Int16 nHSplitMode
= API_SPLITMODE_NONE
;
518 sal_Int16 nVSplitMode
= API_SPLITMODE_NONE
;
519 sal_Int32 nHSplitPos
= 0;
520 sal_Int32 nVSplitPos
= 0;
521 // active pane default
522 sal_Int16 nActivePane
= API_SPLITPANE_BOTTOMLEFT
;
524 // freeze/split position
525 if( (xModel
->mnPaneState
== XML_frozen
) || (xModel
->mnPaneState
== XML_frozenSplit
) )
527 /* Frozen panes: handle split position as row/column positions.
528 #i35812# Excel uses number of visible rows/columns in the
529 frozen area (rows/columns scolled outside are not incuded),
530 Calc uses absolute position of first unfrozen row/column. */
531 const CellAddress
& rMaxApiPos
= getAddressConverter().getMaxApiAddress();
532 if( (xModel
->mfSplitX
>= 1.0) && (xModel
->maFirstPos
.Column
+ xModel
->mfSplitX
<= rMaxApiPos
.Column
) )
533 nHSplitPos
= static_cast< sal_Int32
>( xModel
->maFirstPos
.Column
+ xModel
->mfSplitX
);
534 nHSplitMode
= (nHSplitPos
> 0) ? API_SPLITMODE_FREEZE
: API_SPLITMODE_NONE
;
535 if( (xModel
->mfSplitY
>= 1.0) && (xModel
->maFirstPos
.Row
+ xModel
->mfSplitY
<= rMaxApiPos
.Row
) )
536 nVSplitPos
= static_cast< sal_Int32
>( xModel
->maFirstPos
.Row
+ xModel
->mfSplitY
);
537 nVSplitMode
= (nVSplitPos
> 0) ? API_SPLITMODE_FREEZE
: API_SPLITMODE_NONE
;
539 else if( xModel
->mnPaneState
== XML_split
)
541 // split window: view settings API uses twips...
542 nHSplitPos
= getLimitedValue
< sal_Int32
, double >( xModel
->mfSplitX
+ 0.5, 0, SAL_MAX_INT32
);
543 nHSplitMode
= (nHSplitPos
> 0) ? API_SPLITMODE_SPLIT
: API_SPLITMODE_NONE
;
544 nVSplitPos
= getLimitedValue
< sal_Int32
, double >( xModel
->mfSplitY
+ 0.5, 0, SAL_MAX_INT32
);
545 nVSplitMode
= (nVSplitPos
> 0) ? API_SPLITMODE_SPLIT
: API_SPLITMODE_NONE
;
549 switch( xModel
->mnActivePaneId
)
551 // no horizontal split -> always use left panes
552 // no vertical split -> always use *bottom* panes
554 nActivePane
= (nVSplitMode
== API_SPLITMODE_NONE
) ? API_SPLITPANE_BOTTOMLEFT
: API_SPLITPANE_TOPLEFT
;
557 nActivePane
= (nHSplitMode
== API_SPLITMODE_NONE
) ?
558 ((nVSplitMode
== API_SPLITMODE_NONE
) ? API_SPLITPANE_BOTTOMLEFT
: API_SPLITPANE_TOPLEFT
) :
559 ((nVSplitMode
== API_SPLITMODE_NONE
) ? API_SPLITPANE_BOTTOMRIGHT
: API_SPLITPANE_TOPRIGHT
);
562 nActivePane
= API_SPLITPANE_BOTTOMLEFT
;
564 case XML_bottomRight
:
565 nActivePane
= (nHSplitMode
== API_SPLITMODE_NONE
) ? API_SPLITPANE_BOTTOMLEFT
: API_SPLITPANE_BOTTOMRIGHT
;
569 // automatic grid color
570 if( xModel
->mbDefGridColor
)
571 xModel
->maGridColor
.setAuto();
573 // write the sheet view settings into the property sequence
574 PropertyMap aPropMap
;
575 aPropMap
[ PROP_TableSelected
] <<= bSelected
;
576 aPropMap
[ PROP_CursorPositionX
] <<= aCursor
.Column
;
577 aPropMap
[ PROP_CursorPositionY
] <<= aCursor
.Row
;
578 aPropMap
[ PROP_HorizontalSplitMode
] <<= nHSplitMode
;
579 aPropMap
[ PROP_VerticalSplitMode
] <<= nVSplitMode
;
580 aPropMap
[ PROP_HorizontalSplitPositionTwips
] <<= nHSplitPos
;
581 aPropMap
[ PROP_VerticalSplitPositionTwips
] <<= nVSplitPos
;
582 aPropMap
[ PROP_ActiveSplitRange
] <<= nActivePane
;
583 aPropMap
[ PROP_PositionLeft
] <<= aFirstPos
.Column
;
584 aPropMap
[ PROP_PositionTop
] <<= aFirstPos
.Row
;
585 aPropMap
[ PROP_PositionRight
] <<= xModel
->maSecondPos
.Column
;
586 aPropMap
[ PROP_PositionBottom
] <<= ((nVSplitPos
> 0) ? xModel
->maSecondPos
.Row
: xModel
->maFirstPos
.Row
);
587 aPropMap
[ PROP_ZoomType
] <<= API_ZOOMTYPE_PERCENT
;
588 aPropMap
[ PROP_ZoomValue
] <<= static_cast< sal_Int16
>( xModel
->getNormalZoom() );
589 aPropMap
[ PROP_PageViewZoomValue
] <<= static_cast< sal_Int16
>( xModel
->getPageBreakZoom() );
590 aPropMap
[ PROP_GridColor
] <<= xModel
->maGridColor
.getColor( *this );
591 aPropMap
[ PROP_ShowPageBreakPreview
] <<= xModel
->isPageBreakPreview();
592 aPropMap
[ PROP_ShowFormulas
] <<= xModel
->mbShowFormulas
;
593 aPropMap
[ PROP_ShowGrid
] <<= xModel
->mbShowGrid
;
594 aPropMap
[ PROP_HasColumnRowHeaders
] <<= xModel
->mbShowHeadings
;
595 aPropMap
[ PROP_ShowZeroValues
] <<= xModel
->mbShowZeros
;
596 aPropMap
[ PROP_IsOutlineSymbolsSet
] <<= xModel
->mbShowOutline
;
598 if (!xModel
->maTabColor
.isAuto())
599 aPropMap
[ PROP_TabColor
] <<= static_cast< sal_Int32
>(xModel
->maTabColor
.getColor(*this));
601 // store sheet view settings in global view settings object
602 getViewSettings().setSheetViewSettings( getSheetIndex(), xModel
, Any( aPropMap
.makePropertyValueSequence() ) );
605 // private --------------------------------------------------------------------
607 SheetViewModelRef
SheetViewSettings::createSheetView()
609 SheetViewModelRef
xModel( new SheetViewModel
);
610 maSheetViews
.push_back( xModel
);
614 // ============================================================================
616 WorkbookViewModel::WorkbookViewModel() :
622 mnFirstVisSheet( 0 ),
623 mnTabBarWidth( OOX_BOOKVIEW_TABBARRATIO_DEF
),
624 mnVisibility( XML_visible
),
625 mbShowTabBar( true ),
626 mbShowHorScroll( true ),
627 mbShowVerScroll( true ),
632 // ----------------------------------------------------------------------------
634 ViewSettings::ViewSettings( const WorkbookHelper
& rHelper
) :
635 WorkbookHelper( rHelper
)
639 void ViewSettings::importWorkbookView( const AttributeList
& rAttribs
)
641 WorkbookViewModel
& rModel
= createWorkbookView();
642 rModel
.mnWinX
= rAttribs
.getInteger( XML_xWindow
, 0 );
643 rModel
.mnWinY
= rAttribs
.getInteger( XML_yWindow
, 0 );
644 rModel
.mnWinWidth
= rAttribs
.getInteger( XML_windowWidth
, 0 );
645 rModel
.mnWinHeight
= rAttribs
.getInteger( XML_windowHeight
, 0 );
646 rModel
.mnActiveSheet
= rAttribs
.getInteger( XML_activeTab
, 0 );
647 rModel
.mnFirstVisSheet
= rAttribs
.getInteger( XML_firstSheet
, 0 );
648 rModel
.mnTabBarWidth
= rAttribs
.getInteger( XML_tabRatio
, 600 );
649 rModel
.mnVisibility
= rAttribs
.getToken( XML_visibility
, XML_visible
);
650 rModel
.mbShowTabBar
= rAttribs
.getBool( XML_showSheetTabs
, true );
651 rModel
.mbShowHorScroll
= rAttribs
.getBool( XML_showHorizontalScroll
, true );
652 rModel
.mbShowVerScroll
= rAttribs
.getBool( XML_showVerticalScroll
, true );
653 rModel
.mbMinimized
= rAttribs
.getBool( XML_minimized
, false );
656 void ViewSettings::importWorkbookView( RecordInputStream
& rStrm
)
658 WorkbookViewModel
& rModel
= createWorkbookView();
660 rStrm
>> rModel
.mnWinX
>> rModel
.mnWinY
>> rModel
.mnWinWidth
>> rModel
.mnWinHeight
>> rModel
.mnTabBarWidth
>> rModel
.mnFirstVisSheet
>> rModel
.mnActiveSheet
>> nFlags
;
661 rModel
.mnVisibility
= getFlagValue( nFlags
, OOBIN_WBVIEW_HIDDEN
, XML_hidden
, XML_visible
);
662 rModel
.mbShowTabBar
= getFlag( nFlags
, OOBIN_WBVIEW_SHOWTABBAR
);
663 rModel
.mbShowHorScroll
= getFlag( nFlags
, OOBIN_WBVIEW_SHOWHORSCROLL
);
664 rModel
.mbShowVerScroll
= getFlag( nFlags
, OOBIN_WBVIEW_SHOWVERSCROLL
);
665 rModel
.mbMinimized
= getFlag( nFlags
, OOBIN_WBVIEW_MINIMIZED
);
668 void ViewSettings::importWindow1( BiffInputStream
& rStrm
)
670 sal_uInt16 nWinX
, nWinY
, nWinWidth
, nWinHeight
;
671 rStrm
>> nWinX
>> nWinY
>> nWinWidth
>> nWinHeight
;
673 // WINDOW1 record occures in every sheet in BIFF4W
674 OSL_ENSURE( maBookViews
.empty() || ((getBiff() == BIFF4
) && isWorkbookFile()),
675 "ViewSettings::importWindow1 - multiple WINDOW1 records" );
676 WorkbookViewModel
& rModel
= createWorkbookView();
677 rModel
.mnWinX
= nWinX
;
678 rModel
.mnWinY
= nWinY
;
679 rModel
.mnWinWidth
= nWinWidth
;
680 rModel
.mnWinHeight
= nWinHeight
;
682 if( getBiff() <= BIFF4
)
686 rModel
.mnVisibility
= (nHidden
== 0) ? XML_visible
: XML_hidden
;
690 sal_uInt16 nFlags
, nActiveTab
, nFirstVisTab
, nSelectCnt
, nTabBarWidth
;
691 rStrm
>> nFlags
>> nActiveTab
>> nFirstVisTab
>> nSelectCnt
>> nTabBarWidth
;
693 rModel
.mnActiveSheet
= nActiveTab
;
694 rModel
.mnFirstVisSheet
= nFirstVisTab
;
695 rModel
.mnTabBarWidth
= nTabBarWidth
;
696 rModel
.mnVisibility
= getFlagValue( nFlags
, BIFF_WINDOW1_HIDDEN
, XML_hidden
, XML_visible
);
697 rModel
.mbMinimized
= getFlag( nFlags
, BIFF_WINDOW1_MINIMIZED
);
698 rModel
.mbShowHorScroll
= getFlag( nFlags
, BIFF_WINDOW1_SHOWHORSCROLL
);
699 rModel
.mbShowVerScroll
= getFlag( nFlags
, BIFF_WINDOW1_SHOWVERSCROLL
);
700 rModel
.mbShowTabBar
= getFlag( nFlags
, BIFF_WINDOW1_SHOWTABBAR
);
704 void ViewSettings::setSheetViewSettings( sal_Int32 nSheet
, const SheetViewModelRef
& rxSheetView
, const Any
& rProperties
)
706 maSheetViews
[ nSheet
] = rxSheetView
;
707 maSheetProps
[ nSheet
] = rProperties
;
710 void ViewSettings::finalizeImport()
712 const WorksheetBuffer
& rWorksheets
= getWorksheets();
713 if( rWorksheets
.getSheetCount() <= 0 ) return;
715 // force creation of workbook view model to get the Excel defaults
716 const WorkbookViewModel
& rModel
= maBookViews
.empty() ? createWorkbookView() : *maBookViews
.front();
718 // show object mode is part of workbook settings
719 sal_Int16 nShowMode
= getWorkbookSettings().getApiShowObjectMode();
721 // view settings for all sheets
722 Reference
< XNameContainer
> xSheetsNC
= ContainerHelper::createNameContainer( getGlobalFactory() );
723 if( !xSheetsNC
.is() ) return;
724 for( SheetPropertiesMap::const_iterator aIt
= maSheetProps
.begin(), aEnd
= maSheetProps
.end(); aIt
!= aEnd
; ++aIt
)
725 ContainerHelper::insertByName( xSheetsNC
, rWorksheets
.getCalcSheetName( aIt
->first
), aIt
->second
);
727 // use active sheet to set sheet properties that are document-global in Calc
728 sal_Int32 nActiveSheet
= getActiveSheetIndex();
729 SheetViewModelRef
& rxActiveSheetView
= maSheetViews
[ nActiveSheet
];
730 OSL_ENSURE( rxActiveSheetView
.get(), "ViewSettings::finalizeImport - missing active sheet view settings" );
731 if( !rxActiveSheetView
)
732 rxActiveSheetView
.reset( new SheetViewModel
);
734 Reference
< XIndexContainer
> xContainer
= ContainerHelper::createIndexContainer( getGlobalFactory() );
735 if( xContainer
.is() ) try
737 PropertyMap aPropMap
;
738 aPropMap
[ PROP_Tables
] <<= xSheetsNC
;
739 aPropMap
[ PROP_ActiveTable
] <<= rWorksheets
.getCalcSheetName( nActiveSheet
);
740 aPropMap
[ PROP_HasHorizontalScrollBar
] <<= rModel
.mbShowHorScroll
;
741 aPropMap
[ PROP_HasVerticalScrollBar
] <<= rModel
.mbShowVerScroll
;
742 aPropMap
[ PROP_HasSheetTabs
] <<= rModel
.mbShowTabBar
;
743 aPropMap
[ PROP_RelativeHorizontalTabbarWidth
] <<= double( rModel
.mnTabBarWidth
/ 1000.0 );
744 aPropMap
[ PROP_ShowObjects
] <<= nShowMode
;
745 aPropMap
[ PROP_ShowCharts
] <<= nShowMode
;
746 aPropMap
[ PROP_ShowDrawing
] <<= nShowMode
;
747 aPropMap
[ PROP_GridColor
] <<= rxActiveSheetView
->maGridColor
.getColor( *this );
748 aPropMap
[ PROP_ShowPageBreakPreview
] <<= rxActiveSheetView
->isPageBreakPreview();
749 aPropMap
[ PROP_ShowFormulas
] <<= rxActiveSheetView
->mbShowFormulas
;
750 aPropMap
[ PROP_ShowGrid
] <<= rxActiveSheetView
->mbShowGrid
;
751 aPropMap
[ PROP_HasColumnRowHeaders
] <<= rxActiveSheetView
->mbShowHeadings
;
752 aPropMap
[ PROP_ShowZeroValues
] <<= rxActiveSheetView
->mbShowZeros
;
753 aPropMap
[ PROP_IsOutlineSymbolsSet
] <<= rxActiveSheetView
->mbShowOutline
;
755 xContainer
->insertByIndex( 0, Any( aPropMap
.makePropertyValueSequence() ) );
756 Reference
< XIndexAccess
> xIAccess( xContainer
, UNO_QUERY_THROW
);
757 Reference
< XViewDataSupplier
> xViewDataSuppl( getDocument(), UNO_QUERY_THROW
);
758 xViewDataSuppl
->setViewData( xIAccess
);
762 OSL_ENSURE( false, "ViewSettings::finalizeImport - cannot create document view settings" );
766 sal_Int32
ViewSettings::getActiveSheetIndex() const
768 sal_Int32 nSheetCount
= getLimitedValue
< sal_Int32
, sal_Int32
>( getWorksheets().getSheetCount(), 1, SAL_MAX_INT32
);
769 return maBookViews
.empty() ? 0 : getLimitedValue
< sal_Int32
, sal_Int32
>( maBookViews
.front()->mnActiveSheet
, 0, nSheetCount
- 1 );
772 // private --------------------------------------------------------------------
774 WorkbookViewModel
& ViewSettings::createWorkbookView()
776 WorkbookViewModelRef
xModel( new WorkbookViewModel
);
777 maBookViews
.push_back( xModel
);
781 // ============================================================================