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 <com/sun/star/table/XCellRange.hpp>
32 #include <osl/diagnose.h>
34 #include <oox/core/filterbase.hxx>
40 #include <oox/token/properties.hxx>
41 #include <oox/token/tokens.hxx>
42 #include <addressconverter.hxx>
43 #include <workbooksettings.hxx>
44 #include <worksheetbuffer.hxx>
45 
46 namespace com::sun::star::container { class XNameContainer; }
47 
48 namespace oox::xls {
49 
50 using namespace ::com::sun::star::awt;
51 using namespace ::com::sun::star::container;
52 using namespace ::com::sun::star::document;
53 using namespace ::com::sun::star::uno;
54 
55 using ::oox::core::FilterBase;
56 
57 namespace {
58 
59 const sal_Int32 OOX_BOOKVIEW_TABBARRATIO_DEF = 600;
60 const sal_Int32 OOX_SHEETVIEW_NORMALZOOM_DEF = 100;
61 const sal_Int32 OOX_SHEETVIEW_SHEETLAYZOOM_DEF = 60;
62 
63 const sal_uInt8 BIFF12_PANE_FROZEN = 0x01;
64 const sal_uInt8 BIFF12_PANE_FROZENNOSPLIT = 0x02;
65 
66 const sal_uInt16 BIFF12_SHEETVIEW_SHOWFORMULAS = 0x0002;
67 const sal_uInt16 BIFF12_SHEETVIEW_SHOWGRID = 0x0004;
68 const sal_uInt16 BIFF12_SHEETVIEW_SHOWHEADINGS = 0x0008;
69 const sal_uInt16 BIFF12_SHEETVIEW_SHOWZEROS = 0x0010;
70 const sal_uInt16 BIFF12_SHEETVIEW_RIGHTTOLEFT = 0x0020;
71 const sal_uInt16 BIFF12_SHEETVIEW_SELECTED = 0x0040;
72 const sal_uInt16 BIFF12_SHEETVIEW_SHOWOUTLINE = 0x0100;
73 const sal_uInt16 BIFF12_SHEETVIEW_DEFGRIDCOLOR = 0x0200;
74 
75 const sal_uInt16 BIFF12_CHARTSHEETVIEW_SELECTED = 0x0001;
76 const sal_uInt16 BIFF12_CHARTSHEETVIEW_ZOOMTOFIT = 0x0002;
77 
78 const sal_uInt8 BIFF12_WBVIEW_HIDDEN = 0x01;
79 const sal_uInt8 BIFF12_WBVIEW_MINIMIZED = 0x02;
80 const sal_uInt8 BIFF12_WBVIEW_SHOWHORSCROLL = 0x08;
81 const sal_uInt8 BIFF12_WBVIEW_SHOWVERSCROLL = 0x10;
82 const sal_uInt8 BIFF12_WBVIEW_SHOWTABBAR = 0x20;
83 
84 // Attention: view settings in Calc do not use com.sun.star.view.DocumentZoomType!
85 const sal_Int16 API_ZOOMTYPE_PERCENT = 0;
86 
87 const sal_Int32 API_ZOOMVALUE_MIN = 20;
88 const sal_Int32 API_ZOOMVALUE_MAX = 400;
89 
90 // no predefined constants for split mode
91 const sal_Int16 API_SPLITMODE_NONE = 0;
92 const sal_Int16 API_SPLITMODE_SPLIT = 1;
93 const sal_Int16 API_SPLITMODE_FREEZE = 2;
94 
95 // no predefined constants for pane identifiers
96 const sal_Int16 API_SPLITPANE_TOPLEFT = 0;
97 const sal_Int16 API_SPLITPANE_TOPRIGHT = 1;
98 const sal_Int16 API_SPLITPANE_BOTTOMLEFT = 2;
99 const sal_Int16 API_SPLITPANE_BOTTOMRIGHT = 3;
100 
102 sal_Int32 lclGetOoxPaneId( sal_Int32 nBiffPaneId, sal_Int32 nDefaultPaneId )
103 {
104  static const sal_Int32 spnPaneIds[] = { XML_bottomRight, XML_topRight, XML_bottomLeft, XML_topLeft };
105  return STATIC_ARRAY_SELECT( spnPaneIds, nBiffPaneId, nDefaultPaneId );
106 }
107 
108 } // namespace
109 
111  mnActiveCellId( 0 )
112 {
113 }
114 
116  mnWorkbookViewId( 0 ),
117  mnViewType( XML_normal ),
118  mnActivePaneId( XML_topLeft ),
119  mnPaneState( XML_split ),
120  mfSplitX( 0.0 ),
121  mfSplitY( 0.0 ),
122  mnCurrentZoom( 0 ),
123  mnNormalZoom( 0 ),
124  mnSheetLayoutZoom( 0 ),
125  mnPageLayoutZoom( 0 ),
126  mbSelected( false ),
127  mbRightToLeft( false ),
128  mbDefGridColor( true ),
129  mbShowFormulas( false ),
130  mbShowGrid( true ),
131  mbShowHeadings( true ),
132  mbShowZeros( true ),
133  mbShowOutline( true ),
134  mbZoomToFit( false )
135 {
137 }
138 
140 {
141  return mnViewType == XML_pageBreakPreview;
142 }
143 
145 {
146  const sal_Int32& rnZoom = isPageBreakPreview() ? mnNormalZoom : mnCurrentZoom;
147  sal_Int32 nZoom = (rnZoom > 0) ? rnZoom : OOX_SHEETVIEW_NORMALZOOM_DEF;
148  return getLimitedValue< sal_Int32 >( nZoom, API_ZOOMVALUE_MIN, API_ZOOMVALUE_MAX );
149 }
150 
152 {
153  const sal_Int32& rnZoom = isPageBreakPreview() ? mnCurrentZoom : mnSheetLayoutZoom;
154  sal_Int32 nZoom = (rnZoom > 0) ? rnZoom : OOX_SHEETVIEW_SHEETLAYZOOM_DEF;
155  return getLimitedValue< sal_Int32 >( nZoom, API_ZOOMVALUE_MIN, API_ZOOMVALUE_MAX );
156 }
157 
158 ::Color SheetViewModel::getGridColor( const FilterBase& rFilter ) const
159 {
160  return mbDefGridColor ? API_RGB_TRANSPARENT : maGridColor.getColor( rFilter.getGraphicHelper() );
161 }
162 
164 {
165  return maPaneSelMap.get( mnActivePaneId ).get();
166 }
167 
169 {
170  PaneSelectionModelMap::mapped_type& rxPaneSel = maPaneSelMap[ nPaneId ];
171  if( !rxPaneSel )
172  rxPaneSel = std::make_shared<PaneSelectionModel>();
173  return *rxPaneSel;
174 }
175 
177  WorksheetHelper( rHelper )
178 {
179 }
180 
182 {
183  SheetViewModel& rModel = *createSheetView();
184  rModel.maGridColor.setIndexed( rAttribs.getInteger( XML_colorId, OOX_COLOR_WINDOWTEXT ) );
185  rModel.maFirstPos = getAddressConverter().createValidCellAddress( rAttribs.getString( XML_topLeftCell, OUString() ), getSheetIndex(), false );
186  rModel.mnWorkbookViewId = rAttribs.getToken( XML_workbookViewId, 0 );
187  rModel.mnViewType = rAttribs.getToken( XML_view, XML_normal );
188  rModel.mnCurrentZoom = rAttribs.getInteger( XML_zoomScale, 100 );
189  rModel.mnNormalZoom = rAttribs.getInteger( XML_zoomScaleNormal, 0 );
190  rModel.mnSheetLayoutZoom = rAttribs.getInteger( XML_zoomScaleSheetLayoutView, 0 );
191  rModel.mnPageLayoutZoom = rAttribs.getInteger( XML_zoomScalePageLayoutView, 0 );
192  rModel.mbSelected = rAttribs.getBool( XML_tabSelected, false );
193  rModel.mbRightToLeft = rAttribs.getBool( XML_rightToLeft, false );
194  rModel.mbDefGridColor = rAttribs.getBool( XML_defaultGridColor, true );
195  rModel.mbShowFormulas = rAttribs.getBool( XML_showFormulas, false );
196  rModel.mbShowGrid = rAttribs.getBool( XML_showGridLines, true );
197  rModel.mbShowHeadings = rAttribs.getBool( XML_showRowColHeaders, true );
198  rModel.mbShowZeros = rAttribs.getBool( XML_showZeros, true );
199  rModel.mbShowOutline = rAttribs.getBool( XML_showOutlineSymbols, true );
200 }
201 
203 {
204  OSL_ENSURE( !maSheetViews.empty(), "SheetViewSettings::importPane - missing sheet view model" );
205  if( !maSheetViews.empty() )
206  {
207  SheetViewModel& rModel = *maSheetViews.back();
208  rModel.maSecondPos = getAddressConverter().createValidCellAddress( rAttribs.getString( XML_topLeftCell, OUString() ), getSheetIndex(), false );
209  rModel.mnActivePaneId = rAttribs.getToken( XML_activePane, XML_topLeft );
210  rModel.mnPaneState = rAttribs.getToken( XML_state, XML_split );
211  rModel.mfSplitX = rAttribs.getDouble( XML_xSplit, 0.0 );
212  rModel.mfSplitY = rAttribs.getDouble( XML_ySplit, 0.0 );
213  }
214 }
215 
217 {
218  OSL_ENSURE( !maSheetViews.empty(), "SheetViewSettings::importSelection - missing sheet view model" );
219  if( !maSheetViews.empty() )
220  {
221  // pane this selection belongs to
222  sal_Int32 nPaneId = rAttribs.getToken( XML_pane, XML_topLeft );
223  PaneSelectionModel& rSelData = maSheetViews.back()->createPaneSelection( nPaneId );
224  // cursor position
225  rSelData.maActiveCell = getAddressConverter().createValidCellAddress( rAttribs.getString( XML_activeCell, OUString() ), getSheetIndex(), false );
226  rSelData.mnActiveCellId = rAttribs.getInteger( XML_activeCellId, 0 );
227  // selection
228  rSelData.maSelection.RemoveAll();
229  getAddressConverter().convertToCellRangeList( rSelData.maSelection, rAttribs.getString( XML_sqref, OUString() ), getSheetIndex(), false );
230  }
231 }
232 
234 {
235  SheetViewModel& rModel = *createSheetView();
236  rModel.mnWorkbookViewId = rAttribs.getToken( XML_workbookViewId, 0 );
237  rModel.mnCurrentZoom = rAttribs.getInteger( XML_zoomScale, 100 );
238  rModel.mbSelected = rAttribs.getBool( XML_tabSelected, false );
239  rModel.mbZoomToFit = rAttribs.getBool( XML_zoomToFit, false );
240 }
241 
243 {
244  SheetViewModel& rModel = *createSheetView();
245  sal_uInt16 nFlags;
246  sal_Int32 nViewType;
247  BinAddress aFirstPos;
248  nFlags = rStrm.readuInt16();
249  nViewType = rStrm.readInt32();
250  rStrm >> aFirstPos;
251  rModel.maGridColor.importColorId( rStrm );
252  rModel.mnCurrentZoom = rStrm.readuInt16();
253  rModel.mnNormalZoom = rStrm.readuInt16();
254  rModel.mnSheetLayoutZoom = rStrm.readuInt16();
255  rModel.mnPageLayoutZoom = rStrm.readuInt16();
256  rModel.mnWorkbookViewId = rStrm.readInt32();
257 
258  rModel.maFirstPos = getAddressConverter().createValidCellAddress( aFirstPos, getSheetIndex(), false );
259  static const sal_Int32 spnViewTypes[] = { XML_normal, XML_pageBreakPreview, XML_pageLayout };
260  rModel.mnViewType = STATIC_ARRAY_SELECT( spnViewTypes, nViewType, XML_normal );
261  rModel.mbSelected = getFlag( nFlags, BIFF12_SHEETVIEW_SELECTED );
262  rModel.mbRightToLeft = getFlag( nFlags, BIFF12_SHEETVIEW_RIGHTTOLEFT );
263  rModel.mbDefGridColor = getFlag( nFlags, BIFF12_SHEETVIEW_DEFGRIDCOLOR );
264  rModel.mbShowFormulas = getFlag( nFlags, BIFF12_SHEETVIEW_SHOWFORMULAS );
265  rModel.mbShowGrid = getFlag( nFlags, BIFF12_SHEETVIEW_SHOWGRID );
266  rModel.mbShowHeadings = getFlag( nFlags, BIFF12_SHEETVIEW_SHOWHEADINGS );
267  rModel.mbShowZeros = getFlag( nFlags, BIFF12_SHEETVIEW_SHOWZEROS );
268  rModel.mbShowOutline = getFlag( nFlags, BIFF12_SHEETVIEW_SHOWOUTLINE );
269 }
270 
272 {
273  OSL_ENSURE( !maSheetViews.empty(), "SheetViewSettings::importPane - missing sheet view model" );
274  if( !maSheetViews.empty() )
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 }
292 
294 {
295  OSL_ENSURE( !maSheetViews.empty(), "SheetViewSettings::importSelection - missing sheet view model" );
296  if( !maSheetViews.empty() )
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 }
313 
315 {
316  SheetViewModel& rModel = *createSheetView();
317  sal_uInt16 nFlags;
318  nFlags = rStrm.readuInt16();
319  rModel.mnCurrentZoom = rStrm.readInt32();
320  rModel.mnWorkbookViewId = rStrm.readInt32();
321 
322  rModel.mbSelected = getFlag( nFlags, BIFF12_CHARTSHEETVIEW_SELECTED );
323  rModel.mbZoomToFit = getFlag( nFlags, BIFF12_CHARTSHEETVIEW_ZOOMTOFIT );
324 }
325 
327 {
328  // force creation of sheet view model to get the Excel defaults
330 
331  // #i59590# #158194# special handling for chart sheets (Excel ignores some settings in chart sheets)
333  {
334  xModel->maPaneSelMap.clear();
335  xModel->maFirstPos = xModel->maSecondPos = ScAddress( SCCOL ( 0 ), SCROW ( 0 ), getSheetIndex() );
336  xModel->mnViewType = XML_normal;
337  xModel->mnActivePaneId = XML_topLeft;
338  xModel->mnPaneState = XML_split;
339  xModel->mfSplitX = xModel->mfSplitY = 0.0;
340  xModel->mbRightToLeft = false;
341  xModel->mbDefGridColor = true;
342  xModel->mbShowFormulas = false;
343  xModel->mbShowGrid = true;
344  xModel->mbShowHeadings = true;
345  xModel->mbShowZeros = true;
346  xModel->mbShowOutline = true;
347  }
348 
349  // sheet selected (active sheet must be selected)
350  bool bSelected = xModel->mbSelected || (getSheetIndex() == getViewSettings().getActiveCalcSheet());
351  if ( bSelected )
352  {
353  // active tab/sheet cannot be hidden
354  // always force it to be displayed
355  PropertySet aPropSet( getSheet() );
356  aPropSet.setProperty( PROP_IsVisible, true );
357  }
358  // visible area and current cursor position (selection not supported via API)
359  ScAddress aFirstPos = xModel->maFirstPos;
360  const PaneSelectionModel* pPaneSel = xModel->getActiveSelection();
361  ScAddress aCursor = pPaneSel ? pPaneSel->maActiveCell : aFirstPos;
362 
363  // freeze/split position default
364  sal_Int16 nHSplitMode = API_SPLITMODE_NONE;
365  sal_Int16 nVSplitMode = API_SPLITMODE_NONE;
366  sal_Int32 nHSplitPos = 0;
367  sal_Int32 nVSplitPos = 0;
368  // active pane default
369  sal_Int16 nActivePane = API_SPLITPANE_BOTTOMLEFT;
370 
371  // freeze/split position
372  if( (xModel->mnPaneState == XML_frozen) || (xModel->mnPaneState == XML_frozenSplit) )
373  {
374  /* Frozen panes: handle split position as row/column positions.
375  #i35812# Excel uses number of visible rows/columns in the
376  frozen area (rows/columns scolled outside are not included),
377  Calc uses absolute position of first unfrozen row/column. */
378  const ScAddress& rMaxApiPos = getAddressConverter().getMaxApiAddress();
379  if( (xModel->mfSplitX >= 1.0) && ( xModel->maFirstPos.Col() + xModel->mfSplitX <= rMaxApiPos.Col() ) )
380  nHSplitPos = static_cast< sal_Int32 >( xModel->maFirstPos.Col() + xModel->mfSplitX );
381  nHSplitMode = (nHSplitPos > 0) ? API_SPLITMODE_FREEZE : API_SPLITMODE_NONE;
382  if( (xModel->mfSplitY >= 1.0) && ( xModel->maFirstPos.Row() + xModel->mfSplitY <= rMaxApiPos.Row() ) )
383  nVSplitPos = static_cast< sal_Int32 >( xModel->maFirstPos.Row() + xModel->mfSplitY );
384  nVSplitMode = (nVSplitPos > 0) ? API_SPLITMODE_FREEZE : API_SPLITMODE_NONE;
385  }
386  else if( xModel->mnPaneState == XML_split )
387  {
388  // split window: view settings API uses twips...
389  nHSplitPos = getLimitedValue< sal_Int32, double >( xModel->mfSplitX + 0.5, 0, SAL_MAX_INT32 );
390  nHSplitMode = (nHSplitPos > 0) ? API_SPLITMODE_SPLIT : API_SPLITMODE_NONE;
391  nVSplitPos = getLimitedValue< sal_Int32, double >( xModel->mfSplitY + 0.5, 0, SAL_MAX_INT32 );
392  nVSplitMode = (nVSplitPos > 0) ? API_SPLITMODE_SPLIT : API_SPLITMODE_NONE;
393  }
394 
395  // active pane
396  switch( xModel->mnActivePaneId )
397  {
398  // no horizontal split -> always use left panes
399  // no vertical split -> always use *bottom* panes
400  case XML_topLeft:
401  nActivePane = (nVSplitMode == API_SPLITMODE_NONE) ? API_SPLITPANE_BOTTOMLEFT : API_SPLITPANE_TOPLEFT;
402  break;
403  case XML_topRight:
404  nActivePane = (nHSplitMode == API_SPLITMODE_NONE) ?
405  ((nVSplitMode == API_SPLITMODE_NONE) ? API_SPLITPANE_BOTTOMLEFT : API_SPLITPANE_TOPLEFT) :
406  ((nVSplitMode == API_SPLITMODE_NONE) ? API_SPLITPANE_BOTTOMRIGHT : API_SPLITPANE_TOPRIGHT);
407  break;
408  case XML_bottomLeft:
409  nActivePane = API_SPLITPANE_BOTTOMLEFT;
410  break;
411  case XML_bottomRight:
412  nActivePane = (nHSplitMode == API_SPLITMODE_NONE) ? API_SPLITPANE_BOTTOMLEFT : API_SPLITPANE_BOTTOMRIGHT;
413  break;
414  }
415 
416  // write the sheet view settings into the property sequence
417  PropertyMap aPropMap;
418  aPropMap.setProperty( PROP_TableSelected, bSelected);
419  aPropMap.setProperty( PROP_CursorPositionX, aCursor.Col() );
420  aPropMap.setProperty( PROP_CursorPositionY, aCursor.Row() );
421  aPropMap.setProperty( PROP_HorizontalSplitMode, nHSplitMode);
422  aPropMap.setProperty( PROP_VerticalSplitMode, nVSplitMode);
423  aPropMap.setProperty( PROP_HorizontalSplitPositionTwips, nHSplitPos);
424  aPropMap.setProperty( PROP_VerticalSplitPositionTwips, nVSplitPos);
425  aPropMap.setProperty( PROP_ActiveSplitRange, nActivePane);
426  aPropMap.setProperty( PROP_PositionLeft, aFirstPos.Col() );
427  aPropMap.setProperty( PROP_PositionTop, aFirstPos.Row() );
428  aPropMap.setProperty( PROP_PositionRight, xModel->maSecondPos.Col() );
429  aPropMap.setProperty( PROP_PositionBottom, ((nVSplitPos > 0) ? xModel->maSecondPos.Row() : xModel->maFirstPos.Row() ) );
430  aPropMap.setProperty( PROP_ZoomType, API_ZOOMTYPE_PERCENT);
431  aPropMap.setProperty( PROP_ZoomValue, static_cast< sal_Int16 >( xModel->getNormalZoom() ));
432  aPropMap.setProperty( PROP_PageViewZoomValue, static_cast< sal_Int16 >( xModel->getPageBreakZoom() ));
433  aPropMap.setProperty( PROP_GridColor, xModel->getGridColor( getBaseFilter() ));
434  aPropMap.setProperty( PROP_ShowPageBreakPreview, xModel->isPageBreakPreview());
435  aPropMap.setProperty( PROP_ShowFormulas, xModel->mbShowFormulas);
436  aPropMap.setProperty( PROP_ShowGrid, xModel->mbShowGrid);
437  aPropMap.setProperty( PROP_HasColumnRowHeaders, xModel->mbShowHeadings);
438  aPropMap.setProperty( PROP_ShowZeroValues, xModel->mbShowZeros);
439  aPropMap.setProperty( PROP_IsOutlineSymbolsSet, xModel->mbShowOutline);
440 
441  // store sheet view settings in global view settings object
443 }
444 
446 {
447  return !maSheetViews.empty() && maSheetViews.front()->mbRightToLeft;
448 }
449 
450 // private --------------------------------------------------------------------
451 
453 {
454  SheetViewModelRef xModel = std::make_shared<SheetViewModel>();
455  maSheetViews.push_back( xModel );
456  return xModel;
457 }
458 
460  mnWinX( 0 ),
461  mnWinY( 0 ),
462  mnWinWidth( 0 ),
463  mnWinHeight( 0 ),
464  mnActiveSheet( 0 ),
465  mnFirstVisSheet( 0 ),
466  mnTabBarWidth( OOX_BOOKVIEW_TABBARRATIO_DEF ),
467  mnVisibility( XML_visible ),
468  mbShowTabBar( true ),
469  mbShowHorScroll( true ),
470  mbShowVerScroll( true ),
471  mbMinimized( false )
472 {
473 }
474 
476  WorkbookHelper( rHelper ),
477  mbValidOleSize( false )
478 {
479 }
480 
482 {
484  rModel.mnWinX = rAttribs.getInteger( XML_xWindow, 0 );
485  rModel.mnWinY = rAttribs.getInteger( XML_yWindow, 0 );
486  rModel.mnWinWidth = rAttribs.getInteger( XML_windowWidth, 0 );
487  rModel.mnWinHeight = rAttribs.getInteger( XML_windowHeight, 0 );
488  rModel.mnActiveSheet = rAttribs.getInteger( XML_activeTab, 0 );
489  rModel.mnFirstVisSheet = rAttribs.getInteger( XML_firstSheet, 0 );
490  rModel.mnTabBarWidth = rAttribs.getInteger( XML_tabRatio, 600 );
491  rModel.mnVisibility = rAttribs.getToken( XML_visibility, XML_visible );
492  rModel.mbShowTabBar = rAttribs.getBool( XML_showSheetTabs, true );
493  rModel.mbShowHorScroll = rAttribs.getBool( XML_showHorizontalScroll, true );
494  rModel.mbShowVerScroll = rAttribs.getBool( XML_showVerticalScroll, true );
495  rModel.mbMinimized = rAttribs.getBool( XML_minimized, false );
496 }
497 
499 {
500  OUString aRange = rAttribs.getString( XML_ref, OUString() );
501  mbValidOleSize = getAddressConverter().convertToCellRange( maOleSize, aRange, 0, true, false );
502 }
503 
505 {
507  sal_uInt8 nFlags;
508  rModel.mnWinX = rStrm.readInt32();
509  rModel.mnWinY = rStrm.readInt32();
510  rModel.mnWinWidth = rStrm.readInt32();
511  rModel.mnWinHeight = rStrm.readInt32();
512  rModel.mnTabBarWidth = rStrm.readInt32();
513  rModel.mnFirstVisSheet = rStrm.readInt32();
514  rModel.mnActiveSheet = rStrm.readInt32();
515  nFlags = rStrm.readuChar();
516  rModel.mnVisibility = getFlagValue( nFlags, BIFF12_WBVIEW_HIDDEN, XML_hidden, XML_visible );
517  rModel.mbShowTabBar = getFlag( nFlags, BIFF12_WBVIEW_SHOWTABBAR );
518  rModel.mbShowHorScroll = getFlag( nFlags, BIFF12_WBVIEW_SHOWHORSCROLL );
519  rModel.mbShowVerScroll = getFlag( nFlags, BIFF12_WBVIEW_SHOWVERSCROLL );
520  rModel.mbMinimized = getFlag( nFlags, BIFF12_WBVIEW_MINIMIZED );
521 }
522 
524 {
525  BinRange aBinRange;
526  rStrm >> aBinRange;
527  mbValidOleSize = getAddressConverter().convertToCellRange( maOleSize, aBinRange, 0, true, false );
528 }
529 
530 void ViewSettings::setSheetViewSettings( sal_Int16 nSheet, const SheetViewModelRef& rxSheetView, const Any& rProperties )
531 {
532  maSheetViews[ nSheet ] = rxSheetView;
533  maSheetProps[ nSheet ] = rProperties;
534 }
535 
536 void ViewSettings::setSheetUsedArea( const ScRange& rUsedArea )
537 {
538  assert( rUsedArea.IsValid() );
539  maSheetUsedAreas[ rUsedArea.aStart.Tab() ] = rUsedArea;
540 }
541 
543 {
544  const WorksheetBuffer& rWorksheets = getWorksheets();
545  if( rWorksheets.getWorksheetCount() <= 0 ) return;
546 
547  // force creation of workbook view model to get the Excel defaults
548  const WorkbookViewModel& rModel = maBookViews.empty() ? createWorkbookView() : *maBookViews.front();
549 
550  // show object mode is part of workbook settings
551  sal_Int16 nShowMode = getWorkbookSettings().getApiShowObjectMode();
552 
553  // view settings for all sheets
554  Reference< XNameContainer > xSheetsNC = NamedPropertyValues::create( getBaseFilter().getComponentContext() );
555  if( !xSheetsNC.is() ) return;
556  for( const auto& [rWorksheet, rObj] : maSheetProps )
557  ContainerHelper::insertByName( xSheetsNC, rWorksheets.getCalcSheetName( rWorksheet ), rObj );
558 
559  // use active sheet to set sheet properties that are document-global in Calc
560  sal_Int16 nActiveSheet = getActiveCalcSheet();
561  SheetViewModelRef& rxActiveSheetView = maSheetViews[ nActiveSheet ];
562  OSL_ENSURE( rxActiveSheetView, "ViewSettings::finalizeImport - missing active sheet view settings" );
563  if( !rxActiveSheetView )
564  rxActiveSheetView = std::make_shared<SheetViewModel>();
565 
566  Reference< XIndexContainer > xContainer = IndexedPropertyValues::create( getBaseFilter().getComponentContext() );
567  if( xContainer.is() ) try
568  {
569  PropertyMap aPropMap;
570  aPropMap.setProperty( PROP_Tables, xSheetsNC);
571  aPropMap.setProperty( PROP_ActiveTable, rWorksheets.getCalcSheetName( nActiveSheet ));
572  aPropMap.setProperty( PROP_HasHorizontalScrollBar, rModel.mbShowHorScroll);
573  aPropMap.setProperty( PROP_HasVerticalScrollBar, rModel.mbShowVerScroll);
574  aPropMap.setProperty( PROP_HasSheetTabs, rModel.mbShowTabBar);
575  aPropMap.setProperty( PROP_RelativeHorizontalTabbarWidth, double( rModel.mnTabBarWidth / 1000.0 ));
576  aPropMap.setProperty( PROP_ShowObjects, nShowMode);
577  aPropMap.setProperty( PROP_ShowCharts, nShowMode);
578  aPropMap.setProperty( PROP_ShowDrawing, nShowMode);
579  aPropMap.setProperty( PROP_GridColor, rxActiveSheetView->getGridColor( getBaseFilter() ));
580  aPropMap.setProperty( PROP_ShowPageBreakPreview, rxActiveSheetView->isPageBreakPreview());
581  aPropMap.setProperty( PROP_ShowFormulas, rxActiveSheetView->mbShowFormulas);
582  aPropMap.setProperty( PROP_ShowGrid, rxActiveSheetView->mbShowGrid);
583  aPropMap.setProperty( PROP_HasColumnRowHeaders, rxActiveSheetView->mbShowHeadings);
584  aPropMap.setProperty( PROP_ShowZeroValues, rxActiveSheetView->mbShowZeros);
585  aPropMap.setProperty( PROP_IsOutlineSymbolsSet, rxActiveSheetView->mbShowOutline);
586 
587  xContainer->insertByIndex( 0, Any( aPropMap.makePropertyValueSequence() ) );
588  Reference< XViewDataSupplier > xViewDataSuppl( getDocument(), UNO_QUERY_THROW );
589  xViewDataSuppl->setViewData( xContainer );
590  }
591  catch( Exception& )
592  {
593  OSL_FAIL( "ViewSettings::finalizeImport - cannot create document view settings" );
594  }
595 
596  /* Set visible area to be used if this document is an embedded OLE object.
597  #i44077# If a new OLE object is inserted from file, there is no OLESIZE
598  record in the Excel file. In this case, use the used area calculated
599  from file contents (used cells and drawing objects). */
600  maOleSize.aStart.SetTab( nActiveSheet );
601  maOleSize.aEnd.SetTab( nActiveSheet );
602  const ScRange* pVisibleArea = mbValidOleSize ?
604  if( pVisibleArea )
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 }
622 
624 {
625  return maBookViews.empty() ? 0 : ::std::max< sal_Int16 >( getWorksheets().getCalcSheetIndex( maBookViews.front()->mnActiveSheet ), 0 );
626 }
627 
628 // private --------------------------------------------------------------------
629 
631 {
632  WorkbookViewModelRef xModel = std::make_shared<WorkbookViewModel>();
633  maBookViews.push_back( xModel );
634  return *xModel;
635 }
636 
637 } // namespace oox
638 
639 /* 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)
const ::Color API_RGB_TRANSPARENT(0xffffffff)
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)
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:1108
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.