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>
39 #include <oox/token/properties.hxx>
40 #include <oox/token/tokens.hxx>
55 using ::oox::core::FilterBase;
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;
63 const sal_uInt8 BIFF12_PANE_FROZEN = 0x01;
64 const sal_uInt8 BIFF12_PANE_FROZENNOSPLIT = 0x02;
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;
75 const sal_uInt16 BIFF12_CHARTSHEETVIEW_SELECTED = 0x0001;
76 const sal_uInt16 BIFF12_CHARTSHEETVIEW_ZOOMTOFIT = 0x0002;
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;
85 const sal_Int16 API_ZOOMTYPE_PERCENT = 0;
87 const sal_Int32 API_ZOOMVALUE_MIN = 20;
88 const sal_Int32 API_ZOOMVALUE_MAX = 400;
91 const sal_Int16 API_SPLITMODE_NONE = 0;
92 const sal_Int16 API_SPLITMODE_SPLIT = 1;
93 const sal_Int16 API_SPLITMODE_FREEZE = 2;
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;
102 sal_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 );
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;
289 rModel.
mnActivePaneId = lclGetOoxPaneId( nActivePaneId, XML_topLeft );
295 OSL_ENSURE( !
maSheetViews.empty(),
"SheetViewSettings::importSelection - missing sheet view model" );
304 rStrm >> aActiveCell;
334 xModel->maPaneSelMap.clear();
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;
359 ScAddress aFirstPos = xModel->maFirstPos;
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);
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() ));
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);
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() );
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>();
567 if( xContainer.is() )
try
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 };
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).
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.
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.
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
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_Int32 mnViewType
Index into list of workbookView elements.
SheetViewModel()
True = zoom chart sheet to fit window.
std::shared_ptr< SheetViewModel > SheetViewModelRef
::oox::core::FilterBase & getBaseFilter() const
Returns the base filter object (base class of all filters).
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.
bool mbRightToLeft
True = sheet is selected.
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.
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 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.
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.
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.
static bool IsHeadlessModeEnabled()
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.
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
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.
bool m_bDetectedRangeSegmentation false
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.