fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / sc / source / filter / oox / viewsettings.cxx
blob05a70fcd9350dd69f86db2c861ac8aa331b0f9eb
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "viewsettings.hxx"
22 #include <com/sun/star/awt/Point.hpp>
23 #include <com/sun/star/awt/Size.hpp>
24 #include <com/sun/star/beans/PropertyValue.hpp>
25 #include <com/sun/star/container/XIndexContainer.hpp>
26 #include <com/sun/star/container/XNameContainer.hpp>
27 #include <com/sun/star/document/IndexedPropertyValues.hpp>
28 #include <com/sun/star/document/XViewDataSupplier.hpp>
29 #include <com/sun/star/document/NamedPropertyValues.hpp>
30 #include <osl/diagnose.h>
31 #include <unotools/mediadescriptor.hxx>
32 #include <oox/core/filterbase.hxx>
33 #include <oox/helper/attributelist.hxx>
34 #include <oox/helper/containerhelper.hxx>
35 #include <oox/helper/propertymap.hxx>
36 #include <oox/helper/propertyset.hxx>
37 #include "addressconverter.hxx"
38 #include "biffinputstream.hxx"
39 #include "unitconverter.hxx"
40 #include "workbooksettings.hxx"
41 #include "worksheetbuffer.hxx"
43 namespace oox {
44 namespace xls {
46 using namespace ::com::sun::star::awt;
47 using namespace ::com::sun::star::container;
48 using namespace ::com::sun::star::document;
49 using namespace ::com::sun::star::table;
50 using namespace ::com::sun::star::uno;
52 using ::oox::core::FilterBase;
54 namespace {
56 const sal_Int32 OOX_BOOKVIEW_TABBARRATIO_DEF = 600; /// Default tabbar ratio.
57 const sal_Int32 OOX_SHEETVIEW_NORMALZOOM_DEF = 100; /// Default zoom for normal view.
58 const sal_Int32 OOX_SHEETVIEW_SHEETLAYZOOM_DEF = 60; /// Default zoom for pagebreak preview.
60 const sal_uInt8 BIFF12_PANE_FROZEN = 0x01;
61 const sal_uInt8 BIFF12_PANE_FROZENNOSPLIT = 0x02;
63 const sal_uInt16 BIFF12_SHEETVIEW_SHOWFORMULAS = 0x0002;
64 const sal_uInt16 BIFF12_SHEETVIEW_SHOWGRID = 0x0004;
65 const sal_uInt16 BIFF12_SHEETVIEW_SHOWHEADINGS = 0x0008;
66 const sal_uInt16 BIFF12_SHEETVIEW_SHOWZEROS = 0x0010;
67 const sal_uInt16 BIFF12_SHEETVIEW_RIGHTTOLEFT = 0x0020;
68 const sal_uInt16 BIFF12_SHEETVIEW_SELECTED = 0x0040;
69 const sal_uInt16 BIFF12_SHEETVIEW_SHOWOUTLINE = 0x0100;
70 const sal_uInt16 BIFF12_SHEETVIEW_DEFGRIDCOLOR = 0x0200;
72 const sal_uInt16 BIFF12_CHARTSHEETVIEW_SELECTED = 0x0001;
73 const sal_uInt16 BIFF12_CHARTSHEETVIEW_ZOOMTOFIT = 0x0002;
75 const sal_uInt8 BIFF12_WBVIEW_HIDDEN = 0x01;
76 const sal_uInt8 BIFF12_WBVIEW_MINIMIZED = 0x02;
77 const sal_uInt8 BIFF12_WBVIEW_SHOWHORSCROLL = 0x08;
78 const sal_uInt8 BIFF12_WBVIEW_SHOWVERSCROLL = 0x10;
79 const sal_uInt8 BIFF12_WBVIEW_SHOWTABBAR = 0x20;
81 // Attention: view settings in Calc do not use com.sun.star.view.DocumentZoomType!
82 const sal_Int16 API_ZOOMTYPE_PERCENT = 0; /// Zoom value in percent.
84 const sal_Int32 API_ZOOMVALUE_MIN = 20; /// Minimum zoom in Calc.
85 const sal_Int32 API_ZOOMVALUE_MAX = 400; /// Maximum zoom in Calc.
87 // no predefined constants for split mode
88 const sal_Int16 API_SPLITMODE_NONE = 0; /// No splits in window.
89 const sal_Int16 API_SPLITMODE_SPLIT = 1; /// Window is split.
90 const sal_Int16 API_SPLITMODE_FREEZE = 2; /// Window has frozen panes.
92 // no predefined constants for pane idetifiers
93 const sal_Int16 API_SPLITPANE_TOPLEFT = 0; /// Top-left, or top pane.
94 const sal_Int16 API_SPLITPANE_TOPRIGHT = 1; /// Top-right pane.
95 const sal_Int16 API_SPLITPANE_BOTTOMLEFT = 2; /// Bottom-left, bottom, left, or single pane.
96 const sal_Int16 API_SPLITPANE_BOTTOMRIGHT = 3; /// Bottom-right, or right pane.
98 /** Returns the OOXML pane identifier from the passed BIFF pane id. */
99 sal_Int32 lclGetOoxPaneId( sal_Int32 nBiffPaneId, sal_Int32 nDefaultPaneId )
101 static const sal_Int32 spnPaneIds[] = { XML_bottomRight, XML_topRight, XML_bottomLeft, XML_topLeft };
102 return STATIC_ARRAY_SELECT( spnPaneIds, nBiffPaneId, nDefaultPaneId );
105 } // namespace
107 PaneSelectionModel::PaneSelectionModel() :
108 mnActiveCellId( 0 )
112 SheetViewModel::SheetViewModel() :
113 mnWorkbookViewId( 0 ),
114 mnViewType( XML_normal ),
115 mnActivePaneId( XML_topLeft ),
116 mnPaneState( XML_split ),
117 mfSplitX( 0.0 ),
118 mfSplitY( 0.0 ),
119 mnCurrentZoom( 0 ),
120 mnNormalZoom( 0 ),
121 mnSheetLayoutZoom( 0 ),
122 mnPageLayoutZoom( 0 ),
123 mbSelected( false ),
124 mbRightToLeft( false ),
125 mbDefGridColor( true ),
126 mbShowFormulas( false ),
127 mbShowGrid( true ),
128 mbShowHeadings( true ),
129 mbShowZeros( true ),
130 mbShowOutline( true ),
131 mbZoomToFit( false )
133 maGridColor.setIndexed( OOX_COLOR_WINDOWTEXT );
136 bool SheetViewModel::isPageBreakPreview() const
138 return mnViewType == XML_pageBreakPreview;
141 sal_Int32 SheetViewModel::getNormalZoom() const
143 const sal_Int32& rnZoom = isPageBreakPreview() ? mnNormalZoom : mnCurrentZoom;
144 sal_Int32 nZoom = (rnZoom > 0) ? rnZoom : OOX_SHEETVIEW_NORMALZOOM_DEF;
145 return getLimitedValue< sal_Int32 >( nZoom, API_ZOOMVALUE_MIN, API_ZOOMVALUE_MAX );
148 sal_Int32 SheetViewModel::getPageBreakZoom() const
150 const sal_Int32& rnZoom = isPageBreakPreview() ? mnCurrentZoom : mnSheetLayoutZoom;
151 sal_Int32 nZoom = (rnZoom > 0) ? rnZoom : OOX_SHEETVIEW_SHEETLAYZOOM_DEF;
152 return getLimitedValue< sal_Int32 >( nZoom, API_ZOOMVALUE_MIN, API_ZOOMVALUE_MAX );
155 sal_Int32 SheetViewModel::getGridColor( const FilterBase& rFilter ) const
157 return mbDefGridColor ? API_RGB_TRANSPARENT : maGridColor.getColor( rFilter.getGraphicHelper() );
160 const PaneSelectionModel* SheetViewModel::getPaneSelection( sal_Int32 nPaneId ) const
162 return maPaneSelMap.get( nPaneId ).get();
165 const PaneSelectionModel* SheetViewModel::getActiveSelection() const
167 return getPaneSelection( mnActivePaneId );
170 PaneSelectionModel& SheetViewModel::createPaneSelection( sal_Int32 nPaneId )
172 PaneSelectionModelMap::mapped_type& rxPaneSel = maPaneSelMap[ nPaneId ];
173 if( !rxPaneSel )
174 rxPaneSel.reset( new PaneSelectionModel );
175 return *rxPaneSel;
178 SheetViewSettings::SheetViewSettings( const WorksheetHelper& rHelper ) :
179 WorksheetHelper( rHelper )
183 void SheetViewSettings::importSheetView( const AttributeList& rAttribs )
185 SheetViewModel& rModel = *createSheetView();
186 rModel.maGridColor.setIndexed( rAttribs.getInteger( XML_colorId, OOX_COLOR_WINDOWTEXT ) );
187 rModel.maFirstPos = getAddressConverter().createValidCellAddress( rAttribs.getString( XML_topLeftCell, OUString() ), getSheetIndex(), false );
188 rModel.mnWorkbookViewId = rAttribs.getToken( XML_workbookViewId, 0 );
189 rModel.mnViewType = rAttribs.getToken( XML_view, XML_normal );
190 rModel.mnCurrentZoom = rAttribs.getInteger( XML_zoomScale, 100 );
191 rModel.mnNormalZoom = rAttribs.getInteger( XML_zoomScaleNormal, 0 );
192 rModel.mnSheetLayoutZoom = rAttribs.getInteger( XML_zoomScaleSheetLayoutView, 0 );
193 rModel.mnPageLayoutZoom = rAttribs.getInteger( XML_zoomScalePageLayoutView, 0 );
194 rModel.mbSelected = rAttribs.getBool( XML_tabSelected, false );
195 rModel.mbRightToLeft = rAttribs.getBool( XML_rightToLeft, false );
196 rModel.mbDefGridColor = rAttribs.getBool( XML_defaultGridColor, true );
197 rModel.mbShowFormulas = rAttribs.getBool( XML_showFormulas, false );
198 rModel.mbShowGrid = rAttribs.getBool( XML_showGridLines, true );
199 rModel.mbShowHeadings = rAttribs.getBool( XML_showRowColHeaders, true );
200 rModel.mbShowZeros = rAttribs.getBool( XML_showZeros, true );
201 rModel.mbShowOutline = rAttribs.getBool( XML_showOutlineSymbols, true );
204 void SheetViewSettings::importPane( const AttributeList& rAttribs )
206 OSL_ENSURE( !maSheetViews.empty(), "SheetViewSettings::importPane - missing sheet view model" );
207 if( !maSheetViews.empty() )
209 SheetViewModel& rModel = *maSheetViews.back();
210 rModel.maSecondPos = getAddressConverter().createValidCellAddress( rAttribs.getString( XML_topLeftCell, OUString() ), getSheetIndex(), false );
211 rModel.mnActivePaneId = rAttribs.getToken( XML_activePane, XML_topLeft );
212 rModel.mnPaneState = rAttribs.getToken( XML_state, XML_split );
213 rModel.mfSplitX = rAttribs.getDouble( XML_xSplit, 0.0 );
214 rModel.mfSplitY = rAttribs.getDouble( XML_ySplit, 0.0 );
218 void SheetViewSettings::importSelection( const AttributeList& rAttribs )
220 OSL_ENSURE( !maSheetViews.empty(), "SheetViewSettings::importSelection - missing sheet view model" );
221 if( !maSheetViews.empty() )
223 // pane this selection belongs to
224 sal_Int32 nPaneId = rAttribs.getToken( XML_pane, XML_topLeft );
225 PaneSelectionModel& rSelData = maSheetViews.back()->createPaneSelection( nPaneId );
226 // cursor position
227 rSelData.maActiveCell = getAddressConverter().createValidCellAddress( rAttribs.getString( XML_activeCell, OUString() ), getSheetIndex(), false );
228 rSelData.mnActiveCellId = rAttribs.getInteger( XML_activeCellId, 0 );
229 // selection
230 rSelData.maSelection.clear();
231 getAddressConverter().convertToCellRangeList( rSelData.maSelection, rAttribs.getString( XML_sqref, OUString() ), getSheetIndex(), false );
235 void SheetViewSettings::importChartSheetView( const AttributeList& rAttribs )
237 SheetViewModel& rModel = *createSheetView();
238 rModel.mnWorkbookViewId = rAttribs.getToken( XML_workbookViewId, 0 );
239 rModel.mnCurrentZoom = rAttribs.getInteger( XML_zoomScale, 100 );
240 rModel.mbSelected = rAttribs.getBool( XML_tabSelected, false );
241 rModel.mbZoomToFit = rAttribs.getBool( XML_zoomToFit, false );
244 void SheetViewSettings::importSheetView( SequenceInputStream& rStrm )
246 SheetViewModel& rModel = *createSheetView();
247 sal_uInt16 nFlags;
248 sal_Int32 nViewType;
249 BinAddress aFirstPos;
250 nFlags = rStrm.readuInt16();
251 nViewType = rStrm.readInt32();
252 rStrm >> aFirstPos;
253 rModel.maGridColor.importColorId( rStrm );
254 rModel.mnCurrentZoom = rStrm.readuInt16();
255 rModel.mnNormalZoom = rStrm.readuInt16();
256 rModel.mnSheetLayoutZoom = rStrm.readuInt16();
257 rModel.mnPageLayoutZoom = rStrm.readuInt16();
258 rModel.mnWorkbookViewId = rStrm.readInt32();
260 rModel.maFirstPos = getAddressConverter().createValidCellAddress( aFirstPos, getSheetIndex(), false );
261 static const sal_Int32 spnViewTypes[] = { XML_normal, XML_pageBreakPreview, XML_pageLayout };
262 rModel.mnViewType = STATIC_ARRAY_SELECT( spnViewTypes, nViewType, XML_normal );
263 rModel.mbSelected = getFlag( nFlags, BIFF12_SHEETVIEW_SELECTED );
264 rModel.mbRightToLeft = getFlag( nFlags, BIFF12_SHEETVIEW_RIGHTTOLEFT );
265 rModel.mbDefGridColor = getFlag( nFlags, BIFF12_SHEETVIEW_DEFGRIDCOLOR );
266 rModel.mbShowFormulas = getFlag( nFlags, BIFF12_SHEETVIEW_SHOWFORMULAS );
267 rModel.mbShowGrid = getFlag( nFlags, BIFF12_SHEETVIEW_SHOWGRID );
268 rModel.mbShowHeadings = getFlag( nFlags, BIFF12_SHEETVIEW_SHOWHEADINGS );
269 rModel.mbShowZeros = getFlag( nFlags, BIFF12_SHEETVIEW_SHOWZEROS );
270 rModel.mbShowOutline = getFlag( nFlags, BIFF12_SHEETVIEW_SHOWOUTLINE );
273 void SheetViewSettings::importPane( SequenceInputStream& rStrm )
275 OSL_ENSURE( !maSheetViews.empty(), "SheetViewSettings::importPane - missing sheet view model" );
276 if( !maSheetViews.empty() )
278 SheetViewModel& rModel = *maSheetViews.back();
280 BinAddress aSecondPos;
281 sal_Int32 nActivePaneId;
282 sal_uInt8 nFlags;
283 rModel.mfSplitX = rStrm.readDouble();
284 rModel.mfSplitY = rStrm.readDouble();
285 rStrm >> aSecondPos;
286 nActivePaneId = rStrm.readInt32();
287 nFlags = rStrm.readuChar();
289 rModel.maSecondPos = getAddressConverter().createValidCellAddress( aSecondPos, getSheetIndex(), false );
290 rModel.mnActivePaneId = lclGetOoxPaneId( nActivePaneId, XML_topLeft );
291 rModel.mnPaneState = getFlagValue( nFlags, BIFF12_PANE_FROZEN, getFlagValue( nFlags, BIFF12_PANE_FROZENNOSPLIT, XML_frozen, XML_frozenSplit ), XML_split );
295 void SheetViewSettings::importSelection( SequenceInputStream& rStrm )
297 OSL_ENSURE( !maSheetViews.empty(), "SheetViewSettings::importSelection - missing sheet view model" );
298 if( !maSheetViews.empty() )
300 // pane this selection belongs to
301 sal_Int32 nPaneId = rStrm.readInt32();
302 PaneSelectionModel& rPaneSel = maSheetViews.back()->createPaneSelection( lclGetOoxPaneId( nPaneId, -1 ) );
303 // cursor position
304 BinAddress aActiveCell;
305 rStrm >> aActiveCell;
306 rPaneSel.mnActiveCellId = rStrm.readInt32();
307 rPaneSel.maActiveCell = getAddressConverter().createValidCellAddress( aActiveCell, getSheetIndex(), false );
308 // selection
309 BinRangeList aSelection;
310 rStrm >> aSelection;
311 rPaneSel.maSelection.clear();
312 getAddressConverter().convertToCellRangeList( rPaneSel.maSelection, aSelection, getSheetIndex(), false );
316 void SheetViewSettings::importChartSheetView( SequenceInputStream& rStrm )
318 SheetViewModel& rModel = *createSheetView();
319 sal_uInt16 nFlags;
320 nFlags = rStrm.readuInt16();
321 rModel.mnCurrentZoom = rStrm.readInt32();
322 rModel.mnWorkbookViewId = rStrm.readInt32();
324 rModel.mbSelected = getFlag( nFlags, BIFF12_CHARTSHEETVIEW_SELECTED );
325 rModel.mbZoomToFit = getFlag( nFlags, BIFF12_CHARTSHEETVIEW_ZOOMTOFIT );
328 void SheetViewSettings::finalizeImport()
330 // force creation of sheet view model to get the Excel defaults
331 SheetViewModelRef xModel = maSheetViews.empty() ? createSheetView() : maSheetViews.front();
333 // #i59590# #158194# special handling for chart sheets (Excel ignores some settings in chart sheets)
334 if( getSheetType() == SHEETTYPE_CHARTSHEET )
336 xModel->maPaneSelMap.clear();
337 xModel->maFirstPos = xModel->maSecondPos = CellAddress( getSheetIndex(), 0, 0 );
338 xModel->mnViewType = XML_normal;
339 xModel->mnActivePaneId = XML_topLeft;
340 xModel->mnPaneState = XML_split;
341 xModel->mfSplitX = xModel->mfSplitY = 0.0;
342 xModel->mbRightToLeft = false;
343 xModel->mbDefGridColor = true;
344 xModel->mbShowFormulas = false;
345 xModel->mbShowGrid = true;
346 xModel->mbShowHeadings = true;
347 xModel->mbShowZeros = true;
348 xModel->mbShowOutline = true;
351 // sheet selected (active sheet must be selected)
352 bool bSelected = xModel->mbSelected || (getSheetIndex() == getViewSettings().getActiveCalcSheet());
353 if ( bSelected )
355 // active tab/sheet cannot be hidden
356 // always force it to be displayed
357 PropertySet aPropSet( getSheet() );
358 aPropSet.setProperty( PROP_IsVisible, sal_True );
360 // visible area and current cursor position (selection not supported via API)
361 CellAddress aFirstPos = xModel->maFirstPos;
362 const PaneSelectionModel* pPaneSel = xModel->getActiveSelection();
363 CellAddress aCursor = pPaneSel ? pPaneSel->maActiveCell : aFirstPos;
365 // freeze/split position default
366 sal_Int16 nHSplitMode = API_SPLITMODE_NONE;
367 sal_Int16 nVSplitMode = API_SPLITMODE_NONE;
368 sal_Int32 nHSplitPos = 0;
369 sal_Int32 nVSplitPos = 0;
370 // active pane default
371 sal_Int16 nActivePane = API_SPLITPANE_BOTTOMLEFT;
373 // freeze/split position
374 if( (xModel->mnPaneState == XML_frozen) || (xModel->mnPaneState == XML_frozenSplit) )
376 /* Frozen panes: handle split position as row/column positions.
377 #i35812# Excel uses number of visible rows/columns in the
378 frozen area (rows/columns scolled outside are not incuded),
379 Calc uses absolute position of first unfrozen row/column. */
380 const CellAddress& rMaxApiPos = getAddressConverter().getMaxApiAddress();
381 if( (xModel->mfSplitX >= 1.0) && (xModel->maFirstPos.Column + xModel->mfSplitX <= rMaxApiPos.Column) )
382 nHSplitPos = static_cast< sal_Int32 >( xModel->maFirstPos.Column + xModel->mfSplitX );
383 nHSplitMode = (nHSplitPos > 0) ? API_SPLITMODE_FREEZE : API_SPLITMODE_NONE;
384 if( (xModel->mfSplitY >= 1.0) && (xModel->maFirstPos.Row + xModel->mfSplitY <= rMaxApiPos.Row) )
385 nVSplitPos = static_cast< sal_Int32 >( xModel->maFirstPos.Row + xModel->mfSplitY );
386 nVSplitMode = (nVSplitPos > 0) ? API_SPLITMODE_FREEZE : API_SPLITMODE_NONE;
388 else if( xModel->mnPaneState == XML_split )
390 // split window: view settings API uses twips...
391 nHSplitPos = getLimitedValue< sal_Int32, double >( xModel->mfSplitX + 0.5, 0, SAL_MAX_INT32 );
392 nHSplitMode = (nHSplitPos > 0) ? API_SPLITMODE_SPLIT : API_SPLITMODE_NONE;
393 nVSplitPos = getLimitedValue< sal_Int32, double >( xModel->mfSplitY + 0.5, 0, SAL_MAX_INT32 );
394 nVSplitMode = (nVSplitPos > 0) ? API_SPLITMODE_SPLIT : API_SPLITMODE_NONE;
397 // active pane
398 switch( xModel->mnActivePaneId )
400 // no horizontal split -> always use left panes
401 // no vertical split -> always use *bottom* panes
402 case XML_topLeft:
403 nActivePane = (nVSplitMode == API_SPLITMODE_NONE) ? API_SPLITPANE_BOTTOMLEFT : API_SPLITPANE_TOPLEFT;
404 break;
405 case XML_topRight:
406 nActivePane = (nHSplitMode == API_SPLITMODE_NONE) ?
407 ((nVSplitMode == API_SPLITMODE_NONE) ? API_SPLITPANE_BOTTOMLEFT : API_SPLITPANE_TOPLEFT) :
408 ((nVSplitMode == API_SPLITMODE_NONE) ? API_SPLITPANE_BOTTOMRIGHT : API_SPLITPANE_TOPRIGHT);
409 break;
410 case XML_bottomLeft:
411 nActivePane = API_SPLITPANE_BOTTOMLEFT;
412 break;
413 case XML_bottomRight:
414 nActivePane = (nHSplitMode == API_SPLITMODE_NONE) ? API_SPLITPANE_BOTTOMLEFT : API_SPLITPANE_BOTTOMRIGHT;
415 break;
418 // write the sheet view settings into the property sequence
419 PropertyMap aPropMap;
420 aPropMap.setProperty( PROP_TableSelected, bSelected);
421 aPropMap.setProperty( PROP_CursorPositionX, aCursor.Column);
422 aPropMap.setProperty( PROP_CursorPositionY, aCursor.Row);
423 aPropMap.setProperty( PROP_HorizontalSplitMode, nHSplitMode);
424 aPropMap.setProperty( PROP_VerticalSplitMode, nVSplitMode);
425 aPropMap.setProperty( PROP_HorizontalSplitPositionTwips, nHSplitPos);
426 aPropMap.setProperty( PROP_VerticalSplitPositionTwips, nVSplitPos);
427 aPropMap.setProperty( PROP_ActiveSplitRange, nActivePane);
428 aPropMap.setProperty( PROP_PositionLeft, aFirstPos.Column);
429 aPropMap.setProperty( PROP_PositionTop, aFirstPos.Row);
430 aPropMap.setProperty( PROP_PositionRight, xModel->maSecondPos.Column);
431 aPropMap.setProperty( PROP_PositionBottom, ((nVSplitPos > 0) ? xModel->maSecondPos.Row : xModel->maFirstPos.Row));
432 aPropMap.setProperty( PROP_ZoomType, API_ZOOMTYPE_PERCENT);
433 aPropMap.setProperty( PROP_ZoomValue, static_cast< sal_Int16 >( xModel->getNormalZoom() ));
434 aPropMap.setProperty( PROP_PageViewZoomValue, static_cast< sal_Int16 >( xModel->getPageBreakZoom() ));
435 aPropMap.setProperty( PROP_GridColor, xModel->getGridColor( getBaseFilter() ));
436 aPropMap.setProperty( PROP_ShowPageBreakPreview, xModel->isPageBreakPreview());
437 aPropMap.setProperty( PROP_ShowFormulas, xModel->mbShowFormulas);
438 aPropMap.setProperty( PROP_ShowGrid, xModel->mbShowGrid);
439 aPropMap.setProperty( PROP_HasColumnRowHeaders, xModel->mbShowHeadings);
440 aPropMap.setProperty( PROP_ShowZeroValues, xModel->mbShowZeros);
441 aPropMap.setProperty( PROP_IsOutlineSymbolsSet, xModel->mbShowOutline);
443 // store sheet view settings in global view settings object
444 getViewSettings().setSheetViewSettings( getSheetIndex(), xModel, Any( aPropMap.makePropertyValueSequence() ) );
447 bool SheetViewSettings::isSheetRightToLeft() const
449 return !maSheetViews.empty() && maSheetViews.front()->mbRightToLeft;
452 // private --------------------------------------------------------------------
454 SheetViewModelRef SheetViewSettings::createSheetView()
456 SheetViewModelRef xModel( new SheetViewModel );
457 maSheetViews.push_back( xModel );
458 return xModel;
461 WorkbookViewModel::WorkbookViewModel() :
462 mnWinX( 0 ),
463 mnWinY( 0 ),
464 mnWinWidth( 0 ),
465 mnWinHeight( 0 ),
466 mnActiveSheet( 0 ),
467 mnFirstVisSheet( 0 ),
468 mnTabBarWidth( OOX_BOOKVIEW_TABBARRATIO_DEF ),
469 mnVisibility( XML_visible ),
470 mbShowTabBar( true ),
471 mbShowHorScroll( true ),
472 mbShowVerScroll( true ),
473 mbMinimized( false )
477 ViewSettings::ViewSettings( const WorkbookHelper& rHelper ) :
478 WorkbookHelper( rHelper ),
479 mbValidOleSize( false )
483 void ViewSettings::importWorkbookView( const AttributeList& rAttribs )
485 WorkbookViewModel& rModel = createWorkbookView();
486 rModel.mnWinX = rAttribs.getInteger( XML_xWindow, 0 );
487 rModel.mnWinY = rAttribs.getInteger( XML_yWindow, 0 );
488 rModel.mnWinWidth = rAttribs.getInteger( XML_windowWidth, 0 );
489 rModel.mnWinHeight = rAttribs.getInteger( XML_windowHeight, 0 );
490 rModel.mnActiveSheet = rAttribs.getInteger( XML_activeTab, 0 );
491 rModel.mnFirstVisSheet = rAttribs.getInteger( XML_firstSheet, 0 );
492 rModel.mnTabBarWidth = rAttribs.getInteger( XML_tabRatio, 600 );
493 rModel.mnVisibility = rAttribs.getToken( XML_visibility, XML_visible );
494 rModel.mbShowTabBar = rAttribs.getBool( XML_showSheetTabs, true );
495 rModel.mbShowHorScroll = rAttribs.getBool( XML_showHorizontalScroll, true );
496 rModel.mbShowVerScroll = rAttribs.getBool( XML_showVerticalScroll, true );
497 rModel.mbMinimized = rAttribs.getBool( XML_minimized, false );
500 void ViewSettings::importOleSize( const AttributeList& rAttribs )
502 OUString aRange = rAttribs.getString( XML_ref, OUString() );
503 mbValidOleSize = getAddressConverter().convertToCellRange( maOleSize, aRange, 0, true, false );
506 void ViewSettings::importWorkbookView( SequenceInputStream& rStrm )
508 WorkbookViewModel& rModel = createWorkbookView();
509 sal_uInt8 nFlags;
510 rModel.mnWinX = rStrm.readInt32();
511 rModel.mnWinY = rStrm.readInt32();
512 rModel.mnWinWidth = rStrm.readInt32();
513 rModel.mnWinHeight = rStrm.readInt32();
514 rModel.mnTabBarWidth = rStrm.readInt32();
515 rModel.mnFirstVisSheet = rStrm.readInt32();
516 rModel.mnActiveSheet = rStrm.readInt32();
517 nFlags = rStrm.readuChar();
518 rModel.mnVisibility = getFlagValue( nFlags, BIFF12_WBVIEW_HIDDEN, XML_hidden, XML_visible );
519 rModel.mbShowTabBar = getFlag( nFlags, BIFF12_WBVIEW_SHOWTABBAR );
520 rModel.mbShowHorScroll = getFlag( nFlags, BIFF12_WBVIEW_SHOWHORSCROLL );
521 rModel.mbShowVerScroll = getFlag( nFlags, BIFF12_WBVIEW_SHOWVERSCROLL );
522 rModel.mbMinimized = getFlag( nFlags, BIFF12_WBVIEW_MINIMIZED );
525 void ViewSettings::importOleSize( SequenceInputStream& rStrm )
527 BinRange aBinRange;
528 rStrm >> aBinRange;
529 mbValidOleSize = getAddressConverter().convertToCellRange( maOleSize, aBinRange, 0, true, false );
532 void ViewSettings::setSheetViewSettings( sal_Int16 nSheet, const SheetViewModelRef& rxSheetView, const Any& rProperties )
534 maSheetViews[ nSheet ] = rxSheetView;
535 maSheetProps[ nSheet ] = rProperties;
538 void ViewSettings::setSheetUsedArea( const CellRangeAddress& rUsedArea )
540 maSheetUsedAreas[ rUsedArea.Sheet ] = rUsedArea;
543 void ViewSettings::finalizeImport()
545 const WorksheetBuffer& rWorksheets = getWorksheets();
546 if( rWorksheets.getWorksheetCount() <= 0 ) return;
548 // force creation of workbook view model to get the Excel defaults
549 const WorkbookViewModel& rModel = maBookViews.empty() ? createWorkbookView() : *maBookViews.front();
551 // show object mode is part of workbook settings
552 sal_Int16 nShowMode = getWorkbookSettings().getApiShowObjectMode();
554 // view settings for all sheets
555 Reference< XNameContainer > xSheetsNC = NamedPropertyValues::create( getBaseFilter().getComponentContext() );
556 if( !xSheetsNC.is() ) return;
557 for( SheetPropertiesMap::const_iterator aIt = maSheetProps.begin(), aEnd = maSheetProps.end(); aIt != aEnd; ++aIt )
558 ContainerHelper::insertByName( xSheetsNC, rWorksheets.getCalcSheetName( aIt->first ), aIt->second );
560 // use active sheet to set sheet properties that are document-global in Calc
561 sal_Int16 nActiveSheet = getActiveCalcSheet();
562 SheetViewModelRef& rxActiveSheetView = maSheetViews[ nActiveSheet ];
563 OSL_ENSURE( rxActiveSheetView.get(), "ViewSettings::finalizeImport - missing active sheet view settings" );
564 if( !rxActiveSheetView )
565 rxActiveSheetView.reset( new SheetViewModel );
567 Reference< XIndexContainer > xContainer = IndexedPropertyValues::create( getBaseFilter().getComponentContext() );
568 if( xContainer.is() ) try
570 PropertyMap aPropMap;
571 aPropMap.setProperty( PROP_Tables, xSheetsNC);
572 aPropMap.setProperty( PROP_ActiveTable, rWorksheets.getCalcSheetName( nActiveSheet ));
573 aPropMap.setProperty( PROP_HasHorizontalScrollBar, rModel.mbShowHorScroll);
574 aPropMap.setProperty( PROP_HasVerticalScrollBar, rModel.mbShowVerScroll);
575 aPropMap.setProperty( PROP_HasSheetTabs, rModel.mbShowTabBar);
576 aPropMap.setProperty( PROP_RelativeHorizontalTabbarWidth, double( rModel.mnTabBarWidth / 1000.0 ));
577 aPropMap.setProperty( PROP_ShowObjects, nShowMode);
578 aPropMap.setProperty( PROP_ShowCharts, nShowMode);
579 aPropMap.setProperty( PROP_ShowDrawing, nShowMode);
580 aPropMap.setProperty( PROP_GridColor, rxActiveSheetView->getGridColor( getBaseFilter() ));
581 aPropMap.setProperty( PROP_ShowPageBreakPreview, rxActiveSheetView->isPageBreakPreview());
582 aPropMap.setProperty( PROP_ShowFormulas, rxActiveSheetView->mbShowFormulas);
583 aPropMap.setProperty( PROP_ShowGrid, rxActiveSheetView->mbShowGrid);
584 aPropMap.setProperty( PROP_HasColumnRowHeaders, rxActiveSheetView->mbShowHeadings);
585 aPropMap.setProperty( PROP_ShowZeroValues, rxActiveSheetView->mbShowZeros);
586 aPropMap.setProperty( PROP_IsOutlineSymbolsSet, rxActiveSheetView->mbShowOutline);
588 xContainer->insertByIndex( 0, Any( aPropMap.makePropertyValueSequence() ) );
589 Reference< XViewDataSupplier > xViewDataSuppl( getDocument(), UNO_QUERY_THROW );
590 xViewDataSuppl->setViewData( xContainer );
592 catch( Exception& )
594 OSL_FAIL( "ViewSettings::finalizeImport - cannot create document view settings" );
597 /* Set visible area to be used if this document is an embedded OLE object.
598 #i44077# If a new OLE object is inserted from file, there is no OLESIZE
599 record in the Excel file. In this case, use the used area calculated
600 from file contents (used cells and drawing objects). */
601 maOleSize.Sheet = nActiveSheet;
602 const CellRangeAddress* pVisibleArea = mbValidOleSize ?
603 &maOleSize : ContainerHelper::getMapElement( maSheetUsedAreas, nActiveSheet );
604 if( pVisibleArea )
606 // calculate the visible area in units of 1/100 mm
607 PropertySet aRangeProp( getCellRangeFromDoc( *pVisibleArea ) );
608 css::awt::Point aPos;
609 css::awt::Size aSize;
610 if( aRangeProp.getProperty( aPos, PROP_Position ) && aRangeProp.getProperty( aSize, PROP_Size ) )
612 // set the visible area as sequence of long at the media descriptor
613 Sequence< sal_Int32 > aWinExtent( 4 );
614 aWinExtent[ 0 ] = aPos.X;
615 aWinExtent[ 1 ] = aPos.Y;
616 aWinExtent[ 2 ] = aPos.X + aSize.Width;
617 aWinExtent[ 3 ] = aPos.Y + aSize.Height;
618 getBaseFilter().getMediaDescriptor()[ "WinExtent" ] <<= aWinExtent;
623 sal_Int16 ViewSettings::getActiveCalcSheet() const
625 return maBookViews.empty() ? 0 : ::std::max< sal_Int16 >( getWorksheets().getCalcSheetIndex( maBookViews.front()->mnActiveSheet ), 0 );
628 // private --------------------------------------------------------------------
630 WorkbookViewModel& ViewSettings::createWorkbookView()
632 WorkbookViewModelRef xModel( new WorkbookViewModel );
633 maBookViews.push_back( xModel );
634 return *xModel;
637 } // namespace xls
638 } // namespace oox
640 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */