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>
55using ::oox::core::FilterBase;
59const sal_Int32 OOX_BOOKVIEW_TABBARRATIO_DEF = 600;
60const sal_Int32 OOX_SHEETVIEW_NORMALZOOM_DEF = 100;
61const sal_Int32 OOX_SHEETVIEW_SHEETLAYZOOM_DEF = 60;
64const sal_uInt8 BIFF12_PANE_FROZENNOSPLIT = 0x02;
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;
75const sal_uInt16 BIFF12_CHARTSHEETVIEW_SELECTED = 0x0001;
76const sal_uInt16 BIFF12_CHARTSHEETVIEW_ZOOMTOFIT = 0x0002;
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;
85const sal_Int16 API_ZOOMTYPE_PERCENT = 0;
87const sal_Int32 API_ZOOMVALUE_MIN = 20;
88const sal_Int32 API_ZOOMVALUE_MAX = 400;
91const sal_Int16 API_SPLITMODE_NONE = 0;
92const sal_Int16 API_SPLITMODE_SPLIT = 1;
93const sal_Int16 API_SPLITMODE_FREEZE = 2;
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;
102sal_Int32 lclGetOoxPaneId( sal_Int32 nBiffPaneId, sal_Int32 nDefaultPaneId )
104 static const sal_Int32 spnPaneIds[] = { XML_bottomRight, XML_topRight, XML_bottomLeft, XML_topLeft };
116 mnWorkbookViewId( 0 ),
117 mnViewType( XML_normal ),
118 mnActivePaneId( XML_topLeft ),
119 mnPaneState( XML_split ),
124 mnSheetLayoutZoom( 0 ),
125 mnPageLayoutZoom( 0 ),
127 mbRightToLeft( false ),
128 mbDefGridColor( true ),
129 mbShowFormulas( false ),
131 mbShowHeadings( true ),
133 mbShowOutline( true ),
147 sal_Int32 nZoom = (rnZoom > 0) ? rnZoom : OOX_SHEETVIEW_NORMALZOOM_DEF;
148 return getLimitedValue< sal_Int32 >( nZoom, API_ZOOMVALUE_MIN, API_ZOOMVALUE_MAX );
154 sal_Int32 nZoom = (rnZoom > 0) ? rnZoom : OOX_SHEETVIEW_SHEETLAYZOOM_DEF;
155 return getLimitedValue< sal_Int32 >( nZoom, API_ZOOMVALUE_MIN, API_ZOOMVALUE_MAX );
172 rxPaneSel = std::make_shared<PaneSelectionModel>();
204 OSL_ENSURE( !
maSheetViews.empty(),
"SheetViewSettings::importPane - missing sheet view model" );
218 OSL_ENSURE( !
maSheetViews.empty(),
"SheetViewSettings::importSelection - missing sheet view model" );
222 sal_Int32 nPaneId = rAttribs.
getToken( XML_pane, XML_topLeft );
248 nFlags =
rStrm.readuInt16();
249 nViewType =
rStrm.readInt32();
259 static const sal_Int32 spnViewTypes[] = { XML_normal, XML_pageBreakPreview, XML_pageLayout };
273 OSL_ENSURE( !
maSheetViews.empty(),
"SheetViewSettings::importPane - missing sheet view model" );
280 sal_Int32 nActivePaneId;
285 nActivePaneId =
rStrm.readInt32();
286 nFlags =
rStrm.readuChar();
289 rModel.
mnActivePaneId = lclGetOoxPaneId( nActivePaneId, XML_topLeft );
295 OSL_ENSURE( !
maSheetViews.empty(),
"SheetViewSettings::importSelection - missing sheet view model" );
300 sal_Int32 nPaneId =
rStrm.readInt32();
304 rStrm >> aActiveCell;
318 nFlags =
rStrm.readuInt16();
334 xModel->maPaneSelMap.clear();
336 xModel->mnViewType = XML_normal;
337 xModel->mnActivePaneId = XML_topLeft;
338 xModel->mnPaneState = XML_split;
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;
364 sal_Int16 nHSplitMode = API_SPLITMODE_NONE;
365 sal_Int16 nVSplitMode = API_SPLITMODE_NONE;
366 sal_Int32 nHSplitPos = 0;
367 sal_Int32 nVSplitPos = 0;
369 sal_Int16 nActivePane = API_SPLITPANE_BOTTOMLEFT;
372 if( (
xModel->mnPaneState == XML_frozen) || (
xModel->mnPaneState == XML_frozenSplit) )
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;
386 else if(
xModel->mnPaneState == XML_split )
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;
396 switch(
xModel->mnActivePaneId )
401 nActivePane = (nVSplitMode == API_SPLITMODE_NONE) ? API_SPLITPANE_BOTTOMLEFT : API_SPLITPANE_TOPLEFT;
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);
409 nActivePane = API_SPLITPANE_BOTTOMLEFT;
411 case XML_bottomRight:
412 nActivePane = (nHSplitMode == API_SPLITMODE_NONE) ? API_SPLITPANE_BOTTOMLEFT : API_SPLITPANE_BOTTOMRIGHT;
418 aPropMap.
setProperty( PROP_TableSelected, bSelected);
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);
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() ));
465 mnFirstVisSheet( 0 ),
466 mnTabBarWidth( OOX_BOOKVIEW_TABBARRATIO_DEF ),
467 mnVisibility( XML_visible ),
468 mbShowTabBar( true ),
469 mbShowHorScroll( true ),
470 mbShowVerScroll( true ),
477 mbValidOleSize( false )
500 OUString aRange = rAttribs.
getString( XML_ref, OUString() );
515 nFlags =
rStrm.readuChar();
555 if( !xSheetsNC.is() )
return;
562 OSL_ENSURE( rxActiveSheetView,
"ViewSettings::finalizeImport - missing active sheet view settings" );
563 if( !rxActiveSheetView )
564 rxActiveSheetView = std::make_shared<SheetViewModel>();
576 aPropMap.
setProperty( PROP_ShowObjects, nShowMode);
578 aPropMap.
setProperty( PROP_ShowDrawing, nShowMode);
580 aPropMap.
setProperty( PROP_ShowPageBreakPreview, rxActiveSheetView->isPageBreakPreview());
581 aPropMap.
setProperty( PROP_ShowFormulas, rxActiveSheetView->mbShowFormulas);
596 aPropMap.
setProperty(PROP_ShowGrid, rxActiveSheetView->mbShowGrid);
598 aPropMap.
setProperty( PROP_HasColumnRowHeaders, rxActiveSheetView->mbShowHeadings);
599 aPropMap.
setProperty( PROP_ShowZeroValues, rxActiveSheetView->mbShowZeros);
600 aPropMap.
setProperty( PROP_IsOutlineSymbolsSet, rxActiveSheetView->mbShowOutline);
603 Reference< XViewDataSupplier > xViewDataSuppl(
getDocument(), UNO_QUERY_THROW );
604 xViewDataSuppl->setViewData( xContainer );
608 OSL_FAIL(
"ViewSettings::finalizeImport - cannot create document view settings" );
624 css::awt::Point aPos;
625 css::awt::Size aSize;
629 Sequence< sal_Int32 > aWinExtent{ aPos.X, aPos.Y,
630 aPos.X + aSize.Width, aPos.Y + aSize.Height };
static bool IsHeadlessModeEnabled()
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)
Reference< XComponentContext > getComponentContext(Reference< XMultiServiceFactory > const &factory)
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
constexpr OUStringLiteral PROP_GridColor