Update ooo320-m1
[ooovba.git] / oox / source / xls / viewsettings.cxx
blob4eaa668244576ed7fd78f35d6abcccd47a29f206
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;
60 using ::oox::core::FilterBase;
62 namespace oox {
63 namespace xls {
65 // ============================================================================
67 namespace {
69 const sal_Int32 OOX_BOOKVIEW_TABBARRATIO_DEF = 600; /// Default tabbar ratio.
70 const sal_Int32 OOX_SHEETVIEW_NORMALZOOM_DEF = 100; /// Default zoom for normal view.
71 const sal_Int32 OOX_SHEETVIEW_SHEETLAYZOOM_DEF = 60; /// Default zoom for pagebreak preview.
72 const sal_Int32 OOX_SHEETVIEW_PAGELAYZOOM_DEF = 100; /// Default zoom for page layout view.
74 const sal_uInt8 OOBIN_PANE_FROZEN = 0x01;
75 const sal_uInt8 OOBIN_PANE_FROZENNOSPLIT = 0x02;
77 const sal_uInt16 OOBIN_SHEETVIEW_WINPROTECTED = 0x0001;
78 const sal_uInt16 OOBIN_SHEETVIEW_SHOWFORMULAS = 0x0002;
79 const sal_uInt16 OOBIN_SHEETVIEW_SHOWGRID = 0x0004;
80 const sal_uInt16 OOBIN_SHEETVIEW_SHOWHEADINGS = 0x0008;
81 const sal_uInt16 OOBIN_SHEETVIEW_SHOWZEROS = 0x0010;
82 const sal_uInt16 OOBIN_SHEETVIEW_RIGHTTOLEFT = 0x0020;
83 const sal_uInt16 OOBIN_SHEETVIEW_SELECTED = 0x0040;
84 const sal_uInt16 OOBIN_SHEETVIEW_SHOWRULER = 0x0080;
85 const sal_uInt16 OOBIN_SHEETVIEW_SHOWOUTLINE = 0x0100;
86 const sal_uInt16 OOBIN_SHEETVIEW_DEFGRIDCOLOR = 0x0200;
87 const sal_uInt16 OOBIN_SHEETVIEW_SHOWWHITESPACE = 0x0400;
89 const sal_uInt16 OOBIN_CHARTSHEETVIEW_SELECTED = 0x0001;
90 const sal_uInt16 OOBIN_CHARTSHEETVIEW_ZOOMTOFIT = 0x0002;
92 const sal_uInt8 OOBIN_WBVIEW_HIDDEN = 0x01;
93 const sal_uInt8 OOBIN_WBVIEW_MINIMIZED = 0x02;
94 const sal_uInt8 OOBIN_WBVIEW_SHOWHORSCROLL = 0x08;
95 const sal_uInt8 OOBIN_WBVIEW_SHOWVERSCROLL = 0x10;
96 const sal_uInt8 OOBIN_WBVIEW_SHOWTABBAR = 0x20;
97 const sal_uInt8 OOBIN_WBVIEW_AUTOFILTERGROUP = 0x40;
99 const sal_uInt8 BIFF_PANE_BOTTOMRIGHT = 0; /// Bottom-right pane.
100 const sal_uInt8 BIFF_PANE_TOPRIGHT = 1; /// Right, or top-right pane.
101 const sal_uInt8 BIFF_PANE_BOTTOMLEFT = 2; /// Bottom, or bottom-left pane.
102 const sal_uInt8 BIFF_PANE_TOPLEFT = 3; /// Single, top, left, or top-left pane.
104 const sal_uInt16 BIFF_WINDOW1_HIDDEN = 0x0001;
105 const sal_uInt16 BIFF_WINDOW1_MINIMIZED = 0x0002;
106 const sal_uInt16 BIFF_WINDOW1_SHOWHORSCROLL = 0x0008;
107 const sal_uInt16 BIFF_WINDOW1_SHOWVERSCROLL = 0x0010;
108 const sal_uInt16 BIFF_WINDOW1_SHOWTABBAR = 0x0020;
110 const sal_uInt16 BIFF_WINDOW2_SHOWFORMULAS = 0x0001;
111 const sal_uInt16 BIFF_WINDOW2_SHOWGRID = 0x0002;
112 const sal_uInt16 BIFF_WINDOW2_SHOWHEADINGS = 0x0004;
113 const sal_uInt16 BIFF_WINDOW2_FROZEN = 0x0008;
114 const sal_uInt16 BIFF_WINDOW2_SHOWZEROS = 0x0010;
115 const sal_uInt16 BIFF_WINDOW2_DEFGRIDCOLOR = 0x0020;
116 const sal_uInt16 BIFF_WINDOW2_RIGHTTOLEFT = 0x0040;
117 const sal_uInt16 BIFF_WINDOW2_SHOWOUTLINE = 0x0080;
118 const sal_uInt16 BIFF_WINDOW2_FROZENNOSPLIT = 0x0100;
119 const sal_uInt16 BIFF_WINDOW2_SELECTED = 0x0200;
120 const sal_uInt16 BIFF_WINDOW2_DISPLAYED = 0x0400;
121 const sal_uInt16 BIFF_WINDOW2_PAGEBREAKMODE = 0x0800;
123 // Attention: view settings in Calc do not use com.sun.star.view.DocumentZoomType!
124 const sal_Int16 API_ZOOMTYPE_PERCENT = 0; /// Zoom value in percent.
126 const sal_Int32 API_ZOOMVALUE_MIN = 20; /// Minimum zoom in Calc.
127 const sal_Int32 API_ZOOMVALUE_MAX = 400; /// Maximum zoom in Calc.
129 // no predefined constants for split mode
130 const sal_Int16 API_SPLITMODE_NONE = 0; /// No splits in window.
131 const sal_Int16 API_SPLITMODE_SPLIT = 1; /// Window is split.
132 const sal_Int16 API_SPLITMODE_FREEZE = 2; /// Window has frozen panes.
134 // no predefined constants for pane idetifiers
135 const sal_Int16 API_SPLITPANE_TOPLEFT = 0; /// Top-left, or top pane.
136 const sal_Int16 API_SPLITPANE_TOPRIGHT = 1; /// Top-right pane.
137 const sal_Int16 API_SPLITPANE_BOTTOMLEFT = 2; /// Bottom-left, bottom, left, or single pane.
138 const sal_Int16 API_SPLITPANE_BOTTOMRIGHT = 3; /// Bottom-right, or right pane.
140 // ----------------------------------------------------------------------------
142 /** Returns the OOXML pane identifier from the passed OOBIN or BIFF pane id. */
143 sal_Int32 lclGetOoxPaneId( sal_Int32 nBinPaneId, sal_Int32 nDefaultPaneId )
145 static const sal_Int32 spnPaneIds[] = { XML_bottomRight, XML_topRight, XML_bottomLeft, XML_topLeft };
146 return STATIC_ARRAY_SELECT( spnPaneIds, nBinPaneId, nDefaultPaneId );
149 } // namespace
151 // ============================================================================
153 PaneSelectionModel::PaneSelectionModel() :
154 mnActiveCellId( 0 )
158 // ----------------------------------------------------------------------------
160 SheetViewModel::SheetViewModel() :
161 mnWorkbookViewId( 0 ),
162 mnViewType( XML_normal ),
163 mnActivePaneId( XML_topLeft ),
164 mnPaneState( XML_split ),
165 mfSplitX( 0.0 ),
166 mfSplitY( 0.0 ),
167 mnCurrentZoom( 0 ),
168 mnNormalZoom( 0 ),
169 mnSheetLayoutZoom( 0 ),
170 mnPageLayoutZoom( 0 ),
171 mbSelected( false ),
172 mbRightToLeft( false ),
173 mbDefGridColor( true ),
174 mbShowFormulas( false ),
175 mbShowGrid( true ),
176 mbShowHeadings( true ),
177 mbShowZeros( true ),
178 mbShowOutline( true ),
179 mbZoomToFit( false )
181 maGridColor.setIndexed( OOX_COLOR_WINDOWTEXT );
184 bool SheetViewModel::isPageBreakPreview() const
186 return mnViewType == XML_pageBreakPreview;
189 sal_Int32 SheetViewModel::getNormalZoom() const
191 const sal_Int32& rnZoom = isPageBreakPreview() ? mnNormalZoom : mnCurrentZoom;
192 sal_Int32 nZoom = (rnZoom > 0) ? rnZoom : OOX_SHEETVIEW_NORMALZOOM_DEF;
193 return getLimitedValue< sal_Int32 >( nZoom, API_ZOOMVALUE_MIN, API_ZOOMVALUE_MAX );
196 sal_Int32 SheetViewModel::getPageBreakZoom() const
198 const sal_Int32& rnZoom = isPageBreakPreview() ? mnCurrentZoom : mnSheetLayoutZoom;
199 sal_Int32 nZoom = (rnZoom > 0) ? rnZoom : OOX_SHEETVIEW_SHEETLAYZOOM_DEF;
200 return getLimitedValue< sal_Int32 >( nZoom, API_ZOOMVALUE_MIN, API_ZOOMVALUE_MAX );
203 sal_Int32 SheetViewModel::getGridColor( const FilterBase& rFilter ) const
205 return mbDefGridColor ? API_RGB_TRANSPARENT : maGridColor.getColor( rFilter );
208 const PaneSelectionModel* SheetViewModel::getPaneSelection( sal_Int32 nPaneId ) const
210 return maPaneSelMap.get( nPaneId ).get();
213 const PaneSelectionModel* SheetViewModel::getActiveSelection() const
215 return getPaneSelection( mnActivePaneId );
218 PaneSelectionModel& SheetViewModel::createPaneSelection( sal_Int32 nPaneId )
220 PaneSelectionModelMap::mapped_type& rxPaneSel = maPaneSelMap[ nPaneId ];
221 if( !rxPaneSel )
222 rxPaneSel.reset( new PaneSelectionModel );
223 return *rxPaneSel;
226 // ----------------------------------------------------------------------------
228 SheetViewSettings::SheetViewSettings( const WorksheetHelper& rHelper ) :
229 WorksheetHelper( rHelper )
233 void SheetViewSettings::importSheetView( const AttributeList& rAttribs )
235 SheetViewModel& rModel = *createSheetView();
236 rModel.maGridColor.setIndexed( rAttribs.getInteger( XML_colorId, OOX_COLOR_WINDOWTEXT ) );
237 rModel.maFirstPos = getAddressConverter().createValidCellAddress( rAttribs.getString( XML_topLeftCell, OUString() ), getSheetIndex(), false );
238 rModel.mnWorkbookViewId = rAttribs.getToken( XML_workbookViewId, 0 );
239 rModel.mnViewType = rAttribs.getToken( XML_view, XML_normal );
240 rModel.mnCurrentZoom = rAttribs.getInteger( XML_zoomScale, 100 );
241 rModel.mnNormalZoom = rAttribs.getInteger( XML_zoomScaleNormal, 0 );
242 rModel.mnSheetLayoutZoom = rAttribs.getInteger( XML_zoomScaleSheetLayoutView, 0 );
243 rModel.mnPageLayoutZoom = rAttribs.getInteger( XML_zoomScalePageLayoutView, 0 );
244 rModel.mbSelected = rAttribs.getBool( XML_tabSelected, false );
245 rModel.mbRightToLeft = rAttribs.getBool( XML_rightToLeft, false );
246 rModel.mbDefGridColor = rAttribs.getBool( XML_defaultGridColor, true );
247 rModel.mbShowFormulas = rAttribs.getBool( XML_showFormulas, false );
248 rModel.mbShowGrid = rAttribs.getBool( XML_showGridLines, true );
249 rModel.mbShowHeadings = rAttribs.getBool( XML_showRowColHeaders, true );
250 rModel.mbShowZeros = rAttribs.getBool( XML_showZeros, true );
251 rModel.mbShowOutline = rAttribs.getBool( XML_showOutlineSymbols, true );
254 void SheetViewSettings::importTabColor( const AttributeList& rAttribs )
256 SheetViewModel& rModel = maSheetViews.empty() ? *createSheetView() : *maSheetViews.back();
257 rModel.maTabColor.importColor( rAttribs );
260 void SheetViewSettings::importPane( const AttributeList& rAttribs )
262 OSL_ENSURE( !maSheetViews.empty(), "SheetViewSettings::importPane - missing sheet view model" );
263 if( !maSheetViews.empty() )
265 SheetViewModel& rModel = *maSheetViews.back();
266 rModel.maSecondPos = getAddressConverter().createValidCellAddress( rAttribs.getString( XML_topLeftCell, OUString() ), getSheetIndex(), false );
267 rModel.mnActivePaneId = rAttribs.getToken( XML_activePane, XML_topLeft );
268 rModel.mnPaneState = rAttribs.getToken( XML_state, XML_split );
269 rModel.mfSplitX = rAttribs.getDouble( XML_xSplit, 0.0 );
270 rModel.mfSplitY = rAttribs.getDouble( XML_ySplit, 0.0 );
274 void SheetViewSettings::importSelection( const AttributeList& rAttribs )
276 OSL_ENSURE( !maSheetViews.empty(), "SheetViewSettings::importSelection - missing sheet view model" );
277 if( !maSheetViews.empty() )
279 // pane this selection belongs to
280 sal_Int32 nPaneId = rAttribs.getToken( XML_pane, XML_topLeft );
281 PaneSelectionModel& rSelData = maSheetViews.back()->createPaneSelection( nPaneId );
282 // cursor position
283 rSelData.maActiveCell = getAddressConverter().createValidCellAddress( rAttribs.getString( XML_activeCell, OUString() ), getSheetIndex(), false );
284 rSelData.mnActiveCellId = rAttribs.getInteger( XML_activeCellId, 0 );
285 // selection
286 rSelData.maSelection.clear();
287 getAddressConverter().convertToCellRangeList( rSelData.maSelection, rAttribs.getString( XML_sqref, OUString() ), getSheetIndex(), false );
291 void SheetViewSettings::importChartSheetView( const AttributeList& rAttribs )
293 SheetViewModel& rModel = *createSheetView();
294 rModel.mnWorkbookViewId = rAttribs.getToken( XML_workbookViewId, 0 );
295 rModel.mnCurrentZoom = rAttribs.getInteger( XML_zoomScale, 100 );
296 rModel.mbSelected = rAttribs.getBool( XML_tabSelected, false );
297 rModel.mbZoomToFit = rAttribs.getBool( XML_zoomToFit, false );
300 void SheetViewSettings::importSheetView( RecordInputStream& rStrm )
302 SheetViewModel& rModel = *createSheetView();
303 sal_uInt16 nFlags;
304 sal_Int32 nViewType;
305 BinAddress aFirstPos;
306 rStrm >> nFlags >> nViewType >> aFirstPos;
307 rModel.maGridColor.importColorId( rStrm );
308 rModel.mnCurrentZoom = rStrm.readuInt16();
309 rModel.mnNormalZoom = rStrm.readuInt16();
310 rModel.mnSheetLayoutZoom = rStrm.readuInt16();
311 rModel.mnPageLayoutZoom = rStrm.readuInt16();
312 rStrm >> rModel.mnWorkbookViewId;
314 rModel.maFirstPos = getAddressConverter().createValidCellAddress( aFirstPos, getSheetIndex(), false );
315 static const sal_Int32 spnViewTypes[] = { XML_normal, XML_pageBreakPreview, XML_pageLayout };
316 rModel.mnViewType = STATIC_ARRAY_SELECT( spnViewTypes, nViewType, XML_normal );
317 rModel.mbSelected = getFlag( nFlags, OOBIN_SHEETVIEW_SELECTED );
318 rModel.mbRightToLeft = getFlag( nFlags, OOBIN_SHEETVIEW_RIGHTTOLEFT );
319 rModel.mbDefGridColor = getFlag( nFlags, OOBIN_SHEETVIEW_DEFGRIDCOLOR );
320 rModel.mbShowFormulas = getFlag( nFlags, OOBIN_SHEETVIEW_SHOWFORMULAS );
321 rModel.mbShowGrid = getFlag( nFlags, OOBIN_SHEETVIEW_SHOWGRID );
322 rModel.mbShowHeadings = getFlag( nFlags, OOBIN_SHEETVIEW_SHOWHEADINGS );
323 rModel.mbShowZeros = getFlag( nFlags, OOBIN_SHEETVIEW_SHOWZEROS );
324 rModel.mbShowOutline = getFlag( nFlags, OOBIN_SHEETVIEW_SHOWOUTLINE );
327 void SheetViewSettings::importPane( RecordInputStream& rStrm )
329 OSL_ENSURE( !maSheetViews.empty(), "SheetViewSettings::importPane - missing sheet view model" );
330 if( !maSheetViews.empty() )
332 SheetViewModel& rModel = *maSheetViews.back();
334 BinAddress aSecondPos;
335 sal_Int32 nActivePaneId;
336 sal_uInt8 nFlags;
337 rStrm >> rModel.mfSplitX >> rModel.mfSplitY >> aSecondPos >> nActivePaneId >> nFlags;
339 rModel.maSecondPos = getAddressConverter().createValidCellAddress( aSecondPos, getSheetIndex(), false );
340 rModel.mnActivePaneId = lclGetOoxPaneId( nActivePaneId, XML_topLeft );
341 rModel.mnPaneState = getFlagValue( nFlags, OOBIN_PANE_FROZEN, getFlagValue( nFlags, OOBIN_PANE_FROZENNOSPLIT, XML_frozen, XML_frozenSplit ), XML_split );
345 void SheetViewSettings::importSelection( RecordInputStream& rStrm )
347 OSL_ENSURE( !maSheetViews.empty(), "SheetViewSettings::importSelection - missing sheet view model" );
348 if( !maSheetViews.empty() )
350 // pane this selection belongs to
351 sal_Int32 nPaneId = rStrm.readInt32();
352 PaneSelectionModel& rPaneSel = maSheetViews.back()->createPaneSelection( lclGetOoxPaneId( nPaneId, -1 ) );
353 // cursor position
354 BinAddress aActiveCell;
355 rStrm >> aActiveCell >> rPaneSel.mnActiveCellId;
356 rPaneSel.maActiveCell = getAddressConverter().createValidCellAddress( aActiveCell, getSheetIndex(), false );
357 // selection
358 BinRangeList aSelection;
359 rStrm >> aSelection;
360 rPaneSel.maSelection.clear();
361 getAddressConverter().convertToCellRangeList( rPaneSel.maSelection, aSelection, getSheetIndex(), false );
365 void SheetViewSettings::importChartSheetView( RecordInputStream& rStrm )
367 SheetViewModel& rModel = *createSheetView();
368 sal_uInt16 nFlags;
369 rStrm >> nFlags >> rModel.mnCurrentZoom >> rModel.mnWorkbookViewId;
371 rModel.mbSelected = getFlag( nFlags, OOBIN_CHARTSHEETVIEW_SELECTED );
372 rModel.mbZoomToFit = getFlag( nFlags, OOBIN_CHARTSHEETVIEW_ZOOMTOFIT );
375 void SheetViewSettings::importWindow2( BiffInputStream& rStrm )
377 OSL_ENSURE( maSheetViews.empty(), "SheetViewSettings::importWindow2 - multiple WINDOW2 records" );
378 SheetViewModel& rModel = *createSheetView();
379 if( getBiff() == BIFF2 )
381 rModel.mbShowFormulas = rStrm.readuInt8() != 0;
382 rModel.mbShowGrid = rStrm.readuInt8() != 0;
383 rModel.mbShowHeadings = rStrm.readuInt8() != 0;
384 rModel.mnPaneState = (rStrm.readuInt8() == 0) ? XML_split : XML_frozen;
385 rModel.mbShowZeros = rStrm.readuInt8() != 0;
386 BinAddress aFirstPos;
387 rStrm >> aFirstPos;
388 rModel.maFirstPos = getAddressConverter().createValidCellAddress( aFirstPos, getSheetIndex(), false );
389 rModel.mbDefGridColor = rStrm.readuInt8() != 0;
390 rModel.maGridColor.importColorRgb( rStrm );
392 else
394 sal_uInt16 nFlags;
395 BinAddress aFirstPos;
396 rStrm >> nFlags >> aFirstPos;
398 rModel.maFirstPos = getAddressConverter().createValidCellAddress( aFirstPos, getSheetIndex(), false );
399 rModel.mnPaneState = getFlagValue( nFlags, BIFF_WINDOW2_FROZEN, getFlagValue( nFlags, BIFF_WINDOW2_FROZENNOSPLIT, XML_frozen, XML_frozenSplit ), XML_split );
400 rModel.mbSelected = getFlag( nFlags, BIFF_WINDOW2_SELECTED );
401 rModel.mbRightToLeft = getFlag( nFlags, BIFF_WINDOW2_RIGHTTOLEFT );
402 rModel.mbDefGridColor = getFlag( nFlags, BIFF_WINDOW2_DEFGRIDCOLOR );
403 rModel.mbShowFormulas = getFlag( nFlags, BIFF_WINDOW2_SHOWFORMULAS );
404 rModel.mbShowGrid = getFlag( nFlags, BIFF_WINDOW2_SHOWGRID );
405 rModel.mbShowHeadings = getFlag( nFlags, BIFF_WINDOW2_SHOWHEADINGS );
406 rModel.mbShowZeros = getFlag( nFlags, BIFF_WINDOW2_SHOWZEROS );
407 rModel.mbShowOutline = getFlag( nFlags, BIFF_WINDOW2_SHOWOUTLINE );
409 if( getBiff() == BIFF8 )
411 rModel.mnViewType = getFlagValue( nFlags, BIFF_WINDOW2_PAGEBREAKMODE, XML_pageBreakPreview, XML_normal );
413 rModel.maGridColor.importColorId( rStrm );
414 // zoom data not included in chart sheets
415 if( (getSheetType() != SHEETTYPE_CHARTSHEET) && (rStrm.getRemaining() >= 6) )
417 rStrm.skip( 2 );
418 sal_uInt16 nPageZoom, nNormalZoom;
419 rStrm >> nPageZoom >> nNormalZoom;
420 rModel.mnSheetLayoutZoom = nPageZoom;
421 rModel.mnNormalZoom = nNormalZoom;
424 else
426 rModel.maGridColor.importColorRgb( rStrm );
431 void SheetViewSettings::importPane( BiffInputStream& rStrm )
433 OSL_ENSURE( !maSheetViews.empty(), "SheetViewSettings::importPane - missing leading WINDOW2 record" );
434 if( !maSheetViews.empty() )
436 sal_uInt8 nActivePaneId;
437 sal_uInt16 nSplitX, nSplitY;
438 BinAddress aSecondPos;
439 rStrm >> nSplitX >> nSplitY >> aSecondPos >> nActivePaneId;
441 SheetViewModel& rModel = *maSheetViews.back();
442 rModel.mfSplitX = nSplitX;
443 rModel.mfSplitY = nSplitY;
444 rModel.maSecondPos = getAddressConverter().createValidCellAddress( aSecondPos, getSheetIndex(), false );
445 rModel.mnActivePaneId = lclGetOoxPaneId( nActivePaneId, XML_topLeft );
449 void SheetViewSettings::importScl( BiffInputStream& rStrm )
451 OSL_ENSURE( !maSheetViews.empty(), "SheetViewSettings::importScl - missing leading WINDOW2 record" );
452 if( !maSheetViews.empty() )
454 sal_uInt16 nNum, nDenom;
455 rStrm >> nNum >> nDenom;
456 OSL_ENSURE( nDenom > 0, "SheetViewSettings::importScl - invalid denominator" );
457 if( nDenom > 0 )
458 maSheetViews.back()->mnCurrentZoom = getLimitedValue< sal_Int32, sal_uInt16 >( (nNum * 100) / nDenom, 10, 400 );
462 void SheetViewSettings::importSelection( BiffInputStream& rStrm )
464 OSL_ENSURE( !maSheetViews.empty(), "SheetViewSettings::importPane - missing leading WINDOW2 record" );
465 if( !maSheetViews.empty() )
467 // pane this selection belongs to
468 sal_uInt8 nPaneId = rStrm.readuInt8();
469 PaneSelectionModel& rPaneSel = maSheetViews.back()->createPaneSelection( lclGetOoxPaneId( nPaneId, -1 ) );
470 // cursor position
471 BinAddress aActiveCell;
472 sal_uInt16 nActiveCellId;
473 rStrm >> aActiveCell >> nActiveCellId;
474 rPaneSel.maActiveCell = getAddressConverter().createValidCellAddress( aActiveCell, getSheetIndex(), false );
475 rPaneSel.mnActiveCellId = nActiveCellId;
476 // selection
477 rPaneSel.maSelection.clear();
478 BinRangeList aSelection;
479 aSelection.read( rStrm, false );
480 getAddressConverter().convertToCellRangeList( rPaneSel.maSelection, aSelection, getSheetIndex(), false );
484 void SheetViewSettings::finalizeImport()
486 // force creation of sheet view model to get the Excel defaults
487 SheetViewModelRef xModel = maSheetViews.empty() ? createSheetView() : maSheetViews.front();
489 // #i59590# #158194# special handling for chart sheets (Excel ignores some settings in chart sheets)
490 if( getSheetType() == SHEETTYPE_CHARTSHEET )
492 xModel->maPaneSelMap.clear();
493 xModel->maFirstPos = xModel->maSecondPos = CellAddress( getSheetIndex(), 0, 0 );
494 xModel->mnViewType = XML_normal;
495 xModel->mnActivePaneId = XML_topLeft;
496 xModel->mnPaneState = XML_split;
497 xModel->mfSplitX = xModel->mfSplitY = 0.0;
498 xModel->mbRightToLeft = false;
499 xModel->mbDefGridColor = true;
500 xModel->mbShowFormulas = false;
501 xModel->mbShowGrid = true;
502 xModel->mbShowHeadings = true;
503 xModel->mbShowZeros = true;
504 xModel->mbShowOutline = true;
507 // mirrored sheet (this is not a view setting in Calc)
508 if( xModel->mbRightToLeft )
510 PropertySet aPropSet( getSheet() );
511 aPropSet.setProperty( PROP_TableLayout, ::com::sun::star::text::WritingMode2::RL_TB );
514 // sheet selected (active sheet must be selected)
515 bool bSelected = xModel->mbSelected || (getSheetIndex() == getViewSettings().getActiveCalcSheet());
517 // visible area and current cursor position (selection not supported via API)
518 CellAddress aFirstPos = xModel->maFirstPos;
519 const PaneSelectionModel* pPaneSel = xModel->getActiveSelection();
520 CellAddress aCursor = pPaneSel ? pPaneSel->maActiveCell : aFirstPos;
522 // freeze/split position default
523 sal_Int16 nHSplitMode = API_SPLITMODE_NONE;
524 sal_Int16 nVSplitMode = API_SPLITMODE_NONE;
525 sal_Int32 nHSplitPos = 0;
526 sal_Int32 nVSplitPos = 0;
527 // active pane default
528 sal_Int16 nActivePane = API_SPLITPANE_BOTTOMLEFT;
530 // freeze/split position
531 if( (xModel->mnPaneState == XML_frozen) || (xModel->mnPaneState == XML_frozenSplit) )
533 /* Frozen panes: handle split position as row/column positions.
534 #i35812# Excel uses number of visible rows/columns in the
535 frozen area (rows/columns scolled outside are not incuded),
536 Calc uses absolute position of first unfrozen row/column. */
537 const CellAddress& rMaxApiPos = getAddressConverter().getMaxApiAddress();
538 if( (xModel->mfSplitX >= 1.0) && (xModel->maFirstPos.Column + xModel->mfSplitX <= rMaxApiPos.Column) )
539 nHSplitPos = static_cast< sal_Int32 >( xModel->maFirstPos.Column + xModel->mfSplitX );
540 nHSplitMode = (nHSplitPos > 0) ? API_SPLITMODE_FREEZE : API_SPLITMODE_NONE;
541 if( (xModel->mfSplitY >= 1.0) && (xModel->maFirstPos.Row + xModel->mfSplitY <= rMaxApiPos.Row) )
542 nVSplitPos = static_cast< sal_Int32 >( xModel->maFirstPos.Row + xModel->mfSplitY );
543 nVSplitMode = (nVSplitPos > 0) ? API_SPLITMODE_FREEZE : API_SPLITMODE_NONE;
545 else if( xModel->mnPaneState == XML_split )
547 // split window: view settings API uses twips...
548 nHSplitPos = getLimitedValue< sal_Int32, double >( xModel->mfSplitX + 0.5, 0, SAL_MAX_INT32 );
549 nHSplitMode = (nHSplitPos > 0) ? API_SPLITMODE_SPLIT : API_SPLITMODE_NONE;
550 nVSplitPos = getLimitedValue< sal_Int32, double >( xModel->mfSplitY + 0.5, 0, SAL_MAX_INT32 );
551 nVSplitMode = (nVSplitPos > 0) ? API_SPLITMODE_SPLIT : API_SPLITMODE_NONE;
554 // active pane
555 switch( xModel->mnActivePaneId )
557 // no horizontal split -> always use left panes
558 // no vertical split -> always use *bottom* panes
559 case XML_topLeft:
560 nActivePane = (nVSplitMode == API_SPLITMODE_NONE) ? API_SPLITPANE_BOTTOMLEFT : API_SPLITPANE_TOPLEFT;
561 break;
562 case XML_topRight:
563 nActivePane = (nHSplitMode == API_SPLITMODE_NONE) ?
564 ((nVSplitMode == API_SPLITMODE_NONE) ? API_SPLITPANE_BOTTOMLEFT : API_SPLITPANE_TOPLEFT) :
565 ((nVSplitMode == API_SPLITMODE_NONE) ? API_SPLITPANE_BOTTOMRIGHT : API_SPLITPANE_TOPRIGHT);
566 break;
567 case XML_bottomLeft:
568 nActivePane = API_SPLITPANE_BOTTOMLEFT;
569 break;
570 case XML_bottomRight:
571 nActivePane = (nHSplitMode == API_SPLITMODE_NONE) ? API_SPLITPANE_BOTTOMLEFT : API_SPLITPANE_BOTTOMRIGHT;
572 break;
575 // write the sheet view settings into the property sequence
576 PropertyMap aPropMap;
577 aPropMap[ PROP_TableSelected ] <<= bSelected;
578 aPropMap[ PROP_CursorPositionX ] <<= aCursor.Column;
579 aPropMap[ PROP_CursorPositionY ] <<= aCursor.Row;
580 aPropMap[ PROP_HorizontalSplitMode ] <<= nHSplitMode;
581 aPropMap[ PROP_VerticalSplitMode ] <<= nVSplitMode;
582 aPropMap[ PROP_HorizontalSplitPositionTwips ] <<= nHSplitPos;
583 aPropMap[ PROP_VerticalSplitPositionTwips ] <<= nVSplitPos;
584 aPropMap[ PROP_ActiveSplitRange ] <<= nActivePane;
585 aPropMap[ PROP_PositionLeft ] <<= aFirstPos.Column;
586 aPropMap[ PROP_PositionTop ] <<= aFirstPos.Row;
587 aPropMap[ PROP_PositionRight ] <<= xModel->maSecondPos.Column;
588 aPropMap[ PROP_PositionBottom ] <<= ((nVSplitPos > 0) ? xModel->maSecondPos.Row : xModel->maFirstPos.Row);
589 aPropMap[ PROP_ZoomType ] <<= API_ZOOMTYPE_PERCENT;
590 aPropMap[ PROP_ZoomValue ] <<= static_cast< sal_Int16 >( xModel->getNormalZoom() );
591 aPropMap[ PROP_PageViewZoomValue ] <<= static_cast< sal_Int16 >( xModel->getPageBreakZoom() );
592 aPropMap[ PROP_GridColor ] <<= xModel->getGridColor( getBaseFilter() );
593 aPropMap[ PROP_ShowPageBreakPreview ] <<= xModel->isPageBreakPreview();
594 aPropMap[ PROP_ShowFormulas ] <<= xModel->mbShowFormulas;
595 aPropMap[ PROP_ShowGrid ] <<= xModel->mbShowGrid;
596 aPropMap[ PROP_HasColumnRowHeaders ] <<= xModel->mbShowHeadings;
597 aPropMap[ PROP_ShowZeroValues ] <<= xModel->mbShowZeros;
598 aPropMap[ PROP_IsOutlineSymbolsSet ] <<= xModel->mbShowOutline;
600 if (!xModel->maTabColor.isAuto())
601 aPropMap[ PROP_TabColor ] <<= static_cast< sal_Int32 >(xModel->maTabColor.getColor(getBaseFilter()));
603 // store sheet view settings in global view settings object
604 getViewSettings().setSheetViewSettings( getSheetIndex(), xModel, Any( aPropMap.makePropertyValueSequence() ) );
607 // private --------------------------------------------------------------------
609 SheetViewModelRef SheetViewSettings::createSheetView()
611 SheetViewModelRef xModel( new SheetViewModel );
612 maSheetViews.push_back( xModel );
613 return xModel;
616 // ============================================================================
618 WorkbookViewModel::WorkbookViewModel() :
619 mnWinX( 0 ),
620 mnWinY( 0 ),
621 mnWinWidth( 0 ),
622 mnWinHeight( 0 ),
623 mnActiveSheet( 0 ),
624 mnFirstVisSheet( 0 ),
625 mnTabBarWidth( OOX_BOOKVIEW_TABBARRATIO_DEF ),
626 mnVisibility( XML_visible ),
627 mbShowTabBar( true ),
628 mbShowHorScroll( true ),
629 mbShowVerScroll( true ),
630 mbMinimized( false )
634 // ----------------------------------------------------------------------------
636 ViewSettings::ViewSettings( const WorkbookHelper& rHelper ) :
637 WorkbookHelper( rHelper )
641 void ViewSettings::importWorkbookView( const AttributeList& rAttribs )
643 WorkbookViewModel& rModel = createWorkbookView();
644 rModel.mnWinX = rAttribs.getInteger( XML_xWindow, 0 );
645 rModel.mnWinY = rAttribs.getInteger( XML_yWindow, 0 );
646 rModel.mnWinWidth = rAttribs.getInteger( XML_windowWidth, 0 );
647 rModel.mnWinHeight = rAttribs.getInteger( XML_windowHeight, 0 );
648 rModel.mnActiveSheet = rAttribs.getInteger( XML_activeTab, 0 );
649 rModel.mnFirstVisSheet = rAttribs.getInteger( XML_firstSheet, 0 );
650 rModel.mnTabBarWidth = rAttribs.getInteger( XML_tabRatio, 600 );
651 rModel.mnVisibility = rAttribs.getToken( XML_visibility, XML_visible );
652 rModel.mbShowTabBar = rAttribs.getBool( XML_showSheetTabs, true );
653 rModel.mbShowHorScroll = rAttribs.getBool( XML_showHorizontalScroll, true );
654 rModel.mbShowVerScroll = rAttribs.getBool( XML_showVerticalScroll, true );
655 rModel.mbMinimized = rAttribs.getBool( XML_minimized, false );
658 void ViewSettings::importWorkbookView( RecordInputStream& rStrm )
660 WorkbookViewModel& rModel = createWorkbookView();
661 sal_uInt8 nFlags;
662 rStrm >> rModel.mnWinX >> rModel.mnWinY >> rModel.mnWinWidth >> rModel.mnWinHeight >> rModel.mnTabBarWidth >> rModel.mnFirstVisSheet >> rModel.mnActiveSheet >> nFlags;
663 rModel.mnVisibility = getFlagValue( nFlags, OOBIN_WBVIEW_HIDDEN, XML_hidden, XML_visible );
664 rModel.mbShowTabBar = getFlag( nFlags, OOBIN_WBVIEW_SHOWTABBAR );
665 rModel.mbShowHorScroll = getFlag( nFlags, OOBIN_WBVIEW_SHOWHORSCROLL );
666 rModel.mbShowVerScroll = getFlag( nFlags, OOBIN_WBVIEW_SHOWVERSCROLL );
667 rModel.mbMinimized = getFlag( nFlags, OOBIN_WBVIEW_MINIMIZED );
670 void ViewSettings::importWindow1( BiffInputStream& rStrm )
672 sal_uInt16 nWinX, nWinY, nWinWidth, nWinHeight;
673 rStrm >> nWinX >> nWinY >> nWinWidth >> nWinHeight;
675 // WINDOW1 record occures in every sheet in BIFF4W
676 OSL_ENSURE( maBookViews.empty() || ((getBiff() == BIFF4) && isWorkbookFile()),
677 "ViewSettings::importWindow1 - multiple WINDOW1 records" );
678 WorkbookViewModel& rModel = createWorkbookView();
679 rModel.mnWinX = nWinX;
680 rModel.mnWinY = nWinY;
681 rModel.mnWinWidth = nWinWidth;
682 rModel.mnWinHeight = nWinHeight;
684 if( getBiff() <= BIFF4 )
686 sal_uInt8 nHidden;
687 rStrm >> nHidden;
688 rModel.mnVisibility = (nHidden == 0) ? XML_visible : XML_hidden;
690 else
692 sal_uInt16 nFlags, nActiveTab, nFirstVisTab, nSelectCnt, nTabBarWidth;
693 rStrm >> nFlags >> nActiveTab >> nFirstVisTab >> nSelectCnt >> nTabBarWidth;
695 rModel.mnActiveSheet = nActiveTab;
696 rModel.mnFirstVisSheet = nFirstVisTab;
697 rModel.mnTabBarWidth = nTabBarWidth;
698 rModel.mnVisibility = getFlagValue( nFlags, BIFF_WINDOW1_HIDDEN, XML_hidden, XML_visible );
699 rModel.mbMinimized = getFlag( nFlags, BIFF_WINDOW1_MINIMIZED );
700 rModel.mbShowHorScroll = getFlag( nFlags, BIFF_WINDOW1_SHOWHORSCROLL );
701 rModel.mbShowVerScroll = getFlag( nFlags, BIFF_WINDOW1_SHOWVERSCROLL );
702 rModel.mbShowTabBar = getFlag( nFlags, BIFF_WINDOW1_SHOWTABBAR );
706 void ViewSettings::setSheetViewSettings( sal_Int16 nSheet, const SheetViewModelRef& rxSheetView, const Any& rProperties )
708 maSheetViews[ nSheet ] = rxSheetView;
709 maSheetProps[ nSheet ] = rProperties;
712 void ViewSettings::finalizeImport()
714 const WorksheetBuffer& rWorksheets = getWorksheets();
715 if( rWorksheets.getWorksheetCount() <= 0 ) return;
717 // force creation of workbook view model to get the Excel defaults
718 const WorkbookViewModel& rModel = maBookViews.empty() ? createWorkbookView() : *maBookViews.front();
720 // show object mode is part of workbook settings
721 sal_Int16 nShowMode = getWorkbookSettings().getApiShowObjectMode();
723 // view settings for all sheets
724 Reference< XNameContainer > xSheetsNC = ContainerHelper::createNameContainer( getGlobalFactory() );
725 if( !xSheetsNC.is() ) return;
726 for( SheetPropertiesMap::const_iterator aIt = maSheetProps.begin(), aEnd = maSheetProps.end(); aIt != aEnd; ++aIt )
727 ContainerHelper::insertByName( xSheetsNC, rWorksheets.getCalcSheetName( aIt->first ), aIt->second );
729 // use active sheet to set sheet properties that are document-global in Calc
730 sal_Int16 nActiveSheet = getActiveCalcSheet();
731 SheetViewModelRef& rxActiveSheetView = maSheetViews[ nActiveSheet ];
732 OSL_ENSURE( rxActiveSheetView.get(), "ViewSettings::finalizeImport - missing active sheet view settings" );
733 if( !rxActiveSheetView )
734 rxActiveSheetView.reset( new SheetViewModel );
736 Reference< XIndexContainer > xContainer = ContainerHelper::createIndexContainer( getGlobalFactory() );
737 if( xContainer.is() ) try
739 PropertyMap aPropMap;
740 aPropMap[ PROP_Tables ] <<= xSheetsNC;
741 aPropMap[ PROP_ActiveTable ] <<= rWorksheets.getCalcSheetName( nActiveSheet );
742 aPropMap[ PROP_HasHorizontalScrollBar ] <<= rModel.mbShowHorScroll;
743 aPropMap[ PROP_HasVerticalScrollBar ] <<= rModel.mbShowVerScroll;
744 aPropMap[ PROP_HasSheetTabs ] <<= rModel.mbShowTabBar;
745 aPropMap[ PROP_RelativeHorizontalTabbarWidth ] <<= double( rModel.mnTabBarWidth / 1000.0 );
746 aPropMap[ PROP_ShowObjects ] <<= nShowMode;
747 aPropMap[ PROP_ShowCharts ] <<= nShowMode;
748 aPropMap[ PROP_ShowDrawing ] <<= nShowMode;
749 aPropMap[ PROP_GridColor ] <<= rxActiveSheetView->getGridColor( getBaseFilter() );
750 aPropMap[ PROP_ShowPageBreakPreview ] <<= rxActiveSheetView->isPageBreakPreview();
751 aPropMap[ PROP_ShowFormulas ] <<= rxActiveSheetView->mbShowFormulas;
752 aPropMap[ PROP_ShowGrid ] <<= rxActiveSheetView->mbShowGrid;
753 aPropMap[ PROP_HasColumnRowHeaders ] <<= rxActiveSheetView->mbShowHeadings;
754 aPropMap[ PROP_ShowZeroValues ] <<= rxActiveSheetView->mbShowZeros;
755 aPropMap[ PROP_IsOutlineSymbolsSet ] <<= rxActiveSheetView->mbShowOutline;
757 xContainer->insertByIndex( 0, Any( aPropMap.makePropertyValueSequence() ) );
758 Reference< XIndexAccess > xIAccess( xContainer, UNO_QUERY_THROW );
759 Reference< XViewDataSupplier > xViewDataSuppl( getDocument(), UNO_QUERY_THROW );
760 xViewDataSuppl->setViewData( xIAccess );
762 catch( Exception& )
764 OSL_ENSURE( false, "ViewSettings::finalizeImport - cannot create document view settings" );
768 sal_Int16 ViewSettings::getActiveCalcSheet() const
770 return maBookViews.empty() ? 0 : ::std::max< sal_Int16 >( getWorksheets().getCalcSheetIndex( maBookViews.front()->mnActiveSheet ), 0 );
773 // private --------------------------------------------------------------------
775 WorkbookViewModel& ViewSettings::createWorkbookView()
777 WorkbookViewModelRef xModel( new WorkbookViewModel );
778 maBookViews.push_back( xModel );
779 return *xModel;
782 // ============================================================================
784 } // namespace xls
785 } // namespace oox