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/XViewDataSupplier.hpp>
27#include <com/sun/star/document/NamedPropertyValues.hpp>
28#include <com/sun/star/sheet/XSpreadsheet.hpp>
29#include <com/sun/star/sheet/XSpreadsheetDocument.hpp>
31#include <osl/diagnose.h>
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#include <vcl/svapp.hxx>
45
46namespace com::sun::star::container { class XNameContainer; }
47
48namespace oox::xls {
49
50using namespace ::com::sun::star::awt;
51using namespace ::com::sun::star::container;
52using namespace ::com::sun::star::document;
53using namespace ::com::sun::star::uno;
54
55using ::oox::core::FilterBase;
56
57namespace {
58
59const sal_Int32 OOX_BOOKVIEW_TABBARRATIO_DEF = 600;
60const sal_Int32 OOX_SHEETVIEW_NORMALZOOM_DEF = 100;
61const sal_Int32 OOX_SHEETVIEW_SHEETLAYZOOM_DEF = 60;
62
63const sal_uInt8 BIFF12_PANE_FROZEN = 0x01;
64const sal_uInt8 BIFF12_PANE_FROZENNOSPLIT = 0x02;
65
66const sal_uInt16 BIFF12_SHEETVIEW_SHOWFORMULAS = 0x0002;
67const sal_uInt16 BIFF12_SHEETVIEW_SHOWGRID = 0x0004;
68const sal_uInt16 BIFF12_SHEETVIEW_SHOWHEADINGS = 0x0008;
69const sal_uInt16 BIFF12_SHEETVIEW_SHOWZEROS = 0x0010;
70const sal_uInt16 BIFF12_SHEETVIEW_RIGHTTOLEFT = 0x0020;
71const sal_uInt16 BIFF12_SHEETVIEW_SELECTED = 0x0040;
72const sal_uInt16 BIFF12_SHEETVIEW_SHOWOUTLINE = 0x0100;
73const sal_uInt16 BIFF12_SHEETVIEW_DEFGRIDCOLOR = 0x0200;
74
75const sal_uInt16 BIFF12_CHARTSHEETVIEW_SELECTED = 0x0001;
76const sal_uInt16 BIFF12_CHARTSHEETVIEW_ZOOMTOFIT = 0x0002;
77
78const sal_uInt8 BIFF12_WBVIEW_HIDDEN = 0x01;
79const sal_uInt8 BIFF12_WBVIEW_MINIMIZED = 0x02;
80const sal_uInt8 BIFF12_WBVIEW_SHOWHORSCROLL = 0x08;
81const sal_uInt8 BIFF12_WBVIEW_SHOWVERSCROLL = 0x10;
82const sal_uInt8 BIFF12_WBVIEW_SHOWTABBAR = 0x20;
83
84// Attention: view settings in Calc do not use com.sun.star.view.DocumentZoomType!
85const sal_Int16 API_ZOOMTYPE_PERCENT = 0;
86
87const sal_Int32 API_ZOOMVALUE_MIN = 20;
88const sal_Int32 API_ZOOMVALUE_MAX = 400;
89
90// no predefined constants for split mode
91const sal_Int16 API_SPLITMODE_NONE = 0;
92const sal_Int16 API_SPLITMODE_SPLIT = 1;
93const sal_Int16 API_SPLITMODE_FREEZE = 2;
94
95// no predefined constants for pane identifiers
96const sal_Int16 API_SPLITPANE_TOPLEFT = 0;
97const sal_Int16 API_SPLITPANE_TOPRIGHT = 1;
98const sal_Int16 API_SPLITPANE_BOTTOMLEFT = 2;
99const sal_Int16 API_SPLITPANE_BOTTOMRIGHT = 3;
100
102sal_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;
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 return;
276
277 SheetViewModel& rModel = *maSheetViews.back();
278
279 BinAddress aSecondPos;
280 sal_Int32 nActivePaneId;
281 sal_uInt8 nFlags;
282 rModel.mfSplitX = rStrm.readDouble();
283 rModel.mfSplitY = rStrm.readDouble();
284 rStrm >> aSecondPos;
285 nActivePaneId = rStrm.readInt32();
286 nFlags = rStrm.readuChar();
287
288 rModel.maSecondPos = getAddressConverter().createValidCellAddress( aSecondPos, getSheetIndex(), false );
289 rModel.mnActivePaneId = lclGetOoxPaneId( nActivePaneId, XML_topLeft );
290 rModel.mnPaneState = getFlagValue( nFlags, BIFF12_PANE_FROZEN, getFlagValue( nFlags, BIFF12_PANE_FROZENNOSPLIT, XML_frozen, XML_frozenSplit ), XML_split );
291}
292
294{
295 OSL_ENSURE( !maSheetViews.empty(), "SheetViewSettings::importSelection - missing sheet view model" );
296 if( maSheetViews.empty() )
297 return;
298
299 // pane this selection belongs to
300 sal_Int32 nPaneId = rStrm.readInt32();
301 PaneSelectionModel& rPaneSel = maSheetViews.back()->createPaneSelection( lclGetOoxPaneId( nPaneId, -1 ) );
302 // cursor position
303 BinAddress aActiveCell;
304 rStrm >> aActiveCell;
305 rPaneSel.mnActiveCellId = rStrm.readInt32();
306 rPaneSel.maActiveCell = getAddressConverter().createValidCellAddress( aActiveCell, getSheetIndex(), false );
307 // selection
308 BinRangeList aSelection;
309 rStrm >> aSelection;
310 rPaneSel.maSelection.RemoveAll();
311 getAddressConverter().convertToCellRangeList( rPaneSel.maSelection, aSelection, getSheetIndex(), false );
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
530void ViewSettings::setSheetViewSettings( sal_Int16 nSheet, const SheetViewModelRef& rxSheetView, const Any& rProperties )
531{
532 maSheetViews[ nSheet ] = rxSheetView;
533 maSheetProps[ nSheet ] = rProperties;
534}
535
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
567 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);
583 {
584 // tdf#126541 sheet based grid visibility shouldn't overwrite the global grid visibility
585 aPropMap.setProperty(PROP_ShowGrid, true);
586 }
587 else
588 {
589 // tdf#142854 except for headless mode, otherwise we could get a regression here:
590 // The sheet based grid visibility (bShowGrid) is stored in view settings. Headless
591 // mode means not to export view setting, including sheet based grid visibility.
592 // As the old workaround, use global visibility to keep the losing sheet visibility.
593 // FIXME: this only works correctly if all sheets have the same grid visibility.
594 // The sheet based bShowGrid should be moved to another location, which is supported
595 // by the headless mode, too.
596 aPropMap.setProperty(PROP_ShowGrid, rxActiveSheetView->mbShowGrid);
597 }
598 aPropMap.setProperty( PROP_HasColumnRowHeaders, rxActiveSheetView->mbShowHeadings);
599 aPropMap.setProperty( PROP_ShowZeroValues, rxActiveSheetView->mbShowZeros);
600 aPropMap.setProperty( PROP_IsOutlineSymbolsSet, rxActiveSheetView->mbShowOutline);
601
602 xContainer->insertByIndex( 0, Any( aPropMap.makePropertyValueSequence() ) );
603 Reference< XViewDataSupplier > xViewDataSuppl( getDocument(), UNO_QUERY_THROW );
604 xViewDataSuppl->setViewData( xContainer );
605 }
606 catch( Exception& )
607 {
608 OSL_FAIL( "ViewSettings::finalizeImport - cannot create document view settings" );
609 }
610
611 /* Set visible area to be used if this document is an embedded OLE object.
612 #i44077# If a new OLE object is inserted from file, there is no OLESIZE
613 record in the Excel file. In this case, use the used area calculated
614 from file contents (used cells and drawing objects). */
615 maOleSize.aStart.SetTab( nActiveSheet );
616 maOleSize.aEnd.SetTab( nActiveSheet );
617 const ScRange* pVisibleArea = mbValidOleSize ?
619 if( !pVisibleArea )
620 return;
621
622 // calculate the visible area in units of 1/100 mm
623 PropertySet aRangeProp( getCellRangeFromDoc( *pVisibleArea ) );
624 css::awt::Point aPos;
625 css::awt::Size aSize;
626 if( aRangeProp.getProperty( aPos, PROP_Position ) && aRangeProp.getProperty( aSize, PROP_Size ) )
627 {
628 // set the visible area as sequence of long at the media descriptor
629 Sequence< sal_Int32 > aWinExtent{ aPos.X, aPos.Y,
630 aPos.X + aSize.Width, aPos.Y + aSize.Height };
631 getBaseFilter().getMediaDescriptor()[ "WinExtent" ] <<= aWinExtent;
632 }
633}
634
636{
637 return maBookViews.empty() ? 0 : ::std::max< sal_Int16 >( getWorksheets().getCalcSheetIndex( maBookViews.front()->mnActiveSheet ), 0 );
638}
639
640// private --------------------------------------------------------------------
641
643{
644 WorkbookViewModelRef xModel = std::make_shared<WorkbookViewModel>();
645 maBookViews.push_back( xModel );
646 return *xModel;
647}
648
649} // namespace oox
650
651/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
static bool IsHeadlessModeEnabled()
SCTAB Tab() const
Definition: address.hxx:283
SCROW Row() const
Definition: address.hxx:274
void SetTab(SCTAB nTabP)
Definition: address.hxx:295
SCCOL Col() const
Definition: address.hxx:279
void RemoveAll()
Definition: rangelst.cxx:1101
ScAddress aEnd
Definition: address.hxx:498
bool IsValid() const
Definition: address.hxx:544
ScAddress aStart
Definition: address.hxx:497
std::optional< sal_Int32 > getInteger(sal_Int32 nAttrToken) const
std::optional< OUString > getString(sal_Int32 nAttrToken) const
std::optional< bool > getBool(sal_Int32 nAttrToken) const
std::optional< sal_Int32 > getToken(sal_Int32 nAttrToken) const
std::optional< double > getDouble(sal_Int32 nAttrToken) const
static const MapType::mapped_type * getMapElement(const MapType &rMap, const typename MapType::key_type &rKey)
static bool insertByName(const css::uno::Reference< css::container::XNameContainer > &rxNameContainer, const OUString &rName, const css::uno::Any &rObject)
css::uno::Sequence< css::beans::PropertyValue > makePropertyValueSequence() const
bool setProperty(sal_Int32 nPropId, Type &&rValue)
bool getProperty(Type &orValue, sal_Int32 nPropId) const
bool setProperty(sal_Int32 nPropId, const Type &rValue)
mapped_type get(key_type nKey) const
container_type::mapped_type mapped_type
utl::MediaDescriptor & getMediaDescriptor() const
::Color getColor(const GraphicHelper &rGraphicHelper, ::Color nPhClr=API_RGB_TRANSPARENT) const
ScAddress createValidCellAddress(const OUString &rString, sal_Int16 nSheet, bool bTrackOverflow)
Returns a valid cell address by moving it into allowed dimensions.
bool convertToCellRange(ScRange &orRange, std::u16string_view aString, sal_Int16 nSheet, bool bAllowOverflow, bool bTrackOverflow)
Tries to convert the passed string to a cell range address.
const ScAddress & getMaxApiAddress() const
Returns the biggest valid cell address in the own Calc document.
void convertToCellRangeList(ScRangeList &orRanges, std::u16string_view aString, sal_Int16 nSheet, bool bTrackOverflow)
Tries to convert the passed string to a cell range list.
A 2D cell range address list for binary filters.
void importColorId(SequenceInputStream &rStrm)
Imports a 32-bit palette color identifier from the passed BIFF12 stream.
void setIndexed(sal_Int32 nPaletteIdx, double fTint=0.0)
Sets the color to the passed palette index.
void importPane(const AttributeList &rAttribs)
Imports the pane element containing sheet pane settings.
bool isSheetRightToLeft() const
Returns true, if the sheet layout is set to right-to-left.
void finalizeImport()
Converts all imported sheet view settings.
void importChartSheetView(const AttributeList &rAttribs)
Imports the sheetView element containing view settings of a chart sheet.
SheetViewModelRef createSheetView()
SheetViewModelVec maSheetViews
void importSelection(const AttributeList &rAttribs)
Imports the selection element containing selection settings for a pane.
void importSheetView(const AttributeList &rAttribs)
Imports the sheetView element containing sheet view settings.
SheetViewSettings(const WorksheetHelper &rHelper)
void finalizeImport()
Converts all imported document view settings.
std::map< sal_Int16, css::uno::Any > maSheetProps
Active view model for each sheet.
bool mbValidOleSize
Visible area if this is an embedded OLE object.
ViewSettings(const WorkbookHelper &rHelper)
WorkbookViewModel & createWorkbookView()
void setSheetUsedArea(const ScRange &rUsedArea)
Stores the used area for a specific worksheet.
void importOleSize(const AttributeList &rAttribs)
Imports the oleSize element containing the visible size of the workbook.
WorkbookViewModelVec maBookViews
void setSheetViewSettings(sal_Int16 nSheet, const SheetViewModelRef &rxSheetView, const css::uno::Any &rProperties)
Stores converted view settings for a specific worksheet.
SheetViewModelMap maSheetViews
Workbook view models.
void importWorkbookView(const AttributeList &rAttribs)
Imports the workbookView element containing workbook view settings.
sal_Int16 getActiveCalcSheet() const
Returns the Calc index of the active sheet.
std::map< sal_Int16, ScRange > maSheetUsedAreas
Converted property sequences for each sheet.
ScRange maOleSize
Used area (cell range) of every sheet.
Helper class to provide access to global workbook data.
WorksheetBuffer & getWorksheets() const
Returns the worksheet buffer containing sheet names and properties.
AddressConverter & getAddressConverter() const
Returns the converter for string to cell address/range conversion.
WorkbookSettings & getWorkbookSettings() const
Returns the global workbook settings object.
css::uno::Reference< css::table::XCellRange > getCellRangeFromDoc(const ScRange &rRange) const
Returns the XCellRange interface for the passed cell range address.
ViewSettings & getViewSettings() const
Returns the workbook and sheet view settings object.
::oox::core::FilterBase & getBaseFilter() const
Returns the base filter object (base class of all filters).
const css::uno::Reference< css::sheet::XSpreadsheetDocument > & getDocument() const
Returns a reference to the source/target spreadsheet document model.
sal_Int16 getApiShowObjectMode() const
Returns the show objects mode (considered a view setting in Calc).
Stores information about all sheets in a spreadsheet document.
OUString getCalcSheetName(sal_Int32 nWorksheet) const
Returns the finalized name of the specified worksheet.
sal_Int32 getWorksheetCount() const
Returns the number of original sheets contained in the workbook.
WorksheetType getSheetType() const
Returns the type of this sheet.
SCTAB getSheetIndex() const
Returns the index of the current sheet.
const css::uno::Reference< css::sheet::XSpreadsheet > & getSheet() const
Returns the XSpreadsheet interface of the current sheet.
#define STATIC_ARRAY_SELECT(array, index, def)
@ Exception
Reference< XComponentContext > getComponentContext(Reference< XMultiServiceFactory > const &factory)
void SvStream & rStrm
const sal_Int32 OOX_COLOR_WINDOWTEXT
System window background color (BIFF3-BIFF4).
std::shared_ptr< WorkbookViewModel > WorkbookViewModelRef
std::shared_ptr< SheetViewModel > SheetViewModelRef
ReturnType getFlagValue(Type nBitField, Type nMask, ReturnType nSet, ReturnType nUnset)
const ::Color API_RGB_TRANSPARENT(ColorTransparency, 0xffffffff)
bool getFlag(Type nBitField, Type nMask)
A 2D cell address struct for binary filters.
A 2D cell range address struct for binary filters.
Contains all settings for a selection in a single pane of a sheet.
ScRangeList maSelection
Position of active cell (cursor).
sal_Int32 mnActiveCellId
Selected cell ranges.
PaneSelectionModel()
Index of active cell in selection list.
Contains all view settings for a single sheet.
sal_Int32 mnActivePaneId
View type (normal, page break, layout).
const PaneSelectionModel * getActiveSelection() const
Returns the selection data of the active pane.
double mfSplitX
Pane state (frozen, split).
sal_Int32 mnSheetLayoutZoom
Zoom factor for normal view.
sal_Int32 getNormalZoom() const
Returns the zoom in normal view (returns default, if current value is 0).
sal_Int32 mnCurrentZoom
Split Y position (twips), or number of frozen rows.
bool mbSelected
Zoom factor for page layout view.
double mfSplitY
Split X position (twips), or number of frozen columns.
bool mbShowFormulas
True = default grid color.
sal_Int32 mnPaneState
Active pane (with cell cursor).
sal_Int32 getPageBreakZoom() const
Returns the zoom in pagebreak preview (returns default, if current value is 0).
bool mbDefGridColor
True = sheet in right-to-left mode.
bool mbRightToLeft
True = sheet is selected.
bool mbShowOutline
True = show zero value zells.
sal_Int32 mnViewType
Index into list of workbookView elements.
PaneSelectionModelMap maPaneSelMap
sal_Int32 mnWorkbookViewId
First visible cell in additional panes.
::Color getGridColor(const ::oox::core::FilterBase &rFilter) const
Returns the grid color as RGB value.
sal_Int32 mnNormalZoom
Zoom factor for current view.
bool isPageBreakPreview() const
Returns true, if page break preview is active.
ScAddress maFirstPos
Grid color.
ScAddress maSecondPos
First visible cell.
sal_Int32 mnPageLayoutZoom
Zoom factor for pagebreak preview.
bool mbShowZeros
True = show column/row headings.
SheetViewModel()
True = zoom chart sheet to fit window.
bool mbShowGrid
True = show formulas instead of results.
bool mbShowHeadings
True = show cell grid.
PaneSelectionModel & createPaneSelection(sal_Int32 nPaneId)
Returns read/write access to the selection data of the specified pane.
bool mbZoomToFit
True = show outlines.
Color maGridColor
Selections of all panes.
Contains all view settings for the entire document.
sal_Int32 mnVisibility
Width of sheet tabbar (1/1000 of window width).
bool mbMinimized
True = show vertical sheet scrollbars.
sal_Int32 mnWinY
X position of the workbook window (twips).
WorkbookViewModel()
True = workbook window is minimized.
sal_Int32 mnWinWidth
Y position of the workbook window (twips).
sal_Int32 mnFirstVisSheet
Displayed (active) sheet.
sal_Int32 mnActiveSheet
Height of the workbook window (twips).
bool mbShowTabBar
Visibility state of workbook window.
bool mbShowHorScroll
True = show sheet tabbar.
sal_Int32 mnWinHeight
Width of the workbook window (twips).
bool mbShowVerScroll
True = show horizontal sheet scrollbars.
sal_Int32 mnTabBarWidth
First visible sheet in sheet tabbar.
Reference< XModel > xModel
unsigned char sal_uInt8
#define SAL_MAX_INT32
sal_Int16 SCCOL
Definition: types.hxx:21
sal_Int32 SCROW
Definition: types.hxx:17
constexpr OUStringLiteral PROP_GridColor