LibreOffice Module sc (master)  1
viewsettings.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 
20 #include <viewsettings.hxx>
21 
22 #include <com/sun/star/awt/Point.hpp>
23 #include <com/sun/star/awt/Size.hpp>
24 #include <com/sun/star/beans/XPropertySet.hpp>
25 #include <com/sun/star/container/XIndexContainer.hpp>
26 #include <com/sun/star/document/IndexedPropertyValues.hpp>
27 #include <com/sun/star/document/XViewDataSupplier.hpp>
28 #include <com/sun/star/document/NamedPropertyValues.hpp>
29 #include <com/sun/star/sheet/XSpreadsheet.hpp>
30 #include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
31 #include <osl/diagnose.h>
33 #include <oox/core/filterbase.hxx>
39 #include <oox/token/properties.hxx>
40 #include <oox/token/tokens.hxx>
41 #include <addressconverter.hxx>
42 #include <workbooksettings.hxx>
43 #include <worksheetbuffer.hxx>
44 
45 namespace com::sun::star::container { class XNameContainer; }
46 
47 namespace oox::xls {
48 
49 using namespace ::com::sun::star::awt;
50 using namespace ::com::sun::star::container;
51 using namespace ::com::sun::star::document;
52 using namespace ::com::sun::star::uno;
53 
54 using ::oox::core::FilterBase;
55 
56 namespace {
57 
58 const sal_Int32 OOX_BOOKVIEW_TABBARRATIO_DEF = 600;
59 const sal_Int32 OOX_SHEETVIEW_NORMALZOOM_DEF = 100;
60 const sal_Int32 OOX_SHEETVIEW_SHEETLAYZOOM_DEF = 60;
61 
62 const sal_uInt8 BIFF12_PANE_FROZEN = 0x01;
63 const sal_uInt8 BIFF12_PANE_FROZENNOSPLIT = 0x02;
64 
65 const sal_uInt16 BIFF12_SHEETVIEW_SHOWFORMULAS = 0x0002;
66 const sal_uInt16 BIFF12_SHEETVIEW_SHOWGRID = 0x0004;
67 const sal_uInt16 BIFF12_SHEETVIEW_SHOWHEADINGS = 0x0008;
68 const sal_uInt16 BIFF12_SHEETVIEW_SHOWZEROS = 0x0010;
69 const sal_uInt16 BIFF12_SHEETVIEW_RIGHTTOLEFT = 0x0020;
70 const sal_uInt16 BIFF12_SHEETVIEW_SELECTED = 0x0040;
71 const sal_uInt16 BIFF12_SHEETVIEW_SHOWOUTLINE = 0x0100;
72 const sal_uInt16 BIFF12_SHEETVIEW_DEFGRIDCOLOR = 0x0200;
73 
74 const sal_uInt16 BIFF12_CHARTSHEETVIEW_SELECTED = 0x0001;
75 const sal_uInt16 BIFF12_CHARTSHEETVIEW_ZOOMTOFIT = 0x0002;
76 
77 const sal_uInt8 BIFF12_WBVIEW_HIDDEN = 0x01;
78 const sal_uInt8 BIFF12_WBVIEW_MINIMIZED = 0x02;
79 const sal_uInt8 BIFF12_WBVIEW_SHOWHORSCROLL = 0x08;
80 const sal_uInt8 BIFF12_WBVIEW_SHOWVERSCROLL = 0x10;
81 const sal_uInt8 BIFF12_WBVIEW_SHOWTABBAR = 0x20;
82 
83 // Attention: view settings in Calc do not use com.sun.star.view.DocumentZoomType!
84 const sal_Int16 API_ZOOMTYPE_PERCENT = 0;
85 
86 const sal_Int32 API_ZOOMVALUE_MIN = 20;
87 const sal_Int32 API_ZOOMVALUE_MAX = 400;
88 
89 // no predefined constants for split mode
90 const sal_Int16 API_SPLITMODE_NONE = 0;
91 const sal_Int16 API_SPLITMODE_SPLIT = 1;
92 const sal_Int16 API_SPLITMODE_FREEZE = 2;
93 
94 // no predefined constants for pane identifiers
95 const sal_Int16 API_SPLITPANE_TOPLEFT = 0;
96 const sal_Int16 API_SPLITPANE_TOPRIGHT = 1;
97 const sal_Int16 API_SPLITPANE_BOTTOMLEFT = 2;
98 const sal_Int16 API_SPLITPANE_BOTTOMRIGHT = 3;
99 
101 sal_Int32 lclGetOoxPaneId( sal_Int32 nBiffPaneId, sal_Int32 nDefaultPaneId )
102 {
103  static const sal_Int32 spnPaneIds[] = { XML_bottomRight, XML_topRight, XML_bottomLeft, XML_topLeft };
104  return STATIC_ARRAY_SELECT( spnPaneIds, nBiffPaneId, nDefaultPaneId );
105 }
106 
107 } // namespace
108 
110  mnActiveCellId( 0 )
111 {
112 }
113 
115  mnWorkbookViewId( 0 ),
116  mnViewType( XML_normal ),
117  mnActivePaneId( XML_topLeft ),
118  mnPaneState( XML_split ),
119  mfSplitX( 0.0 ),
120  mfSplitY( 0.0 ),
121  mnCurrentZoom( 0 ),
122  mnNormalZoom( 0 ),
123  mnSheetLayoutZoom( 0 ),
124  mnPageLayoutZoom( 0 ),
125  mbSelected( false ),
126  mbRightToLeft( false ),
127  mbDefGridColor( true ),
128  mbShowFormulas( false ),
129  mbShowGrid( true ),
130  mbShowHeadings( true ),
131  mbShowZeros( true ),
132  mbShowOutline( true ),
133  mbZoomToFit( false )
134 {
136 }
137 
139 {
140  return mnViewType == XML_pageBreakPreview;
141 }
142 
144 {
145  const sal_Int32& rnZoom = isPageBreakPreview() ? mnNormalZoom : mnCurrentZoom;
146  sal_Int32 nZoom = (rnZoom > 0) ? rnZoom : OOX_SHEETVIEW_NORMALZOOM_DEF;
147  return getLimitedValue< sal_Int32 >( nZoom, API_ZOOMVALUE_MIN, API_ZOOMVALUE_MAX );
148 }
149 
151 {
152  const sal_Int32& rnZoom = isPageBreakPreview() ? mnCurrentZoom : mnSheetLayoutZoom;
153  sal_Int32 nZoom = (rnZoom > 0) ? rnZoom : OOX_SHEETVIEW_SHEETLAYZOOM_DEF;
154  return getLimitedValue< sal_Int32 >( nZoom, API_ZOOMVALUE_MIN, API_ZOOMVALUE_MAX );
155 }
156 
157 ::Color SheetViewModel::getGridColor( const FilterBase& rFilter ) const
158 {
159  return mbDefGridColor ? API_RGB_TRANSPARENT : maGridColor.getColor( rFilter.getGraphicHelper() );
160 }
161 
163 {
164  return maPaneSelMap.get( mnActivePaneId ).get();
165 }
166 
168 {
169  PaneSelectionModelMap::mapped_type& rxPaneSel = maPaneSelMap[ nPaneId ];
170  if( !rxPaneSel )
171  rxPaneSel = std::make_shared<PaneSelectionModel>();
172  return *rxPaneSel;
173 }
174 
176  WorksheetHelper( rHelper )
177 {
178 }
179 
181 {
182  SheetViewModel& rModel = *createSheetView();
183  rModel.maGridColor.setIndexed( rAttribs.getInteger( XML_colorId, OOX_COLOR_WINDOWTEXT ) );
184  rModel.maFirstPos = getAddressConverter().createValidCellAddress( rAttribs.getString( XML_topLeftCell, OUString() ), getSheetIndex(), false );
185  rModel.mnWorkbookViewId = rAttribs.getToken( XML_workbookViewId, 0 );
186  rModel.mnViewType = rAttribs.getToken( XML_view, XML_normal );
187  rModel.mnCurrentZoom = rAttribs.getInteger( XML_zoomScale, 100 );
188  rModel.mnNormalZoom = rAttribs.getInteger( XML_zoomScaleNormal, 0 );
189  rModel.mnSheetLayoutZoom = rAttribs.getInteger( XML_zoomScaleSheetLayoutView, 0 );
190  rModel.mnPageLayoutZoom = rAttribs.getInteger( XML_zoomScalePageLayoutView, 0 );
191  rModel.mbSelected = rAttribs.getBool( XML_tabSelected, false );
192  rModel.mbRightToLeft = rAttribs.getBool( XML_rightToLeft, false );
193  rModel.mbDefGridColor = rAttribs.getBool( XML_defaultGridColor, true );
194  rModel.mbShowFormulas = rAttribs.getBool( XML_showFormulas, false );
195  rModel.mbShowGrid = rAttribs.getBool( XML_showGridLines, true );
196  rModel.mbShowHeadings = rAttribs.getBool( XML_showRowColHeaders, true );
197  rModel.mbShowZeros = rAttribs.getBool( XML_showZeros, true );
198  rModel.mbShowOutline = rAttribs.getBool( XML_showOutlineSymbols, true );
199 }
200 
202 {
203  OSL_ENSURE( !maSheetViews.empty(), "SheetViewSettings::importPane - missing sheet view model" );
204  if( !maSheetViews.empty() )
205  {
206  SheetViewModel& rModel = *maSheetViews.back();
207  rModel.maSecondPos = getAddressConverter().createValidCellAddress( rAttribs.getString( XML_topLeftCell, OUString() ), getSheetIndex(), false );
208  rModel.mnActivePaneId = rAttribs.getToken( XML_activePane, XML_topLeft );
209  rModel.mnPaneState = rAttribs.getToken( XML_state, XML_split );
210  rModel.mfSplitX = rAttribs.getDouble( XML_xSplit, 0.0 );
211  rModel.mfSplitY = rAttribs.getDouble( XML_ySplit, 0.0 );
212  }
213 }
214 
216 {
217  OSL_ENSURE( !maSheetViews.empty(), "SheetViewSettings::importSelection - missing sheet view model" );
218  if( !maSheetViews.empty() )
219  {
220  // pane this selection belongs to
221  sal_Int32 nPaneId = rAttribs.getToken( XML_pane, XML_topLeft );
222  PaneSelectionModel& rSelData = maSheetViews.back()->createPaneSelection( nPaneId );
223  // cursor position
224  rSelData.maActiveCell = getAddressConverter().createValidCellAddress( rAttribs.getString( XML_activeCell, OUString() ), getSheetIndex(), false );
225  rSelData.mnActiveCellId = rAttribs.getInteger( XML_activeCellId, 0 );
226  // selection
227  rSelData.maSelection.RemoveAll();
228  getAddressConverter().convertToCellRangeList( rSelData.maSelection, rAttribs.getString( XML_sqref, OUString() ), getSheetIndex(), false );
229  }
230 }
231 
233 {
234  SheetViewModel& rModel = *createSheetView();
235  rModel.mnWorkbookViewId = rAttribs.getToken( XML_workbookViewId, 0 );
236  rModel.mnCurrentZoom = rAttribs.getInteger( XML_zoomScale, 100 );
237  rModel.mbSelected = rAttribs.getBool( XML_tabSelected, false );
238  rModel.mbZoomToFit = rAttribs.getBool( XML_zoomToFit, false );
239 }
240 
242 {
243  SheetViewModel& rModel = *createSheetView();
244  sal_uInt16 nFlags;
245  sal_Int32 nViewType;
246  BinAddress aFirstPos;
247  nFlags = rStrm.readuInt16();
248  nViewType = rStrm.readInt32();
249  rStrm >> aFirstPos;
250  rModel.maGridColor.importColorId( rStrm );
251  rModel.mnCurrentZoom = rStrm.readuInt16();
252  rModel.mnNormalZoom = rStrm.readuInt16();
253  rModel.mnSheetLayoutZoom = rStrm.readuInt16();
254  rModel.mnPageLayoutZoom = rStrm.readuInt16();
255  rModel.mnWorkbookViewId = rStrm.readInt32();
256 
257  rModel.maFirstPos = getAddressConverter().createValidCellAddress( aFirstPos, getSheetIndex(), false );
258  static const sal_Int32 spnViewTypes[] = { XML_normal, XML_pageBreakPreview, XML_pageLayout };
259  rModel.mnViewType = STATIC_ARRAY_SELECT( spnViewTypes, nViewType, XML_normal );
260  rModel.mbSelected = getFlag( nFlags, BIFF12_SHEETVIEW_SELECTED );
261  rModel.mbRightToLeft = getFlag( nFlags, BIFF12_SHEETVIEW_RIGHTTOLEFT );
262  rModel.mbDefGridColor = getFlag( nFlags, BIFF12_SHEETVIEW_DEFGRIDCOLOR );
263  rModel.mbShowFormulas = getFlag( nFlags, BIFF12_SHEETVIEW_SHOWFORMULAS );
264  rModel.mbShowGrid = getFlag( nFlags, BIFF12_SHEETVIEW_SHOWGRID );
265  rModel.mbShowHeadings = getFlag( nFlags, BIFF12_SHEETVIEW_SHOWHEADINGS );
266  rModel.mbShowZeros = getFlag( nFlags, BIFF12_SHEETVIEW_SHOWZEROS );
267  rModel.mbShowOutline = getFlag( nFlags, BIFF12_SHEETVIEW_SHOWOUTLINE );
268 }
269 
271 {
272  OSL_ENSURE( !maSheetViews.empty(), "SheetViewSettings::importPane - missing sheet view model" );
273  if( maSheetViews.empty() )
274  return;
275 
276  SheetViewModel& rModel = *maSheetViews.back();
277 
278  BinAddress aSecondPos;
279  sal_Int32 nActivePaneId;
280  sal_uInt8 nFlags;
281  rModel.mfSplitX = rStrm.readDouble();
282  rModel.mfSplitY = rStrm.readDouble();
283  rStrm >> aSecondPos;
284  nActivePaneId = rStrm.readInt32();
285  nFlags = rStrm.readuChar();
286 
287  rModel.maSecondPos = getAddressConverter().createValidCellAddress( aSecondPos, getSheetIndex(), false );
288  rModel.mnActivePaneId = lclGetOoxPaneId( nActivePaneId, XML_topLeft );
289  rModel.mnPaneState = getFlagValue( nFlags, BIFF12_PANE_FROZEN, getFlagValue( nFlags, BIFF12_PANE_FROZENNOSPLIT, XML_frozen, XML_frozenSplit ), XML_split );
290 }
291 
293 {
294  OSL_ENSURE( !maSheetViews.empty(), "SheetViewSettings::importSelection - missing sheet view model" );
295  if( maSheetViews.empty() )
296  return;
297 
298  // pane this selection belongs to
299  sal_Int32 nPaneId = rStrm.readInt32();
300  PaneSelectionModel& rPaneSel = maSheetViews.back()->createPaneSelection( lclGetOoxPaneId( nPaneId, -1 ) );
301  // cursor position
302  BinAddress aActiveCell;
303  rStrm >> aActiveCell;
304  rPaneSel.mnActiveCellId = rStrm.readInt32();
305  rPaneSel.maActiveCell = getAddressConverter().createValidCellAddress( aActiveCell, getSheetIndex(), false );
306  // selection
307  BinRangeList aSelection;
308  rStrm >> aSelection;
309  rPaneSel.maSelection.RemoveAll();
310  getAddressConverter().convertToCellRangeList( rPaneSel.maSelection, aSelection, getSheetIndex(), false );
311 }
312 
314 {
315  SheetViewModel& rModel = *createSheetView();
316  sal_uInt16 nFlags;
317  nFlags = rStrm.readuInt16();
318  rModel.mnCurrentZoom = rStrm.readInt32();
319  rModel.mnWorkbookViewId = rStrm.readInt32();
320 
321  rModel.mbSelected = getFlag( nFlags, BIFF12_CHARTSHEETVIEW_SELECTED );
322  rModel.mbZoomToFit = getFlag( nFlags, BIFF12_CHARTSHEETVIEW_ZOOMTOFIT );
323 }
324 
326 {
327  // force creation of sheet view model to get the Excel defaults
329 
330  // #i59590# #158194# special handling for chart sheets (Excel ignores some settings in chart sheets)
332  {
333  xModel->maPaneSelMap.clear();
334  xModel->maFirstPos = xModel->maSecondPos = ScAddress( SCCOL ( 0 ), SCROW ( 0 ), getSheetIndex() );
335  xModel->mnViewType = XML_normal;
336  xModel->mnActivePaneId = XML_topLeft;
337  xModel->mnPaneState = XML_split;
338  xModel->mfSplitX = xModel->mfSplitY = 0.0;
339  xModel->mbRightToLeft = false;
340  xModel->mbDefGridColor = true;
341  xModel->mbShowFormulas = false;
342  xModel->mbShowGrid = true;
343  xModel->mbShowHeadings = true;
344  xModel->mbShowZeros = true;
345  xModel->mbShowOutline = true;
346  }
347 
348  // sheet selected (active sheet must be selected)
349  bool bSelected = xModel->mbSelected || (getSheetIndex() == getViewSettings().getActiveCalcSheet());
350  if ( bSelected )
351  {
352  // active tab/sheet cannot be hidden
353  // always force it to be displayed
354  PropertySet aPropSet( getSheet() );
355  aPropSet.setProperty( PROP_IsVisible, true );
356  }
357  // visible area and current cursor position (selection not supported via API)
358  ScAddress aFirstPos = xModel->maFirstPos;
359  const PaneSelectionModel* pPaneSel = xModel->getActiveSelection();
360  ScAddress aCursor = pPaneSel ? pPaneSel->maActiveCell : aFirstPos;
361 
362  // freeze/split position default
363  sal_Int16 nHSplitMode = API_SPLITMODE_NONE;
364  sal_Int16 nVSplitMode = API_SPLITMODE_NONE;
365  sal_Int32 nHSplitPos = 0;
366  sal_Int32 nVSplitPos = 0;
367  // active pane default
368  sal_Int16 nActivePane = API_SPLITPANE_BOTTOMLEFT;
369 
370  // freeze/split position
371  if( (xModel->mnPaneState == XML_frozen) || (xModel->mnPaneState == XML_frozenSplit) )
372  {
373  /* Frozen panes: handle split position as row/column positions.
374  #i35812# Excel uses number of visible rows/columns in the
375  frozen area (rows/columns scolled outside are not included),
376  Calc uses absolute position of first unfrozen row/column. */
377  const ScAddress& rMaxApiPos = getAddressConverter().getMaxApiAddress();
378  if( (xModel->mfSplitX >= 1.0) && ( xModel->maFirstPos.Col() + xModel->mfSplitX <= rMaxApiPos.Col() ) )
379  nHSplitPos = static_cast< sal_Int32 >( xModel->maFirstPos.Col() + xModel->mfSplitX );
380  nHSplitMode = (nHSplitPos > 0) ? API_SPLITMODE_FREEZE : API_SPLITMODE_NONE;
381  if( (xModel->mfSplitY >= 1.0) && ( xModel->maFirstPos.Row() + xModel->mfSplitY <= rMaxApiPos.Row() ) )
382  nVSplitPos = static_cast< sal_Int32 >( xModel->maFirstPos.Row() + xModel->mfSplitY );
383  nVSplitMode = (nVSplitPos > 0) ? API_SPLITMODE_FREEZE : API_SPLITMODE_NONE;
384  }
385  else if( xModel->mnPaneState == XML_split )
386  {
387  // split window: view settings API uses twips...
388  nHSplitPos = getLimitedValue< sal_Int32, double >( xModel->mfSplitX + 0.5, 0, SAL_MAX_INT32 );
389  nHSplitMode = (nHSplitPos > 0) ? API_SPLITMODE_SPLIT : API_SPLITMODE_NONE;
390  nVSplitPos = getLimitedValue< sal_Int32, double >( xModel->mfSplitY + 0.5, 0, SAL_MAX_INT32 );
391  nVSplitMode = (nVSplitPos > 0) ? API_SPLITMODE_SPLIT : API_SPLITMODE_NONE;
392  }
393 
394  // active pane
395  switch( xModel->mnActivePaneId )
396  {
397  // no horizontal split -> always use left panes
398  // no vertical split -> always use *bottom* panes
399  case XML_topLeft:
400  nActivePane = (nVSplitMode == API_SPLITMODE_NONE) ? API_SPLITPANE_BOTTOMLEFT : API_SPLITPANE_TOPLEFT;
401  break;
402  case XML_topRight:
403  nActivePane = (nHSplitMode == API_SPLITMODE_NONE) ?
404  ((nVSplitMode == API_SPLITMODE_NONE) ? API_SPLITPANE_BOTTOMLEFT : API_SPLITPANE_TOPLEFT) :
405  ((nVSplitMode == API_SPLITMODE_NONE) ? API_SPLITPANE_BOTTOMRIGHT : API_SPLITPANE_TOPRIGHT);
406  break;
407  case XML_bottomLeft:
408  nActivePane = API_SPLITPANE_BOTTOMLEFT;
409  break;
410  case XML_bottomRight:
411  nActivePane = (nHSplitMode == API_SPLITMODE_NONE) ? API_SPLITPANE_BOTTOMLEFT : API_SPLITPANE_BOTTOMRIGHT;
412  break;
413  }
414 
415  // write the sheet view settings into the property sequence
416  PropertyMap aPropMap;
417  aPropMap.setProperty( PROP_TableSelected, bSelected);
418  aPropMap.setProperty( PROP_CursorPositionX, aCursor.Col() );
419  aPropMap.setProperty( PROP_CursorPositionY, aCursor.Row() );
420  aPropMap.setProperty( PROP_HorizontalSplitMode, nHSplitMode);
421  aPropMap.setProperty( PROP_VerticalSplitMode, nVSplitMode);
422  aPropMap.setProperty( PROP_HorizontalSplitPositionTwips, nHSplitPos);
423  aPropMap.setProperty( PROP_VerticalSplitPositionTwips, nVSplitPos);
424  aPropMap.setProperty( PROP_ActiveSplitRange, nActivePane);
425  aPropMap.setProperty( PROP_PositionLeft, aFirstPos.Col() );
426  aPropMap.setProperty( PROP_PositionTop, aFirstPos.Row() );
427  aPropMap.setProperty( PROP_PositionRight, xModel->maSecondPos.Col() );
428  aPropMap.setProperty( PROP_PositionBottom, ((nVSplitPos > 0) ? xModel->maSecondPos.Row() : xModel->maFirstPos.Row() ) );
429  aPropMap.setProperty( PROP_ZoomType, API_ZOOMTYPE_PERCENT);
430  aPropMap.setProperty( PROP_ZoomValue, static_cast< sal_Int16 >( xModel->getNormalZoom() ));
431  aPropMap.setProperty( PROP_PageViewZoomValue, static_cast< sal_Int16 >( xModel->getPageBreakZoom() ));
432  aPropMap.setProperty( PROP_GridColor, xModel->getGridColor( getBaseFilter() ));
433  aPropMap.setProperty( PROP_ShowPageBreakPreview, xModel->isPageBreakPreview());
434  aPropMap.setProperty( PROP_ShowFormulas, xModel->mbShowFormulas);
435  aPropMap.setProperty( PROP_ShowGrid, xModel->mbShowGrid);
436  aPropMap.setProperty( PROP_HasColumnRowHeaders, xModel->mbShowHeadings);
437  aPropMap.setProperty( PROP_ShowZeroValues, xModel->mbShowZeros);
438  aPropMap.setProperty( PROP_IsOutlineSymbolsSet, xModel->mbShowOutline);
439 
440  // store sheet view settings in global view settings object
442 }
443 
445 {
446  return !maSheetViews.empty() && maSheetViews.front()->mbRightToLeft;
447 }
448 
449 // private --------------------------------------------------------------------
450 
452 {
453  SheetViewModelRef xModel = std::make_shared<SheetViewModel>();
454  maSheetViews.push_back( xModel );
455  return xModel;
456 }
457 
459  mnWinX( 0 ),
460  mnWinY( 0 ),
461  mnWinWidth( 0 ),
462  mnWinHeight( 0 ),
463  mnActiveSheet( 0 ),
464  mnFirstVisSheet( 0 ),
465  mnTabBarWidth( OOX_BOOKVIEW_TABBARRATIO_DEF ),
466  mnVisibility( XML_visible ),
467  mbShowTabBar( true ),
468  mbShowHorScroll( true ),
469  mbShowVerScroll( true ),
470  mbMinimized( false )
471 {
472 }
473 
475  WorkbookHelper( rHelper ),
476  mbValidOleSize( false )
477 {
478 }
479 
481 {
483  rModel.mnWinX = rAttribs.getInteger( XML_xWindow, 0 );
484  rModel.mnWinY = rAttribs.getInteger( XML_yWindow, 0 );
485  rModel.mnWinWidth = rAttribs.getInteger( XML_windowWidth, 0 );
486  rModel.mnWinHeight = rAttribs.getInteger( XML_windowHeight, 0 );
487  rModel.mnActiveSheet = rAttribs.getInteger( XML_activeTab, 0 );
488  rModel.mnFirstVisSheet = rAttribs.getInteger( XML_firstSheet, 0 );
489  rModel.mnTabBarWidth = rAttribs.getInteger( XML_tabRatio, 600 );
490  rModel.mnVisibility = rAttribs.getToken( XML_visibility, XML_visible );
491  rModel.mbShowTabBar = rAttribs.getBool( XML_showSheetTabs, true );
492  rModel.mbShowHorScroll = rAttribs.getBool( XML_showHorizontalScroll, true );
493  rModel.mbShowVerScroll = rAttribs.getBool( XML_showVerticalScroll, true );
494  rModel.mbMinimized = rAttribs.getBool( XML_minimized, false );
495 }
496 
498 {
499  OUString aRange = rAttribs.getString( XML_ref, OUString() );
500  mbValidOleSize = getAddressConverter().convertToCellRange( maOleSize, aRange, 0, true, false );
501 }
502 
504 {
506  sal_uInt8 nFlags;
507  rModel.mnWinX = rStrm.readInt32();
508  rModel.mnWinY = rStrm.readInt32();
509  rModel.mnWinWidth = rStrm.readInt32();
510  rModel.mnWinHeight = rStrm.readInt32();
511  rModel.mnTabBarWidth = rStrm.readInt32();
512  rModel.mnFirstVisSheet = rStrm.readInt32();
513  rModel.mnActiveSheet = rStrm.readInt32();
514  nFlags = rStrm.readuChar();
515  rModel.mnVisibility = getFlagValue( nFlags, BIFF12_WBVIEW_HIDDEN, XML_hidden, XML_visible );
516  rModel.mbShowTabBar = getFlag( nFlags, BIFF12_WBVIEW_SHOWTABBAR );
517  rModel.mbShowHorScroll = getFlag( nFlags, BIFF12_WBVIEW_SHOWHORSCROLL );
518  rModel.mbShowVerScroll = getFlag( nFlags, BIFF12_WBVIEW_SHOWVERSCROLL );
519  rModel.mbMinimized = getFlag( nFlags, BIFF12_WBVIEW_MINIMIZED );
520 }
521 
523 {
524  BinRange aBinRange;
525  rStrm >> aBinRange;
526  mbValidOleSize = getAddressConverter().convertToCellRange( maOleSize, aBinRange, 0, true, false );
527 }
528 
529 void ViewSettings::setSheetViewSettings( sal_Int16 nSheet, const SheetViewModelRef& rxSheetView, const Any& rProperties )
530 {
531  maSheetViews[ nSheet ] = rxSheetView;
532  maSheetProps[ nSheet ] = rProperties;
533 }
534 
535 void ViewSettings::setSheetUsedArea( const ScRange& rUsedArea )
536 {
537  assert( rUsedArea.IsValid() );
538  maSheetUsedAreas[ rUsedArea.aStart.Tab() ] = rUsedArea;
539 }
540 
542 {
543  const WorksheetBuffer& rWorksheets = getWorksheets();
544  if( rWorksheets.getWorksheetCount() <= 0 ) return;
545 
546  // force creation of workbook view model to get the Excel defaults
547  const WorkbookViewModel& rModel = maBookViews.empty() ? createWorkbookView() : *maBookViews.front();
548 
549  // show object mode is part of workbook settings
550  sal_Int16 nShowMode = getWorkbookSettings().getApiShowObjectMode();
551 
552  // view settings for all sheets
553  Reference< XNameContainer > xSheetsNC = NamedPropertyValues::create( getBaseFilter().getComponentContext() );
554  if( !xSheetsNC.is() ) return;
555  for( const auto& [rWorksheet, rObj] : maSheetProps )
556  ContainerHelper::insertByName( xSheetsNC, rWorksheets.getCalcSheetName( rWorksheet ), rObj );
557 
558  // use active sheet to set sheet properties that are document-global in Calc
559  sal_Int16 nActiveSheet = getActiveCalcSheet();
560  SheetViewModelRef& rxActiveSheetView = maSheetViews[ nActiveSheet ];
561  OSL_ENSURE( rxActiveSheetView, "ViewSettings::finalizeImport - missing active sheet view settings" );
562  if( !rxActiveSheetView )
563  rxActiveSheetView = std::make_shared<SheetViewModel>();
564 
565  Reference< XIndexContainer > xContainer = IndexedPropertyValues::create( getBaseFilter().getComponentContext() );
566  if( xContainer.is() ) try
567  {
568  PropertyMap aPropMap;
569  aPropMap.setProperty( PROP_Tables, xSheetsNC);
570  aPropMap.setProperty( PROP_ActiveTable, rWorksheets.getCalcSheetName( nActiveSheet ));
571  aPropMap.setProperty( PROP_HasHorizontalScrollBar, rModel.mbShowHorScroll);
572  aPropMap.setProperty( PROP_HasVerticalScrollBar, rModel.mbShowVerScroll);
573  aPropMap.setProperty( PROP_HasSheetTabs, rModel.mbShowTabBar);
574  aPropMap.setProperty( PROP_RelativeHorizontalTabbarWidth, double( rModel.mnTabBarWidth / 1000.0 ));
575  aPropMap.setProperty( PROP_ShowObjects, nShowMode);
576  aPropMap.setProperty( PROP_ShowCharts, nShowMode);
577  aPropMap.setProperty( PROP_ShowDrawing, nShowMode);
578  aPropMap.setProperty( PROP_GridColor, rxActiveSheetView->getGridColor( getBaseFilter() ));
579  aPropMap.setProperty( PROP_ShowPageBreakPreview, rxActiveSheetView->isPageBreakPreview());
580  aPropMap.setProperty( PROP_ShowFormulas, rxActiveSheetView->mbShowFormulas);
581  aPropMap.setProperty( PROP_ShowGrid, rxActiveSheetView->mbShowGrid);
582  aPropMap.setProperty( PROP_HasColumnRowHeaders, rxActiveSheetView->mbShowHeadings);
583  aPropMap.setProperty( PROP_ShowZeroValues, rxActiveSheetView->mbShowZeros);
584  aPropMap.setProperty( PROP_IsOutlineSymbolsSet, rxActiveSheetView->mbShowOutline);
585 
586  xContainer->insertByIndex( 0, Any( aPropMap.makePropertyValueSequence() ) );
587  Reference< XViewDataSupplier > xViewDataSuppl( getDocument(), UNO_QUERY_THROW );
588  xViewDataSuppl->setViewData( xContainer );
589  }
590  catch( Exception& )
591  {
592  OSL_FAIL( "ViewSettings::finalizeImport - cannot create document view settings" );
593  }
594 
595  /* Set visible area to be used if this document is an embedded OLE object.
596  #i44077# If a new OLE object is inserted from file, there is no OLESIZE
597  record in the Excel file. In this case, use the used area calculated
598  from file contents (used cells and drawing objects). */
599  maOleSize.aStart.SetTab( nActiveSheet );
600  maOleSize.aEnd.SetTab( nActiveSheet );
601  const ScRange* pVisibleArea = mbValidOleSize ?
603  if( !pVisibleArea )
604  return;
605 
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 ) )
611  {
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;
619  }
620 }
621 
623 {
624  return maBookViews.empty() ? 0 : ::std::max< sal_Int16 >( getWorksheets().getCalcSheetIndex( maBookViews.front()->mnActiveSheet ), 0 );
625 }
626 
627 // private --------------------------------------------------------------------
628 
630 {
631  WorkbookViewModelRef xModel = std::make_shared<WorkbookViewModel>();
632  maBookViews.push_back( xModel );
633  return *xModel;
634 }
635 
636 } // namespace oox
637 
638 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Helper class to provide access to global workbook data.
sal_Int32 mnWinWidth
Y position of the workbook window (twips).
bool isSheetRightToLeft() const
Returns true, if the sheet layout is set to right-to-left.
bool mbZoomToFit
True = show outlines.
sal_Int32 mnWinHeight
Width of the workbook window (twips).
WorkbookViewModelVec maBookViews
double mfSplitY
Split X position (twips), or number of frozen columns.
sal_Int32 mnTabBarWidth
First visible sheet in sheet tabbar.
sal_Int32 mnActivePaneId
View type (normal, page break, layout).
ScAddress aStart
Definition: address.hxx:500
OptValue< bool > getBool(sal_Int32 nAttrToken) const
sal_Int16 getApiShowObjectMode() const
Returns the show objects mode (considered a view setting in Calc).
sal_Int32 mnNormalZoom
Zoom factor for current view.
SCROW Row() const
Definition: address.hxx:262
bool mbShowGrid
True = show formulas instead of results.
Stores information about all sheets in a spreadsheet document.
bool getProperty(Type &orValue, sal_Int32 nPropId) const
A 2D cell range address list for binary filters.
A 2D cell address struct for binary filters.
OptValue< sal_Int32 > getInteger(sal_Int32 nAttrToken) const
ScRange maOleSize
Used area (cell range) of every sheet.
sal_Int32 mnCurrentZoom
Split Y position (twips), or number of frozen rows.
const sal_Int32 OOX_COLOR_WINDOWTEXT
System window background color (BIFF3-BIFF4).
OUString getCalcSheetName(sal_Int32 nWorksheet) const
Returns the finalized name of the specified worksheet.
A 2D cell range address struct for binary filters.
::Color getGridColor(const ::oox::core::FilterBase &rFilter) const
Returns the grid color as RGB value.
Contains all view settings for the entire document.
const ScAddress & getMaxApiAddress() const
Returns the biggest valid cell address in the own Calc document.
bool setProperty(sal_Int32 nPropId, Type &&rValue)
void finalizeImport()
Converts all imported sheet view settings.
ScAddress aEnd
Definition: address.hxx:501
ScRangeList maSelection
Position of active cell (cursor).
OptValue< double > getDouble(sal_Int32 nAttrToken) const
css::uno::Reference< css::table::XCellRange > getCellRangeFromDoc(const ScRange &rRange) const
Returns the XCellRange interface for the passed cell range address.
#define STATIC_ARRAY_SELECT(array, index, def)
OptValue< OUString > getString(sal_Int32 nAttrToken) const
unsigned char readuChar()
ScAddress maFirstPos
Grid color.
bool mbMinimized
True = show vertical sheet scrollbars.
utl::MediaDescriptor & getMediaDescriptor() const
void importChartSheetView(const AttributeList &rAttribs)
Imports the sheetView element containing view settings of a chart sheet.
void setSheetViewSettings(sal_Int16 nSheet, const SheetViewModelRef &rxSheetView, const css::uno::Any &rProperties)
Stores converted view settings for a specific worksheet.
WorkbookSettings & getWorkbookSettings() const
Returns the global workbook settings object.
sal_Int32 mnWinY
X position of the workbook window (twips).
bool mbShowZeros
True = show column/row headings.
ScAddress maSecondPos
First visible cell.
PaneSelectionModel()
Index of active cell in selection list.
bool isPageBreakPreview() const
Returns true, if page break preview is active.
ViewSettings & getViewSettings() const
Returns the workbook and sheet view settings object.
sal_uInt16 readuInt16()
sal_Int32 mnViewType
Index into list of workbookView elements.
SheetViewModel()
True = zoom chart sheet to fit window.
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
std::shared_ptr< SheetViewModel > SheetViewModelRef
::oox::core::FilterBase & getBaseFilter() const
Returns the base filter object (base class of all filters).
SCTAB Tab() const
Definition: address.hxx:271
sal_Int32 mnVisibility
Width of sheet tabbar (1/1000 of window width).
sal_Int16 getActiveCalcSheet() const
Returns the Calc index of the active sheet.
SheetViewModelMap maSheetViews
Workbook view models.
bool getFlag(Type nBitField, Type nMask)
const ::Color API_RGB_TRANSPARENT(ColorTransparency, 0xffffffff)
Contains all settings for a selection in a single pane of a sheet.
void SetTab(SCTAB nTabP)
Definition: address.hxx:283
bool mbRightToLeft
True = sheet is selected.
#define SAL_MAX_INT32
sal_Int32 getPageBreakZoom() const
Returns the zoom in pagebreak preview (returns default, if current value is 0).
std::shared_ptr< WorkbookViewModel > WorkbookViewModelRef
const css::uno::Reference< css::sheet::XSpreadsheetDocument > & getDocument() const
Returns a reference to the source/target spreadsheet document model.
sal_Int16 SCCOL
Definition: types.hxx:22
SheetViewModelRef createSheetView()
::Color getColor(const GraphicHelper &rGraphicHelper,::Color nPhClr=API_RGB_TRANSPARENT) const
WorksheetType getSheetType() const
Returns the type of this sheet.
void importSelection(const AttributeList &rAttribs)
Imports the selection element containing selection settings for a pane.
container_type::mapped_type mapped_type
sal_Int32 mnPaneState
Active pane (with cell cursor).
SheetViewSettings(const WorksheetHelper &rHelper)
bool mbDefGridColor
True = sheet in right-to-left mode.
css::uno::Sequence< css::beans::PropertyValue > makePropertyValueSequence() const
void convertToCellRangeList(ScRangeList &orRanges, const OUString &rString, sal_Int16 nSheet, bool bTrackOverflow)
Tries to convert the passed string to a cell range list.
sal_Int32 mnPageLayoutZoom
Zoom factor for pagebreak preview.
static bool insertByName(const css::uno::Reference< css::container::XNameContainer > &rxNameContainer, const OUString &rName, const css::uno::Any &rObject)
WorkbookViewModel()
True = workbook window is minimized.
SheetViewModelVec maSheetViews
Reference< XComponentContext > getComponentContext(Reference< XMultiServiceFactory > const &factory)
sal_Int32 getNormalZoom() const
Returns the zoom in normal view (returns default, if current value is 0).
bool IsValid() const
Definition: address.hxx:547
bool convertToCellRange(ScRange &orRange, const OUString &rString, sal_Int16 nSheet, bool bAllowOverflow, bool bTrackOverflow)
Tries to convert the passed string to a cell range address.
sal_Int32 getWorksheetCount() const
Returns the number of original sheets contained in the workbook.
SCCOL Col() const
Definition: address.hxx:267
sal_Int32 mnFirstVisSheet
Displayed (active) sheet.
void importColorId(SequenceInputStream &rStrm)
Imports a 32-bit palette color identifier from the passed BIFF12 stream.
double mfSplitX
Pane state (frozen, split).
static const MapType::mapped_type * getMapElement(const MapType &rMap, const typename MapType::key_type &rKey)
sal_Int16 getCalcSheetIndex(sal_Int32 nWorksheet) const
Returns the Calc index of the specified worksheet.
sal_Int32 SCROW
Definition: types.hxx:18
mapped_type get(key_type nKey) const
bool mbSelected
Zoom factor for page layout view.
void setSheetUsedArea(const ScRange &rUsedArea)
Stores the used area for a specific worksheet.
ScAddress createValidCellAddress(const OUString &rString, sal_Int16 nSheet, bool bTrackOverflow)
Returns a valid cell address by moving it into allowed dimensions.
const css::uno::Reference< css::sheet::XSpreadsheet > & getSheet() const
Returns the XSpreadsheet interface of the current sheet.
unsigned char sal_uInt8
ReturnType getFlagValue(Type nBitField, Type nMask, ReturnType nSet, ReturnType nUnset)
WorkbookViewModel & createWorkbookView()
std::map< sal_Int16, ScRange > maSheetUsedAreas
Converted property sequences for each sheet.
void importWorkbookView(const AttributeList &rAttribs)
Imports the workbookView element containing workbook view settings.
SCTAB getSheetIndex() const
Returns the index of the current sheet.
ViewSettings(const WorkbookHelper &rHelper)
bool mbShowOutline
True = show zero value zells.
void finalizeImport()
Converts all imported document view settings.
void importSheetView(const AttributeList &rAttribs)
Imports the sheetView element containing sheet view settings.
void setIndexed(sal_Int32 nPaletteIdx, double fTint=0.0)
Sets the color to the passed palette index.
const PaneSelectionModel * getActiveSelection() const
Returns the selection data of the active pane.
sal_Int32 mnSheetLayoutZoom
Zoom factor for normal view.
PaneSelectionModel & createPaneSelection(sal_Int32 nPaneId)
Returns read/write access to the selection data of the specified pane.
bool mbShowHeadings
True = show cell grid.
Reference< XModel > xModel
bool mbShowHorScroll
True = show sheet tabbar.
sal_Int32 mnActiveCellId
Selected cell ranges.
bool mbValidOleSize
Visible area if this is an embedded OLE object.
Color maGridColor
Selections of all panes.
sal_Int32 mnWorkbookViewId
First visible cell in additional panes.
bool mbShowVerScroll
True = show horizontal sheet scrollbars.
void importPane(const AttributeList &rAttribs)
Imports the pane element containing sheet pane settings.
bool mbShowTabBar
Visibility state of workbook window.
bool mbShowFormulas
True = default grid color.
std::map< sal_Int16, css::uno::Any > maSheetProps
Active view model for each sheet.
Contains all view settings for a single sheet.
PaneSelectionModelMap maPaneSelMap
void RemoveAll()
Definition: rangelst.cxx:1106
bool setProperty(sal_Int32 nPropId, const Type &rValue)
sal_Int32 mnActiveSheet
Height of the workbook window (twips).
OptValue< sal_Int32 > getToken(sal_Int32 nAttrToken) const
AddressConverter & getAddressConverter() const
Returns the converter for string to cell address/range conversion.
void importOleSize(const AttributeList &rAttribs)
Imports the oleSize element containing the visible size of the workbook.
WorksheetBuffer & getWorksheets() const
Returns the worksheet buffer containing sheet names and properties.