1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir #include "oox/xls/viewsettings.hxx" 29*cdf0e10cSrcweir 30*cdf0e10cSrcweir #include <com/sun/star/awt/Point.hpp> 31*cdf0e10cSrcweir #include <com/sun/star/awt/Size.hpp> 32*cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp> 33*cdf0e10cSrcweir #include <com/sun/star/container/XIndexContainer.hpp> 34*cdf0e10cSrcweir #include <com/sun/star/container/XNameContainer.hpp> 35*cdf0e10cSrcweir #include <com/sun/star/document/XViewDataSupplier.hpp> 36*cdf0e10cSrcweir #include <comphelper/mediadescriptor.hxx> 37*cdf0e10cSrcweir #include "oox/core/filterbase.hxx" 38*cdf0e10cSrcweir #include "oox/helper/attributelist.hxx" 39*cdf0e10cSrcweir #include "oox/helper/containerhelper.hxx" 40*cdf0e10cSrcweir #include "oox/helper/propertymap.hxx" 41*cdf0e10cSrcweir #include "oox/helper/propertyset.hxx" 42*cdf0e10cSrcweir #include "oox/xls/addressconverter.hxx" 43*cdf0e10cSrcweir #include "oox/xls/biffinputstream.hxx" 44*cdf0e10cSrcweir #include "oox/xls/unitconverter.hxx" 45*cdf0e10cSrcweir #include "oox/xls/workbooksettings.hxx" 46*cdf0e10cSrcweir #include "oox/xls/worksheetbuffer.hxx" 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir namespace oox { 49*cdf0e10cSrcweir namespace xls { 50*cdf0e10cSrcweir 51*cdf0e10cSrcweir // ============================================================================ 52*cdf0e10cSrcweir 53*cdf0e10cSrcweir using namespace ::com::sun::star::awt; 54*cdf0e10cSrcweir using namespace ::com::sun::star::container; 55*cdf0e10cSrcweir using namespace ::com::sun::star::document; 56*cdf0e10cSrcweir using namespace ::com::sun::star::table; 57*cdf0e10cSrcweir using namespace ::com::sun::star::uno; 58*cdf0e10cSrcweir 59*cdf0e10cSrcweir using ::oox::core::FilterBase; 60*cdf0e10cSrcweir using ::rtl::OUString; 61*cdf0e10cSrcweir 62*cdf0e10cSrcweir // ============================================================================ 63*cdf0e10cSrcweir 64*cdf0e10cSrcweir namespace { 65*cdf0e10cSrcweir 66*cdf0e10cSrcweir const sal_Int32 OOX_BOOKVIEW_TABBARRATIO_DEF = 600; /// Default tabbar ratio. 67*cdf0e10cSrcweir const sal_Int32 OOX_SHEETVIEW_NORMALZOOM_DEF = 100; /// Default zoom for normal view. 68*cdf0e10cSrcweir const sal_Int32 OOX_SHEETVIEW_SHEETLAYZOOM_DEF = 60; /// Default zoom for pagebreak preview. 69*cdf0e10cSrcweir const sal_Int32 OOX_SHEETVIEW_PAGELAYZOOM_DEF = 100; /// Default zoom for page layout view. 70*cdf0e10cSrcweir 71*cdf0e10cSrcweir const sal_uInt8 BIFF12_PANE_FROZEN = 0x01; 72*cdf0e10cSrcweir const sal_uInt8 BIFF12_PANE_FROZENNOSPLIT = 0x02; 73*cdf0e10cSrcweir 74*cdf0e10cSrcweir const sal_uInt16 BIFF12_SHEETVIEW_WINPROTECTED = 0x0001; 75*cdf0e10cSrcweir const sal_uInt16 BIFF12_SHEETVIEW_SHOWFORMULAS = 0x0002; 76*cdf0e10cSrcweir const sal_uInt16 BIFF12_SHEETVIEW_SHOWGRID = 0x0004; 77*cdf0e10cSrcweir const sal_uInt16 BIFF12_SHEETVIEW_SHOWHEADINGS = 0x0008; 78*cdf0e10cSrcweir const sal_uInt16 BIFF12_SHEETVIEW_SHOWZEROS = 0x0010; 79*cdf0e10cSrcweir const sal_uInt16 BIFF12_SHEETVIEW_RIGHTTOLEFT = 0x0020; 80*cdf0e10cSrcweir const sal_uInt16 BIFF12_SHEETVIEW_SELECTED = 0x0040; 81*cdf0e10cSrcweir const sal_uInt16 BIFF12_SHEETVIEW_SHOWRULER = 0x0080; 82*cdf0e10cSrcweir const sal_uInt16 BIFF12_SHEETVIEW_SHOWOUTLINE = 0x0100; 83*cdf0e10cSrcweir const sal_uInt16 BIFF12_SHEETVIEW_DEFGRIDCOLOR = 0x0200; 84*cdf0e10cSrcweir const sal_uInt16 BIFF12_SHEETVIEW_SHOWWHITESPACE = 0x0400; 85*cdf0e10cSrcweir 86*cdf0e10cSrcweir const sal_uInt16 BIFF12_CHARTSHEETVIEW_SELECTED = 0x0001; 87*cdf0e10cSrcweir const sal_uInt16 BIFF12_CHARTSHEETVIEW_ZOOMTOFIT = 0x0002; 88*cdf0e10cSrcweir 89*cdf0e10cSrcweir const sal_uInt8 BIFF12_WBVIEW_HIDDEN = 0x01; 90*cdf0e10cSrcweir const sal_uInt8 BIFF12_WBVIEW_MINIMIZED = 0x02; 91*cdf0e10cSrcweir const sal_uInt8 BIFF12_WBVIEW_SHOWHORSCROLL = 0x08; 92*cdf0e10cSrcweir const sal_uInt8 BIFF12_WBVIEW_SHOWVERSCROLL = 0x10; 93*cdf0e10cSrcweir const sal_uInt8 BIFF12_WBVIEW_SHOWTABBAR = 0x20; 94*cdf0e10cSrcweir const sal_uInt8 BIFF12_WBVIEW_AUTOFILTERGROUP = 0x40; 95*cdf0e10cSrcweir 96*cdf0e10cSrcweir const sal_uInt8 BIFF_PANE_BOTTOMRIGHT = 0; /// Bottom-right pane. 97*cdf0e10cSrcweir const sal_uInt8 BIFF_PANE_TOPRIGHT = 1; /// Right, or top-right pane. 98*cdf0e10cSrcweir const sal_uInt8 BIFF_PANE_BOTTOMLEFT = 2; /// Bottom, or bottom-left pane. 99*cdf0e10cSrcweir const sal_uInt8 BIFF_PANE_TOPLEFT = 3; /// Single, top, left, or top-left pane. 100*cdf0e10cSrcweir 101*cdf0e10cSrcweir const sal_uInt16 BIFF_WINDOW1_HIDDEN = 0x0001; 102*cdf0e10cSrcweir const sal_uInt16 BIFF_WINDOW1_MINIMIZED = 0x0002; 103*cdf0e10cSrcweir const sal_uInt16 BIFF_WINDOW1_SHOWHORSCROLL = 0x0008; 104*cdf0e10cSrcweir const sal_uInt16 BIFF_WINDOW1_SHOWVERSCROLL = 0x0010; 105*cdf0e10cSrcweir const sal_uInt16 BIFF_WINDOW1_SHOWTABBAR = 0x0020; 106*cdf0e10cSrcweir 107*cdf0e10cSrcweir const sal_uInt16 BIFF_WINDOW2_SHOWFORMULAS = 0x0001; 108*cdf0e10cSrcweir const sal_uInt16 BIFF_WINDOW2_SHOWGRID = 0x0002; 109*cdf0e10cSrcweir const sal_uInt16 BIFF_WINDOW2_SHOWHEADINGS = 0x0004; 110*cdf0e10cSrcweir const sal_uInt16 BIFF_WINDOW2_FROZEN = 0x0008; 111*cdf0e10cSrcweir const sal_uInt16 BIFF_WINDOW2_SHOWZEROS = 0x0010; 112*cdf0e10cSrcweir const sal_uInt16 BIFF_WINDOW2_DEFGRIDCOLOR = 0x0020; 113*cdf0e10cSrcweir const sal_uInt16 BIFF_WINDOW2_RIGHTTOLEFT = 0x0040; 114*cdf0e10cSrcweir const sal_uInt16 BIFF_WINDOW2_SHOWOUTLINE = 0x0080; 115*cdf0e10cSrcweir const sal_uInt16 BIFF_WINDOW2_FROZENNOSPLIT = 0x0100; 116*cdf0e10cSrcweir const sal_uInt16 BIFF_WINDOW2_SELECTED = 0x0200; 117*cdf0e10cSrcweir const sal_uInt16 BIFF_WINDOW2_DISPLAYED = 0x0400; 118*cdf0e10cSrcweir const sal_uInt16 BIFF_WINDOW2_PAGEBREAKMODE = 0x0800; 119*cdf0e10cSrcweir 120*cdf0e10cSrcweir // Attention: view settings in Calc do not use com.sun.star.view.DocumentZoomType! 121*cdf0e10cSrcweir const sal_Int16 API_ZOOMTYPE_PERCENT = 0; /// Zoom value in percent. 122*cdf0e10cSrcweir 123*cdf0e10cSrcweir const sal_Int32 API_ZOOMVALUE_MIN = 20; /// Minimum zoom in Calc. 124*cdf0e10cSrcweir const sal_Int32 API_ZOOMVALUE_MAX = 400; /// Maximum zoom in Calc. 125*cdf0e10cSrcweir 126*cdf0e10cSrcweir // no predefined constants for split mode 127*cdf0e10cSrcweir const sal_Int16 API_SPLITMODE_NONE = 0; /// No splits in window. 128*cdf0e10cSrcweir const sal_Int16 API_SPLITMODE_SPLIT = 1; /// Window is split. 129*cdf0e10cSrcweir const sal_Int16 API_SPLITMODE_FREEZE = 2; /// Window has frozen panes. 130*cdf0e10cSrcweir 131*cdf0e10cSrcweir // no predefined constants for pane idetifiers 132*cdf0e10cSrcweir const sal_Int16 API_SPLITPANE_TOPLEFT = 0; /// Top-left, or top pane. 133*cdf0e10cSrcweir const sal_Int16 API_SPLITPANE_TOPRIGHT = 1; /// Top-right pane. 134*cdf0e10cSrcweir const sal_Int16 API_SPLITPANE_BOTTOMLEFT = 2; /// Bottom-left, bottom, left, or single pane. 135*cdf0e10cSrcweir const sal_Int16 API_SPLITPANE_BOTTOMRIGHT = 3; /// Bottom-right, or right pane. 136*cdf0e10cSrcweir 137*cdf0e10cSrcweir // ---------------------------------------------------------------------------- 138*cdf0e10cSrcweir 139*cdf0e10cSrcweir /** Returns the OOXML pane identifier from the passed BIFF pane id. */ 140*cdf0e10cSrcweir sal_Int32 lclGetOoxPaneId( sal_Int32 nBiffPaneId, sal_Int32 nDefaultPaneId ) 141*cdf0e10cSrcweir { 142*cdf0e10cSrcweir static const sal_Int32 spnPaneIds[] = { XML_bottomRight, XML_topRight, XML_bottomLeft, XML_topLeft }; 143*cdf0e10cSrcweir return STATIC_ARRAY_SELECT( spnPaneIds, nBiffPaneId, nDefaultPaneId ); 144*cdf0e10cSrcweir } 145*cdf0e10cSrcweir 146*cdf0e10cSrcweir } // namespace 147*cdf0e10cSrcweir 148*cdf0e10cSrcweir // ============================================================================ 149*cdf0e10cSrcweir 150*cdf0e10cSrcweir PaneSelectionModel::PaneSelectionModel() : 151*cdf0e10cSrcweir mnActiveCellId( 0 ) 152*cdf0e10cSrcweir { 153*cdf0e10cSrcweir } 154*cdf0e10cSrcweir 155*cdf0e10cSrcweir // ---------------------------------------------------------------------------- 156*cdf0e10cSrcweir 157*cdf0e10cSrcweir SheetViewModel::SheetViewModel() : 158*cdf0e10cSrcweir mnWorkbookViewId( 0 ), 159*cdf0e10cSrcweir mnViewType( XML_normal ), 160*cdf0e10cSrcweir mnActivePaneId( XML_topLeft ), 161*cdf0e10cSrcweir mnPaneState( XML_split ), 162*cdf0e10cSrcweir mfSplitX( 0.0 ), 163*cdf0e10cSrcweir mfSplitY( 0.0 ), 164*cdf0e10cSrcweir mnCurrentZoom( 0 ), 165*cdf0e10cSrcweir mnNormalZoom( 0 ), 166*cdf0e10cSrcweir mnSheetLayoutZoom( 0 ), 167*cdf0e10cSrcweir mnPageLayoutZoom( 0 ), 168*cdf0e10cSrcweir mbSelected( false ), 169*cdf0e10cSrcweir mbRightToLeft( false ), 170*cdf0e10cSrcweir mbDefGridColor( true ), 171*cdf0e10cSrcweir mbShowFormulas( false ), 172*cdf0e10cSrcweir mbShowGrid( true ), 173*cdf0e10cSrcweir mbShowHeadings( true ), 174*cdf0e10cSrcweir mbShowZeros( true ), 175*cdf0e10cSrcweir mbShowOutline( true ), 176*cdf0e10cSrcweir mbZoomToFit( false ) 177*cdf0e10cSrcweir { 178*cdf0e10cSrcweir maGridColor.setIndexed( OOX_COLOR_WINDOWTEXT ); 179*cdf0e10cSrcweir } 180*cdf0e10cSrcweir 181*cdf0e10cSrcweir bool SheetViewModel::isPageBreakPreview() const 182*cdf0e10cSrcweir { 183*cdf0e10cSrcweir return mnViewType == XML_pageBreakPreview; 184*cdf0e10cSrcweir } 185*cdf0e10cSrcweir 186*cdf0e10cSrcweir sal_Int32 SheetViewModel::getNormalZoom() const 187*cdf0e10cSrcweir { 188*cdf0e10cSrcweir const sal_Int32& rnZoom = isPageBreakPreview() ? mnNormalZoom : mnCurrentZoom; 189*cdf0e10cSrcweir sal_Int32 nZoom = (rnZoom > 0) ? rnZoom : OOX_SHEETVIEW_NORMALZOOM_DEF; 190*cdf0e10cSrcweir return getLimitedValue< sal_Int32 >( nZoom, API_ZOOMVALUE_MIN, API_ZOOMVALUE_MAX ); 191*cdf0e10cSrcweir } 192*cdf0e10cSrcweir 193*cdf0e10cSrcweir sal_Int32 SheetViewModel::getPageBreakZoom() const 194*cdf0e10cSrcweir { 195*cdf0e10cSrcweir const sal_Int32& rnZoom = isPageBreakPreview() ? mnCurrentZoom : mnSheetLayoutZoom; 196*cdf0e10cSrcweir sal_Int32 nZoom = (rnZoom > 0) ? rnZoom : OOX_SHEETVIEW_SHEETLAYZOOM_DEF; 197*cdf0e10cSrcweir return getLimitedValue< sal_Int32 >( nZoom, API_ZOOMVALUE_MIN, API_ZOOMVALUE_MAX ); 198*cdf0e10cSrcweir } 199*cdf0e10cSrcweir 200*cdf0e10cSrcweir sal_Int32 SheetViewModel::getGridColor( const FilterBase& rFilter ) const 201*cdf0e10cSrcweir { 202*cdf0e10cSrcweir return mbDefGridColor ? API_RGB_TRANSPARENT : maGridColor.getColor( rFilter.getGraphicHelper() ); 203*cdf0e10cSrcweir } 204*cdf0e10cSrcweir 205*cdf0e10cSrcweir const PaneSelectionModel* SheetViewModel::getPaneSelection( sal_Int32 nPaneId ) const 206*cdf0e10cSrcweir { 207*cdf0e10cSrcweir return maPaneSelMap.get( nPaneId ).get(); 208*cdf0e10cSrcweir } 209*cdf0e10cSrcweir 210*cdf0e10cSrcweir const PaneSelectionModel* SheetViewModel::getActiveSelection() const 211*cdf0e10cSrcweir { 212*cdf0e10cSrcweir return getPaneSelection( mnActivePaneId ); 213*cdf0e10cSrcweir } 214*cdf0e10cSrcweir 215*cdf0e10cSrcweir PaneSelectionModel& SheetViewModel::createPaneSelection( sal_Int32 nPaneId ) 216*cdf0e10cSrcweir { 217*cdf0e10cSrcweir PaneSelectionModelMap::mapped_type& rxPaneSel = maPaneSelMap[ nPaneId ]; 218*cdf0e10cSrcweir if( !rxPaneSel ) 219*cdf0e10cSrcweir rxPaneSel.reset( new PaneSelectionModel ); 220*cdf0e10cSrcweir return *rxPaneSel; 221*cdf0e10cSrcweir } 222*cdf0e10cSrcweir 223*cdf0e10cSrcweir // ---------------------------------------------------------------------------- 224*cdf0e10cSrcweir 225*cdf0e10cSrcweir SheetViewSettings::SheetViewSettings( const WorksheetHelper& rHelper ) : 226*cdf0e10cSrcweir WorksheetHelper( rHelper ) 227*cdf0e10cSrcweir { 228*cdf0e10cSrcweir } 229*cdf0e10cSrcweir 230*cdf0e10cSrcweir void SheetViewSettings::importSheetView( const AttributeList& rAttribs ) 231*cdf0e10cSrcweir { 232*cdf0e10cSrcweir SheetViewModel& rModel = *createSheetView(); 233*cdf0e10cSrcweir rModel.maGridColor.setIndexed( rAttribs.getInteger( XML_colorId, OOX_COLOR_WINDOWTEXT ) ); 234*cdf0e10cSrcweir rModel.maFirstPos = getAddressConverter().createValidCellAddress( rAttribs.getString( XML_topLeftCell, OUString() ), getSheetIndex(), false ); 235*cdf0e10cSrcweir rModel.mnWorkbookViewId = rAttribs.getToken( XML_workbookViewId, 0 ); 236*cdf0e10cSrcweir rModel.mnViewType = rAttribs.getToken( XML_view, XML_normal ); 237*cdf0e10cSrcweir rModel.mnCurrentZoom = rAttribs.getInteger( XML_zoomScale, 100 ); 238*cdf0e10cSrcweir rModel.mnNormalZoom = rAttribs.getInteger( XML_zoomScaleNormal, 0 ); 239*cdf0e10cSrcweir rModel.mnSheetLayoutZoom = rAttribs.getInteger( XML_zoomScaleSheetLayoutView, 0 ); 240*cdf0e10cSrcweir rModel.mnPageLayoutZoom = rAttribs.getInteger( XML_zoomScalePageLayoutView, 0 ); 241*cdf0e10cSrcweir rModel.mbSelected = rAttribs.getBool( XML_tabSelected, false ); 242*cdf0e10cSrcweir rModel.mbRightToLeft = rAttribs.getBool( XML_rightToLeft, false ); 243*cdf0e10cSrcweir rModel.mbDefGridColor = rAttribs.getBool( XML_defaultGridColor, true ); 244*cdf0e10cSrcweir rModel.mbShowFormulas = rAttribs.getBool( XML_showFormulas, false ); 245*cdf0e10cSrcweir rModel.mbShowGrid = rAttribs.getBool( XML_showGridLines, true ); 246*cdf0e10cSrcweir rModel.mbShowHeadings = rAttribs.getBool( XML_showRowColHeaders, true ); 247*cdf0e10cSrcweir rModel.mbShowZeros = rAttribs.getBool( XML_showZeros, true ); 248*cdf0e10cSrcweir rModel.mbShowOutline = rAttribs.getBool( XML_showOutlineSymbols, true ); 249*cdf0e10cSrcweir } 250*cdf0e10cSrcweir 251*cdf0e10cSrcweir void SheetViewSettings::importPane( const AttributeList& rAttribs ) 252*cdf0e10cSrcweir { 253*cdf0e10cSrcweir OSL_ENSURE( !maSheetViews.empty(), "SheetViewSettings::importPane - missing sheet view model" ); 254*cdf0e10cSrcweir if( !maSheetViews.empty() ) 255*cdf0e10cSrcweir { 256*cdf0e10cSrcweir SheetViewModel& rModel = *maSheetViews.back(); 257*cdf0e10cSrcweir rModel.maSecondPos = getAddressConverter().createValidCellAddress( rAttribs.getString( XML_topLeftCell, OUString() ), getSheetIndex(), false ); 258*cdf0e10cSrcweir rModel.mnActivePaneId = rAttribs.getToken( XML_activePane, XML_topLeft ); 259*cdf0e10cSrcweir rModel.mnPaneState = rAttribs.getToken( XML_state, XML_split ); 260*cdf0e10cSrcweir rModel.mfSplitX = rAttribs.getDouble( XML_xSplit, 0.0 ); 261*cdf0e10cSrcweir rModel.mfSplitY = rAttribs.getDouble( XML_ySplit, 0.0 ); 262*cdf0e10cSrcweir } 263*cdf0e10cSrcweir } 264*cdf0e10cSrcweir 265*cdf0e10cSrcweir void SheetViewSettings::importSelection( const AttributeList& rAttribs ) 266*cdf0e10cSrcweir { 267*cdf0e10cSrcweir OSL_ENSURE( !maSheetViews.empty(), "SheetViewSettings::importSelection - missing sheet view model" ); 268*cdf0e10cSrcweir if( !maSheetViews.empty() ) 269*cdf0e10cSrcweir { 270*cdf0e10cSrcweir // pane this selection belongs to 271*cdf0e10cSrcweir sal_Int32 nPaneId = rAttribs.getToken( XML_pane, XML_topLeft ); 272*cdf0e10cSrcweir PaneSelectionModel& rSelData = maSheetViews.back()->createPaneSelection( nPaneId ); 273*cdf0e10cSrcweir // cursor position 274*cdf0e10cSrcweir rSelData.maActiveCell = getAddressConverter().createValidCellAddress( rAttribs.getString( XML_activeCell, OUString() ), getSheetIndex(), false ); 275*cdf0e10cSrcweir rSelData.mnActiveCellId = rAttribs.getInteger( XML_activeCellId, 0 ); 276*cdf0e10cSrcweir // selection 277*cdf0e10cSrcweir rSelData.maSelection.clear(); 278*cdf0e10cSrcweir getAddressConverter().convertToCellRangeList( rSelData.maSelection, rAttribs.getString( XML_sqref, OUString() ), getSheetIndex(), false ); 279*cdf0e10cSrcweir } 280*cdf0e10cSrcweir } 281*cdf0e10cSrcweir 282*cdf0e10cSrcweir void SheetViewSettings::importChartSheetView( const AttributeList& rAttribs ) 283*cdf0e10cSrcweir { 284*cdf0e10cSrcweir SheetViewModel& rModel = *createSheetView(); 285*cdf0e10cSrcweir rModel.mnWorkbookViewId = rAttribs.getToken( XML_workbookViewId, 0 ); 286*cdf0e10cSrcweir rModel.mnCurrentZoom = rAttribs.getInteger( XML_zoomScale, 100 ); 287*cdf0e10cSrcweir rModel.mbSelected = rAttribs.getBool( XML_tabSelected, false ); 288*cdf0e10cSrcweir rModel.mbZoomToFit = rAttribs.getBool( XML_zoomToFit, false ); 289*cdf0e10cSrcweir } 290*cdf0e10cSrcweir 291*cdf0e10cSrcweir void SheetViewSettings::importSheetView( SequenceInputStream& rStrm ) 292*cdf0e10cSrcweir { 293*cdf0e10cSrcweir SheetViewModel& rModel = *createSheetView(); 294*cdf0e10cSrcweir sal_uInt16 nFlags; 295*cdf0e10cSrcweir sal_Int32 nViewType; 296*cdf0e10cSrcweir BinAddress aFirstPos; 297*cdf0e10cSrcweir rStrm >> nFlags >> nViewType >> aFirstPos; 298*cdf0e10cSrcweir rModel.maGridColor.importColorId( rStrm ); 299*cdf0e10cSrcweir rModel.mnCurrentZoom = rStrm.readuInt16(); 300*cdf0e10cSrcweir rModel.mnNormalZoom = rStrm.readuInt16(); 301*cdf0e10cSrcweir rModel.mnSheetLayoutZoom = rStrm.readuInt16(); 302*cdf0e10cSrcweir rModel.mnPageLayoutZoom = rStrm.readuInt16(); 303*cdf0e10cSrcweir rStrm >> rModel.mnWorkbookViewId; 304*cdf0e10cSrcweir 305*cdf0e10cSrcweir rModel.maFirstPos = getAddressConverter().createValidCellAddress( aFirstPos, getSheetIndex(), false ); 306*cdf0e10cSrcweir static const sal_Int32 spnViewTypes[] = { XML_normal, XML_pageBreakPreview, XML_pageLayout }; 307*cdf0e10cSrcweir rModel.mnViewType = STATIC_ARRAY_SELECT( spnViewTypes, nViewType, XML_normal ); 308*cdf0e10cSrcweir rModel.mbSelected = getFlag( nFlags, BIFF12_SHEETVIEW_SELECTED ); 309*cdf0e10cSrcweir rModel.mbRightToLeft = getFlag( nFlags, BIFF12_SHEETVIEW_RIGHTTOLEFT ); 310*cdf0e10cSrcweir rModel.mbDefGridColor = getFlag( nFlags, BIFF12_SHEETVIEW_DEFGRIDCOLOR ); 311*cdf0e10cSrcweir rModel.mbShowFormulas = getFlag( nFlags, BIFF12_SHEETVIEW_SHOWFORMULAS ); 312*cdf0e10cSrcweir rModel.mbShowGrid = getFlag( nFlags, BIFF12_SHEETVIEW_SHOWGRID ); 313*cdf0e10cSrcweir rModel.mbShowHeadings = getFlag( nFlags, BIFF12_SHEETVIEW_SHOWHEADINGS ); 314*cdf0e10cSrcweir rModel.mbShowZeros = getFlag( nFlags, BIFF12_SHEETVIEW_SHOWZEROS ); 315*cdf0e10cSrcweir rModel.mbShowOutline = getFlag( nFlags, BIFF12_SHEETVIEW_SHOWOUTLINE ); 316*cdf0e10cSrcweir } 317*cdf0e10cSrcweir 318*cdf0e10cSrcweir void SheetViewSettings::importPane( SequenceInputStream& rStrm ) 319*cdf0e10cSrcweir { 320*cdf0e10cSrcweir OSL_ENSURE( !maSheetViews.empty(), "SheetViewSettings::importPane - missing sheet view model" ); 321*cdf0e10cSrcweir if( !maSheetViews.empty() ) 322*cdf0e10cSrcweir { 323*cdf0e10cSrcweir SheetViewModel& rModel = *maSheetViews.back(); 324*cdf0e10cSrcweir 325*cdf0e10cSrcweir BinAddress aSecondPos; 326*cdf0e10cSrcweir sal_Int32 nActivePaneId; 327*cdf0e10cSrcweir sal_uInt8 nFlags; 328*cdf0e10cSrcweir rStrm >> rModel.mfSplitX >> rModel.mfSplitY >> aSecondPos >> nActivePaneId >> nFlags; 329*cdf0e10cSrcweir 330*cdf0e10cSrcweir rModel.maSecondPos = getAddressConverter().createValidCellAddress( aSecondPos, getSheetIndex(), false ); 331*cdf0e10cSrcweir rModel.mnActivePaneId = lclGetOoxPaneId( nActivePaneId, XML_topLeft ); 332*cdf0e10cSrcweir rModel.mnPaneState = getFlagValue( nFlags, BIFF12_PANE_FROZEN, getFlagValue( nFlags, BIFF12_PANE_FROZENNOSPLIT, XML_frozen, XML_frozenSplit ), XML_split ); 333*cdf0e10cSrcweir } 334*cdf0e10cSrcweir } 335*cdf0e10cSrcweir 336*cdf0e10cSrcweir void SheetViewSettings::importSelection( SequenceInputStream& rStrm ) 337*cdf0e10cSrcweir { 338*cdf0e10cSrcweir OSL_ENSURE( !maSheetViews.empty(), "SheetViewSettings::importSelection - missing sheet view model" ); 339*cdf0e10cSrcweir if( !maSheetViews.empty() ) 340*cdf0e10cSrcweir { 341*cdf0e10cSrcweir // pane this selection belongs to 342*cdf0e10cSrcweir sal_Int32 nPaneId = rStrm.readInt32(); 343*cdf0e10cSrcweir PaneSelectionModel& rPaneSel = maSheetViews.back()->createPaneSelection( lclGetOoxPaneId( nPaneId, -1 ) ); 344*cdf0e10cSrcweir // cursor position 345*cdf0e10cSrcweir BinAddress aActiveCell; 346*cdf0e10cSrcweir rStrm >> aActiveCell >> rPaneSel.mnActiveCellId; 347*cdf0e10cSrcweir rPaneSel.maActiveCell = getAddressConverter().createValidCellAddress( aActiveCell, getSheetIndex(), false ); 348*cdf0e10cSrcweir // selection 349*cdf0e10cSrcweir BinRangeList aSelection; 350*cdf0e10cSrcweir rStrm >> aSelection; 351*cdf0e10cSrcweir rPaneSel.maSelection.clear(); 352*cdf0e10cSrcweir getAddressConverter().convertToCellRangeList( rPaneSel.maSelection, aSelection, getSheetIndex(), false ); 353*cdf0e10cSrcweir } 354*cdf0e10cSrcweir } 355*cdf0e10cSrcweir 356*cdf0e10cSrcweir void SheetViewSettings::importChartSheetView( SequenceInputStream& rStrm ) 357*cdf0e10cSrcweir { 358*cdf0e10cSrcweir SheetViewModel& rModel = *createSheetView(); 359*cdf0e10cSrcweir sal_uInt16 nFlags; 360*cdf0e10cSrcweir rStrm >> nFlags >> rModel.mnCurrentZoom >> rModel.mnWorkbookViewId; 361*cdf0e10cSrcweir 362*cdf0e10cSrcweir rModel.mbSelected = getFlag( nFlags, BIFF12_CHARTSHEETVIEW_SELECTED ); 363*cdf0e10cSrcweir rModel.mbZoomToFit = getFlag( nFlags, BIFF12_CHARTSHEETVIEW_ZOOMTOFIT ); 364*cdf0e10cSrcweir } 365*cdf0e10cSrcweir 366*cdf0e10cSrcweir void SheetViewSettings::importWindow2( BiffInputStream& rStrm ) 367*cdf0e10cSrcweir { 368*cdf0e10cSrcweir OSL_ENSURE( maSheetViews.empty(), "SheetViewSettings::importWindow2 - multiple WINDOW2 records" ); 369*cdf0e10cSrcweir SheetViewModel& rModel = *createSheetView(); 370*cdf0e10cSrcweir if( getBiff() == BIFF2 ) 371*cdf0e10cSrcweir { 372*cdf0e10cSrcweir rModel.mbShowFormulas = rStrm.readuInt8() != 0; 373*cdf0e10cSrcweir rModel.mbShowGrid = rStrm.readuInt8() != 0; 374*cdf0e10cSrcweir rModel.mbShowHeadings = rStrm.readuInt8() != 0; 375*cdf0e10cSrcweir rModel.mnPaneState = (rStrm.readuInt8() == 0) ? XML_split : XML_frozen; 376*cdf0e10cSrcweir rModel.mbShowZeros = rStrm.readuInt8() != 0; 377*cdf0e10cSrcweir BinAddress aFirstPos; 378*cdf0e10cSrcweir rStrm >> aFirstPos; 379*cdf0e10cSrcweir rModel.maFirstPos = getAddressConverter().createValidCellAddress( aFirstPos, getSheetIndex(), false ); 380*cdf0e10cSrcweir rModel.mbDefGridColor = rStrm.readuInt8() != 0; 381*cdf0e10cSrcweir rModel.maGridColor.importColorRgb( rStrm ); 382*cdf0e10cSrcweir } 383*cdf0e10cSrcweir else 384*cdf0e10cSrcweir { 385*cdf0e10cSrcweir sal_uInt16 nFlags; 386*cdf0e10cSrcweir BinAddress aFirstPos; 387*cdf0e10cSrcweir rStrm >> nFlags >> aFirstPos; 388*cdf0e10cSrcweir 389*cdf0e10cSrcweir rModel.maFirstPos = getAddressConverter().createValidCellAddress( aFirstPos, getSheetIndex(), false ); 390*cdf0e10cSrcweir rModel.mnPaneState = getFlagValue( nFlags, BIFF_WINDOW2_FROZEN, getFlagValue( nFlags, BIFF_WINDOW2_FROZENNOSPLIT, XML_frozen, XML_frozenSplit ), XML_split ); 391*cdf0e10cSrcweir rModel.mbSelected = getFlag( nFlags, BIFF_WINDOW2_SELECTED ); 392*cdf0e10cSrcweir rModel.mbRightToLeft = getFlag( nFlags, BIFF_WINDOW2_RIGHTTOLEFT ); 393*cdf0e10cSrcweir rModel.mbDefGridColor = getFlag( nFlags, BIFF_WINDOW2_DEFGRIDCOLOR ); 394*cdf0e10cSrcweir rModel.mbShowFormulas = getFlag( nFlags, BIFF_WINDOW2_SHOWFORMULAS ); 395*cdf0e10cSrcweir rModel.mbShowGrid = getFlag( nFlags, BIFF_WINDOW2_SHOWGRID ); 396*cdf0e10cSrcweir rModel.mbShowHeadings = getFlag( nFlags, BIFF_WINDOW2_SHOWHEADINGS ); 397*cdf0e10cSrcweir rModel.mbShowZeros = getFlag( nFlags, BIFF_WINDOW2_SHOWZEROS ); 398*cdf0e10cSrcweir rModel.mbShowOutline = getFlag( nFlags, BIFF_WINDOW2_SHOWOUTLINE ); 399*cdf0e10cSrcweir 400*cdf0e10cSrcweir if( getBiff() == BIFF8 ) 401*cdf0e10cSrcweir { 402*cdf0e10cSrcweir rModel.mnViewType = getFlagValue( nFlags, BIFF_WINDOW2_PAGEBREAKMODE, XML_pageBreakPreview, XML_normal ); 403*cdf0e10cSrcweir 404*cdf0e10cSrcweir rModel.maGridColor.importColorId( rStrm ); 405*cdf0e10cSrcweir // zoom data not included in chart sheets 406*cdf0e10cSrcweir if( (getSheetType() != SHEETTYPE_CHARTSHEET) && (rStrm.getRemaining() >= 6) ) 407*cdf0e10cSrcweir { 408*cdf0e10cSrcweir rStrm.skip( 2 ); 409*cdf0e10cSrcweir sal_uInt16 nPageZoom, nNormalZoom; 410*cdf0e10cSrcweir rStrm >> nPageZoom >> nNormalZoom; 411*cdf0e10cSrcweir rModel.mnSheetLayoutZoom = nPageZoom; 412*cdf0e10cSrcweir rModel.mnNormalZoom = nNormalZoom; 413*cdf0e10cSrcweir } 414*cdf0e10cSrcweir } 415*cdf0e10cSrcweir else 416*cdf0e10cSrcweir { 417*cdf0e10cSrcweir rModel.maGridColor.importColorRgb( rStrm ); 418*cdf0e10cSrcweir } 419*cdf0e10cSrcweir } 420*cdf0e10cSrcweir } 421*cdf0e10cSrcweir 422*cdf0e10cSrcweir void SheetViewSettings::importPane( BiffInputStream& rStrm ) 423*cdf0e10cSrcweir { 424*cdf0e10cSrcweir OSL_ENSURE( !maSheetViews.empty(), "SheetViewSettings::importPane - missing leading WINDOW2 record" ); 425*cdf0e10cSrcweir if( !maSheetViews.empty() ) 426*cdf0e10cSrcweir { 427*cdf0e10cSrcweir sal_uInt8 nActivePaneId; 428*cdf0e10cSrcweir sal_uInt16 nSplitX, nSplitY; 429*cdf0e10cSrcweir BinAddress aSecondPos; 430*cdf0e10cSrcweir rStrm >> nSplitX >> nSplitY >> aSecondPos >> nActivePaneId; 431*cdf0e10cSrcweir 432*cdf0e10cSrcweir SheetViewModel& rModel = *maSheetViews.back(); 433*cdf0e10cSrcweir rModel.mfSplitX = nSplitX; 434*cdf0e10cSrcweir rModel.mfSplitY = nSplitY; 435*cdf0e10cSrcweir rModel.maSecondPos = getAddressConverter().createValidCellAddress( aSecondPos, getSheetIndex(), false ); 436*cdf0e10cSrcweir rModel.mnActivePaneId = lclGetOoxPaneId( nActivePaneId, XML_topLeft ); 437*cdf0e10cSrcweir } 438*cdf0e10cSrcweir } 439*cdf0e10cSrcweir 440*cdf0e10cSrcweir void SheetViewSettings::importScl( BiffInputStream& rStrm ) 441*cdf0e10cSrcweir { 442*cdf0e10cSrcweir OSL_ENSURE( !maSheetViews.empty(), "SheetViewSettings::importScl - missing leading WINDOW2 record" ); 443*cdf0e10cSrcweir if( !maSheetViews.empty() ) 444*cdf0e10cSrcweir { 445*cdf0e10cSrcweir sal_uInt16 nNum, nDenom; 446*cdf0e10cSrcweir rStrm >> nNum >> nDenom; 447*cdf0e10cSrcweir OSL_ENSURE( nDenom > 0, "SheetViewSettings::importScl - invalid denominator" ); 448*cdf0e10cSrcweir if( nDenom > 0 ) 449*cdf0e10cSrcweir maSheetViews.back()->mnCurrentZoom = getLimitedValue< sal_Int32, sal_uInt16 >( (nNum * 100) / nDenom, 10, 400 ); 450*cdf0e10cSrcweir } 451*cdf0e10cSrcweir } 452*cdf0e10cSrcweir 453*cdf0e10cSrcweir void SheetViewSettings::importSelection( BiffInputStream& rStrm ) 454*cdf0e10cSrcweir { 455*cdf0e10cSrcweir OSL_ENSURE( !maSheetViews.empty(), "SheetViewSettings::importPane - missing leading WINDOW2 record" ); 456*cdf0e10cSrcweir if( !maSheetViews.empty() ) 457*cdf0e10cSrcweir { 458*cdf0e10cSrcweir // pane this selection belongs to 459*cdf0e10cSrcweir sal_uInt8 nPaneId = rStrm.readuInt8(); 460*cdf0e10cSrcweir PaneSelectionModel& rPaneSel = maSheetViews.back()->createPaneSelection( lclGetOoxPaneId( nPaneId, -1 ) ); 461*cdf0e10cSrcweir // cursor position 462*cdf0e10cSrcweir BinAddress aActiveCell; 463*cdf0e10cSrcweir sal_uInt16 nActiveCellId; 464*cdf0e10cSrcweir rStrm >> aActiveCell >> nActiveCellId; 465*cdf0e10cSrcweir rPaneSel.maActiveCell = getAddressConverter().createValidCellAddress( aActiveCell, getSheetIndex(), false ); 466*cdf0e10cSrcweir rPaneSel.mnActiveCellId = nActiveCellId; 467*cdf0e10cSrcweir // selection 468*cdf0e10cSrcweir rPaneSel.maSelection.clear(); 469*cdf0e10cSrcweir BinRangeList aSelection; 470*cdf0e10cSrcweir aSelection.read( rStrm, false ); 471*cdf0e10cSrcweir getAddressConverter().convertToCellRangeList( rPaneSel.maSelection, aSelection, getSheetIndex(), false ); 472*cdf0e10cSrcweir } 473*cdf0e10cSrcweir } 474*cdf0e10cSrcweir 475*cdf0e10cSrcweir void SheetViewSettings::finalizeImport() 476*cdf0e10cSrcweir { 477*cdf0e10cSrcweir // force creation of sheet view model to get the Excel defaults 478*cdf0e10cSrcweir SheetViewModelRef xModel = maSheetViews.empty() ? createSheetView() : maSheetViews.front(); 479*cdf0e10cSrcweir 480*cdf0e10cSrcweir // #i59590# #158194# special handling for chart sheets (Excel ignores some settings in chart sheets) 481*cdf0e10cSrcweir if( getSheetType() == SHEETTYPE_CHARTSHEET ) 482*cdf0e10cSrcweir { 483*cdf0e10cSrcweir xModel->maPaneSelMap.clear(); 484*cdf0e10cSrcweir xModel->maFirstPos = xModel->maSecondPos = CellAddress( getSheetIndex(), 0, 0 ); 485*cdf0e10cSrcweir xModel->mnViewType = XML_normal; 486*cdf0e10cSrcweir xModel->mnActivePaneId = XML_topLeft; 487*cdf0e10cSrcweir xModel->mnPaneState = XML_split; 488*cdf0e10cSrcweir xModel->mfSplitX = xModel->mfSplitY = 0.0; 489*cdf0e10cSrcweir xModel->mbRightToLeft = false; 490*cdf0e10cSrcweir xModel->mbDefGridColor = true; 491*cdf0e10cSrcweir xModel->mbShowFormulas = false; 492*cdf0e10cSrcweir xModel->mbShowGrid = true; 493*cdf0e10cSrcweir xModel->mbShowHeadings = true; 494*cdf0e10cSrcweir xModel->mbShowZeros = true; 495*cdf0e10cSrcweir xModel->mbShowOutline = true; 496*cdf0e10cSrcweir } 497*cdf0e10cSrcweir 498*cdf0e10cSrcweir // sheet selected (active sheet must be selected) 499*cdf0e10cSrcweir bool bSelected = xModel->mbSelected || (getSheetIndex() == getViewSettings().getActiveCalcSheet()); 500*cdf0e10cSrcweir 501*cdf0e10cSrcweir // visible area and current cursor position (selection not supported via API) 502*cdf0e10cSrcweir CellAddress aFirstPos = xModel->maFirstPos; 503*cdf0e10cSrcweir const PaneSelectionModel* pPaneSel = xModel->getActiveSelection(); 504*cdf0e10cSrcweir CellAddress aCursor = pPaneSel ? pPaneSel->maActiveCell : aFirstPos; 505*cdf0e10cSrcweir 506*cdf0e10cSrcweir // freeze/split position default 507*cdf0e10cSrcweir sal_Int16 nHSplitMode = API_SPLITMODE_NONE; 508*cdf0e10cSrcweir sal_Int16 nVSplitMode = API_SPLITMODE_NONE; 509*cdf0e10cSrcweir sal_Int32 nHSplitPos = 0; 510*cdf0e10cSrcweir sal_Int32 nVSplitPos = 0; 511*cdf0e10cSrcweir // active pane default 512*cdf0e10cSrcweir sal_Int16 nActivePane = API_SPLITPANE_BOTTOMLEFT; 513*cdf0e10cSrcweir 514*cdf0e10cSrcweir // freeze/split position 515*cdf0e10cSrcweir if( (xModel->mnPaneState == XML_frozen) || (xModel->mnPaneState == XML_frozenSplit) ) 516*cdf0e10cSrcweir { 517*cdf0e10cSrcweir /* Frozen panes: handle split position as row/column positions. 518*cdf0e10cSrcweir #i35812# Excel uses number of visible rows/columns in the 519*cdf0e10cSrcweir frozen area (rows/columns scolled outside are not incuded), 520*cdf0e10cSrcweir Calc uses absolute position of first unfrozen row/column. */ 521*cdf0e10cSrcweir const CellAddress& rMaxApiPos = getAddressConverter().getMaxApiAddress(); 522*cdf0e10cSrcweir if( (xModel->mfSplitX >= 1.0) && (xModel->maFirstPos.Column + xModel->mfSplitX <= rMaxApiPos.Column) ) 523*cdf0e10cSrcweir nHSplitPos = static_cast< sal_Int32 >( xModel->maFirstPos.Column + xModel->mfSplitX ); 524*cdf0e10cSrcweir nHSplitMode = (nHSplitPos > 0) ? API_SPLITMODE_FREEZE : API_SPLITMODE_NONE; 525*cdf0e10cSrcweir if( (xModel->mfSplitY >= 1.0) && (xModel->maFirstPos.Row + xModel->mfSplitY <= rMaxApiPos.Row) ) 526*cdf0e10cSrcweir nVSplitPos = static_cast< sal_Int32 >( xModel->maFirstPos.Row + xModel->mfSplitY ); 527*cdf0e10cSrcweir nVSplitMode = (nVSplitPos > 0) ? API_SPLITMODE_FREEZE : API_SPLITMODE_NONE; 528*cdf0e10cSrcweir } 529*cdf0e10cSrcweir else if( xModel->mnPaneState == XML_split ) 530*cdf0e10cSrcweir { 531*cdf0e10cSrcweir // split window: view settings API uses twips... 532*cdf0e10cSrcweir nHSplitPos = getLimitedValue< sal_Int32, double >( xModel->mfSplitX + 0.5, 0, SAL_MAX_INT32 ); 533*cdf0e10cSrcweir nHSplitMode = (nHSplitPos > 0) ? API_SPLITMODE_SPLIT : API_SPLITMODE_NONE; 534*cdf0e10cSrcweir nVSplitPos = getLimitedValue< sal_Int32, double >( xModel->mfSplitY + 0.5, 0, SAL_MAX_INT32 ); 535*cdf0e10cSrcweir nVSplitMode = (nVSplitPos > 0) ? API_SPLITMODE_SPLIT : API_SPLITMODE_NONE; 536*cdf0e10cSrcweir } 537*cdf0e10cSrcweir 538*cdf0e10cSrcweir // active pane 539*cdf0e10cSrcweir switch( xModel->mnActivePaneId ) 540*cdf0e10cSrcweir { 541*cdf0e10cSrcweir // no horizontal split -> always use left panes 542*cdf0e10cSrcweir // no vertical split -> always use *bottom* panes 543*cdf0e10cSrcweir case XML_topLeft: 544*cdf0e10cSrcweir nActivePane = (nVSplitMode == API_SPLITMODE_NONE) ? API_SPLITPANE_BOTTOMLEFT : API_SPLITPANE_TOPLEFT; 545*cdf0e10cSrcweir break; 546*cdf0e10cSrcweir case XML_topRight: 547*cdf0e10cSrcweir nActivePane = (nHSplitMode == API_SPLITMODE_NONE) ? 548*cdf0e10cSrcweir ((nVSplitMode == API_SPLITMODE_NONE) ? API_SPLITPANE_BOTTOMLEFT : API_SPLITPANE_TOPLEFT) : 549*cdf0e10cSrcweir ((nVSplitMode == API_SPLITMODE_NONE) ? API_SPLITPANE_BOTTOMRIGHT : API_SPLITPANE_TOPRIGHT); 550*cdf0e10cSrcweir break; 551*cdf0e10cSrcweir case XML_bottomLeft: 552*cdf0e10cSrcweir nActivePane = API_SPLITPANE_BOTTOMLEFT; 553*cdf0e10cSrcweir break; 554*cdf0e10cSrcweir case XML_bottomRight: 555*cdf0e10cSrcweir nActivePane = (nHSplitMode == API_SPLITMODE_NONE) ? API_SPLITPANE_BOTTOMLEFT : API_SPLITPANE_BOTTOMRIGHT; 556*cdf0e10cSrcweir break; 557*cdf0e10cSrcweir } 558*cdf0e10cSrcweir 559*cdf0e10cSrcweir // write the sheet view settings into the property sequence 560*cdf0e10cSrcweir PropertyMap aPropMap; 561*cdf0e10cSrcweir aPropMap[ PROP_TableSelected ] <<= bSelected; 562*cdf0e10cSrcweir aPropMap[ PROP_CursorPositionX ] <<= aCursor.Column; 563*cdf0e10cSrcweir aPropMap[ PROP_CursorPositionY ] <<= aCursor.Row; 564*cdf0e10cSrcweir aPropMap[ PROP_HorizontalSplitMode ] <<= nHSplitMode; 565*cdf0e10cSrcweir aPropMap[ PROP_VerticalSplitMode ] <<= nVSplitMode; 566*cdf0e10cSrcweir aPropMap[ PROP_HorizontalSplitPositionTwips ] <<= nHSplitPos; 567*cdf0e10cSrcweir aPropMap[ PROP_VerticalSplitPositionTwips ] <<= nVSplitPos; 568*cdf0e10cSrcweir aPropMap[ PROP_ActiveSplitRange ] <<= nActivePane; 569*cdf0e10cSrcweir aPropMap[ PROP_PositionLeft ] <<= aFirstPos.Column; 570*cdf0e10cSrcweir aPropMap[ PROP_PositionTop ] <<= aFirstPos.Row; 571*cdf0e10cSrcweir aPropMap[ PROP_PositionRight ] <<= xModel->maSecondPos.Column; 572*cdf0e10cSrcweir aPropMap[ PROP_PositionBottom ] <<= ((nVSplitPos > 0) ? xModel->maSecondPos.Row : xModel->maFirstPos.Row); 573*cdf0e10cSrcweir aPropMap[ PROP_ZoomType ] <<= API_ZOOMTYPE_PERCENT; 574*cdf0e10cSrcweir aPropMap[ PROP_ZoomValue ] <<= static_cast< sal_Int16 >( xModel->getNormalZoom() ); 575*cdf0e10cSrcweir aPropMap[ PROP_PageViewZoomValue ] <<= static_cast< sal_Int16 >( xModel->getPageBreakZoom() ); 576*cdf0e10cSrcweir aPropMap[ PROP_GridColor ] <<= xModel->getGridColor( getBaseFilter() ); 577*cdf0e10cSrcweir aPropMap[ PROP_ShowPageBreakPreview ] <<= xModel->isPageBreakPreview(); 578*cdf0e10cSrcweir aPropMap[ PROP_ShowFormulas ] <<= xModel->mbShowFormulas; 579*cdf0e10cSrcweir aPropMap[ PROP_ShowGrid ] <<= xModel->mbShowGrid; 580*cdf0e10cSrcweir aPropMap[ PROP_HasColumnRowHeaders ] <<= xModel->mbShowHeadings; 581*cdf0e10cSrcweir aPropMap[ PROP_ShowZeroValues ] <<= xModel->mbShowZeros; 582*cdf0e10cSrcweir aPropMap[ PROP_IsOutlineSymbolsSet ] <<= xModel->mbShowOutline; 583*cdf0e10cSrcweir 584*cdf0e10cSrcweir // store sheet view settings in global view settings object 585*cdf0e10cSrcweir getViewSettings().setSheetViewSettings( getSheetIndex(), xModel, Any( aPropMap.makePropertyValueSequence() ) ); 586*cdf0e10cSrcweir } 587*cdf0e10cSrcweir 588*cdf0e10cSrcweir bool SheetViewSettings::isSheetRightToLeft() const 589*cdf0e10cSrcweir { 590*cdf0e10cSrcweir return !maSheetViews.empty() && maSheetViews.front()->mbRightToLeft; 591*cdf0e10cSrcweir } 592*cdf0e10cSrcweir 593*cdf0e10cSrcweir // private -------------------------------------------------------------------- 594*cdf0e10cSrcweir 595*cdf0e10cSrcweir SheetViewModelRef SheetViewSettings::createSheetView() 596*cdf0e10cSrcweir { 597*cdf0e10cSrcweir SheetViewModelRef xModel( new SheetViewModel ); 598*cdf0e10cSrcweir maSheetViews.push_back( xModel ); 599*cdf0e10cSrcweir return xModel; 600*cdf0e10cSrcweir } 601*cdf0e10cSrcweir 602*cdf0e10cSrcweir // ============================================================================ 603*cdf0e10cSrcweir 604*cdf0e10cSrcweir WorkbookViewModel::WorkbookViewModel() : 605*cdf0e10cSrcweir mnWinX( 0 ), 606*cdf0e10cSrcweir mnWinY( 0 ), 607*cdf0e10cSrcweir mnWinWidth( 0 ), 608*cdf0e10cSrcweir mnWinHeight( 0 ), 609*cdf0e10cSrcweir mnActiveSheet( 0 ), 610*cdf0e10cSrcweir mnFirstVisSheet( 0 ), 611*cdf0e10cSrcweir mnTabBarWidth( OOX_BOOKVIEW_TABBARRATIO_DEF ), 612*cdf0e10cSrcweir mnVisibility( XML_visible ), 613*cdf0e10cSrcweir mbShowTabBar( true ), 614*cdf0e10cSrcweir mbShowHorScroll( true ), 615*cdf0e10cSrcweir mbShowVerScroll( true ), 616*cdf0e10cSrcweir mbMinimized( false ) 617*cdf0e10cSrcweir { 618*cdf0e10cSrcweir } 619*cdf0e10cSrcweir 620*cdf0e10cSrcweir // ---------------------------------------------------------------------------- 621*cdf0e10cSrcweir 622*cdf0e10cSrcweir ViewSettings::ViewSettings( const WorkbookHelper& rHelper ) : 623*cdf0e10cSrcweir WorkbookHelper( rHelper ), 624*cdf0e10cSrcweir mbValidOleSize( false ) 625*cdf0e10cSrcweir { 626*cdf0e10cSrcweir } 627*cdf0e10cSrcweir 628*cdf0e10cSrcweir void ViewSettings::importWorkbookView( const AttributeList& rAttribs ) 629*cdf0e10cSrcweir { 630*cdf0e10cSrcweir WorkbookViewModel& rModel = createWorkbookView(); 631*cdf0e10cSrcweir rModel.mnWinX = rAttribs.getInteger( XML_xWindow, 0 ); 632*cdf0e10cSrcweir rModel.mnWinY = rAttribs.getInteger( XML_yWindow, 0 ); 633*cdf0e10cSrcweir rModel.mnWinWidth = rAttribs.getInteger( XML_windowWidth, 0 ); 634*cdf0e10cSrcweir rModel.mnWinHeight = rAttribs.getInteger( XML_windowHeight, 0 ); 635*cdf0e10cSrcweir rModel.mnActiveSheet = rAttribs.getInteger( XML_activeTab, 0 ); 636*cdf0e10cSrcweir rModel.mnFirstVisSheet = rAttribs.getInteger( XML_firstSheet, 0 ); 637*cdf0e10cSrcweir rModel.mnTabBarWidth = rAttribs.getInteger( XML_tabRatio, 600 ); 638*cdf0e10cSrcweir rModel.mnVisibility = rAttribs.getToken( XML_visibility, XML_visible ); 639*cdf0e10cSrcweir rModel.mbShowTabBar = rAttribs.getBool( XML_showSheetTabs, true ); 640*cdf0e10cSrcweir rModel.mbShowHorScroll = rAttribs.getBool( XML_showHorizontalScroll, true ); 641*cdf0e10cSrcweir rModel.mbShowVerScroll = rAttribs.getBool( XML_showVerticalScroll, true ); 642*cdf0e10cSrcweir rModel.mbMinimized = rAttribs.getBool( XML_minimized, false ); 643*cdf0e10cSrcweir } 644*cdf0e10cSrcweir 645*cdf0e10cSrcweir void ViewSettings::importOleSize( const AttributeList& rAttribs ) 646*cdf0e10cSrcweir { 647*cdf0e10cSrcweir OUString aRange = rAttribs.getString( XML_ref, OUString() ); 648*cdf0e10cSrcweir mbValidOleSize = getAddressConverter().convertToCellRange( maOleSize, aRange, 0, true, false ); 649*cdf0e10cSrcweir } 650*cdf0e10cSrcweir 651*cdf0e10cSrcweir void ViewSettings::importWorkbookView( SequenceInputStream& rStrm ) 652*cdf0e10cSrcweir { 653*cdf0e10cSrcweir WorkbookViewModel& rModel = createWorkbookView(); 654*cdf0e10cSrcweir sal_uInt8 nFlags; 655*cdf0e10cSrcweir rStrm >> rModel.mnWinX >> rModel.mnWinY >> rModel.mnWinWidth >> rModel.mnWinHeight >> rModel.mnTabBarWidth >> rModel.mnFirstVisSheet >> rModel.mnActiveSheet >> nFlags; 656*cdf0e10cSrcweir rModel.mnVisibility = getFlagValue( nFlags, BIFF12_WBVIEW_HIDDEN, XML_hidden, XML_visible ); 657*cdf0e10cSrcweir rModel.mbShowTabBar = getFlag( nFlags, BIFF12_WBVIEW_SHOWTABBAR ); 658*cdf0e10cSrcweir rModel.mbShowHorScroll = getFlag( nFlags, BIFF12_WBVIEW_SHOWHORSCROLL ); 659*cdf0e10cSrcweir rModel.mbShowVerScroll = getFlag( nFlags, BIFF12_WBVIEW_SHOWVERSCROLL ); 660*cdf0e10cSrcweir rModel.mbMinimized = getFlag( nFlags, BIFF12_WBVIEW_MINIMIZED ); 661*cdf0e10cSrcweir } 662*cdf0e10cSrcweir 663*cdf0e10cSrcweir void ViewSettings::importOleSize( SequenceInputStream& rStrm ) 664*cdf0e10cSrcweir { 665*cdf0e10cSrcweir BinRange aBinRange; 666*cdf0e10cSrcweir rStrm >> aBinRange; 667*cdf0e10cSrcweir mbValidOleSize = getAddressConverter().convertToCellRange( maOleSize, aBinRange, 0, true, false ); 668*cdf0e10cSrcweir } 669*cdf0e10cSrcweir 670*cdf0e10cSrcweir void ViewSettings::importWindow1( BiffInputStream& rStrm ) 671*cdf0e10cSrcweir { 672*cdf0e10cSrcweir sal_uInt16 nWinX, nWinY, nWinWidth, nWinHeight; 673*cdf0e10cSrcweir rStrm >> nWinX >> nWinY >> nWinWidth >> nWinHeight; 674*cdf0e10cSrcweir 675*cdf0e10cSrcweir // WINDOW1 record occures in every sheet in BIFF4W 676*cdf0e10cSrcweir OSL_ENSURE( maBookViews.empty() || ((getBiff() == BIFF4) && isWorkbookFile()), 677*cdf0e10cSrcweir "ViewSettings::importWindow1 - multiple WINDOW1 records" ); 678*cdf0e10cSrcweir WorkbookViewModel& rModel = createWorkbookView(); 679*cdf0e10cSrcweir rModel.mnWinX = nWinX; 680*cdf0e10cSrcweir rModel.mnWinY = nWinY; 681*cdf0e10cSrcweir rModel.mnWinWidth = nWinWidth; 682*cdf0e10cSrcweir rModel.mnWinHeight = nWinHeight; 683*cdf0e10cSrcweir 684*cdf0e10cSrcweir if( getBiff() <= BIFF4 ) 685*cdf0e10cSrcweir { 686*cdf0e10cSrcweir sal_uInt8 nHidden; 687*cdf0e10cSrcweir rStrm >> nHidden; 688*cdf0e10cSrcweir rModel.mnVisibility = (nHidden == 0) ? XML_visible : XML_hidden; 689*cdf0e10cSrcweir } 690*cdf0e10cSrcweir else 691*cdf0e10cSrcweir { 692*cdf0e10cSrcweir sal_uInt16 nFlags, nActiveTab, nFirstVisTab, nSelectCnt, nTabBarWidth; 693*cdf0e10cSrcweir rStrm >> nFlags >> nActiveTab >> nFirstVisTab >> nSelectCnt >> nTabBarWidth; 694*cdf0e10cSrcweir 695*cdf0e10cSrcweir rModel.mnActiveSheet = nActiveTab; 696*cdf0e10cSrcweir rModel.mnFirstVisSheet = nFirstVisTab; 697*cdf0e10cSrcweir rModel.mnTabBarWidth = nTabBarWidth; 698*cdf0e10cSrcweir rModel.mnVisibility = getFlagValue( nFlags, BIFF_WINDOW1_HIDDEN, XML_hidden, XML_visible ); 699*cdf0e10cSrcweir rModel.mbMinimized = getFlag( nFlags, BIFF_WINDOW1_MINIMIZED ); 700*cdf0e10cSrcweir rModel.mbShowHorScroll = getFlag( nFlags, BIFF_WINDOW1_SHOWHORSCROLL ); 701*cdf0e10cSrcweir rModel.mbShowVerScroll = getFlag( nFlags, BIFF_WINDOW1_SHOWVERSCROLL ); 702*cdf0e10cSrcweir rModel.mbShowTabBar = getFlag( nFlags, BIFF_WINDOW1_SHOWTABBAR ); 703*cdf0e10cSrcweir } 704*cdf0e10cSrcweir } 705*cdf0e10cSrcweir 706*cdf0e10cSrcweir void ViewSettings::importOleSize( BiffInputStream& rStrm ) 707*cdf0e10cSrcweir { 708*cdf0e10cSrcweir rStrm.skip( 2 ); 709*cdf0e10cSrcweir BinRange aBinRange; 710*cdf0e10cSrcweir aBinRange.read( rStrm, false ); 711*cdf0e10cSrcweir mbValidOleSize = getAddressConverter().convertToCellRange( maOleSize, aBinRange, 0, true, false ); 712*cdf0e10cSrcweir } 713*cdf0e10cSrcweir 714*cdf0e10cSrcweir void ViewSettings::setSheetViewSettings( sal_Int16 nSheet, const SheetViewModelRef& rxSheetView, const Any& rProperties ) 715*cdf0e10cSrcweir { 716*cdf0e10cSrcweir maSheetViews[ nSheet ] = rxSheetView; 717*cdf0e10cSrcweir maSheetProps[ nSheet ] = rProperties; 718*cdf0e10cSrcweir } 719*cdf0e10cSrcweir 720*cdf0e10cSrcweir void ViewSettings::setSheetUsedArea( const CellRangeAddress& rUsedArea ) 721*cdf0e10cSrcweir { 722*cdf0e10cSrcweir maSheetUsedAreas[ rUsedArea.Sheet ] = rUsedArea; 723*cdf0e10cSrcweir } 724*cdf0e10cSrcweir 725*cdf0e10cSrcweir void ViewSettings::finalizeImport() 726*cdf0e10cSrcweir { 727*cdf0e10cSrcweir const WorksheetBuffer& rWorksheets = getWorksheets(); 728*cdf0e10cSrcweir if( rWorksheets.getWorksheetCount() <= 0 ) return; 729*cdf0e10cSrcweir 730*cdf0e10cSrcweir // force creation of workbook view model to get the Excel defaults 731*cdf0e10cSrcweir const WorkbookViewModel& rModel = maBookViews.empty() ? createWorkbookView() : *maBookViews.front(); 732*cdf0e10cSrcweir 733*cdf0e10cSrcweir // show object mode is part of workbook settings 734*cdf0e10cSrcweir sal_Int16 nShowMode = getWorkbookSettings().getApiShowObjectMode(); 735*cdf0e10cSrcweir 736*cdf0e10cSrcweir // view settings for all sheets 737*cdf0e10cSrcweir Reference< XNameContainer > xSheetsNC = ContainerHelper::createNameContainer( getBaseFilter().getComponentContext() ); 738*cdf0e10cSrcweir if( !xSheetsNC.is() ) return; 739*cdf0e10cSrcweir for( SheetPropertiesMap::const_iterator aIt = maSheetProps.begin(), aEnd = maSheetProps.end(); aIt != aEnd; ++aIt ) 740*cdf0e10cSrcweir ContainerHelper::insertByName( xSheetsNC, rWorksheets.getCalcSheetName( aIt->first ), aIt->second ); 741*cdf0e10cSrcweir 742*cdf0e10cSrcweir // use active sheet to set sheet properties that are document-global in Calc 743*cdf0e10cSrcweir sal_Int16 nActiveSheet = getActiveCalcSheet(); 744*cdf0e10cSrcweir SheetViewModelRef& rxActiveSheetView = maSheetViews[ nActiveSheet ]; 745*cdf0e10cSrcweir OSL_ENSURE( rxActiveSheetView.get(), "ViewSettings::finalizeImport - missing active sheet view settings" ); 746*cdf0e10cSrcweir if( !rxActiveSheetView ) 747*cdf0e10cSrcweir rxActiveSheetView.reset( new SheetViewModel ); 748*cdf0e10cSrcweir 749*cdf0e10cSrcweir Reference< XIndexContainer > xContainer = ContainerHelper::createIndexContainer( getBaseFilter().getComponentContext() ); 750*cdf0e10cSrcweir if( xContainer.is() ) try 751*cdf0e10cSrcweir { 752*cdf0e10cSrcweir PropertyMap aPropMap; 753*cdf0e10cSrcweir aPropMap[ PROP_Tables ] <<= xSheetsNC; 754*cdf0e10cSrcweir aPropMap[ PROP_ActiveTable ] <<= rWorksheets.getCalcSheetName( nActiveSheet ); 755*cdf0e10cSrcweir aPropMap[ PROP_HasHorizontalScrollBar ] <<= rModel.mbShowHorScroll; 756*cdf0e10cSrcweir aPropMap[ PROP_HasVerticalScrollBar ] <<= rModel.mbShowVerScroll; 757*cdf0e10cSrcweir aPropMap[ PROP_HasSheetTabs ] <<= rModel.mbShowTabBar; 758*cdf0e10cSrcweir aPropMap[ PROP_RelativeHorizontalTabbarWidth ] <<= double( rModel.mnTabBarWidth / 1000.0 ); 759*cdf0e10cSrcweir aPropMap[ PROP_ShowObjects ] <<= nShowMode; 760*cdf0e10cSrcweir aPropMap[ PROP_ShowCharts ] <<= nShowMode; 761*cdf0e10cSrcweir aPropMap[ PROP_ShowDrawing ] <<= nShowMode; 762*cdf0e10cSrcweir aPropMap[ PROP_GridColor ] <<= rxActiveSheetView->getGridColor( getBaseFilter() ); 763*cdf0e10cSrcweir aPropMap[ PROP_ShowPageBreakPreview ] <<= rxActiveSheetView->isPageBreakPreview(); 764*cdf0e10cSrcweir aPropMap[ PROP_ShowFormulas ] <<= rxActiveSheetView->mbShowFormulas; 765*cdf0e10cSrcweir aPropMap[ PROP_ShowGrid ] <<= rxActiveSheetView->mbShowGrid; 766*cdf0e10cSrcweir aPropMap[ PROP_HasColumnRowHeaders ] <<= rxActiveSheetView->mbShowHeadings; 767*cdf0e10cSrcweir aPropMap[ PROP_ShowZeroValues ] <<= rxActiveSheetView->mbShowZeros; 768*cdf0e10cSrcweir aPropMap[ PROP_IsOutlineSymbolsSet ] <<= rxActiveSheetView->mbShowOutline; 769*cdf0e10cSrcweir 770*cdf0e10cSrcweir xContainer->insertByIndex( 0, Any( aPropMap.makePropertyValueSequence() ) ); 771*cdf0e10cSrcweir Reference< XIndexAccess > xIAccess( xContainer, UNO_QUERY_THROW ); 772*cdf0e10cSrcweir Reference< XViewDataSupplier > xViewDataSuppl( getDocument(), UNO_QUERY_THROW ); 773*cdf0e10cSrcweir xViewDataSuppl->setViewData( xIAccess ); 774*cdf0e10cSrcweir } 775*cdf0e10cSrcweir catch( Exception& ) 776*cdf0e10cSrcweir { 777*cdf0e10cSrcweir OSL_ENSURE( false, "ViewSettings::finalizeImport - cannot create document view settings" ); 778*cdf0e10cSrcweir } 779*cdf0e10cSrcweir 780*cdf0e10cSrcweir /* Set visible area to be used if this document is an embedded OLE object. 781*cdf0e10cSrcweir #i44077# If a new OLE object is inserted from file, there is no OLESIZE 782*cdf0e10cSrcweir record in the Excel file. In this case, use the used area calculated 783*cdf0e10cSrcweir from file contents (used cells and drawing objects). */ 784*cdf0e10cSrcweir maOleSize.Sheet = nActiveSheet; 785*cdf0e10cSrcweir const CellRangeAddress* pVisibleArea = mbValidOleSize ? 786*cdf0e10cSrcweir &maOleSize : ContainerHelper::getMapElement( maSheetUsedAreas, nActiveSheet ); 787*cdf0e10cSrcweir if( pVisibleArea ) 788*cdf0e10cSrcweir { 789*cdf0e10cSrcweir // calculate the visible area in units of 1/100 mm 790*cdf0e10cSrcweir PropertySet aRangeProp( getCellRangeFromDoc( *pVisibleArea ) ); 791*cdf0e10cSrcweir Point aPos; 792*cdf0e10cSrcweir Size aSize; 793*cdf0e10cSrcweir if( aRangeProp.getProperty( aPos, PROP_Position ) && aRangeProp.getProperty( aSize, PROP_Size ) ) 794*cdf0e10cSrcweir { 795*cdf0e10cSrcweir // set the visible area as sequence of long at the media descriptor 796*cdf0e10cSrcweir Sequence< sal_Int32 > aWinExtent( 4 ); 797*cdf0e10cSrcweir aWinExtent[ 0 ] = aPos.X; 798*cdf0e10cSrcweir aWinExtent[ 1 ] = aPos.Y; 799*cdf0e10cSrcweir aWinExtent[ 2 ] = aPos.X + aSize.Width; 800*cdf0e10cSrcweir aWinExtent[ 3 ] = aPos.Y + aSize.Height; 801*cdf0e10cSrcweir getBaseFilter().getMediaDescriptor()[ CREATE_OUSTRING( "WinExtent" ) ] <<= aWinExtent; 802*cdf0e10cSrcweir } 803*cdf0e10cSrcweir } 804*cdf0e10cSrcweir } 805*cdf0e10cSrcweir 806*cdf0e10cSrcweir sal_Int16 ViewSettings::getActiveCalcSheet() const 807*cdf0e10cSrcweir { 808*cdf0e10cSrcweir return maBookViews.empty() ? 0 : ::std::max< sal_Int16 >( getWorksheets().getCalcSheetIndex( maBookViews.front()->mnActiveSheet ), 0 ); 809*cdf0e10cSrcweir } 810*cdf0e10cSrcweir 811*cdf0e10cSrcweir // private -------------------------------------------------------------------- 812*cdf0e10cSrcweir 813*cdf0e10cSrcweir WorkbookViewModel& ViewSettings::createWorkbookView() 814*cdf0e10cSrcweir { 815*cdf0e10cSrcweir WorkbookViewModelRef xModel( new WorkbookViewModel ); 816*cdf0e10cSrcweir maBookViews.push_back( xModel ); 817*cdf0e10cSrcweir return *xModel; 818*cdf0e10cSrcweir } 819*cdf0e10cSrcweir 820*cdf0e10cSrcweir // ============================================================================ 821*cdf0e10cSrcweir 822*cdf0e10cSrcweir } // namespace xls 823*cdf0e10cSrcweir } // namespace oox 824